KiCad PCB EDA Suite
SCH_REFERENCE_LIST Class Reference

SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierarchy, a component can be used more than once and its reference designator is dependent on the sheet path for the same component. More...

#include <sch_reference_list.h>

Public Member Functions

 SCH_REFERENCE_LIST ()
 Constructor. More...
 
SCH_REFERENCEoperator[] (int aIndex)
 
void Clear ()
 
unsigned GetCount () const
 Function GetCount. More...
 
SCH_REFERENCEGetItem (int aIdx)
 Function GetItem. More...
 
void AddItem (SCH_REFERENCE &aItem)
 Function AddItem adds a SCH_REFERENCE object to the list of references. More...
 
void RemoveItem (unsigned int aIndex)
 Function RemoveItem removes an item from the list of references. More...
 
void SplitReferences ()
 Function SplitReferences attempts to split all reference designators into a name (U) and number (1). More...
 
void UpdateAnnotation ()
 function UpdateAnnotation Updates the reference components for the schematic project (or the current sheet) Note: this function does not calculate the reference numbers stored in m_NumRef So, it must be called after calculation of new reference numbers More...
 
void Annotate (bool aUseSheetNum, int aSheetIntervalId, int aStartNumber, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap)
 Function Annotate set the reference designators in the list that have not been annotated. More...
 
int CheckAnnotation (REPORTER &aReporter)
 Function CheckAnnotation check for annotations errors. More...
 
void SortByXCoordinate ()
 Function sortByXCoordinate sorts the list of references by X position. More...
 
void SortByYCoordinate ()
 Function sortByYCoordinate sorts the list of references by Y position. More...
 
void SortByTimeStamp ()
 Function SortComponentsByTimeStamp sort the flat list by Time Stamp (sheet path + timestamp). More...
 
void SortByRefAndValue ()
 Function SortByRefAndValue sorts the list of references by value. More...
 
void SortByReferenceOnly ()
 Function SortByReferenceOnly sorts the list of references by reference. More...
 
int FindRef (const wxString &aPath) const
 searches the list for a component with a given reference. More...
 
int FindUnit (size_t aIndex, int aUnit)
 searches the sorted list of components for a another component with the same reference and a given part unit. More...
 
int FindRefByPath (const wxString &aPath) const
 searches the list for a component with the given KIID path More...
 
void GetRefsInUse (int aIndex, std::vector< int > &aIdList, int aMinRefId)
 Function GetRefsInUse adds all the reference designator numbers greater than aMinRefId to aIdList skipping the reference at aIndex. More...
 
int GetLastReference (int aIndex, int aMinValue)
 Function GetLastReference returns the last used (greatest) reference number in the reference list for the prefix reference given by aIndex. More...
 

Static Public Member Functions

static wxString Shorthand (std::vector< SCH_REFERENCE > aList)
 Function Shorthand Returns a shorthand string representing all the references in the list. More...
 

Private Member Functions

int CreateFirstFreeRefId (std::vector< int > &aIdList, int aFirstValue)
 Function CreateFirstFreeRefId searches for the first free reference number in aListId of reference numbers in use. More...
 

Static Private Member Functions

