Skip to content

Commit

Permalink
Gui: [skip ci] add function to convert Inventor file into STL format
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 18, 2020
1 parent 49bfbf7 commit 601ac70
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Mod/Mesh/Gui/AppMeshGui.cpp
Expand Up @@ -23,6 +23,10 @@

#include "PreCompiled.h"
#ifndef _PreComp_
# include <Inventor/SoDB.h>
# include <Inventor/SoInput.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/annex/ForeignFiles/SoSTLFileKit.h>
#endif

#include <Base/Interpreter.h>
Expand Down Expand Up @@ -72,12 +76,43 @@ class Module : public Py::ExtensionModule<Module>
public:
Module() : Py::ExtensionModule<Module>("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()
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Mesh/Gui/PreCompiled.h
Expand Up @@ -82,6 +82,7 @@
// Inventor
#ifndef __InventorAll__
# include <Gui/InventorAll.h>
# include <Inventor/annex/ForeignFiles/SoSTLFileKit.h>
#endif

#elif defined(FC_OS_WIN32)
Expand Down

2 comments on commit 601ac70

@vocx-fc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compilation in Travis fails because it cannot find <Inventor/annex/ForeignFiles/SoSTLFileKit.h>.

Is this provided by a new Coin? Travis seems to install libcoin80-dev but in my system I have libcoin-dev which I think is newer.

@wwmayer
Copy link
Contributor Author

@wwmayer wwmayer commented on 601ac70 Mar 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SoSTLFileKit.h is not the problem but how it includes the header of its base class declaration. Instead of using the full path Inventor/annex/ForeignFiles it starts directly with ForeignFiles but this is not part of the includes paths.
With newer Coin3d versions this issue has been fixed. A workaround for travis is to append ${COIN3D_INCLUDE_DIRS}/Inventor/annex as done with 1fcab29

As you can with the very latest commit travis succeeds again.

Please sign in to comment.