Avoid empty meshes. Improve object type detection.

This commit is contained in:
Ian Rees 2017-02-19 13:22:55 +13:00 committed by wmayer
parent 2231baa060
commit da0f810282
3 changed files with 15 additions and 14 deletions

View File

@ -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))) {

View File

@ -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<App::Part *>(obj)->getOutList()) {
auto groupEx( obj->getExtensionByType<App::GroupExtension>() );
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(

View File

@ -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