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, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap)
 Function Annotate set the reference designators in the list that have not been annotated. More...
 
int CheckAnnotation (wxArrayString *aMessageList)
 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 ResetHiddenReferences ()
 Function ResetHiddenReferences clears the annotation for all references that have an invisible reference designator. 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 183 of file sch_reference_list.h.

Constructor & Destructor Documentation

SCH_REFERENCE_LIST::SCH_REFERENCE_LIST ( )
inline

Constructor.

Definition at line 191 of file sch_reference_list.h.

192  {
193  }

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

Referenced by SCH_SHEET_PATH::GetComponents().

224  {
225  componentFlatList.push_back( aItem );
226  }
std::vector< SCH_REFERENCE > componentFlatList
void SCH_REFERENCE_LIST::Annotate ( bool  aUseSheetNum,
int  aSheetIntervalId,
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.
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 286 of file component_references_lister.cpp.

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

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

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

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
aMessageListA wxArrayString to store error messages.
Returns
The number of errors found.

Definition at line 491 of file component_references_lister.cpp.

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

Referenced by SCH_EDIT_FRAME::CheckAnnotate().

492 {
493  int error = 0;
494  wxString tmp;
495  wxString msg;
496 
498 
499  // Spiit reference designators into name (prefix) and number: IC1 becomes IC, and 1.
500  SplitReferences();
501 
502  // count not yet annotated items or annotation error.
503  for( unsigned ii = 0; ii < componentFlatList.size(); ii++ )
504  {
505  msg.Empty();
506  tmp.Empty();
507 
508  if( componentFlatList[ii].m_IsNew ) // Not yet annotated
509  {
510  if( componentFlatList[ii].m_NumRef >= 0 )
511  tmp << componentFlatList[ii].m_NumRef;
512  else
513  tmp = wxT( "?" );
514 
515 
516  if( ( componentFlatList[ii].m_Unit > 0 )
517  && ( componentFlatList[ii].m_Unit < 0x7FFFFFFF ) )
518  {
519  msg.Printf( _( "Item not annotated: %s%s (unit %d)\n" ),
520  GetChars( componentFlatList[ii].GetRef() ),
521  GetChars( tmp ),
522  componentFlatList[ii].m_Unit );
523  }
524  else
525  {
526  msg.Printf( _( "Item not annotated: %s%s\n" ),
527  GetChars( componentFlatList[ii].GetRef() ),
528  GetChars( tmp ) );
529  }
530 
531  if( aMessageList )
532  aMessageList->Add( msg + wxT( "\n" ) );
533 
534  error++;
535  break;
536  }
537 
538  // Error if unit number selected does not exist ( greater than the number of
539  // parts in the component ). This can happen if a component has changed in a
540  // library after a previous annotation.
541  if( std::max( componentFlatList[ii].GetLibPart()->GetUnitCount(), 1 )
542  < componentFlatList[ii].m_Unit )
543  {
544  if( componentFlatList[ii].m_NumRef >= 0 )
545  tmp << componentFlatList[ii].m_NumRef;
546  else
547  tmp = wxT( "?" );
548 
549  msg.Printf( _( "Error item %s%s unit %d and no more than %d parts\n" ),
550  GetChars( componentFlatList[ii].GetRef() ),
551  GetChars( tmp ),
552  componentFlatList[ii].m_Unit,
553  componentFlatList[ii].GetLibPart()->GetUnitCount() );
554 
555  if( aMessageList )
556  aMessageList->Add( msg );
557 
558  error++;
559  break;
560  }
561  }
562 
563  if( error )
564  return error;
565 
566  // count the duplicated elements (if all are annotated)
567  int imax = componentFlatList.size() - 1;
568 
569  for( int ii = 0; (ii < imax) && (error < 4); ii++ )
570  {
571  msg.Empty();
572  tmp.Empty();
573 
574  if( ( componentFlatList[ii].CompareRef( componentFlatList[ii + 1] ) != 0 )
575  || ( componentFlatList[ii].m_NumRef != componentFlatList[ii + 1].m_NumRef ) )
576  continue;
577 
578  // Same reference found. If same unit, error!
579  if( componentFlatList[ii].m_Unit == componentFlatList[ii + 1].m_Unit )
580  {
581  if( componentFlatList[ii].m_NumRef >= 0 )
582  tmp << componentFlatList[ii].m_NumRef;
583  else
584  tmp = wxT( "?" );
585 
586  if( ( componentFlatList[ii].m_Unit > 0 )
587  && ( componentFlatList[ii].m_Unit < 0x7FFFFFFF ) )
588  {
589  msg.Printf( _( "Multiple item %s%s (unit %d)\n" ),
590  GetChars( componentFlatList[ii].GetRef() ),
591  GetChars( tmp ),
592  componentFlatList[ii].m_Unit );
593  }
594  else
595  {
596  msg.Printf( _( "Multiple item %s%s\n" ),
597  GetChars( componentFlatList[ii].GetRef() ),
598  GetChars( tmp ) );
599  }
600 
601  if( aMessageList )
602  aMessageList->Add( msg );
603 
604  error++;
605  continue;
606  }
607 
608  /* Test error if units are different but number of parts per package
609  * too high (ex U3 ( 1 part) and we find U3B this is an error) */
610  if( componentFlatList[ii].GetLibPart()->GetUnitCount()
611  != componentFlatList[ii + 1].GetLibPart()->GetUnitCount() )
612  {
613  if( componentFlatList[ii].m_NumRef >= 0 )
614  tmp << componentFlatList[ii].m_NumRef;
615  else
616  tmp = wxT( "?" );
617 
618  if( ( componentFlatList[ii].m_Unit > 0 )
619  && ( componentFlatList[ii].m_Unit < 0x7FFFFFFF ) )
620  {
621  msg.Printf( _( "Multiple item %s%s (unit %d)\n" ),
622  GetChars( componentFlatList[ii].GetRef() ),
623  GetChars( tmp ),
624  componentFlatList[ii].m_Unit );
625  }
626  else
627  {
628  msg.Printf( _( "Multiple item %s%s\n" ),
629  GetChars( componentFlatList[ii].GetRef() ),
630  GetChars( tmp ) );
631  }
632 
633  if( aMessageList )
634  aMessageList->Add( msg );
635 
636  error++;
637  }
638 
639  // Error if values are different between units, for the same reference
640  int next = ii + 1;
641 
642  if( componentFlatList[ii].CompareValue( componentFlatList[next] ) != 0 )
643  {
644  msg.Printf( _( "Different values for %s%d%s (%s) and %s%d%s (%s)" ),
645  GetChars( componentFlatList[ii].GetRef() ),
646  componentFlatList[ii].m_NumRef,
648  componentFlatList[ii].m_Unit ) ),
649  GetChars( componentFlatList[ii].m_Value->GetText() ),
650  GetChars( componentFlatList[next].GetRef() ),
651  componentFlatList[next].m_NumRef,
653  componentFlatList[next].m_Unit ) ),
654  GetChars( componentFlatList[next].m_Value->GetText() ) );
655 
656  if( aMessageList )
657  aMessageList->Add( msg + wxT( "\n" ));
658 
659  error++;
660  }
661  }
662 
663  // count the duplicated time stamps
664  SortByTimeStamp();
665 
666  for( int ii = 0; ( ii < imax ) && ( error < 4 ); ii++ )
667  {
668  if( ( componentFlatList[ii].m_TimeStamp != componentFlatList[ii + 1].m_TimeStamp )
669  || ( componentFlatList[ii].GetSheetPath() != componentFlatList[ii + 1].GetSheetPath() ) )
670  continue;
671 
672  // Same time stamp found.
673  wxString full_path;
674 
675  full_path.Printf( wxT( "%s%8.8X" ),
676  GetChars( componentFlatList[ii].GetSheetPath().Path() ),
677  componentFlatList[ii].m_TimeStamp );
678 
679  msg.Printf( _( "Duplicate time stamp (%s) for %s%d and %s%d" ),
680  GetChars( full_path ),
681  GetChars( componentFlatList[ii].GetRef() ), componentFlatList[ii].m_NumRef,
682  GetChars( componentFlatList[ii + 1].GetRef() ),
683  componentFlatList[ii + 1].m_NumRef );
684 
685  if( aMessageList )
686  aMessageList->Add( msg + wxT( "\n" ));
687 
688  error++;
689  }
690 
691  return error;
692 }
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)
Function SubReference.
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 251 of file component_references_lister.cpp.

