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:
EE_CONDITIONS PCB_SELECTION_CONDITIONS PL_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 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 KICAD_T aTypes[])
 

Helper function used by OnlyTypes()

More...
 
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...
 
static bool notFunc (const SELECTION_CONDITION &aCondition, 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)
 
SELECTION_CONDITION operator! (const SELECTION_CONDITION &aCondition)
 

Detailed Description

Class that groups generic conditions for selected items.

Definition at line 48 of file selection_conditions.h.

Member Function Documentation

◆ andFunc()

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 149 of file selection_conditions.h.

151  {
152  return aConditionA( aSelection ) && aConditionB( aSelection );
153  }

Referenced by operator &&().

◆ Count()

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 58 of file selection_conditions.cpp.

59 {
60  return std::bind( &SELECTION_CONDITIONS::countFunc, _1, aNumber );
61 }
static bool countFunc(const SELECTION &aSelection, int aNumber)
Helper function used by Count()

References countFunc().

Referenced by LIB_EDIT_TOOL::Init(), LIB_PIN_TOOL::Init(), SCH_EDIT_TOOL::Init(), EE_INSPECTION_TOOL::Init(), PAD_TOOL::Init(), EE_SELECTION_TOOL::Init(), EDIT_TOOL::Init(), and ZONE_CONTEXT_MENU::update().

◆ countFunc()

bool SELECTION_CONDITIONS::countFunc ( const SELECTION aSelection,
int  aNumber 
)
staticprivate

Helper function used by Count()

Definition at line 120 of file selection_conditions.cpp.

121 {
122  return aSelection.Size() == aNumber;
123 }
int Size() const
Returns the number of selected parts.
Definition: selection.h:125

References SELECTION::Size().

Referenced by Count().

◆ HasType()

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 40 of file selection_conditions.cpp.

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

References hasTypeFunc().

Referenced by PAD_TOOL::Init().

◆ hasTypeFunc()

bool SELECTION_CONDITIONS::hasTypeFunc ( const SELECTION aSelection,
KICAD_T  aType 
)
staticprivate

Helper function used by HasType()

Definition at line 76 of file selection_conditions.cpp.

77 {
78  for( const auto& item : aSelection )
79  {
80  if( item->Type() == aType )
81  return true;
82  }
83 
84  return false;
85 }

Referenced by HasType().

◆ LessThan()

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 70 of file selection_conditions.cpp.

71 {
72  return std::bind( &SELECTION_CONDITIONS::lessThanFunc, _1, aNumber );
73 }
static bool lessThanFunc(const SELECTION &aSelection, int aNumber)
Helper function used by LessThan()

References lessThanFunc().

◆ lessThanFunc()

bool SELECTION_CONDITIONS::lessThanFunc ( const SELECTION aSelection,
int  aNumber 
)
staticprivate

Helper function used by LessThan()

Definition at line 132 of file selection_conditions.cpp.

133 {
134  return aSelection.Size() < aNumber;
135 }
int Size() const
Returns the number of selected parts.
Definition: selection.h:125

References SELECTION::Size().

Referenced by LessThan().

◆ MoreThan()

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 64 of file selection_conditions.cpp.

65 {
66  return std::bind( &SELECTION_CONDITIONS::moreThanFunc, _1, aNumber );
67 }
static bool moreThanFunc(const SELECTION &aSelection, int aNumber)
Helper function used by MoreThan()

References moreThanFunc().

Referenced by SCH_EDIT_TOOL::Init(), ALIGN_DISTRIBUTE_TOOL::Init(), EE_SELECTION_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), PL_EDITOR_FRAME::ReCreateMenuBar(), and ZONE_CONTEXT_MENU::update().

◆ moreThanFunc()

bool SELECTION_CONDITIONS::moreThanFunc ( const SELECTION aSelection,
int  aNumber 
)
staticprivate

Helper function used by MoreThan()

Definition at line 126 of file selection_conditions.cpp.

127 {
128  return aSelection.Size() > aNumber;
129 }
int Size() const
Returns the number of selected parts.
Definition: selection.h:125

References SELECTION::Size().

Referenced by MoreThan().

◆ NotEmpty()

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 34 of file selection_conditions.cpp.

