Salome HOME
8ba33909daef2c8b1c3b1a94cdc78a4f95314d29
[modules/shaper.git] / src / GeomAPI / GeomAPI_Trsf.cpp
1 // Copyright (C) 2014-2022  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_Trsf.h>
21
22 #include <GeomAPI_Ax1.h>
23 #include <GeomAPI_Ax2.h>
24
25 #include <gp_Ax1.hxx>
26 #include <gp_Ax2.hxx>
27 #include <gp_GTrsf.hxx>
28 #include <gp_Trsf.hxx>
29
30 #define MY_TRSF implPtr<gp_Trsf>()
31
32 #include <iostream>
33
34 //=================================================================================================
35 GeomAPI_Trsf::GeomAPI_Trsf()
36 : GeomAPI_Interface(new gp_Trsf())
37 {
38 }
39
40 //=================================================================================================
41 GeomAPI_Trsf::GeomAPI_Trsf(void* theTrsf)
42 : GeomAPI_Interface((gp_Trsf*)theTrsf)
43 {
44 }
45
46 //=================================================================================================
47 void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
48                                   const double theDistance)
49 {
50   MY_TRSF->SetTranslation(gp_Vec(theAxis->impl<gp_Ax1>().Direction()) * theDistance);
51 }
52
53 //=================================================================================================
54 void GeomAPI_Trsf::setTranslation(const double theDx, const double theDy, const double theDz)
55 {
56   MY_TRSF->SetTranslation(gp_Vec(theDx, theDy, theDz));
57 }
58
59 //=================================================================================================
60 void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
61                                   const std::shared_ptr<GeomAPI_Pnt> theEndPoint)
62 {
63   MY_TRSF->SetTranslation(theStartPoint->impl<gp_Pnt>(), theEndPoint->impl<gp_Pnt>());
64 }
65
66 //=================================================================================================
67 void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
68                                const double theAngle)
69 {
70   MY_TRSF->SetRotation(theAxis->impl<gp_Ax1>(), theAngle / 180.0 * M_PI);
71 }
72
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)
77 {
78   gp_Pnt aCenterPoint = theCenterPoint->impl<gp_Pnt>();
79   gp_Pnt aStartPoint = theStartPoint->impl<gp_Pnt>();
80   gp_Pnt aEndPoint = theEndPoint->impl<gp_Pnt>();
81
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
88
89   MY_TRSF->SetRotation(anAxis, anAngle);
90 }
91
92 //=================================================================================================
93 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Pnt> thePoint)
94 {
95   MY_TRSF->SetMirror(thePoint->impl<gp_Pnt>());
96 }
97
98 //=================================================================================================
99 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Ax1> theAxis)
100 {
101   MY_TRSF->SetMirror(theAxis->impl<gp_Ax1>());
102 }
103
104 //=================================================================================================
105 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Ax2> thePlane)
106 {
107   MY_TRSF->SetMirror(thePlane->impl<gp_Ax2>());
108 }
109
110 //=================================================================================================
111 void GeomAPI_Trsf::setScale(const std::shared_ptr<GeomAPI_Pnt>& theCenter,
112                             const double theScale)
113 {
114   MY_TRSF->SetScale(theCenter->impl<gp_Pnt>(), theScale);
115 }