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)
 
unsigned GetCount ()
 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 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 unit with designated 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 211 of file sch_reference_list.h.

Constructor & Destructor Documentation

◆ SCH_REFERENCE_LIST()

SCH_REFERENCE_LIST::SCH_REFERENCE_LIST ( )
inline

Constructor.

Definition at line 219 of file sch_reference_list.h.

220  {
221  }

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 251 of file sch_reference_list.h.

252  {
253  flatList.push_back( aItem );
254  }
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 272 of file component_references_lister.cpp.

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

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

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

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

Referenced by Annotate().

◆ FindRefByPath()

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

Searches unit with designated 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().

◆ 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 241 of file sch_reference_list.h.

242  {
243  return flatList[aIdx];
244  }
std::vector< SCH_REFERENCE > flatList

References flatList.

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

204 {
205  int lastNumber = aMinValue;
206 
207  for( SCH_REFERENCE& ref : flatList )
208  {
209  // search only for the current reference prefix:
210  if( flatList[aIndex].CompareRef( ref ) != 0 )
211  continue;
212 
213  // update max value for the current reference prefix
214  if( lastNumber < ref.m_NumRef )
215  lastNumber = ref.m_NumRef;
216  }
217 
218  return lastNumber;
219 }
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 181 of file component_references_lister.cpp.

182 {
183  aIdList.clear();
184 
185  for( SCH_REFERENCE& ref : flatList )
186  {
187  if( flatList[aIndex].CompareRef( ref ) == 0 && ref.m_NumRef >= aMinRefId )
188  aIdList.push_back( ref.m_NumRef );
189  }
190 
191  sort( aIdList.begin(), aIdList.end() );
192 
193  // Ensure each reference number appears only once. If there are components with
194  // multiple parts per package the same number will be stored for each part.
195  std::vector< int >::iterator it = unique( aIdList.begin(), aIdList.end() );
196 
197  // Using the C++ unique algorithm only moves the duplicate entries to the end of
198  // of the array. This removes the duplicate entries from the array.
199  aIdList.resize( it - aIdList.begin() );
200 }
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 223 of file sch_reference_list.h.

224  {
225  return flatList[ aIndex ];
226  }
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 748 of file component_references_lister.cpp.

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

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 404 of file sch_reference_list.h.

405  {
406  sort( flatList.begin(), flatList.end(), sortByRefAndValue );
407  }
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 420 of file sch_reference_list.h.

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

References flatList, and sortByReferenceOnly().

◆ 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 384 of file sch_reference_list.h.

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

References flatList, and sortByTimeStamp().

◆ 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 355 of file sch_reference_list.h.

356  {
357  sort( flatList.begin(), flatList.end(), sortByXPosition );
358  }
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 374 of file sch_reference_list.h.

375  {
376  sort( flatList.begin(), flatList.end(), sortByYPosition );
377  }
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 282 of file sch_reference_list.h.

283  {
284  for( unsigned ii = 0; ii < GetCount(); ii++ )
285  flatList[ii].Split();
286  }
std::vector< SCH_REFERENCE > flatList
unsigned GetCount()
Function GetCount.

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 295 of file sch_reference_list.h.

296  {
297  /* update the reference numbers */
298  for( unsigned ii = 0; ii < GetCount(); ii++ )
299  {
300  flatList[ii].Annotate();
301  }
302  }
std::vector< SCH_REFERENCE > flatList
unsigned GetCount()
Function GetCount.

References flatList, and GetCount().

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

Friends And Related Function Documentation

◆ BACK_ANNOTATE

friend class BACK_ANNOTATE
friend

Definition at line 520 of file sch_reference_list.h.

◆ BACK_ANNOTATION

friend class BACK_ANNOTATION
friend

Definition at line 490 of file sch_reference_list.h.

Member Data Documentation

◆ flatList


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