From: Mikko Rasa Date: Sat, 24 Aug 2013 08:37:18 +0000 (+0300) Subject: Refactor Designer::use_tool so tools don't need to take a set of objects X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5e39ffb806f876099fcad5f2f5fe35993090de8a;p=r2c2.git Refactor Designer::use_tool so tools don't need to take a set of objects --- diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 045d9ab..292d5a9 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -227,17 +227,17 @@ void Designer::track_properties() void Designer::extend_track() { - use_tool(); + use_tool_with_selected_objects(); } void Designer::connect_tracks() { - use_tool()->connect(); + use_tool_with_selected_objects()->connect(); } void Designer::flatten_tracks() { - use_tool()->flatten(); + use_tool_with_selected_objects()->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(); + use_tool_with_selected_objects(); else if(key==Msp::Input::KEY_N) new_track(); else if(key==Msp::Input::KEY_G) - use_tool(); + use_tool_with_selected_objects(); else if(key==Msp::Input::KEY_R) - use_tool(); + use_tool_with_selected_objects(); else if(key==Msp::Input::KEY_D) { const set &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(); } 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(); else if(key==Msp::Input::KEY_Z) - use_tool(); + use_tool_with_selected_objects(); 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()->flatten(); + use_tool_with_selected_objects()->flatten(); else if(key==Msp::Input::KEY_E && shift) - use_tool()->even_slope(true); + use_tool_with_selected_objects()->even_slope(true); else if(key==Msp::Input::KEY_E) - use_tool()->even_slope(); + use_tool_with_selected_objects()->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()->connect(); + use_tool_with_selected_objects()->connect(); else if(key==Msp::Input::KEY_V) svg_export(); else if(key==Msp::Input::KEY_P) track_properties(); } +template +T *Designer::use_tool_with_selected_objects() +{ + T *tool = new T(*this, mouse, selection.get_objects()); + use_tool(tool); + return tool; +} + template 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) diff --git a/source/designer/designer.h b/source/designer/designer.h index 3036e14..dadbf06 100644 --- a/source/designer/designer.h +++ b/source/designer/designer.h @@ -107,7 +107,10 @@ private: void tick(); void key_press(unsigned); template + T *use_tool_with_selected_objects(); + template T *use_tool(); + void use_tool(Tool *); void button_press(unsigned); void apply_camera(); void render(); diff --git a/source/designer/measure.cpp b/source/designer/measure.cpp index 2857b0d..e123780 100644 --- a/source/designer/measure.cpp +++ b/source/designer/measure.cpp @@ -10,7 +10,7 @@ using namespace std; using namespace R2C2; using namespace Msp; -Measure::Measure(Designer &d, Input::Mouse &m, const set &): +Measure::Measure(Designer &d, Input::Mouse &m): Tool(d, m), start_pinned(false), mesh((GL::COLOR4_UBYTE, GL::VERTEX3)) diff --git a/source/designer/measure.h b/source/designer/measure.h index 9a270d9..41ea18e 100644 --- a/source/designer/measure.h +++ b/source/designer/measure.h @@ -19,7 +19,7 @@ private: Msp::GL::Mesh mesh; public: - Measure(Designer &, Msp::Input::Mouse &, const std::set &); + Measure(Designer &, Msp::Input::Mouse &); virtual ~Measure(); float get_parallel_distance() const { return par_dist; }