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 not valid.";
60 myError = "Translation builder :: source shape is not valid.";
67 myError = "Translation builder :: source shape is not valid.";
74 myError = "Translation builder :: start point is not valid.";
78 myError = "Translation builder :: end point is not valid.";
82 myError = "Translation builder :: source shape is invalid.";
85 if(myStartPoint->distance(myEndPoint) < Precision::Confusion()) {
86 myError = "Translation builder :: start point and end point coincide.";
92 myError = "Translation builder :: method not implemented.";
98 //=================================================================================================
99 void GeomAlgoAPI_Translation::build()
101 gp_Trsf* aTrsf = new gp_Trsf();
103 switch (myMethodType) {
105 const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
106 aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * myDistance);
110 aTrsf->SetTranslation(gp_Vec(myDx, myDy, myDz));
114 const gp_Pnt& aStartPoint = myStartPoint->impl<gp_Pnt>();
115 const gp_Pnt& aEndPoint = myEndPoint->impl<gp_Pnt>();
116 aTrsf->SetTranslation(aStartPoint, aEndPoint);
120 myError = "Translation builder :: method not supported";
125 const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
127 if(aSourceShape.IsNull()) {
128 myError = "Translation builder :: source shape does not contain any actual shape.";
132 // Transform the shape while copying it.
133 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
135 myError = "Translation builder :: transform initialization failed.";
140 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
142 if(!aBuilder->IsDone()) {
143 myError = "Translation builder :: algorithm failed.";
147 TopoDS_Shape aResult = aBuilder->Shape();
149 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
150 aShape->setImpl(new TopoDS_Shape(aResult));