KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
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 <trace_helpers.h>
28
29#include <tool/tool_event.h>
30#include <tool/tool_manager.h>
32#include <tool/action_menu.h>
33
34#include <wx/log.h>
35
36TOOL_INTERACTIVE::TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName ) :
37 TOOL_BASE( INTERACTIVE, aId, aName ),
38 m_menu( *this )
39{
40}
41
42
43TOOL_INTERACTIVE::TOOL_INTERACTIVE( const std::string& aName ) :
44 TOOL_BASE( INTERACTIVE, TOOL_MANAGER::MakeToolId( aName ), aName ),
45 m_menu( *this )
46{
47}
48
49
51{
52}
53
54
56{
58}
59
60
62{
63 return m_toolMgr->ScheduleWait( this, aEventList );
64}
65
66
68{
71}
72
73
75{
76 wxLogTrace( kicadTraceToolStack,
77 wxS( "TOOL_INTERACTIVE::goInternal: Tool '%s', Registering handler for actions '%s'" ),
78 GetName(), aConditions.Names() );
79
80 m_toolMgr->ScheduleNextState( this, aState, aConditions );
81}
82
83
85{
86 if( aMenu )
87 aMenu->SetTool( this );
88 else
89 aTrigger = CMENU_OFF;
90
91 m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
92}
93
94
95void TOOL_INTERACTIVE::RunMainStack( std::function<void()> aFunc )
96{
97 m_toolMgr->RunMainStack( this, std::move( aFunc ) );
98}
99
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void SetTool(TOOL_INTERACTIVE *aTool)
Set a tool that is the creator of the menu.
Base abstract interface for all kinds of tools.
Definition: tool_base.h:66
const std::string & GetName() const
Return the name of the tool.
Definition: tool_base.h:135
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
TOOL_ID m_toolId
Name of the tool.
Definition: tool_base.h:211
A list of TOOL_EVENTs, with overloaded || operators allowing for concatenating TOOL_EVENTs with littl...
Definition: tool_event.h:636
const std::string Names() const
Returns a string containing the names of all the events in this list.
Definition: tool_event.cpp:198
Generic, UI-independent tool event.
Definition: tool_event.h:167
void SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Assign a context menu and tells when it should be activated.
void RunMainStack(std::function< void()> aFunc)
Call a function using the main stack.
virtual void setTransitions()=0
This method is meant to be overridden in order to specify handlers for events.
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)
virtual ~TOOL_INTERACTIVE()
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
void resetTransitions()
Clear the current transition map and restores the default one created by setTransitions().
void Activate()
Run the tool.
Master controller class:
Definition: tool_manager.h:57
void ScheduleNextState(TOOL_BASE *aTool, TOOL_STATE_FUNC &aHandler, const TOOL_EVENT_LIST &aConditions)
Define a state transition.
bool InvokeTool(TOOL_ID aToolId)
Call a tool by sending a tool activation event to tool of given ID.
void RunMainStack(TOOL_BASE *aTool, std::function< void()> aFunc)
void ClearTransitions(TOOL_BASE *aTool)
Clear the state transition map for a tool.
void ScheduleContextMenu(TOOL_BASE *aTool, ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger)
Set behavior of the tool's context popup menu.
TOOL_EVENT * ScheduleWait(TOOL_BASE *aTool, const TOOL_EVENT_LIST &aConditions)
Pause execution of a given tool until one or more events matching aConditions arrives.
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:58
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:56
@ INTERACTIVE
Tool that interacts with the user.
Definition: tool_base.h:49
CONTEXT_MENU_TRIGGER
Defines when a context menu is opened.
Definition: tool_event.h:150
@ CMENU_OFF
Definition: tool_event.h:153
wxLogTrace helper definitions.