MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / RestoreDocFile

Method RestoreDocFile

src/Mod/Fem/App/PropertyPostDataObject.cpp:455–585  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453}
454
455void PropertyPostDataObject::RestoreDocFile(Base::Reader& reader)
456{
457 Base::FileInfo xml(reader.getFileName());
458 // create a temporary file and copy the content from the zip stream
459 Base::FileInfo fi(App::Application::getTempFileName());
460 Base::FileInfo fo;
461
462 // read in the ASCII file and write back to the file stream
463 Base::ofstream file(fi, std::ios::out | std::ios::binary);
464 unsigned long ulSize = 0;
465 if (reader) {
466 std::streambuf* buf = file.rdbuf();
467 reader >> buf;
468 file.flush();
469 ulSize = buf->pubseekoff(0, std::ios::cur, std::ios::in);
470 }
471 file.close();
472
473 // Read the data from the temp file
474 if (ulSize > 0) {
475 std::string extension = xml.extension();
476
477 // TODO: read in of composite data structures need to be coded,
478 // including replace of "GetOutputAsDataSet()"
479 vtkSmartPointer<vtkXMLReader> xmlReader = nullptr;
480 if (extension == "vtp") {
481 xmlReader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
482 }
483 else if (extension == "vts") {
484 xmlReader = vtkSmartPointer<vtkXMLStructuredGridReader>::New();
485 }
486 else if (extension == "vtr") {
487 xmlReader = vtkSmartPointer<vtkXMLRectilinearGridReader>::New();
488 }
489 else if (extension == "vtu") {
490 xmlReader = vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
491 }
492 else if (extension == "vti") {
493 xmlReader = vtkSmartPointer<vtkXMLImageDataReader>::New();
494 }
495 else if (extension == "vtt") {
496 xmlReader = vtkSmartPointer<vtkXMLTableReader>::New();
497 }
498 else if (extension == "zip") {
499
500 // first unzip the file into a datafolder
501 zipios::ZipInputStream ZipReader(fi.filePath());
502 fo = Base::FileInfo(App::Application::getTempPath() + "vtk_extract_datadir");
503 fo.createDirectories();
504
505 try {
506 zipios::ConstEntryPointer entry = ZipReader.getNextEntry();
507 while (entry->isValid()) {
508 Base::FileInfo entry_path(fo.filePath() + entry->getName());
509 if (entry->isDirectory()) {
510 // seems not to be called
511 entry_path.createDirectories();
512 }

Callers

nothing calls this directly

Calls 15

createDirectoriesMethod · 0.80
dirPathMethod · 0.80
FileInfoClass · 0.50
getFileNameMethod · 0.45
flushMethod · 0.45
closeMethod · 0.45
extensionMethod · 0.45
filePathMethod · 0.45
getNextEntryMethod · 0.45
isValidMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected