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
34class SELECTION;
35
37typedef std::function<bool (const SELECTION&)> SELECTION_CONDITION;
38
40 const SELECTION_CONDITION& aConditionB );
41
43 const SELECTION_CONDITION& aConditionB );
44
46
47
52typedef bool ( &SELECTION_BOOL )( const SELECTION& );
53
55 SELECTION_BOOL aConditionB );
56
58 const SELECTION_CONDITION& aConditionB );
59
61 SELECTION_BOOL aConditionB );
62
64 const SELECTION_CONDITION& aConditionB );
65
70{
71public:
75 static bool ShowAlways( const SELECTION& aSelection ) { return true; }
76
80 static bool ShowNever( const SELECTION& aSelection ) { return false; }
81
85 static bool NotEmpty( const SELECTION& aSelection );
86
90 static bool Empty( const SELECTION& aSelection );
91
95 static bool Idle( const SELECTION& aSelection );
96
100 static bool IdleSelection( const SELECTION& aSelection );
101
109 static SELECTION_CONDITION HasType( KICAD_T aType );
110
118 static SELECTION_CONDITION HasTypes( std::vector<KICAD_T> aTypes );
119
126 static SELECTION_CONDITION OnlyTypes( std::vector<KICAD_T> aTypes );
127
135 static SELECTION_CONDITION Count( int aNumber );
136
144 static SELECTION_CONDITION MoreThan( int aNumber );
145
153 static SELECTION_CONDITION LessThan( int aNumber );
154
155private:
157 static bool hasTypeFunc( const SELECTION& aSelection, KICAD_T aType );
158
160 static bool hasTypesFunc( const SELECTION& aSelection, std::vector<KICAD_T> aTypes );
161
163 static bool onlyTypesFunc( const SELECTION& aSelection, std::vector<KICAD_T> aTypes );
164
166 static bool countFunc( const SELECTION& aSelection, int aNumber );
167
169 static bool moreThanFunc( const SELECTION& aSelection, int aNumber );
170
172 static bool lessThanFunc( const SELECTION& aSelection, int aNumber );
173
175 static bool orFunc( const SELECTION_CONDITION& aConditionA,
176 const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
177 {
178 return aConditionA( aSelection ) || aConditionB( aSelection );
179 }
180
182 static bool andFunc( const SELECTION_CONDITION& aConditionA,
183 const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
184 {
185 return aConditionA( aSelection ) && aConditionB( aSelection );
186 }
187
189 static bool notFunc( const SELECTION_CONDITION& aCondition, const SELECTION& aSelection )
190 {
191 return !aCondition( aSelection );
192 }
193
195 static bool orBoolFunc( const SELECTION_CONDITION& aConditionA,
196 SELECTION_BOOL& aConditionB, const SELECTION& aSelection )
197 {
198 return aConditionA( aSelection ) || aConditionB( aSelection );
199 }
200
202 static bool andBoolFunc( const SELECTION_CONDITION& aConditionA,
203 SELECTION_BOOL& aConditionB, const SELECTION& aSelection )
204 {
205 return aConditionA( aSelection ) && aConditionB( aSelection );
206 }
207
208 friend SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
209 const SELECTION_CONDITION& aConditionB );
210
211 friend SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
212 const SELECTION_CONDITION& aConditionB );
213
214 friend SELECTION_CONDITION operator!( const SELECTION_CONDITION& aCondition );
215
216 friend SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
217 SELECTION_BOOL aConditionB );
218
219 friend SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
220 SELECTION_BOOL aConditionB );
221};
222
223#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 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