Salome HOME
EDF 2281 : Add 2 primitives for hexa mesh
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ChamferDriver.cxx
index 2d1714931b4fbdee032bbd728dc7b0f2effccf7f..d24bce73e7de3cfcc83717feded5326ac1cfaf14 100644 (file)
@@ -1,3 +1,24 @@
+// 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
+//
+// 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.
+//
+// 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 <Standard_Stream.hxx>
 
 #include <GEOMImpl_IChamfer.hxx>
 #include <GEOMImpl_Types.hxx>
 #include <GEOMImpl_ILocalOperations.hxx>
-#include <GEOM_Function.hxx>
 #include <GEOMImpl_Block6Explorer.hxx>
 
+#include <GEOM_Function.hxx>
+
+#include <BRepLib.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepTools.hxx>
 #include <BRepFilletAPI_MakeChamfer.hxx>
 
+#include <ShapeFix_Shape.hxx>
+#include <ShapeFix_ShapeTolerance.hxx>
+
 #include <TopAbs.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
@@ -113,13 +139,14 @@ Standard_Integer GEOMImpl_ChamferDriver::Execute(TFunction_Logbook& log) const
           M.FindFromIndex(i).Extent() == 2)
         fill.Add(aD, E, F);
     }
-  } else if (aType == CHAMFER_SHAPE_EDGE) {
+  }
+  else if (aType == CHAMFER_SHAPE_EDGE || aType == CHAMFER_SHAPE_EDGE_AD) {
     // chamfer on edges, common to two faces, with D1 on the first face
-    double aD1 = aCI.GetD1();
-    double aD2 = aCI.GetD2();
+
     TopoDS_Shape aFace1, aFace2;
     if (GEOMImpl_ILocalOperations::GetSubShape(aShapeBase, aCI.GetFace1(), aFace1) &&
-        GEOMImpl_ILocalOperations::GetSubShape(aShapeBase, aCI.GetFace2(), aFace2)) {
+        GEOMImpl_ILocalOperations::GetSubShape(aShapeBase, aCI.GetFace2(), aFace2))
+    {
       TopoDS_Face F = TopoDS::Face(aFace1);
 
       // fill map of edges of the second face
@@ -135,15 +162,29 @@ Standard_Integer GEOMImpl_ChamferDriver::Execute(TFunction_Logbook& log) const
         if (aMap.Contains(Exp.Current())) {
           TopoDS_Edge E = TopoDS::Edge(Exp.Current());
           if (!BRepTools::IsReallyClosed(E, F) && !BRep_Tool::Degenerated(E))
-            fill.Add(aD1, aD2, E, F);
+          {
+            if ( aType == CHAMFER_SHAPE_EDGE )
+            {
+              double aD1 = aCI.GetD1();
+              double aD2 = aCI.GetD2();
+              fill.Add(aD1, aD2, E, F);
+            }
+            else
+            {
+              double aD = aCI.GetD();
+              double anAngle = aCI.GetAngle();
+              if ( (anAngle > 0) && (anAngle < (M_PI/2.)) )
+                fill.AddDA(aD, anAngle, E, F);
+            }
+          }
         }
       }
     }
-  } else if (aType == CHAMFER_SHAPE_FACES) {
+  }
+  else if (aType == CHAMFER_SHAPE_FACES || aType == CHAMFER_SHAPE_FACES_AD) {
     // chamfer on all edges of the selected faces, with D1 on the selected face
     // (on first selected face, if the edge belongs to two selected faces)
-    double aD1 = aCI.GetD1();
-    double aD2 = aCI.GetD2();
+
     int aLen = aCI.GetLength();
     int ind = 1;
     TopTools_MapOfShape aMap;
@@ -152,22 +193,71 @@ Standard_Integer GEOMImpl_ChamferDriver::Execute(TFunction_Logbook& log) const
     for (; ind <= aLen; ind++)
     {
       TopoDS_Shape aShapeFace;
-      if (GEOMImpl_ILocalOperations::GetSubShape
-          (aShapeBase, aCI.GetFace(ind), aShapeFace)) {
+      if (GEOMImpl_ILocalOperations::GetSubShape(aShapeBase, aCI.GetFace(ind), aShapeFace))
+      {
         TopoDS_Face F = TopoDS::Face(aShapeFace);
         TopExp_Explorer Exp (F, TopAbs_EDGE);
         for (; Exp.More(); Exp.Next()) {
-          if (!aMap.Contains(Exp.Current())) {
+          if (!aMap.Contains(Exp.Current()))
+          {
             TopoDS_Edge E = TopoDS::Edge(Exp.Current());
             if (!BRepTools::IsReallyClosed(E, F) &&
                 !BRep_Tool::Degenerated(E) &&
                 M.FindFromKey(E).Extent() == 2)
-              fill.Add(aD1, aD2, E, F);
+            {
+              if (aType == CHAMFER_SHAPE_FACES)
+              {
+                double aD1 = aCI.GetD1();
+                double aD2 = aCI.GetD2();
+                fill.Add(aD1, aD2, E, F);
+              }
+              else
+              {
+                double aD = aCI.GetD();
+                double anAngle = aCI.GetAngle();
+                if ( (anAngle > 0) && (anAngle < (M_PI/2.)) )
+                  fill.AddDA(aD, anAngle, E, F);
+              }
+            }
           }
         }
       }
     }
-  } else {
+  }
+  else if (aType == CHAMFER_SHAPE_EDGES || aType == CHAMFER_SHAPE_EDGES_AD)
+  {
+    // chamfer on selected edges with lenght param D1 & D2.
+
+    int aLen = aCI.GetLength();
+    int ind = 1;
+    TopTools_MapOfShape aMap;
+    TopTools_IndexedDataMapOfShapeListOfShape M;
+    GEOMImpl_Block6Explorer::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, M);
+    for (; ind <= aLen; ind++)
+    {
+      TopoDS_Shape aShapeEdge;
+      if (GEOMImpl_ILocalOperations::GetSubShape(aShapeBase, aCI.GetEdge(ind), aShapeEdge))
+      {
+        TopoDS_Edge E = TopoDS::Edge(aShapeEdge);
+        const TopTools_ListOfShape& aFacesList = M.FindFromKey(E);
+        TopoDS_Face F = TopoDS::Face( aFacesList.First() );
+        if (aType == CHAMFER_SHAPE_EDGES)
+        {
+          double aD1 = aCI.GetD1();
+          double aD2 = aCI.GetD2();
+          fill.Add(aD1, aD2, E, F);
+        }
+        else
+        {
+          double aD = aCI.GetD();
+          double anAngle = aCI.GetAngle();
+          if ( (anAngle > 0) && (anAngle < (M_PI/2.)) )
+            fill.AddDA(aD, anAngle, E, F);
+        }
+      }
+    }
+  }
+  else {
   }
 
   fill.Build();
@@ -178,6 +268,17 @@ Standard_Integer GEOMImpl_ChamferDriver::Execute(TFunction_Logbook& log) const
 
   if (aShape.IsNull()) return 0;
 
+  // reduce tolerances
+  ShapeFix_ShapeTolerance aSFT;
+  aSFT.LimitTolerance(aShape, Precision::Confusion(),
+                      Precision::Confusion(), TopAbs_SHAPE);
+  Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape);
+  aSfs->Perform();
+  aShape = aSfs->Shape();
+
+  // fix SameParameter flag
+  BRepLib::SameParameter(aShape, 1.E-5, Standard_True);
+
   aFunction->SetValue(aShape);
 
   log.SetTouched(Label());
@@ -192,7 +293,6 @@ Standard_Integer GEOMImpl_ChamferDriver::Execute(TFunction_Logbook& log) const
 //=======================================================================
 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ChamferDriver_Type_()
 {
-
   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
@@ -200,13 +300,12 @@ Standard_EXPORT Handle_Standard_Type& GEOMImpl_ChamferDriver_Type_()
   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
 
-
   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ChamferDriver",
-                                                        sizeof(GEOMImpl_ChamferDriver),
-                                                        1,
-                                                        (Standard_Address)_Ancestors,
-                                                        (Standard_Address)NULL);
+                                                         sizeof(GEOMImpl_ChamferDriver),
+                                                         1,
+                                                         (Standard_Address)_Ancestors,
+                                                         (Standard_Address)NULL);
 
   return _aType;
 }
@@ -225,5 +324,5 @@ const Handle(GEOMImpl_ChamferDriver) Handle(GEOMImpl_ChamferDriver)::DownCast(co
      }
   }
 
-  return _anOtherObject ;
+  return _anOtherObject;
 }