]> git.tdb.fi Git - r2c2.git/commitdiff
Display icons and addresses for signals and beam gates
authorMikko Rasa <tdb@tdb.fi>
Wed, 20 Nov 2013 11:19:03 +0000 (13:19 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 20 Nov 2013 12:33:29 +0000 (14:33 +0200)
icons/beamgate.mesh [new file with mode: 0644]
icons/sensor.mesh [deleted file]
icons/signal.mesh [new file with mode: 0644]
icons/trackcircuit.mesh [new file with mode: 0644]
source/designer/designer.cpp
source/designer/designer.h

diff --git a/icons/beamgate.mesh b/icons/beamgate.mesh
new file mode 100644 (file)
index 0000000..8db75e7
--- /dev/null
@@ -0,0 +1,17 @@
+vertices VERTEX2
+{
+       vertex2 0.0 0.0;
+       vertex2 0.0 0.5;
+       vertex2 0.2 0.5;
+       vertex2 1.0 0.0;
+       vertex2 1.0 0.5;
+       vertex2 0.8 0.5;
+};
+batch LINE_STRIP
+{
+       indices 0 1 2;
+};
+batch LINE_STRIP
+{
+       indices 3 4 5;
+};
diff --git a/icons/sensor.mesh b/icons/sensor.mesh
deleted file mode 100644 (file)
index cea93f2..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-vertices VERTEX2
-{
-       vertex2 0.0 0.45;
-       vertex2 0.3 0.45;
-       vertex2 1.0 0.45;
-       vertex2 0.7 0.45;
-       vertex2 0.3 0.65;
-};
-batch LINES
-{
-       indices 0 1;
-       indices 2 3 3 4;
-};
diff --git a/icons/signal.mesh b/icons/signal.mesh
new file mode 100644 (file)
index 0000000..8139f32
--- /dev/null
@@ -0,0 +1,10 @@
+vertices VERTEX2
+{
+       vertex2 0.4 0.0;
+       vertex2 0.4 1.0;
+       vertex2 0.6 1.0;
+};
+batch LINE_STRIP
+{
+       indices 0 1 2;
+};
diff --git a/icons/trackcircuit.mesh b/icons/trackcircuit.mesh
new file mode 100644 (file)
index 0000000..cea93f2
--- /dev/null
@@ -0,0 +1,13 @@
+vertices VERTEX2
+{
+       vertex2 0.0 0.45;
+       vertex2 0.3 0.45;
+       vertex2 1.0 0.45;
+       vertex2 0.7 0.45;
+       vertex2 0.3 0.65;
+};
+batch LINES
+{
+       indices 0 1;
+       indices 2 3 3 4;
+};
index a59b3a12dd127839616a13190ceb51b7ee345b4f..6ae9c0726c45701a5915adc9f852d9fdc1b75e66 100644 (file)
@@ -148,9 +148,9 @@ Designer::Designer(int argc, char **argv):
        cat_view->view_all(true);
        main_view->view_all();
 
-       const set<Track *> &tracks = layout->get_all<Track>();
-       for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
-               update_track_icon(layout_3d->get_3d(**i));
+       const set<Object *> &objects = layout->get_all<Object>();
+       for(set<Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+               update_object_icon(**i);
 }
 
 Designer::~Designer()
@@ -406,7 +406,7 @@ void Designer::key_press(unsigned key)
                                if(*j!=*i)
                                        (*i)->snap_to(**j, true);
 
-                       update_track_icon(layout_3d->get_3d(**i));
+                       update_object_icon(**i);
                }
        }
        else if(key==Msp::Input::KEY_F)
@@ -509,25 +509,39 @@ Object *Designer::pick_object(const Vector &pointer)
        return view.get_layout().get_layout().pick<Object>(Ray(cpos, Vector(cray)));
 }
 
-void Designer::update_track_icon(Track3D &track)
+void Designer::update_object_icon(Object &obj)
 {
-       overlay->clear(track);
+       Object3D &obj3d = layout_3d->get_3d(obj);
+       overlay->clear(obj3d);
 
-       if(track.get_track().get_flex())
-               overlay->add_graphic(track, "flex");
+       if(Track *track = dynamic_cast<Track *>(&obj))
+       {
+               if(track->get_flex())
+                       overlay->add_graphic(obj3d, "flex");
 
-       if(unsigned saddr = track.get_track().get_sensor_address())
+               if(unsigned saddr = track->get_sensor_address())
+               {
+                       overlay->add_graphic(obj3d, "trackcircuit");
+                       overlay->set_label(obj3d, lexical_cast<string>(saddr));
+               }
+               else if(unsigned taddr = track->get_turnout_address())
+               {
+                       if(taddr<0x800)
+                       {
+                               overlay->add_graphic(obj3d, "turnout");
+                               overlay->set_label(obj3d, lexical_cast<string>(taddr));
+                       }
+               }
+       }
+       else if(Signal *signal = dynamic_cast<Signal *>(&obj))
        {
-               overlay->add_graphic(track, "sensor");
-               overlay->set_label(track, lexical_cast<string>(saddr));
+               overlay->add_graphic(obj3d, "signal");
+               overlay->set_label(obj3d, lexical_cast<string>(signal->get_address()));
        }
-       else if(unsigned taddr = track.get_track().get_turnout_address())
+       else if(BeamGate *gate = dynamic_cast<BeamGate *>(&obj))
        {
-               if(taddr<0x800)
-               {
-                       overlay->add_graphic(track, "turnout");
-                       overlay->set_label(track, lexical_cast<string>(taddr));
-               }
+               overlay->add_graphic(obj3d, "beamgate");
+               overlay->set_label(obj3d, lexical_cast<string>(gate->get_address()));
        }
 }
 
@@ -538,9 +552,9 @@ void Designer::tool_status(const string &status)
 
 void Designer::object_properties_response(int)
 {
-       const set<Track *> &tracks = selection.get_objects<Track>();
-       for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
-               update_track_icon(layout_3d->get_3d(**i));
+       const set<Object *> &objects = selection.get_objects();
+       for(set<Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+               update_object_icon(**i);
 }
 
 void Designer::route_name_accept(const string &text)
index c09feb9ca2218276f57f5a0e0f3fb8209fe14e5b..499c06cee81f446a7253c4be3e1aa0a9c05ee4fd 100644 (file)
@@ -116,7 +116,7 @@ private:
        void apply_camera();
        void render();
        R2C2::Object *pick_object(const R2C2::Vector &);
-       void update_track_icon(R2C2::Track3D &);
+       void update_object_icon(R2C2::Object &);
        void tool_status(const std::string &);
        void object_properties_response(int);
        void route_name_accept(const std::string &);