KiCad PCB EDA Suite
COMMON_SETTINGS Class Reference

#include <common_settings.h>

Inheritance diagram for COMMON_SETTINGS:
JSON_SETTINGS

Classes

struct  APPEARANCE
 
struct  AUTO_BACKUP
 
struct  ENVIRONMENT
 
struct  GRAPHICS
 
struct  INPUT
 
struct  NETCLASS_PANEL
 
struct  SESSION
 
struct  SYSTEM
 

Public Member Functions

 COMMON_SETTINGS ()
 
virtual ~COMMON_SETTINGS ()
 
virtual bool MigrateFromLegacy (wxConfigBase *aLegacyConfig) override
 Migrates from wxConfig to JSON-based configuration. More...
 
void InitializeEnvironment ()
 Creates the built-in environment variables and sets their default values. More...
 
wxString GetFilename () const
 
wxString GetFullFilename () const
 
void SetFilename (const wxString &aFilename)
 
SETTINGS_LOC GetLocation () const
 
void SetLegacyFilename (const wxString &aFilename)
 
bool IsReadOnly () const
 
void SetReadOnly (bool aReadOnly)
 
virtual void Load ()
 Updates the parameters of this object based on the current JSON document contents. More...
 
virtual bool Store ()
 Stores the current parameters into the JSON document represented by this object Note: this doesn't do any writing to disk; that's handled by SETTINGS_MANAGER. More...
 
virtual bool LoadFromFile (const wxString &aDirectory="")
 Loads the backing file from disk and then calls Load() More...
 
virtual bool SaveToFile (const wxString &aDirectory="", bool aForce=false)
 
void ResetToDefaults ()
 Resets all parameters to default values. More...
 
bool IsDefault (const std::string &aParamName)
 Checks if the current state of a parameter matches its default value. More...
 
OPT< nlohmann::jsonGetJson (const std::string &aPath) const
 Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1.key2.key3" to refer to nested objects. More...
 
template<typename ValueType >
OPT< ValueType > Get (const std::string &aPath) const
 Fetches a value from within the JSON document. More...
 
template<>
OPT< wxString > Get (const std::string &aPath) const
 
template<typename ValueType >
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 library can handle. More...
 
template<>
void Set (const std::string &aPath, wxString aVal)
 
template<>
void Set (const std::string &aPath, wxString aVal)
 
bool Migrate ()
 Migrates the schema of this settings from the version in the file to the latest version. More...
 
void AddNestedSettings (NESTED_SETTINGS *aSettings)
 Transfers ownership of a given NESTED_SETTINGS to this object. More...
 
void ReleaseNestedSettings (NESTED_SETTINGS *aSettings)
 Saves and frees a nested settings object, if it exists within this one. More...
 
void SetManager (SETTINGS_MANAGER *aManager)
 

Static Public Member Functions

static nlohmann::json::json_pointer PointerFromString (std::string aPath)
 Builds a JSON pointer based on a given string. More...
 
static bool SetIfPresent (const nlohmann::json &aObj, const std::string &aPath, wxString &aTarget)
 Sets the given string if the given key/path is present. More...
 
static bool SetIfPresent (const nlohmann::json &aObj, const std::string &aPath, bool &aTarget)
 Sets the given bool if the given key/path is present. More...
 
static bool SetIfPresent (const nlohmann::json &aObj, const std::string &aPath, int &aTarget)
 Sets the given int if the given key/path is present. More...
 
static bool SetIfPresent (const nlohmann::json &aObj, const std::string &aPath, unsigned int &aTarget)
 Sets the given unsigned int if the given key/path is present. More...
 

Public Attributes

APPEARANCE m_Appearance
 
AUTO_BACKUP m_Backup
 
ENVIRONMENT m_Env
 
INPUT m_Input
 
GRAPHICS m_Graphics
 
SESSION m_Session
 
SYSTEM m_System
 
NETCLASS_PANEL m_NetclassPanel
 
wxString m_3DLibsUrl
 
wxString m_3DLibsDownloadPath
 

Protected Member Functions

