]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Merge branch 'BR_v14_rc' into BR_quadtree
authorPaul RASCLE <paul.rascle@edf.fr>
Wed, 8 Jul 2015 21:37:16 +0000 (23:37 +0200)
committerPaul RASCLE <paul.rascle@edf.fr>
Wed, 8 Jul 2015 21:37:16 +0000 (23:37 +0200)
src/HYDROData/HYDROData_Channel.cxx
src/HYDROData/HYDROData_Polyline3D.cxx
src/HYDROData/HYDROData_Polyline3D.h
src/HYDROData/HYDROData_PolylineOperator.cxx
src/HYDROData/HYDROData_PolylineOperator.h
src/HYDROData/HYDROData_Profile.cxx
src/HYDROData/HYDROData_Profile.h
src/HYDROData/HYDROData_Stream.cxx
src/HYDROData/HYDROData_Stream.h

index f689081336606e31be317b31a2c632765e3401e5..819e3030d2dd7df1223c628ddb4425aae9517c21 100644 (file)
 #include "HYDROData_ShapesGroup.h"
 #include "HYDROData_ShapesTool.h"
 #include "HYDROData_Pipes.h"
+#include "HYDROData_Stream.h"
+
+#include <BRepBuilderAPI_MakeWire.hxx>
 
 #include <BRepOffsetAPI_MakePipeShell.hxx>
 #include <BRepOffsetAPI_MakePipe.hxx>
 #include <BRepCheck_Analyzer.hxx>
 
+#include <BRep_Tool.hxx>
+
+#include <BRepBuilderAPI_Transform.hxx>
+
+#include <BRepLib_MakeEdge.hxx>
+#include <BRepLib_MakeWire.hxx>
+
+#include <GeomAPI_ProjectPointOnCurve.hxx>
+
+#include <gp_Ax1.hxx>
+
 #include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+
+#include <TColgp_HArray1OfPnt.hxx>
+#include <TColgp_Array1OfDir.hxx>
+
+#include <TColStd_Array1OfReal.hxx>
+
+#include <TopTools_HArray1OfShape.hxx>
 
 #include <TopoDS.hxx>
 #include <TopoDS_Wire.hxx>
@@ -102,48 +124,175 @@ TopoDS_Shape HYDROData_Channel::GetShape3D() const
 }
 
 bool HYDROData_Channel::CreatePresentations( const Handle(HYDROData_Polyline3D)& theGuideLine,
-                                            const Handle(HYDROData_Profile)&    theProfile,
-                                            PrsDefinition&                      thePrs )
+                                             const Handle(HYDROData_Profile)&    theProfile,
+                                             PrsDefinition&                      thePrs )
 {
-  if ( theGuideLine.IsNull() || theProfile.IsNull() )
+  // Check input parameters
+  if ( theGuideLine.IsNull() || theProfile.IsNull() ) {
     return false;
+  }
 
-  // build 3d shape 
   TopoDS_Wire aPathWire = TopoDS::Wire( theGuideLine->GetShape3D() );
   TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetShape3D() );
-  if ( aPathWire.IsNull() || aProfileWire.IsNull() )
+  if ( aPathWire.IsNull() || aProfileWire.IsNull() ) {
     return false;
+  }
 
 #ifdef DEB_CHANNEL
   BRepTools::Write( aPathWire, "guideline.brep" );
   BRepTools::Write( aProfileWire, "profile.brep" );
 #endif
 
-  HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
-  if( aChannelConstructor.GetStatus() != 0 )
+  // Pre-processing
+  Handle(HYDROData_PolylineXY) aPolylineXY = theGuideLine->GetPolylineXY();
+  if ( aPolylineXY.IsNull() ) {
     return false;
+  }
 
-  aChannelConstructor.Create3dPresentation();
-  aChannelConstructor.Create2dPresentation();
-  thePrs.myPrs3D = aChannelConstructor.Get3dPresentation();
-  thePrs.myPrs2D = aChannelConstructor.Get2dPresentation();
+  /*
+  HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
+  HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
+  int aNbPoints = aPolylinePoints.Length();
+  */
 
-  thePrs.myLeftBank = aChannelConstructor.GetLeftBank();
-  thePrs.myRightBank = aChannelConstructor.GetRightBank();
-  thePrs.myInlet = aChannelConstructor.GetInlet();
-  thePrs.myOutlet = aChannelConstructor.GetOutlet();
+  HYDROData_Polyline3D::Polyline3DPoints aPolylinePoints3D = theGuideLine->GetPoints();
+  int aNbPoints = aPolylinePoints3D.Length();
+  if ( aNbPoints < 2 ) {
+    return false;
+  }
+  
+  // Get tangent in each point of the guide line ( 2D )
+  TColgp_Array1OfDir aTangents( 1, aNbPoints );
+
+  HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
+  
+  if ( aSectionType == HYDROData_IPolyline::SECTION_POLYLINE ) {
+    for ( int i = 1; i <= aNbPoints; ++i ) {
+      gp_XYZ aPnt = aPolylinePoints3D.Value( i );
+      aPnt.SetZ( 0. );
+      gp_XYZ aPrevPnt;
+      if ( i > 1 ) {
+        aPrevPnt = aPolylinePoints3D.Value( i - 1 );
+        aPrevPnt.SetZ( 0. );
+      }
+
+      gp_Vec aDir;
+      if ( i < aNbPoints ) {
+        gp_XYZ aNextPnt = aPolylinePoints3D.Value( i + 1 );
+        aNextPnt.SetZ( 0. );
+
+        gp_Vec anEdgeVec( aPnt, aNextPnt );
+
+        if ( i == 1 ) {
+          aDir = anEdgeVec;
+        } else {
+          gp_Vec aPrevVec( aPrevPnt, aPnt );
+          aDir = aPrevVec.Normalized() + anEdgeVec.Normalized();
+        }
+      } else {
+        aDir = gp_Vec( aPrevPnt, aPnt );
+      }
+            
+      aTangents.SetValue( i, aDir );
+    }
+  } else {
+    // Get curve from the first edge ( 2D )
+    TopTools_SequenceOfShape anEdges;
+    HYDROData_ShapesTool::ExploreShapeToShapes( aPolylineXY->GetShape(), TopAbs_EDGE, anEdges );
+    Standard_Real aStart, anEnd;
+
+    Handle(Geom_Curve) aCurve = BRep_Tool::Curve( TopoDS::Edge( anEdges.First() ), aStart, anEnd );
+    GeomAPI_ProjectPointOnCurve aProject;
+
+    // Get tangents
+    for ( int i = 1; i <= aNbPoints; ++i ) {
+      gp_XYZ aPointToTest = aPolylinePoints3D.Value( i );
+      aPointToTest.SetZ( 0. );
+
+      aProject.Init( aPointToTest, aCurve );
+      Quantity_Parameter aParam = aProject.LowerDistanceParameter();
+      gp_Pnt aPnt;
+      gp_Vec aDir;
+      aCurve->D1( aParam, aPnt, aDir);
+
+      aTangents.SetValue( i, aDir );
+    }
+  }
 
