1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GeomAPI_Ax3.h"
21 #include "GeomAPI_XYZ.h"
22 #include "GeomAPI_Pnt2d.h"
27 #include <Precision.hxx>
30 #define MY_AX3 implPtr<gp_Ax3>()
33 GeomAPI_Ax3::GeomAPI_Ax3()
34 : GeomAPI_Interface(new gp_Ax3())
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>()))
47 void GeomAPI_Ax3::setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin)
49 gp_Ax1 aAx1 = MY_AX3->Axis();
50 aAx1.SetLocation(theOrigin->impl<gp_Pnt>());
51 MY_AX3->SetAxis(aAx1);
54 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::origin() const
56 gp_Pnt aPnt = MY_AX3->Axis().Location();
57 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(),aPnt.Y(),aPnt.Z()));
60 void GeomAPI_Ax3::setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX)
62 MY_AX3->SetXDirection(theDirX->impl<gp_Dir>());
65 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirX() const
67 gp_Dir aDir = MY_AX3->XDirection();
68 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
71 void GeomAPI_Ax3::setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY)
73 MY_AX3->SetYDirection(theDirY->impl<gp_Dir>());
76 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirY() const
78 gp_Dir aDir = MY_AX3->YDirection();
79 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
82 void GeomAPI_Ax3::setNormal(const std::shared_ptr<GeomAPI_Dir>& theNorm)
84 gp_Ax1 aAx1 = MY_AX3->Axis();
85 aAx1.SetDirection(theNorm->impl<gp_Dir>());
86 MY_AX3->SetAxis(aAx1);
89 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::normal() const
91 gp_Dir aDir = MY_AX3->Axis().Direction();
92 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(),aDir.Y(),aDir.Z()));
96 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::to3D(double theX, double theY) const
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));
103 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum.X(), aSum.Y(), aSum.Z()));
106 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Ax3::to2D(double theX, double theY, double theZ) const
108 gp_Pnt anOriginPnt = MY_AX3->Axis().Location();
109 gp_Vec aVec(anOriginPnt, gp_Pnt(theX, theY, theZ));
111 gp_Dir aXDir = MY_AX3->XDirection();
112 gp_Dir aYDir = MY_AX3->YDirection();
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));