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 <stambaughw@gmail.com>
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 
213  int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
214 
223  int ComparePageNumAndName( const SCH_SHEET_PATH& aSheetPathToTest ) const;
224 
231  bool IsContainedWithin( const SCH_SHEET_PATH& aSheetPathToTest ) const;
232 
238  SCH_SHEET* Last() const;
239 
244 
245 
247  SCH_SCREEN* LastScreen() const;
248 
254  wxString PathAsString() const;
255 
261  KIID_PATH Path() const;
262 
269 
276  wxString PathHumanReadable( bool aUseShortRootName = true ) const;
277 
285 
296  void AppendSymbol( SCH_REFERENCE_LIST& aReferences, SCH_SYMBOL* aSymbol,
297  bool aIncludePowerSymbols = true,
298  bool aForceIncludeOrphanSymbols = false ) const;
299 
309  void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
310  bool aForceIncludeOrphanSymbols = false ) const;
311 
323  bool aIncludePowerSymbols = true ) const;
324 
335  bool aIncludePowerSymbols = true ) const;
336 
346  bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName );
347 
365 
366  bool operator==( const SCH_SHEET_PATH& d1 ) const;
367 
368  bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
369 
370  bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
371 
372 private:
373  void initFromOther( const SCH_SHEET_PATH& aOther );
374 
375 protected:
376  std::vector< SCH_SHEET* > m_sheets;
377 
379 
381 
382  std::map<std::pair<wxString, wxString>, bool> m_recursion_test_cache;
383 };
384 
385 
386 namespace std
387 {
388  template<> struct hash<SCH_SHEET_PATH>
389  {
390  size_t operator()( const SCH_SHEET_PATH& path ) const;
391  };
392 }
393 
394 
395 typedef std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS;
396 typedef SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER;
397 
398 
408 {
409 public:
415  SCH_SHEET_LIST( SCH_SHEET* aSheet = nullptr, bool aCheckIntegrity = false );
416 
418 
424  bool IsModified() const;
425 
426  void ClearModifyStatus();
427 
431  SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr ) const;
432 
436  void FillItemMap( std::map<KIID, EDA_ITEM*>& aMap );
437 
446  void AnnotatePowerSymbols();
447 
457  void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
458  bool aForceIncludeOrphanSymbols = false ) const;
459 
471  void GetSymbolsWithinPath( SCH_REFERENCE_LIST& aReferences, const SCH_SHEET_PATH& aSheetPath,
472  bool aIncludePowerSymbols = true,
473  bool aForceIncludeOrphanSymbols = false ) const;
474 
482  void GetSheetsWithinPath( SCH_SHEET_PATHS& aSheets, const SCH_SHEET_PATH& aSheetPath ) const;
483 
493  bool aIncludePowerSymbols = true ) const;
494 
503  bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
504  const wxString& aDestFileName );
505 
510  SCH_SHEET_PATH* FindSheetForScreen( const SCH_SCREEN* aScreen );
511 
515  SCH_SHEET_LIST FindAllSheetsForScreen( const SCH_SCREEN* aScreen ) const;
516 
531  void BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity );
532 
542  void SortByPageNumbers( bool aUpdateVirtualPageNums = true );
543 
544  bool NameExists( const wxString& aSheetName ) const;
545 
546  bool PageNumberExists( const wxString& aPageNumber ) const;
547 
553  void UpdateSymbolInstances( const std::vector<SYMBOL_INSTANCE_REFERENCE>& aSymbolInstances );
554 
562  void UpdateSheetInstances( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances );
563 
564  std::vector<KIID_PATH> GetPaths() const;
565 
566  std::vector<SCH_SHEET_INSTANCE> GetSheetInstances() const;
567 
576  bool AllSheetPageNumbersEmpty() const;
577 
584  void SetInitialPageNumbers();
585 
586 private:
588 };
589 
590 #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
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
int ComparePageNumAndName(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare sheets by their page number and then by their name.
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
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:100
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.
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...