91template<
typename ValueType>
95 PARAM(
const std::string& aJsonPath, ValueType* aPtr,
const ValueType& aDefault,
96 bool aReadOnly =
false ) :
105 PARAM(
const std::string& aJsonPath, ValueType* aPtr,
const ValueType& aDefault,
106 const ValueType& aMin,
const ValueType& aMax,
bool aReadOnly =
false ) :
120 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
122 ValueType val = *optval;
132 else if( aResetIfMissing )
155 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
156 return *optval == *
m_ptr;
177 PARAM_PATH(
const std::string& aJsonPath, wxString* aPtr,
const wxString& aDefault,
178 bool aReadOnly =
false ) :
179 PARAM( aJsonPath, aPtr, aDefault, aReadOnly )
199 if( std::optional<wxString> optval = aSettings.
Get<wxString>(
m_path ) )
208 wxString ret = aString;
209 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
215 wxString ret = aString;
217 if( !ret.Contains( wxT(
"://" ) ) )
218 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
227template<
typename EnumType>
231 PARAM_ENUM(
const std::string& aJsonPath, EnumType* aPtr, EnumType aDefault,
232 EnumType aMin, EnumType aMax,
bool aReadOnly =
false ) :
246 if( std::optional<int> val = aSettings.
Get<
int>(
m_path ) )
248 if( *val >=
static_cast<int>(
m_min ) && *val <=
static_cast<int>(
m_max ) )
249 *
m_ptr =
static_cast<EnumType
>( *val );
250 else if( aResetIfMissing )
254 else if( aResetIfMissing )
262 aSettings->
Set<
int>(
m_path,
static_cast<int>( *m_ptr ) );
277 if( std::optional<int> val = aSettings.
Get<
int>(
m_path ) )
278 return *val ==
static_cast<int>( *m_ptr );
294template<
typename ValueType>
298 PARAM_LAMBDA(
const std::string& aJsonPath, std::function<ValueType()> aGetter,
299 std::function<
void( ValueType )> aSetter, ValueType aDefault,
300 bool aReadOnly =
false ) :
313 if( std::is_same<ValueType, nlohmann::json>::value )
315 if( std::optional<nlohmann::json> optval = aSettings.
GetJson(
m_path ) )
322 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
352 if( std::is_same<ValueType, nlohmann::json>::value )
354 if( std::optional<nlohmann::json> optval = aSettings.
GetJson(
m_path ) )
359 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
391template<
typename ValueType>
395 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
396 double aScale = 1.0,
bool aReadOnly =
false ) :
407 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
408 ValueType aMin, ValueType aMax,
double aScale = 1.0,
bool aReadOnly =
false ) :
426 if( std::optional<double> optval = aSettings.
Get<
double>(
m_path ) )
428 else if( !aResetIfMissing )
459 if( std::optional<double> optval = aSettings.
Get<
double>(
m_path ) )
475template<
typename Type>
479 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
480 std::initializer_list<Type> aDefault,
bool aResetIfEmpty =
false ) :
487 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
488 std::vector<Type> aDefault,
bool aResetIfEmpty =
false ) :
500 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
502 std::vector<Type> val;
506 for(
const auto& el : js->items() )
507 val.push_back( el.value().get<Type>() );
515 else if( aResetIfMissing )
523 nlohmann::json js = nlohmann::json::array();
525 for(
const auto& el : *
m_ptr )
528 aSettings->
Set<nlohmann::json>(
m_path, js );
538 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
542 std::vector<Type> val;
544 for(
const auto& el : js->items() )
548 val.emplace_back( el.value().get<Type>() );
556 return val == *
m_ptr;
587template<
typename Type>
591 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
592 std::initializer_list<Type> aDefault,
bool aReadOnly =
false ) :
598 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
599 std::set<Type> aDefault,
bool aReadOnly =
false ) :
610 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
616 for(
const auto& el : js->items() )
617 val.insert( el.value().get<Type>() );
622 else if( aResetIfMissing )
628 nlohmann::json js = nlohmann::json::array();
630 for(
const auto& el : *
m_ptr )
633 aSettings->
Set<nlohmann::json>(
m_path, js );
644 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
650 for(
const auto& el : js->items() )
651 val.insert( el.value().get<Type>() );
653 return val == *
m_ptr;
679 std::initializer_list<wxString> aDefault ) :
684 std::vector<wxString> aDefault ) :
695 for(
size_t i = 0; i <
m_ptr->size(); i++ )
701 bool MatchesFile(
const JSON_SETTINGS& aSettings )
const override;
706 wxString ret = aString;
707 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
713 wxString ret = aString;
715 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
733template<
typename Value>
737 PARAM_MAP(
const std::string& aJsonPath, std::map<std::string, Value>* aPtr,
738 std::initializer_list<std::pair<const std::string, Value>> aDefault,
739 bool aReadOnly =
false ) :
752 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
754 if( js->is_object() )
758 for(
const auto& el : js->items() )
759 ( *m_ptr )[el.key()] = el.value().get<Value>();
762 else if( aResetIfMissing )
768 nlohmann::json js( {} );
770 for(
const auto& el : *
m_ptr )
771 js[el.first] = el.second;
773 aSettings->
Set<nlohmann::json>(
m_path, js );
783 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
785 if( js->is_object() )
787 if(
m_ptr->size() != js->size() )
790 std::map<std::string, Value> val;
792 for(
const auto& el : js->items() )
793 val[el.key()] = el.value().get<Value>();
795 return val == *
m_ptr;
803 std::map<std::string, Value>*
m_ptr;
826 std::initializer_list<std::pair<const wxString, wxString>> aDefault,
827 bool aReadOnly =
false,
bool aArrayBehavior =
false ) :
835 void Load(
const JSON_SETTINGS& aSettings,
bool aResetIfMissing =
true )
const override;
844 bool MatchesFile(
const JSON_SETTINGS& aSettings )
const override;
847 std::map<wxString, wxString>*
m_ptr;
KICAD_PLUGIN_EXPORT SCENEGRAPH * Load(char const *aFileName)
Read a model file and creates a generic display structure.
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
void Set(const std::string &aPath, ValueType aVal)
Stores a value into the JSON document Will throw an exception if ValueType isn't something that the l...
std::optional< 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....
std::optional< ValueType > Get(const std::string &aPath) const
Fetches a value from within the JSON document.
PARAM_BASE(std::string aJsonPath, bool aReadOnly)
bool m_readOnly
Indicates param pointer should never be overwritten.
const std::string & GetJsonPath() const
void SetClearUnknownKeys(bool aSet=true)
virtual void SetDefault()=0
bool m_clearUnknownKeys
Keys should be cleared from source rather than merged.
bool ClearUnknownKeys() const
virtual void Store(JSON_SETTINGS *aSettings) const =0
Stores the value of this parameter to the given JSON_SETTINGS object.
virtual ~PARAM_BASE()=default
virtual bool MatchesFile(const JSON_SETTINGS &aSettings) const =0
Checks whether the parameter in memory matches the one in a given JSON file.
std::string m_path
Address of the param in the json files.
virtual void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const =0
Loads the value of this parameter from JSON to the underlying storage.
void SetDefault() override
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
EnumType GetDefault() const
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
PARAM_ENUM(const std::string &aJsonPath, EnumType *aPtr, EnumType aDefault, EnumType aMin, EnumType aMax, bool aReadOnly=false)
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
Like a normal param, but with custom getter and setter functions.
std::function< void(ValueType)> m_setter
std::function< ValueType()> m_getter
void SetDefault() override
ValueType GetDefault() const
PARAM_LAMBDA(const std::string &aJsonPath, std::function< ValueType()> aGetter, std::function< void(ValueType)> aSetter, ValueType aDefault, bool aReadOnly=false)
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::vector< Type > aDefault, bool aResetIfEmpty=false)
std::vector< Type > * m_ptr
PARAM_LIST(const std::string &aJsonPath, std::vector< Type > *aPtr, std::initializer_list< Type > aDefault, bool aResetIfEmpty=false)
std::vector< Type > m_default
void SetDefault() override
Represents a map of <std::string, Value>.
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
virtual void SetDefault() override
PARAM_MAP(const std::string &aJsonPath, std::map< std::string, Value > *aPtr, std::initializer_list< std::pair< const std::string, Value > > aDefault, bool aReadOnly=false)
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
std::map< std::string, Value > m_default
std::map< std::string, Value > * m_ptr
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::vector< wxString > aDefault)
wxString toFileFormat(const wxString &aString) const
PARAM_PATH_LIST(const std::string &aJsonPath, std::vector< wxString > *aPtr, std::initializer_list< wxString > aDefault)
wxString fromFileFormat(const wxString &aString) const
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
PARAM_PATH(const std::string &aJsonPath, wxString *aPtr, const wxString &aDefault, bool aReadOnly=false)
wxString fromFileFormat(const wxString &aString) const
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
wxString toFileFormat(const wxString &aString) const
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
ValueType GetDefault() const
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, double aScale=1.0, bool aReadOnly=false)
virtual void SetDefault() override
PARAM_SCALED(const std::string &aJsonPath, ValueType *aPtr, ValueType aDefault, ValueType aMin, ValueType aMax, double aScale=1.0, bool aReadOnly=false)
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
PARAM_SET(const std::string &aJsonPath, std::set< Type > *aPtr, std::initializer_list< Type > aDefault, bool aReadOnly=false)
PARAM_SET(const std::string &aJsonPath, std::set< Type > *aPtr, std::set< Type > aDefault, bool aReadOnly=false)
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.
void SetDefault() override
std::set< Type > m_default
virtual void SetDefault() override
std::map< wxString, wxString > * m_ptr
PARAM_WXSTRING_MAP(const std::string &aJsonPath, std::map< wxString, wxString > *aPtr, std::initializer_list< std::pair< const wxString, wxString > > aDefault, bool aReadOnly=false, bool aArrayBehavior=false)
std::map< wxString, wxString > m_default
void Load(const JSON_SETTINGS &aSettings, bool aResetIfMissing=true) const override
Loads the value of this parameter from JSON to the underlying storage.
PARAM(const std::string &aJsonPath, ValueType *aPtr, const ValueType &aDefault, bool aReadOnly=false)
bool MatchesFile(const JSON_SETTINGS &aSettings) const override
Checks whether the parameter in memory matches the one in a given JSON file.
void SetDefault() override
PARAM(const std::string &aJsonPath, ValueType *aPtr, const ValueType &aDefault, const ValueType &aMin, const ValueType &aMax, bool aReadOnly=false)
ValueType GetDefault() const
void Store(JSON_SETTINGS *aSettings) const override
Stores the value of this parameter to the given JSON_SETTINGS object.