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
32class BUS_ALIAS;
34class EDA_BASE_FRAME;
35class ERC_SETTINGS;
36class PROJECT;
37class SCH_COMMIT;
38class SCH_LINE;
39class SCH_SCREEN;
40class SCH_SHEET;
41class SCH_SHEET_LIST;
42class SCH_GLOBALLABEL;
43class SCH_REFERENCE;
45class TOOL_MANAGER;
47
48namespace KIFONT
49{
50class OUTLINE_FONT;
51}
52
53namespace KIGFX
54{
55class SCH_VIEW;
56}
57
58
59class SCHEMATIC;
60
62{
63public:
65 virtual void OnSchItemsAdded( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
66 virtual void OnSchItemsRemoved( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
67 virtual void OnSchItemsChanged( SCHEMATIC& aSch, std::vector<SCH_ITEM*>& aSchItem ) {}
68
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
80
88class SCHEMATIC : public EDA_ITEM, public EMBEDDED_FILES, public PROJECT::_ELEM
89{
90public:
91 SCHEMATIC( PROJECT* aPrj );
92
93 virtual ~SCHEMATIC();
94
95 virtual wxString GetClass() const override
96 {
97 return wxT( "SCHEMATIC" );
98 }
99
101 void Reset();
102
104 PROJECT& Project() const { return *m_project; }
105 void SetProject( PROJECT* aPrj );
106
107 const std::map<wxString, wxString>* GetProperties() { return &m_properties; }
108
110
112
117
123 bool HasHierarchy() const { return !m_hierarchy.empty(); }
124
125 void RefreshHierarchy();
126
127 SCH_ITEM* ResolveItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr,
128 bool aAllowNullptrReturn = false ) const
129 {
130 return m_hierarchy.ResolveItem( aID, aPathOut, aAllowNullptrReturn );
131 }
132
134 {
135 return *m_rootSheet;
136 }
137
143 std::vector<SCH_SHEET*> GetTopLevelSheets() const;
144
145 SCH_SHEET* GetTopLevelSheet( int aIndex = 0 ) const;
146
147 void SetTopLevelSheets( const std::vector<SCH_SHEET*>& aSheets );
148
154 void AddTopLevelSheet( SCH_SHEET* aSheet );
155
162 bool RemoveTopLevelSheet( SCH_SHEET* aSheet );
163
170 bool IsTopLevelSheet( const SCH_SHEET* aSheet ) const;
171
173 bool IsValid() const
174 {
175 return m_project && m_rootSheet != nullptr;
176 }
177
179 SCH_SCREEN* RootScreen() const;
180
181 void GetContextualTextVars( wxArrayString* aVars ) const;
182
183 bool ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token, int aDepth ) const;
184
186 wxString GetFileName() const;
187
189 {
190 return *m_currentSheet;
191 }
192
193 void SetCurrentSheet( const SCH_SHEET_PATH& aPath )
194 {
195 *m_currentSheet = aPath;
196 }
197
199
201 {
202 return m_connectionGraph;
203 }
204
206
207 ERC_SETTINGS& ErcSettings() const;
208
209 std::vector<SCH_MARKER*> ResolveERCExclusions();
210
212 const EMBEDDED_FILES* GetEmbeddedFiles() const;
213
218 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
219
220 void AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
221
222 void SetBusAliases( const std::vector<std::shared_ptr<BUS_ALIAS>>& aAliases );
223
224 const std::vector<std::shared_ptr<BUS_ALIAS>>& GetAllBusAliases() const
225 {
226 return m_busAliases;
227 }
228
235 std::set<wxString> GetNetClassAssignmentCandidates();
236
243 bool ResolveCrossReference( wxString* token, int aDepth ) const;
244
245 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
246
247 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
248 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
249
250 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
251 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
252
261
274
281
287
292 {
293 m_operatingPoints.clear();
294 }
295
301 void SetOperatingPoint( const wxString& aSignal, double aValue )
302 {
303 m_operatingPoints[ aSignal ] = aValue;
304 }
305
306 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
307
315
319 void RecordERCExclusions();
320
325
330 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
331
336 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
337
342 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
343
350 void OnSchSheetChanged();
351
361 void AddListener( SCHEMATIC_LISTENER* aListener );
362
368 void RemoveListener( SCHEMATIC_LISTENER* aListener );
369
373 void RemoveAllListeners();
374
375 void RunOnNestedEmbeddedFiles( const std::function<void( EMBEDDED_FILES* )>& aFunction ) override;
376
380 void EmbedFonts() override;
381
385 std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
386
393 std::set<const SCH_SCREEN*> GetSchematicsSharedByMultipleProjects() const;
394
400 bool IsComplexHierarchy() const;
401
403
411 void CleanUp( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen = nullptr );
412
416 void RecalculateConnections( SCH_COMMIT* aCommit, SCH_CLEANUP_FLAGS aCleanupFlags,
417 TOOL_MANAGER* aToolManager,
418 PROGRESS_REPORTER* aProgressReporter = nullptr,
419 KIGFX::SCH_VIEW* aSchView = nullptr,
420 std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr,
421 PICKED_ITEMS_LIST* aLastChangeList = nullptr );
422
430
437 bool Contains( const SCH_REFERENCE& aRef ) const;
438
440
451 wxArrayString GetVariantNamesForUI() const;
452
458 wxString GetCurrentVariant() const;
459
460 void SetCurrentVariant( const wxString& aVariantName );
461
467 void DeleteVariant( const wxString& aVariantName, SCH_COMMIT* aCommit = nullptr );
468
469 void AddVariant( const wxString& aVariantName );
470
480 void RenameVariant( const wxString& aOldName, const wxString& aNewName,
481 SCH_COMMIT* aCommit = nullptr );
482
493 void CopyVariant( const wxString& aSourceVariant, const wxString& aNewVariant,
494 SCH_COMMIT* aCommit = nullptr );
495
499 const std::set<wxString>& GetVariantNames() const { return m_variantNames; }
500
507 wxString GetVariantDescription( const wxString& aVariantName ) const;
508
515 void SetVariantDescription( const wxString& aVariantName, const wxString& aDescription );
516
523 void LoadVariants();
524
529
530#if defined(DEBUG)
531 void Show( int nestLevel, std::ostream& os ) const override {}
532#endif
533
535
545 void SaveToHistory( const wxString& aProjectPath, std::vector<HISTORY_FILE_DATA>& aFileData );
546
547private:
548 friend class SCH_EDIT_FRAME;
549
550 template <typename Func, typename... Args>
551 void InvokeListeners( Func&& aFunc, Args&&... args )
552 {
553 for( auto&& l : m_listeners )
554 ( l->*aFunc )( std::forward<Args>( args )... );
555 }
556
557 void ensureVirtualRoot();
560 void rebuildHierarchyState( bool aResetConnectionGraph );
561
563
566
568 std::vector<SCH_SHEET*> m_topLevelSheets;
569
578
581
587 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
588
592 std::map<wxString, wxString> m_properties;
593
597 std::map<wxString, double> m_operatingPoints;
598
603
607 std::vector<SCHEMATIC_LISTENER*> m_listeners;
608
613
615
617
618 std::vector<std::shared_ptr<BUS_ALIAS>> m_busAliases;
619
621
622 std::set<wxString> m_variantNames;
623
627};
628
629#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:41
EMBEDDED_FILES()=default
Container for ERC settings.
Class OUTLINE_FONT implements outline font drawing.
Definition kiid.h:48
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:93
Container for project specific data.
Definition project.h:66
ELEM
The set of #_ELEMs that a PROJECT can hold.
Definition project.h:72
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:66
virtual ~SCHEMATIC_LISTENER()
Definition schematic.h:64
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition schematic.h:67
virtual void OnSchSheetChanged(SCHEMATIC &aSch)
Definition schematic.h:71
virtual void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition schematic.h:65
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition schematic.h:89
void SetCurrentVariant(const wxString &aVariantName)
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition schematic.h:193
bool m_settingTopLevelSheets
Re-entry guard to prevent infinite recursion between ensureDefaultTopLevelSheet and RefreshHierarchy ...
Definition schematic.h:626
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:580
virtual wxString GetClass() const override
Return the class name.
Definition schematic.h:95
bool IsTopLevelSheet(const SCH_SHEET *aSheet) const
Check if a sheet is a top-level sheet (direct child of virtual root).
void loadBusAliasesFromProject()
void AddTopLevelSheet(SCH_SHEET *aSheet)
Add a new top-level sheet to the schematic.
void SetOperatingPoint(const wxString &aSignal, double aValue)
Set operating points from a .op simulation.
Definition schematic.h:301
SCH_SHEET_LIST m_hierarchy
Cache of the entire schematic hierarchy sorted by sheet page number.
Definition schematic.h:602
void rebuildHierarchyState(bool aResetConnectionGraph)
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
void DeleteVariant(const wxString &aVariantName, SCH_COMMIT *aCommit=nullptr)
Delete all information for aVariantName.
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.
wxString GetVariantDescription(const wxString &aVariantName) const
Return the description for a variant.
void LoadVariants()
This is a throw away method for variant testing.
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
const std::vector< std::shared_ptr< BUS_ALIAS > > & GetAllBusAliases() const
Definition schematic.h:224
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:402
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition schematic.h:577
std::vector< SCH_SHEET * > m_topLevelSheets
List of top-level sheets (direct children of virtual root)
Definition schematic.h:568
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.
void AddVariant(const wxString &aVariantName)
int FixupJunctionsAfterImport()
Add junctions to this schematic where required.
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.
void CopyVariant(const wxString &aSourceVariant, const wxString &aNewVariant, SCH_COMMIT *aCommit=nullptr)
Copy a variant from aSourceVariant to aNewVariant.
std::vector< SCH_MARKER * > ResolveERCExclusions()
void SaveToHistory(const wxString &aProjectPath, std::vector< HISTORY_FILE_DATA > &aFileData)
Serialize schematic sheets into HISTORY_FILE_DATA for non-blocking history commit.
void EmbedFonts() override
Embed fonts in the schematic.
SCHEMATIC_SETTINGS & Settings() const
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition schematic.h:291
SCH_SCREEN * GetCurrentScreen() const
Definition schematic.h:198
wxString ConvertKIIDsToRefs(const wxString &aSource) const
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
Definition schematic.h:127
void ensureVirtualRoot()
void ensureCurrentSheetIsTopLevel()
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:620
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition schematic.h:245
SCH_SHEET_LIST BuildUnorderedSheetList() const
void RenameVariant(const wxString &aOldName, const wxString &aNewName, SCH_COMMIT *aCommit=nullptr)
Rename a variant from aOldName to aNewName.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:104
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:587
bool HasHierarchy() const
Check if the hierarchy has been built.
Definition schematic.h:123
std::set< KIFONT::OUTLINE_FONT * > GetFonts() const override
Get a set of fonts used in the schematic.
SCH_SHEET * GetTopLevelSheet(int aIndex=0) const
bool RemoveTopLevelSheet(SCH_SHEET *aSheet)
Remove a top-level sheet from the schematic.
bool Contains(const SCH_REFERENCE &aRef) const
Check if the schematic contains the specified reference.
wxString ConvertRefsToKIIDs(const wxString &aSource) const
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:562
CONNECTION_GRAPH * ConnectionGraph() const
Definition schematic.h:200
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
SCHEMATIC(PROJECT *aPrj)
Definition schematic.cpp:69
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:618
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition schematic.h:551
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:173
void updateProjectBusAliases()
void SetVariantDescription(const wxString &aVariantName, const wxString &aDescription)
Set the description for a variant.
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition schematic.h:528
void RemoveAllListeners()
Remove all listeners.
void SetTopLevelSheets(const std::vector< SCH_SHEET * > &aSheets)
const std::set< wxString > & GetVariantNames() const
Return the set of variant names (without the default placeholder).
Definition schematic.h:499
const std::map< wxString, wxString > * GetProperties()
Definition schematic.h:107
void GetContextualTextVars(wxArrayString *aVars) const
friend class SCH_EDIT_FRAME
Definition schematic.h:548
void ensureDefaultTopLevelSheet()
SCH_SHEET & Root() const
Definition schematic.h:133
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
std::vector< SCH_SHEET * > GetTopLevelSheets() const
Get the list of top-level sheets.
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:612
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:607
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:188
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:597
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition schematic.h:592
ERC_SETTINGS & ErcSettings() const
std::set< wxString > m_variantNames
Definition schematic.h:622
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:534
SCH_SHEET * m_rootSheet
The virtual root sheet (has no screen, contains all top-level sheets)
Definition schematic.h:565
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.
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:48
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:75
@ LOCAL_CLEANUP
Definition schematic.h:77
@ NO_CLEANUP
Definition schematic.h:76
@ GLOBAL_CLEANUP
Definition schematic.h:78
Data produced by a registered saver on the UI thread, consumed by the background commit thread.