Referenced by Annotate().

252 {
253  int expectedId = aFirstValue;
254 
255  // We search for expected Id a value >= aFirstValue.
256  // Skip existing Id < aFirstValue
257  unsigned ii = 0;
258 
259  for( ; ii < aIdList.size(); ii++ )
260  {
261  if( expectedId <= aIdList[ii] )
262  break;
263  }
264 
265  // Ids are sorted by increasing value, from aFirstValue
266  // So we search from aFirstValue the first not used value, i.e. the first hole in list.
267  for( ; ii < aIdList.size(); ii++ )
268  {
269  if( expectedId != aIdList[ii] ) // This id is not yet used.
270  {
271  // Insert this free Id, in order to keep list sorted
272  aIdList.insert( aIdList.begin() + ii, expectedId );
273  return expectedId;
274  }
275 
276  expectedId++;
277  }
278 
279  // All existing Id are tested, and all values are found in use.
280  // So Create a new one.
281  aIdList.push_back( expectedId );
282  return expectedId;
283 }
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 141 of file component_references_lister.cpp.

References componentFlatList.

Referenced by Annotate().

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

Function GetCount.

Returns
the number of items in the list

Definition at line 204 of file sch_reference_list.h.

Referenced by Annotate(), SCH_EDIT_FRAME::backAnnotateFootprints(), SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile(), SplitReferences(), and UpdateAnnotation().

