| 364 | } |
| 365 | |
| 366 | void PropertyPostDataObject::SaveDocFile(Base::Writer& writer) const |
| 367 | { |
| 368 | // If the shape is empty we simply store nothing. The file size will be 0 which |
| 369 | // can be checked when reading in the data. |
| 370 | if (!m_dataObject) { |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | // create a temporary file and copy the content to the zip stream |
| 375 | // once the tmp. filename is known use always the same because otherwise |
| 376 | // we may run into some problems on the Linux platform |
| 377 | static Base::FileInfo fi = Base::FileInfo(App::Application::getTempFileName()); |
| 378 | |
| 379 | Base::FileInfo datafolder; |
| 380 | vtkSmartPointer<vtkXMLWriter> xmlWriter; |
| 381 | if (m_dataObject->IsA("vtkMultiBlockDataSet")) { |
| 382 | |
| 383 | // create a tmp directory to write in |
| 384 | datafolder = Base::FileInfo(App::Application::getTempPath() + "vtk_datadir"); |
| 385 | datafolder.createDirectories(); |
| 386 | auto datafile = Base::FileInfo(datafolder.filePath() + "/datafile.vtm"); |
| 387 | |
| 388 | // create the data: vtm file and subfolder with the subsequent data files |
| 389 | xmlWriter = vtkSmartPointer<vtkXMLMultiBlockDataWriter>::New(); |
| 390 | xmlWriter->SetInputDataObject(m_dataObject); |
| 391 | xmlWriter->SetFileName(datafile.filePath().c_str()); |
| 392 | } |
| 393 | else if (m_dataObject->IsA("vtkTable")) { |
| 394 | xmlWriter = vtkSmartPointer<vtkXMLTableWriter>::New(); |
| 395 | xmlWriter->SetInputDataObject(m_dataObject); |
| 396 | xmlWriter->SetFileName(fi.filePath().c_str()); |
| 397 | } |
| 398 | else { |
| 399 | xmlWriter = vtkSmartPointer<vtkXMLDataSetWriter>::New(); |
| 400 | xmlWriter->SetInputDataObject(m_dataObject); |
| 401 | xmlWriter->SetFileName(fi.filePath().c_str()); |
| 402 | |
| 403 | // Looks like an invalid data object that causes a crash with vtk9 |
| 404 | vtkUnstructuredGrid* dataGrid = vtkUnstructuredGrid::SafeDownCast(m_dataObject); |
| 405 | if (dataGrid && (dataGrid->GetPiece() < 0 || dataGrid->GetNumberOfPoints() <= 0)) { |
| 406 | std::cerr << "PropertyPostDataObject::SaveDocFile: ignore empty vtkUnstructuredGrid\n"; |
| 407 | return; |
| 408 | } |
| 409 | } |
| 410 | xmlWriter->SetDataModeToBinary(); |
| 411 | |
| 412 | if (xmlWriter->Write() != 1) { |
| 413 | // Note: Do NOT throw an exception here because if the tmp. file could |
| 414 | // not be created we should not abort. |
| 415 | // We only print an error message but continue writing the next files to the |
| 416 | // stream... |
| 417 | App::PropertyContainer* father = this->getContainer(); |
| 418 | if (father && father->isDerivedFrom<App::DocumentObject>()) { |
| 419 | App::DocumentObject* obj = static_cast<App::DocumentObject*>(father); |
| 420 | Base::Console().error( |
| 421 | "Dataset of '%s' cannot be written to vtk file '%s'\n", |
| 422 | obj->Label.getValue(), |
| 423 | fi.filePath().c_str() |
nothing calls this directly
no test coverage detected