From 85c1fa1739e9a1ead5836535bcd7b8f33d78ee59 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 12 Nov 2020 15:46:40 +0100 Subject: [PATCH] App: [skip ci] expose functions to Python to get status string of a feature and whether it's valid --- src/App/DocumentObjectPy.xml | 14 ++++++++++++++ src/App/DocumentObjectPyImp.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/App/DocumentObjectPy.xml b/src/App/DocumentObjectPy.xml index 03e993d874..bc1493fc6c 100644 --- a/src/App/DocumentObjectPy.xml +++ b/src/App/DocumentObjectPy.xml @@ -65,6 +65,20 @@ recompute(recursive=False): Recomputes this object + + + Returns the status of the object as string. +If the object is invalid its error description will be returned. +If the object is valid but touched then 'Touched' will be returned, +'Valid' otherwise. + + + + + + Returns True if the object is valid, False otherwise + + diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index ac5ec8db08..618968d42f 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -397,6 +397,34 @@ PyObject* DocumentObjectPy::recompute(PyObject *args) } } +PyObject* DocumentObjectPy::isValid(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + try { + bool ok = getDocumentObjectPtr()->isValid(); + return Py_BuildValue("O", (ok ? Py_True : Py_False)); + } + catch (const Base::Exception& e) { + throw Py::RuntimeError(e.what()); + } +} + +PyObject* DocumentObjectPy::getStatusString(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + try { + Py::String text(getDocumentObjectPtr()->getStatusString()); + return Py::new_reference_to(text); + } + catch (const Base::Exception& e) { + throw Py::RuntimeError(e.what()); + } +} + PyObject* DocumentObjectPy::getSubObject(PyObject *args, PyObject *keywds) { PyObject *obj;