Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / GeomAPI / GeomAPI_Ax3.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_Ax3.h"
22 #include "GeomAPI_XYZ.h"
23 #include "GeomAPI_Pnt2d.h"
24
25 #include <gp_Dir.hxx>
26 #include <gp_Pnt.hxx>
27 #include <gp_Ax3.hxx>
28 #include <Precision.hxx>
29
30
31 #define MY_AX3 implPtr<gp_Ax3>()
32
33
34 GeomAPI_Ax3::GeomAPI_Ax3()
35 : GeomAPI_Interface(new gp_Ax3())
36 {
37 }
38
39 GeomAPI_Ax3::GeomAPI_Ax3(std::shared_ptr<GeomAPI_Pnt> theOrigin,
40                          std::shared_ptr<GeomAPI_Dir> theDirX,
41                          std::shared_ptr<GeomAPI_Dir> theNorm)
42 : GeomAPI_Interface(new gp_Ax3(theOrigin->impl<gp_Pnt>(),
43                                theNorm->impl<gp_Dir>(),
44                                theDirX->impl<gp_Dir>()))
45  {
46  }
47
48 void GeomAPI_Ax3::setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin)
49 {
50   gp_Ax1 aAx1 = MY_AX3->Axis();
51   aAx1.SetLocation(theOrigin->impl<gp_Pnt>());
52   MY_AX3->SetAxis(aAx1);
53 }
54
55 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::origin() const
56 {
57   gp_Pnt aPnt = MY_AX3->Axis().Location();
58   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(),aPnt.Y(),aPnt.Z()));
59 }
60
61 void GeomAPI_Ax3::setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX)
62 {
63   MY_AX3->SetXDirection(theDirX->impl<gp_Dir>());
64 }
65
66 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirX() const
67 {
68   gp_Dir aDir = MY_AX3->XDirection();
69   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
70 }
71
72 void GeomAPI_Ax3::setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY)
73 {
74   MY_AX3->SetYDirection(theDirY->impl<gp_Dir>());
75 }
76
77 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirY() const
78 {
79   gp_Dir aDir = MY_AX3->YDirection();
80   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
81 }
82
83 void GeomAPI_Ax3::setNormal(const std::shared_ptr<GeomAPI_Dir>& theNorm)
84 {
85   gp_Ax1 aAx1 = MY_AX3->Axis();
86   aAx1.SetDirection(theNorm->impl<gp_Dir>());
87   MY_AX3->SetAxis(aAx1);
88 }
89
90 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::normal() const
91 {
92   gp_Dir aDir = MY_AX3->Axis().Direction();
93   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(),aDir.Y(),aDir.Z()));
94 }
95
96
97 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::to3D(double theX, double theY) const
98 {
99   gp_Pnt aPnt = MY_AX3->Axis().Location();
100   gp_Dir aXDir = MY_AX3->XDirection();
101   gp_Dir aYDir = MY_AX3->YDirection();
102   gp_XYZ aSum = aPnt.XYZ().Added(aXDir.XYZ().Multiplied(theX)).Added(aYDir.XYZ().Multiplied(theY));
103
104   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum.X(), aSum.Y(), aSum.Z()));
105 }
106
107 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Ax3::to2D(double theX, double theY, double theZ) const
108 {
109   gp_Pnt anOriginPnt = MY_AX3->Axis().Location();
110   gp_Vec aVec(anOriginPnt, gp_Pnt(0, 0, 0));
111
112   gp_Dir aXDir = MY_AX3->XDirection();
113   gp_Dir aYDir = MY_AX3->YDirection();
114
115   double aX = aVec.X() * aXDir.X() + aVec.Y() * aXDir.Y() + aVec.Z() * aXDir.Z();
116   double aY = aVec.X() * aYDir.X() + aVec.Y() * aYDir.Y() + aVec.Z() * aYDir.Y();
117   return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
118 }