Salome HOME
Porting to OCCT development version: Standard_PI -> M_PI
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_FinderShapeOn.cxx
index 50e94384ab66f9208b9eeec007098bc7d219b1b3..c0f0ac7119bce14fc273e86f6ff78f0c6ce721de 100644 (file)
@@ -1,30 +1,36 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2011  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 
+// 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 
+//
+// 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 
+// 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/
-//
-// File:       GEOMAlgo_FinderShapeOn.cxx
-// Created:    Tue Jan 11 14:44:31 2005
-// Author:     Peter KURNEV
-//             <pkv@irinox>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 
+// File:        GEOMAlgo_FinderShapeOn.cxx
+// Created:     Tue Jan 11 14:44:31 2005
+// Author:      Peter KURNEV
 
 #include <GEOMAlgo_FinderShapeOn.ixx>
 
+#include <Basics_OCCTVersion.hxx>
+
+#if OCC_VERSION_LARGE > 0x06050100 // for OCC-6.5.2 and higher version
+#include <Precision.hxx>
+#endif
+
 #include <gp_Pnt.hxx>
 
 #include <TopAbs_ShapeEnum.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
 #include <TopTools_DataMapOfShapeShape.hxx>
 
+#include <Bnd_Box.hxx>
+#include <BRepBndLib.hxx>
+#include <BRepMesh_IncrementalMesh.hxx>
+
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
 
@@ -347,12 +357,12 @@ void GEOMAlgo_FinderShapeOn::Find(const TopoDS_Shape& aS)
     for (; aIt.More(); aIt.Next()) {
       const TopoDS_Shape& aSImage=aIt.Value(); 
       if (myImages.IsBound(aSImage)) { 
-       const TopoDS_Shape& aSx=myImages.Find(aSImage); 
-       myMSS.Add(aSx, aSts[i]);
+        const TopoDS_Shape& aSx=myImages.Find(aSImage); 
+        myMSS.Add(aSx, aSts[i]);
       }
       else {
-       myErrorStatus=33;// can not find original shape
-       return; 
+        myErrorStatus=33;// can not find original shape
+        return; 
       }
     }
   }
@@ -377,7 +387,11 @@ void GEOMAlgo_FinderShapeOn::MakeArgument1()
   //
   // Argument 1
   if (!myIsAnalytic) {
+#if OCC_VERSION_LARGE > 0x06050100 // for OCC-6.5.2 and higher version
+    aMF.Init(mySurface, Standard_True, Precision::Confusion());
+#else
     aMF.Init(mySurface, Standard_True);
+#endif
     aFErr=aMF.Error();
     if (aFErr!=BRepLib_FaceDone) {
       myErrorStatus=20; // can not build the face
@@ -398,21 +412,21 @@ void GEOMAlgo_FinderShapeOn::MakeArgument1()
       switch (aType) {
       case TopAbs_VERTEX: {
         const TopoDS_Vertex& aVx=TopoDS::Vertex(aS);
-       aBB.UpdateVertex(aVx, myTolerance);
+        aBB.UpdateVertex(aVx, myTolerance);
       }
-       break;
+        break;
       case TopAbs_EDGE: {
         const TopoDS_Edge& aEx=TopoDS::Edge(aS);
-       aBB.UpdateEdge(aEx, myTolerance);
+        aBB.UpdateEdge(aEx, myTolerance);
       }
-       break;
+        break;
       case TopAbs_FACE: {
         const TopoDS_Face& aFx=TopoDS::Face(aS);
-       aBB.UpdateFace(aFx, myTolerance);
+        aBB.UpdateFace(aFx, myTolerance);
       }
-       break;
+        break;
       default:
-       break;
+        break;
       }
     }
   } //  
@@ -463,9 +477,9 @@ void GEOMAlgo_FinderShapeOn::CheckData()
   }
   //
   if (!(myShapeType==TopAbs_VERTEX ||
-       myShapeType==TopAbs_EDGE ||
-       myShapeType==TopAbs_FACE ||
-       myShapeType==TopAbs_SOLID)) {
+        myShapeType==TopAbs_EDGE ||
+        myShapeType==TopAbs_FACE ||
+        myShapeType==TopAbs_SOLID)) {
     myErrorStatus=12; // unallowed subshape type
     return;
   }
@@ -482,9 +496,9 @@ void GEOMAlgo_FinderShapeOn::CheckData()
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_FinderShapeOn::CopySource(const TopoDS_Shape& aE,
-                                       TopTools_DataMapOfShapeShape& aImages,
-                                       TopTools_DataMapOfShapeShape& aOriginals,
-                                       TopoDS_Shape& aEx)
+                                        TopTools_DataMapOfShapeShape& aImages,
+                                        TopTools_DataMapOfShapeShape& aOriginals,
+                                        TopoDS_Shape& aEx)
 {
   Standard_Boolean bFree;
   TopAbs_ShapeEnum aType;
@@ -527,6 +541,58 @@ void GEOMAlgo_FinderShapeOn::CopySource(const TopoDS_Shape& aE,
   //
   aEx.Free(bFree);
 }
+//
+//=======================================================================
+//function : BuildTriangulation
+//purpose  : 
+//=======================================================================
+bool GEOMAlgo_FinderShapeOn::BuildTriangulation (const TopoDS_Shape& theShape)
+{
+  // calculate deflection
+  Standard_Real aDeviationCoefficient = 0.001;
+
+  Bnd_Box B;
+  BRepBndLib::Add(theShape, B);
+  Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
+  B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+
+  Standard_Real dx = aXmax - aXmin, dy = aYmax - aYmin, dz = aZmax - aZmin;
+  Standard_Real aDeflection = Max(Max(dx, dy), dz) * aDeviationCoefficient * 4;
+  Standard_Real aHLRAngle = 0.349066;
+
+  // build triangulation
+  BRepMesh_IncrementalMesh Inc (theShape, aDeflection, Standard_False, aHLRAngle);
+
+  // check triangulation
+  bool isTriangulation = true;
+
+  TopExp_Explorer exp (theShape, TopAbs_FACE);
+  if (exp.More())
+  {
+    TopLoc_Location aTopLoc;
+    Handle(Poly_Triangulation) aTRF;
+    aTRF = BRep_Tool::Triangulation(TopoDS::Face(exp.Current()), aTopLoc);
+    if (aTRF.IsNull()) {
+      isTriangulation = false;
+    }
+  }
+  else // no faces, try edges
+  {
+    TopExp_Explorer expe (theShape, TopAbs_EDGE);
+    if (!expe.More()) {
+      isTriangulation = false;
+    }
+    else {
+      TopLoc_Location aLoc;
+      Handle(Poly_Polygon3D) aPE = BRep_Tool::Polygon3D(TopoDS::Edge(expe.Current()), aLoc);
+      if (aPE.IsNull()) {
+        isTriangulation = false;
+      }
+    }
+  }
+
+  return isTriangulation;
+}
 
 //
 // myErrorStatus :
@@ -544,4 +610,3 @@ void GEOMAlgo_FinderShapeOn::CopySource(const TopoDS_Shape& aE,
 // myWarningStatus
 //
 // 10 -subshapes of type myShapeType can not be fond in myShape
-