-#ifdef DEB_CHANNEL
-  BRepTools::Write( thePrs.myPrs2D, "channel2d.brep" );
-  BRepTools::Write( thePrs.myPrs3D, "channel3d.brep" );
-  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", thePrs.myPrs2D, TopAbs_EDGE );
-  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", thePrs.myLeftBank, TopAbs_EDGE );
-  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", thePrs.myRightBank, TopAbs_EDGE );
-  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", thePrs.myInlet, TopAbs_EDGE );
-  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", thePrs.myOutlet, TopAbs_EDGE );
-#endif
+  // Get the profile middle point ( 3D )
+  gp_Pnt aMiddlePoint( theProfile->GetMiddlePoint() );
+
+  // Translate the profile to each point on the guide line ( 3D )
+  Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aNbPoints );
+  Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aNbPoints );  
+  Handle(TopTools_HArray1OfShape) anArrOfProfiles = new TopTools_HArray1OfShape( 1, aNbPoints );
+
+  for ( int i = 1; i <= aNbPoints; ++i ) {
+    // Get point on the guide line
+    gp_Pnt aPointOnGuide( aPolylinePoints3D.Value( i ) );
+
+    // Define translation and rotation:
+    gp_Trsf Translation, Rotation;
+
+    // Translation
+    Translation.SetTranslation( aMiddlePoint, aPointOnGuide );
+    TopoDS_Wire aTransformedProfile = 
+      TopoDS::Wire( BRepBuilderAPI_Transform( aProfileWire, Translation, Standard_True ) );
+
+    // Rotation
+    gp_Vec aVertical( 0., 0., 1. );
+    TopoDS_Vertex aLeftVertex, aRightVertex;
+    TopExp::Vertices( aTransformedProfile, aLeftVertex, aRightVertex );
+    gp_Pnt aLeftPoint  = BRep_Tool::Pnt( aLeftVertex );
+    gp_Pnt aRightPoint = BRep_Tool::Pnt( aRightVertex );
+    gp_Vec aLeftToRight( aLeftPoint, aRightPoint);
+    gp_Vec NormalToProfile = aVertical ^ aLeftToRight;
+
+    gp_Vec aDir = aTangents.Value( i );
+    gp_Vec AxisOfRotation = NormalToProfile ^ aDir;
+    if (AxisOfRotation.Magnitude() <= gp::Resolution()) {
+      if ( aVertical * aLeftToRight < 0. ) {
+        gp_Ax1 theVertical(aPointOnGuide, gp::DZ() );
+        Rotation.SetRotation(theVertical, M_PI);
+      }
+    } else {
+      gp_Ax1 theAxis(aPointOnGuide, AxisOfRotation);
+      Standard_Real theAngle = NormalToProfile.AngleWithRef(aDir, AxisOfRotation);
+      Rotation.SetRotation(theAxis, theAngle);
+    }
+
+    aTransformedProfile = TopoDS::Wire(BRepBuilderAPI_Transform( aTransformedProfile, Rotation, Standard_True) );
+
+    // Get the first and the last points of the transformed profile
+    TopoDS_Vertex V1, V2;
+    TopExp::Vertices( aTransformedProfile, V1, V2 );
+
+    // Fill the data
+    anArrayOfFPnt->SetValue( i, BRep_Tool::Pnt( V1 ) );
+    anArrayOfLPnt->SetValue( i, BRep_Tool::Pnt( V2 ) );
+       
+    anArrOfProfiles->SetValue( i, aTransformedProfile );
+  }
 
-  return true;
+  // Create presentation
+  HYDROData_Stream::PrsDefinition aPrs;
+  Handle(TopTools_HArray1OfShape) anArrOf2DProfiles; // we don't need 2D profiles for channel/digue presentation
+  bool aRes = HYDROData_Stream::CreatePresentations( anArrayOfFPnt, anArrayOfLPnt,
+                                                     anArrOfProfiles, anArrOf2DProfiles, aPrs );
+  if ( aRes ) {
+    thePrs.myPrs3D = aPrs.myPrs3D;
+    thePrs.myPrs2D = TopoDS::Face( aPrs.myPrs2D );
+    BRepBuilderAPI_MakeWire aMakeWire( aPrs.myLeftBank ) ;
+    thePrs.myLeftBank = aMakeWire.Wire();
+    aMakeWire = BRepBuilderAPI_MakeWire( aPrs.myRightBank );
+    thePrs.myRightBank = aMakeWire.Wire();
+    aMakeWire = BRepBuilderAPI_MakeWire( aPrs.myInlet );
+    thePrs.myInlet = aMakeWire.Wire();
+    aMakeWire = BRepBuilderAPI_MakeWire( aPrs.myOutlet );
+    thePrs.myOutlet = aMakeWire.Wire();
+  }
+
+  return aRes;
 }
 
 void HYDROData_Channel::Update()
index dfc002f17f4bb8313d6cbb2977e0766bb9aa581a..67098e95e274235ccb83efbfa17e14121e35af3c 100644 (file)
 #include "HYDROData_PolylineXY.h"
 #include "HYDROData_Profile.h"
 #include "HYDROData_ProfileUZ.h"
+#include "HYDROData_ShapesTool.h"
 #include "HYDROData_Tool.h"
 
+#include <BRep_Tool.hxx>
+
+#include <Geom_BSplineCurve.hxx>
+
 #include <gp_Pnt2d.hxx>
 #include <gp_XY.hxx>
 #include <gp_XYZ.hxx>
 
+#include <TColStd_Array1OfReal.hxx>
+
 #include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Vertex.hxx>
 #include <TopoDS_Wire.hxx>
 
+#include <TopExp.hxx>
+
+#include <TopExp_Explorer.hxx>
+
+#include <TopTools_SequenceOfShape.hxx>
+
 #include <QColor>
 #include <QStringList>
 
@@ -421,4 +436,76 @@ void HYDROData_Polyline3D::removeChildProfileUZ()
   */
 }
 
