37#include <unordered_set>
55 for(
unsigned ii = 0; ii <
GetCount(); ii++ )
67 for(
unsigned ii = 0; ii <
GetCount(); ii++ )
179 for(
size_t i = 0; i <
m_flatList.size(); ++i )
181 if(
m_flatList[i].GetFullPath() == aFullPath )
191 for(
size_t i = 0; i <
m_flatList.size(); ++i )
202 int aMinRefId )
const
209 if(
m_flatList[aIndex].CompareRef( ref ) == 0 && ref.m_numRef >= aMinRefId && !ref.m_isNew )
210 aIdList.push_back( ref.m_numRef );
213 std::sort( aIdList.begin(), aIdList.end() );
223 std::vector<int> unitsList;
226 unitsList.push_back( aRef.
m_unit );
230 if( ref.CompareValue( aRef ) != 0 )
233 if( ref.CompareLibName( aRef ) != 0 )
237 if( ref.IsSplitNeeded() )
240 if( ref.CompareRef( aRef ) != 0 )
246 unitsList.push_back( ref.m_unit );
249 std::sort( unitsList.begin(), unitsList.end() );
260 const std::vector<int>& aRequiredUnits )
const
264 std::map<int, std::vector<SCH_REFERENCE>> refNumberMap;
269 if( ref.CompareRef( aRef ) != 0 )
275 refNumberMap[ref.m_numRef].push_back( ref );
278 return m_refDesTracker->GetNextRefDesForUnits( aRef, refNumberMap, aRequiredUnits, aMinValue );
284 std::vector<SCH_SYMBOL_INSTANCE> retval;
289 instance.
m_Path = ref.GetSheetPath().Path();
291 instance.
m_Unit = ref.GetUnit();
293 retval.push_back( instance );
306 if( aUnitNumber < 0 )
307 fullref <<
".." << aItem.
GetUnit();
309 fullref <<
".." << aUnitNumber;
319 bool aStartAtCurrent,
327 for(
size_t i = 0; i <
GetCount(); i++ )
338 wxCHECK2_MSG(
path,
continue,
339 wxS(
"Attempting to annotate item on sheet not part of the "
346 if( refstr[refstr.Len() - 1] ==
'?' )
351 lockedSymbols[refstr].AddItem( ref );
354 AnnotateByOptions( aSortOption, aAlgoOption, aStartNumber, lockedSymbols, aAdditionalRefs,
370 bool aStartAtCurrent )
372 switch( aSortOption )
382 switch( aAlgoOption )
393 aStartAtCurrent =
false;
399 aStartAtCurrent =
false;
403 Annotate( useSheetNum, idStep, aStartNumber, aLockedUnitMap, aAdditionalRefs, aStartAtCurrent );
410 bool aStartAtCurrent )
414 wxLogError( wxS(
"No reference tracker set for SCH_REFERENCE_LIST::Annotate()" ) );
432 std::unordered_set<wxString> inUseRefs;
434 for(
size_t i = 0; i < aAdditionalRefs.
GetCount(); i++ )
437 additionalRef.
Split();
449 int LastReferenceNumber = 0;
463 minRefId =
m_flatList[first].m_sheetNum * aSheetIntervalId + 1;
465 minRefId = aStartNumber + 1;
468 for(
unsigned ii = 0; ii <
m_flatList.size(); ii++ )
472 if( ref_unit.m_flag )
478 for(
const SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : aLockedUnitMap )
480 unsigned n_refs = pair.second.GetCount();
482 for(
unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI )
488 lockedList = &pair.second;
493 if( lockedList !=
nullptr )
497 if( (
m_flatList[first].CompareRef( ref_unit ) != 0 )
498 || ( aUseSheetNum && (
m_flatList[first].m_sheetNum != ref_unit.m_sheetNum ) ) )
505 minRefId = ref_unit.m_sheetNum * aSheetIntervalId + 1;
507 minRefId = aStartNumber + 1;
511 if( aStartAtCurrent && ref_unit.m_numRef > 0 )
512 minRefId = ref_unit.m_numRef;
514 wxCHECK( ref_unit.GetLibPart(), );
517 if( ref_unit.GetLibPart()->GetUnitCount() <= 1 )
519 if( ref_unit.m_isNew )
522 ref_unit.m_numRef = LastReferenceNumber;
523 ref_unit.m_numRefStr = ref_unit.formatRefStr( LastReferenceNumber );
527 ref_unit.m_isNew =
false;
533 if( lockedList !=
nullptr )
535 unsigned n_refs = lockedList->
GetCount();
538 if( ref_unit.m_isNew )
541 ref_unit.m_numRef = LastReferenceNumber;
542 ref_unit.m_numRefStr = ref_unit.formatRefStr( LastReferenceNumber );
543 ref_unit.m_isNew =
false;
547 for(
unsigned lockedRefI = 0; lockedRefI < n_refs; ++lockedRefI )
549 const SCH_REFERENCE& lockedRef = ( *lockedList )[lockedRefI];
554 ref_unit.m_unit = lockedRef.
m_unit;
567 for(
unsigned jj = ii + 1; jj <
m_flatList.size(); jj++ )
577 if( inUseRefs.find( ref_candidate ) == inUseRefs.end() )
580 m_flatList[jj].m_numRefStr = ref_unit.m_numRefStr;
585 inUseRefs.insert( ref_candidate );
591 else if( ref_unit.m_isNew )
596 std::vector<int> units = { ref_unit.GetUnit() };
598 ref_unit.m_numRef = LastReferenceNumber;
599 ref_unit.m_numRefStr = ref_unit.formatRefStr( LastReferenceNumber );
600 ref_unit.m_isNew =
false;
608 wxASSERT( originalSize ==
GetCount() );
625 for(
unsigned ii = 0; ii <
m_flatList.size(); ii++ )
638 &&
m_flatList[ii].GetLibPart()->GetUnitCount() > 1 )
640 msg.Printf(
_(
"Item not annotated: %s%s (unit %d)" ),
647 msg.Printf(
_(
"Item not annotated: %s%s" ),
m_flatList[ii].GetRef(), tmp );
665 msg.Printf(
_(
"Error: symbol %s%s%s (unit %d) exceeds units defined (%d)" ),
670 m_flatList[ii].GetLibPart()->GetUnitCount() );
681 for(
int ii = 0; ii < imax; ii++ )
704 msg.Printf(
_(
"Duplicate items %s%s%s\n" ),
708 : wxString( wxT(
"" ) ) );
729 msg.Printf(
_(
"Differing unit counts for item %s%s%s and %s%s%s\n" ),
745 msg.Printf(
_(
"Different values for %s%d%s (%s) and %s%d%s (%s)" ),
766 wxASSERT( aSymbol !=
nullptr );
796 if( aSymbol->
GetRef( &aSheetPath ).IsEmpty() )
797 aSymbol->
SetRef( &aSheetPath, wxT(
"DefRef?" ) );
799 wxString ref = aSymbol->
GetRef( &aSheetPath );
804 wxString value = aSymbol->
GetValue(
false, &aSheetPath,
false );
806 if( value.IsEmpty() )
843 int ll = refText.length() - 1;
845 if( refText[ll] ==
'?' )
853 else if( isdigit( refText[ll] ) == 0 )
861 if( (refText[ll] <=
' ' ) || isdigit( refText[ll] ) )
867 if( isdigit( refText[ll + 1] ) )
870 const char* cp = refText.c_str() + ll + 1;
876 refText.erase( ll + 1 );
890 if( refText.empty() )
893 int ll = refText.length() - 1;
895 return ( refText[ll] ==
'?' ) || isdigit( refText[ll] );
900 const wxString& refDelimiter,
901 const wxString& refRangeDelimiter )
906 while( i < aList.size() )
908 wxString ref = aList[ i ].GetRef();
909 int numRef = aList[ i ].m_numRef;
913 while( i + range < aList.size()
914 && aList[ i + range ].GetRef() == ref
915 && aList[ i + range ].m_numRef ==
int( numRef + range ) )
919 if( range == 2 && refRangeDelimiter.IsEmpty() )
923 if( !retVal.IsEmpty() )
924 retVal << refDelimiter;
928 retVal << ref << aList[ i ].GetRefNumber();
930 else if( range == 2 || refRangeDelimiter.IsEmpty() )
932 retVal << ref << aList[ i ].GetRefNumber();
933 retVal << refDelimiter;
934 retVal << ref << aList[ i + 1 ].GetRefNumber();
938 retVal << ref << aList[ i ].GetRefNumber();
939 retVal << refRangeDelimiter;
940 retVal << ref << aList[ i + ( range - 1 ) ].GetRefNumber();
987 return wxString::Format(
"0%d", aNumber );
989 return wxString::Format(
"%d", aNumber );
1026void SCH_REFERENCE_LIST::Show(
const char* aPrefix )
1028 printf(
"%s\n", aPrefix );
1030 for(
unsigned i = 0; i <
m_flatList.size(); ++i )
1034 printf(
" [%-2d] ref:%-8s num:%-3d lib_part:%s\n", i, schref.
m_ref.ToStdString().c_str(),
wxString GetName() const override
int GetUnitCount() const override
virtual const wxString & GetText() const override
Return the string associated with the text object.
SCH_REFERENCE * FindItem(const SCH_REFERENCE &aItem)
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.
static bool sortByRefAndValue(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
static bool sortBySymbolPtr(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
bool Contains(const SCH_REFERENCE &aItem) const
Return true if aItem exists in this list.
void AnnotateByOptions(enum ANNOTATE_ORDER_T aSortOption, enum ANNOTATE_ALGO_T aAlgoOption, int aStartNumber, const SCH_MULTI_UNIT_REFERENCE_MAP &aLockedUnitMap, const SCH_REFERENCE_LIST &aAdditionalRefs, bool aStartAtCurrent)
Annotate the references by the provided options.
void Annotate(bool aUseSheetNum, int aSheetIntervalId, int aStartNumber, const 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 SortByYCoordinate()
Sort the list of references by Y position.
static bool sortByTimeStamp(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
int FindRef(const wxString &aPath) const
Search the list for a symbol with a given reference.
void SortByXCoordinate()
Sort the list of references by X position.
static bool sortByXPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
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...
void SplitReferences()
Attempt to split all reference designators into a name (U) and number (1).
std::shared_ptr< REFDES_TRACKER > m_refDesTracker
A list of previously used reference designators.
void SortByRefAndValue()
Sort the list of references by value.
std::vector< int > GetUnitsMatchingRef(const SCH_REFERENCE &aRef) const
Return all the unit numbers for a given reference, comparing library reference, value,...
std::vector< SCH_REFERENCE > m_flatList
static bool sortByReferenceOnly(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
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 ...
static wxString Shorthand(std::vector< SCH_REFERENCE > aList, const wxString &refDelimiter, const wxString &refRangeDelimiter)
Return a shorthand string representing all the references in the list.
int FindRefByFullPath(const wxString &aFullPath) const
Search the list for a symbol with the given KIID path (as string).
std::vector< SCH_SYMBOL_INSTANCE > GetSymbolInstances() const
void AddItem(const SCH_REFERENCE &aItem)
void RemoveItem(unsigned int aIndex)
Remove an item from the list of references.
void ReannotateDuplicates(const SCH_REFERENCE_LIST &aAdditionalReferences, ANNOTATE_ALGO_T aAlgoOption)
Convenience function for the Paste Unique functionality.
static bool sortByYPosition(const SCH_REFERENCE &item1, const SCH_REFERENCE &item2)
int CheckAnnotation(ANNOTATION_ERROR_HANDLER aErrorHandler)
Check for annotations errors.
A helper to define a symbol's reference designator in a schematic.
void SetSymbolExcludedFromBoard(bool aEnable)
const SCH_SHEET_PATH & GetSheetPath() const
void SetSymbolExcludedFromBOM(bool aEnable, const wxString &aVariant=wxEmptyString)
SCH_SYMBOL * m_rootSymbol
The symbol associated the reference object.
int m_unit
The unit number for symbol with multiple parts per package.
SCH_SHEET_PATH m_sheetPath
The sheet path for this reference.
wxString m_footprint
The footprint assigned.
wxString formatRefStr(int aNumber) const
int CompareLibName(const SCH_REFERENCE &item) const
int CompareRef(const SCH_REFERENCE &item) const
void SetRef(const wxString &aReference)
bool AlwaysAnnotate() const
Verify the reference should always be automatically annotated.
wxString m_numRefStr
The numeric part in original string form (may have leading zeroes).
bool m_isNew
True if not yet annotated.
bool GetSymbolExcludedFromBOM(const wxString &aVariant=wxEmptyString) const
bool GetSymbolDNP(const wxString &aVariant=wxEmptyString) const
void Split()
Attempt to split the reference designator into a name (U) and number (1).
bool IsSplitNeeded()
Determine if this reference needs to be split or if it likely already has been.
SCH_SYMBOL * GetSymbol() const
wxString m_ref
Symbol reference prefix, without number (for IC1, this is IC) )
void SetSymbolExcludedFromSim(bool aEnable, const wxString &aVariant=wxEmptyString)
int m_sheetNum
The sheet number for the reference.
void SetRefStr(const std::string &aReference)
int m_numRef
The numeric part of the reference designator.
bool GetSymbolExcludedFromBoard() const
LIB_SYMBOL * GetLibPart() const
void SetSheetNumber(int aSheetNumber)
const char * GetRefStr() const
bool IsSameInstance(const SCH_REFERENCE &other) const
Return whether this reference refers to the same symbol instance (symbol and sheet) as another.
KIID m_symbolUuid
UUID of the symbol.
bool GetSymbolExcludedFromSim(const wxString &aVariant=wxEmptyString) const
wxString m_value
The symbol value.
VECTOR2I m_symbolPos
The physical position of the symbol in schematic used to annotate by X or Y position.
wxString GetRefNumber() const
int CompareValue(const SCH_REFERENCE &item) const
void Annotate()
Update the annotation of the symbol according the current object state.
void SetSymbolDNP(bool aEnable, const wxString &aVariant=wxEmptyString)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
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...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare if this is the same sheet path as aSheetPathToTest.
wxString SubReference(int aUnit, bool aAddSeparator=true) const
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText, const wxString &aVariantName=wxEmptyString) const override
const wxString GetFootprintFieldText(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
VECTOR2I GetPosition() const override
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
@ ERCE_UNANNOTATED
Symbol has not been annotated.
@ ERCE_DUPLICATE_REFERENCE
More than one symbol with the same reference.
@ ERCE_EXTRA_UNITS
Symbol has more units than are defined.
@ ERCE_DIFFERENT_UNIT_VALUE
Units of same symbol have different values.
void remove_duplicates(_Container &__c)
Deletes all duplicate values from __c.
wxString buildFullReference(const SCH_REFERENCE &aItem, int aUnitNumber=-1)
std::function< void(ERCE_T aType, const wxString &aMsg, SCH_REFERENCE *aItemA, SCH_REFERENCE *aItemB)> ANNOTATION_ERROR_HANDLER
Define a standard error handler for annotation errors.
ANNOTATE_ORDER_T
Schematic annotation order options.
@ UNSORTED
Annotate by position of symbol in the schematic sheet object list.
@ SORT_BY_X_POSITION
Annotate by X position from left to right.
@ SORT_BY_Y_POSITION
Annotate by Y position from top to bottom.
ANNOTATE_ALGO_T
Schematic annotation type options.
@ 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.
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
wxString From_UTF8(const char *cstring)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
A simple container for schematic symbol instance information.
@ REFERENCE
Field Reference of part, i.e. "IC21".