KiCad PCB EDA Suite
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 (C) 2020-2022 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 <sch_sheet_path.h>
25#include <schematic_settings.h>
26
27
28class BUS_ALIAS;
30class EDA_BASE_FRAME;
31class ERC_SETTINGS;
32class PROJECT;
33class SCH_SCREEN;
34class SCH_SHEET;
35class SCH_SHEET_LIST;
36
37
39{
40public:
42 virtual ~SCHEMATIC_IFACE() {};
43
44 virtual CONNECTION_GRAPH* ConnectionGraph() const = 0;
45 virtual SCH_SHEET_LIST GetSheets() const = 0;
46 virtual void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) = 0;
47 virtual SCH_SHEET_PATH& CurrentSheet() const = 0;
48 virtual wxString GetFileName() const = 0;
49 virtual PROJECT& Prj() const = 0;
50};
51
59class SCHEMATIC : public SCHEMATIC_IFACE, public EDA_ITEM
60{
61public:
62 SCHEMATIC( PROJECT* aPrj );
63
64 virtual ~SCHEMATIC();
65
66 virtual wxString GetClass() const override
67 {
68 return wxT( "SCHEMATIC" );
69 }
70
72 void Reset();
73
75 PROJECT& Prj() const override { return *m_project; }
76 void SetProject( PROJECT* aPrj );
77
78 const std::map<wxString, wxString>* GetProperties() { return &m_properties; }
79
85 SCH_SHEET_LIST GetSheets() const override
86 {
88 }
89
90 SCH_SHEET& Root() const
91 {
92 return *m_rootSheet;
93 }
94
103 void SetRoot( SCH_SHEET* aRootSheet );
104
106 bool IsValid() const
107 {
108 return m_rootSheet != nullptr;
109 }
110
112 SCH_SCREEN* RootScreen() const;
113
114 bool ResolveTextVar( wxString* token, int aDepth ) const;
115
117 wxString GetFileName() const override;
118
119 SCH_SHEET_PATH& CurrentSheet() const override
120 {
121 return *m_currentSheet;
122 }
123
124 void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) override
125 {
126 *m_currentSheet = aPath;
127 }
128
130 {
131 return m_connectionGraph;
132 }
133
135
136 ERC_SETTINGS& ErcSettings() const;
137
138 std::vector<SCH_MARKER*> ResolveERCExclusions();
139
144 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
145
151 std::set<wxString> GetNetClassAssignmentCandidates();
152
158 bool ResolveCrossReference( wxString* token, int aDepth ) const;
159
160 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
161
162 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
163 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
164
165 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
166 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
167
172
181
182#if defined(DEBUG)
183 void Show( int nestLevel, std::ostream& os ) const override {}
184#endif
185
186private:
187 friend class SCH_EDIT_FRAME;
188
190
193
201
204
209 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
210
214 std::map<wxString, wxString> m_properties;
215};
216
217#endif
Calculates the connectivity of a schematic and generates netlists.
The base frame for deriving all KiCad main window classes.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
Container for ERC settings.
Definition: erc_settings.h:109
Container for project specific data.
Definition: project.h:63
virtual void SetCurrentSheet(const SCH_SHEET_PATH &aPath)=0
virtual wxString GetFileName() const =0
virtual CONNECTION_GRAPH * ConnectionGraph() const =0
virtual SCH_SHEET_LIST GetSheets() const =0
virtual SCH_SHEET_PATH & CurrentSheet() const =0
virtual PROJECT & Prj() const =0
virtual ~SCHEMATIC_IFACE()
Definition: schematic.h:42
These settings were stored in SCH_BASE_FRAME previously.
Holds all the data relating to one schematic.
Definition: schematic.h:60
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:51
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
Definition: schematic.cpp:449
CONNECTION_GRAPH * m_connectionGraph
Holds and calculates connectivity information of this schematic.
Definition: schematic.h:203
virtual wxString GetClass() const override
Return the class name.
Definition: schematic.h:66
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:119
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition: schematic.h:200
bool ResolveTextVar(wxString *token, int aDepth) const
Definition: schematic.cpp:123
virtual ~SCHEMATIC()
Definition: schematic.cpp:44
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.
Definition: schematic.cpp:225
std::vector< SCH_MARKER * > ResolveERCExclusions()
Definition: schematic.cpp:186
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:166
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:172
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:129
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Definition: schematic.cpp:387
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition: schematic.h:160
SCH_SHEET_LIST & GetFullHierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:438
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:124
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:209
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:85
wxString ConvertRefsToKIIDs(const wxString &aSource) const
Definition: schematic.cpp:319
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:104
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:76
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
Definition: schematic.cpp:308
PROJECT * m_project
Definition: schematic.h:189
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:117
SCHEMATIC(PROJECT *aPrj)
Definition: schematic.cpp:32
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:240
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:106
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:78
SCH_SHEET & Root() const
Definition: schematic.h:90
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
Definition: schematic.cpp:292
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:259
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition: schematic.h:214
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:179
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition: schematic.h:192
Schematic editor (Eeschema) main window.
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...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:55
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.