KiCad PCB EDA Suite
LIB_COLLECTOR Class Reference

Class LIB_COLLECTOR. More...

#include <lib_collectors.h>

Inheritance diagram for LIB_COLLECTOR:
COLLECTOR

Public Member Functions

 LIB_COLLECTOR (const KICAD_T *aScanTypes=LIB_COLLECTOR::AllItems)
 Constructor LIB_COLLECTOR. More...
 
LIB_ITEMoperator[] (int aIndex) const
 Operator [] overloads COLLECTOR::operator[](int) to return a LIB_ITEM* instead of an EDA_ITEM* type. More...
 
SEARCH_RESULT Inspect (EDA_ITEM *aItem, void *aTestData) override
 Function Inspect is the examining function within the INSPECTOR which is passed to the Iterate function. More...
 
void Collect (LIB_ITEMS_CONTAINER &aItem, const KICAD_T aFilterList[], const wxPoint &aPosition, int aUnit=0, int aConvert=0)
 Function Collect scans a SCH_ITEM using this class's Inspector method, which does the collection. More...
 
bool IsValidIndex (int aIndex)
 Function IsValidIndex tests if aIndex is with the limits of the list of collected items. More...
 
int GetCount () const
 Function GetCount returns the number of objects in the list. More...
 
void Empty ()
 Function Empty sets the list to empty. More...
 
void Append (EDA_ITEM *item)
 Function Append adds an item to the end of the list. More...
 
void Remove (int aIndex)
 Function Remove removes the item at aIndex (first position is 0);. More...
 
void Remove (const EDA_ITEM *aItem)
 Function Remove removes the item aItem (if exists in the collector). More...
 
EDA_ITEM *const * BasePtr () const
 Function BasePtr returns the address of the first element in the array. More...
 
bool HasItem (const EDA_ITEM *aItem) const
 Function HasItem tests if aItem has already been collected. More...
 
void SetScanTypes (const KICAD_T *scanTypes)
 Function SetScanTypes records the list of KICAD_T types to consider for collection by the Inspect() function. More...
 
void SetTimeNow ()
 
time_t GetTime ()
 
void SetRefPos (const wxPoint &aRefPos)
 
const wxPointGetRefPos () const
 
void SetBoundingBox (const EDA_RECT &aRefBox)
 
const EDA_RECTGetBoundingBox () const
 
bool IsSimilarPointAndTime (const wxPoint &aRefPos)
 Function IsSimilarPointAndTime returns true if the given reference point is "similar" (defined here) to the internal reference point and the current time is within a few seconds of the internal m_TimeAtCollection. More...
 
int CountType (KICAD_T aType)
 Function CountType counts the number of items matching aType. More...
 

Static Public Attributes

static const KICAD_T AllItems []
 A scan list for all schematic items. More...
 
static const KICAD_T EditableItems []
 A scan list for all editable schematic items. More...
 
static const KICAD_T MovableItems []
 A scan list for all movable schematic items. More...
 
static const KICAD_T RotatableItems []
 A scan list for all rotatable schematic items. More...
 
static const KICAD_T AllItemsButPins []
 A scan list for all schematic items except pins. More...
 

Protected Attributes

INSPECTOR_FUNC m_inspector
 a class common bridge into the polymorphic Inspect() More...
 
const KICAD_Tm_ScanTypes
 Which object types to scan. More...
 
std::vector< EDA_ITEM * > m_List
 A place to hold collected objects without taking ownership of their memory. More...
 
wxPoint m_RefPos
 A point to test against, and that was used to make the collection. More...
 
EDA_RECT m_RefBox
 A bounding box to test against, and that was used to make the collection. More...
 
time_t m_TimeAtCollection
 The time at which the collection was made. More...
 

Private Attributes

LIB_COLLECTOR_DATA m_data
 

Detailed Description

Class LIB_COLLECTOR.

Definition at line 51 of file lib_collectors.h.

