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
>
31
#include <
tool/tool_interactive.h
>
32
#include <
tool/action_menu.h
>
33
34
#include <
pgm_base.h
>
35
36
#include <wx/log.h>
37
38
39
TOOL_INTERACTIVE::TOOL_INTERACTIVE
(
TOOL_ID
aId,
const
std::string& aName ) :
40
TOOL_BASE
(
INTERACTIVE
, aId, aName )
41
{
42
if
(
Pgm
().IsGUI() )
43
{
44
m_menu
.reset(
new
TOOL_MENU
( *
this
) );
45
}
46
}
47
48
49
TOOL_INTERACTIVE::TOOL_INTERACTIVE
(
const
std::string& aName ) :
50
TOOL_BASE
(
INTERACTIVE
,
TOOL_MANAGER
::MakeToolId( aName ), aName )
51
52
{
53
if
(
Pgm
().IsGUI() )
54
{
55
m_menu
.reset(
new
TOOL_MENU
( *
this
) );
56
}
57
}
58
59
60
TOOL_INTERACTIVE::~TOOL_INTERACTIVE
()
61
{
62
}
63
64
65
void
TOOL_INTERACTIVE::Activate
()
66
{
67
m_toolMgr
->
InvokeTool
(
m_toolId
);
68
}
69
70
71
TOOL_EVENT
*
TOOL_INTERACTIVE::Wait
(
const
TOOL_EVENT_LIST
& aEventList )
72
{
73
return
m_toolMgr
->
ScheduleWait
(
this
, aEventList );
74
}
75
76
77
void
TOOL_INTERACTIVE::resetTransitions
()
78
{
79
m_toolMgr
->
ClearTransitions
(
this
);
80
setTransitions
();
81
}
82
83
84
void
TOOL_INTERACTIVE::goInternal
(
TOOL_STATE_FUNC
& aState,
const
TOOL_EVENT_LIST
& aConditions )
85
{
86
wxLogTrace(
kicadTraceToolStack
,
87
wxS(
"TOOL_INTERACTIVE::goInternal: Tool '%s', Registering handler for "
88
"actions '%s'"
),
89
GetName
(), aConditions.
Names
() );
90
91
m_toolMgr
->
ScheduleNextState
(
this
, aState, aConditions );
92
}
93
94
95
void
TOOL_INTERACTIVE::SetContextMenu
(
ACTION_MENU
* aMenu,
CONTEXT_MENU_TRIGGER
aTrigger )
96
{
97
if
( aMenu )
98
aMenu->
SetTool
(
this
);
99
else
100
aTrigger =
CMENU_OFF
;
101
102
m_toolMgr
->
ScheduleContextMenu
(
this
, aMenu, aTrigger );
103
}
104
105
106
void
TOOL_INTERACTIVE::RunMainStack
( std::function<
void
()> aFunc )
107
{
108
m_toolMgr
->
RunMainStack
(
this
, std::move( aFunc ) );
109
}
110
111
112
TOOL_MENU
&
TOOL_INTERACTIVE::GetToolMenu
()
113
{
114
return
*
m_menu
.get();
115
}
action_menu.h
ACTION_MENU
Define the structure of a menu based on ACTIONs.
Definition:
action_menu.h:49
ACTION_MENU::SetTool
void SetTool(TOOL_INTERACTIVE *aTool)
Set a tool that is the creator of the menu.
Definition:
action_menu.cpp:313
TOOL_BASE
Base abstract interface for all kinds of tools.
Definition:
tool_base.h:66
TOOL_BASE::GetName
const std::string & GetName() const
Return the name of the tool.
Definition:
tool_base.h:136
TOOL_BASE::m_toolMgr
TOOL_MANAGER * m_toolMgr
Definition:
tool_base.h:220
TOOL_BASE::m_toolId
TOOL_ID m_toolId
Unique id, assigned by a TOOL_MANAGER instance.
Definition:
tool_base.h:215
TOOL_EVENT_LIST
A list of TOOL_EVENTs, with overloaded || operators allowing for concatenating TOOL_EVENTs with littl...
Definition:
tool_event.h:640
TOOL_EVENT_LIST::Names
const std::string Names() const
Return a string containing the names of all the events in this list.
Definition:
tool_event.cpp:198
TOOL_EVENT
Generic, UI-independent tool event.
Definition:
tool_event.h:168
TOOL_INTERACTIVE::SetContextMenu
void SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Assign a context menu and tells when it should be activated.
Definition:
tool_interactive.cpp:95
TOOL_INTERACTIVE::RunMainStack
void RunMainStack(std::function< void()> aFunc)
Call a function using the main stack.
Definition:
tool_interactive.cpp:106
TOOL_INTERACTIVE::GetToolMenu
TOOL_MENU & GetToolMenu()
Definition:
tool_interactive.cpp:112
TOOL_INTERACTIVE::setTransitions
virtual void setTransitions()=0
This method is meant to be overridden in order to specify handlers for events.
TOOL_INTERACTIVE::goInternal
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)
Definition:
tool_interactive.cpp:84
TOOL_INTERACTIVE::m_menu
std::unique_ptr< TOOL_MENU > m_menu
The functions below are not yet implemented - their interface may change.
Definition:
tool_interactive.h:125
TOOL_INTERACTIVE::~TOOL_INTERACTIVE
virtual ~TOOL_INTERACTIVE()
Definition:
tool_interactive.cpp:60
TOOL_INTERACTIVE::TOOL_INTERACTIVE
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.
Definition:
tool_interactive.cpp:39
TOOL_INTERACTIVE::Wait
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.
Definition:
tool_interactive.cpp:71
TOOL_INTERACTIVE::resetTransitions
void resetTransitions()
Clear the current transition map and restores the default one created by setTransitions().
Definition:
tool_interactive.cpp:77
TOOL_INTERACTIVE::Activate
void Activate()
Run the tool.
Definition:
tool_interactive.cpp:65
TOOL_MANAGER
Master controller class:
Definition:
tool_manager.h:62
TOOL_MANAGER::ScheduleNextState
void ScheduleNextState(TOOL_BASE *aTool, TOOL_STATE_FUNC &aHandler, const TOOL_EVENT_LIST &aConditions)
Define a state transition.
Definition:
tool_manager.cpp:687
TOOL_MANAGER::InvokeTool
bool InvokeTool(TOOL_ID aToolId)
Call a tool by sending a tool activation event to tool of given ID.
Definition:
tool_manager.cpp:267
TOOL_MANAGER::RunMainStack
void RunMainStack(TOOL_BASE *aTool, std::function< void()> aFunc)
Definition:
tool_manager.cpp:702
TOOL_MANAGER::ClearTransitions
void ClearTransitions(TOOL_BASE *aTool)
Clear the state transition map for a tool.
Definition:
tool_manager.cpp:696
TOOL_MANAGER::ScheduleContextMenu
void ScheduleContextMenu(TOOL_BASE *aTool, ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger)
Set behavior of the tool's context popup menu.
Definition:
tool_manager.cpp:1050
TOOL_MANAGER::ScheduleWait
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.
Definition:
tool_manager.cpp:711
TOOL_MENU
Manage a CONDITIONAL_MENU and some number of CONTEXT_MENUs as sub-menus.
Definition:
tool_menu.h:43
kicadTraceToolStack
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
Definition:
trace_helpers.cpp:37
Pgm
PGM_BASE & Pgm()
The global program "get" accessor.
Definition:
pgm_base.cpp:1073
pgm_base.h
see class PGM_BASE
TOOL_STATE_FUNC
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition:
tool_base.h:58
TOOL_ID
int TOOL_ID
Unique identifier for tools.
Definition:
tool_base.h:56
INTERACTIVE
@ INTERACTIVE
Tool that interacts with the user.
Definition:
tool_base.h:49
tool_event.h
CONTEXT_MENU_TRIGGER
CONTEXT_MENU_TRIGGER
Defines when a context menu is opened.
Definition:
tool_event.h:151
CMENU_OFF
@ CMENU_OFF
Never.
Definition:
tool_event.h:154
tool_interactive.h
tool_manager.h
trace_helpers.h
wxLogTrace helper definitions.
src
common
tool
tool_interactive.cpp
Generated on Tue Jan 21 2025 00:04:54 for KiCad PCB EDA Suite by
1.9.6