34#include <nlohmann/json.hpp>
103 "design_block_chooser.lib_tree.column_widths",
104 [&]() -> nlohmann::json
106 nlohmann::json ret = {};
109 ret[std::string(
name.ToUTF8() )] = width;
113 [&](
const nlohmann::json& aJson )
115 if( !aJson.is_object() )
118 m_DesignBlockChooserPanel.tree.column_widths.clear();
120 for(
const auto& entry : aJson.items() )
122 if( !entry.value().is_number_integer() )
125 m_DesignBlockChooserPanel.tree.column_widths[entry.key()] = entry.value().get<
int>();
130 m_params.emplace_back(
new PARAM<float>(
"graphics.highlight_factor",
131 &m_Graphics.highlight_factor, 0.5f, 0.0, 1.0f ) );
133 m_params.emplace_back(
new PARAM<float>(
"graphics.select_factor",
134 &m_Graphics.select_factor, 0.75f, 0.0, 1.0f ) );
136 m_params.emplace_back(
new PARAM<int>(
"color_picker.default_tab",
137 &m_ColorPicker.default_tab, 0 ) );
139 m_params.emplace_back(
new PARAM_LIST<wxString>(
"lib_tree.columns", &m_LibTree.columns, {} ) );
142 [&]() -> nlohmann::json
144 nlohmann::json ret = {};
146 for(
const std::pair<const wxString, int>& pair : m_LibTree.column_widths )
147 ret[std::string( pair.first.ToUTF8() )] = pair.second;
151 [&](
const nlohmann::json& aJson )
153 if( !aJson.is_object() )
156 m_LibTree.column_widths.clear();
158 for(
const auto& entry : aJson.items() )
160 if( !entry.value().is_number_integer() )
163 m_LibTree.column_widths[ entry.key() ] = entry.value().get<
int>();
168 m_params.emplace_back(
171 m_params.emplace_back(
new PARAM<bool>(
"printing.background",
172 &m_Printing.background,
false ) );
174 m_params.emplace_back(
new PARAM<bool>(
"printing.monochrome",
175 &m_Printing.monochrome,
true ) );
178 &m_Printing.scale, 1.0 ) );
180 m_params.emplace_back(
new PARAM<bool>(
"printing.use_theme",
181 &m_Printing.use_theme,
false ) );
184 &m_Printing.color_theme, wxS(
"" ) ) );
186 m_params.emplace_back(
new PARAM<bool>(
"printing.title_block",
187 &m_Printing.title_block,
false ) );
190 &m_Printing.layers, {} ) );
192 m_params.emplace_back(
new PARAM<int>(
"search_pane.selection_zoom",
193 reinterpret_cast<int*
>( &m_SearchPane.selection_zoom ),
194 static_cast<int>( SEARCH_PANE::SELECTION_ZOOM::PAN ) ) );
196 m_params.emplace_back(
new PARAM<bool>(
"search_pane.search_hidden_fields",
197 &m_SearchPane.search_hidden_fields,
true ) );
199 m_params.emplace_back(
new PARAM<bool>(
"search_pane.search_metadata",
200 &m_SearchPane.search_metadata,
false ) );
202 m_params.emplace_back(
new PARAM<bool>(
"system.first_run_shown",
203 &m_System.first_run_shown,
false ) );
205 m_params.emplace_back(
new PARAM<int>(
"system.max_undo_items",
206 &m_System.max_undo_items, 0 ) );
210 &m_System.file_history, {} ) );
212 if( m_filename == wxS(
"pl_editor" )
213 || ( m_filename == wxS(
"eeschema" ) || m_filename == wxS(
"symbol_editor" ) ) )
215 m_params.emplace_back(
new PARAM<int>(
"system.units",
220 m_params.emplace_back(
new PARAM<int>(
"system.units",
224 m_params.emplace_back(
new PARAM<int>(
"system.last_metric_units",
225 &m_System.last_metric_units,
static_cast<int>(
EDA_UNITS::MM ) ) );
227 m_params.emplace_back(
new PARAM<int>(
"system.last_imperial_units",
228 &m_System.last_imperial_units,
static_cast<int>(
EDA_UNITS::MILS ) ) );
230 m_params.emplace_back(
new PARAM<bool>(
"system.show_import_issues",
231 &m_System.show_import_issues,
true ) );
234 [&]() -> nlohmann::json
236 nlohmann::json js = nlohmann::json::array();
238 for( const auto& [identifier, visible] : m_Plugins.actions )
239 js.push_back( nlohmann::json( { { identifier.ToUTF8(), visible } } ) );
243 [&](
const nlohmann::json& aObj )
245 m_Plugins.actions.clear();
247 if( !aObj.is_array() )
252 for(
const auto& entry : aObj )
254 if( entry.empty() || !entry.is_object() )
257 for(
const auto& pair : entry.items() )
259 m_Plugins.actions.emplace_back( std::make_pair(
260 wxString( pair.key().c_str(), wxConvUTF8 ), pair.value() ) );
264 nlohmann::json::array() ) );
269 m_params.emplace_back(
new PARAM<bool>(
"appearance.custom_toolbars",
270 &m_CustomToolbars,
false ) );
272 addParamsForWindow( &m_Window,
"window" );
274 m_params.emplace_back(
new PARAM<bool>(
"cross_probing.on_selection",
275 &m_CrossProbing.on_selection,
true ) );
277 m_params.emplace_back(
new PARAM<bool>(
"cross_probing.center_on_items",
278 &m_CrossProbing.center_on_items,
true ) );
280 m_params.emplace_back(
new PARAM<bool>(
"cross_probing.zoom_to_fit",
281 &m_CrossProbing.zoom_to_fit,
true ) );
283 m_params.emplace_back(
new PARAM<bool>(
"cross_probing.auto_highlight",
284 &m_CrossProbing.auto_highlight,
true ) );
286 m_params.emplace_back(
new PARAM<bool>(
"cross_probing.flash_selection",
287 &m_CrossProbing.flash_selection,
false ) );
297 ret &=
fromLegacyString( aCfg,
"LastFindString",
"find_replace.find_string" );
298 ret &=
fromLegacyString( aCfg,
"LastReplaceString",
"find_replace.replace_string" );
302 ret &=
fromLegacy<int>( aCfg,
"P22LIB_TREE_MODEL_ADAPTERSelectorColumnWidth",
303 "lib_tree.column_width" );
310 nlohmann::json js = nlohmann::json::array();
316 key.Printf( wxT(
"PlotLayer_%d" ), i );
318 if( aCfg->Read( key, &val ) && val )
322 Set(
"printing.layers", js );
325 ret &=
fromLegacy<bool>( aCfg, f +
"FirstRunShown",
"system.first_run_shown" );
326 ret &=
fromLegacy<int>( aCfg, f +
"DevelMaxUndoItems",
"system.max_undo_items" );
332 nlohmann::json js = nlohmann::json::array();
334 for(
int i = 1; i <= max_history_size; i++ )
336 key.Printf(
"file%d", i );
337 file = aCfg->Read( key, wxEmptyString );
339 if( !file.IsEmpty() )
340 js.push_back( file.ToStdString() );
343 Set(
"system.file_history", js );
354 const int find_replace_history_size = 10;
355 nlohmann::json find_history = nlohmann::json::array();
356 nlohmann::json replace_history = nlohmann::json::array();
357 wxString tmp, find_key, replace_key;
359 for(
int i = 0; i < find_replace_history_size; ++i )
361 find_key.Printf(
"FindStringHistoryList%d", i );
362 replace_key.Printf(
"ReplaceStringHistoryList%d", i );
364 if( aCfg->Read( find_key, &tmp ) )
365 find_history.push_back( tmp.ToStdString() );
367 if( aCfg->Read( replace_key, &tmp ) )
368 replace_history.push_back( tmp.ToStdString() );
371 Set(
"find_replace.find_history", find_history );
372 Set(
"find_replace.replace_history", replace_history );
377 const std::string& aJsonPath )
381 const std::string frameGDO = aFrame +
"GalDisplayOptions";
382 const std::string cursorPath = aJsonPath +
".cursor";
383 const std::string gridPath = aJsonPath +
".grid";
385 ret &=
fromLegacy<bool>( aCfg, aFrame +
"Maximized", aJsonPath +
".maximized" );
386 ret &=
fromLegacyString( aCfg, aFrame +
"MostRecentlyUsedPath", aJsonPath +
".mru_path" );
387 ret &=
fromLegacy<int>( aCfg, aFrame +
"Size_x", aJsonPath +
".size_x" );
388 ret &=
fromLegacy<int>( aCfg, aFrame +
"Size_y", aJsonPath +
".size_y" );
389 ret &=
fromLegacyString( aCfg, aFrame +
"Perspective", aJsonPath +
".perspective" );
390 ret &=
fromLegacy<int>( aCfg, aFrame +
"Pos_x", aJsonPath +
".pos_x" );
391 ret &=
fromLegacy<int>( aCfg, aFrame +
"Pos_y", aJsonPath +
".pos_y" );
394 cursorPath +
".always_show_cursor" );
396 cursorPath +
".cross_hair_mode" );
398 ret &=
fromLegacy<int>( aCfg, aFrame +
"_LastGridSize", gridPath +
".last_size" );
400 ret &=
fromLegacy<int>( aCfg, aFrame +
"FastGrid1", gridPath +
".fast_grid_1" );
401 ret &=
fromLegacy<int>( aCfg, aFrame +
"FastGrid2", gridPath +
".fast_grid_2" );
403 ret &=
fromLegacy<bool>( aCfg, frameGDO +
"GridAxesEnabled", gridPath +
".axes_enabled" );
404 ret &=
fromLegacy<double>( aCfg, frameGDO +
"GridLineWidth", gridPath +
".line_width" );
405 ret &=
fromLegacy<double>( aCfg, frameGDO +
"GridMaxDensity", gridPath +
".min_spacing" );
407 ret &=
fromLegacy<int>( aCfg, frameGDO +
"GridStyle", gridPath +
".style" );
408 ret &=
fromLegacyColor( aCfg, frameGDO +
"GridColor", gridPath +
".color" );
415 int aDefaultWidth,
int aDefaultHeight )
431 &aWindow->
aui_state, nlohmann::json() ) );
584 return {
GRID{ wxEmptyString, wxS(
"100 mil" ), wxS(
"100 mil" ) },
585 GRID{ wxEmptyString, wxS(
"50 mil" ), wxS(
"50 mil" ) },
586 GRID{ wxEmptyString, wxS(
"25 mil" ), wxS(
"25 mil" ) },
587 GRID{ wxEmptyString, wxS(
"10 mil" ), wxS(
"10 mil" ) } };
591 return {
GRID{ wxEmptyString, wxS(
"5.00 mm" ), wxS(
"5.00 mm" ) },
592 GRID{ wxEmptyString, wxS(
"2.50 mm" ), wxS(
"2.50 mm" ) },
593 GRID{ wxEmptyString, wxS(
"2.00 mm" ), wxS(
"2.00 mm" ) },
594 GRID{ wxEmptyString, wxS(
"1.00 mm" ), wxS(
"1.00 mm" ) },
595 GRID{ wxEmptyString, wxS(
"0.50 mm" ), wxS(
"0.50 mm" ) },
596 GRID{ wxEmptyString, wxS(
"0.25 mm" ), wxS(
"0.25 mm" ) },
597 GRID{ wxEmptyString, wxS(
"0.20 mm" ), wxS(
"0.20 mm" ) },
598 GRID{ wxEmptyString, wxS(
"0.10 mm" ), wxS(
"0.10 mm" ) } };
602 return {
GRID{ wxEmptyString, wxS(
"100 mil" ), wxS(
"100 mil" ) },
603 GRID{ wxEmptyString, wxS(
"50 mil" ), wxS(
"50 mil" ) },
604 GRID{ wxEmptyString, wxS(
"25 mil" ), wxS(
"25 mil" ) },
605 GRID{ wxEmptyString, wxS(
"20 mil" ), wxS(
"20 mil" ) },
606 GRID{ wxEmptyString, wxS(
"10 mil" ), wxS(
"10 mil" ) },
607 GRID{ wxEmptyString, wxS(
"5 mil" ), wxS(
"5 mil" ) },
608 GRID{ wxEmptyString, wxS(
"2.5 mil" ), wxS(
"2.5 mil" ) },
609 GRID{ wxEmptyString, wxS(
"2 mil" ), wxS(
"2 mil" ) },
610 GRID{ wxEmptyString, wxS(
"1 mil" ), wxS(
"1 mil" ) },
611 GRID{ wxEmptyString, wxS(
"0.5 mil" ), wxS(
"0.5 mil" ) },
612 GRID{ wxEmptyString, wxS(
"0.2 mil" ), wxS(
"0.2 mil" ) },
613 GRID{ wxEmptyString, wxS(
"0.1 mil" ), wxS(
"0.1 mil" ) },
614 GRID{ wxEmptyString, wxS(
"5.0 mm" ), wxS(
"5.0 mm" ) },
615 GRID{ wxEmptyString, wxS(
"1.5 mm" ), wxS(
"2.5 mm" ) },
616 GRID{ wxEmptyString, wxS(
"1.0 mm" ), wxS(
"1.0 mm" ) },
617 GRID{ wxEmptyString, wxS(
"0.5 mm" ), wxS(
"0.5 mm" ) },
618 GRID{ wxEmptyString, wxS(
"0.25 mm" ), wxS(
"0.25 mm" ) },
619 GRID{ wxEmptyString, wxS(
"0.2 mm" ), wxS(
"0.2 mm" ) },
620 GRID{ wxEmptyString, wxS(
"0.1 mm" ), wxS(
"0.1 mm" ) },
621 GRID{ wxEmptyString, wxS(
"0.05 mm" ), wxS(
"0.0 mm" ) },
622 GRID{ wxEmptyString, wxS(
"0.025 mm" ), wxS(
"0.0 mm" ) },
623 GRID{ wxEmptyString, wxS(
"0.01 mm" ), wxS(
"0.0 mm" ) } };
627 return {
GRID{ wxEmptyString, wxS(
"1000 mil" ), wxS(
"1000 mil" ) },
628 GRID{ wxEmptyString, wxS(
"500 mil" ), wxS(
"500 mil" ) },
629 GRID{ wxEmptyString, wxS(
"250 mil" ), wxS(
"250 mil" ) },
630 GRID{ wxEmptyString, wxS(
"200 mil" ), wxS(
"200 mil" ) },
631 GRID{ wxEmptyString, wxS(
"100 mil" ), wxS(
"100 mil" ) },
632 GRID{ wxEmptyString, wxS(
"50 mil" ), wxS(
"50 mil" ) },
633 GRID{ wxEmptyString, wxS(
"25 mil" ), wxS(
"25 mil" ) },
634 GRID{ wxEmptyString, wxS(
"20 mil" ), wxS(
"20 mil" ) },
635 GRID{ wxEmptyString, wxS(
"10 mil" ), wxS(
"10 mil" ) },
636 GRID{ wxEmptyString, wxS(
"5 mil" ), wxS(
"5 mil" ) },
637 GRID{ wxEmptyString, wxS(
"2 mil" ), wxS(
"2 mil" ) },
638 GRID{ wxEmptyString, wxS(
"1 mil" ), wxS(
"1 mil" ) },
639 GRID{ wxEmptyString, wxS(
"5.0 mm" ), wxS(
"5.0 mm" ) },
640 GRID{ wxEmptyString, wxS(
"2.5 mm" ), wxS(
"2.5 mm" ) },
641 GRID{ wxEmptyString, wxS(
"1.0 mm" ), wxS(
"1.0 mm" ) },
642 GRID{ wxEmptyString, wxS(
"0.5 mm" ), wxS(
"0.5 mm" ) },
643 GRID{ wxEmptyString, wxS(
"0.25 mm" ), wxS(
"0.25 mm" ) },
644 GRID{ wxEmptyString, wxS(
"0.2 mm" ), wxS(
"0.2 mm" ) },
645 GRID{ wxEmptyString, wxS(
"0.1 mm" ), wxS(
"0.1 mm" ) },
646 GRID{ wxEmptyString, wxS(
"0.05 mm" ), wxS(
"0.05 mm" ) },
647 GRID{ wxEmptyString, wxS(
"0.025 mm" ), wxS(
"0.025 mm" ) },
648 GRID{ wxEmptyString, wxS(
"0.01 mm" ), wxS(
"0.01 mm" ) } };
657 if( std::optional<int> optWidth =
Get<int>(
"lib_tree.column_width" ) )
660 At(
"lib_tree" ).erase(
"column_width" );
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
APP_SETTINGS_BASE(const std::string &aFilename, int aSchemaVersion)
FIND_REPLACE m_FindReplace
bool migrateWindowConfig(wxConfigBase *aCfg, const std::string &aFrameName, const std::string &aJsonPath)
Migrate legacy window settings into the JSON document.
bool m_CustomToolbars
Use custom toolbars.
const std::vector< GRID > DefaultGridSizeList() const
void migrateFindReplace(wxConfigBase *aCfg)
! Migrates the find/replace history string list.s
PANEL_DESIGN_BLOCK_CHOOSER m_DesignBlockChooserPanel
void addParamsForWindow(WINDOW_SETTINGS *aWindow, const std::string &aJsonPath, int aDefaultWidth=0, int aDefaultHeight=0)
Add parameters for the given window object.
const std::vector< double > DefaultZoomList() const
COLOR_PICKER m_ColorPicker
virtual std::string getLegacyFrameName() const
virtual bool MigrateFromLegacy(wxConfigBase *aCfg) override
Migrates from wxConfig to JSON-based configuration.
CROSS_PROBING_SETTINGS m_CrossProbing
bool migrateLibTreeWidth()
Migrate the library tree width setting from a single column (Item) to multi-column.
int m_appSettingsSchemaVersion
! Local schema version for common app settings.
static const wxString COLOR_BUILTIN_DEFAULT
bool fromLegacyString(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig string value to a given JSON pointer value.
bool fromLegacy(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig value to a given JSON pointer value.
void Set(const std::string &aPath, ValueType aVal)
Stores a value into the JSON document Will throw an exception if ValueType isn't something that the l...
wxString m_filename
The filename (not including path) of this settings file (inicode)
bool fromLegacyColor(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy COLOR4D stored in a wxConfig string to a given JSON pointer value.
std::optional< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
nlohmann::json & At(const std::string &aPath)
Wrappers for the underlying JSON API so that most consumers don't need json.hpp All of these function...
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
Like a normal param, but with custom getter and setter functions.
virtual COMMON_SETTINGS * GetCommonSettings() const
template KICOMMON_API void JSON_SETTINGS::Set< nlohmann::json >(const std::string &aPath, nlohmann::json aValue)
@ USER
The main config directory (e.g. ~/.config/kicad/)
PGM_BASE & Pgm()
The global program "get" accessor.
KIGFX::CROSS_HAIR_MODE cross_hair_mode
int override_connected_idx
std::vector< GRID > grids
int override_graphics_idx
Common grid settings, available to every frame.
Store the common settings that are saved and loaded for each window / frame.
std::vector< double > zoom_factors
#define ZOOM_LIST_PL_EDITOR
#define ZOOM_LIST_PCBNEW_HYPER
#define ZOOM_LIST_EESCHEMA
#define ZOOM_LIST_GERBVIEW