From 0bab025832b99b439c33ea93c07011b8b7049238 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 24 Feb 2021 10:43:12 -0800 Subject: [PATCH] Fixup toolchaining for immediate mode The move tool can stack on others, so when we re-enter the previous tool this caused another immediate action. We flag re-entry in the tool stack to check for this and avoid unexpected tool starts --- common/tool/tool_event.cpp | 1 + common/tool/tools_holder.cpp | 1 + eeschema/tools/sch_drawing_tools.cpp | 14 ++++++++------ eeschema/tools/symbol_editor_drawing_tools.cpp | 2 +- include/tool/tool_action.h | 2 ++ include/tool/tool_event.h | 14 ++++++++++++-- pagelayout_editor/tools/pl_drawing_tools.cpp | 2 +- pcbnew/tools/board_editor_control.cpp | 2 +- pcbnew/tools/drawing_tool.cpp | 3 ++- 9 files changed, 29 insertions(+), 12 deletions(-) diff --git a/common/tool/tool_event.cpp b/common/tool/tool_event.cpp index b18091c850..a54369cb63 100644 --- a/common/tool/tool_event.cpp +++ b/common/tool/tool_event.cpp @@ -63,6 +63,7 @@ void TOOL_EVENT::init() m_hasPosition = false; m_forceImmediate = false; + m_reactivate = false; } diff --git a/common/tool/tools_holder.cpp b/common/tool/tools_holder.cpp index 5dd4e1932b..64cc7aba77 100644 --- a/common/tool/tools_holder.cpp +++ b/common/tool/tools_holder.cpp @@ -83,6 +83,7 @@ void TOOLS_HOLDER::PopTool( const std::string& actionName ) TOOL_EVENT evt = action->MakeEvent(); evt.SetHasPosition( false ); + evt.SetReactivate( true ); GetToolManager()->PostEvent( evt ); } } diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 155e803108..9fe81665e7 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -84,7 +84,7 @@ bool SCH_DRAWING_TOOLS::Init() } -int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent ) +int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent ) { SCH_COMPONENT* component = aEvent.Parameter(); SCHLIB_FILTER filter; @@ -130,7 +130,7 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent ) getViewControls()->WarpCursor( getViewControls()->GetMousePosition( false ) ); m_toolMgr->RunAction( ACTIONS::refreshPreview ); } - else + else if( !aEvent.IsReactivate() ) { m_toolMgr->RunAction( EE_ACTIONS::cursorClick ); } @@ -357,7 +357,7 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent ) // Prime the pump if( image ) m_toolMgr->RunAction( ACTIONS::refreshPreview ); - else if( aEvent.HasPosition() ) + else if( !aEvent.IsReactivate() ) m_toolMgr->RunAction( ACTIONS::cursorClick ); auto setCursor = @@ -903,7 +903,6 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) SCH_ITEM* item = nullptr; KIGFX::VIEW_CONTROLS* controls = getViewControls(); EE_GRID_HELPER grid( m_toolMgr ); - if( m_inTwoClickPlace ) return 0; else @@ -924,8 +923,12 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) Activate(); // Prime the pump - if( aEvent.HasPosition() || isText || isGlobalLabel || isHierLabel || isNetLabel ) + // If the tool isn't being re-activated + if( aEvent.HasPosition() || ( !aEvent.IsReactivate() + && ( isText || isGlobalLabel || isHierLabel || isNetLabel ) ) ) + { m_toolMgr->RunAction( ACTIONS::cursorClick ); + } auto setCursor = [&]() @@ -997,7 +1000,6 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) } else if( evt->IsMoveTool() ) { - // leave ourselves on the stack so we come back after the move break; } else diff --git a/eeschema/tools/symbol_editor_drawing_tools.cpp b/eeschema/tools/symbol_editor_drawing_tools.cpp index 8f14b9f946..c0abf25745 100644 --- a/eeschema/tools/symbol_editor_drawing_tools.cpp +++ b/eeschema/tools/symbol_editor_drawing_tools.cpp @@ -85,7 +85,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) Activate(); // Prime the pump - if( aEvent.HasPosition() ) + if( aEvent.HasPosition() || ( isText && !aEvent.IsReactivate() ) ) m_toolMgr->RunAction( ACTIONS::cursorClick ); auto setCursor = diff --git a/include/tool/tool_action.h b/include/tool/tool_action.h index 4f12725fe0..6183f3f5d5 100644 --- a/include/tool/tool_action.h +++ b/include/tool/tool_action.h @@ -136,6 +136,8 @@ public: TOOL_ACTION_SCOPE GetScope() const { return m_scope; } + void* GetParam() const { return m_param; } + /** * Return name of the tool associated with the action. It is basically the action name * stripped of the last part (e.g. for "pcbnew.InteractiveDrawing.drawCircle" it is diff --git a/include/tool/tool_event.h b/include/tool/tool_event.h index 322da2f0a2..e61771364f 100644 --- a/include/tool/tool_event.h +++ b/include/tool/tool_event.h @@ -113,11 +113,14 @@ enum TOOL_ACTIONS // Tool activation event. TA_ACTIVATE = 0x100000, + // Tool re-activation event for tools already on the stack + TA_REACTIVATE = 0x200000, + // Model has changed (partial update). - TA_MODEL_CHANGE = 0x200000, + TA_MODEL_CHANGE = 0x400000, // Tool priming event (a special mouse click) - TA_PRIME = 0x400001, + TA_PRIME = 0x800001, TA_ANY = 0xffffffff }; @@ -266,6 +269,10 @@ public: TOOL_BASE* FirstResponder() const { return m_firstResponder; } void SetFirstResponder( TOOL_BASE* aTool ) { m_firstResponder = aTool; } + ///< Controls whether the tool is first being pushed to the stack or being reactivated after a pause + bool IsReactivate() const { return m_reactivate; } + void SetReactivate( bool aReactivate = true ) { m_reactivate = aReactivate; } + ///< Returns information about difference between current mouse cursor position and the place ///< where dragging has started. const VECTOR2D Delta() const @@ -527,6 +534,9 @@ private: bool m_hasPosition; bool m_forceImmediate; + ///< True when the tool is being re-activated from the stack + bool m_reactivate; + ///< Difference between mouse cursor position and ///< the point where dragging event has started VECTOR2D m_mouseDelta; diff --git a/pagelayout_editor/tools/pl_drawing_tools.cpp b/pagelayout_editor/tools/pl_drawing_tools.cpp index 39914ec48d..67573b80a0 100644 --- a/pagelayout_editor/tools/pl_drawing_tools.cpp +++ b/pagelayout_editor/tools/pl_drawing_tools.cpp @@ -88,7 +88,7 @@ int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent ) Activate(); // Prime the pump - if( aEvent.HasPosition() || isText ) + if( aEvent.HasPosition() || ( !aEvent.IsReactivate() && isText ) ) m_toolMgr->RunAction( ACTIONS::cursorClick ); auto setCursor = diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index 585a9281f4..bd4406f308 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -818,7 +818,7 @@ int BOARD_EDITOR_CONTROL::PlaceFootprint( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, fp ); m_toolMgr->RunAction( ACTIONS::refreshPreview ); } - else + else if( !aEvent.IsReactivate() ) m_toolMgr->RunAction( PCB_ACTIONS::cursorClick ); auto setCursor = diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 9e6b375d5a..8aa9970738 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -436,7 +436,8 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) Activate(); // Prime the pump - m_toolMgr->RunAction( ACTIONS::cursorClick ); + if( !aEvent.IsReactivate() ) + m_toolMgr->RunAction( ACTIONS::cursorClick ); auto setCursor = [&]()