48 m_rootSheet( nullptr )
69 if( !symbol || aProperty->
Name() !=
_HKI(
"Text" ) )
75 wxString newValue = aItem->
Get<wxString>( aProperty );
77 if( field->
GetId() == FIELD_T::REFERENCE )
79 symbol->
SetRef( &sheetPath, newValue );
87 wxString ref = symbol->
GetRef( &sheetPath );
93 std::vector<SCH_SYMBOL*> otherUnits;
99 switch( field->
GetId() )
102 case FIELD_T::FOOTPRINT:
103 case FIELD_T::DATASHEET:
106 aCommit->
Modify( otherUnit, sheet.LastScreen() );
108 otherUnit->GetField( field->
GetId() )->SetText( newValue );
140 project.m_ErcSettings =
nullptr;
143 delete project.m_SchematicSettings;
144 project.m_SchematicSettings =
nullptr;
166 project.m_ErcSettings =
nullptr;
169 delete project.m_SchematicSettings;
170 project.m_SchematicSettings =
nullptr;
181 project.m_SchematicSettings->LoadFromFile();
182 project.m_SchematicSettings->m_NgspiceSettings->LoadFromFile();
183 project.m_ErcSettings->LoadFromFile();
190 wxCHECK_RET( aRootSheet, wxS(
"Call to SetRoot with null SCH_SHEET!" ) );
225 [&](
const wxString& aVar )
228 aVars->push_back( aVar );
233 add( wxT(
"SHEETPATH" ) );
234 add( wxT(
"SHEETNAME" ) );
235 add( wxT(
"FILENAME" ) );
236 add( wxT(
"FILEPATH" ) );
237 add( wxT(
"PROJECTNAME" ) );
250 wxCHECK( aSheetPath,
false );
252 if( token->IsSameAs( wxT(
"#" ) ) )
257 else if( token->IsSameAs( wxT(
"##" ) ) )
259 *token = wxString::Format(
"%i",
Root().CountSheets() );
262 else if( token->IsSameAs( wxT(
"SHEETPATH" ) ) )
267 else if( token->IsSameAs( wxT(
"SHEETNAME" ) ) )
272 else if( token->IsSameAs( wxT(
"FILENAME" ) ) )
275 *token = fn.GetFullName();
278 else if( token->IsSameAs( wxT(
"FILEPATH" ) ) )
281 *token = fn.GetFullPath();
284 else if( token->IsSameAs( wxT(
"PROJECTNAME" ) ) )
293 if(
Prj().TextVarResolver( token ) )
330 std::set<wxString> migratedExclusions;
344 const wxString settingsKey = testMarker->
GetRCItem()->GetSettingsKey();
346 if( settingsKey != wxT(
"pin_to_pin" )
347 && settingsKey != wxT(
"hier_label_mismatch" )
348 && settingsKey != wxT(
"different_unit_net" ) )
363 settings.
m_ErcExclusions.insert( migratedExclusions.begin(), migratedExclusions.end() );
373 std::set<wxString>::iterator it = settings.
m_ErcExclusions.find( serialized );
383 std::vector<SCH_MARKER*> newMarkers;
392 newMarkers.push_back( marker );
406 for(
const std::shared_ptr<BUS_ALIAS>& alias : sheet.LastScreen()->GetBusAliases() )
408 if( alias->GetName() == aLabel )
419 std::set<wxString> names;
428 names.insert( key.Name );
439 wxString ref = token->BeforeFirst(
':', &remainder );
445 if(
path.size() > 1 )
455 if( refSymbol->
ResolveTextVar( &sheetPath, &remainder, aDepth + 1 ) )
458 *token = refSymbol->
GetRef( &sheetPath,
true ) + wxS(
":" ) + remainder;
468 if( refSheet->
ResolveTextVar( &sheetPath, &remainder, aDepth + 1 ) )
480 std::map<int, wxString> namesMap;
484 if( sheet.size() == 1 )
485 namesMap[sheet.GetVirtualPageNumber()] =
_(
"<root sheet>" );
487 namesMap[sheet.GetVirtualPageNumber()] = sheet.Last()->GetName();
496 std::map<int, wxString> pagesMap;
499 pagesMap[sheet.GetVirtualPageNumber()] = sheet.GetPageNumber();
508 size_t sourceLen = aSource.length();
510 for(
size_t i = 0; i < sourceLen; ++i )
512 if( aSource[i] ==
'$' && i + 1 < sourceLen && aSource[i+1] ==
'{' )
515 bool isCrossRef =
false;
518 for( i = i + 2; i < sourceLen; ++i )
520 if( aSource[i] ==
'{'
521 && ( aSource[i-1] ==
'_' || aSource[i-1] ==
'^' || aSource[i-1] ==
'~' ) )
526 if( aSource[i] ==
'}' )
534 if( aSource[i] ==
':' )
537 token.append( aSource[i] );
543 wxString ref = token.BeforeFirst(
':', &remainder );
548 for(
size_t jj = 0; jj < references.
GetCount(); jj++ )
550 SCH_SYMBOL* refSymbol = references[ jj ].GetSymbol();
552 if( ref == refSymbol->
GetRef( &references[ jj ].GetSheetPath(),
true ) )
557 token =
path.AsString() + wxS(
":" ) + remainder;
563 newbuf.append( wxS(
"${" ) + token + wxS(
"}" ) );
567 newbuf.append( aSource[i] );
578 size_t sourceLen = aSource.length();
580 for(
size_t i = 0; i < sourceLen; ++i )
582 if( aSource[i] ==
'$' && i + 1 < sourceLen && aSource[i+1] ==
'{' )
585 bool isCrossRef =
false;
587 for( i = i + 2; i < sourceLen; ++i )
589 if( aSource[i] ==
'}' )
592 if( aSource[i] ==
':' )
595 token.append( aSource[i] );
601 wxString ref = token.BeforeFirst(
':', &remainder );
607 if(
path.size() > 1 )
616 token = refSymbol->
GetRef( &sheetPath,
true ) + wxS(
":" ) + remainder;
620 newbuf.append( wxS(
"${" ) + token + wxS(
"}" ) );
624 newbuf.append( aSource[i] );
647 wxString filename = rootFn.GetName();
663 int sheet_number = 1;
670 if( sheet.Path() == current_sheetpath )
676 for( screen = s_list.
GetFirst(); screen !=
nullptr; screen = s_list.
GetNext() )
688 std::map<wxString, std::set<int>>& pageRefsMap =
GetPageRefsMap();
697 wxString resolvedLabel = global->
GetShownText( &sheet,
false );
699 pageRefsMap[ resolvedLabel ].insert( sheet.GetVirtualPageNumber() );
708 std::vector<SCH_GLOBALLABEL*> currentSheetGlobalLabels;
711 currentSheetGlobalLabels.push_back(
static_cast<SCH_GLOBALLABEL*
>( item ) );
715 std::vector<SCH_FIELD>& fields = globalLabel->GetFields();
717 fields[0].SetVisible( show );
721 if( fields.size() == 1 && fields[0].GetTextPos() == globalLabel->GetPosition() )
725 aItemCallback( globalLabel );
732 const wxString& aRange )
734 wxString spiceNetName( aNetName.Lower() );
737 if( spiceNetName == wxS(
"gnd" ) || spiceNetName == wxS(
"0" ) )
738 return wxEmptyString;
757 std::deque<EDA_ITEM*> allItems;
759 for(
auto item : screen->Items() )
760 allItems.push_back( item );
763 for(
const VECTOR2I& point : screen->GetNeededJunctions( allItems ) )
766 screen->Append( junction );
769 for(
SCH_LINE* wire : screen->GetBusesAndWires( point,
true ) )
772 screen->Append( newSegment );
837 for(
unsigned i = 0; i < sheetList.size(); i++ )
885 std::set<KIFONT::OUTLINE_FONT*>
fonts;
891 for(
SCH_ITEM* item : sheet.LastScreen()->Items() )
903 if( outline->GetEmbeddingPermission() == EMBEDDING_PERMISSION::EDITABLE
904 || outline->GetEmbeddingPermission() == EMBEDDING_PERMISSION::INSTALLABLE )
906 fonts.insert( outline );
926 wxLogTrace(
"EMBED",
"Failed to add font file: %s", font->GetFileName() );
937 std::set<const SCH_SCREEN*> retv;
950 const std::vector<SCH_SYMBOL_INSTANCE> symbolInstances = symbol->
GetInstances();
954 if( !hierarchy.
HasPath( instance.m_Path ) )
956 retv.insert( screen );
961 if( retv.count( screen ) )
978 wxCHECK2( screen,
continue );
980 if( screen->GetRefCount() > 1 )
void SetPageCount(int aPageCount)
void SetPageNumber(const wxString &aPageNumber)
void SetVirtualPageNumber(int aPageNumber)
Represent a set of changes (additions, deletions or modifications) of a data model (e....
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Modify a given item in the model.
Calculate the connectivity of a schematic and generates netlists.
const NET_MAP & GetNetMap() const
A subgraph is a set of items that are electrically connected on a single sheet.
static PRIORITY GetDriverPriority(SCH_ITEM *aDriver)
Return the priority (higher is more important) of a candidate driver.
const SCH_CONNECTION * GetDriverConnection() const
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
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
Container for ERC settings.
std::map< wxString, wxString > m_ErcExclusionComments
std::set< wxString > m_ErcExclusions
Class that other classes need to inherit from, in order to be inspectable.
wxAny Get(PROPERTY_BASE *aProperty) const
FONT is an abstract base class for both outline and stroke fonts.
virtual bool IsStroke() const
Class OUTLINE_FONT implements outline font drawing.
A logical library item identifier and consists of various portions much like a URI.
std::shared_ptr< RC_ITEM > GetRCItem() const
void SetExcluded(bool aExcluded, const wxString &aComment=wxEmptyString)
wxString GetComment() const
static void ConvertToSpiceMarkup(wxString *aNetName)
Remove formatting wrappers and replace illegal spice net name characters with underscores.
The backing store for a PROJECT, in JSON format.
ERC_SETTINGS * m_ErcSettings
Eeschema params.
SCHEMATIC_SETTINGS * m_SchematicSettings
Container for project specific data.
virtual const wxString GetProjectName() const
Return the short name of the project.
virtual PROJECT_FILE & GetProjectFile() const
const wxString & Name() const
static PROPERTY_MANAGER & Instance()
void UnregisterListeners(TYPE_ID aType)
void RegisterListener(TYPE_ID aType, PROPERTY_LISTENER aListenerFunc)
Registers a listener for the given type.
virtual void OnSchItemsRemoved(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
virtual void OnSchSheetChanged(SCHEMATIC &aSch)
virtual void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
These are loaded from Eeschema settings but then overwritten by the project settings.
bool m_IntersheetRefsShow
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
std::set< const SCH_SCREEN * > GetSchematicsSharedByMultipleProjects() const
Return a list of schematic files in the current project that contain instance data for multiple proje...
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
void OnItemsAdded(std::vector< SCH_ITEM * > &aNewItems)
Must be used if Add() is used using a BULK_x ADD_MODE to generate a change event for listeners.
CONNECTION_GRAPH * m_connectionGraph
Hold and calculate connectivity information of this schematic.
SCH_SHEET_LIST m_hierarchy
Cache of the entire schematic hierarchy sorted by sheet page number.
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
bool IsComplexHierarchy() const
Test if the schematic is a complex hierarchy.
void OnSchSheetChanged()
Notify the schematic and its listeners that the current sheet has been changed.
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
void OnItemsRemoved(std::vector< SCH_ITEM * > &aRemovedItems)
Must be used if Remove() is used using a BULK_x REMOVE_MODE to generate a change event for listeners.
std::shared_ptr< BUS_ALIAS > GetBusAlias(const wxString &aLabel) const
Return a pointer to a bus alias object for the given label, or null if one doesn't exist.
std::vector< SCH_MARKER * > ResolveERCExclusions()
void EmbedFonts() override
Embed fonts in the schematic.
SCHEMATIC_SETTINGS & Settings() const
wxString ConvertKIIDsToRefs(const wxString &aSource) const
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
std::map< wxString, std::set< int > > & GetPageRefsMap()
void FixupJunctions()
Add junctions to this schematic where required.
std::set< KIFONT::OUTLINE_FONT * > GetFonts() const override
Get a set of fonts used in the schematic.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
wxString ConvertRefsToKIIDs(const wxString &aSource) const
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
void SetProject(PROJECT *aPrj)
void AddListener(SCHEMATIC_LISTENER *aListener)
Add a listener to the schematic to receive calls whenever something on the schematic has been modifie...
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
EMBEDDED_FILES * GetEmbeddedFiles() override
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
void RecomputeIntersheetRefs(const std::function< void(SCH_GLOBALLABEL *)> &aItemCallback)
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
void InvokeListeners(Func &&aFunc, Args &&... args)
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
void RemoveAllListeners()
Remove all listeners.
void GetContextualTextVars(wxArrayString *aVars) const
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
wxString GetUniqueFilenameForCurrentSheet()
Get the unique file name for the current sheet.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
SCH_SHEET_PATH & CurrentSheet() const
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
ERC_SETTINGS & ErcSettings() const
void OnItemsChanged(std::vector< SCH_ITEM * > &aItems)
Notify the schematic and its listeners that an item on the schematic has been modified in some way.
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Base class for any item which can be embedded within the SCHEMATIC container class,...
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const override
Segment description base class to describe items which have 2 end points (track, wire,...
SCH_LINE * BreakAt(const VECTOR2I &aPoint)
Break this segment into two at the specified point.
static SCH_MARKER * DeserializeFromString(const SCH_SHEET_LIST &aSheetList, const wxString &data)
wxString SerializeToString() const
bool IsLegacyMarker() const
Determine if this marker is legacy (i.e.
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
const wxString & GetFileName() const
const TITLE_BLOCK & GetTitleBlock() const
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
std::optional< SCH_SHEET_PATH > GetSheetPathByKIIDPath(const KIID_PATH &aPath, bool aIncludeLastSheet=true) const
Finds a SCH_SHEET_PATH that matches the provided KIID_PATH.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Fetch a SCH_ITEM by ID.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
bool HasPath(const KIID_PATH &aPath) const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false) const
Return the sheet path in a human readable form made from the sheet names.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
wxString GetPageNumber() const
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.
void SetVirtualPageNumber(int aPageNumber)
Set the sheet instance virtual page number.
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void clear()
Forwarded method from std::vector.
size_t size() const
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
int CountSheets() const
Count the number of sheets found in "this" sheet including all of the subsheets.
SCH_SCREEN * GetScreen() const
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
const LIB_ID & GetLibId() const override
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Helper class to recognize Spice formatted values.
wxString ToString() const
Return string value as when converting double to string (e.g.
bool TextVarResolver(wxString *aToken, const PROJECT *aProject, int aFlags=0) const
static void GetContextualTextVars(wxArrayString *aVars)
wxString GetTextVars(const wxString &aSource)
Returns any variables unexpanded, e.g.
static bool empty(const wxTextEntryBase *aCtrl)
void ignore_unused(const T &)
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
void CollectOtherUnits(const wxString &aRef, int aUnit, const LIB_ID &aLibId, SCH_SHEET_PATH &aSheet, std::vector< SCH_SYMBOL * > *otherUnits)
A simple container for schematic symbol instance information.