KiCad PCB EDA Suite
SCH_REFERENCE_LIST Class Reference

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

#include <sch_reference_list.h>

Public Member Functions

 SCH_REFERENCE_LIST ()
 
SCH_REFERENCEoperator[] (int aIndex)
 
void Clear ()
 
unsigned GetCount () const
 
SCH_REFERENCEGetItem (int aIdx)
 
void AddItem (SCH_REFERENCE &aItem)
 
void RemoveItem (unsigned int aIndex)
 Remove an item from the list of references. More...
 
void SplitReferences ()
 Attempt to split all reference designators into a name (U) and number (1). More...
 
void UpdateAnnotation ()
 Update the symbol references for the schematic project (or the current sheet). More...
 
void Annotate (bool aUseSheetNum, int aSheetIntervalId, int aStartNumber, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap)
 Set the reference designators in the list that have not been annotated. More...
 
int CheckAnnotation (ANNOTATION_ERROR_HANDLER aErrorHandler)
 Check for annotations errors. More...
 
void SortByXCoordinate ()
 Sort the list of references by X position. More...
 
void SortByYCoordinate ()
 Sort the list of references by Y position. More...
 
void SortByTimeStamp ()
 Sort the flat list by Time Stamp (sheet path + timestamp). More...
 
void SortByRefAndValue ()
 Sort the list of references by value. More...
 
void SortByReferenceOnly ()
 Sort the list of references by reference. More...
 
int FindRef (const wxString &aPath) const
 Search the list for a symbol with a given reference. More...
 
int FindUnit (size_t aIndex, int aUnit)
 Search the sorted list of symbols for a another symbol with the same reference and a given part unit. More...
 
int FindRefByPath (const wxString &aPath) const
 Search the list for a symbol with the given KIID path. More...
 
void GetRefsInUse (int aIndex, std::vector< int > &aIdList, int aMinRefId)
 Add all the reference designator numbers greater than aMinRefId to aIdList skipping the reference at aIndex. More...
 
int GetLastReference (int aIndex, int aMinValue)
 Return the last used (greatest) reference number in the reference list for the prefix used by the symbol pointed to by aIndex. More...
 

Static Public Member Functions

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

Private Member Functions

int CreateFirstFreeRefId (std::vector< int > &aIdList, int aFirstValue)
 Search 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

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

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

Definition at line 196 of file sch_reference_list.h.

Constructor & Destructor Documentation

◆ SCH_REFERENCE_LIST()

SCH_REFERENCE_LIST::SCH_REFERENCE_LIST ( )
inline

Definition at line 203 of file sch_reference_list.h.

204  {
205  }

Member Function Documentation

◆ AddItem()

void SCH_REFERENCE_LIST::AddItem ( SCH_REFERENCE aItem)
inline

Definition at line 221 of file sch_reference_list.h.

221 { flatList.push_back( aItem ); }
std::vector< SCH_REFERENCE > flatList

References flatList.

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

◆ Annotate()

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

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 282 of file component_references_lister.cpp.

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

◆ CheckAnnotation()

int SCH_REFERENCE_LIST::CheckAnnotation ( ANNOTATION_ERROR_HANDLER  aErrorHandler)

Check for annotations errors.

The following annotation error conditions are tested:

  • Symbols not annotated.
  • Symbols having the same reference designator (duplicates).
  • Symbols with multiple parts per package having different reference designators.
  • Symbols with multiple parts per package with invalid part count.
Parameters
aErrorHandlerA handler for errors.
Returns
The number of errors found.

Definition at line 498 of file component_references_lister.cpp.

