Salome HOME
Partition naming
[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 : myDone(false),
20   myTrsf(theTrsf)
21 {
22   build(theSourceShape, theTrsf);
23 }
24
25 //=================================================================================================
26 void GeomAlgoAPI_Transform::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
27                                   std::shared_ptr<GeomAPI_Trsf>  theTrsf)
28 {
29   if(!theSourceShape || !theTrsf) {
30     return;
31   }
32
33   const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
34   const gp_Trsf& aTrsf = theTrsf->impl<gp_Trsf>();
35
36   if(aSourceShape.IsNull()) {
37     return;
38   }
39
40   BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
41   if(!aBuilder) {
42     return;
43   }
44   myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
45
46   myDone = aBuilder->IsDone() == Standard_True;
47   if(!myDone) {
48     return;
49   }
50
51   TopoDS_Shape aResult = aBuilder->Shape();
52
53   // Fill data map to keep correct orientation of sub-shapes.
54   myMap.reset(new GeomAPI_DataMapOfShapeShape());
55   for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
56     std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
57     aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
58     myMap->bind(aCurrentShape, aCurrentShape);
59   }
60
61   myShape.reset(new GeomAPI_Shape());
62   myShape->setImpl(new TopoDS_Shape(aResult));
63 }
64
65 //=================================================================================================
66 const bool GeomAlgoAPI_Transform::isValid() const
67 {
68   BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
69   return (aChecker.IsValid() == Standard_True);
70 }
71
72 //=================================================================================================
73 const bool GeomAlgoAPI_Transform::hasVolume() const
74 {
75   bool hasVolume(false);
76   if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
77     hasVolume = true;
78   }
79   return hasVolume;
80 }
81
82 //=================================================================================================
83 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Transform::shape() const
84 {
85   return myShape;
86 }
87
88 //=================================================================================================
89 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Transform::mapOfShapes() const
90 {
91   return myMap;
92 }
93
94 //=================================================================================================
95 std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Transform::makeShape() const
96 {
97   return myMkShape;
98 }
99
100 //=================================================================================================
101 std::shared_ptr<GeomAPI_Trsf> GeomAlgoAPI_Transform::transformation() const
102 {
103   return myTrsf;
104 }