2013-08-06 08:30:09 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-01-18 08:04:11 +00:00
|
|
|
* Copyright (C) 2013-2017 CERN
|
2013-08-06 08:30:09 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-27 16:51:21 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
2013-08-06 08:30:09 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2013-08-02 14:46:53 +00:00
|
|
|
#include <map>
|
2014-07-09 11:50:27 +00:00
|
|
|
#include <stack>
|
|
|
|
#include <algorithm>
|
2013-08-02 14:46:53 +00:00
|
|
|
|
|
|
|
#include <boost/optional.hpp>
|
|
|
|
|
|
|
|
#include <wx/event.h>
|
2014-07-09 12:01:07 +00:00
|
|
|
#include <wx/clipbrd.h>
|
2013-08-02 14:46:53 +00:00
|
|
|
|
|
|
|
#include <view/view.h>
|
|
|
|
|
|
|
|
#include <tool/tool_base.h>
|
|
|
|
#include <tool/tool_interactive.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tool/context_menu.h>
|
|
|
|
#include <tool/coroutine.h>
|
2013-09-27 16:51:21 +00:00
|
|
|
#include <tool/action_manager.h>
|
2013-08-02 14:46:53 +00:00
|
|
|
|
|
|
|
#include <wxPcbStruct.h>
|
2014-04-04 09:56:04 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
2013-08-02 14:46:53 +00:00
|
|
|
|
|
|
|
using boost::optional;
|
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
/// Struct describing the current execution state of a TOOL
|
2013-09-02 12:21:12 +00:00
|
|
|
struct TOOL_MANAGER::TOOL_STATE
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
TOOL_STATE( TOOL_BASE* aTool ) :
|
|
|
|
theTool( aTool )
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
TOOL_STATE( const TOOL_STATE& aState )
|
|
|
|
{
|
|
|
|
theTool = aState.theTool;
|
|
|
|
idle = aState.idle;
|
|
|
|
pendingWait = aState.pendingWait;
|
|
|
|
pendingContextMenu = aState.pendingContextMenu;
|
|
|
|
contextMenu = aState.contextMenu;
|
|
|
|
contextMenuTrigger = aState.contextMenuTrigger;
|
|
|
|
cofunc = aState.cofunc;
|
|
|
|
wakeupEvent = aState.wakeupEvent;
|
|
|
|
waitEvents = aState.waitEvents;
|
|
|
|
transitions = aState.transitions;
|
2017-02-11 20:26:08 +00:00
|
|
|
vcSettings = aState.vcSettings;
|
2014-07-09 11:50:27 +00:00
|
|
|
// do not copy stateStack
|
|
|
|
}
|
|
|
|
|
|
|
|
~TOOL_STATE()
|
|
|
|
{
|
|
|
|
assert( stateStack.empty() );
|
|
|
|
}
|
|
|
|
|
2013-09-02 12:21:12 +00:00
|
|
|
/// The tool itself
|
2013-10-14 11:43:57 +00:00
|
|
|
TOOL_BASE* theTool;
|
2013-09-02 12:21:12 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
/// Is the tool active (pending execution) or disabled at the moment
|
|
|
|
bool idle;
|
2013-09-02 12:21:12 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
/// Flag defining if the tool is waiting for any event (i.e. if it
|
|
|
|
/// issued a Wait() call).
|
|
|
|
bool pendingWait;
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
/// Is there a context menu being displayed
|
|
|
|
bool pendingContextMenu;
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
/// Context menu currently used by the tool
|
|
|
|
CONTEXT_MENU* contextMenu;
|
2013-09-02 12:21:12 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
/// Defines when the context menu is opened
|
|
|
|
CONTEXT_MENU_TRIGGER contextMenuTrigger;
|
2013-09-02 12:21:12 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
/// Tool execution context
|
2015-02-14 20:28:47 +00:00
|
|
|
COROUTINE<int, const TOOL_EVENT&>* cofunc;
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
/// The event that triggered the execution/wakeup of the tool after Wait() call
|
|
|
|
TOOL_EVENT wakeupEvent;
|
2013-09-24 13:47:07 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
/// List of events the tool is currently waiting for
|
|
|
|
TOOL_EVENT_LIST waitEvents;
|
|
|
|
|
|
|
|
/// List of possible transitions (ie. association of events and state handlers that are executed
|
|
|
|
/// upon the event reception
|
|
|
|
std::vector<TRANSITION> transitions;
|
|
|
|
|
2017-02-11 20:26:08 +00:00
|
|
|
/// VIEW_CONTROLS settings to preserve settings when the tools are switched
|
2017-03-06 10:41:06 +00:00
|
|
|
KIGFX::VC_SETTINGS vcSettings;
|
2017-02-11 20:26:08 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
void operator=( const TOOL_STATE& aState )
|
|
|
|
{
|
|
|
|
theTool = aState.theTool;
|
|
|
|
idle = aState.idle;
|
|
|
|
pendingWait = aState.pendingWait;
|
|
|
|
pendingContextMenu = aState.pendingContextMenu;
|
|
|
|
contextMenu = aState.contextMenu;
|
|
|
|
contextMenuTrigger = aState.contextMenuTrigger;
|
|
|
|
cofunc = aState.cofunc;
|
|
|
|
wakeupEvent = aState.wakeupEvent;
|
|
|
|
waitEvents = aState.waitEvents;
|
|
|
|
transitions = aState.transitions;
|
2017-02-11 20:26:08 +00:00
|
|
|
vcSettings = aState.vcSettings;
|
2014-07-09 11:50:27 +00:00
|
|
|
// do not copy stateStack
|
|
|
|
}
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
bool operator==( const TOOL_MANAGER::TOOL_STATE& aRhs ) const
|
2013-09-24 13:47:07 +00:00
|
|
|
{
|
2013-10-14 14:13:35 +00:00
|
|
|
return aRhs.theTool == this->theTool;
|
2013-09-24 13:47:07 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
bool operator!=( const TOOL_MANAGER::TOOL_STATE& aRhs ) const
|
2013-09-24 13:47:07 +00:00
|
|
|
{
|
2013-10-14 14:13:35 +00:00
|
|
|
return aRhs.theTool != this->theTool;
|
2013-09-24 13:47:07 +00:00
|
|
|
}
|
2014-07-09 11:50:27 +00:00
|
|
|
|
2014-07-09 12:23:13 +00:00
|
|
|
/**
|
|
|
|
* Function Push()
|
|
|
|
* Stores the current state of the tool on stack. Stacks are stored internally and are not
|
|
|
|
* shared between different TOOL_STATE objects.
|
|
|
|
*/
|
2014-07-09 11:50:27 +00:00
|
|
|
void Push()
|
|
|
|
{
|
2017-02-11 20:26:08 +00:00
|
|
|
auto state = std::make_unique<TOOL_STATE>( *this );
|
|
|
|
stateStack.push( std::move( state ) );
|
2014-07-09 11:50:27 +00:00
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:23:13 +00:00
|
|
|
/**
|
|
|
|
* Function Pop()
|
|
|
|
* Restores state of the tool from stack. Stacks are stored internally and are not
|
|
|
|
* shared between different TOOL_STATE objects.
|
|
|
|
* @return True if state was restored, false if the stack was empty.
|
|
|
|
*/
|
2014-07-09 11:50:27 +00:00
|
|
|
bool Pop()
|
|
|
|
{
|
|
|
|
delete cofunc;
|
|
|
|
|
|
|
|
if( !stateStack.empty() )
|
|
|
|
{
|
2017-02-11 20:26:08 +00:00
|
|
|
*this = *stateStack.top().get();
|
2014-07-09 11:50:27 +00:00
|
|
|
stateStack.pop();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cofunc = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
///> Stack preserving previous states of a TOOL.
|
2017-02-11 20:26:08 +00:00
|
|
|
std::stack<std::unique_ptr<TOOL_STATE>> stateStack;
|
2014-07-09 11:50:27 +00:00
|
|
|
|
|
|
|
///> Restores the initial state.
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
idle = true;
|
|
|
|
pendingWait = false;
|
|
|
|
pendingContextMenu = false;
|
|
|
|
cofunc = NULL;
|
|
|
|
contextMenu = NULL;
|
|
|
|
contextMenuTrigger = CMENU_OFF;
|
2017-02-11 20:26:08 +00:00
|
|
|
vcSettings.Reset();
|
2014-07-09 11:50:27 +00:00
|
|
|
transitions.clear();
|
|
|
|
}
|
2013-08-02 14:46:53 +00:00
|
|
|
};
|
|
|
|
|
2013-08-08 12:59:59 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
TOOL_MANAGER::TOOL_MANAGER() :
|
2015-03-11 16:04:20 +00:00
|
|
|
m_model( NULL ),
|
|
|
|
m_view( NULL ),
|
|
|
|
m_viewControls( NULL ),
|
|
|
|
m_editFrame( NULL ),
|
2017-03-06 10:49:52 +00:00
|
|
|
m_passEvent( false ),
|
|
|
|
m_menuActive( false )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-09-27 16:51:21 +00:00
|
|
|
m_actionMgr = new ACTION_MANAGER( this );
|
2017-03-06 10:49:52 +00:00
|
|
|
|
|
|
|
// Keep default VIEW_CONTROLS settings at the bottom of the stack
|
|
|
|
m_vcStack.push( KIGFX::VC_SETTINGS() );
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-08 12:59:59 +00:00
|
|
|
|
2013-09-11 17:37:52 +00:00
|
|
|
TOOL_MANAGER::~TOOL_MANAGER()
|
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
std::map<TOOL_BASE*, TOOL_STATE*>::iterator it, it_end;
|
2013-09-11 17:37:52 +00:00
|
|
|
|
|
|
|
for( it = m_toolState.begin(), it_end = m_toolState.end(); it != it_end; ++it )
|
|
|
|
{
|
|
|
|
delete it->second->cofunc; // delete cofunction
|
|
|
|
delete it->second; // delete TOOL_STATE
|
|
|
|
delete it->first; // delete the tool itself
|
|
|
|
}
|
2013-09-27 16:51:21 +00:00
|
|
|
|
2014-05-14 14:29:53 +00:00
|
|
|
delete m_actionMgr;
|
2013-09-11 17:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-08 12:50:32 +00:00
|
|
|
void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-12-03 14:17:43 +00:00
|
|
|
wxASSERT_MSG( m_toolNameIndex.find( aTool->GetName() ) == m_toolNameIndex.end(),
|
|
|
|
wxT( "Adding two tools with the same name may result in unexpected behaviour.") );
|
|
|
|
wxASSERT_MSG( m_toolIdIndex.find( aTool->GetId() ) == m_toolIdIndex.end(),
|
|
|
|
wxT( "Adding two tools with the same ID may result in unexpected behaviour.") );
|
2014-07-09 09:59:24 +00:00
|
|
|
wxASSERT_MSG( m_toolTypes.find( typeid( *aTool ).name() ) == m_toolTypes.end(),
|
|
|
|
wxT( "Adding two tools of the same type may result in unexpected behaviour.") );
|
2013-12-03 14:17:43 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
TOOL_STATE* st = new TOOL_STATE( aTool );
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
m_toolState[aTool] = st;
|
|
|
|
m_toolNameIndex[aTool->GetName()] = st;
|
|
|
|
m_toolIdIndex[aTool->GetId()] = st;
|
2014-07-09 09:59:24 +00:00
|
|
|
m_toolTypes[typeid( *aTool ).name()] = st->theTool;
|
2013-10-14 11:43:57 +00:00
|
|
|
|
2015-07-02 14:09:51 +00:00
|
|
|
aTool->attachManager( this );
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:30:09 +00:00
|
|
|
|
2013-08-30 08:37:26 +00:00
|
|
|
bool TOOL_MANAGER::InvokeTool( TOOL_ID aToolId )
|
2013-08-20 12:49:08 +00:00
|
|
|
{
|
|
|
|
TOOL_BASE* tool = FindTool( aToolId );
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
if( tool && tool->GetType() == INTERACTIVE )
|
2013-09-19 15:02:57 +00:00
|
|
|
return invokeTool( tool );
|
2013-08-30 08:37:26 +00:00
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
return false; // there is no tool with the given id
|
2013-09-19 15:02:57 +00:00
|
|
|
}
|
2013-08-22 13:07:34 +00:00
|
|
|
|
2013-08-30 08:37:26 +00:00
|
|
|
|
2013-09-19 15:02:57 +00:00
|
|
|
bool TOOL_MANAGER::InvokeTool( const std::string& aToolName )
|
|
|
|
{
|
|
|
|
TOOL_BASE* tool = FindTool( aToolName );
|
2013-08-30 08:37:26 +00:00
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
if( tool && tool->GetType() == INTERACTIVE )
|
2013-09-19 15:02:57 +00:00
|
|
|
return invokeTool( tool );
|
2013-08-30 08:37:26 +00:00
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
return false; // there is no tool with the given name
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TOOL_MANAGER::RegisterAction( TOOL_ACTION* aAction )
|
|
|
|
{
|
|
|
|
m_actionMgr->RegisterAction( aAction );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TOOL_MANAGER::UnregisterAction( TOOL_ACTION* aAction )
|
|
|
|
{
|
|
|
|
m_actionMgr->UnregisterAction( aAction );
|
2013-08-20 12:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-21 10:28:34 +00:00
|
|
|
bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* aParam )
|
2013-12-03 14:41:41 +00:00
|
|
|
{
|
2014-07-09 14:25:50 +00:00
|
|
|
TOOL_ACTION* action = m_actionMgr->FindAction( aActionName );
|
|
|
|
|
2017-03-03 13:53:55 +00:00
|
|
|
if( !action )
|
2014-07-09 14:25:50 +00:00
|
|
|
{
|
2017-03-03 13:53:55 +00:00
|
|
|
wxASSERT_MSG( false, wxString::Format( wxT( "Could not find action %s." ), aActionName ) );
|
|
|
|
return false;
|
2014-07-09 14:25:50 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 13:53:55 +00:00
|
|
|
RunAction( *action, aNow, aParam );
|
2015-04-30 08:46:08 +00:00
|
|
|
|
2014-07-09 14:25:50 +00:00
|
|
|
return false;
|
2013-12-03 14:41:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-21 10:28:34 +00:00
|
|
|
void TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam )
|
2014-02-28 14:46:05 +00:00
|
|
|
{
|
2014-11-21 10:28:34 +00:00
|
|
|
TOOL_EVENT event = aAction.MakeEvent();
|
2015-04-30 08:46:01 +00:00
|
|
|
|
|
|
|
// Allow to override the action parameter
|
|
|
|
if( aParam )
|
|
|
|
event.SetParameter( aParam );
|
2014-11-21 10:28:34 +00:00
|
|
|
|
2014-07-09 14:25:50 +00:00
|
|
|
if( aNow )
|
2017-03-06 10:49:52 +00:00
|
|
|
processEvent( event );
|
2014-07-09 14:25:50 +00:00
|
|
|
else
|
2014-11-21 10:28:34 +00:00
|
|
|
PostEvent( event );
|
2014-02-28 14:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-28 08:29:00 +00:00
|
|
|
int TOOL_MANAGER::GetHotKey( const TOOL_ACTION& aAction )
|
|
|
|
{
|
|
|
|
return m_actionMgr->GetHotKey( aAction );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-05 18:39:42 +00:00
|
|
|
void TOOL_MANAGER::UpdateHotKeys()
|
|
|
|
{
|
|
|
|
m_actionMgr->UpdateHotKeys();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-19 15:02:57 +00:00
|
|
|
bool TOOL_MANAGER::invokeTool( TOOL_BASE* aTool )
|
2013-08-20 12:49:08 +00:00
|
|
|
{
|
2013-09-19 15:02:57 +00:00
|
|
|
wxASSERT( aTool != NULL );
|
2013-08-20 12:49:08 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
TOOL_EVENT evt( TC_COMMAND, TA_ACTIVATE, aTool->GetName() );
|
2017-03-06 10:49:52 +00:00
|
|
|
processEvent( evt );
|
2013-09-19 15:02:57 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TOOL_MANAGER::runTool( TOOL_ID aToolId )
|
|
|
|
{
|
|
|
|
TOOL_BASE* tool = FindTool( aToolId );
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
if( tool && tool->GetType() == INTERACTIVE )
|
2013-09-19 15:02:57 +00:00
|
|
|
return runTool( tool );
|
2013-08-30 08:37:26 +00:00
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
return false; // there is no tool with the given id
|
2013-08-20 12:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-19 15:02:57 +00:00
|
|
|
bool TOOL_MANAGER::runTool( const std::string& aToolName )
|
|
|
|
{
|
|
|
|
TOOL_BASE* tool = FindTool( aToolName );
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
if( tool && tool->GetType() == INTERACTIVE )
|
2013-09-19 15:02:57 +00:00
|
|
|
return runTool( tool );
|
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
return false; // there is no tool with the given name
|
2013-09-19 15:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TOOL_MANAGER::runTool( TOOL_BASE* aTool )
|
|
|
|
{
|
|
|
|
wxASSERT( aTool != NULL );
|
|
|
|
|
|
|
|
if( !isRegistered( aTool ) )
|
2013-12-03 14:17:43 +00:00
|
|
|
{
|
|
|
|
wxASSERT_MSG( false, wxT( "You cannot run unregistered tools" ) );
|
2013-09-19 15:02:57 +00:00
|
|
|
return false;
|
2013-12-03 14:17:43 +00:00
|
|
|
}
|
2013-09-19 15:02:57 +00:00
|
|
|
|
2017-02-11 20:26:08 +00:00
|
|
|
TOOL_ID id = aTool->GetId();
|
|
|
|
|
2014-04-01 12:35:09 +00:00
|
|
|
// If the tool is already active, bring it to the top of the active tools stack
|
2014-01-07 13:11:53 +00:00
|
|
|
if( isActive( aTool ) )
|
2014-04-01 12:35:09 +00:00
|
|
|
{
|
2017-02-11 20:26:08 +00:00
|
|
|
m_activeTools.erase( std::find( m_activeTools.begin(), m_activeTools.end(), id ) );
|
|
|
|
m_activeTools.push_front( id );
|
2013-09-19 15:02:57 +00:00
|
|
|
return false;
|
2014-04-01 12:35:09 +00:00
|
|
|
}
|
2013-10-14 14:13:35 +00:00
|
|
|
|
2013-12-09 09:42:38 +00:00
|
|
|
aTool->Reset( TOOL_INTERACTIVE::RUN );
|
2015-04-30 08:46:03 +00:00
|
|
|
aTool->SetTransitions();
|
2013-09-19 15:02:57 +00:00
|
|
|
|
|
|
|
// Add the tool on the front of the processing queue (it gets events first)
|
2017-02-11 20:26:08 +00:00
|
|
|
m_activeTools.push_front( id );
|
2013-09-19 15:02:57 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-20 12:49:08 +00:00
|
|
|
TOOL_BASE* TOOL_MANAGER::FindTool( int aId ) const
|
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
std::map<TOOL_ID, TOOL_STATE*>::const_iterator it = m_toolIdIndex.find( aId );
|
2013-08-20 12:49:08 +00:00
|
|
|
|
|
|
|
if( it != m_toolIdIndex.end() )
|
|
|
|
return it->second->theTool;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TOOL_BASE* TOOL_MANAGER::FindTool( const std::string& aName ) const
|
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
std::map<std::string, TOOL_STATE*>::const_iterator it = m_toolNameIndex.find( aName );
|
2013-08-20 12:49:08 +00:00
|
|
|
|
|
|
|
if( it != m_toolNameIndex.end() )
|
|
|
|
return it->second->theTool;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-01-30 10:38:02 +00:00
|
|
|
|
2016-08-05 17:45:14 +00:00
|
|
|
void TOOL_MANAGER::DeactivateTool()
|
2013-12-09 09:42:38 +00:00
|
|
|
{
|
2017-02-11 20:26:08 +00:00
|
|
|
// Deactivate the active tool, but do not run anything new
|
|
|
|
TOOL_EVENT evt( TC_COMMAND, TA_CANCEL_TOOL );
|
2017-03-06 10:49:52 +00:00
|
|
|
processEvent( evt );
|
2016-08-05 17:45:14 +00:00
|
|
|
}
|
|
|
|
|
2017-01-30 10:38:02 +00:00
|
|
|
|
2016-08-05 17:45:14 +00:00
|
|
|
void TOOL_MANAGER::ResetTools( TOOL_BASE::RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
DeactivateTool();
|
2014-12-09 23:50:31 +00:00
|
|
|
|
2017-03-07 16:18:22 +00:00
|
|
|
for( auto& state : m_toolState )
|
2015-04-30 08:46:03 +00:00
|
|
|
{
|
2017-03-07 16:18:22 +00:00
|
|
|
state.first->Reset( aReason );
|
|
|
|
state.first->SetTransitions();
|
2015-04-30 08:46:03 +00:00
|
|
|
}
|
2013-12-09 09:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-30 10:38:02 +00:00
|
|
|
void TOOL_MANAGER::InitTools()
|
|
|
|
{
|
|
|
|
for( auto it = m_toolState.begin(); it != m_toolState.end(); /* iteration in the loop */ )
|
|
|
|
{
|
|
|
|
TOOL_BASE* tool = it->first;
|
|
|
|
TOOL_STATE* state = it->second;
|
|
|
|
++it; // keep the iterator valid if the element is going to be erased
|
|
|
|
|
|
|
|
if( !tool->Init() )
|
|
|
|
{
|
2017-02-23 07:30:29 +00:00
|
|
|
wxMessageBox(
|
2017-01-30 10:38:02 +00:00
|
|
|
wxString::Format( "Initialization of tool '%s' failed", tool->GetName() ) );
|
|
|
|
|
|
|
|
// Unregister the tool
|
|
|
|
m_toolState.erase( tool );
|
|
|
|
m_toolNameIndex.erase( tool->GetName() );
|
|
|
|
m_toolIdIndex.erase( tool->GetId() );
|
|
|
|
m_toolTypes.erase( typeid( *tool ).name() );
|
|
|
|
|
|
|
|
delete state;
|
|
|
|
delete tool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResetTools( TOOL_BASE::RUN );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-09 15:05:05 +00:00
|
|
|
int TOOL_MANAGER::GetPriority( int aToolId ) const
|
|
|
|
{
|
|
|
|
int priority = 0;
|
|
|
|
|
2016-08-08 15:20:02 +00:00
|
|
|
for( auto it = m_activeTools.begin(), itEnd = m_activeTools.end(); it != itEnd; ++it )
|
2014-04-09 15:05:05 +00:00
|
|
|
{
|
|
|
|
if( *it == aToolId )
|
|
|
|
return priority;
|
|
|
|
|
|
|
|
++priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-20 12:49:08 +00:00
|
|
|
void TOOL_MANAGER::ScheduleNextState( TOOL_BASE* aTool, TOOL_STATE_FUNC& aHandler,
|
2013-08-06 08:30:09 +00:00
|
|
|
const TOOL_EVENT_LIST& aConditions )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
TOOL_STATE* st = m_toolState[aTool];
|
2013-10-14 14:13:35 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
st->transitions.push_back( TRANSITION( aConditions, aHandler ) );
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:30:09 +00:00
|
|
|
|
2016-09-21 09:54:58 +00:00
|
|
|
void TOOL_MANAGER::RunMainStack( TOOL_BASE* aTool, std::function<void()> aFunc )
|
|
|
|
{
|
|
|
|
TOOL_STATE* st = m_toolState[aTool];
|
|
|
|
st->cofunc->RunMainStack( std::move( aFunc ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-19 07:47:36 +00:00
|
|
|
optional<TOOL_EVENT> TOOL_MANAGER::ScheduleWait( TOOL_BASE* aTool,
|
2013-08-06 08:30:09 +00:00
|
|
|
const TOOL_EVENT_LIST& aConditions )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
TOOL_STATE* st = m_toolState[aTool];
|
2013-09-27 16:51:21 +00:00
|
|
|
|
2017-02-23 10:36:52 +00:00
|
|
|
assert( !st->pendingWait ); // everything collapses on two KiYield() in a row
|
2014-07-09 14:25:50 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
// indicate to the manager that we are going to sleep and we shall be
|
|
|
|
// woken up when an event matching aConditions arrive
|
|
|
|
st->pendingWait = true;
|
|
|
|
st->waitEvents = aConditions;
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
// switch context back to event dispatcher loop
|
2017-02-23 07:30:29 +00:00
|
|
|
st->cofunc->KiYield();
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
return st->wakeupEvent;
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:30:09 +00:00
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
void TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
// iterate over all registered tools
|
2017-02-11 20:26:08 +00:00
|
|
|
for( auto it = m_activeTools.begin(); it != m_activeTools.end(); ++it )
|
2013-08-30 08:37:26 +00:00
|
|
|
{
|
2016-07-04 14:12:21 +00:00
|
|
|
TOOL_STATE* st = m_toolIdIndex[*it];
|
2013-08-30 08:37:26 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
// the tool state handler is waiting for events (i.e. called Wait() method)
|
|
|
|
if( st->pendingWait )
|
|
|
|
{
|
|
|
|
if( st->waitEvents.Matches( aEvent ) )
|
|
|
|
{
|
2014-07-09 13:10:32 +00:00
|
|
|
// By default, only messages are passed further
|
2015-07-15 12:08:52 +00:00
|
|
|
m_passEvent = ( aEvent.Category() == TC_MESSAGE );
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
// got matching event? clear wait list and wake up the coroutine
|
|
|
|
st->wakeupEvent = aEvent;
|
|
|
|
st->pendingWait = false;
|
|
|
|
st->waitEvents.clear();
|
2013-10-14 14:13:35 +00:00
|
|
|
|
2017-03-06 10:49:52 +00:00
|
|
|
if( st->cofunc )
|
|
|
|
{
|
|
|
|
pushViewControls();
|
|
|
|
applyViewControls( st );
|
|
|
|
bool end = !st->cofunc->Resume();
|
|
|
|
saveViewControls( st );
|
|
|
|
popViewControls();
|
|
|
|
|
|
|
|
if( end )
|
|
|
|
it = finishTool( st );
|
|
|
|
}
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
// If the tool did not request to propagate
|
|
|
|
// the event to other tools, we should stop it now
|
|
|
|
if( !m_passEvent )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-08-30 08:37:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 16:18:22 +00:00
|
|
|
for( auto& state : m_toolState )
|
2013-08-30 08:37:26 +00:00
|
|
|
{
|
2017-03-07 16:18:22 +00:00
|
|
|
TOOL_STATE* st = state.second;
|
2017-01-25 10:31:55 +00:00
|
|
|
bool finished = false;
|
2017-01-18 08:04:11 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
// no state handler in progress - check if there are any transitions (defined by
|
|
|
|
// Go() method that match the event.
|
2017-01-18 08:04:11 +00:00
|
|
|
if( !st->transitions.empty() )
|
2013-10-14 11:43:57 +00:00
|
|
|
{
|
2016-06-29 20:07:55 +00:00
|
|
|
for( TRANSITION& tr : st->transitions )
|
2013-10-14 11:43:57 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
if( tr.first.Matches( aEvent ) )
|
2013-10-14 11:43:57 +00:00
|
|
|
{
|
2016-08-02 08:34:27 +00:00
|
|
|
auto func_copy = tr.second;
|
|
|
|
|
2014-07-09 14:25:50 +00:00
|
|
|
// if there is already a context, then store it
|
2014-07-09 11:50:27 +00:00
|
|
|
if( st->cofunc )
|
|
|
|
st->Push();
|
|
|
|
|
2016-08-02 08:34:27 +00:00
|
|
|
st->cofunc = new COROUTINE<int, const TOOL_EVENT&>( std::move( func_copy ) );
|
2016-07-04 22:14:32 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
// as the state changes, the transition table has to be set up again
|
|
|
|
st->transitions.clear();
|
|
|
|
|
|
|
|
// got match? Run the handler.
|
2017-03-06 10:49:52 +00:00
|
|
|
pushViewControls();
|
|
|
|
applyViewControls( st );
|
2014-07-09 11:50:27 +00:00
|
|
|
st->cofunc->Call( aEvent );
|
2017-03-06 10:49:52 +00:00
|
|
|
saveViewControls( st );
|
|
|
|
popViewControls();
|
2014-07-09 11:50:27 +00:00
|
|
|
|
|
|
|
if( !st->cofunc->Running() )
|
|
|
|
finishTool( st ); // The couroutine has finished immediately?
|
|
|
|
|
2017-01-25 10:31:55 +00:00
|
|
|
// if it is a message, continue processing
|
|
|
|
finished = !( aEvent.Category() == TC_MESSAGE );
|
2017-01-18 08:04:11 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
// there is no point in further checking, as transitions got cleared
|
|
|
|
break;
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-18 08:04:11 +00:00
|
|
|
|
2017-01-25 10:31:55 +00:00
|
|
|
if( finished )
|
2017-01-18 08:04:11 +00:00
|
|
|
break; // only the first tool gets the event
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:30:09 +00:00
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
bool TOOL_MANAGER::dispatchStandardEvents( const TOOL_EVENT& aEvent )
|
2013-09-27 16:51:21 +00:00
|
|
|
{
|
2014-04-09 15:33:22 +00:00
|
|
|
if( aEvent.Action() == TA_KEY_PRESSED )
|
2013-09-27 16:51:21 +00:00
|
|
|
{
|
|
|
|
// Check if there is a hotkey associated
|
|
|
|
if( m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() ) )
|
2014-07-09 11:50:27 +00:00
|
|
|
return false; // hotkey event was handled so it does not go any further
|
2013-09-27 16:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
bool TOOL_MANAGER::dispatchActivation( const TOOL_EVENT& aEvent )
|
2013-09-19 15:02:57 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
if( aEvent.IsActivate() )
|
2013-09-19 15:02:57 +00:00
|
|
|
{
|
2015-07-15 12:08:52 +00:00
|
|
|
std::map<std::string, TOOL_STATE*>::iterator tool = m_toolNameIndex.find( *aEvent.GetCommandStr() );
|
2014-07-09 11:50:27 +00:00
|
|
|
|
|
|
|
if( tool != m_toolNameIndex.end() )
|
|
|
|
{
|
|
|
|
runTool( tool->second->theTool );
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-19 15:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent )
|
2013-08-30 08:37:26 +00:00
|
|
|
{
|
2017-02-24 15:39:52 +00:00
|
|
|
// Store the current tool ID to decide whether to restore the cursor position
|
|
|
|
TOOL_ID activeTool = GetCurrentToolId();
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( TOOL_ID toolId : m_activeTools )
|
2013-08-30 08:37:26 +00:00
|
|
|
{
|
2013-09-02 12:21:12 +00:00
|
|
|
TOOL_STATE* st = m_toolIdIndex[toolId];
|
2013-08-30 08:37:26 +00:00
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
// the tool requested a context menu. The menu is activated on RMB click (CMENU_BUTTON mode)
|
|
|
|
// or immediately (CMENU_NOW) mode. The latter is used for clarification lists.
|
2017-02-24 15:39:52 +00:00
|
|
|
if( st->contextMenuTrigger == CMENU_OFF )
|
|
|
|
continue;
|
2013-09-26 12:09:18 +00:00
|
|
|
|
2017-02-24 15:39:52 +00:00
|
|
|
if( st->contextMenuTrigger == CMENU_BUTTON && !aEvent.IsClick( BUT_RIGHT ) )
|
|
|
|
break;
|
2013-09-26 12:09:18 +00:00
|
|
|
|
2017-02-24 15:39:52 +00:00
|
|
|
st->pendingWait = true;
|
|
|
|
st->waitEvents = TOOL_EVENT( TC_ANY, TA_ANY );
|
2015-07-24 07:42:46 +00:00
|
|
|
|
2017-02-24 15:39:52 +00:00
|
|
|
// Store the menu pointer in case it is changed by the TOOL when handling menu events
|
|
|
|
CONTEXT_MENU* m = st->contextMenu;
|
2013-09-26 12:09:18 +00:00
|
|
|
|
2017-02-24 15:39:52 +00:00
|
|
|
if( st->contextMenuTrigger == CMENU_NOW )
|
|
|
|
st->contextMenuTrigger = CMENU_OFF;
|
2014-07-09 14:50:31 +00:00
|
|
|
|
2017-02-24 15:39:52 +00:00
|
|
|
VECTOR2D cursor = m_viewControls->GetCursorPosition();
|
2015-04-30 08:46:05 +00:00
|
|
|
|
2017-02-24 15:39:52 +00:00
|
|
|
// Temporarily store the cursor position, so the tools could execute actions
|
|
|
|
// using the point where the user has invoked a context menu
|
|
|
|
if( m_viewControls->ForcedCursorPosition() )
|
|
|
|
m_origCursor = cursor;
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2017-02-24 15:39:52 +00:00
|
|
|
m_viewControls->ForceCursorPosition( true, cursor );
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2017-02-24 15:39:52 +00:00
|
|
|
// Display a copy of menu
|
|
|
|
std::unique_ptr<CONTEXT_MENU> menu( m->Clone() );
|
|
|
|
|
|
|
|
// Run update handlers on the created copy
|
|
|
|
menu->UpdateAll();
|
2017-03-06 10:49:52 +00:00
|
|
|
m_menuActive = true;
|
2017-02-24 15:39:52 +00:00
|
|
|
GetEditFrame()->PopupMenu( menu.get() );
|
2017-03-06 10:49:52 +00:00
|
|
|
m_menuActive = false;
|
2017-02-24 15:39:52 +00:00
|
|
|
|
|
|
|
// If nothing was chosen from the context menu, we must notify the tool as well
|
|
|
|
if( menu->GetSelected() < 0 )
|
|
|
|
{
|
|
|
|
TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CHOICE, -1 );
|
2015-07-24 07:42:46 +00:00
|
|
|
evt.SetParameter( m );
|
2015-04-30 08:46:07 +00:00
|
|
|
dispatchInternal( evt );
|
2017-02-24 15:39:52 +00:00
|
|
|
}
|
2015-04-30 08:46:07 +00:00
|
|
|
|
2017-02-24 15:39:52 +00:00
|
|
|
// Notify the tools that menu has been closed
|
|
|
|
TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CLOSED );
|
|
|
|
evt.SetParameter( m );
|
|
|
|
dispatchInternal( evt );
|
|
|
|
|
|
|
|
// Restore the cursor settings if the tool is still active
|
|
|
|
if( activeTool == GetCurrentToolId() )
|
|
|
|
{
|
|
|
|
m_viewControls->ForceCursorPosition( (bool) m_origCursor,
|
2017-02-24 16:34:23 +00:00
|
|
|
m_origCursor.get_value_or( VECTOR2D( 0, 0 ) ) );
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|
2017-02-24 15:39:52 +00:00
|
|
|
|
|
|
|
m_origCursor = boost::none;
|
|
|
|
break;
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|
2014-07-09 11:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-11 20:26:08 +00:00
|
|
|
TOOL_MANAGER::ID_LIST::iterator TOOL_MANAGER::finishTool( TOOL_STATE* aState )
|
2014-07-09 11:50:27 +00:00
|
|
|
{
|
2017-02-11 20:26:08 +00:00
|
|
|
auto it = std::find( m_activeTools.begin(), m_activeTools.end(), aState->theTool->GetId() );
|
2016-07-04 14:12:21 +00:00
|
|
|
|
2017-02-11 20:26:08 +00:00
|
|
|
if( !aState->Pop() )
|
|
|
|
{
|
|
|
|
// Deactivate the tool if there are no other contexts saved on the stack
|
|
|
|
if( it != m_activeTools.end() )
|
|
|
|
it = m_activeTools.erase( it );
|
2014-07-09 11:50:27 +00:00
|
|
|
}
|
2015-04-30 08:46:03 +00:00
|
|
|
|
2017-01-18 08:04:11 +00:00
|
|
|
// Set transitions to be ready for future TOOL_EVENTs
|
2015-04-30 08:46:03 +00:00
|
|
|
aState->theTool->SetTransitions();
|
2017-04-03 22:56:30 +00:00
|
|
|
m_viewControls->ForceCursorPosition( false );
|
2016-07-04 14:12:21 +00:00
|
|
|
|
2017-02-11 20:26:08 +00:00
|
|
|
return it;
|
2014-07-09 11:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-06 10:49:52 +00:00
|
|
|
void TOOL_MANAGER::ProcessEvent( const TOOL_EVENT& aEvent )
|
2014-07-09 11:50:27 +00:00
|
|
|
{
|
2017-03-06 10:49:52 +00:00
|
|
|
processEvent( aEvent );
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2017-03-06 10:49:52 +00:00
|
|
|
if( TOOL_STATE* active = GetCurrentToolState() )
|
2014-07-09 14:25:50 +00:00
|
|
|
{
|
2017-03-06 10:49:52 +00:00
|
|
|
applyViewControls( active );
|
2014-07-09 14:25:50 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
if( m_view->IsDirty() )
|
|
|
|
{
|
2015-02-19 13:53:31 +00:00
|
|
|
EDA_DRAW_FRAME* f = static_cast<EDA_DRAW_FRAME*>( GetEditFrame() );
|
2014-05-13 09:22:51 +00:00
|
|
|
f->GetGalCanvas()->Refresh(); // fixme: ugly hack, provide a method in TOOL_DISPATCHER.
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:30:09 +00:00
|
|
|
|
|
|
|
void TOOL_MANAGER::ScheduleContextMenu( TOOL_BASE* aTool, CONTEXT_MENU* aMenu,
|
2013-09-02 12:21:12 +00:00
|
|
|
CONTEXT_MENU_TRIGGER aTrigger )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
TOOL_STATE* st = m_toolState[aTool];
|
|
|
|
|
|
|
|
st->contextMenu = aMenu;
|
|
|
|
st->contextMenuTrigger = aTrigger;
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:30:09 +00:00
|
|
|
|
2014-07-09 12:01:07 +00:00
|
|
|
bool TOOL_MANAGER::SaveClipboard( const std::string& aText )
|
|
|
|
{
|
|
|
|
if( wxTheClipboard->Open() )
|
|
|
|
{
|
2014-07-09 12:23:13 +00:00
|
|
|
wxTheClipboard->SetData( new wxTextDataObject( wxString( aText.c_str(), wxConvUTF8 ) ) );
|
2014-07-09 12:01:07 +00:00
|
|
|
wxTheClipboard->Close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string TOOL_MANAGER::GetClipboard() const
|
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
if( wxTheClipboard->Open() )
|
|
|
|
{
|
|
|
|
if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
|
|
|
|
{
|
|
|
|
wxTextDataObject data;
|
|
|
|
wxTheClipboard->GetData( data );
|
|
|
|
|
|
|
|
result = data.GetText().mb_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-06 08:30:09 +00:00
|
|
|
TOOL_ID TOOL_MANAGER::MakeToolId( const std::string& aToolName )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
static int currentId;
|
2013-10-14 14:13:35 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
return currentId++;
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 08:52:50 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
void TOOL_MANAGER::SetEnvironment( EDA_ITEM* aModel, KIGFX::VIEW* aView,
|
|
|
|
KIGFX::VIEW_CONTROLS* aViewControls, wxWindow* aFrame )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
m_model = aModel;
|
|
|
|
m_view = aView;
|
|
|
|
m_viewControls = aViewControls;
|
|
|
|
m_editFrame = aFrame;
|
2015-05-05 18:39:42 +00:00
|
|
|
m_actionMgr->UpdateHotKeys();
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
2013-09-19 15:02:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool TOOL_MANAGER::isActive( TOOL_BASE* aTool )
|
|
|
|
{
|
|
|
|
if( !isRegistered( aTool ) )
|
|
|
|
return false;
|
|
|
|
|
2014-01-07 13:11:53 +00:00
|
|
|
// Just check if the tool is on the active tools stack
|
|
|
|
return std::find( m_activeTools.begin(), m_activeTools.end(), aTool->GetId() ) != m_activeTools.end();
|
2013-09-19 15:02:57 +00:00
|
|
|
}
|
2017-03-02 11:02:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
void TOOL_MANAGER::saveViewControls( TOOL_STATE* aState )
|
|
|
|
{
|
|
|
|
aState->vcSettings = m_viewControls->GetSettings();
|
|
|
|
|
2017-03-06 10:49:52 +00:00
|
|
|
// If context menu has overridden the cursor position, restore the original position
|
2017-03-02 11:02:10 +00:00
|
|
|
// (see dispatchContextMenu())
|
2017-03-06 10:49:52 +00:00
|
|
|
if( m_menuActive )
|
2017-03-02 11:02:10 +00:00
|
|
|
{
|
2017-03-06 10:49:52 +00:00
|
|
|
if( m_origCursor )
|
|
|
|
{
|
|
|
|
aState->vcSettings.m_forceCursorPosition = true;
|
|
|
|
aState->vcSettings.m_forcedPosition = *m_origCursor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aState->vcSettings.m_forceCursorPosition = false;
|
|
|
|
}
|
2017-03-02 11:02:10 +00:00
|
|
|
}
|
2017-03-06 10:49:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TOOL_MANAGER::applyViewControls( TOOL_STATE* aState )
|
|
|
|
{
|
|
|
|
m_viewControls->ApplySettings( aState->vcSettings );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TOOL_MANAGER::pushViewControls()
|
|
|
|
{
|
|
|
|
m_vcStack.push( m_viewControls->GetSettings() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TOOL_MANAGER::popViewControls()
|
|
|
|
{
|
|
|
|
m_viewControls->ApplySettings( m_vcStack.top() );
|
|
|
|
m_vcStack.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
// Early dispatch of events destined for the TOOL_MANAGER
|
|
|
|
if( !dispatchStandardEvents( aEvent ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
dispatchInternal( aEvent );
|
|
|
|
dispatchActivation( aEvent );
|
|
|
|
dispatchContextMenu( aEvent );
|
|
|
|
|
|
|
|
// Dispatch queue
|
|
|
|
while( !m_eventQueue.empty() )
|
2017-03-02 11:02:10 +00:00
|
|
|
{
|
2017-03-06 10:49:52 +00:00
|
|
|
TOOL_EVENT event = m_eventQueue.front();
|
|
|
|
m_eventQueue.pop_front();
|
|
|
|
processEvent( event );
|
2017-03-02 11:02:10 +00:00
|
|
|
}
|
|
|
|
}
|