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
31class BUS_ALIAS;
33class EDA_BASE_FRAME;
34class ERC_SETTINGS;
35class PROJECT;
36class SCH_COMMIT;
37class SCH_LINE;
38class SCH_SCREEN;
39class SCH_SHEET;
40class SCH_SHEET_LIST;
41class SCH_GLOBALLABEL;
42class SCH_REFERENCE;
44class TOOL_MANAGER;
46
47namespace KIFONT
48{
49class OUTLINE_FONT;
50}
51
52namespace KIGFX
53{
54class SCH_VIEW;
55}
56
57
58class SCHEMATIC;
59
61{
62public:
64 virtual void OnSchItemsAdded( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
65 virtual void OnSchItemsRemoved( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
66 virtual void OnSchItemsChanged( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
67
68 // This is called when the user changes to a new sheet, not when a sheet is altered.
69 // Sheet alteration events will call OnSchItems*
70 virtual void OnSchSheetChanged( SCHEMATIC& aSch ) {}
71};
72
79
87class SCHEMATIC : public EDA_ITEM, public EMBEDDED_FILES, public PROJECT::_ELEM
88{
89public:
90 SCHEMATIC( PROJECT* aPrj );
91
92 virtual ~SCHEMATIC();
93
94 virtual wxString GetClass() const override
95 {
96 return wxT( "SCHEMATIC" );
97 }
98
100 void Reset();
101
103 PROJECT& Project() const { return *m_project; }
104 void SetProject( PROJECT* aPrj );
105
106 const std::map<wxString, wxString>* GetProperties() { return &m_properties; }
107
109 {
110 SCH_SHEET_LIST hierarchy( m_rootSheet );
111
112 hierarchy.SortByPageNumbers();
113
114 return hierarchy;
115 }
116
118 {
119 SCH_SHEET_LIST sheets;
120
121 if( m_rootSheet )
122 sheets.BuildSheetList( m_rootSheet, false );
123
124 return sheets;
125 }
126
131
132 void RefreshHierarchy();
133
134 SCH_ITEM* ResolveItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr,
135 bool aAllowNullptrReturn = false ) const
136 {
137 return BuildUnorderedSheetList().ResolveItem( aID, aPathOut, aAllowNullptrReturn );
138 }
139
141 {
142 return *m_rootSheet;
143 }
144
153 void SetRoot( SCH_SHEET* aRootSheet );
154
156 bool IsValid() const
157 {
158 return m_rootSheet != nullptr;
159 }
160
162 SCH_SCREEN* RootScreen() const;
163
164 void GetContextualTextVars( wxArrayString* aVars ) const;
165
166 bool ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token, int aDepth ) const;
167
169 wxString GetFileName() const;
170
172 {
173 return *m_currentSheet;
174 }
175
176 void SetCurrentSheet( const SCH_SHEET_PATH& aPath )
177 {
178 *m_currentSheet = aPath;
179 }
180
182
184 {
185 return m_connectionGraph;
186 }
187
189
190 ERC_SETTINGS& ErcSettings() const;
191
192 std::vector<SCH_MARKER*> ResolveERCExclusions();
193
195 const EMBEDDED_FILES* GetEmbeddedFiles() const;
196
201 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
202
209 std::set<wxString> GetNetClassAssignmentCandidates();
210
217 bool ResolveCrossReference( wxString* token, int aDepth ) const;
218
219 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
220
221 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
222 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
223
224 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
225 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
226
235
248
255
261
266 {
267 m_operatingPoints.clear();
268 }
269
275 void SetOperatingPoint( const wxString& aSignal, double aValue )
276 {
277 m_operatingPoints[ aSignal ] = aValue;
278 }
279
280 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
281
289
293 void RecordERCExclusions();
294
299
304 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
305
310 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
311
316 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
317
324 void OnSchSheetChanged();
325
335 void AddListener( SCHEMATIC_LISTENER* aListener );
336
342 void RemoveListener( SCHEMATIC_LISTENER* aListener );
343
347 void RemoveAllListeners();
348
349 void RunOnNestedEmbeddedFiles( const std::function<void( EMBEDDED_FILES* )>& aFunction ) override;
350
354 void EmbedFonts() override;
355
359 std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
360
367 std::set<const SCH_SCREEN*> GetSchematicsSharedByMultipleProjects() const;
368
374 bool IsComplexHierarchy() const;
375
377
385 void CleanUp( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen = nullptr );
386
390 void RecalculateConnections( SCH_COMMIT* aCommit, SCH_CLEANUP_FLAGS aCleanupFlags,
391 TOOL_MANAGER* aToolManager,
392 PROGRESS_REPORTER* aProgressReporter = nullptr,
393 KIGFX::SCH_VIEW* aSchView = nullptr,
394 std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr,
395 PICKED_ITEMS_LIST* aLastChangeList = nullptr );
396
404
411 bool Contains( const SCH_REFERENCE& aRef ) const;
412
414
419
420#if defined(DEBUG)
421 void Show( int nestLevel, std::ostream& os ) const override {}
422#endif
423
425
426private:
427 friend class SCH_EDIT_FRAME;
428
429 template <typename Func, typename... Args>
430 void InvokeListeners( Func&& aFunc, Args&&... args )
431 {
432 for( auto&& l : m_listeners )
433 ( l->*aFunc )( std::forward<Args>( args )... );
434 }
435
437
440
449
452
458 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
459
463 std::map<wxString, wxString> m_properties;
464
468 std::map<wxString, double> m_operatingPoints;
469
474
478 std::vector<SCHEMATIC_LISTENER*> m_listeners;
479
484};
485
486#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:39
EMBEDDED_FILES()=default
Container for ERC settings.
Class OUTLINE_FONT implements outline font drawing.
Definition kiid.h:49
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:97
Container for project specific data.
Definition project.h:65
ELEM
The set of #_ELEMs that a PROJECT can hold.
Definition project.h:71
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:65
virtual ~SCHEMATIC_LISTENER()
Definition schematic.h:63
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition schematic.h:66
virtual void OnSchSheetChanged(SCHEMATIC &aSch)
Definition schematic.h:70
virtual void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition schematic.h:64
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition schematic.h:88
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition schematic.h:176
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:451
virtual wxString GetClass() const override
Return the class name.
Definition schematic.h:94
void SetOperatingPoint(const wxString &aSignal, double aValue)
Set operating points from a .op simulation.
Definition schematic.h:275
SCH_SHEET_LIST m_hierarchy
Cache of the entire schematic hierarchy sorted by sheet page number.
Definition schematic.h:473
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 ...
void CacheExistingAnnotation()
Store all existing annotations in the REFDES_TRACKER.
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
Definition schematic.h:108
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.
void SetSchematicHolder(SCHEMATIC_HOLDER *aHolder)
Definition schematic.h:376
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition schematic.h:448
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.
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.
std::vector< SCH_MARKER * > ResolveERCExclusions()
void EmbedFonts() override
Embed fonts in the schematic.
SCHEMATIC_SETTINGS & Settings() const
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition schematic.h:265
SCH_SCREEN * GetCurrentScreen() const
Definition schematic.h:181
wxString ConvertKIIDsToRefs(const wxString &aSource) const
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
Definition schematic.h:134
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()
Definition schematic.h:219
SCH_SHEET_LIST BuildUnorderedSheetList() const
Definition schematic.h:117
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:103
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:458
void FixupJunctionsAfterImport()
Add junctions to this schematic where required.
std::set< KIFONT::OUTLINE_FONT * > GetFonts() const override
Get a set of fonts used in the schematic.
bool Contains(const SCH_REFERENCE &aRef) const
Check if the schematic contains the specified reference.
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
PROJECT * m_project
Definition schematic.h:436
CONNECTION_GRAPH * ConnectionGraph() const
Definition schematic.h:183
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
SCHEMATIC(PROJECT *aPrj)
Definition schematic.cpp:56
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 InvokeListeners(Func &&aFunc, Args &&... args)
Definition schematic.h:430
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:156
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition schematic.h:418
void RemoveAllListeners()
Remove all listeners.
const std::map< wxString, wxString > * GetProperties()
Definition schematic.h:106
void GetContextualTextVars(wxArrayString *aVars) const
friend class SCH_EDIT_FRAME
Definition schematic.h:427
SCH_SHEET & Root() const
Definition schematic.h:140
std::map< int, wxString > GetVirtualPageToSheetNamesMap() 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.
SCHEMATIC_HOLDER * m_schematicHolder
What currently "Holds" the schematic, i.e.
Definition schematic.h:483
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.
Definition schematic.h:478
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:171
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.
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition schematic.h:468
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition schematic.h:463
ERC_SETTINGS & ErcSettings() const
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:424
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition schematic.h:439
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
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.
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
Fetch a SCH_ITEM by ID.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
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:47
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:74
@ LOCAL_CLEANUP
Definition schematic.h:76
@ NO_CLEANUP
Definition schematic.h:75
@ GLOBAL_CLEANUP
Definition schematic.h:77