0031313: Foundation Classes - Dump improvement for classes
[occt.git] / src / Geom / Geom_ToroidalSurface.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_Curve.hxx>
21 #include <Geom_Geometry.hxx>
22 #include <Geom_ToroidalSurface.hxx>
23 #include <GeomAbs_UVSense.hxx>
24 #include <gp.hxx>
25 #include <gp_Ax3.hxx>
26 #include <gp_Circ.hxx>
27 #include <gp_Dir.hxx>
28 #include <gp_Pnt.hxx>
29 #include <gp_Torus.hxx>
30 #include <gp_Trsf.hxx>
31 #include <gp_Vec.hxx>
32 #include <gp_XYZ.hxx>
33 #include <Standard_ConstructionError.hxx>
34 #include <Standard_DimensionError.hxx>
35 #include <Standard_RangeError.hxx>
36 #include <Standard_Type.hxx>
37
38 IMPLEMENT_STANDARD_RTTIEXT(Geom_ToroidalSurface,Geom_ElementarySurface)
39
40 typedef Geom_ToroidalSurface         ToroidalSurface;
41 typedef TColStd_Array1OfReal      Array1OfReal;
42 typedef gp_Ax1  Ax1;
43 typedef gp_Ax2  Ax2;
44 typedef gp_Ax3  Ax3;
45 typedef gp_Circ Circ;
46 typedef gp_Dir  Dir;
47 typedef gp_Pnt  Pnt;
48 typedef gp_Trsf Trsf;
49 typedef gp_Vec  Vec;
50 typedef gp_XYZ  XYZ;
51
52
53
54 //=======================================================================
55 //function : Copy
56 //purpose  : 
57 //=======================================================================
58
59 Handle(Geom_Geometry) Geom_ToroidalSurface::Copy () const {
60  
61    Handle(Geom_ToroidalSurface) Cs;
62    Cs = new ToroidalSurface (pos, majorRadius, minorRadius);
63    return Cs;
64 }
65
66
67
68 //=======================================================================
69 //function : Geom_ToroidalSurface
70 //purpose  : 
71 //=======================================================================
72
73 Geom_ToroidalSurface::Geom_ToroidalSurface 
74   ( const Ax3& A3, 
75     const Standard_Real MajorRadius, 
76     const Standard_Real MinorRadius )
77  
78 : majorRadius (MajorRadius), minorRadius (MinorRadius) {
79
80   if (MinorRadius < 0.0 || MajorRadius < 0.0) {
81     throw Standard_ConstructionError();
82   }
83   else {
84     pos = A3;
85   }
86 }
87
88
89 //=======================================================================
90 //function : Geom_ToroidalSurface
91 //purpose  : 
92 //=======================================================================
93
94 Geom_ToroidalSurface::Geom_ToroidalSurface (const gp_Torus& T)  
95 : majorRadius (T.MajorRadius()), minorRadius (T.MinorRadius()) {
96
97    pos = T.Position();
98 }
99
100
101
102 //=======================================================================
103 //function : MajorRadius
104 //purpose  : 
105 //=======================================================================
106
107 Standard_Real Geom_ToroidalSurface::MajorRadius () const { 
108
109   return majorRadius; 
110 }
111
112 //=======================================================================
113
114 //function : MinorRadius
115 //purpose  : 
116 //=======================================================================
117
118 Standard_Real Geom_ToroidalSurface::MinorRadius () const {
119   
120   return minorRadius; 
121 }
122
123
124 //=======================================================================
125 //function : UReversedParameter
126 //purpose  : 
127 //=======================================================================
128
129 Standard_Real Geom_ToroidalSurface::UReversedParameter( const Standard_Real U) const {
130
131   return (2.*M_PI - U);
132 }
133
134
135 //=======================================================================
136 //function : VReversedParameter
137 //purpose  : 
138 //=======================================================================
139
140 Standard_Real Geom_ToroidalSurface::VReversedParameter( const Standard_Real V) const {
141
142   return (2.*M_PI - V);
143 }
144
145
146 //=======================================================================
147 //function : IsUClosed
148 //purpose  : 
149 //=======================================================================
150
151 Standard_Boolean Geom_ToroidalSurface::IsUClosed () const {
152
153   return Standard_True; 
154 }
155
156 //=======================================================================
157 //function : IsVClosed
158 //purpose  : 
159 //=======================================================================
160
161 Standard_Boolean Geom_ToroidalSurface::IsVClosed () const {
162
163   return Standard_True; 
164 }
165
166 //=======================================================================
167 //function : IsUPeriodic
168 //purpose  : 
169 //=======================================================================
170
171 Standard_Boolean Geom_ToroidalSurface::IsUPeriodic () const {
172
173   return Standard_True; 
174 }
175
176 //=======================================================================
177 //function : IsVPeriodic
178 //purpose  : 
179 //=======================================================================
180
181 Standard_Boolean Geom_ToroidalSurface::IsVPeriodic () const {
182
183  return Standard_True; 
184 }
185
186
187 //=======================================================================
188 //function : SetMajorRadius
189 //purpose  : 
190 //=======================================================================
191
192 void Geom_ToroidalSurface::SetMajorRadius (const Standard_Real MajorRadius) {
193
194   if (MajorRadius - minorRadius <= gp::Resolution())
195     throw Standard_ConstructionError();
196   else 
197     majorRadius = MajorRadius;
198 }
199
200
201 //=======================================================================
202 //function : SetMinorRadius
203 //purpose  : 
204 //=======================================================================
205
206 void Geom_ToroidalSurface::SetMinorRadius (const Standard_Real MinorRadius) {
207
208   if (MinorRadius < 0.0 || majorRadius - MinorRadius <= gp::Resolution())
209     throw Standard_ConstructionError();
210   else 
211     minorRadius = MinorRadius;
212 }
213
214
215 //=======================================================================
216 //function : SetTorus
217 //purpose  : 
218 //=======================================================================
219
220 void Geom_ToroidalSurface::SetTorus (const gp_Torus& T) {
221   
222    minorRadius = T.MinorRadius();
223    majorRadius = T.MajorRadius();
224    pos = T.Position();
225 }
226
227
228 //=======================================================================
229 //function : Area
230 //purpose  : 
231 //=======================================================================
232
233 Standard_Real Geom_ToroidalSurface::Area () const {
234   return 4.0 * M_PI * M_PI * minorRadius * majorRadius;
235 }
236
237
238 //=======================================================================
239 //function : Bounds
240 //purpose  : 
241 //=======================================================================
242
243 void Geom_ToroidalSurface::Bounds (Standard_Real& U1,
244                                    Standard_Real& U2, 
245                                    Standard_Real& V1, 
246                                    Standard_Real& V2 ) const {
247  
248   U1 = 0.0;  
249   V1 = 0.0;  
250   U2 = 2*M_PI;  
251   V2 = 2*M_PI;
252 }
253
254
255 //=======================================================================
256 //function : Coefficients
257 //purpose  : 
258 //=======================================================================
259
260 void Geom_ToroidalSurface::Coefficients (Array1OfReal& Coef) const {
261
262   gp_Torus Tor (pos, majorRadius, minorRadius);
263   Tor.Coefficients (Coef);
264 }
265
266
267 //=======================================================================
268 //function : D0
269 //purpose  : 
270 //=======================================================================
271
272 void Geom_ToroidalSurface::D0 (const Standard_Real U, const Standard_Real V, Pnt& P) const 
273 {
274
275   ElSLib::TorusD0 (U, V, pos, majorRadius, minorRadius,P);
276 }
277
278
279 //=======================================================================
280 //function : D1
281 //purpose  : 
282 //=======================================================================
283
284 void Geom_ToroidalSurface::D1 
285   (const Standard_Real U, const Standard_Real V, 
286          Pnt& P, 
287          Vec& D1U, Vec& D1V) const 
288 {
289   ElSLib::TorusD1 (U, V, pos, majorRadius, minorRadius, P, D1U, D1V);  
290 }
291
292
293 //=======================================================================
294 //function : D2
295 //purpose  : 
296 //=======================================================================
297
298 void Geom_ToroidalSurface::D2 
299   (const Standard_Real U  , const Standard_Real V, 
300          Pnt& P  , 
301          Vec& D1U, Vec& D1V, 
302          Vec& D2U, Vec& D2V, Vec& D2UV ) const 
303 {
304   ElSLib::TorusD2 (U, V, pos, majorRadius, minorRadius, P, D1U, D1V,
305                    D2U, D2V, D2UV);  
306 }
307
308
309 //=======================================================================
310 //function : D3
311 //purpose  : 
312 //=======================================================================
313
314 void Geom_ToroidalSurface::D3 
315   (const Standard_Real U, const Standard_Real V,
316          Pnt& P, 
317          Vec& D1U, Vec& D1V,
318          Vec& D2U, Vec& D2V, Vec& D2UV,
319          Vec& D3U, Vec& D3V, Vec& D3UUV, Vec& D3UVV ) const 
320 {
321
322   ElSLib::TorusD3 (U, V, pos, majorRadius, minorRadius, P, D1U, D1V,
323                    D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV);  
324 }
325
326
327 //=======================================================================
328 //function : DN
329 //purpose  : 
330 //=======================================================================
331
332 Vec Geom_ToroidalSurface::DN 
333   (const Standard_Real    U , const Standard_Real    V, 
334    const Standard_Integer Nu, const Standard_Integer Nv ) const {
335
336   Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv <0, "  ");
337   return ElSLib::TorusDN (U, V, pos, majorRadius, minorRadius, Nu, Nv);
338 }
339
340
341 //=======================================================================
342 //function : Torus
343 //purpose  : 
344 //=======================================================================
345
346 gp_Torus Geom_ToroidalSurface::Torus () const {
347
348    return gp_Torus (pos, majorRadius, minorRadius);
349 }
350
351
352 //=======================================================================
353 //function : UIso
354 //purpose  : 
355 //=======================================================================
356
357 Handle(Geom_Curve) Geom_ToroidalSurface::UIso (const Standard_Real U) const 
358 {
359   Handle(Geom_Circle) 
360     GC = new Geom_Circle(ElSLib::TorusUIso(pos,majorRadius,minorRadius,U));
361   return GC;
362 }
363
364
365 //=======================================================================
366 //function : VIso
367 //purpose  : 
368 //=======================================================================
369
370 Handle(Geom_Curve) Geom_ToroidalSurface::VIso (const Standard_Real V) const 
371 {
372   Handle(Geom_Circle) GC = 
373     new Geom_Circle(ElSLib::TorusVIso(pos,majorRadius,minorRadius,V));
374   return GC;
375 }
376
377
378 //=======================================================================
379 //function : Volume
380 //purpose  : 
381 //=======================================================================
382
383 Standard_Real Geom_ToroidalSurface::Volume () const {
384
385   return (M_PI * minorRadius * minorRadius) * (2.0 * M_PI * majorRadius);
386 }
387
388
389 //=======================================================================
390 //function : Transform
391 //purpose  : 
392 //=======================================================================
393
394 void Geom_ToroidalSurface::Transform (const Trsf& T) {
395
396    majorRadius = majorRadius * Abs(T.ScaleFactor());
397    minorRadius = minorRadius * Abs(T.ScaleFactor());
398    pos.Transform (T);
399 }
400
401 //=======================================================================
402 //function : DumpJson
403 //purpose  : 
404 //=======================================================================
405 void Geom_ToroidalSurface::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
406 {
407   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
408
409   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Geom_ElementarySurface)
410
411   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, majorRadius)
412   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, minorRadius)
413 }