From 93046076241575c70ec09086480d65de3d786533 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Wed, 14 Sep 2022 13:31:56 -0400 Subject: [PATCH] TOOL_EVENT: make command string non-optional We're getting segfaults in places where this isn't checked. Also, add some asserts so we can catch bad tool push/pop. Removes all uses of GetCommandStr() and makes it private. --- common/tool/picker_tool.cpp | 5 +- common/tool/tool_event.cpp | 21 +++--- common/tool/tool_manager.cpp | 7 +- common/tool/tools_holder.cpp | 14 +++- common/tool/zoom_tool.cpp | 9 +-- eeschema/tools/sch_drawing_tools.cpp | 73 ++++++++----------- eeschema/tools/sch_edit_tool.cpp | 3 +- eeschema/tools/sch_editor_control.cpp | 9 +-- eeschema/tools/sch_line_wire_bus_tool.cpp | 19 ++--- eeschema/tools/sch_line_wire_bus_tool.h | 2 +- eeschema/tools/sch_move_tool.cpp | 10 +-- .../tools/symbol_editor_drawing_tools.cpp | 31 ++++---- eeschema/tools/symbol_editor_edit_tool.cpp | 3 +- eeschema/tools/symbol_editor_move_tool.cpp | 8 +- gerbview/tools/gerbview_inspection_tool.cpp | 7 +- include/tool/tool_event.h | 16 ++-- include/tool/tools_holder.h | 16 +++- pagelayout_editor/tools/pl_drawing_tools.cpp | 12 ++- pagelayout_editor/tools/pl_edit_tool.cpp | 11 ++- pcbnew/microwave/microwave_tool.cpp | 10 +-- pcbnew/router/length_tuner_tool.cpp | 5 +- pcbnew/router/router_tool.cpp | 14 ++-- pcbnew/tools/board_editor_control.cpp | 10 +-- pcbnew/tools/board_inspection_tool.cpp | 3 +- pcbnew/tools/drawing_stackup_table_tool.cpp | 11 ++- pcbnew/tools/drawing_tool.cpp | 71 ++++++++---------- pcbnew/tools/drawing_tool.h | 10 ++- pcbnew/tools/edit_tool.cpp | 19 ++--- pcbnew/tools/edit_tool.h | 2 +- pcbnew/tools/edit_tool_move_fct.cpp | 14 ++-- pcbnew/tools/pad_tool.cpp | 11 ++- pcbnew/tools/pcb_control.cpp | 6 +- pcbnew/tools/pcb_picker_tool.cpp | 12 +-- pcbnew/tools/pcb_tool_base.cpp | 2 +- pcbnew/tools/pcb_tool_base.h | 2 +- pcbnew/tools/pcb_viewer_tools.cpp | 7 +- 36 files changed, 221 insertions(+), 264 deletions(-) diff --git a/common/tool/picker_tool.cpp b/common/tool/picker_tool.cpp index 1549e92d25..afa5abe9aa 100644 --- a/common/tool/picker_tool.cpp +++ b/common/tool/picker_tool.cpp @@ -77,8 +77,7 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) KIGFX::VIEW_CONTROLS* controls = getViewControls(); int finalize_state = WAIT_CANCEL; - std::string tool = *aEvent.Parameter(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); Activate(); setControls(); @@ -194,7 +193,7 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) reset(); controls->ForceCursorPosition( false ); - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); return 0; } diff --git a/common/tool/tool_event.cpp b/common/tool/tool_event.cpp index c19405a526..df6f411df3 100644 --- a/common/tool/tool_event.cpp +++ b/common/tool/tool_event.cpp @@ -180,8 +180,7 @@ const std::string TOOL_EVENT::Format() const ev += tmp; } - if( m_commandStr ) - ev += "cmd-str: " + ( *m_commandStr ); + ev += "cmd-str: " + m_commandStr; return ev; } @@ -212,9 +211,9 @@ bool TOOL_EVENT::IsDblClick( int aButtonMask ) const bool TOOL_EVENT::IsCancelInteractive() const { - return ( ( m_commandStr && *m_commandStr == ACTIONS::cancelInteractive.GetName() ) - || ( m_commandId && *m_commandId == ACTIONS::cancelInteractive.GetId() ) - || ( m_actions == TA_CANCEL_TOOL ) ); + return ( ( m_commandStr == ACTIONS::cancelInteractive.GetName() ) + || ( m_commandId && *m_commandId == ACTIONS::cancelInteractive.GetId() ) + || ( m_actions == TA_CANCEL_TOOL ) ); } @@ -229,26 +228,24 @@ bool TOOL_EVENT::IsSelectionEvent() const bool TOOL_EVENT::IsPointEditor() const { - return ( ( m_commandStr && m_commandStr->find( "PointEditor" ) != GetCommandStr()->npos ) - || ( m_commandId && *m_commandId == ACTIONS::activatePointEditor.GetId() ) ); + return ( ( m_commandStr.find( "PointEditor" ) != getCommandStr().npos ) + || ( m_commandId && *m_commandId == ACTIONS::activatePointEditor.GetId() ) ); } bool TOOL_EVENT::IsMoveTool() const { - return ( m_commandStr - && m_commandStr->find( "InteractiveMove" ) != GetCommandStr()->npos ); + return ( m_commandStr.find( "InteractiveMove" ) != getCommandStr().npos ); } bool TOOL_EVENT::IsEditorTool() const { - return ( m_commandStr - && m_commandStr->find( "InteractiveEdit" ) != GetCommandStr()->npos ); + return ( m_commandStr.find( "InteractiveEdit" ) != getCommandStr().npos ); } bool TOOL_EVENT::IsSimulator() const { - return ( m_commandStr && m_commandStr->find( "Simulation" ) != GetCommandStr()->npos ); + return ( m_commandStr.find( "Simulation" ) != getCommandStr().npos ); } diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index a38d2e5ef2..5df273998c 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -829,7 +829,7 @@ bool TOOL_MANAGER::dispatchActivation( const TOOL_EVENT& aEvent ) if( aEvent.IsActivate() ) { - auto tool = m_toolNameIndex.find( *aEvent.GetCommandStr() ); + auto tool = m_toolNameIndex.find( aEvent.getCommandStr() ); if( tool != m_toolNameIndex.end() ) { @@ -1153,9 +1153,8 @@ bool TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent ) if( GetToolHolder() && !GetToolHolder()->GetDoImmediateActions() ) { // An tool-selection-event has no position - if( mod_event.GetCommandStr() - && *mod_event.GetCommandStr() != GetToolHolder()->CurrentToolName() - && !mod_event.ForceImmediate() ) + if( mod_event.getCommandStr() != GetToolHolder()->CurrentToolName() + && !mod_event.ForceImmediate() ) { mod_event.SetHasPosition( false ); } diff --git a/common/tool/tools_holder.cpp b/common/tool/tools_holder.cpp index d32f0f4107..5a5a9d378f 100644 --- a/common/tool/tools_holder.cpp +++ b/common/tool/tools_holder.cpp @@ -41,8 +41,12 @@ TOOLS_HOLDER::TOOLS_HOLDER() : // TODO: Implement an RAII mechanism for the stack PushTool/PopTool pairs -void TOOLS_HOLDER::PushTool( const std::string& actionName ) +void TOOLS_HOLDER::PushTool( const TOOL_EVENT& aEvent ) { + const std::string& actionName = aEvent.getCommandStr(); + + wxASSERT_MSG( !actionName.empty(), "Pushed Empty Tool Name!" ); + m_toolStack.push_back( actionName ); // Human cognitive stacking is very shallow; deeper tool stacks just get annoying @@ -58,8 +62,12 @@ void TOOLS_HOLDER::PushTool( const std::string& actionName ) } -void TOOLS_HOLDER::PopTool( const std::string& actionName ) +void TOOLS_HOLDER::PopTool( const TOOL_EVENT& aEvent ) { + const std::string& actionName = aEvent.getCommandStr(); + + wxASSERT_MSG( !aEvent.getCommandStr().empty(), "Popped Empty Tool Name!" ); + // Push/pop events can get out of order (such as when they're generated by the Simulator // frame but not processed until the mouse is back in the Schematic frame), so make sure // we're popping the right stack frame. @@ -94,6 +102,8 @@ void TOOLS_HOLDER::PopTool( const std::string& actionName ) return; } } + + wxASSERT_MSG( false, "Popped a Tool Not on the Tool Stack!" ); } diff --git a/common/tool/zoom_tool.cpp b/common/tool/zoom_tool.cpp index e905fc6d34..50bee386e8 100644 --- a/common/tool/zoom_tool.cpp +++ b/common/tool/zoom_tool.cpp @@ -60,12 +60,7 @@ void ZOOM_TOOL::Reset( RESET_REASON aReason ) int ZOOM_TOOL::Main( const TOOL_EVENT& aEvent ) { - std::string tool; - - if( aEvent.GetCommandStr() ) - tool = *aEvent.GetCommandStr(); - - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -102,7 +97,7 @@ int ZOOM_TOOL::Main( const TOOL_EVENT& aEvent ) // Exit zoom tool m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); return 0; } diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index aece094003..af9abf7881 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -144,8 +144,7 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) wxFAIL_MSG( "PlaceSymbol(): unexpected request" ); } - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto addSymbol = [&]( SCH_SYMBOL* aSymbol ) @@ -250,9 +249,8 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() ); // The tool hotkey is interpreted as a click when drawing - bool isSyntheticClick = symbol - && evt->IsActivate() && evt->HasPosition() - && evt->GetCommandStr() == tool; + bool isSyntheticClick = symbol && evt->IsActivate() && evt->HasPosition() + && evt->Matches( aEvent ); if( evt->IsCancelInteractive() ) { @@ -264,7 +262,7 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -291,7 +289,7 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -463,8 +461,7 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent ) m_view->AddToPreview( image->Clone() ); } - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -514,9 +511,8 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent ) VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() ); // The tool hotkey is interpreted as a click when drawing - bool isSyntheticClick = image - && evt->IsActivate() && evt->HasPosition() - && evt->GetCommandStr() == tool; + bool isSyntheticClick = image && evt->IsActivate() && evt->HasPosition() + && evt->Matches( aEvent ); if( evt->IsCancelInteractive() ) { @@ -528,13 +524,13 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } if( immediateMode ) { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -561,7 +557,7 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -629,7 +625,7 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent ) if( immediateMode ) { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -751,8 +747,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) aEvent.Position() : controls->GetMousePosition() ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -790,7 +785,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) if( evt->IsCancelInteractive() ) { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } else if( evt->IsActivate() ) @@ -802,7 +797,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -841,7 +836,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) if( evt->IsDblClick( BUT_LEFT ) || type == SCH_SHEET_PIN_T ) // Finish tool. { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -1135,8 +1130,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() { @@ -1208,9 +1202,8 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) controls->ForceCursorPosition( true, cursorPos ); // The tool hotkey is interpreted as a click when drawing - bool isSyntheticClick = item - && evt->IsActivate() && evt->HasPosition() - && evt->GetCommandStr() == tool; + bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() + && evt->Matches( aEvent ); if( evt->IsCancelInteractive() ) { @@ -1222,7 +1215,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -1252,7 +1245,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -1489,8 +1482,7 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -1526,9 +1518,8 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() ); // The tool hotkey is interpreted as a click when drawing - bool isSyntheticClick = item - && evt->IsActivate() && evt->HasPosition() - && evt->GetCommandStr() == tool; + bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() + && evt->Matches( aEvent ); if( evt->IsCancelInteractive() ) { @@ -1538,7 +1529,7 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -1565,7 +1556,7 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -1698,8 +1689,7 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -1735,9 +1725,8 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() ); // The tool hotkey is interpreted as a click when drawing - bool isSyntheticClick = sheet - && evt->IsActivate() && evt->HasPosition() - && evt->GetCommandStr() == tool; + bool isSyntheticClick = sheet && evt->IsActivate() && evt->HasPosition() + && evt->Matches( aEvent ); if( evt->IsCancelInteractive() ) { @@ -1749,7 +1738,7 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -1780,7 +1769,7 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 74ffdd14ea..d44a1d8c51 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1294,7 +1294,6 @@ int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { - std::string tool = *aEvent.GetCommandStr(); PICKER_TOOL* picker = m_toolMgr->GetTool(); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); @@ -1355,7 +1354,7 @@ int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false ); } ); - m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true ); return 0; } diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 2d46a01043..15fc019198 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -922,8 +922,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false ); } ); - std::string tool = *aEvent.GetCommandStr(); - m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true ); return 0; } @@ -1012,8 +1011,7 @@ int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false ); } ); - std::string tool = *aEvent.GetCommandStr(); - m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true ); return 0; } @@ -1384,7 +1382,6 @@ int SCH_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime ) m_frame->RecalculateConnections( NO_CLEANUP ); - std::string tool = *aEvent.GetCommandStr(); PICKER_TOOL* picker = m_toolMgr->GetTool(); // Deactivate other tools; particularly important if another PICKER is currently running @@ -1399,7 +1396,7 @@ int SCH_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) return highlightNet( m_toolMgr, aPos ); } ); - m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true ); return 0; } diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index 451b3a78d3..9e0730da32 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -302,8 +302,7 @@ int SCH_LINE_WIRE_BUS_TOOL::DrawSegments( const TOOL_EVENT& aEvent ) DRAW_SEGMENT_EVENT_PARAMS* params = aEvent.Parameter(); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); if( aEvent.HasPosition() ) @@ -316,7 +315,7 @@ int SCH_LINE_WIRE_BUS_TOOL::DrawSegments( const TOOL_EVENT& aEvent ) startSegments( params->layer, cursorPos, params->sourceSegment ); } - return doDrawSegments( tool, params->layer, params->quitOnDraw ); + return doDrawSegments( aEvent, params->layer, params->quitOnDraw ); } @@ -331,8 +330,7 @@ int SCH_LINE_WIRE_BUS_TOOL::UnfoldBus( const TOOL_EVENT& aEvent ) wxString net; SCH_LINE* segment = nullptr; - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); Activate(); if( netPtr ) @@ -377,11 +375,11 @@ int SCH_LINE_WIRE_BUS_TOOL::UnfoldBus( const TOOL_EVENT& aEvent ) // If we have an unfolded wire to draw, then draw it if( segment ) { - return doDrawSegments( tool, LAYER_WIRE, false ); + return doDrawSegments( aEvent, LAYER_WIRE, false ); } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); return 0; } } @@ -574,7 +572,7 @@ void SCH_LINE_WIRE_BUS_TOOL::computeBreakPoint( const std::pairGetScreen(); SCH_LINE* segment = nullptr; @@ -647,9 +645,8 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType, bool twoSegments = currentMode != LINE_MODE::LINE_MODE_FREE; // The tool hotkey is interpreted as a click when drawing - bool isSyntheticClick = ( segment || m_busUnfold.in_progress ) - && evt->IsActivate() && evt->HasPosition() - && evt->GetCommandStr() == aTool; + bool isSyntheticClick = ( segment || m_busUnfold.in_progress ) && evt->IsActivate() + && evt->HasPosition() && evt->Matches( aTool ); setCursor(); grid.SetMask( GRID_HELPER::ALL ); diff --git a/eeschema/tools/sch_line_wire_bus_tool.h b/eeschema/tools/sch_line_wire_bus_tool.h index 22a5687207..d037329f57 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.h +++ b/eeschema/tools/sch_line_wire_bus_tool.h @@ -100,7 +100,7 @@ public: int TrimOverLappingWires( const TOOL_EVENT& aEvent ); private: - int doDrawSegments( const std::string& aTool, int aType, bool aQuitOnDraw ); + int doDrawSegments( const TOOL_EVENT& aTool, int aType, bool aQuitOnDraw ); SCH_LINE* startSegments( int aType, const VECTOR2D& aPos, SCH_LINE* aSegment = nullptr ); SCH_LINE* doUnfoldBus( const wxString& aNet, const VECTOR2I& aPos = VECTOR2I( 0, 0 ) ); void finishSegments(); diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index 002b36deec..bf58a8ef31 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -144,20 +144,20 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) // Must be done after Activate() so that it gets set into the correct context controls->ShowCursor( true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); if( selection.Empty() ) { // Note that it's important to go through push/pop even when the selection is empty. // This keeps other tools from having to special-case an empty move. - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); return 0; } bool restore_state = false; bool chain_commands = false; - TOOL_EVENT* evt = const_cast( &aEvent ); + TOOL_EVENT copy = aEvent; + TOOL_EVENT* evt = © VECTOR2I prevPos; int snapLayer = UNDEFINED_LAYER; @@ -910,7 +910,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) m_dragAdditions.clear(); m_lineConnectionCache.clear(); m_moveInProgress = false; - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); return 0; } diff --git a/eeschema/tools/symbol_editor_drawing_tools.cpp b/eeschema/tools/symbol_editor_drawing_tools.cpp index 99b04d4df0..9a2619a705 100644 --- a/eeschema/tools/symbol_editor_drawing_tools.cpp +++ b/eeschema/tools/symbol_editor_drawing_tools.cpp @@ -95,8 +95,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -145,9 +144,8 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) controls->ForceCursorPosition( true, cursorPos ); // The tool hotkey is interpreted as a click when drawing - bool isSyntheticClick = item - && evt->IsActivate() && evt->HasPosition() - && evt->GetCommandStr() == tool; + bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() + && evt->Matches( aEvent ); if( evt->IsCancelInteractive() ) { @@ -159,7 +157,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -189,7 +187,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -341,8 +339,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -376,9 +373,8 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() ); // The tool hotkey is interpreted as a click when drawing - bool isSyntheticClick = item - && evt->IsActivate() && evt->HasPosition() - && evt->GetCommandStr() == tool; + bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() + && evt->Matches( aEvent ); if( evt->IsCancelInteractive() ) { @@ -388,7 +384,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -408,7 +404,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -542,8 +538,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) int SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent ) { - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -564,12 +559,12 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent ) if( evt->IsCancelInteractive() ) { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } else if( evt->IsActivate() ) { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) ) diff --git a/eeschema/tools/symbol_editor_edit_tool.cpp b/eeschema/tools/symbol_editor_edit_tool.cpp index ae6764df7f..4937c6abc9 100644 --- a/eeschema/tools/symbol_editor_edit_tool.cpp +++ b/eeschema/tools/symbol_editor_edit_tool.cpp @@ -333,7 +333,6 @@ int SYMBOL_EDITOR_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) int SYMBOL_EDITOR_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { - std::string tool = *aEvent.GetCommandStr(); PICKER_TOOL* picker = m_toolMgr->GetTool(); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); @@ -401,7 +400,7 @@ int SYMBOL_EDITOR_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false ); } ); - m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true ); return 0; } diff --git a/eeschema/tools/symbol_editor_move_tool.cpp b/eeschema/tools/symbol_editor_move_tool.cpp index 3b2328f38a..8062391ade 100644 --- a/eeschema/tools/symbol_editor_move_tool.cpp +++ b/eeschema/tools/symbol_editor_move_tool.cpp @@ -110,8 +110,7 @@ int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) return 0; } - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); Activate(); // Must be done after Activate() so that it gets set into the correct context @@ -120,7 +119,8 @@ int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) bool restore_state = false; bool chain_commands = false; - TOOL_EVENT* evt = const_cast( &aEvent ); + TOOL_EVENT copy = aEvent; + TOOL_EVENT* evt = © VECTOR2I prevPos; if( !selection.Front()->IsNew() ) @@ -365,7 +365,7 @@ int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) } m_moveInProgress = false; - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); return 0; } diff --git a/gerbview/tools/gerbview_inspection_tool.cpp b/gerbview/tools/gerbview_inspection_tool.cpp index 6117858adb..60c3228d47 100644 --- a/gerbview/tools/gerbview_inspection_tool.cpp +++ b/gerbview/tools/gerbview_inspection_tool.cpp @@ -207,8 +207,7 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) EDA_UNITS units = m_frame->GetUserUnits(); KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, gerbIUScale, units, false, false ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -247,7 +246,7 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -263,7 +262,7 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } diff --git a/include/tool/tool_event.h b/include/tool/tool_event.h index 4491a7101d..5a7b36e9a1 100644 --- a/include/tool/tool_event.h +++ b/include/tool/tool_event.h @@ -39,6 +39,7 @@ class TOOL_ACTION; class TOOL_MANAGER; class TOOL_BASE; +class TOOLS_HOLDER; /** * Internal (GUI-independent) event definitions. @@ -368,8 +369,8 @@ public: if( m_category == TC_COMMAND || m_category == TC_MESSAGE ) { - if( (bool) m_commandStr && (bool) aEvent.m_commandStr ) - return *m_commandStr == *aEvent.m_commandStr; + if( !m_commandStr.empty() && !aEvent.getCommandStr().empty() ) + return m_commandStr == aEvent.m_commandStr; if( (bool) m_commandId && (bool) aEvent.m_commandId ) return *m_commandId == *aEvent.m_commandId; @@ -466,11 +467,6 @@ public: return m_commandId; } - std::optional GetCommandStr() const - { - return m_commandStr; - } - void SetMousePosition( const VECTOR2D& aP ) { m_mousePos = aP; @@ -478,9 +474,13 @@ public: private: friend class TOOL_DISPATCHER; + friend class TOOL_MANAGER; + friend class TOOLS_HOLDER; void init(); + const std::string& getCommandStr() const { return m_commandStr; } + void setMouseDragOrigin( const VECTOR2D& aP ) { m_mouseDragOrigin = aP; @@ -551,7 +551,7 @@ private: TOOL_BASE* m_firstResponder; std::optional m_commandId; - std::optional m_commandStr; + std::string m_commandStr; }; typedef std::optional OPT_TOOL_EVENT; diff --git a/include/tool/tools_holder.h b/include/tool/tools_holder.h index be85348b67..a01b3ea3c7 100644 --- a/include/tool/tools_holder.h +++ b/include/tool/tools_holder.h @@ -110,8 +110,20 @@ public: * "tools", such as rectangle and circle, or wire and bus. So each user-level tool is * actually a #TOOL_ACTION. */ - virtual void PushTool( const std::string& actionName ); - virtual void PopTool( const std::string& actionName ); + + /** + * @brief Pushes a tool to the stack. + * + * @param aEvent The event that is starting the tool to be pushed to the stack. + */ + virtual void PushTool( const TOOL_EVENT& aEvent ); + + /** + * @brief Pops a tool from the stack. + * + * @param aEvent The event that started the tool that was pushed to the stack. + */ + virtual void PopTool( const TOOL_EVENT& aEvent ); bool ToolStackIsEmpty() { return m_toolStack.empty(); } diff --git a/pagelayout_editor/tools/pl_drawing_tools.cpp b/pagelayout_editor/tools/pl_drawing_tools.cpp index 0b8caa8b53..5ea265d9a7 100644 --- a/pagelayout_editor/tools/pl_drawing_tools.cpp +++ b/pagelayout_editor/tools/pl_drawing_tools.cpp @@ -78,8 +78,7 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -122,7 +121,7 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent ) cleanup(); else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -138,7 +137,7 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -226,8 +225,7 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -333,7 +331,7 @@ int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) getViewControls()->SetAutoPan( false ); getViewControls()->CaptureCursor( false ); m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); return 0; } diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index 1988391843..23d076cbeb 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -117,8 +117,7 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) unique_peers.insert( drawItem->GetPeer() ); } - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); Activate(); // Must be done after Activate() so that it gets set into the correct context @@ -127,7 +126,8 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) bool restore_state = false; bool chain_commands = false; - TOOL_EVENT* evt = const_cast( &aEvent ); + TOOL_EVENT copy = aEvent; + TOOL_EVENT* evt = © VECTOR2I prevPos; if( !selection.Front()->IsNew() ) @@ -301,7 +301,7 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) m_toolMgr->PostEvent( EVENTS::SelectedEvent ); m_moveInProgress = false; - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); return 0; } @@ -389,7 +389,6 @@ int PL_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) int PL_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { - std::string tool = *aEvent.GetCommandStr(); PICKER_TOOL* picker = m_toolMgr->GetTool(); // Deactivate other tools; particularly important if another PICKER is currently running @@ -455,7 +454,7 @@ int PL_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PL_ACTIONS::selectionActivate, false ); } ); - m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true ); return 0; } diff --git a/pcbnew/microwave/microwave_tool.cpp b/pcbnew/microwave/microwave_tool.cpp index 0a233103bf..ca1c0fee6d 100644 --- a/pcbnew/microwave/microwave_tool.cpp +++ b/pcbnew/microwave/microwave_tool.cpp @@ -89,8 +89,7 @@ int MICROWAVE_TOOL::addMicrowaveFootprint( const TOOL_EVENT& aEvent ) MICROWAVE_PLACER placer( this, aEvent.Parameter() ); - doInteractiveItemPlacement( *aEvent.GetCommandStr(), &placer, - _( "Place microwave feature" ), + doInteractiveItemPlacement( aEvent, &placer, _( "Place microwave feature" ), IPO_REPEAT | IPO_ROTATE | IPO_FLIP ); return 0; @@ -114,8 +113,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent ) KIGFX::VIEW_CONTROLS& controls = *getViewControls(); PCB_EDIT_FRAME& frame = *getEditFrame(); - std::string tool = *aEvent.GetCommandStr(); - frame.PushTool( tool ); + frame.PushTool( aEvent ); auto setCursor = [&]() @@ -161,7 +159,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent ) cleanup(); else { - frame.PopTool( tool ); + frame.PopTool( aEvent ); break; } } @@ -177,7 +175,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent ) } else { - frame.PopTool( tool ); + frame.PopTool( aEvent ); break; } } diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index b1aad62020..a3eecdc3a7 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -274,8 +274,7 @@ int LENGTH_TUNER_TOOL::MainLoop( const TOOL_EVENT& aEvent ) // Deselect all items m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - std::string tool = *aEvent.GetCommandStr(); - frame()->PushTool( tool ); + frame()->PushTool( aEvent ); auto setCursor = [&]() @@ -338,7 +337,7 @@ int LENGTH_TUNER_TOOL::MainLoop( const TOOL_EVENT& aEvent ) m_savedSizes = m_router->Sizes(); frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); - frame()->PopTool( tool ); + frame()->PopTool( aEvent ); return 0; } diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 02e280615c..5fb36941b6 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -1534,8 +1534,7 @@ int ROUTER_TOOL::RouteSelected( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - std::string tool = aEvent.GetCommandStr().value(); - frame->PushTool( tool ); + frame->PushTool( aEvent ); auto setCursor = [&]() @@ -1632,7 +1631,7 @@ int ROUTER_TOOL::RouteSelected( const TOOL_EVENT& aEvent ) } m_iface->SetCommitFlags( 0 ); - frame->PopTool( tool ); + frame->PopTool( aEvent ); return 0; } @@ -1654,8 +1653,7 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent ) // Deselect all items m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - std::string tool = *aEvent.GetCommandStr(); - frame->PushTool( tool ); + frame->PushTool( aEvent ); auto setCursor = [&]() @@ -1684,7 +1682,7 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent ) if( evt->IsCancelInteractive() ) { - frame->PopTool( tool ); + frame->PopTool( aEvent ); break; } else if( evt->IsActivate() ) @@ -1696,7 +1694,7 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent ) } else { - frame->PopTool( tool ); + frame->PopTool( aEvent ); break; } } @@ -1769,7 +1767,7 @@ int ROUTER_TOOL::MainLoop( const TOOL_EVENT& aEvent ) if( m_cancelled ) { - frame->PopTool( tool ); + frame->PopTool( aEvent ); break; } } diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index c57dfc1f72..3329da1265 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -982,8 +982,7 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -1058,7 +1057,7 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -1074,7 +1073,7 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent ) } else { - frame()->PopTool( tool ); + frame()->PopTool( aEvent ); break; } } @@ -1570,7 +1569,6 @@ void BOARD_EDITOR_CONTROL::DoSetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* int BOARD_EDITOR_CONTROL::DrillOrigin( const TOOL_EVENT& aEvent ) { - std::string tool = *aEvent.GetCommandStr(); PCB_PICKER_TOOL* picker = m_toolMgr->GetTool(); // Deactivate other tools; particularly important if another PICKER is currently running @@ -1584,7 +1582,7 @@ int BOARD_EDITOR_CONTROL::DrillOrigin( const TOOL_EVENT& aEvent ) return false; // drill origin is a one-shot; don't continue with tool } ); - m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true ); return 0; } diff --git a/pcbnew/tools/board_inspection_tool.cpp b/pcbnew/tools/board_inspection_tool.cpp index bb637fd576..7b249d38a7 100644 --- a/pcbnew/tools/board_inspection_tool.cpp +++ b/pcbnew/tools/board_inspection_tool.cpp @@ -1539,7 +1539,6 @@ int BOARD_INSPECTION_TOOL::ClearHighlight( const TOOL_EVENT& aEvent ) int BOARD_INSPECTION_TOOL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) { - std::string tool = *aEvent.GetCommandStr(); PCB_PICKER_TOOL* picker = m_toolMgr->GetTool(); BOARD* board = getModel(); @@ -1610,7 +1609,7 @@ int BOARD_INSPECTION_TOOL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) } } ); - m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true ); return 0; } diff --git a/pcbnew/tools/drawing_stackup_table_tool.cpp b/pcbnew/tools/drawing_stackup_table_tool.cpp index c72d625e60..67cab4e728 100644 --- a/pcbnew/tools/drawing_stackup_table_tool.cpp +++ b/pcbnew/tools/drawing_stackup_table_tool.cpp @@ -554,8 +554,7 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent, // do not capture or auto-pan until we start placing the table SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); Activate(); // Must be done after Activate() so that it gets set into the correct context @@ -586,7 +585,7 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent, if( evt->IsCancelInteractive() ) { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); cancelled = true; break; } @@ -617,7 +616,7 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent, } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); cancelled = true; break; } @@ -638,7 +637,7 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent, if( destLayer == PCB_LAYER_ID::UNDEFINED_LAYER ) { // The user did not pick any layer. - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); cancelled = true; break; } @@ -663,7 +662,7 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent, } commit.Push( wxT( "Placing items" ) ); - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index a2cdbde824..37c8b1607b 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -313,11 +313,10 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent ) if( aEvent.HasPosition() ) startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); Activate(); - while( drawShape( tool, &line, startingPoint ) ) + while( drawShape( aEvent, &line, startingPoint ) ) { if( line ) { @@ -387,11 +386,10 @@ int DRAWING_TOOL::DrawRectangle( const TOOL_EVENT& aEvent ) if( aEvent.HasPosition() ) startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); Activate(); - while( drawShape( tool, &rect, startingPoint ) ) + while( drawShape( aEvent, &rect, startingPoint ) ) { if( rect ) { @@ -447,11 +445,10 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent ) if( aEvent.HasPosition() ) startingPoint = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); Activate(); - while( drawShape( tool, &circle, startingPoint ) ) + while( drawShape( aEvent, &circle, startingPoint ) ) { if( circle ) { @@ -495,14 +492,13 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent ) arc->SetShape( SHAPE_T::ARC ); arc->SetFlags( IS_NEW ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); Activate(); if( aEvent.HasPosition() ) startingPoint = aEvent.Position(); - while( drawArc( tool, &arc, startingPoint ) ) + while( drawArc( aEvent, &arc, startingPoint ) ) { if( arc ) { @@ -553,8 +549,7 @@ int DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent ) m_view->AddToPreview( image->Clone() ); } - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() { @@ -610,13 +605,13 @@ int DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } if( immediateMode ) { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -643,7 +638,7 @@ int DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -715,7 +710,7 @@ int DRAWING_TOOL::PlaceImage( const TOOL_EVENT& aEvent ) if( immediateMode ) { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -797,8 +792,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); Activate(); // Must be done after Activate() so that it gets set into the correct context @@ -832,7 +826,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -848,7 +842,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -1079,8 +1073,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); Activate(); // Must be done after Activate() so that it gets set into the correct context @@ -1130,7 +1123,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -1150,7 +1143,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -1560,8 +1553,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &selectedItems ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -1636,7 +1628,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); m_controls->ForceCursorPosition( false ); - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); return 0; } @@ -1659,8 +1651,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -1701,7 +1692,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) // Usually, we do not need to change twice the anchor position, // so deselect the active tool - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } else if( evt->IsClick( BUT_RIGHT ) ) @@ -1710,7 +1701,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) } else if( evt->IsCancelInteractive() || evt->IsActivate() ) { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } else @@ -1759,7 +1750,7 @@ static void updateSegmentFromGeometryMgr( const KIGFX::PREVIEW::TWO_POINT_GEOMET } -bool DRAWING_TOOL::drawShape( const std::string& aTool, PCB_SHAPE** aGraphic, +bool DRAWING_TOOL::drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic, std::optional aStartingPoint ) { SHAPE_T shape = ( *aGraphic )->GetShape(); @@ -2152,7 +2143,7 @@ static void updateArcFromConstructionMgr( const KIGFX::PREVIEW::ARC_GEOM_MANAGER } -bool DRAWING_TOOL::drawArc( const std::string& aTool, PCB_SHAPE** aGraphic, +bool DRAWING_TOOL::drawArc( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic, std::optional aStartingPoint ) { PCB_SHAPE*& graphic = *aGraphic; @@ -2498,8 +2489,7 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) status.SetTextColor( wxColour( 255, 0, 0 ) ); status.SetText( _( "Self-intersecting polygons are not allowed" ) ); - std::string tool = *aEvent.GetCommandStr(); - m_frame->PushTool( tool ); + m_frame->PushTool( aEvent ); auto setCursor = [&]() @@ -2554,7 +2544,7 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) { // We've handled the cancel event. Don't cancel other tools evt->SetPassEvent( false ); - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -2574,7 +2564,7 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) } else { - m_frame->PopTool( tool ); + m_frame->PopTool( aEvent ); break; } } @@ -3216,8 +3206,7 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::VIA ); - doInteractiveItemPlacement( *aEvent.GetCommandStr(), &placer, _( "Place via" ), - IPO_REPEAT | IPO_SINGLE_CLICK ); + doInteractiveItemPlacement( aEvent, &placer, _( "Place via" ), IPO_REPEAT | IPO_SINGLE_CLICK ); return 0; } diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 79412b85ec..fd3b716e45 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -229,7 +229,8 @@ private: * @return False if the tool was canceled before the origin was set or origin and end are * the same point. */ - bool drawShape( const std::string& aTool, PCB_SHAPE** aGraphic, std::optional aStartingPoint ); + bool drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic, + std::optional aStartingPoint ); /** * Start drawing an arc. @@ -239,7 +240,8 @@ private: * @return False if the tool was canceled before the origin was set or origin and end are * the same point. */ - bool drawArc( const std::string& aTool, PCB_SHAPE** aGraphic, std::optional aStartingPoint ); + bool drawArc( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic, + std::optional aStartingPoint ); /** * Draw a polygon, that is added as a zone or a keepout area. @@ -274,7 +276,7 @@ private: /** * Clamps the end vector to respect numeric limits of difference representation - * + * * @param aOrigin - the origin vector. * @param aEnd - the end vector. * @return clamped end vector. @@ -304,7 +306,7 @@ private: /** * Clamps the end vector to respect numeric limits of radius representation - * + * * @param aOrigin - the origin vector. * @param aEnd - the end vector. * @return clamped end vector. diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 87cefbe171..0dd8f49699 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -1431,8 +1431,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) return 0; } - std::string tool = *aEvent.GetCommandStr(); - editFrame->PushTool( tool ); + editFrame->PushTool( aEvent ); std::vector lockedItems; Activate(); @@ -1473,7 +1472,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) { wxBell(); canvas()->Refresh(); - editFrame->PopTool( tool ); + editFrame->PopTool( aEvent ); return 0; } @@ -1669,7 +1668,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) else m_commit->Push( _( "Delete" ) ); - editFrame->PopTool( tool ); + editFrame->PopTool( aEvent ); return 0; } @@ -2087,12 +2086,14 @@ bool EDIT_TOOL::pickReferencePoint( const wxString& aTooltip, const wxString& aS int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent ) { - std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint"; CLIPBOARD_IO io; PCB_GRID_HELPER grid( m_toolMgr, getEditFrame()->GetMagneticItemsSettings() ); + TOOL_EVENT selectReferencePoint( aEvent.Category(), aEvent.Action(), + "pcbnew.InteractiveEdit.selectReferencePoint", + TOOL_ACTION_SCOPE::AS_GLOBAL ); - frame()->PushTool( tool ); + frame()->PushTool( selectReferencePoint ); Activate(); PCB_SELECTION& selection = m_selectionTool->RequestSelection( @@ -2128,7 +2129,7 @@ int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent ) _( "Copy canceled" ), refPoint ) ) { - frame()->PopTool( tool ); + frame()->PopTool( selectReferencePoint ); return 0; } } @@ -2144,7 +2145,7 @@ int EDIT_TOOL::copyToClipboard( const TOOL_EVENT& aEvent ) frame()->SetStatusText( _( "Selection copied" ) ); } - frame()->PopTool( tool ); + frame()->PopTool( selectReferencePoint ); return 0; } @@ -2157,7 +2158,7 @@ int EDIT_TOOL::cutToClipboard( const TOOL_EVENT& aEvent ) // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items // that were copied to the clipboard, no more, no fewer. Filtering for locked item, if // any will be done in the copyToClipboard() routine - TOOL_EVENT evt( aEvent.Category(), aEvent.Action(), TOOL_ACTION_SCOPE::AS_GLOBAL ); + TOOL_EVENT evt = aEvent; evt.SetParameter( PCB_ACTIONS::REMOVE_FLAGS::CUT ); Remove( evt ); } diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index f82b3f38f9..e52f4e4bf0 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -185,7 +185,7 @@ private: bool invokeInlineRouter( int aDragMode ); bool isRouterActive() const; - int doMoveSelection( TOOL_EVENT aEvent, bool aPickReference = false ); + int doMoveSelection( const TOOL_EVENT& aEvent, bool aPickReference = false ); VECTOR2I getSafeMovement( const VECTOR2I& aMovement, const BOX2I& aSourceBBox, const VECTOR2D& aBBoxOffset ); diff --git a/pcbnew/tools/edit_tool_move_fct.cpp b/pcbnew/tools/edit_tool_move_fct.cpp index 8f68cd8b60..1626872489 100644 --- a/pcbnew/tools/edit_tool_move_fct.cpp +++ b/pcbnew/tools/edit_tool_move_fct.cpp @@ -439,9 +439,7 @@ VECTOR2I EDIT_TOOL::getSafeMovement( const VECTOR2I& aMovement, const BOX2I& aSo } -// Note: aEvent MUST NOT be const&; the source will get de-allocated if we go into the picker's -// event loop. -int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) +int EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, bool aPickReference ) { PCB_BASE_EDIT_FRAME* editFrame = getEditFrame(); BOARD* board = editFrame->GetBoard(); @@ -485,8 +483,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) if( selection.Empty() ) return 0; - std::string tool = *aEvent.GetCommandStr(); - editFrame->PushTool( tool ); + editFrame->PushTool( aEvent ); Activate(); // Must be done after Activate() so that it gets set into the correct context @@ -500,7 +497,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) if( is_hover ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - editFrame->PopTool( tool ); + editFrame->PopTool( aEvent ); return 0; } @@ -546,7 +543,8 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) BOX2I originalBBox; bool updateBBox = true; PCB_GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() ); - TOOL_EVENT* evt = &aEvent; + TOOL_EVENT copy = aEvent; + TOOL_EVENT* evt = © VECTOR2I prevPos; bool hv45Mode = false; @@ -926,7 +924,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &orig_items ); - editFrame->PopTool( tool ); + editFrame->PopTool( aEvent ); editFrame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); return restore_state ? -1 : 0; diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index 2302f90ae7..8dd830d85b 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -299,8 +299,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - std::string tool = *aEvent.GetCommandStr(); - frame()->PushTool( tool ); + frame()->PushTool( aEvent ); VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag std::list selectedPads; @@ -349,14 +348,14 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); commit.Revert(); - frame()->PopTool( tool ); + frame()->PopTool( aEvent ); break; } else if( evt->IsActivate() ) { commit.Push( _( "Renumber pads" ) ); - frame()->PopTool( tool ); + frame()->PopTool( aEvent ); break; } else if( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) @@ -452,7 +451,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent ) evt->IsDblClick( BUT_LEFT ) ) { commit.Push( _( "Renumber pads" ) ); - frame()->PopTool( tool ); + frame()->PopTool( aEvent ); break; } else if( evt->IsClick( BUT_RIGHT ) ) @@ -558,7 +557,7 @@ int PAD_TOOL::PlacePad( const TOOL_EVENT& aEvent ) PAD_PLACER placer( this ); - doInteractiveItemPlacement( *aEvent.GetCommandStr(), &placer, _( "Place pad" ), + doInteractiveItemPlacement( aEvent, &placer, _( "Place pad" ), IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP ); return 0; diff --git a/pcbnew/tools/pcb_control.cpp b/pcbnew/tools/pcb_control.cpp index 78936f216c..ae27f3be40 100644 --- a/pcbnew/tools/pcb_control.cpp +++ b/pcbnew/tools/pcb_control.cpp @@ -518,7 +518,6 @@ int PCB_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) if( m_isFootprintEditor && !getEditFrame()->GetModel() ) return 0; - std::string tool = *aEvent.GetCommandStr(); PCB_PICKER_TOOL* picker = m_toolMgr->GetTool(); if( !picker ) // Happens in footprint wizard @@ -535,7 +534,7 @@ int PCB_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) return false; // drill origin is a one-shot; don't continue with tool } ); - m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true ); } return 0; @@ -558,7 +557,6 @@ int PCB_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent ) if( m_isFootprintEditor && !m_frame->GetBoard()->GetFirstFootprint() ) return 0; - std::string tool = *aEvent.GetCommandStr(); PCB_PICKER_TOOL* picker = m_toolMgr->GetTool(); m_pickerItem = nullptr; @@ -644,7 +642,7 @@ int PCB_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent ) m_frame->GetCanvas()->Refresh(); } ); - m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); + m_toolMgr->RunAction( ACTIONS::pickerTool, true ); return 0; } diff --git a/pcbnew/tools/pcb_picker_tool.cpp b/pcbnew/tools/pcb_picker_tool.cpp index 4dff271e79..0478360be9 100644 --- a/pcbnew/tools/pcb_picker_tool.cpp +++ b/pcbnew/tools/pcb_picker_tool.cpp @@ -43,16 +43,13 @@ int PCB_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) PCB_GRID_HELPER grid( m_toolMgr, frame->GetMagneticItemsSettings() ); int finalize_state = WAIT_CANCEL; - std::string tool = *aEvent.Parameter(); - - if( !tool.empty() ) - frame->PushTool( tool ); + frame->PushTool( aEvent ); Activate(); setControls(); - auto setCursor = - [&]() + auto setCursor = + [&]() { frame->GetCanvas()->SetCurrentCursor( m_cursor ); controls->ShowCursor( true ); @@ -173,8 +170,7 @@ int PCB_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) controls->ForceCursorPosition( false ); controls->ShowCursor( false ); - if( !tool.empty() ) - frame->PopTool( tool ); + frame->PopTool( aEvent ); return 0; } diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index 783b1ecf3a..badaa456ed 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -36,7 +36,7 @@ #include #include -void PCB_TOOL_BASE::doInteractiveItemPlacement( const std::string& aTool, +void PCB_TOOL_BASE::doInteractiveItemPlacement( const TOOL_EVENT& aTool, INTERACTIVE_PLACER_BASE* aPlacer, const wxString& aCommitMessage, int aOptions ) { diff --git a/pcbnew/tools/pcb_tool_base.h b/pcbnew/tools/pcb_tool_base.h index 864831ca57..16076f5afb 100644 --- a/pcbnew/tools/pcb_tool_base.h +++ b/pcbnew/tools/pcb_tool_base.h @@ -145,7 +145,7 @@ protected: * @param aItemCreator the callable that will attempt to create the item * @param aCommitMessage the message used on a successful commit */ - void doInteractiveItemPlacement( const std::string& aTool, INTERACTIVE_PLACER_BASE *aPlacer, + void doInteractiveItemPlacement( const TOOL_EVENT& aTool, INTERACTIVE_PLACER_BASE* aPlacer, const wxString& aCommitMessage, int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT ); diff --git a/pcbnew/tools/pcb_viewer_tools.cpp b/pcbnew/tools/pcb_viewer_tools.cpp index ebf839e495..846ed298b3 100644 --- a/pcbnew/tools/pcb_viewer_tools.cpp +++ b/pcbnew/tools/pcb_viewer_tools.cpp @@ -197,8 +197,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent ) auto& view = *getView(); auto& controls = *getViewControls(); - std::string tool = *aEvent.GetCommandStr(); - frame()->PushTool( tool ); + frame()->PushTool( aEvent ); TWO_POINT_GEOMETRY_MANAGER twoPtMgr; PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() ); @@ -253,7 +252,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent ) } else { - frame()->PopTool( tool ); + frame()->PopTool( aEvent ); break; } } @@ -269,7 +268,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent ) } else { - frame()->PopTool( tool ); + frame()->PopTool( aEvent ); break; } }