94template<
typename ValueType>
98 PARAM(
const std::string& aJsonPath, ValueType* aPtr,
const ValueType& aDefault,
99 bool aReadOnly =
false ) :
108 PARAM(
const std::string& aJsonPath, ValueType* aPtr,
const ValueType& aDefault,
109 const ValueType& aMin,
const ValueType& aMax,
bool aReadOnly =
false ) :
123 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
125 ValueType val = *optval;
135 else if( aResetIfMissing )
158 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
159 return *optval == *
m_ptr;
180 PARAM_PATH(
const std::string& aJsonPath, wxString* aPtr,
const wxString& aDefault,
181 bool aReadOnly =
false ) :
182 PARAM( aJsonPath, aPtr, aDefault, aReadOnly )
202 if( std::optional<wxString> optval = aSettings.
Get<wxString>(
m_path ) )
211 wxString ret = aString;
212 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
218 wxString ret = aString;
220 if( !ret.Contains( wxT(
"://" ) ) )
221 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
230template<
typename EnumType>
234 PARAM_ENUM(
const std::string& aJsonPath, EnumType* aPtr, EnumType aDefault,
235 EnumType aMin, EnumType aMax,
bool aReadOnly =
false ) :
249 if( std::optional<int> val = aSettings.
Get<
int>(
m_path ) )
251 if( *val >=
static_cast<int>(
m_min ) && *val <=
static_cast<int>(
m_max ) )
252 *
m_ptr =
static_cast<EnumType
>( *val );
253 else if( aResetIfMissing )
257 else if( aResetIfMissing )
265 aSettings->
Set<
int>(
m_path,
static_cast<int>( *m_ptr ) );
280 if( std::optional<int> val = aSettings.
Get<
int>(
m_path ) )
281 return *val ==
static_cast<int>( *m_ptr );
297template<
typename ValueType>
301 PARAM_LAMBDA(
const std::string& aJsonPath, std::function<ValueType()> aGetter,
302 std::function<
void( ValueType )> aSetter, ValueType aDefault,
303 bool aReadOnly =
false ) :
316 if( std::is_same<ValueType, nlohmann::json>::value )
318 if( std::optional<nlohmann::json> optval = aSettings.
GetJson(
m_path ) )
325 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
355 if( std::is_same<ValueType, nlohmann::json>::value )
357 if( std::optional<nlohmann::json> optval = aSettings.
GetJson(
m_path ) )
362 if( std::optional<ValueType> optval = aSettings.
Get<ValueType>(
m_path ) )
378 if constexpr( std::is_same_v<ValueType, nlohmann::json> )
408template<
typename ValueType>
412 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
413 double aScale = 1.0,
bool aReadOnly =
false ) :
424 PARAM_SCALED(
const std::string& aJsonPath, ValueType* aPtr, ValueType aDefault,
425 ValueType aMin, ValueType aMax,
double aScale = 1.0,
bool aReadOnly =
false ) :
443 if( std::optional<double> optval = aSettings.
Get<
double>(
m_path ) )
445 else if( !aResetIfMissing )
476 if( std::optional<double> optval = aSettings.
Get<
double>(
m_path ) )
492template<
typename Type>
496 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
497 std::initializer_list<Type> aDefault,
bool aResetIfEmpty =
false ) :
504 PARAM_LIST(
const std::string& aJsonPath, std::vector<Type>* aPtr,
505 std::vector<Type> aDefault,
bool aResetIfEmpty =
false ) :
517 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
519 std::vector<Type> val;
523 for(
const auto& el : js->items() )
524 val.push_back( el.value().get<Type>() );
532 else if( aResetIfMissing )
540 nlohmann::json js = nlohmann::json::array();
542 for(
const auto& el : *
m_ptr )
545 aSettings->
Set<nlohmann::json>(
m_path, js );
555 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
559 std::vector<Type> val;
561 for(
const auto& el : js->items() )
565 val.emplace_back( el.value().get<Type>() );
573 return val == *
m_ptr;
604template<
typename Type>
608 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
609 std::initializer_list<Type> aDefault,
bool aReadOnly =
false ) :
615 PARAM_SET(
const std::string& aJsonPath, std::set<Type>* aPtr,
616 std::set<Type> aDefault,
bool aReadOnly =
false ) :
627 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
633 for(
const auto& el : js->items() )
634 val.insert( el.value().get<Type>() );
639 else if( aResetIfMissing )
645 nlohmann::json js = nlohmann::json::array();
647 for(
const auto& el : *
m_ptr )
650 aSettings->
Set<nlohmann::json>(
m_path, js );
661 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
667 for(
const auto& el : js->items() )
668 val.insert( el.value().get<Type>() );
670 return val == *
m_ptr;
696 std::initializer_list<wxString> aDefault ) :
701 std::vector<wxString> aDefault ) :
712 for(
size_t i = 0; i <
m_ptr->size(); i++ )
718 bool MatchesFile(
const JSON_SETTINGS& aSettings )
const override;
723 wxString ret = aString;
724 ret.Replace( wxT(
"\\" ), wxT(
"/" ) );
730 wxString ret = aString;
732 ret.Replace( wxT(
"/" ), wxT(
"\\" ) );
750template<
typename Value>
754 PARAM_MAP(
const std::string& aJsonPath, std::map<std::string, Value>* aPtr,
755 std::initializer_list<std::pair<const std::string, Value>> aDefault,
756 bool aReadOnly =
false ) :
769 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
771 if( js->is_object() )
775 for(
const auto& el : js->items() )
776 ( *m_ptr )[el.key()] = el.value().get<Value>();
779 else if( aResetIfMissing )
785 nlohmann::json js( {} );
787 for(
const auto& el : *
m_ptr )
788 js[el.first] = el.second;
790 aSettings->
Set<nlohmann::json>(
m_path, js );
800 if( std::optional<nlohmann::json> js = aSettings.
GetJson(
m_path ) )
802 if( js->is_object() )
804 if(
m_ptr->size() != js->size() )
807 std::map<std::string, Value> val;
809 for(
const auto& el : js->items() )
810 val[el.key()] = el.value().get<Value>();
812 return val == *
m_ptr;
820 std::map<std::string, Value>*
m_ptr;
843 std::initializer_list<std::pair<const wxString, wxString>> aDefault,
844 bool aReadOnly =
false,
bool aArrayBehavior =
false ) :
852 void Load(
const JSON_SETTINGS& aSettings,
bool aResetIfMissing =
true )
const override;
861 bool MatchesFile(
const JSON_SETTINGS& aSettings )
const override;
864 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.
bool ResetsParamsIfMissing() const
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 persisting the parameter would leave the file unchanged.
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 persisting the parameter would leave the file unchanged.
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 persisting the parameter would leave the file unchanged.
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 persisting the parameter would leave the file unchanged.
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 persisting the parameter would leave the file unchanged.
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 persisting the parameter would leave the file unchanged.
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 persisting the parameter would leave the file unchanged.
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 persisting the parameter would leave the file unchanged.
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 persisting the parameter would leave the file unchanged.
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.