+HYDROData_Polyline3D::Polyline3DPoints HYDROData_Polyline3D::GetPoints() const
+{
+  Polyline3DPoints aPoints;
+
+  Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
+  TopoDS_Wire aWire = TopoDS::Wire( GetShape3D() );
+  if ( aPolylineXY.IsNull() || aWire.IsNull() ) {
+    return aPoints; 
+  }
+
+  // Explode polyline on edges
+  TopTools_SequenceOfShape anEdges;
+  HYDROData_ShapesTool::ExploreShapeToShapes( aWire, TopAbs_EDGE, anEdges );
+
+  // Get points
+  if ( !anEdges.IsEmpty() ) {
+    HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
+    
+    if ( aSectionType == HYDROData_IPolyline::SECTION_POLYLINE ) {
+      // Get points from wire
+      /* Seems that intermediate vertices are duplicated
+      TopExp_Explorer anExp( aWire, TopAbs_VERTEX );
+      for ( ; anExp.More(); anExp.Next() ) {
+        TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
+        if ( !aVertex.IsNull() ) {
+          gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
+          aPoints.Append( aPnt.XYZ() );
+        }
+      }
+      */
+      TopExp_Explorer anExp( aWire, TopAbs_EDGE );
+      bool isFirst = true;
+      for ( ; anExp.More(); anExp.Next() ) {
+        TopoDS_Edge anEdge = TopoDS::Edge( anExp.Current() );
+        if ( !anEdge.IsNull() ) {
+          TopoDS_Vertex aV1, aV2;
+          TopExp::Vertices( anEdge, aV1, aV2 );
+          if ( isFirst ) {
+            gp_Pnt aPnt1 = BRep_Tool::Pnt( aV1 );
+            aPoints.Append( aPnt1.XYZ() );
+          }
+
+          gp_Pnt aPnt2 = BRep_Tool::Pnt( aV2 );
+          aPoints.Append( aPnt2.XYZ() );
+
+          isFirst = false;
+        }
+      }
+    } else {
+      // Get points from spline curve
+      Standard_Real aStart, anEnd;
+      Handle(Geom_Curve) aCurve = BRep_Tool::Curve( TopoDS::Edge( anEdges.First() ), aStart, anEnd );
+      Handle(Geom_BSplineCurve) aGeomSpline = Handle(Geom_BSplineCurve)::DownCast( aCurve );
+
+      if ( !aGeomSpline.IsNull() ) {
+        int aNbKnots = aGeomSpline->NbKnots();
+
+        TColStd_Array1OfReal aSplineKnots( 1, aNbKnots );
+        aGeomSpline->Knots( aSplineKnots );
+
+        for ( int i = 1; i <= aNbKnots; ++i ) {
+          const Standard_Real& aKnot = aSplineKnots.Value( i );
+          gp_Pnt aPnt;
+          aGeomSpline->D0( aKnot, aPnt );
+          aPoints.Append( aPnt.XYZ() );
+        }
+      }
+    }
+  }
+
+  return aPoints; 
+}
 
index 259a504773e718a38c368599a982aaf848543bcc..aa4520ff3beba6f85cbf5b0b516a9a38931fb1bf 100644 (file)
@@ -154,6 +154,11 @@ public:
    */
   HYDRODATA_EXPORT void SetChildProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile );
 
+  /**
+   * Returns list of polyline points.
+   * \return list of 3D points
+   */
+  HYDRODATA_EXPORT Polyline3DPoints GetPoints() const;
 
 protected:
 
index acec03bc92e29fc11ce8ba12797f2a41b99bdb54..ae9a70f944d8c98bbd066e73bde5da0ddb585537 100644 (file)
 #include <HYDROData_Document.h>
 #include <BRepAdaptor_Curve.hxx>
 #include <BRep_Builder.hxx>
+#include <BRep_Tool.hxx>
 #include <BRepBuilderAPI_MakeEdge2d.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
 #include <Extrema_ExtCC.hxx>
 #include <Extrema_ExtPC.hxx>
+#include <GeomAPI_Interpolate.hxx>
 #include <NCollection_Vector.hxx>
 #include <Precision.hxx>
 #include <ShapeAnalysis_TransferParametersProj.hxx>
 #include <ShapeBuild_Edge.hxx>
+#include <TColgp_Array1OfVec.hxx>
+#include <TColgp_HArray1OfPnt.hxx>
+#include <TColStd_HArray1OfBoolean.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Wire.hxx>
@@ -68,9 +74,10 @@ static TopoDS_Edge ReplaceVertex(
   return TopoDS::Edge(aNewEdge.Oriented(aOrient));
 }
 
