X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fdesigner%2Fdesigner.cpp;h=5f125fd11c64a0ed44e90321568364a948b30994;hb=7e27b311e33beda1746eb63e0945633f262427f6;hp=86fc3494a424508b20ad93de6c685db00cc8ecbd;hpb=2abb7008a1e2b93b77742693becf6fe0b8567d6e;p=r2c2.git diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 86fc349..5f125fd 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -28,6 +28,7 @@ Distributed under the GPL #include #include "libr2c2/route.h" #include "libr2c2/tracktype.h" +#include "libr2c2/zone.h" #include "3d/path.h" #include "designer.h" #include "input.h" @@ -39,6 +40,8 @@ Distributed under the GPL #include "svgexporter.h" #include "trackbar.h" #include "trackproperties.h" +#include "zonebar.h" +#include "zoneproperties.h" using namespace std; using namespace R2C2; @@ -52,6 +55,7 @@ Designer::Designer(int argc, char **argv): root(ui_res, window), base_object(0), cur_route(0), + cur_zone(0), mode(SELECT), manipulator(*this, root, selection), measure(*this), @@ -130,6 +134,7 @@ Designer::Designer(int argc, char **argv): toolbars.push_back(new Layoutbar(*this)); toolbars.push_back(new Trackbar(*this)); toolbars.push_back(new Routebar(*this)); + toolbars.push_back(new Zonebar(*this)); for(vector::iterator i=toolbars.begin(); i!=toolbars.end(); ++i) { root.add(**i); @@ -249,6 +254,22 @@ void Designer::flatten_tracks() manipulator.flatten(); } +void Designer::svg_export() +{ + InputDialog *input = new InputDialog(*this, "SVG export", FS::basepart(filename)+".svg"); + input->signal_accept.connect(sigc::mem_fun(this, &Designer::svg_export_accept)); +} + +void Designer::edit_route(Route *r) +{ + cur_route = r; + cur_zone = 0; + if(cur_route) + show_route(*cur_route); + else + clear_paths(); +} + void Designer::rename_route() { if(mode!=SELECT || !cur_route) @@ -258,33 +279,60 @@ void Designer::rename_route() input->signal_accept.connect(sigc::mem_fun(this, &Designer::route_name_accept)); } -void Designer::svg_export() +void Designer::add_selection_to_route() { - InputDialog *input = new InputDialog(*this, "SVG export", FS::basepart(filename)+".svg"); - input->signal_accept.connect(sigc::mem_fun(this, &Designer::svg_export_accept)); + if(!cur_route) + return; + + try + { + cur_route->add_tracks(selection.get_tracks()); + } + catch(const Exception &e) + { + lbl_status->set_text(e.what()); + } + + show_route(*cur_route); } -void Designer::edit_route(Route *r) +void Designer::edit_zone(Zone *z) { - cur_route = r; - show_route(r); + cur_zone = z; + cur_route = 0; + if(cur_zone) + show_zone(*cur_zone); + else + clear_paths(); } -void Designer::add_selection_to_route() +void Designer::zone_properties() { - if(!cur_route) + if(!cur_zone) + return; + + ZoneProperties *zone_prop = new ZoneProperties(*cur_zone); + root.add(*zone_prop); + const GLtk::Geometry &root_geom = root.get_geometry(); + const GLtk::Geometry &dlg_geom = zone_prop->get_geometry(); + zone_prop->set_position((root_geom.w-dlg_geom.w)/2, (root_geom.h-dlg_geom.h)/2); +} + +void Designer::add_selection_to_zone() +{ + if(!cur_zone) return; try { - cur_route->add_tracks(selection.get_tracks()); + cur_zone->add_tracks(selection.get_tracks()); } catch(const Exception &e) { lbl_status->set_text(e.what()); } - show_route(cur_route); + show_zone(*cur_zone); } Point Designer::map_pointer_to_ground(int x, int y) @@ -395,7 +443,12 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) else if(key==Msp::Input::KEY_E) manipulator.even_slope(); else if(key==Msp::Input::KEY_A) - add_selection_to_route(); + { + if(cur_route) + add_selection_to_route(); + else if(cur_zone) + add_selection_to_zone(); + } else if(key==Msp::Input::KEY_C) connect_tracks(); else if(key==Msp::Input::KEY_V) @@ -649,28 +702,44 @@ string Designer::tooltip(int x, int y) return string(); } -void Designer::show_route(const Route *route) +void Designer::clear_paths() { const set <racks = layout->get_tracks(); for(set::iterator i=ltracks.begin(); i!=ltracks.end(); ++i) { Track3D &t3d = layout_3d->get_track(**i); - if(route && route->has_track(**i)) - { - t3d.get_path().set_color(GL::Color(0.5, 0.8, 1.0)); - if((*i)->get_type().is_turnout()) - { - unsigned tid = (*i)->get_turnout_id(); - int path = (tid ? route->get_turnout(tid) : -1); - if(path>=0) - t3d.get_path().set_path(path); - else - t3d.get_path().set_mask((*i)->get_type().get_paths()); - } - else - t3d.get_path().set_path(0); - } + t3d.get_path().set_mask(0); + } +} + +void Designer::show_route(const Route &route) +{ + clear_paths(); + + const set &rtracks = route.get_tracks(); + for(set::iterator i=rtracks.begin(); i!=rtracks.end(); ++i) + { + Track3D &t3d = layout_3d->get_track(**i); + t3d.get_path().set_color(GL::Color(0.5, 0.8, 1.0)); + int path = -1; + if(unsigned tid = (*i)->get_turnout_id()) + path = route.get_turnout(tid); + if(path>=0) + t3d.get_path().set_path(path); else - t3d.get_path().set_mask(0); + t3d.get_path().set_mask((*i)->get_type().get_paths()); + } +} + +void Designer::show_zone(const Zone &zone) +{ + clear_paths(); + + const Zone::TrackSet &ztracks = zone.get_tracks(); + for(Zone::TrackSet::const_iterator i=ztracks.begin(); i!=ztracks.end(); ++i) + { + Track3D &t3d = layout_3d->get_track(**i); + t3d.get_path().set_color(GL::Color(0.8, 1.0, 0.5)); + t3d.get_path().set_mask((*i)->get_type().get_paths()); } }