205  {
206  return componentFlatList.size();
207  }
std::vector< SCH_REFERENCE > componentFlatList
SCH_REFERENCE& SCH_REFERENCE_LIST::GetItem ( int  aIdx)
inline

Function GetItem.

Returns
the aIdx item

Definition at line 213 of file sch_reference_list.h.

214  {
215  return componentFlatList[aIdx];
216  }
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 232 of file component_references_lister.cpp.

References componentFlatList.

Referenced by Annotate().

233 {
234  int lastNumber = aMinValue;
235 
236  for( unsigned ii = 0; ii < componentFlatList.size(); ii++ )
237  {
238  // search only for the current reference prefix:
239  if( componentFlatList[aIndex].CompareRef( componentFlatList[ii] ) != 0 )
240  continue;
241 
242  // update max value for the current reference prefix
243  if( lastNumber < componentFlatList[ii].m_NumRef )
244  lastNumber = componentFlatList[ii].m_NumRef;
245  }
246 
247  return lastNumber;
248 }
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 209 of file component_references_lister.cpp.

References componentFlatList.

Referenced by Annotate().

210 {
211  aIdList.clear();
212 
213  for( unsigned ii = 0; ii < componentFlatList.size(); ii++ )
214  {
215  if( ( componentFlatList[aIndex].CompareRef( componentFlatList[ii] ) == 0 )
216  && ( componentFlatList[ii].m_NumRef >= aMinRefId ) )
217  aIdList.push_back( componentFlatList[ii].m_NumRef );
218  }
219 
220  sort( aIdList.begin(), aIdList.end() );
221 
222  // Ensure each reference number appears only once. If there are components with
223  // multiple parts per package the same number will be stored for each part.
224  std::vector< int >::iterator it = unique( aIdList.begin(), aIdList.end() );
225 
226  // Using the C++ unique algorithm only moves the duplicate entries to the end of
227  // of the array. This removes the duplicate entries from the array.
228  aIdList.resize( it - aIdList.begin() );
229 }
std::vector< SCH_REFERENCE > componentFlatList
SCH_REFERENCE& SCH_REFERENCE_LIST::operator[] ( int  aIndex)
inline

Definition at line 195 of file sch_reference_list.h.

196  {
197  return componentFlatList[ aIndex ];
198  }
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 46 of file component_references_lister.cpp.

References componentFlatList.

47 {
48  if( aIndex < componentFlatList.size() )
49  componentFlatList.erase( componentFlatList.begin() + aIndex );
50 }
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 163 of file component_references_lister.cpp.

References componentFlatList, and SortByReferenceOnly().

164 {
165  SCH_COMPONENT* libItem;
166  wxString oldName;
167  wxString currName;
168 
169  // The component list **MUST** be sorted by reference and by unit number
170  // in order to find all parts of a component
172 
173  for( unsigned ii = 0; ii < componentFlatList.size(); ii++ )
174  {
175 
176  libItem = componentFlatList[ii].m_RootCmp;
177  if( libItem == NULL )
178  continue;
179 
180  currName = componentFlatList[ii].GetRef();
181 
182  if( !oldName.IsEmpty() )
183  {
184  if( oldName == currName ) // currName is a subpart of oldName: remove it
185  {
186  componentFlatList.erase( componentFlatList.begin() + ii );
187  ii--;
188  }
189  }
190 
191  oldName = currName;
192  }
193 }
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:68
void SCH_REFERENCE_LIST::ResetHiddenReferences ( )

