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
111
116
122 bool HasHierarchy() const { return !m_hierarchy.empty(); }
123
124 void RefreshHierarchy();
125
126 SCH_ITEM* ResolveItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr,
127 bool aAllowNullptrReturn = false ) const
128 {
129 return BuildUnorderedSheetList().ResolveItem( aID, aPathOut, aAllowNullptrReturn );
130 }
131
133 {
134 return *m_rootSheet;
135 }
136
142 std::vector<SCH_SHEET*> GetTopLevelSheets() const;
143
144 SCH_SHEET* GetTopLevelSheet( int aIndex = 0 ) const;
145
146 void SetTopLevelSheets( const std::vector<SCH_SHEET*>& aSheets );
147
153 void AddTopLevelSheet( SCH_SHEET* aSheet );
154
161 bool RemoveTopLevelSheet( SCH_SHEET* aSheet );
162
169 bool IsTopLevelSheet( const SCH_SHEET* aSheet ) const;
170
172 bool IsValid() const
173 {
174 return m_project && m_rootSheet != nullptr;
175 }
176
178 SCH_SCREEN* RootScreen() const;
179
180 void GetContextualTextVars( wxArrayString* aVars ) const;
181
182 bool ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token, int aDepth ) const;
183
185 wxString GetFileName() const;
186
188 {
189 return *m_currentSheet;
190 }
191
192 void SetCurrentSheet( const SCH_SHEET_PATH& aPath )
193 {
194 *m_currentSheet = aPath;
195 }
196
198
200 {
201 return m_connectionGraph;
202 }
203
205
206 ERC_SETTINGS& ErcSettings() const;
207
208 std::vector<SCH_MARKER*> ResolveERCExclusions();
209
211 const EMBEDDED_FILES* GetEmbeddedFiles() const;
212
217 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
218
219 void AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
220
221 void SetBusAliases( const std::vector<std::shared_ptr<BUS_ALIAS>>& aAliases );
222
223 const std::vector<std::shared_ptr<BUS_ALIAS>>& GetAllBusAliases() const
224 {
225 return m_busAliases;
226 }
227
234 std::set<wxString> GetNetClassAssignmentCandidates();
235
242 bool ResolveCrossReference( wxString* token, int aDepth ) const;
243
244 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
245
246 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
247 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
248
249 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
250 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
251
260
273
280
286
291 {
292 m_operatingPoints.clear();
293 }
294
300 void SetOperatingPoint( const wxString& aSignal, double aValue )
301 {
302 m_operatingPoints[ aSignal ] = aValue;
303 }
304
305 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
306
314
318 void RecordERCExclusions();
319
324
329 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
330
335 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
336
341 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
342
349 void OnSchSheetChanged();
350
360 void AddListener( SCHEMATIC_LISTENER* aListener );
361
367 void RemoveListener( SCHEMATIC_LISTENER* aListener );
368
372 void RemoveAllListeners();
373
374 void RunOnNestedEmbeddedFiles( const std::function<void( EMBEDDED_FILES* )>& aFunction ) override;
375
379 void EmbedFonts() override;
380
384 std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
385
392 std::set<const SCH_SCREEN*> GetSchematicsSharedByMultipleProjects() const;
393
399 bool IsComplexHierarchy() const;
400
402
410 void CleanUp( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen = nullptr );
411
415 void RecalculateConnections( SCH_COMMIT* aCommit, SCH_CLEANUP_FLAGS aCleanupFlags,
416 TOOL_MANAGER* aToolManager,
417 PROGRESS_REPORTER* aProgressReporter = nullptr,
418 KIGFX::SCH_VIEW* aSchView = nullptr,
419 std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr,
420 PICKED_ITEMS_LIST* aLastChangeList = nullptr );
421
429
436 bool Contains( const SCH_REFERENCE& aRef ) const;
437
439
450 wxArrayString GetVariantNamesForUI() const;
451
457 wxString GetCurrentVariant() const;
458
459 void SetCurrentVariant( const wxString& aVariantName );
460
466 void DeleteVariant( const wxString& aVariantName, SCH_COMMIT* aCommit = nullptr );
467
468 void AddVariant( const wxString& aVariantName );
469
479 void RenameVariant( const wxString& aOldName, const wxString& aNewName,
480 SCH_COMMIT* aCommit = nullptr );
481
492 void CopyVariant( const wxString& aSourceVariant, const wxString& aNewVariant,
493 SCH_COMMIT* aCommit = nullptr );
494
498 const std::set<wxString>& GetVariantNames() const { return m_variantNames; }
499
506 wxString GetVariantDescription( const wxString& aVariantName ) const;
507
514 void SetVariantDescription( const wxString& aVariantName, const wxString& aDescription );
515
522 void LoadVariants();
523
528
529#if defined(DEBUG)
530 void Show( int nestLevel, std::ostream& os ) const override {}
531#endif
532
534
543 void SaveToHistory( const wxString& aProjectPath, std::vector<wxString>& aFiles );
544
545private:
546 friend class SCH_EDIT_FRAME;
547
548 template <typename Func, typename... Args>
549 void InvokeListeners( Func&& aFunc, Args&&... args )
550 {
551 for( auto&& l : m_listeners )
552 ( l->*aFunc )( std::forward<Args>( args )... );
553 }
554
555 void ensureVirtualRoot();
558 void rebuildHierarchyState( bool aResetConnectionGraph );
559
561
564
566 std::vector<SCH_SHEET*> m_topLevelSheets;
567
576
579
585 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
586
590 std::map<wxString, wxString> m_properties;
591
595 std::map<wxString, double> m_operatingPoints;
596
601
605 std::vector<SCHEMATIC_LISTENER*> m_listeners;
606
611
613
615
616 std::vector<std::shared_ptr<BUS_ALIAS>> m_busAliases;
617
619
620 std::set<wxString> m_variantNames;
621
625};
626
627#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:92
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 SetCurrentVariant(const wxString &aVariantName)
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition schematic.h:192
bool m_settingTopLevelSheets
Re-entry guard to prevent infinite recursion between ensureDefaultTopLevelSheet and RefreshHierarchy ...
Definition schematic.h:624
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:578
virtual wxString GetClass() const override
Return the class name.
Definition schematic.h:94
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:300
SCH_SHEET_LIST m_hierarchy
Cache of the entire schematic hierarchy sorted by sheet page number.
Definition schematic.h:600
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:223
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:401
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition schematic.h:575
std::vector< SCH_SHEET * > m_topLevelSheets
List of top-level sheets (direct children of virtual root)
Definition schematic.h:566
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)
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 EmbedFonts() override
Embed fonts in the schematic.
SCHEMATIC_SETTINGS & Settings() const
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition schematic.h:290
SCH_SCREEN * GetCurrentScreen() const
Definition schematic.h:197
wxString ConvertKIIDsToRefs(const wxString &aSource) const
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
Definition schematic.h:126
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:618
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition schematic.h:244
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: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:585
bool HasHierarchy() const
Check if the hierarchy has been built.
Definition schematic.h:122
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.
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:560
CONNECTION_GRAPH * ConnectionGraph() const
Definition schematic.h:199
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
SCHEMATIC(PROJECT *aPrj)
Definition schematic.cpp:66
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:616
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition schematic.h:549
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:172
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:527
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:498
const std::map< wxString, wxString > * GetProperties()
Definition schematic.h:106
void GetContextualTextVars(wxArrayString *aVars) const
friend class SCH_EDIT_FRAME
Definition schematic.h:546
void ensureDefaultTopLevelSheet()
SCH_SHEET & Root() const
Definition schematic.h:132
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:610
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:605
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:187
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.
void SaveToHistory(const wxString &aProjectPath, std::vector< wxString > &aFiles)
Save schematic files to the .history directory.
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition schematic.h:595
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition schematic.h:590
ERC_SETTINGS & ErcSettings() const
std::set< wxString > m_variantNames
Definition schematic.h:620
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:533
SCH_SHEET * m_rootSheet
The virtual root sheet (has no screen, contains all top-level sheets)
Definition schematic.h:563
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.
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:74
@ LOCAL_CLEANUP
Definition schematic.h:76
@ NO_CLEANUP
Definition schematic.h:75
@ GLOBAL_CLEANUP
Definition schematic.h:77