Active object manager for the Viewer
This commit is contained in:
@@ -64,6 +64,7 @@
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
#include <CXX/Objects.hxx>
|
||||
|
||||
using namespace Gui;
|
||||
@@ -223,15 +224,20 @@ Py::Object View3DInventorPy::getattr(const char * attr)
|
||||
s_out << "Cannot access attribute '" << attr << "' of deleted object";
|
||||
throw Py::RuntimeError(s_out.str());
|
||||
}
|
||||
else {
|
||||
Py::Object obj = Py::PythonExtension<View3DInventorPy>::getattr(attr);
|
||||
if (PyCFunction_Check(obj.ptr())) {
|
||||
PyCFunctionObject* op = reinterpret_cast<PyCFunctionObject*>(obj.ptr());
|
||||
if (!pycxx_handler)
|
||||
pycxx_handler = op->m_ml->ml_meth;
|
||||
op->m_ml->ml_meth = method_varargs_ext_handler;
|
||||
}
|
||||
return obj;
|
||||
else {
|
||||
App::DocumentObject *docObj = _view->ActiveObjects.getObject<App::DocumentObject>(attr);
|
||||
if (docObj){
|
||||
return Py::Object(docObj->getPyObject());
|
||||
}else{
|
||||
Py::Object obj = Py::PythonExtension<View3DInventorPy>::getattr(attr);
|
||||
if (PyCFunction_Check(obj.ptr())) {
|
||||
PyCFunctionObject* op = reinterpret_cast<PyCFunctionObject*>(obj.ptr());
|
||||
if (!pycxx_handler)
|
||||
pycxx_handler = op->m_ml->ml_meth;
|
||||
op->m_ml->ml_meth = method_varargs_ext_handler;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2116,47 +2122,59 @@ Py::Object View3DInventorPy::addDraggerCallback(const Py::Tuple& args)
|
||||
|
||||
Py::Object View3DInventorPy::removeDraggerCallback(const Py::Tuple& args)
|
||||
{
|
||||
PyObject* dragger;
|
||||
char* type;
|
||||
PyObject* method;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "OsO", &dragger,&type, &method))
|
||||
throw Py::Exception();
|
||||
PyObject* dragger;
|
||||
char* type;
|
||||
PyObject* method;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "OsO", &dragger, &type, &method))
|
||||
throw Py::Exception();
|
||||
|
||||
//Check if dragger is a SoDragger object and cast
|
||||
void* ptr = 0;
|
||||
try {
|
||||
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoDragger *", dragger, &ptr, 0);
|
||||
}
|
||||
catch (const Base::Exception&) {
|
||||
throw Py::Exception("The first argument must be of type SoDragger");
|
||||
}
|
||||
//Check if dragger is a SoDragger object and cast
|
||||
void* ptr = 0;
|
||||
try {
|
||||
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoDragger *", dragger, &ptr, 0);
|
||||
}
|
||||
catch (const Base::Exception&) {
|
||||
throw Py::Exception("The first argument must be of type SoDragger");
|
||||
}
|
||||
|
||||
SoDragger* drag = reinterpret_cast<SoDragger*>(ptr);
|
||||
try {
|
||||
if (strcmp(type,"addFinishCallback")==0) {
|
||||
drag->removeFinishCallback(draggerCallback,method);
|
||||
}
|
||||
else if (strcmp(type,"addStartCallback")==0) {
|
||||
drag->removeStartCallback(draggerCallback,method);
|
||||
}
|
||||
else if (strcmp(type,"addMotionCallback")==0) {
|
||||
drag->removeMotionCallback(draggerCallback,method);
|
||||
}
|
||||
else if (strcmp(type,"addValueChangedCallback")==0) {
|
||||
drag->removeValueChangedCallback(draggerCallback,method);
|
||||
}
|
||||
else {
|
||||
std::string s;
|
||||
std::ostringstream s_out;
|
||||
s_out << type << " is not a valid dragger callback type";
|
||||
throw Py::Exception(s_out.str());
|
||||
}
|
||||
SoDragger* drag = reinterpret_cast<SoDragger*>(ptr);
|
||||
try {
|
||||
if (strcmp(type, "addFinishCallback") == 0) {
|
||||
drag->removeFinishCallback(draggerCallback, method);
|
||||
}
|
||||
else if (strcmp(type, "addStartCallback") == 0) {
|
||||
drag->removeStartCallback(draggerCallback, method);
|
||||
}
|
||||
else if (strcmp(type, "addMotionCallback") == 0) {
|
||||
drag->removeMotionCallback(draggerCallback, method);
|
||||
}
|
||||
else if (strcmp(type, "addValueChangedCallback") == 0) {
|
||||
drag->removeValueChangedCallback(draggerCallback, method);
|
||||
}
|
||||
else {
|
||||
std::string s;
|
||||
std::ostringstream s_out;
|
||||
s_out << type << " is not a valid dragger callback type";
|
||||
throw Py::Exception(s_out.str());
|
||||
}
|
||||
|
||||
callbacks.remove(method);
|
||||
Py_DECREF(method);
|
||||
return Py::Callable(method, false);
|
||||
}
|
||||
catch (const Py::Exception&) {
|
||||
throw;
|
||||
}
|
||||
callbacks.remove(method);
|
||||
Py_DECREF(method);
|
||||
return Py::Callable(method, false);
|
||||
}
|
||||
catch (const Py::Exception&) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object View3DInventorPy::setActiveObject(const Py::Tuple& args)
|
||||
{
|
||||
App::DocumentObjectPy* docObject = 0;
|
||||
char* name;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "sO!", &name, &App::DocumentObjectPy::Type, &docObject))
|
||||
throw Py::Exception();
|
||||
|
||||
if (docObject){
|
||||
_view->ActiveObjects.setObject(docObject->getDocumentObjectPtr(), name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user