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 <base_struct.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 
100 class wxFindReplaceData;
101 class SCH_SHEET;
102 class SCH_SCREEN;
103 class SCH_MARKER;
104 class SCH_ITEM;
106 
107 
112 typedef std::map<wxString, SCH_REFERENCE_LIST> SCH_MULTI_UNIT_REFERENCE_MAP;
113 
128 {
129 protected:
130  std::vector< SCH_SHEET* > m_sheets;
131 
133 
135 
136  std::map<std::pair<wxString, wxString>, bool> m_recursion_test_cache;
137 
138 public:
139  SCH_SHEET_PATH();
140 
141  SCH_SHEET_PATH( const SCH_SHEET_PATH& aOther );
142 
143  SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& aOther );
144 
146  SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); }
147 
149  void clear()
150  {
151  m_sheets.clear();
152  Rehash();
153  }
154 
156  bool empty() const { return m_sheets.empty(); }
157 
159  void pop_back()
160  {
161  m_sheets.pop_back();
162  Rehash();
163  }
164 
166  void push_back( SCH_SHEET* aSheet )
167  {
168  m_sheets.push_back( aSheet );
169  Rehash();
170  }
171 
173  size_t size() const { return m_sheets.size(); }
174 
175  void Rehash();
176 
177  size_t GetCurrentHash() const { return m_current_hash; }
178 
179  void SetPageNumber( int aPageNumber ) { m_pageNumber = aPageNumber; }
180 
181  int GetPageNumber() const { return m_pageNumber; }
182 
183  const SCH_SHEET* GetSheet( unsigned aIndex ) const
184  {
185  SCH_SHEET* retv = NULL;
186 
187  if( aIndex < size() )
188  retv = at( aIndex );
189 
190  return const_cast< SCH_SHEET* >( retv );
191  }
192 
201  int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
202 
208  SCH_SHEET* Last() const;
209 
215 
216 
218  SCH_SCREEN* LastScreen() const;
219 
226  wxString PathAsString() const;
227 
232  KIID_PATH Path() const;
233 
241  wxString PathHumanReadable() const;
242 
247  static wxString GetRootPathName( bool aUseShortName = true );
248 
259 
270  void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
271  bool aForceIncludeOrphanComponents = false ) const;
272 
283  bool aIncludePowerSymbols = true ) const;
284 
296  bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName );
297 
298  bool operator==( const SCH_SHEET_PATH& d1 ) const;
299 
300  bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
301 
302  bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
303 
304 private:
305 
306  void initFromOther( const SCH_SHEET_PATH& aOther );
307 };
308 
309 
310 namespace std
311 {
312  template<> struct hash<SCH_SHEET_PATH>
313  {
314  size_t operator()( const SCH_SHEET_PATH& path ) const;
315  };
316 }
317 
318 
319 typedef std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS;
320 typedef SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER;
321 
322 
334 {
335 private:
337 
338 public:
339 
346  SCH_SHEET_LIST( SCH_SHEET* aSheet = NULL );
347 
349 
355  bool IsModified();
356 
357  void ClearModifyStatus();
358 
362  SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr );
363 
367  void FillItemMap( std::map<KIID, EDA_ITEM*>& aMap );
368 
377  void AnnotatePowerSymbols();
378 
390  void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
391  bool aForceIncludeOrphanComponents = false ) const;
392 
403  bool aIncludePowerSymbols = true ) const;
404 
415  bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
416  const wxString& aDestFileName );
417 
424 
434  void BuildSheetList( SCH_SHEET* aSheet );
435 
436  bool NameExists( const wxString& aSheetName );
437 
443  void UpdateSymbolInstances( const std::vector<COMPONENT_INSTANCE_REFERENCE>& aSymbolInstances );
444 
445  std::vector<KIID_PATH> GetPaths() const;
446 
459  void ReplaceLegacySheetPaths( const std::vector<KIID_PATH>& aOldSheetPaths );
460 };
461 
462 #endif // CLASS_DRAWSHEET_PATH_H
SCH_SHEET_LIST.
void UpdateSymbolInstances(const std::vector< COMPONENT_INSTANCE_REFERENCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
bool IsModified()
Function IsModified checks the entire hierarchy for any modifications.
void initFromOther(const SCH_SHEET_PATH &aOther)
void GetComponents(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false) const
Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the sheet.
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr)
Fetch a SCH_ITEM by ID.
SCH_SHEET * Last() const
Function Last returns a pointer to the last sheet of the list One can see the others sheet as the "pa...
bool operator==(const SCH_SHEET_PATH &d1) const
void SetPageNumber(int aPageNumber)
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
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:56
std::map< std::pair< wxString, wxString >, bool > m_recursion_test_cache
Page numbers are maintained by the sheet load order.
wxString PathAsString() const
Function PathAsString the path uses the time stamps which do not changes even when editing sheet para...
void UpdateAllScreenReferences()
Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) f...
SCH_SHEET_PATH * FindSheetForScreen(SCH_SCREEN *aScreen)
Function FindSheetForScreen.
SCH_SHEET_LIST(SCH_SHEET *aSheet=NULL)
Constructor build a flattened list of SCH_SHEET_PATH objects from aSheet.
void GetMultiUnitComponents(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true) const
Function GetMultiUnitComponents adds a SCH_REFERENCE_LIST object to aRefList for each same-reference ...
void GetMultiUnitComponents(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true) const
Function GetMultiUnitComponents adds a SCH_REFERENCE_LIST object to aRefList for each same-reference ...
SCH_REFERENCE_LIST is used to create a flattened list of components 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: common.h:68
bool TestForRecursion(const SCH_SHEET_LIST &aSrcSheetHierarchy, const wxString &aDestFileName)
Function TestForRecursion.
static wxString GetRootPathName(bool aUseShortName=true)
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
void GetComponents(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false) const
Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the list of...
SCH_SHEET_PATH m_currentSheetPath
A simple container for schematic symbol instance infromation.
std::vector< SCH_SHEET * > m_sheets
SCH_SHEET_PATH.
void BuildSheetList(SCH_SHEET *aSheet)
Function BuildSheetList builds the list of sheets and their sheet path from aSheet.
void clear()
Forwarded method from std::vector.
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Type SCH_MULTI_UNIT_REFERENCE_MAP is used to create a map of reference designators for multi-unit par...
bool NameExists(const wxString &aSheetName)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
const SCH_SHEET * GetSheet(unsigned aIndex) const
SCH_SCREEN * LastScreen()
Function LastScreen.
int GetPageNumber() const
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()
Function AnnotatePowerSymbols Silently annotates the not yet annotated power symbols of the entire hi...
wxString PathHumanReadable() const
Function PathHumanReadable returns the sheet path in a human readable form, i.e.
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)
Function TestForRecursion.
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Function Cmp Compare if this is the same sheet path as aSheetPathToTest.