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.

206 lines
5.6 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 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 center_on_items; ///< Automatically pan to cross-probed items
  30. bool zoom_to_fit; ///< Zoom to fit items (ignored if center_on_items is off)
  31. bool auto_highlight; ///< Automatically turn on highlight mode in the target frame
  32. };
  33. /**
  34. * Common cursor settings, available to every frame
  35. */
  36. struct CURSOR_SETTINGS
  37. {
  38. bool always_show_cursor;
  39. bool fullscreen_cursor;
  40. };
  41. /**
  42. * Common grid settings, available to every frame
  43. */
  44. struct GRID_SETTINGS
  45. {
  46. bool axes_enabled;
  47. std::vector<wxString> sizes;
  48. wxString user_grid_x;
  49. wxString user_grid_y;
  50. int last_size_idx;
  51. int fast_grid_1;
  52. int fast_grid_2;
  53. double line_width;
  54. double min_spacing;
  55. bool show;
  56. int style;
  57. int snap;
  58. };
  59. /**
  60. * Stores the window positioning/state
  61. */
  62. struct WINDOW_STATE
  63. {
  64. bool maximized;
  65. int size_x;
  66. int size_y;
  67. int pos_x;
  68. int pos_y;
  69. unsigned int display;
  70. };
  71. /**
  72. * Stores the common settings that are saved and loaded for each window / frame
  73. */
  74. struct WINDOW_SETTINGS
  75. {
  76. WINDOW_STATE state;
  77. wxString mru_path;
  78. wxString perspective;
  79. std::vector<double> zoom_factors;
  80. CURSOR_SETTINGS cursor;
  81. GRID_SETTINGS grid;
  82. };
  83. /**
  84. * APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad
  85. * application. It stores settings that should exist for every app, but may be different from
  86. * app to app depending on the user's preferences.
  87. *
  88. * COMMON_SETTINGS stores settings that are always the same across all applications.
  89. */
  90. class APP_SETTINGS_BASE : public JSON_SETTINGS
  91. {
  92. public:
  93. struct FIND_REPLACE
  94. {
  95. int flags;
  96. wxString find_string;
  97. std::vector<wxString> find_history;
  98. wxString replace_string;
  99. std::vector<wxString> replace_history;
  100. };
  101. struct GRAPHICS
  102. {
  103. int canvas_type;
  104. float highlight_factor; ///< How much to brighten highlighted objects by
  105. float select_factor; ///< How much to brighten selected objects by
  106. float high_contrast_factor; ///< How much to darken inactive layers 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. public:
  139. CROSS_PROBING_SETTINGS m_CrossProbing;
  140. FIND_REPLACE m_FindReplace;
  141. GRAPHICS m_Graphics;
  142. COLOR_PICKER m_ColorPicker;
  143. LIB_TREE m_LibTree;
  144. PRINTING m_Printing;
  145. SYSTEM m_System;
  146. WINDOW_SETTINGS m_Window;
  147. /// Active color theme name
  148. wxString m_ColorTheme;
  149. ///! Local schema version for common app settings
  150. int m_appSettingsSchemaVersion;
  151. protected:
  152. virtual std::string getLegacyFrameName() const { return std::string(); }
  153. ///! Migrates the find/replace history string lists
  154. void migrateFindReplace( wxConfigBase* aCfg );
  155. /**
  156. * Migrates legacy window settings into the JSON document
  157. * @param aCfg is the wxConfig object to read from
  158. * @param aFrameName is the prefix for window settings in the legacy config file
  159. * @param aJsonPath is the prefix for storing window settings in the JSON file
  160. * @return true if all settings were migrated
  161. */
  162. bool migrateWindowConfig( wxConfigBase* aCfg, const std::string& aFrameName,
  163. const std::string& aJsonPath );
  164. /**
  165. * Adds parameters for the given window object
  166. * @param aWindow is the target window settings object
  167. * @param aJsonPath is the path to read parameters from
  168. */
  169. void addParamsForWindow( WINDOW_SETTINGS* aWindow, const std::string& aJsonPath );
  170. };
  171. #endif