]> git.tdb.fi Git - r2c2.git/commitdiff
Refactor Designer::use_tool so tools don't need to take a set of objects
authorMikko Rasa <tdb@tdb.fi>
Sat, 24 Aug 2013 08:37:18 +0000 (11:37 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 24 Aug 2013 08:37:18 +0000 (11:37 +0300)
source/designer/designer.cpp
source/designer/designer.h
source/designer/measure.cpp
source/designer/measure.h

index 045d9abc1f7139fc9d36646ea26dbf25e20335fb..292d5a9cb12a3e43c6b952b9306d8588644987b2 100644 (file)
@@ -227,17 +227,17 @@ void Designer::track_properties()
 
 void Designer::extend_track()
 {
-       use_tool<ExtendTool>();
+       use_tool_with_selected_objects<ExtendTool>();
 }
 
 void Designer::connect_tracks()
 {
-       use_tool<ExtendTool>()->connect();
+       use_tool_with_selected_objects<ExtendTool>()->connect();
 }
 
 void Designer::flatten_tracks()
 {
-       use_tool<SlopeTool>()->flatten();
+       use_tool_with_selected_objects<SlopeTool>()->flatten();
 }
 
 void Designer::svg_export()
@@ -361,13 +361,13 @@ void Designer::key_press(unsigned key)
        bool shift = keyboard.get_button_state(Input::KEY_SHIFT_L) || keyboard.get_button_state(Input::KEY_SHIFT_R);
 
        if(key==Msp::Input::KEY_N && shift)
-               use_tool<ExtendTool>();
+               use_tool_with_selected_objects<ExtendTool>();
        else if(key==Msp::Input::KEY_N)
                new_track();
        else if(key==Msp::Input::KEY_G)
-               use_tool<MoveTool>();
+               use_tool_with_selected_objects<MoveTool>();
        else if(key==Msp::Input::KEY_R)
-               use_tool<RotateTool>();
+               use_tool_with_selected_objects<RotateTool>();
        else if(key==Msp::Input::KEY_D)
        {
                const set<Object *> &sel_objs = selection.get_objects();
@@ -382,7 +382,7 @@ void Designer::key_press(unsigned key)
 
                selection.replace(new_objs.begin(), new_objs.end());
 
-               cur_tool = new MoveTool(*this, mouse, selection.get_objects());
+               use_tool_with_selected_objects<MoveTool>();
        }
        else if(key==Msp::Input::KEY_W)
                save();
@@ -395,7 +395,7 @@ void Designer::key_press(unsigned key)
        else if(key==Msp::Input::KEY_M)
                use_tool<Measure>();
        else if(key==Msp::Input::KEY_Z)
-               use_tool<ElevateTool>();
+               use_tool_with_selected_objects<ElevateTool>();
        else if(key==Msp::Input::KEY_ESC)
        {
                if(cur_tool)
@@ -426,11 +426,11 @@ void Designer::key_press(unsigned key)
                }
        }
        else if(key==Msp::Input::KEY_F)
-               use_tool<SlopeTool>()->flatten();
+               use_tool_with_selected_objects<SlopeTool>()->flatten();
        else if(key==Msp::Input::KEY_E && shift)
-               use_tool<SlopeTool>()->even_slope(true);
+               use_tool_with_selected_objects<SlopeTool>()->even_slope(true);
        else if(key==Msp::Input::KEY_E)
-               use_tool<SlopeTool>()->even_slope();
+               use_tool_with_selected_objects<SlopeTool>()->even_slope();
        else if(key==Msp::Input::KEY_A)
        {
                if(cur_route)
@@ -439,15 +439,30 @@ void Designer::key_press(unsigned key)
                        add_selection_to_zone();
        }
        else if(key==Msp::Input::KEY_C)
-               use_tool<ExtendTool>()->connect();
+               use_tool_with_selected_objects<ExtendTool>()->connect();
        else if(key==Msp::Input::KEY_V)
                svg_export();
        else if(key==Msp::Input::KEY_P)
                track_properties();
 }
 
+template<typename T>
+T *Designer::use_tool_with_selected_objects()
+{
+       T *tool = new T(*this, mouse, selection.get_objects());
+       use_tool(tool);
+       return tool;
+}
+
 template<typename T>
 T *Designer::use_tool()
+{
+       T *tool = new T(*this, mouse);
+       use_tool(tool);
+       return tool;
+}
+
+void Designer::use_tool(Tool *tool)
 {
        if(cur_tool)
        {
@@ -455,13 +470,10 @@ T *Designer::use_tool()
                cur_tool = 0;
        }
 
-       T *tool = new T(*this, mouse, selection.get_objects());
        cur_tool = tool;
        cur_tool->signal_status.connect(sigc::mem_fun(this, &Designer::manipulation_status));
        manipulation_status(cur_tool->get_status());
        mode = TOOL;
-
-       return tool;
 }
 
 void Designer::button_press(unsigned btn)
index 3036e1485fedb096a1aca6ea5f03b22af97cf024..dadbf068c1b3ed9a6bf3772a71f51220df4b1876 100644 (file)
@@ -107,7 +107,10 @@ private:
        void tick();
        void key_press(unsigned);
        template<typename T>
+       T *use_tool_with_selected_objects();
+       template<typename T>
        T *use_tool();
+       void use_tool(Tool *);
        void button_press(unsigned);
        void apply_camera();
        void render();
index 2857b0d7f631834c177a464a1788d71b787f01b6..e12378061fe35dadefdcfe21da818d0f160f8172 100644 (file)
@@ -10,7 +10,7 @@ using namespace std;
 using namespace R2C2;
 using namespace Msp;
 
-Measure::Measure(Designer &d, Input::Mouse &m, const set<Object *> &):
+Measure::Measure(Designer &d, Input::Mouse &m):
        Tool(d, m),
        start_pinned(false),
        mesh((GL::COLOR4_UBYTE, GL::VERTEX3))
index 9a270d94bea3cfeedb038c6cd2075d315206fd47..41ea18ee91135f237e809c8fdb27c90d66ad3146 100644 (file)
@@ -19,7 +19,7 @@ private:
        Msp::GL::Mesh mesh;
 
 public:
-       Measure(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
+       Measure(Designer &, Msp::Input::Mouse &);
        virtual ~Measure();
 
        float get_parallel_distance() const { return par_dist; }