KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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#include <project.h>
28
29
30class BUS_ALIAS;
32class EDA_BASE_FRAME;
33class ERC_SETTINGS;
34class PROJECT;
35class SCH_SCREEN;
36class SCH_SHEET;
37class SCH_SHEET_LIST;
38class SCH_GLOBALLABEL;
39
40namespace KIFONT
41{
42class OUTLINE_FONT;
43}
44
45
46class SCHEMATIC;
47
49{
50public:
52 virtual void OnSchItemsAdded( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
53 virtual void OnSchItemsRemoved( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
54 virtual void OnSchItemsChanged( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
55
56 // This is called when the user changes to a new sheet, not when a sheet is altered.
57 // Sheet alteration events will call OnSchItems*
58 virtual void OnSchSheetChanged( SCHEMATIC& aSch ) {}
59};
60
68class SCHEMATIC : public EDA_ITEM, public EMBEDDED_FILES, public PROJECT::_ELEM
69{
70public:
71 SCHEMATIC( PROJECT* aPrj );
72
73 virtual ~SCHEMATIC();
74
75 virtual wxString GetClass() const override
76 {
77 return wxT( "SCHEMATIC" );
78 }
79
81 void Reset();
82
84 PROJECT& Prj() const { return *m_project; }
85 void SetProject( PROJECT* aPrj );
86
87 const std::map<wxString, wxString>* GetProperties() { return &m_properties; }
88
90 {
91 SCH_SHEET_LIST hierarchy( m_rootSheet );
92
93 hierarchy.SortByPageNumbers();
94
95 return hierarchy;
96 }
97
99 {
100 SCH_SHEET_LIST sheets;
101 sheets.BuildSheetList( m_rootSheet, false );
102 return sheets;
103 }
104
109
110 void RefreshHierarchy();
111
112 SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr ) const
113 {
114 return BuildUnorderedSheetList().GetItem( aID, aPathOut );
115 }
116
118 {
119 return *m_rootSheet;
120 }
121
130 void SetRoot( SCH_SHEET* aRootSheet );
131
133 bool IsValid() const
134 {
135 return m_rootSheet != nullptr;
136 }
137
139 SCH_SCREEN* RootScreen() const;
140
141 void GetContextualTextVars( wxArrayString* aVars ) const;
142
143 bool ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token, int aDepth ) const;
144
146 wxString GetFileName() const;
147
149 {
150 return *m_currentSheet;
151 }
152
153 void SetCurrentSheet( const SCH_SHEET_PATH& aPath )
154 {
155 *m_currentSheet = aPath;
156 }
157
159 {
160 return m_connectionGraph;
161 }
162
164
165 ERC_SETTINGS& ErcSettings() const;
166
167 std::vector<SCH_MARKER*> ResolveERCExclusions();
168
170 const EMBEDDED_FILES* GetEmbeddedFiles() const;
171
176 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
177
184 std::set<wxString> GetNetClassAssignmentCandidates();
185
192 bool ResolveCrossReference( wxString* token, int aDepth ) const;
193
194 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
195
196 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
197 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
198
199 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
200 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
201
210
223
230
235 void RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback );
236
241 {
242 m_operatingPoints.clear();
243 }
244
250 void SetOperatingPoint( const wxString& aSignal, double aValue )
251 {
252 m_operatingPoints[ aSignal ] = aValue;
253 }
254
255 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
256
263 void FixupJunctions();
264
268 void RecordERCExclusions();
269
274
279 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
280
285 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
286
291 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
292
299 void OnSchSheetChanged();
300
310 void AddListener( SCHEMATIC_LISTENER* aListener );
311
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
359
360private:
361 friend class SCH_EDIT_FRAME;
362
363 template <typename Func, typename... Args>
364 void InvokeListeners( Func&& aFunc, Args&&... args )
365 {
366 for( auto&& l : m_listeners )
367 ( l->*aFunc )( std::forward<Args>( args )... );
368 }
369
371
374
383
386
392 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
393
397 std::map<wxString, wxString> m_properties;
398
402 std::map<wxString, double> m_operatingPoints;
403
408
412 std::vector<SCHEMATIC_LISTENER*> m_listeners;
413};
414
415#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:95
Container for ERC settings.
Definition: erc_settings.h:135
Definition: kiid.h:49
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition: project.h:96
Container for project specific data.
Definition: project.h:64
ELEM
The set of #_ELEMs that a PROJECT can hold.
Definition: project.h:70
virtual void OnSchItemsRemoved(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:53
virtual ~SCHEMATIC_LISTENER()
Definition: schematic.h:51
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:54
virtual void OnSchSheetChanged(SCHEMATIC &aSch)
Definition: schematic.h:58
virtual void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:52
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition: schematic.h:69
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:84
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition: schematic.h:153
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:132
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:935
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
Definition: schematic.cpp:632
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:779
CONNECTION_GRAPH * m_connectionGraph
Hold and calculate connectivity information of this schematic.
Definition: schematic.h:385
virtual wxString GetClass() const override
Return the class name.
Definition: schematic.h:75
void SetOperatingPoint(const wxString &aSignal, double aValue)
Set operating points from a .op simulation.
Definition: schematic.h:250
SCH_SHEET_LIST m_hierarchy
Cache of the entire schematic hierarchy sorted by sheet page number.
Definition: schematic.h:407
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
Definition: schematic.cpp:854
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
Definition: schematic.h:89
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
Definition: schematic.cpp:810
bool IsComplexHierarchy() const
Test if the schematic is a complex hierarchy.
Definition: schematic.cpp:970
void OnSchSheetChanged()
Notify the schematic and its listeners that the current sheet has been changed.
Definition: schematic.cpp:797
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:300
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition: schematic.h:382
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
Definition: schematic.cpp:731
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:785
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:402
std::vector< SCH_MARKER * > ResolveERCExclusions()
Definition: schematic.cpp:320
void EmbedFonts() override
Embed fonts in the schematic.
Definition: schematic.cpp:916
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:306
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition: schematic.h:240
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Definition: schematic.cpp:575
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: schematic.cpp:828
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:208
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition: schematic.h:194
SCH_SHEET_LIST BuildUnorderedSheetList() const
Definition: schematic.h:98
void FixupJunctions()
Add junctions to this schematic where required.
Definition: schematic.cpp:751
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:392
std::set< KIFONT::OUTLINE_FONT * > GetFonts() const override
Get a set of fonts used in the schematic.
Definition: schematic.cpp:883
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Definition: schematic.h:112
wxString ConvertRefsToKIIDs(const wxString &aSource) const
Definition: schematic.cpp:505
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:188
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:158
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:803
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
Definition: schematic.cpp:494
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: schematic.cpp:871
PROJECT * m_project
Definition: schematic.h:370
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:158
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:202
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
Definition: schematic.cpp:247
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:417
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:685
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition: schematic.h:364
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:133
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition: schematic.h:352
void RemoveAllListeners()
Remove all listeners.
Definition: schematic.cpp:822
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:87
void GetContextualTextVars(wxArrayString *aVars) const
Definition: schematic.cpp:222
SCH_SHEET & Root() const
Definition: schematic.h:117
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
Definition: schematic.cpp:478
wxString GetUniqueFilenameForCurrentSheet()
Get the unique file name for the current sheet.
Definition: schematic.cpp:640
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
Definition: schematic.cpp:656
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
Definition: schematic.h:412
SCH_SHEET_PATH & CurrentSheet() const
Definition: schematic.h:148
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:436
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition: schematic.h:402
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition: schematic.h:397
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:313
void RefreshHierarchy()
Definition: schematic.cpp:216
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:791
PROJECT::ELEM ProjectElementType() override
Definition: schematic.h:358
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition: schematic.h:373
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
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:47
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.