From c5c83bd271bd7a9dde8099b0e14519da25a7e9cb Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 28 Feb 2014 15:46:05 +0100 Subject: [PATCH] Added TOOL_MANAGER & ACTION_MANAGER::RunAction( const TOOL_ACTION aAction ). Selection clearing is invoked using TOOL_ACTION object rather than its name. --- common/tool/action_manager.cpp | 20 ++++++++++---------- common/tool/tool_manager.cpp | 6 ++++++ include/tool/action_manager.h | 16 ++++++++-------- include/tool/tool_manager.h | 10 +++++++++- pcbnew/edit.cpp | 1 + pcbnew/tools/edit_tool.cpp | 12 ++++++------ pcbnew/tools/selection_tool.cpp | 2 +- 7 files changed, 41 insertions(+), 26 deletions(-) diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp index a00d4d08cc..ce0c403e43 100644 --- a/common/tool/action_manager.cpp +++ b/common/tool/action_manager.cpp @@ -94,12 +94,20 @@ bool ACTION_MANAGER::RunAction( const std::string& aActionName ) const if( it == m_actionNameIndex.end() ) return false; // no action with given name found - runAction( it->second ); + RunAction( it->second ); return true; } +void ACTION_MANAGER::RunAction( const TOOL_ACTION* aAction ) const +{ + TOOL_EVENT event = aAction->MakeEvent(); + + m_toolMgr->ProcessEvent( event ); +} + + bool ACTION_MANAGER::RunHotKey( int aHotKey ) const { std::map::const_iterator it = m_actionHotKeys.find( aHotKey ); @@ -107,7 +115,7 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const if( it == m_actionHotKeys.end() ) return false; // no appropriate action found for the hotkey - runAction( it->second ); + RunAction( it->second ); return true; } @@ -117,11 +125,3 @@ void ACTION_MANAGER::ClearHotKey( int aHotKey ) { m_actionHotKeys.erase( aHotKey ); } - - -void ACTION_MANAGER::runAction( const TOOL_ACTION* aAction ) const -{ - TOOL_EVENT event = aAction->MakeEvent(); - - m_toolMgr->ProcessEvent( event ); -} diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index f36d0cb343..57a98779f6 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -196,6 +196,12 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName ) } +void TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction ) +{ + m_actionMgr->RunAction( &aAction ); +} + + bool TOOL_MANAGER::invokeTool( TOOL_BASE* aTool ) { wxASSERT( aTool != NULL ); diff --git a/include/tool/action_manager.h b/include/tool/action_manager.h index fa66a23eba..b38b329abc 100644 --- a/include/tool/action_manager.h +++ b/include/tool/action_manager.h @@ -81,6 +81,14 @@ public: */ bool RunAction( const std::string& aActionName ) const; + /** + * Function RunAction() + * Prepares an appropriate event and sends it to the destination specified in a TOOL_ACTION + * object. + * @param aAction is the action to be run. + */ + void RunAction( const TOOL_ACTION* aAction ) const; + /** * Function RunHotKey() * Runs an action associated with a hotkey (if there is one available). @@ -108,14 +116,6 @@ private: ///> Map for indexing actions by their hotkeys std::map m_actionHotKeys; - - /** - * Function runAction() - * Prepares an appropriate event and sends it to the destination specified in a TOOL_ACTION - * object. - * @param aAction is the action to be run. - */ - void runAction( const TOOL_ACTION* aAction ) const; }; #endif /* ACTION_MANAGER_H_ */ diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 6e9c18acb0..c07dcfe94e 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -101,13 +101,21 @@ public: /** * Function RunAction() - * Runs the specified action. The common format is "application.ToolName.Action". + * Runs the specified action. The common format for action names is "application.ToolName.Action". * * @param aActionName is the name of action to be invoked. * @return True if the action finished successfully, false otherwise. */ bool RunAction( const std::string& aActionName ); + /** + * Function RunAction() + * Runs the specified action. + * + * @param aAction is the action to be invoked. + */ + void RunAction( const TOOL_ACTION& aAction ); + /** * Function FindTool() * Searches for a tool with given ID. diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index be15d90c64..18e0d0a0bb 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -1458,6 +1458,7 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) if( IsGalCanvasActive() ) { std::string actionName = COMMON_ACTIONS::TranslateLegacyId( id ); + if( !actionName.empty() ) m_toolManager->RunAction( actionName ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index ab79ba8e84..06692910e2 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -172,7 +172,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) } if( unselect ) - m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Clear" ); + m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); RN_DATA* ratsnest = getModel( PCB_T )->GetRatsnest(); ratsnest->ClearSimple(); @@ -230,7 +230,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent ) getModel( PCB_T )->GetRatsnest()->Recalculate(); if( unselect ) - m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Clear" ); + m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); } setTransitions(); @@ -277,7 +277,7 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) getModel( PCB_T )->GetRatsnest()->Recalculate(); if( unselect ) - m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Clear" ); + m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); return 0; } @@ -321,7 +321,7 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent ) getModel( PCB_T )->GetRatsnest()->Recalculate(); if( unselect ) - m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Clear" ); + m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); return 0; } @@ -339,7 +339,7 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent ) PCB_EDIT_FRAME* editFrame = static_cast( m_toolMgr->GetEditFrame() ); // As we are about to remove items, they have to be removed from the selection first - m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Clear" ); + m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear ); // Save them for( unsigned int i = 0; i < selectedItems.GetCount(); ++i ) @@ -461,7 +461,7 @@ bool EDIT_TOOL::makeSelection( const SELECTION_TOOL::SELECTION& aSelection ) if( aSelection.Empty() ) { // Try to find an item that could be modified - m_toolMgr->RunAction( "pcbnew.InteractiveSelection.Single" ); + m_toolMgr->RunAction( COMMON_ACTIONS::selectionSingle ); if( aSelection.Empty() ) { diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 24d00f2439..20f88508df 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -123,7 +123,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) if( m_selection.Empty() ) selectSingle( evt->Position() ); - m_toolMgr->RunAction( "pcbnew.InteractiveEdit.properties" ); + m_toolMgr->RunAction( COMMON_ACTIONS::properties ); } // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them