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
91
void
AddMenu
(
ACTION_MENU
* aMenu,
92
const
SELECTION_CONDITION
& aCondition =
SELECTION_CONDITIONS::ShowAlways
,
93
int
aOrder =
ANY_ORDER
);
94
100
void
AddSeparator
(
int
aOrder =
ANY_ORDER
);
101
102
void
AddSeparator
(
const
SELECTION_CONDITION
& aCondition,
int
aOrder =
ANY_ORDER
);
103
107
void
Evaluate
(
const
SELECTION
& aSelection );
108
114
void
Resolve
();
115
116
private
:
118
class
ENTRY
119
{
120
public
:
121
ENTRY
(
const
TOOL_ACTION
* aAction,
SELECTION_CONDITION
aCondition,
int
aOrder,
122
bool
aCheckmark ) :
123
m_type
(
ACTION
),
124
m_icon
( static_cast<
BITMAPS
>( 0 ) ),
125
m_condition
(
std
::
move
( aCondition ) ),
126
m_order
( aOrder ),
127
m_isCheckmarkEntry
( aCheckmark )
128
{
129
m_data
.action = aAction;
130
}
131
132
ENTRY
(
ACTION_MENU
* aMenu,
SELECTION_CONDITION
aCondition,
int
aOrder ) :
133
m_type
(
MENU
),
134
m_icon
( static_cast<
BITMAPS
>( 0 ) ),
135
m_condition
(
std
::
move
( aCondition ) ),
136
m_order
( aOrder ),
137
m_isCheckmarkEntry
( false )
138
{
139
m_data
.menu = aMenu;
140
}
141
142
ENTRY
(
const
wxMenuItem& aItem,
BITMAPS
aBitmap,
143
SELECTION_CONDITION
aCondition,
int
aOrder,
bool
aCheckmark ) :
144
m_type
(
WXITEM
),
145
m_icon
( aBitmap ),
146
m_condition
(
std
::
move
( aCondition ) ),
147
m_order
( aOrder ),
148
m_isCheckmarkEntry
( aCheckmark )
149
{
150
m_data
.wxItem =
new
wxMenuItem(
nullptr
, aItem.GetId(), aItem.GetItemLabel(),
151
aItem.GetHelp(), aItem.GetKind() );
152
}
153
154
// Separator
155
ENTRY
(
SELECTION_CONDITION
aCondition,
int
aOrder ) :
156
m_type
(
SEPARATOR
),
157
m_icon
( static_cast<
BITMAPS
>( 0 ) ),
158
m_data
(),
159
m_condition
(
std
::
move
( aCondition ) ),
160
m_order
( aOrder ),
161
m_isCheckmarkEntry
( false )
162
{
163
}
164
165
ENTRY
(
const
ENTRY
& aEntry );
166
167
~ENTRY
();
168
170
enum
ENTRY_TYPE
{
171
ACTION
,
172
MENU
,
173
WXITEM
,
174
SEPARATOR
175
};
176
177
inline
ENTRY_TYPE
Type
()
const
178
{
179
return
m_type
;
180
}
181
182
inline
BITMAPS
GetIcon
()
const
183
{
184
return
m_icon
;
185
}
186
187
inline
const
TOOL_ACTION
*
Action
()
const
188
{
189
assert(
m_type
==
ACTION
);
190
return
m_data
.action;
191
}
192
193
inline
ACTION_MENU
*
Menu
()
const
194
{
195
assert(
m_type
==
MENU
);
196
return
m_data
.menu;
197
}
198
199
inline
wxMenuItem*
wxItem
()
const
200
{
201
assert(
m_type
==
WXITEM
);
202
return
m_data
.wxItem;
203
}
204
205
inline
bool
IsCheckmarkEntry
()
const
206
{
207
return
m_isCheckmarkEntry
;
208
}
209
210
inline
const
SELECTION_CONDITION
&
Condition
()
const
211
{
212
return
m_condition
;
213
}
214
215
inline
int
Order
()
const
216
{
217
return
m_order
;
218
}
219
220
inline
void
SetOrder
(
int
aOrder )
221
{
222
m_order
= aOrder;
223
}
224
225
private
:
226
ENTRY_TYPE
m_type
;
227
BITMAPS
m_icon
;
228
229
// This class owns the wxItem object and needs to create, copy and delete it accordingly
230
// But it does not own the action nor menu item
231
union
{
232
const
TOOL_ACTION
*
action
;
233
ACTION_MENU
*
menu
;
234
wxMenuItem*
wxItem
;
235
}
m_data
;
236
238
SELECTION_CONDITION
m_condition
;
239
241
int
m_order
;
242
243
bool
m_isCheckmarkEntry
;
244
};
245
247
void
addEntry
(
ENTRY
aEntry );
248
250
std::list<ENTRY>
m_entries
;
251
};
252
253
#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:374
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:286
CONDITIONAL_MENU::ENTRY
< Helper class to organize menu entries.Inserts the entry, preserving the requested order.
Definition
conditional_menu.h:119
CONDITIONAL_MENU::ENTRY::m_order
int m_order
Definition
conditional_menu.h:241
CONDITIONAL_MENU::ENTRY::m_isCheckmarkEntry
bool m_isCheckmarkEntry
Definition
conditional_menu.h:243
CONDITIONAL_MENU::ENTRY::wxItem
wxMenuItem * wxItem
Definition
conditional_menu.h:234
CONDITIONAL_MENU::ENTRY::Action
const TOOL_ACTION * Action() const
Definition
conditional_menu.h:187
CONDITIONAL_MENU::ENTRY::ENTRY_TYPE
ENTRY_TYPE
Definition
conditional_menu.h:170
CONDITIONAL_MENU::ENTRY::MENU
@ MENU
Definition
conditional_menu.h:172
CONDITIONAL_MENU::ENTRY::ACTION
@ ACTION
Definition
conditional_menu.h:171
CONDITIONAL_MENU::ENTRY::SEPARATOR
@ SEPARATOR
Definition
conditional_menu.h:174
CONDITIONAL_MENU::ENTRY::WXITEM
@ WXITEM
Definition
conditional_menu.h:173
CONDITIONAL_MENU::ENTRY::IsCheckmarkEntry
bool IsCheckmarkEntry() const
Definition
conditional_menu.h:205
CONDITIONAL_MENU::ENTRY::SetOrder
void SetOrder(int aOrder)
Definition
conditional_menu.h:220
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(const TOOL_ACTION *aAction, SELECTION_CONDITION aCondition, int aOrder, bool aCheckmark)
Definition
conditional_menu.h:121
CONDITIONAL_MENU::ENTRY::~ENTRY
~ENTRY()
Possible entry types.
Definition
conditional_menu.cpp:254
CONDITIONAL_MENU::ENTRY::m_data
union CONDITIONAL_MENU::ENTRY::@223133073310361045126170055313230071325071242350 m_data
Condition to be fulfilled to show the entry in menu.
CONDITIONAL_MENU::ENTRY::action
const TOOL_ACTION * action
Definition
conditional_menu.h:232
CONDITIONAL_MENU::ENTRY::m_condition
SELECTION_CONDITION m_condition
Order number, the higher the number the lower position it takes it is in the menu.
Definition
conditional_menu.h:238
CONDITIONAL_MENU::ENTRY::menu
ACTION_MENU * menu
Definition
conditional_menu.h:233
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(ACTION_MENU *aMenu, SELECTION_CONDITION aCondition, int aOrder)
Definition
conditional_menu.h:132
CONDITIONAL_MENU::ENTRY::m_icon
BITMAPS m_icon
Definition
conditional_menu.h:227
CONDITIONAL_MENU::ENTRY::Order
int Order() const
Definition
conditional_menu.h:215
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(const wxMenuItem &aItem, BITMAPS aBitmap, SELECTION_CONDITION aCondition, int aOrder, bool aCheckmark)
Definition
conditional_menu.h:142
CONDITIONAL_MENU::ENTRY::wxItem
wxMenuItem * wxItem() const
Definition
conditional_menu.h:199
CONDITIONAL_MENU::ENTRY::Menu
ACTION_MENU * Menu() const
Definition
conditional_menu.h:193
CONDITIONAL_MENU::ENTRY::m_type
ENTRY_TYPE m_type
Definition
conditional_menu.h:226
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(SELECTION_CONDITION aCondition, int aOrder)
Definition
conditional_menu.h:155
CONDITIONAL_MENU::ENTRY::Type
ENTRY_TYPE Type() const
Definition
conditional_menu.h:177
CONDITIONAL_MENU::ENTRY::GetIcon
BITMAPS GetIcon() const
Definition
conditional_menu.h:182
CONDITIONAL_MENU::ENTRY::Condition
const SELECTION_CONDITION & Condition() const
Definition
conditional_menu.h:210
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)
List of all menu entries.
Definition
conditional_menu.cpp:205
CONDITIONAL_MENU::m_entries
std::list< ENTRY > m_entries
Definition
conditional_menu.h:250
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:63
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 Fri Jun 26 2026 00:05:37 for KiCad PCB EDA Suite by
1.13.2