+template<typename TCurveType>
 static Standard_Boolean WireToCurve(
   const TopoDS_Wire& theWire,
-  NCollection_Vector<TopoDS_Edge>& theEdges,
+  TCurveType& theCurve,
   Standard_Boolean& theIsClosed)
 {
   TopTools_IndexedDataMapOfShapeListOfShape aVertexToEdges;
@@ -119,7 +126,7 @@ static Standard_Boolean WireToCurve(
   {
     const TopoDS_Edge aEdge = TopoDS::Edge(aEdges->First());
     aEdges->RemoveFirst();
-    theEdges.Append(aEdge);
+    theCurve.Append(aEdge);
     Standard_Integer aVN2 =
       aVertexToEdges.FindIndex(TopExp::FirstVertex(aEdge));
     if (aVN2 == aVN)
@@ -140,17 +147,16 @@ static Standard_Boolean WireToCurve(
       aEdges->Append(aEdge);
     }
   }
-  return (!theIsClosed && theEdges.Size() == aVCount - 1) ||
-    (theIsClosed && theEdges.Size() == aVCount);
+  return (!theIsClosed && theCurve.Size() == aVCount - 1) ||
+    (theIsClosed && theCurve.Size() == aVCount);
 }
 
-static void CurveToWire(
-  const NCollection_Vector<TopoDS_Edge>& theEdges, TopoDS_Wire& theWire)
+template<typename TCurveType>
+static void CurveToWire(const TCurveType& theCurve, TopoDS_Wire& theWire)
 {
   BRep_Builder aBulder;
   aBulder.MakeWire(theWire);
-  NCollection_Vector<TopoDS_Edge>::Iterator aEIt(theEdges);
-  for (; aEIt.More(); aEIt.Next())
+  for (typename TCurveType::Iterator aEIt(theCurve); aEIt.More(); aEIt.Next())
   {
     aBulder.Add(theWire, aEIt.Value());
   }
@@ -470,6 +476,262 @@ static Standard_Integer IntersectCurve(
   return aIntCount;
 }
 
+static void CloseCurve(NCollection_Sequence<TopoDS_Edge>& theCurve)
+{
+  const TopoDS_Vertex aVertex = TopoDS::Vertex(TopExp::LastVertex(
+    theCurve.Last(), Standard_True).Oriented(TopAbs_FORWARD));
+  const TopoDS_Edge& aEdge = theCurve.First();
+  const TopoDS_Edge aForwardEdge = TopoDS::Edge(aEdge.Oriented(TopAbs_FORWARD));
+  theCurve.ChangeFirst() = TopoDS::Edge(ShapeBuild_Edge().CopyReplaceVertices(
+    aForwardEdge, aVertex, TopoDS_Vertex()).Oriented(aEdge.Orientation()));
+}
+
+static Standard_Boolean IsClosed(
+  const NCollection_Sequence<TopoDS_Edge>& theCurve)
+{
+  return TopExp::FirstVertex(theCurve.First(), Standard_True).
+    IsSame(TopExp::LastVertex(theCurve.Last(), Standard_True));
+}
+
+static void ExtendCurve(
+  const Standard_Integer thePosition,
+  NCollection_Sequence<TopoDS_Edge>& theCurve,
+  NCollection_Sequence<TopoDS_Edge>& theExtension)
+{
+  if (thePosition == 0)
+  {
+    const TopoDS_Vertex aVertex = TopoDS::Vertex(TopExp::LastVertex(
+      theExtension.Last(), Standard_True).Oriented(TopAbs_FORWARD));
+    TopoDS_Edge& aEdge = theCurve.ChangeFirst();
+    aEdge = TopoDS::Edge(ShapeBuild_Edge().CopyReplaceVertices(
+        TopoDS::Edge(aEdge.Oriented(TopAbs_FORWARD)), aVertex, TopoDS_Vertex()).
+      Oriented(aEdge.Orientation()));
+    theCurve.Prepend(theExtension);
+  }
+  else
+  {
+    const TopoDS_Vertex aVertex = TopoDS::Vertex(TopExp::FirstVertex(
+      theExtension.First(), Standard_True).Oriented(TopAbs_REVERSED));
+    TopoDS_Edge& aEdge = theCurve.ChangeLast();
+    aEdge = TopoDS::Edge(ShapeBuild_Edge().CopyReplaceVertices(
+        TopoDS::Edge(aEdge.Oriented(TopAbs_FORWARD)), TopoDS_Vertex(), aVertex).
+      Oriented(aEdge.Orientation()));
+    theCurve.Append(theExtension);
+  }
+}
+
+static void ExtendCurve(
+  const Standard_Integer thePosition,
+  const TopoDS_Edge& theExtension,
+  NCollection_Sequence<TopoDS_Edge>& theCurve)
+{
+  NCollection_Sequence<TopoDS_Edge> aExtension;
+  aExtension.Append(theExtension);
+  ExtendCurve(thePosition, theCurve, aExtension);
+}
+
+static gp_XYZ Tangent(
+  const Adaptor3d_Curve& theCurve, const Standard_Integer thePosition)
+{
+  const Standard_Real aParam = (thePosition == 0) ?
+    theCurve.FirstParameter() : theCurve.LastParameter();
+  gp_Pnt aP;
+  gp_Vec aV;
+  theCurve.D1(aParam, aP, aV);
+  Standard_Real aNorm = aV.Magnitude();
+  aNorm = (aNorm >= Precision::PConfusion()) ? aNorm : 0;
+  return ((1 / aNorm) * aV).XYZ();
+}
+
+static gp_XYZ Tangent(
+  const TopoDS_Edge& theEdge, const Standard_Integer thePosition)
+{
+  BRepAdaptor_Curve aCurve(theEdge);
+  return Tangent(BRepAdaptor_Curve(theEdge), thePosition);
+}
+
+static Standard_Boolean Interpolate(
+  const gp_Pnt thePoint1,
+  const gp_Pnt thePoint2,
+  const gp_Vec theTangent1,
+  const gp_Vec theTangent2,
+  Handle(Geom_BSplineCurve)& theBSpline)
+{
+  Handle(TColgp_HArray1OfPnt) aPs = new TColgp_HArray1OfPnt(1, 2);
+  TColgp_Array1OfVec aTs(1, 2);
+  Handle(TColStd_HArray1OfBoolean) aTFs = new TColStd_HArray1OfBoolean(1, 2);
+  aPs->SetValue(1, thePoint1);
+  aPs->SetValue(2, thePoint2);
+  aTs.SetValue(1, theTangent1);
+  aTs.SetValue(2, theTangent2);
+  aTFs->SetValue(1, Standard_True);
+  aTFs->SetValue(2, Standard_True);
+  GeomAPI_Interpolate aInterpolator(aPs, Standard_False, 0);
+  aInterpolator.Load(aTs, aTFs, Standard_False);
+  aInterpolator.Perform();
+  const Standard_Boolean aResult = (aInterpolator.IsDone() == Standard_True);
+  if (aResult)
+  {
+    theBSpline = aInterpolator.Curve();
+  }
+  return aResult;
+}
+
+static Standard_Boolean Merge(
+  const TopoDS_Wire& theWire,
+  const Standard_Real theTolerance,
+  NCollection_Vector<NCollection_Sequence<TopoDS_Edge> >& theMergedCurves)
+{
+  NCollection_Sequence<TopoDS_Edge> aCurve;
+  Standard_Boolean isClosed;
+  if (!WireToCurve(theWire, aCurve, isClosed))
+  {
+    return Standard_False;
+  }
+
+  if (isClosed)
+  {
+    theMergedCurves.Append(aCurve);
+    return Standard_True;
+  }
+
+  const Standard_Real aSqTol = theTolerance * theTolerance;
+  const gp_Pnt aPs[] = {
+    BRep_Tool::Pnt(TopExp::FirstVertex(aCurve.First(), Standard_True)),
+    BRep_Tool::Pnt(TopExp::LastVertex(aCurve.Last(), Standard_True))};
+  if (!isClosed && aPs[0].SquareDistance(aPs[1]) <= aSqTol)
+  {
+    CloseCurve(aCurve);
+    theMergedCurves.Append(aCurve);
+    return Standard_True;
+  }
+
+  NCollection_Sequence<TopoDS_Edge>* aCurves[] = {NULL, NULL};
+  Standard_Integer aOrder = 0;
+  for (NCollection_Vector<NCollection_Sequence<TopoDS_Edge> >::Iterator
+    aCIt(theMergedCurves); aCIt.More(); aCIt.Next())
+  {
+    NCollection_Sequence<TopoDS_Edge>& aC = aCIt.ChangeValue();
+    if (aC.IsEmpty() || IsClosed(aC))
+    {
+      continue;
+    }
+
+    const gp_Pnt aP1 =
+      BRep_Tool::Pnt(TopExp::FirstVertex(aC.First(), Standard_True));
+    if (aCurves[0] == NULL && aP1.SquareDistance(aPs[1]) <= aSqTol)
+    {
+      aCurves[0] = &aC;
+    }
+
+    const gp_Pnt aP2 =
+      BRep_Tool::Pnt(TopExp::LastVertex(aC.Last(), Standard_True));
+    if (aCurves[1] == NULL && aP2.SquareDistance(aPs[0]) <= aSqTol)
+    {
+      aCurves[1] = &aC;
+      aOrder = (aCurves[0] == NULL) ? 1 : 0;
+    }
+  }
+
+  if (aCurves[0] == NULL && aCurves[1] == NULL)
+  {
+    theMergedCurves.Append(aCurve);
+  }
+  else if (aCurves[1] == NULL)
+  {
+    ExtendCurve(0, *aCurves[0], aCurve);
+  }
+  else if (aCurves[0] == NULL)
+  {
+    ExtendCurve(1, *aCurves[1], aCurve);
+  }
+  else
+  {
+    ExtendCurve(aOrder, *aCurves[aOrder], aCurve);
+    if (aCurves[0] != aCurves[1])
+    {
+      ExtendCurve(aOrder, *aCurves[aOrder], *aCurves[1 - aOrder]);
+    }
+    else
+    {
+      CloseCurve(*aCurves[aOrder]);
+    }
+  }
+  return Standard_True;
+}
+
+static Standard_Boolean Connect(
+  const TopoDS_Wire& theWire,
+  const Standard_Real theTolerance,
+  NCollection_Vector<NCollection_Sequence<TopoDS_Edge> >& theMergedCurves)
+{
+  NCollection_Sequence<TopoDS_Edge> aCurve;
+  Standard_Boolean isClosed;
+  if (!WireToCurve(theWire, aCurve, isClosed))
+  {
+    return Standard_False;
+  }
+
+  if (isClosed)
+  {
+    theMergedCurves.Append(aCurve);
+    return Standard_True;
+  }
+
+  const Standard_Real aSqTol = theTolerance * theTolerance;
+  const gp_Pnt aPs[] = {
+    BRep_Tool::Pnt(TopExp::FirstVertex(aCurve.First(), Standard_True)),
+    BRep_Tool::Pnt(TopExp::LastVertex(aCurve.Last(), Standard_True))};
+  if (!isClosed && aPs[0].SquareDistance(aPs[1]) <= aSqTol)
+  {
+    CloseCurve(aCurve);
+    theMergedCurves.Append(aCurve);
+    return Standard_True;
+  }
+
+  for (NCollection_Vector<NCollection_Sequence<TopoDS_Edge> >::Iterator
+    aCIt(theMergedCurves); aCIt.More(); aCIt.Next())
+  {
+    NCollection_Sequence<TopoDS_Edge>& aCurve2 = aCIt.ChangeValue();
+    if (aCurve2.IsEmpty() || IsClosed(aCurve2))
+    {
+      continue;
+    }
+
+    const TopoDS_Edge* aEdges2[] = {&aCurve2.First(), &aCurve2.Last()};
+    const gp_Pnt aPs2[] = {
+      BRep_Tool::Pnt(TopExp::FirstVertex(*aEdges2[0], Standard_True)),
+      BRep_Tool::Pnt(TopExp::LastVertex(*aEdges2[1], Standard_True))};
+    const Standard_Real aSqDists[] =
+      {aPs2[0].SquareDistance(aPs[1]), aPs2[1].SquareDistance(aPs[0])};
+    const Standard_Integer aOrder = (aSqDists[0] <= aSqDists[1]) ? 0 : 1;
+    if (aSqDists[aOrder] > aSqTol)
+    {
+      const TopoDS_Edge& aEdge = (aOrder == 0) ? aCurve.Last() : aCurve.First();
+      const gp_Pnt aPs3[] = {aPs[1 - aOrder], aPs2[aOrder]};
+      const gp_XYZ aTs[] =
+        {Tangent(aEdge, 1 - aOrder), Tangent(*aEdges2[aOrder], aOrder)};
+      Handle(Geom_BSplineCurve) aBSpline;
+      if (!Interpolate(aPs3[aOrder], aPs3[1 - aOrder],
+        aTs[aOrder], aTs[1 - aOrder], aBSpline))
+      {
+        return Standard_False;
+      }
+
+      ExtendCurve(aOrder, BRepBuilderAPI_MakeEdge(aBSpline), aCurve2);
+    }
+    ExtendCurve(aOrder, aCurve2, aCurve);
+    if (aSqDists[1 - aOrder] <= aSqTol)
+    {
+      CloseCurve(aCurve2);
+    }
+    return Standard_True;
+  }
+
+  theMergedCurves.Append(aCurve);
+  return Standard_True;
+}
+
 bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
                                         const Handle( HYDROData_PolylineXY )& thePolyline,
                                         const gp_Pnt2d& thePoint,
@@ -518,29 +780,43 @@ bool HYDROData_PolylineOperator::Merge( const Handle( HYDROData_Document )& theD
                                         bool isConnectByNewSegment,
                                         double theTolerance )
 {
-  TopoDS_Shape aMergedPolyline;
-
-  int f = thePolylines.Lower(), l = thePolylines.Upper();
-  for( int i=f; i<=l; i++ )
+  NCollection_Vector<NCollection_Sequence<TopoDS_Edge> > aMergedCurves;
+  HYDROData_SequenceOfObjects::Iterator aPIt(thePolylines);
+  for (; aPIt.More(); aPIt.Next())
   {
-    Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( thePolylines.Value( i ) );
-    std::vector<TopoDS_Wire> aCurves = GetWires( aPolyline );
-    for( int j=0, m=aCurves.size(); j<m; j++ )
-      if( !Merge( aMergedPolyline, aCurves[j], isConnectByNewSegment, theTolerance ) )
+    Handle(HYDROData_PolylineXY) aPolyline =
+      Handle(HYDROData_PolylineXY)::DownCast(aPIt.Value());
+    std::vector<TopoDS_Wire> aWires = GetWires(aPolyline);
+    for (std::vector<TopoDS_Wire>::const_iterator aWIt = aWires.begin(),
+      aLastWIt = aWires.end(); aWIt != aLastWIt; ++aWIt)
+    {
+      const Standard_Boolean aResult = !isConnectByNewSegment ?
+        ::Merge(*aWIt, theTolerance, aMergedCurves) :
+        Connect(*aWIt, theTolerance, aMergedCurves);
+      if (!aResult)
+      {
         return false;
+      }
+    }
   }
 
-  std::vector<TopoDS_Shape> aShapes( 1 );
-  aShapes[0] = aMergedPolyline;
-  CreatePolylines( theDoc, theName, aShapes, false );
-
-  return true;
-}
+  TopoDS_Compound aWireSet;
+  BRep_Builder aBuilder;
+  aBuilder.MakeCompound(aWireSet);
+  for (NCollection_Vector<NCollection_Sequence<TopoDS_Edge> >::Iterator
+    aCIt(aMergedCurves); aCIt.More(); aCIt.Next())
+  {
+    if (!aCIt.Value().IsEmpty())
+    {
+      TopoDS_Wire aWire;
+      CurveToWire(aCIt.Value(), aWire);
+      aBuilder.Add(aWireSet, aWire);
+    }
+  }
 
-bool HYDROData_PolylineOperator::Merge( TopoDS_Shape& theShape, const TopoDS_Wire& theWire, 
-                                        bool isConnectByNewSegment, double theTolerance )
-{
-  //TODO
+  std::vector<TopoDS_Shape> aPolylines(1);
+  aPolylines[0] = aWireSet;
+  CreatePolylines(theDoc, theName, aPolylines, false);
   return true;
 }
 
@@ -573,7 +849,7 @@ bool HYDROData_PolylineOperator::split( const Handle( HYDROData_Document )& theD
     }
 
     NCollection_Vector<NCollection_Sequence<Standard_Real> > aParams;
-    aParams.SetValue(aPSCount - 1, NCollection_Sequence<Standard_Real>());
+    aParams.SetValue(aCurve.Size() - 1, NCollection_Sequence<Standard_Real>());
     for (int aTSI = 0; aTSI < aTSCount; ++aTSI)
     {
       IntersectCurve(aCurve, aToolCurves[aTSI], aParams);
@@ -715,32 +991,6 @@ std::vector<TopoDS_Shape> HYDROData_PolylineOperator::Split( const TopoDS_Wire&
   return aResult;
 }
 
-std::vector<TopoDS_Shape> HYDROData_PolylineOperator::Split( const TopoDS_Wire& theWire,
-                                                             const TopoDS_Wire& theTool,
-                                                             double theTolerance )
-{
-  std::vector<TopoDS_Shape> aResult;
-  NCollection_Vector<TopoDS_Edge> aWEdges, aTEdges;
-  Standard_Boolean aIsWClosed, aIsTClosed;
-  if (!WireToCurve(theWire, aWEdges, aIsWClosed) ||
-    !WireToCurve(theTool, aTEdges, aIsTClosed))
-  {
-    return aResult;
-  }
-
-
-  //TODO
-  return aResult;
-}
-
-std::vector<TopoDS_Shape> HYDROData_PolylineOperator::Split( const std::vector<TopoDS_Wire>& theWires,
-                                                             double theTolerance )
-{
-  std::vector<TopoDS_Shape> aResult;
-  //TODO
-  return aResult;
-}
-
 bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc,
                                                   const QString& theNamePrefix,
                                                   const std::vector<TopoDS_Shape>& theShapes,
index 3f92f0befff43394b0cdf9c4223241bcbdac71f7..0b0fdceeba7e2220c21eb097dbcb4f26a5723c48 100644 (file)
@@ -58,14 +58,6 @@ protected:
   static std::vector<TopoDS_Shape> Split( const TopoDS_Wire& theWire,
                                           const gp_Pnt2d& thePoint,
                                           double theTolerance );
-  static std::vector<TopoDS_Shape> Split( const TopoDS_Wire& theWire,
-                                          const TopoDS_Wire& theTool,
-                                          double theTolerance );
-  static std::vector<TopoDS_Shape> Split( const std::vector<TopoDS_Wire>& theWires,
-                                          double theTolerance );
-
-  static bool Merge( TopoDS_Shape& theShape, const TopoDS_Wire& theWire, 
-                     bool isConnectByNewSegment, double theTolerance );
 
   static bool CreatePolylines( const Handle( HYDROData_Document )& theDoc,
                                const QString& theNamePrefix,
index 6fbfd97a90ddce334d6147278c4c26107294f785..cef87e2f953fe4c6a4f926879e782b84c3ea5887 100755 (executable)
 #include <BRepBuilderAPI_MakeWire.hxx>
 #include <BRepBuilderAPI_MakePolygon.hxx>
 
+#include <BRepExtrema_ExtCC.hxx>
+
+#include <BRep_Tool.hxx>
+
+#include <gp_Lin.hxx>
 #include <gp_XY.hxx>
 #include <gp_XYZ.hxx>
 #include <gp_Pnt2d.hxx>
 #include <TDataStd_AsciiString.hxx>
 #include <TDataStd_RealArray.hxx>
 
+#include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Wire.hxx>
+#include <TopoDS_Iterator.hxx>
 
 #include <OSD_File.hxx>
 #include <OSD_Protection.hxx>
@@ -748,3 +755,40 @@ HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint() const
   return aBottom;
 }
 
+ HYDROData_Profile::ProfilePoint HYDROData_Profile::GetMiddlePoint() const
+ {
+   ProfilePoint aMiddlePoint;
+  
+   gp_XY aLeftPnt, aRightPnt;
+   if ( GetLeftPoint( aLeftPnt, false ) && GetRightPoint( aRightPnt, false ) ) {
+     gp_XYZ aPnt1( aLeftPnt.X(), aLeftPnt.Y(), 0. );
+     gp_XYZ aPnt2( aRightPnt.X(), aRightPnt.Y(), 0. );
+     gp_Pnt aMiddlePoint2d( 0.5 * ( aPnt1 + aPnt2 ) ); 
+
+     gp_Lin aMidLin( aMiddlePoint2d, gp::DZ() );
+     TopoDS_Edge aMidEdge = BRepLib_MakeEdge( aMidLin );
+
+     TopoDS_Iterator anIt( TopoDS::Wire( GetShape3D() )  );
+     for ( ; anIt.More(); anIt.Next()) {
+       const TopoDS_Edge& anEdge = TopoDS::Edge( anIt.Value() );
+
+       /*
+       Standard_Real aStart, anEnd;
+       Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aStart, anEnd );
+       gp_Pnt aMiddlePointOnCurve = aCurve->Value( ( aStart + anEnd ) / 2 );
+       */
+
+       BRepExtrema_ExtCC ExtremaEE( aMidEdge, anEdge);
+       if (ExtremaEE.IsDone() && ExtremaEE.NbExt() != 0) {
+         for ( Standard_Integer i = 1; i <= ExtremaEE.NbExt(); i++ ) {
+           if ( ExtremaEE.SquareDistance(i) <= Precision::Confusion() ) {
+             aMiddlePoint = ExtremaEE.PointOnE1(i).XYZ();
+             break;
+           }
+         }
+       }
+     }
+   }
+
+   return aMiddlePoint;
+ }
\ No newline at end of file
index 0c3ab048806a7d44faf646a30638f71d69c9ef64..fb7edcd7e6cb537e2e842319208e149531468b98 100644 (file)
@@ -196,6 +196,12 @@ public:
    */
   HYDRODATA_EXPORT ProfilePoint GetBottomPoint() const;
 
+  /**
+   * Return profile middle point.
+   * \return non-parametric profile point
+   */
+  HYDRODATA_EXPORT ProfilePoint GetMiddlePoint() const;
+
 public:
   // Public methods to work with files.
 
index e9da1296964a7c1b7a99ba8d5be4df0784f08035..42a62b5771f92a31f0ccbe1475d0e29404041127 100644 (file)
@@ -73,7 +73,7 @@
 #include <GeomAPI_Interpolate.hxx>
 #include <Geom_BSplineCurve.hxx>
 
-#include <TopTools_Array1OfShape.hxx>
+#include <TopTools_HArray1OfShape.hxx>
 
 #include <SortTools_QuickSortOfReal.hxx>
 
@@ -197,11 +197,10 @@ bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_PolylineXY)&
   if ( theHydAxis.IsNull() || theProfiles.Length() < 2 )
     return false;
 
-  gp_Pnt aPrevFirstPoint, aPrevLastPoint;
   Handle(TColgp_HArray1OfPnt) anArrayOfFPnt    = new TColgp_HArray1OfPnt(1, theProfiles.Length());
   Handle(TColgp_HArray1OfPnt) anArrayOfLPnt    = new TColgp_HArray1OfPnt(1, theProfiles.Length());  
-  TopTools_Array1OfShape anArrOfProfiles(1, theProfiles.Length());
-  TopTools_Array1OfShape anArrOf2DProfiles(1, theProfiles.Length());
+  Handle(TopTools_HArray1OfShape) anArrOfProfiles = new TopTools_HArray1OfShape(1, theProfiles.Length());
+  Handle(TopTools_HArray1OfShape) anArrOf2DProfiles = new TopTools_HArray1OfShape(1, theProfiles.Length());
 
   // Pre-processing
   HYDROData_SequenceOfObjects::Iterator anIter( theProfiles );
@@ -217,11 +216,10 @@ bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_PolylineXY)&
     if ( !aProfile->GetLeftPoint( aPnt1, false ) || !aProfile->GetRightPoint( aPnt2, false ) )
       continue;
 
-    anArrOfProfiles.SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
-    anArrOf2DProfiles.SetValue(i,aProfile->GetTopShape());
+    anArrOfProfiles->SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
+    anArrOf2DProfiles->SetValue(i,aProfile->GetTopShape());
 
-    gp_Pnt aCurFirstPoint( aPnt1.X(), aPnt1.Y(), 0 ), aCurFP;
-    gp_Pnt aCurLastPoint(  aPnt2.X(), aPnt2.Y(), 0 ), aCurLP;
+    gp_Pnt aCurFP, aCurLP;
     TopoDS_Vertex aV1, aV2;
     TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2);
        gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
