KiCad PCB EDA Suite
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 (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
6
*
7
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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, you may find one here:
21
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22
* or you may search the http://www.gnu.org website for the version 2 license,
23
* or you may write to the Free Software Foundation, Inc.,
24
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25
*/
26
27
#ifndef __TOOL_INTERACTIVE_H
28
#define __TOOL_INTERACTIVE_H
29
30
#include <string>
31
#include <
tool/tool_menu.h
>
32
#include <
tool/tool_event.h
>
33
#include <
tool/tool_base.h
>
34
35
class
ACTION_MENU
;
36
37
class
TOOL_INTERACTIVE
:
public
TOOL_BASE
38
{
39
public
:
43
TOOL_INTERACTIVE
(
TOOL_ID
aId,
const
std::string& aName );
44
48
TOOL_INTERACTIVE
(
const
std::string& aName );
49
virtual
~TOOL_INTERACTIVE
();
50
56
void
Activate
();
57
58
TOOL_MENU
&
GetToolMenu
() {
return
m_menu
; }
59
66
void
SetContextMenu
(
ACTION_MENU
* aMenu,
CONTEXT_MENU_TRIGGER
aTrigger =
CMENU_BUTTON
);
67
73
void
RunMainStack
( std::function<
void
()> aFunc );
74
80
template
<
class
T>
81
void
Go
(
int
(T::* aStateFunc)(
const
TOOL_EVENT
& ),
82
const
TOOL_EVENT_LIST
& aConditions =
TOOL_EVENT
(
TC_ANY
,
TA_ANY
) );
83
89
TOOL_EVENT
*
Wait
(
const
TOOL_EVENT_LIST
& aEventList =
TOOL_EVENT
(
TC_ANY
,
TA_ANY
) );
90
94
/*template <class Parameters, class ReturnValue>
95
bool InvokeTool( const std::string& aToolName, const Parameters& parameters,
96
ReturnValue& returnValue );
97
98
template <class Parameters, class ReturnValue>
99
bool InvokeWindow( const std::string& aWindowName, const Parameters& parameters,
100
ReturnValue& returnValue );
101
102
template <class T>
103
void Yield( const T& returnValue );*/
104
105
protected
:
106
TOOL_MENU
m_menu
;
107
108
private
:
114
virtual
void
setTransitions
() = 0;
115
119
void
resetTransitions
();
120
121
void
goInternal
(
TOOL_STATE_FUNC
& aState,
const
TOOL_EVENT_LIST
& aConditions );
122
123
friend
class
TOOL_MANAGER
;
124
};
125
126
// hide TOOL_MANAGER implementation
127
template
<
class
T>
128
void
TOOL_INTERACTIVE::Go
(
int
(T::* aStateFunc)(
const
TOOL_EVENT
& ),
129
const
TOOL_EVENT_LIST
& aConditions )
130
{
131
TOOL_STATE_FUNC
sptr = std::bind( aStateFunc, static_cast<T*>(
this
), std::placeholders::_1 );
132
133
goInternal
( sptr, aConditions );
134
}
135
136
#endif
TOOL_INTERACTIVE::m_menu
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
Definition:
tool_interactive.h:106
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:57
ACTION_MENU
Defines the structure of a menu based on ACTIONs.
Definition:
action_menu.h:45
TOOL_INTERACTIVE::RunMainStack
void RunMainStack(std::function< void()> aFunc)
Call a function using the main stack.
Definition:
tool_interactive.cpp:87
TOOL_MENU
Manage a CONDITIONAL_MENU and some number of CONTEXT_MENUs as sub-menus.
Definition:
tool_menu.h:42
TOOL_INTERACTIVE::TOOL_INTERACTIVE
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Create a tool with given id & name.
Definition:
tool_interactive.cpp:32
TOOL_INTERACTIVE::GetToolMenu
TOOL_MENU & GetToolMenu()
Definition:
tool_interactive.h:58
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:76
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:128
CMENU_BUTTON
Definition:
tool_event.h:165
TC_ANY
Definition:
tool_event.h:59
TOOL_MANAGER
Master controller class:
Definition:
tool_manager.h:52
TOOL_ID
int TOOL_ID
Unique identifier for tools.
Definition:
tool_base.h:57
TOOL_INTERACTIVE::resetTransitions
void resetTransitions()
Clear the current transition map and restores the default one created by setTransitions().
Definition:
tool_interactive.cpp:63
TOOL_EVENT_LIST
A list of TOOL_EVENTs, with overloaded || operators allowing for concatenating TOOL_EVENTs with littl...
Definition:
tool_event.h:575
tool_base.h
CONTEXT_MENU_TRIGGER
CONTEXT_MENU_TRIGGER
Defines when a context menu is opened.
Definition:
tool_event.h:163
TOOL_EVENT
Generic, UI-independent tool event.
Definition:
tool_event.h:173
TOOL_INTERACTIVE::~TOOL_INTERACTIVE
virtual ~TOOL_INTERACTIVE()
Definition:
tool_interactive.cpp:46
TOOL_STATE_FUNC
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition:
tool_base.h:59
TOOL_INTERACTIVE
Definition:
tool_interactive.h:37
TOOL_INTERACTIVE::setTransitions
virtual void setTransitions()=0
This method is meant to be overridden in order to specify handlers for events.
tool_event.h
TOOL_BASE
Base abstract interface for all kinds of tools.
Definition:
tool_base.h:66
TOOL_INTERACTIVE::goInternal
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)
Definition:
tool_interactive.cpp:70
TOOL_INTERACTIVE::Activate
void Activate()
Run the tool.
Definition:
tool_interactive.cpp:51
tool_menu.h
TA_ANY
Definition:
tool_event.h:125
include
tool
tool_interactive.h
Generated on Mon Mar 8 2021 04:17:21 for KiCad PCB EDA Suite by
1.8.15