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_Trsf.h>
22 #include <GeomAPI_Ax1.h>
23 #include <GeomAPI_Ax2.h>
27 #include <gp_GTrsf.hxx>
28 #include <gp_Trsf.hxx>
30 #define MY_TRSF implPtr<gp_Trsf>()
34 //=================================================================================================
35 GeomAPI_Trsf::GeomAPI_Trsf()
36 : GeomAPI_Interface(new gp_Trsf())
40 //=================================================================================================
41 GeomAPI_Trsf::GeomAPI_Trsf(void* theTrsf)
42 : GeomAPI_Interface((gp_Trsf*)theTrsf)
46 //=================================================================================================
47 void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
48 const double theDistance)
50 MY_TRSF->SetTranslation(gp_Vec(theAxis->impl<gp_Ax1>().Direction()) * theDistance);
53 //=================================================================================================
54 void GeomAPI_Trsf::setTranslation(const double theDx, const double theDy, const double theDz)
56 MY_TRSF->SetTranslation(gp_Vec(theDx, theDy, theDz));
59 //=================================================================================================
60 void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
61 const std::shared_ptr<GeomAPI_Pnt> theEndPoint)
63 MY_TRSF->SetTranslation(theStartPoint->impl<gp_Pnt>(), theEndPoint->impl<gp_Pnt>());
66 //=================================================================================================
67 void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
68 const double theAngle)
70 MY_TRSF->SetRotation(theAxis->impl<gp_Ax1>(), theAngle / 180.0 * M_PI);
73 //=================================================================================================
74 void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
75 const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
76 const std::shared_ptr<GeomAPI_Pnt> theEndPoint)
78 gp_Pnt aCenterPoint = theCenterPoint->impl<gp_Pnt>();
79 gp_Pnt aStartPoint = theStartPoint->impl<gp_Pnt>();
80 gp_Pnt aEndPoint = theEndPoint->impl<gp_Pnt>();
82 gp_Vec aVec1(aCenterPoint, aStartPoint);
83 gp_Vec aVec2(aCenterPoint, aEndPoint);
84 gp_Dir aDir(aVec1 ^ aVec2);
85 gp_Ax1 anAxis(aCenterPoint, aDir);
86 double anAngle = aVec1.Angle(aVec2);
87 if (fabs(anAngle) < Precision::Angular()) anAngle += 2.*M_PI; // Taken from old GEOM code
89 MY_TRSF->SetRotation(anAxis, anAngle);
92 //=================================================================================================
93 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Pnt> thePoint)
95 MY_TRSF->SetMirror(thePoint->impl<gp_Pnt>());
98 //=================================================================================================
99 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Ax1> theAxis)
101 MY_TRSF->SetMirror(theAxis->impl<gp_Ax1>());
104 //=================================================================================================
105 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Ax2> thePlane)
107 MY_TRSF->SetMirror(thePlane->impl<gp_Ax2>());