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