KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_sheet_path.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 (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
31#ifndef CLASS_DRAWSHEET_PATH_H
32#define CLASS_DRAWSHEET_PATH_H
33
34#include <map>
35#include <optional>
36
37#include <kiid.h>
38#include <wx/string.h>
39
44{
46
47 // Things that can be annotated:
48 wxString m_Reference;
49 int m_Unit = 1;
50
51 // Do not use. This is left over from the dubious decision to instantiate symbol value
52 // and footprint fields.
53 wxString m_Value;
54 wxString m_Footprint;
55
56 // The project name associated with this instance.
57 wxString m_ProjectName;
58};
59
60
65{
67
68 wxString m_PageNumber;
69
70 // The project name associated with this instance.
71 wxString m_ProjectName;
72};
73
74
113class EDA_ITEM;
114class SCH_SHEET;
115class SCH_SCREEN;
116class SCH_MARKER;
117class SCH_ITEM;
118class SCH_SYMBOL;
120
121
125typedef std::map<wxString, SCH_REFERENCE_LIST> SCH_MULTI_UNIT_REFERENCE_MAP;
126
137{
138public:
140
141 SCH_SHEET_PATH( const SCH_SHEET_PATH& aOther );
142
143 SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& aOther );
144
145 SCH_SHEET_PATH operator+( const SCH_SHEET_PATH& aOther );
146
147 ~SCH_SHEET_PATH() = default;
148
150 SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); }
151
153 void clear()
154 {
155 m_sheets.clear();
156 Rehash();
157 }
158
160 bool empty() const { return m_sheets.empty(); }
161
163 void pop_back()
164 {
165 m_sheets.pop_back();
166 Rehash();
167 }
168
170 void push_back( SCH_SHEET* aSheet )
171 {
172 m_sheets.push_back( aSheet );
173 Rehash();
174 }
175
177 size_t size() const { return m_sheets.size(); }
178
179 std::vector<SCH_SHEET*>::iterator erase( std::vector<SCH_SHEET*>::const_iterator aPosition )
180 {
181 return m_sheets.erase( aPosition );
182 }
183
184 void Rehash();
185
186 size_t GetCurrentHash() const { return m_current_hash; }
187
197 void SetVirtualPageNumber( int aPageNumber ) { m_virtualPageNumber = aPageNumber; }
198
200
206 void SetPageNumber( const wxString& aPageNumber );
207
208 wxString GetPageNumber() const;
209
210 const SCH_SHEET* GetSheet( unsigned aIndex ) const
211 {
212 SCH_SHEET* retv = nullptr;
213
214 if( aIndex < size() )
215 retv = at( aIndex );
216
217 return retv;
218 }
219
220 bool IsFullPath() const;
221
230 int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
231
233 wxString GetCachedPageNumber() const { return m_cached_page_number; }
234
243 int ComparePageNum( const SCH_SHEET_PATH& aSheetPathToTest ) const;
244
251 bool IsContainedWithin( const SCH_SHEET_PATH& aSheetPathToTest ) const;
252
258 SCH_SHEET* Last() const;
259
264
265
267 SCH_SCREEN* LastScreen() const;
268
269 bool GetExcludedFromSim() const;
270 bool GetExcludedFromBOM() const;
271 bool GetExcludedFromBoard() const;
272 bool GetDNP() const;
273
277 SCH_ITEM* GetItem( const KIID& aID ) const;
278
284 wxString PathAsString() const;
285
291 KIID_PATH Path() const;
292
299 wxString PathHumanReadable( bool aUseShortRootName = true,
300 bool aStripTrailingSeparator = false ) const;
301
308 void UpdateAllScreenReferences() const;
309
320 void AppendSymbol( SCH_REFERENCE_LIST& aReferences, SCH_SYMBOL* aSymbol,
321 bool aIncludePowerSymbols = true,
322 bool aForceIncludeOrphanSymbols = false ) const;
323
333 void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
334 bool aForceIncludeOrphanSymbols = false ) const;
335
347 bool aIncludePowerSymbols = true ) const;
348
359 bool aIncludePowerSymbols = true ) const;
360
370 bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName );
371
389
407 void AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
408 const wxString& aProjectName );
409
410 void RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath );
411
412 bool operator==( const SCH_SHEET_PATH& d1 ) const;
413
414 bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
415
416 bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
417
418private:
419 void initFromOther( const SCH_SHEET_PATH& aOther );
420
421protected:
422 std::vector<SCH_SHEET*> m_sheets;
423
425 mutable wxString m_cached_page_number;
426
428
429 std::map<std::pair<wxString, wxString>, bool> m_recursion_test_cache;
430};
431
432
433namespace std
434{
435 template<> struct hash<SCH_SHEET_PATH>
436 {
437 size_t operator()( const SCH_SHEET_PATH& path ) const;
438 };
439}
440
442{
443 size_t operator()( const SCH_SHEET_PATH& path ) const
444 {
445 return path.GetCurrentHash();
446 }
447};
448
450{
451 bool operator()( const SCH_SHEET_PATH& lhs, const SCH_SHEET_PATH& rhs ) const
452 {
453 return lhs.GetCurrentHash() < rhs.GetCurrentHash();
454 }
455};
456
457
466class SCH_SHEET_LIST : public std::vector<SCH_SHEET_PATH>
467{
468public:
474 SCH_SHEET_LIST( SCH_SHEET* aSheet = nullptr );
475
477
483 bool IsModified() const;
484
485 void ClearModifyStatus();
486
490 SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr ) const;
491
495 void FillItemMap( std::map<KIID, EDA_ITEM*>& aMap );
496
506
516 void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
517 bool aForceIncludeOrphanSymbols = false ) const;
518
530 void GetSymbolsWithinPath( SCH_REFERENCE_LIST& aReferences, const SCH_SHEET_PATH& aSheetPath,
531 bool aIncludePowerSymbols = true,
532 bool aForceIncludeOrphanSymbols = false ) const;
533
541 void GetSheetsWithinPath( std::vector<SCH_SHEET_PATH>& aSheets,
542 const SCH_SHEET_PATH& aSheetPath ) const;
543
544
550 std::optional<SCH_SHEET_PATH> GetSheetPathByKIIDPath( const KIID_PATH& aPath,
551 bool aIncludeLastSheet = true ) const;
552
553
563 bool aIncludePowerSymbols = true ) const;
564
573 bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
574 const wxString& aDestFileName );
575
581
587
591 SCH_SHEET_LIST FindAllSheetsForScreen( const SCH_SCREEN* aScreen ) const;
592
607 void BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity );
608
618 void SortByPageNumbers( bool aUpdateVirtualPageNums = true );
619
620 bool NameExists( const wxString& aSheetName ) const;
621
622 bool PageNumberExists( const wxString& aPageNumber ) const;
623
629 void TrimToPageNumbers( const std::vector<wxString>& aPageInclusions );
630
636 void UpdateSymbolInstanceData( const std::vector<SCH_SYMBOL_INSTANCE>& aSymbolInstances );
637
645 void UpdateSheetInstanceData( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances );
646
647 std::vector<KIID_PATH> GetPaths() const;
648
654 std::vector<SCH_SHEET_INSTANCE> GetSheetInstances() const;
655
664 bool AllSheetPageNumbersEmpty() const;
665
673
681 void AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
682 const wxString& aProjectName );
683
684 void AddNewSheetInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
685 int aLastVirtualPageNumber );
686
687 int GetLastVirtualPageNumber() const;
688
689 void RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath );
690
691 bool HasPath( const KIID_PATH& aPath ) const;
692
693 bool ContainsSheet( const SCH_SHEET* aSheet ) const;
694
695private:
697};
698
699#endif // CLASS_DRAWSHEET_PATH_H
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
Definition: kiid.h:49
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
std::optional< SCH_SHEET_PATH > GetSheetPathByKIIDPath(const KIID_PATH &aPath, bool aIncludeLastSheet=true) const
Finds a SCH_SHEET_PATH that matches the provided KIID_PATH.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Fetch a SCH_ITEM by ID.
void GetMultiUnitSymbols(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true) const
Add a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the li...
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Fill an item cache for temporary use when many items need to be fetched.
SCH_SHEET_PATH m_currentSheetPath
void TrimToPageNumbers(const std::vector< wxString > &aPageInclusions)
Truncates the list by removing sheet's with page numbers not in the given list.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
void AddNewSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath, const wxString &aProjectName)
Attempt to add new symbol instances for all symbols in this list of sheet paths prefixed with aPrefix...
bool NameExists(const wxString &aSheetName) const
std::vector< SCH_SHEET_INSTANCE > GetSheetInstances() const
Fetch the instance information for all of the sheets in the hiearchy.
void UpdateSheetInstanceData(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
void SetInitialPageNumbers()
Set initial sheet page numbers.
void RemoveSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath)
SCH_SHEET_LIST FindAllSheetsForScreen(const SCH_SCREEN *aScreen) const
Return a SCH_SHEET_LIST with a copy of all the SCH_SHEET_PATH using a particular screen.
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
bool IsModified() const
Check the entire hierarchy for any modifications.
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
int GetLastVirtualPageNumber() const
void UpdateSymbolInstanceData(const std::vector< SCH_SYMBOL_INSTANCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
void GetSheetsWithinPath(std::vector< SCH_SHEET_PATH > &aSheets, const SCH_SHEET_PATH &aSheetPath) const
Add a SCH_SHEET_PATH object to aSheets for each sheet in the list that are contained within aSheetPat...
bool PageNumberExists(const wxString &aPageNumber) const
void AddNewSheetInstances(const SCH_SHEET_PATH &aPrefixSheetPath, int aLastVirtualPageNumber)
bool ContainsSheet(const SCH_SHEET *aSheet) const
std::vector< KIID_PATH > GetPaths() const
void GetSymbolsWithinPath(SCH_REFERENCE_LIST &aReferences, const SCH_SHEET_PATH &aSheetPath, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets that are contained wi...
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
SCH_SHEET_PATH FindSheetForScreen(const SCH_SCREEN *aScreen)
Return the first SCH_SHEET_PATH object (not necessarily the only one) using a particular screen.
bool HasPath(const KIID_PATH &aPath) const
SCH_SHEET_PATH * FindSheetForPath(const SCH_SHEET_PATH *aPath)
Return a pointer to the first SCH_SHEET_PATH object (not necessarily the only one) matching the provi...
bool TestForRecursion(const SCH_SHEET_LIST &aSrcSheetHierarchy, const wxString &aDestFileName)
Test every SCH_SHEET_PATH in this SCH_SHEET_LIST to verify if adding the sheets stored in aSrcSheetHi...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool GetExcludedFromBOM() const
bool operator!=(const SCH_SHEET_PATH &d1) const
SCH_ITEM * GetItem(const KIID &aID) const
Fetch a SCH_ITEM by ID.
void AppendMultiUnitSymbol(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, SCH_SYMBOL *aSymbol, bool aIncludePowerSymbols=true) const
Append a SCH_REFERENCE_LIST object to aRefList based on aSymbol, storing same-reference set of multi-...
const SCH_SHEET * GetSheet(unsigned aIndex) const
bool empty() const
Forwarded method from std::vector.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.
int ComparePageNum(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare sheets by their page number.
size_t GetCurrentHash() const
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false) const
Return the sheet path in a human readable form made from the sheet names.
std::vector< SCH_SHEET * >::iterator erase(std::vector< SCH_SHEET * >::const_iterator aPosition)
bool operator==(const SCH_SHEET_PATH &d1) const
void AddNewSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath, const wxString &aProjectName)
Attempt to add new symbol instances for all symbols in this sheet path prefixed with aPrefixSheetPath...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
bool TestForRecursion(const wxString &aSrcFileName, const wxString &aDestFileName)
Test the SCH_SHEET_PATH file names to check adding the sheet stored in the file aSrcFileName to the s...
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
bool operator<(const SCH_SHEET_PATH &d1) const
bool IsFullPath() const
void MakeFilePathRelativeToParentSheet()
Make the sheet file name relative to its parent sheet.
wxString GetCachedPageNumber() const
std::vector< SCH_SHEET * > m_sheets
SCH_SCREEN * LastScreen()
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare if this is the same sheet path as aSheetPathToTest.
void GetMultiUnitSymbols(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true) const
Add a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the sh...
void initFromOther(const SCH_SHEET_PATH &aOther)
wxString m_cached_page_number
wxString GetPageNumber() const
void RemoveSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath)
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
~SCH_SHEET_PATH()=default
void CachePageNumber() const
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.
void SetVirtualPageNumber(int aPageNumber)
Set the sheet instance virtual page number.
void AppendSymbol(SCH_REFERENCE_LIST &aReferences, SCH_SYMBOL *aSymbol, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Append a SCH_REFERENCE object to aReferences based on aSymbol.
std::map< std::pair< wxString, wxString >, bool > m_recursion_test_cache
Page numbers are maintained by the sheet load order.
bool GetExcludedFromSim() const
wxString PathAsString() const
Return the path of time stamps which do not changes even when editing sheet parameters.
bool GetExcludedFromBoard() const
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
SCH_SHEET_PATH & operator=(const SCH_SHEET_PATH &aOther)
bool GetDNP() const
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
SCH_SHEET_PATH operator+(const SCH_SHEET_PATH &aOther)
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void clear()
Forwarded method from std::vector.
size_t size() const
Forwarded method from std::vector.
int GetVirtualPageNumber() const
void pop_back()
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
Schematic symbol object.
Definition: sch_symbol.h:105
STL namespace.
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
bool operator()(const SCH_SHEET_PATH &lhs, const SCH_SHEET_PATH &rhs) const
size_t operator()(const SCH_SHEET_PATH &path) const