KiCad PCB EDA Suite
Loading...
Searching...
No Matches
tool_interactive.h
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
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6
*
7
* @author Tomasz Wlostowski <
[email protected]
>
8
*
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License
11
* as published by the Free Software Foundation; either version 2
12
* of the License, or (at your option) any later version.
13
*
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
18
*
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <https://www.gnu.org/licenses/>.
21
*/
22
23
#ifndef __TOOL_INTERACTIVE_H
24
#define __TOOL_INTERACTIVE_H
25
26
#include <string>
27
#include <
tool/tool_menu.h
>
28
#include <
tool/tool_event.h
>
// Needed for CONTEXT_MENU_TRIGGER
29
#include <
tool/tool_base.h
>
30
31
class
ACTION_MENU
;
32
33
34
struct
REENTRANCY_GUARD
35
{
36
REENTRANCY_GUARD
(
bool
* aFlag ) :
37
m_flag
( aFlag )
38
{
39
*
m_flag
=
true
;
40
}
41
42
~REENTRANCY_GUARD
()
43
{
44
*
m_flag
=
false
;
45
}
46
47
private
:
48
bool
*
m_flag
;
49
};
50
51
52
class
TOOL_INTERACTIVE
:
public
TOOL_BASE
53
{
54
public
:
58
TOOL_INTERACTIVE
(
TOOL_ID
aId,
const
std::string& aName );
59
63
TOOL_INTERACTIVE
(
const
std::string& aName );
64
virtual
~TOOL_INTERACTIVE
();
65
71
void
Activate
();
72
73
TOOL_MENU
&
GetToolMenu
();
74
81
void
SetContextMenu
(
ACTION_MENU
* aMenu,
CONTEXT_MENU_TRIGGER
aTrigger =
CMENU_BUTTON
);
82
88
void
RunMainStack
( std::function<
void
()> aFunc );
89
95
template
<
class
T>
96
void
Go
(
int
(
T
::* aStateFunc)(
const
TOOL_EVENT
& ),
97
const
TOOL_EVENT_LIST
& aConditions =
TOOL_EVENT
(
TC_ANY
,
TA_ANY
) );
98
104
TOOL_EVENT
*
Wait
(
const
TOOL_EVENT_LIST
& aEventList =
TOOL_EVENT
(
TC_ANY
,
TA_ANY
) );
105
109
/*template <class Parameters, class ReturnValue>
110
bool InvokeTool( const std::string& aToolName, const Parameters& parameters,
111
ReturnValue& returnValue );
112
113
template <class Parameters, class ReturnValue>
114
bool InvokeWindow( const std::string& aWindowName, const Parameters& parameters,
115
ReturnValue& returnValue );
116
117
template <class T>
118
void Yield( const T& returnValue );*/
119
120
protected
:
121
std::unique_ptr<TOOL_MENU>
m_menu
;
122
123
private
:
129
virtual
void
setTransitions
() = 0;
130
134
void
resetTransitions
();
135
136
void
goInternal
(
TOOL_STATE_FUNC
& aState,
const
TOOL_EVENT_LIST
& aConditions );
137
138
friend
class
TOOL_MANAGER
;
139
};
140
141
// hide TOOL_MANAGER implementation
142
template
<
class
T>
143
void
TOOL_INTERACTIVE::Go
(
int
(
T
::* aStateFunc)(
const
TOOL_EVENT
& ),
144
const
TOOL_EVENT_LIST
& aConditions )
145
{
146
TOOL_STATE_FUNC
sptr = std::bind( aStateFunc,
static_cast<
T
*
>
(
this
), std::placeholders::_1 );
147
148
goInternal
( sptr, aConditions );
149
}
150
151
#endif
ACTION_MENU
Define the structure of a menu based on ACTIONs.
Definition
action_menu.h:43
TOOL_BASE::TOOL_BASE
TOOL_BASE(TOOL_TYPE aType, TOOL_ID aId, const std::string &aName=std::string(""))
Definition
tool_base.h:64
TOOL_EVENT_LIST
A list of TOOL_EVENTs, with overloaded || operators allowing for concatenating TOOL_EVENTs with littl...
Definition
tool_event.h:644
TOOL_EVENT
Generic, UI-independent tool event.
Definition
tool_event.h:167
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:91
TOOL_INTERACTIVE::RunMainStack
void RunMainStack(std::function< void()> aFunc)
Call a function using the main stack.
Definition
tool_interactive.cpp:102
TOOL_INTERACTIVE::Go
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
Definition
tool_interactive.h:143
TOOL_INTERACTIVE::GetToolMenu
TOOL_MENU & GetToolMenu()
Definition
tool_interactive.cpp:108
TOOL_INTERACTIVE::setTransitions
virtual void setTransitions()=0
This method is meant to be overridden in order to specify handlers for events.
TOOL_INTERACTIVE::TOOL_MANAGER
friend class TOOL_MANAGER
Definition
tool_interactive.h:138
TOOL_INTERACTIVE::goInternal
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)
Definition
tool_interactive.cpp:80
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:121
TOOL_INTERACTIVE::~TOOL_INTERACTIVE
virtual ~TOOL_INTERACTIVE()
Definition
tool_interactive.cpp:56
TOOL_INTERACTIVE::TOOL_INTERACTIVE
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.
Definition
tool_interactive.cpp:35
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:67
TOOL_INTERACTIVE::resetTransitions
void resetTransitions()
Clear the current transition map and restores the default one created by setTransitions().
Definition
tool_interactive.cpp:73
TOOL_INTERACTIVE::Activate
void Activate()
Run the tool.
Definition
tool_interactive.cpp:61
TOOL_MENU
Manage a CONDITIONAL_MENU and some number of CONTEXT_MENUs as sub-menus.
Definition
tool_menu.h:39
REENTRANCY_GUARD::REENTRANCY_GUARD
REENTRANCY_GUARD(bool *aFlag)
Definition
tool_interactive.h:36
REENTRANCY_GUARD::~REENTRANCY_GUARD
~REENTRANCY_GUARD()
Definition
tool_interactive.h:42
REENTRANCY_GUARD::m_flag
bool * m_flag
Definition
tool_interactive.h:48
tool_base.h
TOOL_STATE_FUNC
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition
tool_base.h:54
TOOL_ID
int TOOL_ID
Unique identifier for tools.
Definition
tool_base.h:52
tool_event.h
TA_ANY
@ TA_ANY
Definition
tool_event.h:122
CONTEXT_MENU_TRIGGER
CONTEXT_MENU_TRIGGER
Defines when a context menu is opened.
Definition
tool_event.h:150
CMENU_BUTTON
@ CMENU_BUTTON
On the right button.
Definition
tool_event.h:151
TC_ANY
@ TC_ANY
Definition
tool_event.h:56
tool_menu.h
TRANSLINE_PARAMETERS::T
@ T
Definition
transline_calculation_base.h:39
src
include
tool
tool_interactive.h
Generated on Fri Jun 26 2026 00:05:37 for KiCad PCB EDA Suite by
1.13.2