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.

192 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 CERN
  5. * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
  6. * @author Jon Evans <jon@craftyjon.com>
  7. *
  8. * This program is free software: you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation, either version 3 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef KICAD_PROJECT_FILE_H
  22. #define KICAD_PROJECT_FILE_H
  23. #include <common.h> // needed for wxstring hash template
  24. #include <kiid.h>
  25. #include <project/board_project_settings.h>
  26. #include <settings/json_settings.h>
  27. #include <settings/nested_settings.h>
  28. class BOARD_DESIGN_SETTINGS;
  29. class ERC_SETTINGS;
  30. class NET_SETTINGS;
  31. class SCHEMATIC_SETTINGS;
  32. class TEMPLATES;
  33. /**
  34. * For files like sheets and boards, a pair of that object KIID and display name
  35. * Display name is typically blank for the project root sheet
  36. */
  37. typedef std::pair<KIID, wxString> FILE_INFO_PAIR;
  38. /**
  39. * For storing PcbNew MRU paths of various types
  40. */
  41. enum LAST_PATH_TYPE : unsigned int
  42. {
  43. LAST_PATH_NETLIST = 0,
  44. LAST_PATH_STEP,
  45. LAST_PATH_IDF,
  46. LAST_PATH_VRML,
  47. LAST_PATH_SPECCTRADSN,
  48. LAST_PATH_GENCAD,
  49. LAST_PATH_SIZE
  50. };
  51. /**
  52. * The backing store for a PROJECT, in JSON format.
  53. *
  54. * There is either zero or one PROJECT_FILE for every PROJECT
  55. * (you can have a dummy PROJECT that has no file)
  56. */
  57. class PROJECT_FILE : public JSON_SETTINGS
  58. {
  59. public:
  60. /**
  61. * Construct the project file for a project
  62. * @param aFullPath is the full disk path to the project
  63. */
  64. PROJECT_FILE( const wxString& aFullPath );
  65. virtual ~PROJECT_FILE() = default;
  66. virtual bool MigrateFromLegacy( wxConfigBase* aCfg ) override;
  67. bool SaveToFile( const wxString& aDirectory = "", bool aForce = false ) override;
  68. bool SaveAs( const wxString& aDirectory, const wxString& aFile );
  69. void SetProject( PROJECT* aProject )
  70. {
  71. m_project = aProject;
  72. }
  73. std::vector<FILE_INFO_PAIR>& GetSheets()
  74. {
  75. return m_sheets;
  76. }
  77. std::vector<FILE_INFO_PAIR>& GetBoards()
  78. {
  79. return m_boards;
  80. }
  81. std::shared_ptr<NET_SETTINGS>& NetSettings()
  82. {
  83. return m_NetSettings;
  84. }
  85. protected:
  86. wxString getFileExt() const override;
  87. wxString getLegacyFileExt() const override;
  88. /**
  89. * Below are project-level settings that have not been moved to a dedicated file
  90. */
  91. public:
  92. /**
  93. * Shared params, used by more than one application
  94. */
  95. /// The list of pinned symbol libraries
  96. std::vector<wxString> m_PinnedSymbolLibs;
  97. /// The list of pinned footprint libraries
  98. std::vector<wxString> m_PinnedFootprintLibs;
  99. std::map<wxString, wxString> m_TextVars;
  100. /**
  101. * Eeschema params
  102. */
  103. // Schematic ERC settings: lifecycle managed by SCHEMATIC
  104. ERC_SETTINGS* m_ErcSettings;
  105. // Schematic editing and misc settings: lifecycle managed by SCHEMATIC
  106. SCHEMATIC_SETTINGS* m_SchematicSettings;
  107. // Legacy parameters LibDir and LibName, for importing old projects
  108. wxString m_LegacyLibDir;
  109. wxArrayString m_LegacyLibNames;
  110. /**
  111. * CvPcb params
  112. */
  113. /// List of equivalence (equ) files used in the project
  114. std::vector<wxString> m_EquivalenceFiles;
  115. /**
  116. * PcbNew params
  117. */
  118. /// Drawing sheet file
  119. wxString m_BoardDrawingSheetFile;
  120. /// MRU path storage
  121. wxString m_PcbLastPath[LAST_PATH_SIZE];
  122. /**
  123. * Board design settings for this project's board. This will be initialized by PcbNew after
  124. * loading a board so that BOARD_DESIGN_SETTINGS doesn't need to live in common for now.
  125. * Owned by the BOARD; may be null if a board isn't loaded: be careful
  126. */
  127. BOARD_DESIGN_SETTINGS* m_BoardSettings;
  128. /**
  129. * Net settings for this project (owned here)
  130. *
  131. * @note If we go multi-board in the future, we have to decide whether to use a global
  132. * NET_SETTINGS or have one per board. Right now I think global makes more sense
  133. * (one set of schematics, one netlist partitioned into multiple boards)
  134. */
  135. std::shared_ptr<NET_SETTINGS> m_NetSettings;
  136. std::vector<LAYER_PRESET> m_LayerPresets; /// List of stored layer presets
  137. std::vector<VIEWPORT> m_Viewports; /// List of stored viewports (pos + zoom)
  138. std::vector<VIEWPORT3D> m_Viewports3D; /// List of stored 3D viewports (view matrixes)
  139. private:
  140. /// An list of schematic sheets in this project
  141. std::vector<FILE_INFO_PAIR> m_sheets;
  142. /// A list of board files in this project
  143. std::vector<FILE_INFO_PAIR> m_boards;
  144. /// A link to the owning PROJECT
  145. PROJECT* m_project;
  146. };
  147. // Specializations to allow directly reading/writing FILE_INFO_PAIRs from JSON
  148. void to_json( nlohmann::json& aJson, const FILE_INFO_PAIR& aPair );
  149. void from_json( const nlohmann::json& aJson, FILE_INFO_PAIR& aPair );
  150. #endif