KiCad PCB EDA Suite
PCB_SELECTION_CONDITIONS Class Reference

#include <pcb_selection_conditions.h>

Inheritance diagram for PCB_SELECTION_CONDITIONS:
SELECTION_CONDITIONS

Static Public Member Functions

static bool OnlyConnectedItems (const SELECTION &aSelection)
 Function OnlyConnectedItems Tests if selection contains exclusively connected items (pads, tracks, vias, zones). More...
 
static SELECTION_CONDITION SameNet (bool aAllowUnconnected=false)
 Function SameNet Creates a functor that tests if selection contains items belonging to the same net or are unconnected if aAllowUnconnected == true. More...
 
static SELECTION_CONDITION SameLayer ()
 Function SameLayer Creates a functor that tests if selection contains items that belong exclusively to the same layer. More...
 
static SELECTION_CONDITION OnlyGraphicShapeTypes (const std::set< STROKE_T > aTypes)
 Creates a functor that tests if the selection contains DRAWSEGMENT* items of certain shapes This implicitly includes an OnlyType( PCB_LINE_T ) as part of the test. More...
 
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 sameNetFunc (const SELECTION &aSelection, bool aAllowUnconnected)
 

Helper function used by SameNet()

More...
 
static bool sameLayerFunc (const SELECTION &aSelection)
 

Helper function used by SameLayer()

More...
 
static bool onlyGraphicShapeTypesFunc (const SELECTION &aSelection, const std::set< STROKE_T > aTypes)
 

Helper function used by OnlyGraphicShapeTypes()

More...
 

Detailed Description

Definition at line 33 of file pcb_selection_conditions.h.

Member Function Documentation

◆ Count()

SELECTION_CONDITION SELECTION_CONDITIONS::Count ( int  aNumber)
staticinherited

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 SELECTION_CONDITIONS::countFunc().

Referenced by LIB_EDIT_TOOL::Init(), LIB_PIN_TOOL::Init(), SCH_EDIT_TOOL::Init(), EE_INSPECTION_TOOL::Init(), PCB_INSPECTION_TOOL::Init(), PAD_TOOL::Init(), EE_SELECTION_TOOL::Init(), EDIT_TOOL::Init(), and PCB_EDIT_FRAME::setupUIConditions().

◆ Empty()

bool SELECTION_CONDITIONS::Empty ( const SELECTION aSelection)
staticinherited

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

References SELECTION::Empty().

Referenced by EE_SELECTION_TOOL::Init().

◆ HasType()

SELECTION_CONDITION SELECTION_CONDITIONS::HasType ( KICAD_T  aType)
staticinherited

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 SELECTION_CONDITIONS::hasTypeFunc().

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

◆ Idle()

bool SELECTION_CONDITIONS::Idle ( const SELECTION aSelection)
staticinherited

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: base_struct.h:237
EDA_ITEM * Front() const
Definition: selection.h:184

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

◆ IdleSelection()

bool SELECTION_CONDITIONS::IdleSelection ( const SELECTION aSelection)
staticinherited

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: base_struct.h:237
EDA_ITEM * Front() const
Definition: selection.h:184

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)
staticinherited

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 SELECTION_CONDITIONS::lessThanFunc().

◆ MoreThan()

SELECTION_CONDITION SELECTION_CONDITIONS::MoreThan ( int  aNumber)
staticinherited

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 SELECTION_CONDITIONS::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().

◆ NotEmpty()

bool SELECTION_CONDITIONS::NotEmpty ( const SELECTION aSelection)
staticinherited

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

References SELECTION::Empty().

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

◆ OnlyConnectedItems()

bool PCB_SELECTION_CONDITIONS::OnlyConnectedItems ( const SELECTION aSelection)
static

Function OnlyConnectedItems Tests if selection contains exclusively connected items (pads, tracks, vias, zones).

Parameters
aSelectionis the selection to be tested.
Returns
True if there are only connected items connected.

Definition at line 36 of file pcb_selection_conditions.cpp.

37 {
38  if( aSelection.Empty() )
39  return false;
40 
41  for( const auto &item : aSelection )
42  {
43  auto type = item->Type();
44 
45  if( type != PCB_PAD_T && type != PCB_VIA_T && type != PCB_TRACE_T && type != PCB_ZONE_AREA_T )
46  return false;
47  }
48 
49  return true;
50 }
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:106
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:121
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97

References SELECTION::Empty(), PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, and PCB_ZONE_AREA_T.

◆ OnlyGraphicShapeTypes()

S_C PCB_SELECTION_CONDITIONS::OnlyGraphicShapeTypes ( const std::set< STROKE_T aTypes)
static

Creates a functor that tests if the selection contains DRAWSEGMENT* items of certain shapes This implicitly includes an OnlyType( PCB_LINE_T ) as part of the test.

Parameters
aTypesis a list of allowed DRAWSEGMENT shapes (
See also
STROKE_T)
Returns
functor testing if selected items match the given list of allowed shapes

Definition at line 65 of file pcb_selection_conditions.cpp.

66 {
67  return std::bind( &PCB_SELECTION_CONDITIONS::onlyGraphicShapeTypesFunc, _1, aTypes );
68 }
static bool onlyGraphicShapeTypesFunc(const SELECTION &aSelection, const std::set< STROKE_T > aTypes)
Helper function used by OnlyGraphicShapeTypes()

References onlyGraphicShapeTypesFunc().

Referenced by CONVERT_TOOL::Init().

◆ onlyGraphicShapeTypesFunc()

