Gui: make View3DInventorPy acting as sub-class of MDIViewPy

This commit is contained in:
wmayer
2021-11-21 19:44:38 +01:00
parent 292f6dcaa7
commit fad2fd9568
3 changed files with 132 additions and 121 deletions

View File

@@ -224,7 +224,7 @@ View3DInventor::~View3DInventor()
}
if (_viewerPy) {
static_cast<View3DInventorPy*>(_viewerPy)->_view = 0;
Base::PyGILStateLocker lock;
Py_DECREF(_viewerPy);
}

View File

@@ -52,7 +52,6 @@
#include "View3DViewerPy.h"
#include "ActiveObjectList.h"
#include "PythonWrapper.h"
#include "MDIViewPy.h"
#include <Base/Console.h>
@@ -82,7 +81,6 @@ void View3DInventorPy::init_type()
behaviors().supportGetattr();
behaviors().supportSetattr();
add_varargs_method("message",&View3DInventorPy::message,"message()");
add_varargs_method("fitAll",&View3DInventorPy::fitAll,"fitAll()");
add_keyword_method("boxZoom",&View3DInventorPy::boxZoom,"boxZoom()");
@@ -213,7 +211,7 @@ void View3DInventorPy::init_type()
}
View3DInventorPy::View3DInventorPy(View3DInventor *vi)
: _view(vi)
: base(vi)
{
}
@@ -224,11 +222,16 @@ View3DInventorPy::~View3DInventorPy()
Py_DECREF(*it);
}
View3DInventor* View3DInventorPy::getView3DIventorPtr()
{
return qobject_cast<View3DInventor*>(base.getMDIViewPtr());
}
Py::Object View3DInventorPy::repr()
{
std::string s;
std::ostringstream s_out;
if (!_view)
if (!getView3DIventorPtr())
throw Py::RuntimeError("Cannot print representation of deleted object");
s_out << "View3DInventor";
return Py::String(s_out.str());
@@ -247,28 +250,57 @@ PyObject *View3DInventorPy::method_varargs_ext_handler(PyObject *_self_and_name_
catch (const std::exception& e) {
throw Py::RuntimeError(e.what());
}
catch (const Py::Exception&) {
throw;
}
catch (...) {
throw Py::RuntimeError("Unknown C++ exception");
}
}
// Since with PyCXX it's not possible to make a sub-class of MDIViewPy
// a trick is to use MDIViewPy as class member and override getattr() to
// join the attributes of both classes. This way all methods of MDIViewPy
// appear for SheetViewPy, too.
Py::Object View3DInventorPy::getattribute(const char * attr)
{
if (!getView3DIventorPtr())
throw Py::RuntimeError("Cannot print representation of deleted object");
std::string name( attr );
if (name == "__dict__" || name == "__class__") {
Py::Dict dict_self(BaseType::getattr("__dict__"));
Py::Dict dict_base(base.getattr("__dict__"));
for (auto it : dict_base) {
dict_self.setItem(it.first, it.second);
}
return dict_self;
}
try {
return BaseType::getattr(attr);
}
catch (Py::AttributeError& e) {
e.clear();
return base.getattr(attr);
}
}
Py::Object View3DInventorPy::getattr(const char * attr)
{
if (!_view) {
std::string s;
if (!getView3DIventorPtr()) {
std::ostringstream s_out;
s_out << "Cannot access attribute '" << attr << "' of deleted object";
throw Py::RuntimeError(s_out.str());
}
else {
// see if an active object has the same name
App::DocumentObject *docObj = _view->getActiveObject<App::DocumentObject*>(attr);
App::DocumentObject *docObj = getView3DIventorPtr()->getActiveObject<App::DocumentObject*>(attr);
if (docObj) {
return Py::Object(docObj->getPyObject(),true);
}
else {
// else looking for a method with the name and call it
Py::Object obj = Py::PythonExtension<View3DInventorPy>::getattr(attr);
Py::Object obj = getattribute(attr);
if (PyCFunction_Check(obj.ptr())) {
PyCFunctionObject* op = reinterpret_cast<PyCFunctionObject*>(obj.ptr());
if (op->m_ml->ml_flags == METH_VARARGS) {
@@ -284,39 +316,17 @@ Py::Object View3DInventorPy::getattr(const char * attr)
int View3DInventorPy::setattr(const char * attr, const Py::Object & value)
{
if (!_view) {
if (!getView3DIventorPtr()) {
std::string s;
std::ostringstream s_out;
s_out << "Cannot access attribute '" << attr << "' of deleted object";
throw Py::RuntimeError(s_out.str());
}
else {
return Py::PythonExtension<View3DInventorPy>::setattr(attr, value);
return BaseType::setattr(attr, value);
}
}
Py::Object View3DInventorPy::message(const Py::Tuple& args)
{
const char **ppReturn = 0;
char *psMsgStr;
if (!PyArg_ParseTuple(args.ptr(), "s;Message string needed (string)",&psMsgStr)) // convert args: Python->C
throw Py::Exception();
try {
_view->onMsg(psMsgStr,ppReturn);
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}
catch (const std::exception& e) {
throw Py::RuntimeError(e.what());
}
catch (...) {
throw Py::RuntimeError("Unknown C++ exception");
}
return Py::None();
}
Py::Object View3DInventorPy::fitAll(const Py::Tuple& args)
{
double factor = 1.0;
@@ -324,7 +334,7 @@ Py::Object View3DInventorPy::fitAll(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->viewAll((float)factor);
getView3DIventorPtr()->getViewer()->viewAll((float)factor);
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -347,7 +357,7 @@ Py::Object View3DInventorPy::boxZoom(const Py::Tuple& args, const Py::Dict& kwds
throw Py::Exception();
SbBox2s box(xmin, ymin, xmax, ymax);
_view->getViewer()->boxZoom(box);
getView3DIventorPtr()->getViewer()->boxZoom(box);
return Py::None();
}
@@ -470,7 +480,7 @@ Py::Object View3DInventorPy::viewBottom(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->setCameraOrientation(Camera::rotation(Camera::Bottom));
getView3DIventorPtr()->getViewer()->setCameraOrientation(Camera::rotation(Camera::Bottom));
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -491,7 +501,7 @@ Py::Object View3DInventorPy::viewFront(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->setCameraOrientation(Camera::rotation(Camera::Front));
getView3DIventorPtr()->getViewer()->setCameraOrientation(Camera::rotation(Camera::Front));
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -512,7 +522,7 @@ Py::Object View3DInventorPy::viewLeft(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->setCameraOrientation(Camera::rotation(Camera::Left));
getView3DIventorPtr()->getViewer()->setCameraOrientation(Camera::rotation(Camera::Left));
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -533,7 +543,7 @@ Py::Object View3DInventorPy::viewRear(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->setCameraOrientation(Camera::rotation(Camera::Rear));
getView3DIventorPtr()->getViewer()->setCameraOrientation(Camera::rotation(Camera::Rear));
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -554,7 +564,7 @@ Py::Object View3DInventorPy::viewRight(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->setCameraOrientation(Camera::rotation(Camera::Right));
getView3DIventorPtr()->getViewer()->setCameraOrientation(Camera::rotation(Camera::Right));
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -575,7 +585,7 @@ Py::Object View3DInventorPy::viewTop(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->setCameraOrientation(Camera::rotation(Camera::Top));
getView3DIventorPtr()->getViewer()->setCameraOrientation(Camera::rotation(Camera::Top));
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -596,7 +606,7 @@ Py::Object View3DInventorPy::viewIsometric(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->setCameraOrientation(Camera::rotation(Camera::Isometric));
getView3DIventorPtr()->getViewer()->setCameraOrientation(Camera::rotation(Camera::Isometric));
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -617,7 +627,7 @@ Py::Object View3DInventorPy::viewDimetric(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->setCameraOrientation(Camera::rotation(Camera::Dimetric));
getView3DIventorPtr()->getViewer()->setCameraOrientation(Camera::rotation(Camera::Dimetric));
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -638,7 +648,7 @@ Py::Object View3DInventorPy::viewTrimetric(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->setCameraOrientation(Camera::rotation(Camera::Trimetric));
getView3DIventorPtr()->getViewer()->setCameraOrientation(Camera::rotation(Camera::Trimetric));
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -707,7 +717,7 @@ Py::Object View3DInventorPy::viewDefaultOrientation(const Py::Tuple& args)
rot.setValue(q0, q1, q2, q3);
}
SoCamera* cam = _view->getViewer()->getCamera();
SoCamera* cam = getView3DIventorPtr()->getViewer()->getCamera();
cam->orientation = rot;
if (scale < 0.0){
@@ -750,7 +760,7 @@ Py::Object View3DInventorPy::viewRotateLeft(const Py::Tuple& args)
throw Py::Exception();
try {
SoCamera* cam = _view->getViewer()->getSoRenderManager()->getCamera();
SoCamera* cam = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getCamera();
SbRotation rot = cam->orientation.getValue();
SbVec3f vdir(0, 0, -1);
rot.multVec(vdir, vdir);
@@ -776,7 +786,7 @@ Py::Object View3DInventorPy::viewRotateRight(const Py::Tuple& args)
throw Py::Exception();
try {
SoCamera* cam = _view->getViewer()->getSoRenderManager()->getCamera();
SoCamera* cam = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getCamera();
SbRotation rot = cam->orientation.getValue();
SbVec3f vdir(0, 0, -1);
rot.multVec(vdir, vdir);
@@ -802,7 +812,7 @@ Py::Object View3DInventorPy::zoomIn(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->navigationStyle()->zoomIn();
getView3DIventorPtr()->getViewer()->navigationStyle()->zoomIn();
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -823,7 +833,7 @@ Py::Object View3DInventorPy::zoomOut(const Py::Tuple& args)
throw Py::Exception();
try {
_view->getViewer()->navigationStyle()->zoomOut();
getView3DIventorPtr()->getViewer()->navigationStyle()->zoomOut();
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -852,13 +862,13 @@ Py::Object View3DInventorPy::setCameraOrientation(const Py::Tuple& args)
float q1 = (float)Py::Float(tuple[1]);
float q2 = (float)Py::Float(tuple[2]);
float q3 = (float)Py::Float(tuple[3]);
_view->getViewer()->setCameraOrientation(SbRotation(q0, q1, q2, q3), PyObject_IsTrue(m));
getView3DIventorPtr()->getViewer()->setCameraOrientation(SbRotation(q0, q1, q2, q3), PyObject_IsTrue(m));
}
else if (PyObject_TypeCheck(o, &Base::RotationPy::Type)) {
Base::Rotation r = (Base::Rotation)Py::Rotation(o,false);
double q0, q1, q2, q3;
r.getValue(q0, q1, q2, q3);
_view->getViewer()->setCameraOrientation(SbRotation((float)q0, (float)q1, (float)q2, (float)q3), PyObject_IsTrue(m));
getView3DIventorPtr()->getViewer()->setCameraOrientation(SbRotation((float)q0, (float)q1, (float)q2, (float)q3), PyObject_IsTrue(m));
}
else {
throw Py::ValueError("Neither tuple nor rotation object");
@@ -884,7 +894,7 @@ Py::Object View3DInventorPy::getCameraOrientation(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
SbRotation rot = _view->getViewer()->getCameraOrientation();
SbRotation rot = getView3DIventorPtr()->getViewer()->getCameraOrientation();
float q0,q1,q2,q3;
rot.getValue(q0,q1,q2,q3);
return Py::Rotation(Base::Rotation(q0,q1,q2,q3));
@@ -904,12 +914,12 @@ Py::Object View3DInventorPy::viewPosition(const Py::Tuple& args)
Base::Vector3d pos = plm->getPosition();
double q0,q1,q2,q3;
rot.getValue(q0,q1,q2,q3);
_view->getViewer()->moveCameraTo(
getView3DIventorPtr()->getViewer()->moveCameraTo(
SbRotation((float)q0, (float)q1, (float)q2, (float)q3),
SbVec3f((float)pos.x, (float)pos.y, (float)pos.z), steps, ms);
}
SoCamera* cam = _view->getViewer()->getSoRenderManager()->getCamera();
SoCamera* cam = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getCamera();
if (!cam) return Py::None();
SbRotation rot = cam->orientation.getValue();
@@ -928,7 +938,7 @@ Py::Object View3DInventorPy::startAnimating(const Py::Tuple& args)
float velocity;
if (!PyArg_ParseTuple(args.ptr(), "ffff", &x,&y,&z,&velocity))
throw Py::Exception();
_view->getViewer()->startAnimating(SbVec3f(x,y,z),velocity);
getView3DIventorPtr()->getViewer()->startAnimating(SbVec3f(x,y,z),velocity);
return Py::None();
}
@@ -936,7 +946,7 @@ Py::Object View3DInventorPy::stopAnimating(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
_view->getViewer()->stopAnimating();
getView3DIventorPtr()->getViewer()->stopAnimating();
return Py::None();
}
@@ -945,7 +955,7 @@ Py::Object View3DInventorPy::setAnimationEnabled(const Py::Tuple& args)
int ok;
if (!PyArg_ParseTuple(args.ptr(), "i", &ok))
throw Py::Exception();
_view->getViewer()->setAnimationEnabled(ok!=0);
getView3DIventorPtr()->getViewer()->setAnimationEnabled(ok!=0);
return Py::None();
}
@@ -953,7 +963,7 @@ Py::Object View3DInventorPy::isAnimationEnabled(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
SbBool ok = _view->getViewer()->isAnimationEnabled();
SbBool ok = getView3DIventorPtr()->getViewer()->isAnimationEnabled();
return Py::Boolean(ok ? true : false);
}
@@ -962,7 +972,7 @@ Py::Object View3DInventorPy::setPopupMenuEnabled(const Py::Tuple& args)
int ok;
if (!PyArg_ParseTuple(args.ptr(), "i", &ok))
throw Py::Exception();
_view->getViewer()->setPopupMenuEnabled(ok!=0);
getView3DIventorPtr()->getViewer()->setPopupMenuEnabled(ok!=0);
return Py::None();
}
@@ -970,7 +980,7 @@ Py::Object View3DInventorPy::isPopupMenuEnabled(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
SbBool ok = _view->getViewer()->isPopupMenuEnabled();
SbBool ok = getView3DIventorPtr()->getViewer()->isPopupMenuEnabled();
return Py::Boolean(ok ? true : false);
}
@@ -998,10 +1008,10 @@ Py::Object View3DInventorPy::saveImage(const Py::Tuple& args)
bg.setNamedColor(colname);
QImage img;
_view->getViewer()->savePicture(w, h, s, bg, img);
getView3DIventorPtr()->getViewer()->savePicture(w, h, s, bg, img);
SoFCOffscreenRenderer& renderer = SoFCOffscreenRenderer::instance();
SoCamera* cam = _view->getViewer()->getSoRenderManager()->getCamera();
SoCamera* cam = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getCamera();
renderer.writeToImageFile(encodedName.c_str(), cComment, cam->getViewVolume().getMatrix(), img);
return Py::None();
@@ -1042,11 +1052,11 @@ Py::Object View3DInventorPy::saveVectorGraphic(const Py::Tuple& args)
QColor bg;
QString colname = QString::fromLatin1(name);
if (colname.compare(QLatin1String("Current"), Qt::CaseInsensitive) == 0)
bg = _view->getViewer()->backgroundColor();
bg = getView3DIventorPtr()->getViewer()->backgroundColor();
else
bg.setNamedColor(colname);
_view->getViewer()->saveGraphic(ps,bg,vo.get());
getView3DIventorPtr()->getViewer()->saveGraphic(ps,bg,vo.get());
out->closeFile();
return Py::None();
}
@@ -1057,7 +1067,7 @@ Py::Object View3DInventorPy::getCameraNode(const Py::Tuple& args)
throw Py::Exception();
try {
SoNode* camera = _view->getViewer()->getSoRenderManager()->getCamera();
SoNode* camera = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getCamera();
PyObject* proxy = 0;
std::string type;
type = "So"; // seems that So prefix is missing in camera node
@@ -1083,7 +1093,7 @@ Py::Object View3DInventorPy::getCamera(const Py::Tuple& args)
try {
SoWriteAction wa(&out);
SoCamera * cam = _view->getViewer()->getSoRenderManager()->getCamera();
SoCamera * cam = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getCamera();
if (cam) wa.apply(cam);
else buffer[0] = '\0';
return Py::String(buffer);
@@ -1104,7 +1114,7 @@ Py::Object View3DInventorPy::getViewDirection(const Py::Tuple& args)
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
try {
SbVec3f dvec = _view->getViewer()->getViewDirection();
SbVec3f dvec = getView3DIventorPtr()->getViewer()->getViewDirection();
return Py::Vector(Base::Vector3f(dvec[0], dvec[1], dvec[2]));
}
catch (const Base::Exception& e) {
@@ -1134,7 +1144,7 @@ Py::Object View3DInventorPy::setViewDirection(const Py::Tuple& args)
dir.setValue((float)x, (float)y, (float)z);
if (dir.length() < 0.001f)
throw Py::ValueError("Null vector cannot be used to set direction");
_view->getViewer()->setViewDirection(dir);
getView3DIventorPtr()->getViewer()->setViewDirection(dir);
return Py::None();
}
}
@@ -1163,7 +1173,7 @@ Py::Object View3DInventorPy::setCamera(const Py::Tuple& args)
throw Py::Exception();
try {
_view->setCamera(buffer);
getView3DIventorPtr()->setCamera(buffer);
return Py::None();
}
catch (const Base::Exception& e) {
@@ -1185,7 +1195,7 @@ Py::Object View3DInventorPy::getCameraType(const Py::Tuple& args)
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
SoCamera* cam = _view->getViewer()->getSoRenderManager()->getCamera();
SoCamera* cam = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getCamera();
if (!cam) {
throw Py::RuntimeError("No camera set!");
}
@@ -1226,9 +1236,9 @@ Py::Object View3DInventorPy::setCameraType(const Py::Tuple& args)
if (cameratype < 0 || cameratype > 1)
throw Py::IndexError("Out of range");
if (cameratype==0)
_view->getViewer()->setCameraType(SoOrthographicCamera::getClassTypeId());
getView3DIventorPtr()->getViewer()->setCameraType(SoOrthographicCamera::getClassTypeId());
else
_view->getViewer()->setCameraType(SoPerspectiveCamera::getClassTypeId());
getView3DIventorPtr()->getViewer()->setCameraType(SoPerspectiveCamera::getClassTypeId());
return Py::None();
}
@@ -1263,7 +1273,7 @@ Py::Object View3DInventorPy::dump(const Py::Tuple& args)
throw Py::Exception();
try {
_view->dump(filename, PyObject_IsTrue(onlyVisible));
getView3DIventorPtr()->dump(filename, PyObject_IsTrue(onlyVisible));
return Py::None();
}
catch (const Base::Exception& e) {
@@ -1324,7 +1334,7 @@ Py::Object View3DInventorPy::setStereoType(const Py::Tuple& args)
if (stereomode < 0 || stereomode > 4)
throw Py::IndexError("Out of range");
Quarter::SoQTQuarterAdaptor::StereoMode mode = Quarter::SoQTQuarterAdaptor::StereoMode(stereomode);
_view->getViewer()->setStereoMode(mode);
getView3DIventorPtr()->getViewer()->setStereoMode(mode);
return Py::None();
}
catch (const Base::Exception& e) {
@@ -1344,7 +1354,7 @@ Py::Object View3DInventorPy::getStereoType(const Py::Tuple& args)
throw Py::Exception();
try {
int mode = (int)(_view->getViewer()->stereoMode());
int mode = (int)(getView3DIventorPtr()->getViewer()->stereoMode());
return Py::String(StereoTypeEnums[mode]);
}
catch (const Base::Exception& e) {
@@ -1387,10 +1397,10 @@ Py::Object View3DInventorPy::getCursorPos(const Py::Tuple& args)
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
try {
QPoint pos = _view->mapFromGlobal(QCursor::pos());
QPoint pos = getView3DIventorPtr()->mapFromGlobal(QCursor::pos());
Py::Tuple tuple(2);
tuple.setItem(0, Py::Int(pos.x()));
tuple.setItem(1, Py::Int(_view->height()-pos.y()-1));
tuple.setItem(1, Py::Int(getView3DIventorPtr()->height()-pos.y()-1));
return tuple;
}
catch (const Py::Exception&) {
@@ -1401,7 +1411,7 @@ Py::Object View3DInventorPy::getCursorPos(const Py::Tuple& args)
Py::Object View3DInventorPy::getObjectInfo(const Py::Tuple& args)
{
PyObject* object;
float r = _view->getViewer()->getPickRadius();
float r = getView3DIventorPtr()->getViewer()->getPickRadius();
if (!PyArg_ParseTuple(args.ptr(), "O|f", &object, &r))
throw Py::Exception();
@@ -1419,10 +1429,10 @@ Py::Object View3DInventorPy::getObjectInfo(const Py::Tuple& args)
// graph traversal we must not use a second SoHandleEventAction as
// we will get Coin warnings because of multiple scene graph traversals
// which is regarded as error-prone.
SoRayPickAction action(_view->getViewer()->getSoRenderManager()->getViewportRegion());
SoRayPickAction action(getView3DIventorPtr()->getViewer()->getSoRenderManager()->getViewportRegion());
action.setPoint(SbVec2s((long)x,(long)y));
action.setRadius(r);
action.apply(_view->getViewer()->getSoRenderManager()->getSceneGraph());
action.apply(getView3DIventorPtr()->getViewer()->getSoRenderManager()->getSceneGraph());
SoPickedPoint *Point = action.getPickedPoint();
Py::Object ret = Py::None();
@@ -1433,9 +1443,9 @@ Py::Object View3DInventorPy::getObjectInfo(const Py::Tuple& args)
dict.setItem("y", Py::Float(pt[1]));
dict.setItem("z", Py::Float(pt[2]));
Gui::Document* doc = _view->getViewer()->getDocument();
Gui::Document* doc = getView3DIventorPtr()->getViewer()->getDocument();
ViewProvider *vp = doc ? doc->getViewProviderByPathFromHead(Point->getPath())
: _view->getViewer()->getViewProviderByPath(Point->getPath());
: getView3DIventorPtr()->getViewer()->getViewProviderByPath(Point->getPath());
if (vp && vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) {
if (!vp->isSelectable())
return ret;
@@ -1509,7 +1519,7 @@ Py::Object View3DInventorPy::getObjectInfo(const Py::Tuple& args)
Py::Object View3DInventorPy::getObjectsInfo(const Py::Tuple& args)
{
PyObject* object;
float r = _view->getViewer()->getPickRadius();
float r = getView3DIventorPtr()->getViewer()->getPickRadius();
if (!PyArg_ParseTuple(args.ptr(), "O|f", &object, &r))
throw Py::Exception();
@@ -1527,14 +1537,14 @@ Py::Object View3DInventorPy::getObjectsInfo(const Py::Tuple& args)
// graph traversal we must not use a second SoHandleEventAction as
// we will get Coin warnings because of multiple scene graph traversals
// which is regarded as error-prone.
SoRayPickAction action(_view->getViewer()->getSoRenderManager()->getViewportRegion());
SoRayPickAction action(getView3DIventorPtr()->getViewer()->getSoRenderManager()->getViewportRegion());
action.setPickAll(true);
action.setRadius(r);
action.setPoint(SbVec2s((long)x,(long)y));
action.apply(_view->getViewer()->getSoRenderManager()->getSceneGraph());
action.apply(getView3DIventorPtr()->getViewer()->getSoRenderManager()->getSceneGraph());
const SoPickedPointList& pp = action.getPickedPointList();
Gui::Document* doc = _view->getViewer()->getDocument();
Gui::Document* doc = getView3DIventorPtr()->getViewer()->getDocument();
Py::Object ret = Py::None();
if (pp.getLength() > 0) {
Py::List list;
@@ -1547,7 +1557,7 @@ Py::Object View3DInventorPy::getObjectsInfo(const Py::Tuple& args)
dict.setItem("z", Py::Float(pt[2]));
ViewProvider *vp = doc ? doc->getViewProviderByPathFromHead(point->getPath())
: _view->getViewer()->getViewProviderByPath(point->getPath());
: getView3DIventorPtr()->getViewer()->getViewProviderByPath(point->getPath());
if(vp && vp->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) {
if(!vp->isSelectable())
continue;
@@ -1625,7 +1635,7 @@ Py::Object View3DInventorPy::getSize(const Py::Tuple& args)
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
try {
SbVec2s size = _view->getViewer()->getSoRenderManager()->getSize();
SbVec2s size = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getSize();
Py::Tuple tuple(2);
tuple.setItem(0, Py::Int(size[0]));
tuple.setItem(1, Py::Int(size[1]));
@@ -1646,7 +1656,7 @@ Py::Object View3DInventorPy::getPoint(const Py::Tuple& args)
y = (int)Py::Int(t[1]);
}
try {
SbVec3f pt = _view->getViewer()->getPointOnScreen(SbVec2s(x,y));
SbVec3f pt = getView3DIventorPtr()->getViewer()->getPointOnScreen(SbVec2s(x,y));
return Py::Vector(Base::Vector3f(pt[0], pt[1], pt[2]));
}
catch (const Base::Exception& e) {
@@ -1675,11 +1685,11 @@ Py::Object View3DInventorPy::getPointOnScreen(const Py::Tuple& args)
}
try {
const SbViewportRegion& vp = _view->getViewer()->getSoRenderManager()->getViewportRegion();
const SbViewportRegion& vp = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getViewportRegion();
float fRatio = vp.getViewportAspectRatio();
const SbVec2s& sp = vp.getViewportSizePixels();
//float dX, dY; vp.getViewportSize().getValue(dX, dY);
SbViewVolume vv = _view->getViewer()->getSoRenderManager()->getCamera()->getViewVolume(fRatio);
SbViewVolume vv = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getCamera()->getViewVolume(fRatio);
SbVec3f pt(vx,vy,vz);
vv.projectToScreen(pt, pt);
@@ -1720,7 +1730,7 @@ Py::Object View3DInventorPy::listNavigationTypes(const Py::Tuple&)
Py::Object View3DInventorPy::getNavigationType(const Py::Tuple&)
{
std::string name = _view->getViewer()->navigationStyle()->getTypeId().getName();
std::string name = getView3DIventorPtr()->getViewer()->navigationStyle()->getTypeId().getName();
return Py::String(name);
}
@@ -1730,7 +1740,7 @@ Py::Object View3DInventorPy::setNavigationType(const Py::Tuple& args)
if (!PyArg_ParseTuple(args.ptr(), "s", &style))
throw Py::Exception();
Base::Type type = Base::Type::fromName(style);
_view->getViewer()->setNavigationType(type);
getView3DIventorPtr()->getViewer()->setNavigationType(type);
return Py::None();
}
@@ -2111,7 +2121,7 @@ Py::Object View3DInventorPy::addEventCallback(const Py::Tuple& args)
throw Py::TypeError(s_out.str());
}
_view->getViewer()->addEventCallback(eventId, View3DInventorPy::eventCallback, method);
getView3DIventorPtr()->getViewer()->addEventCallback(eventId, View3DInventorPy::eventCallback, method);
callbacks.push_back(method);
Py_INCREF(method);
return Py::Callable(method, false);
@@ -2139,7 +2149,7 @@ Py::Object View3DInventorPy::removeEventCallback(const Py::Tuple& args)
throw Py::TypeError(s_out.str());
}
_view->getViewer()->removeEventCallback(eventId, View3DInventorPy::eventCallback, method);
getView3DIventorPtr()->getViewer()->removeEventCallback(eventId, View3DInventorPy::eventCallback, method);
callbacks.remove(method);
Py_DECREF(method);
return Py::None();
@@ -2164,7 +2174,7 @@ Py::Object View3DInventorPy::setAnnotation(const Py::Tuple& args)
throw Py::RuntimeError(e.what());
}
_view->getGuiDocument()->setAnnotationViewProvider(psAnnoName, view);
getView3DIventorPtr()->getGuiDocument()->setAnnotationViewProvider(psAnnoName, view);
return Py::None();
}
@@ -2174,9 +2184,9 @@ Py::Object View3DInventorPy::removeAnnotation(const Py::Tuple& args)
if (!PyArg_ParseTuple(args.ptr(), "s", &psAnnoName))
throw Py::Exception();
ViewProvider* view = 0;
view = _view->getGuiDocument()->getAnnotationViewProvider(psAnnoName);
view = getView3DIventorPtr()->getGuiDocument()->getAnnotationViewProvider(psAnnoName);
if (view) {
_view->getGuiDocument()->removeAnnotationViewProvider(psAnnoName);
getView3DIventorPtr()->getGuiDocument()->removeAnnotationViewProvider(psAnnoName);
return Py::None();
}
else {
@@ -2193,7 +2203,7 @@ Py::Object View3DInventorPy::getSceneGraph(const Py::Tuple& args)
throw Py::Exception();
try {
SoNode* scene = _view->getViewer()->getSceneGraph();
SoNode* scene = getView3DIventorPtr()->getViewer()->getSceneGraph();
PyObject* proxy = 0;
proxy = Base::Interpreter().createSWIGPointerObj("pivy.coin", "SoSeparator *", (void*)scene, 1);
scene->ref();
@@ -2209,7 +2219,7 @@ Py::Object View3DInventorPy::getViewer(const Py::Tuple& args)
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
View3DInventorViewer* viewer = _view->getViewer();
View3DInventorViewer* viewer = getView3DIventorPtr()->getViewer();
return Py::Object(viewer->getPyObject(), true);
}
@@ -2313,7 +2323,7 @@ Py::Object View3DInventorPy::addEventCallbackPivy(const Py::Tuple& args)
SoEventCallbackCB* callback = (ex == 1 ?
View3DInventorPy::eventCallbackPivyEx :
View3DInventorPy::eventCallbackPivy);
_view->getViewer()->addEventCallback(*eventId, callback, method);
getView3DIventorPtr()->getViewer()->addEventCallback(*eventId, callback, method);
callbacks.push_back(method);
Py_INCREF(method);
return Py::Callable(method, false);
@@ -2355,7 +2365,7 @@ Py::Object View3DInventorPy::removeEventCallbackPivy(const Py::Tuple& args)
SoEventCallbackCB* callback = (ex == 1 ?
View3DInventorPy::eventCallbackPivyEx :
View3DInventorPy::eventCallbackPivy);
_view->getViewer()->removeEventCallback(*eventId, callback, method);
getView3DIventorPtr()->getViewer()->removeEventCallback(*eventId, callback, method);
callbacks.remove(method);
Py_DECREF(method);
return Py::Callable(method, false);
@@ -2370,7 +2380,7 @@ Py::Object View3DInventorPy::setAxisCross(const Py::Tuple& args)
int ok;
if (!PyArg_ParseTuple(args.ptr(), "i", &ok))
throw Py::Exception();
_view->getViewer()->setAxisCross(ok!=0);
getView3DIventorPtr()->getViewer()->setAxisCross(ok!=0);
return Py::None();
}
@@ -2378,7 +2388,7 @@ Py::Object View3DInventorPy::hasAxisCross(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
SbBool ok = _view->getViewer()->hasAxisCross();
SbBool ok = getView3DIventorPtr()->getViewer()->hasAxisCross();
return Py::Boolean(ok ? true : false);
}
@@ -2522,13 +2532,13 @@ Py::Object View3DInventorPy::setActiveObject(const Py::Tuple& args)
throw Py::Exception();
if (docObject == Py_None) {
_view->setActiveObject(0, name);
getView3DIventorPtr()->setActiveObject(0, name);
}
else {
if (!PyObject_TypeCheck(docObject, &App::DocumentObjectPy::Type))
throw Py::TypeError("Expect the second argument to be a document object or None");
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(docObject)->getDocumentObjectPtr();
_view->setActiveObject(obj, name, subname);
getView3DIventorPtr()->setActiveObject(obj, name, subname);
}
return Py::None();
@@ -2543,7 +2553,7 @@ Py::Object View3DInventorPy::getActiveObject(const Py::Tuple& args)
App::DocumentObject *parent = 0;
std::string subname;
App::DocumentObject* obj = _view->getActiveObject<App::DocumentObject*>(name,&parent,&subname);
App::DocumentObject* obj = getView3DIventorPtr()->getActiveObject<App::DocumentObject*>(name,&parent,&subname);
if (!obj)
return Py::None();
@@ -2562,7 +2572,7 @@ Py::Object View3DInventorPy::getViewProvidersOfType(const Py::Tuple& args)
if (!PyArg_ParseTuple(args.ptr(), "s", &name))
throw Py::Exception();
std::vector<ViewProvider*> vps = _view->getViewer()->getViewProvidersOfType(Base::Type::fromName(name));
std::vector<ViewProvider*> vps = getView3DIventorPtr()->getViewer()->getViewProvidersOfType(Base::Type::fromName(name));
Py::List list;
for (std::vector<ViewProvider*>::iterator it = vps.begin(); it != vps.end(); ++it) {
list.append(Py::asObject((*it)->getPyObject()));
@@ -2575,7 +2585,7 @@ Py::Object View3DInventorPy::redraw(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
_view->getViewer()->redraw();
getView3DIventorPtr()->getViewer()->redraw();
return Py::None();
}
@@ -2586,7 +2596,7 @@ Py::Object View3DInventorPy::setName(const Py::Tuple& args)
throw Py::Exception();
try {
_view->setWindowTitle(QString::fromUtf8(buffer));
getView3DIventorPtr()->setWindowTitle(QString::fromUtf8(buffer));
return Py::None();
}
catch (const Base::Exception& e) {
@@ -2614,7 +2624,7 @@ Py::Object View3DInventorPy::toggleClippingPlane(const Py::Tuple& args, const Py
Base::Placement pla;
if(pyPla!=Py_None)
pla = *static_cast<Base::PlacementPy*>(pyPla)->getPlacementPtr();
_view->getViewer()->toggleClippingPlane(toggle,PyObject_IsTrue(beforeEditing),
getView3DIventorPtr()->getViewer()->toggleClippingPlane(toggle,PyObject_IsTrue(beforeEditing),
PyObject_IsTrue(noManip),pla);
return Py::None();
}
@@ -2623,7 +2633,7 @@ Py::Object View3DInventorPy::hasClippingPlane(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
return Py::Boolean(_view->getViewer()->hasClippingPlane());
return Py::Boolean(getView3DIventorPtr()->getViewer()->hasClippingPlane());
}
Py::Object View3DInventorPy::graphicsView(const Py::Tuple& args)
@@ -2633,10 +2643,10 @@ Py::Object View3DInventorPy::graphicsView(const Py::Tuple& args)
PythonWrapper wrap;
wrap.loadWidgetsModule();
return wrap.fromQWidget(_view->getViewer(), "QGraphicsView");
return wrap.fromQWidget(getView3DIventorPtr()->getViewer(), "QGraphicsView");
}
Py::Object View3DInventorPy::cast_to_base(const Py::Tuple&)
{
return Gui::MDIViewPy::create(_view);
return Gui::MDIViewPy::create(getView3DIventorPtr());
}

View File

@@ -26,6 +26,8 @@
#include <Base/PyObjectBase.h>
#include <CXX/Extensions.hxx>
#include <Gui/MDIView.h>
#include <Gui/MDIViewPy.h>
class SoEventCallback;
class SoDragger;
@@ -56,16 +58,18 @@ public:
class View3DInventorPy : public Py::PythonExtension<View3DInventorPy>
{
public:
static void init_type(void); // announce properties and methods
using BaseType = Py::PythonExtension<View3DInventorPy>;
static void init_type(); // announce properties and methods
View3DInventorPy(View3DInventor *vi);
~View3DInventorPy();
View3DInventor* getView3DIventorPtr();
Py::Object repr();
Py::Object getattr(const char *);
int setattr(const char *, const Py::Object &);
Py::Object cast_to_base(const Py::Tuple&);
Py::Object message(const Py::Tuple&);
Py::Object fitAll(const Py::Tuple&);
Py::Object boxZoom(const Py::Tuple&, const Py::Dict&);
Py::Object viewBottom(const Py::Tuple&);
@@ -135,9 +139,6 @@ public:
Py::Object toggleClippingPlane(const Py::Tuple& args, const Py::Dict &);
Py::Object hasClippingPlane(const Py::Tuple& args);
Py::Object graphicsView(const Py::Tuple& args);
Py::Object cast_to_base(const Py::Tuple&);
View3DInventor* getView3DIventorPtr() {return _view;}
private:
static void eventCallback(void * ud, SoEventCallback * n);
@@ -149,11 +150,11 @@ private:
typedef PyObject* (*method_varargs_handler)(PyObject *_self, PyObject *_args);
static method_varargs_handler pycxx_handler;
static PyObject *method_varargs_ext_handler(PyObject *_self, PyObject *_args);
Py::Object getattribute(const char *);
private:
Gui::MDIViewPy base;
std::list<PyObject*> callbacks;
View3DInventor* _view;
friend class View3DInventor;
};
} // namespace Gui