From a802ca87e0b3176ba223c7bbd9b024a0e3c94e85 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 17 Feb 2014 18:21:00 +0100 Subject: [PATCH] Added TOOL_ACTION for PNS router activation. Most of the GAL tools are activated by corresponding buttons on the right toolbar. Removed menu entry for PNS router (as it is activated as the usual "Add track" tool). --- common/tool/tool_dispatcher.cpp | 18 +--------- pcbnew/edit.cpp | 12 +++++++ pcbnew/menubar_pcbframe.cpp | 7 ---- pcbnew/pcbframe.cpp | 6 ---- pcbnew/pcbnew_id.h | 4 +-- pcbnew/router/router_tool.cpp | 3 +- pcbnew/tools/common_actions.cpp | 63 ++++++++++++++++++++++++++++----- pcbnew/tools/common_actions.h | 12 +++++++ pcbnew/tools/pcb_tools.cpp | 1 + 9 files changed, 83 insertions(+), 43 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 83e9e20d41..b19da891e2 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -32,8 +32,6 @@ #include -#include - #include #include @@ -273,19 +271,5 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) void TOOL_DISPATCHER::DispatchWxCommand( const wxCommandEvent& aEvent ) { - bool activateTool = false; - std::string toolName; - - // fixme: use TOOL_ACTIONs here - switch( aEvent.GetId() ) - { - case ID_PNS_ROUTER_TOOL: - toolName = "pcbnew.InteractiveRouter"; - activateTool = true; - break; - } - - // do nothing if the legacy view is active - if( activateTool && m_editFrame->IsGalCanvasActive() ) - m_toolMgr->InvokeTool( toolName ); + // no events to dispatch currently } diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 7b3ddc2846..6846dda597 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -54,6 +54,9 @@ #include #include +#include +#include + // Handles the selection of command events. void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) { @@ -1451,4 +1454,13 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) break; } + + if( IsGalCanvasActive() ) + { + std::string actionName = COMMON_ACTIONS::TranslateLegacyId( id ); + if( !actionName.empty() ) + m_toolManager->RunAction( actionName ); + + return; + } } diff --git a/pcbnew/menubar_pcbframe.cpp b/pcbnew/menubar_pcbframe.cpp index 3bb2763081..4d88d95ff3 100644 --- a/pcbnew/menubar_pcbframe.cpp +++ b/pcbnew/menubar_pcbframe.cpp @@ -312,13 +312,6 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() _( "Reset text size and width of all module fields to current defaults" ), KiBitmap( reset_text_xpm ) ); - editMenu->AppendSeparator(); - - AddMenuItem( editMenu, ID_PNS_ROUTER_TOOL, - _( "Interactive router" ), - _( "Interactive router drag&drop tool." ), - KiBitmap( tools_xpm ) ); - /** Create View menu **/ wxMenu* viewMenu = new wxMenu; diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 967f8dde9c..f87ae2e959 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -126,12 +126,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) EVT_MENU( wxID_EXIT, PCB_EDIT_FRAME::OnQuit ) // menu Config - - /* Tom's hacks start */ - EVT_MENU ( ID_PNS_ROUTER_TOOL, PCB_EDIT_FRAME::onGenericCommand ) - EVT_TOOL ( ID_PNS_ROUTER_TOOL, PCB_EDIT_FRAME::onGenericCommand ) - /* Tom's hacks end */ - EVT_MENU( ID_PCB_DRAWINGS_WIDTHS_SETUP, PCB_EDIT_FRAME::OnConfigurePcbOptions ) EVT_MENU( ID_PCB_LIB_TABLE_EDIT, PCB_EDIT_FRAME::Process_Config ) EVT_MENU( ID_CONFIG_SAVE, PCB_EDIT_FRAME::Process_Config ) diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 3dad96290a..83a620c256 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -369,9 +369,7 @@ enum pcbnew_ids ID_FOOTPRINT_WIZARD_PAGES_WINDOW, ID_FOOTPRINT_WIZARD_PARAMETERS_WINDOW, ID_FOOTPRINT_WIZARD_SELECT_WIZARD, - ID_FOOTPRINT_WIZARD_EXPORT_TO_BOARD, - - ID_PNS_ROUTER_TOOL + ID_FOOTPRINT_WIZARD_EXPORT_TO_BOARD }; #endif // PCBNEW_ID_H_ diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 6896bb5a15..24073dc6cd 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -31,6 +31,7 @@ #include #include +#include #include @@ -88,7 +89,7 @@ void ROUTER_TOOL::Reset( RESET_REASON aReason ) if( getView() ) m_router->SetView( getView() ); - Go( &ROUTER_TOOL::Main, TOOL_EVENT( TC_COMMAND, TA_ACTION, GetName() ) ); + Go( &ROUTER_TOOL::Main, COMMON_ACTIONS::routerActivate.MakeEvent() ); } diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 339087bdb8..64dc5f760d 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -24,6 +24,7 @@ #include "common_actions.h" #include +#include #include // Selection tool actions @@ -57,38 +58,82 @@ TOOL_ACTION COMMON_ACTIONS::properties( "pcbnew.InteractiveEdit.properties", AS_GLOBAL, 'E', "Properties...", "Displays properties window" ); +// Drawing tool actions TOOL_ACTION COMMON_ACTIONS::drawLine( "pcbnew.InteractiveDrawing.line", - AS_GLOBAL, 'D', + AS_GLOBAL, 0, "Draw a line", "Draw a line" ); TOOL_ACTION COMMON_ACTIONS::drawCircle( "pcbnew.InteractiveDrawing.circle", - AS_GLOBAL, 'S', + AS_GLOBAL, 0, "Draw a circle", "Draw a circle" ); TOOL_ACTION COMMON_ACTIONS::drawArc( "pcbnew.InteractiveDrawing.arc", - AS_GLOBAL, 'A', + AS_GLOBAL, 0, "Draw an arc", "Draw an arc" ); TOOL_ACTION COMMON_ACTIONS::drawText( "pcbnew.InteractiveDrawing.text", - AS_GLOBAL, 'T', + AS_GLOBAL, 0, "Add a text", "Add a text" ); TOOL_ACTION COMMON_ACTIONS::drawDimension( "pcbnew.InteractiveDrawing.dimension", - AS_GLOBAL, 'X', + AS_GLOBAL, 0, "Add a dimension", "Add a dimension" ); TOOL_ACTION COMMON_ACTIONS::drawZone( "pcbnew.InteractiveDrawing.zone", - AS_GLOBAL, 'B', + AS_GLOBAL, 0, "Add a filled zone", "Add a filled zone" ); TOOL_ACTION COMMON_ACTIONS::drawKeepout( "pcbnew.InteractiveDrawing.keepout", - AS_GLOBAL, 'N', + AS_GLOBAL, 0, "Add a keepout area", "Add a keepout area" ); TOOL_ACTION COMMON_ACTIONS::placeTarget( "pcbnew.InteractiveDrawing.placeTarget", - AS_GLOBAL, 'C', + AS_GLOBAL, 0, "Add layer alignment target", "Add layer alignment target" ); TOOL_ACTION COMMON_ACTIONS::placeModule( "pcbnew.InteractiveDrawing.placeModule", - AS_GLOBAL, 'V', + AS_GLOBAL, 0, "Add modules", "Add modules" ); + +TOOL_ACTION COMMON_ACTIONS::routerActivate( "pcbnew.InteractiveRouter", + AS_GLOBAL, 0, + "Run push & shove router", "Run push & shove router" ); + + +std::string COMMON_ACTIONS::TranslateLegacyId( int aId ) +{ + switch( aId ) + { + case ID_PCB_MODULE_BUTT: + return COMMON_ACTIONS::placeModule.GetName(); + + case ID_TRACK_BUTT: + return COMMON_ACTIONS::routerActivate.GetName(); + + case ID_PCB_ZONES_BUTT: + return COMMON_ACTIONS::drawZone.GetName(); + + case ID_PCB_KEEPOUT_AREA_BUTT: + return COMMON_ACTIONS::drawKeepout.GetName(); + + case ID_PCB_ADD_LINE_BUTT: + return COMMON_ACTIONS::drawLine.GetName(); + + case ID_PCB_CIRCLE_BUTT: + return COMMON_ACTIONS::drawCircle.GetName(); + + case ID_PCB_ARC_BUTT: + return COMMON_ACTIONS::drawArc.GetName(); + + case ID_PCB_ADD_TEXT_BUTT: + return COMMON_ACTIONS::drawText.GetName(); + + case ID_PCB_DIMENSION_BUTT: + return COMMON_ACTIONS::drawDimension.GetName(); + + case ID_PCB_MIRE_BUTT: + return COMMON_ACTIONS::placeTarget.GetName(); + } + + return ""; +} diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index fc66573988..5d4908ac59 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -83,4 +83,16 @@ public: /// Activation of the drawing tool (placing a MODULE) static TOOL_ACTION placeModule; + + /// Activation of the Push and Shove router + static TOOL_ACTION routerActivate; + + /** + * Function TranslateLegacyId() + * Translates legacy tool ids to the corresponding TOOL_ACTION name. + * @param aId is legacy tool id to be translated. + * @return std::string is name of the corresponding TOOL_ACTION. It may be empty, if there is + * no corresponding TOOL_ACTION. + */ + static std::string TranslateLegacyId( int aId ); }; diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index 23c899b2fa..9ddfccc34d 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -64,6 +64,7 @@ void PCB_EDIT_FRAME::setupTools() 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 );