bool PCB_SELECTION_CONDITIONS::onlyGraphicShapeTypesFunc ( const SELECTION aSelection,
const std::set< STROKE_T aTypes 
)
staticprivate

Helper function used by OnlyGraphicShapeTypes()

Definition at line 139 of file pcb_selection_conditions.cpp.

141 {
142  if( aSelection.Empty() )
143  return false;
144 
145  for( const EDA_ITEM* item : aSelection )
146  {
147  if( item->Type() != PCB_LINE_T )
148  return false;
149 
150  STROKE_T shape = static_cast<const DRAWSEGMENT*>( item )->GetShape();
151 
152  if( !aTypes.count( shape ) )
153  return false;
154  }
155 
156  return true;
157 }
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:121
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91

References SELECTION::Empty(), and PCB_LINE_T.

Referenced by OnlyGraphicShapeTypes().

◆ OnlyType()

SELECTION_CONDITION SELECTION_CONDITIONS::OnlyType ( KICAD_T  aType)
staticinherited

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 SELECTION_CONDITIONS::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().

◆ OnlyTypes()

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

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 SELECTION_CONDITIONS::onlyTypesFunc().

Referenced by SCH_EDIT_TOOL::Init(), CONVERT_TOOL::Init(), PCB_INSPECTION_TOOL::Init(), PCB_EDITOR_CONTROL::Init(), EE_SELECTION_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().

◆ SameLayer()

S_C PCB_SELECTION_CONDITIONS::SameLayer ( )
static

Function SameLayer Creates a functor that tests if selection contains items that belong exclusively to the same layer.

In case of items belonging to multiple layers, it is enough to have a single common layer with other items.

Returns
Functor testing if selected items share at least one common layer.

Definition at line 59 of file pcb_selection_conditions.cpp.

60 {
61  return std::bind( &PCB_SELECTION_CONDITIONS::sameLayerFunc, _1 );
62 }
static bool sameLayerFunc(const SELECTION &aSelection)
Helper function used by SameLayer()

References sameLayerFunc().

Referenced by CONVERT_TOOL::Init(), and PCB_EDIT_FRAME::setupUIConditions().

◆ sameLayerFunc()

bool PCB_SELECTION_CONDITIONS::sameLayerFunc ( const SELECTION aSelection)
staticprivate

Helper function used by SameLayer()

Definition at line 118 of file pcb_selection_conditions.cpp.

119 {
120  if( aSelection.Empty() )
121  return false;
122 
123  LSET layerSet;
124  layerSet.set();
125 
126  for( const auto& i : aSelection )
127  {
128  auto item = static_cast<BOARD_ITEM*>( i );
129  layerSet &= item->GetLayerSet();
130 
131  if( !layerSet.any() ) // there are no common layers left
132  return false;
133  }
134 
135  return true;
136 }
LSET is a set of PCB_LAYER_IDs.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:121

References SELECTION::Empty().

Referenced by SameLayer().

◆ SameNet()

S_C PCB_SELECTION_CONDITIONS::SameNet ( bool  aAllowUnconnected = false)
static

Function SameNet Creates a functor that tests if selection contains items belonging to the same net or are unconnected if aAllowUnconnected == true.

Parameters
aAllowUnconnecteddetermines if unconnected items (with no net code assigned) should be treated as connected to the same net.
Returns
Functor testing if selected items are belonging to the same net.

Definition at line 53 of file pcb_selection_conditions.cpp.

54 {
55  return std::bind( &PCB_SELECTION_CONDITIONS::sameNetFunc, _1, aAllowUnconnected );
56 }
static bool sameNetFunc(const SELECTION &aSelection, bool aAllowUnconnected)
Helper function used by SameNet()

References sameNetFunc().

Referenced by PCB_EDIT_FRAME::setupUIConditions().

◆ sameNetFunc()

bool PCB_SELECTION_CONDITIONS::sameNetFunc ( const SELECTION aSelection,
bool  aAllowUnconnected 
)
staticprivate

Helper function used by SameNet()

Definition at line 72 of file pcb_selection_conditions.cpp.

73 {
74  if( aSelection.Empty() )
75  return false;
76 
77  int netcode = -1; // -1 stands for 'net code is not yet determined'
78 
79  for( const auto& aitem : aSelection )
80  {
81  int current_netcode = -1;
82 
83  const BOARD_CONNECTED_ITEM* item =
84  dynamic_cast<const BOARD_CONNECTED_ITEM*>( aitem );
85 
86  if( item )
87  {
88  current_netcode = item->GetNetCode();
89  }
90  else
91  {
92  if( !aAllowUnconnected )
93  return false;
94  else
95  // if it is not a BOARD_CONNECTED_ITEM, treat it as if there was no net assigned
96  current_netcode = 0;
97  }
98 
99  assert( current_netcode >= 0 );
100 
101  if( netcode < 0 )
102  {
103  netcode = current_netcode;
104 
105  if( netcode == NETINFO_LIST::UNCONNECTED && !aAllowUnconnected )
106  return false;
107  }
108  else if( netcode != current_netcode )
109  {
110  return false;
111  }
112  }
113 
114  return true;
115 }
int GetNetCode() const
Function GetNetCode.
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:121
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:478

References SELECTION::Empty(), BOARD_CONNECTED_ITEM::GetNetCode(), and NETINFO_LIST::UNCONNECTED.

Referenced by SameNet().

◆ ShowAlways()

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

◆ ShowNever()

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

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().


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