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 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 SELECTION_CONDITIONS_H_
24#define SELECTION_CONDITIONS_H_
25
26#include <functional>
27#include <core/typeinfo.h>
28#include <vector>
29
30class SELECTION;
31
33typedef std::function<bool (const SELECTION&)> SELECTION_CONDITION;
34
36 const SELECTION_CONDITION& aConditionB );
37
39 const SELECTION_CONDITION& aConditionB );
40
42
43
48typedef bool ( &SELECTION_BOOL )( const SELECTION& );
49
51 SELECTION_BOOL aConditionB );
52
54 const SELECTION_CONDITION& aConditionB );
55
57 SELECTION_BOOL aConditionB );
58
60 const SELECTION_CONDITION& aConditionB );
61
66{
67public:
71 static bool ShowAlways( const SELECTION& aSelection ) { return true; }
72
76 static bool ShowNever( const SELECTION& aSelection ) { return false; }
77
81 static bool NotEmpty( const SELECTION& aSelection );
82
86 static bool Empty( const SELECTION& aSelection );
87
91 static bool Idle( const SELECTION& aSelection );
92
96 static bool IdleSelection( const SELECTION& aSelection );
97
105 static SELECTION_CONDITION HasType( KICAD_T aType );
106
114 static SELECTION_CONDITION HasTypes( std::vector<KICAD_T> aTypes );
115
122 static SELECTION_CONDITION OnlyTypes( std::vector<KICAD_T> aTypes );
123
131 static SELECTION_CONDITION Count( int aNumber );
132
140 static SELECTION_CONDITION MoreThan( int aNumber );
141
149 static SELECTION_CONDITION LessThan( int aNumber );
150
151private:
153 static bool hasTypeFunc( const SELECTION& aSelection, KICAD_T aType );
154
156 static bool hasTypesFunc( const SELECTION& aSelection, std::vector<KICAD_T> aTypes );
157
159 static bool onlyTypesFunc( const SELECTION& aSelection, std::vector<KICAD_T> aTypes );
160
162 static bool countFunc( const SELECTION& aSelection, int aNumber );
163
165 static bool moreThanFunc( const SELECTION& aSelection, int aNumber );
166
168 static bool lessThanFunc( const SELECTION& aSelection, int aNumber );
169
171 static bool orFunc( const SELECTION_CONDITION& aConditionA,
172 const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
173 {
174 return aConditionA( aSelection ) || aConditionB( aSelection );
175 }
176
178 static bool andFunc( const SELECTION_CONDITION& aConditionA,
179 const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
180 {
181 return aConditionA( aSelection ) && aConditionB( aSelection );
182 }
183
185 static bool notFunc( const SELECTION_CONDITION& aCondition, const SELECTION& aSelection )
186 {
187 return !aCondition( aSelection );
188 }
189
191 static bool orBoolFunc( const SELECTION_CONDITION& aConditionA,
192 SELECTION_BOOL& aConditionB, const SELECTION& aSelection )
193 {
194 return aConditionA( aSelection ) || aConditionB( aSelection );
195 }
196
198 static bool andBoolFunc( const SELECTION_CONDITION& aConditionA,
199 SELECTION_BOOL& aConditionB, const SELECTION& aSelection )
200 {
201 return aConditionA( aSelection ) && aConditionB( aSelection );
202 }
203
204 friend SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
205 const SELECTION_CONDITION& aConditionB );
206
207 friend SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
208 const SELECTION_CONDITION& aConditionB );
209
210 friend SELECTION_CONDITION operator!( const SELECTION_CONDITION& aCondition );
211
212 friend SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
213 SELECTION_BOOL aConditionB );
214
215 friend SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
216 SELECTION_BOOL aConditionB );
217};
218
219#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 HasTypes().
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 MoreThan().
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 Count().
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 LessThan().
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)
Helper function used by operator &&.
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 OnlyTypes().
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)
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)
bool(& SELECTION_BOOL)(const SELECTION &)
Signature for a reference to a function that takes a SELECTION and returns a boolean.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71