]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAPI/GeomAPI_Trsf.cpp
Salome HOME
Improve movement of single point of a constrained feature.
[modules/shaper.git] / src / GeomAPI / GeomAPI_Trsf.cpp
1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_Trsf.cpp
4 // Created:     13 Jul 2015
5 // Author:      Mikhail PONIKAROV
6 //
7 // Modified by Clarisse Genrault (CEA) : 17 Nov 2016
8
9 #include<GeomAPI_Trsf.h>
10
11 #include <GeomAPI_Ax1.h>
12 #include <GeomAPI_Ax2.h>
13
14 #include <gp_Ax1.hxx>
15 #include <gp_Ax2.hxx>
16 #include <gp_Trsf.hxx>
17
18 #define MY_TRSF implPtr<gp_Trsf>()
19
20 #include <iostream>
21
22 //=================================================================================================
23 GeomAPI_Trsf::GeomAPI_Trsf()
24 : GeomAPI_Interface(new gp_Trsf())
25 {
26 }
27
28 //=================================================================================================
29 GeomAPI_Trsf::GeomAPI_Trsf(void* theTrsf)
30 : GeomAPI_Interface(theTrsf)
31 {
32 }
33
34 //=================================================================================================
35 void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
36                                   const double theDistance)
37 {
38   MY_TRSF->SetTranslation(gp_Vec(theAxis->impl<gp_Ax1>().Direction()) * theDistance);
39 }
40
41 //=================================================================================================
42 void GeomAPI_Trsf::setTranslation(const double theDx, const double theDy, const double theDz)
43 {
44   MY_TRSF->SetTranslation(gp_Vec(theDx, theDy, theDz));
45 }
46
47 //=================================================================================================
48 void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
49                                   const std::shared_ptr<GeomAPI_Pnt> theEndPoint)
50 {
51   MY_TRSF->SetTranslation(theStartPoint->impl<gp_Pnt>(), theEndPoint->impl<gp_Pnt>());
52 }
53
54 //=================================================================================================
55 void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
56                                const double theAngle)
57 {
58   MY_TRSF->SetRotation(theAxis->impl<gp_Ax1>(), theAngle / 180.0 * M_PI);
59 }
60
61 //=================================================================================================
62 void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
63                                const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
64                                const std::shared_ptr<GeomAPI_Pnt> theEndPoint)
65 {
66   gp_Pnt aCenterPoint = theCenterPoint->impl<gp_Pnt>();
67   gp_Pnt aStartPoint = theStartPoint->impl<gp_Pnt>();
68   gp_Pnt aEndPoint = theEndPoint->impl<gp_Pnt>();
69
70   gp_Vec aVec1(aCenterPoint, aStartPoint);
71   gp_Vec aVec2(aCenterPoint, aEndPoint);
72   gp_Dir aDir(aVec1 ^ aVec2);
73   gp_Ax1 anAxis(aCenterPoint, aDir);
74   double anAngle = aVec1.Angle(aVec2);
75   if (fabs(anAngle) < Precision::Angular()) anAngle += 2.*M_PI; // Taken from old GEOM code
76
77   MY_TRSF->SetRotation(anAxis, anAngle);
78 }
79
80 //=================================================================================================
81 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Pnt> thePoint)
82 {
83   MY_TRSF->SetMirror(thePoint->impl<gp_Pnt>());
84 }
85
86 //=================================================================================================
87 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Ax1> theAxis)
88 {
89   MY_TRSF->SetMirror(theAxis->impl<gp_Ax1>());
90 }
91
92 //=================================================================================================
93 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Ax2> thePlane)
94 {
95   MY_TRSF->SetMirror(thePlane->impl<gp_Ax2>());
96 }