diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index fc6bc76288e8..b0228fe3c181 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -823,16 +823,29 @@ void View3DInventor::restoreOverrideCursor() _viewer->getWidget()->setCursor(QCursor(Qt::ArrowCursor)); } -void View3DInventor::dump(const char* filename) +// defined in SoFCDB.cpp +extern SoNode* replaceSwitchesInSceneGraph(SoNode*); + +void View3DInventor::dump(const char* filename, bool onlyVisible) { SoGetPrimitiveCountAction action; action.setCanApproximate(true); action.apply(_viewer->getSceneGraph()); + SoNode* node = _viewer->getSceneGraph(); + if (onlyVisible) { + node = replaceSwitchesInSceneGraph(node); + node->ref(); + } + if ( action.getTriangleCount() > 100000 || action.getPointCount() > 30000 || action.getLineCount() > 10000 ) - _viewer->dumpToFile(_viewer->getSceneGraph(), filename, true); + _viewer->dumpToFile(node, filename, true); else - _viewer->dumpToFile(_viewer->getSceneGraph(), filename, false); + _viewer->dumpToFile(node, filename, false); + + if (onlyVisible) { + node->unref(); + } } void View3DInventor::windowStateChanged(MDIView* view) diff --git a/src/Gui/View3DInventor.h b/src/Gui/View3DInventor.h index 5e22c9619257..76534a2851af 100644 --- a/src/Gui/View3DInventor.h +++ b/src/Gui/View3DInventor.h @@ -113,7 +113,7 @@ public Q_SLOTS: void setOverrideCursor(const QCursor&); void restoreOverrideCursor(); - void dump(const char* filename); + void dump(const char* filename, bool onlyVisible=false); protected Q_SLOTS: void stopAnimating(); diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index fe967a4d5464..bc73deca014f 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -113,7 +113,7 @@ void View3DInventorPy::init_type() add_varargs_method("stopAnimating",&View3DInventorPy::stopAnimating,"stopAnimating()"); add_varargs_method("setAnimationEnabled",&View3DInventorPy::setAnimationEnabled,"setAnimationEnabled()"); add_varargs_method("isAnimationEnabled",&View3DInventorPy::isAnimationEnabled,"isAnimationEnabled()"); - add_varargs_method("dump",&View3DInventorPy::dump,"dump()"); + add_varargs_method("dump",&View3DInventorPy::dump,"dump(filename, [onlyVisible=False])"); add_varargs_method("dumpNode",&View3DInventorPy::dumpNode,"dumpNode(node)"); add_varargs_method("setStereoType",&View3DInventorPy::setStereoType,"setStereoType()"); add_varargs_method("getStereoType",&View3DInventorPy::getStereoType,"getStereoType()"); @@ -1233,11 +1233,12 @@ Py::Object View3DInventorPy::listCameraTypes(const Py::Tuple& args) Py::Object View3DInventorPy::dump(const Py::Tuple& args) { char* filename; - if (!PyArg_ParseTuple(args.ptr(), "s", &filename)) + PyObject *onlyVisible = Py_False; + if (!PyArg_ParseTuple(args.ptr(), "s|O", &filename, &onlyVisible)) throw Py::Exception(); try { - _view->dump(filename); + _view->dump(filename, PyObject_IsTrue(onlyVisible)); return Py::None(); } catch (const Base::Exception& e) {