void registerMigration (int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
 Registers a migration from one schema version to another. More...
 
template<typename ValueType >
bool fromLegacy (wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
 Translates a legacy wxConfig value to a given JSON pointer value. More...
 
bool fromLegacyString (wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
 Translates a legacy wxConfig string value to a given JSON pointer value. More...
 
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. More...
 
virtual wxString getFileExt () const
 
virtual wxString getLegacyFileExt () const
 

Protected Attributes

wxString m_filename
 The filename (not including path) of this settings file (inicode) More...
 
wxString m_legacy_filename
 The filename of the wxConfig legacy file (if different from m_filename) More...
 
SETTINGS_LOC m_location
 The location of this settings file (. More...
 
std::vector< PARAM_BASE * > m_params
 The list of parameters (owned by this object) More...
 
std::vector< NESTED_SETTINGS * > m_nested_settings
 Nested settings files that live inside this one, if any. More...
 
bool m_createIfMissing
 Whether or not the backing store file should be created it if doesn't exist. More...
 
bool m_createIfDefault
 Whether or not the backing store file should be created if all parameters are still at their default values. More...
 
bool m_writeFile
 Whether or not the backing store file should be written. More...
 
bool m_deleteLegacyAfterMigration
 Whether or not to delete legacy file after migration. More...
 
bool m_resetParamsIfMissing
 Whether or not to set parameters to their default value if missing from JSON on Load() More...
 
int m_schemaVersion
 Version of this settings schema. More...
 
SETTINGS_MANAGERm_manager
 A pointer to the settings manager managing this file (may be null) More...
 
std::vector< nlohmann::json::json_pointer > m_preserved_paths
 A list of JSON pointers that are preserved during a read-update-write to disk. More...
 
std::map< int, std::pair< int, std::function< bool()> > > m_migrators
 A map of starting schema version to a pair of <ending version, migrator function> More...
 

Private Member Functions

bool migrateSchema0to1 ()
 
bool migrateSchema1to2 ()
 

Detailed Description

Definition at line 47 of file common_settings.h.

Constructor & Destructor Documentation

◆ COMMON_SETTINGS()

COMMON_SETTINGS::COMMON_SETTINGS ( )

Definition at line 46 of file common_settings.cpp.

46  :
48  m_Appearance(),
49  m_Backup(),
50  m_Env(),
51  m_Input(),
52  m_Graphics(),
53  m_Session(),
54  m_System(),
56 {
57  // This only effect the first time KiCad is run. The user's setting will be used for all
58  // subsequent runs.
59  // Menu icons are off by default on OSX and on for all other platforms.
60  // Use automatic canvas scaling on OSX, but not on the other platforms (their detection
61  // isn't as good).
62 #if defined( __WXMAC__ )
63  bool defaultUseIconsInMenus = false;
64  double canvasScale = 0.0;
65 #else
66  bool defaultUseIconsInMenus = true;
67  double canvasScale = 1.0;
68 #endif
69 
70  m_params.emplace_back( new PARAM<double>( "appearance.canvas_scale",
71  &m_Appearance.canvas_scale, canvasScale ) );
72 
73  m_params.emplace_back( new PARAM<int>( "appearance.icon_scale",
74  &m_Appearance.icon_scale, 0 ) );
75 
76  m_params.emplace_back( new PARAM_ENUM<ICON_THEME>( "appearance.icon_theme",
78 
79  m_params.emplace_back( new PARAM<bool>( "appearance.use_icons_in_menus",
80  &m_Appearance.use_icons_in_menus, defaultUseIconsInMenus ) );
81 
82  m_params.emplace_back( new PARAM<bool>( "auto_backup.enabled", &m_Backup.enabled, true ) );
83 
84  m_params.emplace_back( new PARAM<bool>( "auto_backup.backup_on_autosave",
85  &m_Backup.backup_on_autosave, false ) );
86 
87  m_params.emplace_back( new PARAM<int>( "auto_backup.limit_total_files",
88  &m_Backup.limit_total_files, 25 ) );
89 
90  m_params.emplace_back( new PARAM<unsigned long long>( "auto_backup.limit_total_size",
91  &m_Backup.limit_total_size, 104857600 ) );
92 
93  m_params.emplace_back( new PARAM<int>( "auto_backup.limit_daily_files",
95 
96  m_params.emplace_back( new PARAM<int>( "auto_backup.min_interval",
97  &m_Backup.min_interval, 300 ) );
98 
99  m_params.emplace_back( new PARAM<bool>( "environment.show_warning_dialog",
100  &m_Env.show_warning_dialog, false ) );
101 
102  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "environment.vars",
103  [&]() -> nlohmann::json
104  {
105  nlohmann::json ret = {};
106 
107  for( const std::pair<wxString, ENV_VAR_ITEM> entry : m_Env.vars )
108  {
109  const ENV_VAR_ITEM& var = entry.second;
110 
111  wxASSERT( entry.first == var.GetKey() );
112 
113  // Default values are never persisted
114  if( var.IsDefault() )
115  {
116  wxLogTrace( traceEnvVars,
117  "COMMON_SETTINGS: Env var %s skipping save (default)",
118  var.GetKey() );
119  continue;
120  }
121 
122  wxString value = var.GetValue();
123 
124  // Vars that existed in JSON are persisted, but if they were overridden
125  // externally, we persist the old value (i.e. the one that was loaded from JSON)
126  if( var.GetDefinedExternally() )
127  {
128  if( var.GetDefinedInSettings() )
129  {
130  wxLogTrace( traceEnvVars,
131  "COMMON_SETTINGS: Env var %s was overridden externally, "
132  "saving previously-loaded value %s",
133  var.GetKey(), var.GetSettingsValue() );
134  value = var.GetSettingsValue();
135  }
136  else
137  {
138  wxLogTrace( traceEnvVars,
139  "COMMON_SETTINGS: Env var %s skipping save (external)",
140  var.GetKey() );
141  continue;
142  }
143  }
144 
145  wxLogTrace( traceEnvVars,
146  "COMMON_SETTINGS: Saving env var %s = %s",
147  var.GetKey(), value);
148 
149  std::string key( var.GetKey().ToUTF8() );
150  ret[key] = value;
151  }
152 
153  return ret;
154  },
155  [&]( const nlohmann::json& aJson )
156  {
157  if( !aJson.is_object() )
158  return;
159 
160  for( const auto& entry : aJson.items() )
161  {
162  wxString key = wxString( entry.key().c_str(), wxConvUTF8 );
163  wxString val = entry.value().get<wxString>();
164 
165  if( m_Env.vars.count( key ) )
166  {
167  if( m_Env.vars[key].GetDefinedExternally() )
168  {
169  wxLogTrace( traceEnvVars, "COMMON_SETTINGS: %s is defined externally",
170  key );
171  m_Env.vars[key].SetDefinedInSettings();
172  m_Env.vars[key].SetSettingsValue( val );
173  continue;
174  }
175  else
176  {
177  wxLogTrace( traceEnvVars, "COMMON_SETTINGS: Updating %s: %s -> %s",
178  key, m_Env.vars[key].GetValue(), val );
179  m_Env.vars[key].SetValue( val );
180  }
181  }
182  else
183  {
184  wxLogTrace( traceEnvVars, "COMMON_SETTINGS: Loaded new var: %s = %s",
185  key, val );
186  m_Env.vars[key] = ENV_VAR_ITEM( key, val );
187  }
188 
189  m_Env.vars[key].SetDefinedInSettings();
190  m_Env.vars[key].SetSettingsValue( val );
191  }
192  },
193  {} ) );
194 
195  m_params.emplace_back( new PARAM<bool>( "input.auto_pan", &m_Input.auto_pan, false ) );
196 
197  m_params.emplace_back( new PARAM<int>( "input.auto_pan_acceleration",
199 
200  m_params.emplace_back( new PARAM<bool>( "input.center_on_zoom",
201  &m_Input.center_on_zoom, true ) );
202 
203  m_params.emplace_back( new PARAM<bool>( "input.immediate_actions",
204  &m_Input.immediate_actions, true ) );
205 
206  m_params.emplace_back( new PARAM<bool>( "input.warp_mouse_on_move",
207  &m_Input.warp_mouse_on_move, true ) );
208 
209  m_params.emplace_back( new PARAM<bool>( "input.horizontal_pan",
210  &m_Input.horizontal_pan, false ) );
211 
212  m_params.emplace_back( new PARAM<bool>( "input.zoom_acceleration",
213  &m_Input.zoom_acceleration, false ) );
214 
215 #ifdef __WXMAC__
216  int default_zoom_speed = 5;
217 #else
218  int default_zoom_speed = 1;
219 #endif
220 
221  m_params.emplace_back( new PARAM<int>( "input.zoom_speed",
222  &m_Input.zoom_speed, default_zoom_speed ) );
223 
224  m_params.emplace_back( new PARAM<bool>( "input.zoom_speed_auto",
225  &m_Input.zoom_speed_auto, true ) );
226 
227  m_params.emplace_back( new PARAM<int>( "input.scroll_modifier_zoom",
229 
230  m_params.emplace_back( new PARAM<int>( "input.scroll_modifier_pan_h",
231  &m_Input.scroll_modifier_pan_h, WXK_CONTROL ) );
232 
233  m_params.emplace_back( new PARAM<int>( "input.scroll_modifier_pan_v",
234  &m_Input.scroll_modifier_pan_v, WXK_SHIFT ) );
235 
236  m_params.emplace_back( new PARAM_ENUM<MOUSE_DRAG_ACTION>( "input.mouse_left",
239 
240  m_params.emplace_back( new PARAM_ENUM<MOUSE_DRAG_ACTION>( "input.mouse_middle",
243 
244  m_params.emplace_back( new PARAM_ENUM<MOUSE_DRAG_ACTION>( "input.mouse_right",
247 
248  m_params.emplace_back( new PARAM<int>( "graphics.opengl_antialiasing_mode",
249  &m_Graphics.opengl_aa_mode, 0, 0, 4 ) );
250 
251  m_params.emplace_back( new PARAM<int>( "graphics.cairo_antialiasing_mode",
252  &m_Graphics.cairo_aa_mode, 0, 0, 3 ) );
253 
254  m_params.emplace_back( new PARAM<int>( "system.autosave_interval",
255  &m_System.autosave_interval, 600 ) );
256 
257  m_params.emplace_back( new PARAM<wxString>( "system.editor_name",
258  &m_System.editor_name, "" ) );
259 
260  m_params.emplace_back( new PARAM<int>( "system.file_history_size",
261  &m_System.file_history_size, 9 ) );
262 
263  m_params.emplace_back( new PARAM<wxString>( "system.language",
264  &m_System.language, "Default" ) );
265 
266  m_params.emplace_back( new PARAM<wxString>( "system.pdf_viewer_name",
267  &m_System.pdf_viewer_name, "" ) );
268 
269  m_params.emplace_back( new PARAM<bool>( "system.use_system_pdf_viewer",
270  &m_System.use_system_pdf_viewer, true ) );
271 
272  m_params.emplace_back( new PARAM<wxString>( "system.working_dir",
273  &m_System.working_dir, "" ) );
274 
275  m_params.emplace_back( new PARAM<int>( "system.clear_3d_cache_interval",
277 
278  m_params.emplace_back( new PARAM<bool>( "session.remember_open_files",
279  &m_Session.remember_open_files, false ) );
280 
281  m_params.emplace_back( new PARAM<int>( "netclass_panel.sash_pos",
282  &m_NetclassPanel.sash_pos, 160 ) );
283 
284  registerMigration( 0, 1, std::bind( &COMMON_SETTINGS::migrateSchema0to1, this ) );
285  registerMigration( 1, 2, std::bind( &COMMON_SETTINGS::migrateSchema1to2, this ) );
286 }
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
unsigned long long limit_total_size
Maximum total size of backups (bytes), 0 for unlimited.
MOUSE_DRAG_ACTION drag_left
KiCad uses environment variables internally for determining the base paths for libraries,...
const int commonSchemaVersion
! Update the schema version whenever a migration is required
bool enabled
Automatically back up the project when files are saved.
AUTO_BACKUP m_Backup
APPEARANCE m_Appearance
Stores an enum as an integer.
Definition: parameters.h:226
nlohmann::json json
Definition: gerbview.cpp:41
MOUSE_DRAG_ACTION drag_right
NETCLASS_PANEL m_NetclassPanel
ENVIRONMENT m_Env
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
Definition: json_settings.h:58
int min_interval
Minimum time, in seconds, between subsequent backups.
void registerMigration(int aOldSchemaVersion, int aNewSchemaVersion, std::function< bool(void)> aMigrator)
Registers a migration from one schema version to another.
The main config directory (e.g. ~/.config/kicad/)
bool backup_on_autosave
Trigger a backup on autosave.
int limit_daily_files
Maximum files to keep per day, 0 for unlimited.
MOUSE_DRAG_ACTION drag_middle
int limit_total_files
Maximum number of backup archives to retain.

References AUTO, COMMON_SETTINGS::AUTO_BACKUP::backup_on_autosave, COMMON_SETTINGS::APPEARANCE::canvas_scale, COMMON_SETTINGS::AUTO_BACKUP::enabled, COMMON_SETTINGS::APPEARANCE::icon_scale, COMMON_SETTINGS::APPEARANCE::icon_theme, LIGHT, COMMON_SETTINGS::AUTO_BACKUP::limit_daily_files, COMMON_SETTINGS::AUTO_BACKUP::limit_total_files, COMMON_SETTINGS::AUTO_BACKUP::limit_total_size, m_Appearance, m_Backup, m_Env, JSON_SETTINGS::m_params, COMMON_SETTINGS::AUTO_BACKUP::min_interval, COMMON_SETTINGS::ENVIRONMENT::show_warning_dialog, traceEnvVars, COMMON_SETTINGS::APPEARANCE::use_icons_in_menus, USER, and COMMON_SETTINGS::ENVIRONMENT::vars.

◆ ~COMMON_SETTINGS()

virtual COMMON_SETTINGS::~COMMON_SETTINGS ( )
inlinevirtual

Definition at line 128 of file common_settings.h.

128 {}

Member Function Documentation

◆ AddNestedSettings()

void JSON_SETTINGS::AddNestedSettings ( NESTED_SETTINGS aSettings)
inherited

Transfers ownership of a given NESTED_SETTINGS to this object.

Can be used to construct a NESTED_SETTINGS without the parent object needing to know about the implementation of the nested object;

Parameters
aSettingsis the settings object to take ownership of
aTargetis a pointer to update to the passed in settings

Definition at line 675 of file json_settings.cpp.

676 {
677  wxLogTrace( traceSettings, "AddNestedSettings %s", aSettings->GetFilename() );
678  m_nested_settings.push_back( aSettings );
679 }
wxString GetFilename() const
Definition: json_settings.h:66
std::vector< NESTED_SETTINGS * > m_nested_settings
Nested settings files that live inside this one, if any.
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.

References JSON_SETTINGS::GetFilename(), JSON_SETTINGS::m_nested_settings, and traceSettings.

Referenced by NESTED_SETTINGS::SetParent().

◆ fromLegacy()

template<typename ValueType >
template bool JSON_SETTINGS::fromLegacy< bool > ( wxConfigBase *  aConfig,
const std::string &  aKey,
const std::string &  aDest 
)
protectedinherited

Translates a legacy wxConfig value to a given JSON pointer value.

Template Parameters
ValueTypeis the basic type of the value
Parameters
aConfigis the legacy config to read from
aKeyis the key (within the current path) to read
aDestis a string that will form a JSON pointer (key1.key2.key3) to write to

Definition at line 587 of file json_settings.cpp.

589 {
590  ValueType val;
591 
592  if( aConfig->Read( aKey, &val ) )
593  {
594  try
595  {
596  ( *this )[PointerFromString( aDest )] = val;
597  }
598  catch( ... )
599  {
600  wxASSERT_MSG( false, wxT( "Could not write value in fromLegacy!" ) );
601  return false;
602  }
603 
604  return true;
605  }
606 
607  return false;
608 }
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References JSON_SETTINGS::PointerFromString().

◆ fromLegacyColor()

bool JSON_SETTINGS::fromLegacyColor ( wxConfigBase *  aConfig,
const std::string &  aKey,
const std::string &  aDest 
)
protectedinherited

Translates a legacy COLOR4D stored in a wxConfig string to a given JSON pointer value.

Parameters
aConfigis the legacy config to read from
aKeyis the key (within the current path) to read
aDestis a string that will form a JSON pointer (key1.key2.key3) to write to

Definition at line 647 of file json_settings.cpp.

649 {
650  wxString str;
651 
652  if( aConfig->Read( aKey, &str ) )
653  {
655  color.SetFromWxString( str );
656 
657  try
658  {
659  nlohmann::json js = nlohmann::json::array( { color.r, color.g, color.b, color.a } );
660  ( *this )[PointerFromString( aDest )] = js;
661  }
662  catch( ... )
663  {
664  wxASSERT_MSG( false, wxT( "Could not write value in fromLegacyColor!" ) );
665  return false;
666  }
667 
668  return true;
669  }
670 
671  return false;
672 }
int color
Definition: DXF_plotter.cpp:60
nlohmann::json json
Definition: gerbview.cpp:41
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References color, and JSON_SETTINGS::PointerFromString().

Referenced by APP_SETTINGS_BASE::migrateWindowConfig().

◆ fromLegacyString()

bool JSON_SETTINGS::fromLegacyString ( wxConfigBase *  aConfig,
const std::string &  aKey,
const std::string &  aDest 
)
protectedinherited

Translates a legacy wxConfig string value to a given JSON pointer value.

Parameters
aConfigis the legacy config to read from
aKeyis the key (within the current path) to read
aDestis a string that will form a JSON pointer (key1.key2.key3) to write to

Definition at line 623 of file json_settings.cpp.

625 {
626  wxString str;
627 
628  if( aConfig->Read( aKey, &str ) )
629  {
630  try
631  {
632  ( *this )[PointerFromString( aDest )] = str.ToUTF8();
633  }
634  catch( ... )
635  {
636  wxASSERT_MSG( false, wxT( "Could not write value in fromLegacyString!" ) );
637  return false;
638  }
639 
640  return true;
641  }
642 
643  return false;
644 }
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References JSON_SETTINGS::PointerFromString().

Referenced by BITMAP2CMP_SETTINGS::MigrateFromLegacy(), FOOTPRINT_EDITOR_SETTINGS::MigrateFromLegacy(), GERBVIEW_SETTINGS::MigrateFromLegacy(), SYMBOL_EDITOR_SETTINGS::MigrateFromLegacy(), PROJECT_FILE::MigrateFromLegacy(), PCB_CALCULATOR_SETTINGS::MigrateFromLegacy(), MigrateFromLegacy(), APP_SETTINGS_BASE::MigrateFromLegacy(), EESCHEMA_SETTINGS::MigrateFromLegacy(), PCBNEW_SETTINGS::MigrateFromLegacy(), and APP_SETTINGS_BASE::migrateWindowConfig().

◆ Get() [1/2]

template<typename ValueType >
OPT<ValueType> JSON_SETTINGS::Get ( const std::string &  aPath) const
inlineinherited

Fetches a value from within the JSON document.

Will return an empty optional if the value is not found or a mismatching type.

Template Parameters
ValueTypeis the type to cast to
Parameters
aPathis the path within the document to retrieve
Returns
a value from within this document

Definition at line 133 of file json_settings.h.

134  {
135  if( OPT<nlohmann::json> ret = GetJson( aPath ) )
136  {
137  try
138  {
139  return ret->get<ValueType>();
140  }
141  catch( ... )
142  {
143  }
144  }
145 
146  return NULLOPT;
147  }
OPT< nlohmann::json > GetJson(const std::string &aPath) const
Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1....
const auto NULLOPT
Definition: optional.h:9
boost::optional< T > OPT
Definition: optional.h:7

References JSON_SETTINGS::GetJson(), and NULLOPT.

Referenced by PARAM< wxString >::Load(), COLOR_MAP_PARAM::Load(), PARAM_ENUM< EnumType >::Load(), PARAM_LAMBDA< nlohmann::json >::Load(), PARAM_SCALED< ValueType >::Load(), PARAM< wxString >::MatchesFile(), COLOR_MAP_PARAM::MatchesFile(), PARAM_PATH::MatchesFile(), PARAM_ENUM< EnumType >::MatchesFile(), PARAM_LAMBDA< nlohmann::json >::MatchesFile(), and PARAM_SCALED< ValueType >::MatchesFile().

◆ Get() [2/2]

OPT< wxString > JSON_SETTINGS::Get ( const std::string &  aPath) const
inherited

Definition at line 705 of file json_settings.cpp.

706 {
707  if( OPT<nlohmann::json> opt_json = GetJson( aPath ) )
708  return wxString( opt_json->get<std::string>().c_str(), wxConvUTF8 );
709 
710  return NULLOPT;
711 }
OPT< nlohmann::json > GetJson(const std::string &aPath) const
Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1....
const auto NULLOPT
Definition: optional.h:9
boost::optional< T > OPT
Definition: optional.h:7

References JSON_SETTINGS::GetJson(), and NULLOPT.

◆ getFileExt()

virtual wxString JSON_SETTINGS::getFileExt ( ) const
inlineprotectedvirtualinherited

Reimplemented in PROJECT_FILE, and PROJECT_LOCAL_SETTINGS.

Definition at line 283 of file json_settings.h.

284  {
285  return wxT( "json" );
286  }

Referenced by JSON_SETTINGS::GetFullFilename(), JSON_SETTINGS::LoadFromFile(), and JSON_SETTINGS::SaveToFile().

◆ GetFilename()

◆ GetFullFilename()

wxString JSON_SETTINGS::GetFullFilename ( ) const
inherited

Definition at line 81 of file json_settings.cpp.

82 {
83  return wxString( m_filename + "." + getFileExt() );
84 }
wxString m_filename
The filename (not including path) of this settings file (inicode)
virtual wxString getFileExt() const

References JSON_SETTINGS::getFileExt(), and JSON_SETTINGS::m_filename.

Referenced by JSON_SETTINGS::JSON_SETTINGS(), NESTED_SETTINGS::LoadFromFile(), JSON_SETTINGS::LoadFromFile(), and JSON_SETTINGS::SaveToFile().

◆ GetJson()

OPT< nlohmann::json > JSON_SETTINGS::GetJson ( const std::string &  aPath) const
inherited

Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1.key2.key3" to refer to nested objects.

Parameters
aPathis a string containing one or more keys separated by '.'
Returns
a JSON object from within this one

Definition at line 436 of file json_settings.cpp.

437 {
438  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
439 
440  if( contains( ptr ) )
441  {
442  try
443  {
444  return OPT<nlohmann::json>{ at( ptr ) };
445  }
446  catch( ... )
447  {
448  }
449  }
450 
451  return OPT<nlohmann::json>{};
452 }
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:81
boost::optional< T > OPT
Definition: optional.h:7
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References alg::contains(), and JSON_SETTINGS::PointerFromString().

Referenced by JSON_SETTINGS::Get(), PARAM_LAMBDA< nlohmann::json >::Load(), PARAM_LIST< wxString >::Load(), PARAM_MAP< Value >::Load(), PARAM_WXSTRING_MAP::Load(), PARAM_LAMBDA< nlohmann::json >::MatchesFile(), PARAM_LIST< wxString >::MatchesFile(), PARAM_PATH_LIST::MatchesFile(), PARAM_MAP< Value >::MatchesFile(), and PARAM_WXSTRING_MAP::MatchesFile().

◆ getLegacyFileExt()

virtual wxString JSON_SETTINGS::getLegacyFileExt ( ) const
inlineprotectedvirtualinherited

Reimplemented in PROJECT_FILE, and PROJECT_LOCAL_SETTINGS.

Definition at line 288 of file json_settings.h.

289  {
290  return wxEmptyString;
291  }

Referenced by JSON_SETTINGS::LoadFromFile().

◆ GetLocation()

SETTINGS_LOC JSON_SETTINGS::GetLocation ( ) const
inlineinherited

Definition at line 72 of file json_settings.h.

72 { return m_location; }
SETTINGS_LOC m_location
The location of this settings file (.

References JSON_SETTINGS::m_location.

Referenced by SETTINGS_MANAGER::GetPathForSettingsFile().

◆ InitializeEnvironment()

void COMMON_SETTINGS::InitializeEnvironment ( )

Creates the built-in environment variables and sets their default values.

Definition at line 447 of file common_settings.cpp.

448 {
449  auto addVar =
450  [&]( const wxString& aKey, const wxString& aDefault )
451  {
452  m_Env.vars[aKey] = ENV_VAR_ITEM( aKey, aDefault, aDefault );
453 
454  wxString envValue;
455 
456  if( wxGetEnv( aKey, &envValue ) == true && !envValue.IsEmpty() )
457  {
458  m_Env.vars[aKey].SetValue( envValue );
459  m_Env.vars[aKey].SetDefinedExternally();
460  wxLogTrace( traceEnvVars,
461  "InitializeEnvironment: Entry %s defined externally as %s", aKey,
462  envValue );
463  }
464  else
465  {
466  wxLogTrace( traceEnvVars, "InitializeEnvironment: Setting entry %s to default %s",
467  aKey, aDefault );
468  }
469  };
470 
471  wxFileName basePath( PATHS::GetStockEDALibraryPath(), wxEmptyString );
472 
473  wxFileName path( basePath );
474  path.AppendDir( wxT( "modules" ) );
475  addVar( wxT( "KICAD6_FOOTPRINT_DIR" ), path.GetFullPath() );
476 
477  path = basePath;
478  path.AppendDir( wxT( "3dmodels" ) );
479  addVar( wxT( "KICAD6_3DMODEL_DIR" ), path.GetFullPath() );
480 
481  // We don't have just one default template path, so use this logic that originally was in
482  // PGM_BASE::InitPgm to determine the best default template path
483  {
484  // Attempt to find the best default template path.
485  SEARCH_STACK bases;
486  SEARCH_STACK templatePaths;
487 
488  SystemDirsAppend( &bases );
489 
490  for( unsigned i = 0; i < bases.GetCount(); ++i )
491  {
492  wxFileName fn( bases[i], wxEmptyString );
493 
494  // Add KiCad template file path to search path list.
495  fn.AppendDir( "template" );
496 
497  // Only add path if exists and can be read by the user.
498  if( fn.DirExists() && fn.IsDirReadable() )
499  {
500  wxLogTrace( tracePathsAndFiles, "Checking template path '%s' exists",
501  fn.GetPath() );
502  templatePaths.AddPaths( fn.GetPath() );
503  }
504  }
505 
506  if( templatePaths.IsEmpty() )
507  {
508  path = basePath;
509  path.AppendDir( "template" );
510  }
511  else
512  {
513  // Take the first one. There may be more but this will likely be the best option.
514  path.AssignDir( templatePaths[0] );
515  }
516 
517  addVar( wxT( "KICAD6_TEMPLATE_DIR" ), path.GetFullPath() );
518  }
519 
520  addVar( wxT( "KICAD_USER_TEMPLATE_DIR" ), PATHS::GetUserTemplatesPath() );
521 
522  path = basePath;
523  path.AppendDir( wxT( "library" ) );
524  addVar( wxT( "KICAD6_SYMBOL_DIR" ), path.GetFullPath() );
525 }
KiCad uses environment variables internally for determining the base paths for libraries,...
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
Look for files in a number of paths.
Definition: search_stack.h:41
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
Definition: paths.cpp:86
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
ENVIRONMENT m_Env
const wxChar *const traceEnvVars
Flag to enable debug output of environment variable operations.
static wxString GetStockEDALibraryPath()
Gets the stock (install) EDA library data path, which is the base path for templates,...
Definition: paths.cpp:175
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).

References SEARCH_STACK::AddPaths(), PATHS::GetStockEDALibraryPath(), PATHS::GetUserTemplatesPath(), m_Env, path, SystemDirsAppend(), traceEnvVars, tracePathsAndFiles, and COMMON_SETTINGS::ENVIRONMENT::vars.

Referenced by PGM_BASE::InitPgm().

◆ IsDefault()

bool JSON_SETTINGS::IsDefault ( const std::string &  aParamName)
inherited

Checks if the current state of a parameter matches its default value.

Parameters
aParamNameis the JSON path to the parameter
Returns
true if the given parameter is at its default value

Definition at line 324 of file json_settings.cpp.

325 {
326  for( const PARAM_BASE* param : m_params )
327  {
328  if( param->GetJsonPath() == aParamName )
329  return param->IsDefault();
330  }
331 
332  return false;
333 }
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)

References JSON_SETTINGS::m_params.

◆ IsReadOnly()

bool JSON_SETTINGS::IsReadOnly ( ) const
inlineinherited

◆ Load()

void JSON_SETTINGS::Load ( )
virtualinherited

Updates the parameters of this object based on the current JSON document contents.

Definition at line 87 of file json_settings.cpp.

88 {
89  for( auto param : m_params )
90  {
91  try
92  {
93  param->Load( this, m_resetParamsIfMissing );
94  }
95  catch( ... )
96  {
97  // Skip unreadable parameters in file
98  wxLogTrace( traceSettings, "param '%s' load err", param->GetJsonPath().c_str() );
99  }
100  }
101 }
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
bool m_resetParamsIfMissing
Whether or not to set parameters to their default value if missing from JSON on Load()
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.

References JSON_SETTINGS::m_params, JSON_SETTINGS::m_resetParamsIfMissing, and traceSettings.

Referenced by COLOR_SETTINGS::CreateBuiltinColorSettings(), NESTED_SETTINGS::LoadFromFile(), JSON_SETTINGS::LoadFromFile(), BOARD_DESIGN_SETTINGS::LoadFromFile(), COLOR_SETTINGS::migrateSchema0to1(), and SETTINGS_MANAGER::SaveColorSettings().

◆ LoadFromFile()

bool JSON_SETTINGS::LoadFromFile ( const wxString &  aDirectory = "")
virtualinherited

Loads the backing file from disk and then calls Load()

Parameters
aDirectoryis the path to the file
Returns
true if the file was found on disk and loaded or migrated

Reimplemented in BOARD_DESIGN_SETTINGS, and NESTED_SETTINGS.

Definition at line 104 of file json_settings.cpp.

105 {
106  // First, load all params to default values
107  clear();
108  Load();
109 
110  bool success = true;
111  bool migrated = false;
112  bool legacy_migrated = false;
113 
114  LOCALE_IO locale;
115 
116  auto migrateFromLegacy = [&] ( wxFileName& aPath ) {
117  // Backup and restore during migration so that the original can be mutated if convenient
118  bool backed_up = false;
119  wxFileName temp;
120 
121  if( aPath.IsDirWritable() )
122  {
123  temp.AssignTempFileName( aPath.GetFullPath() );
124 
125  if( !wxCopyFile( aPath.GetFullPath(), temp.GetFullPath() ) )
126  {
127  wxLogTrace( traceSettings, "%s: could not create temp file for migration",
128  GetFullFilename() );
129  }
130  else
131  backed_up = true;
132  }
133 
134  // Silence popups if legacy file is read-only
135  wxLogNull doNotLog;
136 
137  wxConfigBase::DontCreateOnDemand();
138  auto cfg = std::make_unique<wxFileConfig>( wxT( "" ), wxT( "" ), aPath.GetFullPath() );
139 
140  // If migrate fails or is not implemented, fall back to built-in defaults that were
141  // already loaded above
142  if( !MigrateFromLegacy( cfg.get() ) )
143  {
144  wxLogTrace( traceSettings,
145  "%s: migrated; not all settings were found in legacy file",
146  GetFullFilename() );
147  }
148  else
149  {
150  wxLogTrace( traceSettings, "%s: migrated from legacy format", GetFullFilename() );
151  }
152 
153  if( backed_up )
154  {
155  cfg.reset();
156 
157  if( !wxCopyFile( temp.GetFullPath(), aPath.GetFullPath() ) )
158  {
159  wxLogTrace( traceSettings,
160  "migrate; copy temp file %s to %s failed",
161  temp.GetFullPath(), aPath.GetFullPath() );
162  }
163 
164  if( !wxRemoveFile( temp.GetFullPath() ) )
165  {
166  wxLogTrace( traceSettings,
167  "migrate; failed to remove temp file %s",
168  temp.GetFullPath() );
169  }
170  }
171 
172  // Either way, we want to clean up the old file afterwards
173  legacy_migrated = true;
174  };
175 
176  wxFileName path;
177 
178  if( aDirectory.empty() )
179  {
180  path.Assign( m_filename );
181  path.SetExt( getFileExt() );
182  }
183  else
184  {
185  wxString dir( aDirectory );
186  path.Assign( dir, m_filename, getFileExt() );
187  }
188 
189  if( !path.Exists() )
190  {
191  // Case 1: legacy migration, no .json extension yet
192  path.SetExt( getLegacyFileExt() );
193 
194  if( path.Exists() )
195  {
196  migrateFromLegacy( path );
197  }
198  // Case 2: legacy filename is different from new one
199  else if( !m_legacy_filename.empty() )
200  {
201  path.SetName( m_legacy_filename );
202 
203  if( path.Exists() )
204  migrateFromLegacy( path );
205  }
206  else
207  {
208  success = false;
209  }
210  }
211  else
212  {
213  if( !path.IsFileWritable() )
214  m_writeFile = false;
215 
216  try
217  {
218  FILE* fp = wxFopen( path.GetFullPath(), wxT( "rt" ) );
219 
220  if( fp )
221  {
222  *static_cast<nlohmann::json*>( this ) = nlohmann::json::parse( fp, nullptr,
223  /* allow_exceptions = */ true,
224  /* ignore_comments = */ true );
225 
226  // If parse succeeds, check if schema migration is required
227  int filever = -1;
228 
229  try
230  {
231  filever = at( PointerFromString( "meta.version" ) ).get<int>();
232  }
233  catch( ... )
234  {
235  wxLogTrace( traceSettings, "%s: file version could not be read!",
236  GetFullFilename() );
237  success = false;
238  }
239 
240  if( filever >= 0 && filever < m_schemaVersion )
241  {
242  wxLogTrace( traceSettings, "%s: attempting migration from version %d to %d",
243  GetFullFilename(), filever, m_schemaVersion );
244 
245  if( Migrate() )
246  {
247  migrated = true;
248  }
249  else
250  {
251  wxLogTrace( traceSettings, "%s: migration failed!", GetFullFilename() );
252  }
253  }
254  else if( filever > m_schemaVersion )
255  {
256  wxLogTrace( traceSettings,
257  "%s: warning: file version %d is newer than latest (%d)",
258  GetFullFilename(), filever, m_schemaVersion );
259  }
260  }
261  else
262  {
263  wxLogTrace( traceSettings, "%s exists but can't be opened for read",
264  GetFullFilename() );
265  }
266  }
267  catch( nlohmann::json::parse_error& error )
268  {
269  wxLogTrace( traceSettings, "Json parse error reading %s: %s",
270  path.GetFullPath(), error.what() );
271  wxLogTrace( traceSettings, "Attempting migration in case file is in legacy format" );
272  migrateFromLegacy( path );
273  }
274  }
275 
276  // Now that we have new data in the JSON structure, load the params again
277  Load();
278 
279  // And finally load any nested settings
280  for( auto settings : m_nested_settings )
281  settings->LoadFromFile();
282 
283  wxLogTrace( traceSettings, "Loaded <%s> with schema %d", GetFullFilename(), m_schemaVersion );
284 
285  // If we migrated, clean up the legacy file (with no extension)
286  if( legacy_migrated || migrated )
287  {
288  if( legacy_migrated && m_deleteLegacyAfterMigration && !wxRemoveFile( path.GetFullPath() ) )
289  {
290  wxLogTrace( traceSettings, "Warning: could not remove legacy file %s",
291  path.GetFullPath() );
292  }
293 
294  // And write-out immediately so that we don't lose data if the program later crashes.
296  SaveToFile( aDirectory, true );
297  }
298 
299  return success;
300 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
virtual wxString getLegacyFileExt() const
bool parse(std::istream &aStream, bool aVerbose)
Parse a PCB or footprint file from the given input stream.
wxString GetFullFilename() const
bool m_deleteLegacyAfterMigration
Whether or not to delete legacy file after migration.
wxString m_filename
The filename (not including path) of this settings file (inicode)
bool Migrate()
Migrates the schema of this settings from the version in the file to the latest version.
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
wxString m_legacy_filename
The filename of the wxConfig legacy file (if different from m_filename)
std::vector< NESTED_SETTINGS * > m_nested_settings
Nested settings files that live inside this one, if any.
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.
virtual wxString getFileExt() const
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.
virtual bool MigrateFromLegacy(wxConfigBase *aLegacyConfig)
Migrates from wxConfig to JSON-based configuration.
int m_schemaVersion
Version of this settings schema.
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
bool m_writeFile
Whether or not the backing store file should be written.

References JSON_SETTINGS::getFileExt(), JSON_SETTINGS::GetFullFilename(), JSON_SETTINGS::getLegacyFileExt(), JSON_SETTINGS::Load(), JSON_SETTINGS::m_deleteLegacyAfterMigration, JSON_SETTINGS::m_filename, JSON_SETTINGS::m_legacy_filename, JSON_SETTINGS::m_nested_settings, JSON_SETTINGS::m_schemaVersion, JSON_SETTINGS::m_writeFile, JSON_SETTINGS::Migrate(), JSON_SETTINGS::MigrateFromLegacy(), parse(), path, JSON_SETTINGS::PointerFromString(), JSON_SETTINGS::SaveToFile(), and traceSettings.

Referenced by SETTINGS_MANAGER::SaveColorSettings().

◆ Migrate()

bool JSON_SETTINGS::Migrate ( )
inherited

Migrates the schema of this settings from the version in the file to the latest version.

Schema migration doesn't need to be used every time a setting is added! This is intended to be more of an "escape hatch" in the event that we decide to move settings around or make other changes to a settings file format that can't simply be handled by loading a new default

Returns
true if migration was successful

Definition at line 464 of file json_settings.cpp.

465 {
466  int filever = at( PointerFromString( "meta.version" ) ).get<int>();
467 
468  while( filever < m_schemaVersion )
469  {
470  if( !m_migrators.count( filever ) )
471  {
472  wxLogTrace( traceSettings, "Migrator missing for %s version %d!",
473  typeid( *this ).name(), filever );
474  return false;
475  }
476 
477  std::pair<int, std::function<bool()>> pair = m_migrators.at( filever );
478 
479  if( pair.second() )
480  {
481  wxLogTrace( traceSettings, "Migrated %s from %d to %d", typeid( *this ).name(),
482  filever, pair.first );
483  filever = pair.first;
484  ( *this )[PointerFromString( "meta.version" )] = filever;
485  }
486  else
487  {
488  wxLogTrace( traceSettings, "Migration failed for %s from %d to %d",
489  typeid( *this ).name(), filever, pair.first );
490  return false;
491  }
492  }
493 
494  return true;
495 }
std::map< int, std::pair< int, std::function< bool()> > > m_migrators
A map of starting schema version to a pair of <ending version, migrator function>
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.
int m_schemaVersion
Version of this settings schema.

References JSON_SETTINGS::m_migrators, JSON_SETTINGS::m_schemaVersion, JSON_SETTINGS::PointerFromString(), and traceSettings.

Referenced by NESTED_SETTINGS::LoadFromFile(), and JSON_SETTINGS::LoadFromFile().

◆ MigrateFromLegacy()

bool COMMON_SETTINGS::MigrateFromLegacy ( wxConfigBase *  aLegacyConfig)
overridevirtual

Migrates from wxConfig to JSON-based configuration.

Should be implemented by any subclasses of JSON_SETTINGS that map to a legacy (wxConfig-based) config file.

Parameters
aLegacyConfigis a wxConfigBase holding a loaded configuration to migrate
Returns
true if migration was successful

Reimplemented from JSON_SETTINGS.

Definition at line 357 of file common_settings.cpp.

358 {
359  bool ret = true;
360 
361  ret &= fromLegacy<double>( aCfg, "CanvasScale", "appearance.canvas_scale" );
362  ret &= fromLegacy<int>( aCfg, "IconScale", "appearance.icon_scale" );
363  ret &= fromLegacy<bool>( aCfg, "UseIconsInMenus", "appearance.use_icons_in_menus" );
364 
365 // Force OSX to automatically scale the canvas. Before v6, the user setting wasn't used on OSX
366 // and was set to 1.0. In v6, the setting is now used by OSX and should default to automatic
367 // scaling.
368 #ifdef __WXMAC__
369  ( *this )[PointerFromString( "appearance.canvas_scale" )] = 0.0;
370 #endif
371 
372  ret &= fromLegacy<bool>( aCfg, "ShowEnvVarWarningDialog", "environment.show_warning_dialog" );
373 
374  auto load_env_vars = [&] () {
375  wxString key, value;
376  long index = 0;
377  nlohmann::json::json_pointer ptr = PointerFromString( "environment.vars" );
378 
379  aCfg->SetPath( "EnvironmentVariables" );
380  ( *this )[ptr] = nlohmann::json( {} );
381 
382  while( aCfg->GetNextEntry( key, index ) )
383  {
384  if( envVarBlacklist.count( key ) )
385  {
386  wxLogTrace( traceSettings, "Migrate Env: %s is blacklisted; skipping.", key );
387  continue;
388  }
389 
390  value = aCfg->Read( key, wxEmptyString );
391 
392  if( !value.IsEmpty() )
393  {
394  ptr.push_back( key.ToStdString() );
395 
396  wxLogTrace( traceSettings, "Migrate Env: %s=%s", ptr.to_string(), value );
397  ( *this )[ptr] = value.ToUTF8();
398 
399  ptr.pop_back();
400  }
401  }
402 
403  aCfg->SetPath( ".." );
404  };
405 
406  load_env_vars();
407 
408  bool mousewheel_pan = false;
409 
410  if( aCfg->Read( "MousewheelPAN", &mousewheel_pan ) && mousewheel_pan )
411  {
412  ( *this )[PointerFromString( "input.horizontal_pan" )] = true;
413 
414  ( *this )[PointerFromString( "input.scroll_modifier_pan_h" )] = WXK_SHIFT;
415  ( *this )[PointerFromString( "input.scroll_modifier_pan_v" )] = 0;
416  ( *this )[PointerFromString( "input.scroll_modifier_zoom" )] = WXK_CONTROL;
417  }
418 
419  ret &= fromLegacy<bool>( aCfg, "AutoPAN", "input.auto_pan" );
420  ret &= fromLegacy<bool>( aCfg, "ImmediateActions", "input.immediate_actions" );
421  ret &= fromLegacy<bool>( aCfg, "PreferSelectionToDragging", "input.prefer_select_to_drag" );
422  ret &= fromLegacy<bool>( aCfg, "MoveWarpsCursor", "input.warp_mouse_on_move" );
423  ret &= fromLegacy<bool>( aCfg, "ZoomNoCenter", "input.center_on_zoom" );
424 
425  // This was stored inverted in legacy config
426  if( ret )
427  {
428  auto p = PointerFromString( "input.center_on_zoom" );
429  ( *this )[p] = !( *this )[p];
430  }
431 
432  ret &= fromLegacy<int>( aCfg, "OpenGLAntialiasingMode", "graphics.opengl_antialiasing_mode" );
433  ret &= fromLegacy<int>( aCfg, "CairoAntialiasingMode", "graphics.cairo_antialiasing_mode" );
434 
435  ret &= fromLegacy<int>( aCfg, "AutoSaveInterval", "system.autosave_interval" );
436  ret &= fromLegacyString( aCfg, "Editor", "system.editor_name" );
437  ret &= fromLegacy<int>( aCfg, "FileHistorySize", "system.file_history_size" );
438  ret &= fromLegacyString( aCfg, "LanguageID", "system.language" );
439  ret &= fromLegacyString( aCfg, "PdfBrowserName", "system.pdf_viewer_name" );
440  ret &= fromLegacy<bool>( aCfg, "UseSystemBrowser", "system.use_system_pdf_viewer" );
441  ret &= fromLegacyString( aCfg, "WorkingDir", "system.working_dir" );
442 
443  return ret;
444 }
nlohmann::json json
Definition: gerbview.cpp:41
bool fromLegacyString(wxConfigBase *aConfig, const std::string &aKey, const std::string &aDest)
Translates a legacy wxConfig string value to a given JSON pointer value.
const std::set< wxString > envVarBlacklist
! The following environment variables will never be migrated from a previous version
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References envVarBlacklist, JSON_SETTINGS::fromLegacyString(), JSON_SETTINGS::PointerFromString(), and traceSettings.

◆ migrateSchema0to1()

bool COMMON_SETTINGS::migrateSchema0to1 ( )
private

Schema version 0 to 1:

mousewheel_pan is replaced by explicit settings for scroll wheel behavior

Definition at line 289 of file common_settings.cpp.

290 {
297  nlohmann::json::json_pointer mwp_pointer( "/input/mousewheel_pan"_json_pointer );
298 
299  bool mwp = false;
300 
301  try
302  {
303  mwp = at( mwp_pointer );
304  at( nlohmann::json::json_pointer( "/input"_json_pointer ) ).erase( "mousewheel_pan" );
305  }
306  catch( ... )
307  {
308  wxLogTrace( traceSettings, "COMMON_SETTINGS::Migrate 0->1: mousewheel_pan not found" );
309  }
310 
311  if( mwp )
312  {
313  ( *this )[nlohmann::json::json_pointer( "/input/horizontal_pan" )] = true;
314 
315  ( *this )[nlohmann::json::json_pointer( "/input/scroll_modifier_pan_h" )] = WXK_SHIFT;
316  ( *this )[nlohmann::json::json_pointer( "/input/scroll_modifier_pan_v" )] = 0;
317  ( *this )[nlohmann::json::json_pointer( "/input/scroll_modifier_zoom" )] = WXK_CONTROL;
318  }
319  else
320  {
321  ( *this )[nlohmann::json::json_pointer( "/input/horizontal_pan" )] = false;
322 
323  ( *this )[nlohmann::json::json_pointer( "/input/scroll_modifier_pan_h" )] = WXK_CONTROL;
324  ( *this )[nlohmann::json::json_pointer( "/input/scroll_modifier_pan_v" )] = WXK_SHIFT;
325  ( *this )[nlohmann::json::json_pointer( "/input/scroll_modifier_zoom" )] = 0;
326  }
327 
328  return true;
329 }
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.

References traceSettings.

◆ migrateSchema1to2()

bool COMMON_SETTINGS::migrateSchema1to2 ( )
private

Definition at line 332 of file common_settings.cpp.

333 {
334  nlohmann::json::json_pointer v1_pointer( "/input/prefer_select_to_drag"_json_pointer );
335 
336  bool prefer_selection = false;
337 
338  try
339  {
340  prefer_selection = at( v1_pointer );
341  at( nlohmann::json::json_pointer( "/input"_json_pointer ) ).erase( "prefer_select_to_drag" );
342  }
343  catch( ... )
344  {
345  wxLogTrace( traceSettings, "COMMON_SETTINGS::Migrate 1->2: prefer_select_to_drag not found" );
346  }
347 
348  if( prefer_selection )
349  ( *this )[nlohmann::json::json_pointer( "/input/mouse_left" )] = MOUSE_DRAG_ACTION::SELECT;
350  else
351  ( *this )[nlohmann::json::json_pointer( "/input/mouse_left" )] = MOUSE_DRAG_ACTION::DRAG_ANY;
352 
353  return true;
354 }
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.

References DRAG_ANY, SELECT, and traceSettings.

◆ PointerFromString()

nlohmann::json::json_pointer JSON_SETTINGS::PointerFromString ( std::string  aPath)
staticinherited

Builds a JSON pointer based on a given string.

Parameters
aPathis the path in the form "key1.key2.key3"
Returns
a JSON pointer that can be used to index into a JSON object

Definition at line 506 of file json_settings.cpp.

507 {
508  std::replace( aPath.begin(), aPath.end(), '.', '/' );
509  aPath.insert( 0, "/" );
510 
511  nlohmann::json::json_pointer p;
512 
513  try
514  {
515  p = nlohmann::json::json_pointer( aPath );
516  }
517  catch( ... )
518  {
519  wxASSERT_MSG( false, wxT( "Invalid pointer path in PointerFromString!" ) );
520  }
521 
522  return p;
523 }

Referenced by JSON_SETTINGS::fromLegacy(), JSON_SETTINGS::fromLegacyColor(), JSON_SETTINGS::fromLegacyString(), JSON_SETTINGS::GetJson(), JSON_SETTINGS::JSON_SETTINGS(), NESTED_SETTINGS::LoadFromFile(), JSON_SETTINGS::LoadFromFile(), BOARD_DESIGN_SETTINGS::LoadFromFile(), JSON_SETTINGS::Migrate(), EESCHEMA_SETTINGS::migrateBomSettings(), APP_SETTINGS_BASE::migrateFindReplace(), FOOTPRINT_EDITOR_SETTINGS::MigrateFromLegacy(), GERBVIEW_SETTINGS::MigrateFromLegacy(), SYMBOL_EDITOR_SETTINGS::MigrateFromLegacy(), PROJECT_FILE::MigrateFromLegacy(), EDA_3D_VIEWER_SETTINGS::MigrateFromLegacy(), PCB_CALCULATOR_SETTINGS::MigrateFromLegacy(), MigrateFromLegacy(), APP_SETTINGS_BASE::MigrateFromLegacy(), EESCHEMA_SETTINGS::MigrateFromLegacy(), PCBNEW_SETTINGS::MigrateFromLegacy(), SETTINGS_MANAGER::SaveColorSettings(), NESTED_SETTINGS::SaveToFile(), PROJECT_LOCAL_SETTINGS::SaveToFile(), PROJECT_FILE::SaveToFile(), JSON_SETTINGS::Set(), and JSON_SETTINGS::SetIfPresent().

◆ registerMigration()

void JSON_SETTINGS::registerMigration ( int  aOldSchemaVersion,
int  aNewSchemaVersion,
std::function< bool(void)>  aMigrator 
)
protectedinherited

Registers a migration from one schema version to another.

If the schema version in the file loaded from disk is less than the schema version of the JSON_SETTINGS class, migration functions will be called one after the other until the data is up-to-date.

Parameters
aOldSchemaVersionis the starting schema version for this migration
aNewSchemaVersionis the ending schema version for this migration
aMigratoris a function that performs the migration and returns true if successful

Definition at line 455 of file json_settings.cpp.

457 {
458  wxASSERT( aNewSchemaVersion > aOldSchemaVersion );
459  wxASSERT( aNewSchemaVersion <= m_schemaVersion );
460  m_migrators[aOldSchemaVersion] = std::make_pair( aNewSchemaVersion, aMigrator );
461 }
std::map< int, std::pair< int, std::function< bool()> > > m_migrators
A map of starting schema version to a pair of <ending version, migrator function>
int m_schemaVersion
Version of this settings schema.

References JSON_SETTINGS::m_migrators, and JSON_SETTINGS::m_schemaVersion.

Referenced by BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS(), COLOR_SETTINGS::COLOR_SETTINGS(), EESCHEMA_SETTINGS::EESCHEMA_SETTINGS(), FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS(), and PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS().

◆ ReleaseNestedSettings()

void JSON_SETTINGS::ReleaseNestedSettings ( NESTED_SETTINGS aSettings)
inherited

Saves and frees a nested settings object, if it exists within this one.

Parameters
aSettingsis a pointer to a NESTED_SETTINGS that has already been added to this one

Definition at line 682 of file json_settings.cpp.

683 {
684  if( !aSettings )
685  return;
686 
687  auto it = std::find_if( m_nested_settings.begin(), m_nested_settings.end(),
688  [&aSettings]( const JSON_SETTINGS* aPtr ) {
689  return aPtr == aSettings;
690  } );
691 
692  if( it != m_nested_settings.end() )
693  {
694  wxLogTrace( traceSettings, "Flush and release %s", ( *it )->GetFilename() );
695  ( *it )->SaveToFile();
696  m_nested_settings.erase( it );
697  }
698 
699  aSettings->SetParent( nullptr );
700 }
void SetParent(JSON_SETTINGS *aParent, bool aLoadFromFile=true)
std::vector< NESTED_SETTINGS * > m_nested_settings
Nested settings files that live inside this one, if any.
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.

References JSON_SETTINGS::m_nested_settings, NESTED_SETTINGS::SetParent(), and traceSettings.

Referenced by BOARD_DESIGN_SETTINGS::~BOARD_DESIGN_SETTINGS(), ERC_SETTINGS::~ERC_SETTINGS(), NESTED_SETTINGS::~NESTED_SETTINGS(), NET_SETTINGS::~NET_SETTINGS(), and SCHEMATIC_SETTINGS::~SCHEMATIC_SETTINGS().

◆ ResetToDefaults()

void JSON_SETTINGS::ResetToDefaults ( )
inherited

Resets all parameters to default values.

Does NOT write to file or update underlying JSON.

Definition at line 317 of file json_settings.cpp.

318 {
319  for( auto param : m_params )
320  param->SetDefault();
321 }
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)

References JSON_SETTINGS::m_params.

Referenced by EDA_3D_VIEWER::Process_Special_Functions(), PANEL_COMMON_SETTINGS::ResetPanel(), and PANEL_MOUSE_SETTINGS::ResetPanel().

◆ SaveToFile()

bool JSON_SETTINGS::SaveToFile ( const wxString &  aDirectory = "",
bool  aForce = false 
)
virtualinherited
   Calls Store() and then writes the contents of the JSON document to a file
   @param aDirectory is the directory to save to, including trailing separator

c *

Returns
true if the file was saved

Reimplemented in PROJECT_FILE, PROJECT_LOCAL_SETTINGS, and NESTED_SETTINGS.

Definition at line 336 of file json_settings.cpp.

337 {
338  if( !m_writeFile )
339  return false;
340 
341  // Default PROJECT won't have a filename set
342  if( m_filename.IsEmpty() )
343  return false;
344 
345  wxFileName path;
346 
347  if( aDirectory.empty() )
348  {
349  path.Assign( m_filename );
350  path.SetExt( getFileExt() );
351  }
352  else
353  {
354  wxString dir( aDirectory );
355  path.Assign( dir, m_filename, getFileExt() );
356  }
357 
358  if( !m_createIfMissing && !path.FileExists() )
359  {
360  wxLogTrace( traceSettings,
361  "File for %s doesn't exist and m_createIfMissing == false; not saving",
362  GetFullFilename() );
363  return false;
364  }
365 
366  // Ensure the path exists, and create it if not.
367  if( !path.DirExists() && !path.Mkdir() )
368  {
369  wxLogTrace( traceSettings, "Warning: could not create path %s, can't save %s",
370  path.GetPath(), GetFullFilename() );
371  return false;
372  }
373 
374  if( ( path.FileExists() && !path.IsFileWritable() ) ||
375  ( !path.FileExists() && !path.IsDirWritable() ) )
376  {
377  wxLogTrace( traceSettings, "File for %s is read-only; not saving", GetFullFilename() );
378  return false;
379  }
380 
381  bool modified = false;
382 
383  for( auto settings : m_nested_settings )
384  modified |= settings->SaveToFile();
385 
386  modified |= Store();
387 
388  if( !modified && !aForce && path.FileExists() )
389  {
390  wxLogTrace( traceSettings, "%s contents not modified, skipping save", GetFullFilename() );
391  return false;
392  }
393  else if( !modified && !aForce && !m_createIfDefault )
394  {
395  wxLogTrace( traceSettings,
396  "%s contents still default and m_createIfDefault == false; not saving",
397  GetFullFilename() );
398  return false;
399  }
400 
401  wxLogTrace( traceSettings, "Saving %s", GetFullFilename() );
402 
404  bool success = true;
405 
406  try
407  {
408  std::stringstream buffer;
409  buffer << std::setw( 2 ) << *this << std::endl;
410 
411  wxFFileOutputStream fileStream( path.GetFullPath(), "wb" );
412 
413  if( !fileStream.IsOk()
414  || !fileStream.WriteAll( buffer.str().c_str(), buffer.str().size() ) )
415  {
416  wxLogTrace( traceSettings, "Warning: could not save %s", GetFullFilename() );
417  success = false;
418  }
419  }
420  catch( nlohmann::json::exception& error )
421  {
422  wxLogTrace( traceSettings, "Catch error: could not save %s. Json error %s",
423  GetFullFilename(), error.what() );
424  success = false;
425  }
426  catch( ... )
427  {
428  wxLogTrace( traceSettings, "Error: could not save %s." );
429  success = false;
430  }
431 
432  return success;
433 }
virtual bool Store()
Stores the current parameters into the JSON document represented by this object Note: this doesn't do...
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
bool m_createIfMissing
Whether or not the backing store file should be created it if doesn't exist.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
wxString GetFullFilename() const
wxString m_filename
The filename (not including path) of this settings file (inicode)
std::vector< NESTED_SETTINGS * > m_nested_settings
Nested settings files that live inside this one, if any.
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.
bool m_createIfDefault
Whether or not the backing store file should be created if all parameters are still at their default ...
virtual wxString getFileExt() const
bool m_writeFile
Whether or not the backing store file should be written.

References dummy(), JSON_SETTINGS::getFileExt(), JSON_SETTINGS::GetFullFilename(), JSON_SETTINGS::m_createIfDefault, JSON_SETTINGS::m_createIfMissing, JSON_SETTINGS::m_filename, JSON_SETTINGS::m_nested_settings, JSON_SETTINGS::m_writeFile, path, JSON_SETTINGS::Store(), and traceSettings.

Referenced by JSON_SETTINGS::LoadFromFile(), PANEL_COLOR_SETTINGS::OnThemeChanged(), SETTINGS_MANAGER::SaveColorSettings(), PROJECT_LOCAL_SETTINGS::SaveToFile(), PROJECT_FILE::SaveToFile(), and PGM_BASE::SetLanguage().

◆ Set() [1/3]

template<typename ValueType >
void JSON_SETTINGS::Set ( const std::string &  aPath,
ValueType  aVal 
)
inlineinherited

Stores a value into the JSON document Will throw an exception if ValueType isn't something that the library can handle.

Template Parameters
ValueTypeis the type to store
Parameters
aPathis a path to store in the form "key1.key2.key3"
aValis the value to store

Definition at line 157 of file json_settings.h.

158  {
159  ( *this )[PointerFromString( aPath ) ] = aVal;
160  }
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References JSON_SETTINGS::PointerFromString().

Referenced by COLOR_MAP_PARAM::Store(), PARAM< wxString >::Store(), PARAM_PATH::Store(), PARAM_ENUM< EnumType >::Store(), PARAM_LAMBDA< nlohmann::json >::Store(), PARAM_SCALED< ValueType >::Store(), PARAM_LIST< wxString >::Store(), PARAM_PATH_LIST::Store(), PARAM_MAP< Value >::Store(), and PARAM_WXSTRING_MAP::Store().

◆ Set() [2/3]

template<>
void JSON_SETTINGS::Set ( const std::string &  aPath,
wxString  aVal 
)
inherited

◆ Set() [3/3]

template<>
void JSON_SETTINGS::Set ( const std::string &  aPath,
wxString  aVal 
)
inherited

Definition at line 714 of file json_settings.cpp.

715 {
716  ( *this )[PointerFromString( std::move( aPath ) ) ] = aVal.ToUTF8();
717 }
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References JSON_SETTINGS::PointerFromString().

◆ SetFilename()

void JSON_SETTINGS::SetFilename ( const wxString &  aFilename)
inlineinherited

Definition at line 70 of file json_settings.h.

70 { m_filename = aFilename; }
wxString m_filename
The filename (not including path) of this settings file (inicode)

References JSON_SETTINGS::m_filename.

Referenced by SETTINGS_MANAGER::SaveProjectAs(), and SETTINGS_MANAGER::SaveProjectCopy().

◆ SetIfPresent() [1/4]

bool JSON_SETTINGS::SetIfPresent ( const nlohmann::json aObj,
const std::string &  aPath,
wxString &  aTarget 
)
staticinherited

Sets the given string if the given key/path is present.

Parameters
aObjis the source object
aTargetis the storage destination
Returns
True if set, false if not

Definition at line 526 of file json_settings.cpp.

528 {
529  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
530 
531  if( aObj.contains( ptr ) && aObj.at( ptr ).is_string() )
532  {
533  aTarget = aObj.at( ptr ).get<wxString>();
534  return true;
535  }
536 
537  return false;
538 }
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References JSON_SETTINGS::PointerFromString().

Referenced by FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS(), and PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS().

◆ SetIfPresent() [2/4]

bool JSON_SETTINGS::SetIfPresent ( const nlohmann::json aObj,
const std::string &  aPath,
bool &  aTarget 
)
staticinherited

Sets the given bool if the given key/path is present.

Parameters
aObjis the source object
aTargetis the storage destination
Returns
True if set, false if not

Definition at line 541 of file json_settings.cpp.

543 {
544  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
545 
546  if( aObj.contains( ptr ) && aObj.at( ptr ).is_boolean() )
547  {
548  aTarget = aObj.at( ptr ).get<bool>();
549  return true;
550  }
551 
552  return false;
553 }
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References JSON_SETTINGS::PointerFromString().

◆ SetIfPresent() [3/4]

bool JSON_SETTINGS::SetIfPresent ( const nlohmann::json aObj,
const std::string &  aPath,
int &  aTarget 
)
staticinherited

Sets the given int if the given key/path is present.

Parameters
aObjis the source object
aTargetis the storage destination
Returns
True if set, false if not

Definition at line 556 of file json_settings.cpp.

558 {
559  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
560 
561  if( aObj.contains( ptr ) && aObj.at( ptr ).is_number_integer() )
562  {
563  aTarget = aObj.at( ptr ).get<int>();
564  return true;
565  }
566 
567  return false;
568 }
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References JSON_SETTINGS::PointerFromString().

◆ SetIfPresent() [4/4]

bool JSON_SETTINGS::SetIfPresent ( const nlohmann::json aObj,
const std::string &  aPath,
unsigned int &  aTarget 
)
staticinherited

Sets the given unsigned int if the given key/path is present.

Parameters
aObjis the source object
aTargetis the storage destination
Returns
True if set, false if not

Definition at line 571 of file json_settings.cpp.

573 {
574  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
575 
576  if( aObj.contains( ptr ) && aObj.at( ptr ).is_number_unsigned() )
577  {
578  aTarget = aObj.at( ptr ).get<unsigned int>();
579  return true;
580  }
581 
582  return false;
583 }
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References JSON_SETTINGS::PointerFromString().

◆ SetLegacyFilename()

void JSON_SETTINGS::SetLegacyFilename ( const wxString &  aFilename)
inlineinherited

Definition at line 74 of file json_settings.h.

74 { m_legacy_filename = aFilename; }
wxString m_legacy_filename
The filename of the wxConfig legacy file (if different from m_filename)

References JSON_SETTINGS::m_legacy_filename.

Referenced by SYMBOL_EDITOR_SETTINGS::SYMBOL_EDITOR_SETTINGS().

◆ SetManager()

void JSON_SETTINGS::SetManager ( SETTINGS_MANAGER aManager)
inlineinherited

Definition at line 197 of file json_settings.h.

198  {
199  m_manager = aManager;
200  }
SETTINGS_MANAGER * m_manager
A pointer to the settings manager managing this file (may be null)

References JSON_SETTINGS::m_manager.

◆ SetReadOnly()

void JSON_SETTINGS::SetReadOnly ( bool  aReadOnly)
inlineinherited

Definition at line 77 of file json_settings.h.

77 { m_writeFile = !aReadOnly; }
bool m_writeFile
Whether or not the backing store file should be written.

References JSON_SETTINGS::m_writeFile.

Referenced by PANEL_COLOR_SETTINGS::OnThemeChanged().

◆ Store()

bool JSON_SETTINGS::Store ( )
virtualinherited

Stores the current parameters into the JSON document represented by this object Note: this doesn't do any writing to disk; that's handled by SETTINGS_MANAGER.

Returns
true if any part of the JSON document was updated

Definition at line 303 of file json_settings.cpp.

304 {
305  bool modified = false;
306 
307  for( auto param : m_params )
308  {
309  modified |= !param->MatchesFile( this );
310  param->Store( this );
311  }
312 
313  return modified;
314 }
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)

References JSON_SETTINGS::m_params.

Referenced by PANEL_FP_EDITOR_COLOR_SETTINGS::PANEL_FP_EDITOR_COLOR_SETTINGS(), SETTINGS_MANAGER::SaveColorSettings(), NESTED_SETTINGS::SaveToFile(), and JSON_SETTINGS::SaveToFile().

Member Data Documentation

◆ m_3DLibsDownloadPath

wxString COMMON_SETTINGS::m_3DLibsDownloadPath

Definition at line 161 of file common_settings.h.

◆ m_3DLibsUrl

wxString COMMON_SETTINGS::m_3DLibsUrl

Definition at line 159 of file common_settings.h.

◆ m_Appearance

◆ m_Backup

◆ m_createIfDefault

bool JSON_SETTINGS::m_createIfDefault
protectedinherited

Whether or not the backing store file should be created if all parameters are still at their default values.

Ignored if m_createIfMissing is false or m_writeFile is false.

Definition at line 315 of file json_settings.h.

Referenced by JSON_SETTINGS::SaveToFile().

◆ m_createIfMissing

bool JSON_SETTINGS::m_createIfMissing
protectedinherited

Whether or not the backing store file should be created it if doesn't exist.

Definition at line 309 of file json_settings.h.

Referenced by JSON_SETTINGS::SaveToFile().

◆ m_deleteLegacyAfterMigration

bool JSON_SETTINGS::m_deleteLegacyAfterMigration
protectedinherited

Whether or not to delete legacy file after migration.

Definition at line 321 of file json_settings.h.

Referenced by JSON_SETTINGS::LoadFromFile(), and PROJECT_FILE::PROJECT_FILE().

◆ m_Env

◆ m_filename

◆ m_Graphics

◆ m_Input

◆ m_legacy_filename

wxString JSON_SETTINGS::m_legacy_filename
protectedinherited

The filename of the wxConfig legacy file (if different from m_filename)

Definition at line 297 of file json_settings.h.

Referenced by JSON_SETTINGS::LoadFromFile(), and JSON_SETTINGS::SetLegacyFilename().

◆ m_location

SETTINGS_LOC JSON_SETTINGS::m_location
protectedinherited

The location of this settings file (.

See also
SETTINGS_LOC)

Definition at line 300 of file json_settings.h.

Referenced by JSON_SETTINGS::GetLocation().

◆ m_manager

SETTINGS_MANAGER* JSON_SETTINGS::m_manager
protectedinherited

A pointer to the settings manager managing this file (may be null)

Definition at line 330 of file json_settings.h.

Referenced by FOOTPRINT_EDITOR_SETTINGS::migrateSchema0to1(), COLOR_SETTINGS::migrateSchema0to1(), and JSON_SETTINGS::SetManager().

◆ m_migrators

std::map<int, std::pair<int, std::function<bool()> > > JSON_SETTINGS::m_migrators
protectedinherited

A map of starting schema version to a pair of <ending version, migrator function>

Definition at line 336 of file json_settings.h.

Referenced by JSON_SETTINGS::Migrate(), and JSON_SETTINGS::registerMigration().

◆ m_nested_settings

std::vector<NESTED_SETTINGS*> JSON_SETTINGS::m_nested_settings
protectedinherited

Nested settings files that live inside this one, if any.

Definition at line 306 of file json_settings.h.

Referenced by JSON_SETTINGS::AddNestedSettings(), JSON_SETTINGS::LoadFromFile(), JSON_SETTINGS::ReleaseNestedSettings(), and JSON_SETTINGS::SaveToFile().

◆ m_NetclassPanel

◆ m_params

◆ m_preserved_paths

std::vector<nlohmann::json::json_pointer> JSON_SETTINGS::m_preserved_paths
protectedinherited

A list of JSON pointers that are preserved during a read-update-write to disk.

Definition at line 333 of file json_settings.h.

◆ m_resetParamsIfMissing

bool JSON_SETTINGS::m_resetParamsIfMissing
protectedinherited

Whether or not to set parameters to their default value if missing from JSON on Load()

Definition at line 324 of file json_settings.h.

Referenced by BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS(), and JSON_SETTINGS::Load().

◆ m_schemaVersion

int JSON_SETTINGS::m_schemaVersion
protectedinherited

◆ m_Session

SESSION COMMON_SETTINGS::m_Session

◆ m_System

◆ m_writeFile

bool JSON_SETTINGS::m_writeFile
protectedinherited

The documentation for this class was generated from the following files: