do not use an int but an enum to handle different modes
This commit is contained in:
@@ -371,23 +371,26 @@ PyObject *FeaturePythonImp::getPyObject(void)
|
||||
return new FeaturePythonPyT<DocumentObjectPy>(object);
|
||||
}
|
||||
|
||||
int FeaturePythonImp::hasChildElement() const {
|
||||
_FC_PY_CALL_CHECK(hasChildElement,return(-1));
|
||||
FeaturePythonImp::ValueT
|
||||
FeaturePythonImp::hasChildElement() const
|
||||
{
|
||||
_FC_PY_CALL_CHECK(hasChildElement,return(NotImplemented));
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(object->getPyObject(), true));
|
||||
Py::Boolean ok(Base::pyCall(py_hasChildElement.ptr(),args.ptr()));
|
||||
return static_cast<bool>(ok) ? 1 : 0;
|
||||
return static_cast<bool>(ok) ? Accepted : Rejected;
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
|
||||
PyErr_Clear();
|
||||
return -1;
|
||||
return NotImplemented;
|
||||
}
|
||||
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
return 0;
|
||||
return Rejected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,43 +457,48 @@ std::string FeaturePythonImp::getViewProviderName()
|
||||
return std::string();
|
||||
}
|
||||
|
||||
int FeaturePythonImp::canLinkProperties() const {
|
||||
_FC_PY_CALL_CHECK(canLinkProperties,return(-1));
|
||||
FeaturePythonImp::ValueT
|
||||
FeaturePythonImp::canLinkProperties() const
|
||||
{
|
||||
_FC_PY_CALL_CHECK(canLinkProperties,return(NotImplemented));
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(object->getPyObject(), true));
|
||||
Py::Boolean ok(Base::pyCall(py_canLinkProperties.ptr(),args.ptr()));
|
||||
return ok?1:0;
|
||||
return ok ? Accepted : Rejected;
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
|
||||
PyErr_Clear();
|
||||
return -1;
|
||||
return NotImplemented;
|
||||
}
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
return 0;
|
||||
return Rejected;
|
||||
}
|
||||
}
|
||||
|
||||
int FeaturePythonImp::allowDuplicateLabel() const {
|
||||
_FC_PY_CALL_CHECK(allowDuplicateLabel,return(-1));
|
||||
FeaturePythonImp::ValueT
|
||||
FeaturePythonImp::allowDuplicateLabel() const
|
||||
{
|
||||
_FC_PY_CALL_CHECK(allowDuplicateLabel,return(NotImplemented));
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(object->getPyObject(), true));
|
||||
Py::Boolean ok(Base::pyCall(py_allowDuplicateLabel.ptr(),args.ptr()));
|
||||
return ok?1:0;
|
||||
return ok ? Accepted : Rejected;
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
|
||||
PyErr_Clear();
|
||||
return -1;
|
||||
return NotImplemented;
|
||||
}
|
||||
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
return 0;
|
||||
return Rejected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,10 +522,12 @@ int FeaturePythonImp::canLoadPartial() const {
|
||||
}
|
||||
}
|
||||
|
||||
int FeaturePythonImp::redirectSubName(std::ostringstream &ss,
|
||||
App::DocumentObject *topParent, App::DocumentObject *child) const
|
||||
FeaturePythonImp::ValueT
|
||||
FeaturePythonImp::redirectSubName(std::ostringstream &ss,
|
||||
App::DocumentObject *topParent,
|
||||
App::DocumentObject *child) const
|
||||
{
|
||||
FC_PY_CALL_CHECK(redirectSubName);
|
||||
_FC_PY_CALL_CHECK(redirectSubName,return(NotImplemented));
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
Py::Tuple args(4);
|
||||
@@ -526,20 +536,21 @@ int FeaturePythonImp::redirectSubName(std::ostringstream &ss,
|
||||
args.setItem(2,topParent?Py::Object(topParent->getPyObject(),true):Py::Object());
|
||||
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 0;
|
||||
if (ret.isNone())
|
||||
return Rejected;
|
||||
ss.str("");
|
||||
ss << ret.as_string();
|
||||
return 1;
|
||||
return Accepted;
|
||||
}
|
||||
catch (Py::Exception&) {
|
||||
if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
|
||||
PyErr_Clear();
|
||||
return -1;
|
||||
return NotImplemented;
|
||||
}
|
||||
|
||||
Base::PyException e; // extract the Python error text
|
||||
e.ReportException();
|
||||
return 0;
|
||||
return Rejected;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,12 @@ class Property;
|
||||
class AppExport FeaturePythonImp
|
||||
{
|
||||
public:
|
||||
enum ValueT {
|
||||
NotImplemented = 0, // not handled
|
||||
Accepted = 1, // handled and accepted
|
||||
Rejected = 2 // handled and rejected
|
||||
};
|
||||
|
||||
FeaturePythonImp(App::DocumentObject*);
|
||||
~FeaturePythonImp();
|
||||
|
||||
@@ -61,19 +67,20 @@ public:
|
||||
bool getSubObjects(std::vector<std::string> &ret, int reason) const;
|
||||
|
||||
bool getLinkedObject(App::DocumentObject *&ret, bool recurse,
|
||||
Base::Matrix4D *mat, bool transform, int depth) const;
|
||||
Base::Matrix4D *mat, bool transform, int depth) const;
|
||||
|
||||
int canLinkProperties() const;
|
||||
ValueT canLinkProperties() const;
|
||||
|
||||
int allowDuplicateLabel() const;
|
||||
ValueT allowDuplicateLabel() const;
|
||||
|
||||
int redirectSubName(std::ostringstream &ss,
|
||||
App::DocumentObject *topParent, App::DocumentObject *child) const;
|
||||
ValueT redirectSubName(std::ostringstream &ss,
|
||||
App::DocumentObject *topParent,
|
||||
App::DocumentObject *child) const;
|
||||
|
||||
int canLoadPartial() const;
|
||||
|
||||
/// return true to activate tree view group object handling
|
||||
int hasChildElement() const;
|
||||
ValueT hasChildElement() const;
|
||||
/// Get sub-element visibility
|
||||
int isElementVisible(const char *) const;
|
||||
/// Set sub-element visibility
|
||||
@@ -235,10 +242,14 @@ public:
|
||||
|
||||
/// return true to activate tree view group object handling
|
||||
virtual bool hasChildElement() const override {
|
||||
int ret = imp->hasChildElement();
|
||||
if(ret<0)
|
||||
switch (imp->hasChildElement()) {
|
||||
case FeaturePythonImp::Accepted:
|
||||
return true;
|
||||
case FeaturePythonImp::Rejected:
|
||||
return false;
|
||||
default:
|
||||
return FeatureT::hasChildElement();
|
||||
return ret?true:false;
|
||||
}
|
||||
}
|
||||
/// Get sub-element visibility
|
||||
virtual int isElementVisible(const char *element) const override {
|
||||
@@ -256,26 +267,38 @@ public:
|
||||
}
|
||||
|
||||
virtual bool canLinkProperties() const override {
|
||||
int ret = imp->canLinkProperties();
|
||||
if(ret < 0)
|
||||
switch (imp->canLinkProperties()) {
|
||||
case FeaturePythonImp::Accepted:
|
||||
return true;
|
||||
case FeaturePythonImp::Rejected:
|
||||
return false;
|
||||
default:
|
||||
return FeatureT::canLinkProperties();
|
||||
return ret?true:false;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool allowDuplicateLabel() const override {
|
||||
int ret = imp->allowDuplicateLabel();
|
||||
if(ret < 0)
|
||||
switch (imp->allowDuplicateLabel()) {
|
||||
case FeaturePythonImp::Accepted:
|
||||
return true;
|
||||
case FeaturePythonImp::Rejected:
|
||||
return false;
|
||||
default:
|
||||
return FeatureT::allowDuplicateLabel();
|
||||
return ret?true:false;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool redirectSubName(std::ostringstream &ss,
|
||||
App::DocumentObject *topParent, App::DocumentObject *child) const override
|
||||
{
|
||||
int ret = imp->redirectSubName(ss,topParent,child);
|
||||
if(ret < 0)
|
||||
return FeatureT::redirectSubName(ss,topParent,child);
|
||||
return ret?true:false;
|
||||
switch (imp->redirectSubName(ss,topParent,child)) {
|
||||
case FeaturePythonImp::Accepted:
|
||||
return true;
|
||||
case FeaturePythonImp::Rejected:
|
||||
return false;
|
||||
default:
|
||||
return FeatureT::redirectSubName(ss, topParent, child);
|
||||
}
|
||||
}
|
||||
|
||||
virtual int canLoadPartial() const override {
|
||||
|
||||
Reference in New Issue
Block a user