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 The 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
30
31#ifndef CLASS_DRAWSHEET_PATH_H
32#define CLASS_DRAWSHEET_PATH_H
33
34#include <map>
35#include <memory>
36#include <optional>
37
38#include <kiid.h>
39#include <wx/string.h>
40
41class SCH_SYMBOL;
42class SCH_SHEET;
43
48{
49public:
50 VARIANT( const wxString& aName = wxEmptyString ) :
51 m_Name( aName ),
52 m_ExcludedFromSim( false ),
53 m_ExcludedFromBOM( false ),
54 m_ExcludedFromBoard( false ),
56 m_DNP( false )
57 {
58 }
59
60 virtual ~VARIANT() = default;
61
62 wxString m_Name;
63 wxString m_Description;
68 bool m_DNP;
69 std::map<wxString, wxString> m_Fields;
70};
71
72
82{
83public:
84 SCH_SYMBOL_VARIANT( const wxString& aName = wxEmptyString ) :
85 VARIANT( aName )
86 {}
87
88 void InitializeAttributes( const SCH_SYMBOL& aSymbol );
89
90 virtual ~SCH_SYMBOL_VARIANT() = default;
91};
92
93
98{
100
101 // Things that can be annotated:
102 wxString m_Reference;
103 int m_Unit = 1;
104
105 // Do not use. This is left over from the dubious decision to instantiate symbol value
106 // and footprint fields. This is now handle by variants.
107 wxString m_Value;
108 wxString m_Footprint;
109
110 // The project name associated with this instance.
112
113 bool m_DNP = false;
114 bool m_ExcludedFromBOM = false;
115 bool m_ExcludedFromSim = false;
118
120 std::map<wxString, SCH_SYMBOL_VARIANT> m_Variants;
121};
122
123
135{
136public:
137 SCH_SHEET_VARIANT( const wxString& aName = wxEmptyString ) :
138 VARIANT( aName )
139 {}
140
141 virtual ~SCH_SHEET_VARIANT() = default;
142
143 void InitializeAttributes( const SCH_SHEET& aSheet );
144};
145
146
151{
153
154 wxString m_PageNumber;
155
156 // The project name associated with this instance.
158
159 bool m_DNP = false;
160 bool m_ExcludedFromBOM = false;
161 bool m_ExcludedFromSim = false;
164
166 std::map<wxString, SCH_SHEET_VARIANT> m_Variants;
167};
168
169
202
203
204class EDA_ITEM;
205class SCH_SHEET;
206class SCH_SCREEN;
207class SCH_MARKER;
208class SCH_ITEM;
209class SCH_SYMBOL;
211
212
216typedef std::map<wxString, SCH_REFERENCE_LIST> SCH_MULTI_UNIT_REFERENCE_MAP;
217
228{
229public:
231
232 SCH_SHEET_PATH( const SCH_SHEET_PATH& aOther );
233
234 SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& aOther );
235
236 // Move assignment operator
238
239 SCH_SHEET_PATH operator+( const SCH_SHEET_PATH& aOther );
240
241 ~SCH_SHEET_PATH() = default;
242
244 SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); }
245
247 void clear()
248 {
249 m_sheets.clear();
250 Rehash();
251 }
252
254 bool empty() const { return m_sheets.empty(); }
255
257 void pop_back()
258 {
259 m_sheets.pop_back();
260 Rehash();
261 }
262
264 void push_back( SCH_SHEET* aSheet )
265 {
266 m_sheets.push_back( aSheet );
267 Rehash();
268 }
269
271 size_t size() const { return m_sheets.size(); }
272
273 std::vector<SCH_SHEET*>::iterator erase( std::vector<SCH_SHEET*>::const_iterator aPosition )
274 {
275 return m_sheets.erase( aPosition );
276 }
277
278 void Rehash();
279
280 size_t GetCurrentHash() const { return m_current_hash; }
281
291 void SetVirtualPageNumber( int aPageNumber ) { m_virtualPageNumber = aPageNumber; }
292
294
300 void SetPageNumber( const wxString& aPageNumber );
301
302 wxString GetPageNumber() const;
303
304 int GetPageNumberAsInt() const;
305
306 const SCH_SHEET* GetSheet( unsigned aIndex ) const
307 {
308 SCH_SHEET* retv = nullptr;
309
310 if( aIndex < size() )
311 retv = at( aIndex );
312
313 return retv;
314 }
315
324 int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
325
327 wxString GetCachedPageNumber() const { return m_cached_page_number; }
328
337 int ComparePageNum( const SCH_SHEET_PATH& aSheetPathToTest ) const;
338
345 bool IsContainedWithin( const SCH_SHEET_PATH& aSheetPathToTest ) const;
346
352 SCH_SHEET* Last() const;
353
358
359
361 SCH_SCREEN* LastScreen() const;
362
363 bool GetExcludedFromSim() const;
364 bool GetExcludedFromSim( const wxString& aVariantName ) const;
365 bool GetExcludedFromBOM() const;
366 bool GetExcludedFromBOM( const wxString& aVariantName ) const;
367 bool GetExcludedFromBoard() const;
368 bool GetExcludedFromBoard( const wxString& aVariantName ) const;
369 bool GetDNP() const;
370 bool GetDNP( const wxString& aVariantName ) const;
371
375 SCH_ITEM* ResolveItem( const KIID& aID ) const;
376
382 wxString PathAsString() const;
383
389 KIID_PATH Path() const;
390
406 wxString PathHumanReadable( bool aUseShortRootName = true,
407 bool aStripTrailingSeparator = false,
408 bool aEscapeSheetNames = false ) const;
409
416 void UpdateAllScreenReferences() const;
417
428 void AppendSymbol( SCH_REFERENCE_LIST& aReferences, SCH_SYMBOL* aSymbol,
429 bool aIncludePowerSymbols = true,
430 bool aForceIncludeOrphanSymbols = false ) const;
431
441 void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
442 bool aForceIncludeOrphanSymbols = false ) const;
443
455 bool aIncludePowerSymbols = true ) const;
456
467 bool aIncludePowerSymbols = true ) const;
468
478 bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName );
479
497
515 void AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
516 const wxString& aProjectName );
517
518 void RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath );
519
520 void CheckForMissingSymbolInstances( const wxString& aProjectName );
521
522 bool operator==( const SCH_SHEET_PATH& d1 ) const;
523
524 bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
525
526 bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
527
528private:
529 void initFromOther( const SCH_SHEET_PATH& aOther );
530
531protected:
532 std::vector<SCH_SHEET*> m_sheets;
533
535 mutable wxString m_cached_page_number;
536
538
539 std::map<std::pair<wxString, wxString>, bool> m_recursion_test_cache;
540};
541
542
543namespace std
544{
545 template<> struct hash<SCH_SHEET_PATH>
546 {
547 size_t operator()( const SCH_SHEET_PATH& path ) const;
548 };
549}
550
552{
553 size_t operator()( const SCH_SHEET_PATH& path ) const
554 {
555 return path.GetCurrentHash();
556 }
557};
558
560{
561 bool operator()( const SCH_SHEET_PATH& lhs, const SCH_SHEET_PATH& rhs ) const
562 {
563 return lhs.GetCurrentHash() < rhs.GetCurrentHash();
564 }
565};
566
567
576class SCH_SHEET_LIST : public std::vector<SCH_SHEET_PATH>
577{
578public:
584 SCH_SHEET_LIST( SCH_SHEET* aSheet = nullptr );
585
587
593 bool IsModified() const;
594
595 void ClearModifyStatus();
596
602 SCH_ITEM* ResolveItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr,
603 bool aAllowNullptrReturn = false ) const;
604
608 void FillItemMap( std::map<KIID, EDA_ITEM*>& aMap );
609
619
629 void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
630 bool aForceIncludeOrphanSymbols = false ) const;
631
643 void GetSymbolsWithinPath( SCH_REFERENCE_LIST& aReferences, const SCH_SHEET_PATH& aSheetPath,
644 bool aIncludePowerSymbols = true,
645 bool aForceIncludeOrphanSymbols = false ) const;
646
654 void GetSheetsWithinPath( std::vector<SCH_SHEET_PATH>& aSheets,
655 const SCH_SHEET_PATH& aSheetPath ) const;
656
657
663 std::optional<SCH_SHEET_PATH> GetSheetPathByKIIDPath( const KIID_PATH& aPath,
664 bool aIncludeLastSheet = true ) const;
665
666
676 bool aIncludePowerSymbols = true ) const;
677
686 bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
687 const wxString& aDestFileName );
688
694
700
704 SCH_SHEET_LIST FindAllSheetsForScreen( const SCH_SCREEN* aScreen ) const;
705
720 void BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity );
721
731 void SortByPageNumbers( bool aUpdateVirtualPageNums = true );
732
738 void SortByHierarchicalPageNumbers( bool aUpdateVirtualPageNums = true );
739
740 bool NameExists( const wxString& aSheetName ) const;
741
742 bool PageNumberExists( const wxString& aPageNumber ) const;
743
749 void TrimToPageNumbers( const std::vector<wxString>& aPageInclusions );
750
758 void UpdateSymbolInstanceData( const std::vector<SCH_SYMBOL_INSTANCE>& aSymbolInstances );
759
767 void UpdateSheetInstanceData( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances );
768
769 std::vector<KIID_PATH> GetPaths() const;
770
776 std::vector<SCH_SHEET_INSTANCE> GetSheetInstances() const;
777
786 bool AllSheetPageNumbersEmpty() const;
787
795
803 void AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
804 const wxString& aProjectName );
805
806 void AddNewSheetInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
807 int aLastVirtualPageNumber );
808
809 int GetLastVirtualPageNumber() const;
810
811 void RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath );
812
813 void CheckForMissingSymbolInstances( const wxString& aProjectName );
814
815 bool HasPath( const KIID_PATH& aPath ) const;
816
817 bool ContainsSheet( const SCH_SHEET* aSheet ) const;
818
828 std::optional<SCH_SHEET_PATH> GetOrdinalPath( const SCH_SCREEN* aScreen ) const;
829
830private:
832};
833
834#endif // CLASS_DRAWSHEET_PATH_H
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
Definition kiid.h:49
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
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 * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) 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...
std::optional< SCH_SHEET_PATH > GetOrdinalPath(const SCH_SCREEN *aScreen) const
Return the ordinal sheet path of aScreen.
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 hierarchy.
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.
SCH_SHEET_LIST(SCH_SHEET *aSheet=nullptr)
Construct a flattened list of SCH_SHEET_PATH objects from aSheet.
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 SortByHierarchicalPageNumbers(bool aUpdateVirtualPageNums=true)
This works like SortByPageNumbers, but it sorts the sheets first by their hierarchical depth and then...
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.
void CheckForMissingSymbolInstances(const wxString &aProjectName)
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
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
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
void MakeFilePathRelativeToParentSheet()
Make the sheet file name relative to its parent sheet.
SCH_ITEM * ResolveItem(const KIID &aID) const
Fetch a SCH_ITEM by ID.
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)
void CheckForMissingSymbolInstances(const wxString &aProjectName)
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.
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false, bool aEscapeSheetNames=false) const
Return the sheet path in a human readable form made from the sheet names.
std::map< std::pair< wxString, wxString >, bool > m_recursion_test_cache
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)
int GetPageNumberAsInt() const
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)
int m_virtualPageNumber
Page numbers are maintained by the sheet load order.
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.
void InitializeAttributes(const SCH_SHEET &aSheet)
SCH_SHEET_VARIANT(const wxString &aName=wxEmptyString)
virtual ~SCH_SHEET_VARIANT()=default
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
virtual ~SCH_SYMBOL_VARIANT()=default
void InitializeAttributes(const SCH_SYMBOL &aSymbol)
SCH_SYMBOL_VARIANT(const wxString &aName=wxEmptyString)
Schematic symbol object.
Definition sch_symbol.h:76
wxString m_Name
virtual ~VARIANT()=default
bool m_ExcludedFromBOM
std::map< wxString, wxString > m_Fields
bool m_ExcludedFromPosFiles
bool m_ExcludedFromSim
bool m_ExcludedFromBoard
wxString m_Description
VARIANT(const wxString &aName=wxEmptyString)
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.
std::map< wxString, SCH_SHEET_VARIANT > m_Variants
A list of sheet variants.
A simple container for schematic symbol instance information.
std::map< wxString, SCH_SYMBOL_VARIANT > m_Variants
A list of symbol variants.
bool operator()(const SCH_SHEET_PATH &lhs, const SCH_SHEET_PATH &rhs) const
size_t operator()(const SCH_SHEET_PATH &path) const
size_t operator()(const SCH_SHEET_PATH &path) const
std::string path