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 Types

using ITER = std::vector< EDA_ITEM * >::iterator
 
using CITER = std::vector< EDA_ITEM * >::const_iterator
 

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 (EDA_UNITS_T aUnits)
 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 ()
 
ITER begin ()
 
CITER begin () const
 
ITER end ()
 
CITER end () const
 
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 wxPoint & GetRefPos () 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 237 of file sch_collectors.h.

Member Typedef Documentation

◆ CITER

using COLLECTOR::CITER = std::vector<EDA_ITEM*>::const_iterator
inherited

Definition at line 90 of file collector.h.

◆ ITER

using COLLECTOR::ITER = std::vector<EDA_ITEM*>::iterator
inherited

Definition at line 89 of file collector.h.

Constructor & Destructor Documentation

◆ SCH_FIND_COLLECTOR()

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 275 of file sch_collectors.h.

276  {
277  SetScanTypes( aScanTypes );
278  m_foundIndex = 0;
279  SetForceSearch( false );
280  m_currentSheetPath = NULL;
281  m_lib_hash = 0;
282  }
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:215
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.

References m_currentSheetPath, m_foundIndex, m_lib_hash, SetForceSearch(), and COLLECTOR::SetScanTypes().

Member Function Documentation

◆ Append()

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

134  {
135  m_List.push_back( item );
136  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65

References COLLECTOR::m_List.

Referenced by GENERAL_COLLECTOR::Collect(), DIALOG_DRC_CONTROL::doSelectionMenu(), EditToolSelectionFilter(), SELECTION_TOOL::guessSelectionCandidates(), GERBER_COLLECTOR::Inspect(), LIB_COLLECTOR::Inspect(), SCH_COLLECTOR::Inspect(), GENERAL_COLLECTOR::Inspect(), Inspect(), SCH_TYPE_COLLECTOR::Inspect(), PCB_TYPE_COLLECTOR::Inspect(), PCB_LAYER_COLLECTOR::Inspect(), ROUTER_TOOL::NeighboringSegmentFilter(), and SELECTION_TOOL::RequestSelection().

◆ BasePtr()

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

186  {
187  return &m_List[0];
188  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65

References COLLECTOR::m_List.

◆ begin() [1/2]

ITER COLLECTOR::begin ( )
inlineinherited

Definition at line 92 of file collector.h.

92 { return m_List.begin(); }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65

References COLLECTOR::m_List.

Referenced by SELECTION_TOOL::RequestSelection().

◆ begin() [2/2]

CITER COLLECTOR::begin ( ) const
inlineinherited

Definition at line 94 of file collector.h.

94 { return m_List.cbegin(); }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65

References COLLECTOR::m_List.

◆ Collect()

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 591 of file sch_collectors.cpp.

593 {
594  if( !IsSearchRequired( aFindReplaceData ) && !m_List.empty() && !m_forceSearch )
595  return;
596 
597  m_findReplaceData = aFindReplaceData;
598  Empty(); // empty the collection just in case
599  m_data.clear();
600  m_foundIndex = 0;
601  m_sheetPaths.clear();
602  SetForceSearch( false );
603 
604  if( aSheetPath )
605  {
606  m_currentSheetPath = aSheetPath;
607  m_sheetPaths.push_back( *m_currentSheetPath );
609  }
610  else
611  {
612  SCH_SHEET_LIST schematic( g_RootSheet );
613 
614  for( unsigned i = 0; i < schematic.size(); i++ )
615  {
616  m_currentSheetPath = &schematic[i];
617  m_sheetPaths.push_back( *m_currentSheetPath );
619  }
620  }
621 
622 #if defined(DEBUG)
623  dump();
624 #endif
625 
626  if( m_List.size() != m_data.size() )
627  {
628  wxFAIL_MSG( wxT( "List size mismatch." ) );
629  m_List.clear();
630  m_data.clear();
631  }
632 }
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:56
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
SCH_ITEM * LastDrawList() const
Function LastDrawList.
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.

References dump(), Empty(), g_RootSheet, i, IsSearchRequired(), EDA_ITEM::IterateForward(), SCH_SHEET_PATH::LastDrawList(), m_currentSheetPath, m_data, m_findReplaceData, m_forceSearch, m_foundIndex, COLLECTOR::m_inspector, COLLECTOR::m_List, COLLECTOR::m_ScanTypes, m_sheetPaths, and SetForceSearch().

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

◆ CountType()

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

266  {
267  int cnt = 0;
268  for( size_t i = 0; i < m_List.size(); i++ )
269  {
270  if( m_List[i]->Type() == aType )
271  cnt++;
272  }
273  return cnt;
274  }
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

References i, and COLLECTOR::m_List.

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

◆ Empty()

void SCH_FIND_COLLECTOR::Empty ( )
inline

Definition at line 284 of file sch_collectors.h.

285  {
286  m_foundIndex = 0;
288  m_data.clear();
289  }
void Empty()
Function Empty sets the list to empty.
Definition: collector.h:123
std::vector< SCH_FIND_COLLECTOR_DATA > m_data
Data associated with each found item.
int m_foundIndex
The current found item list index.

References COLLECTOR::Empty(), m_data, and m_foundIndex.

Referenced by Collect().

◆ end() [1/2]

ITER COLLECTOR::end ( )
inlineinherited

Definition at line 93 of file collector.h.

93 { return m_List.end(); }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65

References COLLECTOR::m_List.

Referenced by SELECTION_TOOL::RequestSelection().

◆ end() [2/2]

CITER COLLECTOR::end ( ) const
inlineinherited

Definition at line 95 of file collector.h.

95 { return m_List.cend(); }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65

References COLLECTOR::m_List.

◆ GetBoundingBox()

const EDA_RECT& COLLECTOR::GetBoundingBox ( ) const
inlineinherited

Definition at line 234 of file collector.h.

234 { 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

References COLLECTOR::m_RefBox.

◆ GetCount()

int COLLECTOR::GetCount ( ) const
inlineinherited

Function GetCount returns the number of objects in the list.

Definition at line 114 of file collector.h.

115  {
116  return (int) m_List.size();
117  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65

References COLLECTOR::m_List.

Referenced by AllAreModulesAndReturnSmallestIfSo(), SCH_EDIT_FRAME::AppendSchematic(), BuildBoardPolygonOutlines(), calcMaxArea(), connectedItemFilter(), connectedTrackFilter(), MODULE::CoverageRatio(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), SELECTION_TOOL::doSelectionMenu(), EditToolSelectionFilter(), MODULE_EDITOR_TOOLS::EnumeratePads(), EDIT_TOOL::FootprintFilter(), DSN::SPECCTRA_DB::FromBOARD(), GetItem(), PANEL_SETUP_LAYERS::getNonRemovableLayers(), PANEL_SETUP_LAYERS::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(), SCH_EDIT_FRAME::OnSelectItem(), GERBER_COLLECTOR::operator[](), LIB_COLLECTOR::operator[](), SCH_COLLECTOR::operator[](), COLLECTOR::operator[](), PCB_COLLECTOR::operator[](), EDIT_TOOL::PadFilter(), PassedEnd(), PCB_BASE_FRAME::PcbGeneralLocateAndDisplay(), SELECTION_TOOL::pickSmallestComponent(), SCH_COMPONENT::ResolveAll(), PCB_EDIT_FRAME::SelectHighLight(), GERBVIEW_SELECTION_TOOL::selectPoint(), SELECTION_TOOL::selectPoint(), PANEL_SETUP_LAYERS::TransferDataFromWindow(), SCH_COMPONENT::UpdateAllPinCaches(), and UpdateIndex().

◆ GetFindData()

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 492 of file sch_collectors.cpp.

493 {
494  wxCHECK_MSG( (unsigned) aIndex < m_data.size(), SCH_FIND_COLLECTOR_DATA(),
495  wxT( "Attempt to get find data outside of list boundary." ) );
496 
497  return m_data[ aIndex ];
498 }
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.

References m_data.

◆ GetFoundIndex()

int SCH_FIND_COLLECTOR::GetFoundIndex ( ) const
inline

Definition at line 299 of file sch_collectors.h.

299 { return m_foundIndex; }
int m_foundIndex
The current found item list index.

References m_foundIndex.

◆ GetItem() [1/2]

SCH_ITEM * SCH_FIND_COLLECTOR::GetItem ( int  ndx) const

Definition at line 386 of file sch_collectors.cpp.

387 {
388  if( (unsigned)ndx >= (unsigned)GetCount() )
389  return NULL;
390 
391  // Do not simply return m_List[ ndx ] as it might have been deleted. Instead
392  // treat it as a weak reference and search the sheets for an item with the same
393  // pointer value.
394 
395  void* weakRef = m_List[ ndx ];
396  SCH_ITEM* item = &g_DeletedSchItem;
397 
398  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* candidate, void* testData )
399  {
400  if( (void*) candidate == weakRef )
401  {
402  item = (SCH_ITEM*) candidate;
403  return SEARCH_QUIT;
404  }
405 
406  return SEARCH_CONTINUE;
407  };
408 
409  for( unsigned i = 0; i < m_sheetPaths.size(); i++ )
410  {
411  EDA_ITEM::IterateForward( m_sheetPaths[ i ].LastDrawList(),
412  inspector, nullptr, SCH_COLLECTOR::AllItems );
413  }
414 
415  return item;
416 }
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:77
static const KICAD_T AllItems[]
A scan list for all schematic items.
DELETED_SCH_ITEM g_DeletedSchItem
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
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:154
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...

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

Referenced by GetItem(), GetText(), SCH_EDIT_FRAME::OnFindReplace(), SCH_EDIT_FRAME::OnFindSchematicItem(), operator[](), ReplaceItem(), and SCH_EDIT_FRAME::updateFindReplaceView().

◆ GetItem() [2/2]

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 529 of file sch_collectors.cpp.

530 {
531  if( PassedEnd() )
532  return NULL;
533 
534  aData = m_data[ m_foundIndex ];
535  return GetItem( m_foundIndex );
536 }
std::vector< SCH_FIND_COLLECTOR_DATA > m_data
Data associated with each found item.
SCH_ITEM * GetItem(int ndx) const
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 ...

References GetItem(), m_data, m_foundIndex, and PassedEnd().

◆ GetLibHash()

int SCH_FIND_COLLECTOR::GetLibHash ( ) const
inline

Definition at line 296 of file sch_collectors.h.

296 { return m_lib_hash; }
int m_lib_hash
last known library change hash, used to detect library changes which should trigger cache obsolescenc...

References m_lib_hash.

Referenced by SCH_EDIT_FRAME::IsSearchCacheObsolete().

◆ GetRefPos()

const wxPoint& COLLECTOR::GetRefPos ( ) const
inlineinherited

Definition at line 231 of file collector.h.

231 { return m_RefPos; }
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
Definition: collector.h:68

References COLLECTOR::m_RefPos.

Referenced by PCB_EDIT_FRAME::OnRightClick().

◆ GetText()

wxString SCH_FIND_COLLECTOR::GetText ( EDA_UNITS_T  aUnits)

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 501 of file sch_collectors.cpp.

502 {
503  wxCHECK_MSG( (GetCount() != 0) && IsValidIndex( m_foundIndex ), wxEmptyString,
504  wxT( "Cannot get found item at invalid index." ) );
505 
507  EDA_ITEM* foundItem = GetItem( m_foundIndex );
508 
509  if( data.GetParent() )
510  {
511  return wxString::Format( _( "Match %i of %i: %s of %s in sheet %s" ),
512  m_foundIndex + 1,
513  GetCount(),
514  foundItem->GetSelectMenuText( aUnits ),
515  data.GetParent()->GetSelectMenuText( aUnits ),
516  data.GetSheetPath() );
517  }
518  else
519  {
520  return wxString::Format( _( "Match %i of %i: %s in sheet %s" ),
521  m_foundIndex + 1,
522  GetCount(),
523  foundItem->GetSelectMenuText( aUnits ),
524  data.GetSheetPath() );
525  }
526 }
bool IsValidIndex(int aIndex)
Function IsValidIndex tests if aIndex is with the limits of the list of collected items.
Definition: collector.h:105
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 GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
SCH_ITEM * GetItem(int ndx) const
wxString GetSheetPath() const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int m_foundIndex
The current found item list index.
virtual wxString GetSelectMenuText(EDA_UNITS_T aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
SCH_ITEM * GetParent() const

References Format(), COLLECTOR::GetCount(), GetItem(), SCH_FIND_COLLECTOR_DATA::GetParent(), EDA_ITEM::GetSelectMenuText(), SCH_FIND_COLLECTOR_DATA::GetSheetPath(), COLLECTOR::IsValidIndex(), m_data, and m_foundIndex.

Referenced by SCH_EDIT_FRAME::updateFindReplaceView().

◆ GetTime()

timestamp_t COLLECTOR::GetTime ( )
inlineinherited

Definition at line 225 of file collector.h.

226  {
227  return m_TimeAtCollection;
228  }
timestamp_t m_TimeAtCollection
The time at which the collection was made.
Definition: collector.h:74

References COLLECTOR::m_TimeAtCollection.

◆ HasItem()

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

198  {
199  for( size_t i = 0; i < m_List.size(); i++ )
200  {
201  if( m_List[i] == aItem )
202  return true;
203  }
204 
205  return false;
206  }
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

References i, and COLLECTOR::m_List.

Referenced by EditToolSelectionFilter().

◆ IncrementIndex()

void SCH_FIND_COLLECTOR::IncrementIndex ( )
inline

Definition at line 392 of file sch_collectors.h.

392 { m_foundIndex += 1; }
int m_foundIndex
The current found item list index.

References m_foundIndex.

Referenced by SCH_EDIT_FRAME::OnFindReplace().

◆ Inspect()

SEARCH_RESULT SCH_FIND_COLLECTOR::Inspect ( EDA_ITEM aItem,
void *  aTestData 
)
overridevirtual

Implements COLLECTOR.

Definition at line 555 of file sch_collectors.cpp.

556 {
557  wxPoint position;
558 
559  if( aItem->Matches( m_findReplaceData, m_currentSheetPath, &position ) )
560  {
561  if( aItem->Type() == LIB_PIN_T )
562  {
563  wxCHECK_MSG( aTestData && ( (EDA_ITEM*) aTestData )->Type() == SCH_COMPONENT_T,
564  SEARCH_CONTINUE, wxT( "Cannot inspect invalid data. Bad programmer!" ) );
565 
566  // Pin positions are relative to their parent component's position and
567  // orientation in the schematic. The pin's position must be converted
568  // schematic coordinates.
569  SCH_COMPONENT* component = (SCH_COMPONENT*) aTestData;
570  TRANSFORM transform = component->GetTransform();
571  position.y = -position.y;
572  position = transform.TransformCoordinate( position ) + component->GetPosition();
573  }
574 
575  Append( aItem );
576  m_data.push_back( SCH_FIND_COLLECTOR_DATA( position,
578  (SCH_ITEM*) aTestData ) );
579  }
580 
581  return SEARCH_CONTINUE;
582 }
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:420
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.
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:41
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:133
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
TRANSFORM & GetTransform() const
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:70
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:154
wxString PathHumanReadable() const
Function PathHumanReadable returns the sheet path in a human readable form, i.e.
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.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201

References COLLECTOR::Append(), SCH_COMPONENT::GetPosition(), SCH_COMPONENT::GetTransform(), LIB_PIN_T, m_currentSheetPath, m_data, m_findReplaceData, EDA_ITEM::Matches(), SCH_SHEET_PATH::PathHumanReadable(), SCH_COMPONENT_T, SEARCH_CONTINUE, TRANSFORM::TransformCoordinate(), and EDA_ITEM::Type().

◆ IsSearchRequired()

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 340 of file sch_collectors.h.

341  {
342  return m_findReplaceData.ChangesCompare( aFindReplaceData ) || m_forceSearch ||
343  (m_findReplaceData.IsWrapping() != aFindReplaceData.IsWrapping());
344  }
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.

References SCH_FIND_REPLACE_DATA::ChangesCompare(), SCH_FIND_REPLACE_DATA::IsWrapping(), m_findReplaceData, and m_forceSearch.

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

◆ IsSimilarPointAndTime()

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

246  {
247  const int distMax = 2; // adjust these here
248  const timestamp_t timeMax = 3; // seconds
249 
250  int dx = abs( aRefPos.x - m_RefPos.x );
251  int dy = abs( aRefPos.y - m_RefPos.y );
252 
253  if( dx <= distMax && dy <= distMax &&
254  GetNewTimeStamp() - m_TimeAtCollection <= timeMax )
255  return true;
256  else
257  return false;
258  }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53
#define abs(a)
Definition: auxiliary.h:84
timestamp_t GetNewTimeStamp()
Definition: common.cpp:216
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

References abs, GetNewTimeStamp(), COLLECTOR::m_RefPos, and COLLECTOR::m_TimeAtCollection.

◆ IsValidIndex()

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

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

References COLLECTOR::m_List.

Referenced by GetText(), and ReplaceItem().

◆ operator[]()

SCH_ITEM * SCH_FIND_COLLECTOR::operator[] ( int  ndx) const

Definition at line 419 of file sch_collectors.cpp.

420 {
421  return GetItem( ndx );
422 }
SCH_ITEM * GetItem(int ndx) const

References GetItem().

◆ PassedEnd()

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 425 of file sch_collectors.cpp.

426 {
427  bool retv = false;
428 
429  wxUint32 flags = m_findReplaceData.GetFlags();
430 
431  if( GetCount() == 0 )
432  return true;
433 
434  if( !(flags & FR_SEARCH_WRAP) || (flags & FR_SEARCH_REPLACE) )
435  {
436  if( flags & wxFR_DOWN )
437  {
438  if( m_foundIndex >= GetCount() )
439  retv = true;
440  }
441  else
442  {
443  if( m_foundIndex < 0 )
444  retv = true;
445  }
446  }
447 
448  return retv;
449 }
Wrap around the beginning or end of search list.
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
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.

References FR_SEARCH_REPLACE, FR_SEARCH_WRAP, COLLECTOR::GetCount(), m_findReplaceData, and m_foundIndex.

Referenced by GetItem(), SCH_EDIT_FRAME::OnFindReplace(), and ReplaceItem().

◆ Remove() [1/2]

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

144  {
145  m_List.erase( m_List.begin() + aIndex );
146  }
std::vector< EDA_ITEM * > m_List
A place to hold collected objects without taking ownership of their memory.
Definition: collector.h:65

References COLLECTOR::m_List.

Referenced by connectedItemFilter(), connectedTrackFilter(), EditToolSelectionFilter(), EDIT_TOOL::FootprintFilter(), SELECTION_TOOL::guessSelectionCandidates(), highlightNet(), EDIT_TOOL::PadFilter(), PCB_BASE_FRAME::PcbGeneralLocateAndDisplay(), GERBVIEW_SELECTION_TOOL::selectPoint(), and SELECTION_TOOL::selectPoint().

◆ Remove() [2/2]

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

154  {
155  for( size_t i = 0; i < m_List.size(); i++ )
156  {
157  if( m_List[i] == aItem )
158  {
159  m_List.erase( m_List.begin() + i);
160  return;
161  }
162  }
163  }
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

References i, and COLLECTOR::m_List.

◆ ReplaceItem()

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 539 of file sch_collectors.cpp.

540 {
541  if( PassedEnd() )
542  return false;
543 
544  wxCHECK_MSG( IsValidIndex( m_foundIndex ), false,
545  wxT( "Invalid replace list index in SCH_FIND_COLLECTOR." ) );
546 
547  EDA_ITEM* item = GetItem( m_foundIndex );
548 
549  bool replaced = item->Replace( m_findReplaceData, aSheetPath );
550 
551  return replaced;
552 }
bool IsValidIndex(int aIndex)
Function IsValidIndex tests if aIndex is with the limits of the list of collected items.
Definition: collector.h:105
bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
SCH_ITEM * GetItem(int ndx) const
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:154
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.

References GetItem(), COLLECTOR::IsValidIndex(), m_findReplaceData, m_foundIndex, PassedEnd(), and EDA_ITEM::Replace().

Referenced by SCH_EDIT_FRAME::OnFindReplace().

◆ SetBoundingBox()

void COLLECTOR::SetBoundingBox ( const EDA_RECT aRefBox)
inlineinherited

Definition at line 233 of file collector.h.

233 { 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

References COLLECTOR::m_RefBox.

◆ SetForceSearch()

void SCH_FIND_COLLECTOR::SetForceSearch ( bool  doSearch = true)
inline

Definition at line 294 of file sch_collectors.h.

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

References m_forceSearch.

Referenced by Collect(), SCH_EDIT_FRAME::IsSearchCacheObsolete(), SCH_EDIT_FRAME::OnFindReplace(), SCH_EDIT_FRAME::OnModify(), and SCH_FIND_COLLECTOR().

◆ SetFoundIndex()

void SCH_FIND_COLLECTOR::SetFoundIndex ( int  aIndex)
inline

Definition at line 300 of file sch_collectors.h.

301  {
302  m_foundIndex = ( (unsigned) aIndex < m_data.size() ) ? aIndex : 0;
303  }
std::vector< SCH_FIND_COLLECTOR_DATA > m_data
Data associated with each found item.
int m_foundIndex
The current found item list index.

References m_data, and m_foundIndex.

◆ SetLibHash()

void SCH_FIND_COLLECTOR::SetLibHash ( int  aHash)
inline

Definition at line 297 of file sch_collectors.h.

297 { m_lib_hash = aHash; }
int m_lib_hash
last known library change hash, used to detect library changes which should trigger cache obsolescenc...

References m_lib_hash.

Referenced by SCH_EDIT_FRAME::IsSearchCacheObsolete().

◆ SetRefPos()

void COLLECTOR::SetRefPos ( const wxPoint &  aRefPos)
inlineinherited

Definition at line 230 of file collector.h.

230 { m_RefPos = aRefPos; }
wxPoint m_RefPos
A point to test against, and that was used to make the collection.
Definition: collector.h:68

References COLLECTOR::m_RefPos.

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

◆ SetReplaceString()

void SCH_FIND_COLLECTOR::SetReplaceString ( const wxString &  aReplaceString)

Update the replace string without changing anything else.

Definition at line 585 of file sch_collectors.cpp.

586 {
587  m_findReplaceData.SetReplaceString( aReplaceString );
588 }
SCH_FIND_REPLACE_DATA m_findReplaceData
The criteria used to test for matching items.

References m_findReplaceData.

Referenced by SCH_EDIT_FRAME::OnFindReplace().

◆ SetScanTypes()

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

216  {
217  m_ScanTypes = scanTypes;
218  }
const KICAD_T * m_ScanTypes
Which object types to scan.
Definition: collector.h:62

References COLLECTOR::m_ScanTypes.

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

◆ SetTimeNow()

void COLLECTOR::SetTimeNow ( )
inlineinherited

Definition at line 220 of file collector.h.

221  {
223  }
timestamp_t GetNewTimeStamp()
Definition: common.cpp:216
timestamp_t m_TimeAtCollection
The time at which the collection was made.
Definition: collector.h:74

References GetNewTimeStamp(), and COLLECTOR::m_TimeAtCollection.

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

◆ UpdateIndex()

void SCH_FIND_COLLECTOR::UpdateIndex ( )

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

Definition at line 471 of file sch_collectors.cpp.

472 {
473  wxUint32 flags = m_findReplaceData.GetFlags();
474 
475  if( flags & wxFR_DOWN )
476  {
477  if( m_foundIndex < GetCount() )
478  m_foundIndex += 1;
479  if( (m_foundIndex >= GetCount()) && (flags & FR_SEARCH_WRAP) )
480  m_foundIndex = 0;
481  }
482  else
483  {
484  if( m_foundIndex >= 0 )
485  m_foundIndex -= 1;
486  if( (m_foundIndex < 0) && (flags & FR_SEARCH_WRAP) )
487  m_foundIndex = GetCount() - 1;
488  }
489 }
Wrap around the beginning or end of search list.
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
int m_foundIndex
The current found item list index.
SCH_FIND_REPLACE_DATA m_findReplaceData
The criteria used to test for matching items.

References FR_SEARCH_WRAP, COLLECTOR::GetCount(), m_findReplaceData, and m_foundIndex.

Referenced by SCH_EDIT_FRAME::OnFindSchematicItem().

Member Data Documentation

◆ m_currentSheetPath

SCH_SHEET_PATH* SCH_FIND_COLLECTOR::m_currentSheetPath
private

The path of the sheet currently being iterated over.

Definition at line 246 of file sch_collectors.h.

Referenced by Collect(), Inspect(), and SCH_FIND_COLLECTOR().

◆ m_data

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

Data associated with each found item.

Definition at line 240 of file sch_collectors.h.

Referenced by Collect(), Empty(), GetFindData(), GetItem(), GetText(), Inspect(), and SetFoundIndex().

◆ m_findReplaceData

SCH_FIND_REPLACE_DATA SCH_FIND_COLLECTOR::m_findReplaceData
private

The criteria used to test for matching items.

Definition at line 243 of file sch_collectors.h.

Referenced by Collect(), Inspect(), IsSearchRequired(), PassedEnd(), ReplaceItem(), SetReplaceString(), and UpdateIndex().

◆ m_forceSearch

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 256 of file sch_collectors.h.

Referenced by Collect(), IsSearchRequired(), and SetForceSearch().

◆ m_foundIndex

int SCH_FIND_COLLECTOR::m_foundIndex
private

The current found item list index.

Definition at line 252 of file sch_collectors.h.

Referenced by Collect(), Empty(), GetFoundIndex(), GetItem(), GetText(), IncrementIndex(), PassedEnd(), ReplaceItem(), SCH_FIND_COLLECTOR(), SetFoundIndex(), and UpdateIndex().

◆ m_inspector

◆ m_lib_hash

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 260 of file sch_collectors.h.

Referenced by GetLibHash(), SCH_FIND_COLLECTOR(), and SetLibHash().

◆ m_List

◆ m_RefBox

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(), and COLLECTOR::SetBoundingBox().

◆ m_RefPos

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(), GENERAL_COLLECTOR::Inspect(), COLLECTOR::IsSimilarPointAndTime(), and COLLECTOR::SetRefPos().

◆ m_ScanTypes

const KICAD_T* COLLECTOR::m_ScanTypes
protectedinherited

◆ m_sheetPaths

SCH_SHEET_PATHS SCH_FIND_COLLECTOR::m_sheetPaths
private

The paths of the all the sheets in the collector.

Definition at line 249 of file sch_collectors.h.

Referenced by Collect(), and GetItem().

◆ m_TimeAtCollection

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(), COLLECTOR::IsSimilarPointAndTime(), and COLLECTOR::SetTimeNow().


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