0025266: Debug statements in the source are getting flushed on to the console
[occt.git] / src / IGESToBRep / IGESToBRep_TopoSurface.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 //=======================================================================
15 //modified: 
16 // Integration to ensure SCCS base integrity
17 // 21.12.98 rln, gka S4054
18 // 28.12.98 dce S3767 New messaging system
19 //#55,#56 rln 25.12.98 UKI60878
20 //:l1 abv 10.01.99: USA60022 7289: fix missing seam
21 //#63 rln 19.01.99 UKI60878 no offset if C0 surface is converted into the grid of C1 surfaces
22 //%13 pdn 15.02.99 USA60293 entities 792, 8604 .. handling of C0 ruled surfaces, tabulated cylindres,
23 //                 and surfaces of revolution.
24 //:p4 abv, pdn 23.02.99: PRO9234 #15720: call BRepTools::Update() for faces
25 //%14 pdn 24.02.99 implementing of ShapeFix_Face on IGES  
26 //    pdn 17.04.99 S4181: Implementing of reading IGES elementary surfaces.
27 //    pdn 10.05.99 S4137: Using modified ShapeDivide tools
28 //#11 smh 22.12.99 BUC60625 Transform axis.
29 //#12 smh 12.12.99 FRA62468 - Using conversion to B-Spline for Offset surface
30 //=======================================================================
31
32 #include <IGESToBRep_TopoSurface.ixx>
33
34 #include <Standard_ErrorHandler.hxx>
35 #include <IGESToBRep.hxx>
36 #include <IGESToBRep_CurveAndSurface.hxx>
37 #include <IGESToBRep_TopoCurve.hxx>
38 #include <IGESToBRep_BasicCurve.hxx>
39 #include <IGESToBRep_BasicSurface.hxx>
40
41 #include <BRepAdaptor_Curve.hxx>
42 #include <BRepPrimAPI_MakePrism.hxx>
43 #include <BRepPrimAPI_MakeRevol.hxx>
44 //S4054: ShapeTool_MakeWire -> ShapeExtend_WireData //:g8: BRepLib_MakeWire -> ShapeTool_MakeWire
45 #include <BRepGProp.hxx>
46 #include <BRepFill.hxx>
47 #include <BRepLib_MakeFace.hxx>
48 #include <BRep_Builder.hxx>
49 #include <BRep_Tool.hxx>
50
51 #include <ElSLib.hxx>
52
53 #include <GProp.hxx>
54 #include <GProp_GProps.hxx>
55
56 #include <GeomAbs_Shape.hxx>
57
58 #include <Geom2d_Line.hxx>
59 #include <Geom2d_Curve.hxx>
60
61 #include <Geom_BezierCurve.hxx>
62 #include <Geom_Curve.hxx>
63 #include <Geom_ConicalSurface.hxx>
64 #include <Geom_CylindricalSurface.hxx>
65 #include <Geom_OffsetSurface.hxx>
66 #include <Geom_Plane.hxx>
67 #include <Geom_Surface.hxx>
68 #include <Geom_SurfaceOfLinearExtrusion.hxx>
69 #include <Geom_RectangularTrimmedSurface.hxx>
70 #include <Geom_SphericalSurface.hxx>
71 #include <Geom_ToroidalSurface.hxx>
72
73 #include <IGESData_IGESEntity.hxx>
74 #include <IGESData_ToolLocation.hxx>
75
76 #include <IGESGeom_BSplineSurface.hxx>
77 #include <IGESGeom_BoundedSurface.hxx>
78 #include <IGESGeom_CurveOnSurface.hxx>
79 #include <IGESGeom_Line.hxx>
80 #include <IGESGeom_Point.hxx>
81 #include <IGESGeom_Direction.hxx>
82
83 #include <IGESSolid_CylindricalSurface.hxx>
84 #include <IGESSolid_ConicalSurface.hxx>
85 #include <IGESSolid_ToroidalSurface.hxx>
86 #include <IGESSolid_SphericalSurface.hxx>
87 #include <IGESSolid_PlaneSurface.hxx>
88
89 #include <Interface_Macros.hxx>
90
91 #include <gp_GTrsf.hxx>
92
93 #include <Precision.hxx>
94
95 #include <TopAbs.hxx>
96
97 #include <TopoDS.hxx>
98 #include <TopoDS_Edge.hxx>
99 #include <TopoDS_Face.hxx>
100 #include <TopoDS_Iterator.hxx>
101 #include <TopoDS_Shape.hxx>
102 #include <TopoDS_Shell.hxx>
103 #include <TopoDS_Vertex.hxx>
104 #include <TopoDS_Wire.hxx>
105
106 #include <TopExp.hxx>
107 #include <TopExp_Explorer.hxx>
108
109 #include <TopLoc_Location.hxx>
110
111 #include <gp.hxx>
112 #include <gp_Ax1.hxx>
113 #include <gp_Cylinder.hxx>
114 #include <gp_Cone.hxx>
115 #include <gp_Dir.hxx>
116 #include <gp_Dir2d.hxx>
117 #include <gp_Pln.hxx>
118 #include <gp_Pnt.hxx>
119 #include <gp_Sphere.hxx>
120 #include <gp_Torus.hxx>
121 #include <gp_Trsf.hxx>
122 #include <gp_Vec.hxx>
123 #include <stdio.h>
124
125 //:e3
126 #include <TColgp_Array1OfPnt.hxx>
127 #include <TColStd_Array1OfReal.hxx>
128 #include <TColStd_Array1OfInteger.hxx>
129 #include <Geom_BSplineCurve.hxx>
130 #include <Geom_Line.hxx>
131 #include <BRepTools.hxx>//#16
132 #include <ShapeAnalysis.hxx>
133 //S4054
134 #include <ShapeExtend_WireData.hxx>
135 #include <ShapeFix_Wire.hxx>
136 #include <Geom_TrimmedCurve.hxx>
137 #include <GeomConvert.hxx>
138 #include <GeomLib.hxx>
139 #include <BSplCLib.hxx>
140 //S3767
141 #include <Message_Msg.hxx>
142 #include <IGESData_IGESModel.hxx>
143
144 #include <IGESGeom_CircularArc.hxx>
145 #include <ElCLib.hxx>
146
147 #include <BRepOffset_MakeOffset.hxx>
148 #include <BRep_Tool.hxx>
149 #include <Geom_BSplineSurface.hxx>
150 #include <ShapeAlgo.hxx>
151 #include <ShapeAlgo_AlgoContainer.hxx>
152 #include <BRepBuilderAPI_MakeFace.hxx>
153 #include <Geom_SurfaceOfRevolution.hxx>
154
155 //=======================================================================
156 //function : IGESToBRep_TopoSurface
157 //purpose  : 
158 //=======================================================================
159
160 IGESToBRep_TopoSurface::IGESToBRep_TopoSurface()
161      :IGESToBRep_CurveAndSurface()
162 {  
163 }
164
165
166 //=======================================================================
167 //function : IGESToBRep_TopoSurface
168 //purpose  : 
169 //=======================================================================
170
171 IGESToBRep_TopoSurface::IGESToBRep_TopoSurface
172   (const IGESToBRep_CurveAndSurface& CS)
173      :IGESToBRep_CurveAndSurface(CS)
174 {  
175 }
176
177
178 //=======================================================================
179 //function : IGESToBRep_TopoSurface
180 //purpose  : 
181 //=======================================================================
182
183 IGESToBRep_TopoSurface::IGESToBRep_TopoSurface
184   (const Standard_Real    eps,
185    const Standard_Real    epsCoeff,
186    const Standard_Real    epsGeom,
187    const Standard_Boolean mode,
188    const Standard_Boolean modeapprox,
189    const Standard_Boolean optimized)
190      :IGESToBRep_CurveAndSurface(eps, epsCoeff, epsGeom, mode, 
191                                  modeapprox, optimized)
192 {  
193 }
194
195 static Standard_Boolean extractCurve3d (const TopoDS_Shape& theEdges,
196                                         Handle(Geom_Curve)& theCurve)
197 {
198   TopExp_Explorer anExp(theEdges, TopAbs_EDGE);
199   Standard_Integer howMuch = 0;
200   Standard_Real f = 0., l = 0.;
201   for (; anExp.More(); anExp.Next()) {
202     TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
203     if (anEdge.IsNull())
204       continue;
205     howMuch++;
206     theCurve = BRep_Tool::Curve(anEdge, f, l);
207   }
208   if ( howMuch != 1 || theCurve.IsNull() )
209     return Standard_False;
210   
211   if ( f != theCurve->FirstParameter() || l != theCurve->LastParameter() )
212     theCurve = new Geom_TrimmedCurve ( theCurve, f, l );
213   return Standard_True;
214 }
215
216
217 //=======================================================================
218 //function : TransferTopoSurface
219 //purpose  : 
220 //=======================================================================
221
222 TopoDS_Shape IGESToBRep_TopoSurface::TransferTopoSurface
223        (const Handle(IGESData_IGESEntity)& st)
224 { // Declaration of messages// 
225   // DCE 22/12/98
226   //Message_Msg msg1005("IGES_1005");
227   ////////////////////////////
228
229   TopoDS_Shape res;
230   TheULength = 1.;
231   //S4054
232   if (st.IsNull()) {
233     Message_Msg msg1005("IGES_1005");
234     SendFail(st, msg1005);
235   }
236   ////modified by jgv, 20.11.2009 for OCC21487///
237   else if (HasShapeResult(st))
238     {
239       res = GetShapeResult(st);
240       return res;
241     }
242   ///////////////////////////////////////////////
243   else if (IGESToBRep::IsBasicSurface(st)) {
244     res = TransferTopoBasicSurface(st);
245   }
246   else if (st->IsKind(STANDARD_TYPE(IGESGeom_TrimmedSurface))) {
247     DeclareAndCast(IGESGeom_TrimmedSurface, st144, st);
248     res = TransferTrimmedSurface(st144);
249   }
250   else if (st->IsKind(STANDARD_TYPE(IGESGeom_SurfaceOfRevolution))) {
251     DeclareAndCast(IGESGeom_SurfaceOfRevolution, st120, st);
252     res = TransferSurfaceOfRevolution(st120);
253   }
254   else if (st->IsKind(STANDARD_TYPE(IGESGeom_TabulatedCylinder))) {
255     DeclareAndCast(IGESGeom_TabulatedCylinder, st122, st);
256     res = TransferTabulatedCylinder(st122);
257   }
258   else if (st->IsKind(STANDARD_TYPE(IGESGeom_RuledSurface))) {
259     DeclareAndCast(IGESGeom_RuledSurface, st118, st);
260     res = TransferRuledSurface(st118);
261   }
262   else if (st->IsKind(STANDARD_TYPE(IGESGeom_Plane))) {
263     DeclareAndCast(IGESGeom_Plane, st108, st);
264     res = TransferPlane(st108);
265   }
266   else if (st->IsKind(STANDARD_TYPE(IGESGeom_BoundedSurface))) {
267     DeclareAndCast(IGESGeom_BoundedSurface, st143, st);
268     res = TransferBoundedSurface(st143);
269   }
270   else if (st->IsKind(STANDARD_TYPE(IGESGeom_OffsetSurface))) {
271     DeclareAndCast(IGESGeom_OffsetSurface, st140, st);
272     res = TransferOffsetSurface(st140);
273   }
274   //S4181 pdn IGESSolid_PlaneSurface recognized as basic surface
275   else if (st->IsKind(STANDARD_TYPE(IGESBasic_SingleParent)))  {
276     DeclareAndCast(IGESBasic_SingleParent,st402_9,st);
277     res = TransferPerforate(st402_9);    // limite : Planes seulement
278   }
279   else {
280    //  AddFail(st, "The IGESEntity is not a Topologic Surface.");
281   }
282   SetShapeResult (st, res);
283   return res;
284 }
285
286 //=======================================================================
287 //function : TransferTopoBasicSurface
288 //purpose  : 
289 //=======================================================================
290
291 TopoDS_Shape IGESToBRep_TopoSurface::TransferTopoBasicSurface
292        (const Handle(IGESData_IGESEntity)& st)
293 { // Declaration of messages// 
294   // DCE 22/12/98
295   //Message_Msg msg1005("IGES_1005");
296   ////////////////////////////
297
298   TopoDS_Shape  res;
299
300   if (st.IsNull()) {
301     Message_Msg msg1005("IGES_1005");
302     SendFail(st, msg1005);
303     return res;
304   }
305   if (!IGESToBRep::IsBasicSurface(st)) {
306   //  AddFail(st, "BasicSurface Transfer Error : Not Allowed IGESEntity");  This message can not occur.
307     return res;
308   }
309
310   IGESToBRep_BasicSurface BS(*this);
311
312   Handle(Geom_Surface) surf = BS.TransferBasicSurface(st);
313   if (surf.IsNull()) {
314     // AddFail(st, "Surface Conversion Error"); Messages have ever been Added in the called function.
315     return res;
316   }
317
318   //#9 rln 26/02/98 UKI60106
319   if (surf->Continuity() < GeomAbs_C1) {
320     Message_Msg msg1250("IGES_1250");
321     SendWarning(st, msg1250);
322   }
323   if(surf->IsKind(STANDARD_TYPE(Geom_Plane))){
324     BRep_Builder B;
325     TopoDS_Face plane;
326     B.MakeFace(plane);
327     B.UpdateFace(plane, surf, TopLoc_Location(), Precision::Confusion());
328     res = plane; 
329   }
330   else {
331     BRepLib_MakeFace makeFace(surf, Precision::Confusion());
332     res = makeFace.Face();
333   }
334
335   if (st->HasTransf()) {
336     gp_Trsf trsf;
337     SetEpsilon(1.E-04);
338     if (IGESData_ToolLocation::ConvertLocation
339         (GetEpsilon(),st->CompoundLocation(),trsf,GetUnitFactor())) { 
340       TopLoc_Location locFace(trsf);
341       res.Move(locFace);
342     }
343     else {
344       Message_Msg msg1035("IGES_1035");
345       SendWarning(st, msg1035);
346     } 
347   }
348   return res;
349 }
350
351
352 //=======================================================================
353 //function : TransferRuledSurface
354 //purpose  : 
355 //=======================================================================
356 static void reparamBSpline(Handle(Geom_Curve)& curve,
357                            const Standard_Real First,
358                            const Standard_Real Last)
359 {
360   Handle (Geom_BSplineCurve) bscurve;
361   if (!curve->IsKind (STANDARD_TYPE (Geom_BSplineCurve))) {
362     if (curve->FirstParameter() < First || curve->LastParameter() > Last)
363       curve = new Geom_TrimmedCurve (curve, First, Last);
364     bscurve = GeomConvert::CurveToBSplineCurve (curve, Convert_RationalC1);
365   }
366   else {
367     bscurve = Handle (Geom_BSplineCurve)::DownCast (curve);
368     bscurve->Segment (First, Last);
369   }
370   
371   if (bscurve.IsNull())
372     return;
373   
374   TColStd_Array1OfReal Knots(1, bscurve->NbKnots());
375   bscurve->Knots(Knots);
376   BSplCLib::Reparametrize (0., 1., Knots);
377   bscurve->SetKnots(Knots);
378   curve = bscurve;
379 }
380
381 static void ReparamCurve(TopoDS_Edge& edge)
382 {
383   TopLoc_Location L;
384   Standard_Real First, Last;
385   
386   Handle (Geom_Curve) curve = Handle (Geom_Curve)::DownCast (BRep_Tool::Curve ( edge, L, First, Last )->Copy());
387   //if ( Abs (First) <= Precision::PConfusion() && Abs (Last - 1.) <= Precision::PConfusion() ) return;
388   if(!curve->IsKind(STANDARD_TYPE(Geom_Line))) return;
389   
390   reparamBSpline( curve, First, Last );
391   
392   BRep_Builder B;
393   B.UpdateEdge ( edge, curve, L, Precision::Confusion() );
394   B.Range ( edge, 0., 1 );
395 }
396
397
398 //=======================================================================
399 //function : TransferRuledSurface
400 //purpose  : 
401 //=======================================================================
402
403 TopoDS_Shape IGESToBRep_TopoSurface::TransferRuledSurface
404   (const Handle(IGESGeom_RuledSurface)& st)
405 { // Declaration of messages// 
406   // DCE 22/12/98
407   //Message_Msg msg1005("IGES_1005");
408   ////////////////////////////////
409   TopoDS_Shape res;
410
411   if (st.IsNull()) {
412     Message_Msg msg1005("IGES_1005");
413     SendFail(st, msg1005);
414     return res;
415   }
416
417   IGESToBRep_TopoCurve TC(*this);
418   //%13 pdn 12.02.99 
419   TC.SetContinuity (0);
420   Handle(IGESData_IGESEntity) igesCurve1 = st->FirstCurve();
421   Handle(IGESData_IGESEntity) igesCurve2 = st->SecondCurve();
422
423   if (igesCurve1.IsNull()) {
424     Message_Msg msg148("XSTEP_148");
425     SendFail(st, msg148); // Curve Reading Error : Null IGESEntity
426     return res;
427   }
428   if (igesCurve2.IsNull()) {
429     Message_Msg msg149("XSTEP_149");
430     SendFail(st, msg149); // Curve Reading Error : Null IGESEntity
431     return res;
432   }
433
434   Standard_Integer nbEdges1,   nbEdges2;
435   TopoDS_Shape     shape1,     shape2;
436   TopoDS_Wire      wire1,      wire2;
437   TopoDS_Wire      newWire1,   newWire2;
438   //TopoDS_Edge      edge1,      edge2; // skl
439
440   if (IGESToBRep::IsTopoCurve(igesCurve1)) { 
441     shape1 = TC.TransferTopoCurve(igesCurve1);
442     if (shape1.IsNull()) {
443       Message_Msg msg1156("IGES_1156");
444       const Standard_CString typeName(igesCurve1->DynamicType()->Name());
445       Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesCurve1);
446       msg1156.Arg(typeName);
447       msg1156.Arg(label);
448       SendFail(st, msg1156);
449       return res;
450     }
451
452     //%13 pdn 15.02.99
453     //added by rln on 03/12/97
454     //if shape1 is a wire it means that the curve1 in file was of continuity C0
455     //in order to get a face instead of shell when to BRepFill shape1
456     //should be retransfered with contionuity C0 (to get an edge). Once shape1
457     //has been built with C0, it is useless to require C1 from shape2 because
458     //anyway resulting surface was of continuity C0. Thus shape2 is built with C0
459 //    if (shape1.ShapeType() != TopAbs_EDGE) {
460 //      TC.SetContinuity (0);
461 //      shape1  = TC.TransferTopoCurve(igesCurve1);
462 //      if (shape1.IsNull()) {
463 //      Message_Msg msg1156("IGES_1156");
464 //      const Standard_CString typeName(igesCurve1->DynamicType()->Name());
465 //      Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesCurve1);
466 //      msg1156.Arg(typeName);
467 //      msg1156.Arg(label);
468 //      SendFail(st, msg1156);  
469 //      return res;
470 //      }
471 //      else {  
472 //        Message_Msg msg1250("IGES_1250");
473 //        SendWarning (st, msg1250); // RuledSurface was built with continuity C0
474 //      }
475 //    }
476     
477     TopAbs_ShapeEnum shapeEnum1 = shape1.ShapeType();
478     switch (shapeEnum1) {
479     case TopAbs_EDGE :
480       {
481         TopoDS_Edge edge1 = TopoDS::Edge(shape1);
482         ReparamCurve(edge1);
483         nbEdges1 = 1;
484       }
485       break;
486     case TopAbs_WIRE : 
487       {
488         wire1    = TopoDS::Wire(shape1);
489         nbEdges1 = 0;
490         for (TopoDS_Iterator hulot(wire1); hulot.More(); hulot.Next()) {
491          TopoDS_Edge edge1 = TopoDS::Edge(hulot.Value());
492          ReparamCurve(edge1);
493          nbEdges1++;
494         }
495       }
496       break;
497     default: 
498       {
499         // AddFail(st, "Curve Conversion Error."); This message can not occur.
500         return res;
501       }
502       //break; //szv#4:S4163:12Mar99 unreachable
503     }
504   }
505   else { 
506     Message_Msg msg148("XSTEP_148");
507     SendFail(st, msg148);
508     // Curve Type not Allowed.
509     return res;
510   }
511     
512   if (IGESToBRep::IsTopoCurve(igesCurve2)) { 
513     shape2 = TC.TransferTopoCurve(igesCurve2);
514     // dirflg = 0 join first to first, last to last
515     // dirflg = 1 join first to last, last to first
516     
517     if (shape2.IsNull()) {
518       Message_Msg msg1156("IGES_1156");
519       const Standard_CString typeName(igesCurve2->DynamicType()->Name());
520       Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesCurve2);
521       msg1156.Arg(typeName);
522       msg1156.Arg(label);
523       SendFail(st, msg1156);
524       // Curve Conversion Error.
525       return res;
526     }
527    Standard_Integer dirflag = st->DirectionFlag ();
528    // if (dirflag == 1){ // gka BUC60685
529       
530     //  shape2.Reverse();
531     //}
532
533     TopAbs_ShapeEnum shapeEnum2 = shape2.ShapeType();
534     switch (shapeEnum2) {
535     case TopAbs_EDGE : 
536       {
537         TopoDS_Edge edge2 = TopoDS::Edge(shape2);
538         ReparamCurve(edge2);
539         if (dirflag == 1)
540           shape2.Reverse();
541         nbEdges2 = 1;
542       }
543       break;
544     case TopAbs_WIRE :
545       {
546         wire2 = TopoDS::Wire(shape2);
547         nbEdges2 = 0;
548         for (TopoDS_Iterator cousto(wire2); cousto.More(); cousto.Next())  {
549           TopoDS_Edge edge2 = TopoDS::Edge(cousto.Value());
550           ReparamCurve(edge2);
551           nbEdges2++;
552         }
553         if (dirflag == 1) {   //gka BUC60685
554           Handle(ShapeExtend_WireData) sewd2 = new ShapeExtend_WireData;
555           sewd2->Add(shape2);
556           sewd2->Reverse();
557           wire2 = sewd2->Wire();
558         }
559       }
560       break;
561     default:
562       { 
563         // AddFail(st, "Curve Conversion Error.");
564         return res;
565       }
566       //break; //szv#4:S4163:12Mar99 unreachable
567     }
568   }
569   else { 
570     Message_Msg msg149("XSTEP_149");
571     SendFail(st, msg149);
572     // Curve Type not Allowed
573     return res;
574   }
575   
576
577   if (nbEdges1 != nbEdges2) {
578     if (nbEdges1 == 1) {
579       Handle(ShapeExtend_WireData) sewd1 = new ShapeExtend_WireData;
580       sewd1->Add(shape1);
581       wire1  = sewd1->Wire();
582     }
583     else if (nbEdges2 == 1) {
584       Handle(ShapeExtend_WireData) sewd2 = new ShapeExtend_WireData;
585       sewd2->Add(shape2);
586       wire2  = sewd2->Wire();
587     }
588
589     if (!st->IsRuledByParameter()) {
590       // AddWarning (st,"Compute by parametric constant ratio");
591     }
592     if (!ShapeAlgo::AlgoContainer()->HomoWires
593         (wire1, wire2, newWire1, newWire2, st->IsRuledByParameter())) {
594       Message_Msg msg1255("IGES_1255");// "Ruled Surface Construction Error");
595       SendFail(st, msg1255);
596       return res;
597     }
598     nbEdges1 = 2;           // a number > 1
599   }
600
601   else if (nbEdges1 != 1) {
602     newWire1 = wire1;
603     newWire2 = wire2;
604   }
605
606
607   if (nbEdges1 == 1) {
608     
609     //:e3 abv 31 Mar 98: UK4.igs 3170: ruled surface with directixes - line
610     // In IGES, line is parametrised [0;1] - this should have been kept !
611     // Let us detect the case and remake curve as bspline [0;1]
612     for ( Standard_Integer i=1; i <=2; i++ ) {
613       //#43 rln 20.11.98 S4054 BUC50047 entity D463 (circles as generatrices [0, 2*PI])
614       //reparameterisation should be for all curves not with range [0, 1] (see IGES)
615       TopoDS_Edge edge = TopoDS::Edge ( i==1 ? shape1 : shape2 );
616       //ReparamCurve(edge);
617       TopLoc_Location L;
618       Standard_Real First, Last;
619       Handle (Geom_Curve) curve = Handle (Geom_Curve)::DownCast (BRep_Tool::Curve ( edge, L, First, Last )->Copy());
620       if ( Abs (First) <= Precision::PConfusion() && Abs (Last - 1.) <= Precision::PConfusion() ) continue;
621       
622       Handle (Geom_BSplineCurve) bscurve;
623       if (!curve->IsKind (STANDARD_TYPE (Geom_BSplineCurve))) {
624         if (curve->FirstParameter() < First || curve->LastParameter() > Last)
625           curve = new Geom_TrimmedCurve (curve, First, Last);
626         bscurve = GeomConvert::CurveToBSplineCurve (curve, Convert_RationalC1);
627       }
628       else {
629         bscurve = Handle (Geom_BSplineCurve)::DownCast (curve);
630         bscurve->Segment (First, Last);
631       }
632       TColStd_Array1OfReal Knots(1, bscurve->NbKnots());
633       bscurve->Knots(Knots);
634       BSplCLib::Reparametrize (0., 1., Knots);
635       bscurve->SetKnots(Knots);
636       
637       BRep_Builder B;
638       B.UpdateEdge ( edge, bscurve, L, Precision::Confusion() );
639       B.Range ( edge, 0., 1 );
640       if ( i ==1 ) shape1 = edge;
641       else shape2 = edge;
642     }
643     
644     res = BRepFill::Face(TopoDS::Edge(shape1), TopoDS::Edge(shape2));
645     Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(res));
646     if(surf->Continuity()==GeomAbs_C0) {
647       Message_Msg msg1250("IGES_1250");
648       SendWarning (st, msg1250);
649     }
650   }
651   else {
652     res = BRepFill::Shell(newWire1, newWire2);
653   }
654   if (res.IsNull()) {
655     Message_Msg msg1255("IGES_1255");// "Ruled Surface Construction Error");
656     SendFail(st, msg1255);
657     return res;
658   }
659
660
661   if (st->HasTransf()) {
662     gp_Trsf trsf;
663     SetEpsilon(1.E-04);
664     if (IGESData_ToolLocation::ConvertLocation
665         (GetEpsilon(),st->CompoundLocation(), trsf,GetUnitFactor())) { 
666       TopLoc_Location shapeLoc(trsf);
667       res.Move(shapeLoc);
668     }
669     else {
670       Message_Msg msg1035("IGES_1035");
671       SendWarning(st,msg1035); // Transformation : not a similarity
672     }
673   }
674   return res;
675 }
676
677
678 //=======================================================================
679 //function : TransferSurfaceOfRevolution
680 //purpose  : 
681 //=======================================================================
682
683 TopoDS_Shape IGESToBRep_TopoSurface::TransferSurfaceOfRevolution
684   (const Handle(IGESGeom_SurfaceOfRevolution)& st)
685 { // Declaration of messages// 
686   // DCE 22/12/98
687   //Message_Msg msg1005("IGES_1005");
688   ////////////////////////////////
689   TopoDS_Shape res;
690   if (st.IsNull()) {
691     Message_Msg msg1005("IGES_1005");
692     SendFail(st, msg1005);
693     return res;
694   }
695
696   IGESToBRep_TopoCurve  TC(*this);
697   IGESToBRep_BasicCurve BC(*this);
698   Handle(IGESData_IGESEntity) igesGeneratrix = st->Generatrix();
699   Handle(IGESGeom_Line)       igesAxis       = st->AxisOfRevolution();
700
701   if (igesGeneratrix.IsNull() || !IGESToBRep::IsTopoCurve(igesGeneratrix) ) {
702     Message_Msg msg153("XSTEP_153");
703     SendFail(st, msg153);
704     // Generatrix Reading Error : Null IGESEntity
705     // Generatrix : Not Allowed IGESEntity.
706     return res;
707   }
708   
709   DeclareAndCast(IGESGeom_Line,srgen,st->Generatrix());
710   if (!srgen.IsNull()) {
711     gp_Pnt gen1 = srgen->StartPoint();
712     gp_Pnt gen2 = srgen->EndPoint();
713     TheULength = gen1.Distance(gen2)*GetUnitFactor();
714   }
715
716   if (igesAxis.IsNull()) {
717     Message_Msg msg152("XSTEP_152");
718     SendFail(st, msg152);
719     return res;
720   }
721
722   //%13 pdn 15.02.99 
723   TC.SetContinuity(0);
724   TopoDS_Shape generatrix  = TC.TransferTopoCurve(igesGeneratrix);
725   if (generatrix.IsNull()) {
726     Message_Msg msg1156("IGES_1156");
727     const Standard_CString typeName("generatrix");
728     Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesGeneratrix);
729     msg1156.Arg(typeName);
730     msg1156.Arg(label);
731     SendFail(st, msg1156);
732     // Generatrix Conversion Error.
733     return res;
734   }
735
736   gp_Trsf startLoc;
737   gp_Pnt pt1 = igesAxis->TransformedStartPoint(); //smh#11
738   gp_Pnt pt2 = igesAxis->TransformedEndPoint(); //smh#11
739   pt1.Scale(gp_Pnt(0,0,0),GetUnitFactor());
740   pt2.Scale(gp_Pnt(0,0,0),GetUnitFactor());
741   //#30 rln 19.10.98 To keep IGES surface normal CAS.CADE axis = reversed IGES axis
742   //CAS.CADE SA = 2*PI - IGES TA
743   //CAS.CADE TA = 2*PI - IGES SA
744   //gp_Ax1 revolAxis(pt1, gp_Dir(gp_Vec(pt1, pt2)));
745   //Standard_Real startAngle = st->StartAngle();
746   //Standard_Real endAngle = st->EndAngle();
747   gp_Ax1 revolAxis(pt1, gp_Dir( gp_Vec (pt2, pt1)));
748   Standard_Real startAngle = 2 * M_PI - st->EndAngle();
749   Standard_Real endAngle = 2 * M_PI - st->StartAngle();
750   Standard_Real deltaAngle = endAngle - startAngle;
751   Standard_Boolean IsFullAngle = ( deltaAngle > 2.*M_PI-Precision::PConfusion() );
752   if (IsFullAngle) deltaAngle = 2.*M_PI;  // ** CKY 18-SEP-1996
753   // il faudra translater les courbes 2d de startAngle pour 
754   // etre en phase IGES et BRep
755   startLoc.SetRotation(revolAxis, startAngle);
756   generatrix.Move(startLoc);
757   
758   // PTV file D44-11325-6.igs OCC660 depends on OCC450
759   // PTV 29.05.2002 OCC450 create Surface of Revolution by native API
760   // file NIC_file5.igs 
761   // (BRepPrimAPI_MakeRevol replace surface of revolution by plane then 3D and 2D curves are inconsistent;
762   // and 3D is ignored. As result shape is rectangle instead circle shape.
763   Handle(Geom_Curve) aBasisCurve;
764   
765   {
766     try
767     {
768       OCC_CATCH_SIGNALS
769       if (extractCurve3d(generatrix, aBasisCurve))
770       {
771         BRepBuilderAPI_MakeFace aMakeF;
772         Handle(Geom_Surface) aResultSurf = 
773                 new Geom_SurfaceOfRevolution(aBasisCurve, revolAxis);
774
775         if ( !aResultSurf.IsNull())
776         {
777           if (!IsFullAngle)
778           {
779             const Standard_Real VF = aBasisCurve->FirstParameter();
780             const Standard_Real VL = aBasisCurve->LastParameter();
781             
782             // PTV 29.08.2002  begin of OCC663 Trim surface by correct parameters
783             const Standard_Real UF = 0;
784             const Standard_Real UL = endAngle - startAngle;
785             // PTV 29.08.2002  end of OCC663
786
787             aMakeF.Init(aResultSurf, UF, UL, VF, VL, Precision::Confusion());
788           }//if (!IsFullAngle)
789           else
790           {
791             aMakeF.Init(aResultSurf, Standard_True, Precision::Confusion());
792           }
793
794           if (aMakeF.IsDone())
795             res = aMakeF.Face();
796         }//if ( !aResultSurf.IsNull())
797       }//if (extractCurve3d(generatrix, aBasisCurve))
798     }
799     catch (Standard_Failure)
800     {
801 #ifdef IGESTOBREP_DEB
802       cout << "Warning: IgesToBRep_TopoSurface::"
803                     "TransferSurfaceOfRevolution(): exception by Geom: ";
804       Standard_Failure::Caught()->Print ( cout ); cout << endl;
805 #endif
806     }//catch (Standard_Failure)
807   }
808   
809   if ( res.IsNull() ) {
810     // do as usual.
811   
812     BRepPrimAPI_MakeRevol revol(generatrix, revolAxis, deltaAngle);
813 //mjm: si debug IsDone()est fait : 
814 //  if (!revol.IsDone()) {
815 //    AddFail(st, "Revol Construction Error.");
816 //    return res;
817 //  }
818     res = revol.Shape();
819   }
820   //%13 pdn 15.02.99
821   if (res.ShapeType() == TopAbs_FACE) {
822     Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(res));
823     if(surf->Continuity()==GeomAbs_C0) {
824       Message_Msg msg1250("IGES_1250");
825       SendWarning (st, msg1250);
826     } 
827   }
828
829   if (st->HasTransf()) {
830     gp_Trsf trsf;
831     SetEpsilon(1.E-04);
832     if (IGESData_ToolLocation::ConvertLocation
833         (GetEpsilon(), st->CompoundLocation(), trsf, GetUnitFactor())) { 
834       TopLoc_Location shapeLoc(trsf);
835       res.Move(shapeLoc);
836     }
837     else {
838       Message_Msg msg1035("IGES_1035");
839       SendWarning(st,msg1035); // Transformation : not a similarity
840     }
841   }
842     
843   return res;
844 }
845
846
847 //=======================================================================
848 //function : TransferTabulatedCylinder
849 //purpose  : 
850 //=======================================================================
851
852 TopoDS_Shape IGESToBRep_TopoSurface::TransferTabulatedCylinder
853        (const Handle(IGESGeom_TabulatedCylinder)& st)
854 { // Declaration of messages// 
855   // DCE 22/12/98
856   //Message_Msg msg1005("IGES_1005");
857   ////////////////////////////////
858   TopoDS_Shape res;
859   if (st.IsNull()) {
860     Message_Msg msg1005("IGES_1005");
861     SendFail(st, msg1005);
862     return res;
863   }
864
865   IGESToBRep_TopoCurve TC(*this);
866 //  TopoDS_Edge  firstEdge;//commented by rln on 02/12/97
867
868   Handle(IGESData_IGESEntity) igesDirectrix = st->Directrix();
869   if (igesDirectrix.IsNull() || !IGESToBRep::IsTopoCurve(igesDirectrix) ) {
870     Message_Msg msg153("XSTEP_153");
871     SendFail(st, msg153); 
872     // Directrix Reading Error : Null IGESEntity
873     //Directrix, not allowed IGESEntity
874     return res;
875   }
876
877   //%13 pdn 15.02.99
878   TC.SetContinuity(0);
879   TopoDS_Shape directrix = TC.TransferTopoCurve(igesDirectrix);
880   if (directrix.IsNull()) {
881     Message_Msg msg1156("IGES_1156");
882     const Standard_CString typeName("directrix");
883     Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesDirectrix);
884     msg1156.Arg(typeName);
885     msg1156.Arg(label);
886     SendFail(st, msg1156);
887     // Directrix Conversion Error.
888     return res;
889   }
890
891   //modified by rln on 03/12/97
892   //TopoDS_Vertex firstVertex = TopExp::FirstVertex(firstEdge);
893   TopoDS_Vertex firstVertex, lastVertex;
894   ShapeAnalysis::FindBounds (directrix, firstVertex, lastVertex);
895   gp_Pnt pt1  = BRep_Tool::Pnt(firstVertex);
896   gp_Pnt pt2  = st->EndPoint();
897   pt2.Scale(gp_Pnt(0,0,0),GetUnitFactor());
898
899   TheULength = pt1.Distance(pt2);
900   if(TheULength < Precision::Confusion()) {
901     Message_Msg msg("Tabulated cylinder with zero length");
902     SendFail (st, msg); // TabulatedCylinder was built with continuity C0
903     return res;
904   }
905
906   // PTV file D44-11325-6.igs OCC660 depends on OCC450
907   // PTV 29.05.2002 OCC450 create Surface of LinearExtrusion by native API
908   // see description about problem in Surface of Revolution
909   Handle(Geom_Curve) aBasisCurve;
910   {
911   try {
912     OCC_CATCH_SIGNALS
913     if (extractCurve3d(directrix, aBasisCurve)) {
914       gp_Vec dir (pt1, pt2);
915       Handle(Geom_Surface) aResultSurf = 
916         new Geom_SurfaceOfLinearExtrusion(aBasisCurve, dir);
917       if (!aResultSurf.IsNull()) {
918         //aResultSurf = 
919         //  new Geom_RectangularTrimmedSurface(aResultSurf, 
920         //                                     aBasisCurve->FirstParameter(),
921         //                                     aBasisCurve->LastParameter(),
922         //                                     0., dir.Magnitude() );
923         BRepBuilderAPI_MakeFace aMakeF(aResultSurf, aBasisCurve->FirstParameter(),
924                                              aBasisCurve->LastParameter(),
925                                              0., dir.Magnitude(),
926                                              Precision::Confusion());
927         if (aMakeF.IsDone())
928           res = aMakeF.Face();
929       }
930     }
931   }
932   catch (Standard_Failure) {
933 #ifdef IGESTOBREP_DEB
934     cout << "Warning: IgesToBRep_TopoSurface::TransferTabulatedCylinder(): exception by Geom: ";
935     Standard_Failure::Caught()->Print ( cout ); cout << endl;
936 #endif
937   }
938   }
939   
940   if ( res.IsNull() ) {
941     // do as usual.
942     BRepPrimAPI_MakePrism prism(directrix, gp_Vec(pt1, pt2));
943 //mjm: si debug IsDone() est fait
944 //  if (!prism.IsDone()) {
945 //    AddFail(st, "Prism Construction Error.");
946 //    return res;
947 //  }
948     res = prism.Shape();
949   }
950   //#16 rln 08/04/98 coq-inf-support.igs entity 2105
951   //CAS.CADE can parametrize SurfaceOfLinearExtrusion with generatrix opposite to Vec(pt1, pt2)
952   //and with parametrization V > 0, while in IGES TabulatedCylinder is parametrized with positive V
953   //direction exactly in the direction Vec(pt1, pt2)
954   if (res.ShapeType() == TopAbs_FACE) {
955     Standard_Real UMin, UMax, VMin, VMax;
956     BRepTools::UVBounds (TopoDS::Face (res), UMin, UMax, VMin, VMax);
957     if (VMax <= Precision::PConfusion() && VMin < -Precision::PConfusion()) {
958       TheULength *= -1;
959       res.Reverse();
960     }
961     Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(res));
962     if(surf->Continuity()==GeomAbs_C0) {
963       Message_Msg msg1250("IGES_1250");
964       SendWarning (st, msg1250);
965     }
966   }
967     
968   if (st->HasTransf()) {
969     gp_Trsf trsf;
970     SetEpsilon(1.E-04);
971     if (IGESData_ToolLocation::ConvertLocation
972         (GetEpsilon(),st->CompoundLocation(), trsf, GetUnitFactor())) { 
973       TopLoc_Location shapeLoc(trsf);
974       res.Move(shapeLoc);
975     }
976     else {
977       Message_Msg msg1035("IGES_1035");
978       SendWarning(st,msg1035); // Transformation : not a similarity
979     }
980   }
981   return res;
982 }
983
984
985 //=======================================================================
986 //function : TransferOffsetSurface
987 //purpose  : 
988 //=======================================================================
989
990 TopoDS_Shape IGESToBRep_TopoSurface::TransferOffsetSurface
991   (const Handle(IGESGeom_OffsetSurface)& st)
992 { // Declaration of messages// 
993   // DCE 22/12/98
994   //Message_Msg msg1005("IGES_1005");
995   ////////////////////////////////
996   TopoDS_Shape    res;
997   if (st.IsNull()) {
998     Message_Msg msg1005("IGES_1005");
999     SendFail(st, msg1005);
1000     return res;
1001   }
1002
1003   TopoDS_Shape    igesShape;
1004   TopoDS_Face     face;
1005   TopLoc_Location basisLoc;
1006
1007   Handle (IGESData_IGESEntity) igesSrf = st->Surface();
1008   if (igesSrf.IsNull() || !IGESToBRep::IsTopoSurface(igesSrf) ) {
1009     Message_Msg msg164("XSTEP_164");
1010     SendFail(st, msg164); 
1011     // Basis Surface Reading Error : Null IGESEntity
1012     // Basis Surface Transfer Error : Not Allowed IGESEntity 
1013     return res;
1014   }
1015
1016   igesShape = TransferTopoSurface(igesSrf);
1017   if (igesShape.IsNull()) {
1018     Message_Msg msg1156("IGES_1156");
1019     const Standard_CString typeName("basis surface");
1020     Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
1021     msg1156.Arg(typeName);
1022     msg1156.Arg(label);
1023     SendFail(st, msg1156);  // Basis Surface Conversion Error.
1024     return res;
1025   }
1026   
1027   TopAbs_ShapeEnum shapeEnum = igesShape.ShapeType();
1028   switch (shapeEnum) {
1029   case TopAbs_FACE :
1030     {
1031       face = TopoDS::Face(igesShape);
1032       break;
1033     }
1034   case TopAbs_SHELL :
1035     {
1036       SendWarning(st, "The First Surface only will be transfered.");
1037       TopoDS_Iterator dabovil(igesShape);
1038       if (dabovil.More()) {
1039         face = TopoDS::Face(dabovil.Value());
1040         break;
1041       }
1042       /* else  AddF("... */
1043     }
1044   default:
1045     {
1046       Message_Msg msg1156("IGES_1156");
1047       const Standard_CString typeName("basis surface");
1048       Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
1049       msg1156.Arg(typeName);
1050       msg1156.Arg(label);
1051       SendFail(st, msg1156);  // Basis Surface Conversion Error.
1052       return res;
1053     }
1054   }
1055   
1056   
1057   //Handle(Geom_Surface) geomSupport = BRep_Tool::Surface(face, basisLoc);
1058   // attention on ne peut construire une Geom_OffsetSurface que
1059   // si la surface de base est au moins C1, sinon on plante !
1060   //#56 rln 25.12.98 UKI60878 entity D593 (Offset surface on C0 B-Spline)
1061   //Trying to eliminate previous limitation on processing only C1 surfaces
1062   Handle(Geom_Surface) geomSupport = BRep_Tool::Surface(face);
1063   Handle(Geom_OffsetSurface) basisSrf;
1064   
1065   if (geomSupport->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
1066     DeclareAndCast(Geom_OffsetSurface, geom140, geomSupport);
1067     geom140->SetOffsetValue(basisSrf->Offset() + 
1068                             st->Distance()*GetUnitFactor());
1069     basisSrf = geom140;
1070   }
1071   else {
1072     if (geomSupport->Continuity() == GeomAbs_C0) {
1073       res = ShapeAlgo::AlgoContainer()->C0ShapeToC1Shape (face, Abs (st->Distance()) * GetUnitFactor());
1074       if(res.ShapeType()!=TopAbs_FACE) {
1075         Message_Msg msg1266("IGES_1266");
1076         SendFail(st, msg1266);//Basis surface is C0-continuous and cannot be corrected to C1-continuous.
1077         return res;
1078       }
1079       else {
1080         geomSupport = BRep_Tool::Surface (TopoDS::Face(res));
1081         if (geomSupport->Continuity() == GeomAbs_C0) {
1082           Message_Msg msg1266("IGES_1266");
1083           SendFail(st, msg1266);//Basis surface is C0-continuous and cannot be corrected to C1-continuous.
1084           res.Nullify();
1085           return res;
1086         }
1087       }
1088       Message_Msg msg1267("IGES_1267");
1089       SendWarning(st, msg1267);//Basis surface is C0-continuous but was corrected to C1-continuous
1090     }
1091     //smh#12
1092     if (res.IsNull()) res = face;
1093     geomSupport = BRep_Tool::Surface (TopoDS::Face(res));
1094     Standard_Real umin, umax, vmin, vmax;
1095     geomSupport->Bounds (umin, umax, vmin, vmax);
1096     if (Precision::IsInfinite (umin) || Precision::IsInfinite (umax) ||
1097         Precision::IsInfinite (vmin) || Precision::IsInfinite (vmax)) {
1098       // convert to C1 B-Spline
1099       BRepTools::UVBounds (face, umin, umax, vmin, vmax);
1100       Handle(Geom_RectangularTrimmedSurface) TS = new Geom_RectangularTrimmedSurface (geomSupport, umin, umax, vmin, vmax);
1101       Handle (Geom_BSplineSurface) BS = ShapeAlgo::AlgoContainer()->ConvertSurfaceToBSpline(TS, umin, umax, vmin, vmax);
1102       if (BS.IsNull() || BS->Continuity() == GeomAbs_C0) {
1103         Message_Msg msg1265("IGES_1265");
1104         SendFail(st, msg1265); // OffsetSurface Construction Error.
1105         return res;
1106       }
1107       else {
1108         geomSupport = BS;
1109       }
1110     }
1111     basisSrf = new Geom_OffsetSurface(geomSupport, st->Distance()*GetUnitFactor());
1112   }
1113   
1114   BRepLib_MakeFace MF(basisSrf, Precision::Confusion());
1115   if(!MF.IsDone()) {
1116     Message_Msg msg1265("IGES_1265");
1117     SendFail(st, msg1265); // OffsetSurface Construction Error.
1118     return res;
1119   }
1120
1121   res = MF.Face();
1122   
1123   if (st->HasTransf()) {
1124     gp_Trsf trsf;
1125     SetEpsilon(1.E-04);
1126     if (IGESData_ToolLocation::ConvertLocation
1127         (GetEpsilon(),st->CompoundLocation(),trsf, GetUnitFactor())) { 
1128       TopLoc_Location loc2(trsf);
1129       res.Move(loc2);
1130     }
1131     else {
1132       Message_Msg msg1035("IGES_1035");
1133       SendWarning(st,msg1035); // Transformation : not a similarity
1134     }
1135   }
1136   return res;
1137 }
1138
1139
1140 //=======================================================================
1141 //function : TransferTrimmedSurface
1142 //purpose  : 
1143 //=======================================================================
1144
1145 TopoDS_Shape IGESToBRep_TopoSurface::TransferTrimmedSurface
1146        (const Handle(IGESGeom_TrimmedSurface)& st)
1147 { // Declaration of messages// 
1148   // DCE 22/12/98
1149   //Message_Msg msg1005("IGES_1005");
1150   ////////////////////////////////
1151   TopoDS_Shape res;
1152   if (st.IsNull()) {
1153     Message_Msg msg1005("IGES_1005");
1154     SendFail(st, msg1005);
1155     return res;
1156   }
1157   
1158   TopAbs_ShapeEnum shapeEnum;
1159   IGESToBRep_TopoCurve TC(*this);
1160
1161   Handle (IGESData_IGESEntity) igesSurface = st->Surface();
1162   if (igesSurface.IsNull() || !IGESToBRep::IsTopoSurface(igesSurface) ) {
1163     Message_Msg msg169("XSTEP_169");   
1164     SendFail(st, msg169);
1165     // BasicSurface Transfer Error : Null IGESEntity
1166     // Basis Surface, not Allowed IGESEntity.
1167     return res;
1168   }
1169   gp_Trsf2d trans;
1170   Standard_Real uFact;
1171   TopoDS_Face  face, faceres;
1172   
1173   TopoDS_Shape myshape = ParamSurface(igesSurface, trans, uFact);
1174
1175   if (!myshape.IsNull()) {
1176     shapeEnum = myshape.ShapeType();
1177     switch (shapeEnum) {
1178     case TopAbs_FACE :
1179       {
1180         face = TopoDS::Face(myshape);
1181         faceres = face;
1182         break;
1183       }
1184     case TopAbs_SHELL :
1185       {
1186         TopoDS_Iterator IT(myshape);
1187         Standard_Integer nbfaces = 0;
1188         for (; IT.More(); IT.Next()) {
1189           nbfaces++;
1190           face = TopoDS::Face(IT.Value());
1191           faceres = face;
1192         }
1193         //szv#4:S4163:12Mar99 optimized
1194         if (nbfaces != 1) {
1195           Message_Msg msg1156("IGES_1156");
1196           const Standard_CString typeName("basis surface");
1197           Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSurface);
1198           msg1156.Arg(typeName);
1199           msg1156.Arg(label);
1200           SendFail(st, msg1156);  // Not Implemented Trimmed Composite Surface.
1201           return myshape;
1202         }
1203       }
1204       break;
1205     default:
1206       {
1207         Message_Msg msg1156("IGES_1156");
1208         const Standard_CString typeName("basis surface");
1209         Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSurface);
1210         msg1156.Arg(typeName);
1211         msg1156.Arg(label);
1212         SendFail(st, msg1156);  // Basis Surface Conversion Error.
1213         return res;
1214       }
1215     }
1216   }
1217   else {
1218     return res;
1219   }
1220   
1221   //obtaining a surface
1222   TopLoc_Location L;
1223   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(face, L);
1224   TC.SetSurface(aSurf);
1225   
1226   if (st->HasOuterContour()) {
1227     face.EmptyCopy();
1228     TopoDS_Shape myshape1 = TC.TransferCurveOnFace (face, st->OuterContour(), trans, uFact, Standard_False);
1229     // si ca se passe mal , on recupere au moins la face avec NaturalRestriction
1230     if (myshape1 .IsNull()) {
1231       face = faceres;
1232       BRep_Builder B;
1233       B.NaturalRestriction(face,Standard_False);
1234     }
1235   }
1236   for (Standard_Integer i = 1; i <= st->NbInnerContours(); i++) {
1237     TopoDS_Shape myshape2 = TC.TransferCurveOnFace (face, st->InnerContour(i), trans, uFact, Standard_False);
1238   }
1239   BRepTools::Update ( face ); //:p4
1240   //%16 pdn 08.04.99
1241   return face;
1242 }
1243
1244
1245 //=======================================================================
1246 //function : TransferBoundedSurface
1247 //purpose  : 
1248 //=======================================================================
1249
1250 TopoDS_Shape  IGESToBRep_TopoSurface::TransferBoundedSurface
1251   (const Handle(IGESGeom_BoundedSurface)&  st)
1252 { // Declaration of messages// 
1253   // DCE 22/12/98
1254   //Message_Msg msg1005("IGES_1005");
1255   ////////////////////////////////
1256   TopoDS_Shape res;
1257   if (st.IsNull()) {
1258     Message_Msg msg1005("IGES_1005");
1259     SendFail(st, msg1005);
1260     return res;
1261   }
1262
1263   if (st->RepresentationType()==0) {
1264     Message_Msg msg1275("IGES_1275");
1265     SendWarning(st, msg1275);
1266     // Model Space Representation Not Implemented : the result will be the basis surface
1267   }
1268   
1269   TopAbs_ShapeEnum shapeEnum;
1270   IGESToBRep_TopoCurve TC(*this);
1271   Handle (IGESData_IGESEntity) igesSrf = st->Surface();
1272   if (igesSrf.IsNull() || !IGESToBRep::IsTopoSurface(igesSrf) ) {
1273     Message_Msg msg166("XSTEP_166");
1274     SendFail( st, msg166);
1275     // Basis Surface Transfer Error : Null IGESEntity.
1276     // Basis Surface Transfer Error : Not Allowed IGESEntity.
1277     return res;
1278   }
1279   gp_Trsf2d trans;
1280   Standard_Real uFact;
1281   TopoDS_Face  face;
1282
1283   TopoDS_Shape myshape = ParamSurface(igesSrf, trans, uFact);
1284
1285   if (myshape.IsNull()) {
1286     //#55 rln 24.12.98 UKI60878 entity D593
1287 #ifdef IGESTOBREP_DEB
1288     cout << "Fail: IGESToBRep_TopoSurface::TransferBoundedSurface  UntrimmedSurface is translated into Null" << endl;
1289 #endif
1290     return res;
1291   }
1292   else {
1293     shapeEnum = myshape.ShapeType();
1294     switch (shapeEnum) {
1295     case TopAbs_FACE :
1296       {
1297         face = TopoDS::Face(myshape);
1298       }
1299       break;
1300     case TopAbs_SHELL :
1301       {
1302         TopoDS_Iterator IT(myshape);
1303         Standard_Integer nbfaces = 0;
1304         for (; IT.More(); IT.Next()) {
1305           nbfaces++;
1306           face = TopoDS::Face(IT.Value());
1307         }
1308         //szv#4:S4163:12Mar99 optimized
1309         if (nbfaces != 1) {
1310           Message_Msg msg1156("IGES_1156");
1311           const Standard_CString typeName("basis surface");
1312           Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
1313           msg1156.Arg(typeName);
1314           msg1156.Arg(label);
1315           SendFail(st, msg1156);
1316           // Not Implemented Trimmed Composite Surface.
1317           return myshape;
1318         }
1319       }
1320       break;
1321     default:
1322       { 
1323         Message_Msg msg1156("IGES_1156");
1324         const Standard_CString typeName("basis surface");
1325         Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
1326         msg1156.Arg(typeName);
1327         msg1156.Arg(label);
1328         SendFail(st, msg1156);
1329         return res;
1330       }
1331     }
1332   }
1333   
1334   face.EmptyCopy();
1335   for (Standard_Integer i = 1; i <= st->NbBoundaries(); i++) 
1336     TC.TransferBoundaryOnFace(face, st->Boundary(i), trans, uFact);
1337   
1338   BRepTools::Update ( face ); //:p4
1339   //#22 rln 01.06.98 UK3.igs entity 1279
1340 //  ShapeFix_Face sff ( face );
1341 //  sff.FixMissingSeam(); //:l1 abv 10 Jan 99: USA60022 7289: fix missing seam
1342 //  if(sff.FixSmallAreaWire()) { //%14 pdn 24.02,99: USA60293: fix small area wires.
1343 //    AddFail(st, "Small area wire detected, dropped"); 
1344 //  }
1345 //  sff.FixOrientation();
1346 //  face = sff.Face();
1347   //%16 pdn 08.04.99
1348   return face;
1349 }
1350
1351
1352 //=======================================================================
1353 //function : TransferPlane
1354 //purpose  : 
1355 //=======================================================================
1356
1357 TopoDS_Shape IGESToBRep_TopoSurface::TransferPlane
1358   (const Handle(IGESGeom_Plane)& st)
1359 { // Declaration of messages// 
1360   // DCE 22/12/98
1361   //Message_Msg msg1005("IGES_1005");
1362   ////////////////////////////////
1363   TopoDS_Shape     res;
1364   if (st.IsNull()) {
1365     Message_Msg msg1005("IGES_1005");
1366     SendFail(st, msg1005);
1367     return res;
1368   }
1369
1370   gp_Pln  pln;
1371   gp_Trsf trsf;
1372   res = TransferPlaneParts (st, pln,trsf,Standard_True);
1373 //   res contient (en principe ...) une Face avec eventuellement un Wire
1374 //   il reste a la mettre en position
1375   if (trsf.Form() != gp_Identity) {
1376     TopLoc_Location loc(trsf);
1377     res.Location(loc);
1378   }
1379   return res;
1380 }
1381
1382
1383 //=======================================================================
1384 //function : TransferPlaneSurface
1385 //purpose  : this function transferred into IGESToBRep_BasicSurface
1386 //=======================================================================
1387
1388
1389 //=======================================================================
1390 //function : TransferPerforate
1391 //purpose  : 
1392 //=======================================================================
1393
1394 TopoDS_Shape  IGESToBRep_TopoSurface::TransferPerforate
1395   (const Handle(IGESBasic_SingleParent)& st)
1396 { // Declaration of messages// 
1397   // DCE 22/12/98
1398   //Message_Msg msg1005("IGES_1005");
1399   ////////////////////////////////
1400   TopoDS_Shape     res;
1401   if (st.IsNull()) {
1402     Message_Msg msg1005("IGES_1005");
1403     SendFail(st, msg1005);
1404     return res;
1405   }
1406
1407   //char mess[100];
1408   gp_Pln  pln;
1409   gp_Trsf trsf;
1410   DeclareAndCast(IGESGeom_Plane,p0,st->SingleParent());
1411   BRep_Builder B;
1412   if (p0.IsNull()) {
1413     Message_Msg msg206("XSTEP_206");   
1414     SendFail(st, msg206);
1415     // SingleParent does not describe a holed face
1416     return res;
1417   }
1418   res = TransferPlaneParts (p0,pln,trsf,Standard_True);
1419 //res demarre avec la face et son contour externe
1420   Standard_Integer nb = st->NbChildren();
1421   for (Standard_Integer i = 1; i <= nb; i ++) {
1422     DeclareAndCast(IGESGeom_Plane,pi,st->Child(i));
1423     if (pi.IsNull()) {
1424       Message_Msg msg1285("IGES_1285");
1425       msg1285.Arg(i);
1426       // A child is not a Plane, skipped, n0 %d
1427       SendWarning(st,msg1285);
1428       continue;
1429     }
1430     gp_Pln  pli;
1431     gp_Trsf trsi;
1432     TopoDS_Shape wire = TransferPlaneParts (pi,pli,trsi,Standard_False);
1433 //    si ce n est pas un Wire, sauter
1434     if (wire.ShapeType() != TopAbs_WIRE) {
1435       Message_Msg msg1156("IGES_1156");
1436       const Standard_CString typeName("hole");
1437       Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(pi);
1438       msg1156.Arg(typeName);
1439       msg1156.Arg(label);
1440       SendWarning(st, msg1156);
1441       // A hole could not be transferred, skipped, n0 %d
1442       continue;
1443     }
1444 //    coplanaires ? verifier
1445     if (!pln.Position().IsCoplanar(pli.Position(),GetEpsGeom(),GetEpsilon())) {
1446       Message_Msg msg1295("IGES_1295");
1447       msg1295.Arg(i);
1448       SendWarning(st,msg1295);
1449       // "A hole is not well coplanar to the face, n0 %d",i);
1450     }
1451 //    Ne pas oublier de composer la transformation locale a ce Wire
1452     if (trsi.Form() != gp_Identity) {
1453       TopLoc_Location locw(trsi);
1454       wire.Location(locw);
1455     }
1456     B.Add (res,wire);
1457   }
1458 //    Enfin, appliquer la trsf globale
1459   if (trsf.Form() != gp_Identity) {
1460     TopLoc_Location loc(trsf);
1461     res.Location(loc);
1462   }
1463   return res;
1464 }
1465
1466
1467 //=======================================================================
1468 //function : TransferPlaneParts
1469 //purpose  : 
1470 //=======================================================================
1471 TopoDS_Shape IGESToBRep_TopoSurface::TransferPlaneParts(const Handle(IGESGeom_Plane)& st,
1472                                                         gp_Pln&  pln,  
1473                                                         gp_Trsf&  trsf,
1474                                                         const Standard_Boolean first)
1475 { // Declaration of messages// 
1476   // DCE 22/12/98
1477   //Message_Msg msg1005("IGES_1005");
1478   ////////////////////////////////
1479   TopoDS_Shape res;
1480   if (st.IsNull()) {
1481     Message_Msg msg1005("IGES_1005");
1482     SendFail(st, msg1005);
1483     return res;
1484   }
1485
1486   Standard_Real a, b, c, d;
1487   // equation de Geom : ax + by + cz + d = 0.0;
1488   // equation de IGES : ax + by + cz = d;
1489   st->Equation(a, b, c, d);
1490   pln = gp_Pln(a, b, c, -d);
1491   
1492   TopoDS_Face plane;
1493   TopoDS_Wire wire;
1494   BRep_Builder B;
1495   if (first) {
1496     B.MakeFace(plane);         // Just to create a empty Plane with a Tshape.
1497     Handle (Geom_Plane) geomPln = new Geom_Plane(pln);
1498     geomPln->Scale(gp_Pnt(0,0,0),GetUnitFactor());
1499 //   ATTENTION, ici on CALCULE la trsf, on ne l`applique pas ...
1500     //S4054: B.UpdateFace (plane, geomPln, TopLoc_Location(), 
1501                            //GetEpsGeom()*GetUnitFactor());
1502     B.UpdateFace (plane, geomPln, TopLoc_Location(), Precision::Confusion());
1503     //:3 by ABV 5 Nov 97: set Infinite() flag (see below for unsetting)
1504     plane.Infinite ( Standard_True );  //:3
1505   }
1506
1507 //   ATTENTION, ici on CALCULE la trsf, on ne l'appliquera qu'a la fin !
1508   if (st->HasTransf()) {
1509     SetEpsilon(1.E-04);
1510     if (!IGESData_ToolLocation::ConvertLocation
1511         (GetEpsilon(), st->CompoundLocation(),trsf,GetUnitFactor())) { 
1512       Message_Msg msg1035("IGES_1035");
1513       SendWarning(st,msg1035); // Transformation : not a similarity
1514     }
1515   }
1516
1517   if (st->HasBoundingCurve()) {
1518     IGESToBRep_TopoCurve TC(*this);
1519     Handle(IGESData_IGESEntity) crv = st->BoundingCurve();
1520
1521     if (crv.IsNull()) {
1522       Message_Msg msg1300("IGES_1300");
1523       SendWarning(st,msg1300);
1524       //:4 by ABV 5 Nov 97: plane cannot be trimmed - let it be infinite
1525       //:4 NOTE: NB "else"
1526       //:4      return res;
1527     }
1528     else //:4
1529       
1530       if (IGESToBRep::IsTopoCurve(crv)) {
1531         gp_Trsf trans;
1532         if (crv->IsKind(STANDARD_TYPE(IGESGeom_CurveOnSurface))) {
1533           DeclareAndCast(IGESGeom_CurveOnSurface, crv142, crv);
1534           TopoDS_Shape myshape = TC.TransferCurveOnFace (plane, crv142, trans, TheULength, Standard_False);
1535           
1536           //:3 by ABV 5 Nov 97: set plane to be finite
1537           if ( first ) {
1538             TopExp_Explorer ws ( plane, TopAbs_WIRE ); 
1539             if ( ws.More() ) plane.Infinite ( Standard_False ); 
1540           }
1541         }
1542         else {
1543           TopoDS_Shape     shape = TC.TransferTopoCurve(crv);
1544           TopAbs_ShapeEnum shapeEnum = shape.ShapeType();
1545           switch (shapeEnum) {
1546           case TopAbs_EDGE :
1547             {
1548               TopoDS_Edge edge = TopoDS::Edge(shape);
1549               Handle(ShapeExtend_WireData) sewd = new ShapeExtend_WireData;
1550               sewd->Add(edge);
1551               wire = sewd->Wire();
1552             }
1553             break;
1554           case TopAbs_WIRE :
1555             {
1556               wire = TopoDS::Wire(shape);           
1557             }
1558           break;
1559           default:
1560             { 
1561               Message_Msg msg1156("IGES_1156");
1562               const Standard_CString typeName("Bounding curve");
1563               Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(crv);
1564               msg1156.Arg(typeName);
1565               msg1156.Arg(label);
1566               SendWarning(st, msg1156);
1567               if (first) res = plane;
1568               else       res = wire;
1569               return res;
1570             }
1571           }
1572           //S4054 CTS18953 entity 14
1573           Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
1574           sfw->Load (wire);
1575           sfw->FixConnected (GetMaxTol());
1576           wire = sfw->Wire();
1577           BRepLib_MakeFace MF(pln, wire, Standard_False);
1578           if (!MF.IsDone()) {
1579             // AddFail(st, "Plane Construction Error.");
1580             return res;
1581           }
1582           
1583           TopoDS_Face F = MF.Face();
1584           GProp_GProps G;
1585           BRepGProp::SurfaceProperties(F,G);
1586           if (G.Mass() < 0) {
1587             if(!st->HasBoundingCurveHole())    
1588               wire.Reverse();
1589           }
1590           else
1591             if( st->HasBoundingCurveHole())
1592               wire.Reverse();
1593           //:3 by ABV 5 Nov 97: set plane to be finite
1594           //:3        if (first) B.Add (plane,wire);
1595           if ( first ) { 
1596             B.Add ( plane, wire ); 
1597             plane.Infinite ( Standard_False ); 
1598           } 
1599           //BRepLib_MakeFace MP(pln, wire);
1600           //plane = MP.Face();
1601         }
1602       }
1603       else {
1604         Message_Msg msg1156("IGES_1156");
1605         const Standard_CString typeName("Bounding curve");
1606         Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(crv);
1607         msg1156.Arg(typeName);
1608         msg1156.Arg(label);
1609         SendWarning(st, msg1156);
1610         // Plane Cannot Be Trimmed.
1611       }
1612   }
1613   
1614   if (first) res = plane;
1615   else       res = wire;
1616   return res;
1617 }
1618
1619
1620 //=======================================================================
1621 //function : ParamSurface
1622 //purpose  : 
1623 //=======================================================================
1624 TopoDS_Shape IGESToBRep_TopoSurface::ParamSurface(const Handle(IGESData_IGESEntity)& st,
1625                                                   gp_Trsf2d& trans,
1626                                                   Standard_Real& uFact) 
1627 { // Declaration of messages// 
1628   // DCE 22/12/98
1629   //Message_Msg msg1005("IGES_1005");
1630   ////////////////////////////////
1631
1632   TopoDS_Shape res;
1633
1634   TopoDS_Shape basisSurface = TransferTopoSurface(st);
1635   Standard_Real uscale = 1.;
1636   Standard_Real cscale = TheULength;
1637   if (basisSurface.IsNull()) {
1638     Message_Msg msg1005("IGES_1005");
1639     SendFail(st, msg1005);
1640     return res;
1641   }
1642
1643   TopAbs_ShapeEnum shapeEnum;
1644   shapeEnum = basisSurface.ShapeType();
1645   TopoDS_Face  face;
1646   switch (shapeEnum) {
1647   case TopAbs_FACE :
1648     {
1649       face = TopoDS::Face(basisSurface);
1650       break;
1651     }
1652   case TopAbs_SHELL :
1653     {
1654       TopoDS_Iterator IT(basisSurface);
1655       Standard_Integer nbfaces = 0;
1656       for (; IT.More(); IT.Next()) {
1657         nbfaces++;
1658         face = TopoDS::Face(IT.Value());
1659       }
1660       //szv#4:S4163:12Mar99 optimized
1661       if (nbfaces != 1) {
1662          Message_Msg msg1156("IGES_1156");
1663          const Standard_CString typeName("basis surface");
1664          Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(st);
1665          msg1156.Arg(typeName);
1666          msg1156.Arg(label);
1667          SendWarning(st, msg1156);
1668          return basisSurface;
1669       }
1670     }
1671     break;
1672   default:
1673     {
1674       //AddFail(st, "Basis Surface Transfer Error.");
1675       return res;
1676     }
1677   }
1678   
1679   //S4181 pdn 19.04.99 defining shift of parametric space on base 
1680   // of CAS.CADE type of surface  
1681   Standard_Real paramu = 0., paramv = 0.;
1682   TopLoc_Location L;
1683   TopoDS_Edge theedge;
1684   Handle(Geom_Surface) Surf = BRep_Tool::Surface(face);
1685
1686   if (Surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { 
1687     DeclareAndCast(Geom_RectangularTrimmedSurface, rectang, Surf);
1688     Surf = rectang->BasisSurface();
1689   }
1690
1691   if ((Surf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) ||
1692       (Surf->IsKind(STANDARD_TYPE(Geom_ConicalSurface)))     ||
1693       (Surf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)))    ||
1694       (Surf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)))) {
1695     TopExp_Explorer TE;
1696     for ( TE.Init(face,TopAbs_EDGE); TE.More(); TE.Next()){
1697       TopoDS_Edge myedge = TopoDS::Edge(TE.Current());
1698       Standard_Real First, Last;
1699       Handle(Geom2d_Curve) Curve2d = BRep_Tool::CurveOnSurface
1700         (myedge, face, First, Last);
1701       if ( Curve2d->IsKind(STANDARD_TYPE(Geom2d_Line))) {
1702         DeclareAndCast(Geom2d_Line, Line2d, Curve2d);   
1703         if (Line2d->Direction().IsParallel(gp::DY2d(),Precision::Angular())){
1704           theedge = myedge;
1705           break;
1706         }
1707       }
1708     }
1709
1710     Standard_Real First, Last;
1711     Handle(Geom_Curve) Curve3d = BRep_Tool::Curve(theedge, First, Last); 
1712     if (Precision::IsNegativeInfinite(First)) First = 0.;  
1713     
1714     if (Surf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))){
1715       DeclareAndCast(Geom_CylindricalSurface, Cyl, Surf);
1716       gp_Cylinder TheCyl = Cyl->Cylinder();
1717       ElSLib::CylinderParameters(TheCyl.Position(), 
1718                                  TheCyl.Radius(), 
1719                                  Curve3d->Value(First), paramu , paramv );
1720     }
1721
1722     else if (Surf->IsKind(STANDARD_TYPE(Geom_ConicalSurface))){
1723       DeclareAndCast(Geom_ConicalSurface, Cone, Surf);
1724       gp_Cone TheCone = Cone->Cone();
1725       ElSLib::ConeParameters(TheCone.Position(), 
1726                              TheCone.RefRadius(), 
1727                              TheCone.SemiAngle(), 
1728                              Curve3d->Value(First), paramu , paramv );
1729     }
1730
1731     else if (Surf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))){
1732       DeclareAndCast(Geom_ToroidalSurface, Tore, Surf);
1733       gp_Torus TheTore = Tore->Torus();
1734       ElSLib::TorusParameters(TheTore.Position(), 
1735                               TheTore.MajorRadius(), 
1736                               TheTore.MinorRadius(), 
1737                               Curve3d->Value(First), paramu , paramv );
1738     }
1739     else if (Surf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) &&
1740              //: abv 18.06.02: loopback on s1.brep BRep mode, face 32 - the spherical surface (192)
1741              //: in IGES is from [-90,90] by V, i.e. similar to OCC, thus only scaling is enough
1742              ! st->IsKind (STANDARD_TYPE(IGESSolid_SphericalSurface)) ) {
1743       DeclareAndCast(Geom_SphericalSurface, Sphere, Surf);
1744       gp_Sphere TheSphere = Sphere->Sphere();
1745       ElSLib::SphereParameters(TheSphere.Position(), 
1746                                TheSphere.Radius(), 
1747                                Curve3d->Value(First), paramu , paramv );
1748     }
1749         
1750     //#88 rln 06.04.99 CTS60168, BLEND.IGS entity 68
1751     //Generatrix is Transformed Circular Arc. When creating CAS.CADE surface parameterization
1752     //has changed.
1753     if (st->IsKind (STANDARD_TYPE (IGESGeom_SurfaceOfRevolution))) {
1754       DeclareAndCast (IGESGeom_SurfaceOfRevolution, revol, st);
1755       Handle(IGESData_IGESEntity) generatrix = revol->Generatrix();
1756       if (generatrix->IsKind (STANDARD_TYPE (IGESGeom_CircularArc))) {
1757         DeclareAndCast (IGESGeom_CircularArc, circ, generatrix);
1758         gp_Pnt2d startpoint = circ->StartPoint();
1759         paramv -= ElCLib::Parameter (gp_Circ2d (gp_Ax2d (circ->Center(), gp_Dir2d(1,0)), circ->Radius()), startpoint);
1760         if (Surf->IsKind (STANDARD_TYPE(Geom_SphericalSurface)))
1761           paramv += ShapeAnalysis::AdjustToPeriod(paramv, - M_PI, M_PI);
1762         else if (Surf->IsKind (STANDARD_TYPE(Geom_ToroidalSurface)))
1763           paramv += ShapeAnalysis::AdjustToPeriod(paramv, 0, M_PI * 2);
1764       }
1765     }
1766     else if (st->IsKind (STANDARD_TYPE (IGESGeom_TabulatedCylinder))) {
1767       DeclareAndCast (IGESGeom_TabulatedCylinder, cylinder, st);
1768       Handle(IGESData_IGESEntity) directrix = cylinder->Directrix();
1769       if (directrix->IsKind (STANDARD_TYPE (IGESGeom_CircularArc))) {
1770         DeclareAndCast (IGESGeom_CircularArc, circ, directrix);
1771         gp_Pnt2d startpoint = circ->StartPoint();
1772         paramu -= ElCLib::Parameter (gp_Circ2d (gp_Ax2d (circ->Center(), gp_Dir2d(1,0)), circ->Radius()), startpoint);
1773         paramu += ShapeAnalysis::AdjustToPeriod(paramu, 0, M_PI * 2);
1774       }
1775     }
1776
1777   }
1778
1779   if ( Abs(paramu) <= Precision::Confusion()) paramu = 0.;
1780   if ( Abs(paramv) <= Precision::Confusion()) paramv = 0.;
1781   
1782   //S4181 pdn 16.04.99 computation of transformation depending on 
1783   //IGES Type of surface
1784   Handle(IGESData_IGESEntity) isrf = st;
1785   if (isrf->IsKind(STANDARD_TYPE(IGESGeom_OffsetSurface))){
1786     DeclareAndCast(IGESGeom_OffsetSurface, offsurf, isrf);
1787     isrf = offsurf->Surface();
1788   }
1789   if (isrf->IsKind(STANDARD_TYPE(IGESGeom_SurfaceOfRevolution))) {
1790     DeclareAndCast(IGESGeom_SurfaceOfRevolution, st120, isrf);
1791     //S4181 pdn 19.04.99 defining transformation matrix
1792     gp_Trsf2d tmp;
1793     tmp.SetTranslation(gp_Vec2d (0, -2 * M_PI));
1794     trans.PreMultiply(tmp);
1795     tmp.SetMirror(gp::OX2d());
1796     trans.PreMultiply(tmp);
1797     tmp.SetMirror(gp_Ax2d (gp::Origin2d(), gp_Dir2d (1.,1.)));
1798     trans.PreMultiply(tmp);
1799     uscale = 1./cscale;
1800     //#30 rln 19.10.98
1801     //CAS.CADE SA = 2*PI - IGES TA
1802     //paramu = st120->StartAngle();
1803     paramu = -(2 * M_PI - st120->EndAngle());
1804   }
1805   else
1806     paramu = 0.;
1807   
1808   if (isrf->IsKind(STANDARD_TYPE(IGESGeom_RuledSurface))) {
1809     uscale = 1./cscale;
1810   }
1811   
1812   // corrected skl 13.11.2001 for BUC61054
1813   if (isrf->IsKind(STANDARD_TYPE(IGESGeom_TabulatedCylinder))) {
1814     Handle(IGESGeom_TabulatedCylinder) igtc = Handle(IGESGeom_TabulatedCylinder)::DownCast(isrf);
1815     Handle(IGESData_IGESEntity) idie = igtc->Directrix();
1816     Standard_Real uln=1;
1817     Standard_Real Umin,Umax,Vmin,Vmax;
1818     //scaling parameterization from [0,1]
1819     Surf->Bounds(Umin,Umax,Vmin,Vmax);
1820     uln = Abs(Umax-Umin);
1821     //computing shift of pcurves
1822     uscale = uln/cscale;
1823     paramu = Umin/uln;
1824   }
1825   
1826   if (isrf->IsKind(STANDARD_TYPE(IGESSolid_CylindricalSurface))||
1827       isrf->IsKind(STANDARD_TYPE(IGESSolid_ConicalSurface))) {
1828     uscale = M_PI/180.;
1829   }
1830   
1831   if (isrf->IsKind(STANDARD_TYPE(IGESSolid_SphericalSurface))) {
1832     cscale = M_PI/180.;
1833     uscale = 1.;
1834   }
1835       
1836   if (isrf->IsKind(STANDARD_TYPE(IGESSolid_ToroidalSurface))) {
1837     gp_Trsf2d tmp;
1838     tmp.SetTranslation(gp_Vec2d (0, -360.)); // in IGES terms
1839     trans.PreMultiply(tmp);
1840     tmp.SetMirror(gp::OX2d());
1841     trans.PreMultiply(tmp);
1842     tmp.SetMirror(gp_Ax2d (gp::Origin2d(), gp_Dir2d (1.,1.)));
1843     trans.PreMultiply(tmp);
1844     if(paramv > 0)
1845       paramv = paramv*180./M_PI;
1846     cscale = M_PI/180.;
1847     uscale = 1.;
1848   } 
1849     
1850   gp_Trsf2d tmp;
1851   tmp.SetTranslation(gp_Pnt2d(0.,0.), gp_Pnt2d(paramu,paramv));
1852   trans.PreMultiply(tmp);
1853   
1854   tmp.SetScale(gp_Pnt2d(0,0),cscale);
1855   trans.PreMultiply(tmp);
1856   uFact = uscale;
1857   return face;
1858 }
1859