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 21 #ifndef _APP_SETTINGS_H 22 #define _APP_SETTINGS_H 23 24 #include <gal/color4d.h> 25 #include <settings/json_settings.h> 26 27 /** 28 * Cross-probing behavior 29 */ 30 struct CROSS_PROBING_SETTINGS 31 { 32 bool center_on_items; ///< Automatically pan to cross-probed items 33 bool zoom_to_fit; ///< Zoom to fit items (ignored if center_on_items is off) 34 bool auto_highlight; ///< Automatically turn on highlight mode in the target frame 35 }; 36 37 /** 38 * Common cursor settings, available to every frame 39 */ 40 struct CURSOR_SETTINGS 41 { 42 bool always_show_cursor; 43 bool fullscreen_cursor; 44 }; 45 46 /** 47 * Common grid settings, available to every frame 48 */ 49 struct GRID_SETTINGS 50 { 51 bool axes_enabled; 52 std::vector<wxString> sizes; 53 wxString user_grid_x; 54 wxString user_grid_y; 55 int last_size_idx; 56 int fast_grid_1; 57 int fast_grid_2; 58 double line_width; 59 double min_spacing; 60 bool show; 61 int style; 62 int snap; 63 }; 64 65 /** 66 * Stores the window positioning/state 67 */ 68 struct WINDOW_STATE 69 { 70 bool maximized; 71 int size_x; 72 int size_y; 73 int pos_x; 74 int pos_y; 75 unsigned int display; 76 }; 77 78 /** 79 * Stores the common settings that are saved and loaded for each window / frame 80 */ 81 struct WINDOW_SETTINGS 82 { 83 WINDOW_STATE state; 84 wxString mru_path; 85 wxString perspective; 86 std::vector<double> zoom_factors; 87 88 CURSOR_SETTINGS cursor; 89 GRID_SETTINGS grid; 90 }; 91 92 /** 93 * APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad 94 * application. It stores settings that should exist for every app, but may be different from 95 * app to app depending on the user's preferences. 96 * 97 * COMMON_SETTINGS stores settings that are always the same across all applications. 98 */ 99 class APP_SETTINGS_BASE : public JSON_SETTINGS 100 { 101 public: 102 103 104 struct FIND_REPLACE 105 { 106 int flags; 107 wxString find_string; 108 std::vector<wxString> find_history; 109 wxString replace_string; 110 std::vector<wxString> replace_history; 111 }; 112 113 struct GRAPHICS 114 { 115 int canvas_type; 116 float highlight_factor; ///< How much to brighten highlighted objects by 117 float select_factor; ///< How much to brighten selected objects by 118 float high_contrast_factor; ///< How much to darken inactive layers by 119 }; 120 121 struct COLOR_PICKER 122 { 123 int default_tab; 124 }; 125 126 struct LIB_TREE 127 { 128 int column_width; 129 }; 130 131 struct PRINTING 132 { 133 bool background; ///< Whether or not to print background color 134 bool monochrome; ///< Whether or not to print in monochrome 135 double scale; ///< Printout scale 136 bool use_theme; ///< If false, display color theme will be used 137 wxString color_theme; ///< Color theme to use for printing 138 bool title_block; ///< Whether or not to print title block 139 std::vector<int> layers; ///< List of enabled layers for printing 140 }; 141 142 struct SYSTEM 143 { 144 bool first_run_shown; 145 int max_undo_items; 146 std::vector<wxString> file_history; 147 int units; 148 int last_metric_units; 149 int last_imperial_units; 150 }; 151 152 APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaVersion ); 153 ~APP_SETTINGS_BASE()154 virtual ~APP_SETTINGS_BASE() {} 155 156 virtual bool MigrateFromLegacy( wxConfigBase* aCfg ) override; 157 158 /** 159 * By default, this returns the list of grids available in PcbNew-based applications. 160 * Eeschema does not allow customization of the grid. If it ever does, override this in 161 * Eeschema settings to provide a different set of defaults. 162 * @return a default value for the window.grid.sizes parameter 163 */ 164 virtual const std::vector<wxString> DefaultGridSizeList() const; 165 166 public: 167 CROSS_PROBING_SETTINGS m_CrossProbing; 168 169 FIND_REPLACE m_FindReplace; 170 171 GRAPHICS m_Graphics; 172 173 COLOR_PICKER m_ColorPicker; 174 175 LIB_TREE m_LibTree; 176 177 PRINTING m_Printing; 178 179 SYSTEM m_System; 180 181 WINDOW_SETTINGS m_Window; 182 183 /// Active color theme name 184 wxString m_ColorTheme; 185 186 ///! Local schema version for common app settings 187 int m_appSettingsSchemaVersion; 188 189 protected: 190 getLegacyFrameName()191 virtual std::string getLegacyFrameName() const { return std::string(); } 192 193 ///! Migrates the find/replace history string lists 194 void migrateFindReplace( wxConfigBase* aCfg ); 195 196 /** 197 * Migrates legacy window settings into the JSON document 198 * @param aCfg is the wxConfig object to read from 199 * @param aFrameName is the prefix for window settings in the legacy config file 200 * @param aJsonPath is the prefix for storing window settings in the JSON file 201 * @return true if all settings were migrated 202 */ 203 bool migrateWindowConfig( wxConfigBase* aCfg, const std::string& aFrameName, 204 const std::string& aJsonPath ); 205 206 /** 207 * Adds parameters for the given window object 208 * @param aWindow is the target window settings object 209 * @param aJsonPath is the path to read parameters from 210 */ 211 void addParamsForWindow( WINDOW_SETTINGS* aWindow, const std::string& aJsonPath ); 212 }; 213 214 #endif 215