]> git.tdb.fi Git - r2c2.git/commitdiff
Display the total length of selected tracks in status bar
authorMikko Rasa <tdb@tdb.fi>
Mon, 25 Oct 2010 11:41:51 +0000 (11:41 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 25 Oct 2010 11:41:51 +0000 (11:41 +0000)
Reuse Shift+L to select blocks

source/designer/designer.cpp
source/designer/designer.h
source/designer/selection.cpp
source/designer/selection.h

index 5ea589bcc22c5c292fb76962a1621c50fbe18dcc..c60ae8e8688b5c318262d71e40a48d48aebacfb4 100644 (file)
@@ -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<Track *> &tracks = layout->get_tracks();
-               float len = 0;
-               for(set<Track *>::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<Track *> &tracks = selection.get_tracks();
+       if(tracks.empty())
+               lbl_status->set_text(string());
+       else
+       {
+               float len = 0;
+               for(set<Track *>::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)
index 5cb0c7849fe834186b2dad44aea14dcb66790711..a43906043da391e681622a11d98b26b7b9fa9240 100644 (file)
@@ -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();
index 5f71e8b68a5b6be56d72cb2d73f878689807e7d2..c6b1e390d97cb8f80f2aad3ea3f0cc60171b2ac0 100644 (file)
@@ -6,6 +6,7 @@ Distributed under the GPL
 */
 
 #include <algorithm>
+#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<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
+       {
+               const set<Track *> &btracks = (*i)->get_block().get_tracks();
+               for(set<Track *>::iterator j=btracks.begin(); j!=btracks.end(); ++j)
+                       if(!tracks.count(*j))
+                       {
+                               tracks.insert(*j);
+                               changed = true;
+                       }
+       }
+
+       if(changed)
+               signal_changed.emit();
+}
index abae6832ccfe2cc75f2777be45bc0be4cc636ba3..24d935458448014411d5a65c32cb5b98bd054fe7 100644 (file)
@@ -30,6 +30,7 @@ public:
        void toggle_track(Marklin::Track *);
        void select_more();
        void select_linked();
+       void select_blocks();
 };
 
 #endif