1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Movement.cpp
4 // Created: 8 June 2015
5 // Author: Dmitry Bobylev
7 #include <GeomAlgoAPI_Movement.h>
9 #include <GeomAlgoAPI_ShapeTools.h>
11 #include <BRepBuilderAPI_Transform.hxx>
12 #include <BRepCheck_Analyzer.hxx>
14 #include <Precision.hxx>
15 #include <TopExp_Explorer.hxx>
17 //=================================================================================================
18 GeomAlgoAPI_Movement::GeomAlgoAPI_Movement(std::shared_ptr<GeomAPI_Shape> theSourceShape,
19 std::shared_ptr<GeomAPI_Ax1> theAxis,
21 bool theSimpleTransform)
24 build(theSourceShape, theAxis, theDistance, theSimpleTransform);
27 //=================================================================================================
28 void GeomAlgoAPI_Movement::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
29 std::shared_ptr<GeomAPI_Ax1> theAxis,
31 bool theSimpleTransform)
33 if(!theSourceShape || !theAxis) {
37 const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
38 const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
40 if(aSourceShape.IsNull()) {
45 aTrsf.SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
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
57 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
61 myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
63 myDone = aBuilder->IsDone() == Standard_True;
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);
79 myShape.reset(new GeomAPI_Shape());
80 myShape->setImpl(new TopoDS_Shape(aResult));
83 //=================================================================================================
84 const bool GeomAlgoAPI_Movement::isValid() const
86 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
87 return (aChecker.IsValid() == Standard_True);
90 //=================================================================================================
91 const bool GeomAlgoAPI_Movement::hasVolume() const
93 bool hasVolume(false);
94 if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
100 //=================================================================================================
101 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Movement::shape() const
106 //=================================================================================================
107 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Movement::mapOfShapes() const
112 //=================================================================================================
113 std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Movement::makeShape() const
118 //=================================================================================================
119 std::shared_ptr<GeomAPI_Trsf> GeomAlgoAPI_Movement::transformation() const