Is it possible to create TDocStd_Document instance from an existing file.xbf?

I want somehow to accelerate a model downloading. The slowest operation is transferring data from a step file to the TDocStd_Document ( stepReader.Perform(pathToStepFile, document) ) - for 20mb model it takes 10 seconds. I am curious about transferring data only once and then just use previously saved TDocStd_Document file. I would be glad to hear any suggestions how to speed up the process of creating a document from a file, or other best practices about displaying the model with all its nested sub shapes.

Dmitrii Pasukhin's picture

Hello,

The most part of transfer time is creating shapes.
Exchange attributes takes a little time. You can save and load any xbf or ocf documents in/from file.
Using XCafDoc_Editor you can copy some shapes to another document with all attributes.

For more information, Can you give more information about your use case?

Best regards, Dmitrii.

Кирилл Жильников's picture

I am loading a model.step from a directory. Then in my program I need to display this model and get access to all its sub-shapes. For getting access to sub-shapes and attributes I am using TDocStd_Document. I need to speed up model loading in order to visualize it as fast as possible. I thought about multithreading, but I have nothing to multithread.

void OcctGtkViewer::InitializeOcctDoc(string pathToFile)
{
occtApp = new TDocStd_Application();
BinXCAFDrivers::DefineFormat(occtApp);

occtApp->NewDocument("BinXCAF", occtDoc);

if (pathToFile == "")
pathToFile = testModelFolder;

STEPCAFControl_Reader aStepReader;

aStepReader.Perform(pathToFile.c_str(), occtDoc);

TCollection_ExtendedString s("./ file.std");

occtApp->SaveAs(occtDoc, s);
}

Then I use occtDoc in a recursive function in order to find and visualize sub-shapes. I am interested in how to construct this occtDoc the way more faster. The idea I had is about transferring data from the step file only once and then just creating an instance of TDocStd_Document based on saved document with already transferred data of a specific step model.

Dmitrii Pasukhin's picture

For speed up visualization you can pre-tesselate all shapes before saving. As soon as you tesselate all shapes they visualize very faster after loading XCAF file. For speed up loading XCAF file in this case you can remove all child(sub-shapes) of tesselated shapes(if they do not contain important information).

In general case you can't speed up loading time of XCAF doc.

Best regards, Dmitrii.

Кирилл Жильников's picture

I'm also interested in cases where you need to save a TDocStd_Document doc instance to a folder. Just to visualize the model hierarchy? And for what I need to use a app->Open(pathToDoc, docInstance) command?

Dmitrii Pasukhin's picture

Unfortunatelly, I need more information. I don't understand what you mean.

Best regards, Dmitrii.

Кирилл Жильников's picture

So, the final question: is it impossible to pass already saved xbf file to TDocStd_Document in order to skip the step of trespassing data from the step file to the new created document?

Dmitrii Pasukhin's picture

You can load existed xbf file to the TDocStd_Document and work with it you dont need Step file after.

To copy one loaded document to new, you can just copy all labels. For example, using XCafDoc_Editor::Clone

Best regards,  Dmitrii.

Кирилл Жильников's picture

I have found only CloneShapeLabel() method which takes label to transfer. I am pretty new to open cascade, could you please give a code example which illustrates, how to create a TDocStd_Document instance, based on a saved xbf file ( ./src/model.xbf )

Dmitrii Pasukhin's picture

If you want to load document from file, just call anApp->Open(...). I need more information to give more detailed answer.

Best regards, Dmitrii.

Кирилл Жильников's picture

Yes, you are right! That is what I need, Thanks!