Salome HOME
Create SketcherPrs package
[modules/shaper.git] / src / GeomAPI / GeomAPI_Ax3.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_Ax3.cpp
4 // Created:     16 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7
8 #include "GeomAPI_Ax3.h"
9 #include "GeomAPI_XYZ.h"
10 #include "GeomAPI_Pnt2d.h"
11
12 #include <gp_Dir.hxx>
13 #include <gp_Pnt.hxx>
14 #include <gp_Ax3.hxx>
15 #include <Precision.hxx>
16
17
18 #define MY_AX3 static_cast<gp_Ax3*>(myImpl)
19
20
21 GeomAPI_Ax3::GeomAPI_Ax3()
22 : GeomAPI_Interface(new gp_Ax3())
23 {
24 }
25
26 GeomAPI_Ax3::GeomAPI_Ax3(std::shared_ptr<GeomAPI_Pnt> theOrigin,
27                          std::shared_ptr<GeomAPI_Dir> theDirX,
28                          std::shared_ptr<GeomAPI_Dir> theDirY,
29                          std::shared_ptr<GeomAPI_Dir> theNorm)
30 : GeomAPI_Interface(new gp_Ax3(theOrigin->impl<gp_Pnt>(), 
31                                theNorm->impl<gp_Dir>(), 
32                                theDirX->impl<gp_Dir>()))
33  {
34    MY_AX3->SetYDirection(theDirY->impl<gp_Dir>());
35  }
36
37 void GeomAPI_Ax3::setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin)
38 {
39   gp_Ax1 aAx1 = MY_AX3->Axis();
40   aAx1.SetLocation(theOrigin->impl<gp_Pnt>());
41   MY_AX3->SetAxis(aAx1);
42 }
43
44 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::origin() const
45 {
46   gp_Pnt aPnt = MY_AX3->Axis().Location();
47   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(),aPnt.Y(),aPnt.Z()));
48 }
49
50 void GeomAPI_Ax3::setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX)
51 {
52   MY_AX3->SetXDirection(theDirX->impl<gp_Dir>());
53 }
54
55 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirX() const
56 {
57   gp_Dir aDir = MY_AX3->XDirection();
58   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
59 }
60
61 void GeomAPI_Ax3::setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY)
62 {
63   MY_AX3->SetYDirection(theDirY->impl<gp_Dir>());
64 }
65
66 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirY() const
67 {
68   gp_Dir aDir = MY_AX3->YDirection();
69   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
70 }
71
72 void GeomAPI_Ax3::setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm)
73 {
74   gp_Ax1 aAx1 = MY_AX3->Axis();
75   aAx1.SetDirection(theNorm->impl<gp_Dir>());
76   MY_AX3->SetAxis(aAx1);
77 }
78
79 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::norm() const
80 {
81   gp_Dir aDir = MY_AX3->Axis().Direction();
82   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(),aDir.Y(),aDir.Z()));
83 }
84
85
86 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::to3D(double theX, double theY) const
87 {
88   gp_Pnt aPnt = MY_AX3->Axis().Location();
89   gp_Dir aXDir = MY_AX3->XDirection();
90   gp_Dir aYDir = MY_AX3->YDirection();
91   gp_XYZ aSum = aPnt.XYZ().Added(aXDir.XYZ().Multiplied(theX)).Added(aYDir.XYZ().Multiplied(theY));
92
93   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum.X(), aSum.Y(), aSum.Z()));
94 }
95
96 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Ax3::to2D(double theX, double theY, double theZ) const
97 {
98   gp_Pnt anOriginPnt = MY_AX3->Axis().Location();
99   gp_Vec aVec(anOriginPnt, gp_Pnt(0, 0, 0));
100
101   gp_Dir aXDir = MY_AX3->XDirection();
102   gp_Dir aYDir = MY_AX3->YDirection();
103
104   double aX = aVec.X() * aXDir.X() + aVec.Y() * aXDir.Y() + aVec.Z() * aXDir.Z();
105   double aY = aVec.X() * aYDir.X() + aVec.Y() * aYDir.Y() + aVec.Z() * aYDir.Y();
106   return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
107 }