]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp
Salome HOME
Make the movement, placement and rotation 3D features may be applied to the Part...
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Rotation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_Rotation.cpp
4 // Created:     12 May 2015
5 // Author:      Dmitry Bobylev
6
7 #include <GeomAlgoAPI_Rotation.h>
8
9 #include <GeomAlgoAPI_ShapeProps.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_Rotation::GeomAlgoAPI_Rotation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
18                                            std::shared_ptr<GeomAPI_Ax1>   theAxis,
19                                            double                         theAngle,
20                                            bool theSimpleTransform)
21 : myDone(false),
22   myShape(new GeomAPI_Shape()),
23   myMap(new GeomAPI_DataMapOfShapeShape()),
24   myMkShape(new GeomAlgoAPI_MakeShape())
25 {
26   build(theSourceShape, theAxis, theAngle, theSimpleTransform);
27 }
28
29 //=================================================================================================
30 void GeomAlgoAPI_Rotation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
31                                  std::shared_ptr<GeomAPI_Ax1>   theAxis,
32                                  double                         theAngle,
33                                  bool theSimpleTransform)
34 {
35   if(!theSourceShape || !theAxis) {
36     return;
37   }
38
39   const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
40   const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
41
42   if(aSourceShape.IsNull()) {
43     return;
44   }
45
46   gp_Trsf aTrsf;
47   aTrsf.SetRotation(anAxis, theAngle / 180.0 * M_PI);
48
49   TopoDS_Shape aResult;
50   // Transform the shape with copying it.
51   if (theSimpleTransform) {
52     TopLoc_Location aDelta(aTrsf);
53     aResult = aSourceShape.Moved(aDelta);
54     myDone = true; // is OK for sure
55   } else {
56     BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
57     if(!aBuilder) {
58       return;
59     }
60
61     myDone = aBuilder->IsDone() == Standard_True;
62
63     if(!myDone) {
64       return;
65     }
66
67     aResult = aBuilder->Shape();
68     // Fill data map to keep correct orientation of sub-shapes.
69     for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
70       std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
71       aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
72       myMap->bind(aCurrentShape, aCurrentShape);
73     }
74     myMkShape->setImpl(aBuilder);
75   }
76
77   myShape->setImpl(new TopoDS_Shape(aResult));
78 }
79
80 //=================================================================================================
81 const bool GeomAlgoAPI_Rotation::isValid() const
82 {
83   BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
84   return (aChecker.IsValid() == Standard_True);
85 }
86
87 //=================================================================================================
88 const bool GeomAlgoAPI_Rotation::hasVolume() const
89 {
90   bool hasVolume(false);
91   if(isValid() && (GeomAlgoAPI_ShapeProps::volume(myShape) > Precision::Confusion())) {
92     hasVolume = true;
93   }
94   return hasVolume;
95 }
96
97 //=================================================================================================
98 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Rotation::shape() const
99 {
100   return myShape;
101 }
102
103 //=================================================================================================
104 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Rotation::mapOfShapes() const
105 {
106   return myMap;
107 }
108
109 //=================================================================================================
110 std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Rotation::makeShape() const
111 {
112   return myMkShape;
113 }