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 // Modified by Clarisse Genrault (CEA) : 17 Nov 2016
9 #include "GeomAlgoAPI_Translation.h"
11 #include <BRepBuilderAPI_Transform.hxx>
12 #include <Precision.hxx>
15 //=================================================================================================
16 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
17 std::shared_ptr<GeomAPI_Ax1> theAxis,
20 myMethodType = BY_DISTANCE;
21 mySourceShape = theSourceShape;
23 myDistance = theDistance;
26 //=================================================================================================
27 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
32 myMethodType = BY_DIM;
33 mySourceShape = theSourceShape;
39 //=================================================================================================
40 bool GeomAlgoAPI_Translation::check()
42 switch (myMethodType) {
45 myError = "Translation builder :: axis is invalid.";
48 // TODO : verification de la distance
50 myError = "Translation builder :: source shape is invalid.";
56 if ((fabs(myDx) < Precision::Confusion()) &&
57 (fabs(myDy) < Precision::Confusion()) &&
58 (fabs(myDz) < Precision::Confusion())) {
59 myError = "Translation builder :: Dx, Dy and Dz are null.";
63 myError = "Translation builder :: source shape is invalid.";
69 myError = "Translation builder :: method not implemented.";
75 //=================================================================================================
76 void GeomAlgoAPI_Translation::build()
78 gp_Trsf* aTrsf = new gp_Trsf();
80 switch (myMethodType) {
82 const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
83 aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * myDistance);
87 aTrsf->SetTranslation(gp_Vec(myDx, myDy, myDz));
91 myError = "Translation builder :: method not supported";
96 const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
98 if(aSourceShape.IsNull()) {
99 myError = "Translation builder :: source shape does not contain any actual shape.";
103 // Transform the shape while copying it.
104 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
106 myError = "Translation builder :: source shape does not contain any actual shape.";
111 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
113 if(!aBuilder->IsDone()) {
114 myError = "Translation builder :: source shape does not contain any actual shape.";
118 TopoDS_Shape aResult = aBuilder->Shape();
120 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
121 aShape->setImpl(new TopoDS_Shape(aResult));