diff --git a/src/Mod/Mesh/Gui/AppMeshGui.cpp b/src/Mod/Mesh/Gui/AppMeshGui.cpp index 4b6d1e7dcaf4..76d7d460647f 100644 --- a/src/Mod/Mesh/Gui/AppMeshGui.cpp +++ b/src/Mod/Mesh/Gui/AppMeshGui.cpp @@ -23,6 +23,10 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include +# include +# include +# include #endif #include @@ -72,12 +76,43 @@ class Module : public Py::ExtensionModule public: Module() : Py::ExtensionModule("MeshGui") { + add_varargs_method("convertToSTL",&Module::convertToSTL, + "Convert a scene into an STL." + ); initialize("This module is the MeshGui module."); // register with Python } virtual ~Module() {} private: + Py::Object convertToSTL(const Py::Tuple& args) + { + char* inname; + char* outname; + if (!PyArg_ParseTuple(args.ptr(), "etet","utf-8",&inname,"utf-8",&outname)) + throw Py::Exception(); + std::string inputName = std::string(inname); + PyMem_Free(inname); + std::string outputName = std::string(outname); + PyMem_Free(outname); + + bool ok = false; + SoInput in; + if (in.openFile(inputName.c_str())) { + SoSeparator * node = SoDB::readAll(&in); + if (node) { + node->ref(); + SoSTLFileKit* stlKit = new SoSTLFileKit(); + stlKit->ref(); + ok = stlKit->readScene(node); + stlKit->writeFile(outputName.c_str()); + stlKit->unref(); + node->unref(); + } + } + + return Py::Boolean(ok); + } }; PyObject* initModule() diff --git a/src/Mod/Mesh/Gui/PreCompiled.h b/src/Mod/Mesh/Gui/PreCompiled.h index b317cfee8124..081e61844f3e 100644 --- a/src/Mod/Mesh/Gui/PreCompiled.h +++ b/src/Mod/Mesh/Gui/PreCompiled.h @@ -82,6 +82,7 @@ // Inventor #ifndef __InventorAll__ # include +# include #endif #elif defined(FC_OS_WIN32)