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 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)
 Test if there are any items selected. More...
 
static bool Empty (const SELECTION &aSelection)
 Test if there are no items selected. More...
 
static bool Idle (const SELECTION &aSelection)
 Test if there no items selected or being edited. More...
 
static bool IdleSelection (const SELECTION &aSelection)
 Test if all selected items are not being edited. More...
 
static SELECTION_CONDITION HasType (KICAD_T aType)
 Create 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)
 Create a functor that tests if the selected items are only of given type. More...
 
static SELECTION_CONDITION OnlyTypes (const KICAD_T aTypes[])
 Create a functor that tests if the selected items are only of given types. More...
 
static SELECTION_CONDITION Count (int aNumber)
 Create 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)
 Create 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)
 Create 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 OnlyTypes() More...
 
static bool onlyTypesFunc (const SELECTION &aSelection, const KICAD_T aTypes[])
 Helper function used by Count() More...
 
static bool countFunc (const SELECTION &aSelection, int aNumber)
 Helper function used by MoreThan() More...
 
static bool moreThanFunc (const SELECTION &aSelection, int aNumber)
 Helper function used by LessThan() More...
 
static bool lessThanFunc (const SELECTION &aSelection, int aNumber)
 Helper function used by operator||. 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)
 

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 68 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

Definition at line 225 of file selection_conditions.h.

227  {
228  return aConditionA( aSelection ) && aConditionB( aSelection );
229  }

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

Referenced by operator &&().

◆ Count()

SELECTION_CONDITION SELECTION_CONDITIONS::Count ( int  aNumber)
static

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

78 {
79  return std::bind( &SELECTION_CONDITIONS::countFunc, _1, aNumber );
80 }
static bool countFunc(const SELECTION &aSelection, int aNumber)
Helper function used by MoreThan()

References countFunc().

Referenced by SYMBOL_EDITOR_EDIT_TOOL::Init(), SYMBOL_EDITOR_PIN_TOOL::Init(), SCH_EDIT_TOOL::Init(), EE_INSPECTION_TOOL::Init(), PAD_TOOL::Init(), CONVERT_TOOL::Init(), EE_SELECTION_TOOL::Init(), BOARD_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 MoreThan()

Definition at line 139 of file selection_conditions.cpp.

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

References SELECTION::Size().

Referenced by Count().

◆ Empty()

bool SELECTION_CONDITIONS::Empty ( const SELECTION aSelection)
static

Test if there are no items selected.

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

Definition at line 41 of file selection_conditions.cpp.

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

References SELECTION::Empty().

Referenced by PL_SELECTION_TOOL::Init(), and EE_SELECTION_TOOL::Init().

◆ HasType()

SELECTION_CONDITION SELECTION_CONDITIONS::HasType ( KICAD_T  aType)
static

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

60 {
61  return std::bind( &SELECTION_CONDITIONS::hasTypeFunc, _1, aType );
62 }
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()

Helper function used by OnlyType()

Definition at line 95 of file selection_conditions.cpp.

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

Referenced by HasType().

◆ Idle()

bool SELECTION_CONDITIONS::Idle ( const SELECTION aSelection)
static

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

48 {
49  return ( !aSelection.Front() || aSelection.Front()->GetEditFlags() == 0 );
50 }
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:158
EDA_ITEM * Front() const
Definition: selection.h:144

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

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

◆ IdleSelection()

bool SELECTION_CONDITIONS::IdleSelection ( const SELECTION aSelection)
static

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

54 {
55  return ( aSelection.Front() && aSelection.Front()->GetEditFlags() == 0 );
56 }
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:158
EDA_ITEM * Front() const
Definition: selection.h:144

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

Referenced by SYMBOL_EDITOR_EDIT_TOOL::Init(), SYMBOL_EDITOR_MOVE_TOOL::Init(), and SCH_EDIT_TOOL::Init().

◆ LessThan()

SELECTION_CONDITION SELECTION_CONDITIONS::LessThan ( int  aNumber)
static

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

90 {
91  return std::bind( &SELECTION_CONDITIONS::lessThanFunc, _1, aNumber );
92 }
static bool lessThanFunc(const SELECTION &aSelection, int aNumber)
Helper function used by operator||.

References lessThanFunc().

Referenced by EE_SELECTION_TOOL::Init().

◆ lessThanFunc()

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

Helper function used by operator||.

Definition at line 151 of file selection_conditions.cpp.

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

