From: Mikko Rasa Date: Mon, 25 Oct 2010 11:41:51 +0000 (+0000) Subject: Display the total length of selected tracks in status bar X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e9653dffd0026fb3c02c91a4c0feca688a86c721;p=r2c2.git Display the total length of selected tracks in status bar Reuse Shift+L to select blocks --- diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 5ea589b..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)); @@ -290,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) @@ -504,6 +499,20 @@ void Designer::update_track_icon(Track3D &track) } } +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)); + } +} + void Designer::manipulation_status(const string &status) { lbl_status->set_text(status); @@ -511,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() @@ -527,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) diff --git a/source/designer/designer.h b/source/designer/designer.h index 5cb0c78..a439060 100644 --- a/source/designer/designer.h +++ b/source/designer/designer.h @@ -107,6 +107,7 @@ private: void render(); Marklin::Track3D *pick_track(int, int); void update_track_icon(Marklin::Track3D &); + void selection_changed(); void manipulation_status(const std::string &); void manipulation_done(bool); void measure_changed(); diff --git a/source/designer/selection.cpp b/source/designer/selection.cpp index 5f71e8b..c6b1e39 100644 --- a/source/designer/selection.cpp +++ b/source/designer/selection.cpp @@ -6,6 +6,7 @@ Distributed under the GPL */ #include +#include "libmarklin/block.h" #include "selection.h" using namespace std; @@ -94,3 +95,21 @@ void Selection::select_linked() if(changed) signal_changed.emit(); } + +void Selection::select_blocks() +{ + bool changed = false; + for(set::iterator i=tracks.begin(); i!=tracks.end(); ++i) + { + const set &btracks = (*i)->get_block().get_tracks(); + for(set::iterator j=btracks.begin(); j!=btracks.end(); ++j) + if(!tracks.count(*j)) + { + tracks.insert(*j); + changed = true; + } + } + + if(changed) + signal_changed.emit(); +} diff --git a/source/designer/selection.h b/source/designer/selection.h index abae683..24d9354 100644 --- a/source/designer/selection.h +++ b/source/designer/selection.h @@ -30,6 +30,7 @@ public: void toggle_track(Marklin::Track *); void select_more(); void select_linked(); + void select_blocks(); }; #endif