static bool sortByRefAndValue (const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
 
static bool sortByXPosition (const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
 
static bool sortByYPosition (const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
 
static bool sortByTimeStamp (const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
 
static bool sortByReferenceOnly (const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
 

Private Attributes

std::vector< SCH_REFERENCEflatList
 

Friends

class BACK_ANNOTATION
 
class BACK_ANNOTATE
 

Detailed Description

SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierarchy, a component can be used more than once and its reference designator is dependent on the sheet path for the same component.

This flattened list is used for netlist generation, BOM generation, and schematic annotation.

Definition at line 215 of file sch_reference_list.h.

Constructor & Destructor Documentation

◆ SCH_REFERENCE_LIST()

SCH_REFERENCE_LIST::SCH_REFERENCE_LIST ( )
inline

Constructor.

Definition at line 223 of file sch_reference_list.h.

224  {
225  }

Member Function Documentation

◆ AddItem()

void SCH_REFERENCE_LIST::AddItem ( SCH_REFERENCE aItem)
inline

Function AddItem adds a SCH_REFERENCE object to the list of references.

Parameters
aItem- a SCH_REFERENCE item to add

Definition at line 260 of file sch_reference_list.h.

261  {
262  flatList.push_back( aItem );
263  }
std::vector< SCH_REFERENCE > flatList

References flatList.

Referenced by SCH_SHEET_LIST::AnnotatePowerSymbols(), and SCH_SHEET_PATH::GetComponents().

◆ Annotate()

void SCH_REFERENCE_LIST::Annotate ( bool  aUseSheetNum,
int  aSheetIntervalId,
int  aStartNumber,
SCH_MULTI_UNIT_REFERENCE_MAP  aLockedUnitMap 
)

Function Annotate set the reference designators in the list that have not been annotated.

Parameters
aUseSheetNumSet to true to start annotation for each sheet at the sheet number times aSheetIntervalId. Otherwise annotate incrementally.
aSheetIntervalIdThe per sheet reference designator multiplier.
aStartNumberThe number to start with if NOT numbering based on sheet number.
aLockedUnitMapA SCH_MULTI_UNIT_REFERENCE_MAP of reference designator wxStrings to SCH_REFERENCE_LISTs. May be an empty map. If not empty, any multi-unit parts found in this map will be annotated as a group rather than individually.

If a the sheet number is 2 and aSheetIntervalId is 100, then the first reference designator would be 201 and the last reference designator would be 299 when no overlap occurs with sheet number 3. If there are 150 items in sheet number 2, then items are referenced U201 to U351, and items in sheet 3 start from U352

Definition at line 284 of file component_references_lister.cpp.

286 {
287  if ( flatList.size() == 0 )
288  return;
289 
290  int LastReferenceNumber = 0;
291  int NumberOfUnits, Unit;
292 
293  /* calculate index of the first component with the same reference prefix
294  * than the current component. All components having the same reference
295  * prefix will receive a reference number with consecutive values:
296  * IC .. will be set to IC4, IC4, IC5 ...
297  */
298  unsigned first = 0;
299 
300  // calculate the last used number for this reference prefix:
301  int minRefId;
302 
303  // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
304  if( aUseSheetNum )
305  minRefId = flatList[first].m_SheetNum * aSheetIntervalId + 1;
306  else
307  minRefId = aStartNumber + 1;
308 
309  // For multi units components, when "keep order of multi unit" option is selected,
310  // store the list of already used full references.
311  // The algorithm try to allocate the new reference to components having the same
312  // old reference.
313  // This algo works fine as long as the previous annotation has no duplicates.
314  // But when a hierarchy is reannotated with this option, the previous anotation can
315  // have duplicate references, and obviously we must fix these duplicate.
316  // therefore do not try to allocate a full reference more than once when trying
317  // to keep this order of multi units.
318  // inUseRefs keep trace of previously allocated references
319  std::unordered_set<wxString> inUseRefs;
320 
321  // This is the list of all Id already in use for a given reference prefix.
322  // Will be refilled for each new reference prefix.
323  std::vector<int>idList;
324  GetRefsInUse( first, idList, minRefId );
325 
326  for( unsigned ii = 0; ii < flatList.size(); ii++ )
327  {
328  auto& ref_unit = flatList[ii];
329 
330  if( ref_unit.m_Flag )
331  continue;
332 
333  // Check whether this component is in aLockedUnitMap.
334  SCH_REFERENCE_LIST* lockedList = NULL;
335  for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : aLockedUnitMap )
336  {
337  unsigned n_refs = pair.second.GetCount();
338 
339  for( unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI )
340  {
341  SCH_REFERENCE &thisRef = pair.second[thisRefI];
342 
343  if( thisRef.IsSameInstance( ref_unit ) )
344  {
345  lockedList = &pair.second;
346  break;
347  }
348  }
349  if( lockedList != NULL ) break;
350  }
351 
352  if( ( flatList[first].CompareRef( ref_unit ) != 0 )
353  || ( aUseSheetNum && ( flatList[first].m_SheetNum != ref_unit.m_SheetNum ) ) )
354  {
355  // New reference found: we need a new ref number for this reference
356  first = ii;
357 
358  // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
359  if( aUseSheetNum )
360  minRefId = ref_unit.m_SheetNum * aSheetIntervalId + 1;
361  else
362  minRefId = aStartNumber + 1;
363 
364  GetRefsInUse( first, idList, minRefId );
365  }
366 
367  // Annotation of one part per package components (trivial case).
368  if( ref_unit.GetLibPart()->GetUnitCount() <= 1 )
369  {
370  if( ref_unit.m_IsNew )
371  {
372  LastReferenceNumber = CreateFirstFreeRefId( idList, minRefId );
373  ref_unit.m_NumRef = LastReferenceNumber;
374  }
375 
376  ref_unit.m_Unit = 1;
377  ref_unit.m_Flag = 1;
378  ref_unit.m_IsNew = false;
379  continue;
380  }
381 
382  // Annotation of multi-unit parts ( n units per part ) (complex case)
383  NumberOfUnits = ref_unit.GetLibPart()->GetUnitCount();
384 
385  if( ref_unit.m_IsNew )
386  {
387  LastReferenceNumber = CreateFirstFreeRefId( idList, minRefId );
388  ref_unit.m_NumRef = LastReferenceNumber;
389 
390  if( !ref_unit.IsUnitsLocked() )
391  ref_unit.m_Unit = 1;
392 
393  ref_unit.m_Flag = 1;
394  }
395 
396  // If this component is in aLockedUnitMap, copy the annotation to all
397  // components that are not it
398  if( lockedList != NULL )
399  {
400  unsigned n_refs = lockedList->GetCount();
401 
402  for( unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI )
403  {
404  SCH_REFERENCE &thisRef = (*lockedList)[thisRefI];
405 
406  if( thisRef.IsSameInstance( ref_unit ) )
407  {
408  // This is the component we're currently annotating. Hold the unit!
409  ref_unit.m_Unit = thisRef.m_Unit;
410  // lock this new full reference
411  inUseRefs.insert( buildFullReference( ref_unit ) );
412  }
413 
414  if( thisRef.CompareValue( ref_unit ) != 0 )
415  continue;
416 
417  if( thisRef.CompareLibName( ref_unit ) != 0 )
418  continue;
419 
420  // Find the matching component
421  for( unsigned jj = ii + 1; jj < flatList.size(); jj++ )
422  {
423  if( ! thisRef.IsSameInstance( flatList[jj] ) )
424  continue;
425 
426  wxString ref_candidate = buildFullReference( ref_unit, thisRef.m_Unit );
427 
428  // propagate the new reference and unit selection to the "old" component,
429  // if this new full reference is not already used (can happens when initial
430  // multiunits components have duplicate references)
431  if( inUseRefs.find( ref_candidate ) == inUseRefs.end() )
432  {
433  flatList[jj].m_NumRef = ref_unit.m_NumRef;
434  flatList[jj].m_Unit = thisRef.m_Unit;
435  flatList[jj].m_IsNew = false;
436  flatList[jj].m_Flag = 1;
437  // lock this new full reference
438  inUseRefs.insert( ref_candidate );
439  break;
440  }
441  }
442  }
443  }
444  else
445  {
446  /* search for others units of this component.
447  * we search for others parts that have the same value and the same
448  * reference prefix (ref without ref number)
449  */
450  for( Unit = 1; Unit <= NumberOfUnits; Unit++ )
451  {
452  if( ref_unit.m_Unit == Unit )
453  continue;
454 
455  int found = FindUnit( ii, Unit );
456 
457  if( found >= 0 )
458  continue; // this unit exists for this reference (unit already annotated)
459 
460  // Search a component to annotate ( same prefix, same value, not annotated)
461  for( unsigned jj = ii + 1; jj < flatList.size(); jj++ )
462  {
463  auto& cmp_unit = flatList[jj];
464 
465  if( cmp_unit.m_Flag ) // already tested
466  continue;
467 
468  if( cmp_unit.CompareRef( ref_unit ) != 0 )
469  continue;
470 
471  if( cmp_unit.CompareValue( ref_unit ) != 0 )
472  continue;
473 
474  if( cmp_unit.CompareLibName( ref_unit ) != 0 )
475  continue;
476 
477  if( aUseSheetNum &&
478  cmp_unit.GetSheetPath().Cmp( ref_unit.GetSheetPath() ) != 0 )
479  continue;
480 
481  if( !cmp_unit.m_IsNew )
482  continue;
483 
484  // Component without reference number found, annotate it if possible
485  if( !cmp_unit.IsUnitsLocked()
486  || ( cmp_unit.m_Unit == Unit ) )
487  {
488  cmp_unit.m_NumRef = ref_unit.m_NumRef;
489  cmp_unit.m_Unit = Unit;
490  cmp_unit.m_Flag = 1;
491  cmp_unit.m_IsNew = false;
492  break;
493  }
494  }
495  }
496  }
497  }
498 }
SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierarchy,...
void GetRefsInUse(int aIndex, std::vector< int > &aIdList, int aMinRefId)
Function GetRefsInUse adds all the reference designator numbers greater than aMinRefId to aIdList ski...
int m_Unit
The unit number for components with multiple parts per package.
#define NULL
int CompareValue(const SCH_REFERENCE &item) const
wxString buildFullReference(const SCH_REFERENCE &aItem, int aUnitNumber=-1)
int CompareLibName(const SCH_REFERENCE &item) const
int FindUnit(size_t aIndex, int aUnit)
searches the sorted list of components for a another component with the same reference and a given pa...
unsigned GetCount() const
Function GetCount.
bool IsSameInstance(const SCH_REFERENCE &other) const
Function IsSameInstance returns whether this reference refers to the same component instance (compone...
int CreateFirstFreeRefId(std::vector< int > &aIdList, int aFirstValue)
Function CreateFirstFreeRefId searches for the first free reference number in aListId of reference nu...
std::vector< SCH_REFERENCE > flatList
SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.

References buildFullReference(), SCH_REFERENCE::CompareLibName(), SCH_REFERENCE::CompareValue(), CreateFirstFreeRefId(), FindUnit(), flatList, GetCount(), GetRefsInUse(), SCH_REFERENCE::IsSameInstance(), SCH_REFERENCE::m_Unit, and NULL.

Referenced by SCH_EDIT_FRAME::AnnotateComponents(), and SCH_SHEET_LIST::AnnotatePowerSymbols().

◆ CheckAnnotation()

int SCH_REFERENCE_LIST::CheckAnnotation ( REPORTER aReporter)

Function CheckAnnotation check for annotations errors.

The following annotation error conditions are tested:

  • Components not annotated.
  • Components having the same reference designator (duplicates).
  • Components with multiple parts per package having different reference designators.
  • Components with multiple parts per package with invalid part count.
Parameters
aReporterA sink for error messages. Use NULL_REPORTER if you don't need errors.
Returns
The number of errors found.

Definition at line 500 of file component_references_lister.cpp.

501 {
502  int error = 0;
503  wxString tmp;
504  wxString msg;
505 
507 
508  // Spiit reference designators into name (prefix) and number: IC1 becomes IC, and 1.
509  SplitReferences();
510 
511  // count not yet annotated items or annotation error.
512  for( unsigned ii = 0; ii < flatList.size(); ii++ )
513  {
514  msg.Empty();
515  tmp.Empty();
516 
517  if( flatList[ii].m_IsNew ) // Not yet annotated
518  {
519  if( flatList[ii].m_NumRef >= 0 )
520  tmp << flatList[ii].m_NumRef;
521  else
522  tmp = wxT( "?" );
523 
524 
525  if( ( flatList[ii].m_Unit > 0 )
526  && ( flatList[ii].m_Unit < 0x7FFFFFFF ) )
527  {
528  msg.Printf( _( "Item not annotated: %s%s (unit %d)\n" ),
529  flatList[ii].GetRef(),
530  tmp,
531  flatList[ii].m_Unit );
532  }
533  else
534  {
535  msg.Printf( _( "Item not annotated: %s%s\n" ),
536  flatList[ii].GetRef(),
537  tmp );
538  }
539 
540  aReporter.Report( msg, RPT_SEVERITY_WARNING );
541  error++;
542  break;
543  }
544 
545  // Error if unit number selected does not exist ( greater than the number of
546  // parts in the component ). This can happen if a component has changed in a
547  // library after a previous annotation.
548  if( std::max( flatList[ii].GetLibPart()->GetUnitCount(), 1 )
549  < flatList[ii].m_Unit )
550  {
551  if( flatList[ii].m_NumRef >= 0 )
552  tmp << flatList[ii].m_NumRef;
553  else
554  tmp = wxT( "?" );
555 
556  msg.Printf( _( "Error: symbol %s%s unit %d and symbol has only %d units defined\n" ),
557  flatList[ii].GetRef(),
558  tmp,
559  flatList[ii].m_Unit,
560  flatList[ii].GetLibPart()->GetUnitCount() );
561 
562  aReporter.Report( msg, RPT_SEVERITY_ERROR );
563  error++;
564  break;
565  }
566  }
567 
568  if( error )
569  return error;
570 
571  // count the duplicated elements (if all are annotated)
572  int imax = flatList.size() - 1;
573 
574  for( int ii = 0; ii < imax; ii++ )
575  {
576  msg.Empty();
577  tmp.Empty();
578 
579  if( ( flatList[ii].CompareRef( flatList[ii + 1] ) != 0 )
580  || ( flatList[ii].m_NumRef != flatList[ii + 1].m_NumRef ) )
581  continue;
582 
583  // Same reference found. If same unit, error!
584  if( flatList[ii].m_Unit == flatList[ii + 1].m_Unit )
585  {
586  if( flatList[ii].m_NumRef >= 0 )
587  tmp << flatList[ii].m_NumRef;
588  else
589  tmp = wxT( "?" );
590 
591  if( ( flatList[ii].m_Unit > 0 )
592  && ( flatList[ii].m_Unit < 0x7FFFFFFF ) )
593  {
594  msg.Printf( _( "Multiple item %s%s (unit %d)\n" ),
595  flatList[ii].GetRef(),
596  tmp,
597  flatList[ii].m_Unit );
598  }
599  else
600  {
601  msg.Printf( _( "Multiple item %s%s\n" ),
602  flatList[ii].GetRef(),
603  tmp );
604  }
605 
606  aReporter.Report( msg, RPT_SEVERITY_ERROR );
607  error++;
608  continue;
609  }
610 
611  /* Test error if units are different but number of parts per package
612  * too high (ex U3 ( 1 part) and we find U3B this is an error) */
613  if( flatList[ii].GetLibPart()->GetUnitCount()
614  != flatList[ ii + 1].GetLibPart()->GetUnitCount() )
615  {
616  if( flatList[ii].m_NumRef >= 0 )
617  tmp << flatList[ii].m_NumRef;
618  else
619  tmp = wxT( "?" );
620 
621  if( ( flatList[ii].m_Unit > 0 )
622  && ( flatList[ii].m_Unit < 0x7FFFFFFF ) )
623  {
624  msg.Printf( _( "Multiple item %s%s (unit %d)\n" ),
625  flatList[ii].GetRef(),
626  tmp,
627  flatList[ii].m_Unit );
628  }
629  else
630  {
631  msg.Printf( _( "Multiple item %s%s\n" ),
632  flatList[ii].GetRef(),
633  tmp );
634  }
635 
636  aReporter.Report( msg, RPT_SEVERITY_ERROR );
637  error++;
638  }
639 
640  // Error if values are different between units, for the same reference
641  int next = ii + 1;
642 
643  if( flatList[ii].CompareValue( flatList[next] ) != 0 )
644  {
645  msg.Printf( _( "Different values for %s%d%s (%s) and %s%d%s (%s)" ),
646  flatList[ii].GetRef(),
647  flatList[ii].m_NumRef,
648  LIB_PART::SubReference( flatList[ii].m_Unit ),
649  flatList[ii].m_Value,
650  flatList[next].GetRef(),
651  flatList[next].m_NumRef,
653  flatList[next].m_Value );
654 
655  aReporter.Report( msg, RPT_SEVERITY_ERROR );
656  error++;
657  }
658  }
659 
660  return error;
661 }
CITER next(CITER it)
Definition: ptree.cpp:126
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
void SortByRefAndValue()
Function SortByRefAndValue sorts the list of references by value.
void SplitReferences()
Function SplitReferences attempts to split all reference designators into a name (U) and number (1).
#define _(s)
Definition: 3d_actions.cpp:33
static wxString SubReference(int aUnit, bool aAddSeparator=true)
std::vector< SCH_REFERENCE > flatList

References _, flatList, next(), REPORTER::Report(), RPT_SEVERITY_ERROR, RPT_SEVERITY_WARNING, SortByRefAndValue(), SplitReferences(), and LIB_PART::SubReference().

Referenced by SCH_EDIT_FRAME::CheckAnnotate().

◆ Clear()

void SCH_REFERENCE_LIST::Clear ( )
inline

Definition at line 232 of file sch_reference_list.h.

233  {
234  flatList.clear();
235  }
std::vector< SCH_REFERENCE > flatList

References flatList.

Referenced by SCH_EDITOR_CONTROL::doCopy().

◆ CreateFirstFreeRefId()

int SCH_REFERENCE_LIST::CreateFirstFreeRefId ( std::vector< int > &  aIdList,
int  aFirstValue 
)
private

Function CreateFirstFreeRefId searches for the first free reference number in aListId of reference numbers in use.

This function just searches for a hole in a list of incremented numbers, this list must be sorted by increasing values and each value can be stored only once. The new value is added to the list.

See also
BuildRefIdInUseList to prepare this list
Parameters
aIdListThe buffer that contains the reference numbers in use.
aFirstValueThe first expected free value
Returns
The first free (not yet used) value.

Definition at line 234 of file component_references_lister.cpp.

235 {
236  int expectedId = aFirstValue;
237 
238  // We search for expected Id a value >= aFirstValue.
239  // Skip existing Id < aFirstValue
240  unsigned ii = 0;
241 
242  for( ; ii < aIdList.size(); ii++ )
243  {
244  if( expectedId <= aIdList[ii] )
245  break;
246  }
247 
248  // Ids are sorted by increasing value, from aFirstValue
249  // So we search from aFirstValue the first not used value, i.e. the first hole in list.
250  for( ; ii < aIdList.size(); ii++ )
251  {
252  if( expectedId != aIdList[ii] ) // This id is not yet used.
253  {
254  // Insert this free Id, in order to keep list sorted
255  aIdList.insert( aIdList.begin() + ii, expectedId );
256  return expectedId;
257  }
258 
259  expectedId++;
260  }
261 
262  // All existing Id are tested, and all values are found in use.
263  // So Create a new one.
264  aIdList.push_back( expectedId );
265  return expectedId;
266 }

Referenced by Annotate().

◆ FindRef()

int SCH_REFERENCE_LIST::FindRef ( const wxString &  aPath) const

searches the list for a component with a given reference.

Parameters
aPath
Returns

Definition at line 181 of file component_references_lister.cpp.

182 {
183  for( size_t i = 0; i < flatList.size(); ++i )
184  {
185  if( flatList[i].GetRef() == aRef )
186  return i;
187  }
188 
189  return -1;
190 }
std::vector< SCH_REFERENCE > flatList

References flatList.

Referenced by BACK_ANNOTATE::getChangeList().

◆ FindRefByPath()

int SCH_REFERENCE_LIST::FindRefByPath ( const wxString &  aPath) const

searches the list for a component with the given KIID path

Parameters
aPathpath to search
Returns
index in aComponentsList if found or -1 if not found

Definition at line 169 of file component_references_lister.cpp.

170 {
171  for( size_t i = 0; i < flatList.size(); ++i )
172  {
173  if( flatList[i].GetPath() == aPath )
174  return i;
175  }
176 
177  return -1;
178 }
std::vector< SCH_REFERENCE > flatList

References flatList.

Referenced by BACK_ANNOTATE::getChangeList(), and SCH_EDITOR_CONTROL::updatePastedInstances().

◆ FindUnit()

int SCH_REFERENCE_LIST::FindUnit ( size_t  aIndex,
int  aUnit 
)

searches the sorted list of components for a another component with the same reference and a given part unit.

Use this method to manage components with multiple parts per package.

Parameters
aIndex= index in aComponentsList for of given SCH_REFERENCE item to test.
aUnit= the given unit number to search
Returns
index in aComponentsList if found or -1 if not found

Definition at line 147 of file component_references_lister.cpp.

148 {
149  int NumRef;
150 
151  NumRef = flatList[aIndex].m_NumRef;
152 
153  for( size_t ii = 0; ii < flatList.size(); ii++ )
154  {
155  if( ( aIndex == ii )
156  || ( flatList[ii].m_IsNew )
157  || ( flatList[ii].m_NumRef != NumRef )
158  || ( flatList[aIndex].CompareRef( flatList[ii] ) != 0 ) )
159  continue;
160 
161  if( flatList[ii].m_Unit == aUnit )
162  return (int) ii;
163  }
164 
165  return -1;
166 }
std::vector< SCH_REFERENCE > flatList

References flatList.

Referenced by Annotate().

◆ GetCount()

◆ GetItem()

SCH_REFERENCE& SCH_REFERENCE_LIST::GetItem ( int  aIdx)
inline

Function GetItem.

Returns
the aIdx item

Definition at line 250 of file sch_reference_list.h.

251  {
252  return flatList[aIdx];
253  }
std::vector< SCH_REFERENCE > flatList

References flatList.

Referenced by ERC_TESTER::TestMultiunitFootprints().

◆ GetLastReference()

int SCH_REFERENCE_LIST::GetLastReference ( int  aIndex,
int  aMinValue 
)

Function GetLastReference returns the last used (greatest) reference number in the reference list for the prefix reference given by aIndex.

The component list must be sorted.

Parameters
aIndexThe index of the reference item used for the search pattern.
aMinValueThe minimum value for the current search.

Definition at line 215 of file component_references_lister.cpp.

216 {
217  int lastNumber = aMinValue;
218 
219  for( SCH_REFERENCE& ref : flatList )
220  {
221  // search only for the current reference prefix:
222  if( flatList[aIndex].CompareRef( ref ) != 0 )
223  continue;
224 
225  // update max value for the current reference prefix
226  if( lastNumber < ref.m_NumRef )
227  lastNumber = ref.m_NumRef;
228  }
229 
230  return lastNumber;
231 }
std::vector< SCH_REFERENCE > flatList
SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.

References flatList.

◆ GetRefsInUse()

void SCH_REFERENCE_LIST::GetRefsInUse ( int  aIndex,
std::vector< int > &  aIdList,
int  aMinRefId 
)

Function GetRefsInUse adds all the reference designator numbers greater than aMinRefId to aIdList skipping the reference at aIndex.

Parameters
aIndex= the current component index to use for reference prefix filtering.
aIdList= the buffer to fill
aMinRefId= the min id value to store. all values < aMinRefId are ignored

Definition at line 193 of file component_references_lister.cpp.

194 {
195  aIdList.clear();
196 
197  for( SCH_REFERENCE& ref : flatList )
198  {
199  if( flatList[aIndex].CompareRef( ref ) == 0 && ref.m_NumRef >= aMinRefId )
200  aIdList.push_back( ref.m_NumRef );
201  }
202 
203  sort( aIdList.begin(), aIdList.end() );
204 
205  // Ensure each reference number appears only once. If there are components with
206  // multiple parts per package the same number will be stored for each part.
207  std::vector< int >::iterator it = unique( aIdList.begin(), aIdList.end() );
208 
209  // Using the C++ unique algorithm only moves the duplicate entries to the end of
210  // of the array. This removes the duplicate entries from the array.
211  aIdList.resize( it - aIdList.begin() );
212 }
std::vector< SCH_REFERENCE > flatList
SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.

References flatList.

Referenced by Annotate().

◆ operator[]()

SCH_REFERENCE& SCH_REFERENCE_LIST::operator[] ( int  aIndex)
inline

Definition at line 227 of file sch_reference_list.h.

228  {
229  return flatList[ aIndex ];
230  }
std::vector< SCH_REFERENCE > flatList

References flatList.

◆ RemoveItem()

void SCH_REFERENCE_LIST::RemoveItem ( unsigned int  aIndex)

Function RemoveItem removes an item from the list of references.

Parameters
aIndexis the index of the item to be removed.

Definition at line 46 of file component_references_lister.cpp.

47 {
48  if( aIndex < flatList.size() )
49  flatList.erase( flatList.begin() + aIndex );
50 }
std::vector< SCH_REFERENCE > flatList

References flatList.

◆ Shorthand()

wxString SCH_REFERENCE_LIST::Shorthand ( std::vector< SCH_REFERENCE aList)
static

Function Shorthand Returns a shorthand string representing all the references in the list.

For instance, "R1, R2, R4 - R7, U1"

Parameters
aList

Definition at line 761 of file component_references_lister.cpp.

762 {
763  wxString retVal;
764  size_t i = 0;
765 
766  while( i < aList.size() )
767  {
768  wxString ref = aList[ i ].GetRef();
769  int numRef = aList[ i ].m_NumRef;
770 
771  size_t range = 1;
772 
773  while( i + range < aList.size()
774  && aList[ i + range ].GetRef() == ref
775  && aList[ i + range ].m_NumRef == int( numRef + range ) )
776  {
777  range++;
778  }
779 
780  if( !retVal.IsEmpty() )
781  retVal << wxT( ", " );
782 
783  if( range == 1 )
784  {
785  retVal << ref << aList[ i ].GetRefNumber();
786  }
787  else if( range == 2 )
788  {
789  retVal << ref << aList[ i ].GetRefNumber();
790  retVal << wxT( ", " );
791  retVal << ref << aList[ i + 1 ].GetRefNumber();
792  }
793  else
794  {
795  retVal << ref << aList[ i ].GetRefNumber();
796  retVal << wxT( "-" );
797  retVal << ref << aList[ i + ( range - 1 ) ].GetRefNumber();
798  }
799 
800  i+= range;
801  }
802 
803  return retVal;
804 }

Referenced by FIELDS_EDITOR_GRID_DATA_MODEL::GetValue().

◆ SortByRefAndValue()

void SCH_REFERENCE_LIST::SortByRefAndValue ( )
inline

Function SortByRefAndValue sorts the list of references by value.

Components are sorted in the following order:

  • Numeric value of reference designator.
  • Value of component.
  • Unit number when component has multiple parts.
  • Sheet number.
  • X coordinate position.
  • Y coordinate position.

Definition at line 413 of file sch_reference_list.h.

414  {
415  sort( flatList.begin(), flatList.end(), sortByRefAndValue );
416  }
static bool sortByRefAndValue(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
std::vector< SCH_REFERENCE > flatList

References flatList, and sortByRefAndValue().

Referenced by CheckAnnotation().

◆ sortByRefAndValue()

bool SCH_REFERENCE_LIST::sortByRefAndValue ( const SCH_REFERENCE item1,
const SCH_REFERENCE item2 
)
staticprivate

Definition at line 93 of file component_references_lister.cpp.

95 {
96  int ii = item1.CompareRef( item2 );
97 
98  if( ii == 0 )
99  ii = item1.CompareValue( item2 );
100 
101  if( ii == 0 )
102  ii = item1.m_Unit - item2.m_Unit;
103 
104  if( ii == 0 )
105  ii = item1.m_SheetNum - item2.m_SheetNum;
106 
107  if( ii == 0 )
108  ii = item1.m_CmpPos.x - item2.m_CmpPos.x;
109 
110  if( ii == 0 )
111  ii = item1.m_CmpPos.y - item2.m_CmpPos.y;
112 
113  if( ii == 0 )
114  return item1.m_Uuid < item2.m_Uuid; // ensure a deterministic sort
115  else
116  return ii < 0;
117 }
wxPoint m_CmpPos
The physical position of the component in schematic used to annotate by X or Y position.
KIID m_Uuid
UUID of the component.
int m_SheetNum
The sheet number for the reference.
int m_Unit
The unit number for components with multiple parts per package.
int CompareValue(const SCH_REFERENCE &item) const
int CompareRef(const SCH_REFERENCE &item) const

References SCH_REFERENCE::CompareRef(), SCH_REFERENCE::CompareValue(), SCH_REFERENCE::m_CmpPos, SCH_REFERENCE::m_SheetNum, SCH_REFERENCE::m_Unit, SCH_REFERENCE::m_Uuid, wxPoint::x, and wxPoint::y.

Referenced by SortByRefAndValue().

◆ SortByReferenceOnly()

void SCH_REFERENCE_LIST::SortByReferenceOnly ( )
inline

Function SortByReferenceOnly sorts the list of references by reference.

Components are sorted in the following order:

  • Numeric value of reference designator.
  • Unit number when component has multiple parts.

Definition at line 429 of file sch_reference_list.h.

430  {
431  sort( flatList.begin(), flatList.end(), sortByReferenceOnly );
432  }
static bool sortByReferenceOnly(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
std::vector< SCH_REFERENCE > flatList

References flatList, and sortByReferenceOnly().

Referenced by SCH_SEXPR_PLUGIN::Format().

◆ sortByReferenceOnly()

bool SCH_REFERENCE_LIST::sortByReferenceOnly ( const SCH_REFERENCE item1,
const SCH_REFERENCE item2 
)
staticprivate

Definition at line 120 of file component_references_lister.cpp.

122 {
123  int ii = UTIL::RefDesStringCompare( item1.GetRef(), item2.GetRef() );
124 
125  if( ii == 0 )
126  ii = item1.m_Unit - item2.m_Unit;
127 
128  if( ii == 0 )
129  return item1.m_Uuid < item2.m_Uuid; // ensure a deterministic sort
130  else
131  return ii < 0;
132 }
KIID m_Uuid
UUID of the component.
int m_Unit
The unit number for components with multiple parts per package.
int RefDesStringCompare(const wxString &aFirst, const wxString &aSecond)
Acts just like the strcmp function but treats numbers within the string text correctly for sorting.
wxString GetRef() const

References SCH_REFERENCE::GetRef(), SCH_REFERENCE::m_Unit, SCH_REFERENCE::m_Uuid, and UTIL::RefDesStringCompare().

Referenced by SortByReferenceOnly().

◆ SortByTimeStamp()

void SCH_REFERENCE_LIST::SortByTimeStamp ( )
inline

Function SortComponentsByTimeStamp sort the flat list by Time Stamp (sheet path + timestamp).

Useful to detect duplicate Time Stamps

Definition at line 393 of file sch_reference_list.h.

394  {
395  sort( flatList.begin(), flatList.end(), sortByTimeStamp );
396  }
static bool sortByTimeStamp(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
std::vector< SCH_REFERENCE > flatList

References flatList, and sortByTimeStamp().

Referenced by BACK_ANNOTATE::checkForUnusedSymbols().

◆ sortByTimeStamp()

bool SCH_REFERENCE_LIST::sortByTimeStamp ( const SCH_REFERENCE item1,
const SCH_REFERENCE item2 
)
staticprivate

Definition at line 135 of file component_references_lister.cpp.

137 {
138  int ii = item1.m_SheetPath.Cmp( item2.m_SheetPath );
139 
140  if( ii == 0 )
141  return item1.m_Uuid < item2.m_Uuid; // ensure a deterministic sort
142  else
143  return ii < 0;
144 }
KIID m_Uuid
UUID of the component.
SCH_SHEET_PATH m_SheetPath
The sheet path for this reference.
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Function Cmp Compare if this is the same sheet path as aSheetPathToTest.

References SCH_SHEET_PATH::Cmp(), SCH_REFERENCE::m_SheetPath, and SCH_REFERENCE::m_Uuid.

Referenced by BACK_ANNOTATE::checkForUnusedSymbols(), and SortByTimeStamp().

◆ SortByXCoordinate()

void SCH_REFERENCE_LIST::SortByXCoordinate ( )
inline

Function sortByXCoordinate sorts the list of references by X position.

Components are sorted as follows:

  • Numeric value of reference designator.
  • Sheet number.
  • X coordinate position.
  • Y coordinate position.
  • Time stamp.

Definition at line 364 of file sch_reference_list.h.

365  {
366  sort( flatList.begin(), flatList.end(), sortByXPosition );
367  }
std::vector< SCH_REFERENCE > flatList
static bool sortByXPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)

References flatList, and sortByXPosition().

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

◆ sortByXPosition()

bool SCH_REFERENCE_LIST::sortByXPosition ( const SCH_REFERENCE item1,
const SCH_REFERENCE item2 
)
staticprivate

Definition at line 53 of file component_references_lister.cpp.

54 {
55  int ii = item1.CompareRef( item2 );
56 
57  if( ii == 0 )
58  ii = item1.m_SheetNum - item2.m_SheetNum;
59 
60  if( ii == 0 )
61  ii = item1.m_CmpPos.x - item2.m_CmpPos.x;
62 
63  if( ii == 0 )
64  ii = item1.m_CmpPos.y - item2.m_CmpPos.y;
65 
66  if( ii == 0 )
67  return item1.m_Uuid < item2.m_Uuid; // ensure a deterministic sort
68  else
69  return ii < 0;
70 }
wxPoint m_CmpPos
The physical position of the component in schematic used to annotate by X or Y position.
KIID m_Uuid
UUID of the component.
int m_SheetNum
The sheet number for the reference.
int CompareRef(const SCH_REFERENCE &item) const

References SCH_REFERENCE::CompareRef(), SCH_REFERENCE::m_CmpPos, SCH_REFERENCE::m_SheetNum, SCH_REFERENCE::m_Uuid, wxPoint::x, and wxPoint::y.

Referenced by SortByXCoordinate().

◆ SortByYCoordinate()

void SCH_REFERENCE_LIST::SortByYCoordinate ( )
inline

Function sortByYCoordinate sorts the list of references by Y position.

Components are sorted as follows:

  • Numeric value of reference designator.
  • Sheet number.
  • Y coordinate position.
  • X coordinate position.
  • Time stamp.

Definition at line 383 of file sch_reference_list.h.

384  {
385  sort( flatList.begin(), flatList.end(), sortByYPosition );
386  }
static bool sortByYPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
std::vector< SCH_REFERENCE > flatList

References flatList, and sortByYPosition().

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

◆ sortByYPosition()

bool SCH_REFERENCE_LIST::sortByYPosition ( const SCH_REFERENCE item1,
const SCH_REFERENCE item2 
)
staticprivate

Definition at line 73 of file component_references_lister.cpp.

74 {
75  int ii = item1.CompareRef( item2 );
76 
77  if( ii == 0 )
78  ii = item1.m_SheetNum - item2.m_SheetNum;
79 
80  if( ii == 0 )
81  ii = item1.m_CmpPos.y - item2.m_CmpPos.y;
82 
83  if( ii == 0 )
84  ii = item1.m_CmpPos.x - item2.m_CmpPos.x;
85 
86  if( ii == 0 )
87  return item1.m_Uuid < item2.m_Uuid; // ensure a deterministic sort
88  else
89  return ii < 0;
90 }
wxPoint m_CmpPos
The physical position of the component in schematic used to annotate by X or Y position.
KIID m_Uuid
UUID of the component.
int m_SheetNum
The sheet number for the reference.
int CompareRef(const SCH_REFERENCE &item) const

References SCH_REFERENCE::CompareRef(), SCH_REFERENCE::m_CmpPos, SCH_REFERENCE::m_SheetNum, SCH_REFERENCE::m_Uuid, wxPoint::x, and wxPoint::y.

Referenced by SortByYCoordinate().

◆ SplitReferences()

void SCH_REFERENCE_LIST::SplitReferences ( )
inline

Function SplitReferences attempts to split all reference designators into a name (U) and number (1).

If the last character is '?' or not a digit, the reference is tagged as not annotated. For components with multiple parts per package that are not already annotated, set m_Unit to a max value (0x7FFFFFFF).

See also
SCH_REFERENCE::Split()

Definition at line 291 of file sch_reference_list.h.

292  {
293  for( unsigned ii = 0; ii < GetCount(); ii++ )
294  flatList[ii].Split();
295  }
unsigned GetCount() const
Function GetCount.
std::vector< SCH_REFERENCE > flatList

References flatList, and GetCount().

Referenced by SCH_EDIT_FRAME::AnnotateComponents(), SCH_SHEET_LIST::AnnotatePowerSymbols(), CheckAnnotation(), and FIELDS_EDITOR_GRID_DATA_MODEL::FIELDS_EDITOR_GRID_DATA_MODEL().

◆ UpdateAnnotation()

void SCH_REFERENCE_LIST::UpdateAnnotation ( )
inline

function UpdateAnnotation Updates the reference components for the schematic project (or the current sheet) Note: this function does not calculate the reference numbers stored in m_NumRef So, it must be called after calculation of new reference numbers

See also
SCH_REFERENCE::Annotate()

Definition at line 304 of file sch_reference_list.h.

305  {
306  /* update the reference numbers */
307  for( unsigned ii = 0; ii < GetCount(); ii++ )
308  {
309  flatList[ii].Annotate();
310  }
311  }
unsigned GetCount() const
Function GetCount.
std::vector< SCH_REFERENCE > flatList

References flatList, and GetCount().

Referenced by SCH_SHEET_LIST::AnnotatePowerSymbols().

Friends And Related Function Documentation

◆ BACK_ANNOTATE

friend class BACK_ANNOTATE
friend

Definition at line 536 of file sch_reference_list.h.

◆ BACK_ANNOTATION

friend class BACK_ANNOTATION
friend

Definition at line 506 of file sch_reference_list.h.

Member Data Documentation

◆ flatList


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