X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fdesigner.cpp;h=5f125fd11c64a0ed44e90321568364a948b30994;hb=7e27b311e33beda1746eb63e0945633f262427f6;hp=d3932338a9edbbc23681f2afd164b7b0e45530ca;hpb=8e3009751ee81e0e5312cae53ee844bdd9e49628;p=r2c2.git diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index d393233..5f125fd 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -1,6 +1,6 @@ /* $Id$ -This file is part of the MSP Märklin suite +This file is part of R²C² Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -26,29 +26,36 @@ Distributed under the GPL #include #include #include -#include "libmarklin/route.h" -#include "libmarklin/tracktype.h" +#include "libr2c2/route.h" +#include "libr2c2/tracktype.h" +#include "libr2c2/zone.h" #include "3d/path.h" #include "designer.h" #include "input.h" +#include "layoutbar.h" #include "manipulator.h" #include "measure.h" +#include "routebar.h" #include "selection.h" #include "svgexporter.h" -#include "toolbar.h" +#include "trackbar.h" +#include "trackproperties.h" +#include "zonebar.h" +#include "zoneproperties.h" using namespace std; -using namespace Marklin; +using namespace R2C2; using namespace Msp; Application::RegApp Designer::reg; Designer::Designer(int argc, char **argv): window(1280, 960), - ui_res("marklin.res"), + ui_res("r2c2.res"), root(ui_res, window), base_object(0), cur_route(0), + cur_zone(0), mode(SELECT), manipulator(*this, root, selection), measure(*this), @@ -124,17 +131,25 @@ Designer::Designer(int argc, char **argv): root.signal_pointer_motion.connect(sigc::mem_fun(this, &Designer::pointer_motion)); root.signal_tooltip.connect(sigc::mem_fun(this, &Designer::tooltip)); - toolbar = new Toolbar(*this); - root.add(*toolbar); - toolbar->set_position(0, window.get_height()-toolbar->get_geometry().h); - toolbar->set_focusable(false); + 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); + if(i!=toolbars.begin()) + (*i)->expand(false); + (*i)->signal_expanded.connect(sigc::hide(sigc::mem_fun(this, &Designer::arrange_toolbars))); + } + arrange_toolbars(); - GLtk::Panel *statusbar = new GLtk::Panel(ui_res); + GLtk::Panel *statusbar = new GLtk::Panel; root.add(*statusbar); statusbar->set_size(window.get_width(), 20); statusbar->set_focusable(false); - lbl_status = new GLtk::Label(ui_res); + lbl_status = new GLtk::Label; statusbar->add(*lbl_status); lbl_status->set_geometry(GLtk::Geometry(20, 2, 300, 16)); @@ -179,51 +194,64 @@ void Designer::quit() void Designer::new_track() { + if(mode!=SELECT) + return; + mode = CATALOGUE; + lbl_status->set_text("Select new track or press Esc to cancel"); } -void Designer::set_turnout_id() +void Designer::erase_tracks() { - Track *track = selection.get_track(); - if(selection.size()==1 && track->get_type().is_turnout()) + if(mode!=SELECT) + return; + + set tracks = selection.get_tracks(); + selection.clear(); + for(set::iterator i=tracks.begin(); i!=tracks.end(); ++i) { - InputDialog *input = new InputDialog(*this, "Turnout ID", lexical_cast(track->get_turnout_id())); - input->signal_accept.connect(sigc::mem_fun(this, &Designer::turnout_id_accept)); + overlay->clear(layout_3d->get_track(**i)); + delete *i; } } -void Designer::set_sensor_id() +void Designer::track_properties() { - const set &tracks = selection.get_tracks(); - bool ok = false; - int id = -1; - for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) - { - if(!(*i)->get_type().is_turnout()) - ok = true; - if(static_cast((*i)->get_sensor_id())!=id) - { - if(id==-1) - id = (*i)->get_sensor_id(); - else - id = -2; - } - } + if(mode!=SELECT || selection.empty()) + return; - if(ok) - { - InputDialog *input = new InputDialog(*this, "Sensor ID", (id>=0 ? lexical_cast(id) : string())); - input->signal_accept.connect(sigc::mem_fun(this, &Designer::sensor_id_accept)); - } + TrackProperties *track_prop = new TrackProperties(selection); + root.add(*track_prop); + const GLtk::Geometry &root_geom = root.get_geometry(); + const GLtk::Geometry &dlg_geom = track_prop->get_geometry(); + track_prop->set_position((root_geom.w-dlg_geom.w)/2, (root_geom.h-dlg_geom.h)/2); + + track_prop->signal_response.connect(sigc::mem_fun(this, &Designer::track_properties_response)); } -void Designer::rename_route() +void Designer::extend_track() { - if(!cur_route) + if(mode!=SELECT) return; - InputDialog *input = new InputDialog(*this, "Route name", cur_route->get_name()); - input->signal_accept.connect(sigc::mem_fun(this, &Designer::route_name_accept)); + if(manipulator.start_extend()) + mode = MANIPULATE; +} + +void Designer::connect_tracks() +{ + if(mode!=SELECT) + return; + + manipulator.connect(); +} + +void Designer::flatten_tracks() +{ + if(mode!=SELECT) + return; + + manipulator.flatten(); } void Designer::svg_export() @@ -235,7 +263,20 @@ void Designer::svg_export() void Designer::edit_route(Route *r) { cur_route = r; - show_route(r); + cur_zone = 0; + if(cur_route) + show_route(*cur_route); + else + clear_paths(); +} + +void Designer::rename_route() +{ + if(mode!=SELECT || !cur_route) + return; + + InputDialog *input = new InputDialog(*this, "Route name", cur_route->get_name()); + input->signal_accept.connect(sigc::mem_fun(this, &Designer::route_name_accept)); } void Designer::add_selection_to_route() @@ -252,7 +293,46 @@ void Designer::add_selection_to_route() lbl_status->set_text(e.what()); } - show_route(cur_route); + show_route(*cur_route); +} + +void Designer::edit_zone(Zone *z) +{ + cur_zone = z; + cur_route = 0; + if(cur_zone) + show_zone(*cur_zone); + else + clear_paths(); +} + +void Designer::zone_properties() +{ + 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_zone->add_tracks(selection.get_tracks()); + } + catch(const Exception &e) + { + lbl_status->set_text(e.what()); + } + + show_zone(*cur_zone); } Point Designer::map_pointer_to_ground(int x, int y) @@ -293,10 +373,7 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) mod = Input::mod_from_sys(mod); if(key==Msp::Input::KEY_N && (mod&Input::MOD_SHIFT)) - { - manipulator.start_extend(); - mode = MANIPULATE; - } + extend_track(); else if(key==Msp::Input::KEY_N) new_track(); else if(key==Msp::Input::KEY_G) @@ -343,16 +420,7 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) selection.clear(); } else if(key==Msp::Input::KEY_X) - { - set tracks = selection.get_tracks(); - selection.clear(); - for(set::iterator i=tracks.begin(); i!=tracks.end(); ++i) - { - overlay->clear(layout_3d->get_track(**i)); - layout->remove_track(**i); - delete *i; - } - } + erase_tracks(); else if(key==Msp::Input::KEY_F && (mod&Input::MOD_SHIFT)) { const set &tracks = selection.get_tracks(); @@ -369,21 +437,24 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) } } else if(key==Msp::Input::KEY_F) - manipulator.flatten(); + flatten_tracks(); else if(key==Msp::Input::KEY_E && (mod&Input::MOD_SHIFT)) manipulator.even_slope(true); else if(key==Msp::Input::KEY_E) manipulator.even_slope(); - else if(key==Msp::Input::KEY_T) - set_turnout_id(); - else if(key==Msp::Input::KEY_S) - set_sensor_id(); 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) - manipulator.connect(); + connect_tracks(); else if(key==Msp::Input::KEY_V) svg_export(); + else if(key==Msp::Input::KEY_P) + track_properties(); } void Designer::button_press(int x, int y, unsigned btn, unsigned mod) @@ -581,25 +652,22 @@ void Designer::measure_done() selection_changed(); } -void Designer::turnout_id_accept(const string &text) +void Designer::arrange_toolbars() { - Track *track = selection.get_track(); - unsigned id = (text.empty() ? 0 : lexical_cast(text)); - track->set_turnout_id(id); - - update_track_icon(layout_3d->get_track(*track)); + unsigned x = 0; + for(vector::iterator i=toolbars.begin(); i!=toolbars.end(); ++i) + { + const GLtk::Geometry &geom = (*i)->get_geometry(); + (*i)->set_position(x, window.get_height()-geom.h); + x += geom.w; + } } -void Designer::sensor_id_accept(const string &text) +void Designer::track_properties_response(int) { const set &tracks = selection.get_tracks(); - unsigned id = (text.empty() ? 0 : lexical_cast(text)); for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) - { - (*i)->set_sensor_id(id); - update_track_icon(layout_3d->get_track(**i)); - } } void Designer::route_name_accept(const string &text) @@ -634,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()); } }