From da0f8102829f343d066ad3940bb603e106ca95a2 Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Sun, 19 Feb 2017 13:22:55 +1300 Subject: [PATCH] Avoid empty meshes. Improve object type detection. --- src/Mod/Mesh/App/AppMeshPy.cpp | 8 ++++++-- src/Mod/Mesh/App/Exporter.cpp | 18 ++++++++---------- src/Mod/Mesh/App/Exporter.h | 3 +-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Mod/Mesh/App/AppMeshPy.cpp b/src/Mod/Mesh/App/AppMeshPy.cpp index 811446389..76d044ab5 100644 --- a/src/Mod/Mesh/App/AppMeshPy.cpp +++ b/src/Mod/Mesh/App/AppMeshPy.cpp @@ -315,7 +315,12 @@ private: std::string outputFileName(fileNamePy); PyMem_Free(fileNamePy); - MeshObject global_mesh; + // Construct list of objects to export before making the Exporter, so + // we don't get empty exports if the list can't be constructed. + Py::Sequence list(objects); + if (list.length() == 0) { + return Py::None(); + } auto exportFormat( MeshOutput::GetFormat(outputFileName.c_str()) ); @@ -338,7 +343,6 @@ private: throw Py::Exception(Base::BaseExceptionFreeCADError, exStr.c_str()); } - Py::Sequence list(objects); for (auto it : list) { PyObject *item = it.ptr(); if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { diff --git a/src/Mod/Mesh/App/Exporter.cpp b/src/Mod/Mesh/App/Exporter.cpp index 532aa5b49..bea12f40e 100644 --- a/src/Mod/Mesh/App/Exporter.cpp +++ b/src/Mod/Mesh/App/Exporter.cpp @@ -47,9 +47,8 @@ using namespace MeshCore; Exporter::Exporter() : meshFeatId( Base::Type::fromName("Mesh::Feature") ), - partFeatId( Base::Type::fromName("Part::Feature") ), - appPartId( Base::Type::fromName("App::Part") ), - appDOGId( Base::Type::fromName("App::DocumentObjectGroup") ) + appPartId( Base::Type::fromName("Part::Feature") ), + groupExtensionId( App::GroupExtension::getExtensionClassTypeId() ) { } //static @@ -68,13 +67,13 @@ bool Exporter::addAppGroup(App::DocumentObject *obj, float tol) { auto ret(true); - for (auto it : static_cast(obj)->getOutList()) { + auto groupEx( obj->getExtensionByType() ); + for (auto it : groupEx->Group.getValues()) { if (it->getTypeId().isDerivedFrom(meshFeatId)) { ret &= addMeshFeat(it); - } else if (it->getTypeId().isDerivedFrom(partFeatId)) { + } else if (it->getTypeId().isDerivedFrom(appPartId)) { ret &= addPartFeat(it, tol); - } else if ( it->getTypeId().isDerivedFrom(appPartId) || - it->getTypeId().isDerivedFrom(appDOGId) ) { + } else if (it->hasExtension(groupExtensionId)) { // Recurse ret &= addAppGroup(it, tol); } @@ -87,10 +86,9 @@ bool Exporter::addObject(App::DocumentObject *obj, float tol) { if (obj->getTypeId().isDerivedFrom(meshFeatId)) { return addMeshFeat( obj ); - } else if (obj->getTypeId().isDerivedFrom(partFeatId)) { + } else if (obj->getTypeId().isDerivedFrom(appPartId)) { return addPartFeat( obj, tol ); - } else if ( obj->getTypeId().isDerivedFrom(appPartId) || - obj->getTypeId().isDerivedFrom(appDOGId) ) { + } else if (obj->hasExtension(groupExtensionId)) { return addAppGroup( obj, tol ); } else { Base::Console().Message( diff --git a/src/Mod/Mesh/App/Exporter.h b/src/Mod/Mesh/App/Exporter.h index d2f195bde..72dba3387 100644 --- a/src/Mod/Mesh/App/Exporter.h +++ b/src/Mod/Mesh/App/Exporter.h @@ -71,9 +71,8 @@ class Exporter static std::string xmlEscape(const std::string &input); const Base::Type meshFeatId; - const Base::Type partFeatId; const Base::Type appPartId; - const Base::Type appDOGId; + const Base::Type groupExtensionId; }; /// Creates a single mesh, in a file, from one or more objects