Salome HOME
Merge from V6_main 01/04/2013
[modules/geom.git] / src / GEOMImpl / GEOMImpl_OffsetDriver.cxx
index 63d94554952a27ab92c8f12a501d892e47509664..2c870d03c7aa4a35a12149f455ff76187537cfb5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  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
@@ -35,6 +35,8 @@
 #include <TopAbs.hxx>
 #include <TopExp.hxx>
 
+#include <BRepClass3d_SolidClassifier.hxx>
+
 #include <Precision.hxx>
 #include <gp_Pnt.hxx>
 
@@ -45,6 +47,8 @@
 #include <Standard_ConstructionError.hxx>
 #include <StdFail_NotDone.hxx>
 
+#include "utilities.h"
+
 //=======================================================================
 //function : GetID
 //purpose  :
@@ -117,6 +121,15 @@ Standard_Integer GEOMImpl_OffsetDriver::Execute(TFunction_Logbook& log) const
   } 
   else if (aType == OFFSET_THICKENING || aType == OFFSET_THICKENING_COPY)
   {
+    BRepClass3d_SolidClassifier aClassifier = BRepClass3d_SolidClassifier(aShapeBase);
+    aClassifier.PerformInfinitePoint(Precision::Confusion());
+    if (aClassifier.State()==TopAbs_IN)
+    {
+      // If the generated pipe faces normals are oriented towards the inside, the offset is negative
+      // so that the thickening is still towards outside
+      anOffset=-anOffset;
+    }
+
     BRepOffset_MakeOffset myOffsetShape(aShapeBase, anOffset, aTol, BRepOffset_Skin,
                                         Standard_False, Standard_False, GeomAbs_Intersection, Standard_True);
   
@@ -125,6 +138,15 @@ Standard_Integer GEOMImpl_OffsetDriver::Execute(TFunction_Logbook& log) const
       StdFail_NotDone::Raise("Thickening construction failed");
     }
     aShape = myOffsetShape.Shape();
+    
+    // Control the solid orientation. This is mostly done to fix a bug in case of extrusion
+    // of a circle. The built solid is then badly oriented
+    BRepClass3d_SolidClassifier anotherClassifier = BRepClass3d_SolidClassifier(aShape);
+    anotherClassifier.PerformInfinitePoint(Precision::Confusion());
+    if (anotherClassifier.State()==TopAbs_IN)
+    {
+      aShape.Reverse();
+    }
   }
 
   if (aShape.IsNull()) return 0;