2013-08-02 14:46:53 +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>
|
2016-07-04 22:14:32 +00:00
|
|
|
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-08-02 14:46:53 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TOOL_INTERACTIVE_H
|
|
|
|
#define __TOOL_INTERACTIVE_H
|
|
|
|
|
|
|
|
#include <string>
|
2019-06-05 19:15:57 +00:00
|
|
|
#include <tool/tool_menu.h>
|
2013-08-02 14:46:53 +00:00
|
|
|
#include <tool/tool_event.h>
|
|
|
|
#include <tool/tool_base.h>
|
|
|
|
|
2019-05-14 11:14:00 +00:00
|
|
|
class ACTION_MENU;
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2013-08-07 09:20:12 +00:00
|
|
|
class TOOL_INTERACTIVE : public TOOL_BASE
|
|
|
|
{
|
2013-08-02 14:46:53 +00:00
|
|
|
public:
|
2013-09-27 14:23:43 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* Creates a tool with given id & name. The name must be unique. */
|
2013-10-14 11:43:57 +00:00
|
|
|
TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* Creates a tool with given name. The name must be unique. */
|
|
|
|
TOOL_INTERACTIVE( const std::string& aName );
|
|
|
|
virtual ~TOOL_INTERACTIVE();
|
|
|
|
|
2014-02-06 13:45:33 +00:00
|
|
|
/**
|
|
|
|
* Function Activate()
|
|
|
|
* Runs the tool. After activation, the tool starts receiving events until it is finished.
|
|
|
|
*/
|
|
|
|
void Activate();
|
|
|
|
|
2019-06-05 19:15:57 +00:00
|
|
|
TOOL_MENU& GetToolMenu() { return m_menu; }
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
/**
|
|
|
|
* Function SetContextMenu()
|
|
|
|
*
|
|
|
|
* Assigns a context menu and tells when it should be activated.
|
|
|
|
* @param aMenu is the menu to be assigned.
|
|
|
|
* @param aTrigger determines conditions upon which the context menu is activated.
|
|
|
|
*/
|
2019-05-14 11:14:00 +00:00
|
|
|
void SetContextMenu( ACTION_MENU* aMenu, CONTEXT_MENU_TRIGGER aTrigger = CMENU_BUTTON );
|
2013-10-14 11:43:57 +00:00
|
|
|
|
2016-09-21 09:54:58 +00:00
|
|
|
/**
|
|
|
|
* Function RunMainStack()
|
|
|
|
*
|
|
|
|
* Calls a function using the main stack.
|
|
|
|
* @param aFunc is the function to be calls.
|
|
|
|
*/
|
|
|
|
void RunMainStack( std::function<void()> aFunc );
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
/**
|
|
|
|
* Function Go()
|
|
|
|
*
|
|
|
|
* Defines which state (aStateFunc) to go when a certain event arrives (aConditions).
|
|
|
|
* No conditions means any event.
|
|
|
|
*/
|
2013-10-14 14:13:35 +00:00
|
|
|
template <class T>
|
2015-02-14 20:28:47 +00:00
|
|
|
void Go( int (T::* aStateFunc)( const TOOL_EVENT& ),
|
2013-10-14 18:40:36 +00:00
|
|
|
const TOOL_EVENT_LIST& aConditions = TOOL_EVENT( TC_ANY, TA_ANY ) );
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Wait()
|
|
|
|
*
|
|
|
|
* Suspends execution of the tool until an event specified in aEventList arrives.
|
|
|
|
* No parameters means waiting for any event.
|
|
|
|
*/
|
2019-06-17 13:43:22 +00:00
|
|
|
TOOL_EVENT* Wait( const TOOL_EVENT_LIST& aEventList = TOOL_EVENT( TC_ANY, TA_ANY ) );
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
/** functions below are not yet implemented - their interface may change */
|
2013-10-14 14:13:35 +00:00
|
|
|
/*template <class Parameters, class ReturnValue>
|
2013-10-14 11:43:57 +00:00
|
|
|
bool InvokeTool( const std::string& aToolName, const Parameters& parameters,
|
|
|
|
ReturnValue& returnValue );
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
template <class Parameters, class ReturnValue>
|
2013-10-14 11:43:57 +00:00
|
|
|
bool InvokeWindow( const std::string& aWindowName, const Parameters& parameters,
|
|
|
|
ReturnValue& returnValue );
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
template <class T>
|
2013-10-14 11:43:57 +00:00
|
|
|
void Yield( const T& returnValue );*/
|
2013-08-02 14:46:53 +00:00
|
|
|
|
|
|
|
protected:
|
2019-06-05 19:15:57 +00:00
|
|
|
TOOL_MENU m_menu;
|
2013-08-02 14:46:53 +00:00
|
|
|
|
|
|
|
private:
|
2017-07-31 12:30:51 +00:00
|
|
|
/**
|
|
|
|
* This method is meant to be overridden in order to specify handlers for events. It is called
|
|
|
|
* every time tool is reset or finished.
|
|
|
|
*/
|
|
|
|
virtual void setTransitions() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the current transition map and restores the default one created by setTransitions().
|
|
|
|
*/
|
|
|
|
void resetTransitions();
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
void goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions );
|
2017-07-31 12:30:51 +00:00
|
|
|
|
|
|
|
friend class TOOL_MANAGER;
|
2013-08-02 14:46:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// hide TOOL_MANAGER implementation
|
2013-10-14 14:13:35 +00:00
|
|
|
template <class T>
|
2015-02-14 20:28:47 +00:00
|
|
|
void TOOL_INTERACTIVE::Go( int (T::* aStateFunc)( const TOOL_EVENT& ),
|
2013-10-14 18:40:36 +00:00
|
|
|
const TOOL_EVENT_LIST& aConditions )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2016-07-04 22:14:32 +00:00
|
|
|
TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
|
2013-10-14 14:13:35 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
goInternal( sptr, aConditions );
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|