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;
42class SCH_REFERENCE;
44class TOOL_MANAGER;
46
47namespace KIFONT
48{
49class OUTLINE_FONT;
50}
51
52namespace KIGFX
53{
54class SCH_VIEW;
55}
56
57
58class SCHEMATIC;
59
61{
62public:
64 virtual void OnSchItemsAdded( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
65 virtual void OnSchItemsRemoved( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
66 virtual void OnSchItemsChanged( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
67
68 // This is called when the user changes to a new sheet, not when a sheet is altered.
69 // Sheet alteration events will call OnSchItems*
70 virtual void OnSchSheetChanged( SCHEMATIC& aSch ) {}
71};
72
74{
78};
79
87class SCHEMATIC : public EDA_ITEM, public EMBEDDED_FILES, public PROJECT::_ELEM
88{
89public:
90 SCHEMATIC( PROJECT* aPrj );
91
92 virtual ~SCHEMATIC();
93
94 virtual wxString GetClass() const override
95 {
96 return wxT( "SCHEMATIC" );
97 }
98
100 void Reset();
101
103 PROJECT& Project() const { return *m_project; }
104 void SetProject( PROJECT* aPrj );
105
106 const std::map<wxString, wxString>* GetProperties() { return &m_properties; }
107
109 {
110 SCH_SHEET_LIST hierarchy( m_rootSheet );
111
112 hierarchy.SortByPageNumbers();
113
114 return hierarchy;
115 }
116
118 {
119 SCH_SHEET_LIST sheets;
120
121 if( m_rootSheet )
122 sheets.BuildSheetList( m_rootSheet, false );
123
124 return sheets;
125 }
126
131
132 void RefreshHierarchy();
133
134 SCH_ITEM* ResolveItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr,
135 bool aAllowNullptrReturn = false ) const
136 {
137 return BuildUnorderedSheetList().ResolveItem( aID, aPathOut, aAllowNullptrReturn );
138 }
139
141 {
142 return *m_rootSheet;
143 }
144
153 void SetRoot( SCH_SHEET* aRootSheet );
154
156 bool IsValid() const
157 {
158 return m_rootSheet != nullptr;
159 }
160
162 SCH_SCREEN* RootScreen() const;
163
164 void GetContextualTextVars( wxArrayString* aVars ) const;
165
166 bool ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token, int aDepth ) const;
167
169 wxString GetFileName() const;
170
172 {
173 return *m_currentSheet;
174 }
175
176 void SetCurrentSheet( const SCH_SHEET_PATH& aPath )
177 {
178 *m_currentSheet = aPath;
179 }
180
182
184 {
185 return m_connectionGraph;
186 }
187
189
190 ERC_SETTINGS& ErcSettings() const;
191
192 std::vector<SCH_MARKER*> ResolveERCExclusions();
193
195 const EMBEDDED_FILES* GetEmbeddedFiles() const;
196
201 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
202
209 std::set<wxString> GetNetClassAssignmentCandidates();
210
217 bool ResolveCrossReference( wxString* token, int aDepth ) const;
218
219 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
220
221 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
222 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
223
224 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
225 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
226
235
248
255
261
266 {
267 m_operatingPoints.clear();
268 }
269
275 void SetOperatingPoint( const wxString& aSignal, double aValue )
276 {
277 m_operatingPoints[ aSignal ] = aValue;
278 }
279
280 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
281
289
299 void BreakSegment( SCH_COMMIT* aCommit, SCH_LINE* aSegment, const VECTOR2I& aPoint, SCH_LINE** aNewSegment,
300 SCH_SCREEN* aScreen );
301
311 bool BreakSegments( SCH_COMMIT* aCommit, const VECTOR2I& aPoint, SCH_SCREEN* aScreen );
312
321 bool BreakSegmentsOnJunctions( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen );
322
326 void RecordERCExclusions();
327
332
337 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
338
343 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
344
349 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
350
357 void OnSchSheetChanged();
358
368 void AddListener( SCHEMATIC_LISTENER* aListener );
369
375 void RemoveListener( SCHEMATIC_LISTENER* aListener );
376
380 void RemoveAllListeners();
381
382 void RunOnNestedEmbeddedFiles( const std::function<void( EMBEDDED_FILES* )>& aFunction ) override;
383
387 void EmbedFonts() override;
388
392 std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
393
400 std::set<const SCH_SCREEN*> GetSchematicsSharedByMultipleProjects() const;
401
407 bool IsComplexHierarchy() const;
408
410
418 void CleanUp( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen = nullptr );
419
423 void RecalculateConnections( SCH_COMMIT* aCommit, SCH_CLEANUP_FLAGS aCleanupFlags,
424 TOOL_MANAGER* aToolManager,
425 PROGRESS_REPORTER* aProgressReporter = nullptr,
426 KIGFX::SCH_VIEW* aSchView = nullptr,
427 std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr,
428 PICKED_ITEMS_LIST* aLastChangeList = nullptr );
429
437
444 bool Contains( const SCH_REFERENCE& aRef ) const;
445
450
451#if defined(DEBUG)
452 void Show( int nestLevel, std::ostream& os ) const override {}
453#endif
454
456
457private:
458 friend class SCH_EDIT_FRAME;
459
460 template <typename Func, typename... Args>
461 void InvokeListeners( Func&& aFunc, Args&&... args )
462 {
463 for( auto&& l : m_listeners )
464 ( l->*aFunc )( std::forward<Args>( args )... );
465 }
466
468
471
480
483
489 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
490
494 std::map<wxString, wxString> m_properties;
495
499 std::map<wxString, double> m_operatingPoints;
500
505
509 std::vector<SCHEMATIC_LISTENER*> m_listeners;
510
515};
516
517#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:98
Container for ERC settings.
Definition: erc_settings.h:132
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:65
virtual ~SCHEMATIC_LISTENER()
Definition: schematic.h:63
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:66
virtual void OnSchSheetChanged(SCHEMATIC &aSch)
Definition: schematic.h:70
virtual void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:64
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition: schematic.h:88
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition: schematic.h:176
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:144
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:1003
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
Definition: schematic.cpp:682
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:835
CONNECTION_GRAPH * m_connectionGraph
Hold and calculate connectivity information of this schematic.
Definition: schematic.h:482
virtual wxString GetClass() const override
Return the class name.
Definition: schematic.h:94
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:1056
void SetOperatingPoint(const wxString &aSignal, double aValue)
Set operating points from a .op simulation.
Definition: schematic.h:275
SCH_SHEET_LIST m_hierarchy
Cache of the entire schematic hierarchy sorted by sheet page number.
Definition: schematic.h:504
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
Definition: schematic.cpp:910
void RecomputeIntersheetRefs()
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
Definition: schematic.cpp:735
void CacheExistingAnnotation()
Store all existing annotations in the REFDES_TRACKER.
Definition: schematic.cpp:200
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
Definition: schematic.h:108
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
Definition: schematic.cpp:866
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:1091
bool IsComplexHierarchy() const
Test if the schematic is a complex hierarchy.
Definition: schematic.cpp:1038
void OnSchSheetChanged()
Notify the schematic and its listeners that the current sheet has been changed.
Definition: schematic.cpp:853
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:350
void SetSchematicHolder(SCHEMATIC_HOLDER *aHolder)
Definition: schematic.h:409
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition: schematic.h:479
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
Definition: schematic.cpp:787
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:1117
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:841
virtual ~SCHEMATIC()
Definition: schematic.cpp:133
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:452
std::vector< SCH_MARKER * > ResolveERCExclusions()
Definition: schematic.cpp:370
void EmbedFonts() override
Embed fonts in the schematic.
Definition: schematic.cpp:984
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:356
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition: schematic.h:265
SCH_SCREEN * GetCurrentScreen() const
Definition: schematic.h:181
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Definition: schematic.cpp:625
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
Definition: schematic.h:134
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: schematic.cpp:884
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:258
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition: schematic.h:219
SCH_SHEET_LIST BuildUnorderedSheetList() const
Definition: schematic.h:117
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:103
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:489
void FixupJunctionsAfterImport()
Add junctions to this schematic where required.
Definition: schematic.cpp:807
std::set< KIFONT::OUTLINE_FONT * > GetFonts() const override
Get a set of fonts used in the schematic.
Definition: schematic.cpp:951
bool Contains(const SCH_REFERENCE &aRef) const
Check if the schematic contains the specified reference.
Definition: schematic.cpp:219
wxString ConvertRefsToKIIDs(const wxString &aSource) const
Definition: schematic.cpp:555
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:238
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:170
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:859
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
Definition: schematic.cpp:544
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: schematic.cpp:927
PROJECT * m_project
Definition: schematic.h:467
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:183
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:252
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
Definition: schematic.cpp:297
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:467
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition: schematic.h:461
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:156
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition: schematic.h:449
void RemoveAllListeners()
Remove all listeners.
Definition: schematic.cpp:878
const std::map< wxString, wxString > * GetProperties()
Definition: schematic.h:106
void GetContextualTextVars(wxArrayString *aVars) const
Definition: schematic.cpp:272
SCH_SHEET & Root() const
Definition: schematic.h:140
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
Definition: schematic.cpp:528
void RunOnNestedEmbeddedFiles(const std::function< void(EMBEDDED_FILES *)> &aFunction) override
Provide access to nested embedded files, such as symbols in schematics and footprints in boards.
Definition: schematic.cpp:939
SCHEMATIC_HOLDER * m_schematicHolder
What currently "Holds" the schematic, i.e.
Definition: schematic.h:514
wxString GetUniqueFilenameForCurrentSheet()
Get the unique file name for the current sheet.
Definition: schematic.cpp:690
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
Definition: schematic.cpp:706
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:1076
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
Definition: schematic.h:509
SCH_SHEET_PATH & CurrentSheet() const
Definition: schematic.h:171
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:486
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:1308
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition: schematic.h:499
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition: schematic.h:494
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:363
void RefreshHierarchy()
Definition: schematic.cpp:266
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:847
PROJECT::ELEM ProjectElementType() override
Definition: schematic.h:455
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition: schematic.h:470
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 helper to define a symbol's reference designator in a schematic.
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:74
@ LOCAL_CLEANUP
Definition: schematic.h:76
@ NO_CLEANUP
Definition: schematic.h:75
@ GLOBAL_CLEANUP
Definition: schematic.h:77