From 543d4af682779e16d914c08c96b6b374f4ab4806 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 15 Aug 2013 10:20:49 +0200 Subject: [PATCH] Added resetting of tools after loading a new board. --- common/tool/tool_manager.cpp | 12 +++++++++--- include/tool/tool_manager.h | 7 +++---- pcbnew/tools/selection_tool.cpp | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 95c743cc26..f659b681b0 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -145,7 +145,7 @@ void TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent ) { st->transitions.clear(); - if(!st->cofunc) + if( !st->cofunc ) st->cofunc = new COROUTINE( tr.second ); else st->cofunc->SetEntry( tr.second ); @@ -174,7 +174,7 @@ bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent ) if( st->contextMenuTrigger == CMENU_NOW ) { st->pendingWait = true; - st->waitEvents = TOOL_EVENT ( TC_Any, TA_Any ); + st->waitEvents = TOOL_EVENT( TC_Any, TA_Any ); st->contextMenuTrigger = CMENU_OFF; GetEditFrame()->PopupMenu( st->contextMenu->GetMenu() ); @@ -222,5 +222,11 @@ void TOOL_MANAGER::SetEnvironment( EDA_ITEM* aModel, KiGfx::VIEW* aView, m_view = aView; m_viewControls = aViewControls; m_editFrame = aFrame; - // fixme: reset tools after changing environment + + // Reset state of the registered tools + BOOST_FOREACH( TOOL_BASE* tool, m_toolState | boost::adaptors::map_keys ) + { + if( tool->GetType() == TOOL_Interactive ) + static_cast( tool )->Reset(); + } } diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index dc7e62ee8f..f428806a0b 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -78,19 +78,18 @@ public: template void InvokeTool( const std::string& name, const Parameters& aToolParams ); - /** * Function FindTool() * Searches for a tool with given name or ID */ - TOOL_BASE *FindTool( int aId ); - TOOL_BASE *FindTool( const std::string& aName ); + TOOL_BASE* FindTool( int aId ); + TOOL_BASE* FindTool( const std::string& aName ); /** * Resets the state of a given tool by clearing its wait and * transition lists and calling tool's internal Reset() method. */ - void ResetTool( TOOL_BASE *aTool ); + void ResetTool( TOOL_BASE* aTool ); /** * Takes an event from the TOOL_DISPATCHER and propagates it to diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 8b24d53d11..14e1b0e403 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -57,6 +57,8 @@ SELECTION_TOOL::~SELECTION_TOOL() void SELECTION_TOOL::Reset() { + m_selectedItems.clear(); + // the tool launches upon reception of activate ("pcbnew.InteractiveSelection") Go( &SELECTION_TOOL::Main, TOOL_EVENT( TC_Command, TA_ActivateTool, GetName() ) ); //"pcbnew.InteractiveSelection")); }