]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAPI/GeomAPI_Vertex.cpp
Salome HOME
Update SketchPlugin_Projection feature (issue #1459)
[modules/shaper.git] / src / GeomAPI / GeomAPI_Vertex.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_Vertex.cpp
4 // Created:     24 Jul 2014
5 // Author:      Artem ZHIDKOV
6
7 #include<GeomAPI_Vertex.h>
8 #include<GeomAPI_Pnt.h>
9
10 #include <TopoDS_Shape.hxx>
11 #include <TopoDS_Edge.hxx>
12 #include <TopoDS.hxx>
13 #include <TopoDS_Vertex.hxx>
14 #include <BRep_Tool.hxx>
15 #include <BRep_Builder.hxx>
16 #include <gp_Pnt.hxx>
17 #include <Precision.hxx>
18
19 GeomAPI_Vertex::GeomAPI_Vertex()
20   : GeomAPI_Shape()
21 {
22 }
23
24 GeomAPI_Vertex::GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape)
25 {
26   if (!theShape->isNull() && theShape->isVertex()) {
27     setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
28   }
29 }
30
31 GeomAPI_Vertex::GeomAPI_Vertex(double theX, double theY, double theZ)
32 {
33   TopoDS_Vertex aVertex;
34   BRep_Builder aBuilder;
35   aBuilder.MakeVertex(aVertex, gp_Pnt(theX, theY, theZ), Precision::Confusion());
36   setImpl(new TopoDS_Shape(aVertex));
37 }
38
39 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Vertex::point()
40 {
41   const TopoDS_Shape& aShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
42   TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);
43   gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
44   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
45 }
46
47 bool GeomAPI_Vertex::isEqual(const std::shared_ptr<GeomAPI_Shape> theVert) const
48 {
49   if (!theVert.get() || ! theVert->isVertex())
50     return false;
51   const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
52   const TopoDS_Shape& aInShape = theVert->impl<TopoDS_Shape>();
53
54   if (aMyShape.ShapeType() != aInShape.ShapeType())
55     return false;
56
57   TopoDS_Vertex aVertex1 = TopoDS::Vertex(aMyShape);
58   gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex1);
59
60   TopoDS_Vertex aVertex2 = TopoDS::Vertex(aInShape);
61   gp_Pnt aPoint2 = BRep_Tool::Pnt(aVertex2);
62
63   return aPoint1.IsEqual(aPoint2, Precision::Confusion()) == Standard_True;
64 }