expose recompute() of document object to Python
This commit is contained in:
parent
a16b143664
commit
2a145a12e1
|
@ -71,23 +71,10 @@ DocumentObject::~DocumentObject(void)
|
|||
}
|
||||
}
|
||||
|
||||
namespace App {
|
||||
class ObjectExecution
|
||||
{
|
||||
public:
|
||||
ObjectExecution(DocumentObject* o) : obj(o)
|
||||
{ obj->StatusBits.set(3); }
|
||||
~ObjectExecution()
|
||||
{ obj->StatusBits.reset(3); }
|
||||
private:
|
||||
DocumentObject* obj;
|
||||
};
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *DocumentObject::recompute(void)
|
||||
{
|
||||
// set/unset the execution bit
|
||||
ObjectExecution exe(this);
|
||||
ObjectStatusLocker exe(App::Recompute, this);
|
||||
return this->execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ enum ObjectStatus {
|
|||
Recompute = 3,
|
||||
Restore = 4,
|
||||
Delete = 5,
|
||||
PythonCall = 6,
|
||||
Expand = 16
|
||||
};
|
||||
|
||||
|
@ -260,6 +261,18 @@ protected: // attributes
|
|||
const std::string *pcNameInDocument;
|
||||
};
|
||||
|
||||
class AppExport ObjectStatusLocker
|
||||
{
|
||||
public:
|
||||
ObjectStatusLocker(ObjectStatus s, DocumentObject* o) : status(s), obj(o)
|
||||
{ obj->setStatus(status, true); }
|
||||
~ObjectStatusLocker()
|
||||
{ obj->setStatus(status, false); }
|
||||
private:
|
||||
ObjectStatus status;
|
||||
DocumentObject* obj;
|
||||
};
|
||||
|
||||
} //namespace App
|
||||
|
||||
#endif // APP_DOCUMENTOBJECT_H
|
||||
|
|
|
@ -45,11 +45,16 @@
|
|||
<UserDocu>Mark the object as unchanged</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="setExpression">
|
||||
<Documentation>
|
||||
<UserDocu>Register an expression for a property</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="setExpression">
|
||||
<Documentation>
|
||||
<UserDocu>Register an expression for a property</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="recompute">
|
||||
<Documentation>
|
||||
<UserDocu>Recomputes this object</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Attribute Name="OutList" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>A list of all objects this object links to.</UserDocu>
|
||||
|
|
|
@ -256,6 +256,19 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args)
|
|||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DocumentObjectPy::recompute(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return NULL;
|
||||
|
||||
try {
|
||||
bool ok = getDocumentObjectPtr()->recomputeFeature();
|
||||
return Py_BuildValue("O", (ok ? Py_True : Py_False));
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
throw Py::RuntimeError(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *DocumentObjectPy::getCustomAttributes(const char* attr) const
|
||||
{
|
||||
|
|
|
@ -51,6 +51,10 @@ FeaturePythonImp::~FeaturePythonImp()
|
|||
*/
|
||||
bool FeaturePythonImp::execute()
|
||||
{
|
||||
// avoid recursive calls of execute()
|
||||
if (object->testStatus(App::PythonCall))
|
||||
return false;
|
||||
|
||||
// Run the execute method of the proxy object.
|
||||
Base::PyGILStateLocker lock;
|
||||
try {
|
||||
|
@ -59,6 +63,7 @@ bool FeaturePythonImp::execute()
|
|||
Py::Object feature = static_cast<PropertyPythonObject*>(proxy)->getValue();
|
||||
if (feature.hasAttr(std::string("execute"))) {
|
||||
if (feature.hasAttr("__object__")) {
|
||||
ObjectStatusLocker exe(App::PythonCall, object);
|
||||
Py::Callable method(feature.getAttr(std::string("execute")));
|
||||
Py::Tuple args;
|
||||
Py::Object res = method.apply(args);
|
||||
|
@ -67,6 +72,7 @@ bool FeaturePythonImp::execute()
|
|||
return true;
|
||||
}
|
||||
else {
|
||||
ObjectStatusLocker exe(App::PythonCall, object);
|
||||
Py::Callable method(feature.getAttr(std::string("execute")));
|
||||
Py::Tuple args(1);
|
||||
args.setItem(0, Py::Object(object->getPyObject(), true));
|
||||
|
|
Loading…
Reference in New Issue
Block a user