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 <embedded_files.h>
25#include <sch_sheet_path.h>
26#include <schematic_settings.h>
27
28
29class BUS_ALIAS;
31class EDA_BASE_FRAME;
32class ERC_SETTINGS;
33class PROJECT;
34class SCH_SCREEN;
35class SCH_SHEET;
36class SCH_SHEET_LIST;
37class SCH_GLOBALLABEL;
38
39
41{
42public:
44 virtual ~SCHEMATIC_IFACE() {};
45
46 virtual CONNECTION_GRAPH* ConnectionGraph() const = 0;
48 virtual void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) = 0;
49 virtual SCH_SHEET_PATH& CurrentSheet() const = 0;
50 virtual wxString GetFileName() const = 0;
51 virtual PROJECT& Prj() const = 0;
52};
53
54class SCHEMATIC;
55
57{
58public:
60 virtual void OnSchItemsAdded( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
61 virtual void OnSchItemsRemoved( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
62 virtual void OnSchItemsChanged( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
63 // This is called when the user changes to a new sheet, not when a sheet is altered.
64 // Sheet alteration events will call OnSchItems*
65 virtual void OnSchSheetChanged( SCHEMATIC& aSch ) {}
66};
67
75class SCHEMATIC : public SCHEMATIC_IFACE, public EDA_ITEM, public EMBEDDED_FILES
76{
77public:
78 SCHEMATIC( PROJECT* aPrj );
79
80 virtual ~SCHEMATIC();
81
82 virtual wxString GetClass() const override
83 {
84 return wxT( "SCHEMATIC" );
85 }
86
88 void Reset();
89
91 PROJECT& Prj() const override { return *m_project; }
92 void SetProject( PROJECT* aPrj );
93
94 const std::map<wxString, wxString>* GetProperties() { return &m_properties; }
95
97 {
99 }
100
102 {
103 SCH_SHEET_LIST sheets;
104 sheets.BuildSheetList( m_rootSheet, false );
105 return sheets;
106 }
107
108 SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr ) const
109 {
110 return BuildUnorderedSheetList().GetItem( aID, aPathOut );
111 }
112
114 {
115 return *m_rootSheet;
116 }
117
126 void SetRoot( SCH_SHEET* aRootSheet );
127
129 bool IsValid() const
130 {
131 return m_rootSheet != nullptr;
132 }
133
135 SCH_SCREEN* RootScreen() const;
136
137 void GetContextualTextVars( wxArrayString* aVars ) const;
138
139 bool ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token, int aDepth ) const;
140
142 wxString GetFileName() const override;
143
144 SCH_SHEET_PATH& CurrentSheet() const override
145 {
146 return *m_currentSheet;
147 }
148
149 void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) override
150 {
151 *m_currentSheet = aPath;
152 }
153
155 {
156 return m_connectionGraph;
157 }
158
160
161 ERC_SETTINGS& ErcSettings() const;
162
163 std::vector<SCH_MARKER*> ResolveERCExclusions();
164
166 const EMBEDDED_FILES* GetEmbeddedFiles() const;
167
172 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
173
179 std::set<wxString> GetNetClassAssignmentCandidates();
180
186 bool ResolveCrossReference( wxString* token, int aDepth ) const;
187
188 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
189
190 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
191 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
192
193 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
194 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
195
200
209
218
225
230 void RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback );
231
236 {
237 m_operatingPoints.clear();
238 }
239
243 void SetOperatingPoint( const wxString& aSignal, double aValue )
244 {
245 m_operatingPoints[ aSignal ] = aValue;
246 }
247
248 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
249
254 void FixupJunctions();
255
259 void RecordERCExclusions();
260
265
270 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
271
276 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
277
282 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
283
289 void OnSchSheetChanged();
290
299 void AddListener( SCHEMATIC_LISTENER* aListener );
300
305 void RemoveListener( SCHEMATIC_LISTENER* aListener );
306
310 void RemoveAllListeners();
311
315 void EmbedFonts() override;
316
321
322#if defined(DEBUG)
323 void Show( int nestLevel, std::ostream& os ) const override {}
324#endif
325
326private:
327 friend class SCH_EDIT_FRAME;
328
329 template <typename Func, typename... Args>
330 void InvokeListeners( Func&& aFunc, Args&&... args )
331 {
332 for( auto&& l : m_listeners )
333 ( l->*aFunc )( std::forward<Args>( args )... );
334 }
335
337
340
348
351
356 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
357
361 std::map<wxString, wxString> m_properties;
362
366 std::map<wxString, double> m_operatingPoints;
367
371 std::vector<SCHEMATIC_LISTENER*> m_listeners;
372};
373
374#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:89
Container for ERC settings.
Definition: erc_settings.h:127
Definition: kiid.h:49
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_PATH & CurrentSheet() const =0
virtual SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const =0
virtual PROJECT & Prj() const =0
virtual ~SCHEMATIC_IFACE()
Definition: schematic.h:44
virtual void OnSchItemsRemoved(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:61
virtual ~SCHEMATIC_LISTENER()
Definition: schematic.h:59
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:62
virtual void OnSchSheetChanged(SCHEMATIC &aSch)
Definition: schematic.h:65
virtual void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:60
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition: schematic.h:76
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:138
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
Definition: schematic.cpp:616
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:762
CONNECTION_GRAPH * m_connectionGraph
Holds and calculates connectivity information of this schematic.
Definition: schematic.h:350
virtual wxString GetClass() const override
Return the class name.
Definition: schematic.h:82
void SetOperatingPoint(const wxString &aSignal, double aValue)
Set operating points from a .op simulation.
Definition: schematic.h:243
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:144
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
Definition: schematic.cpp:837
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
Definition: schematic.cpp:793
void OnSchSheetChanged()
Notify the schematic and its listeners that the current sheet has been changed.
Definition: schematic.cpp:780
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition: schematic.h:347
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
Definition: schematic.cpp:714
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:768
virtual ~SCHEMATIC()
Definition: schematic.cpp:127
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:393
std::vector< SCH_MARKER * > ResolveERCExclusions()
Definition: schematic.cpp:311
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:291
void EmbedFonts() override
Embed fonts in the schematic.
Definition: schematic.cpp:866
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:297
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition: schematic.h:235
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:154
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Definition: schematic.cpp:555
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: schematic.cpp:811
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition: schematic.h:188
SCH_SHEET_LIST BuildUnorderedSheetList() const
Definition: schematic.h:101
SCH_SHEET_LIST & GetFullHierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:605
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:149
void FixupJunctions()
Add junctions to this schematic where required.
Definition: schematic.cpp:734
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:356
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Definition: schematic.h:108
wxString ConvertRefsToKIIDs(const wxString &aSource) const
Definition: schematic.cpp:488
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:194
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:164
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:786
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
Definition: schematic.cpp:477
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: schematic.cpp:854
PROJECT * m_project
Definition: schematic.h:336
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:207
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
Definition: schematic.cpp:238
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:408
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:669
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition: schematic.h:330
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:129
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition: schematic.h:320
void RemoveAllListeners()
Remove all listeners.
Definition: schematic.cpp:805
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:94
void GetContextualTextVars(wxArrayString *aVars) const
Definition: schematic.cpp:213
SCH_SHEET & Root() const
Definition: schematic.h:113
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
Definition: schematic.cpp:461
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const override
Definition: schematic.h:96
wxString GetUniqueFilenameForCurrentSheet()
Definition: schematic.cpp:624
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
Definition: schematic.cpp:640
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
Definition: schematic.h:371
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:91
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:427
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition: schematic.h:366
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition: schematic.h:361
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:304
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:774
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition: schematic.h:339
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Fetch a SCH_ITEM by ID.
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...
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.