Salome HOME
Partition naming
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_PointBuilder.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_PointBuilder.cpp
4 // Created:     02 Jun 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include <GeomAlgoAPI_PointBuilder.h>
8 #include <GeomAPI_Pnt.h>
9 #include <GeomAPI_Shape.h>
10 #include <GeomAPI_Vertex.h>
11 #include <BRepBuilderAPI_MakeVertex.hxx>
12 #include <BRep_Tool.hxx>
13 #include <TopoDS_Vertex.hxx>
14 #include <TopoDS.hxx>
15 #include <gp_Pnt.hxx>
16
17 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_PointBuilder::point(
18     std::shared_ptr<GeomAPI_Pnt> thePoint)
19 {
20   const gp_Pnt& aPnt = thePoint->impl<gp_Pnt>();
21   BRepBuilderAPI_MakeVertex aMaker(aPnt);
22   TopoDS_Vertex aVertex = aMaker.Vertex();
23   std::shared_ptr<GeomAPI_Vertex> aRes(new GeomAPI_Vertex);
24   aRes->setImpl(new TopoDS_Shape(aVertex));
25   return aRes;
26 }
27
28 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_PointBuilder::point(
29     const double theX, const double theY, const double theZ)
30 {
31   const gp_Pnt aPnt(theX, theY, theZ);
32   BRepBuilderAPI_MakeVertex aMaker(aPnt);
33   TopoDS_Vertex aVertex = aMaker.Vertex();
34   std::shared_ptr<GeomAPI_Vertex> aRes(new GeomAPI_Vertex);
35   aRes->setImpl(new TopoDS_Shape(aVertex));
36   return aRes;
37 }
38
39 std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_PointBuilder::point(std::shared_ptr<GeomAPI_Shape> theVertex)
40 {
41   TopoDS_Shape aShape = theVertex->impl<TopoDS_Shape>();
42   if ((!aShape.IsNull()) && (aShape.ShapeType() == TopAbs_VERTEX)) {
43     TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);
44     gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
45     std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
46     return aPnt;
47   }
48   return std::shared_ptr<GeomAPI_Pnt>();
49 }