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, 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 CONDITIONAL_MENU_H
28
#define CONDITIONAL_MENU_H
29
30
#include <
tool/selection_conditions.h
>
31
#include <
tool/action_menu.h
>
32
#include <list>
33
34
class
PCB_SELECTION_TOOL
;
35
class
TOOL_ACTION
;
36
class
TOOL_INTERACTIVE
;
37
38
enum class
BITMAPS
:
unsigned
int;
39
40
41
class
CONDITIONAL_MENU
:
public
ACTION_MENU
42
{
43
public
:
45
static
const
int
ANY_ORDER
= -1;
46
47
CONDITIONAL_MENU
(
TOOL_INTERACTIVE
* aTool );
48
49
ACTION_MENU
*
create
()
const override
;
50
59
void
AddItem
(
const
TOOL_ACTION
& aAction,
const
SELECTION_CONDITION
& aCondition,
60
int
aOrder =
ANY_ORDER
);
61
62
void
AddItem
(
int
aId,
const
wxString& aText,
const
wxString& aTooltip,
BITMAPS
aIcon,
63
const
SELECTION_CONDITION
& aCondition,
int
aOrder =
ANY_ORDER
);
64
76
void
AddCheckItem
(
const
TOOL_ACTION
& aAction,
const
SELECTION_CONDITION
& aCondition,
77
int
aOrder =
ANY_ORDER
);
78
79
void
AddCheckItem
(
int
aId,
const
wxString& aText,
const
wxString& aTooltip,
BITMAPS
aIcon,
80
const
SELECTION_CONDITION
& aCondition,
int
aOrder =
ANY_ORDER
);
81
95
void
AddMenu
(
ACTION_MENU
* aMenu,
96
const
SELECTION_CONDITION
& aCondition =
SELECTION_CONDITIONS::ShowAlways
,
97
int
aOrder =
ANY_ORDER
);
98
104
void
AddSeparator
(
int
aOrder =
ANY_ORDER
);
105
106
void
AddSeparator
(
const
SELECTION_CONDITION
& aCondition,
int
aOrder =
ANY_ORDER
);
107
111
void
Evaluate
(
const
SELECTION
& aSelection );
112
118
void
Resolve
();
119
120
private
:
122
class
ENTRY
123
{
124
public
:
125
ENTRY
(
const
TOOL_ACTION
* aAction,
SELECTION_CONDITION
aCondition,
int
aOrder,
126
bool
aCheckmark ) :
127
m_type
(
ACTION
),
128
m_icon
( static_cast<
BITMAPS
>( 0 ) ),
129
m_condition
(
std
::
move
( aCondition ) ),
130
m_order
( aOrder ),
131
m_isCheckmarkEntry
( aCheckmark )
132
{
133
m_data
.action = aAction;
134
}
135
136
ENTRY
(
ACTION_MENU
* aMenu,
SELECTION_CONDITION
aCondition,
int
aOrder ) :
137
m_type
(
MENU
),
138
m_icon
( static_cast<
BITMAPS
>( 0 ) ),
139
m_condition
(
std
::
move
( aCondition ) ),
140
m_order
( aOrder ),
141
m_isCheckmarkEntry
( false )
142
{
143
m_data
.menu = aMenu;
144
}
145
146
ENTRY
(
const
wxMenuItem& aItem,
BITMAPS
aBitmap,
147
SELECTION_CONDITION
aCondition,
int
aOrder,
bool
aCheckmark ) :
148
m_type
(
WXITEM
),
149
m_icon
( aBitmap ),
150
m_condition
(
std
::
move
( aCondition ) ),
151
m_order
( aOrder ),
152
m_isCheckmarkEntry
( aCheckmark )
153
{
154
m_data
.wxItem =
new
wxMenuItem(
nullptr
, aItem.GetId(), aItem.GetItemLabel(),
155
aItem.GetHelp(), aItem.GetKind() );
156
}
157
158
// Separator
159
ENTRY
(
SELECTION_CONDITION
aCondition,
int
aOrder ) :
160
m_type
(
SEPARATOR
),
161
m_icon
( static_cast<
BITMAPS
>( 0 ) ),
162
m_data
(),
163
m_condition
(
std
::
move
( aCondition ) ),
164
m_order
( aOrder ),
165
m_isCheckmarkEntry
( false )
166
{
167
}
168
169
ENTRY
(
const
ENTRY
& aEntry );
170
171
~ENTRY
();
172
174
enum
ENTRY_TYPE
{
175
ACTION
,
176
MENU
,
177
WXITEM
,
178
SEPARATOR
179
};
180
181
inline
ENTRY_TYPE
Type
()
const
182
{
183
return
m_type
;
184
}
185
186
inline
BITMAPS
GetIcon
()
const
187
{
188
return
m_icon
;
189
}
190
191
inline
const
TOOL_ACTION
*
Action
()
const
192
{
193
assert(
m_type
==
ACTION
);
194
return
m_data
.action;
195
}
196
197
inline
ACTION_MENU
*
Menu
()
const
198
{
199
assert(
m_type
==
MENU
);
200
return
m_data
.menu;
201
}
202
203
inline
wxMenuItem*
wxItem
()
const
204
{
205
assert(
m_type
==
WXITEM
);
206
return
m_data
.wxItem;
207
}
208
209
inline
bool
IsCheckmarkEntry
()
const
210
{
211
return
m_isCheckmarkEntry
;
212
}
213
214
inline
const
SELECTION_CONDITION
&
Condition
()
const
215
{
216
return
m_condition
;
217
}
218
219
inline
int
Order
()
const
220
{
221
return
m_order
;
222
}
223
224
inline
void
SetOrder
(
int
aOrder )
225
{
226
m_order
= aOrder;
227
}
228
229
private
:
230
ENTRY_TYPE
m_type
;
231
BITMAPS
m_icon
;
232
233
// This class owns the wxItem object and needs to create, copy and delete it accordingly
234
// But it does not own the action nor menu item
235
union
{
236
const
TOOL_ACTION
*
action
;
237
ACTION_MENU
*
menu
;
238
wxMenuItem*
wxItem
;
239
}
m_data
;
240
242
SELECTION_CONDITION
m_condition
;
243
245
int
m_order
;
246
247
bool
m_isCheckmarkEntry
;
248
};
249
251
void
addEntry
(
ENTRY
aEntry );
252
254
std::list<ENTRY>
m_entries
;
255
};
256
257
#endif
/* CONDITIONAL_MENU_H */
action_menu.h
BITMAPS
BITMAPS
A list of all bitmap identifiers.
Definition
bitmaps_list.h:33
BITMAPS::move
@ move
Definition
bitmaps_list.h:376
ACTION_MENU::ACTION_MENU
ACTION_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
Default constructor.
Definition
action_menu.cpp:51
ACTION_MENU::TOOL_INTERACTIVE
friend class TOOL_INTERACTIVE
Definition
action_menu.h:284
CONDITIONAL_MENU::ENTRY
< Helper class to organize menu entries.Inserts the entry, preserving the requested order.
Definition
conditional_menu.h:123
CONDITIONAL_MENU::ENTRY::m_order
int m_order
Definition
conditional_menu.h:245
CONDITIONAL_MENU::ENTRY::m_isCheckmarkEntry
bool m_isCheckmarkEntry
Definition
conditional_menu.h:247
CONDITIONAL_MENU::ENTRY::wxItem
wxMenuItem * wxItem
Definition
conditional_menu.h:238
CONDITIONAL_MENU::ENTRY::Action
const TOOL_ACTION * Action() const
Definition
conditional_menu.h:191
CONDITIONAL_MENU::ENTRY::ENTRY_TYPE
ENTRY_TYPE
Definition
conditional_menu.h:174
CONDITIONAL_MENU::ENTRY::MENU
@ MENU
Definition
conditional_menu.h:176
CONDITIONAL_MENU::ENTRY::ACTION
@ ACTION
Definition
conditional_menu.h:175
CONDITIONAL_MENU::ENTRY::SEPARATOR
@ SEPARATOR
Definition
conditional_menu.h:178
CONDITIONAL_MENU::ENTRY::WXITEM
@ WXITEM
Definition
conditional_menu.h:177
CONDITIONAL_MENU::ENTRY::IsCheckmarkEntry
bool IsCheckmarkEntry() const
Definition
conditional_menu.h:209
CONDITIONAL_MENU::ENTRY::SetOrder
void SetOrder(int aOrder)
Definition
conditional_menu.h:224
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(const TOOL_ACTION *aAction, SELECTION_CONDITION aCondition, int aOrder, bool aCheckmark)
Definition
conditional_menu.h:125
CONDITIONAL_MENU::ENTRY::~ENTRY
~ENTRY()
Possible entry types.
Definition
conditional_menu.cpp:258
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:236
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:242
CONDITIONAL_MENU::ENTRY::menu
ACTION_MENU * menu
Definition
conditional_menu.h:237
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(ACTION_MENU *aMenu, SELECTION_CONDITION aCondition, int aOrder)
Definition
conditional_menu.h:136
CONDITIONAL_MENU::ENTRY::m_icon
BITMAPS m_icon
Definition
conditional_menu.h:231
CONDITIONAL_MENU::ENTRY::Order
int Order() const
Definition
conditional_menu.h:219
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(const wxMenuItem &aItem, BITMAPS aBitmap, SELECTION_CONDITION aCondition, int aOrder, bool aCheckmark)
Definition
conditional_menu.h:146
CONDITIONAL_MENU::ENTRY::wxItem
wxMenuItem * wxItem() const
Definition
conditional_menu.h:203
CONDITIONAL_MENU::ENTRY::Menu
ACTION_MENU * Menu() const
Definition
conditional_menu.h:197
CONDITIONAL_MENU::ENTRY::m_type
ENTRY_TYPE m_type
Definition
conditional_menu.h:230
CONDITIONAL_MENU::ENTRY::ENTRY
ENTRY(SELECTION_CONDITION aCondition, int aOrder)
Definition
conditional_menu.h:159
CONDITIONAL_MENU::ENTRY::Type
ENTRY_TYPE Type() const
Definition
conditional_menu.h:181
CONDITIONAL_MENU::ENTRY::GetIcon
BITMAPS GetIcon() const
Definition
conditional_menu.h:186
CONDITIONAL_MENU::ENTRY::Condition
const SELECTION_CONDITION & Condition() const
Definition
conditional_menu.h:214
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:48
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:40
CONDITIONAL_MENU::addEntry
void addEntry(ENTRY aEntry)
List of all menu entries.
Definition
conditional_menu.cpp:209
CONDITIONAL_MENU::m_entries
std::list< ENTRY > m_entries
Definition
conditional_menu.h:254
CONDITIONAL_MENU::AddSeparator
void AddSeparator(int aOrder=ANY_ORDER)
Add a separator to the menu.
Definition
conditional_menu.cpp:97
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:56
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:90
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:112
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:45
CONDITIONAL_MENU::CONDITIONAL_MENU
CONDITIONAL_MENU(TOOL_INTERACTIVE *aTool)
Definition
conditional_menu.cpp:34
CONDITIONAL_MENU::Evaluate
void Evaluate(const SELECTION &aSelection)
Update the contents of the menu based on the supplied conditions.
Definition
conditional_menu.cpp:128
PCB_SELECTION_TOOL
The selection tool: currently supports:
Definition
pcb_selection_tool.h:66
SELECTION_CONDITIONS::ShowAlways
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
Definition
selection_conditions.h:75
SELECTION
Definition
selection.h:39
TOOL_ACTION
Represent a single user action.
Definition
tool_action.h:304
TOOL_INTERACTIVE
Definition
tool_interactive.h:57
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:37
src
include
tool
conditional_menu.h
Generated on Sun Sep 21 2025 01:05:26 for KiCad PCB EDA Suite by
1.13.2