Salome HOME
892869a4c9a7f4593af69285648478443bb49e07
[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> theNorm)
29 : GeomAPI_Interface(new gp_Ax3(theOrigin->impl<gp_Pnt>(), 
30                                theNorm->impl<gp_Dir>(), 
31                                theDirX->impl<gp_Dir>()))
32  {
33  }
34
35 void GeomAPI_Ax3::setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin)
36 {
37   gp_Ax1 aAx1 = MY_AX3->Axis();
38   aAx1.SetLocation(theOrigin->impl<gp_Pnt>());
39   MY_AX3->SetAxis(aAx1);
40 }
41
42 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::origin() const
43 {
44   gp_Pnt aPnt = MY_AX3->Axis().Location();
45   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(),aPnt.Y(),aPnt.Z()));
46 }
47
48 void GeomAPI_Ax3::setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX)
49 {
50   MY_AX3->SetXDirection(theDirX->impl<gp_Dir>());
51 }
52
53 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirX() const
54 {
55   gp_Dir aDir = MY_AX3->XDirection();
56   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
57 }
58
59 void GeomAPI_Ax3::setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY)
60 {
61   MY_AX3->SetYDirection(theDirY->impl<gp_Dir>());
62 }
63
64 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirY() const
65 {
66   gp_Dir aDir = MY_AX3->YDirection();
67   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
68 }
69
70 void GeomAPI_Ax3::setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm)
71 {
72   gp_Ax1 aAx1 = MY_AX3->Axis();
73   aAx1.SetDirection(theNorm->impl<gp_Dir>());
74   MY_AX3->SetAxis(aAx1);
75 }
76
77 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::norm() const
78 {
79   gp_Dir aDir = MY_AX3->Axis().Direction();
80   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(),aDir.Y(),aDir.Z()));
81 }
82
83
84 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::to3D(double theX, double theY) const
85 {
86   gp_Pnt aPnt = MY_AX3->Axis().Location();
87   gp_Dir aXDir = MY_AX3->XDirection();
88   gp_Dir aYDir = MY_AX3->YDirection();
89   gp_XYZ aSum = aPnt.XYZ().Added(aXDir.XYZ().Multiplied(theX)).Added(aYDir.XYZ().Multiplied(theY));
90
91   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum.X(), aSum.Y(), aSum.Z()));
92 }
93
94 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Ax3::to2D(double theX, double theY, double theZ) const
95 {
96   gp_Pnt anOriginPnt = MY_AX3->Axis().Location();
97   gp_Vec aVec(anOriginPnt, gp_Pnt(0, 0, 0));
98
99   gp_Dir aXDir = MY_AX3->XDirection();
100   gp_Dir aYDir = MY_AX3->YDirection();
101
102   double aX = aVec.X() * aXDir.X() + aVec.Y() * aXDir.Y() + aVec.Z() * aXDir.Z();
103   double aY = aVec.X() * aYDir.X() + aVec.Y() * aYDir.Y() + aVec.Z() * aYDir.Y();
104   return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
105 }