KiCad PCB EDA Suite
NET_SETTINGS Class Reference

NET_SETTINGS stores various net-related settings in a project context. More...

#include <net_settings.h>

Inheritance diagram for NET_SETTINGS:
NESTED_SETTINGS JSON_SETTINGS

Public Member Functions

 NET_SETTINGS (JSON_SETTINGS *aParent, const std::string &aPath)
 
virtual ~NET_SETTINGS ()
 
void ResolveNetClassAssignments (bool aRebuildFromScratch=false)
 Explodes the list of netclass assignments to include atomic members of composite labels (buses). More...
 
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
 
SETTINGS_LOC GetLocation () const
 
void SetLegacyFilename (const wxString &aFilename)
 
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)
 
virtual 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 bool ParseBusVector (const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
 Parses a bus vector (e.g. More...
 
static bool ParseBusGroup (wxString aGroup, wxString *name, std::vector< wxString > *aMemberList)
 Parses a bus group label into the name and a list of components. More...
 
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

NETCLASSES m_NetClasses
 
std::map< wxString, wxString > m_NetClassAssignments
 
std::map< wxString, KIGFX::COLOR4Dm_PcbNetColors
 A map of fully-qualified net names to colors used in the board context. More...
 

Protected Member Functions

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...
 

Detailed Description

NET_SETTINGS stores various net-related settings in a project context.

These settings are accessible and editable from both the schematic and PCB editors.

Definition at line 31 of file net_settings.h.

Constructor & Destructor Documentation

◆ NET_SETTINGS()

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

Definition at line 30 of file net_settings.cpp.

30  :
31  NESTED_SETTINGS( "net_settings", netSettingsSchemaVersion, aParent, aPath ),
32  m_NetClasses()
33 {
34  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "classes",
35  [&]() -> nlohmann::json
36  {
37  nlohmann::json ret = nlohmann::json::array();
38 
39  NETCLASSPTR netclass = m_NetClasses.GetDefault();
41 
42  for( unsigned int idx = 0; idx <= m_NetClasses.GetCount(); idx++ )
43  {
44  if( idx > 0 )
45  {
46  netclass = nc->second;
47  ++nc;
48  }
49 
50  // Note: we're in common/, but we do happen to know which of these fields
51  // are used in which units system.
52  nlohmann::json netclassJson = {
53  { "name", netclass->GetName().ToUTF8() },
54  { "clearance", PcbIu2Millimeter( netclass->GetClearance() ) },
55  { "track_width", PcbIu2Millimeter( netclass->GetTrackWidth() ) },
56  { "via_diameter", PcbIu2Millimeter( netclass->GetViaDiameter() ) },
57  { "via_drill", PcbIu2Millimeter( netclass->GetViaDrill() ) },
58  { "microvia_diameter", PcbIu2Millimeter( netclass->GetuViaDiameter() ) },
59  { "microvia_drill", PcbIu2Millimeter( netclass->GetuViaDrill() ) },
60  { "diff_pair_width", PcbIu2Millimeter( netclass->GetDiffPairWidth() ) },
61  { "diff_pair_gap", PcbIu2Millimeter( netclass->GetDiffPairGap() ) },
62  { "diff_pair_via_gap", PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) },
63  { "wire_width", SchIu2Mils( netclass->GetWireWidth() ) },
64  { "bus_width", SchIu2Mils( netclass->GetBusWidth() ) },
65  { "line_style", netclass->GetLineStyle() },
66  { "schematic_color", netclass->GetSchematicColor() },
67  { "pcb_color", netclass->GetPcbColor() }
68  };
69 
70  if( idx > 0 ) // No need to store members of Default netclass
71  {
72  nlohmann::json membersJson = nlohmann::json::array();
73 
74  for( const wxString& member : *netclass )
75  {
76  if( !member.empty() )
77  membersJson.push_back( member );
78  }
79 
80  netclassJson["nets"] = membersJson;
81  }
82 
83  ret.push_back( netclassJson );
84  }
85 
86  return ret;
87  },
88  [&]( const nlohmann::json& aJson )
89  {
90  if( !aJson.is_array() )
91  return;
92 
94  m_NetClassAssignments.clear();
95  NETCLASSPTR netclass;
96  NETCLASSPTR defaultClass = m_NetClasses.GetDefault();
97 
98  auto getInPcbUnits =
99  []( const nlohmann::json& aObj, const std::string& aKey, int aDefault )
100  {
101  if( aObj.contains( aKey ) )
102  return PcbMillimeter2iu( aObj[aKey].get<double>() );
103  else
104  return aDefault;
105  };
106 
107  auto getInSchematicUnits =
108  []( const nlohmann::json& aObj, const std::string& aKey, int aDefault )
109  {
110  if( aObj.contains( aKey ) )
111  return SchMils2iu( aObj[aKey].get<double>() );
112  else
113  return aDefault;
114  };
115 
116  for( const nlohmann::json& entry : aJson )
117  {
118  if( !entry.is_object() || !entry.contains( "name" ) )
119  continue;
120 
121  wxString name = entry["name"];
122 
123  if( name == defaultClass->GetName() )
124  netclass = defaultClass;
125  else
126  netclass = std::make_shared<NETCLASS>( name );
127 
128  netclass->SetClearance( getInPcbUnits( entry, "clearance",
129  netclass->GetClearance() ) );
130  netclass->SetTrackWidth( getInPcbUnits( entry, "track_width",
131  netclass->GetTrackWidth() ) );
132  netclass->SetViaDiameter( getInPcbUnits( entry, "via_diameter",
133  netclass->GetViaDiameter() ) );
134  netclass->SetViaDrill( getInPcbUnits( entry, "via_drill",
135  netclass->GetViaDrill() ) );
136  netclass->SetuViaDiameter( getInPcbUnits( entry, "microvia_diameter",
137  netclass->GetuViaDiameter() ) );
138  netclass->SetuViaDrill( getInPcbUnits( entry, "microvia_drill",
139  netclass->GetuViaDrill() ) );
140  netclass->SetDiffPairWidth( getInPcbUnits( entry, "diff_pair_width",
141  netclass->GetDiffPairWidth() ) );
142  netclass->SetDiffPairGap( getInPcbUnits( entry, "diff_pair_gap",
143  netclass->GetDiffPairGap() ) );
144  netclass->SetDiffPairViaGap( getInPcbUnits( entry, "diff_pair_via_gap",
145  netclass->GetDiffPairViaGap() ) );
146  netclass->SetWireWidth( getInSchematicUnits( entry, "wire_width",
147  netclass->GetWireWidth() ) );
148  netclass->SetBusWidth( getInSchematicUnits( entry, "bus_width",
149  netclass->GetWireWidth() ) );
150 
151  if( entry.contains( "line_style" ) && entry["line_style"].is_number() )
152  netclass->SetLineStyle( entry["line_style"].get<int>() );
153 
154  if( entry.contains( "nets" ) && entry["nets"].is_array() )
155  {
156  for( const auto& net : entry["nets"].items() )
157  netclass->Add( net.value().get<wxString>() );
158  }
159 
160  if( entry.contains( "pcb_color" ) && entry["pcb_color"].is_string() )
161  netclass->SetPcbColor( entry["pcb_color"].get<KIGFX::COLOR4D>() );
162 
163  if( entry.contains( "schematic_color" ) && entry["schematic_color"].is_string() )
164  netclass->SetSchematicColor( entry["schematic_color"].get<KIGFX::COLOR4D>() );
165 
166  if( netclass != defaultClass )
167  m_NetClasses.Add( netclass );
168 
169  for( const wxString& net : *netclass )
170  m_NetClassAssignments[ net ] = netclass->GetName();
171  }
172 
174  },
175  {} ) );
176 
177  m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "net_colors",
178  [&]() -> nlohmann::json
179  {
180  nlohmann::json ret = {};
181 
182  for( const auto& pair : m_PcbNetColors )
183  {
184  std::string key( pair.first.ToUTF8() );
185  ret[key] = pair.second;
186  }
187 
188  return ret;
189  },
190  [&]( const nlohmann::json& aJson )
191  {
192  if( !aJson.is_object() )
193  return;
194 
195  m_PcbNetColors.clear();
196 
197  for( const auto& pair : aJson.items() )
198  {
199  wxString key( pair.key().c_str(), wxConvUTF8 );
200  m_PcbNetColors[key] = pair.value().get<KIGFX::COLOR4D>();
201  }
202  },
203  {} ) );
204 }
std::map< wxString, wxString > m_NetClassAssignments
Definition: net_settings.h:43
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
Like a normal param, but with custom getter and setter functions.
Definition: parameters.h:296
std::map< wxString, KIGFX::COLOR4D > m_PcbNetColors
A map of fully-qualified net names to colors used in the board context.
Definition: net_settings.h:51
constexpr double PcbIu2Millimeter(int iu)
nlohmann::json json
Definition: gerbview.cpp:40
NETCLASS_MAP::const_iterator const_iterator
Definition: netclass.h:247
constexpr int PcbMillimeter2iu(double mm)
iterator begin()
Definition: netclass.h:244
NETCLASSES m_NetClasses
Definition: net_settings.h:39
void ResolveNetClassAssignments(bool aRebuildFromScratch=false)
Explodes the list of netclass assignments to include atomic members of composite labels (buses).
constexpr double SchIu2Mils(int iu)
bool Add(const NETCLASSPTR &aNetclass)
Function Add takes aNetclass and puts it into this NETCLASSES container.
Definition: netclass.cpp:90
void Clear()
Function Clear destroys any contained NETCLASS instances except the Default one, and clears any membe...
Definition: netclass.h:237
const char * name
Definition: DXF_plotter.cpp:60
NESTED_SETTINGS(const std::string &aName, int aSchemaVersion, JSON_SETTINGS *aParent, const std::string &aPath)
unsigned GetCount() const
Function GetCount.
Definition: netclass.h:255
NETCLASSPTR GetDefault() const
Function GetDefault.
Definition: netclass.h:264
constexpr int SchMils2iu(int mils)
const int netSettingsSchemaVersion
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99

References NETCLASSES::Add(), NETCLASSES::begin(), NETCLASSES::Clear(), NETCLASSES::GetCount(), NETCLASSES::GetDefault(), m_NetClassAssignments, m_NetClasses, JSON_SETTINGS::m_params, m_PcbNetColors, name, PcbIu2Millimeter(), PcbMillimeter2iu(), ResolveNetClassAssignments(), SchIu2Mils(), and SchMils2iu().

◆ ~NET_SETTINGS()

NET_SETTINGS::~NET_SETTINGS ( )
virtual

Definition at line 207 of file net_settings.cpp.

208 {
209  // Release early before destroying members
210  if( m_parent )
211  {
213  m_parent = nullptr;
214  }
215 }
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 608 of file json_settings.cpp.

609 {
610  wxLogTrace( traceSettings, "AddNestedSettings %s", aSettings->GetFilename() );
611  m_nested_settings.push_back( aSettings );
612 }
wxString GetFilename() const
Definition: json_settings.h:56
std::vector< NESTED_SETTINGS * > m_nested_settings
Nested settings files that live inside this one, if any.
const char * traceSettings
Flag to enable settings tracing.

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

522 {
523  ValueType val;
524 
525  if( aConfig->Read( aKey, &val ) )
526  {
527  try
528  {
529  ( *this )[PointerFromString( aDest )] = val;
530  }
531  catch( ... )
532  {
533  wxASSERT_MSG( false, wxT( "Could not write value in fromLegacy!" ) );
534  return false;
535  }
536 
537  return true;
538  }
539 
540  return false;
541 }
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 580 of file json_settings.cpp.

582 {
583  wxString str;
584 
585  if( aConfig->Read( aKey, &str ) )
586  {
588  color.SetFromWxString( str );
589 
590  try
591  {
592  nlohmann::json js = nlohmann::json::array( { color.r, color.g, color.b, color.a } );
593  ( *this )[PointerFromString( aDest )] = js;
594  }
595  catch( ... )
596  {
597  wxASSERT_MSG( false, wxT( "Could not write value in fromLegacyColor!" ) );
598  return false;
599  }
600 
601  return true;
602  }
603 
604  return false;
605 }
int color
Definition: DXF_plotter.cpp:61
nlohmann::json json
Definition: gerbview.cpp:40
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:99

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

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

112  {
113  if( OPT<nlohmann::json> ret = GetJson( aPath ) )
114  {
115  try
116  {
117  return ret->get<ValueType>();
118  }
119  catch( ... )
120  {
121  }
122  }
123 
124  return NULLOPT;
125  }
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< ValueType >::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< ValueType >::MatchesFile(), and PARAM_SCALED< ValueType >::MatchesFile().

◆ Get() [2/2]

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

Definition at line 638 of file json_settings.cpp.

639 {
640  if( OPT<nlohmann::json> opt_json = GetJson( aPath ) )
641  return wxString( opt_json->get<std::string>().c_str(), wxConvUTF8 );
642 
643  return NULLOPT;
644 }
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 250 of file json_settings.h.

