Added setValue/getValue/canonicalPath/getPaths/verifyPath methods to various Property classes.

This commit is contained in:
Eivind Kvedalen
2015-09-16 18:40:44 +02:00
committed by wmayer
parent 722a40dd41
commit ddc22a4101
6 changed files with 160 additions and 1 deletions

View File

@@ -35,9 +35,11 @@
#include <Base/Reader.h>
#include <Base/Writer.h>
#include <Base/Stream.h>
#include <Base/Quantity.h>
#include "PropertyStandard.h"
#include "MaterialPy.h"
#include "ObjectIdentifier.h"
using namespace App;
using namespace Base;
@@ -130,6 +132,22 @@ void PropertyInteger::Paste(const Property &from)
hasSetValue();
}
void PropertyInteger::setValue(const ObjectIdentifier &path, const boost::any &value)
{
verifyPath(path);
if (value.type() == typeid(long))
setValue(boost::any_cast<long>(value));
else if (value.type() == typeid(double))
setValue(round(boost::any_cast<double>(value)));
else if (value.type() == typeid(Quantity) && boost::any_cast<Quantity>(value).getUnit().isEmpty())
setValue(round(boost::any_cast<Quantity>(value).getValue()));
else if (value.type() == typeid(int))
setValue(boost::any_cast<int>(value));
else
throw bad_cast();
}
//**************************************************************************
//**************************************************************************
@@ -462,6 +480,26 @@ void PropertyEnumeration::Paste(const Property &from)
hasSetValue();
}
void PropertyEnumeration::setValue(const ObjectIdentifier &path, const boost::any &value)
{
verifyPath(path);
if (value.type() == typeid(int))
setValue(boost::any_cast<int>(value));
else if (value.type() == typeid(double))
setValue(boost::any_cast<double>(value));
else if (value.type() == typeid(short))
setValue(boost::any_cast<short>(value));
else if (value.type() == typeid(std::string))
setValue(boost::any_cast<std::string>(value).c_str());
else if (value.type() == typeid(char*))
setValue(boost::any_cast<char*>(value));
else if (value.type() == typeid(const char*))
setValue(boost::any_cast<const char*>(value));
else
throw bad_cast();
}
//**************************************************************************
//**************************************************************************
// PropertyIntegerConstraint
@@ -920,6 +958,24 @@ void PropertyFloat::Paste(const Property &from)
hasSetValue();
}
void PropertyFloat::setValue(const ObjectIdentifier &path, const boost::any &value)
{
verifyPath(path);
if (value.type() == typeid(double))
setValue(boost::any_cast<double>(value));
else if (value.type() == typeid(Quantity) && boost::any_cast<Quantity>(value).getUnit().isEmpty())
setValue((boost::any_cast<Quantity>(value)).getValue());
else
throw bad_cast();
}
const boost::any PropertyFloat::getValue(const ObjectIdentifier &path) const
{
verifyPath(path);
return _dValue;
}
//**************************************************************************
//**************************************************************************
// PropertyFloatConstraint
@@ -1290,6 +1346,17 @@ unsigned int PropertyString::getMemSize (void) const
return static_cast<unsigned int>(_cValue.size());
}
void PropertyString::setValue(const ObjectIdentifier &path, const boost::any &value)
{
verifyPath(path);
}
const boost::any PropertyString::getValue(const ObjectIdentifier &path) const
{
verifyPath(path);
return _cValue;
}
//**************************************************************************
//**************************************************************************
// PropertyUUID
@@ -1838,6 +1905,29 @@ void PropertyBool::Paste(const Property &from)
hasSetValue();
}
void PropertyBool::setValue(const ObjectIdentifier &path, const boost::any &value)
{
verifyPath(path);
if (value.type() == typeid(bool))
setValue(boost::any_cast<bool>(value));
else if (value.type() == typeid(int))
setValue(boost::any_cast<int>(value) != 0);
else if (value.type() == typeid(double))
setValue(round(boost::any_cast<double>(value)));
else if (value.type() == typeid(Quantity) && boost::any_cast<Quantity>(value).getUnit().isEmpty())
setValue(boost::any_cast<Quantity>(value).getValue() != 0);
else
throw bad_cast();
}
const boost::any PropertyBool::getValue(const ObjectIdentifier &path) const
{
verifyPath(path);
return _lValue;
}
//**************************************************************************
//**************************************************************************
// PropertyBoolList