]> git.tdb.fi Git - r2c2.git/commitdiff
Also use TrackChains as target locations in Timetable
authorMikko Rasa <tdb@tdb.fi>
Tue, 25 Mar 2014 23:54:01 +0000 (01:54 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 26 Mar 2014 00:08:47 +0000 (02:08 +0200)
12 files changed:
data/timetablepanel.ui
source/engineer/timetablepanel.cpp
source/engineer/timetablepanel.h
source/libr2c2/block.cpp
source/libr2c2/block.h
source/libr2c2/route.cpp
source/libr2c2/route.h
source/libr2c2/timetable.cpp
source/libr2c2/timetable.h
source/libr2c2/trackchain.h
source/libr2c2/zone.cpp
source/libr2c2/zone.h

index 3434315a0e96633c23d06ab4d8bdce8eff9e0445..3bd48da62ccfdd1088f88406b3ef7cd044f044be 100644 (file)
@@ -26,7 +26,7 @@ column
                        item "Depart";
                };
 
-               label "lbl_zone"
+               label "lbl_target"
                {
                        text "No selection";
                };
index 6104873fc7096ffe7b49078e694727dd050e25f1..878de865835aa8a44cf48b5619ad4354a3540675 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/core/maputils.h>
 #include <msp/gltk/button.h>
 #include <msp/gltk/root.h>
+#include <msp/input/keys.h>
 #include <msp/strings/format.h>
 #include <msp/strings/regex.h>
 #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<GLtk::Dropdown *>(get_item(widgets, "drp_type"));
-       lbl_zone = dynamic_cast<GLtk::Label *>(get_item(widgets, "lbl_zone"));
+       lbl_target = dynamic_cast<GLtk::Label *>(get_item(widgets, "lbl_target"));
        ent_time = dynamic_cast<GLtk::Entry *>(get_item(widgets, "ent_time"));
 
        dynamic_cast<GLtk::Button *>(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<Timetable::RowType>(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<Track>(ray);
                if(track)
                {
-                       const set<Zone *> &zones = engineer.get_layout().get_all<Zone>();
-                       Zone *track_zone = 0;
-                       for(set<Zone *>::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<Zone *> &zones = engineer.get_layout().get_all<Zone>();
+                               for(set<Zone *>::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);
index a0f5be8cd0fea1351c41f85802f27547d5ca6973..930a0a2cd0e026c36e427826cd47c02c90457ebf 100644 (file)
@@ -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<const R2C2::Timetable::Row *> 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);
 };
index 7c0409d94588caa787f1c73d440189c69de68a0b..e4292eab40960e338ba0a7df7acd68f447e3e14f 100644 (file)
@@ -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),
index 86ad6ce593e0204ee7708fd3ad0a26560547e709..f255e43f2e2421fb18b81bd9c0a6e862e0218a63 100644 (file)
@@ -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
index 7458cc66e2eb87f57a08373d6dfc04041bc5680b..5b37fcc06f3f7d381ec63309d9450ffde7f9e558 100644 (file)
@@ -257,6 +257,11 @@ void Route::save(list<DataFile::Statement> &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));
index 6ada85078e19f18afbc72ab5d595776a34df925b..2133b766532c8c5287ebe6c3b57a89e7b33b0d52 100644 (file)
@@ -58,6 +58,7 @@ private:
 
 public:
        void save(std::list<Msp::DataFile::Statement> &) const;
+       virtual Msp::DataFile::Statement save_reference() const;
 
        static Route *find(const TrackIter &, Track &);
        static Route *find(const TrackIter &, const Route &);
index 631f58a0894ec4fa15c8978c8279fbc4f571cb1c..ed7d01831445e3745a4e7a297d687e5f3c3d7e00 100644 (file)
@@ -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<DataFile::Statement> &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<Timetable::Row>(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)
 {
index b67e5fb3c2baa4761b639dae6a55e3902795e014..07250ca94a941376601ad0dafd4b7419c4daaba2 100644 (file)
@@ -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();
index 729a89cd9c6910882fe641721f86751e93df21e0..e2d6176f2c1733ff093975d39ef5afe132bbebc4 100644 (file)
@@ -4,6 +4,7 @@
 #include <set>
 #include <stdexcept>
 #include <sigc++/trackable.h>
+#include <msp/datafile/statement.h>
 #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
index 318c8150df8fca0a0d8e38c55f8b9edde4b97e25..30b60e99aa65865a0960afc113e3d5f5fedfbd7f 100644 (file)
@@ -70,6 +70,11 @@ void Zone::save(list<DataFile::Statement> &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<Zone>(z)
index 86a36e8a45951bafd307ad4f031eb856512efccc..9688c3419540bcf17173bcfbd49d853875f426ff 100644 (file)
@@ -42,6 +42,7 @@ public:
        unsigned get_number() const { return number; }
 
        void save(std::list<Msp::DataFile::Statement> &) const;
+       virtual Msp::DataFile::Statement save_reference() const;
 };
 
 } // namespace R2C2