Salome HOME
Test case bugs/N4. A fix by PKV.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PipeDriver.cxx
index 93263f51e59e8bc0fb7ff0a39ef0d79dcfdf41fd..400c2a03c31b3c54d9bd217b9e5164e5c4c8facc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -28,6 +28,7 @@
 #include <GEOMImpl_IPipeShellSect.hxx>
 #include <GEOMImpl_IPipeBiNormal.hxx>
 #include <GEOMImpl_IPipe.hxx>
+#include <GEOMImpl_IPipePath.hxx>
 #include <GEOMImpl_GlueDriver.hxx>
 #include <GEOMImpl_Types.hxx>
 #include <GEOM_Function.hxx>
 
 #include <BRep_Tool.hxx>
 #include <BRep_Builder.hxx>
+#include <BRepBuilderAPI_Copy.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
 #include <BRepBuilderAPI_Sewing.hxx>
 #include <BRepCheck_Analyzer.hxx>
+#include <BRepGProp.hxx>
 #include <BRepOffsetAPI_MakePipe.hxx>
 #include <BRepOffsetAPI_MakePipeShell.hxx>
-#include <GProp_GProps.hxx>
-#include <BRepGProp.hxx>
-#include <BRepBuilderAPI_MakeFace.hxx>
-#include <BRepBuilderAPI_Copy.hxx>
 
 #include <TopAbs.hxx>
 #include <TopExp.hxx>
@@ -68,6 +68,8 @@
 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 
+#include <GProp_GProps.hxx>
+
 #include <GeomAPI_ProjectPointOnCurve.hxx>
 #include <GeomAPI_Interpolate.hxx>
 #include <Geom_TrimmedCurve.hxx>
@@ -88,6 +90,7 @@
 #include <TColStd_HSequenceOfTransient.hxx>
 
 #include <Precision.hxx>
+
 #include <Standard_NullObject.hxx>
 #include <Standard_TypeMismatch.hxx>
 #include <Standard_ConstructionError.hxx>
 //=======================================================================
 const Standard_GUID& GEOMImpl_PipeDriver::GetID()
 {
-  static Standard_GUID aPipeDriver("FF1BBB19-5D14-4df2-980B-3A668264EA16");
+  static Standard_GUID aPipeDriver ("FF1BBB19-5D14-4df2-980B-3A668264EA16");
   return aPipeDriver;
 }
 
@@ -502,7 +505,7 @@ static void FindFirstPairFaces(const TopoDS_Shape& S1, const TopoDS_Shape& S2,
 {
   //cout<<"FindFirstPairFaces"<<endl;
 
-  // check if vertexes are subshapes of sections
+  // check if vertexes are sub-shapes of sections
   gp_Pnt P1 = BRep_Tool::Pnt(V1);
   gp_Pnt P2 = BRep_Tool::Pnt(V2);
   TopoDS_Vertex V1new,V2new;
@@ -1822,7 +1825,7 @@ static TopoDS_Shape CreatePipeShellsWithoutPath(GEOMImpl_IPipe* aCI)
     TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces2;
     TopExp::MapShapesAndAncestors(aShBase2, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces2);
 
-    // constuct map face->face (and subshapes)
+    // constuct map face->face (and sub-shapes)
     TopTools_IndexedDataMapOfShapeShape FF;
     //TopoDS_Shape FS1 = SecFs.Value(i), FS2 = SecFs.Value(i+1);
     TopoDS_Shape FS1, FS2;
@@ -1839,7 +1842,7 @@ static TopoDS_Shape CreatePipeShellsWithoutPath(GEOMImpl_IPipe* aCI)
       if (aCI) delete aCI;
       Standard_ConstructionError::Raise("Can not create correct pipe");
     }
-    MESSAGE ("  correspondences for subshapes of first pair of faces is found");
+    MESSAGE ("  correspondences for sub-shapes of first pair of faces is found");
 
     FindNextPairOfFaces(FS1, aMapEdgeFaces1, aMapEdgeFaces2, FF, aCI);
     MESSAGE ("  other correspondences is found, make pipe for all pairs of faces");
@@ -2222,6 +2225,11 @@ static TopoDS_Shape CreatePipeBiNormalAlongVector(const TopoDS_Wire& aWirePath,
     Standard_NullObject::Raise("MakePipe aborted : null base argument");
   }
 
+  // Make copy to prevent modifying of base object: 0021525
+  BRepBuilderAPI_Copy Copy (aShapeBase);
+  if (Copy.IsDone())
+    aShapeBase = Copy.Shape();
+
   TopoDS_Shape aProf;
   if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
     aProf = aShapeBase;
@@ -2233,14 +2241,14 @@ static TopoDS_Shape CreatePipeBiNormalAlongVector(const TopoDS_Wire& aWirePath,
     aProf = aShapeBase;
   }
   else if (aShapeBase.ShapeType() == TopAbs_FACE) {
-    TopExp_Explorer wexp(aShapeBase,TopAbs_WIRE);
+    TopExp_Explorer wexp (aShapeBase,TopAbs_WIRE);
     aProf = wexp.Current();
   }
   else {
     Standard_TypeMismatch::Raise
       ("MakePipe aborted : invalid type of base");
   }
-  BRepOffsetAPI_MakePipeShell PipeBuilder(aWirePath);
+  BRepOffsetAPI_MakePipeShell PipeBuilder (aWirePath);
   PipeBuilder.Add(aProf);
 
   if (aShapeVec.IsNull()) {
@@ -2272,23 +2280,23 @@ static TopoDS_Shape CreatePipeBiNormalAlongVector(const TopoDS_Wire& aWirePath,
 //function : Execute
 //purpose  :
 //=======================================================================
-Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
+Standard_Integer GEOMImpl_PipeDriver::Execute (TFunction_Logbook& log) const
 {
-  //cout<<"PipeDriver::Execute"<<endl;
   if (Label().IsNull()) return 0;
   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
-  GEOMImpl_IPipe* aCI= 0;
   Standard_Integer aType = aFunction->GetType();
+
+  GEOMImpl_IPipe* aCI = 0;
   if (aType == PIPE_BASE_PATH)
-    aCI = new GEOMImpl_IPipe(aFunction);
+    aCI = new GEOMImpl_IPipe (aFunction);
   else if (aType == PIPE_DIFFERENT_SECTIONS)
-    aCI = new GEOMImpl_IPipeDiffSect(aFunction);
+    aCI = new GEOMImpl_IPipeDiffSect (aFunction);
   else if (aType == PIPE_SHELL_SECTIONS)
-    aCI = new GEOMImpl_IPipeShellSect(aFunction);
+    aCI = new GEOMImpl_IPipeShellSect (aFunction);
   else if (aType == PIPE_SHELLS_WITHOUT_PATH)
-    aCI = new GEOMImpl_IPipeShellSect(aFunction);
+    aCI = new GEOMImpl_IPipeShellSect (aFunction);
   else if (aType == PIPE_BI_NORMAL_ALONG_VECTOR)
-    aCI = new GEOMImpl_IPipeBiNormal(aFunction);
+    aCI = new GEOMImpl_IPipeBiNormal (aFunction);
   else
     return 0;
 
@@ -2353,7 +2361,37 @@ Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
     }
 
     // Make pipe
-    aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
+    if (aShapeBase.ShapeType() == TopAbs_EDGE ||
+        aShapeBase.ShapeType() == TopAbs_WIRE)
+    {
+      TopoDS_Wire Profile;
+      if (aShapeBase.ShapeType() == TopAbs_WIRE)
+        Profile = TopoDS::Wire(aShapeBase);
+      else
+      {
+        BRep_Builder BB;
+        BB.MakeWire(Profile);
+        BB.Add(Profile, aShapeBase);
+      }
+
+      BRepOffsetAPI_MakePipeShell Sweep (aWirePath);
+      BRepBuilderAPI_MakeFace FaceBuilder (aWirePath, Standard_True); //to find the plane of spine
+      if (FaceBuilder.IsDone())
+        Sweep.SetMode(FaceBuilder.Face());
+      Sweep.Add(Profile);
+      Sweep.Build();
+      
+      if (!Sweep.IsDone())
+      {
+        if (aCI) delete aCI;
+        Standard_ConstructionError::Raise("MakePipeShell failed");
+      }
+      else
+        aShape = Sweep.Shape(); //result is good
+      
+    }
+    else
+      aShape = BRepOffsetAPI_MakePipe(aWirePath, aShapeBase);
   }
 
   //building pipe with different sections
@@ -2440,8 +2478,18 @@ Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
 
   // Glue (for bug 0020207)
   TopExp_Explorer anExpV (aShape, TopAbs_VERTEX);
-  if (anExpV.More())
-    aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, Precision::Confusion(), Standard_True);
+  if (anExpV.More()) {
+    Standard_Real aVertMaxTol = -RealLast();
+    for (; anExpV.More(); anExpV.Next()) {
+      TopoDS_Vertex aVertex = TopoDS::Vertex(anExpV.Current());
+      Standard_Real aTol = BRep_Tool::Tolerance(aVertex);
+      if (aTol > aVertMaxTol)
+        aVertMaxTol = aTol;
+    }
+    aVertMaxTol += Precision::Confusion();
+    aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, aVertMaxTol, Standard_True);
+    //aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, Precision::Confusion(), Standard_True);
+  }
 
   TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
   aFunction->SetValue(aRes);