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 <schematic_holder.h>
26#include <sch_sheet_path.h>
27#include <schematic_settings.h>
28#include <project.h>
29
30
31class BUS_ALIAS;
33class EDA_BASE_FRAME;
34class ERC_SETTINGS;
35class PROJECT;
36class SCH_COMMIT;
37class SCH_LINE;
38class SCH_SCREEN;
39class SCH_SHEET;
40class SCH_SHEET_LIST;
41class SCH_GLOBALLABEL;
43class TOOL_MANAGER;
45
46namespace KIFONT
47{
48class OUTLINE_FONT;
49}
50
51namespace KIGFX
52{
53class SCH_VIEW;
54}
55
56
57class SCHEMATIC;
58
60{
61public:
63 virtual void OnSchItemsAdded( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
64 virtual void OnSchItemsRemoved( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
65 virtual void OnSchItemsChanged( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
66
67 // This is called when the user changes to a new sheet, not when a sheet is altered.
68 // Sheet alteration events will call OnSchItems*
69 virtual void OnSchSheetChanged( SCHEMATIC& aSch ) {}
70};
71
73{
77};
78
86class SCHEMATIC : public EDA_ITEM, public EMBEDDED_FILES, public PROJECT::_ELEM
87{
88public:
89 SCHEMATIC( PROJECT* aPrj );
90
91 virtual ~SCHEMATIC();
92
93 virtual wxString GetClass() const override
94 {
95 return wxT( "SCHEMATIC" );
96 }
97
99 void Reset();
100
102 PROJECT& Prj() const { return *m_project; }
103 void SetProject( PROJECT* aPrj );
104
105 const std::map<wxString, wxString>* GetProperties() { return &m_properties; }
106
108 {
109 SCH_SHEET_LIST hierarchy( m_rootSheet );
110
111 hierarchy.SortByPageNumbers();
112
113 return hierarchy;
114 }
115
117 {
118 SCH_SHEET_LIST sheets;
119 sheets.BuildSheetList( m_rootSheet, false );
120 return sheets;
121 }
122
127
128 void RefreshHierarchy();
129
130 SCH_ITEM* ResolveItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr,
131 bool aAllowNullptrReturn = false ) const
132 {
133 return BuildUnorderedSheetList().ResolveItem( aID, aPathOut, aAllowNullptrReturn );
134 }
135
137 {
138 return *m_rootSheet;
139 }
140
149 void SetRoot( SCH_SHEET* aRootSheet );
150
152 bool IsValid() const
153 {
154 return m_rootSheet != nullptr;
155 }
156
158 SCH_SCREEN* RootScreen() const;
159
160 void GetContextualTextVars( wxArrayString* aVars ) const;
161
162 bool ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token, int aDepth ) const;
163
165 wxString GetFileName() const;
166
168 {
169 return *m_currentSheet;
170 }
171
172 void SetCurrentSheet( const SCH_SHEET_PATH& aPath )
173 {
174 *m_currentSheet = aPath;
175 }
176
178
180 {
181 return m_connectionGraph;
182 }
183
185
186 ERC_SETTINGS& ErcSettings() const;
187
188 std::vector<SCH_MARKER*> ResolveERCExclusions();
189
191 const EMBEDDED_FILES* GetEmbeddedFiles() const;
192
197 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
198
205 std::set<wxString> GetNetClassAssignmentCandidates();
206
213 bool ResolveCrossReference( wxString* token, int aDepth ) const;
214
215 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
216
217 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
218 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
219
220 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
221 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
222
231
244
251
257
262 {
263 m_operatingPoints.clear();
264 }
265
271 void SetOperatingPoint( const wxString& aSignal, double aValue )
272 {
273 m_operatingPoints[ aSignal ] = aValue;
274 }
275
276 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
277
284 void FixupJunctions();
285
295 void BreakSegment( SCH_COMMIT* aCommit, SCH_LINE* aSegment, const VECTOR2I& aPoint, SCH_LINE** aNewSegment,
296 SCH_SCREEN* aScreen );
297
307 bool BreakSegments( SCH_COMMIT* aCommit, const VECTOR2I& aPoint, SCH_SCREEN* aScreen );
308
317 bool BreakSegmentsOnJunctions( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen );
318
322 void RecordERCExclusions();
323
328
333 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
334
339 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
340
345 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
346
353 void OnSchSheetChanged();
354
364 void AddListener( SCHEMATIC_LISTENER* aListener );
365
371 void RemoveListener( SCHEMATIC_LISTENER* aListener );
372
376 void RemoveAllListeners();
377
381 void EmbedFonts() override;
382
386 std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
387
394 std::set<const SCH_SCREEN*> GetSchematicsSharedByMultipleProjects() const;
395
401 bool IsComplexHierarchy() const;
402
404
412 void CleanUp( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen = nullptr );
413
417 void RecalculateConnections( SCH_COMMIT* aCommit, SCH_CLEANUP_FLAGS aCleanupFlags,
418 TOOL_MANAGER* aToolManager,
419 PROGRESS_REPORTER* aProgressReporter = nullptr,
420 KIGFX::SCH_VIEW* aSchView = nullptr,
421 std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr,
422 PICKED_ITEMS_LIST* aLastChangeList = nullptr );
423
428
429#if defined(DEBUG)
430 void Show( int nestLevel, std::ostream& os ) const override {}
431#endif
432
434
435private:
436 friend class SCH_EDIT_FRAME;
437
438 template <typename Func, typename... Args>
439 void InvokeListeners( Func&& aFunc, Args&&... args )
440 {
441 for( auto&& l : m_listeners )
442 ( l->*aFunc )( std::forward<Args>( args )... );
443 }
444
446
449
458
461
467 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
468
472 std::map<wxString, wxString> m_properties;
473
477 std::map<wxString, double> m_operatingPoints;
478
483
487 std::vector<SCHEMATIC_LISTENER*> m_listeners;
488
493};
494
495#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:97
Container for ERC settings.
Definition: erc_settings.h:135
Definition: kiid.h:49
A holder to handle information on schematic or board items.
A progress reporter interface for use in multi-threaded environments.
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition: project.h:97
Container for project specific data.
Definition: project.h:65
ELEM
The set of #_ELEMs that a PROJECT can hold.
Definition: project.h:71
This is a bridge class to help the schematic be able to affect SCH_EDIT_FRAME without doing anything ...
virtual void OnSchItemsRemoved(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:64
virtual ~SCHEMATIC_LISTENER()
Definition: schematic.h:62
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:65
virtual void OnSchSheetChanged(SCHEMATIC &aSch)
Definition: schematic.h:69
virtual void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:63
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition: schematic.h:87
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:102
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition: schematic.h:172
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:143
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:952
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
Definition: schematic.cpp:643
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:796
CONNECTION_GRAPH * m_connectionGraph
Hold and calculate connectivity information of this schematic.
Definition: schematic.h:460
virtual wxString GetClass() const override
Return the class name.
Definition: schematic.h:93
void BreakSegment(SCH_COMMIT *aCommit, SCH_LINE *aSegment, const VECTOR2I &aPoint, SCH_LINE **aNewSegment, SCH_SCREEN *aScreen)
Break a single segment into two at the specified point.
Definition: schematic.cpp:1005
void SetOperatingPoint(const wxString &aSignal, double aValue)
Set operating points from a .op simulation.
Definition: schematic.h:271
SCH_SHEET_LIST m_hierarchy
Cache of the entire schematic hierarchy sorted by sheet page number.
Definition: schematic.h:482
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
Definition: schematic.cpp:871
void RecomputeIntersheetRefs()
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
Definition: schematic.cpp:696
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
Definition: schematic.h:107
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
Definition: schematic.cpp:827
bool BreakSegmentsOnJunctions(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen)
Test all junctions and bus entries in the schematic for intersections with wires and buses and breaks...
Definition: schematic.cpp:1040
bool IsComplexHierarchy() const
Test if the schematic is a complex hierarchy.
Definition: schematic.cpp:987
void OnSchSheetChanged()
Notify the schematic and its listeners that the current sheet has been changed.
Definition: schematic.cpp:814
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:311
void SetSchematicHolder(SCHEMATIC_HOLDER *aHolder)
Definition: schematic.h:403
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition: schematic.h:457
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
Definition: schematic.cpp:748
void CleanUp(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen=nullptr)
Perform routine schematic cleaning including breaking wire and buses and deleting identical objects s...
Definition: schematic.cpp:1066
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:802
virtual ~SCHEMATIC()
Definition: schematic.cpp:132
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:413
std::vector< SCH_MARKER * > ResolveERCExclusions()
Definition: schematic.cpp:331
void EmbedFonts() override
Embed fonts in the schematic.
Definition: schematic.cpp:933
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:317
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition: schematic.h:261
SCH_SCREEN * GetCurrentScreen() const
Definition: schematic.h:177
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Definition: schematic.cpp:586
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
Definition: schematic.h:130
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: schematic.cpp:845
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:219
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition: schematic.h:215
SCH_SHEET_LIST BuildUnorderedSheetList() const
Definition: schematic.h:116
void FixupJunctions()
Add junctions to this schematic where required.
Definition: schematic.cpp:768
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:467
std::set< KIFONT::OUTLINE_FONT * > GetFonts() const override
Get a set of fonts used in the schematic.
Definition: schematic.cpp:900
wxString ConvertRefsToKIIDs(const wxString &aSource) const
Definition: schematic.cpp:516
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:199
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:169
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:820
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
Definition: schematic.cpp:505
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: schematic.cpp:888
PROJECT * m_project
Definition: schematic.h:445
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:179
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:213
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
Definition: schematic.cpp:258
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:428
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition: schematic.h:439
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:152
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition: schematic.h:427
void RemoveAllListeners()
Remove all listeners.
Definition: schematic.cpp:839
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:105
void GetContextualTextVars(wxArrayString *aVars) const
Definition: schematic.cpp:233
SCH_SHEET & Root() const
Definition: schematic.h:136
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
Definition: schematic.cpp:489
SCHEMATIC_HOLDER * m_schematicHolder
What currently "Holds" the schematic, i.e.
Definition: schematic.h:492
wxString GetUniqueFilenameForCurrentSheet()
Get the unique file name for the current sheet.
Definition: schematic.cpp:651
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
Definition: schematic.cpp:667
bool BreakSegments(SCH_COMMIT *aCommit, const VECTOR2I &aPoint, SCH_SCREEN *aScreen)
Check every wire and bus for a intersection at aPoint and break into two segments at aPoint if an int...
Definition: schematic.cpp:1025
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
Definition: schematic.h:487
SCH_SHEET_PATH & CurrentSheet() const
Definition: schematic.h:167
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:447
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, TOOL_MANAGER *aToolManager, PROGRESS_REPORTER *aProgressReporter=nullptr, KIGFX::SCH_VIEW *aSchView=nullptr, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr, PICKED_ITEMS_LIST *aLastChangeList=nullptr)
Generate the connection data for the entire schematic hierarchy.
Definition: schematic.cpp:1257
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition: schematic.h:477
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition: schematic.h:472
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:324
void RefreshHierarchy()
Definition: schematic.cpp:227
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:808
PROJECT::ELEM ProjectElementType() override
Definition: schematic.h:433
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition: schematic.h:448
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:42
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) 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...
SCH_SCREEN * LastScreen()
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:47
Master controller class:
Definition: tool_manager.h:62
The Cairo implementation of the graphics abstraction layer.
Definition: eda_group.h:33
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
SCH_CLEANUP_FLAGS
Definition: schematic.h:73
@ LOCAL_CLEANUP
Definition: schematic.h:75
@ NO_CLEANUP
Definition: schematic.h:74
@ GLOBAL_CLEANUP
Definition: schematic.h:76