@@ -238,132 +236,7 @@ bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_PolylineXY)&
     anArrayOfLPnt->SetValue(i,aCurLP);
   }
 
-  // Construct of the 3D presentation
-  Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (anArrayOfFPnt);
-  if(aBSpline.IsNull())
-    return false;
-
-  TopoDS_Edge anEdgLeft, anEdgRight;
-  
-  BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
-  if(aMakeEdge.IsDone()) 
-    anEdgLeft = aMakeEdge.Edge();
-
-  if(anEdgLeft.IsNull())
-    return false;
-
-  aBSpline.Nullify();
-  aBSpline = buildInterpolationCurve (anArrayOfLPnt);  
-  if(aBSpline.IsNull())
-    return false;
-
-  aMakeEdge.Init(aBSpline);
-  if(aMakeEdge.IsDone()) 
-    anEdgRight = aMakeEdge.Edge();
-
-  if(anEdgRight.IsNull())
-    return false;
-
-  BRep_Builder aBB;
-  TopoDS_Compound aCmp;
-  aBB.MakeCompound(aCmp);
-  anIter.Init( theProfiles );
-  for (int i=1 ; i < anArrOfProfiles.Length() +1; i++ )  
-    aBB.Add(aCmp, anArrOfProfiles.Value(i));
-
-  aBB.Add(aCmp,anEdgLeft);
-  aBB.Add(aCmp,anEdgRight);
-  BRepCheck_Analyzer aCh(aCmp);
-  if(aCh.IsValid())
-    thePrs.myPrs3D = aCmp;
-#ifdef DEB_UPDATE
-  else {
-    BRepTools::Write(aCmp, "str3d.brep");
-    thePrs.myPrs3D = aCmp;
-  }
-#endif
-
-  // Construct the top presentation
-  for(int i=1;i<= anArrayOfLPnt->Length();i++) {
-      gp_Pnt aPnt = anArrayOfFPnt->Value(i);
-      aPnt.SetZ(.0); // make 2d
-      anArrayOfFPnt->SetValue(i, aPnt);
-      aPnt = anArrayOfLPnt->Value(i);
-      aPnt.SetZ(.0);
-      anArrayOfLPnt->SetValue(i, aPnt);
-  }
-
-  aBSpline.Nullify();
-  aBSpline = buildInterpolationCurve (anArrayOfFPnt);  
-  if(aBSpline.IsNull())
-    return false; 
-
-  aMakeEdge.Init(aBSpline);
-  if(aMakeEdge.IsDone()) 
-      anEdgLeft = aMakeEdge.Edge();
-
-  aBSpline.Nullify();
-  aBSpline = buildInterpolationCurve (anArrayOfLPnt);  
-  if(aBSpline.IsNull())
-    return false; 
-
-  aMakeEdge.Init(aBSpline);
-  if(aMakeEdge.IsDone()) 
-    anEdgRight = aMakeEdge.Edge();
-  if(anEdgRight.IsNull())
-    return false;
-
-  BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
-  TopoDS_Edge aBotEdge, aTopEdge;
-  if(aMakeEdge2.IsDone()) 
-    aBotEdge = aMakeEdge2.Edge();
-
-  BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
-  if(aMakeEdge3.IsDone()) 
-    aTopEdge = aMakeEdge3.Edge();
-
-  // Make wire for 2D presentation with updating of corresponding edges
-  BRepBuilderAPI_MakeWire aMakeWire;
-  
-  aMakeWire.Add( aBotEdge );
-  thePrs.myInlet = aMakeWire.Edge();
-
-  aMakeWire.Add( anEdgLeft );
-  thePrs.myLeftBank = aMakeWire.Edge();
-
-  aMakeWire.Add( aTopEdge );
-  thePrs.myOutlet = aMakeWire.Edge();
-
-  aMakeWire.Add( anEdgRight );
-  thePrs.myRightBank = aMakeWire.Edge();
-
-  TopoDS_Wire aSectProfileWire;
-  if(aMakeWire.IsDone())
-    aSectProfileWire = aMakeWire.Wire();
-
-  BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
-  TopoDS_Face aFace;
-  aMakeFace.Build();
-  if( aMakeFace.IsDone() )
-    aFace = aMakeFace.Face();
-
-  aCmp.Nullify();
-  aBB.MakeCompound(aCmp);
-  aBB.Add(aCmp,aFace);
-  for(int i=1;i <= anArrOf2DProfiles.Length(); i++)
-    aBB.Add(aCmp,anArrOf2DProfiles.Value(i));
-
-  aCh.Init(aCmp);
-  if(aCh.IsValid())
-   thePrs.myPrs2D = aCmp;
-#ifdef DEB_UPDATE
-  else {
-    BRepTools::Write(aCmp, "str2d.brep");
-    thePrs.myPrs2D = aCmp;
-  }
-#endif
-
-  return true;
+  return CreatePresentations( anArrayOfFPnt, anArrayOfLPnt, anArrOfProfiles, anArrOf2DProfiles, thePrs );
 }
 
 void HYDROData_Stream::UpdatePrs()
