diff --git a/common/tool/common_tools.cpp b/common/tool/common_tools.cpp index bc996bb7c9..08b4c06cf3 100644 --- a/common/tool/common_tools.cpp +++ b/common/tool/common_tools.cpp @@ -206,7 +206,7 @@ int COMMON_TOOLS::ToggleCursor( const TOOL_EVENT& aEvent ) } -void COMMON_TOOLS::SetTransitions() +void COMMON_TOOLS::setTransitions() { Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomIn.MakeEvent() ); Go( &COMMON_TOOLS::ZoomInOut, ACTIONS::zoomOut.MakeEvent() ); diff --git a/common/tool/tool_interactive.cpp b/common/tool/tool_interactive.cpp index 38f78aa6ce..54dcae5e04 100644 --- a/common/tool/tool_interactive.cpp +++ b/common/tool/tool_interactive.cpp @@ -58,6 +58,13 @@ OPT_TOOL_EVENT TOOL_INTERACTIVE::Wait( const TOOL_EVENT_LIST& aEventList ) } +void TOOL_INTERACTIVE::resetTransitions() +{ + m_toolMgr->ClearTransitions( this ); + setTransitions(); +} + + void TOOL_INTERACTIVE::goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions ) { m_toolMgr->ScheduleNextState( this, aState, aConditions ); diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 73a37d4305..bfeee80f34 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -372,7 +372,9 @@ bool TOOL_MANAGER::runTool( TOOL_BASE* aTool ) } aTool->Reset( TOOL_INTERACTIVE::RUN ); - aTool->SetTransitions(); + + if( aTool->GetType() == INTERACTIVE ) + static_cast( aTool )->resetTransitions(); // Add the tool on the front of the processing queue (it gets events first) m_activeTools.push_front( id ); @@ -417,8 +419,11 @@ void TOOL_MANAGER::ResetTools( TOOL_BASE::RESET_REASON aReason ) for( auto& state : m_toolState ) { - state.first->Reset( aReason ); - state.first->SetTransitions(); + TOOL_BASE* tool = state.first; + tool->Reset( aReason ); + + if( tool->GetType() == INTERACTIVE ) + static_cast( tool )->resetTransitions(); } } @@ -476,6 +481,12 @@ void TOOL_MANAGER::ScheduleNextState( TOOL_BASE* aTool, TOOL_STATE_FUNC& aHandle } +void TOOL_MANAGER::ClearTransitions( TOOL_BASE* aTool ) +{ + m_toolState[aTool]->transitions.clear(); +} + + void TOOL_MANAGER::RunMainStack( TOOL_BASE* aTool, std::function aFunc ) { TOOL_STATE* st = m_toolState[aTool]; @@ -705,7 +716,11 @@ TOOL_MANAGER::ID_LIST::iterator TOOL_MANAGER::finishTool( TOOL_STATE* aState ) } // Set transitions to be ready for future TOOL_EVENTs - aState->theTool->SetTransitions(); + TOOL_BASE* tool = aState->theTool; + + if( tool->GetType() == INTERACTIVE ) + static_cast( tool )->resetTransitions(); + m_viewControls->ForceCursorPosition( false ); return it; diff --git a/include/tool/common_tools.h b/include/tool/common_tools.h index d3dd3836b1..6e7740393c 100644 --- a/include/tool/common_tools.h +++ b/include/tool/common_tools.h @@ -60,7 +60,7 @@ public: int GridPreset( const TOOL_EVENT& aEvent ); ///> Sets up handlers for various events. - void SetTransitions() override; + void setTransitions() override; private: ///> Pointer to the currently used edit frame. diff --git a/include/tool/tool_base.h b/include/tool/tool_base.h index c8280be24d..549e95ad9d 100644 --- a/include/tool/tool_base.h +++ b/include/tool/tool_base.h @@ -146,13 +146,6 @@ public: return m_toolMgr; } - /** - * Function SetTransitions() - * This method is meant to be overridden in order to specify handlers for events. It is called - * every time tool is reset or finished. - */ - virtual void SetTransitions() {}; - TOOL_SETTINGS& GetSettings(); protected: diff --git a/include/tool/tool_interactive.h b/include/tool/tool_interactive.h index d1b42387a9..4e23d0160a 100644 --- a/include/tool/tool_interactive.h +++ b/include/tool/tool_interactive.h @@ -114,7 +114,20 @@ protected: const TOOL_EVENT evButtonDown(int aButton = BUT_ANY ); private: + /** + * This method is meant to be overridden in order to specify handlers for events. It is called + * every time tool is reset or finished. + */ + virtual void setTransitions() = 0; + + /** + * Clears the current transition map and restores the default one created by setTransitions(). + */ + void resetTransitions(); + void goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions ); + + friend class TOOL_MANAGER; }; // hide TOOL_MANAGER implementation diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index a664e69169..cdc600f7f0 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -307,6 +307,12 @@ public: void ScheduleNextState( TOOL_BASE* aTool, TOOL_STATE_FUNC& aHandler, const TOOL_EVENT_LIST& aConditions ); + /** + * Clears the state transition map for a tool + * @param aTool is the tool that should have the transition map cleared. + */ + void ClearTransitions( TOOL_BASE* aTool ); + void RunMainStack( TOOL_BASE* aTool, std::function aFunc ); /** diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index f4a7a728b2..e3dd12f3df 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -229,7 +229,7 @@ int LENGTH_TUNER_TOOL::TuneDiffPairSkew( const TOOL_EVENT& aEvent ) } -void LENGTH_TUNER_TOOL::SetTransitions() +void LENGTH_TUNER_TOOL::setTransitions() { Go( &LENGTH_TUNER_TOOL::routerOptionsDialog, ACT_RouterOptions.MakeEvent() ); Go( &LENGTH_TUNER_TOOL::meanderSettingsDialog, ACT_Settings.MakeEvent() ); diff --git a/pcbnew/router/length_tuner_tool.h b/pcbnew/router/length_tuner_tool.h index f7f7ba8205..787d5b0262 100644 --- a/pcbnew/router/length_tuner_tool.h +++ b/pcbnew/router/length_tuner_tool.h @@ -40,7 +40,7 @@ public: int TuneDiffPair( const TOOL_EVENT& aEvent ); int TuneDiffPairSkew( const TOOL_EVENT& aEvent ); - void SetTransitions() override; + void setTransitions() override; private: void performTuning(); diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 45f5ba210f..25664ddafb 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -788,7 +788,7 @@ int ROUTER_TOOL::SettingsDialog( const TOOL_EVENT& aEvent ) } -void ROUTER_TOOL::SetTransitions() +void ROUTER_TOOL::setTransitions() { Go( &ROUTER_TOOL::RouteSingleTrace, PCB_ACTIONS::routerActivateSingle.MakeEvent() ); Go( &ROUTER_TOOL::RouteDiffPair, PCB_ACTIONS::routerActivateDiffPair.MakeEvent() ); diff --git a/pcbnew/router/router_tool.h b/pcbnew/router/router_tool.h index be9b01a863..66a7c83a1f 100644 --- a/pcbnew/router/router_tool.h +++ b/pcbnew/router/router_tool.h @@ -43,7 +43,7 @@ public: int SettingsDialog( const TOOL_EVENT& aEvent ); int CustomTrackWidthDialog( const TOOL_EVENT& aEvent ); - void SetTransitions() override; + void setTransitions() override; private: int mainLoop( PNS::ROUTER_MODE aMode ); diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index e9d7708d05..fc653e3a7a 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -1528,7 +1528,7 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) } -void DRAWING_TOOL::SetTransitions() +void DRAWING_TOOL::setTransitions() { Go( &DRAWING_TOOL::DrawLine, PCB_ACTIONS::drawLine.MakeEvent() ); Go( &DRAWING_TOOL::DrawCircle, PCB_ACTIONS::drawCircle.MakeEvent() ); diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index f27428f418..61dc3942f3 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -177,7 +177,7 @@ public: int SetAnchor( const TOOL_EVENT& aEvent ); ///> Sets up handlers for various events. - void SetTransitions() override; + void setTransitions() override; private: diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index cb9f1e4105..b30ca4beff 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -1124,7 +1124,7 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) } -void EDIT_TOOL::SetTransitions() +void EDIT_TOOL::setTransitions() { Go( &EDIT_TOOL::Main, PCB_ACTIONS::editActivate.MakeEvent() ); Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCw.MakeEvent() ); diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 71ff819fe2..6ce3307826 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -129,7 +129,7 @@ public: int MeasureTool( const TOOL_EVENT& aEvent ); ///> Sets up handlers for various events. - void SetTransitions() override; + void setTransitions() override; private: ///> Selection tool used for obtaining selected items diff --git a/pcbnew/tools/microwave_tool.cpp b/pcbnew/tools/microwave_tool.cpp index cf07507090..582e32aed2 100644 --- a/pcbnew/tools/microwave_tool.cpp +++ b/pcbnew/tools/microwave_tool.cpp @@ -391,7 +391,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent ) } -void MICROWAVE_TOOL::SetTransitions() +void MICROWAVE_TOOL::setTransitions() { Go( &MICROWAVE_TOOL::addMicrowaveFootprint, PCB_ACTIONS::microwaveCreateGap.MakeEvent() ); Go( &MICROWAVE_TOOL::addMicrowaveFootprint, PCB_ACTIONS::microwaveCreateStub.MakeEvent() ); diff --git a/pcbnew/tools/microwave_tool.h b/pcbnew/tools/microwave_tool.h index adad7ad7af..b8a60390b1 100644 --- a/pcbnew/tools/microwave_tool.h +++ b/pcbnew/tools/microwave_tool.h @@ -47,7 +47,7 @@ public: bool Init() override; ///> Bind handlers to corresponding TOOL_ACTIONs - void SetTransitions() override; + void setTransitions() override; private: diff --git a/pcbnew/tools/module_editor_tools.cpp b/pcbnew/tools/module_editor_tools.cpp index 57c5d45cc0..cf1c7a2979 100644 --- a/pcbnew/tools/module_editor_tools.cpp +++ b/pcbnew/tools/module_editor_tools.cpp @@ -512,7 +512,7 @@ int MODULE_EDITOR_TOOLS::ModuleEdgeOutlines( const TOOL_EVENT& aEvent ) } -void MODULE_EDITOR_TOOLS::SetTransitions() +void MODULE_EDITOR_TOOLS::setTransitions() { Go( &MODULE_EDITOR_TOOLS::PlacePad, PCB_ACTIONS::placePad.MakeEvent() ); Go( &MODULE_EDITOR_TOOLS::EnumeratePads, PCB_ACTIONS::enumeratePads.MakeEvent() ); diff --git a/pcbnew/tools/module_editor_tools.h b/pcbnew/tools/module_editor_tools.h index 69ee115b0e..d64208af10 100644 --- a/pcbnew/tools/module_editor_tools.h +++ b/pcbnew/tools/module_editor_tools.h @@ -97,7 +97,7 @@ public: int ModuleEdgeOutlines( const TOOL_EVENT& aEvent ); ///> Sets up handlers for various events. - void SetTransitions() override; + void setTransitions() override; }; diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index efb88a9476..7c67095449 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -384,7 +384,7 @@ int PAD_TOOL::pushPadSettings( const TOOL_EVENT& aEvent ) } -void PAD_TOOL::SetTransitions() +void PAD_TOOL::setTransitions() { Go( &PAD_TOOL::applyPadSettings, PCB_ACTIONS::applyPadSettings.MakeEvent() ); Go( &PAD_TOOL::copyPadSettings, PCB_ACTIONS::copyPadSettings.MakeEvent() ); diff --git a/pcbnew/tools/pad_tool.h b/pcbnew/tools/pad_tool.h index 9f8fd0c30a..62e12a6043 100644 --- a/pcbnew/tools/pad_tool.h +++ b/pcbnew/tools/pad_tool.h @@ -47,7 +47,7 @@ public: bool Init() override; ///> Bind handlers to corresponding TOOL_ACTIONs - void SetTransitions() override; + void setTransitions() override; private: ///> Determine if there are any footprints on the board diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index fcba43de25..e128a1f263 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -1140,7 +1140,7 @@ int PCB_EDITOR_CONTROL::UpdateSelectionRatsnest( const TOOL_EVENT& aEvent ) } -void PCB_EDITOR_CONTROL::SetTransitions() +void PCB_EDITOR_CONTROL::setTransitions() { // Track & via size control Go( &PCB_EDITOR_CONTROL::TrackWidthInc, PCB_ACTIONS::trackWidthInc.MakeEvent() ); diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index 3c734707c2..35e193d6b6 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -109,7 +109,7 @@ public: int ShowLocalRatsnest( const TOOL_EVENT& aEvent ); ///> Sets up handlers for various events. - void SetTransitions() override; + void setTransitions() override; private: ///> Pointer to the currently used edit frame. diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 76a859fadd..d967febe87 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -936,7 +936,7 @@ int PCBNEW_CONTROL::ToBeDone( const TOOL_EVENT& aEvent ) } -void PCBNEW_CONTROL::SetTransitions() +void PCBNEW_CONTROL::setTransitions() { // Display modes Go( &PCBNEW_CONTROL::TrackDisplayMode, PCB_ACTIONS::trackDisplayMode.MakeEvent() ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 946b185c19..11131a28fb 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -84,7 +84,7 @@ public: int ToBeDone( const TOOL_EVENT& aEvent ); ///> Sets up handlers for various events. - void SetTransitions() override; + void setTransitions() override; private: ///> Pointer to the currently used edit frame. diff --git a/pcbnew/tools/picker_tool.cpp b/pcbnew/tools/picker_tool.cpp index 36a72af3c4..332aacfd9a 100644 --- a/pcbnew/tools/picker_tool.cpp +++ b/pcbnew/tools/picker_tool.cpp @@ -89,7 +89,7 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) } -void PICKER_TOOL::SetTransitions() +void PICKER_TOOL::setTransitions() { Go( &PICKER_TOOL::Main, PCB_ACTIONS::pickerTool.MakeEvent() ); } diff --git a/pcbnew/tools/picker_tool.h b/pcbnew/tools/picker_tool.h index 2d459da880..75f55719dc 100644 --- a/pcbnew/tools/picker_tool.h +++ b/pcbnew/tools/picker_tool.h @@ -98,8 +98,8 @@ public: m_clickHandler = aHandler; } - ///> @copydoc TOOL_INTERACTIVE::SetTransitions(); - void SetTransitions() override; + ///> @copydoc TOOL_INTERACTIVE::setTransitions(); + void setTransitions() override; private: // Tool settings. diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp index 7b89d8f456..222da9521f 100644 --- a/pcbnew/tools/placement_tool.cpp +++ b/pcbnew/tools/placement_tool.cpp @@ -357,7 +357,7 @@ int ALIGN_DISTRIBUTE_TOOL::DistributeVertically( const TOOL_EVENT& aEvent ) } -void ALIGN_DISTRIBUTE_TOOL::SetTransitions() +void ALIGN_DISTRIBUTE_TOOL::setTransitions() { Go( &ALIGN_DISTRIBUTE_TOOL::AlignTop, PCB_ACTIONS::alignTop.MakeEvent() ); Go( &ALIGN_DISTRIBUTE_TOOL::AlignBottom, PCB_ACTIONS::alignBottom.MakeEvent() ); diff --git a/pcbnew/tools/placement_tool.h b/pcbnew/tools/placement_tool.h index 1eb8f8d860..3888fe05ba 100644 --- a/pcbnew/tools/placement_tool.h +++ b/pcbnew/tools/placement_tool.h @@ -78,7 +78,7 @@ public: int DistributeVertically( const TOOL_EVENT& aEvent ); ///> Sets up handlers for various events. - void SetTransitions() override; + void setTransitions() override; private: SELECTION_TOOL* m_selectionTool; diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index fa11fa1950..5363efa50a 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -737,7 +737,7 @@ EDIT_POINT POINT_EDITOR::get45DegConstrainer() const } -void POINT_EDITOR::SetTransitions() +void POINT_EDITOR::setTransitions() { Go( &POINT_EDITOR::addCorner, PCB_ACTIONS::pointEditorAddCorner.MakeEvent() ); Go( &POINT_EDITOR::removeCorner, PCB_ACTIONS::pointEditorRemoveCorner.MakeEvent() ); diff --git a/pcbnew/tools/point_editor.h b/pcbnew/tools/point_editor.h index cc3e7bf129..24fb8c0987 100644 --- a/pcbnew/tools/point_editor.h +++ b/pcbnew/tools/point_editor.h @@ -57,7 +57,7 @@ public: int OnSelectionChange( const TOOL_EVENT& aEvent ); ///> Sets up handlers for various events. - void SetTransitions() override; + void setTransitions() override; private: ///> Selection tool used for obtaining selected items diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index c8180b7adf..5f254f1072 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -187,7 +187,7 @@ void POSITION_RELATIVE_TOOL::UpdateAnchor( BOARD_ITEM* aItem ) } -void POSITION_RELATIVE_TOOL::SetTransitions() +void POSITION_RELATIVE_TOOL::setTransitions() { Go( &POSITION_RELATIVE_TOOL::PositionRelative, PCB_ACTIONS::positionRelative.MakeEvent() ); Go( &POSITION_RELATIVE_TOOL::SelectPositionRelativeItem, diff --git a/pcbnew/tools/position_relative_tool.h b/pcbnew/tools/position_relative_tool.h index b843a1857d..0829f7ba5d 100644 --- a/pcbnew/tools/position_relative_tool.h +++ b/pcbnew/tools/position_relative_tool.h @@ -92,7 +92,7 @@ public: void UpdateAnchor( BOARD_ITEM* aItem ); ///> Sets up handlers for various events. - void SetTransitions() override; + void setTransitions() override; private: DIALOG_POSITION_RELATIVE* m_position_relative_dialog; diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index ebf93f569f..717653312b 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -594,7 +594,7 @@ bool SELECTION_TOOL::selectMultiple() } -void SELECTION_TOOL::SetTransitions() +void SELECTION_TOOL::setTransitions() { Go( &SELECTION_TOOL::Main, PCB_ACTIONS::selectionActivate.MakeEvent() ); Go( &SELECTION_TOOL::CursorSelection, PCB_ACTIONS::selectionCursor.MakeEvent() ); diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index dab2f5be6f..994a93031d 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -133,7 +133,7 @@ public: static const TOOL_EVENT ClearedEvent; ///> Sets up handlers for various events. - void SetTransitions() override; + void setTransitions() override; ///> Zooms the screen to center and fit the current selection. void zoomFitSelection( void ); diff --git a/pcbnew/tools/zoom_tool.cpp b/pcbnew/tools/zoom_tool.cpp index 4f332c404e..685a0be0e4 100644 --- a/pcbnew/tools/zoom_tool.cpp +++ b/pcbnew/tools/zoom_tool.cpp @@ -134,7 +134,7 @@ bool ZOOM_TOOL::selectRegion() } -void ZOOM_TOOL::SetTransitions() +void ZOOM_TOOL::setTransitions() { Go( &ZOOM_TOOL::Main, PCB_ACTIONS::zoomTool.MakeEvent() ); } diff --git a/pcbnew/tools/zoom_tool.h b/pcbnew/tools/zoom_tool.h index 30ca304e59..801128ae4b 100644 --- a/pcbnew/tools/zoom_tool.h +++ b/pcbnew/tools/zoom_tool.h @@ -37,8 +37,8 @@ public: /// Main loop int Main( const TOOL_EVENT& aEvent ); - /// @copydoc TOOL_BASE::SetTransitions() - void SetTransitions() override; + /// @copydoc TOOL_BASE::setTransitions() + void setTransitions() override; private: bool selectRegion();