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 <eda_item.h>
35 #include <erc_item.h>
36 
37 #include <map>
38 
39 
44 {
46 
47  // Things that can be annotated:
48  wxString m_Reference;
49  int m_Unit;
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 
106 class wxFindReplaceData;
107 class SCH_SHEET;
108 class SCH_SCREEN;
109 class SCH_MARKER;
110 class SCH_ITEM;
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 = NULL;
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 
220  SCH_SHEET* Last() const;
221 
226 
227 
229  SCH_SCREEN* LastScreen() const;
230 
236  wxString PathAsString() const;
237 
243  KIID_PATH Path() const;
244 
251 
258  wxString PathHumanReadable( bool aUseShortRootName = true ) const;
259 
267 
277  void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
278  bool aForceIncludeOrphanSymbols = false ) const;
279 
290  bool aIncludePowerSymbols = true ) const;
291 
301  bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName );
302 
303  bool operator==( const SCH_SHEET_PATH& d1 ) const;
304 
305  bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
306 
307  bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
308 
309 private:
310  void initFromOther( const SCH_SHEET_PATH& aOther );
311 
312 protected:
313  std::vector< SCH_SHEET* > m_sheets;
314 
316 
318 
319  std::map<std::pair<wxString, wxString>, bool> m_recursion_test_cache;
320 };
321 
322 
323 namespace std
324 {
325  template<> struct hash<SCH_SHEET_PATH>
326  {
327  size_t operator()( const SCH_SHEET_PATH& path ) const;
328  };
329 }
330 
331 
332 typedef std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS;
333 typedef SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER;
334 
335 
345 {
346 public:
352  SCH_SHEET_LIST( SCH_SHEET* aSheet = nullptr, bool aCheckIntegrity = false );
353 
355 
361  bool IsModified() const;
362 
363  void ClearModifyStatus();
364 
368  SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr ) const;
369 
373  void FillItemMap( std::map<KIID, EDA_ITEM*>& aMap );
374 
383  void AnnotatePowerSymbols();
384 
394  void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
395  bool aForceIncludeOrphanSymbols = false ) const;
396 
406  bool aIncludePowerSymbols = true ) const;
407 
416  bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
417  const wxString& aDestFileName );
418 
423  SCH_SHEET_PATH* FindSheetForScreen( const SCH_SCREEN* aScreen );
424 
439  void BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity );
440 
447  void SortByPageNumbers( bool aUpdateVirtualPageNums = true );
448 
449  bool NameExists( const wxString& aSheetName ) const;
450 
451  bool PageNumberExists( const wxString& aPageNumber ) const;
452 
458  void UpdateSymbolInstances( const std::vector<SYMBOL_INSTANCE_REFERENCE>& aSymbolInstances );
459 
467  void UpdateSheetInstances( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances );
468 
469  std::vector<KIID_PATH> GetPaths() const;
470 
479  bool AllSheetPageNumbersEmpty() const;
480 
487  void SetInitialPageNumbers();
488 
489 private:
491 };
492 
493 #endif // CLASS_DRAWSHEET_PATH_H
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:63
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)
#define NULL
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.
bool NameExists(const wxString &aSheetName) const
A simple container for schematic symbol instance information.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
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
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
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
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.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:197
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.