How to Load Saved XCAF XML Documents Back into the Structure Tree and Display Geometry in Mayo? #363
-
I have saved all open documents as XCAF XML files in my MainWindow code as shown below: auto docs = m_guiApp->guiDocuments();
for (int i = 0; i < docs.size(); i++) {
auto doc = docs[i]->document();
if (doc.IsNull())
continue;
Handle(TDocStd_Document) doc1 = Handle(TDocStd_Document)::DownCast(doc);
Handle(XmlXCAFDrivers_DocumentStorageDriver) storageDriver = new XmlXCAFDrivers_DocumentStorageDriver(TCollection_ExtendedString("MyApp Copyright"));
std::string filename = "a.xml";
storageDriver->Write(doc1, filename.c_str());
} Now I want to load the saved XML files back into the structure tree and display the corresponding geometry in the viewer. However, I find it difficult to properly associate the loaded XCAF document with the Mayo Document class and update the UI accordingly. Could you please advise on the correct approach to: Load the XCAF XML document from file, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Some good solution would be to provide new reader and writer for the XML XCAF file format and register them in the I/O system. Another solution is to provide additional Load/Save commands in the File menu. auto app = AppModule::get()->application();
doc->ChangeStorageFormat(Document::NameFormatXml);
const PCDM_StoreStatus saveStatus = app->SaveAs(doc, filepathTo<TCollection_ExtendedString>(filepath));
if (saveStatus != PCDM_SS_OK)
throw std::runtime_error("XCAFApp_Application::SaveAs() failed"); The Load command would be like; auto app = AppModule::get()->application();
auto doc = app->newDocument(Document::Format::Xml);
doc->setName(filepath.filename().u8string());
doc->setFilePath(filepath);
const PCDM_ReaderStatus openStatus = app->Open(filepathTo<TCollection_ExtendedString>(filepath), doc);
if (openStatus != PCDM_RS_OK)
throw std::runtime_error("Application::Open() failed"); // TODO Handle error
doc->addEntityTreeNodeSequence(doc->xcaf().topLevelFreeShapes()); Please note I didn't test the code above, let me know your experiments |
Beta Was this translation helpful? Give feedback.
-
Hello, forgot to let you know I have made a branch to experiment XCAF save/open in Mayo: It provides two new File commands to open/saveAs a Document, it might be worth you try it on your side. |
Beta Was this translation helpful? Give feedback.
Hello, forgot to let you know I have made a branch to experiment XCAF save/open in Mayo:
https://github.com/fougue/mayo/tree/lab/xcaf-io
It contains a single commit:
256d8d2
It provides two new File commands to open/saveAs a Document, it might be worth you try it on your side.