]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp
Salome HOME
Fixed validators for Boolean and Intersection
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Rotation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_Rotation.cpp
4 // Created:     12 May 2015
5 // Author:      Dmitry Bobylev
6
7 #include "GeomAlgoAPI_Rotation.h"
8
9 #include <BRepBuilderAPI_Transform.hxx>
10
11 //=================================================================================================
12 GeomAlgoAPI_Rotation::GeomAlgoAPI_Rotation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
13                                            std::shared_ptr<GeomAPI_Ax1>   theAxis,
14                                            double                         theAngle)
15 {
16   build(theSourceShape, theAxis, theAngle);
17 }
18
19 //=================================================================================================
20 void GeomAlgoAPI_Rotation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
21                                  std::shared_ptr<GeomAPI_Ax1>   theAxis,
22                                  double                         theAngle)
23 {
24   if(!theSourceShape || !theAxis) {
25     return;
26   }
27
28   const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
29   const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
30
31   if(aSourceShape.IsNull()) {
32     return;
33   }
34
35   gp_Trsf* aTrsf = new gp_Trsf();
36   aTrsf->SetRotation(anAxis, theAngle / 180.0 * M_PI);
37
38   // Transform the shape with copying it.
39   BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
40   if(!aBuilder) {
41     return;
42   }
43   this->setImpl(aBuilder);
44   this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
45
46   if(aBuilder->IsDone() != Standard_True) {
47     return;
48   }
49   TopoDS_Shape aResult = aBuilder->Shape();
50
51   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
52   aShape->setImpl(new TopoDS_Shape(aResult));
53   this->setShape(aShape);
54   this->setDone(true);
55 }