20#ifndef KICAD_SCHEMATIC_H
21#define KICAD_SCHEMATIC_H
39#include <unordered_map>
163 return wxT(
"SCHEMATIC" );
261 std::vector<std::pair<SCH_SHEET_PATH, SCH_SHEET_PATH>>
RefSuffixCollisions(
bool aIncludeEmpty )
const;
277 bool aAllowNullptrReturn =
false )
const
279 return m_hierarchy.ResolveItem( aID, aPathOut, aAllowNullptrReturn );
435 std::shared_ptr<BUS_ALIAS>
GetBusAlias(
const wxString& aLabel )
const;
437 void AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
439 void SetBusAliases(
const std::vector<std::shared_ptr<BUS_ALIAS>>& aAliases );
541 wxString
GetOperatingPoint(
const wxString& aNetName,
int aPrecision,
const wxString& aRange );
638 std::set<KIFONT::OUTLINE_FONT*>
GetFonts()
const override;
668 const std::set<SCH_SCREEN*>& aLocalScreens = {} );
672 PROGRESS_REPORTER* aProgressReporter =
nullptr,
673 KIGFX::SCH_VIEW* aSchView =
nullptr );
688 TOOL_MANAGER* aToolManager,
689 PROGRESS_REPORTER* aProgressReporter =
nullptr,
690 KIGFX::SCH_VIEW* aSchView =
nullptr,
691 std::function<
void( SCH_ITEM* )>* aChangedItemHandler =
nullptr,
692 PICKED_ITEMS_LIST* aLastChangeList =
nullptr,
693 bool aCleanupDone =
false );
709 bool Contains(
const SCH_REFERENCE& aRef )
const;
740 void DeleteVariant(
const wxString& aVariantName, SCH_COMMIT* aCommit );
742 void AddVariant(
const wxString& aVariantName );
753 void RenameVariant(
const wxString& aOldName,
const wxString& aNewName, SCH_COMMIT* aCommit );
765 void CopyVariant(
const wxString& aSourceVariant,
const wxString& aNewVariant, SCH_COMMIT* aCommit );
775 bool HasVariant(
const wxString& aVariantName )
const;
817 void Show(
int nestLevel, std::ostream& os )
const override {}
831 void SaveToHistory(
const wxString& aProjectPath, std::vector<HISTORY_FILE_DATA>& aFileData );
844 template <
typename Func,
typename... Args>
848 ( l->*aFunc )( std::forward<Args>( args )... );
Calculate the connectivity of a schematic and generate netlists.
The base frame for deriving all KiCad main window classes.
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Implement an R-tree for fast spatial and type indexing of schematic items.
Container for ERC settings.
Implement outline font drawing.
Define a library symbol object.
A holder to handle information on schematic or board items.
A progress reporter interface for use in multi-threaded environments.
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Container for project specific data.
ELEM
The set of _ELEM objects that a PROJECT can hold.
Move-only RAII wrapper around a single listener registration.
This is a bridge class to help the schematic be able to affect SCH_EDIT_FRAME without doing anything ...
virtual void OnSchItemsRemoved(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
virtual ~SCHEMATIC_LISTENER()
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
virtual void OnSchSelectionChanged(SCHEMATIC &aSch)
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_AnnotateReusedSheetSuffixes
Bridges SCHEMATIC's listener stream into the generic TEXT_VAR_TRACKER.
Holds all the data relating to one schematic.
void DeleteVariantDefinition(const wxString &aVariantName)
Delete the definition of a variant.
void SetCurrentVariant(const wxString &aVariantName)
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
bool m_settingTopLevelSheets
Re-entry guard to prevent infinite recursion between ensureDefaultTopLevelSheet and RefreshHierarchy ...
std::unique_ptr< SCH_CONNECTIVITY::NETCHAIN_MANAGER > m_netChains
void updatePackageSuffixes() const
Rebuild m_packageSuffixes when a reference changed; the caller holds m_packageSuffixesMutex.
wxString GetUnitRefSuffix(const SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aPath, int aUnit) const
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...
std::map< std::pair< KIID, KIID_PATH >, wxString > m_packageSuffixes
Package suffix of each instance whose package spans suffixes and is not its own sheet's.
void CreateDefaultScreens()
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.
SCH_CONNECTIVITY::NETCHAIN_MANAGER & NetChains() const
CONNECTION_GRAPH * m_connectionGraph
Hold and calculate connectivity information of this schematic.
std::shared_ptr< void > m_historyLifetime
Sentinel whose expiry signals to LOCAL_HISTORY that this schematic has been destroyed.
virtual wxString GetClass() const override
Return the class name.
bool IsTopLevelSheet(const SCH_SHEET *aSheet) const
Check if a sheet is a top-level sheet (direct child of virtual root).
void loadBusAliasesFromProject()
std::unordered_map< size_t, wxString > m_refSuffixesBySheetHash
Every hierarchy path's suffix by its cached sheet path hash, which SCH_SHEET_PATH equality also relie...
void AddTopLevelSheet(SCH_SHEET *aSheet)
Add a new top-level sheet to the schematic.
SCH_SHEET_LIST m_hierarchy
Cache of the entire schematic hierarchy sorted by sheet page number.
@ TABLE_REMOVED
The reread file has no table; the one in use is kept, even empty, and saved back.
@ CHANGED
The project table changed the aliases in use, so connectivity needs a rebuild.
void rebuildHierarchyState(bool aResetConnectionGraph)
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
void RecomputeIntersheetRefs()
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
std::vector< SCH_MARKER * > ReloadERCExclusions()
Resolve exclusions again after the project file was reread.
void CacheExistingAnnotation()
Store all existing annotations in the REFDES_TRACKER.
wxString GetVariantDescription(const wxString &aVariantName) const
Return the description for a variant.
void LoadVariants()
This is a throw away method for variant testing.
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
const std::vector< std::shared_ptr< BUS_ALIAS > > & GetAllBusAliases() const
bool HasVariant(const wxString &aVariantName) const
Return true if a variant with this name exists in the schematic (case-insensitively).
const wxString & GetHighlightedNetChain() const
std::set< KIID > m_unitSplitSymbols
Symbols whose copies select different units.
std::vector< std::pair< SCH_SHEET_PATH, SCH_SHEET_PATH > > RefSuffixCollisions(bool aIncludeEmpty) const
Find instances of one sheet file whose composed reference suffixes collide.
bool resolveCrossReference(wxString *aToken, int aDepth) const
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.
void SetSchematicHolder(SCHEMATIC_HOLDER *aHolder)
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
std::vector< SCH_SHEET * > m_topLevelSheets
List of top-level sheets (direct children of virtual root)
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
void CleanUp(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen=nullptr)
Perform routine schematic cleaning including breaking wire and buses and deleting identical objects s...
void CopyVariant(const wxString &aSourceVariant, const wxString &aNewVariant, SCH_COMMIT *aCommit)
Copy a variant from aSourceVariant to aNewVariant.
bool TopLevelSheetsMatch(const std::vector< TOP_LEVEL_SHEET_INFO > &aSheets) const
Check a project file's top-level sheet list against the sheets this schematic loaded.
bool IsTopLevelSheetUuid(const KIID &aUuid) const
Check if a UUID names one of this schematic's top level sheets.
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.
void AddVariant(const wxString &aVariantName)
void OnSchSelectionChanged()
Notify the schematic and its listeners that the editor selection has changed.
std::string FormatRefSuffixes() const
void AdoptContent(SCHEMATIC_CONTENT &&aContent) noexcept
Take a staged schematic over from an importer in one indivisible step.
bool m_hasRefSuffixFields
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.
bool HasRefSuffixes() const
True when suffix numbering is enabled and a hierarchy path has a composed suffix.
std::vector< SCH_MARKER * > ResolveERCExclusions()
void SaveToHistory(const wxString &aProjectPath, std::vector< HISTORY_FILE_DATA > &aFileData)
Serialize schematic sheets into HISTORY_FILE_DATA for non-blocking history commit.
const wxString * findRefSuffix(const SCH_SHEET_PATH &aPath) const
The cached suffix of aPath, or nullptr when it has none.
void EmbedFonts() override
Embed fonts in the schematic.
SCHEMATIC_SETTINGS & Settings() const
void ClearOperatingPoints()
Clear operating points from a .op simulation.
wxString GetPackageRefSuffix(const SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aPath) const
Return the suffix the package of a multi-unit symbol's instance composes with.
SCH_SCREEN * GetCurrentScreen() const
wxString ConvertKIIDsToRefs(const wxString &aSource) const
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
void ensureCurrentSheetIsTopLevel()
void SyncLibSymbolPinMaps(const wxString &aSchLibSymbolName, const LIB_SYMBOL &aSource, SCH_COMMIT *aCommit)
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< std::pair< wxString, wxString >, std::map< int, wxString > > m_packageUnitSuffixes
Sheet suffix of each placed unit of a package spanning suffixes, keyed by base and LIB_ID.
wxString m_currentVariant
std::map< wxString, std::set< int > > & GetPageRefsMap()
SCH_SHEET_LIST BuildUnorderedSheetList() const
std::unordered_map< KIID_PATH, wxString > m_refSuffixes
Composed reference suffix of each hierarchy path that has one.
class SCHEMATIC_TEXT_VAR_ADAPTER * GetTextVarAdapter() const
void SetHighlightedNetChain(const wxString &aNetChain)
PROJECT & Project() const
Return a reference to the project this schematic is part of.
std::map< wxString, std::set< int > > m_labelToPageRefsMap
Holds a map of labels to the page sequence (virtual page number) that they appear on.
std::mutex m_packageSuffixesMutex
bool HasHierarchy() const
Check if the hierarchy has been built.
std::set< KIFONT::OUTLINE_FONT * > GetFonts() const override
Get a set of fonts used in the schematic.
SCH_SHEET * GetTopLevelSheet(int aIndex=0) const
bool RemoveTopLevelSheet(SCH_SHEET *aSheet)
Remove a top-level sheet from the schematic.
std::optional< IMPORT_NET_MAP > m_importNetMap
bool Contains(const SCH_REFERENCE &aRef) const
Check if the schematic contains the specified reference.
std::optional< wxString > spanningPackageSuffix(const SCH_SYMBOL *aSymbol, const KIID_PATH &aPath) const
The suffix of a package spanning sheets that aSymbol on aPath belongs to, if any.
const IMPORT_NET_MAP * GetImportNetMap() const
void ClearUnresolvedERCExclusions(int aErrorCode=-1)
std::vector< ERC_EXCLUSION > m_unresolvedErcExclusions
Exclusions whose saved identity cannot currently be reconstructed as a marker.
SCH_CONNECTIVITY::FACADE & Connectivity() const
size_t GetUnresolvedERCExclusionCount() const
wxString ConvertRefsToKIIDs(const wxString &aSource) const
void SetProject(PROJECT *aPrj)
void DeleteVariant(const wxString &aVariantName, SCH_COMMIT *aCommit)
Delete all information for aVariantName.
bool IsHierarchyModified() const
True when any sheet in the hierarchy has unsaved changes.
wxString GetCurrentVariant() const
Return the current variant being edited.
void AddListener(SCHEMATIC_LISTENER *aListener)
Add a listener to the schematic to receive calls whenever something on the schematic has been modifie...
void CleanUpConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, const std::set< SCH_SCREEN * > &aLocalScreens={})
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
EMBEDDED_FILES * GetEmbeddedFiles() override
wxString GetRefSuffix(const SCH_SHEET_PATH &aPath) const
Return the composed reference suffix of aPath as of the last RefreshHierarchy().
CONNECTION_GRAPH * ConnectionGraph() const
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.
std::vector< std::shared_ptr< BUS_ALIAS > > m_busAliases
bool ReloadProjectVariants()
Take the variant list from the project file again after it was reread.
void RefreshRefSuffixes()
Recompose the reference suffix of every sheet path in the hierarchy.
void InvokeListeners(Func &&aFunc, Args &&... args)
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
void updateProjectBusAliases()
void SetVariantDescription(const wxString &aVariantName, const wxString &aDescription)
Set the description for a variant.
void RemoveAllListeners()
Remove all listeners.
std::optional< uint64_t > m_packageSuffixesGeneration
void SetTopLevelSheets(const std::vector< SCH_SHEET * > &aSheets)
Replace the top level sheets, rebuilding the hierarchy and connectivity around them.
void RebuildConnectivity(std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr, KIGFX::SCH_VIEW *aSchView=nullptr)
std::unique_ptr< class SCHEMATIC_TEXT_VAR_ADAPTER > m_textVarAdapter
Reactive text-variable dependency adapter.
void RenameVariant(const wxString &aOldName, const wxString &aNewName, SCH_COMMIT *aCommit)
Rename a variant from aOldName to aNewName.
bool HasProjectBusAliases() const
PROPERTY_LISTENER_SUBSCRIPTION m_fieldListenerSubscription
PROPERTY_MANAGER listener subscription installed in the ctor.
BUS_ALIAS_RELOAD ReloadProjectBusAliases()
Take the bus aliases from the project file again after it was reread.
const std::set< wxString > & GetVariantNames() const
Return the set of variant names (without the default placeholder).
const std::map< wxString, wxString > * GetProperties()
void GetContextualTextVars(wxArrayString *aVars) const
void SetOperatingPoint(const wxString &aNetChain, double aValue)
Set operating points from a .op simulation.
friend class SCH_EDIT_FRAME
void ensureDefaultTopLevelSheet()
std::set< KIID > SplitUnitSymbols() const
Symbols whose copies select different units, for loops that change references as they go.
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, TOOL_MANAGER *aToolManager, PROGRESS_REPORTER *aProgressReporter=nullptr, KIGFX::SCH_VIEW *aSchView=nullptr, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr, PICKED_ITEMS_LIST *aLastChangeList=nullptr, bool aCleanupDone=false)
Generate the connection data for the entire schematic hierarchy.
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
std::vector< SCH_SHEET * > GetTopLevelSheets() const
Get the list of top-level sheets.
wxArrayString GetVariantNamesForUI() const
Return an array of variant names for using in wxWidgets UI controls.
bool CopiesSelectDifferentUnits(const SCH_SYMBOL *aSymbol) const
void RunOnNestedEmbeddedFiles(const std::function< void(EMBEDDED_FILES *)> &aFunction) override
Provide access to nested embedded files, such as symbols in schematics and footprints in boards.
std::unique_ptr< SCH_CONNECTIVITY::FACADE > m_connectivity
SCHEMATIC_HOLDER * m_schematicHolder
What currently "Holds" the schematic, i.e.
wxString GetUniqueFilenameForCurrentSheet()
Get the unique file name for the current sheet.
std::weak_ptr< void > GetHistoryLifetimeToken() const
Liveness token handed to LOCAL_HISTORY::RegisterSaver so a shared autosave timer skips this schematic...
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void SetImportNetMap(IMPORT_NET_MAP aMap)
void SetBusAliases(const std::vector< std::shared_ptr< BUS_ALIAS > > &aAliases)
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
void AppendRefSuffix(wxString &aRef, const SCH_SHEET_PATH &aPath) const
Append the composed reference suffix of aPath to aRef without copying it.
SCH_SHEET_PATH & CurrentSheet() const
bool m_busAliasesFromTable
The aliases in use came from a project table rather than from the sheets.
std::vector< TOP_LEVEL_SHEET_INFO > TopLevelSheetInfos() const
The top-level sheets as the project file records them, with file names relative to the project.
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
wxString m_highlightedNetChain
int FixupJunctionsAfterImport(const std::function< void(SCH_LINE *, SCH_LINE *)> &aOnSplit={})
Add junctions to this schematic where required.
KIID_PATH NormalizeInstancePath(const KIID_PATH &aPath) const
Strip the leading virtual root from a stored instance path, which SCH_SHEET_PATH::Path() omits but st...
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
ERC_SETTINGS & ErcSettings() const
std::set< wxString > m_variantNames
std::map< std::pair< KIID, KIID_PATH >, wxString > PackageRefSuffixes() const
Symbol and sheet path of each instance whose package suffix is another sheet's, with that suffix.
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.
bool HasRefSuffixFields() const
True when a sheet in the hierarchy has suffix text, even text that resolves to nothing.
static wxFileName TopLevelSheetFile(const TOP_LEVEL_SHEET_INFO &aSheet, const wxString &aProjectPath, bool aLegacy)
The file loaded for a listed top-level sheet. A legacy project reads it under the legacy extension.
PROJECT::ELEM ProjectElementType() override
SCH_SHEET * m_rootSheet
The virtual root sheet (has no screen, contains all top-level sheets)
bool IsInstancePathInProject(const KIID_PATH &aPath) const
Test whether an instance path is rooted in this schematic's top level sheets.
Commit for the schematic and symbol editors.
Model-owned source resolver.
Persistent chain configuration and the derived chains for one schematic.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Segment description base class to describe items which have 2 end points (track, wire,...
A helper to define a symbol's reference designator in a schematic.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
The Cairo implementation of the graphics abstraction layer.
Value keys and the key session of the schematic connectivity engine.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Data produced by a registered saver on the UI thread, consumed by either the background local-history...
Import provenance, held only for the lifetime of the importing SCHEMATIC.
A schematic staged off to the side by an importer, ready to be swapped into a live SCHEMATIC in one s...
std::optional< EMBEDDED_FILES > embeddedFiles
std::unique_ptr< SCH_SCREEN > screen
Screen that replaces the target sheet's screen outright.
std::optional< SCH_SHEET_PATH > currentSheet
std::vector< std::unique_ptr< SCH_ITEM > > itemOwners
Items in screenItems that nothing else owns yet.
std::unique_ptr< CONNECTION_GRAPH > connectionGraph
bool preserveNetChains
Keep the schematic's net chains instead of the staged graph's, for append.
std::vector< SCH_SHEET * > topLevelSheets
Replacement top level sheets. Empty leaves the schematic's own in place.
SCH_SHEET * targetSheet
Sheet whose screen receives the content. Null names the schematic's virtual root.
std::unique_ptr< SCH_SCREEN > screenLibSymbols
Screen holding only the library cache that the target screen adopts.
EE_RTREE screenItems
Spatial index that replaces the target screen's own.
wxString drawingSheetFileName
Information about a top-level schematic sheet.