KiCad PCB EDA Suite
tool_interactive.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <string>
26 
27 #include <tool/tool_event.h>
28 #include <tool/tool_manager.h>
29 #include <tool/tool_interactive.h>
30 #include <tool/context_menu.h>
31 
32 TOOL_INTERACTIVE::TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName ) :
33  TOOL_BASE( INTERACTIVE, aId, aName )
34 {
35 }
36 
37 
38 TOOL_INTERACTIVE::TOOL_INTERACTIVE( const std::string& aName ) :
39  TOOL_BASE( INTERACTIVE, TOOL_MANAGER::MakeToolId( aName ), aName )
40 {
41 }
42 
43 
45 {
46 }
47 
48 
50 {
52 }
53 
54 
56 {
57  return m_toolMgr->ScheduleWait( this, aEventList );
58 }
59 
60 
62 {
63  m_toolMgr->ClearTransitions( this );
65 }
66 
67 
69 {
70  m_toolMgr->ScheduleNextState( this, aState, aConditions );
71 }
72 
73 
75 {
76  if( aMenu )
77  aMenu->SetTool( this );
78  else
79  aTrigger = CMENU_OFF;
80 
81  m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
82 }
83 
84 
85 void TOOL_INTERACTIVE::RunMainStack( std::function<void()> aFunc )
86 {
87  m_toolMgr->RunMainStack( this, std::move( aFunc ) );
88 }
89 
void ScheduleNextState(TOOL_BASE *aTool, TOOL_STATE_FUNC &aHandler, const TOOL_EVENT_LIST &aConditions)
Defines a state transition - the events that cause a given handler method in the tool to be called...
Class CONTEXT_MENU.
Definition: context_menu.h:44
void RunMainStack(std::function< void()> aFunc)
Function RunMainStack()
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Constructor.
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:210
void ScheduleContextMenu(TOOL_BASE *aTool, CONTEXT_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger)
Sets behaviour of the tool's context popup menu.
OPT< TOOL_EVENT > ScheduleWait(TOOL_BASE *aTool, const TOOL_EVENT_LIST &aConditions)
Pauses execution of a given tool until one or more events matching aConditions arrives.
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID...
Class TOOL_MANAGER.
Definition: tool_manager.h:49
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:57
void resetTransitions()
Clears the current transition map and restores the default one created by setTransitions().
Class TOOL_EVENT_LIST.
Definition: tool_event.h:468
Tool that interacts with the user
Definition: tool_base.h:50
CONTEXT_MENU_TRIGGER
Defines when a context menu is opened.
Definition: tool_event.h:150
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
virtual ~TOOL_INTERACTIVE()
void SetContextMenu(CONTEXT_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Function SetContextMenu()
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:59
void RunMainStack(TOOL_BASE *aTool, std::function< void()> aFunc)
virtual void setTransitions()=0
This method is meant to be overridden in order to specify handlers for events.
Class TOOL_BASE.
Definition: tool_base.h:68
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)
void Activate()
Function Activate() Runs the tool.
void ClearTransitions(TOOL_BASE *aTool)
Clears the state transition map for a tool.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:460