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  wxString m_Reference;
47  int m_Unit;
48 };
49 
50 
94 class wxFindReplaceData;
95 class SCH_SHEET;
96 class SCH_SCREEN;
97 class SCH_MARKER;
98 class SCH_ITEM;
100 
101 
106 typedef std::map<wxString, SCH_REFERENCE_LIST> SCH_MULTI_UNIT_REFERENCE_MAP;
107 
122 {
123 protected:
124  std::vector< SCH_SHEET* > m_sheets;
125 
127 
129 
130  std::map<std::pair<wxString, wxString>, bool> m_recursion_test_cache;
131 
132 public:
133  SCH_SHEET_PATH();
134 
136  SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); }
137 
139  void clear()
140  {
141  m_sheets.clear();
142  Rehash();
143  }
144 
146  bool empty() const { return m_sheets.empty(); }
147 
149  void pop_back()
150  {
151  m_sheets.pop_back();
152  Rehash();
153  }
154 
156  void push_back( SCH_SHEET* aSheet )
157  {
158  m_sheets.push_back( aSheet );
159  Rehash();
160  }
161 
163  size_t size() const { return m_sheets.size(); }
164 
165  void Rehash();
166 
167  size_t GetCurrentHash() const { return m_current_hash; }
168 
169  void SetPageNumber( int aPageNumber ) { m_pageNumber = aPageNumber; }
170 
171  int GetPageNumber() const { return m_pageNumber; }
172 
173  const SCH_SHEET* GetSheet( unsigned aIndex ) const
174  {
175  SCH_SHEET* retv = NULL;
176 
177  if( aIndex < size() )
178  retv = at( aIndex );
179 
180  return const_cast< SCH_SHEET* >( retv );
181  }
182 
191  int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
192 
198  SCH_SHEET* Last() const;
199 
205 
206 
208  SCH_SCREEN* LastScreen() const;
209 
216  wxString PathAsString() const;
217 
222  KIID_PATH Path() const;
223 
231  wxString PathHumanReadable() const;
232 
237  static wxString GetRootPathName( bool aUseShortName = true );
238 
249 
260  void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
261  bool aForceIncludeOrphanComponents = false ) const;
262 
273  bool aIncludePowerSymbols = true ) const;
274 
285  bool SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
286  bool aSetVisible );
287 
299  bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName );
300 
301  bool operator==( const SCH_SHEET_PATH& d1 ) const;
302 
303  bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
304 
305  bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
306 
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 SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
416  bool aSetVisible );
417 
428  bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
429  const wxString& aDestFileName );
430 
437 
447  void BuildSheetList( SCH_SHEET* aSheet );
448 
449  bool NameExists( const wxString& aSheetName );
450 
456  void UpdateSymbolInstances( const std::vector<COMPONENT_INSTANCE_REFERENCE>& aSymbolInstances );
457 
458  std::vector<KIID_PATH> GetPaths() const;
459 
472  void ReplaceLegacySheetPaths( const std::vector<KIID_PATH>& aOldSheetPaths );
473 };
474 
475 #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 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)
#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.
bool SetComponentFootprint(const wxString &aReference, const wxString &aFootPrint, bool aSetVisible)
Function SetFootprintField searches all the sheets for a component with aReference and set the footpr...
std::vector< SCH_SHEET * > m_sheets
bool SetComponentFootprint(const wxString &aReference, const wxString &aFootPrint, bool aSetVisible)
Function SetFootprintField searches last sheet in the path for a component with aReference and set th...
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:186
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.