Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeTools.cpp
index 197569345369b4f7940438fd77cb795223639e05..443437126dc064a18e4054345574a02ef5c2c9d0 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "GeomAlgoAPI_SketchBuilder.h"
 
+#include <GeomAPI_Ax1.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_Face.h>
@@ -47,7 +48,9 @@
 #include <Geom2d_Curve.hxx>
 #include <BRepLib_CheckCurveOnSurface.hxx>
 #include <BRep_Tool.hxx>
+#include <Geom_Line.hxx>
 #include <Geom_Plane.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
 #include <GeomLib_IsPlanarSurface.hxx>
 #include <GeomLib_Tool.hxx>
 #include <gp_Pln.hxx>
@@ -868,3 +871,20 @@ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::findShape(
 
   return aResultShape;
 }
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Dir> GeomAlgoAPI_ShapeTools::buildDirFromAxisAndShape(
+                                    const std::shared_ptr<GeomAPI_Shape> theBaseShape,
+                                    const std::shared_ptr<GeomAPI_Ax1> theAxis)
+{
+  gp_Pnt aCentreOfMassPoint =
+    GeomAlgoAPI_ShapeTools::centreOfMass(theBaseShape)->impl<gp_Pnt>();
+  Handle(Geom_Line) aLine = new Geom_Line(theAxis->impl<gp_Ax1>());
+  GeomAPI_ProjectPointOnCurve aPrjTool(aCentreOfMassPoint, aLine);
+  gp_Pnt aPoint = aPrjTool.NearestPoint();
+
+  std::shared_ptr<GeomAPI_Dir> aDir(new GeomAPI_Dir(aCentreOfMassPoint.X()-aPoint.X(),
+                                                    aCentreOfMassPoint.Y()-aPoint.Y(),
+                                                    aCentreOfMassPoint.Z()-aPoint.Z()));
+  return aDir;
+}
\ No newline at end of file