Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / GeomAPI / GeomAPI_Vertex.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include<GeomAPI_Vertex.h>
22 #include<GeomAPI_Pnt.h>
23
24 #include <TopoDS_Shape.hxx>
25 #include <TopoDS_Edge.hxx>
26 #include <TopoDS.hxx>
27 #include <TopoDS_Vertex.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRep_Builder.hxx>
30 #include <gp_Pnt.hxx>
31 #include <Precision.hxx>
32
33 GeomAPI_Vertex::GeomAPI_Vertex()
34   : GeomAPI_Shape()
35 {
36 }
37
38 GeomAPI_Vertex::GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape)
39 {
40   if (!theShape->isNull() && theShape->isVertex()) {
41     setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
42   }
43 }
44
45 GeomAPI_Vertex::GeomAPI_Vertex(double theX, double theY, double theZ)
46 {
47   TopoDS_Vertex aVertex;
48   BRep_Builder aBuilder;
49   aBuilder.MakeVertex(aVertex, gp_Pnt(theX, theY, theZ), Precision::Confusion());
50   setImpl(new TopoDS_Shape(aVertex));
51 }
52
53 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Vertex::point()
54 {
55   const TopoDS_Shape& aShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
56   TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);
57   gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
58   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
59 }
60
61 bool GeomAPI_Vertex::isEqual(const std::shared_ptr<GeomAPI_Shape> theVert) const
62 {
63   if (!theVert.get() || ! theVert->isVertex())
64     return false;
65   const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
66   const TopoDS_Shape& aInShape = theVert->impl<TopoDS_Shape>();
67
68   if (aMyShape.ShapeType() != aInShape.ShapeType())
69     return false;
70
71   TopoDS_Vertex aVertex1 = TopoDS::Vertex(aMyShape);
72   gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex1);
73
74   TopoDS_Vertex aVertex2 = TopoDS::Vertex(aInShape);
75   gp_Pnt aPoint2 = BRep_Tool::Pnt(aVertex2);
76
77   return aPoint1.IsEqual(aPoint2, Precision::Confusion()) == Standard_True;
78 }