37#include <unordered_set>
55 for(
unsigned ii = 0; ii <
GetCount(); ii++ )
167 for(
size_t i = 0; i <
m_flatList.size(); ++i )
169 if(
m_flatList[i].GetFullPath() == aFullPath )
179 for(
size_t i = 0; i <
m_flatList.size(); ++i )
190 int aMinRefId )
const
197 if(
m_flatList[aIndex].CompareRef( ref ) == 0 && ref.m_numRef >= aMinRefId && !ref.m_isNew )
198 aIdList.push_back( ref.m_numRef );
201 std::sort( aIdList.begin(), aIdList.end() );
211 std::vector<int> unitsList;
214 unitsList.push_back( aRef.
m_unit );
218 if( ref.CompareValue( aRef ) != 0 )
221 if( ref.CompareLibName( aRef ) != 0 )
225 if( ref.IsSplitNeeded() )
228 if( ref.CompareRef( aRef ) != 0 )
234 unitsList.push_back( ref.m_unit );
237 std::sort( unitsList.begin(), unitsList.end() );
248 const std::vector<int>& aRequiredUnits )
const
252 std::map<int, std::vector<SCH_REFERENCE>> refNumberMap;
257 if( ref.CompareRef( aRef ) != 0 )
263 refNumberMap[ref.m_numRef].push_back( ref );
266 return m_refDesTracker->GetNextRefDesForUnits( aRef, refNumberMap, aRequiredUnits, aMinValue );
272 std::vector<SCH_SYMBOL_INSTANCE> retval;
277 instance.
m_Path = ref.GetSheetPath().Path();
279 instance.
m_Unit = ref.GetUnit();
281 retval.push_back( instance );
294 if( aUnitNumber < 0 )
295 fullref <<
".." << aItem.
GetUnit();
297 fullref <<
".." << aUnitNumber;
307 bool aStartAtCurrent,
315 for(
size_t i = 0; i <
GetCount(); i++ )
326 wxCHECK2_MSG(
path,
continue,
327 wxS(
"Attempting to annotate item on sheet not part of the "
334 if( refstr[refstr.Len() - 1] ==
'?' )
339 lockedSymbols[refstr].AddItem( ref );
342 AnnotateByOptions( aSortOption, aAlgoOption, aStartNumber, lockedSymbols, aAdditionalRefs,
358 bool aStartAtCurrent )
360 switch( aSortOption )
370 switch( aAlgoOption )
381 aStartAtCurrent =
false;
387 aStartAtCurrent =
false;
391 Annotate( useSheetNum, idStep, aStartNumber, aLockedUnitMap, aAdditionalRefs, aStartAtCurrent );
398 bool aStartAtCurrent )
402 wxLogError( wxS(
"No reference tracker set for SCH_REFERENCE_LIST::Annotate()" ) );
420 std::unordered_set<wxString> inUseRefs;
422 for(
size_t i = 0; i < aAdditionalRefs.
GetCount(); i++ )
425 additionalRef.
Split();
437 int LastReferenceNumber = 0;
451 minRefId =
m_flatList[first].m_sheetNum * aSheetIntervalId + 1;
453 minRefId = aStartNumber + 1;
456 for(
unsigned ii = 0; ii <
m_flatList.size(); ii++ )
460 if( ref_unit.m_flag )
466 for(
const SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : aLockedUnitMap )
468 unsigned n_refs = pair.second.GetCount();
470 for(
unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI )
476 lockedList = &pair.second;
481 if( lockedList !=
nullptr )
485 if( (
m_flatList[first].CompareRef( ref_unit ) != 0 )
486 || ( aUseSheetNum && (
m_flatList[first].m_sheetNum != ref_unit.m_sheetNum ) ) )
493 minRefId = ref_unit.m_sheetNum * aSheetIntervalId + 1;
495 minRefId = aStartNumber + 1;
499 if( aStartAtCurrent && ref_unit.m_numRef > 0 )
500 minRefId = ref_unit.m_numRef;
502 wxCHECK( ref_unit.GetLibPart(), );
505 if( ref_unit.GetLibPart()->GetUnitCount() <= 1 )
507 if( ref_unit.m_isNew )
510 ref_unit.m_numRef = LastReferenceNumber;
511 ref_unit.m_numRefStr = ref_unit.formatRefStr( LastReferenceNumber );
515 ref_unit.m_isNew =
false;
521 if( lockedList !=
nullptr )
523 unsigned n_refs = lockedList->
GetCount();
526 if( ref_unit.m_isNew )
529 ref_unit.m_numRef = LastReferenceNumber;
530 ref_unit.m_numRefStr = ref_unit.formatRefStr( LastReferenceNumber );
531 ref_unit.m_isNew =
false;
535 for(
unsigned lockedRefI = 0; lockedRefI < n_refs; ++lockedRefI )
537 const SCH_REFERENCE& lockedRef = ( *lockedList )[lockedRefI];
542 ref_unit.m_unit = lockedRef.
m_unit;
555 for(
unsigned jj = ii + 1; jj <
m_flatList.size(); jj++ )
565 if( inUseRefs.find( ref_candidate ) == inUseRefs.end() )
568 m_flatList[jj].m_numRefStr = ref_unit.m_numRefStr;
573 inUseRefs.insert( ref_candidate );
579 else if( ref_unit.m_isNew )
584 std::vector<int> units = { ref_unit.GetUnit() };
586 ref_unit.m_numRef = LastReferenceNumber;
587 ref_unit.m_numRefStr = ref_unit.formatRefStr( LastReferenceNumber );
588 ref_unit.m_isNew =
false;
596 wxASSERT( originalSize ==
GetCount() );
613 for(
unsigned ii = 0; ii <
m_flatList.size(); ii++ )
626 &&
m_flatList[ii].GetLibPart()->GetUnitCount() > 1 )
628 msg.Printf(
_(
"Item not annotated: %s%s (unit %d)" ),
635 msg.Printf(
_(
"Item not annotated: %s%s" ),
m_flatList[ii].GetRef(), tmp );
653 msg.Printf(
_(
"Error: symbol %s%s%s (unit %d) exceeds units defined (%d)" ),
658 m_flatList[ii].GetLibPart()->GetUnitCount() );
669 for(
int ii = 0; ii < imax; ii++ )
692 msg.Printf(
_(
"Duplicate items %s%s%s\n" ),
696 : wxString( wxT(
"" ) ) );
717 msg.Printf(
_(
"Differing unit counts for item %s%s%s and %s%s%s\n" ),
733 msg.Printf(
_(
"Different values for %s%d%s (%s) and %s%d%s (%s)" ),
754 wxASSERT( aSymbol !=
nullptr );
766 if( aSymbol->
GetRef( &aSheetPath ).IsEmpty() )
767 aSymbol->
SetRef( &aSheetPath, wxT(
"DefRef?" ) );
769 wxString ref = aSymbol->
GetRef( &aSheetPath );
774 if( aSymbol->
GetValue(
false, &aSheetPath,
false ).IsEmpty() )
811 int ll = refText.length() - 1;
813 if( refText[ll] ==
'?' )
821 else if( isdigit( refText[ll] ) == 0 )
829 if( (refText[ll] <=
' ' ) || isdigit( refText[ll] ) )
835 if( isdigit( refText[ll + 1] ) )
838 const char* cp = refText.c_str() + ll + 1;
844 refText.erase( ll + 1 );
858 if( refText.empty() )
861 int ll = refText.length() - 1;
863 return ( refText[ll] ==
'?' ) || isdigit( refText[ll] );
868 const wxString& refDelimiter,
869 const wxString& refRangeDelimiter )
874 while( i < aList.size() )
876 wxString ref = aList[ i ].GetRef();
877 int numRef = aList[ i ].m_numRef;
881 while( i + range < aList.size()
882 && aList[ i + range ].GetRef() == ref
883 && aList[ i + range ].m_numRef ==
int( numRef + range ) )
887 if( range == 2 && refRangeDelimiter.IsEmpty() )
891 if( !retVal.IsEmpty() )
892 retVal << refDelimiter;
896 retVal << ref << aList[ i ].GetRefNumber();
898 else if( range == 2 || refRangeDelimiter.IsEmpty() )
900 retVal << ref << aList[ i ].GetRefNumber();
901 retVal << refDelimiter;
902 retVal << ref << aList[ i + 1 ].GetRefNumber();
906 retVal << ref << aList[ i ].GetRefNumber();
907 retVal << refRangeDelimiter;
908 retVal << ref << aList[ i + ( range - 1 ) ].GetRefNumber();
923 return wxString::Format(
"0%d", aNumber );
925 return wxString::Format(
"%d", aNumber );
930void SCH_REFERENCE_LIST::Show(
const char* aPrefix )
932 printf(
"%s\n", aPrefix );
934 for(
unsigned i = 0; i <
m_flatList.size(); ++i )
938 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
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.
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.
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.