Can two separate solids be in one CompSolid?


I am trying to distinguish Solids from a Compound, and group the solids in some shape, I am thinking using CompSolid. I know in theory, CompSolid should contain solids sharing surfaces, but can I put two solids in different location, which are not touching, into one CompSolid? Is there any drawbacks if I do so?

Thank you for your advise.


Forum supervisor's picture

Hi Jane Hu,
As you know CompSolid by definition should have shared faces between participating solids. In your case it is pure Compound. Probably you want to have some kind of filter to be sure that your final shape contains only solids. In this case just implement this filter in your API to be possible to add only expected shapes in Compound.

Yours sincerely,
forum supervisor

Jane Hu's picture

Thank you, forum Supervisor.

My actual question can be stated in detail as this:

In my model, I have some single Solids and Faces, and some solids are grouped together in a Compound. I wanted to export such a model with Compounds(which include only multiple Solids), Solids, Faces, and etc. When I write to a brep file, the code wraps everything into a big Compound. I am able to create a file having Compound inside Compound. However, when I try to read it using TopExp_Explorer, like

TopExp_Explorer Ex;
for (Ex.Init(aShape, TopAbs_COMPSOLID); Ex.More(); Ex.Next())

Ex has only one Compound of the big one, I can't find the small Compound inside the model by this method. Hence, I am not able to create original Compound, Solids, Faces etc. Is it designed this way? I am thinking to find all solids in the model and remove all solids that are not in any Compound, this will give me solids in Compound only. But this way, I can only create a correct Compound when there is only one such Compound in the model. I still can't tell if there are more Compound(Solids' groups) in a model. Is there a better way to do this?

Also, I checked many brep file in your website, and don't see any file having a CS type. Usually when we create models using primitives and boolean operations, we don't create solids sharing surfaces. This is only done when we explicitly ask for merge of two neighboring surfaces on two solids, right? In other words, boolean operation won't return CompSolids, right?
If this is not the case, can you give me an example on the situation that the code will return a CompSolid?

Thank you for your attention, and I am looking forward to hearing from you again!


sergey zaritchny's picture

Hello Jane Hu,

As I understood you would like to iterate model which has structure like Compound in Compound ..., i.e. some kind of "Russian doll".
For this purpose you should use TopoDS_Iterator using as parameter the shape to be iterated.
Lets see the example with 3 levels of hierarchy.
Compound_C1 (level 1)
Solid1 + Solid2 + Solid3 + Compound_C2 (level 2)
Solid4 + Solid5 + Face1 (level 3)
TopoDS_Iterator it (C1);
TopoDS_Shape aShape = it.Value();// here you will get all shapes of level 2
TopoDS_Iterator it2 (aShape);
TopoDS_Shape aShape2 = it2.Value();// here you will get all shapes of level 3,
// i.e: Solid4, Solid5, Face1
I hope it will help you.
Good luck.