]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
new implementation for channels creation
authorasl <asl@opencascade.com>
Thu, 26 Dec 2013 04:39:20 +0000 (04:39 +0000)
committerasl <asl@opencascade.com>
Thu, 26 Dec 2013 04:39:20 +0000 (04:39 +0000)
src/HYDROData/CMakeLists.txt
src/HYDROData/HYDROData_Channel.cxx
src/HYDROData/HYDROData_Pipes.cxx [new file with mode: 0644]
src/HYDROData/HYDROData_Pipes.h [new file with mode: 0644]

index 10aeff0e724fbc36dc7c76432a4c519c5a2d7349..4ef25b8b9f1d86e8e9fa56078bb8b723b7c181ab 100644 (file)
@@ -25,6 +25,7 @@ set(PROJECT_HEADERS
     HYDROData_Obstacle.h
     HYDROData_ObstacleAltitude.h
     HYDROData_OperationsFactory.h
+    HYDROData_Pipes.h
     HYDROData_PolylineXY.h
     HYDROData_Polyline3D.h
     HYDROData_Profile.h
@@ -67,6 +68,7 @@ set(PROJECT_SOURCES
     HYDROData_Obstacle.cxx
     HYDROData_ObstacleAltitude.cxx
     HYDROData_OperationsFactory.cxx
+    HYDROData_Pipes.cxx
     HYDROData_PolylineXY.cxx
     HYDROData_Polyline3D.cxx
     HYDROData_Profile.cxx
index 9499aea834fd372eb43cfc4eaea9cfdbc9185d4b..15335a698575ddce2de2a7221b9660311b9f80bc 100644 (file)
@@ -8,10 +8,12 @@
 #include "HYDROData_Projection.h"
 #include "HYDROData_ShapesGroup.h"
 #include "HYDROData_ShapesTool.h"
+#include "HYDROData_Pipes.h"
 
 #include <BRepOffsetAPI_MakePipeShell.hxx>
 #include <BRepOffsetAPI_MakePipe.hxx>
 #include <BRepCheck_Analyzer.hxx>
+#include <BRepTools.hxx>
 
 #include <TopExp.hxx>
 
@@ -107,67 +109,17 @@ void HYDROData_Channel::Update()
   if(aProfileWire.IsNull())
     return;
 
-  BRepOffsetAPI_MakePipeShell aMkSweep(aPathWire);
-  aMkSweep.Add(aProfileWire,Standard_True, Standard_True);
-  aMkSweep.SetTransitionMode(BRepBuilderAPI_RightCorner);
-  //aMkSweep.SetMode(Standard_True);
-  aMkSweep.Build();
-  if(aMkSweep.IsDone()) {
-    const TopoDS_Shape& aChannel = aMkSweep.Shape();
-    BRepCheck_Analyzer aCheck(aChannel);
-    if(aCheck.IsValid()) 
-    {
-      //BRepTools::Write(aChannel, "ChanV.brep");  
-      SetShape3D( aMkSweep.Shape());
-    } else {
-#ifdef DEB_CHANNEL
-      cout <<"NOT VALID" <<endl;
-      BRepTools::Write(aChannel, "ChanNV.brep");
-#endif
-    }
-  }
-
-  TopoDS_Shape a3dShape = GetShape3D();
-  if ( a3dShape.IsNull() )
-    return;
-
-  // build 2d shape -- temporary solution!!
-  TopoDS_Face aProj = HYDROData_Projection::MakeProjection( a3dShape );
-  SetTopShape( aProj );
-  if ( aProj.IsNull() )
-    return;
-
-  // Create the channel groups
-  TopoDS_Shape aFirstShape = aMkSweep.FirstShape();
-  TopoDS_Shape aLastShape = aMkSweep.LastShape();
-  if ( aFirstShape.IsNull() || aFirstShape.ShapeType() != TopAbs_WIRE ||
-       aLastShape.IsNull()  || aLastShape.ShapeType() != TopAbs_WIRE )
-    return;
-
-  TopoDS_Wire anInletWire = TopoDS::Wire( aFirstShape );
-  TopoDS_Wire anOutletWire = TopoDS::Wire( aLastShape );
-
-  TopoDS_Vertex anInletFirstVert, anInletLastVert;
-  TopExp::Vertices( anInletWire, anInletFirstVert, anInletLastVert );
-
-  const TopTools_ListOfShape& aGeneratedLeftEdges = aMkSweep.Generated( anInletFirstVert );
-  const TopTools_ListOfShape& aGeneratedRightEdges = aMkSweep.Generated( anInletLastVert );
-
-  TopTools_SequenceOfShape aProjEdges;
-  HYDROData_ShapesTool::ExploreShapeToShapes( aProj, TopAbs_EDGE, aProjEdges );
-
-  TopTools_SequenceOfShape aProjLeftEdges;
-  findEdges( aProjEdges, aGeneratedLeftEdges, aProjLeftEdges );
-
-  TopTools_SequenceOfShape aProjRightEdges;
-  findEdges( aProjEdges, aGeneratedRightEdges, aProjRightEdges );
+  //BRepTools::Write( aPathWire, "guideline.brep" );
+  //BRepTools::Write( aProfileWire, "profile.brep" );
 
-  TopTools_SequenceOfShape aProjInletEdges;
-  findEdges( aProjEdges, anInletWire, aProjInletEdges );
+  HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
+  aChannelConstructor.Create3dPresentation();
+  aChannelConstructor.Create2dPresentation();
+  SetShape3D( aChannelConstructor.Get3dPresentation() );
+  SetTopShape( aChannelConstructor.Get2dPresentation() );
 
-  TopTools_SequenceOfShape aProjOutletEdges;
-  findEdges( aProjEdges, anOutletWire, aProjOutletEdges );
 
+  /*TODO: groups via new API
   QString aLeftGroupName = GetName() + "_Left_Bank";
 
   Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
@@ -191,6 +143,7 @@ void HYDROData_Channel::Update()
   Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
   anOutGroup->SetName( anOutGroupName );
   anOutGroup->SetShapes( aProjOutletEdges );
+  */
 }
 
 QColor HYDROData_Channel::DefaultFillingColor()
diff --git a/src/HYDROData/HYDROData_Pipes.cxx b/src/HYDROData/HYDROData_Pipes.cxx
new file mode 100644 (file)
index 0000000..28f2d90
--- /dev/null
@@ -0,0 +1,242 @@
+// File:      HYDROData_Pipes.cxx
+// Created:   25.12.13 16:39:40
+// Author:    jgv@ROLEX
+// Copyright: Open CASCADE 2013
+
+#include <HYDROData_Pipes.h>
+#include <TopExp.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Iterator.hxx>
+#include <gp_Pln.hxx>
+#include <BRepOffsetAPI_NormalProjection.hxx>
+#include <BRepLib_MakeVertex.hxx>
+#include <BRepLib_MakeEdge.hxx>
+#include <BRepLib_MakeFace.hxx>
+#include <BRepLib_MakeWire.hxx>
+#include <BRepExtrema_ExtCC.hxx>
+#include <BRepBuilderAPI_Transform.hxx>
+#include <BRepOffsetAPI_MakePipeShell.hxx>
+#include <BRep_Tool.hxx>
+#include <Geom_Curve.hxx>
+
+HYDROData_Canal3dAnd2d::HYDROData_Canal3dAnd2d(const TopoDS_Wire& Profile,
+                           const TopoDS_Wire& Guideline)
+  : myProfile(Profile), myGuideline(Guideline)
+{
+  TopExp::Vertices(myProfile, myLeftVertex, myRightVertex);
+
+  ProjectWireOntoXOY(myGuideline, myProjectedGuideline);
+  Make2dProfile();
+  SetMiddlePoint2d();
+  SetMiddlePoint3d();
+}
+
+Standard_Boolean HYDROData_Canal3dAnd2d::ProjectWireOntoXOY(const TopoDS_Wire& aWire,
+                                                  TopoDS_Wire& ProjectedWire)
+{
+  gp_Pln XOY; //default plane
+  TopoDS_Face theXOYface = BRepLib_MakeFace(XOY);
+
+  BRepOffsetAPI_NormalProjection OrtProj(theXOYface);
+  OrtProj.Add(aWire);
+  //OrtProj.SetParams(...); ???
+  OrtProj.Build();
+  TopTools_ListOfShape Wires;
+  OrtProj.BuildWire(Wires);
+
+  if (Wires.Extent() != 1)
+    return Standard_False;
+  
+  ProjectedWire = TopoDS::Wire(Wires.First());
+  return Standard_True;
+}
+
+TopoDS_Vertex HYDROData_Canal3dAnd2d::ProjectVertexOntoXOY(const TopoDS_Vertex& aVertex)
+{
+  gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+  gp_Pnt aProjPoint(aPoint.X(), aPoint.Y(), 0.);
+  TopoDS_Vertex aProjVertex = BRepLib_MakeVertex(aProjPoint);
+  return aProjVertex;
+}
+
+void HYDROData_Canal3dAnd2d::Make2dProfile()
+{
+  TopoDS_Vertex ProjectedLeftVertex = ProjectVertexOntoXOY(myLeftVertex);
+  TopoDS_Vertex ProjectedRightVertex = ProjectVertexOntoXOY(myRightVertex);
+  TopoDS_Edge anEdge = BRepLib_MakeEdge(ProjectedLeftVertex, ProjectedRightVertex);
+  myProjectedProfile = BRepLib_MakeWire(anEdge);
+}
+
+void HYDROData_Canal3dAnd2d::SetMiddlePoint2d()
+{
+  TopoDS_Vertex V1, V2;
+  TopExp::Vertices(myProjectedProfile, V1, V2);
+  gp_Pnt Pnt1 = BRep_Tool::Pnt(V1);
+  gp_Pnt Pnt2 = BRep_Tool::Pnt(V2);
+  myMiddlePoint2d.SetXYZ(0.5*(Pnt1.XYZ() + Pnt2.XYZ()));
+}
+
+void HYDROData_Canal3dAnd2d::SetMiddlePoint3d()
+{
+  gp_Lin MidLin(myMiddlePoint2d, gp::DZ());
+  TopoDS_Edge MidEdge = BRepLib_MakeEdge(MidLin);
+  TopoDS_Iterator itw(myProfile);
+  for (; itw.More(); itw.Next())
+  {
+    const TopoDS_Edge& anEdge = TopoDS::Edge(itw.Value());
+    BRepExtrema_ExtCC ExtremaEE(MidEdge, anEdge);
+    if (ExtremaEE.IsDone() && ExtremaEE.NbExt() != 0)
+    {
+      for (Standard_Integer i = 1; i <= ExtremaEE.NbExt(); i++)
+      {
+        if (ExtremaEE.SquareDistance(i) <= Precision::Confusion())
+        {
+          myMiddlePoint3d = ExtremaEE.PointOnE1(i);
+          break;
+        }
+      }
+    }
+  }
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::SetTransformedProfile(const TopoDS_Wire& aProfile,
+                                                const TopoDS_Wire& aGuideline,
+                                                const gp_Pnt& aMiddlePoint)
+{
+  TopoDS_Wire aTransformedProfile;
+  
+  TopoDS_Iterator itw(myProjectedGuideline);
+  TopoDS_Edge FirstEdge = TopoDS::Edge(itw.Value());
+  Standard_Real fpar, lpar;
+  Handle(Geom_Curve) FirstCurve = BRep_Tool::Curve(FirstEdge, fpar, lpar);
+  gp_Pnt StartPnt;
+  gp_Vec StartVec;
+  FirstCurve->D1(fpar, StartPnt, StartVec);
+
+  TopoDS_Vertex FirstOnGuide, LastOnGuide;
+  TopExp::Vertices(aGuideline, FirstOnGuide, LastOnGuide);
+  gp_Pnt StartPointOnGuide = BRep_Tool::Pnt(FirstOnGuide);
+
+  gp_Trsf Translation, Rotation;
+  Translation.SetTranslation(aMiddlePoint, StartPointOnGuide);
+  aTransformedProfile =
+    TopoDS::Wire(BRepBuilderAPI_Transform(aProfile, Translation, Standard_True)); //copy
+
+  gp_Vec Vertical(0.,0.,1.);
+  TopoDS_Vertex LeftVertex, RightVertex;
+  TopExp::Vertices(aTransformedProfile, LeftVertex, RightVertex);
+  gp_Pnt LeftPoint  = BRep_Tool::Pnt(LeftVertex);
+  gp_Pnt RightPoint = BRep_Tool::Pnt(RightVertex);
+  gp_Vec LeftToRight(LeftPoint, RightPoint);
+  gp_Vec NormalToProfile = Vertical ^ LeftToRight;
+
+  gp_Vec AxisOfRotation = NormalToProfile ^ StartVec;
+  if (AxisOfRotation.Magnitude() <= gp::Resolution())
+  {
+    if (Vertical * LeftToRight < 0.)
+    {
+      gp_Ax1 theVertical(StartPointOnGuide, gp::DZ());
+      Rotation.SetRotation(theVertical, M_PI);
+    }
+  }
+  else
+  {
+    gp_Ax1 theAxis(StartPointOnGuide, AxisOfRotation);
+    Standard_Real theAngle = NormalToProfile.AngleWithRef(StartVec, AxisOfRotation);
+    Rotation.SetRotation(theAxis, theAngle);
+  }
+
+  aTransformedProfile =
+    TopoDS::Wire(BRepBuilderAPI_Transform(aTransformedProfile, Rotation, Standard_True)); //copy
+  
+  return aTransformedProfile;
+}
+
+Standard_Boolean HYDROData_Canal3dAnd2d::Create3dPresentation()
+{
+  myTransformedProfile3d = SetTransformedProfile(myProfile, myGuideline, myMiddlePoint3d);
+
+  mySweep3d = new BRepOffsetAPI_MakePipeShell(myGuideline);
+  mySweep3d->SetMode(gp::DZ()); //optional
+  mySweep3d->Add(myTransformedProfile3d);
+  //mySweep3d->SetTransitionMode(BRepBuilderAPI_RightCorner); //optional
+  mySweep3d->Build();
+  if (!mySweep3d->IsDone())
+    return Standard_False;
+
+  myPipe3d = mySweep3d->Shape();
+  return Standard_True;
+}
+
+Standard_Boolean HYDROData_Canal3dAnd2d::Create2dPresentation()
+{
+  myTransformedProfile2d = SetTransformedProfile(myProjectedProfile, myProjectedGuideline, myMiddlePoint2d);
+
+  mySweep2d = new BRepOffsetAPI_MakePipeShell(myProjectedGuideline);
+  mySweep2d->SetMode(gp::DZ()); //optional
+  mySweep2d->Add(myTransformedProfile2d);
+  //mySweep2d->SetTransitionMode(BRepBuilderAPI_RightCorner); //optional
+  mySweep2d->Build();
+  if (!mySweep2d->IsDone())
+    return Standard_False;
+
+  myPipe2d = mySweep2d->Shape();
+  myInlet  = TopoDS::Wire(mySweep2d->FirstShape());
+  myOutlet = TopoDS::Wire(mySweep2d->LastShape());
+  TopoDS_Vertex V1, V2, V3, V4;
+  TopExp::Vertices(myTransformedProfile2d, V1, V2);
+  TopExp::Vertices(myInlet, V3, V4);
+  gp_Pnt P1 = BRep_Tool::Pnt(V1);
+  gp_Pnt P3 = BRep_Tool::Pnt(V3);
+  if (P1.IsEqual(P3, Precision::Confusion()))
+  { myLeftVertex2d = V3; myRightVertex2d = V4; }
+  else
+  { myLeftVertex2d = V4; myRightVertex2d = V3; }
+  
+  return Standard_True;
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::GetBank(const TopoDS_Vertex& aFreeVertex)
+{
+  TopoDS_Wire aBank;
+
+  TopTools_ListOfShape GeneratedShapes;
+  GeneratedShapes = mySweep2d->Generated(aFreeVertex);
+  BRepLib_MakeWire MW;
+  MW.Add(GeneratedShapes);
+  aBank = MW.Wire();
+
+  return aBank;
+}
+
+TopoDS_Shape HYDROData_Canal3dAnd2d::Get3dPresentation()
+{
+  return myPipe3d;
+}
+
+TopoDS_Shape HYDROData_Canal3dAnd2d::Get2dPresentation()
+{
+  return myPipe2d;
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::GetInlet()
+{
+  return myInlet;
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::GetOutlet()
+{
+  return myOutlet;
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::GetLeftBank()
+{
+  return GetBank(myLeftVertex2d);
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::GetRightBank()
+{
+  return GetBank(myRightVertex2d);
+}
diff --git a/src/HYDROData/HYDROData_Pipes.h b/src/HYDROData/HYDROData_Pipes.h
new file mode 100644 (file)
index 0000000..8e9ba19
--- /dev/null
@@ -0,0 +1,72 @@
+
+#ifndef HYDROData_Pipes_HeaderFile
+#define HYDROData_Pipes_HeaderFile
+
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Wire.hxx>
+#include <gp_Pnt.hxx>
+
+class BRepOffsetAPI_MakePipeShell;
+
+class HYDROData_Canal3dAnd2d
+{
+public:
+  HYDROData_Canal3dAnd2d( const TopoDS_Wire& Profile,
+                          const TopoDS_Wire& Guideline );
+  
+  Standard_Boolean Create3dPresentation();
+
+  Standard_Boolean Create2dPresentation();
+
+  Standard_Boolean ProjectWireOntoXOY(const TopoDS_Wire& aWire,
+                                      TopoDS_Wire& ProjectedWire);
+
+  void Make2dProfile();
+
+  TopoDS_Vertex ProjectVertexOntoXOY(const TopoDS_Vertex& aVertex);
+
+  void SetMiddlePoint2d();
+
+  void SetMiddlePoint3d();
+
+  TopoDS_Wire SetTransformedProfile(const TopoDS_Wire& aProfile,
+                                    const TopoDS_Wire& aGuideline,
+                                    const gp_Pnt& aMiddlePoint);
+
+  TopoDS_Wire GetBank(const TopoDS_Vertex& aFreeVertex);
+
+  //Queries
+  TopoDS_Shape Get3dPresentation();
+  TopoDS_Shape Get2dPresentation();
+  TopoDS_Wire GetLeftBank();
+  TopoDS_Wire GetRightBank();
+  TopoDS_Wire GetInlet();
+  TopoDS_Wire GetOutlet();
+
+private:
+
+  TopoDS_Wire myProfile;
+  TopoDS_Wire myGuideline;
+  TopoDS_Vertex myLeftVertex;
+  TopoDS_Vertex myRightVertex;
+  TopoDS_Vertex myLeftVertex2d;
+  TopoDS_Vertex myRightVertex2d;
+  gp_Pnt myMiddlePoint2d;
+  gp_Pnt myMiddlePoint3d;
+
+  TopoDS_Wire myProjectedProfile;
+  TopoDS_Wire myProjectedGuideline;
+  TopoDS_Wire myTransformedProfile3d;
+  TopoDS_Wire myTransformedProfile2d;
+  BRepOffsetAPI_MakePipeShell* mySweep3d;
+  BRepOffsetAPI_MakePipeShell* mySweep2d;
+
+  TopoDS_Shape myPipe3d;
+  TopoDS_Shape myPipe2d;
+  TopoDS_Wire myInlet;
+  TopoDS_Wire myOutlet;
+  //TopoDS_Shape myLeftBank;
+  //TopoDS_Shape myRightBank;
+};
+
+#endif