Salome HOME
RNV: Remove deprecated code.
[modules/geom.git] / src / CurveCreator / CurveCreator_Utils.cxx
index 52fab0c1c4fbf4dbf2b6b47ad861d4bc7d35d322..53f68259f6f769f42b172749abdb8148dd5fdc63 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2013-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -20,6 +20,7 @@
 #include "CurveCreator_Utils.hxx"
 #include "CurveCreator.hxx"
 #include "CurveCreator_Curve.hxx"
+#include "CurveCreator_Section.hxx"
 #include "CurveCreator_UtilsICurve.hxx"
 
 #include <Basics_OCCTVersion.hxx>
@@ -145,7 +146,7 @@ gp_Pnt CurveCreator_Utils::ConvertClickToPoint( int x, int y, Handle(V3d_View) a
   // we need the projection to the XOY plane
   // 1. find a point in the plane of the eye and the normal to the plane
   Standard_Real X, Y, Z;
-  Quantity_Parameter Vx, Vy, Vz;
+  Standard_Real Vx, Vy, Vz;
   aView->ConvertWithProj( x, y, X, Y, Z, Vx, Vy, Vz );
 
   // 2. build a ray from the point by the normal to the XOY plane and intersect it
@@ -186,16 +187,8 @@ gp_Pnt CurveCreator_Utils::ConvertClickToPoint( int x, int y, Handle(V3d_View) a
 //=======================================================================
 // function : constructBSpline
 // purpose  :
-//  The algorithm builds the cubic B-spline passing through the points that the
-//  tangent vector in each given point P is calculated by the following way:
-//  if point P is preceded by a point A and is followed by a point B then
-//  the tangent vector is equal to (P - A) / |P - A| + (B - P) / |B - P|;
-//  if point P is preceded by a point A but is not followed by any point then
-//  the tangent vector is equal to P - A;
-//  if point P is followed by a point B but is not preceded by any point then
-//  the tangent vector is equal to B - P.
 //=======================================================================
-static bool constructBSpline(
+bool CurveCreator_Utils::constructBSpline(
   const Handle(TColgp_HArray1OfPnt)& thePoints,
   const Standard_Boolean theIsClosed,
   Handle(Geom_BSplineCurve)& theBSpline)
@@ -257,6 +250,47 @@ static bool constructBSpline(
   return aResult;
 }
 
+//=======================================================================
+// function : constructWire
+// purpose  :
+//=======================================================================
+TopoDS_Wire CurveCreator_Utils::ConstructWire(
+  Handle(TColgp_HArray1OfPnt) thePoints,
+  const bool theIsPolyline,
+  const bool theIsClosed)
+{
+  TopoDS_Wire aWire;
+  BRep_Builder aBuilder;
+  aBuilder.MakeWire(aWire);
+  const int aPointCount = thePoints->Length();
+  if (theIsPolyline)
+  {
+    const TopoDS_Vertex aFirstVertex =
+      BRepBuilderAPI_MakeVertex(thePoints->Value(1));
+    TopoDS_Vertex aVertex = aFirstVertex;
+    for (Standard_Integer aPN = 1; aPN < aPointCount; ++aPN)
+    {
+      const TopoDS_Vertex aVertex2 =
+        BRepBuilderAPI_MakeVertex(thePoints->Value(aPN + 1));
+      aBuilder.Add(aWire, BRepBuilderAPI_MakeEdge(aVertex, aVertex2));
+      aVertex = aVertex2;
+    }
+    if (theIsClosed && aPointCount > 1)
+    {
+      aBuilder.Add(aWire, BRepBuilderAPI_MakeEdge(aVertex, aFirstVertex));
+    }
+  }
+  else
+  {
+    Handle(Geom_BSplineCurve) aBSpline;
+    if (constructBSpline(thePoints, theIsClosed, aBSpline))
+    {
+      aBuilder.Add(aWire, BRepBuilderAPI_MakeEdge(aBSpline));
+    }
+  }
+  return aWire;
+}
+
 //=======================================================================
 // function : constructShape
 // purpose  :
@@ -277,71 +311,25 @@ void CurveCreator_Utils::constructShape(
     }
 
     // Get the different points.
-    std::vector<gp_Pnt> aTmpPoints;
-    gp_Pnt aFirstPoint;
-    CurveCreator_UtilsICurve::getPoint(theCurve, aSectionI, 0, aFirstPoint);
-    gp_Pnt aPoint = aFirstPoint;
-    aTmpPoints.push_back(aPoint);
-    for (int aPI = 1; aPI < aTmpPointCount; ++aPI)
-    {
-      gp_Pnt aPoint2;
-      CurveCreator_UtilsICurve::getPoint(theCurve, aSectionI, aPI, aPoint2);
-      if (!isEqualPoints(aPoint, aPoint2))
-      {
-        aPoint = aPoint2;
-        aTmpPoints.push_back(aPoint);
-      }
-    }
+    const CurveCreator_ISection* aSection = theCurve->getSection(aSectionI);
+    Handle(TColgp_HArray1OfPnt) aPoints;
+    aSection->GetDifferentPoints(theCurve->getDimension(), aPoints);
+    const int aPointCount = aPoints->Length();
     const bool isClosed = theCurve->isClosed(aSectionI);
-    int aPointCount = aTmpPoints.size();
-    if (isClosed)
-    {
-      while (aPointCount > 1 &&
-        isEqualPoints(aFirstPoint, aTmpPoints[aPointCount - 1]))
-      {
-        --aPointCount;
-      }
-    }
 
     // Add the vertices to the shape.
-    Handle(TColgp_HArray1OfPnt) aPoints =
-      new TColgp_HArray1OfPnt(1, aPointCount);
-    for (Standard_Integer aPI = 0; aPI < aPointCount; ++aPI)
+    for (Standard_Integer aPN = 1; aPN <= aPointCount; ++aPN)
     {
-      aPoints->SetValue(aPI + 1, aTmpPoints[aPI]);
-      aBuilder.Add(aShape, BRepBuilderAPI_MakeVertex(aTmpPoints[aPI]));
-    }
-    if (aPointCount == 1)
-    {
-      continue;
+      aBuilder.Add(aShape, BRepBuilderAPI_MakeVertex(aPoints->Value(aPN)));
     }
 
-    // Add the edges to the shape.
+    // Add the wire to the shape.
     const bool isPolyline =
       (theCurve->getSectionType(aSectionI) == CurveCreator::Polyline);
-    if (isPolyline)
+    const TopoDS_Wire aWire = ConstructWire(aPoints, isPolyline, isClosed);
+    if (!aWire.IsNull())
     {
-      for (Standard_Integer aPN = 1; aPN < aPointCount; ++aPN)
-      {
-        aBuilder.Add(aShape, BRepBuilderAPI_MakeEdge(
-          BRepBuilderAPI_MakeVertex(aPoints->Value(aPN)),
-          BRepBuilderAPI_MakeVertex(aPoints->Value(aPN + 1))));
-      }
-      if (isClosed)
-      {
-        aBuilder.Add(aShape, BRepBuilderAPI_MakeEdge(
-          BRepBuilderAPI_MakeVertex(aPoints->Value(aPointCount)),
-          BRepBuilderAPI_MakeVertex(aPoints->Value(1))));
-      }
-    }
-    else
-    {
-      Handle(Geom_BSplineCurve) aBSpline;
-      if (constructBSpline(aPoints, isClosed, aBSpline))
-      {
-        aBuilder.Add(aShape,
-          BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(aBSpline)));
-      }
+      aBuilder.Add(aShape, aWire);
     }
   }
   theShape = aShape;
@@ -568,7 +556,7 @@ void CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theCo
 {
   thePoints.clear();
 
-  std::list<float> aSelectedPoints;
+  std::list<double> aSelectedPoints;
   gp_Pnt aPnt;
   std::map<CompareSectionToPoint, int> aPointsMap;
 
@@ -630,22 +618,22 @@ void CurveCreator_Utils::setSelectedPoints( Handle(AIS_InteractiveContext) theCo
   //ASL: we switch off automatic highlight to improve performance of selection
   theContext->SetAutomaticHilight( Standard_False );
 
-  Handle_SelectMgr_Selection aSelection = anAISShape->Selection( AIS_Shape::SelectionMode( TopAbs_VERTEX ) );
+  Handle(SelectMgr_Selection) aSelection = anAISShape->Selection( AIS_Shape::SelectionMode( TopAbs_VERTEX ) );
   for( aSelection->Init(); aSelection->More(); aSelection->Next() )
   {    
 #if OCC_VERSION_LARGE > 0x06080100
     const Handle(SelectMgr_SensitiveEntity) aHSenEntity = aSelection->Sensitive();
     if( aHSenEntity.IsNull() )
       continue;
-    Handle_SelectBasics_SensitiveEntity aSenEntity = aHSenEntity->BaseSensitive();
+    Handle(SelectBasics_SensitiveEntity) aSenEntity = aHSenEntity->BaseSensitive();
 #else
-    Handle_SelectBasics_SensitiveEntity aSenEntity = aSelection->Sensitive();
+    Handle(SelectBasics_SensitiveEntity) aSenEntity = aSelection->Sensitive();
 #endif
 
-    Handle_Select3D_SensitivePoint aSenPnt = Handle_Select3D_SensitivePoint::DownCast( aSenEntity );
+    Handle(Select3D_SensitivePoint) aSenPnt = Handle(Select3D_SensitivePoint)::DownCast( aSenEntity );
 
     gp_Pnt anOwnerPnt = aSenPnt->Point();
-    Handle_SelectMgr_EntityOwner anOwner = Handle_SelectMgr_EntityOwner::DownCast( aSenPnt->OwnerId() );
+    Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast( aSenPnt->OwnerId() );
 
 
     CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(),
@@ -699,7 +687,7 @@ void CurveCreator_Utils::setLocalPointContext( const CurveCreator_ICurve* theCur
   }
   else {
     if ( theContext->HasOpenedContext() )
-      theContext->CloseAllContexts();
+      theContext->CloseAllContexts( Standard_True );
   }
 }
 
@@ -1004,7 +992,7 @@ Handle(TColgp_HArray1OfPnt) CurveCreator_Utils::getPoints
 // purpose  : 
 //=======================================================================
 void CurveCreator_Utils::FindPlane
-                       (const Handle_TColgp_HArray1OfPnt &thePoints,
+                       (const Handle(TColgp_HArray1OfPnt) &thePoints,
                               gp_Pln                     &thePlane,
                               Standard_Integer           &thePlnStatus)
 {