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.

184 lines
5.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef KICAD_SCHEMATIC_H
  20. #define KICAD_SCHEMATIC_H
  21. #include <eda_item.h>
  22. #include <sch_sheet_path.h>
  23. #include <schematic_settings.h>
  24. class BUS_ALIAS;
  25. class CONNECTION_GRAPH;
  26. class EDA_BASE_FRAME;
  27. class ERC_SETTINGS;
  28. class PROJECT;
  29. class SCH_SCREEN;
  30. class SCH_SHEET;
  31. class SCH_SHEET_LIST;
  32. /**
  33. * Holds all the data relating to one schematic
  34. * A schematic may consist of one or more sheets (and one root sheet)
  35. * Right now, eeschema can have only one schematic open at a time, but this could change.
  36. * Please keep this possibility in mind when adding to this object.
  37. */
  38. class SCHEMATIC : public EDA_ITEM
  39. {
  40. friend class SCH_EDIT_FRAME;
  41. private:
  42. PROJECT* m_project;
  43. /// The top-level sheet in this schematic hierarchy (or potentially the only one)
  44. SCH_SHEET* m_rootSheet;
  45. /**
  46. * The sheet path of the sheet currently being edited or displayed.
  47. * Note that this was moved here from SCH_EDIT_FRAME because currently many places in the code
  48. * want to know the current sheet. Potentially this can be moved back to the UI code once
  49. * the only places that want to know it are UI-related
  50. */
  51. SCH_SHEET_PATH* m_currentSheet;
  52. /// Holds and calculates connectivity information of this schematic
  53. CONNECTION_GRAPH* m_connectionGraph;
  54. /**
  55. * Holds a map of labels to the page numbers that they appear on. Used to update global
  56. * label intersheet references.
  57. */
  58. std::map<wxString, std::set<wxString>> m_labelToPageRefsMap;
  59. public:
  60. SCHEMATIC( PROJECT* aPrj );
  61. ~SCHEMATIC();
  62. virtual wxString GetClass() const override
  63. {
  64. return wxT( "SCHEMATIC" );
  65. }
  66. /// Initializes this schematic to a blank one, unloading anything existing
  67. void Reset();
  68. /// Return a reference to the project this schematic is part of
  69. PROJECT& Prj() const
  70. {
  71. return *const_cast<PROJECT*>( m_project );
  72. }
  73. void SetProject( PROJECT* aPrj );
  74. /**
  75. * Builds and returns an updated schematic hierarchy
  76. * TODO: can this be cached?
  77. * @return a SCH_SHEET_LIST containing the schematic hierarchy
  78. */
  79. SCH_SHEET_LIST GetSheets() const
  80. {
  81. return SCH_SHEET_LIST( m_rootSheet );
  82. }
  83. SCH_SHEET& Root() const
  84. {
  85. return *m_rootSheet;
  86. }
  87. /**
  88. * Initializes the schematic with a new root sheet.
  89. * This is typically done by calling a file loader that returns the new root sheet
  90. * As a side-effect, takes care of some post-load initialization.
  91. * @param aRootSheet is the new root sheet for this schematic.
  92. */
  93. void SetRoot( SCH_SHEET* aRootSheet );
  94. /// A simple test if the schematic is loaded, not a complete one
  95. bool IsValid() const
  96. {
  97. return m_rootSheet != nullptr;
  98. }
  99. /// Helper to retreive the screen of the root sheet
  100. SCH_SCREEN* RootScreen() const;
  101. /// Helper to retrieve the filename from the root sheet screen
  102. wxString GetFileName() const;
  103. SCH_SHEET_PATH& CurrentSheet() const
  104. {
  105. return *m_currentSheet;
  106. }
  107. void SetCurrentSheet( const SCH_SHEET_PATH& aPath )
  108. {
  109. *m_currentSheet = aPath;
  110. }
  111. CONNECTION_GRAPH* ConnectionGraph() const
  112. {
  113. return m_connectionGraph;
  114. }
  115. SCHEMATIC_SETTINGS& Settings() const;
  116. ERC_SETTINGS& ErcSettings() const;
  117. std::vector<SCH_MARKER*> ResolveERCExclusions();
  118. /**
  119. * Returns a pointer to a bus alias object for the given label, or null if one
  120. * doesn't exist.
  121. */
  122. std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aLabel ) const;
  123. /**
  124. * Returns a list of name candidates for netclass assignment. The list will include both
  125. * composite names (buses) and atomic net names. Names are fetched from available labels,
  126. * power pins, etc.
  127. */
  128. std::vector<wxString> GetNetClassAssignmentCandidates();
  129. /**
  130. * Resolves text vars that refer to other items.
  131. * Note that the actual resolve is delegated to the symbol/sheet in question. This routine
  132. * just does the look-up and delegation.
  133. */
  134. bool ResolveCrossReference( wxString* token, int aDepth ) const;
  135. std::map<wxString, std::set<wxString>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
  136. wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
  137. wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
  138. /**
  139. * Return the full schematic flattened hiearchical sheet list.
  140. */
  141. SCH_SHEET_LIST& GetFullHierarchy() const;
  142. #if defined(DEBUG)
  143. void Show( int nestLevel, std::ostream& os ) const override {}
  144. #endif
  145. };
  146. #endif