From ea6c95a87065d97c79a1e68b5a0c806fca6f1330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Fri, 25 Apr 2025 18:47:06 +0200 Subject: [PATCH] FEM: Fix post object load of unsupported VTK data type --- src/Mod/Fem/App/PropertyPostDataObject.cpp | 49 ++++++++++++---------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/Mod/Fem/App/PropertyPostDataObject.cpp b/src/Mod/Fem/App/PropertyPostDataObject.cpp index e075a9cbeb..37c28243a2 100644 --- a/src/Mod/Fem/App/PropertyPostDataObject.cpp +++ b/src/Mod/Fem/App/PropertyPostDataObject.cpp @@ -211,7 +211,7 @@ void PropertyPostDataObject::createDataObjectByExternalType(vtkSmartPointer::New(); break; default: - break; + throw Base::TypeError("Unsupported VTK data type"); }; } @@ -432,7 +432,7 @@ void PropertyPostDataObject::RestoreDocFile(Base::Reader& reader) // TODO: read in of composite data structures need to be coded, // including replace of "GetOutputAsDataSet()" - vtkSmartPointer xmlReader; + vtkSmartPointer xmlReader = nullptr; if (extension == "vtp") { xmlReader = vtkSmartPointer::New(); } @@ -489,31 +489,38 @@ void PropertyPostDataObject::RestoreDocFile(Base::Reader& reader) xmlReader = vtkSmartPointer::New(); } - xmlReader->SetFileName(fi.filePath().c_str()); - xmlReader->Update(); + if (xmlReader) { + xmlReader->SetFileName(fi.filePath().c_str()); + xmlReader->Update(); - if (!xmlReader->GetOutputDataObject(0)) { - // Note: Do NOT throw an exception here because if the tmp. created file could - // not be read it's NOT an indication for an invalid input stream 'reader'. - // We only print an error message but continue reading the next files from the - // stream... - App::PropertyContainer* father = this->getContainer(); - if (father && father->isDerivedFrom()) { - App::DocumentObject* obj = static_cast(father); - Base::Console().Error("Dataset file '%s' with data of '%s' seems to be empty\n", - fi.filePath().c_str(), - obj->Label.getValue()); + if (!xmlReader->GetOutputDataObject(0)) { + // Note: Do NOT throw an exception here because if the tmp. created file could + // not be read it's NOT an indication for an invalid input stream 'reader'. + // We only print an error message but continue reading the next files from the + // stream... + App::PropertyContainer* father = this->getContainer(); + if (father && father->isDerivedFrom()) { + App::DocumentObject* obj = static_cast(father); + Base::Console().Error("Dataset file '%s' with data of '%s' seems to be empty\n", + fi.filePath().c_str(), + obj->Label.getValue()); + } + else { + Base::Console().Warning("Loaded Dataset file '%s' seems to be empty\n", + fi.filePath().c_str()); + } } else { - Base::Console().Warning("Loaded Dataset file '%s' seems to be empty\n", - fi.filePath().c_str()); + aboutToSetValue(); + createDataObjectByExternalType(xmlReader->GetOutputDataObject(0)); + m_dataObject->DeepCopy(xmlReader->GetOutputDataObject(0)); + hasSetValue(); } } else { - aboutToSetValue(); - createDataObjectByExternalType(xmlReader->GetOutputDataObject(0)); - m_dataObject->DeepCopy(xmlReader->GetOutputDataObject(0)); - hasSetValue(); + Base::Console().Error("Dataset file '%s' is of unsupportet type: %s. Data not loaded.\n", + fi.filePath().c_str(), + extension); } }