@@ -1182,4 +1055,156 @@ void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination )
       }
     }
   }
+}
+
+bool HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt)     theArrayOfFPnt,
+                                            const Handle(TColgp_HArray1OfPnt)     theArrayOfLPnt,
+                                            const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
+                                            const Handle(TopTools_HArray1OfShape) theArrOf2DProfiles,
+                                            PrsDefinition&                        thePrs )
+{
+  if ( theArrayOfFPnt.IsNull() || theArrayOfLPnt.IsNull() || theArrOfProfiles.IsNull() ) {
+    return false;
+  }
+
+  if ( theArrayOfFPnt->Length() != theArrayOfLPnt->Length() ) {
+    return false;
+  }
+  
+  // Construct of the 3D presentation
+  Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (theArrayOfFPnt);
+  if(aBSpline.IsNull())
+    return false;
+
+  TopoDS_Edge anEdgLeft, anEdgRight;
+  
+  BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
+  if(aMakeEdge.IsDone()) 
+    anEdgLeft = aMakeEdge.Edge();
+
+  if(anEdgLeft.IsNull())
+    return false;
+
+  aBSpline.Nullify();
+  aBSpline = buildInterpolationCurve (theArrayOfLPnt);  
+  if(aBSpline.IsNull())
+    return false;
+
+  aMakeEdge.Init(aBSpline);
+  if(aMakeEdge.IsDone()) 
+    anEdgRight = aMakeEdge.Edge();
+
+  if(anEdgRight.IsNull())
+    return false;
+
+  BRep_Builder aBB;
+  TopoDS_Compound aCmp;
+  aBB.MakeCompound(aCmp);
+  for (int i=1 ; i < theArrOfProfiles->Length() +1; i++ )  
+    aBB.Add(aCmp, theArrOfProfiles->Value(i));
+
+  aBB.Add(aCmp,anEdgLeft);
+  aBB.Add(aCmp,anEdgRight);
+  BRepCheck_Analyzer aCh(aCmp);
+  if(aCh.IsValid())
+    thePrs.myPrs3D = aCmp;
+#ifdef DEB_UPDATE
+  else {
+    BRepTools::Write(aCmp, "str3d.brep");
+    thePrs.myPrs3D = aCmp;
+  }
+#endif
+
+  // Construct the top presentation
+  int aNbPoints = theArrayOfFPnt->Length();
+  Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aNbPoints);
+  Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aNbPoints);  
+  for( int i=1; i <= aNbPoints; i++ ) {
+      gp_Pnt aPnt = theArrayOfFPnt->Value(i);
+      aPnt.SetZ(.0); // make 2d
+      anArrayOfFPnt->SetValue(i, aPnt);
+      aPnt = theArrayOfLPnt->Value(i);
+      aPnt.SetZ(.0);
+      anArrayOfLPnt->SetValue(i, aPnt);
+  }
+
+  aBSpline.Nullify();
+  aBSpline = buildInterpolationCurve (anArrayOfFPnt);  
+  if(aBSpline.IsNull())
+    return false; 
+
+  aMakeEdge.Init(aBSpline);
+  if(aMakeEdge.IsDone()) 
+      anEdgLeft = aMakeEdge.Edge();
+
+  aBSpline.Nullify();
+  aBSpline = buildInterpolationCurve (anArrayOfLPnt);  
+  if(aBSpline.IsNull())
+    return false; 
+
+  aMakeEdge.Init(aBSpline);
+  if(aMakeEdge.IsDone()) 
+    anEdgRight = aMakeEdge.Edge();
+  if(anEdgRight.IsNull())
+    return false;
+
+  BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
+  TopoDS_Edge aBotEdge, aTopEdge;
+  if(aMakeEdge2.IsDone()) 
+    aBotEdge = aMakeEdge2.Edge();
+
+  BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
+  if(aMakeEdge3.IsDone()) 
+    aTopEdge = aMakeEdge3.Edge();
+
+  // Make wire for 2D presentation with updating of corresponding edges
+  BRepBuilderAPI_MakeWire aMakeWire;
+  
+  aMakeWire.Add( aBotEdge );
+  thePrs.myInlet = aMakeWire.Edge();
+
+  aMakeWire.Add( anEdgLeft );
+  thePrs.myLeftBank = aMakeWire.Edge();
+
+  aMakeWire.Add( aTopEdge );
+  thePrs.myOutlet = aMakeWire.Edge();
+
+  aMakeWire.Add( anEdgRight );
+  thePrs.myRightBank = aMakeWire.Edge();
+
+  TopoDS_Wire aSectProfileWire;
+  if(aMakeWire.IsDone())
+    aSectProfileWire = aMakeWire.Wire();
+
+  BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
+  TopoDS_Face aFace;
+  aMakeFace.Build();
+  if( aMakeFace.IsDone() )
+    aFace = aMakeFace.Face();
+
+  TopoDS_Shape aPrs2D;
+
+  if ( !theArrOf2DProfiles.IsNull() ) {
+    aCmp.Nullify();
+    aBB.MakeCompound(aCmp);
+    aBB.Add(aCmp,aFace);
+    for(int i=1;i <= theArrOf2DProfiles->Length(); i++)
+      aBB.Add(aCmp, theArrOf2DProfiles->Value(i));
+
+    aPrs2D = aCmp;
+  } else {
+    aPrs2D = aFace;
+  }
+
+  aCh.Init(aPrs2D);
+  if(aCh.IsValid())
+   thePrs.myPrs2D = aPrs2D;
+#ifdef DEB_UPDATE
+  else {
+    BRepTools::Write(aPrs2D, "str2d.brep");
+    thePrs.myPrs2D = aPrs2D;
+  }
+#endif
+
+  return true;
 }
