diff --git a/common/tool/tool_base.cpp b/common/tool/tool_base.cpp index f9191d52d4..6f531cf55e 100644 --- a/common/tool/tool_base.cpp +++ b/common/tool/tool_base.cpp @@ -27,6 +27,11 @@ #include // LAME! +bool TOOL_BASE::IsToolActive() const +{ + return m_toolMgr->IsToolActive( m_toolId ); +} + KIGFX::VIEW* TOOL_BASE::getView() const { return m_toolMgr->GetView(); diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 91da2319c7..d1c7f95fc5 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -580,6 +580,7 @@ void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) // got match? Run the handler. pushViewControls(); applyViewControls( st ); + st->idle = false; st->cofunc->Call( aEvent ); saveViewControls( st ); popViewControls(); @@ -721,6 +722,7 @@ TOOL_MANAGER::ID_LIST::iterator TOOL_MANAGER::finishTool( TOOL_STATE* aState ) if( tool->GetType() == INTERACTIVE ) static_cast( tool )->resetTransitions(); + aState->idle = true; return it; } @@ -875,3 +877,9 @@ void TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent ) processEvent( event ); } } + +bool TOOL_MANAGER::IsToolActive( TOOL_ID aId ) const +{ + auto it = m_toolIdIndex.find( aId ); + return !it->second->idle; +} diff --git a/include/tool/tool_base.h b/include/tool/tool_base.h index 549e95ad9d..167c51d450 100644 --- a/include/tool/tool_base.h +++ b/include/tool/tool_base.h @@ -148,6 +148,8 @@ public: TOOL_SETTINGS& GetSettings(); + bool IsToolActive() const; + protected: friend class TOOL_MANAGER; friend class TOOL_SETTINGS; diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index cdc600f7f0..19b331614c 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -202,6 +202,14 @@ public: */ void DeactivateTool(); + + /** + * Function IsToolActive() + * Returns true if a tool with given id is active (executing) + */ + bool IsToolActive( TOOL_ID aId ) const; + + /** * Function ResetTools() * Resets all tools (i.e. calls their Reset() method). diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index b44c09bc44..06bcf674d3 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -307,16 +307,20 @@ bool EDIT_TOOL::Init() bool EDIT_TOOL::invokeInlineRouter( int aDragMode ) { + auto theRouter = static_cast( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) ); + + if( !theRouter ) + return false; + + // make sure we don't accidentally invoke inline routing mode while the router is already active! + if ( theRouter->IsToolActive() ) + return false; + TRACK* track = uniqueSelected(); VIA* via = uniqueSelected(); if( track || via ) { - auto theRouter = static_cast( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) ); - - if( !theRouter ) - return false; - m_toolMgr->RunAction( PCB_ACTIONS::routerInlineDrag, true, aDragMode ); return true; }