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-2021 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 
36 #include <kiid.h>
37 
42 {
44 
45  // Things that can be annotated:
46  wxString m_Reference;
47  int m_Unit;
48 
49  // Things that can be back-annotated:
50  wxString m_Value;
51  wxString m_Footprint;
52 };
53 
54 
59 {
61 
62  wxString m_PageNumber;
63 };
64 
65 
104 class wxFindReplaceData;
105 class EDA_ITEM;
106 class SCH_SHEET;
107 class SCH_SCREEN;
108 class SCH_MARKER;
109 class SCH_ITEM;
110 class SCH_SYMBOL;
112 
113 
117 typedef std::map<wxString, SCH_REFERENCE_LIST> SCH_MULTI_UNIT_REFERENCE_MAP;
118 
129 {
130 public:
131  SCH_SHEET_PATH();
132 
133  SCH_SHEET_PATH( const SCH_SHEET_PATH& aOther );
134 
135  SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& aOther );
136 
137  ~SCH_SHEET_PATH() = default;
138 
140  SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); }
141 
143  void clear()
144  {
145  m_sheets.clear();
146  Rehash();
147  }
148 
150  bool empty() const { return m_sheets.empty(); }
151 
153  void pop_back()
154  {
155  m_sheets.pop_back();
156  Rehash();
157  }
158 
160  void push_back( SCH_SHEET* aSheet )
161  {
162  m_sheets.push_back( aSheet );
163  Rehash();
164  }
165 
167  size_t size() const { return m_sheets.size(); }
168 
169  void Rehash();
170 
171  size_t GetCurrentHash() const { return m_current_hash; }
172 
182  void SetVirtualPageNumber( int aPageNumber ) { m_virtualPageNumber = aPageNumber; }
183 
185 
191  void SetPageNumber( const wxString& aPageNumber );
192 
193  wxString GetPageNumber() const;
194 
195  const SCH_SHEET* GetSheet( unsigned aIndex ) const
196  {
197  SCH_SHEET* retv = nullptr;
198 
199  if( aIndex < size() )
200  retv = at( aIndex );
201 
202  return retv;
203  }
204 
205  bool IsFullPath() const;
206 
215  int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
216 
225  int ComparePageNum( const SCH_SHEET_PATH& aSheetPathToTest ) const;
226 
233  bool IsContainedWithin( const SCH_SHEET_PATH& aSheetPathToTest ) const;
234 
240  SCH_SHEET* Last() const;
241 
246 
247 
249  SCH_SCREEN* LastScreen() const;
250 
256  wxString PathAsString() const;
257 
263  KIID_PATH Path() const;
264 
271 
278  wxString PathHumanReadable( bool aUseShortRootName = true ) const;
279 
287 
298  void AppendSymbol( SCH_REFERENCE_LIST& aReferences, SCH_SYMBOL* aSymbol,
299  bool aIncludePowerSymbols = true,
300  bool aForceIncludeOrphanSymbols = false ) const;
301 
311  void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
312  bool aForceIncludeOrphanSymbols = false ) const;
313 
325  bool aIncludePowerSymbols = true ) const;
326 
337  bool aIncludePowerSymbols = true ) const;
338 
348  bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName );
349 
367 
368  bool operator==( const SCH_SHEET_PATH& d1 ) const;
369 
370  bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
371 
372  bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
373 
374 private:
375  void initFromOther( const SCH_SHEET_PATH& aOther );
376 
377 protected:
378  std::vector< SCH_SHEET* > m_sheets;
379 
381 
383 
384  std::map<std::pair<wxString, wxString>, bool> m_recursion_test_cache;
385 };
386 
387 
388 namespace std
389 {
390  template<> struct hash<SCH_SHEET_PATH>
391  {
392  size_t operator()( const SCH_SHEET_PATH& path ) const;
393  };
394 }
395 
396 
397 typedef std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS;
398 typedef SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER;
399 
400 
410 {
411 public:
417  SCH_SHEET_LIST( SCH_SHEET* aSheet = nullptr, bool aCheckIntegrity = false );
418 
420 
426  bool IsModified() const;
427 
428  void ClearModifyStatus();
429 
433  SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr ) const;
434 
438  void FillItemMap( std::map<KIID, EDA_ITEM*>& aMap );
439 
448  void AnnotatePowerSymbols();
449 
459  void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
460  bool aForceIncludeOrphanSymbols = false ) const;
461 
473  void GetSymbolsWithinPath( SCH_REFERENCE_LIST& aReferences, const SCH_SHEET_PATH& aSheetPath,
474  bool aIncludePowerSymbols = true,
475  bool aForceIncludeOrphanSymbols = false ) const;
476 
484  void GetSheetsWithinPath( SCH_SHEET_PATHS& aSheets, const SCH_SHEET_PATH& aSheetPath ) const;
485 
495  bool aIncludePowerSymbols = true ) const;
496 
505  bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
506  const wxString& aDestFileName );
507 
512  SCH_SHEET_PATH* FindSheetForScreen( const SCH_SCREEN* aScreen );
513 
517  SCH_SHEET_LIST FindAllSheetsForScreen( const SCH_SCREEN* aScreen ) const;
518 
533  void BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity );
534 
544  void SortByPageNumbers( bool aUpdateVirtualPageNums = true );
545 
546  bool NameExists( const wxString& aSheetName ) const;
547 
548  bool PageNumberExists( const wxString& aPageNumber ) const;
549 
555  void UpdateSymbolInstances( const std::vector<SYMBOL_INSTANCE_REFERENCE>& aSymbolInstances );
556 
564  void UpdateSheetInstances( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances );
565 
566  std::vector<KIID_PATH> GetPaths() const;
567 
573  std::vector<SCH_SHEET_INSTANCE> GetSheetInstances() const;
574 
583  bool AllSheetPageNumbersEmpty() const;
584 
591  void SetInitialPageNumbers();
592 
593 private:
595 };
596 
597 #endif // CLASS_DRAWSHEET_PATH_H
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
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)
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
int ComparePageNum(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare sheets by their page number.
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...
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 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.
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
bool IsModified() const
Check the entire hierarchy for any modifications.
bool operator==(const SCH_SHEET_PATH &d1) const
bool PageNumberExists(const wxString &aPageNumber) const
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
wxString PathHumanReadable(bool aUseShortRootName=true) const
Return the sheet path in a human readable form made from the sheet names.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
bool operator!=(const SCH_SHEET_PATH &d1) const
Definition: bitmap.cpp:64
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 UpdateAllScreenReferences()
Update all the symbol references for this sheet path.
int GetVirtualPageNumber() const
~SCH_SHEET_PATH()=default
void UpdateSheetInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void pop_back()
Forwarded method from std::vector.
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Fill an item cache for temporary use when many items need to be fetched.
Definition: kiid.h:44
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...
SCH_SHEET_PATH & operator=(const SCH_SHEET_PATH &aOther)
size_t size() const
Forwarded method from std::vector.
std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS
SCH_SHEET_PATH m_currentSheetPath
void SetVirtualPageNumber(int aPageNumber)
Set the sheet instance virtual page number.
std::vector< SCH_SHEET * > m_sheets
wxString GetPageNumber() const
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
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-...
bool NameExists(const wxString &aSheetName) const
A simple container for schematic symbol instance information.
std::vector< SCH_SHEET_INSTANCE > GetSheetInstances() const
Fetch the instance information for all of the sheets in the hiearchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
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.
void clear()
Forwarded method from std::vector.
void UpdateSymbolInstances(const std::vector< SYMBOL_INSTANCE_REFERENCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.
KIID_PATH PathWithoutRootUuid() const
Get the sheet path as an KIID_PATH without the root sheet UUID prefix.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
void MakeFilePathRelativeToParentSheet()
Make the sheet file name relative to its parent sheet.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Fetch a SCH_ITEM by ID.
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
A simple container for sheet instance information.
const SCH_SHEET * GetSheet(unsigned aIndex) const
Schematic symbol object.
Definition: sch_symbol.h:78
SCH_SCREEN * LastScreen()
SCH_SHEET_LIST(SCH_SHEET *aSheet=nullptr, bool aCheckIntegrity=false)
Construct a flattened list of SCH_SHEET_PATH objects from aSheet.
size_t GetCurrentHash() const
SCH_SHEET * at(size_t aIndex) 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.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
std::vector< KIID_PATH > GetPaths() const
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
bool empty() const
Forwarded method from std::vector.
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
bool IsFullPath() 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...
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
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 operator<(const SCH_SHEET_PATH &d1) const
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...
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare if this is the same sheet path as aSheetPathToTest.
void SetInitialPageNumbers()
Set initial sheet page numbers.
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...