KiCad PCB EDA Suite
Loading...
Searching...
No Matches
schematic.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef KICAD_SCHEMATIC_H
21#define KICAD_SCHEMATIC_H
22
23#include <eda_item.h>
24#include <embedded_files.h>
25#include <schematic_holder.h>
26#include <sch_sheet_path.h>
27#include <schematic_settings.h>
28#include <project.h>
29
30
32class BUS_ALIAS;
34class EDA_BASE_FRAME;
35class ERC_SETTINGS;
36class PROJECT;
37class SCH_COMMIT;
38class SCH_LINE;
39class SCH_SCREEN;
40class SCH_SHEET;
41class SCH_SHEET_LIST;
42class SCH_GLOBALLABEL;
43class SCH_REFERENCE;
45class TOOL_MANAGER;
47
48namespace KIFONT
49{
50class OUTLINE_FONT;
51}
52
53namespace KIGFX
54{
55class SCH_VIEW;
56}
57
58
59class SCHEMATIC;
60
62{
63public:
65 virtual void OnSchItemsAdded( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
66 virtual void OnSchItemsRemoved( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
67 virtual void OnSchItemsChanged( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
68
69 // This is called when the user changes to a new sheet, not when a sheet is altered.
70 // Sheet alteration events will call OnSchItems*
71 virtual void OnSchSheetChanged( SCHEMATIC& aSch ) {}
72};
73
80
88class SCHEMATIC : public EDA_ITEM, public EMBEDDED_FILES, public PROJECT::_ELEM
89{
90public:
91 SCHEMATIC( PROJECT* aPrj );
92
93 virtual ~SCHEMATIC();
94
95 virtual wxString GetClass() const override
96 {
97 return wxT( "SCHEMATIC" );
98 }
99
101 void Reset();
102
104 PROJECT& Project() const { return *m_project; }
105 void SetProject( PROJECT* aPrj );
106
107 const std::map<wxString, wxString>* GetProperties() { return &m_properties; }
108
110
112
117
123 bool HasHierarchy() const { return !m_hierarchy.empty(); }
124
125 void RefreshHierarchy();
126
127 SCH_ITEM* ResolveItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr,
128 bool aAllowNullptrReturn = false ) const
129 {
130 return m_hierarchy.ResolveItem( aID, aPathOut, aAllowNullptrReturn );
131 }
132
134 {
135 return *m_rootSheet;
136 }
137
143 std::vector<SCH_SHEET*> GetTopLevelSheets() const;
144
145 SCH_SHEET* GetTopLevelSheet( int aIndex = 0 ) const;
146
147 void SetTopLevelSheets( const std::vector<SCH_SHEET*>& aSheets );
148
154 void AddTopLevelSheet( SCH_SHEET* aSheet );
155
162 bool RemoveTopLevelSheet( SCH_SHEET* aSheet );
163
170 bool IsTopLevelSheet( const SCH_SHEET* aSheet ) const;
171
173 bool IsValid() const
174 {
175 return m_project && m_rootSheet != nullptr;
176 }
177
179 SCH_SCREEN* RootScreen() const;
180
181 void GetContextualTextVars( wxArrayString* aVars ) const;
182
183 bool ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token, int aDepth ) const;
184
186 wxString GetFileName() const;
187
189 {
190 return *m_currentSheet;
191 }
192
193 void SetCurrentSheet( const SCH_SHEET_PATH& aPath )
194 {
195 *m_currentSheet = aPath;
196 }
197
199
201 {
202 return m_connectionGraph;
203 }
204
205 const wxString& GetHighlightedNetChain() const { return m_highlightedNetChain; }
206 void SetHighlightedNetChain( const wxString& aNetChain ) { m_highlightedNetChain = aNetChain; }
207
209
210 ERC_SETTINGS& ErcSettings() const;
211
212 std::vector<SCH_MARKER*> ResolveERCExclusions();
213
215 const EMBEDDED_FILES* GetEmbeddedFiles() const;
216
221 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
222
223 void AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
224
225 void SetBusAliases( const std::vector<std::shared_ptr<BUS_ALIAS>>& aAliases );
226
227 const std::vector<std::shared_ptr<BUS_ALIAS>>& GetAllBusAliases() const
228 {
229 return m_busAliases;
230 }
231
238 std::set<wxString> GetNetClassAssignmentCandidates();
239
246 bool ResolveCrossReference( wxString* token, int aDepth ) const;
247
248 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
249
250 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
251 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
252
253 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
254 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
255
264
277
284
290
295 {
296 m_operatingPoints.clear();
297 }
298
304 void SetOperatingPoint( const wxString& aNetChain, double aValue )
305 {
306 m_operatingPoints[ aNetChain ] = aValue;
307 }
308
309 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
310
318
322 void RecordERCExclusions();
323
328
333 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
334
339 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
340
345 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
346
353 void OnSchSheetChanged();
354
364 void AddListener( SCHEMATIC_LISTENER* aListener );
365
371 void RemoveListener( SCHEMATIC_LISTENER* aListener );
372
376 void RemoveAllListeners();
377
378 void RunOnNestedEmbeddedFiles( const std::function<void( EMBEDDED_FILES* )>& aFunction ) override;
379
383 void EmbedFonts() override;
384
388 std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
389
396 std::set<const SCH_SCREEN*> GetSchematicsSharedByMultipleProjects() const;
397
403 bool IsComplexHierarchy() const;
404
406
414 void CleanUp( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen = nullptr );
415
419 void RecalculateConnections( SCH_COMMIT* aCommit, SCH_CLEANUP_FLAGS aCleanupFlags,
420 TOOL_MANAGER* aToolManager,
421 PROGRESS_REPORTER* aProgressReporter = nullptr,
422 KIGFX::SCH_VIEW* aSchView = nullptr,
423 std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr,
424 PICKED_ITEMS_LIST* aLastChangeList = nullptr );
425
433
440 bool Contains( const SCH_REFERENCE& aRef ) const;
441
443
454 wxArrayString GetVariantNamesForUI() const;
455
461 wxString GetCurrentVariant() const;
462
463 void SetCurrentVariant( const wxString& aVariantName );
464
470 void DeleteVariant( const wxString& aVariantName, SCH_COMMIT* aCommit = nullptr );
471
472 void AddVariant( const wxString& aVariantName );
473
483 void RenameVariant( const wxString& aOldName, const wxString& aNewName,
484 SCH_COMMIT* aCommit = nullptr );
485
496 void CopyVariant( const wxString& aSourceVariant, const wxString& aNewVariant,
497 SCH_COMMIT* aCommit = nullptr );
498
502 const std::set<wxString>& GetVariantNames() const { return m_variantNames; }
503
510 wxString GetVariantDescription( const wxString& aVariantName ) const;
511
518 void SetVariantDescription( const wxString& aVariantName, const wxString& aDescription );
519
526 void LoadVariants();
527
532
533#if defined(DEBUG)
534 void Show( int nestLevel, std::ostream& os ) const override {}
535#endif
536
538
548 void SaveToHistory( const wxString& aProjectPath, std::vector<HISTORY_FILE_DATA>& aFileData );
549
550private:
551 friend class SCH_EDIT_FRAME;
552
553 template <typename Func, typename... Args>
554 void InvokeListeners( Func&& aFunc, Args&&... args )
555 {
556 for( auto&& l : m_listeners )
557 ( l->*aFunc )( std::forward<Args>( args )... );
558 }
559
560 void ensureVirtualRoot();
563 void rebuildHierarchyState( bool aResetConnectionGraph );
564
566
569
571 std::vector<SCH_SHEET*> m_topLevelSheets;
572
581
584
586
592 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
593
597 std::map<wxString, wxString> m_properties;
598
602 std::map<wxString, double> m_operatingPoints;
603
608
612 std::vector<SCHEMATIC_LISTENER*> m_listeners;
613
618
620
622
623 std::vector<std::shared_ptr<BUS_ALIAS>> m_busAliases;
624
626
627 std::set<wxString> m_variantNames;
628
632
635 std::unique_ptr<class SCHEMATIC_TEXT_VAR_ADAPTER> m_textVarAdapter;
636
637public:
639};
640
641#endif
Calculate the connectivity of a schematic and generates 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)
Definition eda_item.cpp:41
EMBEDDED_FILES()=default
Container for ERC settings.
Class OUTLINE_FONT implements outline font drawing.
Definition kiid.h:48
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.
Definition project.h:93
Container for project specific data.
Definition project.h:66
ELEM
The set of #_ELEMs that a PROJECT can hold.
Definition project.h:72
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)
Definition schematic.h:66
virtual ~SCHEMATIC_LISTENER()
Definition schematic.h:64
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition schematic.h:67
virtual void OnSchSheetChanged(SCHEMATIC &aSch)
Definition schematic.h:71
virtual void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition schematic.h:65
These are loaded from Eeschema settings but then overwritten by the project settings.
Bridges SCHEMATIC's listener stream into the generic TEXT_VAR_TRACKER.
Holds all the data relating to one schematic.
Definition schematic.h:89
void SetCurrentVariant(const wxString &aVariantName)
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition schematic.h:193
bool m_settingTopLevelSheets
Re-entry guard to prevent infinite recursion between ensureDefaultTopLevelSheet and RefreshHierarchy ...
Definition schematic.h:631
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 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.
CONNECTION_GRAPH * m_connectionGraph
Hold and calculate connectivity information of this schematic.
Definition schematic.h:583
virtual wxString GetClass() const override
Return the class name.
Definition schematic.h:95
bool IsTopLevelSheet(const SCH_SHEET *aSheet) const
Check if a sheet is a top-level sheet (direct child of virtual root).
void loadBusAliasesFromProject()
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.
Definition schematic.h:607
void rebuildHierarchyState(bool aResetConnectionGraph)
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
void DeleteVariant(const wxString &aVariantName, SCH_COMMIT *aCommit=nullptr)
Delete all information for aVariantName.
void RecomputeIntersheetRefs()
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
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
Definition schematic.h:227
const wxString & GetHighlightedNetChain() const
Definition schematic.h:205
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)
Definition schematic.h:405
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition schematic.h:580
std::vector< SCH_SHEET * > m_topLevelSheets
List of top-level sheets (direct children of virtual root)
Definition schematic.h:571
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 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)
int FixupJunctionsAfterImport()
Add junctions to this schematic where required.
virtual ~SCHEMATIC()
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.
void CopyVariant(const wxString &aSourceVariant, const wxString &aNewVariant, SCH_COMMIT *aCommit=nullptr)
Copy a variant from aSourceVariant to aNewVariant.
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.
void EmbedFonts() override
Embed fonts in the schematic.
SCHEMATIC_SETTINGS & Settings() const
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition schematic.h:294
SCH_SCREEN * GetCurrentScreen() const
Definition schematic.h:198
wxString ConvertKIIDsToRefs(const wxString &aSource) const
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
Definition schematic.h:127
void ensureVirtualRoot()
void ensureCurrentSheetIsTopLevel()
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.
wxString m_currentVariant
Definition schematic.h:625
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition schematic.h:248
SCH_SHEET_LIST BuildUnorderedSheetList() const
void RenameVariant(const wxString &aOldName, const wxString &aNewName, SCH_COMMIT *aCommit=nullptr)
Rename a variant from aOldName to aNewName.
class SCHEMATIC_TEXT_VAR_ADAPTER * GetTextVarAdapter() const
Definition schematic.h:638
void SetHighlightedNetChain(const wxString &aNetChain)
Definition schematic.h:206
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:104
std::map< wxString, std::set< int > > m_labelToPageRefsMap
Holds a map of labels to the page sequence (virtual page number) that they appear on.
Definition schematic.h:592
bool HasHierarchy() const
Check if the hierarchy has been built.
Definition schematic.h:123
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.
bool Contains(const SCH_REFERENCE &aRef) const
Check if the schematic contains the specified reference.
wxString ConvertRefsToKIIDs(const wxString &aSource) const
void SetProject(PROJECT *aPrj)
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...
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
EMBEDDED_FILES * GetEmbeddedFiles() override
PROJECT * m_project
Definition schematic.h:565
CONNECTION_GRAPH * ConnectionGraph() const
Definition schematic.h:200
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
SCHEMATIC(PROJECT *aPrj)
Definition schematic.cpp:72
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
Definition schematic.h:623
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition schematic.h:554
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:173
void updateProjectBusAliases()
void SetVariantDescription(const wxString &aVariantName, const wxString &aDescription)
Set the description for a variant.
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition schematic.h:531
void RemoveAllListeners()
Remove all listeners.
void SetTopLevelSheets(const std::vector< SCH_SHEET * > &aSheets)
std::unique_ptr< class SCHEMATIC_TEXT_VAR_ADAPTER > m_textVarAdapter
Reactive text-variable dependency adapter.
Definition schematic.h:635
const std::set< wxString > & GetVariantNames() const
Return the set of variant names (without the default placeholder).
Definition schematic.h:502
const std::map< wxString, wxString > * GetProperties()
Definition schematic.h:107
void GetContextualTextVars(wxArrayString *aVars) const
void SetOperatingPoint(const wxString &aNetChain, double aValue)
Set operating points from a .op simulation.
Definition schematic.h:304
friend class SCH_EDIT_FRAME
Definition schematic.h:551
void ensureDefaultTopLevelSheet()
SCH_SHEET & Root() const
Definition schematic.h:133
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
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.
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.
SCHEMATIC_HOLDER * m_schematicHolder
What currently "Holds" the schematic, i.e.
Definition schematic.h:617
wxString GetUniqueFilenameForCurrentSheet()
Get the unique file name for the current sheet.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void SetBusAliases(const std::vector< std::shared_ptr< BUS_ALIAS > > &aAliases)
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
Definition schematic.h:612
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:188
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
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)
Generate the connection data for the entire schematic hierarchy.
wxString m_highlightedNetChain
Definition schematic.h:585
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition schematic.h:602
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition schematic.h:597
ERC_SETTINGS & ErcSettings() const
std::set< wxString > m_variantNames
Definition schematic.h:627
void RefreshHierarchy()
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.
PROJECT::ELEM ProjectElementType() override
Definition schematic.h:537
SCH_SHEET * m_rootSheet
The virtual root sheet (has no screen, contains all top-level sheets)
Definition schematic.h:568
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:42
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.
Definition sch_sheet.h:48
Master controller class:
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:33
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
SCH_CLEANUP_FLAGS
Definition schematic.h:75
@ LOCAL_CLEANUP
Definition schematic.h:77
@ NO_CLEANUP
Definition schematic.h:76
@ GLOBAL_CLEANUP
Definition schematic.h:78
Data produced by a registered saver on the UI thread, consumed by either the background local-history...