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 (C) 2020-2023 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;
36class SCH_GLOBALLABEL;
37
38
40{
41public:
43 virtual ~SCHEMATIC_IFACE() {};
44
45 virtual CONNECTION_GRAPH* ConnectionGraph() const = 0;
46 virtual SCH_SHEET_LIST GetSheets() const = 0;
47 virtual void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) = 0;
48 virtual SCH_SHEET_PATH& CurrentSheet() const = 0;
49 virtual wxString GetFileName() const = 0;
50 virtual PROJECT& Prj() const = 0;
51};
52
53class SCHEMATIC;
54
56{
57public:
59 virtual void OnSchItemsAdded( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
60 virtual void OnSchItemsRemoved( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
61 virtual void OnSchItemsChanged( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
62 // This is called when the user changes to a new sheet, not when a sheet is altered.
63 // Sheet alteration events will call OnSchItems*
64 virtual void OnSchSheetChanged( SCHEMATIC& aSch ) {}
65};
66
74class SCHEMATIC : public SCHEMATIC_IFACE, public EDA_ITEM
75{
76public:
77 SCHEMATIC( PROJECT* aPrj );
78
79 virtual ~SCHEMATIC();
80
81 virtual wxString GetClass() const override
82 {
83 return wxT( "SCHEMATIC" );
84 }
85
87 void Reset();
88
90 PROJECT& Prj() const override { return *m_project; }
91 void SetProject( PROJECT* aPrj );
92
93 const std::map<wxString, wxString>* GetProperties() { return &m_properties; }
94
100 SCH_SHEET_LIST GetSheets() const override
101 {
102 return SCH_SHEET_LIST( m_rootSheet );
103 }
104
106 {
107 return *m_rootSheet;
108 }
109
118 void SetRoot( SCH_SHEET* aRootSheet );
119
121 bool IsValid() const
122 {
123 return m_rootSheet != nullptr;
124 }
125
127 SCH_SCREEN* RootScreen() const;
128
129 void GetContextualTextVars( wxArrayString* aVars ) const;
130
131 bool ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token, int aDepth ) const;
132
134 wxString GetFileName() const override;
135
136 SCH_SHEET_PATH& CurrentSheet() const override
137 {
138 return *m_currentSheet;
139 }
140
141 void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) override
142 {
143 *m_currentSheet = aPath;
144 }
145
147 {
148 return m_connectionGraph;
149 }
150
152
153 ERC_SETTINGS& ErcSettings() const;
154
155 std::vector<SCH_MARKER*> ResolveERCExclusions();
156
161 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
162
168 std::set<wxString> GetNetClassAssignmentCandidates();
169
175 bool ResolveCrossReference( wxString* token, int aDepth ) const;
176
177 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
178
179 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
180 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
181
182 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
183 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
184
189
198
207
214
219 void RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback );
220
225 {
226 m_operatingPoints.clear();
227 }
228
232 void SetOperatingPoint( const wxString& aSignal, double aValue )
233 {
234 m_operatingPoints[ aSignal ] = aValue;
235 }
236
237 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
238
243 void FixupJunctions();
244
248 void RecordERCExclusions();
249
254
259 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
260
265 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
266
271 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
272
278 void OnSchSheetChanged();
279
288 void AddListener( SCHEMATIC_LISTENER* aListener );
289
294 void RemoveListener( SCHEMATIC_LISTENER* aListener );
295
299 void RemoveAllListeners();
300
301#if defined(DEBUG)
302 void Show( int nestLevel, std::ostream& os ) const override {}
303#endif
304
305private:
306 friend class SCH_EDIT_FRAME;
307
308 template <typename Func, typename... Args>
309 void InvokeListeners( Func&& aFunc, Args&&... args )
310 {
311 for( auto&& l : m_listeners )
312 ( l->*aFunc )( std::forward<Args>( args )... );
313 }
314
316
319
327
330
335 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
336
340 std::map<wxString, wxString> m_properties;
341
345 std::map<wxString, double> m_operatingPoints;
346
350 std::vector<SCHEMATIC_LISTENER*> m_listeners;
351};
352
353#endif
Calculate 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:88
Container for ERC settings.
Definition: erc_settings.h:120
Container for project specific data.
Definition: project.h:62
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:43
virtual void OnSchItemsRemoved(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:60
virtual ~SCHEMATIC_LISTENER()
Definition: schematic.h:58
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:61
virtual void OnSchSheetChanged(SCHEMATIC &aSch)
Definition: schematic.h:64
virtual void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:59
These settings were stored in SCH_BASE_FRAME previously.
Holds all the data relating to one schematic.
Definition: schematic.h:75
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:128
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
Definition: schematic.cpp:603
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.
Definition: schematic.cpp:749
CONNECTION_GRAPH * m_connectionGraph
Holds and calculates connectivity information of this schematic.
Definition: schematic.h:329
virtual wxString GetClass() const override
Return the class name.
Definition: schematic.h:81
void SetOperatingPoint(const wxString &aSignal, double aValue)
Set operating points from a .op simulation.
Definition: schematic.h:232
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:136
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
Definition: schematic.cpp:823
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
Definition: schematic.cpp:780
void OnSchSheetChanged()
Notify the schematic and its listeners that the current sheet has been changed.
Definition: schematic.cpp:767
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition: schematic.h:326
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
Definition: schematic.cpp:701
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.
Definition: schematic.cpp:755
virtual ~SCHEMATIC()
Definition: schematic.cpp:121
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:377
std::vector< SCH_MARKER * > ResolveERCExclusions()
Definition: schematic.cpp:301
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:281
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:287
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition: schematic.h:224
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:146
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Definition: schematic.cpp:541
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: schematic.cpp:798
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition: schematic.h:177
SCH_SHEET_LIST & GetFullHierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:592
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:141
void FixupJunctions()
Add junctions to this schematic where required.
Definition: schematic.cpp:721
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:335
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:100
wxString ConvertRefsToKIIDs(const wxString &aSource) const
Definition: schematic.cpp:473
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:184
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:154
void AddListener(SCHEMATIC_LISTENER *aListener)
Add a listener to the schematic to receive calls whenever something on the schematic has been modifie...
Definition: schematic.cpp:773
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
Definition: schematic.cpp:462
PROJECT * m_project
Definition: schematic.h:315
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:197
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
Definition: schematic.cpp:228
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:392
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 ...
Definition: schematic.cpp:656
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition: schematic.h:309
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:121
void RemoveAllListeners()
Remove all listeners.
Definition: schematic.cpp:792
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:93
void GetContextualTextVars(wxArrayString *aVars) const
Definition: schematic.cpp:203
SCH_SHEET & Root() const
Definition: schematic.h:105
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
Definition: schematic.cpp:446
wxString GetUniqueFilenameForCurrentSheet()
Definition: schematic.cpp:611
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
Definition: schematic.cpp:627
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
Definition: schematic.h:350
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:90
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:411
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition: schematic.h:345
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition: schematic.h:340
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:294
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.
Definition: schematic.cpp:761
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition: schematic.h:318
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:57
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.