fixes 0003680: Export (Ctrl+E) doesn't check to make sure that object being exported is a model at all

This commit is contained in:
wmayer
2018-11-10 19:02:50 +01:00
parent d9fb3a2ac5
commit 05550fcdf0
3 changed files with 58 additions and 7 deletions

View File

@@ -322,6 +322,33 @@ private:
return Py::None();
}
// collect all object types that can be exported as mesh
std::vector<App::DocumentObject*> objectList;
std::string label;
for (auto it : list) {
PyObject *item = it.ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
auto obj( static_cast<App::DocumentObjectPy *>(item)->getDocumentObjectPtr() );
label = obj->Label.getValue();
if (Exporter::isSupported(obj))
objectList.push_back(obj);
}
}
if (objectList.empty()) {
std::string errorMessage;
if (list.length() == 1) {
std::stringstream str;
str << label << " cannot be exported to a mesh file";
errorMessage = str.str();
}
else {
errorMessage = "None of the objects can be exported to a mesh file";
}
throw Py::TypeError(errorMessage);
}
auto exportFormat( MeshOutput::GetFormat(outputFileName.c_str()) );
std::unique_ptr<Exporter> exporter;
@@ -343,13 +370,8 @@ private:
throw Py::Exception(Base::BaseExceptionFreeCADError, exStr.c_str());
}
for (auto it : list) {
PyObject *item = it.ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
auto obj( static_cast<App::DocumentObjectPy *>(item)->getDocumentObjectPtr() );
exporter->addObject(obj, fTolerance);
}
for (auto it : objectList) {
exporter->addObject(it, fTolerance);
}
exporter.reset(); // deletes Exporter, mesh file is written by destructor