37#include <unordered_set>
54 for(
unsigned ii = 0; ii <
GetCount(); ii++ )
162 for(
size_t ii = 0; ii <
m_flatList.size(); ii++ )
180 for(
size_t i = 0; i <
m_flatList.size(); ++i )
182 if(
m_flatList[i].GetFullPath() == aFullPath )
192 for(
size_t i = 0; i <
m_flatList.size(); ++i )
203 int aMinRefId )
const
210 if(
m_flatList[aIndex].CompareRef( ref ) == 0 && ref.m_numRef >= aMinRefId && !ref.m_isNew )
211 aIdList.push_back( ref.m_numRef );
214 std::sort( aIdList.begin(), aIdList.end() );
224 std::vector<int> unitsList;
227 unitsList.push_back( aRef.
m_unit );
231 if( ref.CompareValue( aRef ) != 0 )
234 if( ref.CompareLibName( aRef ) != 0 )
238 if( ref.IsSplitNeeded() )
241 if( ref.CompareRef( aRef ) != 0 )
247 unitsList.push_back( ref.m_unit );
250 std::sort( unitsList.begin(), unitsList.end() );
261 const std::vector<int>& aRequiredUnits )
const
265 std::map<int, std::vector<SCH_REFERENCE>> refNumberMap;
270 if( ref.CompareRef( aRef ) != 0 )
276 refNumberMap[ref.m_numRef].push_back( ref );
280 int minFreeNumber = aMinValue;
282 for( ; refNumberMap[minFreeNumber].size() > 0; ++minFreeNumber )
284 auto isNumberInUse = [&]() ->
bool
286 for(
const int& unit : aRequiredUnits )
288 for(
const SCH_REFERENCE& ref : refNumberMap[minFreeNumber] )
290 if( ref.CompareLibName( aRef ) || ref.CompareValue( aRef )
291 || ref.GetUnit() == unit )
301 if( !isNumberInUse() )
302 return minFreeNumber;
305 return minFreeNumber;
311 std::vector<SCH_SYMBOL_INSTANCE> retval;
316 instance.
m_Path = ref.GetSheetPath().Path();
318 instance.
m_Unit = ref.GetUnit();
320 retval.push_back( instance );
329 int expectedId = aFirstValue;
335 for( ; ii < aIdList.size(); ii++ )
337 if( expectedId <= aIdList[ii] )
343 for( ; ii < aIdList.size(); ii++ )
345 if( expectedId != aIdList[ii] )
348 aIdList.insert( aIdList.begin() + ii, expectedId );
357 aIdList.push_back( expectedId );
368 if( aUnitNumber < 0 )
369 fullref <<
".." << aItem.
GetUnit();
371 fullref <<
".." << aUnitNumber;
381 bool aStartAtCurrent,
389 for(
size_t i = 0; i <
GetCount(); i++ )
400 wxASSERT_MSG(
path, wxT(
"Attempting to annotate item on sheet not part of the hierarchy?" ) );
406 if( refstr[refstr.Len() - 1] ==
'?' )
411 lockedSymbols[refstr].AddItem( ref );
414 AnnotateByOptions( aSortOption, aAlgoOption, aStartNumber, lockedSymbols, aAdditionalRefs,
430 bool aStartAtCurrent )
432 switch( aSortOption )
442 switch( aAlgoOption )
453 aStartAtCurrent =
false;
459 aStartAtCurrent =
false;
463 Annotate( useSheetNum, idStep, aStartNumber, aLockedUnitMap, aAdditionalRefs, aStartAtCurrent );
485 std::unordered_set<wxString> inUseRefs;
487 for(
size_t i = 0; i < aAdditionalRefs.
GetCount(); i++ )
490 additionalRef.
Split();
502 int LastReferenceNumber = 0;
516 minRefId =
m_flatList[first].m_sheetNum * aSheetIntervalId + 1;
518 minRefId = aStartNumber + 1;
521 for(
unsigned ii = 0; ii <
m_flatList.size(); ii++ )
525 if( ref_unit.m_flag )
531 for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : aLockedUnitMap )
533 unsigned n_refs = pair.second.
GetCount();
535 for(
unsigned thisRefI = 0; thisRefI < n_refs; ++thisRefI )
541 lockedList = &pair.second;
546 if( lockedList !=
nullptr )
550 if( (
m_flatList[first].CompareRef( ref_unit ) != 0 )
551 || ( aUseSheetNum && (
m_flatList[first].m_sheetNum != ref_unit.m_sheetNum ) ) )
558 minRefId = ref_unit.m_sheetNum * aSheetIntervalId + 1;
560 minRefId = aStartNumber + 1;
564 if( aStartAtCurrent && ref_unit.m_numRef > 0 )
565 minRefId = ref_unit.m_numRef;
568 if( ref_unit.GetLibPart()->GetUnitCount() <= 1 )
570 if( ref_unit.m_isNew )
572 std::vector<int> idList;
575 ref_unit.m_numRef = LastReferenceNumber;
579 ref_unit.m_isNew =
false;
585 if( lockedList !=
nullptr )
587 unsigned n_refs = lockedList->
GetCount();
590 if( ref_unit.m_isNew )
593 ref_unit.m_numRef = LastReferenceNumber;
594 ref_unit.m_isNew =
false;
598 for(
unsigned lockedRefI = 0; lockedRefI < n_refs; ++lockedRefI )
618 for(
unsigned jj = ii + 1; jj <
m_flatList.size(); jj++ )
628 if( inUseRefs.find( ref_candidate ) == inUseRefs.end() )
635 inUseRefs.insert( ref_candidate );
641 else if( ref_unit.m_isNew )
646 std::vector<int> units = { ref_unit.GetUnit() };
648 ref_unit.m_numRef = LastReferenceNumber;
649 ref_unit.m_isNew =
false;
655 for(
size_t i = originalSize; i < ( aAdditionalRefs.
GetCount() + originalSize ); i++ )
658 wxASSERT( originalSize ==
GetCount() );
675 for(
unsigned ii = 0; ii <
m_flatList.size(); ii++ )
688 &&
m_flatList[ii].GetLibPart()->GetUnitCount() > 1 )
690 msg.Printf(
_(
"Item not annotated: %s%s (unit %d)" ),
697 msg.Printf(
_(
"Item not annotated: %s%s" ),
m_flatList[ii].GetRef(), tmp );
715 msg.Printf(
_(
"Error: symbol %s%s%s (unit %d) exceeds units defined (%d)" ),
720 m_flatList[ii].GetLibPart()->GetUnitCount() );
731 for(
int ii = 0; ii < imax; ii++ )
754 msg.Printf(
_(
"Duplicate items %s%s%s\n" ),
779 msg.Printf(
_(
"Differing unit counts for item %s%s%s and %s%s%s\n" ),
795 msg.Printf(
_(
"Different values for %s%d%s (%s) and %s%d%s (%s)" ),
817 wxASSERT( aSymbol !=
nullptr );
831 if( aSymbol->
GetRef( &aSheetPath ).IsEmpty() )
832 aSymbol->
SetRef( &aSheetPath, wxT(
"DefRef?" ) );
834 wxString ref = aSymbol->
GetRef( &aSheetPath );
875 int ll = refText.length() - 1;
877 if( refText[ll] ==
'?' )
885 else if( isdigit( refText[ll] ) == 0 )
893 if( (refText[ll] <=
' ' ) || isdigit( refText[ll] ) )
897 if( isdigit( refText[ll + 1] ) )
900 const char* cp = refText.c_str() + ll + 1;
905 refText.erase( ll+1 );
919 int ll = refText.length() - 1;
921 return ( refText[ll] ==
'?' ) || isdigit( refText[ll] );
930 while( i < aList.size() )
932 wxString ref = aList[ i ].GetRef();
933 int numRef = aList[ i ].m_numRef;
937 while( i + range < aList.size()
938 && aList[ i + range ].GetRef() == ref
939 && aList[ i + range ].m_numRef ==
int( numRef + range ) )
944 if( !retVal.IsEmpty() )
945 retVal << wxT(
", " );
949 retVal << ref << aList[ i ].GetRefNumber();
951 else if( range == 2 )
953 retVal << ref << aList[ i ].GetRefNumber();
954 retVal << wxT(
", " );
955 retVal << ref << aList[ i + 1 ].GetRefNumber();
959 retVal << ref << aList[ i ].GetRefNumber();
960 retVal << wxT(
"-" );
961 retVal << ref << aList[ i + ( range - 1 ) ].GetRefNumber();
Define a library symbol object.
static wxString SubReference(int aUnit, bool aAddSeparator=true)
int GetUnitCount() const override
For items with units, return the number of units.
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 int createFirstFreeRefId(std::vector< int > &aIdList, int aFirstValue)
Search for the first free reference number in aListId of reference numbers in use.
static wxString Shorthand(std::vector< SCH_REFERENCE > aList)
Return a shorthand string representing all the references in the list.
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 SortByYCoordinate()
Sort the list of references by Y position.
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.
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 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.
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.
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).
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.
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.
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.
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
Return reference name with unit altogether.
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.
LIB_SYMBOL * m_libPart
The source symbol from a library.
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.
void SetValueFieldText(const wxString &aValue)
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
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
VECTOR2I GetPosition() const override
const wxString GetValueFieldText(bool aResolve) const
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
void SetUnit(int aUnit)
Change the unit number to aUnit.
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()
@ 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.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
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.
A simple container for schematic symbol instance information.