499 {
500  int error = 0;
501  wxString tmp;
502  wxString msg;
503 
505 
506  // Spiit reference designators into name (prefix) and number: IC1 becomes IC, and 1.
507  SplitReferences();
508 
509  // count not yet annotated items or annotation error.
510  for( unsigned ii = 0; ii < flatList.size(); ii++ )
511  {
512  msg.Empty();
513  tmp.Empty();
514 
515  if( flatList[ii].m_isNew ) // Not yet annotated
516  {
517  if( flatList[ii].m_numRef >= 0 )
518  tmp << flatList[ii].m_numRef;
519  else
520  tmp = wxT( "?" );
521 
522 
523  if( ( flatList[ii].m_unit > 0 ) && ( flatList[ii].m_unit < 0x7FFFFFFF ) )
524  {
525  msg.Printf( _( "Item not annotated: %s%s (unit %d)\n" ),
526  flatList[ii].GetRef(),
527  tmp,
528  flatList[ii].m_unit );
529  }
530  else
531  {
532  msg.Printf( _( "Item not annotated: %s%s\n" ),
533  flatList[ii].GetRef(),
534  tmp );
535  }
536 
537  aHandler( ERCE_UNANNOTATED, msg, &flatList[ii], nullptr );
538  error++;
539  break;
540  }
541 
542  // Error if unit number selected does not exist (greater than the number of units in
543  // the component). This can happen if a component has changed in a library after a
544  // previous annotation.
545  if( std::max( flatList[ii].GetLibPart()->GetUnitCount(), 1 ) < flatList[ii].m_unit )
546  {
547  if( flatList[ii].m_numRef >= 0 )
548  tmp << flatList[ii].m_numRef;
549  else
550  tmp = wxT( "?" );
551 
552  msg.Printf( _( "Error: symbol %s%s%s (unit %d) exceeds units defined (%d)\n" ),
553  flatList[ii].GetRef(),
554  tmp,
555  LIB_PART::SubReference( flatList[ii].m_unit ),
556  flatList[ii].m_unit,
557  flatList[ii].GetLibPart()->GetUnitCount() );
558 
559  aHandler( ERCE_EXTRA_UNITS, msg, &flatList[ii], nullptr );
560  error++;
561  break;
562  }
563  }
564 
565  // count the duplicated elements (if all are annotated)
566  int imax = flatList.size() - 1;
567 
568  for( int ii = 0; ii < imax; ii++ )
569  {
570  msg.Empty();
571  tmp.Empty();
572 
573  if( ( flatList[ii].CompareRef( flatList[ii + 1] ) != 0 )
574  || ( flatList[ii].m_numRef != flatList[ ii + 1].m_numRef ) )
575  {
576  continue;
577  }
578 
579  // Same reference found. If same unit, error!
580  if( flatList[ii].m_unit == flatList[ ii + 1].m_unit )
581  {
582  if( flatList[ii].m_numRef >= 0 )
583  tmp << flatList[ii].m_numRef;
584  else
585  tmp = wxT( "?" );
586 
587  if( ( flatList[ii].m_unit > 0 ) && ( flatList[ii].m_unit < 0x7FFFFFFF ) )
588  {
589  msg.Printf( _( "Duplicate items %s%s%s\n" ),
590  flatList[ii].GetRef(),
591  tmp,
592  LIB_PART::SubReference( flatList[ii].m_unit ) );
593  }
594  else
595  {
596  msg.Printf( _( "Duplicate items %s%s\n" ),
597  flatList[ii].GetRef(),
598  tmp );
599  }
600 
601  aHandler( ERCE_DUPLICATE_REFERENCE, msg, &flatList[ii], &flatList[ii+1] );
602  error++;
603  continue;
604  }
605 
606  /* Test error if units are different but number of parts per package
607  * too high (ex U3 ( 1 part) and we find U3B this is an error) */
608  if( flatList[ii].GetLibPart()->GetUnitCount()
609  != flatList[ ii + 1].GetLibPart()->GetUnitCount() )
610  {
611  if( flatList[ii].m_numRef >= 0 )
612  tmp << flatList[ii].m_numRef;
613  else
614  tmp = wxT( "?" );
615 
616  if( ( flatList[ii].m_unit > 0 )
617  && ( flatList[ii].m_unit < 0x7FFFFFFF ) )
618  {
619  msg.Printf( _( "Duplicate items %s%s%s\n" ),
620  flatList[ii].GetRef(),
621  tmp,
622  LIB_PART::SubReference( flatList[ii].m_unit ) );
623  }
624  else
625  {
626  msg.Printf( _( "Duplicate items %s%s\n" ),
627  flatList[ii].GetRef(),
628  tmp );
629  }
630 
631  aHandler( ERCE_DUPLICATE_REFERENCE, msg, &flatList[ii], &flatList[ii+1] );
632  error++;
633  }
634 
635  // Error if values are different between units, for the same reference
636  int next = ii + 1;
637 
638  if( flatList[ii].CompareValue( flatList[next] ) != 0 )
639  {
640  msg.Printf( _( "Different values for %s%d%s (%s) and %s%d%s (%s)" ),
641  flatList[ii].GetRef(),
642  flatList[ii].m_numRef,
643  LIB_PART::SubReference( flatList[ii].m_unit ),
644  flatList[ii].m_value,
645  flatList[next].GetRef(),
646  flatList[next].m_numRef,
648  flatList[next].m_value );
649 
650  aHandler( ERCE_DIFFERENT_UNIT_VALUE, msg, &flatList[ii], &flatList[ii+1] );
651  error++;
652  }
653  }
654 
655  return error;
656 }
CITER next(CITER it)
Definition: ptree.cpp:126
Units of same symbol have different values.
Definition: erc_settings.h:70
void SortByRefAndValue()
Sort the list of references by value.
Symbol has not been annotated.
Definition: erc_settings.h:68
More than one symbol with the same reference.
Definition: erc_settings.h:71
void SplitReferences()
Attempt 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)
Definition: lib_symbol.cpp:440
std::vector< SCH_REFERENCE > flatList
Symbol has more units than are defined.
Definition: erc_settings.h:69

