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.

214 lines
6.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
  5. * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef _APP_SETTINGS_H
  21. #define _APP_SETTINGS_H
  22. #include <gal/color4d.h>
  23. #include <settings/json_settings.h>
  24. /**
  25. * Cross-probing behavior
  26. */
  27. struct CROSS_PROBING_SETTINGS
  28. {
  29. bool on_selection; ///< Synchronize the selection for multiple items too
  30. bool center_on_items; ///< Automatically pan to cross-probed items
  31. bool zoom_to_fit; ///< Zoom to fit items (ignored if center_on_items is off)
  32. bool auto_highlight; ///< Automatically turn on highlight mode in the target frame
  33. };
  34. /**
  35. * Common cursor settings, available to every frame
  36. */
  37. struct CURSOR_SETTINGS
  38. {
  39. bool always_show_cursor;
  40. bool fullscreen_cursor;
  41. };
  42. /**
  43. * Common grid settings, available to every frame
  44. */
  45. struct GRID_SETTINGS
  46. {
  47. bool axes_enabled;
  48. std::vector<wxString> sizes;
  49. wxString user_grid_x;
  50. wxString user_grid_y;
  51. int last_size_idx;
  52. int fast_grid_1;
  53. int fast_grid_2;
  54. double line_width;
  55. double min_spacing;
  56. bool show;
  57. int style;
  58. int snap;
  59. };
  60. /**
  61. * Stores the window positioning/state
  62. */
  63. struct WINDOW_STATE
  64. {
  65. bool maximized;
  66. int size_x;
  67. int size_y;
  68. int pos_x;
  69. int pos_y;
  70. unsigned int display;
  71. };
  72. /**
  73. * Stores the common settings that are saved and loaded for each window / frame
  74. */
  75. struct WINDOW_SETTINGS
  76. {
  77. WINDOW_STATE state;
  78. wxString mru_path;
  79. wxString perspective;
  80. std::vector<double> zoom_factors;
  81. CURSOR_SETTINGS cursor;
  82. GRID_SETTINGS grid;
  83. };
  84. /**
  85. * APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad
  86. * application. It stores settings that should exist for every app, but may be different from
  87. * app to app depending on the user's preferences.
  88. *
  89. * COMMON_SETTINGS stores settings that are always the same across all applications.
  90. */
  91. class APP_SETTINGS_BASE : public JSON_SETTINGS
  92. {
  93. public:
  94. struct FIND_REPLACE
  95. {
  96. int flags;
  97. wxString find_string;
  98. std::vector<wxString> find_history;
  99. wxString replace_string;
  100. std::vector<wxString> replace_history;
  101. };
  102. struct GRAPHICS
  103. {
  104. int canvas_type;
  105. float highlight_factor; ///< How much to brighten highlighted objects by
  106. float select_factor; ///< How much to brighten selected objects by
  107. };
  108. struct COLOR_PICKER
  109. {
  110. int default_tab;
  111. };
  112. struct LIB_TREE
  113. {
  114. int column_width;
  115. };
  116. struct PRINTING
  117. {
  118. bool background; ///< Whether or not to print background color
  119. bool monochrome; ///< Whether or not to print in monochrome
  120. double scale; ///< Printout scale
  121. bool use_theme; ///< If false, display color theme will be used
  122. wxString color_theme; ///< Color theme to use for printing
  123. bool title_block; ///< Whether or not to print title block
  124. std::vector<int> layers; ///< List of enabled layers for printing
  125. };
  126. struct SYSTEM
  127. {
  128. bool first_run_shown;
  129. int max_undo_items;
  130. std::vector<wxString> file_history;
  131. int units;
  132. int last_metric_units;
  133. int last_imperial_units;
  134. };
  135. APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaVersion );
  136. virtual ~APP_SETTINGS_BASE() {}
  137. virtual bool MigrateFromLegacy( wxConfigBase* aCfg ) override;
  138. /**
  139. * By default, this returns the list of grids available in PcbNew-based applications.
  140. * Eeschema does not allow customization of the grid. If it ever does, override this in
  141. * Eeschema settings to provide a different set of defaults.
  142. * @return a default value for the window.grid.sizes parameter
  143. */
  144. virtual const std::vector<wxString> DefaultGridSizeList() const;
  145. public:
  146. CROSS_PROBING_SETTINGS m_CrossProbing;
  147. FIND_REPLACE m_FindReplace;
  148. GRAPHICS m_Graphics;
  149. COLOR_PICKER m_ColorPicker;
  150. LIB_TREE m_LibTree;
  151. PRINTING m_Printing;
  152. SYSTEM m_System;
  153. WINDOW_SETTINGS m_Window;
  154. /// Active color theme name
  155. wxString m_ColorTheme;
  156. ///! Local schema version for common app settings
  157. int m_appSettingsSchemaVersion;
  158. protected:
  159. virtual std::string getLegacyFrameName() const { return std::string(); }
  160. ///! Migrates the find/replace history string lists
  161. void migrateFindReplace( wxConfigBase* aCfg );
  162. /**
  163. * Migrates legacy window settings into the JSON document
  164. * @param aCfg is the wxConfig object to read from
  165. * @param aFrameName is the prefix for window settings in the legacy config file
  166. * @param aJsonPath is the prefix for storing window settings in the JSON file
  167. * @return true if all settings were migrated
  168. */
  169. bool migrateWindowConfig( wxConfigBase* aCfg, const std::string& aFrameName,
  170. const std::string& aJsonPath );
  171. /**
  172. * Adds parameters for the given window object
  173. * @param aWindow is the target window settings object
  174. * @param aJsonPath is the path to read parameters from
  175. */
  176. void addParamsForWindow( WINDOW_SETTINGS* aWindow, const std::string& aJsonPath );
  177. };
  178. #endif