0027232: Configuration - fix mblen missing building issue on Android
[occt.git] / src / BRepPrim / BRepPrim_Cone.cxx
1 // Created on: 1992-11-06
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <BRepPrim_Cone.hxx>
19 #include <Geom2d_Line.hxx>
20 #include <Geom_ConicalSurface.hxx>
21 #include <Geom_Line.hxx>
22 #include <gp.hxx>
23 #include <gp_Ax2.hxx>
24 #include <gp_Pnt.hxx>
25 #include <gp_Vec.hxx>
26 #include <Precision.hxx>
27 #include <Standard_DomainError.hxx>
28 #include <TopoDS_Face.hxx>
29
30 //=======================================================================
31 //function : BRepPrim_Cone
32 //purpose  : 
33 //=======================================================================
34 BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle, 
35                              const gp_Ax2& Position, 
36                              const Standard_Real Height, 
37                              const Standard_Real Radius) :
38        BRepPrim_Revolution(Position,0,0),
39        myHalfAngle(Angle),
40        myRadius(Radius)
41 {
42   if (Height < Precision::Confusion())
43     Standard_DomainError::Raise("cone with null height");
44   if (myHalfAngle*Height < Precision::Confusion())
45     Standard_DomainError::Raise("cone with null angle");
46   if ((M_PI/2 - myHalfAngle)*Height < Precision::Confusion())
47     Standard_DomainError::Raise("cone with angle > PI/2");
48   
49   // cut at top
50   VMax(Height / Cos(myHalfAngle));
51   VMin(0.);
52   SetMeridian();
53 }
54
55 //=======================================================================
56 //function : BRepPrim_Cone
57 //purpose  : 
58 //=======================================================================
59
60 BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle) :
61        BRepPrim_Revolution(gp::XOY(),0,RealLast()),
62        myHalfAngle(Angle),
63        myRadius(0.)
64 {
65   if ((Angle < 0) || (Angle > M_PI/2)) 
66     Standard_DomainError::Raise("cone with angle <0 or > PI/2");
67   VMin(0.);
68   SetMeridian();
69 }
70
71 //=======================================================================
72 //function : BRepPrim_Cone
73 //purpose  : 
74 //=======================================================================
75
76 BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle, 
77                              const gp_Pnt& Apex) :
78        BRepPrim_Revolution(gp_Ax2(Apex,gp_Dir(0,0,1),gp_Dir(1,0,0)),
79                            0,RealLast()),
80        myHalfAngle(Angle),
81        myRadius(0.)
82 {
83   if ((Angle < 0) || (Angle > M_PI/2)) 
84     Standard_DomainError::Raise("cone with angle <0 or > PI/2");
85   VMin(0.);
86   SetMeridian();
87 }
88
89 //=======================================================================
90 //function : BRepPrim_Cone
91 //purpose  : 
92 //=======================================================================
93
94 BRepPrim_Cone::BRepPrim_Cone(const Standard_Real Angle,
95                              const gp_Ax2& Axes) :
96        BRepPrim_Revolution( Axes, 0,RealLast()),
97        myHalfAngle(Angle)
98 {
99   if ((Angle < 0) || (Angle > M_PI/2)) 
100     Standard_DomainError::Raise("cone with angle <0 or > PI/2");
101   VMin(0.);
102   SetMeridian();
103 }
104
105 //=======================================================================
106 //function : BRepPrim_Cone
107 //purpose  : 
108 //=======================================================================
109
110 BRepPrim_Cone::BRepPrim_Cone(const Standard_Real R1,
111                              const Standard_Real R2,
112                              const Standard_Real H) :
113        BRepPrim_Revolution(gp::XOY(),0,0)
114 {
115   SetParameters(R1,R2,H);
116   SetMeridian();
117 }
118
119 //=======================================================================
120 //function : BRepPrim_Cone
121 //purpose  : 
122 //=======================================================================
123
124 BRepPrim_Cone::BRepPrim_Cone(const gp_Pnt& Center,
125                              const Standard_Real R1, 
126                              const Standard_Real R2,
127                              const Standard_Real H) :
128        BRepPrim_Revolution(gp_Ax2(Center,gp_Dir(0,0,1),gp_Dir(1,0,0)),
129                            0,0)
130 {
131   SetParameters(R1,R2,H);
132   SetMeridian();
133 }
134
135 //=======================================================================
136 //function : BRepPrim_Cone
137 //purpose  : 
138 //=======================================================================
139
140 BRepPrim_Cone::BRepPrim_Cone(const gp_Ax2& Axes, 
141                              const Standard_Real R1, 
142                              const Standard_Real R2, 
143                              const Standard_Real H) :
144        BRepPrim_Revolution(Axes,0,0)
145 {
146   SetParameters(R1,R2,H);
147   SetMeridian();
148 }
149
150 //=======================================================================
151 //function : MakeEmptyLateralFace
152 //purpose  : 
153 //=======================================================================
154
155 TopoDS_Face  BRepPrim_Cone::MakeEmptyLateralFace()const 
156 {
157   Handle(Geom_ConicalSurface) C =
158     new Geom_ConicalSurface(Axes(),myHalfAngle,myRadius);
159   TopoDS_Face F;
160   myBuilder.Builder().MakeFace(F,C,Precision::Confusion());
161   return F;
162 }
163
164 //=======================================================================
165 //function : SetMeridian
166 //purpose  : 
167 //=======================================================================
168
169 void BRepPrim_Cone::SetMeridian ()
170 {
171   gp_Ax1 A = Axes().Axis();
172   A.Rotate(gp_Ax1(Axes().Location(),Axes().YDirection()),myHalfAngle);
173   gp_Vec V(Axes().XDirection());
174   V *= myRadius;
175   A.Translate(V);
176   Handle(Geom_Line) L = new Geom_Line(A);
177   Handle(Geom2d_Line) L2d = 
178     new Geom2d_Line(gp_Pnt2d(myRadius,0),gp_Dir2d(Sin(myHalfAngle),Cos(myHalfAngle)));
179   Meridian(L,L2d);
180 }
181
182 //=======================================================================
183 //function : SetParameters
184 //purpose  : 
185 //=======================================================================
186
187 void BRepPrim_Cone::SetParameters(const Standard_Real R1,
188                                   const Standard_Real R2,
189                                   const Standard_Real H)
190 {
191   if (((R1 != 0) && (R1 < Precision::Confusion())) ||
192       ((R2 != 0) && (R2 < Precision::Confusion())))
193     Standard_DomainError::Raise("cone with negative or too small radius");
194   if (Abs(R1-R2) < Precision::Confusion())
195     Standard_DomainError::Raise("cone with two identic radii");
196   if (H < Precision::Confusion())
197     Standard_DomainError::Raise("cone with negative or null height");
198
199   myRadius = R1;
200   myHalfAngle = ATan((R2 - R1) / H);
201
202   // cut top and bottom
203   VMin(0.);
204   VMax(Sqrt(H*H + (R2-R1)*(R2-R1)));
205 }  
206
207