Salome HOME
PR: synchro V6_main tag mergeto_V7_main_11Feb13
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PipeDriver.cxx
index 2a5bcadca234c20708255ff1d00fe7440205e5da..9812da16af8b6518df08ad6fb722c75c6fe71e5c 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
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 
-#include <Standard_Stream.hxx>
-
 #include <GEOMImpl_PipeDriver.hxx>
 
-#include <GEOMImpl_IShapesOperations.hxx>
 #include <GEOMImpl_IPipeDiffSect.hxx>
 #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 <GEOMUtils.hxx>
+
 #include <ShapeAnalysis_FreeBounds.hxx>
 #include <ShapeAnalysis_Edge.hxx>
 #include <ShapeFix_Face.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>
 #include <TColStd_HSequenceOfTransient.hxx>
 
 #include <Precision.hxx>
+
 #include <Standard_NullObject.hxx>
 #include <Standard_TypeMismatch.hxx>
 #include <Standard_ConstructionError.hxx>
 
 #include "utilities.h"
 
+//////////////////////////////////////////////////////////////////////////
+// Uncomment below macro to perform gluing in the end of MakePipe operation
+// as fix of issue 0020207.
+//////////////////////////////////////////////////////////////////////////
+//#define GLUE_0020207
+
+
 //=======================================================================
 //function : GetID
 //purpose  :
 //=======================================================================
 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;
 }
 
@@ -2222,6 +2232,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 +2248,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 +2287,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 +2368,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
@@ -2439,6 +2484,8 @@ Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
   }
 
   // Glue (for bug 0020207)
+  // No gluing is needed as the bug 0020207 is fixed in OCCT.
+#ifdef GLUE_0020207
   TopExp_Explorer anExpV (aShape, TopAbs_VERTEX);
   if (anExpV.More()) {
     Standard_Real aVertMaxTol = -RealLast();
@@ -2452,8 +2499,9 @@ Standard_Integer GEOMImpl_PipeDriver::Execute(TFunction_Logbook& log) const
     aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, aVertMaxTol, Standard_True);
     //aShape = GEOMImpl_GlueDriver::GlueFaces(aShape, Precision::Confusion(), Standard_True);
   }
+#endif
 
-  TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
+  TopoDS_Shape aRes = GEOMUtils::CompsolidToCompound(aShape);
   aFunction->SetValue(aRes);
 
   log.SetTouched(Label());