#include "manipulator.h"
#include "measure.h"
#include "movetool.h"
+#include "objectproperties.h"
#include "objectselecttool.h"
#include "rotatetool.h"
#include "routebar.h"
#include "slopetool.h"
#include "svgexporter.h"
#include "trackbar.h"
-#include "trackproperties.h"
#include "zonebar.h"
#include "zoneproperties.h"
}
}
-void Designer::track_properties()
+void Designer::object_properties()
{
use_select_tool();
if(selection.empty())
return;
- TrackProperties *track_prop = new TrackProperties(selection);
- root.add(*track_prop);
- root_layout->set_gravity(*track_prop, 0, 0);
+ ObjectProperties *dlg = new ObjectProperties(selection);
+ root.add(*dlg);
+ root_layout->set_gravity(*dlg, 0, 0);
- track_prop->signal_response.connect(sigc::mem_fun(this, &Designer::track_properties_response));
+ dlg->signal_response.connect(sigc::mem_fun(this, &Designer::object_properties_response));
}
void Designer::extend_track()
else if(key==Msp::Input::KEY_V)
svg_export();
else if(key==Msp::Input::KEY_P)
- track_properties();
+ object_properties();
}
template<typename T>
lbl_status->set_text(status);
}
-void Designer::track_properties_response(int)
+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)
void new_object();
void erase_objects();
- void track_properties();
+ void object_properties();
void extend_track();
void connect_tracks();
void flatten_tracks();
R2C2::Object *pick_object(const R2C2::Vector &);
void update_track_icon(R2C2::Track3D &);
void tool_status(const std::string &);
- void track_properties_response(int);
+ void object_properties_response(int);
void route_name_accept(const std::string &);
void svg_export_accept(const std::string &);
std::string tooltip(int, int);
--- /dev/null
+#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 "objectproperties.h"
+#include "selection.h"
+
+using namespace std;
+using namespace Msp;
+using namespace R2C2;
+
+ObjectProperties::ObjectProperties(const Selection &selection):
+ properties(0),
+ prev_widget(0)
+{
+ set_layout(new GLtk::Layout);
+ GLtk::Column col(*layout);
+
+ GLtk::Label *lbl_title;
+
+ add(*(lbl_title = new GLtk::Label("Object properties")));
+ lbl_title->set_style("title");
+ layout->set_expand(*lbl_title, true, false);
+
+ Object *object = selection.get_object();
+ if(Track *track = dynamic_cast<Track *>(object))
+ {
+ if(track->get_type().is_turnout())
+ {
+ if(selection.size()==1)
+ {
+ lbl_title->set_text("Turnout properties");
+ properties = new TurnoutProperties(*this, *track);
+ }
+ }
+ else
+ {
+ set<Track *> tracks = selection.get_objects<Track>();
+ if(tracks.size()==selection.size())
+ {
+ bool all_linear = true;
+ for(set<Track *>::iterator i=tracks.begin(); (all_linear && i!=tracks.end()); ++i)
+ all_linear = !(*i)->get_type().is_turnout();
+ if(all_linear)
+ {
+ lbl_title->set_text("Track properties");
+ properties = new TrackCircuitProperties(*this, tracks);
+ }
+ }
+ }
+ }
+ else if(selection.size()==1)
+ {
+ if(Signal *signal = dynamic_cast<Signal *>(object))
+ {
+ lbl_title->set_text("Signal properties");
+ properties = new SignalProperties(*this, *signal);
+ }
+ else if(BeamGate *gate = dynamic_cast<BeamGate *>(object))
+ {
+ lbl_title->set_text("Beam gate properties");
+ properties = new BeamGateProperties(*this, *gate);
+ }
+ }
+
+ if(!properties)
+ add(*(new GLtk::Label("No properties available")));
+
+ GLtk::Button *btn;
+
+ {
+ 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_style("green");
+ }
+}
+
+GLtk::Entry *ObjectProperties::add_property(const string &label, const string &value, unsigned size)
+{
+ GLtk::Row row(*layout);
+ add(*(new GLtk::Label(label)));
+
+ GLtk::Entry *entry = new GLtk::Entry(value);
+ add(*entry);
+ if(size)
+ entry->set_edit_size(size, 1);
+
+ if(prev_widget)
+ layout->add_constraint(*entry, GLtk::Layout::ALIGN_LEFT, *prev_widget);
+ prev_widget = entry;
+
+ return entry;
+}
+
+void ObjectProperties::on_response(int code)
+{
+ if(code==1 && properties)
+ properties->apply();
+}
+
+
+ObjectProperties::TurnoutProperties::TurnoutProperties(ObjectProperties &p, Track &t):
+ track(t),
+ ent_address(p.add_property("Turnout address", lexical_cast<string>(track.get_turnout_address()), 5))
+{ }
+
+void ObjectProperties::TurnoutProperties::apply()
+{
+ track.set_turnout_address(lexical_cast<unsigned>(ent_address->get_text()));
+}
+
+
+ObjectProperties::TrackCircuitProperties::TrackCircuitProperties(ObjectProperties &p, const set<Track *> &t):
+ tracks(t),
+ ent_address(p.add_property("Sensor address", string(), 5))
+{
+ int addr = -1;
+ for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
+ {
+ int a = (*i)->get_sensor_address();
+ if(a!=addr)
+ {
+ if(addr==-1)
+ addr = a;
+ else
+ addr = -2;
+ }
+ }
+
+ if(addr>=0)
+ ent_address->set_text(lexical_cast<string>(addr));
+}
+
+void ObjectProperties::TrackCircuitProperties::apply()
+{
+ const string &text = ent_address->get_text();
+ if(!text.empty())
+ {
+ unsigned addr = lexical_cast<unsigned>(text);
+ for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
+ (*i)->set_sensor_address(addr);
+ }
+}
+
+
+ObjectProperties::SignalProperties::SignalProperties(ObjectProperties &p, Signal &s):
+ signal(s),
+ ent_address(p.add_property("Signal address", lexical_cast<string>(signal.get_address()), 5))
+{ }
+
+void ObjectProperties::SignalProperties::apply()
+{
+ signal.set_address(lexical_cast<unsigned>(ent_address->get_text()));
+}
+
+
+ObjectProperties::BeamGateProperties::BeamGateProperties(ObjectProperties &p, BeamGate &g):
+ gate(g),
+ ent_address(p.add_property("Sensor address", lexical_cast<string>(gate.get_address()), 5))
+{ }
+
+void ObjectProperties::BeamGateProperties::apply()
+{
+ gate.set_address(lexical_cast<unsigned>(ent_address->get_text()));
+}
--- /dev/null
+#ifndef TRACKPROPERTIES_H_
+#define TRACKPROPERTIES_H_
+
+#include <msp/gltk/dialog.h>
+#include <msp/gltk/entry.h>
+#include "libr2c2/beamgate.h"
+#include "libr2c2/signal.h"
+#include "libr2c2/track.h"
+
+class Selection;
+
+class ObjectProperties: public Msp::GLtk::Dialog
+{
+private:
+ class Properties
+ {
+ protected:
+ Properties() { }
+ public:
+ virtual ~Properties() { }
+
+ virtual void apply() = 0;
+ };
+
+ class TurnoutProperties: public Properties
+ {
+ private:
+ R2C2::Track &track;
+ Msp::GLtk::Entry *ent_address;
+
+ public:
+ TurnoutProperties(ObjectProperties &, R2C2::Track &);
+
+ virtual void apply();
+ };
+
+ class TrackCircuitProperties: public Properties
+ {
+ private:
+ std::set<R2C2::Track *> tracks;
+ Msp::GLtk::Entry *ent_address;
+
+ public:
+ TrackCircuitProperties(ObjectProperties &, const std::set<R2C2::Track *> &);
+
+ virtual void apply();
+ };
+
+ class SignalProperties: public Properties
+ {
+ private:
+ R2C2::Signal &signal;
+ Msp::GLtk::Entry *ent_address;
+
+ public:
+ SignalProperties(ObjectProperties &, R2C2::Signal &);
+
+ virtual void apply();
+ };
+
+ class BeamGateProperties: public Properties
+ {
+ private:
+ R2C2::BeamGate &gate;
+ Msp::GLtk::Entry *ent_address;
+
+ public:
+ BeamGateProperties(ObjectProperties &, R2C2::BeamGate &);
+
+ virtual void apply();
+ };
+
+ Properties *properties;
+ Msp::GLtk::Widget *prev_widget;
+
+public:
+ ObjectProperties(const Selection &);
+
+private:
+ Msp::GLtk::Entry *add_property(const std::string &, const std::string &, unsigned = 0);
+
+ virtual void on_response(int);
+};
+
+#endif
pnl_content->add(*(btn = new GLtk::Button("Prop")));
btn->set_tooltip("Change properties of selected tracks (P)");
- btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::track_properties));
+ btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::object_properties));
pnl_content->add(*(btn = new GLtk::Button("Xtnd")));
btn->set_tooltip("Extend straight track out of free endpoint (Shift+N)");
+++ /dev/null
-#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"
-
-using namespace std;
-using namespace Msp;
-using namespace R2C2;
-
-TrackProperties::TrackProperties(const Selection &s):
- selection(s)
-{
- set_layout(new GLtk::Layout);
- GLtk::Column col(*layout);
-
- GLtk::Label *lbl1, *lbl2;
-
- add(*(lbl1 = new GLtk::Label("Track properties")));
- lbl1->set_style("title");
-
- {
- GLtk::Row row(*layout);
- add(*(lbl1 = new GLtk::Label("Turnout address")));
- add(*(ent_turnout_addr = new GLtk::Entry));
- ent_turnout_addr->set_edit_size(5, 1);
- }
-
- {
- GLtk::Row row(*layout);
- add(*(lbl2 = new GLtk::Label("Sensor address")));
- layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
- add(*(ent_sensor_addr = new GLtk::Entry));
- ent_sensor_addr->set_edit_size(5, 1);
- }
-
- GLtk::Button *btn;
-
- {
- 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_style("green");
- }
-
- if(selection.size()==1)
- {
- if(unsigned taddr = selection.get_object<Track>()->get_turnout_address())
- ent_turnout_addr->set_text(lexical_cast<string>(taddr));
- }
-
- const set<Track *> &tracks = selection.get_objects<Track>();
- int sensor_addr = -1;
- for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
- {
- if(static_cast<int>((*i)->get_sensor_address())!=sensor_addr)
- {
- if(sensor_addr==-1)
- sensor_addr = (*i)->get_sensor_address();
- else
- sensor_addr = -2;
- }
- }
-
- if(sensor_addr>=0)
- ent_sensor_addr->set_text(lexical_cast<string>(sensor_addr));
-}
-
-void TrackProperties::on_response(int code)
-{
- if(code==1)
- {
- if(selection.size()==1)
- {
- Track *track = selection.get_object<Track>();
- if(track->get_type().is_turnout())
- track->set_turnout_address(lexical_cast<unsigned>(ent_turnout_addr->get_text()));
- }
-
- string sensor_addr_text = ent_sensor_addr->get_text();
- if(!sensor_addr_text.empty())
- {
- unsigned sensor_addr = lexical_cast<unsigned>(sensor_addr_text);
- 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_address(sensor_addr);
- }
- }
-}
+++ /dev/null
-#ifndef TRACKPROPERTIES_H_
-#define TRACKPROPERTIES_H_
-
-#include <msp/gltk/dialog.h>
-#include <msp/gltk/entry.h>
-
-class Selection;
-
-class TrackProperties: public Msp::GLtk::Dialog
-{
-private:
- const Selection &selection;
- Msp::GLtk::Entry *ent_turnout_addr;
- Msp::GLtk::Entry *ent_sensor_addr;
-
-public:
- TrackProperties(const Selection &);
-
-private:
- virtual void on_response(int);
-};
-
-#endif
virtual const SignalType &get_type() const { return type; }
void set_address(unsigned);
+ unsigned get_address() const { return address; }
virtual void set_position(const Vector &);
virtual void set_rotation(const Angle &);
virtual void set_tilt(const Angle &) { }