]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp
Salome HOME
Added option to create Construction Point by intersection of line and plane.
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_PointBuilder.cpp
index 1c7e51bb733736e6a38729c46e5475da71890640..e7414346d08c7f64a1aa29025c088ba04a39a8e0 100644 (file)
@@ -116,23 +116,16 @@ std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByProjection(
     return aVertex;
   }
 
-  std::shared_ptr<GeomAPI_Pnt> aGeomPnt = theVertex->point();
-  gp_Pnt aPnt = aGeomPnt->impl<gp_Pnt>();
+  std::shared_ptr<GeomAPI_Pnt> aProjPnt = theVertex->point();
+  std::shared_ptr<GeomAPI_Pln> aProjPln = thePlane->getPlane();
 
-  std::shared_ptr<GeomAPI_Pln> aGeomPln = thePlane->getPlane();
-  gp_Pln aPln = aGeomPln->impl<gp_Pln>();
+  std::shared_ptr<GeomAPI_Pnt> aPnt = aProjPln->project(aProjPnt);
 
-  gp_Dir aPntAxis = aPnt.XYZ() - aPln.Location().XYZ();
-  gp_Dir aPlnNorm = aPln.Axis().Direction();
-
-  if(aPntAxis * aPlnNorm > 0) {
-    aPlnNorm.Reverse();
+  if(!aPnt.get()) {
+    return aVertex;
   }
 
-  double aDistance = aPln.Distance(aPnt);
-  aPnt.Translate(gp_Vec(aPlnNorm) * aDistance);
-
-  aVertex.reset(new GeomAPI_Vertex(aPnt.X(), aPnt.Y(), aPnt.Z()));
+  aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
 
   return aVertex;
 }
@@ -161,3 +154,28 @@ std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByIntersection(
 
   return aVertex;
 }
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByIntersection(
+    const std::shared_ptr<GeomAPI_Edge> theEdge,
+    const std::shared_ptr<GeomAPI_Face> theFace)
+{
+  std::shared_ptr<GeomAPI_Vertex> aVertex;
+
+  if(!theEdge.get() || !theFace.get() || !theEdge->isLine() || !theFace->isPlanar()) {
+    return aVertex;
+  }
+
+  std::shared_ptr<GeomAPI_Lin> aLin = theEdge->line();
+  std::shared_ptr<GeomAPI_Pln> aPln = theFace->getPlane();
+
+  std::shared_ptr<GeomAPI_Pnt> aPnt = aPln->intersect(aLin);
+
+  if(!aPnt.get()) {
+    return aVertex;
+  }
+
+  aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
+
+  return aVertex;
+}