\ No newline at end of file
index 16d76503ebd1539b327ffcc0d4a335c4e4d3c837..6ebf6427e19a4bfba0df279a5f31bb499196ba01 100644 (file)
@@ -33,6 +33,7 @@ class Handle(HYDROData_Polyline3D);
 class Handle(HYDROData_Profile);
 class HYDROData_IProfilesInterpolator;
 class TColStd_Array1OfReal;
+class Handle(TopTools_HArray1OfShape);
 
 
 /**\class HYDROData_Stream
@@ -79,6 +80,16 @@ public:
                                                     const HYDROData_SequenceOfObjects&  theProfiles,
                                                     PrsDefinition&                      thePrs );
 
+  /**
+   * Creates the presentations(2D and 3D) by given first points, last points and profiles.
+   * If 2D profiles is null - they will not used in the presentation.
+   */
+  HYDRODATA_EXPORT static bool CreatePresentations( const Handle(TColgp_HArray1OfPnt)     theArrayOfFPnt,
+                                                    const Handle(TColgp_HArray1OfPnt)     theArrayOfLPnt,
+                                                    const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
+                                                    const Handle(TopTools_HArray1OfShape) theArrOf2DProfiles,
+                                                    PrsDefinition&                        thePrs );
+
 public:
 
   /**