1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "GeomAlgoAPI_Translation.h"
22 #include <BRepBuilderAPI_Transform.hxx>
23 #include <Precision.hxx>
26 //=================================================================================================
27 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
28 std::shared_ptr<GeomAPI_Ax1> theAxis,
31 myMethodType = BY_DISTANCE;
32 mySourceShape = theSourceShape;
34 myDistance = theDistance;
37 //=================================================================================================
38 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
43 myMethodType = BY_DIM;
44 mySourceShape = theSourceShape;
50 //=================================================================================================
51 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
52 std::shared_ptr<GeomAPI_Pnt> theStartPoint,
53 std::shared_ptr<GeomAPI_Pnt> theEndPoint)
55 myMethodType = BY_POINTS;
56 mySourceShape = theSourceShape;
57 myStartPoint = theStartPoint;
58 myEndPoint = theEndPoint;
61 //=================================================================================================
62 bool GeomAlgoAPI_Translation::check()
64 switch (myMethodType) {
67 myError = "Translation builder :: axis is not valid.";
71 myError = "Translation builder :: source shape is not valid.";
78 myError = "Translation builder :: source shape is not valid.";
85 myError = "Translation builder :: start point is not valid.";
89 myError = "Translation builder :: end point is not valid.";
93 myError = "Translation builder :: source shape is invalid.";
96 if(myStartPoint->distance(myEndPoint) < Precision::Confusion()) {
97 myError = "Translation builder :: start point and end point coincide.";
103 myError = "Translation builder :: method not implemented.";
109 //=================================================================================================
110 void GeomAlgoAPI_Translation::build()
112 gp_Trsf* aTrsf = new gp_Trsf();
114 switch (myMethodType) {
116 const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
117 aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * myDistance);
121 aTrsf->SetTranslation(gp_Vec(myDx, myDy, myDz));
125 const gp_Pnt& aStartPoint = myStartPoint->impl<gp_Pnt>();
126 const gp_Pnt& aEndPoint = myEndPoint->impl<gp_Pnt>();
127 aTrsf->SetTranslation(aStartPoint, aEndPoint);
131 myError = "Translation builder :: method not supported";
136 const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
138 if(aSourceShape.IsNull()) {
139 myError = "Translation builder :: source shape does not contain any actual shape.";
143 // Transform the shape while copying it.
144 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
146 myError = "Translation builder :: transform initialization failed.";
151 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
153 if(!aBuilder->IsDone()) {
154 myError = "Translation builder :: algorithm failed.";
158 TopoDS_Shape aResult = aBuilder->Shape();
160 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
161 aShape->setImpl(new TopoDS_Shape(aResult));