KiCad PCB EDA Suite
SELECTION_CONDITIONS Class Reference

Class that groups generic conditions for selected items. More...

#include <selection_conditions.h>

Inheritance diagram for SELECTION_CONDITIONS:
PCB_SELECTION_CONDITIONS

Static Public Member Functions

static bool ShowAlways (const SELECTION &aSelection)
 Function ShowAlways The default condition function (always returns true). More...
 
static bool NotEmpty (const SELECTION &aSelection)
 Function NotEmpty Tests if there are any items selected. More...
 
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 given type. More...
 
static SELECTION_CONDITION OnlyType (KICAD_T aType)
 Function OnlyType Creates a functor that tests if the selected items are only of given type. More...
 
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. More...
 
static SELECTION_CONDITION OnlyTypes (const KICAD_T aTypes[])
 Function OnlyTypes Creates a functor that tests if the selected items are only of given types. More...
 
static SELECTION_CONDITION Count (int aNumber)
 Function Count Creates a functor that tests if the number of selected items is equal to the value given as parameter. More...
 
static SELECTION_CONDITION MoreThan (int aNumber)
 Function MoreThan Creates a functor that tests if the number of selected items is greater than the value given as parameter. More...
 
static SELECTION_CONDITION LessThan (int aNumber)
 Function LessThan Creates a functor that tests if the number of selected items is smaller than the value given as parameter. More...
 

Static Private Member Functions

static bool hasTypeFunc (const SELECTION &aSelection, KICAD_T aType)
 

Helper function used by HasType()

More...
 
static bool onlyTypeFunc (const SELECTION &aSelection, KICAD_T aType)
 

Helper function used by OnlyType()

More...
 
static bool onlyTypesFunc (const SELECTION &aSelection, const std::vector< KICAD_T > &aTypes)
 

Helper function used by OnlyTypes()

More...
 
static bool onlyTypesFuncArr (const SELECTION &aSelection, const KICAD_T aTypes[])
 
static bool countFunc (const SELECTION &aSelection, int aNumber)
 

Helper function used by Count()

More...
 
static bool moreThanFunc (const SELECTION &aSelection, int aNumber)
 

Helper function used by MoreThan()

More...
 
static bool lessThanFunc (const SELECTION &aSelection, int aNumber)
 

Helper function used by LessThan()

More...
 
static bool orFunc (const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB, const SELECTION &aSelection)
 

Helper function used by operator||

More...
 
static bool andFunc (const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB, const SELECTION &aSelection)
 

Helper function used by operator&&

More...
 

Friends

SELECTION_CONDITION operator|| (const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
 
SELECTION_CONDITION operator&& (const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB)
 

Detailed Description

Class that groups generic conditions for selected items.

Definition at line 47 of file selection_conditions.h.

Member Function Documentation

static bool SELECTION_CONDITIONS::andFunc ( const SELECTION_CONDITION aConditionA,
const SELECTION_CONDITION aConditionB,
const SELECTION aSelection 
)
inlinestaticprivate

Helper function used by operator&&

Definition at line 157 of file selection_conditions.h.

Referenced by operator&&().

159  {
160  return aConditionA( aSelection ) && aConditionB( aSelection );
161  }
SELECTION_CONDITION SELECTION_CONDITIONS::Count ( int  aNumber)
static

Function Count Creates a functor that tests if the number of selected items is equal to the value given as parameter.

Parameters
aNumberis the number of expected items.
Returns
Functor testing if the number of selected items is equal aNumber.

Definition at line 63 of file selection_conditions.cpp.

References countFunc().

Referenced by PAD_CONTEXT_MENU::getEnablements(), PAD_TOOL::Init(), EDIT_TOOL::Init(), and ZONE_CONTEXT_MENU::update().

64 {
65  return std::bind( &SELECTION_CONDITIONS::countFunc, _1, aNumber );
66 }
static bool countFunc(const SELECTION &aSelection, int aNumber)
Helper function used by Count()
bool SELECTION_CONDITIONS::countFunc ( const SELECTION aSelection,
int  aNumber 
)
staticprivate

Helper function used by Count()

Definition at line 163 of file selection_conditions.cpp.

References SELECTION::Size().

Referenced by Count().

164 {
165  return aSelection.Size() == aNumber;
166 }
int Size() const
Returns the number of selected parts.
Definition: selection.h:112
SELECTION_CONDITION SELECTION_CONDITIONS::HasType ( KICAD_T  aType)
static

Function HasType Creates a functor that tests if among the selected items there is at least one of a given type.

Parameters
aTypeis the type that is searched.
Returns
Functor testing for presence of items of a given type.

Definition at line 39 of file selection_conditions.cpp.

References hasTypeFunc().

Referenced by PAD_CONTEXT_MENU::getEnablements(), and PAD_TOOL::Init().

40 {
41  return std::bind( &SELECTION_CONDITIONS::hasTypeFunc, _1, aType );
42 }
static bool hasTypeFunc(const SELECTION &aSelection, KICAD_T aType)
Helper function used by HasType()
bool SELECTION_CONDITIONS::hasTypeFunc ( const SELECTION aSelection,
KICAD_T  aType 
)
staticprivate

Helper function used by HasType()

Definition at line 81 of file selection_conditions.cpp.

Referenced by HasType().

82 {
83  for( const auto& item : aSelection )
84  {
85  if( item->Type() == aType )
86  return true;
87  }
88 
89  return false;
90 }
SELECTION_CONDITION SELECTION_CONDITIONS::LessThan ( int  aNumber)
static

Function LessThan Creates a functor that tests if the number of selected items is smaller than the value given as parameter.

Parameters
aNumberis the number used for comparison.
Returns
Functor testing if the number of selected items is smaller than aNumber.

Definition at line 75 of file selection_conditions.cpp.

References lessThanFunc().

76 {
77  return std::bind( &SELECTION_CONDITIONS::lessThanFunc, _1, aNumber );
78 }
static bool lessThanFunc(const SELECTION &aSelection, int aNumber)
Helper function used by LessThan()
bool SELECTION_CONDITIONS::lessThanFunc ( const SELECTION aSelection,
int  aNumber 
)
staticprivate

Helper function used by LessThan()

Definition at line 175 of file selection_conditions.cpp.

References SELECTION::Size().

Referenced by LessThan().

176 {
177  return aSelection.Size() < aNumber;
178 }
int Size() const
Returns the number of selected parts.
Definition: selection.h:112
SELECTION_CONDITION SELECTION_CONDITIONS::MoreThan ( int  aNumber)
static

Function MoreThan Creates a functor that tests if the number of selected items is greater than the value given as parameter.

Parameters
aNumberis the number used for comparison.
Returns
Functor testing if the number of selected items is greater than aNumber.

Definition at line 69 of file selection_conditions.cpp.

References moreThanFunc().

Referenced by ALIGN_DISTRIBUTE_TOOL::Init(), and ZONE_CONTEXT_MENU::update().

70 {
71  return std::bind( &SELECTION_CONDITIONS::moreThanFunc, _1, aNumber );
72 }
static bool moreThanFunc(const SELECTION &aSelection, int aNumber)
Helper function used by MoreThan()
bool SELECTION_CONDITIONS::moreThanFunc ( const SELECTION aSelection,
int  aNumber 
)
staticprivate

Helper function used by MoreThan()

Definition at line 169 of file selection_conditions.cpp.

References SELECTION::Size().

Referenced by MoreThan().

170 {
171  return aSelection.Size() > aNumber;
172 }
int Size() const
Returns the number of selected parts.
Definition: selection.h:112
bool SELECTION_CONDITIONS::NotEmpty ( const SELECTION aSelection)
static

Function NotEmpty Tests if there are any items selected.

Parameters
aSelectionis the selection to be tested.
Returns
True if there is at least one item selected.

Definition at line 33 of file selection_conditions.cpp.

References SELECTION::Empty().

Referenced by EDIT_TOOL::Init(), and SELECTION_TOOL::Init().

34 {
35  return !aSelection.Empty();
36 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:106
SELECTION_CONDITION SELECTION_CONDITIONS::OnlyType ( KICAD_T  aType)
static

Function OnlyType Creates a functor that tests if the selected items are only of given type.

Parameters
aTypeis the type that is searched.
Returns
Functor testing if selected items are exclusively of one type.

Definition at line 45 of file selection_conditions.cpp.

References onlyTypeFunc().

Referenced by PAD_CONTEXT_MENU::getEnablements(), PCB_EDITOR_CONTROL::Init(), EDIT_TOOL::Init(), SELECT_MENU::update(), and ZONE_CONTEXT_MENU::update().

46 {
47  return std::bind( &SELECTION_CONDITIONS::onlyTypeFunc, _1, aType );
48 }
static bool onlyTypeFunc(const SELECTION &aSelection, KICAD_T aType)
Helper function used by OnlyType()
bool SELECTION_CONDITIONS::onlyTypeFunc ( const SELECTION aSelection,
KICAD_T  aType 
)
staticprivate

Helper function used by OnlyType()

Definition at line 93 of file selection_conditions.cpp.

References SELECTION::Empty().

Referenced by OnlyType().

94 {
95  if( aSelection.Empty() )
96  return false;
97 
98  for( const auto& item : aSelection )
99  {
100  if( item->Type() != aType )
101  return false;
102  }
103 
104  return true;
105 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:106
SELECTION_CONDITION SELECTION_CONDITIONS::OnlyTypes ( const std::vector< KICAD_T > &  aTypes)
static

Function OnlyTypes Creates a functor that tests if the selected items are only of given types.

Parameters
aTypesis a vector containing types that are searched.
Returns
Functor testing if selected items are exclusively of the requested types.

Definition at line 51 of file selection_conditions.cpp.

References onlyTypesFunc().

Referenced by PCB_EDITOR_CONTROL::Init(), EDIT_TOOL::Init(), and EDIT_TOOL::Properties().

52 {
53  return std::bind( &SELECTION_CONDITIONS::onlyTypesFunc, _1, aTypes );
54 }
static bool onlyTypesFunc(const SELECTION &aSelection, const std::vector< KICAD_T > &aTypes)
Helper function used by OnlyTypes()
SELECTION_CONDITION SELECTION_CONDITIONS::OnlyTypes ( const KICAD_T  aTypes[])
static

Function OnlyTypes Creates a functor that tests if the selected items are only of given types.

Parameters
aTypesis an array containing types that are searched. It has to be ended with KICAD_T::EOT as end marker.
Returns
Functor testing if selected items are exclusively of the requested types.

Definition at line 57 of file selection_conditions.cpp.

References onlyTypesFuncArr().

58 {
59  return std::bind( &SELECTION_CONDITIONS::onlyTypesFuncArr, _1, aTypes );
60 }
static bool onlyTypesFuncArr(const SELECTION &aSelection, const KICAD_T aTypes[])
bool SELECTION_CONDITIONS::onlyTypesFunc ( const SELECTION aSelection,
const std::vector< KICAD_T > &  aTypes 
)
staticprivate

Helper function used by OnlyTypes()

Definition at line 108 of file selection_conditions.cpp.

References SELECTION::Empty().

Referenced by OnlyTypes().

109 {
110  if( aSelection.Empty() )
111  return false;
112 
113  for( const auto& item : aSelection )
114  {
115  bool valid = false;
116 
117  for( std::vector<KICAD_T>::const_iterator it = aTypes.begin(); it != aTypes.end(); ++it )
118  {
119  if( item->Type() == *it )
120  {
121  valid = true;
122  break;
123  }
124  }
125 
126  if( !valid )
127  return false;
128  }
129 
130  return true;
131 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:106
bool SELECTION_CONDITIONS::onlyTypesFuncArr ( const SELECTION aSelection,
const KICAD_T  aTypes[] 
)
staticprivate

Definition at line 134 of file selection_conditions.cpp.

References SELECTION::Empty(), and EOT.

Referenced by OnlyTypes().

135 {
136  if( aSelection.Empty() )
137  return false;
138 
139  for( const auto& item : aSelection )
140  {
141  bool valid = false;
142  const KICAD_T* type = aTypes;
143 
144  while( *type != EOT )
145  {
146  if( item->Type() == *type )
147  {
148  valid = true;
149  break;
150  }
151 
152  ++type;
153  }
154 
155  if( !valid )
156  return false;
157  }
158 
159  return true;
160 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:106
search types array terminator (End Of Types)
Definition: typeinfo.h:94
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
static bool SELECTION_CONDITIONS::orFunc ( const SELECTION_CONDITION aConditionA,
const SELECTION_CONDITION aConditionB,
const SELECTION aSelection 
)
inlinestaticprivate

Helper function used by operator||

Definition at line 150 of file selection_conditions.h.

Referenced by operator||().

152  {
153  return aConditionA( aSelection ) || aConditionB( aSelection );
154  }
static bool SELECTION_CONDITIONS::ShowAlways ( const SELECTION aSelection)
inlinestatic

Function ShowAlways The default condition function (always returns true).

Parameters
aSelectionis the selection to be tested.
Returns
Always true;

Definition at line 56 of file selection_conditions.h.

Referenced by TOOL_MENU::AddStandardSubMenus().

57  {
58  return true;
59  }

Friends And Related Function Documentation

SELECTION_CONDITION operator&& ( const SELECTION_CONDITION aConditionA,
const SELECTION_CONDITION aConditionB 
)
friend

Definition at line 188 of file selection_conditions.cpp.

190 {
191  return std::bind( &SELECTION_CONDITIONS::andFunc, aConditionA, aConditionB, _1 );
192 }
static bool andFunc(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 
)
friend

Definition at line 181 of file selection_conditions.cpp.

183 {
184  return std::bind( &SELECTION_CONDITIONS::orFunc, aConditionA, aConditionB, _1 );
185 }
static bool orFunc(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB, const SELECTION &aSelection)
Helper function used by operator||

The documentation for this class was generated from the following files: