Salome HOME
9bc0fb85c83acbbabea4b058923afc4c6fb3489e
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Translation.cpp
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <GeomAlgoAPI_Translation.h>
21
22 #include <GeomAPI_Ax1.h>
23 #include <GeomAPI_Shape.h>
24
25 #include <Precision.hxx>
26
27 //=================================================================================================
28 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
29                                                  std::shared_ptr<GeomAPI_Ax1>   theAxis,
30                                                  double                         theDistance)
31 {
32   if (!theAxis) {
33     myError = "Translation builder :: axis is not valid.";
34     return;
35   }
36
37   GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
38   aTrsf->setTranslation(theAxis, theDistance);
39
40   build(theSourceShape, aTrsf);
41 }
42
43 //=================================================================================================
44 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
45                                                  double                         theDx,
46                                                  double                         theDy,
47                                                  double                         theDz)
48 {
49   GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
50   aTrsf->setTranslation(theDx, theDy, theDz);
51
52   build(theSourceShape, aTrsf);
53 }
54
55 //=================================================================================================
56 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
57                                                  std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
58                                                  std::shared_ptr<GeomAPI_Pnt>   theEndPoint)
59 {
60   if (!theStartPoint) {
61     myError = "Translation builder :: start point is not valid.";
62     return;
63   }
64   if (!theEndPoint) {
65     myError = "Translation builder :: end point is not valid.";
66     return;
67   }
68   if (theStartPoint->distance(theEndPoint) < Precision::Confusion()) {
69     myError = "Translation builder :: start point and end point coincide.";
70     return;
71   }
72
73   GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
74   aTrsf->setTranslation(theStartPoint, theEndPoint);
75
76   build(theSourceShape, aTrsf);
77 }