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
117 void RefreshHierarchy();
118
119 SCH_ITEM* ResolveItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr,
120 bool aAllowNullptrReturn = false ) const
121 {
122 return BuildUnorderedSheetList().ResolveItem( aID, aPathOut, aAllowNullptrReturn );
123 }
124
126 {
127 return *m_rootSheet;
128 }
129
138 void SetRoot( SCH_SHEET* aRootSheet );
139
145 std::vector<SCH_SHEET*> GetTopLevelSheets() const;
146
152 void AddTopLevelSheet( SCH_SHEET* aSheet );
153
160 bool RemoveTopLevelSheet( SCH_SHEET* aSheet );
161
168 bool IsTopLevelSheet( const SCH_SHEET* aSheet ) const;
169
171 bool IsValid() const
172 {
173 return m_project && m_rootSheet != nullptr;
174 }
175
177 SCH_SCREEN* RootScreen() const;
178
179 void GetContextualTextVars( wxArrayString* aVars ) const;
180
181 bool ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token, int aDepth ) const;
182
184 wxString GetFileName() const;
185
187 {
188 return *m_currentSheet;
189 }
190
191 void SetCurrentSheet( const SCH_SHEET_PATH& aPath )
192 {
193 *m_currentSheet = aPath;
194 }
195
197
199 {
200 return m_connectionGraph;
201 }
202
204
205 ERC_SETTINGS& ErcSettings() const;
206
207 std::vector<SCH_MARKER*> ResolveERCExclusions();
208
210 const EMBEDDED_FILES* GetEmbeddedFiles() const;
211
216 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
217
218 void AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
219
220 void SetBusAliases( const std::vector<std::shared_ptr<BUS_ALIAS>>& aAliases );
221
222 const std::vector<std::shared_ptr<BUS_ALIAS>>& GetAllBusAliases() const
223 {
224 return m_busAliases;
225 }
226
233 std::set<wxString> GetNetClassAssignmentCandidates();
234
241 bool ResolveCrossReference( wxString* token, int aDepth ) const;
242
243 std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
244
245 std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
246 std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
247
248 wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
249 wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
250
259
272
279
285
290 {
291 m_operatingPoints.clear();
292 }
293
299 void SetOperatingPoint( const wxString& aSignal, double aValue )
300 {
301 m_operatingPoints[ aSignal ] = aValue;
302 }
303
304 wxString GetOperatingPoint( const wxString& aNetName, int aPrecision, const wxString& aRange );
305
313
317 void RecordERCExclusions();
318
323
328 void OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems );
329
334 void OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems );
335
340 void OnItemsChanged( std::vector<SCH_ITEM*>& aItems );
341
348 void OnSchSheetChanged();
349
359 void AddListener( SCHEMATIC_LISTENER* aListener );
360
366 void RemoveListener( SCHEMATIC_LISTENER* aListener );
367
371 void RemoveAllListeners();
372
373 void RunOnNestedEmbeddedFiles( const std::function<void( EMBEDDED_FILES* )>& aFunction ) override;
374
378 void EmbedFonts() override;
379
383 std::set<KIFONT::OUTLINE_FONT*> GetFonts() const override;
384
391 std::set<const SCH_SCREEN*> GetSchematicsSharedByMultipleProjects() const;
392
398 bool IsComplexHierarchy() const;
399
401
409 void CleanUp( SCH_COMMIT* aCommit, SCH_SCREEN* aScreen = nullptr );
410
414 void RecalculateConnections( SCH_COMMIT* aCommit, SCH_CLEANUP_FLAGS aCleanupFlags,
415 TOOL_MANAGER* aToolManager,
416 PROGRESS_REPORTER* aProgressReporter = nullptr,
417 KIGFX::SCH_VIEW* aSchView = nullptr,
418 std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr,
419 PICKED_ITEMS_LIST* aLastChangeList = nullptr );
420
428
435 bool Contains( const SCH_REFERENCE& aRef ) const;
436
438
449 wxArrayString GetVariantNamesForUI() const;
450
456 wxString GetCurrentVariant() const;
457
458 void SetCurrentVariant( const wxString& aVariantName );
459
465 void DeleteVariant( const wxString& aVariantName );
466
467 void AddVariant( const wxString& aVariantName ) { m_variantNames.emplace( aVariantName ); }
468
473
474#if defined(DEBUG)
475 void Show( int nestLevel, std::ostream& os ) const override {}
476#endif
477
479
488 void SaveToHistory( const wxString& aProjectPath, std::vector<wxString>& aFiles );
489
490private:
491 friend class SCH_EDIT_FRAME;
492
493 template <typename Func, typename... Args>
494 void InvokeListeners( Func&& aFunc, Args&&... args )
495 {
496 for( auto&& l : m_listeners )
497 ( l->*aFunc )( std::forward<Args>( args )... );
498 }
499
501
504
506 std::vector<SCH_SHEET*> m_topLevelSheets;
507
516
519
525 std::map<wxString, std::set<int>> m_labelToPageRefsMap;
526
530 std::map<wxString, wxString> m_properties;
531
535 std::map<wxString, double> m_operatingPoints;
536
541
545 std::vector<SCHEMATIC_LISTENER*> m_listeners;
546
551
553
555
556 std::vector<std::shared_ptr<BUS_ALIAS>> m_busAliases;
557
559
560 std::set<wxString> m_variantNames;
561};
562
563#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:98
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: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:191
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:518
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:299
SCH_SHEET_LIST m_hierarchy
Cache of the entire schematic hierarchy sorted by sheet page number.
Definition schematic.h:540
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
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
const std::vector< std::shared_ptr< BUS_ALIAS > > & GetAllBusAliases() const
Definition schematic.h:222
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:400
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition schematic.h:515
std::vector< SCH_SHEET * > m_topLevelSheets
List of top-level sheets (direct children of virtual root)
Definition schematic.h:506
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)
Definition schematic.h:467
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:289
SCH_SCREEN * GetCurrentScreen() const
Definition schematic.h:196
wxString ConvertKIIDsToRefs(const wxString &aSource) const
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
Definition schematic.h:119
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:558
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition schematic.h:243
SCH_SHEET_LIST BuildUnorderedSheetList() const
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:525
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 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 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:500
CONNECTION_GRAPH * ConnectionGraph() const
Definition schematic.h:198
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
SCHEMATIC(PROJECT *aPrj)
Definition schematic.cpp:63
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:556
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition schematic.h:494
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:171
void updateProjectBusAliases()
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition schematic.h:472
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:491
SCH_SHEET & Root() const
Definition schematic.h:125
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:550
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:545
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:186
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:535
std::map< wxString, wxString > m_properties
Properties for text variable substitution (and perhaps other uses in future).
Definition schematic.h:530
ERC_SETTINGS & ErcSettings() const
std::set< wxString > m_variantNames
Definition schematic.h:560
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:478
SCH_SHEET * m_rootSheet
The virtual root sheet (has no screen, contains all top-level sheets)
Definition schematic.h:503
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: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