Constructor & Destructor Documentation

LIB_COLLECTOR::LIB_COLLECTOR ( const KICAD_T aScanTypes = LIB_COLLECTOR::AllItems)
inline

Constructor LIB_COLLECTOR.

Definition at line 85 of file lib_collectors.h.

References COLLECTOR::SetScanTypes().

86  {
87  SetScanTypes( aScanTypes );
88  }
void SetScanTypes(const KICAD_T *scanTypes)
Function SetScanTypes records the list of KICAD_T types to consider for collection by the Inspect() f...

Member Function Documentation

void COLLECTOR::Append ( EDA_ITEM item)
inlineinherited

Function Append adds an item to the end of the list.

Parameters
itemAn EDA_ITEM* to add.

Definition at line 126 of file class_collector.h.

Referenced by GENERAL_COLLECTOR::Collect(), SELECTION_TOOL::guessSelectionCandidates(), Inspect(), GERBER_COLLECTOR::Inspect(), SCH_COLLECTOR::Inspect(), GENERAL_COLLECTOR::Inspect(), SCH_FIND_COLLECTOR::Inspect(), SCH_TYPE_COLLECTOR::Inspect(), PCB_TYPE_COLLECTOR::Inspect(), and PCB_LAYER_COLLECTOR::Inspect().

