diff --git a/src/App/PropertyGeo.cpp b/src/App/PropertyGeo.cpp index ff5315f87..668edc7df 100644 --- a/src/App/PropertyGeo.cpp +++ b/src/App/PropertyGeo.cpp @@ -34,13 +34,14 @@ #include #include #include +#include #include #include #include #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 &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)); diff --git a/src/App/PropertyGeo.h b/src/App/PropertyGeo.h index e97c7e8a9..4b16db382 100644 --- a/src/App/PropertyGeo.h +++ b/src/App/PropertyGeo.h @@ -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 &paths) const; + const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyPlacementItem"; } diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 7e1d73d79..558ec05fa 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -35,9 +35,11 @@ #include #include #include +#include #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(value)); + else if (value.type() == typeid(double)) + setValue(round(boost::any_cast(value))); + else if (value.type() == typeid(Quantity) && boost::any_cast(value).getUnit().isEmpty()) + setValue(round(boost::any_cast(value).getValue())); + else if (value.type() == typeid(int)) + setValue(boost::any_cast(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(value)); + else if (value.type() == typeid(double)) + setValue(boost::any_cast(value)); + else if (value.type() == typeid(short)) + setValue(boost::any_cast(value)); + else if (value.type() == typeid(std::string)) + setValue(boost::any_cast(value).c_str()); + else if (value.type() == typeid(char*)) + setValue(boost::any_cast(value)); + else if (value.type() == typeid(const char*)) + setValue(boost::any_cast(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(value)); + else if (value.type() == typeid(Quantity) && boost::any_cast(value).getUnit().isEmpty()) + setValue((boost::any_cast(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(_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(value)); + else if (value.type() == typeid(int)) + setValue(boost::any_cast(value) != 0); + else if (value.type() == typeid(double)) + setValue(round(boost::any_cast(value))); + else if (value.type() == typeid(Quantity) && boost::any_cast(value).getUnit().isEmpty()) + setValue(boost::any_cast(value).getValue() != 0); + else + throw bad_cast(); +} + +const boost::any PropertyBool::getValue(const ObjectIdentifier &path) const +{ + verifyPath(path); + + return _lValue; +} + //************************************************************************** //************************************************************************** // PropertyBoolList diff --git a/src/App/PropertyStandard.h b/src/App/PropertyStandard.h index fe59fe062..ab71a316d 100644 --- a/src/App/PropertyStandard.h +++ b/src/App/PropertyStandard.h @@ -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; }; diff --git a/src/App/PropertyUnits.cpp b/src/App/PropertyUnits.cpp index f1d577f44..7f1b2c1dc 100644 --- a/src/App/PropertyUnits.cpp +++ b/src/App/PropertyUnits.cpp @@ -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(value)); + else if (value.type() == typeid(Base::Quantity)) + setValue((boost::any_cast(value)).getValue()); + else + throw bad_cast(); +} + +const boost::any PropertyQuantity::getValue(const ObjectIdentifier &path) const +{ + return Quantity(_dValue, _Unit); +} + //************************************************************************** //************************************************************************** // PropertyQuantityConstraint diff --git a/src/App/PropertyUnits.h b/src/App/PropertyUnits.h index d6d279279..749e80ba9 100644 --- a/src/App/PropertyUnits.h +++ b/src/App/PropertyUnits.h @@ -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;