KiCad PCB EDA Suite
SCH_REFERENCE_LIST Class Reference

Class 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 RemoveSubComponentsFromList ()
 Function RemoveSubComponentsFromList Remove sub components from the list, when multiples parts per package are found in this list. 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. 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)
 Function GetUnit searches the sorted list of components for a another component with the same reference and a given part unit. 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...
 

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_REFERENCEcomponentFlatList
 

Detailed Description

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

Constructor & Destructor Documentation

SCH_REFERENCE_LIST::SCH_REFERENCE_LIST ( )
inline

Constructor.

Definition at line 204 of file sch_reference_list.h.

205  {
206  }

Member Function Documentation

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

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

237  {
238  componentFlatList.push_back( aItem );
239  }
std::vector< SCH_REFERENCE > componentFlatList
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 274 of file component_references_lister.cpp.

References SCH_REFERENCE::CompareLibName(), SCH_REFERENCE::CompareValue(), componentFlatList, CreateFirstFreeRefId(), FindUnit(), GetCount(), GetLastReference(), GetRefsInUse(), SCH_REFERENCE::IsSameInstance(), and SCH_REFERENCE::m_Unit.

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

276 {
277  if ( componentFlatList.size() == 0 )
278  return;
279 
280  int LastReferenceNumber = 0;
281  int NumberOfUnits, Unit;
282 
283  /* calculate index of the first component with the same reference prefix
284  * than the current component. All components having the same reference
285  * prefix will receive a reference number with consecutive values:
286  * IC .. will be set to IC4, IC4, IC5 ...
287  */
288  unsigned first = 0;
289 
290  // calculate the last used number for this reference prefix:
291 #ifdef USE_OLD_ALGO
292  int minRefId = 0;
293 
294  // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
295  if( aUseSheetNum )
296  minRefId = componentFlatList[first].m_SheetNum * aSheetIntervalId;
297 
298  LastReferenceNumber = GetLastReference( first, minRefId );
299 #else
300  int minRefId;
301 
302  // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
303  if( aUseSheetNum )
304  minRefId = componentFlatList[first].m_SheetNum * aSheetIntervalId + 1;
305  else
306  minRefId = aStartNumber + 1;
307 
308  // This is the list of all Id already in use for a given reference prefix.
309  // Will be refilled for each new reference prefix.
310  std::vector<int>idList;
311  GetRefsInUse( first, idList, minRefId );
312 #endif
313  for( unsigned ii = 0; ii < componentFlatList.size(); ii++ )
314  {
315  if( componentFlatList[ii].m_Flag )
316  continue;
317 
318  // Check whether this component is in aLockedUnitMap.
319  SCH_REFERENCE_LIST* lockedList = NULL;
320  for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : aLockedUnitMap )
321  {
322  unsigned n_refs = pair.second.GetCount();
323  for( unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI )
324  {
325  SCH_REFERENCE &thisRef = pair.second[thisRefI];
326 
327  if( thisRef.IsSameInstance( componentFlatList[ii] ) )
328  {
329  lockedList = &pair.second;
330  break;
331  }
332  }
333  if( lockedList != NULL ) break;
334  }
335 
336  if( ( componentFlatList[first].CompareRef( componentFlatList[ii] ) != 0 )
337  || ( aUseSheetNum && ( componentFlatList[first].m_SheetNum != componentFlatList[ii].m_SheetNum ) ) )
338  {
339  // New reference found: we need a new ref number for this reference
340  first = ii;
341 #ifdef USE_OLD_ALGO
342  minRefId = 0;
343 
344  // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
345  if( aUseSheetNum )
346  minRefId = componentFlatList[ii].m_SheetNum * aSheetIntervalId;
347 
348  LastReferenceNumber = componentFlatList.GetLastReference( ii, minRefId );
349 #else
350  // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
351  if( aUseSheetNum )
352  minRefId = componentFlatList[ii].m_SheetNum * aSheetIntervalId + 1;
353  else
354  minRefId = aStartNumber + 1;
355 
356  GetRefsInUse( first, idList, minRefId );
357 #endif
358  }
359 
360  // Annotation of one part per package components (trivial case).
361  if( componentFlatList[ii].GetLibPart()->GetUnitCount() <= 1 )
362  {
363  if( componentFlatList[ii].m_IsNew )
364  {
365 #ifdef USE_OLD_ALGO
366  LastReferenceNumber++;
367 #else
368  LastReferenceNumber = CreateFirstFreeRefId( idList, minRefId );
369 #endif
370  componentFlatList[ii].m_NumRef = LastReferenceNumber;
371  }
372 
373  componentFlatList[ii].m_Unit = 1;
374  componentFlatList[ii].m_Flag = 1;
375  componentFlatList[ii].m_IsNew = false;
376  continue;
377  }
378 
379  // Annotation of multi-unit parts ( n units per part ) (complex case)
380  NumberOfUnits = componentFlatList[ii].GetLibPart()->GetUnitCount();
381 
382  if( componentFlatList[ii].m_IsNew )
383  {
384 #ifdef USE_OLD_ALGO
385  LastReferenceNumber++;
386 #else
387  LastReferenceNumber = CreateFirstFreeRefId( idList, minRefId );
388 #endif
389  componentFlatList[ii].m_NumRef = LastReferenceNumber;
390 
391  if( !componentFlatList[ii].IsUnitsLocked() )
392  componentFlatList[ii].m_Unit = 1;
393 
394  componentFlatList[ii].m_Flag = 1;
395  }
396 
397  // If this component is in aLockedUnitMap, copy the annotation to all
398  // components that are not it
399  if( lockedList != NULL )
400  {
401  unsigned n_refs = lockedList->GetCount();
402  for( unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI )
403  {
404  SCH_REFERENCE &thisRef = (*lockedList)[thisRefI];
405  if( thisRef.IsSameInstance( componentFlatList[ii] ) )
406  {
407  // This is the component we're currently annotating. Hold the unit!
408  componentFlatList[ii].m_Unit = thisRef.m_Unit;
409  }
410 
411  if( thisRef.CompareValue( componentFlatList[ii] ) != 0 ) continue;
412  if( thisRef.CompareLibName( componentFlatList[ii] ) != 0 ) continue;
413 
414  // Find the matching component
415  for( unsigned jj = ii + 1; jj < componentFlatList.size(); jj++ )
416  {
417  if( ! thisRef.IsSameInstance( componentFlatList[jj] ) ) continue;
418  componentFlatList[jj].m_NumRef = componentFlatList[ii].m_NumRef;
419  componentFlatList[jj].m_Unit = thisRef.m_Unit;
420  componentFlatList[jj].m_IsNew = false;
421  componentFlatList[jj].m_Flag = 1;
422  break;
423  }
424  }
425  }
426 
427  else
428  {
429  /* search for others units of this component.
430  * we search for others parts that have the same value and the same
431  * reference prefix (ref without ref number)
432  */
433  for( Unit = 1; Unit <= NumberOfUnits; Unit++ )
434  {
435  if( componentFlatList[ii].m_Unit == Unit )
436  continue;
437 
438  int found = FindUnit( ii, Unit );
439 
440  if( found >= 0 )
441  continue; // this unit exists for this reference (unit already annotated)
442 
443  // Search a component to annotate ( same prefix, same value, not annotated)
444  for( unsigned jj = ii + 1; jj < componentFlatList.size(); jj++ )
445  {
446  if( componentFlatList[jj].m_Flag ) // already tested
447  continue;
448 
449  if( componentFlatList[ii].CompareRef( componentFlatList[jj] ) != 0 )
450  continue;
451 
452  if( componentFlatList[jj].CompareValue( componentFlatList[ii] ) != 0 )
453  continue;
454 
455  if( componentFlatList[jj].CompareLibName( componentFlatList[ii] ) != 0 )
456  continue;
457 
458  if( !componentFlatList[jj].m_IsNew )
459  continue;
460 
461  // Component without reference number found, annotate it if possible
462  if( !componentFlatList[jj].IsUnitsLocked()
463  || ( componentFlatList[jj].m_Unit == Unit ) )
464  {
465  componentFlatList[jj].m_NumRef = componentFlatList[ii].m_NumRef;
466  componentFlatList[jj].m_Unit = Unit;
467  componentFlatList[jj].m_Flag = 1;
468  componentFlatList[jj].m_IsNew = false;
469  break;
470  }
471  }
472  }
473  }
474  }
475 }
int CompareLibName(const SCH_REFERENCE &item) const
std::vector< SCH_REFERENCE > componentFlatList
int CompareValue(const SCH_REFERENCE &item) const
bool IsSameInstance(const SCH_REFERENCE &other) const
Function IsSameInstance returns whether this reference refers to the same component instance (compone...
Class SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierar...
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.
int FindUnit(size_t aIndex, int aUnit)
Function GetUnit searches the sorted list of components for a another component with the same referen...
int CreateFirstFreeRefId(std::vector< int > &aIdList, int aFirstValue)
Function CreateFirstFreeRefId searches for the first free reference number in aListId of reference nu...
int GetLastReference(int aIndex, int aMinValue)
Function GetLastReference returns the last used (greatest) reference number in the reference list for...
unsigned GetCount()
Function GetCount.
Class SCH_REFERENCE is used as a helper to define a component&#39;s reference designator in a schematic...
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 478 of file component_references_lister.cpp.

References componentFlatList, GetChars(), max, next(), REPORTER::Report(), REPORTER::RPT_ERROR, REPORTER::RPT_WARNING, SortByRefAndValue(), SortByTimeStamp(), SplitReferences(), and LIB_PART::SubReference().

Referenced by SCH_EDIT_FRAME::CheckAnnotate().

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

Referenced by Annotate().

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

Function GetUnit 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 142 of file component_references_lister.cpp.

References componentFlatList.

Referenced by Annotate().

143 {
144  int NumRef;
145 
146  NumRef = componentFlatList[aIndex].m_NumRef;
147 
148  for( size_t ii = 0; ii < componentFlatList.size(); ii++ )
149  {
150  if( ( aIndex == ii )
151  || ( componentFlatList[ii].m_IsNew )
152  || ( componentFlatList[ii].m_NumRef != NumRef )
153  || ( componentFlatList[aIndex].CompareRef( componentFlatList[ii] ) != 0 ) )
154  continue;
155 
156  if( componentFlatList[ii].m_Unit == aUnit )
157  return (int) ii;
158  }
159 
160  return -1;
161 }
std::vector< SCH_REFERENCE > componentFlatList
SCH_REFERENCE& SCH_REFERENCE_LIST::GetItem ( int  aIdx)
inline

Function GetItem.

Returns
the aIdx item

Definition at line 226 of file sch_reference_list.h.

227  {
228  return componentFlatList[aIdx];
229  }
std::vector< SCH_REFERENCE > componentFlatList
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 220 of file component_references_lister.cpp.

References componentFlatList.

Referenced by Annotate().

221 {
222  int lastNumber = aMinValue;
223 
224  for( unsigned ii = 0; ii < componentFlatList.size(); ii++ )
225  {
226  // search only for the current reference prefix:
227  if( componentFlatList[aIndex].CompareRef( componentFlatList[ii] ) != 0 )
228  continue;
229 
230  // update max value for the current reference prefix
231  if( lastNumber < componentFlatList[ii].m_NumRef )
232  lastNumber = componentFlatList[ii].m_NumRef;
233  }
234 
235  return lastNumber;
236 }
std::vector< SCH_REFERENCE > componentFlatList
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 197 of file component_references_lister.cpp.

References componentFlatList.

Referenced by Annotate().

198 {
199  aIdList.clear();
200 
201  for( unsigned ii = 0; ii < componentFlatList.size(); ii++ )
202  {
203  if( ( componentFlatList[aIndex].CompareRef( componentFlatList[ii] ) == 0 )
204  && ( componentFlatList[ii].m_NumRef >= aMinRefId ) )
205  aIdList.push_back( componentFlatList[ii].m_NumRef );
206  }
207 
208  sort( aIdList.begin(), aIdList.end() );
209 
210  // Ensure each reference number appears only once. If there are components with
211  // multiple parts per package the same number will be stored for each part.
212  std::vector< int >::iterator it = unique( aIdList.begin(), aIdList.end() );
213 
214  // Using the C++ unique algorithm only moves the duplicate entries to the end of
215  // of the array. This removes the duplicate entries from the array.
216  aIdList.resize( it - aIdList.begin() );
217 }
std::vector< SCH_REFERENCE > componentFlatList
SCH_REFERENCE& SCH_REFERENCE_LIST::operator[] ( int  aIndex)
inline

Definition at line 208 of file sch_reference_list.h.

209  {
210  return componentFlatList[ aIndex ];
211  }
std::vector< SCH_REFERENCE > componentFlatList
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 47 of file component_references_lister.cpp.

References componentFlatList.

48 {
49  if( aIndex < componentFlatList.size() )
50  componentFlatList.erase( componentFlatList.begin() + aIndex );
51 }
std::vector< SCH_REFERENCE > componentFlatList
void SCH_REFERENCE_LIST::RemoveSubComponentsFromList ( )

Function RemoveSubComponentsFromList Remove sub components from the list, when multiples parts per package are found in this list.

Useful to create BOM, when a component must appear only once

Definition at line 164 of file component_references_lister.cpp.

References componentFlatList, and SortByReferenceOnly().

165 {
166  SCH_COMPONENT* libItem;
167  wxString oldName;
168  wxString currName;
169 
170  // The component list **MUST** be sorted by reference and by unit number
171  // in order to find all parts of a component
173 
174  for( unsigned ii = 0; ii < componentFlatList.size(); ii++ )
175  {
176 
177  libItem = componentFlatList[ii].m_RootCmp;
178  if( libItem == NULL )
179  continue;
180 
181  currName = componentFlatList[ii].GetRef();
182 
183  if( !oldName.IsEmpty() )
184  {
185  if( oldName == currName ) // currName is a subpart of oldName: remove it
186  {
187  componentFlatList.erase( componentFlatList.begin() + ii );
188  ii--;
189  }
190  }
191 
192  oldName = currName;
193  }
194 }
std::vector< SCH_REFERENCE > componentFlatList
void SortByReferenceOnly()
Function SortByReferenceOnly sorts the list of references by reference.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
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 397 of file sch_reference_list.h.

Referenced by CheckAnnotation().

398  {
399  sort( componentFlatList.begin(), componentFlatList.end(), sortByRefAndValue );
400  }
std::vector< SCH_REFERENCE > componentFlatList
static bool sortByRefAndValue(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
bool SCH_REFERENCE_LIST::sortByRefAndValue ( const SCH_REFERENCE item1,
const SCH_REFERENCE item2 
)
staticprivate

Definition at line 89 of file component_references_lister.cpp.

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

91 {
92  int ii = item1.CompareRef( item2 );
93  if( ii == 0 )
94  ii = item1.CompareValue( item2 );
95  if( ii == 0 )
96  ii = item1.m_Unit - item2.m_Unit;
97  if( ii == 0 )
98  ii = item1.m_SheetNum - item2.m_SheetNum;
99  if( ii == 0 )
100  ii = item1.m_CmpPos.x - item2.m_CmpPos.x;
101  if( ii == 0 )
102  ii = item1.m_CmpPos.y - item2.m_CmpPos.y;
103  if( ii == 0 )
104  ii = item1.m_TimeStamp - item2.m_TimeStamp;
105 
106  return ii < 0;
107 }
wxPoint m_CmpPos
The physical position of the component in schematic used to annotate by X or Y position.
int CompareValue(const SCH_REFERENCE &item) const
int m_SheetNum
The sheet number for the reference.
int m_Unit
The unit number for components with multiple parts per package.
int CompareRef(const SCH_REFERENCE &item) const
timestamp_t m_TimeStamp
The time stamp for the reference.
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 413 of file sch_reference_list.h.

References UTF8::c_str(), SCH_REFERENCE::GetLibPart(), LIB_PART::GetName(), i, SCH_REFERENCE::m_NumRef, SCH_REFERENCE::m_Ref, and TO_UTF8.

Referenced by RemoveSubComponentsFromList().

414  {
416  }
std::vector< SCH_REFERENCE > componentFlatList
static bool sortByReferenceOnly(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
bool SCH_REFERENCE_LIST::sortByReferenceOnly ( const SCH_REFERENCE item1,
const SCH_REFERENCE item2 
)
staticprivate

Definition at line 110 of file component_references_lister.cpp.

References SCH_COMPONENT::GetField(), SCH_REFERENCE::GetRef(), EDA_TEXT::GetText(), SCH_REFERENCE::m_RootCmp, SCH_REFERENCE::m_Unit, RefDesStringCompare(), and VALUE.

112 {
113  int ii;
114 
115  ii = RefDesStringCompare( item1.GetRef(), item2.GetRef() );
116 
117  if( ii == 0 )
118  {
119  ii = item1.m_RootCmp->GetField( VALUE )->GetText().CmpNoCase( item2.m_RootCmp->GetField( VALUE )->GetText() );
120  }
121 
122  if( ii == 0 )
123  {
124  ii = item1.m_Unit - item2.m_Unit;
125  }
126 
127  return ii < 0;
128 }
int RefDesStringCompare(const wxString &strFWord, const wxString &strSWord)
Function RefDesStringCompare acts just like the strcmp function but treats numbers within the string ...
Definition: string.cpp:466
int m_Unit
The unit number for components with multiple parts per package.
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
SCH_COMPONENT * m_RootCmp
The component associated the reference object.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
wxString GetRef() const
#define VALUE
void SCH_REFERENCE_LIST::SortByTimeStamp ( )
inline

Function SortComponentsByTimeStamp sort the flat list by Time Stamp.

Useful to detect duplicate Time Stamps

Definition at line 377 of file sch_reference_list.h.

Referenced by CheckAnnotation().

378  {
379  sort( componentFlatList.begin(), componentFlatList.end(), sortByTimeStamp );
380  }
static bool sortByTimeStamp(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
std::vector< SCH_REFERENCE > componentFlatList
bool SCH_REFERENCE_LIST::sortByTimeStamp ( const SCH_REFERENCE item1,
const SCH_REFERENCE item2 
)
staticprivate

Definition at line 131 of file component_references_lister.cpp.

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

133 {
134  int ii = item1.m_SheetPath.Cmp( item2.m_SheetPath );
135 
136  if( ii == 0 )
137  ii = item1.m_TimeStamp - item2.m_TimeStamp;
138 
139  return ii < 0;
140 }
timestamp_t m_TimeStamp
The time stamp for the reference.
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.
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 348 of file sch_reference_list.h.

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

349  {
350  sort( componentFlatList.begin(), componentFlatList.end(), sortByXPosition );
351  }
std::vector< SCH_REFERENCE > componentFlatList
static bool sortByXPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
bool SCH_REFERENCE_LIST::sortByXPosition ( const SCH_REFERENCE item1,
const SCH_REFERENCE item2 
)
staticprivate

Definition at line 54 of file component_references_lister.cpp.

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

56 {
57  int ii = item1.CompareRef( item2 );
58 
59  if( ii == 0 )
60  ii = item1.m_SheetNum - item2.m_SheetNum;
61  if( ii == 0 )
62  ii = item1.m_CmpPos.x - item2.m_CmpPos.x;
63  if( ii == 0 )
64  ii = item1.m_CmpPos.y - item2.m_CmpPos.y;
65  if( ii == 0 )
66  ii = item1.m_TimeStamp - item2.m_TimeStamp;
67 
68  return ii < 0;
69 }
wxPoint m_CmpPos
The physical position of the component in schematic used to annotate by X or Y position.
int m_SheetNum
The sheet number for the reference.
int CompareRef(const SCH_REFERENCE &item) const
timestamp_t m_TimeStamp
The time stamp for the reference.
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 367 of file sch_reference_list.h.

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

368  {
369  sort( componentFlatList.begin(), componentFlatList.end(), sortByYPosition );
370  }
std::vector< SCH_REFERENCE > componentFlatList
static bool sortByYPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
bool SCH_REFERENCE_LIST::sortByYPosition ( const SCH_REFERENCE item1,
const SCH_REFERENCE item2 
)
staticprivate

Definition at line 71 of file component_references_lister.cpp.

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

73 {
74  int ii = item1.CompareRef( item2 );
75 
76  if( ii == 0 )
77  ii = item1.m_SheetNum - item2.m_SheetNum;
78  if( ii == 0 )
79  ii = item1.m_CmpPos.y - item2.m_CmpPos.y;
80  if( ii == 0 )
81  ii = item1.m_CmpPos.x - item2.m_CmpPos.x;
82  if( ii == 0 )
83  ii = item1.m_TimeStamp - item2.m_TimeStamp;
84 
85  return ii < 0;
86 }
wxPoint m_CmpPos
The physical position of the component in schematic used to annotate by X or Y position.
int m_SheetNum
The sheet number for the reference.
int CompareRef(const SCH_REFERENCE &item) const
timestamp_t m_TimeStamp
The time stamp for the reference.
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 275 of file sch_reference_list.h.

References SCH_REFERENCE::Split().

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

276  {
277  for( unsigned ii = 0; ii < GetCount(); ii++ )
278  componentFlatList[ii].Split();
279  }
std::vector< SCH_REFERENCE > componentFlatList
unsigned GetCount()
Function GetCount.
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 288 of file sch_reference_list.h.

References SCH_REFERENCE::Annotate().

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

289  {
290  /* update the reference numbers */
291  for( unsigned ii = 0; ii < GetCount(); ii++ )
292  {
293  componentFlatList[ii].Annotate();
294  }
295  }
std::vector< SCH_REFERENCE > componentFlatList
unsigned GetCount()
Function GetCount.

Member Data Documentation

std::vector<SCH_REFERENCE> SCH_REFERENCE_LIST::componentFlatList
private

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