60 : m_type(
SCALAR_INT), m_name(name), m_getInt(getter), m_setInt(setter)
65 : m_type(
SCALAR_BOOL), m_name(name), m_getBool(getter), m_setBool(setter)
70 : m_type(
SCALAR_REAL), m_name(name), m_getReal(getter), m_setReal(setter)
75 : m_type(
STRING), m_name(name), m_getString(getter), m_setString(setter)
80 : m_type(
ARRAY_VEC3), m_name(name), m_numValues(numValues), m_getVec3(getter), m_setVec3(setter)
86 : m_type(
SCALAR_INT), m_name(name), m_group(group), m_getInt(getter), m_setInt(setter)
91 : m_type(
SCALAR_BOOL), m_name(name), m_group(group), m_getBool(getter), m_setBool(setter)
96 : m_type(
SCALAR_REAL), m_name(name), m_group(group), m_getReal(getter), m_setReal(setter)
101 : m_type(
STRING), m_name(name), m_group(group), m_getString(getter), m_setString(setter)
106 : m_type(
ARRAY_VEC3), m_name(name), m_group(group), m_getVec3(getter), m_setVec3(setter)
116 if ( value.isString() ) {
131 result = value.asInt();
133 else if (value.isString()) {
134 result = atoi(value.asString().c_str());
147 if ( value.isBool() )
149 result = value.asBool();
151 else if ( value.isString() ) {
165 if (value.isString())
166 result = value.asString();
176 if ( value.isDouble() ) {
177 return value.asDouble();
179 else if ( value.isString() ) {
181 if ( value.asString() ==
"inf" ) {
184 else if ( value.asString() ==
"-inf" ) {
189 LOGGER_WARNING() <<
"Unknown value \"" << value.asString() <<
"\" in json data for " <<
208 if ( value.isArray() ) {
209 if ( value.size() != m_numValues )
210 LOGGER_WARNING() <<
"Array with values for " << m_name <<
" does not have expected length "
213 agxJson::Value::ArrayIndex maxIndex = std::min(value.size(), std::min(m_numValues, 3u));
215 for ( agxJson::Value::ArrayIndex i = 0; i < maxIndex; i++) {
216 agxJson::Value valueNode = value[i];
224 else if ( value.isDouble() ) {
228 else if ( value.isString() ) {
233 LOGGER_WARNING() <<
"Unknown value \"" << value.asString() <<
"\" in json data for " <<
248 agxJson::Value object;
250 if ( m_group !=
"" ) {
251 if ( !
root.hasMember( m_group.c_str() ) ) {
256 object =
root[m_group];
262 if ( !
object.hasMember( m_name.c_str() ) ) {
268 agxJson::Value valueNode =
object[m_name];
281 m_setVec3( v, material );
286 m_setReal( r, material );
289 else if (m_type ==
STRING) {
290 if (!valueNode.asString().empty()) {
292 m_setString(r, material);
298 m_setInt(val, material);
304 m_setBool( b, material );
354 node = (value ?
"true" :
"false" );
363 agxJson::Value::ArrayIndex maxIndex = std::min(m_numValues, 3u);
364 node.resize( maxIndex );
366 for ( agxJson::Value::ArrayIndex i = 0; i < maxIndex; ++i) {
378 agxJson::Value* outputNode = &
root;
380 if ( m_group.length() > 0 ) {
382 if ( !
root.hasMember( m_group ) ) {
386 outputNode = &
root[ m_group ];
399 else if (m_type ==
STRING) {
409 m_resolved = outputNode->hasMember( m_name );
428 if ( m_group.length() > 0 ) {
441 unsigned int m_numValues { 0 };
458 bool m_resolved {
false };
static AgXString format(const char *format,...)
C printf formatting of a string.
A template class that can be used to read/write a json property and set/get the value in another obje...
bool isDefault(const agxJson::Value &value) const
Is value marked as "default"?
GenericJsonParameter(const agx::String &name, const agx::String &group, PropertySetVec3 setter, PropertyGetVec3 getter)
GenericJsonParameter(const agx::String &name, const agx::String &group, PropertySetReal setter, PropertyGetReal getter)
void writeValueVec3(agxJson::Value &node, agx::Vec3 value)
Write a short array, at most 3 elements.
GenericJsonParameter(const agx::String &name, const agx::String &group, PropertySetBool setter, PropertyGetBool getter)
void writeValueString(agxJson::Value &node, const agx::String value)
Writes a string value to a json node.
void writeValueBool(agxJson::Value &node, bool value)
Writes a bool value to a json node.
GenericJsonParameter(const agx::String &name, PropertySetString setter, PropertyGetString getter)
void writeValueInt(agxJson::Value &node, int value)
Writes an int value to a json node.
int parseInt(const agxJson::Value &value) const
Read an int from a json value.
void parseVec3(const agxJson::Value &value, agx::Vec3 &result) const
Parse a json node and produce a Vec3.
std::function< agx::Vec3(const T *) > PropertyGetVec3
ParameterType
Type of parameter that should be handled.
GenericJsonParameter(const agx::String &name, PropertySetVec3 setter, PropertyGetVec3 getter, unsigned int numValues)
bool writeProperty(agxJson::Value &root, const T *material)
Store a generic property to json.
std::function< void(int, T *) > PropertySetInt
agx::String parseString(const agxJson::Value &value) const
Read a string from a json value.
GenericJsonParameter(const agx::String &name, PropertySetInt setter, PropertyGetInt getter)
std::function< agx::String(const T *) > PropertyGetString
void writeValueReal(agxJson::Value &node, agx::Real value)
Writes a real value to a json node.
std::function< void(agx::String, T *) > PropertySetString
bool isResolved() const
Status flag if parameter could be read/written.
GenericJsonParameter(const agx::String &name, const agx::String &group, PropertySetInt setter, PropertyGetInt getter)
GenericJsonParameter(const agx::String &name, PropertySetBool setter, PropertyGetBool getter)
std::function< void(bool, T *) > PropertySetBool
std::function< bool(const T *) > PropertyGetBool
std::function< void(agx::Vec3, T *) > PropertySetVec3
bool parseBool(const agxJson::Value &value) const
Read a bool from a json value.
GenericJsonParameter(const agx::String &name, PropertySetReal setter, PropertyGetReal getter)
std::function< agx::Real(const T *) > PropertyGetReal
std::function< int(const T *) > PropertyGetInt
std::function< void(agx::Real, T *) > PropertySetReal
agx::Real parseReal(const agxJson::Value &value) const
Read a real number from a json value.
agx::String getParameterPath() const
Text representation of where in the json structure this parameter lives.
bool readProperty(const agxJson::Value &root, T *material, bool optional=false)
Reads a generic property from a json structure.
GenericJsonParameter(const agx::String &name, const agx::String &group, PropertySetString setter, PropertyGetString getter)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
AgXString< std::string > String
AGXCORE_EXPORT const Real Infinity
AGXCORE_EXPORT Component * root()
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)