move handling of dynamic properties from FeaturePythonPyT to DocumentObjectPy

This commit is contained in:
wmayer
2016-11-09 16:09:21 +01:00
parent 07a2182674
commit 76279882da
6 changed files with 87 additions and 140 deletions

View File

@@ -257,13 +257,42 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args)
}
PyObject *DocumentObjectPy::getCustomAttributes(const char* /*attr*/) const
PyObject *DocumentObjectPy::getCustomAttributes(const char* attr) const
{
return 0;
// search for dynamic property
Property* prop = getDocumentObjectPtr()->getDynamicPropertyByName(attr);
if (prop)
return prop->getPyObject();
else
return 0;
}
int DocumentObjectPy::setCustomAttributes(const char* attr, PyObject *obj)
{
// explicitly search for dynamic property
try {
Property* prop = getDocumentObjectPtr()->getDynamicPropertyByName(attr);
if (prop) {
prop->setPyObject(obj);
return 1;
}
}
catch (Base::ValueError &exc) {
std::stringstream s;
s << "Property '" << attr << "': " << exc.what();
throw Py::ValueError(s.str());
}
catch (Base::Exception &exc) {
std::stringstream s;
s << "Attribute (Name: " << attr << ") error: '" << exc.what() << "' ";
throw Py::AttributeError(s.str());
}
catch (...) {
std::stringstream s;
s << "Unknown error in attribute " << attr;
throw Py::AttributeError(s.str());
}
// search in PropertyList
Property *prop = getDocumentObjectPtr()->getPropertyByName(attr);
if (prop) {