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
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
203 void AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
204
205 void SetBusAliases( const std::vector<std::shared_ptr<BUS_ALIAS>>& aAliases );
206
207 const std::vector<std::shared_ptr<BUS_ALIAS>>& GetAllBusAliases() const
208 {
209 return m_busAliases;
210 }
211
218 std::set<wxString> GetNetClassAssignmentCandidates();
219
226 bool ResolveCrossReference( wxString* token, int aDepth ) const;
227
228 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
229
230 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
231 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
232
233 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
234 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
235
244
257
264
270
275 {
276 m_operatingPoints.clear();
277 }
278
284 void SetOperatingPoint( const wxString& aSignal, double aValue )
285 {
286 m_operatingPoints[ aSignal ] = aValue;
287 }
288
289 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
290
298
302 void RecordERCExclusions();
303
308
313 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
314
319 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
320
325 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
326
333 void OnSchSheetChanged();
334
344 void AddListener( SCHEMATIC_LISTENER* aListener );
345
351 void RemoveListener( SCHEMATIC_LISTENER* aListener );
352
356 void RemoveAllListeners();
357
358 void RunOnNestedEmbeddedFiles( const std::function<void( EMBEDDED_FILES* )>& aFunction ) override;
359
363 void EmbedFonts() override;
364
368 std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
369
376 std::set<const SCH_SCREEN*> GetSchematicsSharedByMultipleProjects() const;
377
383 bool IsComplexHierarchy() const;
384
386
394 void CleanUp( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen = nullptr );
395
399 void RecalculateConnections( SCH_COMMIT* aCommit, SCH_CLEANUP_FLAGS aCleanupFlags,
400 TOOL_MANAGER* aToolManager,
401 PROGRESS_REPORTER* aProgressReporter = nullptr,
402 KIGFX::SCH_VIEW* aSchView = nullptr,
403 std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr,
404 PICKED_ITEMS_LIST* aLastChangeList = nullptr );
405
413
420 bool Contains( const SCH_REFERENCE& aRef ) const;
421
423
434 wxArrayString GetVariantNamesForUI() const;
435
441 wxString GetCurrentVariant() const;
442
448 void DeleteVariant( const wxString& aVariantName );
449
454
455#if defined(DEBUG)
456 void Show( int nestLevel, std::ostream& os ) const override {}
457#endif
458
460
461private:
462 friend class SCH_EDIT_FRAME;
463
464 template <typename Func, typename... Args>
465 void InvokeListeners( Func&& aFunc, Args&&... args )
466 {
467 for( auto&& l : m_listeners )
468 ( l->*aFunc )( std::forward<Args>( args )... );
469 }
470
472
475
484
487
493 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
494
498 std::map<wxString, wxString> m_properties;
499
503 std::map<wxString, double> m_operatingPoints;
504
509
513 std::vector<SCHEMATIC_LISTENER*> m_listeners;
514
519
521
523
524 std::vector<std::shared_ptr<BUS_ALIAS>> m_busAliases;
525
527
528 std::set<wxString> m_variantNames;
529};
530
531#endif
Calculate the connectivity of a schematic and generates netlists.
The base frame for deriving all KiCad main window classes.
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:39
EMBEDDED_FILES()=default
Container for ERC settings.
Class OUTLINE_FONT implements outline font drawing.
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.
std::set< const SCH_SCREEN * > GetSchematicsSharedByMultipleProjects() const
Return a list of schematic files in the current project that contain instance data for multiple proje...
void CreateDefaultScreens()
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
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.
CONNECTION_GRAPH * m_connectionGraph
Hold and calculate connectivity information of this schematic.
Definition schematic.h:486
virtual wxString GetClass() const override
Return the class name.
Definition schematic.h:94
void loadBusAliasesFromProject()
void SetOperatingPoint(const wxString &aSignal, double aValue)
Set operating points from a .op simulation.
Definition schematic.h:284
SCH_SHEET_LIST m_hierarchy
Cache of the entire schematic hierarchy sorted by sheet page number.
Definition schematic.h:508
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
void RecomputeIntersheetRefs()
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
void CacheExistingAnnotation()
Store all existing annotations in the REFDES_TRACKER.
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
Definition schematic.h:108
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
const std::vector< std::shared_ptr< BUS_ALIAS > > & GetAllBusAliases() const
Definition schematic.h:207
bool IsComplexHierarchy() const
Test if the schematic is a complex hierarchy.
void OnSchSheetChanged()
Notify the schematic and its listeners that the current sheet has been changed.
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
void SetSchematicHolder(SCHEMATIC_HOLDER *aHolder)
Definition schematic.h:385
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition schematic.h:483
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
void CleanUp(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen=nullptr)
Perform routine schematic cleaning including breaking wire and buses and deleting identical objects s...
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.
virtual ~SCHEMATIC()
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.
std::vector< SCH_MARKER * > ResolveERCExclusions()
void EmbedFonts() override
Embed fonts in the schematic.
SCHEMATIC_SETTINGS & Settings() const
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition schematic.h:274
SCH_SCREEN * GetCurrentScreen() const
Definition schematic.h:181
wxString ConvertKIIDsToRefs(const wxString &aSource) const
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.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
wxString m_currentVariant
Definition schematic.h:526
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition schematic.h:228
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
void DeleteVariant(const wxString &aVariantName)
Delete all information for aVariantName.
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:493
void FixupJunctionsAfterImport()
Add junctions to this schematic where required.
std::set< KIFONT::OUTLINE_FONT * > GetFonts() const override
Get a set of fonts used in the schematic.
bool Contains(const SCH_REFERENCE &aRef) const
Check if the schematic contains the specified reference.
wxString ConvertRefsToKIIDs(const wxString &aSource) const
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
void SetProject(PROJECT *aPrj)
wxString GetCurrentVariant() const
Return the current variant being edited.
void AddListener(SCHEMATIC_LISTENER *aListener)
Add a listener to the schematic to receive calls whenever something on the schematic has been modifie...
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
EMBEDDED_FILES * GetEmbeddedFiles() override
PROJECT * m_project
Definition schematic.h:471
CONNECTION_GRAPH * ConnectionGraph() const
Definition schematic.h:183
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
SCHEMATIC(PROJECT *aPrj)
Definition schematic.cpp:59
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
std::vector< std::shared_ptr< BUS_ALIAS > > m_busAliases
Definition schematic.h:524
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition schematic.h:465
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:156
void updateProjectBusAliases()
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition schematic.h:453
void RemoveAllListeners()
Remove all listeners.
const std::map< wxString, wxString > * GetProperties()
Definition schematic.h:106
void GetContextualTextVars(wxArrayString *aVars) const
friend class SCH_EDIT_FRAME
Definition schematic.h:462
SCH_SHEET & Root() const
Definition schematic.h:140
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
wxArrayString GetVariantNamesForUI() const
Return an array of variant names for using in wxWidgets UI controls.
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.
SCHEMATIC_HOLDER * m_schematicHolder
What currently "Holds" the schematic, i.e.
Definition schematic.h:518
wxString GetUniqueFilenameForCurrentSheet()
Get the unique file name for the current sheet.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void SetBusAliases(const std::vector< std::shared_ptr< BUS_ALIAS > > &aAliases)
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
Definition schematic.h:513
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:171
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
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.
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition schematic.h:503
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition schematic.h:498
ERC_SETTINGS & ErcSettings() const
std::set< wxString > m_variantNames
Definition schematic.h:528
void RefreshHierarchy()
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.
PROJECT::ELEM ProjectElementType() override
Definition schematic.h:459
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition schematic.h:474
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
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:
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