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