KiCad PCB EDA Suite
SCH_FIND_COLLECTOR Class Reference

Class SCH_FIND_COLLECTOR is used to iterate over all of the items in a schematic or sheet and collect all the items that match the given search criteria. More...

#include <sch_collectors.h>

Inheritance diagram for SCH_FIND_COLLECTOR:
COLLECTOR

Public Member Functions

 SCH_FIND_COLLECTOR (const KICAD_T *aScanTypes=SCH_COLLECTOR::AllItems)
 Function dump is a helper to dump the items in the find list for debugging purposes. More...
 
void Empty ()
 
SCH_ITEMGetItem (int ndx) const
 
SCH_ITEMoperator[] (int ndx) const
 
void SetForceSearch (bool doSearch=true)
 
int GetLibHash () const
 
void SetLibHash (int aHash)
 
int GetFoundIndex () const
 
void SetFoundIndex (int aIndex)
 
bool PassedEnd () const
 Function PassedEnd tests if m_foundIndex is beyond the end of the list give the current find/replace criterial in m_findReplaceData. More...
 
void UpdateIndex ()
 Function UpdateIndex updates the list index according to the current find and replace criteria. More...
 
SCH_FIND_COLLECTOR_DATA GetFindData (int aIndex)
 Function GetFindData returns the data associated with the item found at aIndex. More...
 
bool IsSearchRequired (const SCH_FIND_REPLACE_DATA &aFindReplaceData)
 Function IsSearchRequired checks the current collector state against aFindReplaceData to see if a new search needs to be performed to update the collector. More...
 
wxString GetText ()
 Function GetText() More...
 
EDA_ITEMGetItem (SCH_FIND_COLLECTOR_DATA &aFindData)
 Function GetItem returns the item and associated data of the current index. More...
 
bool ReplaceItem (SCH_SHEET_PATH *aSheetPath=NULL)
 Function ReplaceItem performs a string replace of the item at the current index. More...
 
SEARCH_RESULT Inspect (EDA_ITEM *aItem, void *aTestData) override
 
void SetReplaceString (const wxString &aReplaceString)
 Update the replace string without changing anything else. More...
 
void Collect (SCH_FIND_REPLACE_DATA &aFindReplaceData, SCH_SHEET_PATH *aSheetPath=NULL)
 Function Collect scans aSheetPath using this class's Inspector method for items matching aFindReplaceData. More...
 
void IncrementIndex ()
 
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 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 ()
 
timestamp_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...
 
timestamp_t m_TimeAtCollection
 The time at which the collection was made. More...
 

Private Attributes

std::vector< SCH_FIND_COLLECTOR_DATAm_data
 Data associated with each found item. More...
 
SCH_FIND_REPLACE_DATA m_findReplaceData
 The criteria used to test for matching items. More...
 
SCH_SHEET_PATHm_currentSheetPath
 The path of the sheet currently being iterated over. More...
 
SCH_SHEET_PATHS m_sheetPaths
 The paths of the all the sheets in the collector. More...
 
int m_foundIndex
 The current found item list index. More...
 
bool m_forceSearch
 A flag to indicate that the schemtic has been modified and a new search must be performed even if the search criteria hasn't changed. More...
 
int m_lib_hash
 last known library change hash, used to detect library changes which should trigger cache obsolescence. More...
 

Detailed Description

Class SCH_FIND_COLLECTOR is used to iterate over all of the items in a schematic or sheet and collect all the items that match the given search criteria.

Definition at line 232 of file sch_collectors.h.

Constructor & Destructor Documentation

SCH_FIND_COLLECTOR::SCH_FIND_COLLECTOR ( const KICAD_T aScanTypes = SCH_COLLECTOR::AllItems)
inline

Function dump is a helper to dump the items in the find list for debugging purposes.

Constructor SCH_FIND_COLLECTOR

Definition at line 270 of file sch_collectors.h.

References COLLECTOR::SetScanTypes().

