diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp index ce0c403e43..bc1a8be368 100644 --- a/common/tool/action_manager.cpp +++ b/common/tool/action_manager.cpp @@ -60,8 +60,6 @@ void ACTION_MANAGER::RegisterAction( TOOL_ACTION* aAction ) m_actionHotKeys[aAction->m_currentHotKey] = aAction; } - - aAction->setActionMgr( this ); } @@ -71,7 +69,6 @@ void ACTION_MANAGER::UnregisterAction( TOOL_ACTION* aAction ) m_actionIdIndex.erase( aAction->m_id ); // Indicate that the ACTION_MANAGER no longer care about the object - aAction->setActionMgr( NULL ); aAction->setId( -1 ); if( aAction->HasHotKey() ) diff --git a/include/tool/tool_action.h b/include/tool/tool_action.h index 8a3e7c4111..4d91ea982f 100644 --- a/include/tool/tool_action.h +++ b/include/tool/tool_action.h @@ -30,7 +30,7 @@ #include #include -#include +#include /** * Class TOOL_ACTION @@ -50,14 +50,14 @@ public: const std::string& aMenuDesc = std::string( "" ) ) : m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ), m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), - m_menuDescription( aMenuDesc ), m_id( -1 ), m_actionMgr( NULL ) + m_menuDescription( aMenuDesc ), m_id( -1 ) { + TOOL_MANAGER::Instance().RegisterAction( this ); } ~TOOL_ACTION() { - if( m_actionMgr ) - m_actionMgr->UnregisterAction( this ); + TOOL_MANAGER::Instance().UnregisterAction( this ); } bool operator==( const TOOL_ACTION& aRhs ) const @@ -180,12 +180,6 @@ private: m_id = aId; } - /// Assigns ACTION_MANAGER object that handles the TOOL_ACTION. - void setActionMgr( ACTION_MANAGER* aManager ) - { - m_actionMgr = aManager; - } - /// Name of the action (convention is: app.[tool.]action.name) std::string m_name; @@ -210,9 +204,6 @@ private: /// Unique ID for fast matching. Assigned by ACTION_MANAGER. int m_id; - /// Action manager that handles this TOOL_ACTION. - ACTION_MANAGER* m_actionMgr; - /// Origin of the action // const TOOL_BASE* m_origin; diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index c07dcfe94e..04afea3483 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -48,7 +48,13 @@ class wxWindow; class TOOL_MANAGER { public: - TOOL_MANAGER(); + static TOOL_MANAGER& Instance() + { + static TOOL_MANAGER manager; + + return manager; + } + ~TOOL_MANAGER(); /** @@ -211,6 +217,8 @@ public: } private: + TOOL_MANAGER(); + struct TOOL_STATE; typedef std::pair TRANSITION; diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index 139b6f4d3f..4306d67977 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -95,7 +95,7 @@ protected: /// main window. wxAuiToolBar* m_auxiliaryToolBar; - TOOL_MANAGER* m_toolManager; + TOOL_MANAGER& m_toolManager; TOOL_DISPATCHER* m_toolDispatcher; void updateGridSelectBox(); diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 1467773da6..0464d04683 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -131,10 +131,10 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( wxWindow* aParent, ID_DRAWFRAME_TYPE aFrameType, const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize, long aStyle, const wxString & aFrameName) : - EDA_DRAW_FRAME( aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ) + EDA_DRAW_FRAME( aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ), + m_toolManager( TOOL_MANAGER::Instance() ) { m_Pcb = NULL; - m_toolManager = NULL; m_toolDispatcher = NULL; m_DisplayPadFill = true; // How to draw pads diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/board_undo_redo.cpp index a5a3ad314e..5912380180 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/board_undo_redo.cpp @@ -629,7 +629,7 @@ void PCB_EDIT_FRAME::GetBoardFromUndoList( wxCommandEvent& aEvent ) // Inform tools that undo command was issued TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL ); - m_toolManager->ProcessEvent( event ); + m_toolManager.ProcessEvent( event ); /* Get the old list */ PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromUndoList(); @@ -652,7 +652,7 @@ void PCB_EDIT_FRAME::GetBoardFromRedoList( wxCommandEvent& aEvent ) // Inform tools that redo command was issued TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL ); - m_toolManager->ProcessEvent( event ); + m_toolManager.ProcessEvent( event ); /* Get the old list */ PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromRedoList(); diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 91bd9ee4ad..453572ddc5 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -1466,7 +1466,7 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) std::string actionName = COMMON_ACTIONS::TranslateLegacyId( id ); if( !actionName.empty() ) - m_toolManager->RunAction( actionName ); + m_toolManager.RunAction( actionName ); return; } diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index be5896b50e..dee3308be0 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -528,12 +528,9 @@ void PCB_EDIT_FRAME::SetBoard( BOARD* aBoard ) ViewReloadBoard( aBoard ); // update the tool manager with the new board and its view. - if( m_toolManager ) - { - m_toolManager->SetEnvironment( aBoard, GetGalCanvas()->GetView(), - GetGalCanvas()->GetViewControls(), this ); - m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); - } + m_toolManager.SetEnvironment( aBoard, GetGalCanvas()->GetView(), + GetGalCanvas()->GetViewControls(), this ); + m_toolManager.ResetTools( TOOL_BASE::MODEL_RELOAD ); } } @@ -714,9 +711,9 @@ void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable ) // Update potential changes in the ratsnest m_Pcb->GetRatsnest()->Recalculate(); - m_toolManager->SetEnvironment( m_Pcb, GetGalCanvas()->GetView(), + m_toolManager.SetEnvironment( m_Pcb, GetGalCanvas()->GetView(), GetGalCanvas()->GetViewControls(), this ); - m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH ); + m_toolManager.ResetTools( TOOL_BASE::GAL_SWITCH ); } } diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index adb3490de3..88e797b92b 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -44,11 +44,11 @@ using namespace KIGFX; using boost::optional; -static TOOL_ACTION ACT_AutoEndRoute( "AutoEndRoute", AS_CONTEXT, 'F' ); +static TOOL_ACTION ACT_AutoEndRoute( "AutoEndRoute", AS_CONTEXT, 'G' ); static TOOL_ACTION ACT_PlaceVia( "PlaceVia", AS_CONTEXT, 'V' ); -static TOOL_ACTION ACT_OpenRouteOptions( "OpenRouterOptions", AS_CONTEXT, 'E' ); +static TOOL_ACTION ACT_OpenRouteOptions( "OpenRouterOptions", AS_CONTEXT, 'Y' ); static TOOL_ACTION ACT_SwitchPosture( "SwitchPosture", AS_CONTEXT, '/' ); -static TOOL_ACTION ACT_EndTrack( "SwitchPosture", AS_CONTEXT, WXK_END ); +static TOOL_ACTION ACT_EndTrack( "EndTrack", AS_CONTEXT, WXK_END ); ROUTER_TOOL::ROUTER_TOOL() : TOOL_INTERACTIVE( "pcbnew.InteractiveRouter" ) diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index 53683e1a55..28a1b424a3 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -38,54 +38,36 @@ #include "edit_tool.h" #include "drawing_tool.h" #include "point_editor.h" +#include "settings_tool.h" #include "common_actions.h" #include void PCB_EDIT_FRAME::setupTools() { // Create the manager and dispatcher & route draw panel events to the dispatcher - m_toolManager = new TOOL_MANAGER; - m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, this ); + m_toolManager = TOOL_MANAGER::Instance(); + m_toolDispatcher = new TOOL_DISPATCHER( &m_toolManager, this ); GetGalCanvas()->SetEventDispatcher( m_toolDispatcher ); - // Register tool actions - m_toolManager->RegisterAction( &COMMON_ACTIONS::selectionSingle ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::selectionClear ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::editActivate ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::rotate ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::flip ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::remove ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::properties ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::drawLine ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::drawCircle ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::drawArc ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::drawText ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::drawDimension ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::drawZone ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::drawKeepout ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::placeTarget ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::placeModule ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::routerActivate ); - // Register tools - m_toolManager->RegisterTool( new SELECTION_TOOL ); - m_toolManager->RegisterTool( new ROUTER_TOOL ); - m_toolManager->RegisterTool( new EDIT_TOOL ); - m_toolManager->RegisterTool( new DRAWING_TOOL ); - m_toolManager->RegisterTool( new POINT_EDITOR ); + m_toolManager.RegisterTool( new SELECTION_TOOL ); + m_toolManager.RegisterTool( new ROUTER_TOOL ); + m_toolManager.RegisterTool( new EDIT_TOOL ); + m_toolManager.RegisterTool( new DRAWING_TOOL ); + m_toolManager.RegisterTool( new POINT_EDITOR ); + m_toolManager.RegisterTool( new SETTINGS_TOOL ); - m_toolManager->SetEnvironment( NULL, GetGalCanvas()->GetView(), + m_toolManager.SetEnvironment( NULL, GetGalCanvas()->GetView(), GetGalCanvas()->GetViewControls(), this ); - m_toolManager->ResetTools( TOOL_BASE::RUN ); + m_toolManager.ResetTools( TOOL_BASE::RUN ); // Run the selection tool, it is supposed to be always active - m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" ); + m_toolManager.InvokeTool( "pcbnew.InteractiveSelection" ); } void PCB_EDIT_FRAME::destroyTools() { - delete m_toolManager; delete m_toolDispatcher; }