From 745b5328ebfa0e106058c487200d7a8a1cb17dde Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 27 Sep 2013 20:52:34 +0200 Subject: [PATCH] Moved common actions to a separate file. --- common/tool/action_manager.cpp | 2 +- pcbnew/CMakeLists.txt | 1 + pcbnew/tools/common_actions.cpp | 44 +++++++++++++++++++++++++++++ pcbnew/tools/common_actions.h | 49 +++++++++++++++++++++++++++++++++ pcbnew/tools/move_tool.cpp | 26 ++++++----------- pcbnew/tools/move_tool.h | 9 ------ pcbnew/tools/pcb_tools.cpp | 12 ++++++++ pcbnew/tools/selection_tool.cpp | 14 ++-------- pcbnew/tools/selection_tool.h | 7 ----- 9 files changed, 118 insertions(+), 46 deletions(-) create mode 100644 pcbnew/tools/common_actions.cpp create mode 100644 pcbnew/tools/common_actions.h diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp index 78fbefd2da..5828d03247 100644 --- a/common/tool/action_manager.cpp +++ b/common/tool/action_manager.cpp @@ -66,7 +66,7 @@ void ACTION_MANAGER::UnregisterAction( TOOL_ACTION* aAction ) int ACTION_MANAGER::MakeActionId( const std::string& aActionName ) { - static int currentActionId = 0; + static int currentActionId = 1; return currentActionId++; } diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 06c2960ba9..8026cc4c80 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -228,6 +228,7 @@ set( PCBNEW_CLASS_SRCS tools/bright_box.cpp tools/move_tool.cpp tools/pcb_tools.cpp + tools/common_actions.cpp ) set( PCBNEW_SRCS ${PCBNEW_AUTOROUTER_SRCS} ${PCBNEW_CLASS_SRCS} ${PCBNEW_DIALOGS} ) diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp new file mode 100644 index 0000000000..9605302924 --- /dev/null +++ b/pcbnew/tools/common_actions.cpp @@ -0,0 +1,44 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Maciej Suminski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "common_actions.h" +#include + +// Selection tool actions +TOOL_ACTION COMMON_ACTIONS::selectionActivate( "pcbnew.InteractiveSelection", + AS_GLOBAL, 'S', + "Selection tool", "Allows to select items" ); + +// Move tool actions +TOOL_ACTION COMMON_ACTIONS::moveActivate( "pcbnew.InteractiveMove", + AS_GLOBAL, 'M', + "Move", "Moves the selected item(s)" ); + +TOOL_ACTION COMMON_ACTIONS::rotate( "pcbnew.InteractiveMove.rotate", + AS_CONTEXT, ' ', + "Rotate", "Rotates selected item(s)" ); + +TOOL_ACTION COMMON_ACTIONS::flip( "pcbnew.InteractiveMove.flip", + AS_CONTEXT, 'F', + "Flip", "Flips selected item(s)" ); diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h new file mode 100644 index 0000000000..547b86f814 --- /dev/null +++ b/pcbnew/tools/common_actions.h @@ -0,0 +1,49 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Maciej Suminski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include + +class ACTION_MANAGER; + +/** + * Class COMMON_ACTIONS + * + * Gathers all the actions that are shared by tools. The instance of COMMON_ACTIOSN is created + * inside of ACTION_MANAGER object and registers them. + */ +class COMMON_ACTIONS +{ +public: + /// Activation of the move tool + static TOOL_ACTION moveActivate; + + /// Activation of the selection tool + static TOOL_ACTION selectionActivate; + + /// Rotation of selected objects + static TOOL_ACTION rotate; + + /// Flipping of selected objects + static TOOL_ACTION flip; +}; diff --git a/pcbnew/tools/move_tool.cpp b/pcbnew/tools/move_tool.cpp index 768785f7f3..b21a0a19da 100644 --- a/pcbnew/tools/move_tool.cpp +++ b/pcbnew/tools/move_tool.cpp @@ -25,9 +25,9 @@ #include #include #include -#include #include +#include "common_actions.h" #include "selection_tool.h" #include "move_tool.h" @@ -35,12 +35,7 @@ using namespace KiGfx; using boost::optional; MOVE_TOOL::MOVE_TOOL() : - TOOL_INTERACTIVE( "pcbnew.InteractiveMove" ), m_selectionTool( NULL ), - - // Available actions: - m_activate( m_toolName, AS_GLOBAL, 'M', "Move", "Moves the selected item(s)" ), - m_rotate( m_toolName + ".rotate", AS_CONTEXT, ' ', "Rotate", "Rotates selected item(s)" ), - m_flip( m_toolName + ".flip", AS_CONTEXT, 'F', "Flip", "Flips selected item(s)" ) + TOOL_INTERACTIVE( "pcbnew.InteractiveMove" ), m_selectionTool( NULL ) { } @@ -53,7 +48,7 @@ MOVE_TOOL::~MOVE_TOOL() void MOVE_TOOL::Reset() { // The tool launches upon reception of action event ("pcbnew.InteractiveMove") - Go( &MOVE_TOOL::Main, m_activate.MakeEvent() ); + Go( &MOVE_TOOL::Main, COMMON_ACTIONS::moveActivate.MakeEvent() ); } @@ -66,15 +61,10 @@ bool MOVE_TOOL::Init() { m_selectionTool = static_cast( selectionTool ); - // Activate hot keys - m_toolMgr->RegisterAction( &m_activate ); - m_toolMgr->RegisterAction( &m_rotate ); - m_toolMgr->RegisterAction( &m_flip ); - // Add context menu entries that are displayed when selection tool is active - m_selectionTool->AddMenuItem( m_activate ); - m_selectionTool->AddMenuItem( m_rotate ); - m_selectionTool->AddMenuItem( m_flip ); + m_selectionTool->AddMenuItem( COMMON_ACTIONS::moveActivate ); + m_selectionTool->AddMenuItem( COMMON_ACTIONS::rotate ); + m_selectionTool->AddMenuItem( COMMON_ACTIONS::flip ); } else { @@ -115,12 +105,12 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent ) { VECTOR2D cursorPos = getView()->ToWorld( getViewControls()->GetCursorPosition() ); - if( evt->IsAction( &m_rotate ) ) // got rotation event? + if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) // got rotation event? { m_state.Rotate( cursorPos, 900.0 ); m_items.ViewUpdate( VIEW_ITEM::GEOMETRY ); } - else if( evt->IsAction( &m_flip ) ) // got flip event? + else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) // got flip event? { m_state.Flip( cursorPos ); m_items.ViewUpdate( VIEW_ITEM::GEOMETRY ); diff --git a/pcbnew/tools/move_tool.h b/pcbnew/tools/move_tool.h index d96a7ca023..0074ba70b4 100644 --- a/pcbnew/tools/move_tool.h +++ b/pcbnew/tools/move_tool.h @@ -85,15 +85,6 @@ private: /// VIEW_GROUP that helds currently moved items KiGfx::VIEW_GROUP m_items; - - /// Register hotkey for activation of the move tool - TOOL_ACTION m_activate; - - /// Register hotkey for rotation of selected objects - TOOL_ACTION m_rotate; - - /// Register hotkey for flipping of selected objects - TOOL_ACTION m_flip; }; #endif diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index 0cece9dffd..f2e1885821 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -36,6 +36,7 @@ #include "selection_tool.h" #include "move_tool.h" +#include "common_actions.h" #include void PCB_EDIT_FRAME::setupTools() @@ -45,6 +46,12 @@ void PCB_EDIT_FRAME::setupTools() m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, this ); m_galCanvas->SetEventDispatcher( m_toolDispatcher ); + // Register tool actions + m_toolManager->RegisterAction( &COMMON_ACTIONS::moveActivate ); + m_toolManager->RegisterAction( &COMMON_ACTIONS::selectionActivate ); + m_toolManager->RegisterAction( &COMMON_ACTIONS::rotate ); + m_toolManager->RegisterAction( &COMMON_ACTIONS::flip ); + // Register tools m_toolManager->RegisterTool( new SELECTION_TOOL ); m_toolManager->RegisterTool( new ROUTER_TOOL ); @@ -54,6 +61,11 @@ void PCB_EDIT_FRAME::setupTools() void PCB_EDIT_FRAME::destroyTools() { + m_toolManager->UnregisterAction( &COMMON_ACTIONS::moveActivate ); + m_toolManager->UnregisterAction( &COMMON_ACTIONS::selectionActivate ); + m_toolManager->UnregisterAction( &COMMON_ACTIONS::rotate ); + m_toolManager->UnregisterAction( &COMMON_ACTIONS::flip ); + delete m_toolDispatcher; delete m_toolManager; } diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 995a380417..00854f133f 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -44,13 +44,13 @@ #include "selection_tool.h" #include "selection_area.h" #include "bright_box.h" +#include "common_actions.h" using namespace KiGfx; using boost::optional; SELECTION_TOOL::SELECTION_TOOL() : - TOOL_INTERACTIVE( "pcbnew.InteractiveSelection" ), m_multiple( false ), - m_activate( m_toolName, AS_GLOBAL, 'S', "Selection tool", "Allows to select items" ) + TOOL_INTERACTIVE( "pcbnew.InteractiveSelection" ), m_multiple( false ) { m_selArea = new SELECTION_AREA; } @@ -68,15 +68,7 @@ void SELECTION_TOOL::Reset() m_selectedItems.clear(); // The tool launches upon reception of action event ("pcbnew.InteractiveSelection") - Go( &SELECTION_TOOL::Main, m_activate.MakeEvent() ); -} - - -bool SELECTION_TOOL::Init() -{ - m_toolMgr->RegisterAction( &m_activate ); - - return true; + Go( &SELECTION_TOOL::Main, COMMON_ACTIONS::selectionActivate.MakeEvent() ); } diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 928aa4bf6f..8dc8982bd6 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -30,7 +30,6 @@ #include #include -#include #include class SELECTION_AREA; @@ -58,9 +57,6 @@ public: /// @copydoc TOOL_INTERACTIVE::Reset() void Reset(); - /// @copydoc TOOL_INTERACTIVE::Init() - bool Init(); - /** * Function Main() * @@ -194,9 +190,6 @@ private: /// Flag saying if multiple selection mode is active bool m_multiple; - /// Register hotkey fot activation of the selection tool - TOOL_ACTION m_activate; - /// Right click popup menu CONTEXT_MENU m_menu; };