1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Rotation.cpp
4 // Created: 12 May 2015
5 // Author: Dmitry Bobylev
7 #include <GeomAlgoAPI_Rotation.h>
9 #include <GeomAlgoAPI_ShapeProps.h>
11 #include <BRepBuilderAPI_Transform.hxx>
12 #include <BRepCheck_Analyzer.hxx>
13 #include <Precision.hxx>
14 #include <TopExp_Explorer.hxx>
16 //=================================================================================================
17 GeomAlgoAPI_Rotation::GeomAlgoAPI_Rotation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
18 std::shared_ptr<GeomAPI_Ax1> theAxis,
20 bool theSimpleTransform)
22 myShape(new GeomAPI_Shape()),
23 myMap(new GeomAPI_DataMapOfShapeShape()),
24 myMkShape(new GeomAlgoAPI_MakeShape())
26 build(theSourceShape, theAxis, theAngle, theSimpleTransform);
29 //=================================================================================================
30 void GeomAlgoAPI_Rotation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
31 std::shared_ptr<GeomAPI_Ax1> theAxis,
33 bool theSimpleTransform)
35 if(!theSourceShape || !theAxis) {
39 const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
40 const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
42 if(aSourceShape.IsNull()) {
47 aTrsf.SetRotation(anAxis, theAngle / 180.0 * M_PI);
50 // Transform the shape with copying it.
51 if (theSimpleTransform) {
52 TopLoc_Location aDelta(aTrsf);
53 aResult = aSourceShape.Moved(aDelta);
54 //myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
55 myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf)));
56 myDone = true; // is OK for sure
58 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
63 myDone = aBuilder->IsDone() == Standard_True;
69 aResult = aBuilder->Shape();
70 // Fill data map to keep correct orientation of sub-shapes.
71 for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
72 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
73 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
74 myMap->bind(aCurrentShape, aCurrentShape);
76 myMkShape->setImpl(aBuilder);
79 myShape->setImpl(new TopoDS_Shape(aResult));
82 //=================================================================================================
83 const bool GeomAlgoAPI_Rotation::isValid() const
85 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
86 return (aChecker.IsValid() == Standard_True);
89 //=================================================================================================
90 const bool GeomAlgoAPI_Rotation::hasVolume() const
92 bool hasVolume(false);
93 if(isValid() && (GeomAlgoAPI_ShapeProps::volume(myShape) > Precision::Confusion())) {
99 //=================================================================================================
100 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Rotation::shape() const
105 //=================================================================================================
106 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Rotation::mapOfShapes() const
111 //=================================================================================================
112 std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Rotation::makeShape() const
117 //=================================================================================================
118 std::shared_ptr<GeomAPI_Trsf> GeomAlgoAPI_Rotation::transformation() const