References SELECTION::Size().

Referenced by LessThan().

◆ MoreThan()

SELECTION_CONDITION SELECTION_CONDITIONS::MoreThan ( int  aNumber)
static

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

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

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(), FOOTPRINT_EDIT_FRAME::setupUIConditions(), and PCB_EDIT_FRAME::setupUIConditions().

◆ moreThanFunc()

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

Helper function used by LessThan()

Definition at line 145 of file selection_conditions.cpp.

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

References SELECTION::Size().

Referenced by MoreThan().

◆ NotEmpty()

bool SELECTION_CONDITIONS::NotEmpty ( const SELECTION aSelection)
static

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

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

References SELECTION::Empty().

Referenced by SYMBOL_EDITOR_EDIT_TOOL::Init(), PL_EDIT_TOOL::Init(), SCH_EDIT_TOOL::Init(), GROUP_TOOL::Init(), BOARD_EDITOR_CONTROL::Init(), PCB_SELECTION_TOOL::Init(), EDIT_TOOL::Init(), and PL_EDITOR_FRAME::setupUIConditions().

◆ notFunc()

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

Helper function used by operator||.

Definition at line 212 of file selection_conditions.h.

Referenced by operator!().

◆ OnlyType()

SELECTION_CONDITION SELECTION_CONDITIONS::OnlyType ( KICAD_T  aType)
static

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

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

References onlyTypeFunc().

Referenced by SYMBOL_EDITOR_PIN_TOOL::Init(), SCH_EDIT_TOOL::Init(), EE_INSPECTION_TOOL::Init(), PAD_TOOL::Init(), CONVERT_TOOL::Init(), SCH_MOVE_TOOL::Init(), BOARD_EDITOR_CONTROL::Init(), EE_SELECTION_TOOL::Init(), EDIT_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), and PCB_EDIT_FRAME::setupUIConditions().

◆ onlyTypeFunc()

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

Helper function used by OnlyTypes()

Definition at line 107 of file selection_conditions.cpp.

108 {
109  if( aSelection.Empty() )
110  return false;
111 
112  KICAD_T types[] = { aType, EOT };
113 
114  for( const auto& item : aSelection )
115  {
116  if( !item->IsType( types ) )
117  return false;
118  }
119 
120  return true;
121 }
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:97

References SELECTION::Empty(), and EOT.

Referenced by OnlyType().

◆ OnlyTypes()

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

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

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

References onlyTypesFunc().

Referenced by SCH_EDIT_TOOL::Init(), CONVERT_TOOL::Init(), EE_SELECTION_TOOL::Init(), BOARD_INSPECTION_TOOL::Init(), EDIT_TOOL::Init(), EDIT_TOOL::Properties(), PCB_EDIT_FRAME::setupUIConditions(), BOARD_EDITOR_CONTROL::TrackWidthDec(), BOARD_EDITOR_CONTROL::TrackWidthInc(), BOARD_EDITOR_CONTROL::ViaSizeDec(), and BOARD_EDITOR_CONTROL::ViaSizeInc().

◆ onlyTypesFunc()

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

Helper function used by Count()

Definition at line 124 of file selection_conditions.cpp.

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

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

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

Referenced by operator||().

◆ ShowAlways()

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

89  {
90  return false;
91  }

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

166 {
167  return std::bind( &SELECTION_CONDITIONS::andFunc, aConditionA, aConditionB, _1 );
168 }
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 190 of file selection_conditions.cpp.

192 {
193  return std::bind( &SELECTION_CONDITIONS::andBoolFunc, aConditionA, std::ref( aConditionB ), _1 );
194 }
static bool andBoolFunc(const SELECTION_CONDITION &aConditionA, SELECTION_BOOL &aConditionB, const SELECTION &aSelection)

◆ operator!

SELECTION_CONDITION operator! ( const SELECTION_CONDITION aCondition)
friend

Definition at line 171 of file selection_conditions.cpp.

172 {
173  return std::bind( &SELECTION_CONDITIONS::notFunc, aCondition, _1 );
174 }
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 157 of file selection_conditions.cpp.

159 {
160  return std::bind( &SELECTION_CONDITIONS::orFunc, aConditionA, aConditionB, _1 );
161 }
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 177 of file selection_conditions.cpp.

179 {
180  return std::bind( &SELECTION_CONDITIONS::orBoolFunc, aConditionA, std::ref( aConditionB ), _1 );
181 }
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: