37#include <unordered_set>
55 for(
unsigned ii = 0; ii <
GetCount(); ii++ )
161 for(
size_t i = 0; i <
m_flatList.size(); ++i )
163 if(
m_flatList[i].GetFullPath() == aFullPath )
173 for(
size_t i = 0; i <
m_flatList.size(); ++i )
184 int aMinRefId )
const
191 if(
m_flatList[aIndex].CompareRef( ref ) == 0 && ref.m_numRef >= aMinRefId && !ref.m_isNew )
192 aIdList.push_back( ref.m_numRef );
195 std::sort( aIdList.begin(), aIdList.end() );
205 std::vector<int> unitsList;
208 unitsList.push_back( aRef.
m_unit );
212 if( ref.CompareValue( aRef ) != 0 )
215 if( ref.CompareLibName( aRef ) != 0 )
219 if( ref.IsSplitNeeded() )
222 if( ref.CompareRef( aRef ) != 0 )
228 unitsList.push_back( ref.m_unit );
231 std::sort( unitsList.begin(), unitsList.end() );
242 const std::vector<int>& aRequiredUnits )
const
246 std::map<int, std::vector<SCH_REFERENCE>> refNumberMap;
251 if( ref.CompareRef( aRef ) != 0 )
257 refNumberMap[ref.m_numRef].push_back( ref );
260 return m_refDesTracker->GetNextRefDesForUnits( aRef, refNumberMap, aRequiredUnits, aMinValue );
266 std::vector<SCH_SYMBOL_INSTANCE> retval;
271 instance.
m_Path = ref.GetSheetPath().Path();
273 instance.
m_Unit = ref.GetUnit();
275 retval.push_back( instance );
288 if( aUnitNumber < 0 )
289 fullref <<
".." << aItem.
GetUnit();
291 fullref <<
".." << aUnitNumber;
301 bool aStartAtCurrent,
309 for(
size_t i = 0; i <
GetCount(); i++ )
320 wxCHECK2_MSG(
path,
continue,
321 wxS(
"Attempting to annotate item on sheet not part of the "
328 if( refstr[refstr.Len() - 1] ==
'?' )
333 lockedSymbols[refstr].AddItem( ref );
336 AnnotateByOptions( aSortOption, aAlgoOption, aStartNumber, lockedSymbols, aAdditionalRefs,
352 bool aStartAtCurrent )
354 switch( aSortOption )
364 switch( aAlgoOption )
375 aStartAtCurrent =
false;
381 aStartAtCurrent =
false;
385 Annotate( useSheetNum, idStep, aStartNumber, aLockedUnitMap, aAdditionalRefs, aStartAtCurrent );
392 bool aStartAtCurrent )
396 wxLogError( wxS(
"No reference tracker set for SCH_REFERENCE_LIST::Annotate()" ) );
414 std::unordered_set<wxString> inUseRefs;
416 for(
size_t i = 0; i < aAdditionalRefs.
GetCount(); i++ )
419 additionalRef.
Split();
431 int LastReferenceNumber = 0;
445 minRefId =
m_flatList[first].m_sheetNum * aSheetIntervalId + 1;
447 minRefId = aStartNumber + 1;
450 for(
unsigned ii = 0; ii <
m_flatList.size(); ii++ )
454 if( ref_unit.m_flag )
460 for(
const SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : aLockedUnitMap )
462 unsigned n_refs = pair.second.
GetCount();
464 for(
unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI )
470 lockedList = &pair.second;
475 if( lockedList !=
nullptr )
479 if( (
m_flatList[first].CompareRef( ref_unit ) != 0 )
480 || ( aUseSheetNum && (
m_flatList[first].m_sheetNum != ref_unit.m_sheetNum ) ) )
487 minRefId = ref_unit.m_sheetNum * aSheetIntervalId + 1;
489 minRefId = aStartNumber + 1;
493 if( aStartAtCurrent && ref_unit.m_numRef > 0 )
494 minRefId = ref_unit.m_numRef;
496 wxCHECK( ref_unit.GetLibPart(), );
499 if( ref_unit.GetLibPart()->GetUnitCount() <= 1 )
501 if( ref_unit.m_isNew )
504 ref_unit.m_numRef = LastReferenceNumber;
505 ref_unit.m_numRefStr = ref_unit.formatRefStr( LastReferenceNumber );
509 ref_unit.m_isNew =
false;
515 if( lockedList !=
nullptr )
517 unsigned n_refs = lockedList->
GetCount();
520 if( ref_unit.m_isNew )
523 ref_unit.m_numRef = LastReferenceNumber;
524 ref_unit.m_numRefStr = ref_unit.formatRefStr( LastReferenceNumber );
525 ref_unit.m_isNew =
false;
529 for(
unsigned lockedRefI = 0; lockedRefI < n_refs; ++lockedRefI )
531 const SCH_REFERENCE& lockedRef = ( *lockedList )[lockedRefI];
549 for(
unsigned jj = ii + 1; jj <
m_flatList.size(); jj++ )
559 if( inUseRefs.find( ref_candidate ) == inUseRefs.end() )
562 m_flatList[jj].m_numRefStr = ref_unit.m_numRefStr;
567 inUseRefs.insert( ref_candidate );
573 else if( ref_unit.m_isNew )
578 std::vector<int> units = { ref_unit.GetUnit() };
580 ref_unit.m_numRef = LastReferenceNumber;
581 ref_unit.m_numRefStr = ref_unit.formatRefStr( LastReferenceNumber );
582 ref_unit.m_isNew =
false;
590 wxASSERT( originalSize ==
GetCount() );
607 for(
unsigned ii = 0; ii <
m_flatList.size(); ii++ )
620 &&
m_flatList[ii].GetLibPart()->GetUnitCount() > 1 )
622 msg.Printf(
_(
"Item not annotated: %s%s (unit %d)" ),
629 msg.Printf(
_(
"Item not annotated: %s%s" ),
m_flatList[ii].GetRef(), tmp );
647 msg.Printf(
_(
"Error: symbol %s%s%s (unit %d) exceeds units defined (%d)" ),
652 m_flatList[ii].GetLibPart()->GetUnitCount() );
663 for(
int ii = 0; ii < imax; ii++ )
686 msg.Printf(
_(
"Duplicate items %s%s%s\n" ),
690 : wxString( wxT(
"" ) ) );
711 msg.Printf(
_(
"Differing unit counts for item %s%s%s and %s%s%s\n" ),
727 msg.Printf(
_(
"Different values for %s%d%s (%s) and %s%d%s (%s)" ),
748 wxASSERT( aSymbol !=
nullptr );
760 if( aSymbol->
GetRef( &aSheetPath ).IsEmpty() )
761 aSymbol->
SetRef( &aSheetPath, wxT(
"DefRef?" ) );
763 wxString ref = aSymbol->
GetRef( &aSheetPath );
768 if( aSymbol->
GetValue(
false, &aSheetPath,
false ).IsEmpty() )
805 int ll = refText.length() - 1;
807 if( refText[ll] ==
'?' )
815 else if( isdigit( refText[ll] ) == 0 )
823 if( (refText[ll] <=
' ' ) || isdigit( refText[ll] ) )
829 if( isdigit( refText[ll + 1] ) )
832 const char* cp = refText.c_str() + ll + 1;
838 refText.erase( ll + 1 );
852 if( refText.empty() )
855 int ll = refText.length() - 1;
857 return ( refText[ll] ==
'?' ) || isdigit( refText[ll] );
862 const wxString& refDelimiter,
863 const wxString& refRangeDelimiter )
868 while( i < aList.size() )
870 wxString ref = aList[ i ].GetRef();
871 int numRef = aList[ i ].m_numRef;
875 while( i + range < aList.size()
876 && aList[ i + range ].GetRef() == ref
877 && aList[ i + range ].m_numRef ==
int( numRef + range ) )
881 if( range == 2 && refRangeDelimiter.IsEmpty() )
885 if( !retVal.IsEmpty() )
886 retVal << refDelimiter;
890 retVal << ref << aList[ i ].GetRefNumber();
892 else if( range == 2 || refRangeDelimiter.IsEmpty() )
894 retVal << ref << aList[ i ].GetRefNumber();
895 retVal << refDelimiter;
896 retVal << ref << aList[ i + 1 ].GetRefNumber();
900 retVal << ref << aList[ i ].GetRefNumber();
901 retVal << refRangeDelimiter;
902 retVal << ref << aList[ i + ( range - 1 ) ].GetRefNumber();
917 return wxString::Format(
"0%d", aNumber );
919 return wxString::Format(
"%d", aNumber );
924void SCH_REFERENCE_LIST::Show(
const char* aPrefix )
926 printf(
"%s\n", aPrefix );
928 for(
unsigned i = 0; i <
m_flatList.size(); ++i )
932 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 void SetUnit(int aUnit)
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
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)
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 ...
void ReannotateDuplicates(const SCH_REFERENCE_LIST &aAdditionalReferences)
Convenience function for the Paste Unique functionality.
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.
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.
const SCH_SHEET_PATH & GetSheetPath() const
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.
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) )
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.
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.
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.
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...
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 SetValueFieldText(const wxString &aValue)
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const override
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
const wxString GetFootprintFieldText(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const
VECTOR2I GetPosition() const override
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
@ 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.