KiCad PCB EDA Suite
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-2022 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 // Things that can be back-annotated:
52 wxString m_Value;
53 wxString m_Footprint;
54};
55
56
61{
63
64 wxString m_PageNumber;
65};
66
67
106class EDA_ITEM;
107class SCH_SHEET;
108class SCH_SCREEN;
109class SCH_MARKER;
110class SCH_ITEM;
111class SCH_SYMBOL;
113
114
118typedef std::map<wxString, SCH_REFERENCE_LIST> SCH_MULTI_UNIT_REFERENCE_MAP;
119
130{
131public:
133
134 SCH_SHEET_PATH( const SCH_SHEET_PATH& aOther );
135
136 SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& aOther );
137
138 SCH_SHEET_PATH operator+( const SCH_SHEET_PATH& aOther );
139
140 ~SCH_SHEET_PATH() = default;
141
143 SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); }
144
146 void clear()
147 {
148 m_sheets.clear();
149 Rehash();
150 }
151
153 bool empty() const { return m_sheets.empty(); }
154
156 void pop_back()
157 {
158 m_sheets.pop_back();
159 Rehash();
160 }
161
163 void push_back( SCH_SHEET* aSheet )
164 {
165 m_sheets.push_back( aSheet );
166 Rehash();
167 }
168
170 size_t size() const { return m_sheets.size(); }
171
172 void Rehash();
173
174 size_t GetCurrentHash() const { return m_current_hash; }
175
185 void SetVirtualPageNumber( int aPageNumber ) { m_virtualPageNumber = aPageNumber; }
186
188
194 void SetPageNumber( const wxString& aPageNumber );
195
196 wxString GetPageNumber() const;
197
198 const SCH_SHEET* GetSheet( unsigned aIndex ) const
199 {
200 SCH_SHEET* retv = nullptr;
201
202 if( aIndex < size() )
203 retv = at( aIndex );
204
205 return retv;
206 }
207
208 bool IsFullPath() const;
209
218 int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
219
228 int ComparePageNum( const SCH_SHEET_PATH& aSheetPathToTest ) const;
229
236 bool IsContainedWithin( const SCH_SHEET_PATH& aSheetPathToTest ) const;
237
243 SCH_SHEET* Last() const;
244
249
250
252 SCH_SCREEN* LastScreen() const;
253
259 wxString PathAsString() const;
260
266 KIID_PATH Path() const;
267
274
281 wxString PathHumanReadable( bool aUseShortRootName = true ) const;
282
289 void UpdateAllScreenReferences() const;
290
301 void AppendSymbol( SCH_REFERENCE_LIST& aReferences, SCH_SYMBOL* aSymbol,
302 bool aIncludePowerSymbols = true,
303 bool aForceIncludeOrphanSymbols = false ) const;
304
314 void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
315 bool aForceIncludeOrphanSymbols = false ) const;
316
328 bool aIncludePowerSymbols = true ) const;
329
340 bool aIncludePowerSymbols = true ) const;
341
346
356 bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName );
357
375
376 bool operator==( const SCH_SHEET_PATH& d1 ) const;
377
378 bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
379
380 bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
381
382private:
383 void initFromOther( const SCH_SHEET_PATH& aOther );
384
385protected:
386 std::vector< SCH_SHEET* > m_sheets;
387
389
391
392 std::map<std::pair<wxString, wxString>, bool> m_recursion_test_cache;
393};
394
395
396namespace std
397{
398 template<> struct hash<SCH_SHEET_PATH>
399 {
400 size_t operator()( const SCH_SHEET_PATH& path ) const;
401 };
402}
403
405{
406 const size_t operator()( const SCH_SHEET_PATH& path ) const
407 {
408 return path.GetCurrentHash();
409 }
410};
411
413{
414 bool operator()( const SCH_SHEET_PATH& lhs, const SCH_SHEET_PATH& rhs ) const
415 {
416 return lhs.GetCurrentHash() < rhs.GetCurrentHash();
417 }
418};
419
420
421typedef std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS;
422typedef SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER;
423
424
434{
435public:
441 SCH_SHEET_LIST( SCH_SHEET* aSheet = nullptr, bool aCheckIntegrity = false );
442
444
450 bool IsModified() const;
451
452 void ClearModifyStatus();
453
457 SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr ) const;
458
462 void FillItemMap( std::map<KIID, EDA_ITEM*>& aMap );
463
473
483 void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
484 bool aForceIncludeOrphanSymbols = false ) const;
485
497 void GetSymbolsWithinPath( SCH_REFERENCE_LIST& aReferences, const SCH_SHEET_PATH& aSheetPath,
498 bool aIncludePowerSymbols = true,
499 bool aForceIncludeOrphanSymbols = false ) const;
500
508 void GetSheetsWithinPath( SCH_SHEET_PATHS& aSheets, const SCH_SHEET_PATH& aSheetPath ) const;
509
510
516 std::optional<SCH_SHEET_PATH> GetSheetPathByKIIDPath( const KIID_PATH& aPath ) const;
517
518
528 bool aIncludePowerSymbols = true ) const;
529
538 bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
539 const wxString& aDestFileName );
540
546
552
556 SCH_SHEET_LIST FindAllSheetsForScreen( const SCH_SCREEN* aScreen ) const;
557
572 void BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity );
573
583 void SortByPageNumbers( bool aUpdateVirtualPageNums = true );
584
585 bool NameExists( const wxString& aSheetName ) const;
586
587 bool PageNumberExists( const wxString& aPageNumber ) const;
588
594 void UpdateSymbolInstances( const std::vector<SYMBOL_INSTANCE_REFERENCE>& aSymbolInstances );
595
603 void UpdateSheetInstances( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances );
604
605 std::vector<KIID_PATH> GetPaths() const;
606
612 std::vector<SCH_SHEET_INSTANCE> GetSheetInstances() const;
613
622 bool AllSheetPageNumbersEmpty() const;
623
631
636
637private:
639};
640
641#endif // CLASS_DRAWSHEET_PATH_H
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
Definition: kiid.h:47
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
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.
void UpdateSheetInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
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 UpdateSymbolInstances(const std::vector< SYMBOL_INSTANCE_REFERENCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
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 SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
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 SetInitialPageNumbers()
Set initial sheet page numbers.
void MigrateSimModelNameFields()
Migrate V6 simulator models to V7.
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.
SCH_SHEET_LIST(SCH_SHEET *aSheet=nullptr, bool aCheckIntegrity=false)
Construct a flattened list of SCH_SHEET_PATH objects from aSheet.
SCH_SHEET_PATH * FindSheetForScreen(const SCH_SCREEN *aScreen)
Return a pointer to the first SCH_SHEET_PATH object (not necessarily the only one) using a particular...
bool PageNumberExists(const wxString &aPageNumber) const
std::optional< SCH_SHEET_PATH > GetSheetPathByKIIDPath(const KIID_PATH &aPath) const
Finds a SCH_SHEET_PATH that matches the provided KIID_PATH.
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.
void GetSheetsWithinPath(SCH_SHEET_PATHS &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...
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...
KIID_PATH PathWithoutRootUuid() const
Get the sheet path as an KIID_PATH without the root sheet UUID prefix.
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
void SetSymbolInstancesToDefault()
Set all of the symbol instances in this sheet instance to the default symbol instance data.
bool operator==(const SCH_SHEET_PATH &d1) const
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.
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 GetPageNumber() const
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
~SCH_SHEET_PATH()=default
std::vector< SCH_SHEET * > m_sheets
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) 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
Page numbers are maintained by the sheet load order.
wxString PathAsString() const
Return the path of time stamps which do not changes even when editing sheet parameters.
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
SCH_SHEET_PATH & operator=(const SCH_SHEET_PATH &aOther)
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:55
Schematic symbol object.
Definition: sch_symbol.h:79
Definition: bitmap.cpp:64
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS
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.
bool operator()(const SCH_SHEET_PATH &lhs, const SCH_SHEET_PATH &rhs) const
const size_t operator()(const SCH_SHEET_PATH &path) const
A simple container for schematic symbol instance information.