KiCad PCB EDA Suite
SCHEMATIC_SETTINGS Class Reference

These settings were stored in SCH_BASE_FRAME previously. More...

#include <schematic_settings.h>

Inheritance diagram for SCHEMATIC_SETTINGS:
NESTED_SETTINGS JSON_SETTINGS

Public Member Functions

 SCHEMATIC_SETTINGS (JSON_SETTINGS *aParent, const std::string &aPath)
 
virtual ~SCHEMATIC_SETTINGS ()
 
bool LoadFromFile (const wxString &aDirectory="") override
 Loads the JSON document from the parent and then calls Load() More...
 
bool SaveToFile (const wxString &aDirectory="", bool aForce=false) override
 Calls Store() and then saves the JSON document contents into the parent JSON_SETTINGS. More...
 
void SetParent (JSON_SETTINGS *aParent)
 
JSON_SETTINGSGetParent ()
 
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...
 
void ResetToDefaults ()
 Resets all parameters to default values. 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...
 
virtual bool MigrateFromLegacy (wxConfigBase *aLegacyConfig)
 Migrates from wxConfig to JSON-based configuration. 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

int m_DefaultLineWidth
 
int m_DefaultWireThickness
 
int m_DefaultBusThickness
 
int m_DefaultTextSize
 
double m_TextOffsetRatio
 
int m_PinSymbolSize
 
int m_JunctionSize
 
bool m_IntersheetsRefShow
 
bool m_IntersheetsRefFormatShort
 
wxString m_IntersheetsRefPrefix
 
wxString m_IntersheetsRefSuffix
 
wxString m_PageLayoutDescrFile
 
wxString m_PlotDirectoryName
 
wxString m_NetFormatName
 
bool m_SpiceAdjustPassiveValues
 
wxString m_SpiceCommandString
 
TEMPLATES m_TemplateFieldNames
 

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

JSON_SETTINGSm_parent
 A pointer to the parent object to load and store from. More...
 
std::string m_path
 The path (in pointer format) of where to store this document in the parent. More...
 
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...
 

Detailed Description

These settings were stored in SCH_BASE_FRAME previously.

The backing store is currently the project file. They should likely move to a project settings file (JSON) once that framework exists.

These are loaded from eeschema settings but then overwritten by the project settings. All of the values are stored in IU, but the backing file stores in mils.

Definition at line 36 of file schematic_settings.h.

Constructor & Destructor Documentation

◆ SCHEMATIC_SETTINGS()

SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS ( JSON_SETTINGS aParent,
const std::string &  aPath 
)

Definition at line 35 of file schematic_settings.cpp.

