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_ShapeProps.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)
23 myShape(new GeomAPI_Shape()),
24 myMap(new GeomAPI_DataMapOfShapeShape()),
25 myMkShape(new GeomAlgoAPI_MakeShape())
27 build(theSourceShape, theAxis, theDistance, theSimpleTransform);
30 //=================================================================================================
31 void GeomAlgoAPI_Movement::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
32 std::shared_ptr<GeomAPI_Ax1> theAxis,
34 bool theSimpleTransform)
36 if(!theSourceShape || !theAxis) {
40 const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
41 const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
43 if(aSourceShape.IsNull()) {
48 aTrsf.SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
51 // Transform the shape with copying it.
52 if (theSimpleTransform) {
53 TopLoc_Location aDelta(aTrsf);
54 aResult = aSourceShape.Moved(aDelta);
55 myDone = true; // is OK for sure
57 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
62 myDone = aBuilder->IsDone() == Standard_True;
68 aResult = aBuilder->Shape();
69 // Fill data map to keep correct orientation of sub-shapes.
70 for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
71 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
72 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
73 myMap->bind(aCurrentShape, aCurrentShape);
75 myMkShape->setImpl(aBuilder);
78 myShape->setImpl(new TopoDS_Shape(aResult));
81 //=================================================================================================
82 const bool GeomAlgoAPI_Movement::isValid() const
84 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
85 return (aChecker.IsValid() == Standard_True);
88 //=================================================================================================
89 const bool GeomAlgoAPI_Movement::hasVolume() const
91 bool hasVolume(false);
92 if(isValid() && (GeomAlgoAPI_ShapeProps::volume(myShape) > Precision::Confusion())) {
98 //=================================================================================================
99 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Movement::shape() const
104 //=================================================================================================
105 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Movement::mapOfShapes() const
110 //=================================================================================================
111 std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Movement::makeShape() const