]> git.tdb.fi Git - r2c2.git/blobdiff - source/designer/trackproperties.cpp
Add driver for my custom Arduino-based control device
[r2c2.git] / source / designer / trackproperties.cpp
index 8d21bfc36ad9ba923967f76263b2b89354a94785..c95ad02887f24d3bd99868aa7a6a6a83afe73253 100644 (file)
@@ -1,5 +1,8 @@
 #include <msp/gltk/button.h>
+#include <msp/gltk/column.h>
 #include <msp/gltk/label.h>
+#include <msp/gltk/row.h>
+#include "libr2c2/track.h"
 #include "libr2c2/tracktype.h"
 #include "selection.h"
 #include "trackproperties.h"
@@ -11,42 +14,48 @@ using namespace R2C2;
 TrackProperties::TrackProperties(const Selection &s):
        selection(s)
 {
-       set_size(300, 110);
+       set_layout(new GLtk::Layout);
+       GLtk::Column col(*layout);
 
-       GLtk::Label *lbl;
+       GLtk::Label *lbl1, *lbl2;
 
-       add(*(lbl = new GLtk::Label("Track properties")));
-       lbl->set_geometry(GLtk::Geometry(10, geom.h-30, geom.w-20, 20));
+       add(*(lbl1 = new GLtk::Label("Track properties")));
+       lbl1->set_style("title");
 
-       add(*(lbl = new GLtk::Label("Turnout ID")));
-       lbl->set_geometry(GLtk::Geometry(10, geom.h-65, 70, 20));
-
-       add(*(ent_turnout_id = new GLtk::Entry));
-       ent_turnout_id->set_geometry(GLtk::Geometry(80, geom.h-65, 50, 20));
-
-       add(*(lbl = new GLtk::Label("Sensor ID")));
-       lbl->set_geometry(GLtk::Geometry(150, geom.h-65, 70, 20));
+       {
+               GLtk::Row row(*layout);
+               add(*(lbl1 = new GLtk::Label("Turnout ID")));
+               add(*(ent_turnout_id = new GLtk::Entry));
+               ent_turnout_id->set_edit_size(5, 1);
+       }
 
-       add(*(ent_sensor_id = new GLtk::Entry));
-       ent_sensor_id->set_geometry(GLtk::Geometry(220, geom.h-65, 50, 20));
+       {
+               GLtk::Row row(*layout);
+               add(*(lbl2 = new GLtk::Label("Sensor ID")));
+               layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
+               add(*(ent_sensor_id = new GLtk::Entry));
+               ent_sensor_id->set_edit_size(5, 1);
+       }
 
        GLtk::Button *btn;
 
-       add_button(*(btn = new GLtk::Button("Cncl")), 0);
-       btn->set_geometry(GLtk::Geometry(geom.w-90, 10, 40, 24));
-       btn->set_style("red");
+       {
+               GLtk::Row row(*layout);
+               row.split();
+               add_button(*(btn = new GLtk::Button("Cncl")), 0);
+               btn->set_style("red");
 
-       add_button(*(btn = new GLtk::Button("OK")), 1);
-       btn->set_geometry(GLtk::Geometry(geom.w-50, 10, 40, 24));
-       btn->set_style("green");
+               add_button(*(btn = new GLtk::Button("OK")), 1);
+               btn->set_style("green");
+       }
 
        if(selection.size()==1)
        {
-               if(unsigned tid = selection.get_track()->get_turnout_id())
-                       ent_turnout_id->set_text(lexical_cast(tid));
+               if(unsigned tid = selection.get_object<Track>()->get_turnout_id())
+                       ent_turnout_id->set_text(lexical_cast<string>(tid));
        }
 
-       const set<Track *> &tracks = selection.get_tracks();
+       const set<Track *> &tracks = selection.get_objects<Track>();
        int sensor_id = -1;
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
        {
@@ -60,7 +69,7 @@ TrackProperties::TrackProperties(const Selection &s):
        }
 
        if(sensor_id>=0)
-               ent_sensor_id->set_text(lexical_cast(sensor_id));
+               ent_sensor_id->set_text(lexical_cast<string>(sensor_id));
 }
 
 void TrackProperties::on_response(int code)
@@ -69,7 +78,7 @@ void TrackProperties::on_response(int code)
        {
                if(selection.size()==1)
                {
-                       Track *track = selection.get_track();
+                       Track *track = selection.get_object<Track>();
                        if(track->get_type().is_turnout())
                                track->set_turnout_id(lexical_cast<unsigned>(ent_turnout_id->get_text()));
                }
@@ -78,7 +87,7 @@ void TrackProperties::on_response(int code)
                if(!sensor_id_text.empty())
                {
                        unsigned sensor_id = lexical_cast<unsigned>(sensor_id_text);
-                       const set<Track *> &tracks = selection.get_tracks();
+                       const set<Track *> &tracks = selection.get_objects<Track>();
                        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
                                if(!(*i)->get_type().is_turnout())
                                        (*i)->set_sensor_id(sensor_id);