35  :
36  NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath ),
41  m_TextOffsetRatio( 0.08 ),
44  m_IntersheetsRefShow( false ),
49 {
50  EESCHEMA_SETTINGS* appSettings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
51 
52  int defaultLineThickness =
53  appSettings ? appSettings->m_Drawing.default_line_thickness : DEFAULT_LINE_THICKNESS;
54  int defaultWireThickness =
55  appSettings ? appSettings->m_Drawing.default_wire_thickness : DEFAULT_WIRE_THICKNESS;
56  int defaultBusThickness =
57  appSettings ? appSettings->m_Drawing.default_bus_thickness : DEFAULT_BUS_THICKNESS;
58  int defaultTextSize =
59  appSettings ? appSettings->m_Drawing.default_text_size : DEFAULT_TEXT_SIZE;
60  int defaultPinSymbolSize =
61  appSettings ? appSettings->m_Drawing.pin_symbol_size : DEFAULT_TEXT_SIZE / 2;
62  int defaultJunctionSize =
63  appSettings ? appSettings->m_Drawing.default_junction_size : DEFAULT_JUNCTION_DIAM;
64  bool defaultIntersheetsRefShow =
65  appSettings ? appSettings->m_Drawing.intersheets_ref_show : false;
66  bool defaultIntersheetsRefFormatShort =
67  appSettings ? appSettings->m_Drawing.intersheets_ref_short : false;
68  wxString defaultIntersheetsRefPrefix =
69  appSettings ? appSettings->m_Drawing.intersheets_ref_prefix : DEFAULT_IREF_PREFIX;
70  wxString defaultIntersheetsRefSuffix =
71  appSettings ? appSettings->m_Drawing.intersheets_ref_suffix : DEFAULT_IREF_SUFFIX;
72 
73  m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_show",
74  &m_IntersheetsRefShow, defaultIntersheetsRefShow ) );
75 
76  m_params.emplace_back( new PARAM<bool>( "drawing.intersheets_ref_short",
77  &m_IntersheetsRefFormatShort, defaultIntersheetsRefFormatShort ) );
78 
79  m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_prefix",
80  &m_IntersheetsRefPrefix, defaultIntersheetsRefPrefix ) );
81 
82  m_params.emplace_back( new PARAM<wxString>( "drawing.intersheets_ref_suffix",
83  &m_IntersheetsRefSuffix, defaultIntersheetsRefSuffix ) );
84 
85  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_line_thickness",
86  &m_DefaultLineWidth, Mils2iu( defaultLineThickness ),
87  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
88 
89  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_wire_thickness",
90  &m_DefaultWireThickness, Mils2iu( defaultWireThickness ),
91  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
92 
93  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_bus_thickness",
94  &m_DefaultBusThickness, Mils2iu( defaultBusThickness ),
95  Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
96 
97  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_text_size",
99  Mils2iu( defaultTextSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
100  1 / IU_PER_MILS ) );
101 
102  m_params.emplace_back( new PARAM<double>( "drawing.text_offset_ratio",
104  (double) TXT_MARGIN / DEFAULT_SIZE_TEXT, -200.0, 200.0 ) );
105 
106  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.pin_symbol_size",
108  Mils2iu( defaultPinSymbolSize ), Mils2iu( 5 ), Mils2iu( 1000 ),
109  1 / IU_PER_MILS ) );
110 
111  m_params.emplace_back( new PARAM_SCALED<int>( "drawing.default_junction_size",
113  Mils2iu( defaultJunctionSize ), Mils2iu( 5 ), Mils2iu( 1000 ), 1 / IU_PER_MILS ) );
114 
115  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "drawing.field_names",
116  [&]() -> nlohmann::json
117  {
118  nlohmann::json ret = nlohmann::json::array();
119 
120  for( const TEMPLATE_FIELDNAME& field :
122  {
123  ret.push_back( nlohmann::json( {
124  { "name", field.m_Name },
125  { "visible", field.m_Visible },
126  { "url", field.m_URL }
127  } ) );
128  }
129 
130  auto* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
131 
132  if( cfg )
133  {
134  // Save global fieldname templates
135  STRING_FORMATTER sf;
136  m_TemplateFieldNames.Format( &sf, 0, true );
137 
138  wxString record = FROM_UTF8( sf.GetString().c_str() );
139  record.Replace( wxT("\n"), wxT(""), true ); // strip all newlines
140  record.Replace( wxT(" "), wxT(" "), true ); // double space to single
141 
142  cfg->m_Drawing.field_names = record.ToStdString();
143  }
144 
145  return ret;
146  },
147  [&]( const nlohmann::json& aJson )
148  {
149  if( aJson.empty() || !aJson.is_array() )
150  return;
151 
153 
154  for( const nlohmann::json& entry : aJson )
155  {
156  if( !entry.contains( "name" ) || !entry.contains( "url" )
157  || !entry.contains( "visible" ) )
158  continue;
159 
160  TEMPLATE_FIELDNAME field( entry["name"].get<wxString>() );
161  field.m_URL = entry["url"].get<bool>();
162  field.m_Visible = entry["visible"].get<bool>();
164  }
165 
166  auto* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
167 
168  if( cfg )
169  {
170  // Read global fieldname templates
171  wxString templateFieldNames = cfg->m_Drawing.field_names;
172 
173  if( !templateFieldNames.IsEmpty() )
174  {
175  TEMPLATE_FIELDNAMES_LEXER field_lexer( TO_UTF8( templateFieldNames ) );
176 
177  try
178  {
179  m_TemplateFieldNames.Parse( &field_lexer, true );
180  }
181  catch( const IO_ERROR& )
182  {
183  }
184  }
185  }
186  }, {} ) );
187 
188  // TOOD(JE) get rid of this static
189  m_params.emplace_back( new PARAM<wxString>( "page_layout_descr_file",
191 
192  m_params.emplace_back( new PARAM<wxString>( "plot_directory",
193  &m_PlotDirectoryName, "" ) );
194 
195  m_params.emplace_back( new PARAM<wxString>( "net_format_name",
196  &m_NetFormatName, "" ) );
197 
198  m_params.emplace_back( new PARAM<bool>( "spice_adjust_passive_values",
199  &m_SpiceAdjustPassiveValues, false ) );
200 
201  m_params.emplace_back( new PARAM<wxString>( "spice_external_command",
202  &m_SpiceCommandString, "spice \"%I\"" ) );
203 
204  // TODO(JE) should we keep these LIB_PART:: things around?
205  m_params.emplace_back( new PARAM<int>( "subpart_id_separator",
206  LIB_PART::SubpartIdSeparatorPtr(), 0, 0, 126 ) );
207 
208  m_params.emplace_back( new PARAM<int>( "subpart_first_id",
209  LIB_PART::SubpartFirstIdPtr(), 'A', '1', 'z' ) );
210 }
void Format(OUTPUTFORMATTER *out, int nestLevel, bool aGlobal) const
Function Format serializes this object out as text into the given OUTPUTFORMATTER.
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:75
static int * SubpartFirstIdPtr()
return a reference to m_subpartFirstId, only for read/save setting functions
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:115
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Function AddTemplateFieldName inserts or appends a wanted symbol field name into the fieldnames templ...
void Parse(TEMPLATE_FIELDNAMES_LEXER *in, bool aGlobal)
Function Parse fills this object from information in the input stream handled by TEMPLATE_FIELDNAMES_...
TEMPLATES m_TemplateFieldNames
#define DEFAULT_JUNCTION_DIAM
The default bus and wire enty size in mils.
void DeleteAllFieldNameTemplates(bool aGlobal)
Function DeleteAllFieldNameTemplates deletes the entire contents.
nlohmann::json json
Definition: gerbview.cpp:39
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
Definition: base_screen.h:56
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:101
#define DEFAULT_IREF_PREFIX
The intersheets references suffix string.
const int schSettingsSchemaVersion
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Represents a parameter that has a scaling factor between the value in the file and the value used int...
Definition: parameters.h:388
const std::string & GetString()
Definition: richio.h:476
#define DEFAULT_IREF_SUFFIX
#define DEFAULT_LINE_THICKNESS
The default wire width in mils. (can be changed in preference menu)
#define DEFAULT_BUS_THICKNESS
The default noconnect size in mils.
#define TXT_MARGIN
The default pin len value when creating pins(can be changed in preference menu)
#define DEFAULT_WIRE_THICKNESS
The default bus width in mils. (can be changed in preference menu)
NESTED_SETTINGS(const std::string &aName, int aSchemaVersion, JSON_SETTINGS *aParent, const std::string &aPath)
#define IU_PER_MILS
Definition: plotter.cpp:137
static int * SubpartIdSeparatorPtr()
return a reference to m_subpartIdSeparator, only for read/save setting functions
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.
#define DEFAULT_TEXT_SIZE
The offset of the pin name string from the end of the pin in mils.
STRING_FORMATTER implements OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:446
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Function GetTemplateFieldName returns a template fieldnames list for read only access.

References TEMPLATES::AddTemplateFieldName(), DEFAULT_BUS_THICKNESS, EESCHEMA_SETTINGS::DRAWING::default_bus_thickness, DEFAULT_IREF_PREFIX, DEFAULT_IREF_SUFFIX, DEFAULT_JUNCTION_DIAM, EESCHEMA_SETTINGS::DRAWING::default_junction_size, DEFAULT_LINE_THICKNESS, EESCHEMA_SETTINGS::DRAWING::default_line_thickness, DEFAULT_SIZE_TEXT, DEFAULT_TEXT_SIZE, EESCHEMA_SETTINGS::DRAWING::default_text_size, DEFAULT_WIRE_THICKNESS, EESCHEMA_SETTINGS::DRAWING::default_wire_thickness, TEMPLATES::DeleteAllFieldNameTemplates(), TEMPLATES::Format(), FROM_UTF8(), STRING_FORMATTER::GetString(), TEMPLATES::GetTemplateFieldNames(), EESCHEMA_SETTINGS::DRAWING::intersheets_ref_prefix, EESCHEMA_SETTINGS::DRAWING::intersheets_ref_short, EESCHEMA_SETTINGS::DRAWING::intersheets_ref_show, EESCHEMA_SETTINGS::DRAWING::intersheets_ref_suffix, IU_PER_MILS, Kiface(), m_DefaultBusThickness, m_DefaultLineWidth, m_DefaultTextSize, m_DefaultWireThickness, EESCHEMA_SETTINGS::m_Drawing, m_IntersheetsRefFormatShort, m_IntersheetsRefPrefix, m_IntersheetsRefShow, m_IntersheetsRefSuffix, m_JunctionSize, m_NetFormatName, BASE_SCREEN::m_PageLayoutDescrFileName, JSON_SETTINGS::m_params, m_PinSymbolSize, m_PlotDirectoryName, m_SpiceAdjustPassiveValues, m_SpiceCommandString, m_TemplateFieldNames, m_TextOffsetRatio, TEMPLATE_FIELDNAME::m_URL, TEMPLATE_FIELDNAME::m_Visible, TEMPLATES::Parse(), EESCHEMA_SETTINGS::DRAWING::pin_symbol_size, LIB_PART::SubpartFirstIdPtr(), LIB_PART::SubpartIdSeparatorPtr(), TO_UTF8, and TXT_MARGIN.

◆ ~SCHEMATIC_SETTINGS()

SCHEMATIC_SETTINGS::~SCHEMATIC_SETTINGS ( )
virtual

Definition at line 213 of file schematic_settings.cpp.

214 {
215  if( m_parent )
216  {
218  m_parent = nullptr;
219  }
220 }
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
void ReleaseNestedSettings(NESTED_SETTINGS *aSettings)
Saves and frees a nested settings object, if it exists within this one.

References NESTED_SETTINGS::m_parent, and JSON_SETTINGS::ReleaseNestedSettings().

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 643 of file json_settings.cpp.

644 {
645  wxLogTrace( traceSettings, "AddNestedSettings %s", aSettings->GetFilename() );
646  m_nested_settings.push_back( aSettings );
647 }
wxString GetFilename() const
Definition: json_settings.h:64
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 555 of file json_settings.cpp.

557 {
558  ValueType val;
559 
560  if( aConfig->Read( aKey, &val ) )
561  {
562  try
563  {
564  ( *this )[PointerFromString( aDest )] = val;
565  }
566  catch( ... )
567  {
568  wxASSERT_MSG( false, wxT( "Could not write value in fromLegacy!" ) );
569  return false;
570  }
571 
572  return true;
573  }
574 
575  return false;
576 }
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 615 of file json_settings.cpp.

617 {
618  wxString str;
619 
620  if( aConfig->Read( aKey, &str ) )
621  {
623  color.SetFromWxString( str );
624 
625  try
626  {
627  nlohmann::json js = nlohmann::json::array( { color.r, color.g, color.b, color.a } );
628  ( *this )[PointerFromString( aDest )] = js;
629  }
630  catch( ... )
631  {
632  wxASSERT_MSG( false, wxT( "Could not write value in fromLegacyColor!" ) );
633  return false;
634  }
635 
636  return true;
637  }
638 
639  return false;
640 }
int color
Definition: DXF_plotter.cpp:60
nlohmann::json json
Definition: gerbview.cpp:39
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100

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 591 of file json_settings.cpp.

593 {
594  wxString str;
595 
596  if( aConfig->Read( aKey, &str ) )
597  {
598  try
599  {
600  ( *this )[PointerFromString( aDest )] = str.ToUTF8();
601  }
602  catch( ... )
603  {
604  wxASSERT_MSG( false, wxT( "Could not write value in fromLegacyString!" ) );
605  return false;
606  }
607 
608  return true;
609  }
610 
611  return false;
612 }
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(), LIBEDIT_SETTINGS::MigrateFromLegacy(), PROJECT_FILE::MigrateFromLegacy(), COMMON_SETTINGS::MigrateFromLegacy(), PCB_CALCULATOR_SETTINGS::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 124 of file json_settings.h.

125  {
126  if( OPT<nlohmann::json> ret = GetJson( aPath ) )
127  {
128  try
129  {
130  return ret->get<ValueType>();
131  }
132  catch( ... )
133  {
134  }
135  }
136 
137  return NULLOPT;
138  }
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(), BOARD_DESIGN_SETTINGS::LoadFromFile(), 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 673 of file json_settings.cpp.

674 {
675  if( OPT<nlohmann::json> opt_json = GetJson( aPath ) )
676  return wxString( opt_json->get<std::string>().c_str(), wxConvUTF8 );
677 
678  return NULLOPT;
679 }
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 274 of file json_settings.h.

275  {
276  return wxT( "json" );
277  }

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

◆ GetFilename()

◆ GetFullFilename()

wxString JSON_SETTINGS::GetFullFilename ( ) const
inherited

Definition at line 78 of file json_settings.cpp.

79 {
80  return wxString( m_filename + "." + getFileExt() );
81 }
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 404 of file json_settings.cpp.

405 {
406  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
407 
408  if( this->contains( ptr ) )
409  {
410  try
411  {
412  return OPT<nlohmann::json>{ this->at( ptr ) };
413  }
414  catch( ... )
415  {
416  }
417  }
418 
419  return OPT<nlohmann::json>{};
420 }
bool contains(_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 279 of file json_settings.h.

280  {
281  return wxEmptyString;
282  }

Referenced by JSON_SETTINGS::LoadFromFile().

◆ GetLocation()

SETTINGS_LOC JSON_SETTINGS::GetLocation ( ) const
inlineinherited

Definition at line 70 of file json_settings.h.

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

References JSON_SETTINGS::m_location.

Referenced by SETTINGS_MANAGER::GetPathForSettingsFile().

◆ GetParent()

JSON_SETTINGS* NESTED_SETTINGS::GetParent ( void  )
inlineinherited

Definition at line 54 of file nested_settings.h.

55  {
56  return m_parent;
57  }
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.

References NESTED_SETTINGS::m_parent.

Referenced by BOARD_DESIGN_SETTINGS::LoadFromFile().

◆ 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 84 of file json_settings.cpp.

85 {
86  for( auto param : m_params )
87  {
88  try
89  {
90  param->Load( this, m_resetParamsIfMissing );
91  }
92  catch( ... )
93  {
94  // Skip unreadable parameters in file
95  wxLogTrace( traceSettings, "param '%s' load err", param->GetJsonPath().c_str() );
96  }
97  }
98 }
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 NESTED_SETTINGS::LoadFromFile ( const wxString &  aDirectory = "")
overridevirtualinherited

Loads the JSON document from the parent and then calls Load()

Parameters
aDirectory

Reimplemented from JSON_SETTINGS.

Definition at line 42 of file nested_settings.cpp.

43 {
44  clear();
45  bool success = false;
46 
47  if( m_parent )
48  {
49  nlohmann::json::json_pointer ptr = PointerFromString( m_path );
50 
51  if( m_parent->contains( ptr ) )
52  {
53  try
54  {
55  update( ( *m_parent )[ptr] );
56 
57  wxLogTrace( traceSettings, "Loaded NESTED_SETTINGS %s with schema %d",
59 
60  success = true;
61  }
62  catch( ... )
63  {
64  wxLogTrace( traceSettings, "NESTED_SETTINGS %s: Could not load from %s at %s",
66  }
67  }
68  }
69 
70  if( success )
71  {
72  int filever = -1;
73 
74  if( count( PointerFromString( "meta.version" ) ) )
75  {
76  try
77  {
78  filever = at( PointerFromString( "meta.version" ) ).get<int>();
79  }
80  catch( ... )
81  {
82  wxLogTrace( traceSettings, "%s: nested settings version could not be read!",
83  m_filename );
84  success = false;
85  }
86  }
87  else
88  {
89  success = false;
90  }
91 
92  if( filever >= 0 && filever < m_schemaVersion )
93  {
94  wxLogTrace( traceSettings, "%s: attempting migration from version %d to %d",
95  m_filename, filever, m_schemaVersion );
96 
97  if( !Migrate() )
98  {
99  wxLogTrace( traceSettings, "%s: migration failed!", GetFullFilename() );
100  success = false;
101  }
102  }
103  else if( filever > m_schemaVersion )
104  {
105  wxLogTrace( traceSettings,
106  "%s: warning: nested settings version %d is newer than latest (%d)",
107  m_filename, filever, m_schemaVersion );
108  }
109  }
110 
111  Load();
112 
113  return success;
114 }
wxString GetFilename() const
Definition: json_settings.h:64
wxString GetFullFilename() const
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.
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
std::string m_path
The path (in pointer format) of where to store this document in the parent.
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.
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.

References MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::clear(), JSON_SETTINGS::GetFilename(), JSON_SETTINGS::GetFullFilename(), JSON_SETTINGS::Load(), JSON_SETTINGS::m_filename, NESTED_SETTINGS::m_parent, NESTED_SETTINGS::m_path, JSON_SETTINGS::m_schemaVersion, JSON_SETTINGS::Migrate(), JSON_SETTINGS::PointerFromString(), and traceSettings.

Referenced by BOARD_DESIGN_SETTINGS::LoadFromFile(), DIALOG_SCHEMATIC_SETUP::OnAuxiliaryAction(), PNS::ROUTING_SETTINGS::ROUTING_SETTINGS(), NESTED_SETTINGS::SetParent(), and SCHEMATIC::SetProject().

◆ 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 432 of file json_settings.cpp.

433 {
434  int filever = at( PointerFromString( "meta.version" ) ).get<int>();
435 
436  while( filever < m_schemaVersion )
437  {
438  if( !m_migrators.count( filever ) )
439  {
440  wxLogTrace( traceSettings, "Migrator missing for %s version %d!",
441  typeid( *this ).name(), filever );
442  return false;
443  }
444 
445  std::pair<int, std::function<bool()>> pair = m_migrators.at( filever );
446 
447  if( pair.second() )
448  {
449  wxLogTrace( traceSettings, "Migrated %s from %d to %d", typeid( *this ).name(),
450  filever, pair.first );
451  filever = pair.first;
452  ( *this )[PointerFromString( "meta.version" )] = filever;
453  }
454  else
455  {
456  wxLogTrace( traceSettings, "Migration failed for %s from %d to %d",
457  typeid( *this ).name(), filever, pair.first );
458  return false;
459  }
460  }
461 
462  return true;
463 }
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 JSON_SETTINGS::MigrateFromLegacy ( wxConfigBase *  aLegacyConfig)
virtualinherited

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 in PCBNEW_SETTINGS, EESCHEMA_SETTINGS, APP_SETTINGS_BASE, PCB_CALCULATOR_SETTINGS, COMMON_SETTINGS, EDA_3D_VIEWER_SETTINGS, PROJECT_FILE, COLOR_SETTINGS, PROJECT_LOCAL_SETTINGS, LIBEDIT_SETTINGS, GERBVIEW_SETTINGS, FOOTPRINT_EDITOR_SETTINGS, CVPCB_SETTINGS, BITMAP2CMP_SETTINGS, PL_EDITOR_SETTINGS, and KICAD_SETTINGS.

Definition at line 466 of file json_settings.cpp.

467 {
468  wxLogTrace( traceSettings,
469  "MigrateFromLegacy() not implemented for %s", typeid( *this ).name() );
470  return false;
471 }
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.

References traceSettings.

Referenced by JSON_SETTINGS::LoadFromFile().

◆ 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 474 of file json_settings.cpp.

475 {
476  std::replace( aPath.begin(), aPath.end(), '.', '/' );
477  aPath.insert( 0, "/" );
478 
479  nlohmann::json::json_pointer p;
480 
481  try
482  {
483  p = nlohmann::json::json_pointer( aPath );
484  }
485  catch( ... )
486  {
487  wxASSERT_MSG( false, wxT( "Invalid pointer path in PointerFromString!" ) );
488  }
489 
490  return p;
491 }

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(), APP_SETTINGS_BASE::migrateFindReplace(), FOOTPRINT_EDITOR_SETTINGS::MigrateFromLegacy(), GERBVIEW_SETTINGS::MigrateFromLegacy(), PROJECT_FILE::MigrateFromLegacy(), EDA_3D_VIEWER_SETTINGS::MigrateFromLegacy(), COMMON_SETTINGS::MigrateFromLegacy(), PCB_CALCULATOR_SETTINGS::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 423 of file json_settings.cpp.

425 {
426  wxASSERT( aNewSchemaVersion > aOldSchemaVersion );
427  wxASSERT( aNewSchemaVersion <= m_schemaVersion );
428  m_migrators[aOldSchemaVersion] = std::make_pair( aNewSchemaVersion, aMigrator );
429 }
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(), COMMON_SETTINGS::COMMON_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 650 of file json_settings.cpp.

651 {
652  if( !aSettings )
653  return;
654 
655  auto it = std::find_if( m_nested_settings.begin(), m_nested_settings.end(),
656  [&aSettings]( const JSON_SETTINGS* aPtr ) {
657  return aPtr == aSettings;
658  } );
659 
660  if( it != m_nested_settings.end() )
661  {
662  wxLogTrace( traceSettings, "Flush and release %s", ( *it )->GetFilename() );
663  ( *it )->SaveToFile();
664  m_nested_settings.erase( it );
665  }
666 
667  aSettings->SetParent( nullptr );
668 }
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.
void SetParent(JSON_SETTINGS *aParent)

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

Referenced by BOARD::ClearProject(), BOARD_DESIGN_SETTINGS::~BOARD_DESIGN_SETTINGS(), ERC_SETTINGS::~ERC_SETTINGS(), NESTED_SETTINGS::~NESTED_SETTINGS(), NET_SETTINGS::~NET_SETTINGS(), and ~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 298 of file json_settings.cpp.

299 {
300  for( auto param : m_params )
301  param->SetDefault();
302 }
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 NESTED_SETTINGS::SaveToFile ( const wxString &  aDirectory = "",
bool  aForce = false 
)
overridevirtualinherited

Calls Store() and then saves the JSON document contents into the parent JSON_SETTINGS.

Parameters
aDirectoryis ignored
Returns
true if the document contents were updated

Reimplemented from JSON_SETTINGS.

Definition at line 117 of file nested_settings.cpp.

118 {
119  if( !m_parent )
120  return false;
121 
122  bool modified = Store();
123 
124  try
125  {
126  nlohmann::json patch =
127  nlohmann::json::diff( *this, ( *m_parent )[PointerFromString( m_path )] );
128  modified |= !patch.empty();
129  }
130  catch( ... )
131  {
132  modified = true;
133  }
134 
135  if( !modified && !aForce )
136  return false;
137 
138  try
139  {
140  ( *m_parent )[PointerFromString( m_path ) ].update( *this );
141 
142  wxLogTrace( traceSettings, "Stored NESTED_SETTINGS %s with schema %d",
144  }
145  catch( ... )
146  {
147  wxLogTrace( traceSettings, "NESTED_SETTINGS %s: Could not store to %s at %s",
149  }
150 
151  return modified;
152 }
virtual bool Store()
Stores the current parameters into the JSON document represented by this object Note: this doesn't do...
wxString GetFilename() const
Definition: json_settings.h:64
nlohmann::json json
Definition: gerbview.cpp:39
wxString m_filename
The filename (not including path) of this settings file (inicode)
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
std::string m_path
The path (in pointer format) of where to store this document in the parent.
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::GetFilename(), JSON_SETTINGS::m_filename, NESTED_SETTINGS::m_parent, NESTED_SETTINGS::m_path, JSON_SETTINGS::m_schemaVersion, JSON_SETTINGS::PointerFromString(), JSON_SETTINGS::Store(), and traceSettings.

◆ 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 148 of file json_settings.h.

149  {
150  ( *this )[PointerFromString( aPath ) ] = aVal;
151  }
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 682 of file json_settings.cpp.

683 {
684  ( *this )[PointerFromString( std::move( aPath ) ) ] = aVal.ToUTF8();
685 }
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 68 of file json_settings.h.

68 { 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().

◆ 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 494 of file json_settings.cpp.

496 {
497  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
498 
499  if( aObj.contains( ptr ) && aObj.at( ptr ).is_string() )
500  {
501  aTarget = aObj.at( ptr ).get<wxString>();
502  return true;
503  }
504 
505  return false;
506 }
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 509 of file json_settings.cpp.

511 {
512  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
513 
514  if( aObj.contains( ptr ) && aObj.at( ptr ).is_boolean() )
515  {
516  aTarget = aObj.at( ptr ).get<bool>();
517  return true;
518  }
519 
520  return false;
521 }
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 524 of file json_settings.cpp.

526 {
527  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
528 
529  if( aObj.contains( ptr ) && aObj.at( ptr ).is_number_integer() )
530  {
531  aTarget = aObj.at( ptr ).get<int>();
532  return true;
533  }
534 
535  return false;
536 }
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 539 of file json_settings.cpp.

541 {
542  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
543 
544  if( aObj.contains( ptr ) && aObj.at( ptr ).is_number_unsigned() )
545  {
546  aTarget = aObj.at( ptr ).get<unsigned int>();
547  return true;
548  }
549 
550  return false;
551 }
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 72 of file json_settings.h.

72 { 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 LIBEDIT_SETTINGS::LIBEDIT_SETTINGS().

◆ SetManager()

void JSON_SETTINGS::SetManager ( SETTINGS_MANAGER aManager)
inlineinherited

Definition at line 188 of file json_settings.h.

189  {
190  m_manager = aManager;
191  }
SETTINGS_MANAGER * m_manager
A pointer to the settings manager managing this file (may be null)

References JSON_SETTINGS::m_manager.

◆ SetParent()

void NESTED_SETTINGS::SetParent ( JSON_SETTINGS aParent)
inherited

Definition at line 155 of file nested_settings.cpp.

156 {
157  m_parent = aParent;
158 
159  if( m_parent )
160  {
161  m_parent->AddNestedSettings( this );
162 
163  // In case we were created after the parent's ctor
164  LoadFromFile();
165  }
166 }
bool LoadFromFile(const wxString &aDirectory="") override
Loads the JSON document from the parent and then calls Load()
void AddNestedSettings(NESTED_SETTINGS *aSettings)
Transfers ownership of a given NESTED_SETTINGS to this object.
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.

References JSON_SETTINGS::AddNestedSettings(), NESTED_SETTINGS::LoadFromFile(), and NESTED_SETTINGS::m_parent.

Referenced by BOARD::ClearProject(), NESTED_SETTINGS::NESTED_SETTINGS(), JSON_SETTINGS::ReleaseNestedSettings(), and BOARD::SetProject().

◆ SetReadOnly()

void JSON_SETTINGS::SetReadOnly ( bool  aReadOnly)
inlineinherited

Definition at line 75 of file json_settings.h.

75 { 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 284 of file json_settings.cpp.

285 {
286  bool modified = false;
287 
288  for( auto param : m_params )
289  {
290  modified |= !param->MatchesFile( this );
291  param->Store( this );
292  }
293 
294  return modified;
295 }
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)

References JSON_SETTINGS::m_params.

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

Member Data Documentation

◆ 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 306 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 300 of file json_settings.h.

Referenced by JSON_SETTINGS::SaveToFile().

◆ m_DefaultBusThickness

int SCHEMATIC_SETTINGS::m_DefaultBusThickness

◆ m_DefaultLineWidth

◆ m_DefaultTextSize

◆ m_DefaultWireThickness

int SCHEMATIC_SETTINGS::m_DefaultWireThickness

◆ m_deleteLegacyAfterMigration

bool JSON_SETTINGS::m_deleteLegacyAfterMigration
protectedinherited

Whether or not to delete legacy file after migration.

Definition at line 312 of file json_settings.h.

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

◆ m_filename

◆ m_IntersheetsRefFormatShort

◆ m_IntersheetsRefPrefix

◆ m_IntersheetsRefShow

◆ m_IntersheetsRefSuffix

◆ m_JunctionSize

◆ 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 288 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 291 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 321 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 327 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 297 of file json_settings.h.

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

◆ m_NetFormatName

◆ m_PageLayoutDescrFile

wxString SCHEMATIC_SETTINGS::m_PageLayoutDescrFile

Definition at line 58 of file schematic_settings.h.

◆ m_params

◆ m_parent

◆ m_path

std::string NESTED_SETTINGS::m_path
protectedinherited

The path (in pointer format) of where to store this document in the parent.

Definition at line 65 of file nested_settings.h.

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

◆ m_PinSymbolSize

◆ m_PlotDirectoryName

wxString SCHEMATIC_SETTINGS::m_PlotDirectoryName

◆ 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 324 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 315 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_SpiceAdjustPassiveValues

bool SCHEMATIC_SETTINGS::m_SpiceAdjustPassiveValues

◆ m_SpiceCommandString

wxString SCHEMATIC_SETTINGS::m_SpiceCommandString

◆ m_TemplateFieldNames

◆ m_TextOffsetRatio

◆ m_writeFile

bool JSON_SETTINGS::m_writeFile
protectedinherited

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