References _, ERCE_DIFFERENT_UNIT_VALUE, ERCE_DUPLICATE_REFERENCE, ERCE_EXTRA_UNITS, ERCE_UNANNOTATED, flatList, next(), SortByRefAndValue(), SplitReferences(), and LIB_PART::SubReference().

Referenced by SCH_EDIT_FRAME::CheckAnnotate().

◆ Clear()

void SCH_REFERENCE_LIST::Clear ( )
inline

Definition at line 212 of file sch_reference_list.h.

213  {
214  flatList.clear();
215  }
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

Search 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 232 of file component_references_lister.cpp.

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

Referenced by Annotate().

◆ FindRef()

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

Search the list for a symbol with a given reference.

Definition at line 179 of file component_references_lister.cpp.

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

References flatList.

Referenced by BACK_ANNOTATE::getChangeList().

◆ FindRefByPath()

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

Search the list for a symbol with the given KIID path.

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

Definition at line 167 of file component_references_lister.cpp.

168 {
169  for( size_t i = 0; i < flatList.size(); ++i )
170  {
171  if( flatList[i].GetPath() == aPath )
172  return i;
173  }
174 
175  return -1;
176 }
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 
)

Search the sorted list of symbols for a another symbol with the same reference and a given part unit.

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

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

Definition at line 145 of file component_references_lister.cpp.

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

References flatList.

Referenced by Annotate().

◆ GetCount()

◆ GetItem()

SCH_REFERENCE& SCH_REFERENCE_LIST::GetItem ( int  aIdx)
inline

Definition at line 219 of file sch_reference_list.h.

219 { return flatList[aIdx]; }
std::vector< SCH_REFERENCE > flatList

References flatList.

Referenced by ERC_TESTER::TestMultiunitFootprints().

◆ GetLastReference()

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

Return the last used (greatest) reference number in the reference list for the prefix used by the symbol pointed to by aIndex.

The symbol 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 213 of file component_references_lister.cpp.

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

References flatList.

◆ GetRefsInUse()

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

Add all the reference designator numbers greater than aMinRefId to aIdList skipping the reference at aIndex.

Parameters
aIndex= the current symbol's 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 191 of file component_references_lister.cpp.

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

References flatList.

Referenced by Annotate().

◆ operator[]()

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

Definition at line 207 of file sch_reference_list.h.

208  {
209  return flatList[ aIndex ];
210  }
std::vector< SCH_REFERENCE > flatList

References flatList.

◆ RemoveItem()

void SCH_REFERENCE_LIST::RemoveItem ( unsigned int  aIndex)

Remove an item from the list of references.

Parameters
aIndexis the index of the item to be removed.

Definition at line 44 of file component_references_lister.cpp.

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

References flatList.

◆ Shorthand()

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

Return a shorthand string representing all the references in the list.

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

Definition at line 756 of file component_references_lister.cpp.

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

Referenced by FIELDS_EDITOR_GRID_DATA_MODEL::GetValue().

◆ SortByRefAndValue()

void SCH_REFERENCE_LIST::SortByRefAndValue ( )
inline

Sort the list of references by value.

Symbols are sorted in the following order:

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

Definition at line 363 of file sch_reference_list.h.

364  {
365  sort( flatList.begin(), flatList.end(), sortByRefAndValue );
366  }
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 91 of file component_references_lister.cpp.

93 {
94  int ii = item1.CompareRef( item2 );
95 
96  if( ii == 0 )
97  ii = item1.CompareValue( item2 );
98 
99  if( ii == 0 )
100  ii = item1.m_unit - item2.m_unit;
101 
102  if( ii == 0 )
103  ii = item1.m_sheetNum - item2.m_sheetNum;
104 
105  if( ii == 0 )
106  ii = item1.m_symbolPos.x - item2.m_symbolPos.x;
107 
108  if( ii == 0 )
109  ii = item1.m_symbolPos.y - item2.m_symbolPos.y;
110 
111  if( ii == 0 )
112  return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
113  else
114  return ii < 0;
115 }
wxPoint m_symbolPos
The physical position of the symbol in schematic.
int m_sheetNum
The sheet number for the reference.
int m_unit
The unit number for symbol with multiple parts.
int CompareValue(const SCH_REFERENCE &item) const
KIID m_symbolUuid
UUID of the symbol.
int CompareRef(const SCH_REFERENCE &item) const

References SCH_REFERENCE::CompareRef(), SCH_REFERENCE::CompareValue(), SCH_REFERENCE::m_sheetNum, SCH_REFERENCE::m_symbolPos, SCH_REFERENCE::m_symbolUuid, and SCH_REFERENCE::m_unit.

Referenced by SortByRefAndValue().

◆ SortByReferenceOnly()

void SCH_REFERENCE_LIST::SortByReferenceOnly ( )
inline

Sort the list of references by reference.

Symbols are sorted in the following order:

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

Definition at line 378 of file sch_reference_list.h.

379  {
380  sort( flatList.begin(), flatList.end(), sortByReferenceOnly );
381  }
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 118 of file component_references_lister.cpp.

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

References SCH_REFERENCE::GetRef(), SCH_REFERENCE::m_symbolUuid, SCH_REFERENCE::m_unit, and UTIL::RefDesStringCompare().

Referenced by SortByReferenceOnly().

◆ SortByTimeStamp()

void SCH_REFERENCE_LIST::SortByTimeStamp ( )
inline

Sort the flat list by Time Stamp (sheet path + timestamp).

Useful to detect duplicate Time Stamps

Definition at line 344 of file sch_reference_list.h.

345  {
346  sort( flatList.begin(), flatList.end(), sortByTimeStamp );
347  }
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 133 of file component_references_lister.cpp.

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

References SCH_SHEET_PATH::Cmp(), SCH_REFERENCE::m_sheetPath, and SCH_REFERENCE::m_symbolUuid.

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

◆ SortByXCoordinate()

void SCH_REFERENCE_LIST::SortByXCoordinate ( )
inline

Sort the list of references by X position.

Symbols are sorted as follows:

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

Definition at line 316 of file sch_reference_list.h.

317  {
318  sort( flatList.begin(), flatList.end(), sortByXPosition );
319  }
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 51 of file component_references_lister.cpp.

52 {
53  int ii = item1.CompareRef( item2 );
54 
55  if( ii == 0 )
56  ii = item1.m_sheetNum - item2.m_sheetNum;
57 
58  if( ii == 0 )
59  ii = item1.m_symbolPos.x - item2.m_symbolPos.x;
60 
61  if( ii == 0 )
62  ii = item1.m_symbolPos.y - item2.m_symbolPos.y;
63 
64  if( ii == 0 )
65  return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
66  else
67  return ii < 0;
68 }
wxPoint m_symbolPos
The physical position of the symbol in schematic.
int m_sheetNum
The sheet number for the reference.
KIID m_symbolUuid
UUID of the symbol.
int CompareRef(const SCH_REFERENCE &item) const

References SCH_REFERENCE::CompareRef(), SCH_REFERENCE::m_sheetNum, SCH_REFERENCE::m_symbolPos, and SCH_REFERENCE::m_symbolUuid.

Referenced by SortByXCoordinate().

◆ SortByYCoordinate()

void SCH_REFERENCE_LIST::SortByYCoordinate ( )
inline

Sort the list of references by Y position.

Symbols are sorted as follows:

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

Definition at line 334 of file sch_reference_list.h.

335  {
336  sort( flatList.begin(), flatList.end(), sortByYPosition );
337  }
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 71 of file component_references_lister.cpp.

72 {
73  int ii = item1.CompareRef( item2 );
74 
75  if( ii == 0 )
76  ii = item1.m_sheetNum - item2.m_sheetNum;
77 
78  if( ii == 0 )
79  ii = item1.m_symbolPos.y - item2.m_symbolPos.y;
80 
81  if( ii == 0 )
82  ii = item1.m_symbolPos.x - item2.m_symbolPos.x;
83 
84  if( ii == 0 )
85  return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
86  else
87  return ii < 0;
88 }
wxPoint m_symbolPos
The physical position of the symbol in schematic.
int m_sheetNum
The sheet number for the reference.
KIID m_symbolUuid
UUID of the symbol.
int CompareRef(const SCH_REFERENCE &item) const

References SCH_REFERENCE::CompareRef(), SCH_REFERENCE::m_sheetNum, SCH_REFERENCE::m_symbolPos, and SCH_REFERENCE::m_symbolUuid.

Referenced by SortByYCoordinate().

◆ SplitReferences()

void SCH_REFERENCE_LIST::SplitReferences ( )
inline

Attempt 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 symbols 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 246 of file sch_reference_list.h.

247  {
248  for( unsigned ii = 0; ii < GetCount(); ii++ )
249  flatList[ii].Split();
250  }
unsigned GetCount() const
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

Update the symbol references 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 260 of file sch_reference_list.h.

261  {
262  /* update the reference numbers */
263  for( unsigned ii = 0; ii < GetCount(); ii++ )
264  flatList[ii].Annotate();
265  }
void Annotate(bool aUseSheetNum, int aSheetIntervalId, int aStartNumber, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap)
Set the reference designators in the list that have not been annotated.
unsigned GetCount() const
std::vector< SCH_REFERENCE > flatList

References Annotate(), flatList, and GetCount().

Referenced by SCH_SHEET_LIST::AnnotatePowerSymbols().

Friends And Related Function Documentation

◆ BACK_ANNOTATE

friend class BACK_ANNOTATE
friend

Definition at line 477 of file sch_reference_list.h.

◆ BACK_ANNOTATION

friend class BACK_ANNOTATION
friend

Definition at line 449 of file sch_reference_list.h.

Member Data Documentation

◆ flatList


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