Open CASCADE, the 3D modelling kernel
3D modeling & numerical simulation

Search the Forums
See All Topics

Does step support naming/coloring sub shape?

Does step support naming/coloring sub shape?
Cauchy Ding 2008/11/21 03:44
Hi folks,

I am using OCAF to export shapes to step file. All shapes and their sub shapes are attached with a name. I try to export all these information into the step file. But when I import the saved file, I find only the top-level shapes' name are available. I open the step file and find only the top-level shapes' name are stored and sub shapes' name are abandoned. I wonder know whether step support naming/coloring sub shapes. Does iges support naming/coloring sub shapes?
Thanks in advanced. Any suggestion is welcome.

-Cauchy Ding
Roman Lygin 2008/11/21 07:12
Hi Cauchy Ding,

In order to import/export colors, names and other meta data you need to use XDE (eXtended Data Exchange). See documentation for details.
Basically, you have to use {IGES,STEP}CAFControl_{Reader,Writer} classes which uses OCAF document of a special structure, i.e. there are certain expectations to the OCAF tree that contains shapes and associated meta data.
In DRAW you could use:
Draw> pload ALL
Draw> NewDocument d XmlXCAF
Draw> ReadStep myfile.stp d
Draw> DFBrowser d
This will open a browser for your document and you will get an idea of the document structure. Make sure that your %PATH% includes a path to <occ-install-dir>\3dparty\win32\qt\

If you are using your custom OCAF document then you need to extend it making XDE-compliant adding child labels, attributes, etc. before using *CAFControl_* classes.

Good luck.
Cauchy Ding 2008/11/24 01:36
Hi Roman Lygin,

My code lists as follows:

Handle(TDocStd_Document) doc;
Handle(XCAFApp_Application) anApp = XCAFApp_Application::GetApplication();
anApp->NewDocument("MDTV-XCAF", doc);
if ( !XCAFDoc_DocumentTool::IsXCAFDocument (doc) )
return false;
Handle (XCAFDoc_ShapeTool) myAssembly =XCAFDoc_DocumentTool::ShapeTool (doc->Main());
TDF_Label label;
Standard_Boolean makeAssembly=false;
for(i=0; i<shapes.size(); ++i)
shape = shapes[i];
id = shape.TShape()->GetID(); //GetID() is a self-defined function
label = myAssembly->AddShape(shape, makeAssembly);
sprintf(name, "%d", id);
TDataStd_Name::Set (label, name);
TopTools_IndexedMapOfShape subshaps;
for(Standard_Integer I = 1;I<=subshaps.Extent();I++)
const TopoDS_Shape &subShape = subshaps(I);
subID = subShape.TShape()->GetID(); //GetID() is a self-defined function
TDF_Label subLabel = myAssembly->AddSubShape(label, subShape);
sprintf(name, "%d", subID);
TDataStd_Name::Set (subLabel, name);
STEPCAFControl_Writer writer;
if(!writer.Perform(doc, filename))
return false;
return true;

When I open the written .step file, I only find the top-level shape's ID, all sub shapes' ID seems to be omitted by STEPCAFControl_Writer. Would you please give some suggestion to save all sub shapes'ID into file(any format)? Any suggestion is welcome. Thanks in advance.


Cauchy Ding 2008/11/24 02:44
Hi Roman Lygin,

In the XDE document, I find a chapter about the name field:
Name is implemented and used as a TDataStd_Name, which can be attached to any label. Before proceeding, consider that:
In IGES, every entity can have a name with an optional numeric part called a Subscript Label. For example, "MYCURVE" is a name, and "MYCURVE(60)" is a name with a Subscript Label.
In STEP, there are two levels: Part Names and Entity Names:
Part Names are attached to "main shapes" such as parts and assemblies. These Part Names are specifically supported by XDE.
Entity Names can be attached to every Geometric Entity. This option is rarely used, as it tends to overload the exploitation of the data structure. Only some specific cases justify using this option: for example, when the sending system can really ensure the stability of an entity name after each STEP writing. If such stability is ensured, you can use this option to send an Identifier for external applications using a database.
I wonder know how to save the "Entity Name" into the .step file. Thanks in advance.
Roman Lygin 2008/11/24 07:33
Hi Cauchy,

Just spent 5 mins on your case, so this is quite shallow analysis, of course. It may turn out that it's a bug in OCC step writer, as names really don't seem to get stored.
This is what I did. Took IGES file with labels, read into XDE doc and browsed in OCAF browser to make sure the file is read well. Converted it into IGES and STEP. Read back both. The doc from re-read IGES file does contain names, from STEP - does not. Fast scanning both files reveals that IGES file does contain names within the file, STEP file - does not.

Here's a sequence in DRAW (perhaps useful for OCC folks themselves):

Draw> pload ALL
Draw> NewDoc d MDTV-XCAF
Draw> ReadIges d ledu.igs # take any IGES file containing names
Draw> DFBrowser d #check the structure
Draw> WriteStep d ledu2.stp
Draw> WriteIges d ledu2.iges
Draw> NewDoc di MDTV-XCAF
Draw> NewDoc ds MDTV-XCAF
Draw> ReadIges di ledu2.igs
Draw> ReadStep ds ledu2.stp
#close browser window
Draw> DFBrowser ds #no labels
#close browser window
Draw> DFBrowser di #labels are there

There are no easy way here to attach screenshots, otherwise I'd do for better demonstration.
Don't know yet where the bug is, will check as time permits.

Hope this will help you somehow :-|


---> - blog on Open CASCADE
Cauchy Ding 2008/11/24 10:17
Hi Roman Lygin,

Great thanks for your patience and your selflessness on sharing your knowledge and experience on OCC.
According to the XDE document, iges format don't support the sub shapes' name field, but step supports it. But XDE document doesn't say clearly whether it can export/import sub shapes' name field. If my code is correct, it seems as if it can't save them into step file.
Off topic, your three articles about Handle in OCC are really very nice. :) Thanks.


Kevin Malachowski 2012/06/15 19:31
I doubt you still need a solution to this problem, but for anyone on google who needs this solution I managed to figure out how to do what you want to do.

TopoDS_Shape sh = [A shape that is a TopoDS_Compound type];

Handle(TDocStd_Document) document;
Handle(XCAFApp_Application) anApp = XCAFApp_Application::GetApplication();

Handle (XCAFDoc_ShapeTool) shaper= XCAFDoc_DocumentTool::ShapeTool(document->Main());
TDF_Label rootLabel = shaper->AddShape(sh, 1);

Handle(TDataStd_Name) name;
for (Standard_Integer i = 0; i < rootLabel.NbChildren(); i++) {
     TDF_Label child = aLabel.FindChild(i);
     if (child.FindAttribute(TDataStd_Name::GetID(), name)) {
          cout << name->Get() << endl;

          //If we're here, we've found the label for a child. You can name it by calling:
          // TDataStd_Name::Set (child, "Test name!");
          //You can find the shape instance of this child by calling:
          // TopoDS_Shape outShape;
          // bool foundit = shaper->GetShape(child, outShape);

     cout << "----" << endl;
Latest news
  • New features to enhance the development process
  • Open CASCADE Technology 6.7.1 is available for download!
  • Open CASCADE Technology 6.7.0 is available for download!

  • © OPEN CASCADE 2000 - 2014  |  Search  |  Contacts   |  Site map