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