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.";
49 myError = "Translation builder :: source shape is invalid.";
56 myError = "Translation builder :: source shape is invalid.";
62 myError = "Translation builder :: method not implemented.";
68 //=================================================================================================
69 void GeomAlgoAPI_Translation::build()
71 gp_Trsf* aTrsf = new gp_Trsf();
73 switch (myMethodType) {
75 const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
76 aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * myDistance);
80 aTrsf->SetTranslation(gp_Vec(myDx, myDy, myDz));
84 myError = "Translation builder :: method not supported";
89 const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
91 if(aSourceShape.IsNull()) {
92 myError = "Translation builder :: source shape does not contain any actual shape.";
96 // Transform the shape while copying it.
97 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
99 myError = "Translation builder :: source shape does not contain any actual shape.";
104 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
106 if(!aBuilder->IsDone()) {
107 myError = "Translation builder :: source shape does not contain any actual shape.";
111 TopoDS_Shape aResult = aBuilder->Shape();
113 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
114 aShape->setImpl(new TopoDS_Shape(aResult));