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.

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