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 #include <tool/selection.h>
32 
34 typedef std::function<bool (const SELECTION&)> SELECTION_CONDITION;
35 
37  const SELECTION_CONDITION& aConditionB );
38 
40  const SELECTION_CONDITION& aConditionB );
41 
43 
44 
49 {
50 public:
57  static bool ShowAlways( const SELECTION& aSelection )
58  {
59  return true;
60  }
61 
68  static bool NotEmpty( const SELECTION& aSelection );
69 
76  static SELECTION_CONDITION HasType( KICAD_T aType );
77 
84  static SELECTION_CONDITION OnlyType( KICAD_T aType );
85 
93  static SELECTION_CONDITION OnlyTypes( const KICAD_T aTypes[] );
94 
102  static SELECTION_CONDITION Count( int aNumber );
103 
111  static SELECTION_CONDITION MoreThan( int aNumber );
112 
120  static SELECTION_CONDITION LessThan( int aNumber );
121 
122 private:
124  static bool hasTypeFunc( const SELECTION& aSelection, KICAD_T aType );
125 
127  static bool onlyTypeFunc( const SELECTION& aSelection, KICAD_T aType );
128 
130  static bool onlyTypesFunc( const SELECTION& aSelection, const KICAD_T aTypes[] );
131 
133  static bool countFunc( const SELECTION& aSelection, int aNumber );
134 
136  static bool moreThanFunc( const SELECTION& aSelection, int aNumber );
137 
139  static bool lessThanFunc( const SELECTION& aSelection, int aNumber );
140 
142  static bool orFunc( const SELECTION_CONDITION& aConditionA,
143  const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
144  {
145  return aConditionA( aSelection ) || aConditionB( aSelection );
146  }
147 
149  static bool andFunc( const SELECTION_CONDITION& aConditionA,
150  const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
151  {
152  return aConditionA( aSelection ) && aConditionB( aSelection );
153  }
154 
156  static bool notFunc( const SELECTION_CONDITION& aCondition, const SELECTION& aSelection )
157  {
158  return !aCondition( aSelection );
159  }
160 
161  friend SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
162  const SELECTION_CONDITION& aConditionB );
163 
164  friend SELECTION_CONDITION operator&&( const SELECTION_CONDITION& aConditionA,
165  const SELECTION_CONDITION& aConditionB );
166 
167  friend SELECTION_CONDITION operator!( const SELECTION_CONDITION& aCondition );
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 bool notFunc(const SELECTION_CONDITION &aCondition, const SELECTION &aSelection)
Helper function used by operator!
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 OnlyTypes(const KICAD_T aTypes[])
Function OnlyTypes Creates a functor that tests if the selected items are only of given types.
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)
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.
static bool onlyTypesFunc(const SELECTION &aSelection, const KICAD_T aTypes[])
Helper function used by OnlyTypes()
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||
static SELECTION_CONDITION LessThan(int aNumber)
Function LessThan Creates a functor that tests if the number of selected items is smaller than the va...
friend SELECTION_CONDITION operator &&(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
SELECTION_CONDITION operator!(const SELECTION_CONDITION &aCondition)
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
friend SELECTION_CONDITION operator!(const SELECTION_CONDITION &aCondition)
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)
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()