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 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 sameNetFunc (const SELECTION &aSelection, bool aAllowUnconnected)
 

Helper function used by SameNet()

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

Helper function used by SameLayer()

More...
 

Detailed Description

Definition at line 33 of file pcb_selection_conditions.h.

Member Function Documentation

SELECTION_CONDITION SELECTION_CONDITIONS::Count ( int  aNumber)
staticinherited

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 SELECTION_CONDITIONS::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()
SELECTION_CONDITION SELECTION_CONDITIONS::HasType ( KICAD_T  aType)
staticinherited

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 SELECTION_CONDITIONS::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()
SELECTION_CONDITION SELECTION_CONDITIONS::LessThan ( int  aNumber)
staticinherited

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 SELECTION_CONDITIONS::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()
SELECTION_CONDITION SELECTION_CONDITIONS::MoreThan ( int  aNumber)
staticinherited

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 SELECTION_CONDITIONS::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::NotEmpty ( const SELECTION aSelection)
staticinherited

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
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 33 of file pcb_selection_conditions.cpp.

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

34 {
35  if( aSelection.Empty() )
36  return false;
37 
38  for( const auto &item : aSelection )
39  {
40  auto type = item->Type();
41 
42  if( type != PCB_PAD_T && type != PCB_VIA_T && type != PCB_TRACE_T && type != PCB_ZONE_T )
43  return false;
44  }
45 
46  return true;
47 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:106
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
class SEGZONE, a segment used to fill a zone area (segment on a copper layer)
Definition: typeinfo.h:109
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
SELECTION_CONDITION SELECTION_CONDITIONS::OnlyType ( KICAD_T  aType)
staticinherited

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 SELECTION_CONDITIONS::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()
SELECTION_CONDITION SELECTION_CONDITIONS::OnlyTypes ( const std::vector< KICAD_T > &  aTypes)
staticinherited

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 SELECTION_CONDITIONS::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[])
staticinherited

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

58 {
59  return std::bind( &SELECTION_CONDITIONS::onlyTypesFuncArr, _1, aTypes );
60 }
static bool onlyTypesFuncArr(const SELECTION &aSelection, const KICAD_T aTypes[])
SELECTION_CONDITION 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 56 of file pcb_selection_conditions.cpp.

References sameLayerFunc().

Referenced by ZONE_CONTEXT_MENU::update().

57 {
58  return std::bind( &PCB_SELECTION_CONDITIONS::sameLayerFunc, _1 );
59 }
static bool sameLayerFunc(const SELECTION &aSelection)
Helper function used by SameLayer()
bool PCB_SELECTION_CONDITIONS::sameLayerFunc ( const SELECTION aSelection)
staticprivate

Helper function used by SameLayer()

Definition at line 109 of file pcb_selection_conditions.cpp.

References SELECTION::Empty().

Referenced by SameLayer().

110 {
111  if( aSelection.Empty() )
112  return false;
113 
114  LSET layerSet;
115  layerSet.set();
116 
117  for( const auto& i : aSelection )
118  {
119  auto item = static_cast<BOARD_ITEM*>( i );
120  layerSet &= item->GetLayerSet();
121 
122  if( !layerSet.any() ) // there are no common layers left
123  return false;
124  }
125 
126  return true;
127 }
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:106
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
Class LSET is a set of PCB_LAYER_IDs.
SELECTION_CONDITION 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 50 of file pcb_selection_conditions.cpp.

References sameNetFunc().

Referenced by ZONE_CONTEXT_MENU::update().

51 {
52  return std::bind( &PCB_SELECTION_CONDITIONS::sameNetFunc, _1, aAllowUnconnected );
53 }
static bool sameNetFunc(const SELECTION &aSelection, bool aAllowUnconnected)
Helper function used by SameNet()
bool PCB_SELECTION_CONDITIONS::sameNetFunc ( const SELECTION aSelection,
bool  aAllowUnconnected 
)
staticprivate

Helper function used by SameNet()

Definition at line 63 of file pcb_selection_conditions.cpp.

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

Referenced by SameNet().

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

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  }

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