Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom.git into Dev_0.6.1
[modules/shaper.git] / src / GeomAPI / GeomAPI_Pnt.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_Pnt.cpp
4 // Created:     23 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include<GeomAPI_Pnt.h>
8 #include<GeomAPI_XYZ.h>
9 #include<GeomAPI_Pnt2d.h>
10 #include<GeomAPI_Dir.h>
11 #include<GeomAPI_Pln.h>
12
13 #include<gp_Pnt.hxx>
14 #include<gp_Pln.hxx>
15 #include<ProjLib.hxx>
16
17 #define MY_PNT static_cast<gp_Pnt*>(myImpl)
18
19 GeomAPI_Pnt::GeomAPI_Pnt(const double theX, const double theY, const double theZ)
20     : GeomAPI_Interface(new gp_Pnt(theX, theY, theZ))
21 {
22 }
23
24 GeomAPI_Pnt::GeomAPI_Pnt(const std::shared_ptr<GeomAPI_XYZ>& theCoords)
25     : GeomAPI_Interface(new gp_Pnt(theCoords->x(), theCoords->y(), theCoords->z()))
26 {
27 }
28
29 double GeomAPI_Pnt::x() const
30 {
31   return MY_PNT->X();
32 }
33
34 double GeomAPI_Pnt::y() const
35 {
36   return MY_PNT->Y();
37 }
38
39 double GeomAPI_Pnt::z() const
40 {
41   return MY_PNT->Z();
42 }
43
44 void GeomAPI_Pnt::setX(const double theX)
45 {
46   return MY_PNT->SetX(theX);
47 }
48
49 void GeomAPI_Pnt::setY(const double theY)
50 {
51   return MY_PNT->SetY(theY);
52 }
53
54 void GeomAPI_Pnt::setZ(const double theZ)
55 {
56   return MY_PNT->SetZ(theZ);
57 }
58
59 const std::shared_ptr<GeomAPI_XYZ> GeomAPI_Pnt::xyz()
60 {
61   return std::shared_ptr<GeomAPI_XYZ>(new GeomAPI_XYZ(MY_PNT->X(), MY_PNT->Y(), MY_PNT->Z()));
62 }
63
64 double GeomAPI_Pnt::distance(const std::shared_ptr<GeomAPI_Pnt>& theOther) const
65 {
66   return MY_PNT->Distance(theOther->impl<gp_Pnt>());
67 }
68
69 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Pnt::to2D(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
70   const std::shared_ptr<GeomAPI_Dir>& theDirX, const std::shared_ptr<GeomAPI_Dir>& theDirY)
71 {
72   gp_Pnt anOriginPnt(theOrigin->x(), theOrigin->y(), theOrigin->z());
73   gp_Vec aVec(anOriginPnt, impl<gp_Pnt>());
74
75   double aX = aVec.X() * theDirX->x() + aVec.Y() * theDirX->y() + aVec.Z() * theDirX->z();
76   double aY = aVec.X() * theDirY->x() + aVec.Y() * theDirY->y() + aVec.Z() * theDirY->z();
77   return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
78 }
79
80
81 void GeomAPI_Pnt::translate(const std::shared_ptr<GeomAPI_Dir>& theDir, double theDist)
82 {
83   gp_Vec aVec(theDir->impl<gp_Dir>());
84   aVec.Normalize();
85   aVec.Multiply(theDist);
86   MY_PNT->Translate(aVec);
87 }
88
89 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Pnt::to2D(const std::shared_ptr<GeomAPI_Pln>& thePln) const
90 {
91   double aA, aB, aC, aD;
92   thePln->coefficients(aA, aB, aC, aD);
93   gp_Pln aPln(aA, aB, aC, aD);
94
95   gp_Pnt2d aRes = ProjLib::Project(aPln, *MY_PNT);
96   return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aRes.X(), aRes.Y()));
97 }