From 1ac853ffc606b29ffd88b923ed3551ee6282afb2 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 26 Mar 2014 01:54:01 +0200 Subject: [PATCH] Also use TrackChains as target locations in Timetable --- data/timetablepanel.ui | 2 +- source/engineer/timetablepanel.cpp | 78 +++++++++++++++++++----------- source/engineer/timetablepanel.h | 11 +++-- source/libr2c2/block.cpp | 5 ++ source/libr2c2/block.h | 3 ++ source/libr2c2/route.cpp | 5 ++ source/libr2c2/route.h | 1 + source/libr2c2/timetable.cpp | 16 ++++-- source/libr2c2/timetable.h | 7 +-- source/libr2c2/trackchain.h | 4 ++ source/libr2c2/zone.cpp | 5 ++ source/libr2c2/zone.h | 1 + 12 files changed, 97 insertions(+), 41 deletions(-) diff --git a/data/timetablepanel.ui b/data/timetablepanel.ui index 3434315..3bd48da 100644 --- a/data/timetablepanel.ui +++ b/data/timetablepanel.ui @@ -26,7 +26,7 @@ column item "Depart"; }; - label "lbl_zone" + label "lbl_target" { text "No selection"; }; diff --git a/source/engineer/timetablepanel.cpp b/source/engineer/timetablepanel.cpp index 6104873..878de86 100644 --- a/source/engineer/timetablepanel.cpp +++ b/source/engineer/timetablepanel.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "libr2c2/zone.h" @@ -33,9 +34,9 @@ string format_time(const Time::TimeDelta &time) TimetablePanel::TimetablePanel(Engineer &e, R2C2::Train &t): engineer(e), train(t), - zone(0), - zone_pick(false), - picked_zone(0), + target(0), + target_pick(false), + picked_target(0), pick_highlight(0) { Loader::WidgetMap widgets; @@ -47,7 +48,7 @@ TimetablePanel::TimetablePanel(Engineer &e, R2C2::Train &t): lst_timetable->signal_item_selected.connect(sigc::mem_fun(this, &TimetablePanel::row_selected)); drp_type = dynamic_cast(get_item(widgets, "drp_type")); - lbl_zone = dynamic_cast(get_item(widgets, "lbl_zone")); + lbl_target = dynamic_cast(get_item(widgets, "lbl_target")); ent_time = dynamic_cast(get_item(widgets, "ent_time")); dynamic_cast(get_item(widgets, "btn_pick"))->signal_clicked.connect(sigc::mem_fun(this, &TimetablePanel::pick_clicked)); @@ -88,7 +89,7 @@ Timetable::Row TimetablePanel::create_row() Timetable::Row row; row.type = static_cast(drp_type->get_selected_index()+1); - row.zone = zone; + row.target = target; Regex r_time("([01]?[0-9]|2[0-3]):([0-5][0-9])(:([0-5][0-9]))?"); RegMatch m = r_time.match(ent_time->get_text()); @@ -109,16 +110,17 @@ void TimetablePanel::row_selected(unsigned i) if(row) { drp_type->set_selected_index(row->type-1); - if(row->zone) - lbl_zone->set_text(row->zone->get_name()); + if(row->target) + lbl_target->set_text(row->target->get_name()); ent_time->set_text(format_time(row->time)); } } void TimetablePanel::pick_clicked() { - zone_pick = true; - picked_zone = 0; + target_pick = true; + picked_target = 0; + shift = false; signal_grab_pointer.emit(); } @@ -144,22 +146,38 @@ void TimetablePanel::apply_clicked() timetable->modify_row(index, create_row()); } +void TimetablePanel::key_press(unsigned key, unsigned mod) +{ + Panel::key_press(key, mod); + + if(key==Input::KEY_SHIFT_R || key==Input::KEY_SHIFT_L) + shift = true; +} + +void TimetablePanel::key_release(unsigned key, unsigned mod) +{ + Panel::key_release(key, mod); + + if(key==Input::KEY_SHIFT_R || key==Input::KEY_SHIFT_L) + shift = false; +} + void TimetablePanel::button_press(int x, int y, unsigned btn) { Panel::button_press(x, y, btn); - if(zone_pick) + if(target_pick) { signal_ungrab_pointer.emit(); - zone_pick = false; + target_pick = false; delete pick_highlight; pick_highlight = 0; - if(picked_zone && btn==1) + if(picked_target && btn==1) { - zone = picked_zone; - lbl_zone->set_text(zone->get_name()); + target = picked_target; + lbl_target->set_text(target->get_name()); } } } @@ -168,7 +186,7 @@ void TimetablePanel::pointer_motion(int x, int y) { Panel::pointer_motion(x, y); - if(zone_pick) + if(target_pick) { int rx = x; int ry = y; @@ -177,19 +195,23 @@ void TimetablePanel::pointer_motion(int x, int y) Track *track = engineer.get_layout().pick(ray); if(track) { - const set &zones = engineer.get_layout().get_all(); - Zone *track_zone = 0; - for(set::const_iterator i=zones.begin(); (!track_zone && i!=zones.end()); ++i) - if((*i)->has_track(*track)) - track_zone = *i; - if(track_zone!=picked_zone) + TrackChain *t = 0; + if(!shift) + { + const set &zones = engineer.get_layout().get_all(); + for(set::const_iterator i=zones.begin(); (!t && i!=zones.end()); ++i) + if((*i)->has_track(*track)) + t = *i; + } + + if(!t) + t = &track->get_block(); + + if(t!=picked_target) { - picked_zone = track_zone; + picked_target = t; delete pick_highlight; - if(picked_zone) - pick_highlight = new TrackChain3D(engineer.get_layout_3d(), *track_zone); - else - pick_highlight = 0; + pick_highlight = new TrackChain3D(engineer.get_layout_3d(), *picked_target); } } } @@ -201,7 +223,7 @@ TimetableRowItem::TimetableRowItem(ValueType row) if(row) { add(*new GLtk::Label(format_time(row->time))); - if(row->zone) + if(row->target) { string type; switch(row->type) @@ -209,7 +231,7 @@ TimetableRowItem::TimetableRowItem(ValueType row) case Timetable::ARRIVE: type = "Arrive at "; break; case Timetable::DEPART: type = "Depart from "; break; } - add(*new GLtk::Label(type+row->zone->get_name())); + add(*new GLtk::Label(type+row->target->get_name())); } else add(*new GLtk::Label); diff --git a/source/engineer/timetablepanel.h b/source/engineer/timetablepanel.h index a0f5be8..930a0a2 100644 --- a/source/engineer/timetablepanel.h +++ b/source/engineer/timetablepanel.h @@ -20,14 +20,15 @@ private: R2C2::Timetable *timetable; Msp::GLtk::List *lst_timetable; Msp::GLtk::Dropdown *drp_type; - R2C2::Zone *zone; - Msp::GLtk::Label *lbl_zone; + R2C2::TrackChain *target; + Msp::GLtk::Label *lbl_target; Msp::GLtk::Entry *ent_time; Msp::GLtk::BasicListData rows; - bool zone_pick; - R2C2::Zone *picked_zone; + bool target_pick; + R2C2::TrackChain *picked_target; R2C2::TrackChain3D *pick_highlight; + bool shift; public: TimetablePanel(Engineer &, R2C2::Train &); @@ -44,6 +45,8 @@ private: void delete_clicked(); void apply_clicked(); + virtual void key_press(unsigned, unsigned); + virtual void key_release(unsigned, unsigned); virtual void button_press(int, int, unsigned); virtual void pointer_motion(int, int); }; diff --git a/source/libr2c2/block.cpp b/source/libr2c2/block.cpp index 7c0409d..e4292ea 100644 --- a/source/libr2c2/block.cpp +++ b/source/libr2c2/block.cpp @@ -212,6 +212,11 @@ void Block::determine_id() signal_name_changed.emit(name); } +DataFile::Statement Block::save_reference() const +{ + return (DataFile::Statement("block"), id); +} + Block::Endpoint::Endpoint(Track *t, unsigned e): track(t), diff --git a/source/libr2c2/block.h b/source/libr2c2/block.h index 86ad6ce..f255e43 100644 --- a/source/libr2c2/block.h +++ b/source/libr2c2/block.h @@ -65,6 +65,9 @@ public: Train *get_train() const { return train; } private: void determine_id(); + +public: + virtual Msp::DataFile::Statement save_reference() const; }; } // namespace R2C2 diff --git a/source/libr2c2/route.cpp b/source/libr2c2/route.cpp index 7458cc6..5b37fcc 100644 --- a/source/libr2c2/route.cpp +++ b/source/libr2c2/route.cpp @@ -257,6 +257,11 @@ void Route::save(list &st) const st.push_back((DataFile::Statement("turnout"), i->first, i->second)); } +DataFile::Statement Route::save_reference() const +{ + return (DataFile::Statement("route"), name); +} + Route *Route::find(const TrackIter &from, Track &to) { return create_route(from, TrackMatch(to)); diff --git a/source/libr2c2/route.h b/source/libr2c2/route.h index 6ada850..2133b76 100644 --- a/source/libr2c2/route.h +++ b/source/libr2c2/route.h @@ -58,6 +58,7 @@ private: public: void save(std::list &) const; + virtual Msp::DataFile::Statement save_reference() const; static Route *find(const TrackIter &, Track &); static Route *find(const TrackIter &, const Route &); diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index 631f58a..ed7d018 100644 --- a/source/libr2c2/timetable.cpp +++ b/source/libr2c2/timetable.cpp @@ -182,14 +182,14 @@ void Timetable::event(TrainAI &, const Message &msg) Timetable::Row::Row(): type(ARRIVE), - zone(0) + target(0) { } void Timetable::Row::save(list &st) const { st.push_back((DataFile::Statement("type"), type)); st.push_back((DataFile::Statement("time"), time.raw())); - st.push_back((DataFile::Statement("zone"), zone->get_group(), zone->get_number())); + st.push_back(target->save_reference()); } @@ -213,14 +213,15 @@ Timetable::Row::Loader::Loader(Row &r, Layout &l): DataFile::ObjectLoader(r), layout(l) { - add("zone", &Loader::zone); + add("block", &Loader::block); add("time", &Loader::time); add("type", &Row::type); + add("zone", &Loader::zone); } -void Timetable::Row::Loader::zone(const string &name, unsigned number) +void Timetable::Row::Loader::block(unsigned id) { - obj.zone = &layout.get_zone(name, number); + obj.target = &layout.get_block(id); } void Timetable::Row::Loader::time(Time::RawTime t) @@ -228,6 +229,11 @@ void Timetable::Row::Loader::time(Time::RawTime t) obj.time = Time::TimeDelta(t); } +void Timetable::Row::Loader::zone(const string &name, unsigned number) +{ + obj.target = &layout.get_zone(name, number); +} + void operator<<(LexicalConverter &conv, Timetable::RowType rt) { diff --git a/source/libr2c2/timetable.h b/source/libr2c2/timetable.h index b67e5fb..07250ca 100644 --- a/source/libr2c2/timetable.h +++ b/source/libr2c2/timetable.h @@ -7,7 +7,7 @@ namespace R2C2 { class Layout; -class Zone; +class TrackChain; class Timetable: public TrainAI { @@ -41,12 +41,13 @@ public: Loader(Row &, Layout &); private: - void zone(const std::string &, unsigned); + void block(unsigned); void time(Msp::Time::RawTime); + void zone(const std::string &, unsigned); }; RowType type; - Zone *zone; + TrackChain *target; Msp::Time::TimeDelta time; Row(); diff --git a/source/libr2c2/trackchain.h b/source/libr2c2/trackchain.h index 729a89c..e2d6176 100644 --- a/source/libr2c2/trackchain.h +++ b/source/libr2c2/trackchain.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "trackiter.h" namespace R2C2 { @@ -65,6 +66,9 @@ public: private: void object_removed(Object &); + +public: + virtual Msp::DataFile::Statement save_reference() const = 0; }; } // namespace R2C2 diff --git a/source/libr2c2/zone.cpp b/source/libr2c2/zone.cpp index 318c815..30b60e9 100644 --- a/source/libr2c2/zone.cpp +++ b/source/libr2c2/zone.cpp @@ -70,6 +70,11 @@ void Zone::save(list &st) const st.push_back((DataFile::Statement("block"), *i)); } +DataFile::Statement Zone::save_reference() const +{ + return (DataFile::Statement("zone"), group, number); +} + Zone::Loader::Loader(Zone &z): DataFile::ObjectLoader(z) diff --git a/source/libr2c2/zone.h b/source/libr2c2/zone.h index 86a36e8..9688c34 100644 --- a/source/libr2c2/zone.h +++ b/source/libr2c2/zone.h @@ -42,6 +42,7 @@ public: unsigned get_number() const { return number; } void save(std::list &) const; + virtual Msp::DataFile::Statement save_reference() const; }; } // namespace R2C2 -- 2.43.0