KiCad PCB EDA Suite
SCH_REFERENCE_LIST Class Reference

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

#include <sch_reference_list.h>

Public Member Functions

 SCH_REFERENCE_LIST ()
 
SCH_REFERENCEoperator[] (int aIndex)
 
const SCH_REFERENCEoperator[] (int aIndex) const
 
void Clear ()
 
size_t GetCount () const
 
SCH_REFERENCEGetItem (int aIdx)
 
const SCH_REFERENCEGetItem (int aIdx) const
 
void AddItem (const SCH_REFERENCE &aItem)
 
void RemoveItem (unsigned int aIndex)
 Remove an item from the list of references. More...
 
bool Contains (const SCH_REFERENCE &aItem) const
 Return true if aItem exists in this list. More...
 
void SplitReferences ()
 Attempt to split all reference designators into a name (U) and number (1). More...
 
void RemoveAnnotation (bool aIncludePowerSymbols)
 Treat all symbols in this list as non-annotated. More...
 
void UpdateAnnotation ()
 Update the symbol references for the schematic project (or the current sheet). More...
 
void ReannotateByOptions (ANNOTATE_ORDER_T aSortOption, ANNOTATE_ALGO_T aAlgoOption, int aStartNumber, const SCH_REFERENCE_LIST &aAdditionalRefs, bool aStartAtCurrent, SCH_SHEET_LIST *aHierarchy)
 Forces reannotation of the provided references. More...
 
void ReannotateDuplicates (const SCH_REFERENCE_LIST &aAdditionalReferences)
 Convenience function for the Paste Unique functionality. More...
 
void AnnotateByOptions (enum ANNOTATE_ORDER_T aSortOption, enum ANNOTATE_ALGO_T aAlgoOption, int aStartNumber, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap, const SCH_REFERENCE_LIST &aAdditionalRefs, bool aStartAtCurrent)
 Annotate the references by the provided options. More...
 
void Annotate (bool aUseSheetNum, int aSheetIntervalId, int aStartNumber, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap, const SCH_REFERENCE_LIST &aAdditionalRefs, bool aStartAtCurrent=false)
 Set the reference designators in the list that have not been annotated. More...
 
int CheckAnnotation (ANNOTATION_ERROR_HANDLER aErrorHandler)
 Check for annotations errors. More...
 
void SortByXCoordinate ()
 Sort the list of references by X position. More...
 
void SortByYCoordinate ()
 Sort the list of references by Y position. More...
 
void SortByTimeStamp ()
 Sort the flat list by Time Stamp (sheet path + timestamp). More...
 
void SortByRefAndValue ()
 Sort the list of references by value. More...
 
void SortByReferenceOnly ()
 Sort the list of references by reference. More...
 
int FindRef (const wxString &aPath) const
 Search the list for a symbol with a given reference. More...
 
int FindUnit (size_t aIndex, int aUnit, bool aIncludeNew=false) const
 Search the sorted list of symbols for a another symbol with the same reference and a given part unit. More...
 
int FindRefByPath (const wxString &aPath) const
 Search the list for a symbol with the given KIID path. More...
 
void GetRefsInUse (int aIndex, std::vector< int > &aIdList, int aMinRefId) const
 Add all the reference designator numbers greater than aMinRefId to aIdList skipping the reference at aIndex. More...
 
std::vector< int > GetUnitsMatchingRef (const SCH_REFERENCE &aRef) const
 Return all the unit numbers for a given reference, comparing library reference, value, reference number and reference prefix. More...
 
int FindFirstUnusedReference (const SCH_REFERENCE &aRef, int aMinValue, const std::vector< int > &aRequiredUnits) const
 Return the first unused reference number from the properties given in aRef, ensuring all of the units in aRequiredUnits are also unused. More...
 
std::vector< SYMBOL_INSTANCE_REFERENCEGetSymbolInstances () const
 

Static Public Member Functions

static wxString Shorthand (std::vector< SCH_REFERENCE > aList)
 Return a shorthand string representing all the references in the list. 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)
 
static int createFirstFreeRefId (std::vector< int > &aIdList, int aFirstValue)
 Search for the first free reference number in aListId of reference numbers in use. More...
 

Private Attributes

std::vector< SCH_REFERENCEflatList
 

Friends

class BACK_ANNOTATION
 
class BACK_ANNOTATE
 

Detailed Description

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

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

Definition at line 241 of file sch_reference_list.h.

Constructor & Destructor Documentation

◆ SCH_REFERENCE_LIST()

SCH_REFERENCE_LIST::SCH_REFERENCE_LIST ( )
inline

Definition at line 248 of file sch_reference_list.h.

249 {
250 }

Member Function Documentation

◆ AddItem()

◆ Annotate()

void SCH_REFERENCE_LIST::Annotate ( bool  aUseSheetNum,
int  aSheetIntervalId,
int  aStartNumber,
SCH_MULTI_UNIT_REFERENCE_MAP  aLockedUnitMap,
const SCH_REFERENCE_LIST aAdditionalRefs,
bool  aStartAtCurrent = false 
)

Set the reference designators in the list that have not been annotated.

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

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.
aAdditionalRefsAdditional references to use for checking that there a reference designator doesn't already exist. The caller must ensure that none of the references in aAdditionalRefs exist in this list.
aStartAtCurrentUse m_numRef for each reference as the start number (overrides aStartNumber)

Definition at line 469 of file component_references_lister.cpp.

472{
473 if ( flatList.size() == 0 )
474 return;
475
476 size_t originalSize = GetCount();
477
478 // For multi units symbols, store the list of already used full references.
479 // The algorithm tries to allocate the new reference to symbols having the same
480 // old reference.
481 // This algo works fine as long as the previous annotation has no duplicates.
482 // But when a hierarchy is reannotated with this option, the previous annotation can
483 // have duplicate references, and obviously we must fix these duplicate.
484 // therefore do not try to allocate a full reference more than once when trying
485 // to keep this order of multi units.
486 // inUseRefs keep trace of previously allocated references
487 std::unordered_set<wxString> inUseRefs;
488
489 for( size_t i = 0; i < aAdditionalRefs.GetCount(); i++ )
490 {
491 SCH_REFERENCE additionalRef = aAdditionalRefs[i];
492 additionalRef.Split();
493
494 // Add the additional reference to the multi-unit set if annotated
495 if( !additionalRef.m_isNew )
496 inUseRefs.insert( buildFullReference( additionalRef ) );
497
498 // We don't want to reannotate the additional references even if not annotated
499 // so we change the m_isNew flag to be false after splitting
500 additionalRef.m_isNew = false;
501 AddItem( additionalRef ); //add to this container
502 }
503
504 int LastReferenceNumber = 0;
505
506 /* calculate index of the first symbol with the same reference prefix
507 * than the current symbol. All symbols having the same reference
508 * prefix will receive a reference number with consecutive values:
509 * IC .. will be set to IC4, IC4, IC5 ...
510 */
511 unsigned first = 0;
512
513 // calculate the last used number for this reference prefix:
514 int minRefId;
515
516 // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
517 if( aUseSheetNum )
518 minRefId = flatList[first].m_sheetNum * aSheetIntervalId + 1;
519 else
520 minRefId = aStartNumber + 1;
521
522
523 for( unsigned ii = 0; ii < flatList.size(); ii++ )
524 {
525 auto& ref_unit = flatList[ii];
526
527 if( ref_unit.m_flag )
528 continue;
529
530 // Check whether this symbol is in aLockedUnitMap.
531 SCH_REFERENCE_LIST* lockedList = nullptr;
532
533 for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : aLockedUnitMap )
534 {
535 unsigned n_refs = pair.second.GetCount();
536
537 for( unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI )
538 {
539 SCH_REFERENCE &thisRef = pair.second[thisRefI];
540
541 if( thisRef.IsSameInstance( ref_unit ) )
542 {
543 lockedList = &pair.second;
544 break;
545 }
546 }
547
548 if( lockedList != nullptr )
549 break;
550 }
551
552 if( ( flatList[first].CompareRef( ref_unit ) != 0 )
553 || ( aUseSheetNum && ( flatList[first].m_sheetNum != ref_unit.m_sheetNum ) ) )
554 {
555 // New reference found: we need a new ref number for this reference
556 first = ii;
557
558 // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
559 if( aUseSheetNum )
560 minRefId = ref_unit.m_sheetNum * aSheetIntervalId + 1;
561 else
562 minRefId = aStartNumber + 1;
563 }
564
565 // Find references greater than current reference (unless not annotated)
566 if( aStartAtCurrent && ref_unit.m_numRef > 0 )
567 minRefId = ref_unit.m_numRef;
568
569 // Annotation of one part per package symbols (trivial case).
570 if( ref_unit.GetLibPart()->GetUnitCount() <= 1 )
571 {
572 if( ref_unit.m_isNew )
573 {
574 std::vector<int> idList;
575 GetRefsInUse( first, idList, minRefId );
576 LastReferenceNumber = createFirstFreeRefId( idList, minRefId );
577 ref_unit.m_numRef = LastReferenceNumber;
578 }
579
580 ref_unit.m_flag = 1;
581 ref_unit.m_isNew = false;
582 continue;
583 }
584
585 // If this symbol is in aLockedUnitMap, copy the annotation to all
586 // symbols that are not it
587 if( lockedList != nullptr )
588 {
589 unsigned n_refs = lockedList->GetCount();
590 std::vector<int> units = lockedList->GetUnitsMatchingRef( ref_unit );
591
592 if( ref_unit.m_isNew )
593 {
594 LastReferenceNumber = FindFirstUnusedReference( ref_unit, minRefId, units );
595 ref_unit.m_numRef = LastReferenceNumber;
596 ref_unit.m_isNew = false;
597 ref_unit.m_flag = 1;
598 }
599
600 for( unsigned lockedRefI = 0; lockedRefI < n_refs; ++lockedRefI )
601 {
602 SCH_REFERENCE& lockedRef = ( *lockedList )[lockedRefI];
603
604 if( lockedRef.IsSameInstance( ref_unit ) )
605 {
606 // This is the symbol we're currently annotating. Hold the unit!
607 ref_unit.m_unit = lockedRef.m_unit;
608 // lock this new full reference
609 inUseRefs.insert( buildFullReference( ref_unit ) );
610 }
611
612 if( lockedRef.CompareValue( ref_unit ) != 0 )
613 continue;
614
615 if( lockedRef.CompareLibName( ref_unit ) != 0 )
616 continue;
617
618 // Find the matching symbol
619 for( unsigned jj = ii + 1; jj < flatList.size(); jj++ )
620 {
621 if( !lockedRef.IsSameInstance( flatList[jj] ) )
622 continue;
623
624 wxString ref_candidate = buildFullReference( ref_unit, lockedRef.m_unit );
625
626 // propagate the new reference and unit selection to the "old" symbol,
627 // if this new full reference is not already used (can happens when initial
628 // multiunits symbols have duplicate references)
629 if( inUseRefs.find( ref_candidate ) == inUseRefs.end() )
630 {
631 flatList[jj].m_numRef = ref_unit.m_numRef;
632 flatList[jj].m_isNew = false;
633 flatList[jj].m_flag = 1;
634 // lock this new full reference
635 inUseRefs.insert( ref_candidate );
636 break;
637 }
638 }
639 }
640 }
641 else if( ref_unit.m_isNew )
642 {
643 // Reference belonging to multi-unit symbol that has not yet been annotated. We don't
644 // know what group this might belong to, so just find the first unused reference for
645 // this specific unit. The other units will be annotated in the following passes.
646 std::vector<int> units = { ref_unit.GetUnit() };
647 LastReferenceNumber = FindFirstUnusedReference( ref_unit, minRefId, units );
648 ref_unit.m_numRef = LastReferenceNumber;
649 ref_unit.m_isNew = false;
650 ref_unit.m_flag = 1;
651 }
652 }
653
654 // Remove aAdditionalRefs references
655 for( size_t i = originalSize; i < ( aAdditionalRefs.GetCount() + originalSize ); i++ )
656 RemoveItem( originalSize );
657
658 wxASSERT( originalSize == GetCount() ); // Make sure we didn't make a mistake
659}
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
static int createFirstFreeRefId(std::vector< int > &aIdList, int aFirstValue)
Search for the first free reference number in aListId of reference numbers in use.
size_t GetCount() const
int FindFirstUnusedReference(const SCH_REFERENCE &aRef, int aMinValue, const std::vector< int > &aRequiredUnits) const
Return the first unused reference number from the properties given in aRef, ensuring all of the units...
std::vector< int > GetUnitsMatchingRef(const SCH_REFERENCE &aRef) const
Return all the unit numbers for a given reference, comparing library reference, value,...
void GetRefsInUse(int aIndex, std::vector< int > &aIdList, int aMinRefId) const
Add all the reference designator numbers greater than aMinRefId to aIdList skipping the reference at ...
void AddItem(const SCH_REFERENCE &aItem)
void RemoveItem(unsigned int aIndex)
Remove an item from the list of references.
A helper to define a symbol's reference designator in a schematic.
int m_unit
The unit number for symbol with multiple parts per package.
int CompareLibName(const SCH_REFERENCE &item) const
bool m_isNew
True if not yet annotated.
void Split()
Attempt to split the reference designator into a name (U) and number (1).
bool IsSameInstance(const SCH_REFERENCE &other) const
Return whether this reference refers to the same symbol instance (symbol and sheet) as another.
int CompareValue(const SCH_REFERENCE &item) const
wxString buildFullReference(const SCH_REFERENCE &aItem, int aUnitNumber=-1)

References AddItem(), buildFullReference(), SCH_REFERENCE::CompareLibName(), SCH_REFERENCE::CompareValue(), createFirstFreeRefId(), FindFirstUnusedReference(), flatList, GetCount(), GetRefsInUse(), GetUnitsMatchingRef(), SCH_REFERENCE::IsSameInstance(), SCH_REFERENCE::m_isNew, SCH_REFERENCE::m_unit, RemoveItem(), and SCH_REFERENCE::Split().

Referenced by AnnotateByOptions(), SCH_SHEET_LIST::AnnotatePowerSymbols(), and UpdateAnnotation().

◆ AnnotateByOptions()

void SCH_REFERENCE_LIST::AnnotateByOptions ( enum ANNOTATE_ORDER_T  aSortOption,
enum ANNOTATE_ALGO_T  aAlgoOption,
int  aStartNumber,
SCH_MULTI_UNIT_REFERENCE_MAP  aLockedUnitMap,
const SCH_REFERENCE_LIST aAdditionalRefs,
bool  aStartAtCurrent 
)

Annotate the references by the provided options.

Parameters
aSortOptionDefine the annotation order. See ANNOTATE_ORDER_T.
aAlgoOptionDefine the annotation style. See ANNOTATE_ALGO_T.
aStartNumberThe start number for non-sheet-based annotation styles.
appendUndoTrue if the annotation operation should be added to an existing undo, false if it should be separately undo-able.
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.
aAdditionalReferencesAdditional references to check for duplicates
aStartAtCurrentUse m_numRef for each reference as the start number (overrides aStartNumber)

Definition at line 427 of file component_references_lister.cpp.

433{
434 switch( aSortOption )
435 {
436 default:
439 }
440
441 bool useSheetNum;
442 int idStep;
443
444 switch( aAlgoOption )
445 {
446 default:
448 useSheetNum = false;
449 idStep = 1;
450 break;
451
453 useSheetNum = true;
454 idStep = 100;
455 aStartAtCurrent = false; // Not implemented for sheet # * 100
456 break;
457
459 useSheetNum = true;
460 idStep = 1000;
461 aStartAtCurrent = false; // Not implemented for sheet # * 1000
462 break;
463 }
464
465 Annotate( useSheetNum, idStep, aStartNumber, aLockedUnitMap, aAdditionalRefs, aStartAtCurrent );
466}
void SortByYCoordinate()
Sort the list of references by Y position.
void Annotate(bool aUseSheetNum, int aSheetIntervalId, int aStartNumber, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap, const SCH_REFERENCE_LIST &aAdditionalRefs, bool aStartAtCurrent=false)
Set the reference designators in the list that have not been annotated.
void SortByXCoordinate()
Sort the list of references by X position.
@ SORT_BY_X_POSITION
Annotate by X position from left to right.
@ SORT_BY_Y_POSITION
Annotate by Y position from top to bottom.
@ SHEET_NUMBER_X_1000
Annotate using the first free reference number starting at the sheet number * 1000.
@ INCREMENTAL_BY_REF
Annotate incrementally using the first free reference number.
@ SHEET_NUMBER_X_100
Annotate using the first free reference number starting at the sheet number * 100.

References Annotate(), INCREMENTAL_BY_REF, SHEET_NUMBER_X_100, SHEET_NUMBER_X_1000, SORT_BY_X_POSITION, SORT_BY_Y_POSITION, SortByXCoordinate(), and SortByYCoordinate().

Referenced by SCH_EDIT_FRAME::AnnotateSymbols(), and ReannotateByOptions().

◆ CheckAnnotation()

int SCH_REFERENCE_LIST::CheckAnnotation ( ANNOTATION_ERROR_HANDLER  aErrorHandler)

Check for annotations errors.

The following annotation error conditions are tested:

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

Definition at line 662 of file component_references_lister.cpp.

663{
664 int error = 0;
665 wxString tmp;
666 wxString msg;
667
669
670 // Split reference designators into name (prefix) and number: IC1 becomes IC, and 1.
672
673 // count not yet annotated items or annotation error.
674 for( unsigned ii = 0; ii < flatList.size(); ii++ )
675 {
676 msg.Empty();
677 tmp.Empty();
678
679 if( flatList[ii].m_isNew ) // Not yet annotated
680 {
681 if( flatList[ii].m_numRef >= 0 )
682 tmp << flatList[ii].m_numRef;
683 else
684 tmp = wxT( "?" );
685
686 if( ( flatList[ii].m_unit > 0 ) && ( flatList[ii].m_unit < 0x7FFFFFFF ) )
687 {
688 msg.Printf( _( "Item not annotated: %s%s (unit %d)" ),
689 flatList[ii].GetRef(),
690 tmp,
691 flatList[ii].m_unit );
692 }
693 else
694 {
695 msg.Printf( _( "Item not annotated: %s%s" ), flatList[ii].GetRef(), tmp );
696 }
697
698 aHandler( ERCE_UNANNOTATED, msg, &flatList[ii], nullptr );
699 error++;
700 break;
701 }
702
703 // Error if unit number selected does not exist (greater than the number of units in
704 // the symbol). This can happen if a symbol has changed in a library after a
705 // previous annotation.
706 if( std::max( flatList[ii].GetLibPart()->GetUnitCount(), 1 ) < flatList[ii].m_unit )
707 {
708 if( flatList[ii].m_numRef >= 0 )
709 tmp << flatList[ii].m_numRef;
710 else
711 tmp = wxT( "?" );
712
713 msg.Printf( _( "Error: symbol %s%s%s (unit %d) exceeds units defined (%d)" ),
714 flatList[ii].GetRef(),
715 tmp,
717 flatList[ii].m_unit,
718 flatList[ii].GetLibPart()->GetUnitCount() );
719
720 aHandler( ERCE_EXTRA_UNITS, msg, &flatList[ii], nullptr );
721 error++;
722 break;
723 }
724 }
725
726 // count the duplicated elements (if all are annotated)
727 int imax = flatList.size() - 1;
728
729 for( int ii = 0; ii < imax; ii++ )
730 {
731 msg.Empty();
732 tmp.Empty();
733
734 if( ( flatList[ii].CompareRef( flatList[ii + 1] ) != 0 )
735 || ( flatList[ii].m_numRef != flatList[ ii + 1].m_numRef ) )
736 {
737 continue;
738 }
739
740 // Same reference found. If same unit, error!
741 if( flatList[ii].m_unit == flatList[ ii + 1].m_unit )
742 {
743 if( flatList[ii].m_numRef >= 0 )
744 tmp << flatList[ii].m_numRef;
745 else
746 tmp = wxT( "?" );
747
748 if( ( flatList[ii].GetLibPart()->GetUnitCount() > 1 )
749 && ( flatList[ii].m_unit > 0 )
750 && ( flatList[ii].m_unit < 0x7FFFFFFF ) )
751 {
752 msg.Printf( _( "Duplicate items %s%s%s\n" ),
753 flatList[ii].GetRef(),
754 tmp,
755 LIB_SYMBOL::SubReference( flatList[ii].m_unit ) );
756 }
757 else
758 {
759 msg.Printf( _( "Duplicate items %s%s\n" ), flatList[ii].GetRef(), tmp );
760 }
761
762 aHandler( ERCE_DUPLICATE_REFERENCE, msg, &flatList[ii], &flatList[ii+1] );
763 error++;
764 continue;
765 }
766
767 /* Test error if units are different but number of parts per package
768 * too high (ex U3 ( 1 part) and we find U3B this is an error) */
769 if( flatList[ii].GetLibPart()->GetUnitCount()
770 != flatList[ ii + 1].GetLibPart()->GetUnitCount() )
771 {
772 if( flatList[ii].m_numRef >= 0 )
773 tmp << flatList[ii].m_numRef;
774 else
775 tmp = wxT( "?" );
776
777 if( ( flatList[ii].m_unit > 0 )
778 && ( flatList[ii].m_unit < 0x7FFFFFFF ) )
779 {
780 msg.Printf( _( "Duplicate items %s%s%s\n" ),
781 flatList[ii].GetRef(),
782 tmp,
783 LIB_SYMBOL::SubReference( flatList[ii].m_unit ) );
784 }
785 else
786 {
787 msg.Printf( _( "Duplicate items %s%s\n" ), flatList[ii].GetRef(), tmp );
788 }
789
790 aHandler( ERCE_DUPLICATE_REFERENCE, msg, &flatList[ii], &flatList[ii+1] );
791 error++;
792 }
793
794 // Error if values are different between units, for the same reference
795 int next = ii + 1;
796
797 if( flatList[ii].CompareValue( flatList[next] ) != 0 )
798 {
799 msg.Printf( _( "Different values for %s%d%s (%s) and %s%d%s (%s)" ),
800 flatList[ii].GetRef(),
801 flatList[ii].m_numRef,
803 flatList[ii].m_value,
804 flatList[next].GetRef(),
805 flatList[next].m_numRef,
807 flatList[next].m_value );
808
809 aHandler( ERCE_DIFFERENT_UNIT_VALUE, msg, &flatList[ii], &flatList[ii+1] );
810 error++;
811 }
812 }
813
814 return error;
815}
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Definition: lib_symbol.cpp:588
void SplitReferences()
Attempt to split all reference designators into a name (U) and number (1).
void SortByRefAndValue()
Sort the list of references by value.
#define _(s)
@ ERCE_UNANNOTATED
Symbol has not been annotated.
Definition: erc_settings.h:70
@ ERCE_DUPLICATE_REFERENCE
More than one symbol with the same reference.
Definition: erc_settings.h:73
@ ERCE_EXTRA_UNITS
Symbol has more units than are defined.
Definition: erc_settings.h:71
@ ERCE_DIFFERENT_UNIT_VALUE
Units of same symbol have different values.
Definition: erc_settings.h:72
CITER next(CITER it)
Definition: ptree.cpp:126

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

Referenced by SCH_EDIT_FRAME::CheckAnnotate().

◆ Clear()

void SCH_REFERENCE_LIST::Clear ( )
inline

Definition at line 262 of file sch_reference_list.h.

263 {
264 flatList.clear();
265 }

References flatList.

Referenced by TEST_SCH_REFERENCE_LIST_FIXTURE::loadTestCase().

◆ Contains()

bool SCH_REFERENCE_LIST::Contains ( const SCH_REFERENCE aItem) const

Return true if aItem exists in this list.

Parameters
aItemReference to check
Returns
true if aItem exists in this list

Definition at line 52 of file component_references_lister.cpp.

53{
54 for( unsigned ii = 0; ii < GetCount(); ii++ )
55 {
56 if( flatList[ii].IsSameInstance( aItem ) )
57 return true;
58 }
59
60 return false;
61}

References flatList, and GetCount().

Referenced by SCH_EDIT_FRAME::AnnotateSymbols(), and TEST_SCH_REFERENCE_LIST_FIXTURE::getAdditionalRefs().

◆ createFirstFreeRefId()

int SCH_REFERENCE_LIST::createFirstFreeRefId ( std::vector< int > &  aIdList,
int  aFirstValue 
)
staticprivate

Search for the first free reference number in aListId of reference numbers in use.

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

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

Definition at line 329 of file component_references_lister.cpp.

330{
331 int expectedId = aFirstValue;
332
333 // We search for expected Id a value >= aFirstValue.
334 // Skip existing Id < aFirstValue
335 unsigned ii = 0;
336
337 for( ; ii < aIdList.size(); ii++ )
338 {
339 if( expectedId <= aIdList[ii] )
340 break;
341 }
342
343 // Ids are sorted by increasing value, from aFirstValue
344 // So we search from aFirstValue the first not used value, i.e. the first hole in list.
345 for( ; ii < aIdList.size(); ii++ )
346 {
347 if( expectedId != aIdList[ii] ) // This id is not yet used.
348 {
349 // Insert this free Id, in order to keep list sorted
350 aIdList.insert( aIdList.begin() + ii, expectedId );
351 return expectedId;
352 }
353
354 expectedId++;
355 }
356
357 // All existing Id are tested, and all values are found in use.
358 // So Create a new one.
359 aIdList.push_back( expectedId );
360 return expectedId;
361}

Referenced by Annotate().

◆ FindFirstUnusedReference()

int SCH_REFERENCE_LIST::FindFirstUnusedReference ( const SCH_REFERENCE aRef,
int  aMinValue,
const std::vector< int > &  aRequiredUnits 
) const

Return the first unused reference number from the properties given in aRef, ensuring all of the units in aRequiredUnits are also unused.

Parameters
aIndexThe index of the reference item used for the search pattern.
aMinValueThe minimum value for the current search.
aRequiredUnitsList of units to ensure are free

Definition at line 260 of file component_references_lister.cpp.

262{
263 // Create a map of references indexed by reference number, only including those with the same
264 // reference prefix as aRef
265 std::map<int, std::vector<SCH_REFERENCE>> refNumberMap;
266
267 for( const SCH_REFERENCE& ref : flatList )
268 {
269 // search only for the current reference prefix:
270 if( ref.CompareRef( aRef ) != 0 )
271 continue;
272
273 if( ref.m_isNew )
274 continue; // It will be reannotated
275
276 refNumberMap[ref.m_numRef].push_back( ref );
277 }
278
279 // Start at the given minimum value
280 int minFreeNumber = aMinValue;
281
282 for( ; refNumberMap[minFreeNumber].size() > 0; ++minFreeNumber )
283 {
284 auto isNumberInUse = [&]() -> bool
285 {
286 for( const int& unit : aRequiredUnits )
287 {
288 for( const SCH_REFERENCE& ref : refNumberMap[minFreeNumber] )
289 {
290 if( ref.CompareLibName( aRef ) || ref.CompareValue( aRef )
291 || ref.GetUnit() == unit )
292 {
293 return true;
294 }
295 }
296 }
297
298 return false;
299 };
300
301 if( !isNumberInUse() )
302 return minFreeNumber;
303 }
304
305 return minFreeNumber;
306}

References flatList.

Referenced by Annotate().

◆ FindRef()

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

Search the list for a symbol with a given reference.

Definition at line 190 of file component_references_lister.cpp.

191{
192 for( size_t i = 0; i < flatList.size(); ++i )
193 {
194 if( flatList[i].GetRef() == aRef )
195 return i;
196 }
197
198 return -1;
199}

References flatList.

Referenced by BACK_ANNOTATE::getChangeList().

◆ FindRefByPath()

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

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

Parameters
aPathis the path to search.
Returns
index in aSymbolsList if found or -1 if not found.

Definition at line 178 of file component_references_lister.cpp.

179{
180 for( size_t i = 0; i < flatList.size(); ++i )
181 {
182 if( flatList[i].GetPath() == aPath )
183 return i;
184 }
185
186 return -1;
187}

References flatList.

Referenced by BACK_ANNOTATE::getChangeList().

◆ FindUnit()

int SCH_REFERENCE_LIST::FindUnit ( size_t  aIndex,
int  aUnit,
bool  aIncludeNew = false 
) const

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

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

Parameters
aIndexis the index in aSymbolsList for of given SCH_REFERENCE item to test.
aUnitis the given unit number to search.
aIncludeNewtrue to include references with the "new" flag in the search.
Returns
index in aSymbolsList if found or -1 if not found.

Definition at line 158 of file component_references_lister.cpp.

159{
160 int NumRef = flatList[aIndex].m_numRef;
161
162 for( size_t ii = 0; ii < flatList.size(); ii++ )
163 {
164 if( ( aIndex == ii )
165 || ( flatList[ii].m_isNew && !aIncludeNew )
166 || ( flatList[ii].m_numRef != NumRef )
167 || ( flatList[aIndex].CompareRef( flatList[ii] ) != 0 ) )
168 continue;
169
170 if( flatList[ii].m_unit == aUnit )
171 return (int) ii;
172 }
173
174 return -1;
175}

References flatList.

◆ GetCount()

◆ GetItem() [1/2]

SCH_REFERENCE & SCH_REFERENCE_LIST::GetItem ( int  aIdx)
inline

Definition at line 269 of file sch_reference_list.h.

269{ return flatList[aIdx]; }

References flatList.

Referenced by ERC_TESTER::TestMultiunitFootprints().

◆ GetItem() [2/2]

const SCH_REFERENCE & SCH_REFERENCE_LIST::GetItem ( int  aIdx) const
inline

Definition at line 270 of file sch_reference_list.h.

270{ return flatList[aIdx]; }

References flatList.

◆ GetRefsInUse()

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

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

Parameters
aIndexis the current symbol's index to use for reference prefix filtering.
aIdListis the buffer to fill.
aMinRefIdis the minimum ID value to store. All values < aMinRefId are ignored.

Definition at line 202 of file component_references_lister.cpp.

204{
205 aIdList.clear();
206
207 for( const SCH_REFERENCE& ref : flatList )
208 {
209 // Don't add new references to the list as we will reannotate those
210 if( flatList[aIndex].CompareRef( ref ) == 0 && ref.m_numRef >= aMinRefId && !ref.m_isNew )
211 aIdList.push_back( ref.m_numRef );
212 }
213
214 std::sort( aIdList.begin(), aIdList.end() );
215
216 // Ensure each reference number appears only once. If there are symbols with
217 // multiple parts per package the same number will be stored for each part.
218 alg::remove_duplicates( aIdList );
219}
void remove_duplicates(_Container &__c)
Deletes all duplicate values from __c.
Definition: kicad_algo.h:182

References flatList, and alg::remove_duplicates().

Referenced by Annotate().

◆ GetSymbolInstances()

std::vector< SYMBOL_INSTANCE_REFERENCE > SCH_REFERENCE_LIST::GetSymbolInstances ( ) const

Definition at line 309 of file component_references_lister.cpp.

310{
311 std::vector<SYMBOL_INSTANCE_REFERENCE> retval;
312
313 for( const SCH_REFERENCE& ref : flatList )
314 {
316 instance.m_Path = ref.GetSheetPath().Path();
317 instance.m_Reference = ref.GetRef();
318 instance.m_Unit = ref.GetUnit();
319 instance.m_Value = ref.GetValue();
320 instance.m_Footprint = ref.GetFootprint();
321
322 retval.push_back( instance );
323 }
324
325 return retval;
326}
A simple container for schematic symbol instance information.

References flatList, SYMBOL_INSTANCE_REFERENCE::m_Footprint, SYMBOL_INSTANCE_REFERENCE::m_Path, SYMBOL_INSTANCE_REFERENCE::m_Reference, SYMBOL_INSTANCE_REFERENCE::m_Unit, and SYMBOL_INSTANCE_REFERENCE::m_Value.

Referenced by SCH_SEXPR_PLUGIN::Format().

◆ GetUnitsMatchingRef()

std::vector< int > SCH_REFERENCE_LIST::GetUnitsMatchingRef ( const SCH_REFERENCE aRef) const

Return all the unit numbers for a given reference, comparing library reference, value, reference number and reference prefix.

Parameters
aRefis the index of a symbol to use for reference prefix and number filtering.

Definition at line 222 of file component_references_lister.cpp.

223{
224 std::vector<int> unitsList;
225
226 // Always add this reference to the list
227 unitsList.push_back( aRef.m_unit );
228
229 for( SCH_REFERENCE ref : flatList )
230 {
231 if( ref.CompareValue( aRef ) != 0 )
232 continue;
233
234 if( ref.CompareLibName( aRef ) != 0 )
235 continue;
236
237 // Split if needed before comparing ref and number
238 if( ref.IsSplitNeeded() )
239 ref.Split();
240
241 if( ref.CompareRef( aRef ) != 0 )
242 continue;
243
244 if( ref.m_numRef != aRef.m_numRef )
245 continue;
246
247 unitsList.push_back( ref.m_unit );
248 }
249
250 std::sort( unitsList.begin(), unitsList.end() );
251
252 // Ensure each reference number appears only once. If there are symbols with
253 // multiple parts per package the same number will be stored for each part.
254 alg::remove_duplicates( unitsList );
255
256 return unitsList;
257}
int m_numRef
The numeric part of the reference designator.

References flatList, SCH_REFERENCE::m_numRef, SCH_REFERENCE::m_unit, and alg::remove_duplicates().

Referenced by Annotate().

◆ operator[]() [1/2]

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

Definition at line 252 of file sch_reference_list.h.

253 {
254 return flatList[ aIndex ];
255 }

References flatList.

◆ operator[]() [2/2]

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

Definition at line 257 of file sch_reference_list.h.

258 {
259 return flatList[ aIndex ];
260 }

References flatList.

◆ ReannotateByOptions()

void SCH_REFERENCE_LIST::ReannotateByOptions ( ANNOTATE_ORDER_T  aSortOption,
ANNOTATE_ALGO_T  aAlgoOption,
int  aStartNumber,
const SCH_REFERENCE_LIST aAdditionalRefs,
bool  aStartAtCurrent,
SCH_SHEET_LIST aHierarchy 
)

Forces reannotation of the provided references.

Will also reannotate associated multi-unit symbols.

Parameters
aSortOptionDefine the annotation order. See ANNOTATE_ORDER_T.
aAlgoOptionDefine the annotation style. See ANNOTATE_ALGO_T.
aStartNumberThe start number for non-sheet-based annotation styles.
aAdditionalReferencesAdditional references to check for duplicates
aStartAtCurrentUse m_numRef for each reference as the start number (overrides aStartNumber)
aHierarchyOptional sheet path hierarchy for resetting the references' sheet numbers based on their sheet's place in the hierarchy. Set nullptr if not desired.

Definition at line 379 of file component_references_lister.cpp.

385{
387
388 // All multi-unit symbols always locked to ensure consistent re-annotation
389 SCH_MULTI_UNIT_REFERENCE_MAP lockedSymbols;
390
391 for( size_t i = 0; i < GetCount(); i++ )
392 {
393 SCH_REFERENCE& ref = flatList[i];
394 wxString refstr = ref.GetSymbol()->GetRef( &ref.GetSheetPath() );
395
396 // Update sheet numbers based on the reference's sheet's position within the full
397 // hierarchy; we do this now before we annotate so annotation by sheet number * X
398 // works correctly.
399 if( aHierarchy )
400 {
401 SCH_SHEET_PATH* path = aHierarchy->FindSheetForPath( &ref.GetSheetPath() );
402 wxASSERT_MSG( path, wxT( "Attempting to annotate item on sheet not part of the hierarchy?" ) );
403
404 ref.SetSheetNumber( path->GetVirtualPageNumber() );
405 }
406
407 // Never lock unassigned references
408 if( refstr[refstr.Len() - 1] == '?' )
409 continue;
410
411 ref.m_isNew = true; // We want to reannotate all references
412
413 lockedSymbols[refstr].AddItem( ref );
414 }
415
416 AnnotateByOptions( aSortOption, aAlgoOption, aStartNumber, lockedSymbols, aAdditionalRefs,
417 aStartAtCurrent );
418}
void AnnotateByOptions(enum ANNOTATE_ORDER_T aSortOption, enum ANNOTATE_ALGO_T aAlgoOption, int aStartNumber, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap, const SCH_REFERENCE_LIST &aAdditionalRefs, bool aStartAtCurrent)
Annotate the references by the provided options.
const SCH_SHEET_PATH & GetSheetPath() const
SCH_SYMBOL * GetSymbol() const
void SetSheetNumber(int aSheetNumber)
SCH_SHEET_PATH * FindSheetForPath(const SCH_SHEET_PATH *aPath)
Return a pointer to the first SCH_SHEET_PATH object (not necessarily the only one) matching the provi...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:632
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.

References AnnotateByOptions(), SCH_SHEET_LIST::FindSheetForPath(), flatList, GetCount(), SCH_SYMBOL::GetRef(), SCH_REFERENCE::GetSheetPath(), SCH_REFERENCE::GetSymbol(), SCH_REFERENCE::m_isNew, path, SCH_REFERENCE::SetSheetNumber(), and SplitReferences().

Referenced by SCH_DRAWING_TOOLS::PlaceSymbol(), and ReannotateDuplicates().

◆ ReannotateDuplicates()

void SCH_REFERENCE_LIST::ReannotateDuplicates ( const SCH_REFERENCE_LIST aAdditionalReferences)

Convenience function for the Paste Unique functionality.

Do not use as a general reannotation method.

Replaces any duplicate reference designators with the next available number after the present number regardless of configured annotation options.

Multi-unit symbols are reannotated together.

Definition at line 421 of file component_references_lister.cpp.

422{
423 ReannotateByOptions( UNSORTED, INCREMENTAL_BY_REF, 0, aAdditionalReferences, true, nullptr );
424}
void ReannotateByOptions(ANNOTATE_ORDER_T aSortOption, ANNOTATE_ALGO_T aAlgoOption, int aStartNumber, const SCH_REFERENCE_LIST &aAdditionalRefs, bool aStartAtCurrent, SCH_SHEET_LIST *aHierarchy)
Forces reannotation of the provided references.
@ UNSORTED
Annotate by position of symbol in the schematic sheet object list.

References INCREMENTAL_BY_REF, ReannotateByOptions(), and UNSORTED.

◆ RemoveAnnotation()

void SCH_REFERENCE_LIST::RemoveAnnotation ( bool  aIncludePowerSymbols)
inline

Treat all symbols in this list as non-annotated.

Does not update annotation state of the symbols.

See also
SCH_REFERENCE_LIST::UpdateAnnotation

Definition at line 315 of file sch_reference_list.h.

316 {
317 for( unsigned ii = 0; ii < GetCount(); ii++ )
318 {
319 if( !flatList[ii].m_libPart->IsPower() || aIncludePowerSymbols )
320 flatList[ii].m_isNew = true;
321 }
322 }

References flatList, and GetCount().

Referenced by SCH_EDIT_FRAME::AnnotateSymbols().

◆ RemoveItem()

void SCH_REFERENCE_LIST::RemoveItem ( unsigned int  aIndex)

Remove an item from the list of references.

Parameters
aIndexis the index of the item to be removed.

Definition at line 45 of file component_references_lister.cpp.

46{
47 if( aIndex < flatList.size() )
48 flatList.erase( flatList.begin() + aIndex );
49}

References flatList.

Referenced by Annotate().

◆ Shorthand()

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

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

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

Definition at line 919 of file component_references_lister.cpp.

920{
921 wxString retVal;
922 size_t i = 0;
923
924 while( i < aList.size() )
925 {
926 wxString ref = aList[ i ].GetRef();
927 int numRef = aList[ i ].m_numRef;
928
929 size_t range = 1;
930
931 while( i + range < aList.size()
932 && aList[ i + range ].GetRef() == ref
933 && aList[ i + range ].m_numRef == int( numRef + range ) )
934 {
935 range++;
936 }
937
938 if( !retVal.IsEmpty() )
939 retVal << wxT( ", " );
940
941 if( range == 1 )
942 {
943 retVal << ref << aList[ i ].GetRefNumber();
944 }
945 else if( range == 2 )
946 {
947 retVal << ref << aList[ i ].GetRefNumber();
948 retVal << wxT( ", " );
949 retVal << ref << aList[ i + 1 ].GetRefNumber();
950 }
951 else
952 {
953 retVal << ref << aList[ i ].GetRefNumber();
954 retVal << wxT( "-" );
955 retVal << ref << aList[ i + ( range - 1 ) ].GetRefNumber();
956 }
957
958 i+= range;
959 }
960
961 return retVal;
962}

Referenced by FIELDS_EDITOR_GRID_DATA_MODEL::GetValue().

◆ SortByRefAndValue()

void SCH_REFERENCE_LIST::SortByRefAndValue ( )
inline

Sort the list of references by value.

Symbols are sorted in the following order:

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

Definition at line 483 of file sch_reference_list.h.

484 {
485 sort( flatList.begin(), flatList.end(), sortByRefAndValue );
486 }
static bool sortByRefAndValue(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)

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

106{
107 int ii = item1.CompareRef( item2 );
108
109 if( ii == 0 )
110 ii = item1.CompareValue( item2 );
111
112 if( ii == 0 )
113 ii = item1.m_unit - item2.m_unit;
114
115 if( ii == 0 )
116 ii = item1.m_sheetNum - item2.m_sheetNum;
117
118 if( ii == 0 )
119 ii = item1.m_symbolPos.x - item2.m_symbolPos.x;
120
121 if( ii == 0 )
122 ii = item1.m_symbolPos.y - item2.m_symbolPos.y;
123
124 if( ii == 0 )
125 return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
126 else
127 return ii < 0;
128}
int CompareRef(const SCH_REFERENCE &item) const
int m_sheetNum
The sheet number for the reference.
KIID m_symbolUuid
UUID of the symbol.
VECTOR2I m_symbolPos
The physical position of the symbol in schematic used to annotate by X or Y position.

References SCH_REFERENCE::CompareRef(), SCH_REFERENCE::CompareValue(), SCH_REFERENCE::m_sheetNum, SCH_REFERENCE::m_symbolPos, SCH_REFERENCE::m_symbolUuid, SCH_REFERENCE::m_unit, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SortByRefAndValue().

◆ SortByReferenceOnly()

void SCH_REFERENCE_LIST::SortByReferenceOnly ( )
inline

Sort the list of references by reference.

Symbols are sorted in the following order:

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

Definition at line 495 of file sch_reference_list.h.

496 {
497 sort( flatList.begin(), flatList.end(), sortByReferenceOnly );
498 }
static bool sortByReferenceOnly(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)

References flatList, and sortByReferenceOnly().

Referenced by SCH_SEXPR_PLUGIN::Format(), SCH_EDITOR_CONTROL::Paste(), and SCH_DRAWING_TOOLS::PlaceSymbol().

◆ sortByReferenceOnly()

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

Definition at line 131 of file component_references_lister.cpp.

133{
134 int ii = StrNumCmp( item1.GetRef(), item2.GetRef(), false );
135
136 if( ii == 0 )
137 ii = item1.m_unit - item2.m_unit;
138
139 if( ii == 0 )
140 return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
141 else
142 return ii < 0;
143}
wxString GetRef() const
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.

References SCH_REFERENCE::GetRef(), SCH_REFERENCE::m_symbolUuid, SCH_REFERENCE::m_unit, and StrNumCmp().

Referenced by SortByReferenceOnly().

◆ SortByTimeStamp()

void SCH_REFERENCE_LIST::SortByTimeStamp ( )
inline

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

Useful to detect duplicate Time Stamps

Definition at line 467 of file sch_reference_list.h.

468 {
469 sort( flatList.begin(), flatList.end(), sortByTimeStamp );
470 }
static bool sortByTimeStamp(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)

References flatList, and sortByTimeStamp().

Referenced by BACK_ANNOTATE::checkForUnusedSymbols().

◆ sortByTimeStamp()

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

Definition at line 146 of file component_references_lister.cpp.

148{
149 int ii = item1.m_sheetPath.Cmp( item2.m_sheetPath );
150
151 if( ii == 0 )
152 return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
153 else
154 return ii < 0;
155}
SCH_SHEET_PATH m_sheetPath
The sheet path for this reference.
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare if this is the same sheet path as aSheetPathToTest.

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

Referenced by SortByTimeStamp().

◆ SortByXCoordinate()

void SCH_REFERENCE_LIST::SortByXCoordinate ( )
inline

Sort the list of references by X position.

Symbols are sorted as follows:

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

Definition at line 442 of file sch_reference_list.h.

443 {
444 sort( flatList.begin(), flatList.end(), sortByXPosition );
445 }
static bool sortByXPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)

References flatList, and sortByXPosition().

Referenced by AnnotateByOptions().

◆ sortByXPosition()

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

Definition at line 64 of file component_references_lister.cpp.

65{
66 int ii = item1.CompareRef( item2 );
67
68 if( ii == 0 )
69 ii = item1.m_sheetNum - item2.m_sheetNum;
70
71 if( ii == 0 )
72 ii = item1.m_symbolPos.x - item2.m_symbolPos.x;
73
74 if( ii == 0 )
75 ii = item1.m_symbolPos.y - item2.m_symbolPos.y;
76
77 if( ii == 0 )
78 return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
79 else
80 return ii < 0;
81}

References SCH_REFERENCE::CompareRef(), SCH_REFERENCE::m_sheetNum, SCH_REFERENCE::m_symbolPos, SCH_REFERENCE::m_symbolUuid, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SortByXCoordinate().

◆ SortByYCoordinate()

void SCH_REFERENCE_LIST::SortByYCoordinate ( )
inline

Sort the list of references by Y position.

Symbols are sorted as follows:

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

Definition at line 457 of file sch_reference_list.h.

458 {
459 sort( flatList.begin(), flatList.end(), sortByYPosition );
460 }
static bool sortByYPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)

References flatList, and sortByYPosition().

Referenced by AnnotateByOptions().

◆ sortByYPosition()

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

Definition at line 84 of file component_references_lister.cpp.

85{
86 int ii = item1.CompareRef( item2 );
87
88 if( ii == 0 )
89 ii = item1.m_sheetNum - item2.m_sheetNum;
90
91 if( ii == 0 )
92 ii = item1.m_symbolPos.y - item2.m_symbolPos.y;
93
94 if( ii == 0 )
95 ii = item1.m_symbolPos.x - item2.m_symbolPos.x;
96
97 if( ii == 0 )
98 return item1.m_symbolUuid < item2.m_symbolUuid; // ensure a deterministic sort
99 else
100 return ii < 0;
101}

References SCH_REFERENCE::CompareRef(), SCH_REFERENCE::m_sheetNum, SCH_REFERENCE::m_symbolPos, SCH_REFERENCE::m_symbolUuid, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SortByYCoordinate().

◆ SplitReferences()

void SCH_REFERENCE_LIST::SplitReferences ( )
inline

Attempt to split all reference designators into a name (U) and number (1).

If the last character is '?' or not a digit, the reference is tagged as not annotated. For symbols with multiple parts, keeps the unit number intact

See also
SCH_REFERENCE::Split()

Definition at line 304 of file sch_reference_list.h.

305 {
306 for( unsigned ii = 0; ii < GetCount(); ii++ )
307 flatList[ii].Split();
308 }

References flatList, and GetCount().

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

◆ UpdateAnnotation()

void SCH_REFERENCE_LIST::UpdateAnnotation ( )
inline

Update the symbol references for the schematic project (or the current sheet).

Note
This function does not calculate the reference numbers stored in m_numRef so it must be called after calculation of new reference numbers.
See also
SCH_REFERENCE::Annotate()

Definition at line 332 of file sch_reference_list.h.

333 {
334 /* update the reference numbers */
335 for( unsigned ii = 0; ii < GetCount(); ii++ )
336 flatList[ii].Annotate();
337 }

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

Referenced by SCH_SHEET_LIST::AnnotatePowerSymbols(), and SCH_DRAWING_TOOLS::PlaceSymbol().

Friends And Related Function Documentation

◆ BACK_ANNOTATE

friend class BACK_ANNOTATE
friend

Definition at line 607 of file sch_reference_list.h.

◆ BACK_ANNOTATION

friend class BACK_ANNOTATION
friend

Definition at line 579 of file sch_reference_list.h.

Member Data Documentation

◆ flatList


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