1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GeomAlgoAPI_Translation.h"
23 #include <BRepBuilderAPI_Transform.hxx>
24 #include <Precision.hxx>
27 //=================================================================================================
28 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
29 std::shared_ptr<GeomAPI_Ax1> theAxis,
32 myMethodType = BY_DISTANCE;
33 mySourceShape = theSourceShape;
35 myDistance = theDistance;
38 //=================================================================================================
39 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
44 myMethodType = BY_DIM;
45 mySourceShape = theSourceShape;
51 //=================================================================================================
52 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
53 std::shared_ptr<GeomAPI_Pnt> theStartPoint,
54 std::shared_ptr<GeomAPI_Pnt> theEndPoint)
56 myMethodType = BY_POINTS;
57 mySourceShape = theSourceShape;
58 myStartPoint = theStartPoint;
59 myEndPoint = theEndPoint;
62 //=================================================================================================
63 bool GeomAlgoAPI_Translation::check()
65 switch (myMethodType) {
68 myError = "Translation builder :: axis is not valid.";
72 myError = "Translation builder :: source shape is not valid.";
79 myError = "Translation builder :: source shape is not valid.";
86 myError = "Translation builder :: start point is not valid.";
90 myError = "Translation builder :: end point is not valid.";
94 myError = "Translation builder :: source shape is invalid.";
97 if(myStartPoint->distance(myEndPoint) < Precision::Confusion()) {
98 myError = "Translation builder :: start point and end point coincide.";
104 myError = "Translation builder :: method not implemented.";
110 //=================================================================================================
111 void GeomAlgoAPI_Translation::build()
113 gp_Trsf* aTrsf = new gp_Trsf();
115 switch (myMethodType) {
117 const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
118 aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * myDistance);
122 aTrsf->SetTranslation(gp_Vec(myDx, myDy, myDz));
126 const gp_Pnt& aStartPoint = myStartPoint->impl<gp_Pnt>();
127 const gp_Pnt& aEndPoint = myEndPoint->impl<gp_Pnt>();
128 aTrsf->SetTranslation(aStartPoint, aEndPoint);
132 myError = "Translation builder :: method not supported";
137 const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
139 if(aSourceShape.IsNull()) {
140 myError = "Translation builder :: source shape does not contain any actual shape.";
144 // Transform the shape while copying it.
145 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
147 myError = "Translation builder :: transform initialization failed.";
152 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
154 if(!aBuilder->IsDone()) {
155 myError = "Translation builder :: algorithm failed.";
159 TopoDS_Shape aResult = aBuilder->Shape();
161 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
162 aShape->setImpl(new TopoDS_Shape(aResult));