KiCad PCB EDA Suite
Loading...
Searching...
No Matches
conditional_menu.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) 2015 CERN
5
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6
*
7
* @author Maciej Suminski <
[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 CONDITIONAL_MENU_H
24
#define CONDITIONAL_MENU_H
25
26
#include <
tool/selection_conditions.h
>
27
#include <
tool/action_menu.h
>
28
#include <list>
29
30
class
PCB_SELECTION_TOOL
;
31
class
TOOL_ACTION
;
32
class
TOOL_INTERACTIVE
;
33
34
enum class
BITMAPS
:
unsigned
int;
35
36
37
class
CONDITIONAL_MENU
:
public
ACTION_MENU
38
{
39
public
:
41
static
const
int
ANY_ORDER
= -1;
42
43
CONDITIONAL_MENU
(
TOOL_INTERACTIVE
* aTool );
44
45
ACTION_MENU
*
create
()
const override
;
46
55
void
AddItem
(
const
TOOL_ACTION
& aAction,
const
SELECTION_CONDITION
& aCondition,
56
int
aOrder =
ANY_ORDER
);
57
58
void
AddItem
(
int
aId,
const
wxString& aText,
const
wxString& aTooltip,
BITMAPS
aIcon,
59
const
SELECTION_CONDITION
& aCondition,
int
aOrder =
ANY_ORDER
);
60
72
void
AddCheckItem
(
const
TOOL_ACTION
& aAction,
const
SELECTION_CONDITION
& aCondition,
73
int
aOrder =
ANY_ORDER
);
74
75
void
AddCheckItem
(
int
aId,
const
wxString& aText,
const
wxString& aTooltip,
BITMAPS
aIcon,
76
const
SELECTION_CONDITION
& aCondition,
int
aOrder =
ANY_ORDER
);
77
89
void
AddMenu
(
ACTION_MENU
* aMenu,
90
const
SELECTION_CONDITION
& aCondition =
SELECTION_CONDITIONS::ShowAlways
,
91
int
aOrder =
ANY_ORDER
);
92
98
void
AddSeparator
(
int
aOrder =
ANY_ORDER
);
99
100
void
AddSeparator
(
const
SELECTION_CONDITION
& aCondition,
int
aOrder =
ANY_ORDER
);
101
105
void
Evaluate
(
const
SELECTION
& aSelection );
106
112
void
Resolve
();
113
114
private
:
116
class
ENTRY
117
{
118
public
:
119
ENTRY
(
const
TOOL_ACTION
* aAction,
SELECTION_CONDITION
aCondition,
int
aOrder,
120
bool
aCheckmark ) :
121
m_type
(
ACTION
),
122
m_icon
( static_cast<
BITMAPS
>( 0 ) ),
123
m_condition
(
std
::
move
( aCondition ) ),
124
m_order
( aOrder ),
125
m_isCheckmarkEntry
( aCheckmark )
126
{
127
m_data
.action = aAction;
128
}
129
130
ENTRY
(
ACTION_MENU
* aMenu,
SELECTION_CONDITION
aCondition,
int
aOrder ) :
131
m_type
(
MENU
),
132
m_icon
( static_cast<
BITMAPS
>( 0 ) ),
133
m_condition
(
std
::
move
( aCondition ) ),
134
m_order
( aOrder ),
135
m_isCheckmarkEntry
( false )
136
{
137
m_data
.menu = aMenu;
138
}
139
140
ENTRY
(
const
wxMenuItem& aItem,
BITMAPS
aBitmap,
141
SELECTION_CONDITION
aCondition,
int
aOrder,
bool
aCheckmark ) :
142
m_type
(
WXITEM
),
143
m_icon
( aBitmap ),
144
m_condition
(
std
::
move
( aCondition ) ),
145
m_order
( aOrder ),
146
m_isCheckmarkEntry
( aCheckmark )
147
{
148
m_data
.wxItem =
new
wxMenuItem(
nullptr
, aItem.GetId(), aItem.GetItemLabel(),
149
aItem.GetHelp(), aItem.GetKind() );
150
}
151
152
// Separator
153
ENTRY
(
SELECTION_CONDITION
aCondition,
int
aOrder ) :
154
m_type
(
SEPARATOR
),
155
m_icon
( static_cast<
BITMAPS
>( 0 ) ),
156
m_data
(),
157
m_condition
(
std
::
move
( aCondition ) ),
158
m_order
( aOrder ),
159
m_isCheckmarkEntry
( false )
160
{
161
}
162
163
ENTRY
(
const
ENTRY
& aEntry );
164
165
~ENTRY
();
166
168
enum
ENTRY_TYPE
{
169
ACTION
,
170
MENU
,
171
WXITEM
,
172
SEPARATOR
173
};
174
175
inline
ENTRY_TYPE
Type
()
const
176
{
177
return
m_type
;
178
}
179
180
inline
BITMAPS
GetIcon
()
const
181
{
182
return
m_icon
;
183
}
184
185
inline
const
TOOL_ACTION
*
Action
()
const
186
{
187
assert(
m_type
==
ACTION
);
188
return
m_data
.action;
189
}
190
191
inline
ACTION_MENU
*
Menu
()
const
192
{
193
assert(
m_type
==
MENU
);
194
return
m_data
.menu;
195
}
196
197
inline
wxMenuItem*
wxItem
()
const
198
{
199
assert(
m_type
==
WXITEM
);
200
return
m_data
.wxItem;
201
}
202
203
inline
bool
IsCheckmarkEntry
()
const
204
{
205
return
m_isCheckmarkEntry
;
206
}
207
208
inline
const
SELECTION_CONDITION
&
Condition
()
const
209
{
210
return
m_condition
;
211
}
212
213
inline
int
Order
()
const
214
{
215
return
m_order
;
216
}
217
218
inline
void
SetOrder
(
int
aOrder )
219
{
220
m_order
= aOrder;
221
}
222
223
private
:
224
ENTRY_TYPE
m_type
;
225
BITMAPS
m_icon
;
226
227
// This class owns the wxItem object and needs to create, copy and delete it accordingly
228
// But it does not own the action nor menu item
229
union
{
230
const
TOOL_ACTION
*
action
;
231
ACTION_MENU
*
menu
;
232
wxMenuItem*
wxItem
;
233
}
m_data
;
234
236
SELECTION_CONDITION
m_condition
;
237
239
int
m_order
;
240
241
bool
m_isCheckmarkEntry
;
242
};
243
245
void
addEntry
(
ENTRY
aEntry );
246
248
std::list<ENTRY>
m_entries
;
249
};
250
251
#endif
/* CONDITIONAL_MENU_H */
action_menu.h
BITMAPS
BITMAPS
A list of all bitmap identifiers.
Definition
bitmaps_list.h:29
BITMAPS::move
@ move
Definition
bitmaps_list.h:382
ACTION_MENU::ACTION_MENU
ACTION_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
Default constructor.
Definition
action_menu.cpp:47
ACTION_MENU::TOOL_INTERACTIVE
friend class TOOL_INTERACTIVE
Definition
action_menu.h:287
CONDITIONAL_MENU::ENTRY
Helper class to organize menu entries.
Definition
conditional_menu.h:117
CONDITIONAL_MENU::ENTRY::m_order
int m_order
Order number, the higher the number the lower position it takes it is in the menu.
Definition
conditional_menu.h:239
CONDITIONAL_MENU::ENTRY::m_isCheckmarkEntry
bool m_isCheckmarkEntry
Definition
conditional_menu.h:241
CONDITIONAL_MENU::ENTRY::wxItem
wxMenuItem * wxItem
Definition
conditional_menu.h:232
CONDITIONAL_MENU::ENTRY::Action
const TOOL_ACTION * Action() const
Definition
conditional_menu.h:185
CONDITIONAL_MENU::ENTRY::ENTRY_TYPE
ENTRY_TYPE
Possible entry types.
Definition
conditional_menu.h:168
CONDITIONAL_MENU::ENTRY::MENU
@ MENU
Definition
conditional_menu.h:170
CONDITIONAL_MENU::ENTRY::ACTION
@ ACTION
Definition
conditional_menu.h:169
CONDITIONAL_MENU::ENTRY::SEPARATOR
@ SEPARATOR
Definition
conditional_menu.h:172
CONDITIONAL_MENU::ENTRY::WXITEM
@ WXITEM
Definition
conditional_menu.h:171
CONDITIONAL_MENU::ENTRY::IsCheckmarkEntry
bool IsCheckmarkEntry() const
Definition
conditional_menu.h:203
CONDITIONAL_MENU::ENTRY::SetOrder
void SetOrder(int aOrder)
Definition
conditional_menu.h:218
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(const TOOL_ACTION *aAction, SELECTION_CONDITION aCondition, int aOrder, bool aCheckmark)
Definition
conditional_menu.h:119
CONDITIONAL_MENU::ENTRY::~ENTRY
~ENTRY()
Definition
conditional_menu.cpp:254
CONDITIONAL_MENU::ENTRY::m_data
union CONDITIONAL_MENU::ENTRY::@223133073310361045126170055313230071325071242350 m_data
CONDITIONAL_MENU::ENTRY::action
const TOOL_ACTION * action
Definition
conditional_menu.h:230
CONDITIONAL_MENU::ENTRY::m_condition
SELECTION_CONDITION m_condition
Condition to be fulfilled to show the entry in menu.
Definition
conditional_menu.h:236
CONDITIONAL_MENU::ENTRY::menu
ACTION_MENU * menu
Definition
conditional_menu.h:231
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(ACTION_MENU *aMenu, SELECTION_CONDITION aCondition, int aOrder)
Definition
conditional_menu.h:130
CONDITIONAL_MENU::ENTRY::m_icon
BITMAPS m_icon
Definition
conditional_menu.h:225
CONDITIONAL_MENU::ENTRY::Order
int Order() const
Definition
conditional_menu.h:213
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(const wxMenuItem &aItem, BITMAPS aBitmap, SELECTION_CONDITION aCondition, int aOrder, bool aCheckmark)
Definition
conditional_menu.h:140
CONDITIONAL_MENU::ENTRY::wxItem
wxMenuItem * wxItem() const
Definition
conditional_menu.h:197
CONDITIONAL_MENU::ENTRY::Menu
ACTION_MENU * Menu() const
Definition
conditional_menu.h:191
CONDITIONAL_MENU::ENTRY::m_type
ENTRY_TYPE m_type
Definition
conditional_menu.h:224
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(SELECTION_CONDITION aCondition, int aOrder)
Definition
conditional_menu.h:153
CONDITIONAL_MENU::ENTRY::Type
ENTRY_TYPE Type() const
Definition
conditional_menu.h:175
CONDITIONAL_MENU::ENTRY::GetIcon
BITMAPS GetIcon() const
Definition
conditional_menu.h:180
CONDITIONAL_MENU::ENTRY::Condition
const SELECTION_CONDITION & Condition() const
Definition
conditional_menu.h:208
CONDITIONAL_MENU::AddItem
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
Definition
conditional_menu.cpp:44
CONDITIONAL_MENU::create
ACTION_MENU * create() const override
Return an instance of this class. It has to be overridden in inheriting classes.
Definition
conditional_menu.cpp:36
CONDITIONAL_MENU::addEntry
void addEntry(ENTRY aEntry)
Inserts the entry, preserving the requested order.
Definition
conditional_menu.cpp:205
CONDITIONAL_MENU::m_entries
std::list< ENTRY > m_entries
List of all menu entries.
Definition
conditional_menu.h:248
CONDITIONAL_MENU::AddSeparator
void AddSeparator(int aOrder=ANY_ORDER)
Add a separator to the menu.
Definition
conditional_menu.cpp:93
CONDITIONAL_MENU::AddCheckItem
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a checked menu entry to run a TOOL_ACTION on selected items.
Definition
conditional_menu.cpp:52
CONDITIONAL_MENU::AddMenu
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Add a submenu to the menu.
Definition
conditional_menu.cpp:86
CONDITIONAL_MENU::Resolve
void Resolve()
Update the initial contents so that wxWidgets doesn't get its knickers tied in a knot over the menu b...
Definition
conditional_menu.cpp:108
CONDITIONAL_MENU::ANY_ORDER
static const int ANY_ORDER
Constant to indicate that we do not care about an ENTRY location in the menu.
Definition
conditional_menu.h:41
CONDITIONAL_MENU::CONDITIONAL_MENU
CONDITIONAL_MENU(TOOL_INTERACTIVE *aTool)
Definition
conditional_menu.cpp:30
CONDITIONAL_MENU::Evaluate
void Evaluate(const SELECTION &aSelection)
Update the contents of the menu based on the supplied conditions.
Definition
conditional_menu.cpp:124
PCB_SELECTION_TOOL
The selection tool: currently supports:
Definition
pcb_selection_tool.h:64
SELECTION_CONDITIONS::ShowAlways
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
Definition
selection_conditions.h:71
SELECTION
Definition
selection.h:35
TOOL_ACTION
Represent a single user action.
Definition
tool_action.h:300
TOOL_INTERACTIVE
Definition
tool_interactive.h:53
std
STL namespace.
selection_conditions.h
SELECTION_CONDITION
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
Definition
selection_conditions.h:33
src
include
tool
conditional_menu.h
Generated on Wed Oct 7 2026 00:05:59 for KiCad PCB EDA Suite by
1.13.2