]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp
Salome HOME
Code clean up
[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 <GeomAlgoAPI_ShapeTools.h>
10
11 #include <BRepBuilderAPI_Transform.hxx>
12 #include <BRepCheck_Analyzer.hxx>
13 #include <gp_Ax1.hxx>
14 #include <Precision.hxx>
15 #include <TopExp_Explorer.hxx>
16
17 //=================================================================================================
18 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
19                                            std::shared_ptr<GeomAPI_Ax1>   theAxis,
20                                            double                         theDistance,
21                                            bool theSimpleTransform)
22 : myDone(false)
23 {
24   build(theSourceShape, theAxis, theDistance, theSimpleTransform);
25 }
26
27 //=================================================================================================
28 void GeomAlgoAPI_Translation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
29                                  std::shared_ptr<GeomAPI_Ax1>   theAxis,
30                                  double                         theDistance,
31                                  bool theSimpleTransform)
32 {
33   if(!theSourceShape || !theAxis) {
34     return;
35   }
36
37   const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
38   const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
39
40   if(aSourceShape.IsNull()) {
41     return;
42   }
43
44   gp_Trsf aTrsf;
45   aTrsf.SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
46
47   TopoDS_Shape aResult;
48   // Transform the shape with copying it.
49   if (theSimpleTransform) {
50     TopLoc_Location aDelta(aTrsf);
51     aResult = aSourceShape.Moved(aDelta);
52     // store the accumulated information about the result and this delta
53     //myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
54     myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf)));
55     myDone = true; // is OK for sure
56   } else {
57     BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
58     if(!aBuilder) {
59       return;
60     }
61     myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
62
63     myDone = aBuilder->IsDone() == Standard_True;
64
65     if(!myDone) {
66       return;
67     }
68
69     aResult = aBuilder->Shape();
70     // Fill data map to keep correct orientation of sub-shapes.
71     myMap.reset(new GeomAPI_DataMapOfShapeShape());
72     for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
73       std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
74       aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
75       myMap->bind(aCurrentShape, aCurrentShape);
76     }
77   }
78
79   myShape.reset(new GeomAPI_Shape());
80   myShape->setImpl(new TopoDS_Shape(aResult));
81 }
82
83 //=================================================================================================
84 const bool GeomAlgoAPI_Translation::isValid() const
85 {
86   BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
87   return (aChecker.IsValid() == Standard_True);
88 }
89
90 //=================================================================================================
91 const bool GeomAlgoAPI_Translation::hasVolume() const
92 {
93   bool hasVolume(false);
94   if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
95     hasVolume = true;
96   }
97   return hasVolume;
98 }
99
100 //=================================================================================================
101 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Translation::shape() const
102 {
103   return myShape;
104 }
105
106 //=================================================================================================
107 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Translation::mapOfShapes() const
108 {
109   return myMap;
110 }
111
112 //=================================================================================================
113 std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Translation::makeShape() const
114 {
115   return myMkShape;
116 }
117
118 //=================================================================================================
119 std::shared_ptr<GeomAPI_Trsf> GeomAlgoAPI_Translation::transformation() const
120 {
121   return myTrsf;
122 }