251  {
252  return wxT( "json" );
253  }

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

◆ GetFilename()

◆ GetFullFilename()

wxString JSON_SETTINGS::GetFullFilename ( ) const
inherited

Definition at line 79 of file json_settings.cpp.

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

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

Referenced by JSON_SETTINGS::Get(), PARAM_LAMBDA< ValueType >::Load(), PARAM_LIST< wxString >::Load(), PARAM_MAP< Value >::Load(), PARAM_WXSTRING_MAP::Load(), PARAM_LAMBDA< ValueType >::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 255 of file json_settings.h.

256  {
257  return wxEmptyString;
258  }

Referenced by JSON_SETTINGS::LoadFromFile().

◆ GetLocation()

SETTINGS_LOC JSON_SETTINGS::GetLocation ( ) const
inlineinherited

Definition at line 60 of file json_settings.h.

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

◆ Load()

void JSON_SETTINGS::Load ( )
virtualinherited

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

Definition at line 85 of file json_settings.cpp.

86 {
87  for( auto param : m_params )
88  {
89  try
90  {
91  param->Load( this, m_resetParamsIfMissing );
92  }
93  catch( ... )
94  {
95  // Skip unreadable parameters in file
96  wxLogTrace( traceSettings, "param '%s' load err", param->GetJsonPath().c_str() );
97  }
98  }
99 }
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 char * traceSettings
Flag to enable settings tracing.

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

Referenced by 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 44 of file nested_settings.cpp.

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

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

Reimplemented in BOARD_DESIGN_SETTINGS, COMMON_SETTINGS, COLOR_SETTINGS, PROJECT_LOCAL_SETTINGS, and FOOTPRINT_EDITOR_SETTINGS.

Definition at line 424 of file json_settings.cpp.

425 {
426  wxLogTrace( traceSettings, "Migrate() not implemented for %s", typeid( *this ).name() );
427  return false;
428 }
const char * traceSettings
Flag to enable settings tracing.

References 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, COLOR_SETTINGS, PROJECT_FILE, PROJECT_LOCAL_SETTINGS, LIBEDIT_SETTINGS, GERBVIEW_SETTINGS, FOOTPRINT_EDITOR_SETTINGS, CVPCB_SETTINGS, BITMAP2CMP_SETTINGS, PL_EDITOR_SETTINGS, and KICAD_SETTINGS.

Definition at line 431 of file json_settings.cpp.

432 {
433  wxLogTrace( traceSettings,
434  "MigrateFromLegacy() not implemented for %s", typeid( *this ).name() );
435  return false;
436 }
const char * traceSettings
Flag to enable settings tracing.

References traceSettings.

Referenced by JSON_SETTINGS::LoadFromFile().

◆ ParseBusGroup()

bool NET_SETTINGS::ParseBusGroup ( wxString  aGroup,
wxString *  name,
std::vector< wxString > *  aMemberList 
)
static

Parses a bus group label into the name and a list of components.

Parameters
aGroupis the input label, e.g. "USB{DP DM}"
nameis the output group name, e.g. "USB"
aMemberListis a list of member strings, e.g. "DP", "DM"
Returns
true if aGroup was successfully parsed

Definition at line 359 of file net_settings.cpp.

361 {
362  size_t groupLen = aGroup.length();
363  size_t i = 0;
364  wxString prefix;
365  wxString suffix;
366  wxString tmp;
367  int braceNesting = 0;
368 
369  prefix.reserve( groupLen );
370 
371  // Parse prefix
372  //
373  for( ; i < groupLen; ++i )
374  {
375  if( aGroup[i] == '{' )
376  {
377  if( i > 0 && isSuperSub( aGroup[i-1] ) )
378  braceNesting++;
379  else
380  break;
381  }
382  else if( aGroup[i] == '}' )
383  {
384  braceNesting--;
385  }
386 
387  if( aGroup[i] == ' ' || aGroup[i] == '[' || aGroup[i] == ']' )
388  return false;
389 
390  prefix += aGroup[i];
391  }
392 
393  if( braceNesting != 0 )
394  return false;
395 
396  if( aName )
397  *aName = prefix;
398 
399  // Parse members
400  //
401  i++; // '{' character
402 
403  if( i >= groupLen )
404  return false;
405 
406  for( ; i < groupLen; ++i )
407  {
408  if( aGroup[i] == '{' )
409  {
410  if( i > 0 && isSuperSub( aGroup[i-1] ) )
411  braceNesting++;
412  else
413  return false;
414  }
415  else if( aGroup[i] == '}' )
416  {
417  if( braceNesting )
418  braceNesting--;
419  else
420  {
421  if( aMemberList )
422  aMemberList->push_back( tmp );
423 
424  return true;
425  }
426  }
427 
428  if( aGroup[i] == ' ' )
429  {
430  if( aMemberList )
431  aMemberList->push_back( tmp );
432 
433  tmp.Clear();
434  continue;
435  }
436 
437  tmp += aGroup[i];
438  }
439 
440  return false;
441 }
static bool isSuperSub(wxChar c)

References isSuperSub().

Referenced by SCH_CONNECTION::AppendInfoToMsgPanel(), SCH_CONNECTION::ConfigureFromLabel(), SCH_CONNECTION::IsBusLabel(), SCH_NETNAME_VALIDATOR::IsValid(), and ResolveNetClassAssignments().

◆ ParseBusVector()

bool NET_SETTINGS::ParseBusVector ( const wxString &  aBus,
wxString *  aName,
std::vector< wxString > *  aMemberList 
)
static

Parses a bus vector (e.g.

A[7..0]) into name, begin, and end. Ensures that begin and end are positive and that end > begin.

Parameters
aBusis a bus vector label string
aNameout is the bus name, e.g. "A"
aMemberListis a list of member strings, e.g. "A7", "A6", and so on
Returns
true if aBus was successfully parsed

Definition at line 224 of file net_settings.cpp.

226 {
227  auto isDigit = []( wxChar c )
228  {
229  static wxString digits( wxT( "0123456789" ) );
230  return digits.Contains( c );
231  };
232 
233  size_t busLen = aBus.length();
234  size_t i = 0;
235  wxString prefix;
236  wxString suffix;
237  wxString tmp;
238  long begin = 0;
239  long end = 0;
240  int braceNesting = 0;
241 
242  prefix.reserve( busLen );
243 
244  // Parse prefix
245  //
246  for( ; i < busLen; ++i )
247  {
248  if( aBus[i] == '{' )
249  {
250  if( i > 0 && isSuperSub( aBus[i-1] ) )
251  braceNesting++;
252  else
253  return false;
254  }
255  else if( aBus[i] == '}' )
256  {
257  braceNesting--;
258  }
259 
260  if( aBus[i] == ' ' || aBus[i] == ']' )
261  return false;
262 
263  if( aBus[i] == '[' )
264  break;
265 
266  prefix += aBus[i];
267  }
268 
269  // Parse start number
270  //
271  i++; // '[' character
272 
273  if( i >= busLen )
274  return false;
275 
276  for( ; i < busLen; ++i )
277  {
278  if( aBus[i] == '.' && i + 1 < busLen && aBus[i+1] == '.' )
279  {
280  tmp.ToLong( &begin );
281  i += 2;
282  break;
283  }
284 
285  if( !isDigit( aBus[i] ) )
286  return false;
287 
288  tmp += aBus[i];
289  }
290 
291  // Parse end number
292  //
293  tmp = wxEmptyString;
294 
295  if( i >= busLen )
296  return false;
297 
298  for( ; i < busLen; ++i )
299  {
300  if( aBus[i] == ']' )
301  {
302  tmp.ToLong( &end );
303  ++i;
304  break;
305  }
306 
307  if( !isDigit( aBus[i] ) )
308  return false;
309 
310  tmp += aBus[i];
311  }
312 
313  // Parse suffix
314  //
315  for( ; i < busLen; ++i )
316  {
317  if( aBus[i] == '}' )
318  {
319  braceNesting--;
320  suffix += aBus[i];
321  }
322  else if( aBus[i] == '~' )
323  {
324  suffix += aBus[i];
325  }
326  else
327  {
328  return false;
329  }
330  }
331 
332  if( braceNesting != 0 )
333  return false;
334 
335  if( begin == end )
336  return false;
337  else if( begin > end )
338  std::swap( begin, end );
339 
340  if( aName )
341  *aName = prefix;
342 
343  if( aMemberList )
344  {
345  for( long idx = begin; idx <= end; ++idx )
346  {
347  wxString str = prefix;
348  str << idx;
349  str << suffix;
350 
351  aMemberList->emplace_back( str );
352  }
353  }
354 
355  return true;
356 }
bool isDigit(char cc)
Definition: dsnlexer.cpp:439
static bool isSuperSub(wxChar c)

References isDigit(), and isSuperSub().

Referenced by SCH_CONNECTION::ConfigureFromLabel(), SCH_CONNECTION::IsBusLabel(), SCH_NETNAME_VALIDATOR::IsValid(), ResolveNetClassAssignments(), and SCH_EAGLE_PLUGIN::translateEagleBusName().

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

440 {
441  std::replace( aPath.begin(), aPath.end(), '.', '/' );
442  aPath.insert( 0, "/" );
443 
444  nlohmann::json::json_pointer p;
445 
446  try
447  {
448  p = nlohmann::json::json_pointer( aPath );
449  }
450  catch( ... )
451  {
452  wxASSERT_MSG( false, wxT( "Invalid pointer path in PointerFromString!" ) );
453  }
454 
455  return p;
456 }

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(), FOOTPRINT_EDITOR_SETTINGS::Migrate(), PROJECT_LOCAL_SETTINGS::Migrate(), COLOR_SETTINGS::Migrate(), COMMON_SETTINGS::Migrate(), BOARD_DESIGN_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().

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

616 {
617  if( !aSettings )
618  return;
619 
620  auto it = std::find_if( m_nested_settings.begin(), m_nested_settings.end(),
621  [&aSettings]( const JSON_SETTINGS* aPtr ) {
622  return aPtr == aSettings;
623  } );
624 
625  if( it != m_nested_settings.end() )
626  {
627  wxLogTrace( traceSettings, "Flush and release %s", ( *it )->GetFilename() );
628  ( *it )->SaveToFile();
629  m_nested_settings.erase( it );
630  }
631 
632  aSettings->SetParent( nullptr );
633 }
std::vector< NESTED_SETTINGS * > m_nested_settings
Nested settings files that live inside this one, if any.
const char * traceSettings
Flag to enable settings tracing.
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(), 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 299 of file json_settings.cpp.

300 {
301  for( auto param : m_params )
302  param->SetDefault();
303 }
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().

◆ ResolveNetClassAssignments()

void NET_SETTINGS::ResolveNetClassAssignments ( bool  aRebuildFromScratch = false)

Explodes the list of netclass assignments to include atomic members of composite labels (buses).

Parameters
aRebuildFromScratchindicates the assignments should be rebuilt from the netclass membership lists before resolving.

Definition at line 444 of file net_settings.cpp.

