Salome HOME
0e043bbc7126e294a5238fc70483434518de174d
[modules/shaper.git] / src / GeomAPI / GeomAPI_Cylinder.cpp
1 // Copyright (C) 2018-20xx  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <GeomAPI_Cylinder.h>
22 #include <GeomAPI_Pnt.h>
23 #include <GeomAPI_Dir.h>
24
25 #include <gp_Cylinder.hxx>
26 #include <Precision.hxx>
27
28 #define MY_CYL implPtr<gp_Cylinder>()
29
30 static gp_Cylinder* newCyl(const gp_Pnt& theLocation, const gp_Dir& theAxis, const double theRadius)
31 {
32   return new gp_Cylinder(gp_Ax3(theLocation, theAxis), theRadius);
33 }
34
35 //=================================================================================================
36 GeomAPI_Cylinder::GeomAPI_Cylinder(const std::shared_ptr<GeomAPI_Pnt>& theLocation,
37                                    const std::shared_ptr<GeomAPI_Dir>& theAxis,
38                                    const double theRadius)
39   : GeomAPI_Interface(newCyl(theLocation->impl<gp_Pnt>(), theAxis->impl<gp_Dir>(), theRadius)),
40     myHeight(Precision::Infinite())
41 {
42 }
43
44 //=================================================================================================
45 GeomAPI_Cylinder::GeomAPI_Cylinder(const std::shared_ptr<GeomAPI_Pnt>& theLocation,
46                                    const std::shared_ptr<GeomAPI_Dir>& theAxis,
47                                    const double theRadius,
48                                    const double theHeight)
49   : GeomAPI_Interface(newCyl(theLocation->impl<gp_Pnt>(), theAxis->impl<gp_Dir>(), theRadius)),
50     myHeight(theHeight)
51 {
52 }
53
54 //=================================================================================================
55 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Cylinder::location() const
56 {
57   const gp_Pnt& aCenter = MY_CYL->Location();
58   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCenter.X(), aCenter.Y(), aCenter.Z()));
59 }
60
61 //=================================================================================================
62 std::shared_ptr<GeomAPI_Dir> GeomAPI_Cylinder::axis() const
63 {
64   const gp_Dir& anAxis = MY_CYL->Position().Direction();
65   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(anAxis.X(), anAxis.Y(), anAxis.Z()));
66 }
67
68 //=================================================================================================
69 double GeomAPI_Cylinder::radius() const
70 {
71   return MY_CYL->Radius();
72 }
73
74 //=================================================================================================
75 double GeomAPI_Cylinder::height() const
76 {
77   return myHeight;
78 }
79
80 //=================================================================================================
81 bool GeomAPI_Cylinder::isInfinite() const
82 {
83   return Precision::IsInfinite(myHeight);
84 }