271  {
272  SetScanTypes( aScanTypes );
273  m_foundIndex = 0;
274  SetForceSearch( false );
275  m_currentSheetPath = NULL;
276  m_lib_hash = 0;
277  }
SCH_SHEET_PATH * m_currentSheetPath
The path of the sheet currently being iterated over.
void SetScanTypes(const KICAD_T *scanTypes)
Function SetScanTypes records the list of KICAD_T types to consider for collection by the Inspect() f...
Definition: collector.h:207
void SetForceSearch(bool doSearch=true)
int m_lib_hash
last known library change hash, used to detect library changes which should trigger cache obsolescenc...
int m_foundIndex
The current found item list index.

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 125 of file collector.h.

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

126  {
127  m_List.push_back( item );
128  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65
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 177 of file collector.h.

178  {
179  return &m_List[0];
180  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65
void SCH_FIND_COLLECTOR::Collect ( SCH_FIND_REPLACE_DATA aFindReplaceData,
SCH_SHEET_PATH aSheetPath = NULL 
)

Function Collect scans aSheetPath using this class's Inspector method for items matching aFindReplaceData.

Parameters
aFindReplaceDataA SCH_FIND_REPLACE_DATA object containing the search criteria.
aSheetPathA pointer to a SCH_SHEET_PATH object to test for matches. A NULL value searches the entire schematic hierarchy.

Definition at line 575 of file sch_collectors.cpp.

References dump(), COLLECTOR::Empty(), g_RootSheet, i, EDA_ITEM::IterateForward(), SCH_SHEET_PATH::LastDrawList(), COLLECTOR::m_inspector, COLLECTOR::m_List, and COLLECTOR::m_ScanTypes.

Referenced by SCH_EDIT_FRAME::OnFindReplace(), and SCH_EDIT_FRAME::OnFindSchematicItem().

577 {
578  if( !IsSearchRequired( aFindReplaceData ) && !m_List.empty() && !m_forceSearch )
579  return;
580 
581  m_findReplaceData = aFindReplaceData;
582  Empty(); // empty the collection just in case
583  m_data.clear();
584  m_foundIndex = 0;
585  m_sheetPaths.clear();
586  SetForceSearch( false );
587 
588  if( aSheetPath )
589  {
590  m_currentSheetPath = aSheetPath;
591  m_sheetPaths.push_back( *m_currentSheetPath );
593  }
594  else
595  {
596  SCH_SHEET_LIST schematic( g_RootSheet );
597 
598  for( unsigned i = 0; i < schematic.size(); i++ )
599  {
600  m_currentSheetPath = &schematic[i];
601  m_sheetPaths.push_back( *m_currentSheetPath );
603  }
604  }
605 
606 #if defined(DEBUG)
607  dump();
608 #endif
609 
610  if( m_List.size() != m_data.size() )
611  {
612  wxFAIL_MSG( wxT( "List size mismatch." ) );
613  m_List.clear();
614  m_data.clear();
615  }
616 }
SCH_ITEM * LastDrawList() const
Function LastDrawList.
Class SCH_SHEET_LIST.
static SEARCH_RESULT IterateForward(EDA_ITEM *listStart, INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
Function IterateForward walks through the object tree calling the inspector() on each object type req...
bool IsSearchRequired(const SCH_FIND_REPLACE_DATA &aFindReplaceData)
Function IsSearchRequired checks the current collector state against aFindReplaceData to see if a new...
SCH_SHEET_PATH * m_currentSheetPath
The path of the sheet currently being iterated over.
std::vector< SCH_FIND_COLLECTOR_DATA > m_data
Data associated with each found item.
INSPECTOR_FUNC m_inspector
a class common bridge into the polymorphic Inspect()
Definition: collector.h:59
SCH_SHEET_PATHS m_sheetPaths
The paths of the all the sheets in the collector.
void SetForceSearch(bool doSearch=true)
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
int m_foundIndex
The current found item list index.
size_t i
Definition: json11.cpp:597
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65
const KICAD_T * m_ScanTypes
Which object types to scan.
Definition: collector.h:62
bool m_forceSearch
A flag to indicate that the schemtic has been modified and a new search must be performed even if the...
SCH_FIND_REPLACE_DATA m_findReplaceData
The criteria used to test for matching items.
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 257 of file collector.h.

References i.

Referenced by SELECTION_TOOL::guessSelectionCandidates(), and ROUTER_TOOL::NeighboringSegmentFilter().

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

Definition at line 279 of file sch_collectors.h.

References COLLECTOR::Empty(), and SCH_COLLECTOR::operator[]().

280  {
281  m_foundIndex = 0;
283  m_data.clear();
284  }
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:115
std::vector< SCH_FIND_COLLECTOR_DATA > m_data
Data associated with each found item.
int m_foundIndex
The current found item list index.
const EDA_RECT& COLLECTOR::GetBoundingBox ( ) const
inlineinherited

Definition at line 226 of file collector.h.

References COLLECTOR::m_RefBox.

226 { return m_RefBox; }
EDA_RECT m_RefBox
A bounding box to test against, and that was used to make the collection.
Definition: collector.h:71
int COLLECTOR::GetCount ( ) const
inlineinherited

Function GetCount returns the number of objects in the list.

Definition at line 106 of file collector.h.

Referenced by AllAreModulesAndReturnSmallestIfSo(), SCH_EDIT_FRAME::AppendSchematic(), BuildBoardPolygonOutlines(), calcMaxArea(), connectedItemFilter(), connectedTrackFilter(), MODULE::CoverageRatio(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), SELECTION_TOOL::disambiguationMenu(), MODULE_EDITOR_TOOLS::EnumeratePads(), EDIT_TOOL::FootprintFilter(), DSN::SPECCTRA_DB::FromBOARD(), GetItem(), DIALOG_LAYERS_SETUP::getNonRemovableLayers(), DIALOG_LAYERS_SETUP::getRemovedLayersWithItems(), GetText(), GENDRILL_WRITER_BASE::getUniqueLayerPairs(), SELECTION_TOOL::guessSelectionCandidates(), highlightNet(), SCH_EDIT_FRAME::importFile(), SCH_COLLECTOR::IsCorner(), LIB_EDIT_FRAME::locateItem(), SCH_EDIT_FRAME::LocateItem(), DSN::SPECCTRA_DB::makeIMAGE(), ROUTER_TOOL::NeighboringSegmentFilter(), SCH_EDIT_FRAME::OnFindSchematicItem(), LIB_EDIT_FRAME::OnSelectItem(), GERBER_COLLECTOR::operator[](), SCH_COLLECTOR::operator[](), COLLECTOR::operator[](), PassedEnd(), PCB_BASE_FRAME::PcbGeneralLocateAndDisplay(), SELECTION_TOOL::pickSmallestComponent(), SCH_COMPONENT::ResolveAll(), GERBVIEW_SELECTION_TOOL::selectPoint(), SELECTION_TOOL::selectPoint(), DIALOG_LAYERS_SETUP::TransferDataFromWindow(), SCH_COMPONENT::UpdateAllPinCaches(), and UpdateIndex().

107  {
108  return (int) m_List.size();
109  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65
SCH_FIND_COLLECTOR_DATA SCH_FIND_COLLECTOR::GetFindData ( int  aIndex)

Function GetFindData returns the data associated with the item found at aIndex.

Parameters
aIndexThe list index of the data to return.
Returns
The associated found item data at aIndex if aIndex is within the list limits. Otherwise an empty data item will be returned.

Definition at line 476 of file sch_collectors.cpp.

477 {
478  wxCHECK_MSG( (unsigned) aIndex < m_data.size(), SCH_FIND_COLLECTOR_DATA(),
479  wxT( "Attempt to get find data outside of list boundary." ) );
480 
481  return m_data[ aIndex ];
482 }
Class SCH_FIND_COLLECTOR_DATA is used as a data container for the associated item found by the SCH_FI...
std::vector< SCH_FIND_COLLECTOR_DATA > m_data
Data associated with each found item.
int SCH_FIND_COLLECTOR::GetFoundIndex ( ) const
inline

Definition at line 294 of file sch_collectors.h.

294 { return m_foundIndex; }
int m_foundIndex
The current found item list index.
SCH_ITEM * SCH_FIND_COLLECTOR::GetItem ( int  ndx) const

Definition at line 370 of file sch_collectors.cpp.

References SCH_COLLECTOR::AllItems, g_DeletedSchItem, COLLECTOR::GetCount(), i, EDA_ITEM::IterateForward(), COLLECTOR::m_List, SEARCH_CONTINUE, and SEARCH_QUIT.

Referenced by SCH_EDIT_FRAME::OnFindReplace(), SCH_EDIT_FRAME::OnFindSchematicItem(), and SCH_EDIT_FRAME::updateFindReplaceView().

371 {
372  if( (unsigned)ndx >= (unsigned)GetCount() )
373  return NULL;
374 
375  // Do not simply return m_List[ ndx ] as it might have been deleted. Instead
376  // treat it as a weak reference and search the sheets for an item with the same
377  // pointer value.
378 
379  void* weakRef = m_List[ ndx ];
380  SCH_ITEM* item = &g_DeletedSchItem;
381 
382  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* candidate, void* testData )
383  {
384  if( (void*) candidate == weakRef )
385  {
386  item = (SCH_ITEM*) candidate;
387  return SEARCH_QUIT;
388  }
389 
390  return SEARCH_CONTINUE;
391  };
392 
393  for( unsigned i = 0; i < m_sheetPaths.size(); i++ )
394  {
395  EDA_ITEM::IterateForward( m_sheetPaths[ i ].LastDrawList(),
396  inspector, nullptr, SCH_COLLECTOR::AllItems );
397  }
398 
399  return item;
400 }
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:106
static SEARCH_RESULT IterateForward(EDA_ITEM *listStart, INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
Function IterateForward walks through the object tree calling the inspector() on each object type req...
std::function< SEARCH_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Typedef INSPECTOR is used to inspect and possibly collect the (search) results of iterating over a li...
Definition: base_struct.h:75
static const KICAD_T AllItems[]
A scan list for all schematic items.
DELETED_SCH_ITEM g_DeletedSchItem
SCH_SHEET_PATHS m_sheetPaths
The paths of the all the sheets in the collector.
size_t i
Definition: json11.cpp:597
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
EDA_ITEM * SCH_FIND_COLLECTOR::GetItem ( SCH_FIND_COLLECTOR_DATA aFindData)

Function GetItem returns the item and associated data of the current index.

Parameters
aFindDataA reference to a SCH_FIND_COLLECTOR_DATA object to place the associated data for the current item into if the current item index is valid.
Returns
A pointer to the current EDA_ITEM in the list if the list index is valid Otherwise NULL is returned and the aFindData object is not updated.

Definition at line 513 of file sch_collectors.cpp.

514 {
515  if( PassedEnd() )
516  return NULL;
517 
518  aData = m_data[ m_foundIndex ];
519  return GetItem( m_foundIndex );
520 }
SCH_ITEM * GetItem(int ndx) const
std::vector< SCH_FIND_COLLECTOR_DATA > m_data
Data associated with each found item.
int m_foundIndex
The current found item list index.
bool PassedEnd() const
Function PassedEnd tests if m_foundIndex is beyond the end of the list give the current find/replace ...
int SCH_FIND_COLLECTOR::GetLibHash ( ) const
inline

Definition at line 291 of file sch_collectors.h.

Referenced by SCH_EDIT_FRAME::IsSearchCacheObsolete().

291 { return m_lib_hash; }
int m_lib_hash
last known library change hash, used to detect library changes which should trigger cache obsolescenc...
const wxPoint& COLLECTOR::GetRefPos ( ) const
inlineinherited

Definition at line 223 of file collector.h.

References COLLECTOR::m_RefPos.

Referenced by PCB_EDIT_FRAME::OnRightClick().

223 { return m_RefPos; }
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
Definition: collector.h:68
wxString SCH_FIND_COLLECTOR::GetText ( )

Function GetText()

Returns
A wxString object containing the description of the item found at the current index or a wxEmptyString if the list is empty or the index is invalid.

Definition at line 485 of file sch_collectors.cpp.

References GetChars(), COLLECTOR::GetCount(), SCH_FIND_COLLECTOR_DATA::GetParent(), EDA_ITEM::GetSelectMenuText(), SCH_FIND_COLLECTOR_DATA::GetSheetPath(), and COLLECTOR::IsValidIndex().

Referenced by SCH_EDIT_FRAME::updateFindReplaceView().

486 {
487  wxCHECK_MSG( (GetCount() != 0) && IsValidIndex( m_foundIndex ), wxEmptyString,
488  wxT( "Cannot get found item at invalid index." ) );
489 
491  EDA_ITEM* foundItem = GetItem( m_foundIndex );
492 
493  wxString msg;
494 
495  if( data.GetParent() )
496  {
497  msg.Printf( _( "Child item %s of parent item %s found in sheet %s" ),
498  GetChars( foundItem->GetSelectMenuText() ),
499  GetChars( data.GetParent()->GetSelectMenuText() ),
500  GetChars( data.GetSheetPath() ) );
501  }
502  else
503  {
504  msg.Printf( _( "Item %s found in sheet %s" ),
505  GetChars( foundItem->GetSelectMenuText() ),
506  GetChars( data.GetSheetPath() ) );
507  }
508 
509  return msg;
510 }
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:106
SCH_ITEM * GetItem(int ndx) const
bool IsValidIndex(int aIndex)
Function IsValidIndex tests if aIndex is with the limits of the list of collected items...
Definition: collector.h:97
wxString GetSheetPath() const
Class SCH_FIND_COLLECTOR_DATA is used as a data container for the associated item found by the SCH_FI...
std::vector< SCH_FIND_COLLECTOR_DATA > m_data
Data associated with each found item.
virtual wxString GetSelectMenuText() const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
SCH_ITEM * GetParent() const
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
int m_foundIndex
The current found item list index.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
timestamp_t COLLECTOR::GetTime ( )
inlineinherited

Definition at line 217 of file collector.h.

References COLLECTOR::m_TimeAtCollection.

218  {
219  return m_TimeAtCollection;
220  }
timestamp_t m_TimeAtCollection
The time at which the collection was made.
Definition: collector.h:74
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 189 of file collector.h.

References i.

190  {
191  for( size_t i = 0; i < m_List.size(); i++ )
192  {
193  if( m_List[i] == aItem )
194  return true;
195  }
196 
197  return false;
198  }
size_t i
Definition: json11.cpp:597
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65
void SCH_FIND_COLLECTOR::IncrementIndex ( )
inline

Definition at line 387 of file sch_collectors.h.

Referenced by SCH_EDIT_FRAME::OnFindReplace().

387 { m_foundIndex += 1; }
int m_foundIndex
The current found item list index.
SEARCH_RESULT SCH_FIND_COLLECTOR::Inspect ( EDA_ITEM aItem,
void *  aTestData 
)
overridevirtual

Implements COLLECTOR.

Definition at line 539 of file sch_collectors.cpp.

References COLLECTOR::Append(), SCH_COMPONENT::GetPosition(), SCH_COMPONENT::GetTransform(), LIB_PIN_T, EDA_ITEM::Matches(), SCH_COMPONENT_T, SEARCH_CONTINUE, TRANSFORM::TransformCoordinate(), EDA_ITEM::Type(), and wxPoint::y.

540 {
541  wxPoint position;
542 
543  if( aItem->Matches( m_findReplaceData, m_currentSheetPath, &position ) )
544  {
545  if( aItem->Type() == LIB_PIN_T )
546  {
547  wxCHECK_MSG( aTestData && ( (EDA_ITEM*) aTestData )->Type() == SCH_COMPONENT_T,
548  SEARCH_CONTINUE, wxT( "Cannot inspect invalid data. Bad programmer!" ) );
549 
550  // Pin positions are relative to their parent component's position and
551  // orientation in the schematic. The pin's position must be converted
552  // schematic coordinates.
553  SCH_COMPONENT* component = (SCH_COMPONENT*) aTestData;
554  TRANSFORM transform = component->GetTransform();
555  position.y = -position.y;
556  position = transform.TransformCoordinate( position ) + component->GetPosition();
557  }
558 
559  Append( aItem );
560  m_data.push_back( SCH_FIND_COLLECTOR_DATA( position,
562  (SCH_ITEM*) aTestData ) );
563  }
564 
565  return SEARCH_CONTINUE;
566 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
TRANSFORM & GetTransform() const
SCH_SHEET_PATH * m_currentSheetPath
The path of the sheet currently being iterated over.
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:411
Class SCH_FIND_COLLECTOR_DATA is used as a data container for the associated item found by the SCH_FI...
std::vector< SCH_FIND_COLLECTOR_DATA > m_data
Data associated with each found item.
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:125
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:41
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
wxString PathHumanReadable() const
Function PathHumanReadable returns the sheet path in a human readable form, i.e.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
wxPoint GetPosition() const override
Function GetPosition.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
SCH_FIND_REPLACE_DATA m_findReplaceData
The criteria used to test for matching items.
bool SCH_FIND_COLLECTOR::IsSearchRequired ( const SCH_FIND_REPLACE_DATA aFindReplaceData)
inline

Function IsSearchRequired checks the current collector state against aFindReplaceData to see if a new search needs to be performed to update the collector.

Parameters
aFindReplaceDataA SCH_FIND_REPLACE_DATA object containing the search criteria to test for changes against the current search criteria.
Returns
True if aFindReplaceData would require a new search to be performaed or the force search flag is true. Otherwise, false is returned.

Definition at line 335 of file sch_collectors.h.

References SCH_FIND_REPLACE_DATA::ChangesCompare(), SCH_COLLECTOR::Collect(), GetText(), SCH_COLLECTOR::Inspect(), and SCH_FIND_REPLACE_DATA::IsWrapping().

Referenced by SCH_EDIT_FRAME::IsSearchCacheObsolete().

336  {
337  return m_findReplaceData.ChangesCompare( aFindReplaceData ) || m_forceSearch ||
338  (m_findReplaceData.IsWrapping() != aFindReplaceData.IsWrapping());
339  }
bool ChangesCompare(const SCH_FIND_REPLACE_DATA &aFindReplaceData)
Function ChangesCompare tests aFindReplaceData to see if it would result in a change in the search st...
bool m_forceSearch
A flag to indicate that the schemtic has been modified and a new search must be performed even if the...
SCH_FIND_REPLACE_DATA m_findReplaceData
The criteria used to test for matching items.
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 237 of file collector.h.

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

238  {
239  const int distMax = 2; // adjust these here
240  const timestamp_t timeMax = 3; // seconds
241 
242  int dx = abs( aRefPos.x - m_RefPos.x );
243  int dy = abs( aRefPos.y - m_RefPos.y );
244 
245  if( dx <= distMax && dy <= distMax &&
246  GetNewTimeStamp() - m_TimeAtCollection <= timeMax )
247  return true;
248  else
249  return false;
250  }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: base_struct.h:155
#define abs(a)
Definition: auxiliary.h:84
timestamp_t GetNewTimeStamp()
Definition: common.cpp:167
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
Definition: collector.h:68
timestamp_t m_TimeAtCollection
The time at which the collection was made.
Definition: collector.h:74
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 97 of file collector.h.

Referenced by GetText(), and ReplaceItem().

98  {
99  return ( (unsigned) aIndex < m_List.size() );
100  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65
SCH_ITEM * SCH_FIND_COLLECTOR::operator[] ( int  ndx) const

Definition at line 403 of file sch_collectors.cpp.

404 {
405  return GetItem( ndx );
406 }
SCH_ITEM * GetItem(int ndx) const
bool SCH_FIND_COLLECTOR::PassedEnd ( ) const

Function PassedEnd tests if m_foundIndex is beyond the end of the list give the current find/replace criterial in m_findReplaceData.

Returns
True if m_foundIndex has crossed the end of the found item list.

Definition at line 409 of file sch_collectors.cpp.

References dump(), FR_SEARCH_REPLACE, FR_SEARCH_WRAP, GetChars(), COLLECTOR::GetCount(), GetText(), and traceFindReplace.

Referenced by SCH_EDIT_FRAME::OnFindReplace().

410 {
411  bool retv = false;
412 
413  wxUint32 flags = m_findReplaceData.GetFlags();
414 
415  if( GetCount() == 0 )
416  return true;
417 
418  if( !(flags & FR_SEARCH_WRAP) || (flags & FR_SEARCH_REPLACE) )
419  {
420  if( flags & wxFR_DOWN )
421  {
422  if( m_foundIndex >= GetCount() )
423  retv = true;
424  }
425  else
426  {
427  if( m_foundIndex < 0 )
428  retv = true;
429  }
430  }
431 
432  return retv;
433 }
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:106
Wrap around the beginning or end of search list.
int m_foundIndex
The current found item list index.
Perform a search for a item that has replaceable text.
SCH_FIND_REPLACE_DATA m_findReplaceData
The criteria used to test for matching items.
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 135 of file collector.h.

Referenced by connectedItemFilter(), connectedTrackFilter(), EDIT_TOOL::FootprintFilter(), SELECTION_TOOL::guessSelectionCandidates(), ROUTER_TOOL::NeighboringSegmentFilter(), PCB_BASE_FRAME::PcbGeneralLocateAndDisplay(), GERBVIEW_SELECTION_TOOL::selectPoint(), and SELECTION_TOOL::selectPoint().

136  {
137  m_List.erase( m_List.begin() + aIndex );
138  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65
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 145 of file collector.h.

References i.

146  {
147  for( size_t i = 0; i < m_List.size(); i++ )
148  {
149  if( m_List[i] == aItem )
150  {
151  m_List.erase( m_List.begin() + i);
152  return;
153  }
154  }
155  }
size_t i
Definition: json11.cpp:597
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65
bool SCH_FIND_COLLECTOR::ReplaceItem ( SCH_SHEET_PATH aSheetPath = NULL)

Function ReplaceItem performs a string replace of the item at the current index.

Returns
True if the text replace occurred otherwise false.

Definition at line 523 of file sch_collectors.cpp.

References COLLECTOR::IsValidIndex(), and EDA_ITEM::Replace().

Referenced by SCH_EDIT_FRAME::OnFindReplace().

524 {
525  if( PassedEnd() )
526  return false;
527 
528  wxCHECK_MSG( IsValidIndex( m_foundIndex ), false,
529  wxT( "Invalid replace list index in SCH_FIND_COLLECTOR." ) );
530 
531  EDA_ITEM* item = GetItem( m_foundIndex );
532 
533  bool replaced = item->Replace( m_findReplaceData, aSheetPath );
534 
535  return replaced;
536 }
SCH_ITEM * GetItem(int ndx) const
bool IsValidIndex(int aIndex)
Function IsValidIndex tests if aIndex is with the limits of the list of collected items...
Definition: collector.h:97
bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
int m_foundIndex
The current found item list index.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
bool PassedEnd() const
Function PassedEnd tests if m_foundIndex is beyond the end of the list give the current find/replace ...
SCH_FIND_REPLACE_DATA m_findReplaceData
The criteria used to test for matching items.
void COLLECTOR::SetBoundingBox ( const EDA_RECT aRefBox)
inlineinherited

Definition at line 225 of file collector.h.

225 { m_RefBox = aRefBox; }
EDA_RECT m_RefBox
A bounding box to test against, and that was used to make the collection.
Definition: collector.h:71
void SCH_FIND_COLLECTOR::SetForceSearch ( bool  doSearch = true)
inline

Definition at line 289 of file sch_collectors.h.

Referenced by SCH_EDIT_FRAME::IsSearchCacheObsolete(), and SCH_EDIT_FRAME::OnFindReplace().

289 { m_forceSearch = doSearch; }
bool m_forceSearch
A flag to indicate that the schemtic has been modified and a new search must be performed even if the...
void SCH_FIND_COLLECTOR::SetFoundIndex ( int  aIndex)
inline

Definition at line 295 of file sch_collectors.h.

296  {
297  m_foundIndex = ( (unsigned) aIndex < m_data.size() ) ? aIndex : 0;
298  }
std::vector< SCH_FIND_COLLECTOR_DATA > m_data
Data associated with each found item.
int m_foundIndex
The current found item list index.
void SCH_FIND_COLLECTOR::SetLibHash ( int  aHash)
inline

Definition at line 292 of file sch_collectors.h.

Referenced by SCH_EDIT_FRAME::IsSearchCacheObsolete().

292 { m_lib_hash = aHash; }
int m_lib_hash
last known library change hash, used to detect library changes which should trigger cache obsolescenc...
void COLLECTOR::SetRefPos ( const wxPoint aRefPos)
inlineinherited

Definition at line 222 of file collector.h.

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

222 { m_RefPos = aRefPos; }
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
Definition: collector.h:68
void SCH_FIND_COLLECTOR::SetReplaceString ( const wxString &  aReplaceString)

Update the replace string without changing anything else.

Definition at line 569 of file sch_collectors.cpp.

Referenced by SCH_EDIT_FRAME::OnFindReplace().

570 {
571  m_findReplaceData.SetReplaceString( aReplaceString );
572 }
SCH_FIND_REPLACE_DATA m_findReplaceData
The criteria used to test for matching items.
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 207 of file collector.h.

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

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

Definition at line 212 of file collector.h.

References GetNewTimeStamp().

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

213  {
215  }
timestamp_t GetNewTimeStamp()
Definition: common.cpp:167
timestamp_t m_TimeAtCollection
The time at which the collection was made.
Definition: collector.h:74
void SCH_FIND_COLLECTOR::UpdateIndex ( )

Function UpdateIndex updates the list index according to the current find and replace criteria.

Definition at line 455 of file sch_collectors.cpp.

References FR_SEARCH_WRAP, and COLLECTOR::GetCount().

Referenced by SCH_EDIT_FRAME::OnFindSchematicItem().

456 {
457  wxUint32 flags = m_findReplaceData.GetFlags();
458 
459  if( flags & wxFR_DOWN )
460  {
461  if( m_foundIndex < GetCount() )
462  m_foundIndex += 1;
463  if( (m_foundIndex >= GetCount()) && (flags & FR_SEARCH_WRAP) )
464  m_foundIndex = 0;
465  }
466  else
467  {
468  if( m_foundIndex >= 0 )
469  m_foundIndex -= 1;
470  if( (m_foundIndex < 0) && (flags & FR_SEARCH_WRAP) )
471  m_foundIndex = GetCount() - 1;
472  }
473 }
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:106
Wrap around the beginning or end of search list.
int m_foundIndex
The current found item list index.
SCH_FIND_REPLACE_DATA m_findReplaceData
The criteria used to test for matching items.

Member Data Documentation

SCH_SHEET_PATH* SCH_FIND_COLLECTOR::m_currentSheetPath
private

The path of the sheet currently being iterated over.

Definition at line 241 of file sch_collectors.h.

std::vector< SCH_FIND_COLLECTOR_DATA > SCH_FIND_COLLECTOR::m_data
private

Data associated with each found item.

Definition at line 235 of file sch_collectors.h.

SCH_FIND_REPLACE_DATA SCH_FIND_COLLECTOR::m_findReplaceData
private

The criteria used to test for matching items.

Definition at line 238 of file sch_collectors.h.

bool SCH_FIND_COLLECTOR::m_forceSearch
private

A flag to indicate that the schemtic has been modified and a new search must be performed even if the search criteria hasn't changed.

Definition at line 251 of file sch_collectors.h.

int SCH_FIND_COLLECTOR::m_foundIndex
private

The current found item list index.

Definition at line 247 of file sch_collectors.h.

int SCH_FIND_COLLECTOR::m_lib_hash
private

last known library change hash, used to detect library changes which should trigger cache obsolescence.

Definition at line 255 of file sch_collectors.h.

std::vector<EDA_ITEM*> COLLECTOR::m_List
protectedinherited
EDA_RECT COLLECTOR::m_RefBox
protectedinherited

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

Definition at line 71 of file 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 68 of file collector.h.

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

const KICAD_T* COLLECTOR::m_ScanTypes
protectedinherited
SCH_SHEET_PATHS SCH_FIND_COLLECTOR::m_sheetPaths
private

The paths of the all the sheets in the collector.

Definition at line 244 of file sch_collectors.h.

timestamp_t COLLECTOR::m_TimeAtCollection
protectedinherited

The time at which the collection was made.

Definition at line 74 of file collector.h.

Referenced by COLLECTOR::GetTime().


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