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 
36 #include <map>
37 
38 
82 class wxFindReplaceData;
83 class SCH_SHEET;
84 class SCH_SCREEN;
85 class SCH_MARKER;
86 class SCH_ITEM;
88 
89 
94 typedef std::map<wxString, SCH_REFERENCE_LIST> SCH_MULTI_UNIT_REFERENCE_MAP;
95 
110 {
111 protected:
112  std::vector< SCH_SHEET* > m_sheets;
113 
115 
117 
118 public:
119  SCH_SHEET_PATH();
120 
122  SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); }
123 
125  void clear()
126  {
127  m_sheets.clear();
128  Rehash();
129  }
130 
132  bool empty() const { return m_sheets.empty(); }
133 
135  void pop_back()
136  {
137  m_sheets.pop_back();
138  Rehash();
139  }
140 
142  void push_back( SCH_SHEET* aSheet )
143  {
144  m_sheets.push_back( aSheet );
145  Rehash();
146  }
147 
149  size_t size() const { return m_sheets.size(); }
150 
151  void Rehash();
152 
153  size_t GetCurrentHash() const { return m_current_hash; }
154 
155  void SetPageNumber( int aPageNumber ) { m_pageNumber = aPageNumber; }
156 
157  int GetPageNumber() const { return m_pageNumber; }
158 
159  const SCH_SHEET* GetSheet( unsigned aIndex ) const
160  {
161  SCH_SHEET* retv = NULL;
162 
163  if( aIndex < size() )
164  retv = at( aIndex );
165 
166  return const_cast< SCH_SHEET* >( retv );
167  }
168 
177  int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
178 
184  SCH_SHEET* Last() const;
185 
191 
192 
194  SCH_SCREEN* LastScreen() const;
195 
202  wxString PathAsString() const;
203 
208  KIID_PATH Path() const;
209 
217  wxString PathHumanReadable() const;
218 
223  static wxString GetRootPathName( bool aUseShortName = true );
224 
235 
246  void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
247  bool aForceIncludeOrphanComponents = false );
248 
259  bool aIncludePowerSymbols = true );
260 
271  bool SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
272  bool aSetVisible );
273 
285  bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName ) const;
286 
287  bool operator==( const SCH_SHEET_PATH& d1 ) const;
288 
289  bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
290 
291  bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
292 
293 };
294 
295 
296 namespace std
297 {
298  template<> struct hash<SCH_SHEET_PATH>
299  {
300  size_t operator()( const SCH_SHEET_PATH& path ) const;
301  };
302 }
303 
304 
305 typedef std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS;
306 typedef SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER;
307 
308 
320 {
321 private:
324 
325 public:
326 
333  SCH_SHEET_LIST( SCH_SHEET* aSheet = NULL );
334 
336 
342  bool IsModified();
343 
344  void ClearModifyStatus();
345 
349  SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut );
350 
359  void AnnotatePowerSymbols();
360 
372  void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
373  bool aForceIncludeOrphanComponents = false );
374 
385  bool aIncludePowerSymbols = true );
386 
397  bool SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
398  bool aSetVisible );
399 
407  bool IsComplexHierarchy() const;
408 
419  bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
420  const wxString& aDestFileName ) const;
421 
428 
438  void BuildSheetList( SCH_SHEET* aSheet );
439 
440  bool NameExists( const wxString& aSheetName );
441 };
442 
443 #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_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.
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
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.
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.
Definition: common.h:65
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
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_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...
bool NameExists(const wxString &aSheetName)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:215
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 * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut)
Fetch a SCH_ITEM by ID.
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.
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:147
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.