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 
198  SCH_SCREEN* LastScreen() const;
199 
205  SCH_ITEM* LastDrawList() const;
206 
213  SCH_ITEM* FirstDrawList() const;
214 
221  wxString Path() const;
222 
230  wxString PathHumanReadable() const;
231 
236  static wxString GetRootPathName( bool aUseShortName = true );
237 
248 
259  void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
260  bool aForceIncludeOrphanComponents = false );
261 
272  bool aIncludePowerSymbols = true );
273 
284  bool SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
285  bool aSetVisible );
286 
297  SCH_ITEM* FindNextItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false ) const;
298 
309  SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false ) const;
310 
322  bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName ) const;
323 
324  int FindSheet( const wxString& aFileName ) const;
325 
334  SCH_SHEET* FindSheetByName( const wxString& aSheetName );
335 
344  SCH_SHEET* FindSheetByPageNumber( int aPageNumber );
345 
346  bool operator==( const SCH_SHEET_PATH& d1 ) const;
347 
348  bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
349 
350  bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
351 
352 };
353 
354 
355 namespace std
356 {
357  template<> struct hash<SCH_SHEET_PATH>
358  {
359  size_t operator()( const SCH_SHEET_PATH& path ) const;
360  };
361 }
362 
363 
364 typedef std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS;
365 typedef SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER;
366 typedef SCH_SHEET_PATHS::const_iterator SCH_SHEET_PATHS_CITER;
367 typedef SCH_SHEET_PATHS::reverse_iterator SCH_SHEET_PATHS_RITER;
368 typedef SCH_SHEET_PATHS::const_reverse_iterator SCH_SHEET_PATHS_CRITER;
369 
370 
382 {
383 private:
386 
387 public:
388 
395  SCH_SHEET_LIST( SCH_SHEET* aSheet = NULL );
396 
398 
409  SCH_SHEET_PATH* GetSheetByPath( const wxString& aPath, bool aHumanReadable = true );
410 
416  bool IsModified();
417 
418  void ClearModifyStatus();
419 
428  void AnnotatePowerSymbols();
429 
441  void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
442  bool aForceIncludeOrphanComponents = false );
443 
454  bool aIncludePowerSymbols = true );
455 
467  SCH_ITEM* FindNextItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFound = NULL,
468  SCH_ITEM* aLastItem = NULL, bool aWrap = true );
469 
481  SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFound = NULL,
482  SCH_ITEM* aLastItem = NULL, bool aWrap = true );
483 
494  bool SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
495  bool aSetVisible );
496 
504  bool IsComplexHierarchy() const;
505 
516  bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
517  const wxString& aDestFileName ) const;
518 
527  SCH_SHEET* FindSheetByName( const wxString& aSheetName );
528 
535 
545  void BuildSheetList( SCH_SHEET* aSheet );
546 };
547 
548 #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.
Class 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_ITEM * FindPreviousItem(KICAD_T aType, SCH_SHEET_PATH **aSheetFound=NULL, SCH_ITEM *aLastItem=NULL, bool aWrap=true)
Function FindPreviousItem searches the entire schematic for the previous schematic item.
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...
SCH_ITEM * FindNextItem(KICAD_T aType, SCH_SHEET_PATH **aSheetFound=NULL, SCH_ITEM *aLastItem=NULL, bool aWrap=true)
Function FindNextItem searches the entire schematic for the next schematic object.
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)
SCH_ITEM * FirstDrawList() const
Get the last schematic item relative to the first sheet in the list.
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.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
SCH_SHEET_LIST(SCH_SHEET *aSheet=NULL)
Constructor build a flattened list of SCH_SHEET_PATH objects from aSheet.
Class SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierar...
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
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.
Class SCH_SHEET_PATH.
void BuildSheetList(SCH_SHEET *aSheet)
Function BuildSheetList builds the list of sheets and their sheet path from aSheet.
SCH_ITEM * FindPreviousItem(KICAD_T aType, SCH_ITEM *aLastItem=NULL, bool aWrap=false) const
Find the previous schematic item in this sheet path object.
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:209
SCH_ITEM * LastDrawList() const
Function LastDrawList.
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 ...
SCH_ITEM * FindNextItem(KICAD_T aType, SCH_ITEM *aLastItem=NULL, bool aWrap=false) const
Find the next schematic item in this sheet object.
int FindSheet(const wxString &aFileName) const
const SCH_SHEET * GetSheet(unsigned aIndex) const
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.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
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.
SCH_SCREEN * LastScreen() const
Function LastScreen.