Function ResetHiddenReferences clears the annotation for all references that have an invisible reference designator.

Invisible reference designators always have # as the first letter.

Definition at line 196 of file component_references_lister.cpp.

References componentFlatList.

Referenced by Annotate().

197 {
198  for( unsigned ii = 0; ii < componentFlatList.size(); ii++ )
199  {
200  if( componentFlatList[ii].GetRefStr()[0] == '#' )
201  {
202  componentFlatList[ii].m_IsNew = true;
203  componentFlatList[ii].m_NumRef = 0;
204  }
205  }
206 }
std::vector< SCH_REFERENCE > componentFlatList
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 382 of file sch_reference_list.h.

References sortByRefAndValue().

Referenced by CheckAnnotation().

383  {
384  sort( componentFlatList.begin(), componentFlatList.end(), sortByRefAndValue );
385  }
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 88 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.

Referenced by SortByRefAndValue().

90 {
91  int ii = item1.CompareRef( item2 );
92  if( ii == 0 )
93  ii = item1.CompareValue( item2 );
94  if( ii == 0 )
95  ii = item1.m_Unit - item2.m_Unit;
96  if( ii == 0 )
97  ii = item1.m_SheetNum - item2.m_SheetNum;
98  if( ii == 0 )
99  ii = item1.m_CmpPos.x - item2.m_CmpPos.x;
100  if( ii == 0 )
101  ii = item1.m_CmpPos.y - item2.m_CmpPos.y;
102  if( ii == 0 )
103  ii = item1.m_TimeStamp - item2.m_TimeStamp;
104 
105  return ii < 0;
106 }
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
time_t m_TimeStamp
The time stamp for the reference.
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
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 398 of file sch_reference_list.h.

References sortByReferenceOnly().

Referenced by RemoveSubComponentsFromList().

399  {
401  }
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 109 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.

Referenced by SortByReferenceOnly().

111 {
112  int ii;
113 
114  ii = RefDesStringCompare( item1.GetRef(), item2.GetRef() );
115 
116  if( ii == 0 )
117  {
118  ii = item1.m_RootCmp->GetField( VALUE )->GetText().CmpNoCase( item2.m_RootCmp->GetField( VALUE )->GetText() );
119  }
120 
121  if( ii == 0 )
122  {
123  ii = item1.m_Unit - item2.m_Unit;
124  }
125 
126  return ii < 0;
127 }
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:365
int m_Unit
The unit number for components with multiple parts per package.
SCH_FIELD * GetField(int aFieldNdx) const
Function GetField returns a field.
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:130
Field Value of part, i.e. "3.3K".
wxString GetRef() const
void SCH_REFERENCE_LIST::SortByTimeStamp ( )
inline

Function SortComponentsByTimeStamp sort the flat list by Time Stamp.

Useful to detect duplicate Time Stamps

Definition at line 362 of file sch_reference_list.h.

References sortByTimeStamp().

Referenced by CheckAnnotation().

363  {
364  sort( componentFlatList.begin(), componentFlatList.end(), sortByTimeStamp );
365  }
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 130 of file component_references_lister.cpp.

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

Referenced by SortByTimeStamp().

132 {
133  int ii = item1.m_SheetPath.Cmp( item2.m_SheetPath );
134 
135  if( ii == 0 )
136  ii = item1.m_TimeStamp - item2.m_TimeStamp;
137 
138  return ii < 0;
139 }
time_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 333 of file sch_reference_list.h.

References sortByXPosition().

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

334  {
335  sort( componentFlatList.begin(), componentFlatList.end(), sortByXPosition );
336  }
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 53 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.

Referenced by SortByXCoordinate().

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

References sortByYPosition().

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

353  {
354  sort( componentFlatList.begin(), componentFlatList.end(), sortByYPosition );
355  }
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 70 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.

Referenced by SortByYCoordinate().

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

References GetCount().

Referenced by SCH_EDIT_FRAME::AnnotateComponents(), and CheckAnnotation().

263  {
264  for( unsigned ii = 0; ii < GetCount(); ii++ )
265  componentFlatList[ii].Split();
266  }
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 275 of file sch_reference_list.h.

References GetCount().

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

276  {
277  /* update the reference numbers */
278  for( unsigned ii = 0; ii < GetCount(); ii++ )
279  {
280  componentFlatList[ii].Annotate();
281  }
282  }
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: