22#include <unordered_set>
43 for(
size_t i = 0; i < references.
GetCount(); i++ )
45 SCH_SYMBOL* symbol = references[ i ].GetSymbol();
49 curr_full_uuid.push_back( symbol->
m_Uuid );
51 wxString ref = symbol->
GetRef( curr_sheetpath,
true );
54 aMap[ curr_full_uuid.
AsString() ] = ref;
61 std::unordered_set<SCH_SYMBOL*> symbols;
65 switch( item->Type() )
78 symbols.insert(
static_cast<SCH_SYMBOL*
>( item ) );
89 symbols.insert(
static_cast<SCH_SYMBOL*
>( aChild ) );
114 auto clearSymbolAnnotation =
118 commit.
Modify( aItem, aScreen );
127 msg.Printf(
_(
"Cleared annotation for %s (unit %s)." ),
133 msg.Printf(
_(
"Cleared annotation for %s." ),
142 auto clearSheetAnnotation =
146 clearSymbolAnnotation( item, aScreen, aSheet, aResetPrefixes );
149 switch( aAnnotateScope )
154 clearSheetAnnotation( sheet.LastScreen(), &sheet,
false );
160 clearSheetAnnotation( screen, ¤tSheet,
false );
166 std::vector<SCH_ITEM*> tempSubSheets;
169 for(
SCH_ITEM* item : tempSubSheets )
178 clearSheetAnnotation( sheet.LastScreen(), &sheet,
false );
191 clearSymbolAnnotation( symbol, screen, ¤tSheet,
false );
193 for(
EDA_ITEM* item : selection.Items() )
205 clearSheetAnnotation( sheet.LastScreen(), &sheet,
false );
217 static_cast<DIALOG_ERC*
>( erc_dlg )->UpdateAnnotationWarning();
219 commit.
Push(
_(
"Delete Annotation" ) );
228 int aStartNumber,
bool aResetAnnotation,
bool aRegroupUnits,
229 bool aRepairTimestamps,
REPORTER& aReporter )
243 auto addSelectedSheet =
257 addSelectedSheet( item );
269 std::vector<SCH_ITEM*> tempSubSheets;
272 for(
SCH_ITEM* item : tempSubSheets )
281 std::unordered_set<SCH_SYMBOL*> selectedSymbols;
291 std::map<wxString, wxString> previousAnnotation;
295 if( aRepairTimestamps )
302 msg.Printf(
_(
"%d duplicate time stamps were found and replaced." ), count );
312 switch( aAnnotateScope )
344 switch( aAnnotateScope )
368 if( std::optional<std::pair<SCH_SHEET_PATH, SCH_SHEET_PATH>> collision =
371 const auto& [
path, first] = *collision;
373 aReporter.
ReportTail( wxString::Format(
_(
"Sheets %s and %s use %s with the same reference suffix. "
374 "Give each sheet a distinct suffix before annotating." ),
375 first.PathHumanReadable(
false,
true ),
376 path.PathHumanReadable(
false,
true ),
377 path.LastScreen()->GetFileName() ),
382 const std::set<const SCH_SCREEN*> sharedScreens =
384 aAlgoOption, aStartNumber, aResetAnnotation,
390 for(
size_t i = 0; i < references.
GetCount(); i++ )
397 full_uuid.push_back( symbol->
m_Uuid );
399 wxString prevRef = previousAnnotation[ full_uuid.
AsString() ];
400 wxString newRef = symbol->
GetRef( sheet,
true );
404 if( prevRef.Length() )
406 if( newRef == prevRef )
411 msg.Printf(
_(
"Updated %s (unit %s) from %s to %s." ),
419 msg.Printf(
_(
"Updated %s from %s to %s." ),
429 msg.Printf(
_(
"Annotated %s (unit %s) as %s." ),
436 msg.Printf(
_(
"Annotated %s as %s." ),
445 for(
const SCH_SCREEN* screen : sharedScreens )
447 aReporter.
Report( wxString::Format(
_(
"References in %s apply to every sheet that uses it." ),
448 screen->GetFileName() ),
458 aAnnotateScope, aRecursive ) )
470 static_cast<DIALOG_ERC*
>( erc_dlg )->UpdateAnnotationWarning();
489 switch( aAnnotateScope )
502 std::vector<SCH_ITEM*> tempSubSheets;
505 for(
SCH_ITEM* item : tempSubSheets )
530 for(
EDA_ITEM* item : selection.Items() )
std::unordered_set< SCH_SYMBOL * > getInferredSymbols(const SCH_SELECTION &aSelection)
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A base class for most all the KiCad significant classes used in schematics and boards.
KICAD_T Type() const
Returns the type of object.
EDA_ITEM * GetParent() const
wxString AsString() const
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the end of the list, for objects that support report ordering.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SyncView()
Mark all items for refresh.
Commit for the schematic and symbol editors.
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
void mapExistingAnnotation(std::map< wxString, wxString > &aMap)
Fill a map of uuid -> reference from the currently loaded schematic.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
void DeleteAnnotation(ANNOTATE_SCOPE_T aAnnotateScope, bool aRecursive, REPORTER &aReporter)
Clear the current symbol annotation.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
int CheckAnnotate(ANNOTATION_ERROR_HANDLER aErrorHandler, ANNOTATE_SCOPE_T aAnnotateScope, bool aRecursive)
Check for annotation errors.
void AnnotateSymbols(SCH_COMMIT *aCommit, ANNOTATE_SCOPE_T aAnnotateScope, ANNOTATE_ORDER_T aSortOption, ANNOTATE_ALGO_T aAlgoOption, bool aRecursive, int aStartNumber, bool aResetAnnotation, bool aRegroupUnits, bool aRepairTimestamps, REPORTER &aReporter)
Annotate the symbols in the schematic that are not currently annotated.
void UpdateNetHighlightStatus()
A set of SCH_ITEMs (i.e., without duplicates).
Base class for any item which can be embedded within the SCHEMATIC container class,...
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
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 * GetSymbol() const
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
int ReplaceDuplicateTimeStamps()
Test all sheet and symbol objects in the schematic for duplicate time stamps and replaces them as nec...
void GetSheets(std::vector< SCH_ITEM * > *aItems) const
Similar to Items().OfType( SCH_SHEET_T ), but return the sheets in a deterministic order (L-R,...
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void GetSymbolsWithinPath(SCH_REFERENCE_LIST &aReferences, const SCH_SHEET_PATH &aSheetPath, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets that are contained wi...
void GetSheetsWithinPath(std::vector< SCH_SHEET_PATH > &aSheets, const SCH_SHEET_PATH &aSheetPath) const
Add a SCH_SHEET_PATH object to aSheets for each sheet in the list that are contained within aSheetPat...
void GetMultiUnitSymbols(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, SYMBOL_FILTER aSymbolFilter) const
Add a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the li...
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void AppendSymbol(SCH_REFERENCE_LIST &aReferences, SCH_SYMBOL *aSymbol, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Append a SCH_REFERENCE object to aReferences based on aSymbol.
void GetMultiUnitSymbols(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, SYMBOL_FILTER aSymbolFilter) const
Add a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the sh...
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
SCH_SCREEN * LastScreen()
void AppendMultiUnitSymbol(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, SCH_SYMBOL *aSymbol, SYMBOL_FILTER aSymbolFilter) const
Append a SCH_REFERENCE_LIST object to aRefList based on aSymbol, storing same-reference set of multi-...
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
wxString SubReference(int aUnit, bool aAddSeparator=true) const
bool IsAnnotated(const SCH_SHEET_PATH *aSheet) const
Check if the symbol has a valid annotation (reference) for the given sheet path.
void ClearAnnotation(const SCH_SHEET_PATH *aSheetPath, bool aResetPrefix)
Clear exiting symbol annotation.
const wxString GetValue(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString) const override
int GetUnitCount() const override
Return the number of units per package of the symbol.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
This file is part of the common library.
#define DIALOG_ERC_WINDOW_NAME
Class to handle a set of SCH_ITEMs.
std::set< const SCH_SCREEN * > AnnotateReferences(SCH_REFERENCE_LIST &aRefs, SCH_MULTI_UNIT_REFERENCE_MAP aLocked, const SCHEMATIC &aSchematic, ANNOTATE_SCOPE_T aScope, ANNOTATE_ORDER_T aSortOption, ANNOTATE_ALGO_T aAlgoOption, int aStartNumber, bool aResetAnnotation, const std::function< void(SCH_REFERENCE &)> &aBeforeAnnotate)
Annotate aRefs, the references in aScope, around every other symbol of aSchematic.
std::optional< std::pair< SCH_SHEET_PATH, SCH_SHEET_PATH > > FindRefSuffixCollision(const SCH_REFERENCE_LIST &aRefs, const SCHEMATIC &aSchematic)
Find two instances of a reused sheet that aRefs reaches and that compose the same reference suffix.
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.
ANNOTATE_SCOPE_T
Schematic annotation scope options.
@ ANNOTATE_SELECTION
Annotate the selection.
@ ANNOTATE_CURRENT_SHEET
Annotate the current sheet.
@ ANNOTATE_ALL
Annotate the full schematic.
ANNOTATE_ALGO_T
Schematic annotation type options.
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.
@ SYMBOL_FILTER_NON_POWER
@ REFERENCE
Field Reference of part, i.e. "IC21".