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 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
41 std::shared_ptr<GeomAPI_Pnt> theStartPoint,
42 std::shared_ptr<GeomAPI_Pnt> theEndPoint)
44 myMethodType = BY_POINTS;
45 mySourceShape = theSourceShape;
46 myStartPoint = theStartPoint;
47 myEndPoint = theEndPoint;
50 //=================================================================================================
51 bool GeomAlgoAPI_Translation::check()
53 switch (myMethodType) {
56 myError = "Translation builder :: axis is invalid.";
60 myError = "Translation builder :: source shape is invalid.";
67 myError = "Translation builder :: source shape is invalid.";
74 myError = "Translation builder :: start point is invalid.";
78 myError = "Translation builder :: start point is invalid.";
82 myError = "Translation builder :: source shape is invalid.";
88 myError = "Translation builder :: method not implemented.";
94 //=================================================================================================
95 void GeomAlgoAPI_Translation::build()
97 gp_Trsf* aTrsf = new gp_Trsf();
99 switch (myMethodType) {
101 const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
102 aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * myDistance);
106 aTrsf->SetTranslation(gp_Vec(myDx, myDy, myDz));
110 const gp_Pnt& aStartPoint = myStartPoint->impl<gp_Pnt>();
111 const gp_Pnt& aEndPoint = myEndPoint->impl<gp_Pnt>();
112 aTrsf->SetTranslation(aStartPoint, aEndPoint);
116 myError = "Translation builder :: method not supported";
121 const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
123 if(aSourceShape.IsNull()) {
124 myError = "Translation builder :: source shape does not contain any actual shape.";
128 // Transform the shape while copying it.
129 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
131 myError = "Translation builder :: transform initialization failed.";
136 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
138 if(!aBuilder->IsDone()) {
139 myError = "Translation builder :: algorithm failed.";
143 TopoDS_Shape aResult = aBuilder->Shape();
145 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
146 aShape->setImpl(new TopoDS_Shape(aResult));