Salome HOME
Merge branch 'BR_v14_rc' of ssh://git.salome-platform.org/modules/hydro into BR_v14_rc
[modules/hydro.git] / src / HYDROData / HYDROData_Pipes.cxx
index 90d7b088409a6e12072a97a8cc37311bae50969f..9e209546037191bd24999dc0c58e1eadb51422af 100644 (file)
@@ -1,7 +1,20 @@
-// File:      HYDROData_Pipes.cxx
-// Created:   25.12.13 16:39:40
-// Author:    jgv@ROLEX
-// Copyright: Open CASCADE 2013
+// Copyright (C) 2014-2015  EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include <HYDROData_Pipes.h>
 #include <TopExp.hxx>
@@ -44,6 +57,7 @@
 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <TopExp_Explorer.hxx>
+#include <ShapeUpgrade_UnifySameDomain.hxx>
 
 /**
 * GEOMImpl_Fillet1dPoint is an internal class for 1D fillet algorithm
@@ -959,22 +973,29 @@ static void addEdgeRelation(TopTools_DataMapOfShapeShape& theMap,
 
 HYDROData_Canal3dAnd2d::HYDROData_Canal3dAnd2d(const TopoDS_Wire& Profile,
                            const TopoDS_Wire& Guideline)
-  : myProfile(Profile), myOriginalGuideline(Guideline)
+  : myProfile(Profile), myOriginalGuideline(Guideline), myStatus(0)
 {
   TopExp::Vertices(myProfile, myLeftVertex, myRightVertex);
   gp_Pnt LeftPoint  = BRep_Tool::Pnt(myLeftVertex);
   gp_Pnt RightPoint = BRep_Tool::Pnt(myRightVertex);
-  myFilletRadius = (LeftPoint.Distance(RightPoint))/2.;
+  myFilletRadius = (LeftPoint.Distance(RightPoint))/2. * 1.5;
 
   myTolAngular = 0.01;
   MakeSharpVertexList();
   if (!mySharpVertexList.IsEmpty())
     MakeFillet();
+  else
+    myGuideline = myOriginalGuideline;
 
-  ProjectWireOntoXOY(myGuideline, myProjectedGuideline);
-  Make2dProfile();
-  SetMiddlePoint2d();
-  SetMiddlePoint3d();
+  if (myStatus == 0)
+  {
+    if (ProjectWireOntoXOY(myGuideline, myProjectedGuideline))
+    {
+      Make2dProfile();
+      SetMiddlePoint2d();
+      SetMiddlePoint3d();
+    }
+  }
 }
 
 void HYDROData_Canal3dAnd2d::MakeSharpVertexList()
@@ -1039,10 +1060,14 @@ Standard_Boolean HYDROData_Canal3dAnd2d::MakeFillet()
     TopoDS_Wire LocalWire = BRepLib_MakeWire(anEdge1, anEdge2);
     //if ( !takePlane(anEdge1, anEdge2, aV, aPlane) )
     if (!PlaneOfWire(LocalWire, aPlane))
+    {
+      myStatus = 1;
       return Standard_False; // seems edges does not belong to same plane or parallel (fillet can not be build)
+    }
 
     GEOMImpl_Fillet1d aFilletAlgo (anEdge1, anEdge2, aPlane);
     if (!aFilletAlgo.Perform(myFilletRadius)) {
+      myStatus = 2;
       return Standard_False; //can not create fillet at this vertex with given radius
     }
 
@@ -1050,6 +1075,7 @@ Standard_Boolean HYDROData_Canal3dAnd2d::MakeFillet()
     TopoDS_Edge aModifE1, aModifE2;
     TopoDS_Edge aNewE = aFilletAlgo.Result(BRep_Tool::Pnt(aV), aModifE1, aModifE2);
     if (aNewE.IsNull()) {
+      myStatus = 3;
       return Standard_False; //fillet failed at this vertex
     }
 
@@ -1065,6 +1091,7 @@ Standard_Boolean HYDROData_Canal3dAnd2d::MakeFillet()
   }
 
   if (anEdgeToEdgeMap.IsEmpty() && aListOfNewEdge.IsEmpty()) {
+    myStatus = 4;
     return Standard_False; //fillet can't be computed on the given shape with the given radius
   }
 
@@ -1105,7 +1132,10 @@ Standard_Boolean HYDROData_Canal3dAnd2d::ProjectWireOntoXOY(const TopoDS_Wire& a
   OrtProj.BuildWire(Wires);
 
   if (Wires.Extent() != 1)
+  {
+    myStatus = 5;
     return Standard_False;
+  }
   
   ProjectedWire = TopoDS::Wire(Wires.First());
   return Standard_True;
@@ -1217,10 +1247,16 @@ Standard_Boolean HYDROData_Canal3dAnd2d::Create3dPresentation()
   mySweep3d = new BRepOffsetAPI_MakePipeShell(myGuideline);
   mySweep3d->SetMode(gp::DZ()); //optional
   mySweep3d->Add(myTransformedProfile3d);
-  //mySweep3d->SetTransitionMode(BRepBuilderAPI_RightCorner); //optional
+  //Set approx parameters
+  mySweep3d->SetMaxDegree(14);
+  mySweep3d->SetMaxSegments(500);
+  ///////////////////////
   mySweep3d->Build();
   if (!mySweep3d->IsDone())
+  {
+    myStatus = 6;
     return Standard_False;
+  }
 
   myPipe3d = mySweep3d->Shape();
   return Standard_True;
@@ -1233,17 +1269,29 @@ Standard_Boolean HYDROData_Canal3dAnd2d::Create2dPresentation()
   mySweep2d = new BRepOffsetAPI_MakePipeShell(myProjectedGuideline);
   mySweep2d->SetMode(gp::DZ()); //optional
   mySweep2d->Add(myTransformedProfile2d);
-  //mySweep2d->SetTransitionMode(BRepBuilderAPI_RightCorner); //optional
+  //Set approx parameters
+  mySweep2d->SetMaxDegree(14);
+  mySweep2d->SetMaxSegments(500);
+  ///////////////////////
   mySweep2d->Build();
   if (!mySweep2d->IsDone())
+  {
+    myStatus = 7;
     return Standard_False;
+  }
 
   myPipe2d = mySweep2d->Shape();
-  myInlet  = TopoDS::Wire(mySweep2d->FirstShape());
-  myOutlet = TopoDS::Wire(mySweep2d->LastShape());
+  myUnifier.Initialize(myPipe2d);
+  myUnifier.Build();
+  myUnifiedPipe2d = myUnifier.Shape();
+  
+  TopoDS_Wire OriginalInlet  = TopoDS::Wire(mySweep2d->FirstShape());
+  TopoDS_Wire OriginalOutlet = TopoDS::Wire(mySweep2d->LastShape());
+  myInlet  = CreateWireOnUnifiedPipe2d(OriginalInlet);
+  myOutlet = CreateWireOnUnifiedPipe2d(OriginalOutlet);
   TopoDS_Vertex V1, V2, V3, V4;
   TopExp::Vertices(myTransformedProfile2d, V1, V2);
-  TopExp::Vertices(myInlet, V3, V4);
+  TopExp::Vertices(OriginalInlet, V3, V4);
   gp_Pnt P1 = BRep_Tool::Pnt(V1);
   gp_Pnt P3 = BRep_Tool::Pnt(V3);
   if (P1.IsEqual(P3, Precision::Confusion()))
@@ -1264,7 +1312,23 @@ TopoDS_Wire HYDROData_Canal3dAnd2d::GetBank(const TopoDS_Vertex& aFreeVertex)
   MW.Add(GeneratedShapes);
   aBank = MW.Wire();
 
-  return aBank;
+  TopoDS_Wire aBankOnUnifiedPipe2d = CreateWireOnUnifiedPipe2d(aBank);
+
+  return aBankOnUnifiedPipe2d;
+}
+
+TopoDS_Wire HYDROData_Canal3dAnd2d::CreateWireOnUnifiedPipe2d(const TopoDS_Wire& aWireOnPipe2d)
+{
+  BRepLib_MakeWire MW;
+  BRepTools_WireExplorer wexp(aWireOnPipe2d);
+  for (; wexp.More(); wexp.Next())
+  {
+    TopoDS_Shape anEdge = wexp.Current();
+    TopoDS_Shape NewEdge = myUnifier.Generated(anEdge);
+    if (!NewEdge.IsNull())
+      MW.Add(TopoDS::Edge(NewEdge));
+  }
+  return MW.Wire();
 }
 
 TopoDS_Shape HYDROData_Canal3dAnd2d::Get3dPresentation()
@@ -1272,9 +1336,10 @@ TopoDS_Shape HYDROData_Canal3dAnd2d::Get3dPresentation()
   return myPipe3d;
 }
 
-TopoDS_Shape HYDROData_Canal3dAnd2d::Get2dPresentation()
+TopoDS_Face HYDROData_Canal3dAnd2d::Get2dPresentation()
 {
-  return myPipe2d;
+  TopoDS_Iterator iter(myUnifiedPipe2d);
+  return TopoDS::Face(iter.Value());
 }
 
 TopoDS_Wire HYDROData_Canal3dAnd2d::GetInlet()
@@ -1297,6 +1362,12 @@ TopoDS_Wire HYDROData_Canal3dAnd2d::GetRightBank()
   return GetBank(myRightVertex2d);
 }
 
+Standard_Integer HYDROData_Canal3dAnd2d::GetStatus()
+{
+  return myStatus;
+}
+
+
 /*TopoDS_Wire HYDROData_Canal3dAnd2d::GetRoundedGuideline()
 {
   return myGuideline;
@@ -1306,4 +1377,4 @@ TopoDS_Wire HYDROData_Canal3dAnd2d::GetProjectedRoundedGuideline()
 {
   return myProjectedGuideline;
 }
-*/
\ No newline at end of file
+*/