+ // Collect the list of region faces
+ TopTools_ListOfShape aRegionFacesList;
+
+ HYDROData_SequenceOfObjects aZones = GetZones();
+ HYDROData_SequenceOfObjects::Iterator aZoneIter( aZones );
+ for ( ; aZoneIter.More(); aZoneIter.Next() ) {
+ Handle(HYDROData_Zone) aZone =
+ Handle(HYDROData_Zone)::DownCast( aZoneIter.Value() );
+
+ if ( aZone.IsNull() ) {
+ continue;
+ }
+
+ TopoDS_Face aFace = TopoDS::Face( aZone->GetShape() );
+ if ( !aFace.IsNull() ) {
+ aRegionFacesList.Append( aFace );
+ }
+ } // zones iterator
+
+ // Check number of faces
+ int aNbFaces = aRegionFacesList.Extent();
+ if ( aNbFaces > 0 ) {
+ // The unite region face
+ TopoDS_Face aRegionFace;
+
+ if ( aNbFaces == 1 ) {
+ aRegionFace = TopoDS::Face( aRegionFacesList.First() );
+ } else {
+ // Fuse faces into one
+ TopoDS_Shape aFuseShape;
+ TopTools_ListIteratorOfListOfShape aFaceIter( aRegionFacesList );
+ for ( ; aFaceIter.More(); aFaceIter.Next() ) {
+ if ( aFuseShape.IsNull() ) {
+ aFuseShape = aFaceIter.Value();
+ } else {
+ BRepAlgoAPI_Fuse aFuse(aFuseShape, aFaceIter.Value());
+ if ( !aFuse.IsDone() ) {
+ aFuseShape.Nullify();
+ break;
+ }
+ aFuseShape = aFuse.Shape();
+ }
+ } // faces iterator
+
+ // Check the result of fuse operation
+ if ( !aFuseShape.IsNull() ) {
+ ShapeUpgrade_UnifySameDomain anUnifier( aFuseShape );
+ anUnifier.Build();
+ TopoDS_Shape anUnitedShape = anUnifier.Shape();
+
+ TopTools_IndexedMapOfShape aMapOfFaces;
+ TopExp::MapShapes( anUnitedShape, TopAbs_FACE, aMapOfFaces );
+ if ( aMapOfFaces.Extent() == 1 ) {
+ aRegionFace = TopoDS::Face( aMapOfFaces(1) );
+ }
+ }
+ }
+
+ if ( !aRegionFace.IsNull() ) { // result shape is a face
+ aResShape = aRegionFace;
+ } else { // result shape is a shell
+ TopoDS_Shell aShell;
+ BRep_Builder aBuilder;
+ aBuilder.MakeShell( aShell );
+
+ TopTools_ListIteratorOfListOfShape aFaceIter( aRegionFacesList );
+ for ( ; aFaceIter.More(); aFaceIter.Next() ) {
+ aBuilder.Add( aShell, aFaceIter.Value() );
+ }
+
+ aResShape = aShell;
+ }
+ }
+
+ return aResShape;
+}