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 <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
39namespace KIFONT
40{
41class OUTLINE_FONT;
42}
43
44
46{
47public:
49 virtual ~SCHEMATIC_IFACE() {};
50
51 virtual CONNECTION_GRAPH* ConnectionGraph() const = 0;
53 virtual void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) = 0;
54 virtual SCH_SHEET_PATH& CurrentSheet() const = 0;
55 virtual wxString GetFileName() const = 0;
56 virtual PROJECT& Prj() const = 0;
57 virtual SCH_SHEET_LIST Hierarchy() const = 0;
58};
59
60class SCHEMATIC;
61
63{
64public:
66 virtual void OnSchItemsAdded( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
67 virtual void OnSchItemsRemoved( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
68 virtual void OnSchItemsChanged( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
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
81class SCHEMATIC : public SCHEMATIC_IFACE, public EDA_ITEM, public EMBEDDED_FILES
82{
83public:
84 SCHEMATIC( PROJECT* aPrj );
85
86 virtual ~SCHEMATIC();
87
88 virtual wxString GetClass() const override
89 {
90 return wxT( "SCHEMATIC" );
91 }
92
94 void Reset();
95
97 PROJECT& Prj() const override { return *m_project; }
98 void SetProject( PROJECT* aPrj );
99
100 const std::map<wxString, wxString>* GetProperties() { return &m_properties; }
101
103 {
104 SCH_SHEET_LIST hierarchy( m_rootSheet );
105
106 hierarchy.SortByPageNumbers();
107
108 return hierarchy;
109 }
110
112 {
113 SCH_SHEET_LIST sheets;
114 sheets.BuildSheetList( m_rootSheet, false );
115 return sheets;
116 }
117
121 SCH_SHEET_LIST Hierarchy() const override;
122
123 void RefreshHierarchy();
124
125 SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr ) const
126 {
127 return BuildUnorderedSheetList().GetItem( aID, aPathOut );
128 }
129
131 {
132 return *m_rootSheet;
133 }
134
143 void SetRoot( SCH_SHEET* aRootSheet );
144
146 bool IsValid() const
147 {
148 return m_rootSheet != nullptr;
149 }
150
152 SCH_SCREEN* RootScreen() const;
153
154 void GetContextualTextVars( wxArrayString* aVars ) const;
155
156 bool ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token, int aDepth ) const;
157
159 wxString GetFileName() const override;
160
161 SCH_SHEET_PATH& CurrentSheet() const override
162 {
163 return *m_currentSheet;
164 }
165
166 void SetCurrentSheet( const SCH_SHEET_PATH& aPath ) override
167 {
168 *m_currentSheet = aPath;
169 }
170
172 {
173 return m_connectionGraph;
174 }
175
177
178 ERC_SETTINGS& ErcSettings() const;
179
180 std::vector<SCH_MARKER*> ResolveERCExclusions();
181
183 const EMBEDDED_FILES* GetEmbeddedFiles() const;
184
189 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
190
196 std::set<wxString> GetNetClassAssignmentCandidates();
197
203 bool ResolveCrossReference( wxString* token, int aDepth ) const;
204
205 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
206
207 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
208 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
209
210 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
211 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
212
221
230
237
242 void RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback );
243
248 {
249 m_operatingPoints.clear();
250 }
251
255 void SetOperatingPoint( const wxString& aSignal, double aValue )
256 {
257 m_operatingPoints[ aSignal ] = aValue;
258 }
259
260 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
261
266 void FixupJunctions();
267
271 void RecordERCExclusions();
272
277
282 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
283
288 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
289
294 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
295
301 void OnSchSheetChanged();
302
311 void AddListener( SCHEMATIC_LISTENER* aListener );
312
317 void RemoveListener( SCHEMATIC_LISTENER* aListener );
318
322 void RemoveAllListeners();
323
327 void EmbedFonts() override;
328
332 std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
333
340 std::set<const SCH_SCREEN*> GetSchematicsSharedByMultipleProjects() const;
341
347 bool IsComplexHierarchy() const;
348
353
354#if defined(DEBUG)
355 void Show( int nestLevel, std::ostream& os ) const override {}
356#endif
357
358private:
359 friend class SCH_EDIT_FRAME;
360
361 template <typename Func, typename... Args>
362 void InvokeListeners( Func&& aFunc, Args&&... args )
363 {
364 for( auto&& l : m_listeners )
365 ( l->*aFunc )( std::forward<Args>( args )... );
366 }
367
369
372
380
383
388 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
389
393 std::map<wxString, wxString> m_properties;
394
398 std::map<wxString, double> m_operatingPoints;
399
404
408 std::vector<SCHEMATIC_LISTENER*> m_listeners;
409};
410
411#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:135
Definition: kiid.h:49
Container for project specific data.
Definition: project.h:64
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:49
virtual SCH_SHEET_LIST Hierarchy() const =0
virtual void OnSchItemsRemoved(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:67
virtual ~SCHEMATIC_LISTENER()
Definition: schematic.h:65
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:68
virtual void OnSchSheetChanged(SCHEMATIC &aSch)
Definition: schematic.h:71
virtual void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:66
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition: schematic.h:82
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:138
std::set< const SCH_SCREEN * > GetSchematicsSharedByMultipleProjects() const
Return a list of schematic files in the current project that contain instance data for multiple proje...
Definition: schematic.cpp:940
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
Definition: schematic.cpp:638
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:784
CONNECTION_GRAPH * m_connectionGraph
Holds and calculates connectivity information of this schematic.
Definition: schematic.h:382
virtual wxString GetClass() const override
Return the class name.
Definition: schematic.h:88
void SetOperatingPoint(const wxString &aSignal, double aValue)
Set operating points from a .op simulation.
Definition: schematic.h:255
SCH_SHEET_LIST m_hierarchy
Cache of the entire schematic hierarchy sorted by sheet page number.
Definition: schematic.h:403
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:161
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
Definition: schematic.cpp:859
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
Definition: schematic.cpp:815
bool IsComplexHierarchy() const
Test if the schematic is a complex hierarchy.
Definition: schematic.cpp:975
void OnSchSheetChanged()
Notify the schematic and its listeners that the current sheet has been changed.
Definition: schematic.cpp:802
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition: schematic.h:379
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
Definition: schematic.cpp:736
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:790
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:408
std::vector< SCH_MARKER * > ResolveERCExclusions()
Definition: schematic.cpp:326
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:306
void EmbedFonts() override
Embed fonts in the schematic.
Definition: schematic.cpp:921
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:312
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition: schematic.h:247
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:171
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Definition: schematic.cpp:581
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: schematic.cpp:833
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition: schematic.h:205
SCH_SHEET_LIST BuildUnorderedSheetList() const
Definition: schematic.h:111
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:166
void FixupJunctions()
Add junctions to this schematic where required.
Definition: schematic.cpp:756
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:388
SCH_SHEET_LIST Hierarchy() const override
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:214
std::set< KIFONT::OUTLINE_FONT * > GetFonts() const override
Get a set of fonts used in the schematic.
Definition: schematic.cpp:888
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Definition: schematic.h:125
wxString ConvertRefsToKIIDs(const wxString &aSource) const
Definition: schematic.cpp:511
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:808
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
Definition: schematic.cpp:500
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: schematic.cpp:876
PROJECT * m_project
Definition: schematic.h:368
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:208
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
Definition: schematic.cpp:253
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:423
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:691
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition: schematic.h:362
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:146
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition: schematic.h:352
void RemoveAllListeners()
Remove all listeners.
Definition: schematic.cpp:827
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:100
void GetContextualTextVars(wxArrayString *aVars) const
Definition: schematic.cpp:228
SCH_SHEET & Root() const
Definition: schematic.h:130
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
Definition: schematic.cpp:484
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const override
Definition: schematic.h:102
wxString GetUniqueFilenameForCurrentSheet()
Definition: schematic.cpp:646
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
Definition: schematic.cpp:662
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
Definition: schematic.h:408
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:97
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:442
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition: schematic.h:398
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition: schematic.h:393
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:319
void RefreshHierarchy()
Definition: schematic.cpp:222
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:796
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition: schematic.h:371
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:167
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 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...
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.