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