Salome HOME
Updating Primitive Box.
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_PointBuilder.cpp
index b5db2869b32a40415f0e8b317c584bd4f51f40af..cad4bc3cc01b927fb79fe2d86d32be679d8c75a5 100644 (file)
@@ -26,7 +26,8 @@
 #include <TopoDS_Vertex.hxx>
 
 //==================================================================================================
-std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertex(const std::shared_ptr<GeomAPI_Pnt> thePoint)
+std::shared_ptr<GeomAPI_Vertex>
+  GeomAlgoAPI_PointBuilder::vertex(const std::shared_ptr<GeomAPI_Pnt> thePoint)
 {
   const gp_Pnt& aPnt = thePoint->impl<gp_Pnt>();
   BRepBuilderAPI_MakeVertex aMaker(aPnt);
@@ -50,7 +51,8 @@ std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertex(const double th
 }
 
 //==================================================================================================
-std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_PointBuilder::point(const std::shared_ptr<GeomAPI_Shape> theVertex)
+std::shared_ptr<GeomAPI_Pnt>
+  GeomAlgoAPI_PointBuilder::point(const std::shared_ptr<GeomAPI_Shape> theVertex)
 {
   TopoDS_Shape aShape = theVertex->impl<TopoDS_Shape>();
   if ((!aShape.IsNull()) && (aShape.ShapeType() == TopAbs_VERTEX)) {
@@ -63,10 +65,11 @@ std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_PointBuilder::point(const std::shared_p
 }
 
 //==================================================================================================
-std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexOnEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
-                                                                       const double theValue,
-                                                                       const bool theIsPercent,
-                                                                       const bool theIsReverse)
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexOnEdge(
+                                            const std::shared_ptr<GeomAPI_Edge> theEdge,
+                                            const double theValue,
+                                            const bool theIsPercent,
+                                            const bool theIsReverse)
 {
   std::shared_ptr<GeomAPI_Vertex> aVertex;
 
@@ -116,23 +119,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;
 }
@@ -148,32 +144,41 @@ std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByIntersection(
     return aVertex;
   }
 
-  gp_Lin aLin1 = theEdge1->line()->impl<gp_Lin>();
-  gp_Lin aLin2 = theEdge2->line()->impl<gp_Lin>();
+  std::shared_ptr<GeomAPI_Lin> aLin1 = theEdge1->line();
+  std::shared_ptr<GeomAPI_Lin> aLin2 = theEdge2->line();
+
+  std::shared_ptr<GeomAPI_Pnt> aPnt = aLin1->intersect(aLin2);
 
-  if(aLin1.Distance(aLin2) > Precision::Confusion()) {
+  if(!aPnt.get()) {
     return aVertex;
   }
 
-  Handle(Geom_Line) aLine1 = new Geom_Line(aLin1);
-  Handle(Geom_Line) aLine2 = new Geom_Line(aLin2);
+  aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
 
-  GeomAPI_ExtremaCurveCurve anExtrema(aLine1, aLine2);
+  return aVertex;
+}
 
-  Standard_Integer aNbExtrema = anExtrema.NbExtrema();
+//==================================================================================================
+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(aNbExtrema == 0) {
+  if(!theEdge.get() || !theFace.get() || !theEdge->isLine() || !theFace->isPlanar()) {
     return aVertex;
   }
 
-  gp_Pnt aPnt1, aPnt2;
-  for(Standard_Integer anIndex = 1; anIndex <= aNbExtrema; ++anIndex) {
-    if(anExtrema.Distance(anIndex) <= Precision::Confusion()) {
-      anExtrema.Points(anIndex, aPnt1, aPnt2);
-    }
+  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(aPnt1.X(), aPnt1.Y(), aPnt1.Z()));
+  aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
 
   return aVertex;
 }