From 7c1049d86ba0cdab10218dd55bee322c8387cd57 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 17 Jul 2019 21:19:23 +0100 Subject: [PATCH] Fix event-loop issue with some pickers. RunAction returns immediately even when called with "run now" flag. Fixes: lp:1836905 * https://bugs.launchpad.net/kicad/+bug/1836905 --- pcbnew/tools/edit_tool.cpp | 25 ++++++++++++++++++------- pcbnew/tools/edit_tool.h | 15 ++++++++------- pcbnew/tools/position_relative_tool.cpp | 13 +++++++++++-- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index e768b9fbc0..675b91d3cf 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -1286,19 +1286,20 @@ int EDIT_TOOL::EditFpInFpEditor( const TOOL_EVENT& aEvent ) } -bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aP ) +bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aReferencePoint ) { std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint"; STATUS_TEXT_POPUP statusPopup( frame() ); PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); - bool retVal = true; + OPT pickedPoint; + bool done = false; statusPopup.SetText( _( "Select reference point for the copy..." ) ); picker->SetClickHandler( [&]( const VECTOR2D& aPoint ) -> bool { - aP = aPoint; + pickedPoint = aPoint; statusPopup.SetText( _( "Selection copied." ) ); statusPopup.Expire( 800 ); return false; // we don't need any more points @@ -1307,7 +1308,7 @@ bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aP ) picker->SetMotionHandler( [&] ( const VECTOR2D& aPos ) { - statusPopup.Move( aPos + wxPoint( 20, -50 ) ); + statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) ); } ); picker->SetCancelHandler( @@ -1315,7 +1316,12 @@ bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aP ) { statusPopup.SetText( _( "Copy cancelled." ) ); statusPopup.Expire( 800 ); - retVal = false; + } ); + + picker->SetFinalizeHandler( + [&]( const int& aFinalState ) + { + done = true; } ); statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) ); @@ -1323,8 +1329,13 @@ bool EDIT_TOOL::pickCopyReferencePoint( VECTOR2I& aP ) m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - statusPopup.Hide(); - return retVal; + while( !done ) + Wait(); + + if( pickedPoint.is_initialized() ) + aReferencePoint = pickedPoint.get(); + + return pickedPoint.is_initialized(); } diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 21fbd73a28..d50847324a 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -35,6 +35,7 @@ class BOARD_COMMIT; class BOARD_ITEM; class CONNECTIVITY_DATA; +class STATUS_TEXT_POPUP; namespace KIGFX { namespace PREVIEW { @@ -168,12 +169,6 @@ public: BOARD_COMMIT* GetCurrentCommit() const { return m_commit.get(); } private: - SELECTION_TOOL* m_selectionTool; // Selection tool used for obtaining selected items - bool m_dragging; // Indicates objects are being dragged right now - bool m_lockedSelected; // Determines if we prompt before removing locked objects - VECTOR2I m_cursor; // Last cursor position (needed for getModificationPoint() - // to avoid changes of edit reference point). - ///> Returns the right modification point (e.g. for rotation), depending on the number of ///> selected items. bool updateModificationPoint( PCBNEW_SELECTION& aSelection ); @@ -184,8 +179,14 @@ private: bool isInteractiveDragEnabled() const; bool changeTrackWidthOnClick( const PCBNEW_SELECTION& selection ); - bool pickCopyReferencePoint( VECTOR2I& aP ); + bool pickCopyReferencePoint( VECTOR2I& aReferencePoint ); +private: + SELECTION_TOOL* m_selectionTool; // Selection tool used for obtaining selected items + bool m_dragging; // Indicates objects are being dragged right now + bool m_lockedSelected; // Determines if we prompt before removing locked objects + VECTOR2I m_cursor; // Last cursor position (needed for getModificationPoint() + // to avoid changes of edit reference point). std::unique_ptr m_commit; }; diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index 9a97730614..fe57ea3cb2 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -125,6 +125,7 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent std::string tool = "pcbnew.PositionRelative.selectReferenceItem"; PCBNEW_PICKER_TOOL* picker = m_toolMgr->GetTool(); STATUS_TEXT_POPUP statusPopup( frame() ); + bool done = false; statusPopup.SetText( _( "Select reference item..." ) ); @@ -153,7 +154,7 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent picker->SetMotionHandler( [&] ( const VECTOR2D& aPos ) { - statusPopup.Move( aPos + wxPoint( 20, -50 ) ); + statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) ); } ); picker->SetCancelHandler( @@ -165,12 +166,20 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent m_dialog->UpdateAnchor( m_anchor_item ); } ); + picker->SetFinalizeHandler( + [&]( const int& aFinalState ) + { + done = true; + } ); + statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) ); statusPopup.Popup(); m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); - statusPopup.Hide(); + while( !done ) + Wait(); + return 0; }