Salome HOME
#2027 Sketcher Trim Feature: 1. preview/selected attributes in trim; 2. avoid includi...
[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_GTrsf.hxx>
17 #include <gp_Trsf.hxx>
18
19 #define MY_TRSF implPtr<gp_Trsf>()
20
21 #include <iostream>
22
23 //=================================================================================================
24 GeomAPI_Trsf::GeomAPI_Trsf()
25 : GeomAPI_Interface(new gp_Trsf())
26 {
27 }
28
29 //=================================================================================================
30 GeomAPI_Trsf::GeomAPI_Trsf(void* theTrsf)
31 : GeomAPI_Interface(theTrsf)
32 {
33 }
34
35 //=================================================================================================
36 void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
37                                   const double theDistance)
38 {
39   MY_TRSF->SetTranslation(gp_Vec(theAxis->impl<gp_Ax1>().Direction()) * theDistance);
40 }
41
42 //=================================================================================================
43 void GeomAPI_Trsf::setTranslation(const double theDx, const double theDy, const double theDz)
44 {
45   MY_TRSF->SetTranslation(gp_Vec(theDx, theDy, theDz));
46 }
47
48 //=================================================================================================
49 void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
50                                   const std::shared_ptr<GeomAPI_Pnt> theEndPoint)
51 {
52   MY_TRSF->SetTranslation(theStartPoint->impl<gp_Pnt>(), theEndPoint->impl<gp_Pnt>());
53 }
54
55 //=================================================================================================
56 void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
57                                const double theAngle)
58 {
59   MY_TRSF->SetRotation(theAxis->impl<gp_Ax1>(), theAngle / 180.0 * M_PI);
60 }
61
62 //=================================================================================================
63 void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
64                                const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
65                                const std::shared_ptr<GeomAPI_Pnt> theEndPoint)
66 {
67   gp_Pnt aCenterPoint = theCenterPoint->impl<gp_Pnt>();
68   gp_Pnt aStartPoint = theStartPoint->impl<gp_Pnt>();
69   gp_Pnt aEndPoint = theEndPoint->impl<gp_Pnt>();
70
71   gp_Vec aVec1(aCenterPoint, aStartPoint);
72   gp_Vec aVec2(aCenterPoint, aEndPoint);
73   gp_Dir aDir(aVec1 ^ aVec2);
74   gp_Ax1 anAxis(aCenterPoint, aDir);
75   double anAngle = aVec1.Angle(aVec2);
76   if (fabs(anAngle) < Precision::Angular()) anAngle += 2.*M_PI; // Taken from old GEOM code
77
78   MY_TRSF->SetRotation(anAxis, anAngle);
79 }
80
81 //=================================================================================================
82 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Pnt> thePoint)
83 {
84   MY_TRSF->SetMirror(thePoint->impl<gp_Pnt>());
85 }
86
87 //=================================================================================================
88 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Ax1> theAxis)
89 {
90   MY_TRSF->SetMirror(theAxis->impl<gp_Ax1>());
91 }
92
93 //=================================================================================================
94 void GeomAPI_Trsf::setSymmetry(const std::shared_ptr<GeomAPI_Ax2> thePlane)
95 {
96   MY_TRSF->SetMirror(thePlane->impl<gp_Ax2>());
97 }