KiCad PCB EDA Suite
COLLECTOR Class Referenceabstract

Class COLLECTOR is an abstract class that will find and hold all the objects according to an inspection done by the Inspect() function which must be implemented by any derived class. More...

#include <class_collector.h>

Inheritance diagram for COLLECTOR:
GENERAL_COLLECTOR LIB_COLLECTOR PCB_TYPE_COLLECTOR SCH_COLLECTOR SCH_FIND_COLLECTOR SCH_TYPE_COLLECTOR

Public Member Functions

 COLLECTOR ()
 
virtual ~COLLECTOR ()
 
virtual SEARCH_RESULT Inspect (EDA_ITEM *aItem, void *aTestData)=0
 
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_ITEMoperator[] (int aIndex) const
 Function operator[int] is used for read only access and returns the object at aIndex. 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...
 

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

Detailed Description

Class COLLECTOR is an abstract class that will find and hold all the objects according to an inspection done by the Inspect() function which must be implemented by any derived class.

When Inspect() finds an object that it wants to collect, i.e. one that it "likes", then it only has to do an Append( testItem ) on it to add it to its collection, but in all cases for the scan to continue, Inspect() must return SEARCH_CONTINUE.

Later, after collection, the user can iterate through all the objects in the remembered collection using GetCount() and the [int] operator.

Definition at line 56 of file class_collector.h.

Constructor & Destructor Documentation

COLLECTOR::COLLECTOR ( )
inline

Definition at line 78 of file class_collector.h.

References Inspect().

78  :
79  // Inspect() is virtual so calling it from a class common inspector preserves polymorphism.
80  m_inspector( [=] ( EDA_ITEM* aItem, void* aTestData ) { return this->Inspect( aItem, aTestData ); } )
81  {
82  m_ScanTypes = 0;
84  }
INSPECTOR_FUNC m_inspector
a class common bridge into the polymorphic Inspect()
virtual SEARCH_RESULT Inspect(EDA_ITEM *aItem, void *aTestData)=0
time_t m_TimeAtCollection
The time at which the collection was made.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
const KICAD_T * m_ScanTypes
Which object types to scan.
virtual COLLECTOR::~COLLECTOR ( )
inlinevirtual

Definition at line 86 of file class_collector.h.

86 {}

Member Function Documentation

void COLLECTOR::Append ( EDA_ITEM item)
inline

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(), LIB_COLLECTOR::Inspect(), SCH_COLLECTOR::Inspect(), GENERAL_COLLECTOR::Inspect(), SCH_FIND_COLLECTOR::Inspect(), SCH_TYPE_COLLECTOR::Inspect(), and PCB_TYPE_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
inline

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.
int COLLECTOR::CountType ( KICAD_T  aType)
inline

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

Function Empty sets the list to empty.

Definition at line 116 of file class_collector.h.

Referenced by LIB_COLLECTOR::Collect(), SCH_COLLECTOR::Collect(), GENERAL_COLLECTOR::Collect(), SCH_TYPE_COLLECTOR::Collect(), PCB_TYPE_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
inline

Definition at line 227 of file class_collector.h.

References 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
inline

Definition at line 224 of file class_collector.h.

References 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 ( )
inline

Definition at line 218 of file class_collector.h.

References 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
inline

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.
virtual SEARCH_RESULT COLLECTOR::Inspect ( EDA_ITEM aItem,
void *  aTestData 
)
pure virtual
bool COLLECTOR::IsSimilarPointAndTime ( const wxPoint aRefPos)
inline

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  }
time_t GetNewTimeStamp()
Definition: common.cpp:166
#define abs(a)
Definition: auxiliary.h:84
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)
inline

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.
EDA_ITEM* COLLECTOR::operator[] ( int  aIndex) const
inline

Function operator[int] is used for read only access and returns the object at aIndex.

Parameters
aIndexThe index into the list.
Returns
EDA_ITEM* - or something derived from it, or NULL.

Definition at line 164 of file class_collector.h.

References GetCount().

165  {
166  if( (unsigned)aIndex < (unsigned)GetCount() ) // (unsigned) excludes aIndex<0 also
167  return m_List[ aIndex ];
168 
169  return NULL;
170  }
int GetCount() const
Function GetCount returns the number of objects in the list.
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
void COLLECTOR::Remove ( int  aIndex)
inline

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(), 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)
inline

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

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

Definition at line 223 of file class_collector.h.

Referenced by LIB_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)
inline

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 LIB_COLLECTOR::Collect(), SCH_COLLECTOR::Collect(), GENERAL_COLLECTOR::Collect(), SCH_TYPE_COLLECTOR::Collect(), GENERAL_COLLECTOR::GENERAL_COLLECTOR(), LIB_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 ( )
inline

Definition at line 213 of file class_collector.h.

References GetNewTimeStamp().

Referenced by GENERAL_COLLECTOR::Collect().

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

Member Data Documentation

INSPECTOR_FUNC COLLECTOR::m_inspector
protected
EDA_RECT COLLECTOR::m_RefBox
protected

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

wxPoint COLLECTOR::m_RefPos
protected

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

Definition at line 69 of file class_collector.h.

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

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

The time at which the collection was made.

Definition at line 75 of file class_collector.h.

Referenced by GetTime().


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