2013-08-06 08:30:09 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* @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>
|
|
|
|
#include <deque>
|
|
|
|
|
|
|
|
#include <boost/foreach.hpp>
|
2013-09-26 12:09:18 +00:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
2013-08-02 14:46:53 +00:00
|
|
|
#include <boost/optional.hpp>
|
|
|
|
#include <boost/range/adaptor/map.hpp>
|
|
|
|
|
|
|
|
#include <wx/event.h>
|
|
|
|
|
|
|
|
#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>
|
2013-11-11 09:48:49 +00:00
|
|
|
#include <confirm.h>
|
2013-08-02 14:46:53 +00:00
|
|
|
#include <class_drawpanel_gal.h>
|
|
|
|
|
|
|
|
using boost::optional;
|
|
|
|
using namespace std;
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
|
COROUTINE<int, 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;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
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() :
|
2013-09-27 16:51:21 +00:00
|
|
|
m_model( NULL ), m_view( NULL )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-09-27 16:51:21 +00:00
|
|
|
m_actionMgr = new ACTION_MANAGER( this );
|
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()
|
|
|
|
{
|
|
|
|
std::map<TOOL_BASE*, TOOL_STATE*>::iterator it, it_end;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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-10-14 11:43:57 +00:00
|
|
|
TOOL_STATE* st = new TOOL_STATE;
|
|
|
|
|
|
|
|
st->theTool = aTool;
|
|
|
|
st->idle = true;
|
|
|
|
st->pendingWait = false;
|
|
|
|
st->pendingContextMenu = false;
|
|
|
|
st->cofunc = NULL;
|
|
|
|
st->contextMenuTrigger = CMENU_OFF;
|
|
|
|
|
|
|
|
m_toolState[aTool] = st;
|
|
|
|
m_toolNameIndex[aTool->GetName()] = st;
|
|
|
|
m_toolIdIndex[aTool->GetId()] = st;
|
|
|
|
|
|
|
|
aTool->m_toolMgr = this;
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
if( aTool->GetType() == INTERACTIVE )
|
2013-10-14 11:43:57 +00:00
|
|
|
{
|
2013-11-11 09:48:49 +00:00
|
|
|
if( !static_cast<TOOL_INTERACTIVE*>( aTool )->Init() )
|
2013-10-14 11:43:57 +00:00
|
|
|
{
|
2013-11-13 19:59:47 +00:00
|
|
|
std::string msg = StrPrintf( "Initialization of the %s tool failed", aTool->GetName().c_str() );
|
|
|
|
|
|
|
|
DisplayError( NULL, wxString::FromUTF8( msg.c_str() ) );
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
// Unregister the tool
|
|
|
|
m_toolState.erase( aTool );
|
|
|
|
m_toolNameIndex.erase( aTool->GetName() );
|
|
|
|
m_toolIdIndex.erase( aTool->GetId() );
|
|
|
|
|
|
|
|
delete st;
|
|
|
|
delete aTool;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
TOOL_EVENT evt( TC_COMMAND, TA_ACTION, aTool->GetName() );
|
2013-09-19 15:02:57 +00:00
|
|
|
ProcessEvent( evt );
|
|
|
|
|
|
|
|
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 ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TOOL_STATE* state = m_toolState[aTool];
|
|
|
|
|
|
|
|
// If the tool is already active, do not invoke it again
|
|
|
|
if( state->idle == false )
|
|
|
|
return false;
|
2013-10-14 14:13:35 +00:00
|
|
|
|
2013-09-19 15:02:57 +00:00
|
|
|
state->idle = false;
|
|
|
|
|
|
|
|
static_cast<TOOL_INTERACTIVE*>( aTool )->Reset();
|
|
|
|
|
|
|
|
// Add the tool on the front of the processing queue (it gets events first)
|
|
|
|
m_activeTools.push_front( aTool->GetId() );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-20 12:49:08 +00:00
|
|
|
TOOL_BASE* TOOL_MANAGER::FindTool( int aId ) const
|
|
|
|
{
|
2013-09-02 12:21:12 +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
|
|
|
|
{
|
2013-09-02 12:21:12 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
st->cofunc->Yield();
|
|
|
|
|
|
|
|
return st->wakeupEvent;
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:30:09 +00:00
|
|
|
|
|
|
|
void TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
// iterate over all registered tools
|
2013-08-30 08:37:26 +00:00
|
|
|
BOOST_FOREACH( TOOL_ID toolId, m_activeTools )
|
|
|
|
{
|
2013-09-02 12:21:12 +00:00
|
|
|
TOOL_STATE* st = m_toolIdIndex[toolId];
|
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 ) )
|
|
|
|
{
|
|
|
|
// By default, already processed events are not passed further
|
|
|
|
m_passEvent = false;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
if( st->cofunc && !st->cofunc->Resume() )
|
2013-10-14 14:13:35 +00:00
|
|
|
finishTool( st ); // The couroutine has finished
|
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
|
|
|
}
|
|
|
|
|
2013-09-02 12:21:12 +00:00
|
|
|
BOOST_FOREACH( TOOL_STATE* st, m_toolState | boost::adaptors::map_values )
|
2013-08-30 08:37:26 +00:00
|
|
|
{
|
2013-09-27 16:51:21 +00:00
|
|
|
// the tool scheduled next state(s) by calling Go()
|
2013-10-14 11:43:57 +00:00
|
|
|
if( !st->pendingWait )
|
|
|
|
{
|
|
|
|
// no state handler in progress - check if there are any transitions (defined by
|
|
|
|
// Go() method that match the event.
|
|
|
|
if( st->transitions.size() )
|
|
|
|
{
|
|
|
|
BOOST_FOREACH( TRANSITION tr, st->transitions )
|
|
|
|
{
|
|
|
|
if( tr.first.Matches( aEvent ) )
|
|
|
|
{
|
|
|
|
st->transitions.clear();
|
|
|
|
|
|
|
|
// no tool context allocated yet? Create one.
|
|
|
|
if( !st->cofunc )
|
|
|
|
st->cofunc = new COROUTINE<int, TOOL_EVENT&>( tr.second );
|
|
|
|
else
|
|
|
|
st->cofunc->SetEntry( tr.second );
|
|
|
|
|
|
|
|
// got match? Run the handler.
|
|
|
|
st->cofunc->Call( aEvent );
|
|
|
|
|
|
|
|
if( !st->cofunc->Running() )
|
2013-10-14 14:13:35 +00:00
|
|
|
finishTool( st ); // The couroutine has finished immediately?
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:30:09 +00:00
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
bool TOOL_MANAGER::dispatchStandardEvents( TOOL_EVENT& aEvent )
|
|
|
|
{
|
2013-10-14 18:40:36 +00:00
|
|
|
if( aEvent.Action() == TA_KEY_UP )
|
2013-09-27 16:51:21 +00:00
|
|
|
{
|
|
|
|
// Check if there is a hotkey associated
|
|
|
|
if( m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() ) )
|
2013-10-14 14:13:35 +00:00
|
|
|
return false; // hotkey event was handled so it does not go any further
|
2013-09-27 16:51:21 +00:00
|
|
|
}
|
2013-10-14 18:40:36 +00:00
|
|
|
else if( aEvent.Category() == TC_COMMAND ) // it may be a tool activation event
|
2013-09-27 16:51:21 +00:00
|
|
|
{
|
|
|
|
dispatchActivation( aEvent );
|
|
|
|
// do not return false, as the event has to go on to the destined tool
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-19 15:02:57 +00:00
|
|
|
bool TOOL_MANAGER::dispatchActivation( TOOL_EVENT& aEvent )
|
|
|
|
{
|
2013-09-27 16:51:21 +00:00
|
|
|
// Look for the tool that has the same name as parameter in the processed command TOOL_EVENT
|
2013-09-19 15:02:57 +00:00
|
|
|
BOOST_FOREACH( TOOL_STATE* st, m_toolState | boost::adaptors::map_values )
|
|
|
|
{
|
|
|
|
if( st->theTool->GetName() == aEvent.m_commandStr )
|
|
|
|
{
|
|
|
|
runTool( st->theTool );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-02 12:21:12 +00:00
|
|
|
void TOOL_MANAGER::finishTool( TOOL_STATE* aState )
|
2013-08-30 08:37:26 +00:00
|
|
|
{
|
2013-09-24 13:47:07 +00:00
|
|
|
// Find the tool to be deactivated
|
|
|
|
std::deque<TOOL_ID>::iterator it, it_end;
|
2013-10-14 14:13:35 +00:00
|
|
|
|
2013-09-24 13:47:07 +00:00
|
|
|
for( it = m_activeTools.begin(), it_end = m_activeTools.end(); it != it_end; ++it )
|
|
|
|
{
|
|
|
|
if( aState == m_toolIdIndex[*it] )
|
|
|
|
break;
|
|
|
|
}
|
2013-08-30 08:37:26 +00:00
|
|
|
|
2013-09-24 13:47:07 +00:00
|
|
|
if( it != m_activeTools.end() )
|
|
|
|
m_activeTools.erase( it );
|
|
|
|
else
|
2013-09-27 16:51:21 +00:00
|
|
|
wxLogWarning( wxT( "Tried to finish inactive tool" ) );
|
2013-08-30 08:37:26 +00:00
|
|
|
|
2013-09-24 13:47:07 +00:00
|
|
|
aState->idle = true;
|
2013-08-30 08:37:26 +00:00
|
|
|
delete aState->cofunc;
|
|
|
|
aState->cofunc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-06 08:30:09 +00:00
|
|
|
bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-10-14 14:13:35 +00:00
|
|
|
// wxLogDebug( "event: %s", aEvent.Format().c_str() );
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
// Early dispatch of events destined for the TOOL_MANAGER
|
|
|
|
if( !dispatchStandardEvents( aEvent ) )
|
|
|
|
return false;
|
2013-09-19 15:02:57 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
dispatchInternal( aEvent );
|
2013-09-19 15:02:57 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
// popup menu handling
|
2013-08-30 08:37:26 +00:00
|
|
|
BOOST_FOREACH( TOOL_ID toolId, m_activeTools )
|
|
|
|
{
|
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.
|
2013-10-14 11:43:57 +00:00
|
|
|
if( st->contextMenuTrigger != CMENU_OFF )
|
|
|
|
{
|
2013-10-15 08:41:00 +00:00
|
|
|
if( st->contextMenuTrigger == CMENU_BUTTON && !aEvent.IsClick( BUT_RIGHT ) )
|
2013-10-14 11:43:57 +00:00
|
|
|
break;
|
2013-09-26 12:09:18 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
st->pendingWait = true;
|
2013-10-14 18:40:36 +00:00
|
|
|
st->waitEvents = TOOL_EVENT( TC_ANY, TA_ANY );
|
2013-09-26 12:09:18 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
if( st->contextMenuTrigger == CMENU_NOW )
|
|
|
|
st->contextMenuTrigger = CMENU_OFF;
|
2013-09-26 12:09:18 +00:00
|
|
|
|
|
|
|
boost::scoped_ptr<CONTEXT_MENU> menu( new CONTEXT_MENU( *st->contextMenu ) );
|
|
|
|
GetEditFrame()->PopupMenu( menu->GetMenu() );
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
//
|
2013-10-14 18:40:36 +00:00
|
|
|
TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CHOICE );
|
2013-10-14 11:43:57 +00:00
|
|
|
dispatchInternal( evt );
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
if( m_view->IsDirty() )
|
|
|
|
{
|
|
|
|
PCB_EDIT_FRAME* f = static_cast<PCB_EDIT_FRAME*>( GetEditFrame() );
|
2013-10-14 14:13:35 +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-10-14 11:43:57 +00:00
|
|
|
return false;
|
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;
|
|
|
|
|
|
|
|
// the tool wants the menu immediately? Preempt it and do so :)
|
|
|
|
if( aTrigger == CMENU_NOW )
|
|
|
|
st->cofunc->Yield();
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Reset state of the registered tools
|
|
|
|
BOOST_FOREACH( TOOL_ID toolId, m_activeTools )
|
|
|
|
{
|
|
|
|
TOOL_BASE* tool = m_toolIdIndex[toolId]->theTool;
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
if( tool->GetType() == INTERACTIVE )
|
2013-10-14 11:43:57 +00:00
|
|
|
static_cast<TOOL_INTERACTIVE*>( tool )->Reset();
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
return !m_toolState[aTool]->idle;
|
|
|
|
}
|