Added setValue/getValue/canonicalPath/getPaths/verifyPath methods to various Property classes.
This commit is contained in:
parent
722a40dd41
commit
ddc22a4101
|
@ -34,13 +34,14 @@
|
|||
#include <Base/Reader.h>
|
||||
#include <Base/Stream.h>
|
||||
#include <Base/Rotation.h>
|
||||
#include <Base/Quantity.h>
|
||||
#include <Base/VectorPy.h>
|
||||
#include <Base/MatrixPy.h>
|
||||
#include <Base/PlacementPy.h>
|
||||
|
||||
#include "Placement.h"
|
||||
|
||||
#include "PropertyGeo.h"
|
||||
#include "ObjectIdentifier.h"
|
||||
|
||||
using namespace App;
|
||||
using namespace Base;
|
||||
|
@ -538,6 +539,34 @@ const Base::Placement & PropertyPlacement::getValue(void)const
|
|||
return _cPos;
|
||||
}
|
||||
|
||||
void PropertyPlacement::getPaths(std::vector<ObjectIdentifier> &paths) const
|
||||
{
|
||||
paths.push_back(ObjectIdentifier(getContainer()) << ObjectIdentifier::Component::SimpleComponent(getName())
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("Base"))
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("x")));
|
||||
paths.push_back(ObjectIdentifier(getContainer()) << ObjectIdentifier::Component::SimpleComponent(getName())
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("Base"))
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("y")));
|
||||
paths.push_back(ObjectIdentifier(getContainer()) << ObjectIdentifier::Component::SimpleComponent(getName())
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("Base"))
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("z")));
|
||||
paths.push_back(ObjectIdentifier(getContainer()) << ObjectIdentifier::Component::SimpleComponent(getName())
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("Rotation"))
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("Angle")));
|
||||
paths.push_back(ObjectIdentifier(getContainer()) << ObjectIdentifier::Component::SimpleComponent(getName())
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("Rotation"))
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("Axis"))
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("x")));
|
||||
paths.push_back(ObjectIdentifier(getContainer()) << ObjectIdentifier::Component::SimpleComponent(getName())
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("Rotation"))
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("Axis"))
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("y")));
|
||||
paths.push_back(ObjectIdentifier(getContainer()) << ObjectIdentifier::Component::SimpleComponent(getName())
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("Rotation"))
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("Axis"))
|
||||
<< ObjectIdentifier::Component::SimpleComponent(ObjectIdentifier::String("z")));
|
||||
}
|
||||
|
||||
PyObject *PropertyPlacement::getPyObject(void)
|
||||
{
|
||||
return new Base::PlacementPy(new Base::Placement(_cPos));
|
||||
|
|
|
@ -259,6 +259,10 @@ public:
|
|||
/** This method returns a string representation of the property
|
||||
*/
|
||||
const Base::Placement &getValue(void) const;
|
||||
|
||||
/// Get valid paths for this property; used by auto completer
|
||||
void getPaths(std::vector<ObjectIdentifier> &paths) const;
|
||||
|
||||
const char* getEditorName(void) const {
|
||||
return "Gui::PropertyEditor::PropertyPlacementItem";
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -77,6 +77,9 @@ public:
|
|||
|
||||
virtual unsigned int getMemSize (void) const{return sizeof(long);}
|
||||
|
||||
virtual void setValue(const App::ObjectIdentifier & path, const boost::any & value);
|
||||
virtual const boost::any getValue(const App::ObjectIdentifier & path) const { return _lValue; }
|
||||
|
||||
protected:
|
||||
long _lValue;
|
||||
};
|
||||
|
@ -195,6 +198,9 @@ public:
|
|||
virtual Property * Copy(void) const;
|
||||
virtual void Paste(const Property &from);
|
||||
|
||||
virtual void setValue(const App::ObjectIdentifier & path, const boost::any & value);
|
||||
virtual const boost::any getValue(const App::ObjectIdentifier & path) const { return _enum; }
|
||||
|
||||
private:
|
||||
Enumeration _enum;
|
||||
};
|
||||
|
@ -453,6 +459,9 @@ public:
|
|||
|
||||
virtual unsigned int getMemSize (void) const{return sizeof(double);}
|
||||
|
||||
void setValue(const App::ObjectIdentifier &path, const boost::any &value);
|
||||
const boost::any getValue(const App::ObjectIdentifier &path) const;
|
||||
|
||||
protected:
|
||||
double _dValue;
|
||||
};
|
||||
|
@ -605,6 +614,9 @@ public:
|
|||
virtual void Paste(const Property &from);
|
||||
virtual unsigned int getMemSize (void) const;
|
||||
|
||||
void setValue(const App::ObjectIdentifier &path, const boost::any &value);
|
||||
const boost::any getValue(const App::ObjectIdentifier &path) const;
|
||||
|
||||
private:
|
||||
std::string _cValue;
|
||||
};
|
||||
|
@ -756,6 +768,9 @@ public:
|
|||
|
||||
virtual unsigned int getMemSize (void) const{return sizeof(bool);}
|
||||
|
||||
void setValue(const App::ObjectIdentifier &path, const boost::any &value);
|
||||
const boost::any getValue(const App::ObjectIdentifier &path) const;
|
||||
|
||||
private:
|
||||
bool _lValue;
|
||||
};
|
||||
|
|
|
@ -118,6 +118,21 @@ void PropertyQuantity::setPyObject(PyObject *value)
|
|||
PropertyFloat::setValue(quant.getValue());
|
||||
}
|
||||
|
||||
void PropertyQuantity::setValue(const ObjectIdentifier &path, const boost::any &value)
|
||||
{
|
||||
if (value.type() == typeid(double))
|
||||
setValue(boost::any_cast<double>(value));
|
||||
else if (value.type() == typeid(Base::Quantity))
|
||||
setValue((boost::any_cast<Quantity>(value)).getValue());
|
||||
else
|
||||
throw bad_cast();
|
||||
}
|
||||
|
||||
const boost::any PropertyQuantity::getValue(const ObjectIdentifier &path) const
|
||||
{
|
||||
return Quantity(_dValue, _Unit);
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
//**************************************************************************
|
||||
// PropertyQuantityConstraint
|
||||
|
|
|
@ -65,6 +65,12 @@ public:
|
|||
void setUnit(const Base::Unit &u) {_Unit = u;}
|
||||
const Base::Unit &getUnit(void) const {return _Unit;}
|
||||
|
||||
void setValue(double lValue) { PropertyFloat::setValue(lValue); }
|
||||
double getValue(void) const { return PropertyFloat::getValue(); }
|
||||
|
||||
virtual void setValue(const App::ObjectIdentifier &path, const boost::any &value);
|
||||
virtual const boost::any getValue(const App::ObjectIdentifier &path) const;
|
||||
|
||||
protected:
|
||||
Base::Quantity createQuantityFromPy(PyObject *value);
|
||||
Base::Unit _Unit;
|
||||
|
|
Loading…
Reference in New Issue
Block a user