AddComponent behavior (bug or feature)?

I'm using the XDE framework in OpenCascade 6.6.0 to create STEP files for some 3D models. In particular, I would like to create a hierarchy of labels corresponding to the logical organization of the system (e.g. grouping some parts into components, which are then grouped together by type, which are then part of the whole system). At each level, I would like to save the id of the part, and its color.

I'm having this problem with the AddComponent method of the XCAFDoc_DocumentTool::ShapeTool. Basically, I've tried several methods to create this hierarchy, but it all boils down to one problem: when I use AddComponent to add labels that correspond to assemblies, their name and of everything under them changes and cannot be changed back.

I've tried the method suggested by user Pawel here: to build everything bottom-up. Once I use AddComponent on an assembly label, the names got lost.

I've tried a top-down approach, by creating a compound of compounds of solids describing my system, adding the shape to the top level, and then finding the labels associated with each shape; tried to change the name of these labels, and nothing happened (I've used ShapeTool::UpdateAssembly).

I've also tried to build the whole document by going top-down, adding compounds/solids and creating labels for them at every level. Still same, once I add a compound, names are lost.

Basically, every time I use AddComponent to add a compound/assembly, the label names change and they cannot be changed to something else. The colors can be changed at will, but not the label names.

Is this how it's supposed to work, or is there a problem? I've seen some posts related to this behavior on the forums, but there was no definitive answer. Or, is it possible that there is something special that needs to be done when dealing with compounds? It seems strange though that names are lost like that and cannot be changed.

Pawel's picture

Hi Tiberiu,

does the problem refer to STEP files only (labels names lost in written STEP files) or does it occur in Data Framework already?

Can you post a simple reproducer (a couple of lines)?


Tiberiu Chelcea's picture

Hi Pawel, thanks for the answer. I haven't checked data in the Data Framework, I was just checking things in the CadExchanger program (which is built on top of OpenCascade) by loading the files and looking at the names. I was just about to start writing some code to read back the STEP files myself and see if there's any name attached to those solids.

I could post something, but I'm using the official C# wrapper for OCC for development, so it's not easily translatable. However, one good example would be the code from the forum post linked to from my initial post.

For testing, I've used a case with a component that has 6 solids. In test 1, the solids were added directly to the top label, which was created by adding an empty TopoDS_Compound to the document. In test 2, I've created a compound for each individual solid; each compound was added to another compound. This top-level compound was added to document, then I've search for the label of each solid, and changed its name (the example is contrived, but good for my testing purposes). If you want, I can try to translate the C# code in C++.

In test 1, the names appear in CadExchanger (version 2.5.1), while in test 2, the names are still of the format [0:1:1:2]. Interestingly, I've also inspected the STEP files generated in each case. I've looked for the solid named 'pin1'. In test 1, this is the line where that name appears:
#686 = NEXT_ASSEMBLY_USAGE_OCCURRENCE('1','pin1','',#5,#677,$);

in test 2, this is the line:
#66 = PRODUCT('pin1','pin1','',(#67));

so, while I've used the same function to assign names (TDataStd_Name::Set), the result seems quite different.

To make things even more complicated, I've installed STEP-NC, and opened each generated step file. Surprisingly enough, STEP-NC could now see the names in test 2 (which CadExchanger could not) and not see the names in test 1 (which CadExchanger could).

I'm attaching the two step files produced by these tests.

Forum supervisor's picture

Dear Tiberiu,
In XDE, organization of the model by components is made using assembly structure, where each component (part) can be included more than once in the next level shape (as instance).
Both XDE and STEP allow assigning colors and names to individual components (parts) and their instances in the assembly.
See attached sample DRAW script that demonstrates this logic.
In your test 1, you have names assigned to instances, while in test 2, they are assigned to parts.
To ensure that this works well in all systems, you probably need to assign names to both parts and their instances.
Best regards

Tiberiu Chelcea's picture


thank you for the example. I've modified my code and I can see the names & colors both in CadExchanger and STEP-NC. I'm yet to fully figure out when the label produced by AddComponent is for a part or for an instance, but hopefully this will come when I write the full translator for the more complex system.