]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
Salome HOME
Merge branch 'Dev_2.8.0'
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeTools.cpp
index 443437126dc064a18e4054345574a02ef5c2c9d0..04ae892e351dcb00e8e2ede067e17185042ca8fe 100644 (file)
@@ -44,6 +44,7 @@
 #include <BRepGProp.hxx>
 #include <BRepTools.hxx>
 #include <BRepTopAdaptor_FClass2d.hxx>
+#include <BRepClass_FaceClassifier.hxx>
 #include <Geom2d_Curve.hxx>
 #include <Geom2d_Curve.hxx>
 #include <BRepLib_CheckCurveOnSurface.hxx>
@@ -53,6 +54,7 @@
 #include <GeomAPI_ProjectPointOnCurve.hxx>
 #include <GeomLib_IsPlanarSurface.hxx>
 #include <GeomLib_Tool.hxx>
+#include <GeomAPI_ExtremaCurveSurface.hxx>
 #include <gp_Pln.hxx>
 #include <GProp_GProps.hxx>
 #include <IntAna_IntConicQuad.hxx>
@@ -70,6 +72,7 @@
 #include <TopExp_Explorer.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 
+
 #include <BOPAlgo_Builder.hxx>
 #include <BRepBuilderAPI_MakeVertex.hxx>
 #include <TopoDS_Edge.hxx>
@@ -746,6 +749,50 @@ bool GeomAlgoAPI_ShapeTools::isParallel(const std::shared_ptr<GeomAPI_Edge> theE
   return anExt.IsParallel() == Standard_True;
 }
 
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_ShapeTools::intersect(
+  const std::shared_ptr<GeomAPI_Edge> theEdge, const std::shared_ptr<GeomAPI_Face> theFace)
+{
+  if(!theEdge.get() || !theFace.get()) {
+    return std::shared_ptr<GeomAPI_Vertex>();
+  }
+
+  TopoDS_Edge anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
+  double aFirstOnCurve, aLastOnCurve;
+  Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirstOnCurve, aLastOnCurve);
+
+  TopoDS_Face aFace  = TopoDS::Face(theFace->impl<TopoDS_Shape>());
+  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+
+  GeomAPI_ExtremaCurveSurface anExt(aCurve, aSurf);
+  // searching for the best point-intersection
+  int aMaxLevel = 0;
+  gp_Pnt aResult;
+  for(int anIntNum = 1; anIntNum <= anExt.NbExtrema(); anIntNum++) {
+    if (anExt.Distance(anIntNum) > Precision::Confusion())
+      continue;
+    Standard_Real aW, aU, aV;
+    anExt.Parameters(anIntNum, aW, aU, aV);
+    gp_Pnt2d aPointOfSurf(aU, aV);
+    // level of the intersection: if it is inside of edge and/or face the level is higher
+    int aIntLevel = aW > aFirstOnCurve && aW < aLastOnCurve ? 2 : 1;
+    BRepClass_FaceClassifier aFClass(aFace, aPointOfSurf, Precision::Confusion());
+    if (aFClass.State() == TopAbs_IN) // "in" is better than "on"
+      aIntLevel += 2;
+    else if (aFClass.State() == TopAbs_ON)
+      aIntLevel += 1;
+    if (aMaxLevel < aIntLevel) {
+      aMaxLevel = anIntNum;
+      anExt.Points(anIntNum, aResult, aResult);
+    }
+  }
+  if (aMaxLevel > 0) { // intersection found
+    return std::shared_ptr<GeomAPI_Vertex>(
+      new GeomAPI_Vertex(aResult.X(), aResult.Y(), aResult.Z()));
+  }
+  return std::shared_ptr<GeomAPI_Vertex>(); // no intersection found
+}
+
 //==================================================================================================
 void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
                                       const GeomAlgoAPI_ShapeTools::PointToRefsMap& thePointsInfo,
@@ -887,4 +934,4 @@ std::shared_ptr<GeomAPI_Dir> GeomAlgoAPI_ShapeTools::buildDirFromAxisAndShape(
                                                     aCentreOfMassPoint.Y()-aPoint.Y(),
                                                     aCentreOfMassPoint.Z()-aPoint.Z()));
   return aDir;
-}
\ No newline at end of file
+}