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-2020 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 
131 {
132 protected:
133  std::vector< SCH_SHEET* > m_sheets;
134 
136 
138 
139  std::map<std::pair<wxString, wxString>, bool> m_recursion_test_cache;
140 
141 public:
142  SCH_SHEET_PATH();
143 
144  SCH_SHEET_PATH( const SCH_SHEET_PATH& aOther );
145 
146  SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& aOther );
147 
149  SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); }
150 
152  void clear()
153  {
154  m_sheets.clear();
155  Rehash();
156  }
157 
159  bool empty() const { return m_sheets.empty(); }
160 
162  void pop_back()
163  {
164  m_sheets.pop_back();
165  Rehash();
166  }
167 
169  void push_back( SCH_SHEET* aSheet )
170  {
171  m_sheets.push_back( aSheet );
172  Rehash();
173  }
174 
176  size_t size() const { return m_sheets.size(); }
177 
178  void Rehash();
179 
180  size_t GetCurrentHash() const { return m_current_hash; }
181 
191  void SetVirtualPageNumber( int aPageNumber ) { m_virtualPageNumber = aPageNumber; }
192 
194 
200  void SetPageNumber( const wxString& aPageNumber );
201 
202  wxString GetPageNumber() const;
203 
204  const SCH_SHEET* GetSheet( unsigned aIndex ) const
205  {
206  SCH_SHEET* retv = NULL;
207 
208  if( aIndex < size() )
209  retv = at( aIndex );
210 
211  return const_cast< SCH_SHEET* >( retv );
212  }
213 
222  int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
223 
229  SCH_SHEET* Last() const;
230 
235 
236 
238  SCH_SCREEN* LastScreen() const;
239 
245  wxString PathAsString() const;
246 
253  KIID_PATH Path() const;
254 
262 
269  wxString PathHumanReadable( bool aUseShortRootName = true ) const;
270 
278 
289  void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
290  bool aForceIncludeOrphanComponents = false ) const;
291 
302  bool aIncludePowerSymbols = true ) const;
303 
313  bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName );
314 
315  bool operator==( const SCH_SHEET_PATH& d1 ) const;
316 
317  bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
318 
319  bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
320 
321 private:
322 
323  void initFromOther( const SCH_SHEET_PATH& aOther );
324 };
325 
326 
327 namespace std
328 {
329  template<> struct hash<SCH_SHEET_PATH>
330  {
331  size_t operator()( const SCH_SHEET_PATH& path ) const;
332  };
333 }
334 
335 
336 typedef std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS;
337 typedef SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER;
338 
339 
349 {
350 private:
352 
353 public:
354 
360  SCH_SHEET_LIST( SCH_SHEET* aSheet = nullptr, bool aCheckIntegrity = false );
361 
363 
369  bool IsModified();
370 
371  void ClearModifyStatus();
372 
376  SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr );
377 
381  void FillItemMap( std::map<KIID, EDA_ITEM*>& aMap );
382 
391  void AnnotatePowerSymbols();
392 
404  void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
405  bool aForceIncludeOrphanComponents = false ) const;
406 
416  bool aIncludePowerSymbols = true ) const;
417 
426  bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
427  const wxString& aDestFileName );
428 
434 
444  void BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity );
445 
446  bool NameExists( const wxString& aSheetName );
447 
453  void UpdateSymbolInstances( const std::vector<SYMBOL_INSTANCE_REFERENCE>& aSymbolInstances );
454 
462  void UpdateSheetInstances( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances );
463 
464  std::vector<KIID_PATH> GetPaths() const;
465 
478  void ReplaceLegacySheetPaths( const std::vector<KIID_PATH>& aOldSheetPaths );
479 
488  bool AllSheetPageNumbersEmpty() const;
489 
496  void SetInitialPageNumbers();
497 };
498 
499 #endif // CLASS_DRAWSHEET_PATH_H
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
bool IsModified()
Check the entire hierarchy for any modifications.
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
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false) const
Add a SCH_REFERENCE object to aReferences for each component in the list of sheets.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr)
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...
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
bool operator==(const SCH_SHEET_PATH &d1) 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 thesheet names.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
bool operator!=(const SCH_SHEET_PATH &d1) const
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
Definition: bitmap.cpp:58
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 * FindSheetForScreen(SCH_SCREEN *aScreen)
Return a pointer to the first SCH_SHEET_PATH object (not necessarily the only one) using a particular...
void UpdateSheetInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
void GetMultiUnitComponents(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...
SCH_REFERENCE_LIST is used to create a flattened list of symbols because in a complex hierarchy,...
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.
A simple container for schematic symbol instance infromation.
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.
bool NameExists(const wxString &aSheetName)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
A simple container for sheet instance infromation.
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.
std::vector< KIID_PATH > GetPaths() const
void ReplaceLegacySheetPaths(const std::vector< KIID_PATH > &aOldSheetPaths)
Update all of the symbol sheet paths to the sheet paths defined in aOldSheetPaths.
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:194
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 GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false) const
Adds SCH_REFERENCE object to aReferences for each component in the sheet.