Salome HOME
481ae1c725300f0a7a7c2fc742f3f521f79ffe1c
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Transform.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_Transform.cpp
4 // Created:     29 July 2015
5 // Author:      Dmitry Bobylev
6
7 #include "GeomAlgoAPI_Transform.h"
8
9 #include <GeomAlgoAPI_ShapeTools.h>
10
11 #include <BRepBuilderAPI_Transform.hxx>
12 #include <BRepCheck_Analyzer.hxx>
13 #include <Precision.hxx>
14 #include <TopExp_Explorer.hxx>
15
16 //=================================================================================================
17 GeomAlgoAPI_Transform::GeomAlgoAPI_Transform(std::shared_ptr<GeomAPI_Shape> theSourceShape,
18                                              std::shared_ptr<GeomAPI_Trsf>  theTrsf)
19 : myTrsf(theTrsf)
20 {
21   build(theSourceShape, theTrsf);
22 }
23
24 //=================================================================================================
25 void GeomAlgoAPI_Transform::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
26                                   std::shared_ptr<GeomAPI_Trsf>  theTrsf)
27 {
28   if(!theSourceShape || !theTrsf) {
29     return;
30   }
31
32   const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
33   const gp_Trsf& aTrsf = theTrsf->impl<gp_Trsf>();
34
35   if(aSourceShape.IsNull()) {
36     return;
37   }
38
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 }
56
57 //=================================================================================================
58 std::shared_ptr<GeomAPI_Trsf> GeomAlgoAPI_Transform::transformation() const
59 {
60   return myTrsf;
61 }