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,125 +1385,99 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
if( GetToolId() == id )
return;
if( IsGalCanvasActive() )
{
std::string actionName = COMMON_ACTIONS::TranslateLegacyId( id );
INSTALL_UNBUFFERED_DC( dc, m_canvas );
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 );
}
// Stop the current command and deselect the current tool.
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
if( !actionName.empty() )
m_toolManager->RunAction( actionName );
}
}
else
switch( id )
{
INSTALL_UNBUFFERED_DC( dc, m_canvas );
case ID_NO_TOOL_SELECTED:
SetToolID( id, m_canvas->GetDefaultCursor(), wxEmptyString );
break;
// Stop the current command and deselect the current tool.
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
case ID_TRACK_BUTT:
if( g_Drc_On )
SetToolID( id, wxCURSOR_PENCIL, _( "Add tracks" ) );
else
SetToolID( id, wxCURSOR_QUESTION_ARROW, _( "Add tracks" ) );
switch( id )
if( (GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
{
case ID_NO_TOOL_SELECTED:
SetToolID( id, m_canvas->GetDefaultCursor(), wxEmptyString );
break;
case ID_TRACK_BUTT:
if( g_Drc_On )
SetToolID( id, wxCURSOR_PENCIL, _( "Add tracks" ) );
else
SetToolID( id, wxCURSOR_QUESTION_ARROW, _( "Add tracks" ) );
if( (GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
{
Compile_Ratsnest( &dc, true );
}
Compile_Ratsnest( &dc, true );
}
break;
break;
case ID_PCB_MODULE_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add module" ) );
break;
case ID_PCB_MODULE_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add module" ) );
break;
case ID_PCB_ZONES_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add zones" ) );
case ID_PCB_ZONES_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add zones" ) );
if( DisplayOpt.DisplayZonesMode != 0 )
DisplayInfoMessage( this, _( "Warning: zone display is OFF!!!" ) );
if( DisplayOpt.DisplayZonesMode != 0 )
DisplayInfoMessage( this, _( "Warning: zone display is OFF!!!" ) );
if( !GetBoard()->IsHighLightNetON() && (GetBoard()->GetHighLightNetCode() > 0 ) )
HighLight( &dc );
if( !GetBoard()->IsHighLightNetON() && (GetBoard()->GetHighLightNetCode() > 0 ) )
HighLight( &dc );
break;
break;
case ID_PCB_KEEPOUT_AREA_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add keepout" ) );
break;
case ID_PCB_KEEPOUT_AREA_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add keepout" ) );
break;
case ID_PCB_MIRE_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add layer alignment target" ) );
break;
case ID_PCB_MIRE_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add layer alignment target" ) );
break;
case ID_PCB_PLACE_OFFSET_COORD_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Adjust zero" ) );
break;
case ID_PCB_PLACE_OFFSET_COORD_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Adjust zero" ) );
break;
case ID_PCB_PLACE_GRID_COORD_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Adjust grid origin" ) );
break;
case ID_PCB_PLACE_GRID_COORD_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Adjust grid origin" ) );
break;
case ID_PCB_ADD_LINE_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic line" ) );
break;
case ID_PCB_ADD_LINE_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic line" ) );
break;
case ID_PCB_ARC_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic arc" ) );
break;
case ID_PCB_ARC_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic arc" ) );
break;
case ID_PCB_CIRCLE_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic circle" ) );
break;
case ID_PCB_CIRCLE_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add graphic circle" ) );
break;
case ID_PCB_ADD_TEXT_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) );
break;
case ID_PCB_ADD_TEXT_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) );
break;
case ID_COMPONENT_BUTT:
SetToolID( id, wxCURSOR_HAND, _( "Add module" ) );
break;
case ID_COMPONENT_BUTT:
SetToolID( id, wxCURSOR_HAND, _( "Add module" ) );
break;
case ID_PCB_DIMENSION_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add dimension" ) );
break;
case ID_PCB_DIMENSION_BUTT:
SetToolID( id, wxCURSOR_PENCIL, _( "Add dimension" ) );
break;
case ID_PCB_DELETE_ITEM_BUTT:
SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
break;
case ID_PCB_DELETE_ITEM_BUTT:
SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
break;
case ID_PCB_HIGHLIGHT_BUTT:
SetToolID( id, wxCURSOR_HAND, _( "Highlight net" ) );
break;
case ID_PCB_HIGHLIGHT_BUTT:
SetToolID( id, wxCURSOR_HAND, _( "Highlight net" ) );
break;
case ID_PCB_SHOW_1_RATSNEST_BUTT:
SetToolID( id, wxCURSOR_HAND, _( "Select rats nest" ) );
case ID_PCB_SHOW_1_RATSNEST_BUTT:
SetToolID( id, wxCURSOR_HAND, _( "Select rats nest" ) );
if( ( GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK ) == 0 )
Compile_Ratsnest( &dc, true );
if( ( GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK ) == 0 )
Compile_Ratsnest( &dc, true );
break;
}
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