1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GeomAPI_Ax3.h"
22 #include "GeomAPI_XYZ.h"
23 #include "GeomAPI_Pnt2d.h"
28 #include <Precision.hxx>
31 #define MY_AX3 implPtr<gp_Ax3>()
34 GeomAPI_Ax3::GeomAPI_Ax3()
35 : GeomAPI_Interface(new gp_Ax3())
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>()))
48 void GeomAPI_Ax3::setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin)
50 gp_Ax1 aAx1 = MY_AX3->Axis();
51 aAx1.SetLocation(theOrigin->impl<gp_Pnt>());
52 MY_AX3->SetAxis(aAx1);
55 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::origin() const
57 gp_Pnt aPnt = MY_AX3->Axis().Location();
58 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(),aPnt.Y(),aPnt.Z()));
61 void GeomAPI_Ax3::setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX)
63 MY_AX3->SetXDirection(theDirX->impl<gp_Dir>());
66 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirX() const
68 gp_Dir aDir = MY_AX3->XDirection();
69 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
72 void GeomAPI_Ax3::setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY)
74 MY_AX3->SetYDirection(theDirY->impl<gp_Dir>());
77 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirY() const
79 gp_Dir aDir = MY_AX3->YDirection();
80 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
83 void GeomAPI_Ax3::setNormal(const std::shared_ptr<GeomAPI_Dir>& theNorm)
85 gp_Ax1 aAx1 = MY_AX3->Axis();
86 aAx1.SetDirection(theNorm->impl<gp_Dir>());
87 MY_AX3->SetAxis(aAx1);
90 std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::normal() const
92 gp_Dir aDir = MY_AX3->Axis().Direction();
93 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(),aDir.Y(),aDir.Z()));
97 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::to3D(double theX, double theY) const
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));
104 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum.X(), aSum.Y(), aSum.Z()));
107 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Ax3::to2D(double theX, double theY, double theZ) const
109 gp_Pnt anOriginPnt = MY_AX3->Axis().Location();
110 gp_Vec aVec(anOriginPnt, gp_Pnt(0, 0, 0));
112 gp_Dir aXDir = MY_AX3->XDirection();
113 gp_Dir aYDir = MY_AX3->YDirection();
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));