Commit 34fbde42 authored by Maciej Suminski's avatar Maciej Suminski

Improved way of translating wxEvent commands to TOOL_ACTIONs.

parent f8f6fd41
......@@ -288,27 +288,10 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent& aEvent )
{
boost::optional<TOOL_EVENT> evt;
switch( aEvent.GetId() )
{
case ID_ZOOM_IN: // toolbar button "Zoom In"
evt = COMMON_ACTIONS::zoomInCenter.MakeEvent();
break;
case ID_ZOOM_OUT: // toolbar button "Zoom In"
evt = COMMON_ACTIONS::zoomOutCenter.MakeEvent();
break;
case ID_ZOOM_PAGE: // toolbar button "Fit on Screen"
evt = COMMON_ACTIONS::zoomFitScreen.MakeEvent();
break;
default:
aEvent.Skip();
break;
}
boost::optional<TOOL_EVENT> evt = COMMON_ACTIONS::TranslateLegacyId( aEvent.GetId() );
if( evt )
m_toolMgr->ProcessEvent( *evt );
else
aEvent.Skip();
}
......@@ -1385,31 +1385,6 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
if( GetToolId() == id )
return;
if( IsGalCanvasActive() )
{
std::string actionName = COMMON_ACTIONS::TranslateLegacyId( id );
if( !actionName.empty() || id == ID_NO_TOOL_SELECTED )
{
const int MAX_TRIALS = 10;
int trials = 0;
// Cancel the current tool
// TODO while sending a lot of cancel events works for sure, it is not the most
// elegant way to cancel a tool, this should be probably done another way
while( m_toolManager->GetCurrentTool()->GetName() != "pcbnew.InteractiveSelection" &&
trials++ < MAX_TRIALS )
{
TOOL_EVENT cancel( TC_ANY, TA_CANCEL_TOOL );
m_toolManager->ProcessEvent( cancel );
}
if( !actionName.empty() )
m_toolManager->RunAction( actionName );
}
}
else
{
INSTALL_UNBUFFERED_DC( dc, m_canvas );
// Stop the current command and deselect the current tool.
......@@ -1505,5 +1480,4 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
break;
}
}
}
......@@ -269,46 +269,55 @@ TOOL_ACTION COMMON_ACTIONS::showHelp( "pcbnew.Control.showHelp",
"", "" );
std::string COMMON_ACTIONS::TranslateLegacyId( int aId )
boost::optional<TOOL_EVENT> COMMON_ACTIONS::TranslateLegacyId( int aId )
{
switch( aId )
{
case ID_PCB_MODULE_BUTT:
return COMMON_ACTIONS::placeModule.GetName();
return COMMON_ACTIONS::placeModule.MakeEvent();
case ID_TRACK_BUTT:
return COMMON_ACTIONS::routerActivate.GetName();
return COMMON_ACTIONS::routerActivate.MakeEvent();
case ID_PCB_ZONES_BUTT:
return COMMON_ACTIONS::drawZone.GetName();
return COMMON_ACTIONS::drawZone.MakeEvent();
case ID_PCB_KEEPOUT_AREA_BUTT:
return COMMON_ACTIONS::drawKeepout.GetName();
return COMMON_ACTIONS::drawKeepout.MakeEvent();
case ID_PCB_ADD_LINE_BUTT:
return COMMON_ACTIONS::drawLine.GetName();
return COMMON_ACTIONS::drawLine.MakeEvent();
case ID_PCB_CIRCLE_BUTT:
return COMMON_ACTIONS::drawCircle.GetName();
return COMMON_ACTIONS::drawCircle.MakeEvent();
case ID_PCB_ARC_BUTT:
return COMMON_ACTIONS::drawArc.GetName();
return COMMON_ACTIONS::drawArc.MakeEvent();
case ID_PCB_ADD_TEXT_BUTT:
return COMMON_ACTIONS::placeTextPcb.GetName();
return COMMON_ACTIONS::placeTextPcb.MakeEvent();
case ID_MODEDIT_TEXT_TOOL:
return COMMON_ACTIONS::placeTextModule.GetName();
return COMMON_ACTIONS::placeTextModule.MakeEvent();
case ID_PCB_DIMENSION_BUTT:
return COMMON_ACTIONS::drawDimension.GetName();
return COMMON_ACTIONS::drawDimension.MakeEvent();
case ID_PCB_MIRE_BUTT:
return COMMON_ACTIONS::placeTarget.GetName();
return COMMON_ACTIONS::placeTarget.MakeEvent();
case ID_PCB_PLACE_GRID_COORD_BUTT:
return COMMON_ACTIONS::gridSetOrigin.GetName();
return COMMON_ACTIONS::gridSetOrigin.MakeEvent();
case ID_ZOOM_IN: // toolbar button "Zoom In"
return COMMON_ACTIONS::zoomInCenter.MakeEvent();
case ID_ZOOM_OUT: // toolbar button "Zoom In"
return COMMON_ACTIONS::zoomOutCenter.MakeEvent();
case ID_ZOOM_PAGE: // toolbar button "Fit on Screen"
return COMMON_ACTIONS::zoomFitScreen.MakeEvent();
}
return "";
return boost::optional<TOOL_EVENT>();
}
......@@ -23,6 +23,9 @@
*/
#include <tool/tool_action.h>
#include <boost/optional.hpp>
class TOOL_EVENT;
/**
* Class COMMON_ACTIONS
......@@ -153,5 +156,5 @@ public:
* @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 );
static boost::optional<TOOL_EVENT> TranslateLegacyId( int aId );
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment