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