1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Translation.cpp
4 // Created: 8 June 2015
5 // Author: Dmitry Bobylev
7 #include <GeomAlgoAPI_Translation.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_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
19 std::shared_ptr<GeomAPI_Ax1> theAxis,
23 build(theSourceShape, theAxis, theDistance);
26 //=================================================================================================
27 void GeomAlgoAPI_Translation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
28 std::shared_ptr<GeomAPI_Ax1> theAxis,
31 if(!theSourceShape || !theAxis) {
35 const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
36 const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
38 if(aSourceShape.IsNull()) {
42 gp_Trsf* aTrsf = new gp_Trsf();
43 aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
44 myTrsf.reset(new GeomAPI_Trsf(aTrsf));
46 // Transform the shape with copying it.
47 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
51 myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
53 myDone = aBuilder->IsDone() == Standard_True;
59 TopoDS_Shape aResult = aBuilder->Shape();
60 // Fill data map to keep correct orientation of sub-shapes.
61 myMap.reset(new GeomAPI_DataMapOfShapeShape());
62 for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
63 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
64 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
65 myMap->bind(aCurrentShape, aCurrentShape);
68 myShape.reset(new GeomAPI_Shape());
69 myShape->setImpl(new TopoDS_Shape(aResult));
72 //=================================================================================================
73 const bool GeomAlgoAPI_Translation::isValid() const
75 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
76 return (aChecker.IsValid() == Standard_True);
79 //=================================================================================================
80 const bool GeomAlgoAPI_Translation::hasVolume() const
82 bool hasVolume(false);
83 if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
89 //=================================================================================================
90 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Translation::shape() const
95 //=================================================================================================
96 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Translation::mapOfShapes() const
101 //=================================================================================================
102 std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Translation::makeShape() const
107 //=================================================================================================
108 std::shared_ptr<GeomAPI_Trsf> GeomAlgoAPI_Translation::transformation() const