]> git.tdb.fi Git - r2c2.git/blobdiff - source/designer/designer.cpp
Clean up old clutter from Designer
[r2c2.git] / source / designer / designer.cpp
index 045d9abc1f7139fc9d36646ea26dbf25e20335fb..7c100db390172cdbfe76cd90e84844725d3b40c8 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,17 +395,12 @@ 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)
-               {
-                       delete cur_tool;
-                       cur_tool = 0;
-               }
-               else if(mode==CATALOGUE)
+               if(mode==CATALOGUE)
                        mode = SELECT;
-               else
+               else if(mode==SELECT)
                        selection.clear();
        }
        else if(key==Msp::Input::KEY_X)
@@ -426,11 +421,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 +434,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, keyboard, mouse, selection.get_objects());
+       use_tool(tool);
+       return tool;
+}
+
 template<typename T>
 T *Designer::use_tool()
+{
+       T *tool = new T(*this, keyboard, mouse);
+       use_tool(tool);
+       return tool;
+}
+
+void Designer::use_tool(Tool *tool)
 {
        if(cur_tool)
        {
@@ -455,13 +465,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());
+       cur_tool->signal_status.connect(sigc::mem_fun(this, &Designer::tool_status));
+       tool_status(cur_tool->get_status());
        mode = TOOL;
-
-       return tool;
 }
 
 void Designer::button_press(unsigned btn)
@@ -560,17 +567,11 @@ void Designer::selection_changed()
        }
 }
 
-void Designer::manipulation_status(const string &status)
+void Designer::tool_status(const string &status)
 {
        lbl_status->set_text(status);
 }
 
-void Designer::measure_done()
-{
-       mode = SELECT;
-       selection_changed();
-}
-
 void Designer::track_properties_response(int)
 {
        const set<Track *> &tracks = selection.get_objects<Track>();