127  {
128  m_List.push_back( item );
129  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
EDA_ITEM* const* COLLECTOR::BasePtr ( ) const
inlineinherited

Function BasePtr returns the address of the first element in the array.

Only call this if there is at least one element in the vector m_List, otherwise a C++ exception should get thrown.

Definition at line 178 of file class_collector.h.

179  {
180  return &m_List[0];
181  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
void LIB_COLLECTOR::Collect ( LIB_ITEMS_CONTAINER aItem,
const KICAD_T  aFilterList[],
const wxPoint aPosition,
int  aUnit = 0,
int  aConvert = 0 
)

Function Collect scans a SCH_ITEM using this class's Inspector method, which does the collection.

Parameters
aItemA SCH_ITEM to scan.
aFilterListA list of KICAD_T types with a terminating EOT, that determines what is to be collected and the priority order of the resulting collection.
aPositionA wxPoint to use in hit-testing.
aUnitThe unit of the items to collect or zero if all units.
aConvertThe convert of the items to collect or zero if all conversions.

Definition at line 113 of file lib_collectors.cpp.

References COLLECTOR::Empty(), LIB_COLLECTOR_DATA::m_convert, m_data, COLLECTOR::m_inspector, COLLECTOR::m_ScanTypes, LIB_COLLECTOR_DATA::m_unit, SEARCH_QUIT, COLLECTOR::SetRefPos(), and COLLECTOR::SetScanTypes().

Referenced by LIB_EDIT_FRAME::locateItem().

115 {
116  Empty(); // empty the collection just in case
117 
118  SetScanTypes( aFilterList );
119 
120  // remember where the snapshot was taken from and pass refPos to the Inspect() function.
121  SetRefPos( aPosition );
122 
123  m_data.m_unit = aUnit;
124  m_data.m_convert = aConvert;
125 
126  for( LIB_ITEM& item : aItems )
127  {
128  if( SEARCH_QUIT == item.Visit( m_inspector, NULL, m_ScanTypes ) )
129  break;
130  }
131 }
void Empty()
Function Empty sets the list to empty.
void SetScanTypes(const KICAD_T *scanTypes)
Function SetScanTypes records the list of KICAD_T types to consider for collection by the Inspect() f...
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
INSPECTOR_FUNC m_inspector
a class common bridge into the polymorphic Inspect()
void SetRefPos(const wxPoint &aRefPos)
LIB_COLLECTOR_DATA m_data
const KICAD_T * m_ScanTypes
Which object types to scan.
int COLLECTOR::CountType ( KICAD_T  aType)
inlineinherited

Function CountType counts the number of items matching aType.

Parameters
aTypetype we are interested in
Returns
number of occurences

Definition at line 258 of file class_collector.h.

Referenced by SELECTION_TOOL::guessSelectionCandidates().

259  {
260  int cnt = 0;
261  for( size_t i = 0; i < m_List.size(); i++ )
262  {
263  if( m_List[i]->Type() == aType )
264  cnt++;
265  }
266  return cnt;
267  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
void COLLECTOR::Empty ( )
inlineinherited

Function Empty sets the list to empty.

Definition at line 116 of file class_collector.h.

Referenced by Collect(), GERBER_COLLECTOR::Collect(), SCH_COLLECTOR::Collect(), GENERAL_COLLECTOR::Collect(), SCH_TYPE_COLLECTOR::Collect(), PCB_TYPE_COLLECTOR::Collect(), PCB_LAYER_COLLECTOR::Collect(), SCH_FIND_COLLECTOR::Empty(), MODULE_EDITOR_TOOLS::EnumeratePads(), and SELECTION_TOOL::guessSelectionCandidates().

117  {
118  m_List.clear();
119  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
const EDA_RECT& COLLECTOR::GetBoundingBox ( ) const
inlineinherited

Definition at line 227 of file class_collector.h.

References COLLECTOR::m_RefBox.

227 { return m_RefBox; }
EDA_RECT m_RefBox
A bounding box to test against, and that was used to make the collection.
const wxPoint& COLLECTOR::GetRefPos ( ) const
inlineinherited

Definition at line 224 of file class_collector.h.

References COLLECTOR::m_RefPos.

Referenced by PCB_EDIT_FRAME::OnRightClick().

224 { return m_RefPos; }
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
time_t COLLECTOR::GetTime ( )
inlineinherited

Definition at line 218 of file class_collector.h.

References COLLECTOR::m_TimeAtCollection.

219  {
220  return m_TimeAtCollection;
221  }
time_t m_TimeAtCollection
The time at which the collection was made.
bool COLLECTOR::HasItem ( const EDA_ITEM aItem) const
inlineinherited

Function HasItem tests if aItem has already been collected.

Parameters
aItemThe EDA_ITEM* to be tested.
Returns
True if aItem is already collected.

Definition at line 190 of file class_collector.h.

191  {
192  for( size_t i = 0; i < m_List.size(); i++ )
193  {
194  if( m_List[i] == aItem )
195  return true;
196  }
197 
198  return false;
199  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
SEARCH_RESULT LIB_COLLECTOR::Inspect ( EDA_ITEM aItem,
void *  aTestData 
)
overridevirtual

Function Inspect is the examining function within the INSPECTOR which is passed to the Iterate function.

Parameters
aItemAn EDA_ITEM to examine.
aTestDatais not used in this class.
Returns
SEARCH_RESULT SEARCH_QUIT if the iterator is to stop the scan, else SEARCH_CONTINUE;

Implements COLLECTOR.

Definition at line 95 of file lib_collectors.cpp.

References COLLECTOR::Append(), DefaultTransform, LIB_ITEM::GetConvert(), LIB_ITEM::GetUnit(), LIB_ITEM::HitTest(), LIB_COLLECTOR_DATA::m_convert, m_data, COLLECTOR::m_RefPos, LIB_COLLECTOR_DATA::m_unit, and SEARCH_CONTINUE.

96 {
97  LIB_ITEM* item = (LIB_ITEM*) aItem;
98 
99 // wxLogDebug( wxT( "Inspecting item %s, unit %d, convert %d" ),
100 // GetChars( item->GetSelectMenuText() ), item->GetUnit(), item->GetConvert() );
101 
102  if( ( m_data.m_unit && item->GetUnit() && ( m_data.m_unit != item->GetUnit() ) )
103  || ( m_data.m_convert && item->GetConvert() && ( m_data.m_convert != item->GetConvert() ) )
104  || !item->HitTest( m_RefPos, -1, DefaultTransform ) )
105  return SEARCH_CONTINUE;
106 
107  Append( aItem );
108 
109  return SEARCH_CONTINUE;
110 }
int GetUnit() const
virtual bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
LIB_COLLECTOR_DATA m_data
TRANSFORM DefaultTransform
Definition: eeschema.cpp:58
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
int GetConvert() const
bool COLLECTOR::IsSimilarPointAndTime ( const wxPoint aRefPos)
inlineinherited

Function IsSimilarPointAndTime returns true if the given reference point is "similar" (defined here) to the internal reference point and the current time is within a few seconds of the internal m_TimeAtCollection.

Parameters
aRefPosA wxPoint to compare to.
Returns
bool - true if the point and time are similar, else false.

Definition at line 238 of file class_collector.h.

References abs, GetNewTimeStamp(), wxPoint::x, and wxPoint::y.

239  {
240  const int distMax = 2; // adjust these here
241  const time_t timeMax = 3; // seconds
242 
243  int dx = abs( aRefPos.x - m_RefPos.x );
244  int dy = abs( aRefPos.y - m_RefPos.y );
245 
246  if( dx <= distMax && dy <= distMax &&
247  (int)GetNewTimeStamp() - m_TimeAtCollection <= timeMax )
248  return true;
249  else
250  return false;
251  }
#define abs(a)
Definition: auxiliary.h:84
timestamp_t GetNewTimeStamp()
Definition: common.cpp:166
time_t m_TimeAtCollection
The time at which the collection was made.
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
bool COLLECTOR::IsValidIndex ( int  aIndex)
inlineinherited

Function IsValidIndex tests if aIndex is with the limits of the list of collected items.

Parameters
aIndexThe index to test.
Returns
True if aIndex is with the limits of the list of collected items, otherwise false.

Definition at line 98 of file class_collector.h.

Referenced by SCH_FIND_COLLECTOR::GetText(), and SCH_FIND_COLLECTOR::ReplaceItem().

99  {
100  return ( (unsigned) aIndex < m_List.size() );
101  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
LIB_ITEM* LIB_COLLECTOR::operator[] ( int  aIndex) const
inline

Operator [] overloads COLLECTOR::operator[](int) to return a LIB_ITEM* instead of an EDA_ITEM* type.

Parameters
aIndexThe index into the list.
Returns
LIB_ITEM* at aIndex or NULL.

Definition at line 97 of file lib_collectors.h.

References COLLECTOR::GetCount(), and COLLECTOR::m_List.

98  {
99  if( (unsigned)aIndex < (unsigned)GetCount() )
100  return (LIB_ITEM*) m_List[ aIndex ];
101 
102  return NULL;
103  }
int GetCount() const
Function GetCount returns the number of objects in the list.
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
void COLLECTOR::Remove ( int  aIndex)
inlineinherited

Function Remove removes the item at aIndex (first position is 0);.

Parameters
aIndexThe index into the list.

Definition at line 136 of file class_collector.h.

Referenced by SELECTION_TOOL::guessSelectionCandidates(), PCB_BASE_FRAME::PcbGeneralLocateAndDisplay(), GERBVIEW_SELECTION_TOOL::selectPoint(), and SELECTION_TOOL::selectPoint().

137  {
138  m_List.erase( m_List.begin() + aIndex );
139  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
void COLLECTOR::Remove ( const EDA_ITEM aItem)
inlineinherited

Function Remove removes the item aItem (if exists in the collector).

Parameters
aItemthe item to be removed.

Definition at line 146 of file class_collector.h.

147  {
148  for( size_t i = 0; i < m_List.size(); i++ )
149  {
150  if( m_List[i] == aItem )
151  {
152  m_List.erase( m_List.begin() + i);
153  return;
154  }
155  }
156  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
void COLLECTOR::SetBoundingBox ( const EDA_RECT aRefBox)
inlineinherited

Definition at line 226 of file class_collector.h.

226 { m_RefBox = aRefBox; }
EDA_RECT m_RefBox
A bounding box to test against, and that was used to make the collection.
void COLLECTOR::SetRefPos ( const wxPoint aRefPos)
inlineinherited

Definition at line 223 of file class_collector.h.

Referenced by Collect(), GERBER_COLLECTOR::Collect(), SCH_COLLECTOR::Collect(), and GENERAL_COLLECTOR::Collect().

223 { m_RefPos = aRefPos; }
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
void COLLECTOR::SetScanTypes ( const KICAD_T scanTypes)
inlineinherited

Function SetScanTypes records the list of KICAD_T types to consider for collection by the Inspect() function.

Parameters
scanTypesAn array of KICAD_T, terminated by EOT. No copy is is made of this array (so cannot come from caller's stack).

Definition at line 208 of file class_collector.h.

Referenced by Collect(), GERBER_COLLECTOR::Collect(), SCH_COLLECTOR::Collect(), GENERAL_COLLECTOR::Collect(), SCH_TYPE_COLLECTOR::Collect(), GENERAL_COLLECTOR::GENERAL_COLLECTOR(), GERBER_COLLECTOR::GERBER_COLLECTOR(), LIB_COLLECTOR(), SCH_COLLECTOR::SCH_COLLECTOR(), and SCH_FIND_COLLECTOR::SCH_FIND_COLLECTOR().

209  {
210  m_ScanTypes = scanTypes;
211  }
const KICAD_T * m_ScanTypes
Which object types to scan.
void COLLECTOR::SetTimeNow ( )
inlineinherited

Definition at line 213 of file class_collector.h.

References GetNewTimeStamp().

Referenced by GERBER_COLLECTOR::Collect(), and GENERAL_COLLECTOR::Collect().

214  {
216  }
timestamp_t GetNewTimeStamp()
Definition: common.cpp:166
time_t m_TimeAtCollection
The time at which the collection was made.

Member Data Documentation

const KICAD_T LIB_COLLECTOR::AllItems
static
Initial value:

A scan list for all schematic items.

Definition at line 60 of file lib_collectors.h.

const KICAD_T LIB_COLLECTOR::AllItemsButPins
static
Initial value:

A scan list for all schematic items except pins.

Definition at line 80 of file lib_collectors.h.

const KICAD_T LIB_COLLECTOR::EditableItems
static
Initial value:

A scan list for all editable schematic items.

Definition at line 65 of file lib_collectors.h.

LIB_COLLECTOR_DATA LIB_COLLECTOR::m_data
private

Definition at line 53 of file lib_collectors.h.

Referenced by Collect(), and Inspect().

EDA_RECT COLLECTOR::m_RefBox
protectedinherited

A bounding box to test against, and that was used to make the collection.

Definition at line 72 of file class_collector.h.

Referenced by COLLECTOR::GetBoundingBox().

wxPoint COLLECTOR::m_RefPos
protectedinherited

A point to test against, and that was used to make the collection.

Definition at line 69 of file class_collector.h.

Referenced by COLLECTOR::GetRefPos(), Inspect(), GERBER_COLLECTOR::Inspect(), SCH_COLLECTOR::Inspect(), GENERAL_COLLECTOR::Inspect(), and SCH_COLLECTOR::IsDraggableJunction().

const KICAD_T* COLLECTOR::m_ScanTypes
protectedinherited
time_t COLLECTOR::m_TimeAtCollection
protectedinherited

The time at which the collection was made.

Definition at line 75 of file class_collector.h.

Referenced by COLLECTOR::GetTime().

const KICAD_T LIB_COLLECTOR::MovableItems
static
Initial value:

A scan list for all movable schematic items.

Definition at line 70 of file lib_collectors.h.

const KICAD_T LIB_COLLECTOR::RotatableItems
static
Initial value:

A scan list for all rotatable schematic items.

Definition at line 75 of file lib_collectors.h.


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