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 ()
 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 FindRefByFullPath (const wxString &aFullPath) const
 Search the list for a symbol with the given KIID path (as string). 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< SCH_SYMBOL_INSTANCEGetSymbolInstances () 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_REFERENCEm_flatList
 

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

Constructor & Destructor Documentation

◆ SCH_REFERENCE_LIST()

SCH_REFERENCE_LIST::SCH_REFERENCE_LIST ( )
inline

Definition at line 263 of file sch_reference_list.h.

264 {
265 }

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 467 of file sch_reference_list.cpp.

470{
471 if ( m_flatList.size() == 0 )
472 return;
473
474 size_t originalSize = GetCount();
475
476 // For multi units symbols, store the list of already used full references.
477 // The algorithm tries to allocate the new reference to symbols having the same
478 // old reference.
479 // This algo works fine as long as the previous annotation has no duplicates.
480 // But when a hierarchy is reannotated with this option, the previous annotation can
481 // have duplicate references, and obviously we must fix these duplicate.
482 // therefore do not try to allocate a full reference more than once when trying
483 // to keep this order of multi units.
484 // inUseRefs keep trace of previously allocated references
485 std::unordered_set<wxString> inUseRefs;
486
487 for( size_t i = 0; i < aAdditionalRefs.GetCount(); i++ )
488 {
489 SCH_REFERENCE additionalRef = aAdditionalRefs[i];
490 additionalRef.Split();
491
492 // Add the additional reference to the multi-unit set if annotated
493 if( !additionalRef.m_isNew )
494 inUseRefs.insert( buildFullReference( additionalRef ) );
495
496 // We don't want to reannotate the additional references even if not annotated
497 // so we change the m_isNew flag to be false after splitting
498 additionalRef.m_isNew = false;
499 AddItem( additionalRef ); //add to this container
500 }
501
502 int LastReferenceNumber = 0;
503
504 /* calculate index of the first symbol with the same reference prefix
505 * than the current symbol. All symbols having the same reference
506 * prefix will receive a reference number with consecutive values:
507 * IC .. will be set to IC4, IC4, IC5 ...
508 */
509 unsigned first = 0;
510
511 // calculate the last used number for this reference prefix:
512 int minRefId;
513
514 // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
515 if( aUseSheetNum )
516 minRefId = m_flatList[first].m_sheetNum * aSheetIntervalId + 1;
517 else
518 minRefId = aStartNumber + 1;
519
520
521 for( unsigned ii = 0; ii < m_flatList.size(); ii++ )
522 {
523 auto& ref_unit = m_flatList[ii];
524
525 if( ref_unit.m_flag )
526 continue;
527
528 // Check whether this symbol is in aLockedUnitMap.
529 SCH_REFERENCE_LIST* lockedList = nullptr;
530
531 for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : aLockedUnitMap )
532 {
533 unsigned n_refs = pair.second.GetCount();
534
535 for( unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI )
536 {
537 SCH_REFERENCE &thisRef = pair.second[thisRefI];
538
539 if( thisRef.IsSameInstance( ref_unit ) )
540 {
541 lockedList = &pair.second;
542 break;
543 }
544 }
545
546 if( lockedList != nullptr )
547 break;
548 }
549
550 if( ( m_flatList[first].CompareRef( ref_unit ) != 0 )
551 || ( aUseSheetNum && ( m_flatList[first].m_sheetNum != ref_unit.m_sheetNum ) ) )
552 {
553 // New reference found: we need a new ref number for this reference
554 first = ii;
555
556 // when using sheet number, ensure ref number >= sheet number* aSheetIntervalId
557 if( aUseSheetNum )
558 minRefId = ref_unit.m_sheetNum * aSheetIntervalId + 1;
559 else
560 minRefId = aStartNumber + 1;
561 }
562
563 // Find references greater than current reference (unless not annotated)
564 if( aStartAtCurrent && ref_unit.m_numRef > 0 )
565 minRefId = ref_unit.m_numRef;
566
567 // Annotation of one part per package symbols (trivial case).
568 if( ref_unit.GetLibPart()->GetUnitCount() <= 1 )
569 {
570 if( ref_unit.m_isNew )
571 {
572 std::vector<int> idList;
573 GetRefsInUse( first, idList, minRefId );
574 LastReferenceNumber = createFirstFreeRefId( idList, minRefId );
575 ref_unit.m_numRef = LastReferenceNumber;
576 }
577
578 ref_unit.m_flag = 1;
579 ref_unit.m_isNew = false;
580 continue;
581 }
582
583 // If this symbol is in aLockedUnitMap, copy the annotation to all
584 // symbols that are not it
585 if( lockedList != nullptr )
586 {
587 unsigned n_refs = lockedList->GetCount();
588 std::vector<int> units = lockedList->GetUnitsMatchingRef( ref_unit );
589
590 if( ref_unit.m_isNew )
591 {
592 LastReferenceNumber = FindFirstUnusedReference( ref_unit, minRefId, units );
593 ref_unit.m_numRef = LastReferenceNumber;
594 ref_unit.m_isNew = false;
595 ref_unit.m_flag = 1;
596 }
597
598 for( unsigned lockedRefI = 0; lockedRefI < n_refs; ++lockedRefI )
599 {
600 SCH_REFERENCE& lockedRef = ( *lockedList )[lockedRefI];
601
602 if( lockedRef.IsSameInstance( ref_unit ) )
603 {
604 // This is the symbol we're currently annotating. Hold the unit!
605 ref_unit.m_unit = lockedRef.m_unit;
606
607 // lock this new full reference
608 inUseRefs.insert( buildFullReference( ref_unit ) );
609 }
610
611 if( lockedRef.CompareValue( ref_unit ) != 0 )
612 continue;
613
614 if( lockedRef.CompareLibName( ref_unit ) != 0 )
615 continue;
616
617 // Find the matching symbol
618 for( unsigned jj = ii + 1; jj < m_flatList.size(); jj++ )
619 {
620 if( !lockedRef.IsSameInstance( m_flatList[jj] ) )
621 continue;
622
623 wxString ref_candidate = buildFullReference( ref_unit, lockedRef.m_unit );
624
625 // propagate the new reference and unit selection to the "old" symbol,
626 // if this new full reference is not already used (can happens when initial
627 // multiunits symbols have duplicate references)
628 if( inUseRefs.find( ref_candidate ) == inUseRefs.end() )
629 {
630 m_flatList[jj].m_numRef = ref_unit.m_numRef;
631 m_flatList[jj].m_isNew = false;
632 m_flatList[jj].m_flag = 1;
633
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(), GetCount(), GetRefsInUse(), GetUnitsMatchingRef(), SCH_REFERENCE::IsSameInstance(), m_flatList, 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 425 of file sch_reference_list.cpp.

431{
432 switch( aSortOption )
433 {
434 default:
437 }
438
439 bool useSheetNum;
440 int idStep;
441
442 switch( aAlgoOption )
443 {
444 default:
446 useSheetNum = false;
447 idStep = 1;
448 break;
449
451 useSheetNum = true;
452 idStep = 100;
453 aStartAtCurrent = false; // Not implemented for sheet # * 100
454 break;
455
457 useSheetNum = true;
458 idStep = 1000;
459 aStartAtCurrent = false; // Not implemented for sheet # * 1000
460 break;
461 }
462
463 Annotate( useSheetNum, idStep, aStartNumber, aLockedUnitMap, aAdditionalRefs, aStartAtCurrent );
464}
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 sch_reference_list.cpp.

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

References _, SCH_REFERENCE::CompareRef(), SCH_REFERENCE::CompareValue(), ERCE_DIFFERENT_UNIT_VALUE, ERCE_DUPLICATE_REFERENCE, ERCE_EXTRA_UNITS, ERCE_UNANNOTATED, SCH_REFERENCE::GetLibPart(), SCH_REFERENCE::GetRef(), LIB_SYMBOL::GetUnitCount(), m_flatList, SCH_REFERENCE::m_numRef, SCH_REFERENCE::m_unit, SCH_REFERENCE::m_value, SortByRefAndValue(), SplitReferences(), and LIB_SYMBOL::SubReference().

Referenced by SCH_EDIT_FRAME::CheckAnnotate(), EESCHEMA_JOBS_HANDLER::JobExportNetlist(), and EESCHEMA_JOBS_HANDLER::JobExportPythonBom().

◆ Clear()

void SCH_REFERENCE_LIST::Clear ( )
inline

Definition at line 277 of file sch_reference_list.h.

278 {
279 m_flatList.clear();
280 }

References m_flatList.

Referenced by TEST_SCH_REFERENCE_LIST_FIXTURE::loadTestCase(), and SCH_DRAWING_TOOLS::PlaceSymbol().

◆ 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 sch_reference_list.cpp.

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

References GetCount(), and m_flatList.

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 327 of file sch_reference_list.cpp.

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

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 sch_reference_list.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 : m_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 m_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 sch_reference_list.cpp.

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

References m_flatList.

Referenced by BACK_ANNOTATE::getChangeList().

◆ FindRefByFullPath()

int SCH_REFERENCE_LIST::FindRefByFullPath ( const wxString &  aFullPath) const

Search the list for a symbol with the given KIID path (as string).

Parameters
aFullPathis the path of the symbol item to search.
Returns
an index in m_flatList if found or -1 if not found.

Definition at line 178 of file sch_reference_list.cpp.

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

References m_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 sch_reference_list.cpp.

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

References m_flatList.

◆ GetCount()

◆ GetItem() [1/2]

SCH_REFERENCE & SCH_REFERENCE_LIST::GetItem ( int  aIdx)
inline

Definition at line 284 of file sch_reference_list.h.

284{ return m_flatList[aIdx]; }

References m_flatList.

Referenced by ERC_TESTER::TestMissingUnits(), and ERC_TESTER::TestMultiunitFootprints().

◆ GetItem() [2/2]

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

Definition at line 285 of file sch_reference_list.h.

285{ return m_flatList[aIdx]; }

References m_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 sch_reference_list.cpp.

204{
205 aIdList.clear();
206
207 for( const SCH_REFERENCE& ref : m_flatList )
208 {
209 // Don't add new references to the list as we will reannotate those
210 if( m_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 m_flatList, and alg::remove_duplicates().

Referenced by Annotate().

◆ GetSymbolInstances()

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

Definition at line 309 of file sch_reference_list.cpp.

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

References m_flatList, SCH_SYMBOL_INSTANCE::m_Path, SCH_SYMBOL_INSTANCE::m_Reference, and SCH_SYMBOL_INSTANCE::m_Unit.

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 sch_reference_list.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 : m_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}

References m_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 267 of file sch_reference_list.h.

268 {
269 return m_flatList[ aIndex ];
270 }

References m_flatList.

◆ operator[]() [2/2]

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

Definition at line 272 of file sch_reference_list.h.

273 {
274 return m_flatList[ aIndex ];
275 }

References m_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 377 of file sch_reference_list.cpp.

383{
385
386 // All multi-unit symbols always locked to ensure consistent re-annotation
387 SCH_MULTI_UNIT_REFERENCE_MAP lockedSymbols;
388
389 for( size_t i = 0; i < GetCount(); i++ )
390 {
391 SCH_REFERENCE& ref = m_flatList[i];
392 wxString refstr = ref.GetSymbol()->GetRef( &ref.GetSheetPath() );
393
394 // Update sheet numbers based on the reference's sheet's position within the full
395 // hierarchy; we do this now before we annotate so annotation by sheet number * X
396 // works correctly.
397 if( aHierarchy )
398 {
399 SCH_SHEET_PATH* path = aHierarchy->FindSheetForPath( &ref.GetSheetPath() );
400 wxASSERT_MSG( path, wxT( "Attempting to annotate item on sheet not part of the hierarchy?" ) );
401
402 ref.SetSheetNumber( path->GetVirtualPageNumber() );
403 }
404
405 // Never lock unassigned references
406 if( refstr[refstr.Len() - 1] == '?' )
407 continue;
408
409 ref.m_isNew = true; // We want to reannotate all references
410
411 lockedSymbols[refstr].AddItem( ref );
412 }
413
414 AnnotateByOptions( aSortOption, aAlgoOption, aStartNumber, lockedSymbols, aAdditionalRefs,
415 aStartAtCurrent );
416}
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:652
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(), GetCount(), SCH_SYMBOL::GetRef(), SCH_REFERENCE::GetSheetPath(), SCH_REFERENCE::GetSymbol(), m_flatList, 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 419 of file sch_reference_list.cpp.

420{
421 ReannotateByOptions( UNSORTED, INCREMENTAL_BY_REF, 0, aAdditionalReferences, true, nullptr );
422}
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 ( )
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 330 of file sch_reference_list.h.

331 {
332 for( unsigned ii = 0; ii < GetCount(); ii++ )
333 m_flatList[ii].m_isNew = true;
334 }

References GetCount(), and m_flatList.

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 sch_reference_list.cpp.

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

References m_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 925 of file sch_reference_list.cpp.

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

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

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

References m_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 sch_reference_list.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 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 507 of file sch_reference_list.h.

508 {
509 sort( m_flatList.begin(), m_flatList.end(), sortByReferenceOnly );
510 }
static bool sortByReferenceOnly(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)

References m_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 sch_reference_list.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}
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 479 of file sch_reference_list.h.

480 {
481 sort( m_flatList.begin(), m_flatList.end(), sortByTimeStamp );
482 }
static bool sortByTimeStamp(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)

References m_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 sch_reference_list.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 454 of file sch_reference_list.h.

455 {
456 sort( m_flatList.begin(), m_flatList.end(), sortByXPosition );
457 }
static bool sortByXPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)

References m_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 sch_reference_list.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 469 of file sch_reference_list.h.

470 {
471 sort( m_flatList.begin(), m_flatList.end(), sortByYPosition );
472 }
static bool sortByYPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)

References m_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 sch_reference_list.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 319 of file sch_reference_list.h.

320 {
321 for( unsigned ii = 0; ii < GetCount(); ii++ )
322 m_flatList[ii].Split();
323 }

References GetCount(), and m_flatList.

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

345 {
346 /* update the reference numbers */
347 for( unsigned ii = 0; ii < GetCount(); ii++ )
348 m_flatList[ii].Annotate();
349 }

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

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

◆ BACK_ANNOTATION

friend class BACK_ANNOTATION
friend

Definition at line 591 of file sch_reference_list.h.

Member Data Documentation

◆ m_flatList


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