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:
EDA_3D_CONDITIONS EDITOR_CONDITIONS EE_CONDITIONS PCB_SELECTION_CONDITIONS PL_CONDITIONS PCB_EDITOR_CONDITIONS

Static Public Member Functions

static bool ShowAlways (const SELECTION &aSelection)
 The default condition function (always returns true). More...
 
static bool ShowNever (const SELECTION &aSelection)
 Always returns false. More...
 
static bool NotEmpty (const SELECTION &aSelection)
 Tests if there are any items selected. More...
 
static bool Empty (const SELECTION &aSelection)
 Tests if there are no items selected. More...
 
static bool Idle (const SELECTION &aSelection)
 Tests if there no items selected or being edited. More...
 
static bool IdleSelection (const SELECTION &aSelection)
 Tests if all selected items are not being edited. More...
 
static SELECTION_CONDITION HasType (KICAD_T aType)
 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)
 Creates a functor that tests if the selected items are only of given type. More...
 
static SELECTION_CONDITION OnlyTypes (const KICAD_T aTypes[])
 Creates a functor that tests if the selected items are only of given types. More...
 
static SELECTION_CONDITION Count (int aNumber)
 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)
 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)
 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...
 
static bool orBoolFunc (const SELECTION_CONDITION &aConditionA, SELECTION_BOOL &aConditionB, const SELECTION &aSelection)
 

Helper function used by operator||

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

Detailed Description

Class that groups generic conditions for selected items.

Definition at line 66 of file selection_conditions.h.

Member Function Documentation

◆ andBoolFunc()

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

Helper function used by operator&&

Definition at line 222 of file selection_conditions.h.

224  {
225  return aConditionA( aSelection ) && aConditionB( aSelection );
226  }

Referenced by operator &&().

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

204  {
205  return aConditionA( aSelection ) && aConditionB( aSelection );
206  }

Referenced by operator &&().

◆ Count()

SELECTION_CONDITION SELECTION_CONDITIONS::Count ( int  aNumber)
static

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

77 {
78  return std::bind( &SELECTION_CONDITIONS::countFunc, _1, aNumber );
79 }
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(), CONVERT_TOOL::Init(), PAD_TOOL::Init(), EE_SELECTION_TOOL::Init(), PCB_INSPECTION_TOOL::Init(), EDIT_TOOL::Init(), and PCB_EDIT_FRAME::setupUIConditions().

◆ countFunc()

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

Helper function used by Count()

Definition at line 138 of file selection_conditions.cpp.

139 {
140  return aSelection.Size() == aNumber;
141 }
int Size() const
Returns the number of selected parts.
Definition: selection.h:126

References SELECTION::Size().

Referenced by Count().

◆ Empty()

bool SELECTION_CONDITIONS::Empty ( const SELECTION aSelection)
static

Tests if there are no items selected.

Parameters
aSelectionis the selection to be tested.
Returns
True if there are no items selected.

Definition at line 40 of file selection_conditions.cpp.

41 {
42  return aSelection.Empty();
43 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120

References SELECTION::Empty().

Referenced by EE_SELECTION_TOOL::Init().

◆ HasType()

SELECTION_CONDITION SELECTION_CONDITIONS::HasType ( KICAD_T  aType)
static

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

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

References hasTypeFunc().

Referenced by BOARD::GroupLegalOps(), and PAD_TOOL::Init().

◆ hasTypeFunc()

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

Helper function used by HasType()

Definition at line 94 of file selection_conditions.cpp.

95 {
96  for( const auto& item : aSelection )
97  {
98  if( item->Type() == aType )
99  return true;
100  }
101 
102  return false;
103 }

Referenced by HasType().

◆ Idle()

bool SELECTION_CONDITIONS::Idle ( const SELECTION aSelection)
static

Tests if there no items selected or being edited.

Parameters
aSelectionis the selection to be tested.
Returns
True if there are no items being edited or no items selected.

Definition at line 46 of file selection_conditions.cpp.

47 {
48  return ( !aSelection.Front() || aSelection.Front()->GetEditFlags() == 0 );
49 }
STATUS_FLAGS GetEditFlags() const
Definition: eda_item.h:225
EDA_ITEM * Front() const
Definition: selection.h:201

References SELECTION::Front(), and EDA_ITEM::GetEditFlags().

Referenced by LIB_EDIT_TOOL::Init(), SCH_EDIT_TOOL::Init(), EE_INSPECTION_TOOL::Init(), EE_SELECTION_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), SYMBOL_EDIT_FRAME::LoadOneSymbol(), PL_EDITOR_FRAME::setupUIConditions(), PCB_EDIT_FRAME::setupUIConditions(), SCH_EDIT_FRAME::setupUIConditions(), SYMBOL_EDIT_FRAME::setupUIConditions(), and FOOTPRINT_EDIT_FRAME::setupUIConditions().

◆ IdleSelection()

bool SELECTION_CONDITIONS::IdleSelection ( const SELECTION aSelection)
static

Tests if all selected items are not being edited.

Parameters
aSelectionis the selection to be tested.
Returns
True if no selected items are being edited.

Definition at line 52 of file selection_conditions.cpp.

53 {
54  return ( aSelection.Front() && aSelection.Front()->GetEditFlags() == 0 );
55 }
STATUS_FLAGS GetEditFlags() const
Definition: eda_item.h:225
EDA_ITEM * Front() const
Definition: selection.h:201

References SELECTION::Front(), and EDA_ITEM::GetEditFlags().

Referenced by LIB_EDIT_TOOL::Init(), LIB_MOVE_TOOL::Init(), and SCH_EDIT_TOOL::Init().

◆ LessThan()

SELECTION_CONDITION SELECTION_CONDITIONS::LessThan ( int  aNumber)
static

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

89 {
90  return std::bind( &SELECTION_CONDITIONS::lessThanFunc, _1, aNumber );
91 }
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 150 of file selection_conditions.cpp.

151 {
152  return aSelection.Size() < aNumber;
153 }
int Size() const
Returns the number of selected parts.
Definition: selection.h:126

References SELECTION::Size().

Referenced by LessThan().

◆ MoreThan()

SELECTION_CONDITION SELECTION_CONDITIONS::MoreThan ( int  aNumber)
static

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

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

References moreThanFunc().

Referenced by SCH_EDIT_TOOL::Init(), CONVERT_TOOL::Init(), ALIGN_DISTRIBUTE_TOOL::Init(), EE_SELECTION_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), and PCB_EDIT_FRAME::setupUIConditions().

◆ moreThanFunc()

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

Helper function used by MoreThan()

Definition at line 144 of file selection_conditions.cpp.

145 {
146  return aSelection.Size() > aNumber;
147 }
int Size() const
Returns the number of selected parts.
Definition: selection.h:126

References SELECTION::Size().

Referenced by MoreThan().

◆ NotEmpty()

bool SELECTION_CONDITIONS::NotEmpty ( const SELECTION aSelection)
static

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:120

References SELECTION::Empty().

Referenced by LIB_EDIT_TOOL::Init(), SCH_EDIT_TOOL::Init(), PL_EDIT_TOOL::Init(), GROUP_TOOL::Init(), SELECTION_TOOL::Init(), EDIT_TOOL::Init(), PL_EDITOR_FRAME::setupUIConditions(), PCB_EDIT_FRAME::setupUIConditions(), SCH_EDIT_FRAME::setupUIConditions(), SYMBOL_EDIT_FRAME::setupUIConditions(), and FOOTPRINT_EDIT_FRAME::setupUIConditions().

◆ notFunc()

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

Helper function used by operator!

Definition at line 209 of file selection_conditions.h.

210  {
211  return !aCondition( aSelection );
212  }

Referenced by operator!().

◆ OnlyType()

SELECTION_CONDITION SELECTION_CONDITIONS::OnlyType ( KICAD_T  aType)
static

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

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

References onlyTypeFunc().

Referenced by BOARD::GroupLegalOps(), LIB_PIN_TOOL::Init(), SCH_EDIT_TOOL::Init(), EE_INSPECTION_TOOL::Init(), CONVERT_TOOL::Init(), PAD_TOOL::Init(), PCB_EDITOR_CONTROL::Init(), EE_SELECTION_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), EDIT_TOOL::Init(), and PCB_EDIT_FRAME::setupUIConditions().

◆ onlyTypeFunc()

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

Helper function used by OnlyType()

Definition at line 106 of file selection_conditions.cpp.

107 {
108  if( aSelection.Empty() )
109  return false;
110 
111  KICAD_T types[] = { aType, EOT };
112 
113  for( const auto& item : aSelection )
114  {
115  if( !item->IsType( types ) )
116  return false;
117  }
118 
119  return true;
120 }
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:120

References SELECTION::Empty(), and EOT.

Referenced by OnlyType().

◆ OnlyTypes()

SELECTION_CONDITION SELECTION_CONDITIONS::OnlyTypes ( const KICAD_T  aTypes[])
static

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

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

References onlyTypesFunc().

Referenced by SCH_EDIT_TOOL::Init(), CONVERT_TOOL::Init(), PCB_EDITOR_CONTROL::Init(), EE_SELECTION_TOOL::Init(), PCB_INSPECTION_TOOL::Init(), EDIT_TOOL::Init(), EDIT_TOOL::Properties(), PCB_EDIT_FRAME::setupUIConditions(), 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 123 of file selection_conditions.cpp.

124 {
125  if( aSelection.Empty() )
126  return false;
127 
128  for( const auto& item : aSelection )
129  {
130  if( !item->IsType( aTypes ) )
131  return false;
132  }
133 
134  return true;
135 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120

References SELECTION::Empty().

Referenced by OnlyTypes().

◆ orBoolFunc()

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

Helper function used by operator||

Definition at line 215 of file selection_conditions.h.

217  {
218  return aConditionA( aSelection ) || aConditionB( aSelection );
219  }

Referenced by operator||().

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

197  {
198  return aConditionA( aSelection ) || aConditionB( aSelection );
199  }

Referenced by operator||().

◆ ShowAlways()

static bool SELECTION_CONDITIONS::ShowAlways ( const SELECTION aSelection)
inlinestatic

◆ ShowNever()

static bool SELECTION_CONDITIONS::ShowNever ( const SELECTION aSelection)
inlinestatic

Always returns false.

Parameters
aSelectionis the selection to be tested.
Returns
Always false.

Definition at line 86 of file selection_conditions.h.

87  {
88  return false;
89  }

Referenced by ACTION_CONDITIONS::ACTION_CONDITIONS(), and PL_EDITOR_FRAME::setupUIConditions().

Friends And Related Function Documentation

◆ operator && [1/2]

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

Definition at line 163 of file selection_conditions.cpp.

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

◆ operator && [2/2]

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

Definition at line 189 of file selection_conditions.cpp.

191 {
192  return std::bind( &SELECTION_CONDITIONS::andBoolFunc, aConditionA, std::ref( aConditionB ), _1 );
193 }
static bool andBoolFunc(const SELECTION_CONDITION &aConditionA, SELECTION_BOOL &aConditionB, const SELECTION &aSelection)
Helper function used by operator&&

◆ operator!

SELECTION_CONDITION operator! ( const SELECTION_CONDITION aCondition)
friend

Definition at line 170 of file selection_conditions.cpp.

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

◆ operator|| [1/2]

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

Definition at line 156 of file selection_conditions.cpp.

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

◆ operator|| [2/2]

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

Definition at line 176 of file selection_conditions.cpp.

178 {
179  return std::bind( &SELECTION_CONDITIONS::orBoolFunc, aConditionA, std::ref( aConditionB ), _1 );
180 }
static bool orBoolFunc(const SELECTION_CONDITION &aConditionA, SELECTION_BOOL &aConditionB, const SELECTION &aSelection)
Helper function used by operator||

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