35 {
36  return !aSelection.Empty();
37 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119

References SELECTION::Empty().

Referenced by LIB_EDIT_TOOL::Init(), PL_EDIT_TOOL::Init(), SCH_EDIT_TOOL::Init(), PAD_TOOL::Init(), SELECTION_TOOL::Init(), EDIT_TOOL::Init(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), and PCB_EDIT_FRAME::ReCreateMenuBar().

◆ notFunc()

static bool SELECTION_CONDITIONS::notFunc ( const SELECTION_CONDITION aCondition,
const SELECTION aSelection 
)
inlinestaticprivate

Helper function used by operator!

Definition at line 156 of file selection_conditions.h.

157  {
158  return !aCondition( aSelection );
159  }

Referenced by operator!().

◆ OnlyType()

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 46 of file selection_conditions.cpp.

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

References onlyTypeFunc().

Referenced by LIB_PIN_TOOL::Init(), SCH_EDIT_TOOL::Init(), EE_INSPECTION_TOOL::Init(), PAD_TOOL::Init(), PCB_EDITOR_CONTROL::Init(), EE_SELECTION_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), EDIT_TOOL::Init(), and ZONE_CONTEXT_MENU::update().

◆ onlyTypeFunc()

bool SELECTION_CONDITIONS::onlyTypeFunc ( const SELECTION aSelection,
KICAD_T  aType 
)
staticprivate

Helper function used by OnlyType()

Definition at line 88 of file selection_conditions.cpp.

89 {
90  if( aSelection.Empty() )
91  return false;
92 
93  KICAD_T types[] = { aType, EOT };
94 
95  for( const auto& item : aSelection )
96  {
97  if( !item->IsType( types ) )
98  return false;
99  }
100 
101  return true;
102 }
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119

References SELECTION::Empty(), and EOT.

Referenced by OnlyType().

◆ 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 52 of file selection_conditions.cpp.

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

References onlyTypesFunc().

Referenced by SCH_EDIT_TOOL::Init(), PCB_EDITOR_CONTROL::Init(), EE_SELECTION_TOOL::Init(), EDIT_TOOL::Init(), EDIT_TOOL::Properties(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), PCB_EDITOR_CONTROL::ViaSizeDec(), and PCB_EDITOR_CONTROL::ViaSizeInc().

◆ onlyTypesFunc()

bool SELECTION_CONDITIONS::onlyTypesFunc ( const SELECTION aSelection,
const KICAD_T  aTypes[] 
)
staticprivate

Helper function used by OnlyTypes()

Definition at line 105 of file selection_conditions.cpp.

106 {
107  if( aSelection.Empty() )
108  return false;
109 
110  for( const auto& item : aSelection )
111  {
112  if( !item->IsType( aTypes ) )
113  return false;
114  }
115 
116  return true;
117 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119

References SELECTION::Empty().

Referenced by OnlyTypes().

◆ orFunc()

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 142 of file selection_conditions.h.

144  {
145  return aConditionA( aSelection ) || aConditionB( aSelection );
146  }

Referenced by operator||().

◆ ShowAlways()

Friends And Related Function Documentation

◆ operator &&

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

Definition at line 145 of file selection_conditions.cpp.

147 {
148  return std::bind( &SELECTION_CONDITIONS::andFunc, aConditionA, aConditionB, _1 );
149 }
static bool andFunc(const SELECTION_CONDITION &aConditionA, const SELECTION_CONDITION &aConditionB, const SELECTION &aSelection)
Helper function used by operator&&

◆ operator!

SELECTION_CONDITION operator! ( const SELECTION_CONDITION aCondition)
friend

Definition at line 152 of file selection_conditions.cpp.

153 {
154  return std::bind( &SELECTION_CONDITIONS::notFunc, aCondition, _1 );
155 }
static bool notFunc(const SELECTION_CONDITION &aCondition, const SELECTION &aSelection)
Helper function used by operator!

◆ operator||

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

Definition at line 138 of file selection_conditions.cpp.

140 {
141  return std::bind( &SELECTION_CONDITIONS::orFunc, aConditionA, aConditionB, _1 );
142 }
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: