Navigation Menu

Skip to content

Commit

Permalink
App/Gui: unify NotImplementedError handling in python features
Browse files Browse the repository at this point in the history
Recognize NotImplementedError as an indication to call the C++
implementation.
  • Loading branch information
realthunder authored and wwmayer committed Sep 27, 2019
1 parent 68aca24 commit 0f29155
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 156 deletions.
62 changes: 52 additions & 10 deletions src/App/FeaturePython.cpp
Expand Up @@ -84,6 +84,10 @@ bool FeaturePythonImp::execute()
}
}
catch (Py::Exception&) {
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
PyErr_Clear();
return false;
}
Base::PyException e; // extract the Python error text
e.ReportException();
std::stringstream str;
Expand Down Expand Up @@ -272,6 +276,10 @@ bool FeaturePythonImp::getSubObject(DocumentObject *&ret, const char *subname,
return true;
}
catch (Py::Exception&) {
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
PyErr_Clear();
return false;
}
Base::PyException e; // extract the Python error text
e.ReportException();
ret = 0;
Expand Down Expand Up @@ -301,6 +309,10 @@ bool FeaturePythonImp::getSubObjects(std::vector<std::string> &ret, int reason)
return true;
}
catch (Py::Exception&) {
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
PyErr_Clear();
return false;
}
Base::PyException e; // extract the Python error text
e.ReportException();
return true;
Expand Down Expand Up @@ -346,6 +358,10 @@ bool FeaturePythonImp::getLinkedObject(DocumentObject *&ret, bool recurse,
return true;
}
catch (Py::Exception&) {
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
PyErr_Clear();
return false;
}
Base::PyException e; // extract the Python error text
e.ReportException();
ret = 0;
Expand All @@ -369,11 +385,14 @@ int FeaturePythonImp::hasChildElement() const {
return static_cast<bool>(ok) ? 1 : 0;
}
catch (Py::Exception&) {
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
PyErr_Clear();
return -1;
}
Base::PyException e; // extract the Python error text
e.ReportException();
return 0;
}

return -1;
}

int FeaturePythonImp::isElementVisible(const char *element) const {
Expand All @@ -386,10 +405,14 @@ int FeaturePythonImp::isElementVisible(const char *element) const {
return Py::Int(Base::pyCall(py_isElementVisible.ptr(),args.ptr()));
}
catch (Py::Exception&) {
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
PyErr_Clear();
return -2;
}
Base::PyException e; // extract the Python error text
e.ReportException();
return -1;
}
return -2;
}

int FeaturePythonImp::setElementVisible(const char *element, bool visible) {
Expand All @@ -403,11 +426,14 @@ int FeaturePythonImp::setElementVisible(const char *element, bool visible) {
return Py::Int(Base::pyCall(py_setElementVisible.ptr(),args.ptr()));
}
catch (Py::Exception&) {
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
PyErr_Clear();
return -2;
}
Base::PyException e; // extract the Python error text
e.ReportException();
return -1;
}

return -2;
}

bool FeaturePythonImp::allowOverrideViewProviderName() const
Expand Down Expand Up @@ -442,6 +468,10 @@ int FeaturePythonImp::canLinkProperties() const {
return ok?1:0;
}
catch (Py::Exception&) {
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
PyErr_Clear();
return -1;
}
Base::PyException e; // extract the Python error text
e.ReportException();
return 0;
Expand All @@ -458,6 +488,10 @@ int FeaturePythonImp::allowDuplicateLabel() const {
return ok?1:0;
}
catch (Py::Exception&) {
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
PyErr_Clear();
return -1;
}
Base::PyException e; // extract the Python error text
e.ReportException();
return 0;
Expand All @@ -474,13 +508,17 @@ int FeaturePythonImp::canLoadPartial() const {
return ret;
}
catch (Py::Exception&) {
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
PyErr_Clear();
return -1;
}
Base::PyException e; // extract the Python error text
e.ReportException();
return 0;
}
return -1;
}

bool FeaturePythonImp::redirectSubName(std::ostringstream &ss,
int FeaturePythonImp::redirectSubName(std::ostringstream &ss,
App::DocumentObject *topParent, App::DocumentObject *child) const
{
FC_PY_CALL_CHECK(redirectSubName);
Expand All @@ -493,16 +531,20 @@ bool FeaturePythonImp::redirectSubName(std::ostringstream &ss,
args.setItem(3,child?Py::Object(child->getPyObject(),true):Py::Object());
Py::Object ret(Base::pyCall(py_redirectSubName.ptr(),args.ptr()));
if(ret.isNone())
return false;
return 0;
ss.str("");
ss << ret.as_string();
return true;
return 1;
}
catch (Py::Exception&) {
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
PyErr_Clear();
return -1;
}
Base::PyException e; // extract the Python error text
e.ReportException();
return 0;
}
return false;
}

// ---------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions src/App/FeaturePython.h
Expand Up @@ -67,7 +67,7 @@ class AppExport FeaturePythonImp

int allowDuplicateLabel() const;

bool redirectSubName(std::ostringstream &ss,
int redirectSubName(std::ostringstream &ss,
App::DocumentObject *topParent, App::DocumentObject *child) const;

int canLoadPartial() const;
Expand Down Expand Up @@ -272,8 +272,10 @@ class FeaturePythonT : public FeatureT
virtual bool redirectSubName(std::ostringstream &ss,
App::DocumentObject *topParent, App::DocumentObject *child) const override
{
return imp->redirectSubName(ss,topParent,child) ||
FeatureT::redirectSubName(ss,topParent,child);
int ret = imp->redirectSubName(ss,topParent,child);
if(ret < 0)
return FeatureT::redirectSubName(ss,topParent,child);
return ret?true:false;
}

virtual int canLoadPartial() const override {
Expand Down

0 comments on commit 0f29155

Please sign in to comment.