KiCad PCB EDA Suite
Loading...
Searching...
No Matches
selection_conditions.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) 2014 CERN
5 * Copyright (C) 2020-2022 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 SELECTION_CONDITIONS_H_
28#define SELECTION_CONDITIONS_H_
29
30#include <functional>
31#include <core/typeinfo.h>
32#include <vector>
33#include <tool/selection.h>
34
36typedef std::function<bool (const SELECTION&)> SELECTION_CONDITION;
37
39 const SELECTION_CONDITION& aConditionB );
40
42 const SELECTION_CONDITION& aConditionB );
43
45
46
51typedef bool ( &SELECTION_BOOL )( const SELECTION& );
52
54 SELECTION_BOOL aConditionB );
55
57 const SELECTION_CONDITION& aConditionB );
58
60 SELECTION_BOOL aConditionB );
61
63 const SELECTION_CONDITION& aConditionB );
64
69{
70public:
74 static bool ShowAlways( const SELECTION& aSelection ) { return true; }
75
79 static bool ShowNever( const SELECTION& aSelection ) { return false; }
80
84 static bool NotEmpty( const SELECTION& aSelection );
85
89 static bool Empty( const SELECTION& aSelection );
90
94 static bool Idle( const SELECTION& aSelection );
95
99 static bool IdleSelection( const SELECTION& aSelection );
100
108 static SELECTION_CONDITION HasType( KICAD_T aType );
109
117 static SELECTION_CONDITION HasTypes( std::vector<KICAD_T> aTypes );
118
125 static SELECTION_CONDITION OnlyTypes( std::vector<KICAD_T> aTypes );
126
134 static SELECTION_CONDITION Count( int aNumber );
135
143 static SELECTION_CONDITION MoreThan( int aNumber );
144
152 static SELECTION_CONDITION LessThan( int aNumber );
153
154private:
156 static bool hasTypeFunc( const SELECTION& aSelection, KICAD_T aType );
157
159 static bool hasTypesFunc( const SELECTION& aSelection, std::vector<KICAD_T> aTypes );
160
162 static bool onlyTypesFunc( const SELECTION& aSelection, std::vector<KICAD_T> aTypes );
163
165 static bool countFunc( const SELECTION& aSelection, int aNumber );
166
168 static bool moreThanFunc( const SELECTION& aSelection, int aNumber );
169
171 static bool lessThanFunc( const SELECTION& aSelection, int aNumber );
172
174 static bool orFunc( const SELECTION_CONDITION& aConditionA,
175 const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
176 {
177 return aConditionA( aSelection ) || aConditionB( aSelection );
178 }
179
181 static bool andFunc( const SELECTION_CONDITION& aConditionA,
182 const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
183 {
184 return aConditionA( aSelection ) && aConditionB( aSelection );
185 }
186
188 static bool notFunc( const SELECTION_CONDITION& aCondition, const SELECTION& aSelection )
189 {
190 return !aCondition( aSelection );
191 }
192
194 static bool orBoolFunc( const SELECTION_CONDITION& aConditionA,
195 SELECTION_BOOL& aConditionB, const SELECTION& aSelection )
196 {
197 return aConditionA( aSelection ) || aConditionB( aSelection );
198 }
199
201 static bool andBoolFunc( const SELECTION_CONDITION& aConditionA,
202 SELECTION_BOOL& aConditionB, const SELECTION& aSelection )
203 {
204 return aConditionA( aSelection ) && aConditionB( aSelection );
205 }
206
207 friend SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
208 const SELECTION_CONDITION& aConditionB );
209
210 friend SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
211 const SELECTION_CONDITION& aConditionB );
212
213 friend SELECTION_CONDITION operator!( const SELECTION_CONDITION& aCondition );
214
215 friend SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
216 SELECTION_BOOL aConditionB );
217
218 friend SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
219 SELECTION_BOOL aConditionB );
220};
221
222#endif /* SELECTION_CONDITIONS_H_ */
Class that groups generic conditions for selected items.
static bool hasTypesFunc(const SELECTION &aSelection, std::vector< KICAD_T > aTypes)
Helper function used by OnlyTypes()
static SELECTION_CONDITION HasTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if among the selected items there is at least one of a given types.
static SELECTION_CONDITION HasType(KICAD_T aType)
Create a functor that tests if among the selected items there is at least one of a given type.
friend SELECTION_CONDITION operator||(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
static bool Empty(const SELECTION &aSelection)
Test if there are no items selected.
static bool moreThanFunc(const SELECTION &aSelection, int aNumber)
Helper function used by LessThan()
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
static bool countFunc(const SELECTION &aSelection, int aNumber)
Helper function used by MoreThan()
static bool orFunc(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB, const SELECTION &aSelection)
Helper function used by operator&&.
static SELECTION_CONDITION MoreThan(int aNumber)
Create a functor that tests if the number of selected items is greater than the value given as parame...
static bool orBoolFunc(const SELECTION_CONDITION &aConditionA, SELECTION_BOOL &aConditionB, const SELECTION &aSelection)
Helper function used by operator&&.
static bool lessThanFunc(const SELECTION &aSelection, int aNumber)
Helper function used by operator||.
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
static bool IdleSelection(const SELECTION &aSelection)
Test if all selected items are not being edited.
friend SELECTION_CONDITION operator&&(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
static bool andBoolFunc(const SELECTION_CONDITION &aConditionA, SELECTION_BOOL &aConditionB, const SELECTION &aSelection)
friend SELECTION_CONDITION operator!(const SELECTION_CONDITION &aCondition)
static SELECTION_CONDITION LessThan(int aNumber)
Create a functor that tests if the number of selected items is smaller than the value given as parame...
static SELECTION_CONDITION Count(int aNumber)
Create a functor that tests if the number of selected items is equal to the value given as parameter.
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
static bool ShowNever(const SELECTION &aSelection)
Always returns false.
static bool onlyTypesFunc(const SELECTION &aSelection, std::vector< KICAD_T > aTypes)
Helper function used by Count()
static bool andFunc(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB, const SELECTION &aSelection)
Helper function used by operator!
static bool notFunc(const SELECTION_CONDITION &aCondition, const SELECTION &aSelection)
Helper function used by operator||.
static SELECTION_CONDITION OnlyTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if the selected items are only of given types.
static bool hasTypeFunc(const SELECTION &aSelection, KICAD_T aType)
< Helper function used by HasType()
SELECTION_CONDITION operator||(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
bool(&) SELECTION_BOOL(const SELECTION &)
Signature for a reference to a function that takes a SELECTION and returns a boolean.
std::function< bool(const SELECTION &)> SELECTION_CONDITION
< Functor type that checks a specific condition for selected items.
SELECTION_CONDITION operator&&(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
SELECTION_CONDITION operator!(const SELECTION_CONDITION &aCondition)
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78