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-2017 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 
36 #include <map>
37 
38 
82 class wxFindReplaceData;
83 class SCH_SHEET;
84 class SCH_SCREEN;
85 class SCH_MARKER;
86 class SCH_ITEM;
87 class SCH_REFERENCE_LIST;
88 
89 
90 #define SHEET_NOT_FOUND -1
91 
92 
97 typedef std::map<wxString, SCH_REFERENCE_LIST> SCH_MULTI_UNIT_REFERENCE_MAP;
98 
113 {
114 protected:
115  std::vector< SCH_SHEET* > m_sheets;
116 
118 
120 
121 public:
122  SCH_SHEET_PATH();
123 
125  SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); }
126 
128  void clear()
129  {
130  m_sheets.clear();
131  Rehash();
132  }
133 
135  bool empty() const { return m_sheets.empty(); }
136 
138  void pop_back()
139  {
140  m_sheets.pop_back();
141  Rehash();
142  }
143 
145  void push_back( SCH_SHEET* aSheet )
146  {
147  m_sheets.push_back( aSheet );
148  Rehash();
149  }
150 
152  size_t size() const { return m_sheets.size(); }
153 
154  void Rehash();
155 
156  size_t GetCurrentHash() const { return m_current_hash; }
157 
158  void SetPageNumber( int aPageNumber ) { m_pageNumber = aPageNumber; }
159 
160  int GetPageNumber() const { return m_pageNumber; }
161 
162  const SCH_SHEET* GetSheet( unsigned aIndex ) const
163  {
164  SCH_SHEET* retv = NULL;
165 
166  if( aIndex < size() )
167  retv = at( aIndex );
168 
169  return const_cast< SCH_SHEET* >( retv );
170  }
171 
172  SCH_SHEET* GetSheet( unsigned aIndex )
173  {
174  return const_cast< SCH_SHEET* >( static_cast< const SCH_SHEET_PATH& >( *this ).GetSheet( aIndex ) );
175  }
176 
185  int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
186 
192  SCH_SHEET* Last() const;
193 
199 
200 
202  SCH_SCREEN* LastScreen() const;
203 
210  wxString Path() const;
211 
219  wxString PathHumanReadable() const;
220 
225  static wxString GetRootPathName( bool aUseShortName = true );
226 
237 
248  void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
249  bool aForceIncludeOrphanComponents = false );
250 
261  bool aIncludePowerSymbols = true );
262 
273  bool SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
274  bool aSetVisible );
275 
287  bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName ) const;
288 
289  int FindSheet( const wxString& aFileName ) const;
290 
299  SCH_SHEET* FindSheetByName( const wxString& aSheetName );
300 
309  SCH_SHEET* FindSheetByPageNumber( int aPageNumber );
310 
311  bool operator==( const SCH_SHEET_PATH& d1 ) const;
312 
313  bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
314 
315  bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
316 
317 };
318 
319 
320 namespace std
321 {
322  template<> struct hash<SCH_SHEET_PATH>
323  {
324  size_t operator()( const SCH_SHEET_PATH& path ) const;
325  };
326 }
327 
328 
329 typedef std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS;
330 typedef SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER;
331 typedef SCH_SHEET_PATHS::const_iterator SCH_SHEET_PATHS_CITER;
332 typedef SCH_SHEET_PATHS::reverse_iterator SCH_SHEET_PATHS_RITER;
333 typedef SCH_SHEET_PATHS::const_reverse_iterator SCH_SHEET_PATHS_CRITER;
334 
335 
347 {
348 private:
351 
352 public:
353 
360  SCH_SHEET_LIST( SCH_SHEET* aSheet = NULL );
361 
363 
374  SCH_SHEET_PATH* GetSheetByPath( const wxString& aPath, bool aHumanReadable = true );
375 
381  bool IsModified();
382 
383  void ClearModifyStatus();
384 
393  void AnnotatePowerSymbols();
394 
406  void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
407  bool aForceIncludeOrphanComponents = false );
408 
419  bool aIncludePowerSymbols = true );
420 
431  bool SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
432  bool aSetVisible );
433 
441  bool IsComplexHierarchy() const;
442 
453  bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
454  const wxString& aDestFileName ) const;
455 
464  SCH_SHEET* FindSheetByName( const wxString& aSheetName );
465 
472 
482  void BuildSheetList( SCH_SHEET* aSheet );
483 };
484 
485 #endif // CLASS_DRAWSHEET_PATH_H
void GetComponents(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false)
Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the sheet.
SCH_SHEET_LIST.
bool TestForRecursion(const wxString &aSrcFileName, const wxString &aDestFileName) const
Function TestForRecursion.
bool IsModified()
Function IsModified checks the entire hierarchy for any modifications.
SCH_SHEET * FindSheetByName(const wxString &aSheetName)
Function FindSheetByName.
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
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.
bool operator!=(const SCH_SHEET_PATH &d1) const
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
Definition: bitmap.cpp:55
SCH_SHEET_PATH * GetSheetByPath(const wxString &aPath, bool aHumanReadable=true)
Function GetSheetByPath returns a sheet matching the path name in aPath.
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.
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.
SCH_SHEET_PATHS::const_reverse_iterator SCH_SHEET_PATHS_CRITER
SCH_SHEET * FindSheetByName(const wxString &aSheetName)
Function FindSheetByName.
static wxString GetRootPathName(bool aUseShortName=true)
SCH_SHEET_PATHS::const_iterator SCH_SHEET_PATHS_CITER
#define NULL
wxString Path() const
Function Path the path uses the time stamps which do not changes even when editing sheet parameters a...
size_t size() const
Forwarded method from std::vector.
std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS
SCH_SHEET_PATH m_currentSheetPath
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 * GetSheet(unsigned aIndex)
SCH_SHEET * FindSheetByPageNumber(int aPageNumber)
Function FindSheetByPageNumber.
SCH_SHEET_PATH()
Page numbers are maintained by the sheet load order.
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...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:206
void GetMultiUnitComponents(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true)
Function GetMultiUnitComponents adds a SCH_REFERENCE_LIST object to aRefList for each same-reference ...
int FindSheet(const wxString &aFileName) const
const SCH_SHEET * GetSheet(unsigned aIndex) const
SCH_SCREEN * LastScreen()
Function LastScreen.
int GetPageNumber() const
SCH_SHEET_PATHS::reverse_iterator SCH_SHEET_PATHS_RITER
size_t GetCurrentHash() const
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.
bool IsComplexHierarchy() const
Function IsComplexHierarchy searches all of the sheets for duplicate files names which indicates a co...
bool empty() const
Forwarded method from std::vector.
void AnnotatePowerSymbols()
Function AnnotatePowerSymbols Silently annotates the not yet annotated power symbols of the entire hi...
void GetMultiUnitComponents(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true)
Function GetMultiUnitComponents adds a SCH_REFERENCE_LIST object to aRefList for each same-reference ...
void GetComponents(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false)
Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the list of...
wxString PathHumanReadable() const
Function PathHumanReadable returns the sheet path in a human readable form, i.e.
bool TestForRecursion(const SCH_SHEET_LIST &aSrcSheetHierarchy, const wxString &aDestFileName) const
Function TestForRecursion.
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:136
bool operator<(const SCH_SHEET_PATH &d1) const
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Function Cmp Compare if this is the same sheet path as aSheetPathToTest.