diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index ee7518a0e6..c8d2dcd6d2 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -565,8 +565,10 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) picker->ClearHandlers(); picker->SetClickHandler( - [this, simFrame]( const VECTOR2D& aPosition ) + [this]( const VECTOR2D& aPosition ) { + KIWAY_PLAYER* player = m_frame->Kiway().Player( FRAME_SIMULATOR, false ); + SIMULATOR_FRAME* simFrame = static_cast( player ); SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); // We do not really want to keep an item selected in schematic, @@ -614,7 +616,9 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) } else if( currentNames.size() == 1 ) { - simFrame->AddCurrentTrace( currentNames.at( 0 ) ); + if( simFrame ) + simFrame->AddCurrentTrace( currentNames.at( 0 ) ); + return true; } @@ -623,7 +627,9 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) if( modelPinIndex != SIM_MODEL_PIN::NOT_CONNECTED ) { wxString name = currentNames.at( modelPinIndex ); - simFrame->AddCurrentTrace( name ); + + if( simFrame ) + simFrame->AddCurrentTrace( name ); } } catch( const IO_ERROR& e ) @@ -639,7 +645,8 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) wxString spiceNet = UnescapeString( conn->Name() ); NETLIST_EXPORTER_SPICE::ConvertToSpiceMarkup( &spiceNet ); - simFrame->AddVoltageTrace( wxString::Format( "V(%s)", spiceNet ) ); + if( simFrame ) + simFrame->AddVoltageTrace( wxString::Format( "V(%s)", spiceNet ) ); } } @@ -647,7 +654,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) } ); picker->SetMotionHandler( - [this, picker]( const VECTOR2D& aPos ) + [this]( const VECTOR2D& aPos ) { SCH_COLLECTOR collector; collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); @@ -670,9 +677,9 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) } if( item && item->Type() == SCH_PIN_T ) - picker->SetCursor( KICURSOR::CURRENT_PROBE ); + m_toolMgr->GetTool()->SetCursor( KICURSOR::CURRENT_PROBE ); else - picker->SetCursor( KICURSOR::VOLTAGE_PROBE ); + m_toolMgr->GetTool()->SetCursor( KICURSOR::VOLTAGE_PROBE ); if( m_pickerItem != item ) { diff --git a/pcbnew/tools/board_inspection_tool.cpp b/pcbnew/tools/board_inspection_tool.cpp index 46b1834892..307bdbe134 100644 --- a/pcbnew/tools/board_inspection_tool.cpp +++ b/pcbnew/tools/board_inspection_tool.cpp @@ -1903,7 +1903,6 @@ int BOARD_INSPECTION_TOOL::ClearHighlight( const TOOL_EVENT& aEvent ) int BOARD_INSPECTION_TOOL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) { PCB_PICKER_TOOL* picker = m_toolMgr->GetTool(); - BOARD* board = getModel(); // Deactivate other tools; particularly important if another PICKER is currently running Activate(); @@ -1913,7 +1912,7 @@ int BOARD_INSPECTION_TOOL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) picker->ClearHandlers(); picker->SetClickHandler( - [this, board]( const VECTOR2D& pt ) -> bool + [this]( const VECTOR2D& pt ) -> bool { PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); @@ -1933,7 +1932,7 @@ int BOARD_INSPECTION_TOOL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) if( selection.Empty() ) { // Clear the previous local ratsnest if we click off all items - for( FOOTPRINT* fp : board->Footprints() ) + for( FOOTPRINT* fp : getModel()->Footprints() ) { for( PAD* pad : fp->Pads() ) pad->SetLocalRatsnestVisible( displayOptions().m_ShowGlobalRatsnest ); @@ -1966,11 +1965,11 @@ int BOARD_INSPECTION_TOOL::LocalRatsnestTool( const TOOL_EVENT& aEvent ) } ); picker->SetFinalizeHandler( - [this, board]( int aCondition ) + [this]( int aCondition ) { if( aCondition != PCB_PICKER_TOOL::END_ACTIVATE ) { - for( FOOTPRINT* fp : board->Footprints() ) + for( FOOTPRINT* fp : getModel()->Footprints() ) { for( PAD* pad : fp->Pads() ) pad->SetLocalRatsnestVisible( displayOptions().m_ShowGlobalRatsnest ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index a879841301..8d9c757445 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -3326,6 +3326,8 @@ bool EDIT_TOOL::pickReferencePoint( const wxString& aTooltip, const wxString& aS } } + picker->ClearHandlers(); + // Ensure statusPopup is hidden after use and before deleting it: canvas()->SetStatusPopup( nullptr ); m_statusPopup->Hide(); diff --git a/pcbnew/tools/pcb_picker_tool.cpp b/pcbnew/tools/pcb_picker_tool.cpp index ce5ac5211e..cfc713356d 100644 --- a/pcbnew/tools/pcb_picker_tool.cpp +++ b/pcbnew/tools/pcb_picker_tool.cpp @@ -259,11 +259,12 @@ int PCB_PICKER_TOOL::SelectPointInteractively( const TOOL_EVENT& aEvent ) statusPopup.SetText( wxGetTranslation( params.m_Prompt ) ); - const auto sendPoint = [&]( const std::optional& aPoint ) - { - statusPopup.Hide(); - params.m_Receiver->UpdatePickedPoint( aPoint ); - }; + const auto sendPoint = + [&]( const std::optional& aPoint ) + { + statusPopup.Hide(); + params.m_Receiver->UpdatePickedPoint( aPoint ); + }; SetSnapping( true ); SetCursor( KICURSOR::PLACE ); @@ -305,11 +306,13 @@ int PCB_PICKER_TOOL::SelectPointInteractively( const TOOL_EVENT& aEvent ) // Drop into the main event loop Main( aEvent ); + ClearHandlers(); canvas()->SetStatusPopup( nullptr ); frame()->PopTool( aEvent ); return 0; } + int PCB_PICKER_TOOL::SelectItemInteractively( const TOOL_EVENT& aEvent ) { INTERACTIVE_PARAMS params = aEvent.Parameter(); @@ -324,11 +327,12 @@ int PCB_PICKER_TOOL::SelectItemInteractively( const TOOL_EVENT& aEvent ) statusPopup.SetText( wxGetTranslation( params.m_Prompt ) ); - const auto sendItem = [&]( const EDA_ITEM* aItem ) - { - statusPopup.Hide(); - params.m_Receiver->UpdatePickedItem( aItem ); - }; + const auto sendItem = + [&]( const EDA_ITEM* aItem ) + { + statusPopup.Hide(); + params.m_Receiver->UpdatePickedItem( aItem ); + }; SetCursor( KICURSOR::BULLSEYE ); SetSnapping( false ); @@ -339,8 +343,7 @@ int PCB_PICKER_TOOL::SelectItemInteractively( const TOOL_EVENT& aEvent ) { m_toolMgr->RunAction( PCB_ACTIONS::selectionClear ); const PCB_SELECTION& sel = selectionTool->RequestSelection( - []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, - PCB_SELECTION_TOOL* sTool ) + []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool ) { } ); @@ -382,6 +385,7 @@ int PCB_PICKER_TOOL::SelectItemInteractively( const TOOL_EVENT& aEvent ) // Drop into the main event loop Main( aEvent ); + ClearHandlers(); canvas()->SetStatusPopup( nullptr ); frame()->PopTool( aEvent ); return 0;