445 {
446  std::map<wxString, wxString> baseList;
447 
448  if( aRebuildFromScratch )
449  {
450  for( const std::pair<const wxString, NETCLASSPTR>& netclass : m_NetClasses )
451  {
452  for( const wxString& net : *netclass.second )
453  baseList[ net ] = netclass.second->GetName();
454  }
455  }
456  else
457  {
458  baseList = m_NetClassAssignments;
459  }
460 
461  m_NetClassAssignments.clear();
462 
463  for( const auto& ii : baseList )
464  {
465  m_NetClassAssignments[ ii.first ] = ii.second;
466 
467  wxString unescaped = UnescapeString( ii.first );
468  wxString prefix;
469  std::vector<wxString> members;
470 
471  if( ParseBusVector( unescaped, &prefix, &members ) )
472  {
473  prefix = wxEmptyString;
474  }
475  else if( ParseBusGroup( unescaped, &prefix, &members ) )
476  {
477  if( !prefix.IsEmpty() )
478  prefix += wxT( "." );
479  }
480 
481  for( wxString& member : members )
482  m_NetClassAssignments[ prefix + member ] = ii.second;
483  }
484 }
std::map< wxString, wxString > m_NetClassAssignments
Definition: net_settings.h:43
static bool ParseBusGroup(wxString aGroup, wxString *name, std::vector< wxString > *aMemberList)
Parses a bus group label into the name and a list of components.
NETCLASSES m_NetClasses
Definition: net_settings.h:39
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:152
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parses a bus vector (e.g.

References m_NetClassAssignments, m_NetClasses, ParseBusGroup(), ParseBusVector(), and UnescapeString().

Referenced by SCH_EDITOR_CONTROL::AssignNetclass(), SCH_EDIT_FRAME::KiwayMailIn(), NET_SETTINGS(), PCB_EDIT_FRAME::ShowBoardSetupDialog(), and SCH_EDIT_FRAME::ShowSchematicSetupDialog().

◆ 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 119 of file nested_settings.cpp.

120 {
121  if( !m_parent )
122  return false;
123 
124  bool modified = Store();
125 
126  try
127  {
128  nlohmann::json patch =
129  nlohmann::json::diff( *this, ( *m_parent )[PointerFromString( m_path )] );
130  modified |= !patch.empty();
131  }
132  catch( ... )
133  {
134  modified = true;
135  }
136 
137  if( !modified && !aForce )
138  return false;
139 
140  try
141  {
142  ( *m_parent )[PointerFromString( m_path ) ].update( *this );
143 
144  wxLogTrace( traceSettings, "Stored NESTED_SETTINGS %s with schema %d",
146  }
147  catch( ... )
148  {
149  wxLogTrace( traceSettings, "NESTED_SETTINGS %s: Could not store to %s at %s",
151  }
152 
153  return modified;
154 }
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:56
nlohmann::json json
Definition: gerbview.cpp:40
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 char * traceSettings
Flag to enable settings tracing.
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 135 of file json_settings.h.

136  {
137  ( *this )[PointerFromString( aPath ) ] = aVal;
138  }
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< ValueType >::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 647 of file json_settings.cpp.

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

References JSON_SETTINGS::PointerFromString().

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

461 {
462  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
463 
464  if( aObj.contains( ptr ) && aObj.at( ptr ).is_string() )
465  {
466  aTarget = aObj.at( ptr ).get<wxString>();
467  return true;
468  }
469 
470  return false;
471 }
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References JSON_SETTINGS::PointerFromString().

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

476 {
477  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
478 
479  if( aObj.contains( ptr ) && aObj.at( ptr ).is_boolean() )
480  {
481  aTarget = aObj.at( ptr ).get<bool>();
482  return true;
483  }
484 
485  return false;
486 }
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 489 of file json_settings.cpp.

491 {
492  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
493 
494  if( aObj.contains( ptr ) && aObj.at( ptr ).is_number_integer() )
495  {
496  aTarget = aObj.at( ptr ).get<int>();
497  return true;
498  }
499 
500  return false;
501 }
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 504 of file json_settings.cpp.

506 {
507  nlohmann::json::json_pointer ptr = PointerFromString( aPath );
508 
509  if( aObj.contains( ptr ) && aObj.at( ptr ).is_number_unsigned() )
510  {
511  aTarget = aObj.at( ptr ).get<unsigned int>();
512  return true;
513  }
514 
515  return false;
516 }
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 62 of file json_settings.h.

62 { 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 175 of file json_settings.h.

176  {
177  m_manager = aManager;
178  }
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 157 of file nested_settings.cpp.

158 {
159  m_parent = aParent;
160 
161  if( m_parent )
162  {
163  m_parent->AddNestedSettings( this );
164 
165  // In case we were created after the parent's ctor
166  LoadFromFile();
167  }
168 }
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().

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

286 {
287  bool modified = false;
288 
289  for( auto param : m_params )
290  {
291  modified |= !param->MatchesFile( this );
292  param->Store( this );
293  }
294 
295  return modified;
296 }
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 282 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 276 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 288 of file json_settings.h.

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

◆ m_filename

wxString JSON_SETTINGS::m_filename
protectedinherited

◆ 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 264 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 267 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 297 of file json_settings.h.

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

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

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

◆ m_NetClassAssignments

◆ m_NetClasses

◆ 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_PcbNetColors

std::map<wxString, KIGFX::COLOR4D> NET_SETTINGS::m_PcbNetColors

A map of fully-qualified net names to colors used in the board context.

Since these color overrides are for the board, buses are not included here. Only nets that the user has assigned custom colors to will be in this list. Nets that no longer exist will be deleted during a netlist read in PcbNew.

Definition at line 51 of file net_settings.h.

Referenced by PCB_EDIT_FRAME::LoadProjectSettings(), NET_SETTINGS(), and PCB_EDIT_FRAME::SaveProjectSettings().

◆ 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 300 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 291 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_writeFile

bool JSON_SETTINGS::m_writeFile
protectedinherited

Whether or not the backing store file should be written.

Definition at line 285 of file json_settings.h.

Referenced by JSON_SETTINGS::SaveToFile().


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