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_Trsf.h>
23 #include <GeomAPI_Ax1.h>
24 #include <GeomAPI_Ax2.h>
28 #include <gp_GTrsf.hxx>
29 #include <gp_Trsf.hxx>
31 #define MY_TRSF implPtr<gp_Trsf>()
35 //=================================================================================================
36 GeomAPI_Trsf::GeomAPI_Trsf()
37 : GeomAPI_Interface(new gp_Trsf())
41 //=================================================================================================
42 GeomAPI_Trsf::GeomAPI_Trsf(void* theTrsf)
43 : GeomAPI_Interface((gp_Trsf*)theTrsf)
47 //=================================================================================================
48 void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
49 const double theDistance)
51 MY_TRSF->SetTranslation(gp_Vec(theAxis->impl<gp_Ax1>().Direction()) * theDistance);
54 //=================================================================================================
55 void GeomAPI_Trsf::setTranslation(const double theDx, const double theDy, const double theDz)
57 MY_TRSF->SetTranslation(gp_Vec(theDx, theDy, theDz));
60 //=================================================================================================
61 void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
62 const std::shared_ptr<GeomAPI_Pnt> theEndPoint)
64 MY_TRSF->SetTranslation(theStartPoint->impl<gp_Pnt>(), theEndPoint->impl<gp_Pnt>());
67 //=================================================================================================
68 void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
69 const double theAngle)
71 MY_TRSF->SetRotation(theAxis->impl<gp_Ax1>(), theAngle / 180.0 * M_PI);
74 //=================================================================================================
75 void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
76 const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
77 const std::shared_ptr<GeomAPI_Pnt> theEndPoint)
79 gp_Pnt aCenterPoint = theCenterPoint->impl<gp_Pnt>();
80 gp_Pnt aStartPoint = theStartPoint->impl<gp_Pnt>();
81 gp_Pnt aEndPoint = theEndPoint->impl<gp_Pnt>();
83 gp_Vec aVec1(aCenterPoint, aStartPoint);
84 gp_Vec aVec2(aCenterPoint, aEndPoint);
85 gp_Dir aDir(aVec1 ^ aVec2);
86 gp_Ax1 anAxis(aCenterPoint, aDir);
87 double anAngle = aVec1.Angle(aVec2);
88 if (fabs(anAngle) < Precision::Angular()) anAngle += 2.*M_PI; // Taken from old GEOM code
90 MY_TRSF->SetRotation(anAxis, anAngle);
93 //=================================================================================================
94 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Pnt> thePoint)
96 MY_TRSF->SetMirror(thePoint->impl<gp_Pnt>());
99 //=================================================================================================
100 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Ax1> theAxis)
102 MY_TRSF->SetMirror(theAxis->impl<gp_Ax1>());
105 //=================================================================================================
106 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Ax2> thePlane)
108 MY_TRSF->SetMirror(thePlane->impl<gp_Ax2>());