diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index dbb6c88a3d..1ba99e4382 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -230,6 +230,47 @@ FreeCADGui_subgraphFromObject(PyObject * /*self*/, PyObject *args) return Py_None; } +static PyObject * +FreeCADGui_replaceSwitchNodes(PyObject * /*self*/, PyObject *args) +{ + PyObject* proxy; + if (!PyArg_ParseTuple(args, "O", &proxy)) + return nullptr; + + void* ptr = 0; + try { + Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoNode *", proxy, &ptr, 0); + SoNode* node = reinterpret_cast(ptr); + SoNode* replace = SoFCDB::replaceSwitches(node); + if (replace) { + replace->ref(); + + std::string prefix = "So"; + std::string type = replace->getTypeId().getName().getString(); + // doesn't start with the prefix 'So' + if (type.rfind("So", 0) != 0) { + type = prefix + type; + } + else if (type == "SoFCSelectionRoot") { + type = "SoSeparator"; + } + + type += " *"; + PyObject* proxy = 0; + proxy = Base::Interpreter().createSWIGPointerObj("pivy.coin", type.c_str(), (void*)replace, 1); + return Py::new_reference_to(Py::Object(proxy, true)); + } + else { + Py_INCREF(Py_None); + return Py_None; + } + } + catch (const Base::Exception& e) { + PyErr_SetString(PyExc_RuntimeError, e.what()); + return nullptr; + } +} + static PyObject * FreeCADGui_getSoDBVersion(PyObject * /*self*/, PyObject *args) { @@ -293,6 +334,9 @@ struct PyMethodDef FreeCADGui_methods[] = { {"subgraphFromObject",FreeCADGui_subgraphFromObject,METH_VARARGS, "subgraphFromObject(object) -> Node\n\n" "Return the Inventor subgraph to an object"}, + {"replaceSwitchNodes",FreeCADGui_replaceSwitchNodes,METH_VARARGS, + "replaceSwitchNodes(Node) -> Node\n\n" + "Replace Switch nodes with Separators"}, {"getSoDBVersion",FreeCADGui_getSoDBVersion,METH_VARARGS, "getSoDBVersion() -> String\n\n" "Return a text string containing the name\n" diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index 3c9c7fd7be..e5477e9883 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -295,6 +295,11 @@ SoNode* replaceSwitchesInSceneGraph(SoNode* node) return node; } +SoNode* Gui::SoFCDB::replaceSwitches(SoNode* node) +{ + return replaceSwitchesInSceneGraph(node); +} + bool Gui::SoFCDB::writeToVRML(SoNode* node, const char* filename, bool binary) { SoNode* noSwitches = replaceSwitchesInSceneGraph(node); diff --git a/src/Gui/SoFCDB.h b/src/Gui/SoFCDB.h index 129f4e045d..932eab0572 100644 --- a/src/Gui/SoFCDB.h +++ b/src/Gui/SoFCDB.h @@ -40,6 +40,7 @@ public: static SbBool isInitialized(void); static void init(); static void finish(); + static SoNode* replaceSwitches(SoNode* node); /// helper to apply a SoWriteAction to a node and write it to a string static const std::string& writeNodesToString(SoNode * root); static bool writeToVRML(SoNode* node, const char* filename, bool binary);