X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fdesigner.cpp;h=c60ae8e8688b5c318262d71e40a48d48aebacfb4;hb=e9653dffd0026fb3c02c91a4c0feca688a86c721;hp=c6d253e30b275b76d4a62d9f29228ae480ee1815;hpb=e8987fa39c3275a0a293b011e83bccd322e0958a;p=r2c2.git diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index c6d253e..c60ae8e 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -53,6 +53,7 @@ Designer::Designer(int argc, char **argv): window.set_title("Railway Designer"); window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &Designer::exit), 0)); + selection.signal_changed.connect(sigc::mem_fun(this, &Designer::selection_changed)); manipulator.signal_status.connect(sigc::mem_fun(this, &Designer::manipulation_status)); manipulator.signal_done.connect(sigc::mem_fun(this, &Designer::manipulation_done)); measure.signal_changed.connect(sigc::mem_fun(this, &Designer::measure_changed)); @@ -86,6 +87,7 @@ Designer::Designer(int argc, char **argv): pipeline->add_renderable_for_pass(layout_3d->get_scene(), 0); if(base_object) pipeline->add_renderable_for_pass(*base_object, 0); + pipeline->add_renderable_for_pass(layout_3d->get_path_scene(), "unlit"); pipeline->add_renderable_for_pass(layout_3d->get_endpoint_scene(), "unlit"); light.set_position(0, -0.259, 0.966, 0); @@ -129,6 +131,8 @@ Designer::Designer(int argc, char **argv): const list &tracks = layout_3d->get_tracks(); for(list::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) update_track_icon(**i); + + edit_route(0); } Designer::~Designer() @@ -202,12 +206,18 @@ void Designer::set_sensor_id() } } -void Designer::edit_route(Route &r) +void Designer::rename_route() { if(!cur_route) - pipeline->add_renderable_for_pass(layout_3d->get_path_scene(), "unlit"); + return; + + InputDialog *input = new InputDialog(*this, "Route name", cur_route->get_name()); + input->signal_accept.connect(sigc::mem_fun(this, &Designer::route_name_accept)); +} - cur_route = &r; +void Designer::edit_route(Route *r) +{ + cur_route = r; show_route(r); } @@ -218,16 +228,14 @@ void Designer::add_selection_to_route() try { - const set &stracks = selection.get_tracks(); - set tracks(stracks.begin(), stracks.end()); - cur_route->add_tracks(tracks); + cur_route->add_tracks(selection.get_tracks()); } catch(const Exception &e) { IO::print("%s\n", e.what()); } - show_route(*cur_route); + show_route(cur_route); } Point Designer::map_pointer_coords(int x, int y) @@ -283,13 +291,7 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) else if(key==Msp::Input::KEY_PLUS) selection.select_more(); else if(key==Msp::Input::KEY_L && (mod&Input::MOD_SHIFT)) - { - const set &tracks = layout->get_tracks(); - float len = 0; - for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) - len += (*i)->get_type().get_total_length(); - IO::print("Total length: %.1fm\n", len); - } + selection.select_blocks(); else if(key==Msp::Input::KEY_L) selection.select_linked(); else if(key==Msp::Input::KEY_M) @@ -489,8 +491,25 @@ void Designer::update_track_icon(Track3D &track) } else if(unsigned tid = track.get_track().get_turnout_id()) { - overlay->add_graphic(track, "turnout"); - overlay->set_label(track, lexical_cast(tid)); + if(tid<0x800) + { + overlay->add_graphic(track, "turnout"); + overlay->set_label(track, lexical_cast(tid)); + } + } +} + +void Designer::selection_changed() +{ + const set &tracks = selection.get_tracks(); + if(tracks.empty()) + lbl_status->set_text(string()); + else + { + float len = 0; + for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) + len += (*i)->get_type().get_total_length(); + lbl_status->set_text(format("%.2fm of track selected\n", len)); } } @@ -501,8 +520,8 @@ void Designer::manipulation_status(const string &status) void Designer::manipulation_done(bool) { - lbl_status->set_text(string()); mode = SELECT; + selection_changed(); } void Designer::measure_changed() @@ -517,8 +536,8 @@ void Designer::measure_changed() void Designer::measure_done() { - lbl_status->set_text(string()); mode = SELECT; + selection_changed(); } void Designer::turnout_id_accept(const string &text) @@ -542,6 +561,12 @@ void Designer::sensor_id_accept(const string &text) } } +void Designer::route_name_accept(const string &text) +{ + if(cur_route) + cur_route->set_name(text); +} + void Designer::view_all() { Point minp; @@ -587,20 +612,19 @@ string Designer::tooltip(int x, int y) return string(); } -void Designer::show_route(const Route &route) +void Designer::show_route(const Route *route) { const set <racks = layout->get_tracks(); - const set &rtracks = route.get_tracks(); for(set::iterator i=ltracks.begin(); i!=ltracks.end(); ++i) { Track3D &t3d = layout_3d->get_track(**i); - if(rtracks.count(*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); + int path = (tid ? route->get_turnout(tid) : -1); if(path>=0) t3d.get_path().set_path(path); else