Salome HOME
Refs #289 - Spline profile is represented in OCC view as polyline profile
[modules/hydro.git] / src / HYDROData / HYDROData_PolylineXY.cxx
index 06ea1bbced9f51ecdc0b6ef79ab27c1bbaec59d9..f55f42b8ce6ab679873e44bc921122f8a8d4d62f 100755 (executable)
@@ -9,6 +9,7 @@
 #include <BRep_Builder.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
+#include <BRepBuilderAPI_MakePolygon.hxx>
 #include <BRepBuilderAPI_MakeFace.hxx>
 #include <BRepOffsetAPI_NormalProjection.hxx>
 
@@ -326,49 +327,37 @@ TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType&
                                              const bool&                         theIsClosed,
                                              const NCollection_Sequence<gp_XYZ>& thePoints )
 {
-  BRepBuilderAPI_MakeWire aMakeWire;
-  
+  TopoDS_Wire aWire;
   if( theType == SECTION_POLYLINE )
   {
-    for( int i = 1, n = thePoints.Size(); i <= n; ++i )
+    BRepBuilderAPI_MakePolygon aMakeWire;
+    for ( int i = 1, n = thePoints.Length(); i <= n ; ++i )
     {
-      const gp_XYZ& aFirstPoint = thePoints.Value( i );
-
-      gp_XYZ aLastPoint;
-      if ( i == n )
-      {
-        if( theIsClosed )
-          aLastPoint = thePoints.Value( 1 );
-        else
-          break;
-      }
-      else
-      {
-        aLastPoint = thePoints.Value( i + 1 );
-      }
-
-      gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), aFirstPoint.Z() );
-      gp_Pnt aPnt2( aLastPoint.X(), aLastPoint.Y(), aLastPoint.Z() );
-
-      if ( aPnt1.IsEqual( aPnt2, LOCAL_SELECTION_TOLERANCE ) )
-        continue;
-
-      TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
-      aMakeWire.Add( anEdge );
+      gp_XYZ aPoint = thePoints.Value( i );
+      gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
+      aMakeWire.Add( aPnt );
     }
+    if( theIsClosed )
+      aMakeWire.Close();
+
+    if ( aMakeWire.IsDone() )
+      aWire = aMakeWire.Wire();
   }
   else //if( theType == PolylineSection::SECTION_SPLINE )
   {
-    HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
+    BRepBuilderAPI_MakeWire aMakeWire;
 
-    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
-    aMakeWire.Add( anEdge );
-  }
+    if ( thePoints.Size() > 1 )
+    {
+      HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
 
-  TopoDS_Wire aWire;
-  aMakeWire.Build();
-  if ( aMakeWire.IsDone() )
-    aWire = aMakeWire;
+      TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
+      aMakeWire.Add( anEdge );
+    }
+    aMakeWire.Build();
+    if ( aMakeWire.IsDone() )
+      aWire = aMakeWire;
+  }
 
   return aWire;
 }