Adding colors and names to your application. Part 2

by - 20:00

(continued)

OCC_UT_MyXDEApp could have inherited XCAFApp_Application and redefinition of Formats() and ResourcesName() would not have been required. But XCAFApp_Application’s constructor has been declared private (instead of protected) what disables inheritance :-(. Perhaps, OCC folks could correct that.

The document is created in a straightforward way:

Handle(TDocStd_Application) anApp = OCC_UT_MyXDEApp::GetApplication(); Handle(TDocStd_Document) aDoc; anApp->NewDocument ("XmlXCAF", aDoc);

The screenshot below shows the structure of a new document created with above application.




Note that XCAFDoc_DocumentTool has been assigned to the label 0:1:1:1 and it created a sub-tree with several pre-defined labels (XCAFDoc_ShapeTool, _ColorTool, etc).

OCC provides persistence for XDE-specific attributes in all three supported format (see StdResource) – standard textual, xml and binary. Some attributes (e.g. XCAFDoc_MaterialTool) are not stored in a file and are re-creating during read process.


TCollection_ExtendedString anErrorMsg;
anApp->SaveAs (aDoc, "C:\\Dev\\3dmodels\\sampledoc.xml", anErrorMsg);
if (anErrorMsg.Length()) {
std::cout << "Error occurred - " << TCollection_AsciiString (anErrorMsg).ToCString() << std::endl;

}


Here is a resulting XML file:




* Import /export with IGES and STEP *

To read/write colors and names from/to IGES or STEP you have to use classes {IGES,STEP}CAFControl_{Reader,Writer}, e.g. IGESCAFControl_Reader or STEPCAFControl_Writer.

IGESCAFControl_Reader aReader; IFSelect_ReturnStatus aStatus = aReader.ReadFile (aFileName); if (aStatus == IFSelect_RetDone) { Standard_Boolean aRes = aReader.Transfer (aDoc); }

Here is a document content after import of a sample file:



(to be continued)

You May Also Like

7 comments

  1. Roman, could you explain what does it means XDE-compliance. Can I make my existing OCAF-structure XDE-compliant and what are the main prerequisites? Would be possible to import/export IGES/STEP files then? Has it anything to do with the model history?

    ReplyDelete
  2. Svetlozar,
    By XDE-compliance I meant that you need to assign XCAFDoc_DocumentTool attribute using XCAFDoc_DocumentTool::Set(), which internally will create a substructure of the labels. In addition, it will register the document in a global map (for further identification of the label the _DocumentTool has been assigned to).
    After that it will be usable for importing IGES/STEP. You may use the structure and conventions suggested by XCAFDoc_ShapeTool (the way it marks up assemblies, components, subchilds, etc). Or use some mapping from your own subtree before exporting.

    ReplyDelete
  3. Hi Roman,
    First of all, thank you very much for your efforts on sharing your OCC knowledge with us. The blog is really helpful!
    I have one question regarding the use of XDE: In OCCT website it is stated that XDE is an OPTIONAL package. Does it means that I need to purchase a license in order to use the classes from STEPCAFControl? or are the XDE-packages being distributed under the same rules of the other packages of OpenCASCADE?
    Best regards,
    Fernando

    ReplyDelete
  4. Hi Fernando,

    XDE is optional in a sense that you can do conversion of STEP, IGES, etc without it, if you prefer (e.g. you can still convert topology and geometry). It's part of Open CASCADE already, free of charge and licensed under the same license as the rest of the code.

    Roman

    ReplyDelete
  5. hi Roman,
    I have got the tree heirachy as shown in the above figiure using DFD browser when reading one step/Iges file.
    But when I read with next step/Iges file, I could not see the color and layer structure of the next file.
    Is my expection of getting similar tree structure for next data too is right or wrong?
    Is there any initialization necessary for next data, I couldnot understand nicely.
    Hope to get some idea from you.
    Thank you.

    ReplyDelete
  6. Hi Roman,

    I read your description and tried it by my self. But I have a problem, that is already disused in the OCC forum. But I don't understand how I should solve this. I work with Linux and I get the error "could not find the resource:a148e300-5740-11d1-a904-080036aaa103.Location" from this Line:
    Handle(TDocStd_Application) anApp = XDEApp::GetApplication();

    I wrote your answer in the forum: http://www.opencascade.org/org/forum/thread_15610/

    But I don't understand what this means. I have no one of this env vars. I work with qtcreator and set the lib-search-path by my selfe. The code from your description I wrote to a simple *cpp and *.hxx file.
    Could you help me. I'm a little bit despaired.:-((

    Best regards,
    Franz Engel

    ReplyDelete
  7. Hi Franz,
    Thanks for the question. Yes, I saw it on the forum, and it's better to stay there to have single-thread discussion.
    Indeed, you need to set environment and in particular CSF_PluginDefaults variable as this GUID you refer to belongs to the file src/StdResource/Plugin.
    HTH
    Roman

    ReplyDelete