]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #567: change buildShape() method.
authormzn <mzn@opencascade.com>
Mon, 15 Jun 2015 09:19:05 +0000 (12:19 +0300)
committermzn <mzn@opencascade.com>
Mon, 15 Jun 2015 09:19:05 +0000 (12:19 +0300)
src/HYDROData/HYDROData_LandCover.cxx

index 3680865ca4a39b611265412e37f81b1c11311233..b588c1faa7b9c6878d298db512696ba779c76d9e 100644 (file)
@@ -20,7 +20,9 @@
 
 #include "HYDROData_PolylineXY.h"
 
+#include <BRep_Builder.hxx>
 #include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
 #include <TDataStd_AsciiString.hxx>
 #include <TNaming_Builder.hxx>
 #include <TNaming_NamedShape.hxx>
@@ -198,7 +200,70 @@ TopoDS_Shape HYDROData_LandCover::buildShape() const
 {
   TopoDS_Shape aResShape;
 
+  BRepBuilderAPI_MakeWire aMakeWire;
+  
+  TopTools_ListOfShape aClosedWires;
+
+  HYDROData_SequenceOfObjects aRefPolylines = GetPolylines();
+  for ( int i = 1, n = aRefPolylines.Length(); i <= n; ++i ) {
+    Handle(HYDROData_PolylineXY) aPolyline = 
+      Handle(HYDROData_PolylineXY)::DownCast( aRefPolylines.Value( i ) );
+    
+    if ( aPolyline.IsNull() ) {
+      continue;
+    }
+
+    TopoDS_Shape aPolyShape = aPolyline->GetShape();
+    if ( aPolyShape.IsNull() || aPolyShape.ShapeType() != TopAbs_WIRE ) {
+      continue;
+    }
+
+    const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolyShape );
+    if ( aPolylineWire.IsNull() ) {
+      continue;
+    }
+
+    if ( aPolylineWire.Closed() ) {
+      aClosedWires.Append( aPolylineWire );
+    } else {
+      aMakeWire.Add( aPolylineWire );
+      aMakeWire.Build();
+      if ( aMakeWire.IsDone() ) {
+        if ( aMakeWire.Wire().Closed() ) {
+          aClosedWires.Append( aMakeWire.Wire() );
+          aMakeWire = BRepBuilderAPI_MakeWire();
+        }
+      }
+    }
+  }
+
+  if ( aClosedWires.Extent() == 1 ) {
+    // make face
+    BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( aClosedWires.First() ) );
+    aMakeFace.Build();
+    if( aMakeFace.IsDone() ) {
+      aResShape = aMakeFace.Face();
+    }
+  } else if ( aClosedWires.Extent() > 1 ) {
+    // make compound
+    BRep_Builder aBuilder;
+    TopoDS_Compound aCompound;
+    aBuilder.MakeCompound( aCompound );
+
+    TopTools_ListIteratorOfListOfShape aWiresIter( aClosedWires );
+    for ( ; aWiresIter.More(); aWiresIter.Next() ) {
+      BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( aWiresIter.Value() ) );
+      aMakeFace.Build();
+      if( aMakeFace.IsDone() ) {
+        aBuilder.Add( aCompound, aMakeFace.Face() );
+      }
+    }
+
+    aResShape = aCompound;
+  }
+
   ///< \TODO to be reimplemented
+  /*
   TopoDS_Shape anArgShape;
   TopTools_ListOfShape aToolShapes;
   
@@ -263,6 +328,7 @@ TopoDS_Shape HYDROData_LandCover::buildShape() const
       aResShape = aBOP.Shape();
     }
   }
+  */
   
   return aResShape;
 }
\ No newline at end of file