KiCad PCB EDA Suite
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  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef SELECTION_CONDITIONS_H_
26 #define SELECTION_CONDITIONS_H_
27 
28 #include <functional>
29 #include <core/typeinfo.h>
30 #include <vector>
31 
32 #include <tool/selection.h>
33 
35 typedef std::function<bool (const SELECTION&)> SELECTION_CONDITION;
36 
38  const SELECTION_CONDITION& aConditionB );
39 
41  const SELECTION_CONDITION& aConditionB );
42 
43 
48 {
49 public:
56  static bool ShowAlways( const SELECTION& aSelection )
57  {
58  return true;
59  }
60 
67  static bool NotEmpty( const SELECTION& aSelection );
68 
75  static SELECTION_CONDITION HasType( KICAD_T aType );
76 
83  static SELECTION_CONDITION OnlyType( KICAD_T aType );
84 
91  static SELECTION_CONDITION OnlyTypes( const std::vector<KICAD_T>& aTypes );
92 
100  static SELECTION_CONDITION OnlyTypes( const KICAD_T aTypes[] );
101 
109  static SELECTION_CONDITION Count( int aNumber );
110 
118  static SELECTION_CONDITION MoreThan( int aNumber );
119 
127  static SELECTION_CONDITION LessThan( int aNumber );
128 
129 private:
131  static bool hasTypeFunc( const SELECTION& aSelection, KICAD_T aType );
132 
134  static bool onlyTypeFunc( const SELECTION& aSelection, KICAD_T aType );
135 
137  static bool onlyTypesFunc( const SELECTION& aSelection, const std::vector<KICAD_T>& aTypes );
138  static bool onlyTypesFuncArr( const SELECTION& aSelection, const KICAD_T aTypes[] );
139 
141  static bool countFunc( const SELECTION& aSelection, int aNumber );
142 
144  static bool moreThanFunc( const SELECTION& aSelection, int aNumber );
145 
147  static bool lessThanFunc( const SELECTION& aSelection, int aNumber );
148 
150  static bool orFunc( const SELECTION_CONDITION& aConditionA,
151  const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
152  {
153  return aConditionA( aSelection ) || aConditionB( aSelection );
154  }
155 
157  static bool andFunc( const SELECTION_CONDITION& aConditionA,
158  const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
159  {
160  return aConditionA( aSelection ) && aConditionB( aSelection );
161  }
162 
163  friend SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
164  const SELECTION_CONDITION& aConditionB );
165 
166  friend SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
167  const SELECTION_CONDITION& aConditionB );
168 };
169 
170 #endif /* SELECTION_CONDITIONS_H_ */
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
static bool onlyTypeFunc(const SELECTION &aSelection, KICAD_T aType)
Helper function used by OnlyType()
static bool countFunc(const SELECTION &aSelection, int aNumber)
Helper function used by Count()
static SELECTION_CONDITION MoreThan(int aNumber)
Function MoreThan Creates a functor that tests if the number of selected items is greater than the va...
static bool lessThanFunc(const SELECTION &aSelection, int aNumber)
Helper function used by LessThan()
static SELECTION_CONDITION HasType(KICAD_T aType)
Function HasType Creates a functor that tests if among the selected items there is at least one of a ...
Class that groups generic conditions for selected items.
friend SELECTION_CONDITION operator||(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
friend SELECTION_CONDITION operator&&(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
static SELECTION_CONDITION Count(int aNumber)
Function Count Creates a functor that tests if the number of selected items is equal to the value giv...
SELECTION_CONDITION operator||(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
static bool NotEmpty(const SELECTION &aSelection)
Function NotEmpty Tests if there are any items selected.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
static bool orFunc(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB, const SELECTION &aSelection)
Helper function used by operator||
SELECTION_CONDITION operator&&(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
static bool onlyTypesFunc(const SELECTION &aSelection, const std::vector< KICAD_T > &aTypes)
Helper function used by OnlyTypes()
static SELECTION_CONDITION LessThan(int aNumber)
Function LessThan Creates a functor that tests if the number of selected items is smaller than the va...
static SELECTION_CONDITION OnlyTypes(const std::vector< KICAD_T > &aTypes)
Function OnlyTypes Creates a functor that tests if the selected items are only of given types...
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
static bool hasTypeFunc(const SELECTION &aSelection, KICAD_T aType)
Helper function used by HasType()
static bool onlyTypesFuncArr(const SELECTION &aSelection, const KICAD_T aTypes[])
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Function OnlyType Creates a functor that tests if the selected items are only of given type...
static bool andFunc(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB, const SELECTION &aSelection)
Helper function used by operator&&
static bool moreThanFunc(const SELECTION &aSelection, int aNumber)
Helper function used by MoreThan()