You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

699 lines
26 KiB

6 years ago
  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-2023 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. /**
  26. * @file sch_sheet_path.h
  27. * Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
  28. */
  29. #ifndef CLASS_DRAWSHEET_PATH_H
  30. #define CLASS_DRAWSHEET_PATH_H
  31. #include <map>
  32. #include <optional>
  33. #include <kiid.h>
  34. #include <wx/string.h>
  35. /**
  36. * A simple container for schematic symbol instance information.
  37. */
  38. struct SCH_SYMBOL_INSTANCE
  39. {
  40. KIID_PATH m_Path;
  41. // Things that can be annotated:
  42. wxString m_Reference;
  43. int m_Unit = 1;
  44. // Do not use. This is left over from the dubious decision to instantiate symbol value
  45. // and footprint fields.
  46. wxString m_Value;
  47. wxString m_Footprint;
  48. // The project name associated with this instance.
  49. wxString m_ProjectName;
  50. };
  51. /**
  52. * A simple container for sheet instance information.
  53. */
  54. struct SCH_SHEET_INSTANCE
  55. {
  56. KIID_PATH m_Path;
  57. wxString m_PageNumber;
  58. // The project name associated with this instance.
  59. wxString m_ProjectName;
  60. };
  61. /**
  62. * Complex hierarchies
  63. *
  64. * A hierarchical schematic uses sheets (hierarchical sheets) included in a given sheet.
  65. * Each sheet corresponds to a schematic drawing handled by a SCH_SCREEN structure. A
  66. * SCH_SCREEN structure contains drawings, and have a filename to write its data. Also a
  67. * SCH_SCREEN displays a sheet number and the name of the sheet.
  68. *
  69. * In simple (and flat) hierarchies a sheet is linked to a SCH_SCREEN, and a SCH_SCREEN is
  70. * used by the single hierarchical sheet.
  71. *
  72. * In complex hierarchies the same SCH_SCREEN (and its data) is shared by more than one sheet.
  73. * Therefore subsheets (like subsheets in a SCH_SCREEN shared by many sheets) can also be
  74. * shared. So the same SCH_SCREEN must handle different symbol references and unit selections
  75. * depending on which sheet is currently selected, and how a given subsheet is selected. Two
  76. * sheets share the same SCH_SCREEN (the same drawings) if they have the same filename.
  77. *
  78. * In KiCad each symbol and sheet receives (when created) a uuid. So each sheet has 2 id: its
  79. * uuid (which cannot change) and its name (that can be edited and therefore is not reliable
  80. * for strong identification).
  81. * A given sheet in a hierarchy is fully labeled by its path (or sheet path) that is the list
  82. * of uuids found to access it through the hierarchy. The root sheet is /. All other sheets
  83. * have a path like /1234ABCD or /4567FEDC/AA2233DD/. This path can be displayed as human
  84. * readable sheet name like: / or /sheet1/include_sheet/ or /sheet2/include_sheet/
  85. *
  86. * So to know for a given SCH_SCREEN (a given schematic drawings) we must:
  87. * 1) Handle all references possibilities.
  88. * 2) When acceded by a given selected sheet, display (update) the
  89. * corresponding references and sheet path
  90. *
  91. * The class SCH_SHEET_PATH handles paths used to access a sheet. The class SCH_SHEET_LIST
  92. * allows one to handle the full (or partial) list of sheets and their paths in a complex
  93. * hierarchy. The class EDA_ScreenList allows one to handle the list of SCH_SCREEN. It is
  94. * useful to clear or save data, but is not suitable to handle the full complex hierarchy
  95. * possibilities (usable in flat and simple hierarchies).
  96. */
  97. class EDA_ITEM;
  98. class SCH_SHEET;
  99. class SCH_SCREEN;
  100. class SCH_MARKER;
  101. class SCH_ITEM;
  102. class SCH_SYMBOL;
  103. class SCH_REFERENCE_LIST;
  104. /**
  105. * Container to map reference designators for multi-unit parts.
  106. */
  107. typedef std::map<wxString, SCH_REFERENCE_LIST> SCH_MULTI_UNIT_REFERENCE_MAP;
  108. /**
  109. * Handle access to a stack of flattened #SCH_SHEET objects by way of a path for
  110. * creating a flattened schematic hierarchy.
  111. *
  112. * The #SCH_SHEET objects are stored in a list from first (usually the root sheet) to a
  113. * given sheet in last position. The _last_ sheet is usually the sheet we want to select
  114. * or reach (which is what the function Last() returns). Others sheets constitute the
  115. * "path" from the first to the last sheet.
  116. */
  117. class SCH_SHEET_PATH
  118. {
  119. public:
  120. SCH_SHEET_PATH();
  121. SCH_SHEET_PATH( const SCH_SHEET_PATH& aOther );
  122. SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& aOther );
  123. SCH_SHEET_PATH operator+( const SCH_SHEET_PATH& aOther );
  124. ~SCH_SHEET_PATH() = default;
  125. /// Forwarded method from std::vector
  126. SCH_SHEET* at( size_t aIndex ) const { return m_sheets.at( aIndex ); }
  127. /// Forwarded method from std::vector
  128. void clear()
  129. {
  130. m_sheets.clear();
  131. Rehash();
  132. }
  133. /// Forwarded method from std::vector
  134. bool empty() const { return m_sheets.empty(); }
  135. /// Forwarded method from std::vector
  136. void pop_back()
  137. {
  138. m_sheets.pop_back();
  139. Rehash();
  140. }
  141. /// Forwarded method from std::vector
  142. void push_back( SCH_SHEET* aSheet )
  143. {
  144. m_sheets.push_back( aSheet );
  145. Rehash();
  146. }
  147. /// Forwarded method from std::vector
  148. size_t size() const { return m_sheets.size(); }
  149. std::vector<SCH_SHEET*>::iterator erase( std::vector<SCH_SHEET*>::const_iterator aPosition )
  150. {
  151. return m_sheets.erase( aPosition );
  152. }
  153. void Rehash();
  154. size_t GetCurrentHash() const { return m_current_hash; }
  155. /**
  156. * Set the sheet instance virtual page number.
  157. *
  158. * Virtual page numbers are incremental integers set automatically when the sheet path
  159. * hierarchy is created (@see #SCH_SHEET_LIST::BuildSheetList). The virtual page
  160. * numbering is ordered by the X and Y position of the sheet in a schematic which
  161. * mimics the page numbering code prior to the addition of actual user definable page
  162. * numbers. Virtual page numbers should only be use when annotating schematics.
  163. */
  164. void SetVirtualPageNumber( int aPageNumber ) { m_virtualPageNumber = aPageNumber; }
  165. int GetVirtualPageNumber() const { return m_virtualPageNumber; }
  166. /**
  167. * Set the sheet instance user definable page number.
  168. *
  169. * @note User definable page numbers can be any string devoid of white space characters.
  170. */
  171. void SetPageNumber( const wxString& aPageNumber );
  172. wxString GetPageNumber() const;
  173. const SCH_SHEET* GetSheet( unsigned aIndex ) const
  174. {
  175. SCH_SHEET* retv = nullptr;
  176. if( aIndex < size() )
  177. retv = at( aIndex );
  178. return retv;
  179. }
  180. bool IsFullPath() const;
  181. /**
  182. * Compare if this is the same sheet path as \a aSheetPathToTest.
  183. *
  184. * @param aSheetPathToTest is the sheet path to compare.
  185. * @return 1 if this sheet path has more sheets than aSheetPathToTest,
  186. * -1 if this sheet path has fewer sheets than aSheetPathToTest,
  187. * or 0 if same
  188. */
  189. int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
  190. void CachePageNumber() const { m_cached_page_number = GetPageNumber(); }
  191. wxString GetCachedPageNumber() const { return m_cached_page_number; }
  192. /**
  193. * Compare sheets by their page number. If the actual page number is equal, use virtual page
  194. * numbers to compare.
  195. *
  196. * @return -1 if aSheetPathToTest is greater than this (should appear later in the sort order)
  197. * 0 if aSheetPathToTest is equal to this
  198. * 1 if aSheetPathToTest is less than this (should appear earlier in the sort order)
  199. */
  200. int ComparePageNum( const SCH_SHEET_PATH& aSheetPathToTest ) const;
  201. /**
  202. * Check if this path is contained inside aSheetPathToTest.
  203. *
  204. * @param aSheetPathToTest is the sheet path to compare against.
  205. * @return true if this path is contained inside or equal to aSheetPathToTest.
  206. */
  207. bool IsContainedWithin( const SCH_SHEET_PATH& aSheetPathToTest ) const;
  208. /**
  209. * Return a pointer to the last #SCH_SHEET of the list.
  210. *
  211. * One can see the others sheet as the "path" to reach this last sheet.
  212. */
  213. SCH_SHEET* Last() const;
  214. /**
  215. * @return the #SCH_SCREEN relative to the last sheet in list.
  216. */
  217. SCH_SCREEN* LastScreen();
  218. ///< @copydoc SCH_SHEET_PATH::LastScreen()
  219. SCH_SCREEN* LastScreen() const;
  220. bool GetExcludedFromSim() const;
  221. bool GetExcludedFromBOM() const;
  222. bool GetExcludedFromBoard() const;
  223. bool GetDNP() const;
  224. /**
  225. * Fetch a SCH_ITEM by ID.
  226. */
  227. SCH_ITEM* GetItem( const KIID& aID ) const;
  228. /**
  229. * Return the path of time stamps which do not changes even when editing sheet parameters.
  230. *
  231. * A path is something like / (root) or /34005677 or /34005677/00AE4523.
  232. */
  233. wxString PathAsString() const;
  234. /**
  235. * Get the sheet path as an #KIID_PATH.
  236. *
  237. * @note This #KIID_PATH includes the root sheet UUID prefixed to the path.
  238. */
  239. KIID_PATH Path() const;
  240. /**
  241. * Return the sheet path in a human readable form made from the sheet names.
  242. *
  243. * The "normal" path instead uses the #KIID objects in the path that do not change
  244. * even when editing sheet parameters.
  245. */
  246. wxString PathHumanReadable( bool aUseShortRootName = true,
  247. bool aStripTrailingSeparator = false ) const;
  248. /**
  249. * Update all the symbol references for this sheet path.
  250. *
  251. * Mandatory in complex hierarchies because sheets may use the same screen (basic schematic)
  252. * more than once but with different references and units according to the displayed sheet.
  253. */
  254. void UpdateAllScreenReferences() const;
  255. /**
  256. * Append a #SCH_REFERENCE object to \a aReferences based on \a aSymbol
  257. *
  258. * @param aReferences List of references to populate.
  259. * @param aSymbol A symbol to add to aReferences
  260. * @param aIncludePowerSymbols set to false to only get normal symbols.
  261. * @param aForceIncludeOrphanSymbols set to true to include symbols having no symbol found
  262. * in lib. The normal option is false, and set to true
  263. * only to build the full list of symbols.
  264. */
  265. void AppendSymbol( SCH_REFERENCE_LIST& aReferences, SCH_SYMBOL* aSymbol,
  266. bool aIncludePowerSymbols = true,
  267. bool aForceIncludeOrphanSymbols = false ) const;
  268. /**
  269. * Adds #SCH_REFERENCE object to \a aReferences for each symbol in the sheet.
  270. *
  271. * @param aReferences List of references to populate.
  272. * @param aIncludePowerSymbols set to false to only get normal symbols.
  273. * @param aForceIncludeOrphanSymbols set to true to include symbols having no symbol found
  274. * in lib. The normal option is false, and set to true
  275. * only to build the full list of symbols.
  276. */
  277. void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
  278. bool aForceIncludeOrphanSymbols = false ) const;
  279. /**
  280. * Append a #SCH_REFERENCE_LIST object to \a aRefList based on \a aSymbol,
  281. * storing same-reference set of multi-unit parts together.
  282. *
  283. * The map key for each element will be the reference designator.
  284. *
  285. * @param aRefList Map of reference designators to reference lists
  286. * @param aSymbol A symbol to add to aRefList
  287. * @param aIncludePowerSymbols Set to false to only get normal symbols.
  288. */
  289. void AppendMultiUnitSymbol( SCH_MULTI_UNIT_REFERENCE_MAP& aRefList, SCH_SYMBOL* aSymbol,
  290. bool aIncludePowerSymbols = true ) const;
  291. /**
  292. * Add a #SCH_REFERENCE_LIST object to \a aRefList for each same-reference set of
  293. * multi-unit parts in the sheet.
  294. *
  295. * The map key for each element will be the reference designator.
  296. *
  297. * @param aRefList Map of reference designators to reference lists
  298. * @param aIncludePowerSymbols Set to false to only get normal symbols.
  299. */
  300. void GetMultiUnitSymbols( SCH_MULTI_UNIT_REFERENCE_MAP &aRefList,
  301. bool aIncludePowerSymbols = true ) const;
  302. /**
  303. * Test the SCH_SHEET_PATH file names to check adding the sheet stored in the file
  304. * \a aSrcFileName to the sheet stored in file \a aDestFileName will cause a sheet
  305. * path recursion.
  306. *
  307. * @param aSrcFileName is the source file name of the sheet add to \a aDestFileName.
  308. * @param aDestFileName is the file name of the destination sheet for \a aSrcFileName.
  309. * @return true if \a aFileName will cause recursion in the sheet path. Otherwise false.
  310. */
  311. bool TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName );
  312. /**
  313. * Make the sheet file name relative to its parent sheet.
  314. *
  315. * This should only be called when changing the parent sheet path such performing a save
  316. * as or a new schematic without a project in stand alone mode. The sheet file name is
  317. * only made relative if the current file name is relative. Absolute sheet file name paths
  318. * are a user choice so do not change them.
  319. *
  320. * Sheet file name paths are set according to the following criteria:
  321. * - If the sheet file name path is in the same as the parent sheet file name path, set
  322. * the sheet file name to just the file name and extension with no path.
  323. * - If the sheet file name path can be made relative to the parent sheet file name path,
  324. * set the sheet file name using the relative path.
  325. * - If the sheet file name path cannot be converted to a relative path, then fall back to
  326. * the absolute file name path.
  327. */
  328. void MakeFilePathRelativeToParentSheet();
  329. /**
  330. * Attempt to add new symbol instances for all symbols in this sheet path prefixed
  331. * with \a aPrefixSheetPath.
  332. *
  333. * The new symbol instance data will be assigned by the following criteria:
  334. * - If the instance data can be found for this sheet path, use the instance data.
  335. * - If the instance data cannot be found for this sheet path and the instance data cache
  336. * for the symbol is not empty, use the first instance data in the cache.
  337. * - If the cache is empty and the library symbol link is valid, set the instance data
  338. * from the library symbol.
  339. * - If all else fails, set the reference to "U?", the unit to 1, and everything else to
  340. * an empty string.
  341. *
  342. * @param aPrefixSheetPath is the sheet path to prefix to this sheet path for the new symbol
  343. * instance.
  344. * @param aProjectName is the name of the project for the new symbol instance data.
  345. */
  346. void AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
  347. const wxString& aProjectName );
  348. void RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath );
  349. bool operator==( const SCH_SHEET_PATH& d1 ) const;
  350. bool operator!=( const SCH_SHEET_PATH& d1 ) const { return !( *this == d1 ) ; }
  351. bool operator<( const SCH_SHEET_PATH& d1 ) const { return m_sheets < d1.m_sheets; }
  352. private:
  353. void initFromOther( const SCH_SHEET_PATH& aOther );
  354. protected:
  355. std::vector<SCH_SHEET*> m_sheets;
  356. size_t m_current_hash;
  357. mutable wxString m_cached_page_number;
  358. int m_virtualPageNumber; /// Page numbers are maintained by the sheet load order.
  359. std::map<std::pair<wxString, wxString>, bool> m_recursion_test_cache;
  360. };
  361. namespace std
  362. {
  363. template<> struct hash<SCH_SHEET_PATH>
  364. {
  365. size_t operator()( const SCH_SHEET_PATH& path ) const;
  366. };
  367. }
  368. struct SHEET_PATH_HASH
  369. {
  370. size_t operator()( const SCH_SHEET_PATH& path ) const
  371. {
  372. return path.GetCurrentHash();
  373. }
  374. };
  375. struct SHEET_PATH_CMP
  376. {
  377. bool operator()( const SCH_SHEET_PATH& lhs, const SCH_SHEET_PATH& rhs ) const
  378. {
  379. return lhs.GetCurrentHash() < rhs.GetCurrentHash();
  380. }
  381. };
  382. /**
  383. * A container for handling #SCH_SHEET_PATH objects in a flattened hierarchy.
  384. *
  385. * #SCH_SHEET objects are not unique, there can be many sheets with the same filename and
  386. * that share the same #SCH_SCREEN reference. Each The schematic file (#SCH_SCREEN) may
  387. * be shared between these sheets and symbol references are specific to a sheet path.
  388. * When a sheet is entered, symbol references and sheet page number are updated.
  389. */
  390. class SCH_SHEET_LIST : public std::vector<SCH_SHEET_PATH>
  391. {
  392. public:
  393. /**
  394. * Construct a flattened list of SCH_SHEET_PATH objects from \a aSheet.
  395. *
  396. * If aSheet == NULL, then this is an empty hierarchy which the user can populate.
  397. */
  398. SCH_SHEET_LIST( SCH_SHEET* aSheet = nullptr );
  399. ~SCH_SHEET_LIST() {}
  400. /**
  401. * Check the entire hierarchy for any modifications.
  402. *
  403. * @return True if the hierarchy is modified otherwise false.
  404. */
  405. bool IsModified() const;
  406. void ClearModifyStatus();
  407. /**
  408. * Fetch a SCH_ITEM by ID. Also returns the sheet the item was found on in \a aPathOut.
  409. */
  410. SCH_ITEM* GetItem( const KIID& aID, SCH_SHEET_PATH* aPathOut = nullptr ) const;
  411. /**
  412. * Fill an item cache for temporary use when many items need to be fetched.
  413. */
  414. void FillItemMap( std::map<KIID, EDA_ITEM*>& aMap );
  415. /**
  416. * Silently annotate the not yet annotated power symbols of the entire hierarchy of the
  417. * sheet path list.
  418. *
  419. * It is called before creating a netlist, to annotate power symbols, without prompting
  420. * the user about not annotated or duplicate for these symbols, if only these symbols
  421. * need annotation ( a very frequent case ).
  422. */
  423. void AnnotatePowerSymbols();
  424. /**
  425. * Add a #SCH_REFERENCE object to \a aReferences for each symbol in the list of sheets.
  426. *
  427. * @param aReferences List of references to populate.
  428. * @param aIncludePowerSymbols Set to false to only get normal symbols.
  429. * @param aForceIncludeOrphanSymbols Set to true to include symbols having no symbol found
  430. * in lib. The normal option is false, and set to true
  431. * only to build the full list of symbols.
  432. */
  433. void GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
  434. bool aForceIncludeOrphanSymbols = false ) const;
  435. /**
  436. * Add a #SCH_REFERENCE object to \a aReferences for each symbol in the list of sheets that are
  437. * contained within \a aSheetPath as well as recursively downwards inside aSheetPath.
  438. *
  439. * @param aReferences List of references to populate.
  440. * @param aSheetPath Path to return symbols from
  441. * @param aIncludePowerSymbols Set to false to only get normal symbols.
  442. * @param aForceIncludeOrphanSymbols Set to true to include symbols having no symbol found
  443. * in lib. The normal option is false, and set to true
  444. * only to build the full list of symbols.
  445. */
  446. void GetSymbolsWithinPath( SCH_REFERENCE_LIST& aReferences, const SCH_SHEET_PATH& aSheetPath,
  447. bool aIncludePowerSymbols = true,
  448. bool aForceIncludeOrphanSymbols = false ) const;
  449. /**
  450. * Add a #SCH_SHEET_PATH object to \a aSheets for each sheet in the list that are
  451. * contained within \a aSheetPath as well as recursively downwards inside aSheetPath.
  452. *
  453. * @param aReferences List of sheets to populate.
  454. * @param aSheetPath Path to return sheets from
  455. */
  456. void GetSheetsWithinPath( std::vector<SCH_SHEET_PATH>& aSheets,
  457. const SCH_SHEET_PATH& aSheetPath ) const;
  458. /**
  459. * Finds a SCH_SHEET_PATH that matches the provided KIID_PATH.
  460. *
  461. * @param aPath The KIID_PATH to search for.
  462. */
  463. std::optional<SCH_SHEET_PATH> GetSheetPathByKIIDPath( const KIID_PATH& aPath,
  464. bool aIncludeLastSheet = true ) const;
  465. /**
  466. * Add a #SCH_REFERENCE_LIST object to \a aRefList for each same-reference set of
  467. * multi-unit parts in the list of sheets. The map key for each element will be the
  468. * reference designator.
  469. *
  470. * @param aRefList Map of reference designators to reference lists
  471. * @param aIncludePowerSymbols Set to false to only get normal symbols.
  472. */
  473. void GetMultiUnitSymbols( SCH_MULTI_UNIT_REFERENCE_MAP &aRefList,
  474. bool aIncludePowerSymbols = true ) const;
  475. /**
  476. * Test every #SCH_SHEET_PATH in this #SCH_SHEET_LIST to verify if adding the sheets stored
  477. * in \a aSrcSheetHierarchy to the sheet stored in \a aDestFileName will cause recursion.
  478. *
  479. * @param aSrcSheetHierarchy is the SCH_SHEET_LIST of the source sheet add to \a aDestFileName.
  480. * @param aDestFileName is the file name of the destination sheet for \a aSrcFileName.
  481. * @return true if \a aFileName will cause recursion in the sheet path. Otherwise false.
  482. */
  483. bool TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
  484. const wxString& aDestFileName );
  485. /**
  486. * Return a pointer to the first #SCH_SHEET_PATH object (not necessarily the only one)
  487. * matching the provided path. Returns nullptr if not found.
  488. */
  489. SCH_SHEET_PATH* FindSheetForPath( const SCH_SHEET_PATH* aPath );
  490. /**
  491. * Return the first #SCH_SHEET_PATH object (not necessarily the only one) using a particular
  492. * screen.
  493. */
  494. SCH_SHEET_PATH FindSheetForScreen( const SCH_SCREEN* aScreen );
  495. /**
  496. * Return a #SCH_SHEET_LIST with a copy of all the #SCH_SHEET_PATH using a particular screen.
  497. */
  498. SCH_SHEET_LIST FindAllSheetsForScreen( const SCH_SCREEN* aScreen ) const;
  499. /**
  500. * Build the list of sheets and their sheet path from \a aSheet.
  501. *
  502. * If \a aSheet is the root sheet, the full sheet path and sheet list are built.
  503. *
  504. * The list will be ordered as per #SCH_SCREEN::BuildSheetList which results in sheets being ordered
  505. * in the legacy way of using the X and Y positions of the sheets.
  506. *
  507. * @see #SortByPageNumbers to sort by page numbers
  508. *
  509. * @param aSheet is the starting sheet from which the list is built, or NULL
  510. * indicating that g_RootSheet should be used.
  511. * @throw std::bad_alloc if the memory for the sheet path list could not be allocated.
  512. */
  513. void BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity );
  514. /**
  515. * Sort the list of sheets by page number. This should be called after #BuildSheetList
  516. *
  517. * If page numbers happen to be equal, then it compares the sheet names to ensure deterministic
  518. * ordering.
  519. *
  520. * @param aUpdateVirtualPageNums If true, updates the virtual page numbers to match the new
  521. * ordering
  522. */
  523. void SortByPageNumbers( bool aUpdateVirtualPageNums = true );
  524. bool NameExists( const wxString& aSheetName ) const;
  525. bool PageNumberExists( const wxString& aPageNumber ) const;
  526. /**
  527. * Truncates the list by removing sheet's with page numbers not in the given list
  528. *
  529. * @param aPageInclusions List of Page Numbers (non-virtual) to keep
  530. */
  531. void TrimToPageNumbers( const std::vector<wxString>& aPageInclusions );
  532. /**
  533. * Update all of the symbol instance information using \a aSymbolInstances.
  534. * WARNING: Do not call this on anything other than the full hierarchy.
  535. * @param aSymbolInstances is the symbol path information loaded from the root schematic.
  536. */
  537. void UpdateSymbolInstanceData( const std::vector<SCH_SYMBOL_INSTANCE>& aSymbolInstances );
  538. /**
  539. * Update all of the sheet instance information using \a aSheetInstances.
  540. *
  541. * @warning Do not call this on anything other than the full hierarchy.
  542. *
  543. * @param aSymbolInstances is the symbol path information loaded from the root schematic.
  544. */
  545. void UpdateSheetInstanceData( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances );
  546. std::vector<KIID_PATH> GetPaths() const;
  547. /**
  548. * Fetch the instance information for all of the sheets in the hiearchy.
  549. *
  550. * @return all of the sheet instance data for the hierarchy.
  551. */
  552. std::vector<SCH_SHEET_INSTANCE> GetSheetInstances() const;
  553. /**
  554. * Check all of the sheet instance for empty page numbers.
  555. *
  556. * @note This should only return true when loading a legacy schematic or an s-expression
  557. * schematic before version 20201005.
  558. *
  559. * @return true if all sheet instance page numbers are not defined. Otherwise false.
  560. */
  561. bool AllSheetPageNumbersEmpty() const;
  562. /**
  563. * Set initial sheet page numbers.
  564. *
  565. * The number scheme is base on the old pseudo sheet numbering algorithm prior to
  566. * the implementation of user definable sheet page numbers.
  567. */
  568. void SetInitialPageNumbers();
  569. /**
  570. * Attempt to add new symbol instances for all symbols in this list of sheet paths prefixed
  571. * with \a aPrefixSheetPath.
  572. *
  573. * @param aPrefixSheetPath is the sheet path to append the new symbol instances to.
  574. * @param aProjectName is the name of the project for the new symbol instance data.
  575. */
  576. void AddNewSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
  577. const wxString& aProjectName );
  578. void AddNewSheetInstances( const SCH_SHEET_PATH& aPrefixSheetPath,
  579. int aLastVirtualPageNumber );
  580. int GetLastVirtualPageNumber() const;
  581. void RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath );
  582. bool HasPath( const KIID_PATH& aPath ) const;
  583. bool ContainsSheet( const SCH_SHEET* aSheet ) const;
  584. private:
  585. SCH_SHEET_PATH m_currentSheetPath;
  586. };
  587. #endif // CLASS_DRAWSHEET_PATH_H