diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index 6a4e12ec78..6daef96f81 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -949,6 +949,16 @@ void DocumentObject::setExpression(const ObjectIdentifier &path, std::shared_ptr ExpressionEngine.setValue(path, expr); } +/** + * @brief Clear the expression of the object identifier \a path in this document object. + * @param path Target object identifier + */ + +void DocumentObject::clearExpression(const ObjectIdentifier & path) +{ + setExpression(path, std::shared_ptr()); +} + /** * @brief Get expression information associated with \a path. * @param path Object identifier diff --git a/src/App/DocumentObject.h b/src/App/DocumentObject.h index 8486c077a4..e994db5249 100644 --- a/src/App/DocumentObject.h +++ b/src/App/DocumentObject.h @@ -425,6 +425,8 @@ public: virtual void setExpression(const ObjectIdentifier & path, std::shared_ptr expr); + void clearExpression(const ObjectIdentifier & path); + virtual const PropertyExpressionEngine::ExpressionInfo getExpression(const ObjectIdentifier &path) const; virtual void renameObjectIdentifiers(const std::map & paths); diff --git a/src/App/DocumentObjectPy.xml b/src/App/DocumentObjectPy.xml index f15f59399a..d5d54c59e6 100644 --- a/src/App/DocumentObjectPy.xml +++ b/src/App/DocumentObjectPy.xml @@ -55,6 +55,11 @@ Register an expression for a property + + + Clear the expression for a property + + Evaluate an expression diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index 88aec80d87..cd2e01c9c0 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -314,21 +314,31 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args) App::ObjectIdentifier p(ObjectIdentifier::parse(getDocumentObjectPtr(), path)); - if (Py::Object(expr).isNone()) - getDocumentObjectPtr()->setExpression(p, std::shared_ptr()); + if (Py::Object(expr).isNone()) { + getDocumentObjectPtr()->clearExpression(p); + Py_Return; + } else if (PyUnicode_Check(expr)) { const char * exprStr = PyUnicode_AsUTF8(expr); std::shared_ptr shared_expr(Expression::parse(getDocumentObjectPtr(), exprStr)); - if(shared_expr && comment) + if (shared_expr && comment) shared_expr->comment = comment; getDocumentObjectPtr()->setExpression(p, shared_expr); + Py_Return; } - else if (PyUnicode_Check(expr)) { - std::string exprStr = PyUnicode_AsUTF8(expr); - } - else - throw Py::TypeError("String or None expected."); + + throw Py::TypeError("String or None expected."); +} + +PyObject* DocumentObjectPy::clearExpression(PyObject * args) +{ + char * path = nullptr; + if (!PyArg_ParseTuple(args, "s", &path)) + return nullptr; + + App::ObjectIdentifier p(ObjectIdentifier::parse(getDocumentObjectPtr(), path)); + getDocumentObjectPtr()->clearExpression(p); Py_Return; }