0022627: Change OCCT memory management defaults
[occt.git] / src / GeomToIGES / GeomToIGES_GeomSurface.cxx
1 // File:        GeomToIGES_GeomSurface.cxx
2
3 // modif du 22/10/96 mjm
4 // ajout du champ TheLength
5 //:l6 abv 15.01.99: CTS22022: writing full tori
6 //szv#4:S4163:12Mar99
7 //S4181 pdn 20.04.99 implementing of writing IGES elementary surfaces.
8 //szv#10:PRO19566:05Oct99 workaround against weights array loss
9
10 #include <GeomToIGES_GeomSurface.ixx>
11 #include <GeomToIGES_GeomCurve.hxx>
12 #include <GeomToIGES_GeomPoint.hxx>
13 #include <GeomToIGES_GeomVector.hxx>
14
15 #include <Geom_BSplineSurface.hxx>
16 #include <Geom_BezierSurface.hxx>
17 #include <Geom_BoundedSurface.hxx>
18 #include <Geom_CartesianPoint.hxx>
19 #include <Geom_ConicalSurface.hxx>
20 #include <Geom_Circle.hxx>
21 #include <Geom_Curve.hxx>
22 #include <Geom_CylindricalSurface.hxx>
23 #include <Geom_Curve.hxx>
24 #include <Geom_Direction.hxx>
25 #include <Geom_Geometry.hxx>
26 #include <Geom_Line.hxx>
27 #include <Geom_OffsetSurface.hxx>
28 #include <Geom_Plane.hxx>
29 #include <Geom_Point.hxx>
30 #include <Geom_RectangularTrimmedSurface.hxx>
31 #include <Geom_SphericalSurface.hxx>
32 #include <Geom_Surface.hxx>
33 #include <Geom_SurfaceOfLinearExtrusion.hxx>
34 #include <Geom_SurfaceOfRevolution.hxx>
35 #include <Geom_SweptSurface.hxx>
36 #include <Geom_ToroidalSurface.hxx>
37
38 #include <GeomConvert.hxx>
39
40 #include <GeomLProp_SLProps.hxx>
41
42 #include <IGESConvGeom_GeomBuilder.hxx>
43
44 #include <IGESData_IGESEntity.hxx>
45
46 #include <IGESGeom_BoundedSurface.hxx>
47 #include <IGESGeom_BSplineSurface.hxx>
48 #include <IGESGeom_CircularArc.hxx>
49 #include <IGESGeom_CurveOnSurface.hxx>
50 #include <IGESGeom_Direction.hxx>
51 #include <IGESGeom_Line.hxx>
52 #include <IGESGeom_OffsetSurface.hxx>
53 #include <IGESGeom_Plane.hxx>
54 #include <IGESGeom_Point.hxx>
55 #include <IGESGeom_RuledSurface.hxx>
56 #include <IGESGeom_SurfaceOfRevolution.hxx>
57 #include <IGESGeom_TabulatedCylinder.hxx>
58 #include <IGESGeom_TransformationMatrix.hxx>
59
60 #include <IGESSolid_PlaneSurface.hxx>
61 #include <Interface_Macros.hxx>
62
63 #include <gce_MakeLin.hxx>
64
65 #include <gp.hxx>
66 #include <gp_Ax1.hxx>
67 #include <gp_Ax3.hxx>
68 #include <gp_Cone.hxx>
69 #include <gp_Cylinder.hxx>
70 #include <gp_Dir.hxx>
71 #include <gp_Pln.hxx>
72 #include <gp_Pnt.hxx>
73 #include <gp_Sphere.hxx>
74 #include <gp_Torus.hxx>
75 #include <gp_Trsf.hxx>
76 #include <gp_Vec.hxx>
77 #include <gp_XYZ.hxx>
78
79 #include <Precision.hxx>
80
81 #include <TColgp_HArray2OfXYZ.hxx>
82 #include <TColStd_HArray1OfReal.hxx>
83 #include <TColStd_HArray2OfReal.hxx>
84 #include <IGESSolid_CylindricalSurface.hxx>
85 #include <IGESSolid_ConicalSurface.hxx>
86 #include <IGESSolid_SphericalSurface.hxx>
87 #include <IGESSolid_ToroidalSurface.hxx>
88 #include <Geom_TrimmedCurve.hxx>
89
90   
91 //=============================================================================
92 // GeomToIGES_GeomSurface
93 //=============================================================================
94
95 GeomToIGES_GeomSurface::GeomToIGES_GeomSurface()
96 :GeomToIGES_GeomEntity()
97 {
98   myBRepMode = Standard_False;
99   myAnalytic = Standard_False;
100 }
101
102
103 //=============================================================================
104 // GeomToIGES_GeomSurface
105 //=============================================================================
106
107 GeomToIGES_GeomSurface::GeomToIGES_GeomSurface(const GeomToIGES_GeomEntity& GE)
108      :GeomToIGES_GeomEntity(GE)
109 {
110   myBRepMode = Standard_False;
111   myAnalytic = Standard_False;
112 }
113
114
115 //=============================================================================
116 // Transfer des Entites Surface de Geom vers IGES
117 // TransferSurface
118 //=============================================================================
119
120 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface(const Handle(Geom_Surface)& start, 
121                                                                     const Standard_Real Udeb,
122                                                                     const Standard_Real Ufin, 
123                                                                     const Standard_Real Vdeb, 
124                                                                     const Standard_Real Vfin)
125 {
126   Handle(IGESData_IGESEntity) res;
127   if (start.IsNull()) {
128     return res;
129   }
130
131   if (start->IsKind(STANDARD_TYPE(Geom_BoundedSurface))) {
132     DeclareAndCast(Geom_BoundedSurface, Bounded, start);
133     res = TransferSurface(Bounded, Udeb, Ufin, Vdeb, Vfin);
134   }
135   else if (start->IsKind(STANDARD_TYPE(Geom_ElementarySurface))) {
136     DeclareAndCast(Geom_ElementarySurface, Elementary, start);
137     res = TransferSurface(Elementary, Udeb, Ufin, Vdeb, Vfin);
138   }
139   else if ( start->IsKind(STANDARD_TYPE(Geom_SweptSurface))) {
140     DeclareAndCast(Geom_SweptSurface, Swept, start);
141     res = TransferSurface(Swept, Udeb, Ufin, Vdeb, Vfin);
142   }
143   else if ( start->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
144     DeclareAndCast(Geom_OffsetSurface, OffsetS, start);
145     res = TransferSurface(OffsetS, Udeb, Ufin, Vdeb, Vfin);
146   }
147   
148   return res;
149 }
150  
151
152 //=============================================================================
153 // Transfer des Entites BoundedSurface de Geom vers IGES
154 // TransferSurface
155 //=============================================================================
156
157 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface(const Handle(Geom_BoundedSurface)& start, 
158                                                                     const Standard_Real Udeb,
159                                                                     const Standard_Real Ufin,
160                                                                     const Standard_Real Vdeb, 
161                                                                     const Standard_Real Vfin)
162 {
163   Handle(IGESData_IGESEntity) res;
164   if (start.IsNull()) {
165     return res;
166   }
167
168   if (start->IsKind(STANDARD_TYPE(Geom_BSplineSurface))) {
169     DeclareAndCast(Geom_BSplineSurface, BSpline, start);
170     res = TransferSurface(BSpline, Udeb, Ufin, Vdeb, Vfin);
171   }
172   else if (start->IsKind(STANDARD_TYPE(Geom_BezierSurface))) {
173     DeclareAndCast(Geom_BezierSurface, Bezier, start);
174     res = TransferSurface(Bezier, Udeb, Ufin, Vdeb, Vfin);
175   }
176   else if ( start->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
177     DeclareAndCast(Geom_RectangularTrimmedSurface, Trimmed, start);
178     res = TransferSurface(Trimmed,Udeb, Ufin, Vdeb, Vfin);
179   }
180
181   return res;
182 }
183
184
185 //=============================================================================
186 // Transfer des Entites BSplineSurface de Geom vers IGES
187 // TransferSurface
188 //=============================================================================
189
190 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface(const Handle(Geom_BSplineSurface)& start,
191                                                                     const Standard_Real Udeb,
192                                                                     const Standard_Real Ufin,
193                                                                     const Standard_Real Vdeb,
194                                                                     const Standard_Real Vfin)
195 {
196   //  a b-spline surface is defined by :
197   //         The U and V Degree (up to 25)
198   //         The Poles  (and the weights if it is rational)
199   //         The U and V Knots and Multiplicities
200   //         
201   //  The knot vector   is an  increasing  sequence  of reals without  repetition. 
202   //  The multiplicities are the repetition of the knots.
203   //           
204   //  If the knots are regularly spaced (the difference of two consecutive knots  
205   //  is a constant),
206   //  the knots repartition (in U or V) is :
207   //              - Uniform if all multiplicities are 1.
208   //              -  Quasi-uniform if  all multiplicities are  1
209   //              but the first and the last which are Degree+1.
210   //              -   PiecewiseBezier if  all multiplicites  are
211   //              Degree but the   first and the  last which are
212   //              Degree+1. 
213   //              
214   //         The surface may be periodic in U and in V. 
215   //              On a U periodic surface if there are k U knots
216   //              and the poles table  has p rows.  the U period
217   //              is uknot(k) - uknot(1)
218   //              
219   //              the poles and knots are infinite vectors with :
220   //                uknot(i+k) = uknot(i) + period
221   //                pole(i+p,j) = pole(i,j)
222
223
224   Handle(IGESData_IGESEntity) res;
225   TheLength = 1;
226   if (start.IsNull()) {
227     return res;
228   }
229
230   Handle(IGESGeom_BSplineSurface) BSpline = new IGESGeom_BSplineSurface;
231   Handle(Geom_BSplineSurface) mysurface;
232   
233   Standard_Boolean PeriodU = start->IsUPeriodic();
234   Standard_Boolean PeriodV = start->IsVPeriodic();
235   if (PeriodU || PeriodV) {
236     mysurface = Handle(Geom_BSplineSurface)::DownCast(start->Copy());
237
238     //szv#10:PRO19566:05Oct99
239     Standard_Boolean workaround = !(mysurface->IsURational() || mysurface->IsVRational());
240     if (workaround) mysurface->SetWeight(1,1,0.3);
241
242     if ( PeriodU ) mysurface->SetUNotPeriodic();
243     if ( PeriodV ) mysurface->SetVNotPeriodic();
244
245     //szv#10:PRO19566:05Oct99
246     if (workaround) mysurface->SetWeight(1,1,1.);
247   }
248   else {
249     mysurface = start;
250   }
251  
252   Standard_Integer DegU = mysurface->UDegree();
253   Standard_Integer DegV = mysurface->VDegree();
254   Standard_Boolean CloseU = mysurface->IsUClosed();
255   Standard_Boolean CloseV = mysurface->IsVClosed();
256   //Standard_Boolean PeriodU = start->IsUPeriodic();
257   //Standard_Boolean PeriodV = start->IsVPeriodic();
258   Standard_Boolean RationU = mysurface->IsURational();
259   Standard_Boolean RationV = mysurface->IsVRational();
260   Standard_Integer NbUPoles = mysurface->NbUPoles();
261   Standard_Integer NbVPoles = mysurface->NbVPoles();
262   Standard_Integer IndexU = NbUPoles -1;
263   Standard_Integer IndexV = NbVPoles -1;
264   Standard_Boolean Polynom = !(RationU || RationV); //szv#10:PRO19566:05Oct99 && was wrong
265
266   // filling knots array for U :
267   // Sequence des Knots de [-DegU, IndexU+1] dans IGESGeom.
268   Standard_Integer Knotindex;
269   Standard_Real rtampon;
270   Standard_Integer itampon;
271   TColStd_Array1OfReal KU(1, NbUPoles+ DegU+ 1);
272   mysurface->UKnotSequence(KU);
273   itampon = -DegU;
274   Handle(TColStd_HArray1OfReal) KnotsU = 
275     new TColStd_HArray1OfReal(-DegU,IndexU+1 );
276   for ( Knotindex=KU.Lower(); Knotindex<=KU.Upper(); Knotindex++) { 
277     rtampon = KU.Value(Knotindex);
278     KnotsU->SetValue(itampon, rtampon);
279     itampon++;
280   }
281
282   // filling knots array for V :
283   // Sequence des Knots de [-DegV, IndexV+1] dans IGESGeom.
284   TColStd_Array1OfReal KV(1, NbVPoles+ DegV+ 1);
285   mysurface->VKnotSequence(KV);
286   itampon = -DegV;
287   Handle(TColStd_HArray1OfReal) KnotsV = 
288     new TColStd_HArray1OfReal(-DegV, IndexV+1);
289   for ( Knotindex=KV.Lower(); Knotindex<=KV.Upper(); Knotindex++) { 
290     rtampon = KV.Value(Knotindex);
291     KnotsV->SetValue(itampon, rtampon);
292     itampon++;
293   }
294
295   // filling Weights array de [0, IndexU, 0, IndexV]
296   // ----------------------------------------------
297   Handle(TColStd_HArray2OfReal) Weights = 
298     new TColStd_HArray2OfReal(0 , IndexU, 0, IndexV);
299   Standard_Integer WeightRow = Weights->LowerRow();
300   Standard_Integer WeightCol = Weights->LowerCol();
301   Standard_Integer iw, jw;
302
303   if(RationU || RationV) {
304     for ( iw = 1; iw<= IndexU+1; iw++) {
305       for ( jw = 1; jw<= IndexV+1; jw++)
306         Weights->SetValue(WeightRow, WeightCol++, mysurface->Weight(iw,jw));
307       WeightRow++;
308       WeightCol = Weights->LowerCol();
309     }
310   } else {
311     for ( iw = 1; iw<= IndexU+1; iw++) {
312       for ( jw = 1; jw<= IndexV+1; jw++) 
313         Weights->SetValue(WeightRow, WeightCol++, 1.0);
314       WeightRow++;
315       WeightCol = Weights->LowerCol();
316     }
317
318   }
319       
320   // filling Poles array de [0, IndexU, 0, IndexV]
321   // ---------------------------------------------
322   Handle(TColgp_HArray2OfXYZ) Poles = 
323     new TColgp_HArray2OfXYZ(0, IndexU, 0, IndexV);
324   Standard_Integer UIndex = Poles->LowerRow();
325   Standard_Integer VIndex = Poles->LowerCol();
326   Standard_Integer ipole, jpole;
327   Standard_Real Xd, Yd, Zd;
328
329   for ( ipole = 1; ipole<= IndexU+1; ipole++) {
330     for ( jpole = 1; jpole<= IndexV+1; jpole++) {
331       gp_Pnt tempPnt = mysurface-> Pole(ipole, jpole);
332       tempPnt.Coord(Xd, Yd, Zd);
333       gp_XYZ PXYZ = gp_XYZ( Xd/GetUnit(), Yd/GetUnit(), Zd/GetUnit());
334       Poles->SetValue(UIndex, VIndex++, PXYZ);
335     }     
336     UIndex++;
337     VIndex = Poles->LowerCol();
338   }
339       
340   // mjm le 9/10/97 mise en place d`une protection
341   Standard_Real U1,U2,V1,V2;
342   Standard_Real Umin = Udeb;
343   Standard_Real Umax = Ufin;
344   Standard_Real Vmin = Vdeb;
345   Standard_Real Vmax = Vfin;
346   mysurface->Bounds(U1,U2,V1,V2);
347   if ( U1 > Umin ) Umin = U1;
348   if ( V1 > Vmin ) Vmin = V1;
349   if ( U2 < Umax ) Umax = U2;
350   if ( V2 < Vmax ) Vmax = V2;
351
352   BSpline-> Init (IndexU, IndexV, DegU, DegV, CloseU, CloseV, Polynom, PeriodU, 
353                   PeriodV, KnotsU, KnotsV, Weights, Poles, Umin, Umax, Vmin, Vmax);
354   res = BSpline;
355   return res;
356 }
357
358
359 //=============================================================================
360 // Transfer des Entites BezierSurface de Geom vers IGES
361 // TransferSurface
362 //=============================================================================
363
364 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface(const Handle(Geom_BezierSurface)& start,
365                                                                     const Standard_Real /*Udeb*/,
366                                                                     const Standard_Real /*Ufin*/,
367                                                                     const Standard_Real /*Vdeb*/,
368                                                                     const Standard_Real /*Vfin*/)
369 {
370   Handle(IGESData_IGESEntity) res;
371   if (start.IsNull()) {
372     return res;
373   }
374
375   Handle(Geom_BSplineSurface) Bspline = 
376     GeomConvert::SurfaceToBSplineSurface(start);
377   Standard_Real U1,U2,V1,V2;
378   Bspline->Bounds(U1,U2,V1,V2);
379   res = TransferSurface(Bspline, U1, U2, V1, V2);
380   return res;
381 }
382
383
384 //=============================================================================
385 // Transfer des Entites RectangularTrimmedSurface de Geom vers IGES
386 // TransferSurface
387 //=============================================================================
388
389 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface(const Handle(Geom_RectangularTrimmedSurface)& start,
390                                                                     const Standard_Real Udeb,
391                                                                     const Standard_Real Ufin,
392                                                                     const Standard_Real Vdeb,
393                                                                     const Standard_Real Vfin)
394 {
395   Handle(IGESData_IGESEntity) res;
396   if (start.IsNull()) {
397     return res;
398   }
399
400   Handle(Geom_Surface) st = start->BasisSurface();
401   if (st->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { 
402     //message d'erreur pas de trimmed a partir d'une trimmed , 
403     //on peut eventuellement ecrire la surface de base : st.
404     return res;
405   }
406
407   res = TransferSurface(st, Udeb, Ufin, Vdeb, Vfin);
408   return res;
409
410 }
411
412
413 //=============================================================================
414 // Transfer des Entites ElementarySurface de Geom vers IGES
415 // TransferSurface
416 //=============================================================================
417
418 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface(const Handle(Geom_ElementarySurface)& start, 
419                                                                     const Standard_Real Udeb,
420                                                                     const Standard_Real Ufin,
421                                                                     const Standard_Real Vdeb,
422                                                                     const Standard_Real Vfin)
423 {
424   Handle(IGESData_IGESEntity) res;
425   //  All these entities are located in 3D space with an axis
426   //  placement (Location point, XAxis, YAxis, ZAxis). It is 
427   //  their local coordinate system.
428
429   //S4181 pdn 16.04.99 Hereunder, the implementation of translation of CAS.CADE
430   // elementary surfaces into different types of IGES surfaces according to boolean flags
431   if (start.IsNull()) {
432     return res;
433   }
434   if (start->IsKind(STANDARD_TYPE(Geom_Plane))) {
435     DeclareAndCast(Geom_Plane, Plane, start);
436     if(myBRepMode)
437       res = TransferPlaneSurface(Plane, Udeb, Ufin, Vdeb, Vfin);
438     else
439       res = TransferSurface(Plane, Udeb, Ufin, Vdeb, Vfin);
440   }
441   else if (start->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
442     DeclareAndCast(Geom_CylindricalSurface, Cylindrical, start);
443     if(myBRepMode&&myAnalytic)
444       res = TransferCylindricalSurface(Cylindrical, Udeb, Ufin, Vdeb, Vfin);
445     else
446       res = TransferSurface(Cylindrical, Udeb, Ufin, Vdeb, Vfin);
447   }
448   else if ( start->IsKind(STANDARD_TYPE(Geom_ConicalSurface))) {
449     DeclareAndCast(Geom_ConicalSurface, Conical, start);
450     if(myBRepMode&&myAnalytic)
451       res = TransferConicalSurface(Conical, Udeb, Ufin, Vdeb, Vfin);
452     else
453       res = TransferSurface(Conical, Udeb, Ufin, Vdeb, Vfin);
454   }
455   else if (start->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
456     DeclareAndCast(Geom_SphericalSurface, Spherical, start);
457     if(myBRepMode&&myAnalytic)
458       res = TransferSphericalSurface(Spherical, Udeb, Ufin, Vdeb, Vfin);
459     else
460       res = TransferSurface(Spherical, Udeb, Ufin, Vdeb, Vfin);
461   }
462   else if ( start->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))) {
463     DeclareAndCast(Geom_ToroidalSurface, Toroidal, start);
464     if(myBRepMode&&myAnalytic)
465       res = TransferToroidalSurface(Toroidal, Udeb, Ufin, Vdeb, Vfin);
466        else
467          res = TransferSurface(Toroidal, Udeb, Ufin, Vdeb, Vfin);
468   }
469   
470   return res;
471
472 }
473
474
475 //=============================================================================
476 // Transfer des Entites Plane de Geom vers IGES
477 // TransferSurface
478 //=============================================================================
479
480 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface(const Handle(Geom_Plane)& start,
481                                                                     const Standard_Real Udeb,
482                                                                     const Standard_Real Ufin,
483                                                                     const Standard_Real Vdeb,
484                                                                     const Standard_Real Vfin)
485 {
486   // on va ecrire une BSplineSurface pour pouvoir etre coherent avec les courbes 2d
487   Handle(IGESData_IGESEntity) res;
488   TheLength = 1;
489   if (start.IsNull()) {
490     return res;
491   }
492
493   Handle(IGESGeom_BSplineSurface) BSpline = new IGESGeom_BSplineSurface;
494   gp_Pnt P1 ,P2, P3, P4;
495   start->D0(Udeb, Vdeb, P1);
496   start->D0(Udeb, Vfin, P2);
497   start->D0(Ufin, Vdeb, P3);
498   start->D0(Ufin, Vfin, P4);
499   Handle(TColgp_HArray2OfXYZ) Poles = new TColgp_HArray2OfXYZ(0, 1, 0, 1);
500   Standard_Real X,Y,Z;
501   P1.Coord(X,Y,Z);
502   Poles->SetValue (0, 0, gp_XYZ(X/GetUnit(),Y/GetUnit(),Z/GetUnit()));
503   P2.Coord(X,Y,Z);
504   Poles->SetValue (0, 1, gp_XYZ(X/GetUnit(),Y/GetUnit(),Z/GetUnit()));
505   P3.Coord(X,Y,Z);
506   Poles->SetValue (1, 0, gp_XYZ(X/GetUnit(),Y/GetUnit(),Z/GetUnit()));
507   P4.Coord(X,Y,Z);
508   Poles->SetValue (1, 1, gp_XYZ(X/GetUnit(),Y/GetUnit(),Z/GetUnit()));
509
510   Handle(TColStd_HArray1OfReal) KnotsU = new TColStd_HArray1OfReal(-1,2);
511   KnotsU->SetValue(-1, Udeb);
512   KnotsU->SetValue(0, Udeb);
513   KnotsU->SetValue(1, Ufin);
514   KnotsU->SetValue(2, Ufin);
515
516   Handle(TColStd_HArray1OfReal) KnotsV = new TColStd_HArray1OfReal(-1,2);
517   KnotsV->SetValue(-1, Vdeb);
518   KnotsV->SetValue(0, Vdeb);
519   KnotsV->SetValue(1, Vfin);
520   KnotsV->SetValue(2, Vfin);
521
522   Handle(TColStd_HArray2OfReal) Weights = 
523     new TColStd_HArray2OfReal(0, 1, 0, 1, 1.);
524
525   //#32 rln 19.10.98
526   BSpline-> Init ( 1, 1, 1, 1, Standard_False , Standard_False, Standard_True, 
527                   Standard_False, Standard_False,
528                   KnotsU, KnotsV, Weights, Poles, Udeb, Ufin, Vdeb, Vfin);
529   res = BSpline;
530   return res;
531
532 }
533
534
535 //=============================================================================
536 // Transfer des Entites CylindricalSurface de Geom vers IGES
537 // TransferSurface
538 //=============================================================================
539
540 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface
541 ( const Handle(Geom_CylindricalSurface)& start, const Standard_Real Udeb, 
542  const Standard_Real Ufin, const Standard_Real Vdeb, const Standard_Real Vfin)
543 {
544   //  The "ZAxis" is the symmetry axis of the CylindricalSurface, 
545   //  it gives the direction of increasing parametric value V.
546   //  The parametrization range is :
547   //       U [0, 2*PI],  V ]- infinite, + infinite[
548   //  The "XAxis" and the "YAxis" define the placement plane of the 
549   //  surface (Z = 0, and parametric value V = 0)  perpendicular to 
550   //  the symmetry axis. The "XAxis" defines the origin of the 
551   //  parameter U = 0.  The trigonometric sense gives the positive 
552   //  orientation for the parameter U.
553
554   Handle(IGESData_IGESEntity) res;
555   TheLength = 1;
556   if (start.IsNull()) {
557     return res;
558   }
559
560   Handle(IGESGeom_SurfaceOfRevolution) Surf = new IGESGeom_SurfaceOfRevolution;
561   Standard_Real U1 = Udeb;
562   Standard_Real U2 = Ufin;
563   Standard_Real V1 = Vdeb;
564   Standard_Real V2 = Vfin;
565   if (Precision::IsNegativeInfinite(Vdeb)) V1 = -Precision::Infinite();
566   if (Precision::IsPositiveInfinite(Vfin)) V2 = Precision::Infinite();
567
568   // creation de la generatrice : Generatrix 
569   Handle(Geom_Line) Ligne = 
570     new Geom_Line (gp_Pnt(start->Cylinder().Radius(), 0.0, 0.0), 
571                    gp_Dir(0.0, 0.0, 1.0));
572   GeomToIGES_GeomCurve GC(*this);
573   Handle(IGESData_IGESEntity) Generatrix = GC.TransferCurve( Ligne, V1, V2);
574   gp_Pnt gen1 = Ligne->Value(V1);
575   gp_Pnt gen2 = Ligne->Value(V2);
576   TheLength = gen1.Distance(gen2);
577   
578
579   // creation de l`axe : Axis .
580   Handle(IGESGeom_Line) Axis = new IGESGeom_Line;
581   //#30 rln 19.10.98 IGES axis = reversed CAS.CADE axis
582   //Axis->Init(gp_XYZ(0.0, 0.0, 0.0), gp_XYZ(0.0, 0.0, 1.0/GetUnit()));
583   //Surf->Init (Axis, Generatrix, U1, U2);
584   Axis->Init(gp_XYZ (0, 0, 1. / GetUnit()), gp_XYZ (0, 0, 0));  
585   Surf->Init (Axis, Generatrix, 2 * M_PI - U2, 2 * M_PI - U1);
586
587
588   // creation de la Trsf (#124)
589   // il faut tenir compte de l`unite pour la matrice de transformation
590   // (partie translation).
591   IGESConvGeom_GeomBuilder Build;
592   Standard_Real xloc,yloc,zloc;
593   start->Cylinder().Location().Coord(xloc,yloc,zloc);
594   gp_Pnt Loc;
595   Loc.SetCoord(xloc, yloc, zloc);
596   gp_Ax3 Pos = start->Cylinder().Position();
597   Pos.SetLocation(Loc);
598   Build.SetPosition(Pos);
599   if (!Build.IsIdentity()){
600     Handle(IGESGeom_TransformationMatrix) TMat = 
601       new IGESGeom_TransformationMatrix;
602     TMat = Build.MakeTransformation(GetUnit());
603     Surf->InitTransf(TMat);
604   }
605   res = Surf;
606   return res;
607
608 }
609
610
611 //=============================================================================
612 // Transfer des Entites ConicalSurface de Geom vers IGES
613 // TransferSurface
614 //=============================================================================
615
616 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface
617 ( const Handle(Geom_ConicalSurface)& start, const Standard_Real Udeb, 
618  const Standard_Real Ufin, const Standard_Real Vdeb, const Standard_Real Vfin)
619 {
620   //  The "ZAxis" is the symmetry axis of the ConicalSurface, 
621   //  it gives the direction of increasing parametric value V.
622   //  The apex of the surface is on the negative side of this axis.
623   //  The parametrization range is  :
624   //     U [0, 2*PI],  V ]-infinite, + infinite[
625   //  The "XAxis" and the "YAxis" define the placement plane of the 
626   //  surface (Z = 0, and parametric value V = 0)  perpendicular to 
627   //  the symmetry axis. The "XAxis" defines the origin of the 
628   //  parameter U = 0.  The trigonometric sense gives the positive 
629   //  orientation for the parameter U.
630
631
632   Handle(IGESData_IGESEntity) res;
633   TheLength = 1;
634   if (start.IsNull()) {
635     return res;
636   }
637   Handle(IGESGeom_SurfaceOfRevolution) Surf = new IGESGeom_SurfaceOfRevolution;
638   Standard_Real U1 = Udeb;
639   Standard_Real U2 = Ufin;
640   Standard_Real V1 = Vdeb;
641   Standard_Real V2 = Vfin;
642   if (Precision::IsNegativeInfinite(Vdeb)) V1 = -Precision::Infinite();
643   if (Precision::IsPositiveInfinite(Vfin)) V2 = Precision::Infinite();
644
645   // creation de la generatrice : Generatrix
646   Handle(Geom_Line) Ligne = 
647     new Geom_Line( gp_Pnt(start->Cone().RefRadius(), 0.0, 0.0), 
648                    gp_Dir(sin(start->Cone().SemiAngle()), 0.,
649                           cos(start->Cone().SemiAngle())));
650   GeomToIGES_GeomCurve GC(*this);
651   Handle(IGESData_IGESEntity) Generatrix = GC.TransferCurve( Ligne, V1, V2);
652   gp_Pnt gen1 = Ligne->Value(V1);
653   gp_Pnt gen2 = Ligne->Value(V2);
654 //  TheLength = gen1.Distance(gen2)*Cos(start->Cone().SemiAngle());
655   TheLength = gen1.Distance(gen2);
656
657   // creation de l`axe : Axis .
658   Handle(IGESGeom_Line) Axis = new IGESGeom_Line;
659   //#30 rln 19.10.98 IGES axis = reversed CAS.CADE axis
660   //Axis->Init(gp_XYZ(0.0, 0.0, 0.0), gp_XYZ(0.0, 0.0, 1.0/GetUnit()));
661   //Surf->Init (Axis, Generatrix, U1, U2);
662   Axis->Init(gp_XYZ (0, 0, 1. / GetUnit()), gp_XYZ (0, 0, 0));  
663   Surf->Init (Axis, Generatrix, 2 * M_PI - U2, 2 * M_PI - U1);
664
665
666   // creation de la Trsf (#124)
667   // il faut tenir compte de l`unite pour la matrice de transformation
668   // (partie translation).
669   IGESConvGeom_GeomBuilder Build;
670   Standard_Real xloc,yloc,zloc;
671   start->Cone().Location().Coord(xloc,yloc,zloc);
672   gp_Pnt Loc;
673   Loc.SetCoord(xloc, yloc, zloc);
674   gp_Ax3 Pos = start->Cone().Position();
675   Pos.SetLocation(Loc);
676   Build.SetPosition(Pos);
677   if (!Build.IsIdentity()){
678     Handle(IGESGeom_TransformationMatrix) TMat = 
679       new IGESGeom_TransformationMatrix;
680     TMat = Build.MakeTransformation(GetUnit());
681     Surf->InitTransf(TMat);
682   }
683   res = Surf;
684   return res;
685
686 }
687
688
689 //=============================================================================
690 // Transfer des Entites SphericalSurface de Geom vers IGES
691 // TransferSurface
692 //=============================================================================
693
694 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface
695 ( const Handle(Geom_SphericalSurface)& start, const Standard_Real Udeb, 
696  const Standard_Real Ufin, const Standard_Real Vdeb, const Standard_Real Vfin)
697 {
698   //  The center of the sphere is the "Location" point of the local
699   //  coordinate system.
700   //  The V isoparametric curves of the surface  are defined by 
701   //  the section of the spherical surface with plane parallel to the
702   //  plane (Location, XAxis, YAxis). This plane defines the origin of
703   //  parametrization V.
704   //  The U isoparametric curves of the surface are defined by the 
705   //  section of the spherical surface with plane obtained by rotation
706   //  of the plane (Location, XAxis, ZAxis) around ZAxis. This plane
707   //  defines the origin of parametrization u.
708   //  The parametrization range is  U [0, 2*PI],  V [- PI/2, + PI/2]
709
710   Handle(IGESData_IGESEntity) res;
711   TheLength = 1;
712   if (start.IsNull()) {
713     return res;
714   }
715
716   Handle(IGESGeom_SurfaceOfRevolution) Surf = new IGESGeom_SurfaceOfRevolution;
717
718   Standard_Real U1 = Udeb;
719   Standard_Real U2 = Ufin;
720   Standard_Real V1 = Vdeb;
721   Standard_Real V2 = Vfin;
722
723   // creation de la generatrice : Generatrix (1/2 cercle)
724   gp_Ax2 Axe(gp::Origin(), -gp::DY(), gp::DX());
725   Handle(Geom_Circle) Cercle = 
726     new Geom_Circle(Axe, start->Sphere().Radius());
727   GeomToIGES_GeomCurve GC(*this);
728   Handle(IGESData_IGESEntity) Gen = GC.TransferCurve( Cercle, V1, V2);
729
730   // creation de l`axe : Axis .
731   Handle(IGESGeom_Line) Axis = new IGESGeom_Line;
732   //#30 rln 19.10.98 IGES axis = reversed CAS.CADE axis
733   //Axis->Init(gp_XYZ(0.0, 0.0, 0.0), gp_XYZ(0.0, 0.0, 1.0/GetUnit()));
734   Axis->Init(gp_XYZ (0, 0, 1. / GetUnit()), gp_XYZ (0, 0, 0));  
735
736   if ( Gen->IsKind(STANDARD_TYPE(IGESGeom_CircularArc))) {
737     //#30 rln 19.10.98 Surf->Init (Axis, Gen, U1, U2);
738     Surf->Init (Axis, Gen, 2 * M_PI - U2, 2 * M_PI - U1);
739     IGESConvGeom_GeomBuilder Build;
740     Standard_Real xloc,yloc,zloc;
741     start->Sphere().Location().Coord(xloc,yloc,zloc);
742     gp_Pnt Loc;
743     Loc.SetCoord(xloc, yloc, zloc);
744     gp_Ax3 Pos = start->Sphere().Position();
745     Pos.SetLocation(Loc);
746     Build.SetPosition(Pos);
747     if (!Build.IsIdentity()){    
748       Handle(IGESGeom_TransformationMatrix) TMat = 
749         new IGESGeom_TransformationMatrix;
750       TMat = Build.MakeTransformation(GetUnit());
751       Surf->InitTransf(TMat);
752     }
753   }
754   res = Surf;
755   return res;
756 }
757
758
759 //=============================================================================
760 // Transfer des Entites ToroidalSurface de Geom vers IGES
761 // TransferSurface
762 //=============================================================================
763
764 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface
765 ( const Handle(Geom_ToroidalSurface)& start, const Standard_Real Udeb, 
766  const Standard_Real Ufin, const Standard_Real Vdeb, const Standard_Real Vfin)
767 {
768   //  The "Location point" of the axis placement is the center 
769   //  of the surface.
770   //  The plane (Location, XAxis, ZAxis) defines the origin of the
771   //  parametrization U. The plane (Location, XAxis, YAxis)
772   //  defines the origin of the parametrization V.
773   //  The parametrization range is  U [0, 2*PI],  V [0, 2*PI]
774
775
776   Handle(IGESData_IGESEntity) res;
777   TheLength = 1;
778   if (start.IsNull()) {
779     return res;
780   }
781
782   Handle(IGESGeom_SurfaceOfRevolution) Surf = new IGESGeom_SurfaceOfRevolution;
783   Standard_Real U1 = Udeb;
784   Standard_Real U2 = Ufin;
785   Standard_Real V1 = Vdeb;
786   Standard_Real V2 = Vfin;
787
788   // creation de la generatrice : Generatrix (cercle)
789   gp_Ax2 Axe = gp_Ax2(gp_Pnt((start->Torus().MajorRadius()), 0., 0.),
790                       -gp::DY(), gp::DX());
791   Handle(Geom_Circle) Cercle = 
792     new Geom_Circle(Axe, start->Torus().MinorRadius());
793   GeomToIGES_GeomCurve GC(*this);
794   Handle(IGESData_IGESEntity) Gen = GC.TransferCurve( Cercle, V1, V2);
795   
796   // creation de l`axe : Axis .
797   Handle(IGESGeom_Line) Axis = new IGESGeom_Line;
798   //#30 rln 19.10.98 IGES axis = reversed CAS.CADE axis
799   //Axis->Init(gp_XYZ(0.0, 0.0, 0.0), gp_XYZ(0.0, 0.0, 1.0/GetUnit()));
800   Axis->Init(gp_XYZ (0, 0, 1. / GetUnit()), gp_XYZ (0, 0, 0));  
801
802 //:l6 abv: CTS22022: writing full tori:  if ( Gen->IsKind(STANDARD_TYPE(IGESGeom_CircularArc))) {
803     //#30 rln 19.10.98 Surf->Init (Axis, Gen, U1, U2);
804     Surf->Init (Axis, Gen, 2 * M_PI - U2, 2 * M_PI - U1);
805     IGESConvGeom_GeomBuilder Build;
806 /* //:l6: useless
807     Standard_Real xloc,yloc,zloc;
808     start->Torus().Location().Coord(xloc,yloc,zloc);
809     gp_Pnt Loc;
810     Loc.SetCoord(xloc, yloc, zloc);
811 */
812     gp_Ax3 Pos = start->Torus().Position();
813 //:l6    Pos.SetLocation(Loc);
814     Build.SetPosition(Pos);
815     if (!Build.IsIdentity()){
816       Handle(IGESGeom_TransformationMatrix) TMat = 
817         new IGESGeom_TransformationMatrix;
818       TMat = Build.MakeTransformation(GetUnit());
819       Surf->InitTransf(TMat);
820     }
821 //:l6  }
822   res = Surf;
823   return res;
824
825 }
826
827 //=============================================================================
828 // Transfer des Entites SweptSurface de Geom vers IGES
829 // TransferSurface
830 //=============================================================================
831
832 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface
833 ( const Handle(Geom_SweptSurface)& start, const Standard_Real Udeb, 
834  const Standard_Real Ufin, const Standard_Real Vdeb, const Standard_Real Vfin)
835 {
836   Handle(IGESData_IGESEntity) res;
837   if (start.IsNull()) {
838     return res;
839   }
840
841   if (start->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) {
842     DeclareAndCast(Geom_SurfaceOfLinearExtrusion, Extrusion, start);
843     res = TransferSurface(Extrusion, Udeb, Ufin, Vdeb, Vfin);
844   }
845   else if (start->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) {
846     DeclareAndCast(Geom_SurfaceOfRevolution, Revolution, start);
847     res = TransferSurface(Revolution, Udeb, Ufin, Vdeb, Vfin);
848   }
849
850   return res;
851
852 }
853
854 //=============================================================================
855 // Transfer des Entites SurfaceOfLinearExtrusion de Geom vers IGES
856 // TransferSurface
857 //=============================================================================
858
859 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface
860 ( const Handle(Geom_SurfaceOfLinearExtrusion)& start, const Standard_Real Udeb, 
861  const Standard_Real Ufin, const Standard_Real Vdeb, const Standard_Real Vfin)
862 {
863   //  This surface is obtained by sweeping a curve in a given direction.
864   //  The parametrization range for the parameter U is defined with the
865   //  referenced curve.
866   //  The parametrization range for the parameter V is 
867   //  ]-infinite, + infinite[
868   //  The position of the curve gives the origin for the parameter V.
869
870
871   Handle(IGESData_IGESEntity) res;
872   TheLength = 1;
873   if (start.IsNull()) {
874     return res;
875   }
876
877   Handle(IGESGeom_TabulatedCylinder) Surf = new IGESGeom_TabulatedCylinder;
878   Standard_Real U1 = Udeb;
879   Standard_Real U2 = Ufin;
880   Standard_Real V1 = Vdeb;
881   Standard_Real V2 = Vfin;
882   if (Precision::IsNegativeInfinite(Vdeb)) V1 = -Precision::Infinite();
883   if (Precision::IsPositiveInfinite(Vfin)) V2 = Precision::Infinite();
884
885   // added by skl 18.07.2005 for OCC9490
886   Standard_Real UF,UL,VF,VL;
887   start->Bounds(UF,UL,VF,VL);
888   U1=UF;
889   U2=UL;
890
891   Handle(Geom_Curve) TheCurve = start->BasisCurve();
892
893   //dans IGES l'origine de la generatrice est identique a l'origine 
894   //de la directrice , il faut translater la courbe si les deux 
895   //points ne sont pas confondus dans Geom et donc la copier !!!!!!!
896   gp_Pnt TheEnd = start->Value(U1,V2);
897   Standard_Real Xe, Ye, Ze;
898   TheEnd.Coord(Xe, Ye, Ze);
899   gp_XYZ End = gp_XYZ (Xe/GetUnit(), Ye/GetUnit(), Ze/GetUnit());
900
901   GeomToIGES_GeomCurve GC(*this);
902 // commented by skl 18.07.2005 for OCC9490
903   Handle(Geom_Curve) CopyCurve;
904   if ( Abs(V1) > Precision::Confusion()) {
905    CopyCurve = Handle(Geom_Curve)::DownCast
906      (TheCurve->Translated (start->Value(U1,0.), start->Value(U1,V1)));
907   }
908   else {
909     CopyCurve = TheCurve;
910   }
911   //Handle(IGESData_IGESEntity) Directrix = GC.TransferCurve( CopyCurve, V1, V2);
912   Handle(IGESData_IGESEntity) Directrix = GC.TransferCurve( CopyCurve, U1, U2);
913   //Handle(IGESData_IGESEntity) Directrix = GC.TransferCurve( TheCurve, U1, U2);
914   //gp_Pnt gen1 = start->Value(U1,V1);
915   //TheLength = gen1.Distance(TheEnd);
916
917   Surf->Init (Directrix, End);
918   res = Surf;
919   return res;
920
921 }
922
923 //=============================================================================
924 // Transfer des Entites SurfaceOfRevolution de Geom vers IGES
925 // TransferSurface
926 //=============================================================================
927
928 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface
929 ( const Handle(Geom_SurfaceOfRevolution)& start, const Standard_Real Udeb, 
930  const Standard_Real Ufin, const Standard_Real Vdeb, const Standard_Real Vfin)
931 {
932   //  The surface is obtained by rotating a curve a complete revolution
933   //  about an axis. The curve and the axis must be in the same plane.
934   //  For a complete surface of revolution the parametric range is
935   //  0 <= U <= 2*PI.
936   //  The parametric range for V is defined with the revolved curve.
937   //  The origin of the U parametrization is given by the position
938   //  of the revolved curve (reference). The direction of the revolution
939   //  axis defines the positive sense of rotation (trigonometric sense)
940   //  corresponding to the increasing of the parametric value U.
941   //  The derivatives are always defined for the u direction.
942   //  For the v direction the definition of the derivatives depends on
943   //  the degree of continuity of the referenced curve.
944
945   Handle(IGESData_IGESEntity) res;
946   TheLength = 1;
947   if (start.IsNull()) {
948     return res;
949   }
950
951   Handle(IGESGeom_SurfaceOfRevolution) Surf = new IGESGeom_SurfaceOfRevolution;
952   Standard_Real U1 = Udeb;
953   Standard_Real U2 = Ufin;
954   Standard_Real V1 = Vdeb;
955   Standard_Real V2 = Vfin;
956   if (Precision::IsNegativeInfinite(Vdeb)) V1 = -Precision::Infinite();
957   if (Precision::IsPositiveInfinite(Vfin)) V2 = Precision::Infinite();
958
959   // creation de la generatrice : Generatrix 
960   Handle(Geom_Curve) Curve = start->BasisCurve();
961   GeomToIGES_GeomCurve GC(*this);
962   Handle(IGESData_IGESEntity) Generatrix = GC.TransferCurve( Curve, V1, V2);
963   //pdn BUC184: decoding a trimmed curve
964   while( Curve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
965     Handle(Geom_TrimmedCurve) aTrCurve = Handle(Geom_TrimmedCurve)::
966       DownCast(Curve);
967     Curve = aTrCurve->BasisCurve();
968   }
969   
970   if ( Curve->IsKind(STANDARD_TYPE(Geom_Line))) {
971     DeclareAndCast(Geom_Line, Line, Curve);
972     gp_Pnt gen1 = Line->Value(V1);
973     gp_Pnt gen2 = Line->Value(V2);
974     TheLength = gen1.Distance(gen2);
975   }
976
977   // creation de l`axe : Axis .
978   Handle(IGESGeom_Line) Axis = new IGESGeom_Line;
979   gp_Ax1 Axe = start->Axis();
980   Standard_Real X1,Y1,Z1,X2,Y2,Z2;
981   Axe.Location().Coord(X1,Y1,Z1);
982   Axe.Direction().Coord(X2,Y2,Z2);
983
984   //#30 rln 19.10.98 IGES axis = reversed CAS.CADE axis
985   //Axis->Init(gp_XYZ(X1/GetUnit(),Y1/GetUnit(),Z1/GetUnit()),
986   //         gp_XYZ(X2/GetUnit(),Y2/GetUnit(),Z2/GetUnit()));
987   //#36 rln 27.10.98 BUC60328 face 7
988   Axis->Init(gp_XYZ(X1/GetUnit(),Y1/GetUnit(),Z1/GetUnit()),
989              gp_XYZ( (X1 - X2) / GetUnit(), (Y1 - Y2) / GetUnit(), (Z1 - Z2) / GetUnit()));
990
991   Surf->Init (Axis, Generatrix, 2 * M_PI - U2, 2 * M_PI - U1);
992   res = Surf;
993   return res;
994
995 }
996
997
998 //=============================================================================
999 // Transfer des Entites OffsetSurface de Geom vers IGES
1000 // TransferSurface
1001 //=============================================================================
1002
1003 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSurface
1004 ( const Handle(Geom_OffsetSurface)& start, const Standard_Real Udeb, const Standard_Real 
1005  Ufin, const Standard_Real Vdeb, const Standard_Real Vfin)
1006 {
1007   //  An offset surface is a surface at constant distance
1008   //  (Offset) from a basis surface. The distance may be positive
1009   //  or negative to the preferred side of the surface.
1010   //  The positive side is defined by the cross product D1u ^ D1v
1011   //  where D1u and D1v are the tangent vectors of the basis
1012   //  surface in the U and V parametric directions. The previous 
1013   //  cross product defines the normal direction to the basis
1014   //  surface.
1015
1016   Handle(IGESData_IGESEntity) res;
1017   if (start.IsNull()) {
1018     return res;
1019   }
1020
1021   Handle(IGESGeom_OffsetSurface) Surf = new IGESGeom_OffsetSurface;
1022   Handle(Geom_Surface) TheSurf = start->BasisSurface();
1023   Standard_Real U1, U2, V1, V2 , Um, Vm;
1024   start->Bounds (U1, U2, V1, V2);
1025   Um = (U1 + U2 ) /2.;
1026   Vm = (V1 + V2 ) /2.;
1027   Handle(IGESData_IGESEntity) Surface = TransferSurface
1028     (TheSurf, Udeb, Ufin, Vdeb, Vfin);
1029   Standard_Real Distance = start->Offset()/GetUnit();
1030   GeomLProp_SLProps Prop = GeomLProp_SLProps 
1031     (TheSurf, Um, Vm, 1, Precision::Confusion());
1032   gp_Dir Dir = Prop.Normal();
1033   Standard_Real Xd, Yd, Zd;
1034   Dir.Coord(Xd, Yd, Zd);
1035   gp_XYZ Indicator = gp_XYZ(Xd/GetUnit(), Yd/GetUnit(), Zd/GetUnit());
1036
1037   Surf-> Init (Indicator, Distance, Surface);
1038   res = Surf;
1039   return res;
1040
1041 }
1042
1043
1044 //=============================================================================
1045 // Transfer des Entites Plane de Geom vers IGESSolid
1046 // TransferPlaneSurface
1047 //=============================================================================
1048
1049 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferPlaneSurface(const Handle(Geom_Plane)& start,
1050                                                                          const Standard_Real /*Udeb*/,
1051                                                                          const Standard_Real /*Ufin*/,
1052                                                                          const Standard_Real /*Vdeb*/,
1053                                                                          const Standard_Real /*Vfin*/)
1054 {
1055   //  The parametrization range is  U, V  ]- infinite, + infinite[
1056   //  The local coordinate system of the plane is defined with
1057   //  an axis placement two axis.
1058
1059   Handle(IGESData_IGESEntity) res;
1060   TheLength = 1;
1061   if (start.IsNull()) {
1062     return res;
1063   }
1064
1065   Handle(IGESSolid_PlaneSurface) Plsurf = new IGESSolid_PlaneSurface;
1066   GeomToIGES_GeomPoint GP(*this);
1067   GeomToIGES_GeomVector GV(*this);
1068
1069   gp_Pln Pln = start->Pln();
1070
1071   Handle(Geom_CartesianPoint) mypoint = new Geom_CartesianPoint(Pln.Location()); 
1072   Handle(IGESGeom_Point) aLocation = GP.TransferPoint(mypoint);
1073
1074   gp_Ax1 Axe = Pln.Axis();
1075   Handle(Geom_Direction) mydir = new Geom_Direction(Axe.Direction()); 
1076   Handle(IGESGeom_Direction) aNormal = GV.TransferVector(mydir);
1077
1078   gp_Ax1 XAxe = Pln.XAxis();
1079   Handle(Geom_Direction) rdir = new Geom_Direction(XAxe.Direction()); 
1080   Handle(IGESGeom_Direction) refdir = GV.TransferVector(rdir);
1081
1082   Plsurf->Init (aLocation, aNormal, refdir);
1083   res = Plsurf;
1084   return res;
1085
1086 }
1087
1088 //=======================================================================
1089 //function : TransferCylindricaSurface
1090 //purpose  : 
1091 //=======================================================================
1092
1093 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferCylindricalSurface(const Handle(Geom_CylindricalSurface)& start,
1094                                                                                const Standard_Real /*Udeb*/,
1095                                                                                const Standard_Real /*Ufin*/,
1096                                                                                const Standard_Real /*Vdeb*/,
1097                                                                                const Standard_Real /*Vfin*/)
1098 {
1099
1100   Handle(IGESData_IGESEntity) res;
1101   TheLength = 1;
1102   if (start.IsNull()) {
1103     return res;
1104   }
1105
1106   Handle(IGESSolid_CylindricalSurface) CylSurf = new IGESSolid_CylindricalSurface;
1107   GeomToIGES_GeomPoint GP(*this);
1108   GeomToIGES_GeomVector GV(*this);
1109
1110   gp_Cylinder Cyl = start->Cylinder();
1111
1112   Handle(Geom_CartesianPoint) mypoint = new Geom_CartesianPoint(Cyl.Location()); 
1113   Handle(IGESGeom_Point) aLocation = GP.TransferPoint(mypoint);
1114
1115   gp_Ax1 Axe = Cyl.Axis();
1116   Handle(Geom_Direction) mydir = new Geom_Direction(Axe.Direction()); 
1117   Handle(IGESGeom_Direction) Axis = GV.TransferVector(mydir);
1118
1119   gp_Ax1 XAxe = Cyl.XAxis();
1120   Handle(Geom_Direction) rdir = new Geom_Direction(XAxe.Direction()); 
1121   Handle(IGESGeom_Direction) refdir = GV.TransferVector(rdir);
1122
1123   Standard_Real radius = Cyl.Radius();
1124   
1125   CylSurf->Init (aLocation, Axis, radius, refdir);
1126   res = CylSurf;
1127   return res;
1128 }
1129
1130
1131 //=======================================================================
1132 //function : TransferConicalSurface
1133 //purpose  : 
1134 //=======================================================================
1135
1136 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferConicalSurface(const Handle(Geom_ConicalSurface)& start,
1137                                                                            const Standard_Real /*Udeb*/,
1138                                                                            const Standard_Real /*Ufin*/,
1139                                                                            const Standard_Real /*Vdeb*/,
1140                                                                            const Standard_Real /*Vfin*/)
1141 {
1142
1143   Handle(IGESData_IGESEntity) res;
1144   TheLength = 1;
1145   if (start.IsNull()) {
1146     return res;
1147   }
1148
1149   Handle(IGESSolid_ConicalSurface) ConSurf = new IGESSolid_ConicalSurface;
1150   GeomToIGES_GeomPoint GP(*this);
1151   GeomToIGES_GeomVector GV(*this);
1152
1153   gp_Cone Con = start->Cone();
1154   Standard_Real radius = Con.RefRadius();
1155   Standard_Real angle  = Con.SemiAngle();
1156   gp_Ax1 Axe = Con.Axis();
1157   gp_Ax1 XAxe = Con.XAxis();
1158   gp_Dir XDir = XAxe.Direction();
1159
1160   Handle(Geom_CartesianPoint) mypoint = new Geom_CartesianPoint(Con.Location());
1161   if(angle < 0.) {
1162     gp_Pnt pnt = mypoint->Pnt();
1163     mypoint->SetPnt(Con.Apex().XYZ()*2-pnt.XYZ());
1164     angle = -angle;
1165     XDir.Reverse();
1166   }
1167   Handle(IGESGeom_Point) aLocation = GP.TransferPoint(mypoint);
1168
1169   Handle(Geom_Direction) mydir = new Geom_Direction(Axe.Direction()); 
1170   Handle(IGESGeom_Direction) Axis = GV.TransferVector(mydir);
1171
1172   Handle(Geom_Direction) rdir = new Geom_Direction(XDir);//XAxe.Direction()); 
1173   Handle(IGESGeom_Direction) refdir = GV.TransferVector(rdir);
1174
1175   ConSurf->Init (aLocation, Axis, radius, angle*180./M_PI, refdir);
1176   res = ConSurf;
1177   return res;
1178 }
1179
1180
1181 //=======================================================================
1182 //function : TransferSphericalSurface
1183 //purpose  : 
1184 //=======================================================================
1185
1186 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferSphericalSurface(const Handle(Geom_SphericalSurface)& start,
1187                                                                              const Standard_Real /*Udeb*/,
1188                                                                              const Standard_Real /*Ufin*/,
1189                                                                              const Standard_Real /*Vdeb*/,
1190                                                                              const Standard_Real /*Vfin*/)
1191 {
1192
1193   Handle(IGESData_IGESEntity) res;
1194   TheLength = 1;
1195   if (start.IsNull()) {
1196     return res;
1197   }
1198
1199   Handle(IGESSolid_SphericalSurface) SphSurf = new IGESSolid_SphericalSurface;
1200   GeomToIGES_GeomPoint GP(*this);
1201   GeomToIGES_GeomVector GV(*this);
1202
1203   gp_Sphere Sph = start->Sphere();
1204
1205   Handle(Geom_CartesianPoint) mypoint = new Geom_CartesianPoint(Sph.Location()); 
1206   Handle(IGESGeom_Point) aLocation = GP.TransferPoint(mypoint);
1207
1208   gp_Ax1 Axe = Sph.Position().Axis(); 
1209   Handle(Geom_Direction) mydir = new Geom_Direction(Axe.Direction()); 
1210   Handle(IGESGeom_Direction) Axis = GV.TransferVector(mydir);
1211
1212   gp_Ax1 XAxe = Sph.XAxis();
1213   Handle(Geom_Direction) rdir = new Geom_Direction(XAxe.Direction()); 
1214   Handle(IGESGeom_Direction) refdir = GV.TransferVector(rdir);
1215
1216   Standard_Real radius = Sph.Radius();
1217   
1218   SphSurf->Init (aLocation, radius, Axis, refdir);
1219   res = SphSurf;
1220   return res;
1221 }
1222
1223 Handle(IGESData_IGESEntity) GeomToIGES_GeomSurface::TransferToroidalSurface(const Handle(Geom_ToroidalSurface)& start,
1224                                                                             const Standard_Real /*Udeb*/,
1225                                                                             const Standard_Real /*Ufin*/,
1226                                                                             const Standard_Real /*Vdeb*/,
1227                                                                             const Standard_Real /*Vfin*/)
1228 {
1229
1230   Handle(IGESData_IGESEntity) res;
1231   TheLength = 1;
1232   if (start.IsNull()) {
1233     return res;
1234   }
1235
1236   Handle(IGESSolid_ToroidalSurface) TorSurf = new IGESSolid_ToroidalSurface;
1237   GeomToIGES_GeomPoint GP(*this);
1238   GeomToIGES_GeomVector GV(*this);
1239
1240   gp_Torus Tor = start->Torus();
1241
1242   Handle(Geom_CartesianPoint) mypoint = new Geom_CartesianPoint(Tor.Location()); 
1243   Handle(IGESGeom_Point) aLocation = GP.TransferPoint(mypoint);
1244
1245   gp_Ax1 Axe = Tor.Axis(); 
1246   Handle(Geom_Direction) mydir = new Geom_Direction(Axe.Direction()); 
1247   Handle(IGESGeom_Direction) Axis = GV.TransferVector(mydir);
1248
1249   gp_Ax1 XAxe = Tor.XAxis();
1250   Handle(Geom_Direction) rdir = new Geom_Direction(XAxe.Direction()); 
1251   Handle(IGESGeom_Direction) refdir = GV.TransferVector(rdir);
1252
1253   Standard_Real major = Tor.MajorRadius();
1254   Standard_Real minor = Tor.MinorRadius();
1255   
1256   TorSurf->Init (aLocation, Axis, major, minor, refdir);
1257   res = TorSurf;
1258   return res;
1259 }
1260
1261
1262 //=======================================================================
1263 //function : Length
1264 //purpose  : 
1265 //=======================================================================
1266 Standard_Real GeomToIGES_GeomSurface::Length() const
1267 {  return TheLength;  }
1268
1269 //=======================================================================
1270 //function : GetBRepMode
1271 //purpose  : 
1272 //=======================================================================
1273
1274 Standard_Boolean GeomToIGES_GeomSurface::GetBRepMode() const
1275 {
1276   return myBRepMode;
1277 }
1278
1279 //=======================================================================
1280 //function : SetBRepMode
1281 //purpose  : 
1282 //=======================================================================
1283
1284 void GeomToIGES_GeomSurface::SetBRepMode(const Standard_Boolean flag)
1285 {
1286   myBRepMode = flag;
1287 }
1288
1289 //=======================================================================
1290 //function : GetAnalyticMode
1291 //purpose  : 
1292 //=======================================================================
1293
1294 Standard_Boolean GeomToIGES_GeomSurface::GetAnalyticMode() const
1295 {
1296   return myAnalytic;
1297 }
1298
1299 void GeomToIGES_GeomSurface::SetAnalyticMode(const Standard_Boolean flag)
1300 {
1301   myAnalytic = flag;
1302 }
1303