How to save more than one TopoDS_Shape in one brep file?

How can I save more than one selected TopoDS_Shapes from interactive context into one brep file?
I found that the example launched with the sdk only demonstrates how to save the first TopoDS_Shape in the TopTools_HSequenceOfShape.

Any help is appreciated!


mbd_forever's picture

Hi !

You can build a TopoDS_Compound containing all your shapes and store this compound ...


t5vk8g's picture

Now I have already read it from the file as a whole TopoDS_Shape.
The problem is how to downcast TopoDS_Shape to TopoDS_Compound and how to
decompound the TopoDS_Compound to the seperated TopoDS_Shape.


Grey's picture


//To downcast to compound:
TopoDS_Shape aResultShape; //The shape from file
TopoDS_Compound aCompound;
if(aResultShape.ShapeType() == TopAbs_COMPOUND) {
aCompound = TopoDS::Compound(aResultShape);
//To iterate a compound to find for example faces
TopExp_Explorer anExp(aCompound, TopAbs_FACE);
for(; anExp.More(); anExp.Next()) {
TopoDS_Face aFace = TopoDS::Face(anExp.Current());

//To iterate all shapes in the compound
TopoDS_Iterator anIter(aCompound);
for(; anIter.More(); anIter.Next()) {
TopoDS_Shape aSh = anIter.Value();

Just don't forget the necessary header files.
One more point: you don't need to downcast to TopoDS_Compound to use Explorer and Iterator,
it was possible to pass aResultShape directly and got
the same result.


t5vk8g's picture

Thanks to mbd_forever and Grey !