0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Geom / Geom_ConicalSurface.cxx
1 // Created on: 1993-03-10
2 // Created by: JCV
3 // Copyright (c) 1993-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 <ElSLib.hxx>
19 #include <Geom_Circle.hxx>
20 #include <Geom_ConicalSurface.hxx>
21 #include <Geom_Curve.hxx>
22 #include <Geom_Geometry.hxx>
23 #include <Geom_Line.hxx>
24 #include <gp.hxx>
25 #include <gp_Ax2d.hxx>
26 #include <gp_Ax3.hxx>
27 #include <gp_Circ.hxx>
28 #include <gp_Cone.hxx>
29 #include <gp_Dir.hxx>
30 #include <gp_GTrsf2d.hxx>
31 #include <gp_Pnt.hxx>
32 #include <gp_Trsf.hxx>
33 #include <gp_Vec.hxx>
34 #include <gp_XYZ.hxx>
35 #include <Precision.hxx>
36 #include <Standard_ConstructionError.hxx>
37 #include <Standard_RangeError.hxx>
38 #include <Standard_Type.hxx>
39
40 IMPLEMENT_STANDARD_RTTIEXT(Geom_ConicalSurface,Geom_ElementarySurface)
41
42 typedef Geom_ConicalSurface         ConicalSurface;
43 typedef gp_Ax1  Ax1;
44 typedef gp_Ax2  Ax2;
45 typedef gp_Ax3  Ax3;
46 typedef gp_Circ Circ;
47 typedef gp_Dir  Dir;
48 typedef gp_Lin  Lin;
49 typedef gp_Pnt  Pnt;
50 typedef gp_Trsf Trsf;
51 typedef gp_Vec  Vec;
52 typedef gp_XYZ  XYZ;
53
54 //=======================================================================
55 //function : Copy
56 //purpose  : 
57 //=======================================================================
58
59 Handle(Geom_Geometry) Geom_ConicalSurface::Copy () const {
60  
61    Handle(Geom_ConicalSurface) Cs;
62    Cs = new ConicalSurface (pos, semiAngle, radius);
63    return Cs;
64 }
65
66 //=======================================================================
67 //function : Geom_ConicalSurface
68 //purpose  : 
69 //=======================================================================
70
71 Geom_ConicalSurface::Geom_ConicalSurface ( const Ax3& A3 , 
72                                            const Standard_Real Ang, 
73                                            const Standard_Real R) :
74        radius(R), semiAngle (Ang) 
75 {
76
77   if (R < 0.0 || Abs(Ang) <= gp::Resolution() || Abs(Ang) >= M_PI/2.0 - gp::Resolution()) 
78     throw Standard_ConstructionError();
79   
80   pos = A3;
81 }
82
83
84 //=======================================================================
85 //function : Geom_ConicalSurface
86 //purpose  : 
87 //=======================================================================
88
89 Geom_ConicalSurface::Geom_ConicalSurface ( const gp_Cone& C ) 
90 : radius (C.RefRadius()), semiAngle (C.SemiAngle()) 
91 {
92    pos = C.Position();
93 }
94
95
96 //=======================================================================
97 //function : UReversedParameter
98 //purpose  : 
99 //=======================================================================
100
101 Standard_Real Geom_ConicalSurface::UReversedParameter( const Standard_Real U) const
102 {
103   return ( 2.*M_PI - U);
104 }
105
106
107 //=======================================================================
108 //function : VReversedParameter
109 //purpose  : 
110 //=======================================================================
111
112 Standard_Real Geom_ConicalSurface::VReversedParameter( const Standard_Real V) const
113 {
114   return ( -V);
115 }
116
117 //=======================================================================
118 //function : VReverse
119 //purpose  : 
120 //=======================================================================
121
122 void Geom_ConicalSurface::VReverse()
123 {
124   semiAngle = -semiAngle;
125   pos.ZReverse();
126 }
127
128 //=======================================================================
129 //function : RefRadius
130 //purpose  : 
131 //=======================================================================
132
133 Standard_Real Geom_ConicalSurface::RefRadius () const               
134 { return radius; }
135
136 //=======================================================================
137 //function : SemiAngle
138 //purpose  : 
139 //=======================================================================
140
141 Standard_Real Geom_ConicalSurface::SemiAngle () const               
142 { return semiAngle;}
143
144 //=======================================================================
145 //function : IsUClosed
146 //purpose  : 
147 //=======================================================================
148
149 Standard_Boolean Geom_ConicalSurface::IsUClosed () const            
150 { return Standard_True; }
151
152 //=======================================================================
153 //function : IsVClosed
154 //purpose  : 
155 //=======================================================================
156
157 Standard_Boolean Geom_ConicalSurface::IsVClosed () const            
158 { return Standard_False; }
159
160 //=======================================================================
161 //function : IsUPeriodic
162 //purpose  : 
163 //=======================================================================
164
165 Standard_Boolean Geom_ConicalSurface::IsUPeriodic () const          
166 { return Standard_True; }
167
168 //=======================================================================
169 //function : IsVPeriodic
170 //purpose  : 
171 //=======================================================================
172
173 Standard_Boolean Geom_ConicalSurface::IsVPeriodic () const          
174 { return Standard_False; }
175
176 //=======================================================================
177 //function : Cone
178 //purpose  : 
179 //=======================================================================
180
181 gp_Cone Geom_ConicalSurface::Cone () const {
182
183   return gp_Cone (pos, semiAngle, radius);
184 }
185
186
187 //=======================================================================
188 //function : SetCone
189 //purpose  : 
190 //=======================================================================
191
192 void Geom_ConicalSurface::SetCone (const gp_Cone& C) {
193
194   radius = C.RefRadius ();
195   semiAngle   = C.SemiAngle ();
196   pos    = C.Position  ();
197 }
198
199
200 //=======================================================================
201 //function : SetRadius
202 //purpose  : 
203 //=======================================================================
204
205 void Geom_ConicalSurface::SetRadius (const Standard_Real R) {
206
207   if (R < 0.0)  throw Standard_ConstructionError();
208   radius = R;
209 }
210
211
212 //=======================================================================
213 //function : SetSemiAngle
214 //purpose  : 
215 //=======================================================================
216
217 void Geom_ConicalSurface::SetSemiAngle (const Standard_Real Ang) {
218
219   if (Abs(Ang) <= gp::Resolution() || Abs(Ang) >= M_PI/2.0 - gp::Resolution()) {
220     throw Standard_ConstructionError();
221   }
222   semiAngle = Ang;
223 }
224
225
226 //=======================================================================
227 //function : Apex
228 //purpose  : 
229 //=======================================================================
230
231 Pnt Geom_ConicalSurface::Apex () const 
232 {
233
234    XYZ Coord = Position().Direction().XYZ();
235    Coord.Multiply (-radius / Tan (semiAngle));
236    Coord.Add      (Position().Location().XYZ());
237    return Pnt     (Coord);
238 }
239
240
241 //=======================================================================
242 //function : Bounds
243 //purpose  : 
244 //=======================================================================
245
246 void Geom_ConicalSurface::Bounds (Standard_Real& U1, Standard_Real& U2, 
247                                   Standard_Real& V1, Standard_Real& V2) const {
248
249    U1 = 0.0;  U2 = 2.0 * M_PI;  
250    V1 = -Precision::Infinite();  V2 = Precision::Infinite();
251 }
252
253
254 //=======================================================================
255 //function : Coefficients
256 //purpose  : 
257 //=======================================================================
258
259 void Geom_ConicalSurface::Coefficients (Standard_Real& A1, Standard_Real& A2, Standard_Real& A3,
260                                         Standard_Real& B1, Standard_Real& B2, Standard_Real& B3,
261                                         Standard_Real& C1, Standard_Real& C2, Standard_Real& C3, 
262                                         Standard_Real& D)  const 
263 {
264    // Dans le repere du cone :
265    // X**2 + Y**2 - (Myradius - Z * Tan(semiAngle))**2 = 0.0
266
267       Trsf T;
268       T.SetTransformation (pos);
269       Standard_Real KAng = Tan (semiAngle);
270       Standard_Real T11 = T.Value (1, 1);
271       Standard_Real T12 = T.Value (1, 2);
272       Standard_Real T13 = T.Value (1, 3);
273       Standard_Real T14 = T.Value (1, 4);
274       Standard_Real T21 = T.Value (2, 1);
275       Standard_Real T22 = T.Value (2, 2);
276       Standard_Real T23 = T.Value (2, 3);
277       Standard_Real T24 = T.Value (2, 4);
278       Standard_Real T31 = T.Value (3, 1) * KAng;
279       Standard_Real T32 = T.Value (3, 2) * KAng;
280       Standard_Real T33 = T.Value (3, 3) * KAng;
281       Standard_Real T34 = T.Value (3, 4) * KAng;
282       A1 = T11 * T11 + T21 * T21 - T31 * T31;
283       A2 = T12 * T12 + T22 * T22 - T32 * T32;
284       A3 = T13 * T13 + T23 * T23 - T33 * T33;
285       B1 = T11 * T12 + T21 * T22 - T31 * T32;
286       B2 = T11 * T13 + T21 * T23 - T31 * T33;
287       B3 = T12 * T13 + T22 * T23 - T32 * T33;
288       C1 = T11 * T14 + T21 * T24 + radius * T31;
289       C2 = T12 * T14 + T22 * T24 + radius * T32;
290       C3 = T13 * T14 + T23 * T24 + radius * T33;
291       D = T14 * T14 + T24 * T24 - radius * radius - T34 * T34 +
292           2.0 * radius * T34;  
293 }
294
295
296
297 //=======================================================================
298 //function : D0
299 //purpose  : 
300 //=======================================================================
301
302 void Geom_ConicalSurface::D0 (const Standard_Real U, const Standard_Real V, Pnt& P) const 
303 {
304
305   P = ElSLib::ConeValue (U, V, pos, radius, semiAngle);
306 }
307
308
309 //=======================================================================
310 //function : D1
311 //purpose  : 
312 //=======================================================================
313
314 void Geom_ConicalSurface::D1 (const Standard_Real U  , const Standard_Real V, 
315                                     Pnt& P  , 
316                                     Vec& D1U, Vec& D1V     ) const 
317 {
318   ElSLib::ConeD1 (U, V, pos, radius, semiAngle, P, D1U, D1V);
319 }
320
321
322 //=======================================================================
323 //function : D2
324 //purpose  : 
325 //=======================================================================
326
327 void Geom_ConicalSurface::D2 ( const Standard_Real U  , const Standard_Real V, 
328                                      Pnt& P  ,  
329                                      Vec& D1U, Vec& D1V, 
330                                      Vec& D2U, Vec& D2V, Vec& D2UV) const 
331 {
332   ElSLib::ConeD2 (U, V, pos, radius, semiAngle, P, D1U, D1V, 
333                   D2U, D2V, D2UV);
334 }
335
336
337 //=======================================================================
338 //function : D3
339 //purpose  : 
340 //=======================================================================
341
342 void Geom_ConicalSurface::D3 (const Standard_Real U, const Standard_Real V, 
343                               Pnt& P      , 
344                               Vec& D1U    , Vec& D1V,
345                               Vec& D2U    , Vec& D2V, Vec& D2UV,
346                               Vec& D3U    , Vec& D3V, Vec& D3UUV, Vec& D3UVV
347                               ) const
348 {
349   ElSLib::ConeD3 (U, V, pos, radius, semiAngle, P, D1U, D1V, D2U, D2V,
350                   D2UV, D3U, D3V, D3UUV, D3UVV);
351 }
352
353
354 //=======================================================================
355 //function : DN
356 //purpose  : 
357 //=======================================================================
358
359 Vec Geom_ConicalSurface::DN (const Standard_Real    U , const Standard_Real     V, 
360                              const Standard_Integer Nu, const Standard_Integer Nv ) const
361 {
362   Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv < 0, " ");
363   if (Nv > 1) { return Vec (0.0, 0.0, 0.0); }
364   else {
365     return ElSLib::ConeDN (U, V, pos, radius, semiAngle, Nu, Nv);
366   }
367 }
368
369
370 //=======================================================================
371 //function : UIso
372 //purpose  : 
373 //=======================================================================
374
375 Handle(Geom_Curve) Geom_ConicalSurface::UIso (const Standard_Real U) const 
376 {
377   Handle(Geom_Line) 
378     GL = new Geom_Line(ElSLib::ConeUIso(pos,radius,semiAngle,U));
379   return GL;
380 }
381
382
383 //=======================================================================
384 //function : VIso
385 //purpose  : 
386 //=======================================================================
387
388 Handle(Geom_Curve) Geom_ConicalSurface::VIso (const Standard_Real V) const 
389 {
390   Handle(Geom_Circle) 
391     GC = new Geom_Circle(ElSLib::ConeVIso(pos,radius,semiAngle,V));
392   return GC;
393 }
394
395
396 //=======================================================================
397 //function : Transform
398 //purpose  : 
399 //=======================================================================
400
401 void Geom_ConicalSurface::Transform (const Trsf& T) 
402 {
403   radius = radius * Abs(T.ScaleFactor());
404   pos.Transform (T);
405 }
406
407 //=======================================================================
408 //function : TransformParameters
409 //purpose  : 
410 //=======================================================================
411
412 void Geom_ConicalSurface::TransformParameters(Standard_Real& ,
413                                               Standard_Real& V,
414                                               const gp_Trsf& T) 
415 const
416 {
417   if (!Precision::IsInfinite(V)) V *= Abs(T.ScaleFactor());
418 }
419
420 //=======================================================================
421 //function : ParametricTransformation
422 //purpose  : 
423 //=======================================================================
424
425 gp_GTrsf2d Geom_ConicalSurface::ParametricTransformation(const gp_Trsf& T)
426 const
427 {
428   gp_GTrsf2d T2;
429   gp_Ax2d Axis(gp::Origin2d(),gp::DX2d());
430   T2.SetAffinity(Axis, Abs(T.ScaleFactor()));
431   return T2;
432 }
433
434 //=======================================================================
435 //function : DumpJson
436 //purpose  : 
437 //=======================================================================
438 void Geom_ConicalSurface::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
439 {
440   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
441
442   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom_ElementarySurface)
443
444   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, radius)
445   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, semiAngle)
446 }