7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-07 17:25:33 +00:00

Put tool graphics back on the stack

Now that the tool framework gracefully shutdowns the tools, graphics
can be created on the stack inside a tool function.

This reverts commit f6881ce3de.
This commit is contained in:
Ian McInerney 2020-02-03 14:02:25 +00:00
parent b1240b5b1e
commit 8b7d4c2a55
3 changed files with 20 additions and 30 deletions

View File

@ -509,10 +509,6 @@ void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
}
}
// Be sure no tool is left activated, to avoid crash on exit,
// (happens with some tools)
GetToolManager()->DeactivateTool();
// On Windows 7 / 32 bits, on OpenGL mode only, Pcbnew crashes
// when closing this frame if a footprint was selected, and the footprint editor called
// to edit this footprint, and when closing pcbnew if this footprint is still selected

View File

@ -183,14 +183,11 @@ void LENGTH_TUNER_TOOL::performTuning()
VECTOR2I end( m_startSnapPoint );
// Create an instance of PNS_TUNE_STATUS_POPUP.
// DO NOT create it on the stack: otherwise on Windows, wxWidgets 3.1.3
// it creates a crash. I am pretty sure this crash is created by the stack switching
// when managing events (JPC).
std::unique_ptr<PNS_TUNE_STATUS_POPUP> statusPopup( new PNS_TUNE_STATUS_POPUP( frame() ) );
statusPopup->Popup();
PNS_TUNE_STATUS_POPUP statusPopup( frame() );
statusPopup.Popup();
m_router->Move( end, NULL );
updateStatusPopup( *statusPopup );
updateStatusPopup( statusPopup );
while( TOOL_EVENT* evt = Wait() )
{
@ -202,7 +199,7 @@ void LENGTH_TUNER_TOOL::performTuning()
{
end = evt->Position();
m_router->Move( end, NULL );
updateStatusPopup( *statusPopup );
updateStatusPopup( statusPopup );
}
else if( evt->IsClick( BUT_LEFT ) )
{
@ -218,32 +215,32 @@ void LENGTH_TUNER_TOOL::performTuning()
{
placer->AmplitudeStep( -1 );
m_router->Move( end, NULL );
updateStatusPopup( *statusPopup );
updateStatusPopup( statusPopup );
}
else if( evt->IsAction( &ACT_AmplIncrease ) )
{
placer->AmplitudeStep( 1 );
m_router->Move( end, NULL );
updateStatusPopup( *statusPopup );
updateStatusPopup( statusPopup );
}
else if(evt->IsAction( &ACT_SpacingDecrease ) )
{
placer->SpacingStep( -1 );
m_router->Move( end, NULL );
updateStatusPopup( *statusPopup );
updateStatusPopup( statusPopup );
}
else if( evt->IsAction( &ACT_SpacingIncrease ) )
{
placer->SpacingStep( 1 );
m_router->Move( end, NULL );
updateStatusPopup( *statusPopup );
updateStatusPopup( statusPopup );
}
else if( evt->IsAction( &ACT_Settings ) )
{
statusPopup->Hide();
statusPopup.Hide();
TOOL_EVENT dummy;
meanderSettingsDialog( dummy );
statusPopup->Show();
statusPopup.Show();
}
}

View File

@ -1363,36 +1363,33 @@ int EDIT_TOOL::EditFpInFpEditor( const TOOL_EVENT& aEvent )
bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aReferencePoint )
{
std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint";
// Do not create statusPopup on the stack:
// it crashes pcbnew when closing the current main frame
// (perhaps due to stack switching in coroutines)
std::unique_ptr<STATUS_TEXT_POPUP> statusPopup( new STATUS_TEXT_POPUP( frame() ) );
STATUS_TEXT_POPUP statusPopup( frame() );
PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool<PCBNEW_PICKER_TOOL>();
OPT<VECTOR2I> pickedPoint;
bool done = false;
statusPopup->SetText( _( "Select reference point for the copy..." ) );
statusPopup.SetText( _( "Select reference point for the copy..." ) );
picker->SetClickHandler(
[&]( const VECTOR2D& aPoint ) -> bool
{
pickedPoint = aPoint;
statusPopup->SetText( _( "Selection copied." ) );
statusPopup->Expire( 800 );
statusPopup.SetText( _( "Selection copied." ) );
statusPopup.Expire( 800 );
return false; // we don't need any more points
} );
picker->SetMotionHandler(
[&] ( const VECTOR2D& aPos )
{
statusPopup->Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
} );
picker->SetCancelHandler(
[&]()
{
statusPopup->SetText( _( "Copy cancelled." ) );
statusPopup->Expire( 800 );
statusPopup.SetText( _( "Copy cancelled." ) );
statusPopup.Expire( 800 );
} );
picker->SetFinalizeHandler(
@ -1401,8 +1398,8 @@ bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aReferencePoint )
done = true;
} );
statusPopup->Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
statusPopup->Popup();
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
statusPopup.Popup();
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
@ -1410,7 +1407,7 @@ bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aReferencePoint )
Wait();
// Ensure statusPopup is hidden after use and before deleting it:
statusPopup->Hide();
statusPopup.Hide();
if( pickedPoint.is_initialized() )
aReferencePoint = pickedPoint.get();