Salome HOME
Dump with geometrical selection
[modules/shaper.git] / src / GeomAPI / GeomAPI_Cone.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_Cone.h>
22 #include <GeomAPI_Pnt.h>
23 #include <GeomAPI_Dir.h>
24
25 #include <gp_Cone.hxx>
26 #include <Precision.hxx>
27
28 #define MY_CONE implPtr<gp_Cone>()
29
30 static gp_Cone* newCone(const gp_Pnt& theApex, const gp_Dir& theAxis,
31                         const double theSemiAngle, const double theRadius = 0.0)
32 {
33   return new gp_Cone(gp_Ax3(theApex, theAxis), theSemiAngle, theRadius);
34 }
35
36 //=================================================================================================
37 GeomAPI_Cone::GeomAPI_Cone(const std::shared_ptr<GeomAPI_Pnt>& theApex,
38                            const std::shared_ptr<GeomAPI_Dir>& theAxis,
39                            const double theSemiAngle)
40   : GeomAPI_Interface(newCone(theApex->impl<gp_Pnt>(), theAxis->impl<gp_Dir>(), theSemiAngle)),
41     myRadius1(Precision::Infinite()),
42     myRadius2(Precision::Infinite())
43 {
44 }
45
46 //=================================================================================================
47 GeomAPI_Cone::GeomAPI_Cone(const std::shared_ptr<GeomAPI_Pnt>& theLocation,
48                            const std::shared_ptr<GeomAPI_Dir>& theAxis,
49                            const double theSemiAngle,
50                            const double theRadius)
51   : GeomAPI_Interface(
52       newCone(theLocation->impl<gp_Pnt>(), theAxis->impl<gp_Dir>(), theSemiAngle, theRadius)),
53     myRadius1(theRadius),
54     myRadius2(Precision::Infinite())
55 {
56 }
57
58 //=================================================================================================
59 GeomAPI_Cone::GeomAPI_Cone(const std::shared_ptr<GeomAPI_Pnt>& theLocation,
60                            const std::shared_ptr<GeomAPI_Dir>& theAxis,
61                            const double theSemiAngle,
62                            const double theRadius1,
63                            const double theRadius2)
64   : GeomAPI_Interface(
65       newCone(theLocation->impl<gp_Pnt>(), theAxis->impl<gp_Dir>(), theSemiAngle, theRadius1)),
66     myRadius1(theRadius1),
67     myRadius2(theRadius2)
68 {
69 }
70
71 //=================================================================================================
72 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Cone::apex() const
73 {
74   const gp_Pnt& anApex = MY_CONE->Apex();
75   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(anApex.X(), anApex.Y(), anApex.Z()));
76 }
77
78 //=================================================================================================
79 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Cone::location() const
80 {
81   const gp_Pnt& aLoc = MY_CONE->Location();
82   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
83 }
84
85 //=================================================================================================
86 std::shared_ptr<GeomAPI_Dir> GeomAPI_Cone::axis() const
87 {
88   const gp_Dir& anAxis = MY_CONE->Position().Direction();
89   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(anAxis.X(), anAxis.Y(), anAxis.Z()));
90 }
91
92 //=================================================================================================
93 double GeomAPI_Cone::semiAngle() const
94 {
95   return MY_CONE->SemiAngle();
96 }
97
98 //=================================================================================================
99 double GeomAPI_Cone::radius1() const
100 {
101   return myRadius1;
102 }
103
104 //=================================================================================================
105 double GeomAPI_Cone::radius2() const
106 {
107   return myRadius2;
108 }
109
110 //=================================================================================================
111 double GeomAPI_Cone::height() const
112 {
113   if (Precision::IsInfinite(myRadius1) || Precision::IsInfinite(myRadius2))
114     return Precision::Infinite();
115
116   return Abs((myRadius2 - myRadius1) / Tan(semiAngle()));
117 }
118
119 //=================================================================================================
120 bool GeomAPI_Cone::isSemiInfinite() const
121 {
122   return (!Precision::IsInfinite(myRadius1) && Precision::IsInfinite(myRadius2)) ||
123          (Precision::IsInfinite(myRadius1) && !Precision::IsInfinite(myRadius2));
124 }
125
126 //=================================================================================================
127 bool GeomAPI_Cone::isInfinite() const
128 {
129   return Precision::IsInfinite(myRadius1) && Precision::IsInfinite(myRadius2);
130 }