summaryrefslogtreecommitdiff
path: root/src/IGESToBRep/IGESToBRep_TopoSurface.cxx
blob: c0a6378ec862d241aaed45e542f9f304514b9f24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
//=======================================================================
//file    : IGESToBRep_TopoSurface
//modified: 
// Integration to ensure SCCS base integrity
// 21.12.98 rln, gka S4054
// 28.12.98 dce S3767 New messaging system
//#55,#56 rln 25.12.98 UKI60878
//:l1 abv 10.01.99: USA60022 7289: fix missing seam
//#63 rln 19.01.99 UKI60878 no offset if C0 surface is converted into the grid of C1 surfaces
//%13 pdn 15.02.99 USA60293 entities 792, 8604 .. handling of C0 ruled surfaces, tabulated cylindres,
//                 and surfaces of revolution.
//:p4 abv, pdn 23.02.99: PRO9234 #15720: call BRepTools::Update() for faces
//%14 pdn 24.02.99 implementing of ShapeFix_Face on IGES  
//    pdn 17.04.99 S4181: Implementing of reading IGES elementary surfaces.
//    pdn 10.05.99 S4137: Using modified ShapeDivide tools
//#11 smh 22.12.99 BUC60625 Transform axis.
//#12 smh 12.12.99 FRA62468 - Using conversion to B-Spline for Offset surface
//=======================================================================

#include <IGESToBRep_TopoSurface.ixx>

#include <Standard_ErrorHandler.hxx>
#include <IGESToBRep.hxx>
#include <IGESToBRep_CurveAndSurface.hxx>
#include <IGESToBRep_TopoCurve.hxx>
#include <IGESToBRep_BasicCurve.hxx>
#include <IGESToBRep_BasicSurface.hxx>

#include <BRepAdaptor_Curve.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <BRepPrimAPI_MakeRevol.hxx>
//S4054: ShapeTool_MakeWire -> ShapeExtend_WireData //:g8: BRepLib_MakeWire -> ShapeTool_MakeWire
#include <BRepGProp.hxx>
#include <BRepFill.hxx>
#include <BRepLib_MakeFace.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>

#include <ElSLib.hxx>

#include <GProp.hxx>
#include <GProp_GProps.hxx>

#include <GeomAbs_Shape.hxx>

#include <Geom2d_Line.hxx>
#include <Geom2d_Curve.hxx>

#include <Geom_BezierCurve.hxx>
#include <Geom_Curve.hxx>
#include <Geom_ConicalSurface.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_OffsetSurface.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Surface.hxx>
#include <Geom_SurfaceOfLinearExtrusion.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Geom_SphericalSurface.hxx>
#include <Geom_ToroidalSurface.hxx>

#include <IGESData_IGESEntity.hxx>
#include <IGESData_ToolLocation.hxx>
  
#include <IGESGeom_BSplineSurface.hxx>
#include <IGESGeom_BoundedSurface.hxx>
#include <IGESGeom_CurveOnSurface.hxx>
#include <IGESGeom_Line.hxx>
#include <IGESGeom_Point.hxx>
#include <IGESGeom_Direction.hxx>

#include <IGESSolid_CylindricalSurface.hxx>
#include <IGESSolid_ConicalSurface.hxx>
#include <IGESSolid_ToroidalSurface.hxx>
#include <IGESSolid_SphericalSurface.hxx>
#include <IGESSolid_PlaneSurface.hxx>

#include <Interface_Macros.hxx>

#include <gp_GTrsf.hxx>

#include <Precision.hxx>

#include <TopAbs.hxx>

#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>

#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>

#include <TopLoc_Location.hxx>

#include <gp.hxx>
#include <gp_Ax1.hxx>
#include <gp_Cylinder.hxx>
#include <gp_Cone.hxx>
#include <gp_Dir.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt.hxx>
#include <gp_Sphere.hxx>
#include <gp_Torus.hxx>
#include <gp_Trsf.hxx>
#include <gp_Vec.hxx>
#include <stdio.h>

//:e3
#include <TColgp_Array1OfPnt.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_Line.hxx>
#include <BRepTools.hxx>//#16
#include <ShapeAnalysis.hxx>
//S4054
#include <ShapeExtend_WireData.hxx>
#include <ShapeFix_Wire.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <GeomConvert.hxx>
#include <GeomLib.hxx>
#include <BSplCLib.hxx>
//S3767
#include <Message_Msg.hxx>
#include <IGESData_IGESModel.hxx>

#include <IGESGeom_CircularArc.hxx>
#include <ElCLib.hxx>

#include <BRepOffset_MakeOffset.hxx>
#include <BRep_Tool.hxx>
#include <Geom_BSplineSurface.hxx>
#include <ShapeAlgo.hxx>
#include <ShapeAlgo_AlgoContainer.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <Geom_SurfaceOfRevolution.hxx>

//=======================================================================
//function : IGESToBRep_TopoSurface
//purpose  : 
//=======================================================================

IGESToBRep_TopoSurface::IGESToBRep_TopoSurface()
     :IGESToBRep_CurveAndSurface()
{  
}


//=======================================================================
//function : IGESToBRep_TopoSurface
//purpose  : 
//=======================================================================

IGESToBRep_TopoSurface::IGESToBRep_TopoSurface
  (const IGESToBRep_CurveAndSurface& CS)
     :IGESToBRep_CurveAndSurface(CS)
{  
}


//=======================================================================
//function : IGESToBRep_TopoSurface
//purpose  : 
//=======================================================================

IGESToBRep_TopoSurface::IGESToBRep_TopoSurface
  (const Standard_Real    eps,
   const Standard_Real    epsCoeff,
   const Standard_Real    epsGeom,
   const Standard_Boolean mode,
   const Standard_Boolean modeapprox,
   const Standard_Boolean optimized)
     :IGESToBRep_CurveAndSurface(eps, epsCoeff, epsGeom, mode, 
				 modeapprox, optimized)
{  
}

static Standard_Boolean extractCurve3d (const TopoDS_Shape& theEdges,
                                        Handle(Geom_Curve)& theCurve)
{
  TopExp_Explorer anExp(theEdges, TopAbs_EDGE);
  Standard_Integer howMuch = 0;
  Standard_Real f = 0.0, l = 0.0;
  for (; anExp.More(); anExp.Next()) {
    TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
    if (anEdge.IsNull())
      continue;
    howMuch++;
    theCurve = BRep_Tool::Curve(anEdge, f, l);
  }
  if ( howMuch != 1 || theCurve.IsNull() )
    return Standard_False;
  
  if ( f != theCurve->FirstParameter() || l != theCurve->LastParameter() )
    theCurve = new Geom_TrimmedCurve ( theCurve, f, l );
  return Standard_True;
}


//=======================================================================
//function : TransferTopoSurface
//purpose  : 
//=======================================================================

TopoDS_Shape IGESToBRep_TopoSurface::TransferTopoSurface
       (const Handle(IGESData_IGESEntity)& st)
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////

  TopoDS_Shape res;
  TheULength = 1.;
  //S4054
  if (st.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
  }
  ////modified by jgv, 20.11.2009 for OCC21487///
  else if (HasShapeResult(st))
    {
      res = GetShapeResult(st);
      return res;
    }
  ///////////////////////////////////////////////
  else if (IGESToBRep::IsBasicSurface(st)) {
    res = TransferTopoBasicSurface(st);
  }
  else if (st->IsKind(STANDARD_TYPE(IGESGeom_TrimmedSurface))) {
    DeclareAndCast(IGESGeom_TrimmedSurface, st144, st);
    res = TransferTrimmedSurface(st144);
  }
  else if (st->IsKind(STANDARD_TYPE(IGESGeom_SurfaceOfRevolution))) {
    DeclareAndCast(IGESGeom_SurfaceOfRevolution, st120, st);
    res = TransferSurfaceOfRevolution(st120);
  }
  else if (st->IsKind(STANDARD_TYPE(IGESGeom_TabulatedCylinder))) {
    DeclareAndCast(IGESGeom_TabulatedCylinder, st122, st);
    res = TransferTabulatedCylinder(st122);
  }
  else if (st->IsKind(STANDARD_TYPE(IGESGeom_RuledSurface))) {
    DeclareAndCast(IGESGeom_RuledSurface, st118, st);
    res = TransferRuledSurface(st118);
  }
  else if (st->IsKind(STANDARD_TYPE(IGESGeom_Plane))) {
    DeclareAndCast(IGESGeom_Plane, st108, st);
    res = TransferPlane(st108);
  }
  else if (st->IsKind(STANDARD_TYPE(IGESGeom_BoundedSurface))) {
    DeclareAndCast(IGESGeom_BoundedSurface, st143, st);
    res = TransferBoundedSurface(st143);
  }
  else if (st->IsKind(STANDARD_TYPE(IGESGeom_OffsetSurface))) {
    DeclareAndCast(IGESGeom_OffsetSurface, st140, st);
    res = TransferOffsetSurface(st140);
  }
  //S4181 pdn IGESSolid_PlaneSurface recognized as basic surface
  else if (st->IsKind(STANDARD_TYPE(IGESBasic_SingleParent)))  {
    DeclareAndCast(IGESBasic_SingleParent,st402_9,st);
    res = TransferPerforate(st402_9);    // limite : Planes seulement
  }
  else {
   //  AddFail(st, "The IGESEntity is not a Topologic Surface.");
  }
  SetShapeResult (st, res);
  return res;
}

//=======================================================================
//function : TransferTopoBasicSurface
//purpose  : 
//=======================================================================

TopoDS_Shape IGESToBRep_TopoSurface::TransferTopoBasicSurface
       (const Handle(IGESData_IGESEntity)& st)
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////

  TopoDS_Shape  res;

  if (st.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
    return res;
  }
  if (!IGESToBRep::IsBasicSurface(st)) {
  //  AddFail(st, "BasicSurface Transfer Error : Not Allowed IGESEntity");  This message can not occur.
    return res;
  }

  IGESToBRep_BasicSurface BS(*this);

  Handle(Geom_Surface) surf = BS.TransferBasicSurface(st);
  if (surf.IsNull()) {
    // AddFail(st, "Surface Conversion Error"); Messages have ever been Added in the called function.
    return res;
  }

  //#9 rln 26/02/98 UKI60106
  if (surf->Continuity() < GeomAbs_C1) {
    Message_Msg msg1250("IGES_1250");
    SendWarning(st, msg1250);
  }
  if(surf->IsKind(STANDARD_TYPE(Geom_Plane))){
    BRep_Builder B;
    TopoDS_Face plane;
    B.MakeFace(plane);
    B.UpdateFace(plane, surf, TopLoc_Location(), Precision::Confusion());
    res = plane; 
  }
  else {
    BRepLib_MakeFace makeFace(surf, Precision::Confusion());
    res = makeFace.Face();
  }

  if (st->HasTransf()) {
    gp_Trsf trsf;
    SetEpsilon(1.E-04);
    if (IGESData_ToolLocation::ConvertLocation
	(GetEpsilon(),st->CompoundLocation(),trsf,GetUnitFactor())) { 
      TopLoc_Location locFace(trsf);
      res.Move(locFace);
    }
    else {
      Message_Msg msg1035("IGES_1035");
      SendWarning(st, msg1035);
    } 
  }
  return res;
}


//=======================================================================
//function : TransferRuledSurface
//purpose  : 
//=======================================================================
static void reparamBSpline(Handle(Geom_Curve)& curve,
                           const Standard_Real First,
                           const Standard_Real Last)
{
  Handle (Geom_BSplineCurve) bscurve;
  if (!curve->IsKind (STANDARD_TYPE (Geom_BSplineCurve))) {
    if (curve->FirstParameter() < First || curve->LastParameter() > Last)
      curve = new Geom_TrimmedCurve (curve, First, Last);
    bscurve = GeomConvert::CurveToBSplineCurve (curve, Convert_RationalC1);
  }
  else {
    bscurve = Handle (Geom_BSplineCurve)::DownCast (curve);
    bscurve->Segment (First, Last);
  }
  
  if (bscurve.IsNull())
    return;
  
  TColStd_Array1OfReal Knots(1, bscurve->NbKnots());
  bscurve->Knots(Knots);
  BSplCLib::Reparametrize (0., 1., Knots);
  bscurve->SetKnots(Knots);
  curve = bscurve;
}

static void ReparamCurve(TopoDS_Edge& edge)
{
  TopLoc_Location L;
  Standard_Real First, Last;
  
  Handle (Geom_Curve) curve = Handle (Geom_Curve)::DownCast (BRep_Tool::Curve ( edge, L, First, Last )->Copy());
  //if ( Abs (First) <= Precision::PConfusion() && Abs (Last - 1.) <= Precision::PConfusion() ) return;
  if(!curve->IsKind(STANDARD_TYPE(Geom_Line))) return;
  
  reparamBSpline( curve, First, Last );
  
  BRep_Builder B;
  B.UpdateEdge ( edge, curve, L, Precision::Confusion() );
  B.Range ( edge, 0., 1 );
}


//=======================================================================
//function : TransferRuledSurface
//purpose  : 
//=======================================================================

TopoDS_Shape IGESToBRep_TopoSurface::TransferRuledSurface
  (const Handle(IGESGeom_RuledSurface)& st)
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////////
  TopoDS_Shape res;

  if (st.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
    return res;
  }

  IGESToBRep_TopoCurve TC(*this);
  //%13 pdn 12.02.99 
  TC.SetContinuity (0);
  Handle(IGESData_IGESEntity) igesCurve1 = st->FirstCurve();
  Handle(IGESData_IGESEntity) igesCurve2 = st->SecondCurve();

  if (igesCurve1.IsNull()) {
    Message_Msg msg148("XSTEP_148");
    SendFail(st, msg148); // Curve Reading Error : Null IGESEntity
    return res;
  }
  if (igesCurve2.IsNull()) {
    Message_Msg msg149("XSTEP_149");
    SendFail(st, msg149); // Curve Reading Error : Null IGESEntity
    return res;
  }

  Standard_Integer nbEdges1,   nbEdges2;
  TopoDS_Shape     shape1,     shape2;
  TopoDS_Wire      wire1,      wire2;
  TopoDS_Wire      newWire1,   newWire2;
  //TopoDS_Edge      edge1,      edge2; // skl

  if (IGESToBRep::IsTopoCurve(igesCurve1)) { 
    shape1 = TC.TransferTopoCurve(igesCurve1);
    if (shape1.IsNull()) {
      Message_Msg msg1156("IGES_1156");
      const Standard_CString typeName(igesCurve1->DynamicType()->Name());
      Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesCurve1);
      msg1156.Arg(typeName);
      msg1156.Arg(label);
      SendFail(st, msg1156);
      return res;
    }

    //%13 pdn 15.02.99
    //added by rln on 03/12/97
    //if shape1 is a wire it means that the curve1 in file was of continuity C0
    //in order to get a face instead of shell when to BRepFill shape1
    //should be retransfered with contionuity C0 (to get an edge). Once shape1
    //has been built with C0, it is useless to require C1 from shape2 because
    //anyway resulting surface was of continuity C0. Thus shape2 is built with C0
//    if (shape1.ShapeType() != TopAbs_EDGE) {
//      TC.SetContinuity (0);
//      shape1  = TC.TransferTopoCurve(igesCurve1);
//      if (shape1.IsNull()) {
//	Message_Msg msg1156("IGES_1156");
//	const Standard_CString typeName(igesCurve1->DynamicType()->Name());
//	Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesCurve1);
//	msg1156.Arg(typeName);
//	msg1156.Arg(label);
//	SendFail(st, msg1156);  
//	return res;
//      }
//      else {  
//        Message_Msg msg1250("IGES_1250");
//        SendWarning (st, msg1250); // RuledSurface was built with continuity C0
//      }
//    }
    
    TopAbs_ShapeEnum shapeEnum1 = shape1.ShapeType();
    switch (shapeEnum1) {
    case TopAbs_EDGE :
      {
	TopoDS_Edge edge1 = TopoDS::Edge(shape1);
	ReparamCurve(edge1);
	nbEdges1 = 1;
      }
      break;
    case TopAbs_WIRE : 
      {
	wire1    = TopoDS::Wire(shape1);
	nbEdges1 = 0;
	for (TopoDS_Iterator hulot(wire1); hulot.More(); hulot.Next()) {
	 TopoDS_Edge edge1 = TopoDS::Edge(hulot.Value());
	 ReparamCurve(edge1);
	 nbEdges1++;
	}
      }
      break;
    default: 
      {
	// AddFail(st, "Curve Conversion Error."); This message can not occur.
	return res;
      }
      //break; //szv#4:S4163:12Mar99 unreachable
    }
  }
  else { 
    Message_Msg msg148("XSTEP_148");
    SendFail(st, msg148);
    // Curve Type not Allowed.
    return res;
  }
    
  if (IGESToBRep::IsTopoCurve(igesCurve2)) { 
    shape2 = TC.TransferTopoCurve(igesCurve2);
    // dirflg = 0 join first to first, last to last
    // dirflg = 1 join first to last, last to first
    
    if (shape2.IsNull()) {
      Message_Msg msg1156("IGES_1156");
      const Standard_CString typeName(igesCurve2->DynamicType()->Name());
      Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesCurve2);
      msg1156.Arg(typeName);
      msg1156.Arg(label);
      SendFail(st, msg1156);
      // Curve Conversion Error.
      return res;
    }
   Standard_Integer dirflag = st->DirectionFlag ();
   // if (dirflag == 1){ // gka BUC60685
      
    //  shape2.Reverse();
    //}

    TopAbs_ShapeEnum shapeEnum2 = shape2.ShapeType();
    switch (shapeEnum2) {
    case TopAbs_EDGE : 
      {
	TopoDS_Edge edge2 = TopoDS::Edge(shape2);
	ReparamCurve(edge2);
	if (dirflag == 1)
	  shape2.Reverse();
	nbEdges2 = 1;
      }
      break;
    case TopAbs_WIRE :
      {
	wire2 = TopoDS::Wire(shape2);
	nbEdges2 = 0;
	for (TopoDS_Iterator cousto(wire2); cousto.More(); cousto.Next())  {
	  TopoDS_Edge edge2 = TopoDS::Edge(cousto.Value());
	  ReparamCurve(edge2);
	  nbEdges2++;
	}
	if (dirflag == 1) {   //gka BUC60685
	  Handle(ShapeExtend_WireData) sewd2 = new ShapeExtend_WireData;
	  sewd2->Add(shape2);
	  sewd2->Reverse();
	  wire2 = sewd2->Wire();
	}
      }
      break;
    default:
      { 
	// AddFail(st, "Curve Conversion Error.");
	return res;
      }
      //break; //szv#4:S4163:12Mar99 unreachable
    }
  }
  else { 
    Message_Msg msg149("XSTEP_149");
    SendFail(st, msg149);
    // Curve Type not Allowed
    return res;
  }
  

  if (nbEdges1 != nbEdges2) {
    if (nbEdges1 == 1) {
      Handle(ShapeExtend_WireData) sewd1 = new ShapeExtend_WireData;
      sewd1->Add(shape1);
      wire1  = sewd1->Wire();
    }
    else if (nbEdges2 == 1) {
      Handle(ShapeExtend_WireData) sewd2 = new ShapeExtend_WireData;
      sewd2->Add(shape2);
      wire2  = sewd2->Wire();
    }

    if (!st->IsRuledByParameter()) {
      // AddWarning (st,"Compute by parametric constant ratio");
    }
    if (!ShapeAlgo::AlgoContainer()->HomoWires
	(wire1, wire2, newWire1, newWire2, st->IsRuledByParameter())) {
      Message_Msg msg1255("IGES_1255");// "Ruled Surface Construction Error");
      SendFail(st, msg1255);
      return res;
    }
    nbEdges1 = 2;           // a number > 1
  }

  else if (nbEdges1 != 1) {
    newWire1 = wire1;
    newWire2 = wire2;
  }


  if (nbEdges1 == 1) {
    
    //:e3 abv 31 Mar 98: UK4.igs 3170: ruled surface with directixes - line
    // In IGES, line is parametrised [0;1] - this should have been kept !
    // Let us detect the case and remake curve as bspline [0;1]
    for ( Standard_Integer i=1; i <=2; i++ ) {
      //#43 rln 20.11.98 S4054 BUC50047 entity D463 (circles as generatrices [0, 2*PI])
      //reparameterisation should be for all curves not with range [0, 1] (see IGES)
      TopoDS_Edge edge = TopoDS::Edge ( i==1 ? shape1 : shape2 );
      //ReparamCurve(edge);
      TopLoc_Location L;
      Standard_Real First, Last;
      Handle (Geom_Curve) curve = Handle (Geom_Curve)::DownCast (BRep_Tool::Curve ( edge, L, First, Last )->Copy());
      if ( Abs (First) <= Precision::PConfusion() && Abs (Last - 1.) <= Precision::PConfusion() ) continue;
      
      Handle (Geom_BSplineCurve) bscurve;
      if (!curve->IsKind (STANDARD_TYPE (Geom_BSplineCurve))) {
	if (curve->FirstParameter() < First || curve->LastParameter() > Last)
	  curve = new Geom_TrimmedCurve (curve, First, Last);
	bscurve = GeomConvert::CurveToBSplineCurve (curve, Convert_RationalC1);
      }
      else {
	bscurve = Handle (Geom_BSplineCurve)::DownCast (curve);
	bscurve->Segment (First, Last);
      }
      TColStd_Array1OfReal Knots(1, bscurve->NbKnots());
      bscurve->Knots(Knots);
      BSplCLib::Reparametrize (0., 1., Knots);
      bscurve->SetKnots(Knots);
      
      BRep_Builder B;
      B.UpdateEdge ( edge, bscurve, L, Precision::Confusion() );
      B.Range ( edge, 0., 1 );
      if ( i ==1 ) shape1 = edge;
      else shape2 = edge;
    }
    
    res = BRepFill::Face(TopoDS::Edge(shape1), TopoDS::Edge(shape2));
    Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(res));
    if(surf->Continuity()==GeomAbs_C0) {
      Message_Msg msg1250("IGES_1250");
      SendWarning (st, msg1250);
    }
  }
  else {
    res = BRepFill::Shell(newWire1, newWire2);
  }
  if (res.IsNull()) {
    Message_Msg msg1255("IGES_1255");// "Ruled Surface Construction Error");
    SendFail(st, msg1255);
    return res;
  }


  if (st->HasTransf()) {
    gp_Trsf trsf;
    SetEpsilon(1.E-04);
    if (IGESData_ToolLocation::ConvertLocation
	(GetEpsilon(),st->CompoundLocation(), trsf,GetUnitFactor())) { 
      TopLoc_Location shapeLoc(trsf);
      res.Move(shapeLoc);
    }
    else {
      Message_Msg msg1035("IGES_1035");
      SendWarning(st,msg1035); // Transformation : not a similarity
    }
  }
  return res;
}


//=======================================================================
//function : TransferSurfaceOfRevolution
//purpose  : 
//=======================================================================

TopoDS_Shape IGESToBRep_TopoSurface::TransferSurfaceOfRevolution
  (const Handle(IGESGeom_SurfaceOfRevolution)& st)
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////////
  TopoDS_Shape res;
  if (st.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
    return res;
  }

  IGESToBRep_TopoCurve  TC(*this);
  IGESToBRep_BasicCurve BC(*this);
  Handle(IGESData_IGESEntity) igesGeneratrix = st->Generatrix();
  Handle(IGESGeom_Line)       igesAxis       = st->AxisOfRevolution();

  if (igesGeneratrix.IsNull() || !IGESToBRep::IsTopoCurve(igesGeneratrix) ) {
    Message_Msg msg153("XSTEP_153");
    SendFail(st, msg153);
    // Generatrix Reading Error : Null IGESEntity
    // Generatrix : Not Allowed IGESEntity.
    return res;
  }
  
  DeclareAndCast(IGESGeom_Line,srgen,st->Generatrix());
  if (!srgen.IsNull()) {
    gp_Pnt gen1 = srgen->StartPoint();
    gp_Pnt gen2 = srgen->EndPoint();
    TheULength = gen1.Distance(gen2)*GetUnitFactor();
  }

  if (igesAxis.IsNull()) {
    Message_Msg msg152("XSTEP_152");
    SendFail(st, msg152);
    return res;
  }

  //%13 pdn 15.02.99 
  TC.SetContinuity(0);
  TopoDS_Shape generatrix  = TC.TransferTopoCurve(igesGeneratrix);
  if (generatrix.IsNull()) {
    Message_Msg msg1156("IGES_1156");
    const Standard_CString typeName("generatrix");
    Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesGeneratrix);
    msg1156.Arg(typeName);
    msg1156.Arg(label);
    SendFail(st, msg1156);
    // Generatrix Conversion Error.
    return res;
  }

  gp_Trsf startLoc;
  gp_Pnt pt1 = igesAxis->TransformedStartPoint(); //smh#11
  gp_Pnt pt2 = igesAxis->TransformedEndPoint(); //smh#11
  pt1.Scale(gp_Pnt(0,0,0),GetUnitFactor());
  pt2.Scale(gp_Pnt(0,0,0),GetUnitFactor());
  //#30 rln 19.10.98 To keep IGES surface normal CAS.CADE axis = reversed IGES axis
  //CAS.CADE SA = 2*PI - IGES TA
  //CAS.CADE TA = 2*PI - IGES SA
  //gp_Ax1 revolAxis(pt1, gp_Dir(gp_Vec(pt1, pt2)));
  //Standard_Real startAngle = st->StartAngle();
  //Standard_Real endAngle = st->EndAngle();
  gp_Ax1 revolAxis(pt1, gp_Dir( gp_Vec (pt2, pt1)));
  Standard_Real startAngle = 2 * PI - st->EndAngle();
  Standard_Real endAngle = 2 * PI - st->StartAngle();
  Standard_Real deltaAngle = endAngle - startAngle;
  Standard_Boolean IsFullAngle = ( deltaAngle > 2.*PI-Precision::PConfusion() );
  if (IsFullAngle) deltaAngle = 2.*PI;  // ** CKY 18-SEP-1996
  // il faudra translater les courbes 2d de startAngle pour 
  // etre en phase IGES et BRep
  startLoc.SetRotation(revolAxis, startAngle);
  generatrix.Move(startLoc);
  
  // PTV file D44-11325-6.igs OCC660 depends on OCC450
  // PTV 29.05.2002 OCC450 create Surface of Revolution by native API
  // file NIC_file5.igs 
  // (BRepPrimAPI_MakeRevol replace surface of revolution by plane then 3D and 2D curves are inconsistent;
  // and 3D is ignored. As result shape is rectangle instead circle shape.
  Handle(Geom_Curve) aBasisCurve;
  {
  try {
    OCC_CATCH_SIGNALS
    if (extractCurve3d(generatrix, aBasisCurve)) {
      Handle(Geom_Surface) aResultSurf = new Geom_SurfaceOfRevolution(aBasisCurve, revolAxis);
      if ( !aResultSurf.IsNull() && !IsFullAngle ) {
        Standard_Real VF = aBasisCurve->FirstParameter();
        Standard_Real VL = aBasisCurve->LastParameter();
        // PTV 29.08.2002  begin of OCC663 Trim surface by correct parameters
        Standard_Real UF = 0;
        Standard_Real UL = endAngle - startAngle;;
        //aResultSurf = new Geom_RectangularTrimmedSurface(aResultSurf, startAngle, endAngle, VF, VL);
        aResultSurf = new Geom_RectangularTrimmedSurface(aResultSurf, UF, UL, VF, VL);
        // PTV 29.08.2002  end of OCC663
      }
      if (!aResultSurf.IsNull()) {
        BRepBuilderAPI_MakeFace aMakeF(aResultSurf, Precision::Confusion());
        if (aMakeF.IsDone()) res = aMakeF.Face();
      }
    }
  }
  catch (Standard_Failure) {
#ifdef DEB
    cout << "Warning: IgesToBRep_TopoSurface::TransferSurfaceOfRevolution(): exception by Geom: ";
    Standard_Failure::Caught()->Print ( cout ); cout << endl;
#endif
  }
  }
  
  if ( res.IsNull() ) {
    // do as usual.
  
    BRepPrimAPI_MakeRevol revol(generatrix, revolAxis, deltaAngle);
//mjm: si debug IsDone()est fait : 
//  if (!revol.IsDone()) {
//    AddFail(st, "Revol Construction Error.");
//    return res;
//  }
    res = revol.Shape();
  }
  //%13 pdn 15.02.99
  if (res.ShapeType() == TopAbs_FACE) {
    Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(res));
    if(surf->Continuity()==GeomAbs_C0) {
      Message_Msg msg1250("IGES_1250");
      SendWarning (st, msg1250);
    } 
  }

  if (st->HasTransf()) {
    gp_Trsf trsf;
    SetEpsilon(1.E-04);
    if (IGESData_ToolLocation::ConvertLocation
	(GetEpsilon(), st->CompoundLocation(), trsf, GetUnitFactor())) { 
      TopLoc_Location shapeLoc(trsf);
      res.Move(shapeLoc);
    }
    else {
      Message_Msg msg1035("IGES_1035");
      SendWarning(st,msg1035); // Transformation : not a similarity
    }
  }
    
  return res;
}


//=======================================================================
//function : TransferTabulatedCylinder
//purpose  : 
//=======================================================================

TopoDS_Shape IGESToBRep_TopoSurface::TransferTabulatedCylinder
       (const Handle(IGESGeom_TabulatedCylinder)& st)
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////////
  TopoDS_Shape res;
  if (st.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
    return res;
  }

  IGESToBRep_TopoCurve TC(*this);
//  TopoDS_Edge  firstEdge;//commented by rln on 02/12/97

  Handle(IGESData_IGESEntity) igesDirectrix = st->Directrix();
  if (igesDirectrix.IsNull() || !IGESToBRep::IsTopoCurve(igesDirectrix) ) {
    Message_Msg msg153("XSTEP_153");
    SendFail(st, msg153); 
    // Directrix Reading Error : Null IGESEntity
    //Directrix, not allowed IGESEntity
    return res;
  }

  //%13 pdn 15.02.99
  TC.SetContinuity(0);
  TopoDS_Shape directrix = TC.TransferTopoCurve(igesDirectrix);
  if (directrix.IsNull()) {
    Message_Msg msg1156("IGES_1156");
    const Standard_CString typeName("directrix");
    Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesDirectrix);
    msg1156.Arg(typeName);
    msg1156.Arg(label);
    SendFail(st, msg1156);
    // Directrix Conversion Error.
    return res;
  }

  //modified by rln on 03/12/97
  //TopoDS_Vertex firstVertex = TopExp::FirstVertex(firstEdge);
  TopoDS_Vertex firstVertex, lastVertex;
  ShapeAnalysis::FindBounds (directrix, firstVertex, lastVertex);
  gp_Pnt pt1  = BRep_Tool::Pnt(firstVertex);
  gp_Pnt pt2  = st->EndPoint();
  pt2.Scale(gp_Pnt(0,0,0),GetUnitFactor());

  TheULength = pt1.Distance(pt2);
  if(TheULength < Precision::Confusion()) {
    Message_Msg msg("Tabulated cylinder with zero length");
    SendFail (st, msg); // TabulatedCylinder was built with continuity C0
    return res;
  }

  // PTV file D44-11325-6.igs OCC660 depends on OCC450
  // PTV 29.05.2002 OCC450 create Surface of LinearExtrusion by native API
  // see description about problem in Surface of Revolution
  Handle(Geom_Curve) aBasisCurve;
  {
  try {
    OCC_CATCH_SIGNALS
    if (extractCurve3d(directrix, aBasisCurve)) {
      // PTV 29.08.2002 OCC663 file D44-11325-6.igs, entity 4640
      if (igesDirectrix->IsKind(STANDARD_TYPE(IGESGeom_ConicArc))) {
        // PTV 30.08.2002 remove regression on xloop k1.brep in face and brep mode.
        Standard_Real tmpF, tmpL, tmpToler;
        tmpF = aBasisCurve->FirstParameter();
        tmpL = aBasisCurve->LastParameter();
        tmpToler = Precision::PConfusion();
        if ( (fabs(tmpF) >= tmpToler) && (fabs(tmpL - 2*PI) >= tmpToler) )
          reparamBSpline (aBasisCurve, tmpF, tmpL);
      }
      gp_Vec dir (pt1, pt2);
      Handle(Geom_Surface) aResultSurf = 
        new Geom_SurfaceOfLinearExtrusion(aBasisCurve, dir);
      if (!aResultSurf.IsNull()) {
        aResultSurf = 
          new Geom_RectangularTrimmedSurface(aResultSurf, 
                                             aBasisCurve->FirstParameter(),
                                             aBasisCurve->LastParameter(),
                                             0., dir.Magnitude() );
        BRepBuilderAPI_MakeFace aMakeF(aResultSurf, Precision::Confusion());
        if (aMakeF.IsDone()) res = aMakeF.Face();
      }
    }
  }
  catch (Standard_Failure) {
#ifdef DEB
    cout << "Warning: IgesToBRep_TopoSurface::TransferTabulatedCylinder(): exception by Geom: ";
    Standard_Failure::Caught()->Print ( cout ); cout << endl;
#endif
  }
  }
  
  if ( res.IsNull() ) {
    // do as usual.
    BRepPrimAPI_MakePrism prism(directrix, gp_Vec(pt1, pt2));
//mjm: si debug IsDone() est fait
//  if (!prism.IsDone()) {
//    AddFail(st, "Prism Construction Error.");
//    return res;
//  }
    res = prism.Shape();
  }
  //#16 rln 08/04/98 coq-inf-support.igs entity 2105
  //CAS.CADE can parametrize SurfaceOfLinearExtrusion with generatrix opposite to Vec(pt1, pt2)
  //and with parametrization V > 0, while in IGES TabulatedCylinder is parametrized with positive V
  //direction exactly in the direction Vec(pt1, pt2)
  if (res.ShapeType() == TopAbs_FACE) {
    Standard_Real UMin, UMax, VMin, VMax;
    BRepTools::UVBounds (TopoDS::Face (res), UMin, UMax, VMin, VMax);
    if (VMax <= Precision::PConfusion() && VMin < -Precision::PConfusion()) {
      TheULength *= -1;
      res.Reverse();
    }
    Handle(Geom_Surface) surf = BRep_Tool::Surface(TopoDS::Face(res));
    if(surf->Continuity()==GeomAbs_C0) {
      Message_Msg msg1250("IGES_1250");
      SendWarning (st, msg1250);
    }
  }
    
  if (st->HasTransf()) {
    gp_Trsf trsf;
    SetEpsilon(1.E-04);
    if (IGESData_ToolLocation::ConvertLocation
	(GetEpsilon(),st->CompoundLocation(), trsf, GetUnitFactor())) { 
      TopLoc_Location shapeLoc(trsf);
      res.Move(shapeLoc);
    }
    else {
      Message_Msg msg1035("IGES_1035");
      SendWarning(st,msg1035); // Transformation : not a similarity
    }
  }
  return res;
}


//=======================================================================
//function : TransferOffsetSurface
//purpose  : 
//=======================================================================

TopoDS_Shape IGESToBRep_TopoSurface::TransferOffsetSurface
  (const Handle(IGESGeom_OffsetSurface)& st)
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////////
  TopoDS_Shape    res;
  if (st.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
    return res;
  }

  TopoDS_Shape    igesShape;
  TopoDS_Face     face;
  TopLoc_Location basisLoc;

  Handle (IGESData_IGESEntity) igesSrf = st->Surface();
  if (igesSrf.IsNull() || !IGESToBRep::IsTopoSurface(igesSrf) ) {
    Message_Msg msg164("XSTEP_164");
    SendFail(st, msg164); 
    // Basis Surface Reading Error : Null IGESEntity
    // Basis Surface Transfer Error : Not Allowed IGESEntity 
    return res;
  }

  igesShape = TransferTopoSurface(igesSrf);
  if (igesShape.IsNull()) {
    Message_Msg msg1156("IGES_1156");
    const Standard_CString typeName("basis surface");
    Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
    msg1156.Arg(typeName);
    msg1156.Arg(label);
    SendFail(st, msg1156);  // Basis Surface Conversion Error.
    return res;
  }
  
  TopAbs_ShapeEnum shapeEnum = igesShape.ShapeType();
  switch (shapeEnum) {
  case TopAbs_FACE :
    {
      face = TopoDS::Face(igesShape);
      break;
    }
  case TopAbs_SHELL :
    {
      SendWarning(st, "The First Surface only will be transfered.");
      TopoDS_Iterator dabovil(igesShape);
      if (dabovil.More()) {
	face = TopoDS::Face(dabovil.Value());
	break;
      }
      /* else  AddF("... */
    }
  default:
    {
      Message_Msg msg1156("IGES_1156");
      const Standard_CString typeName("basis surface");
      Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
      msg1156.Arg(typeName);
      msg1156.Arg(label);
      SendFail(st, msg1156);  // Basis Surface Conversion Error.
      return res;
    }
  }
  
  
  //Handle(Geom_Surface) geomSupport = BRep_Tool::Surface(face, basisLoc);
  // attention on ne peut construire une Geom_OffsetSurface que
  // si la surface de base est au moins C1, sinon on plante !
  //#56 rln 25.12.98 UKI60878 entity D593 (Offset surface on C0 B-Spline)
  //Trying to eliminate previous limitation on processing only C1 surfaces
  Handle(Geom_Surface) geomSupport = BRep_Tool::Surface(face);
  Handle(Geom_OffsetSurface) basisSrf;
  
  if (geomSupport->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
    DeclareAndCast(Geom_OffsetSurface, geom140, geomSupport);
    geom140->SetOffsetValue(basisSrf->Offset() + 
 			    st->Distance()*GetUnitFactor());
    basisSrf = geom140;
  }
  else {
    if (geomSupport->Continuity() == GeomAbs_C0) {
      res = ShapeAlgo::AlgoContainer()->C0ShapeToC1Shape (face, Abs (st->Distance()) * GetUnitFactor());
      if(res.ShapeType()!=TopAbs_FACE) {
	Message_Msg msg1266("IGES_1266");
	SendFail(st, msg1266);//Basis surface is C0-continuous and cannot be corrected to C1-continuous.
	return res;
      }
      else {
	geomSupport = BRep_Tool::Surface (TopoDS::Face(res));
	if (geomSupport->Continuity() == GeomAbs_C0) {
	  Message_Msg msg1266("IGES_1266");
	  SendFail(st, msg1266);//Basis surface is C0-continuous and cannot be corrected to C1-continuous.
	  res.Nullify();
	  return res;
	}
      }
      Message_Msg msg1267("IGES_1267");
      SendWarning(st, msg1267);//Basis surface is C0-continuous but was corrected to C1-continuous
    }
    //smh#12
    if (res.IsNull()) res = face;
    geomSupport = BRep_Tool::Surface (TopoDS::Face(res));
    Standard_Real umin, umax, vmin, vmax;
    geomSupport->Bounds (umin, umax, vmin, vmax);
    if (Precision::IsInfinite (umin) || Precision::IsInfinite (umax) ||
	Precision::IsInfinite (vmin) || Precision::IsInfinite (vmax)) {
      // convert to C1 B-Spline
      BRepTools::UVBounds (face, umin, umax, vmin, vmax);
      Handle(Geom_RectangularTrimmedSurface) TS = new Geom_RectangularTrimmedSurface (geomSupport, umin, umax, vmin, vmax);
      Handle (Geom_BSplineSurface) BS = ShapeAlgo::AlgoContainer()->ConvertSurfaceToBSpline(TS, umin, umax, vmin, vmax);
      if (BS.IsNull() || BS->Continuity() == GeomAbs_C0) {
	Message_Msg msg1265("IGES_1265");
	SendFail(st, msg1265); // OffsetSurface Construction Error.
	return res;
      }
      else {
	geomSupport = BS;
      }
    }
    basisSrf = new Geom_OffsetSurface(geomSupport, st->Distance()*GetUnitFactor());
  }
  
  BRepLib_MakeFace MF(basisSrf, Precision::Confusion());
  if(!MF.IsDone()) {
    Message_Msg msg1265("IGES_1265");
    SendFail(st, msg1265); // OffsetSurface Construction Error.
    return res;
  }

  res = MF.Face();
  
  if (st->HasTransf()) {
    gp_Trsf trsf;
    SetEpsilon(1.E-04);
    if (IGESData_ToolLocation::ConvertLocation
	(GetEpsilon(),st->CompoundLocation(),trsf, GetUnitFactor())) { 
      TopLoc_Location loc2(trsf);
      res.Move(loc2);
    }
    else {
      Message_Msg msg1035("IGES_1035");
      SendWarning(st,msg1035); // Transformation : not a similarity
    }
  }
  return res;
}


//=======================================================================
//function : TransferTrimmedSurface
//purpose  : 
//=======================================================================

TopoDS_Shape IGESToBRep_TopoSurface::TransferTrimmedSurface
       (const Handle(IGESGeom_TrimmedSurface)& st)
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////////
  TopoDS_Shape res;
  if (st.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
    return res;
  }
  
  TopAbs_ShapeEnum shapeEnum;
  IGESToBRep_TopoCurve TC(*this);

  Handle (IGESData_IGESEntity) igesSurface = st->Surface();
  if (igesSurface.IsNull() || !IGESToBRep::IsTopoSurface(igesSurface) ) {
    Message_Msg msg169("XSTEP_169");   
    SendFail(st, msg169);
    // BasicSurface Transfer Error : Null IGESEntity
    // Basis Surface, not Allowed IGESEntity.
    return res;
  }
  gp_Trsf2d trans;
  Standard_Real uFact;
  TopoDS_Face  face, faceres;
  
  TopoDS_Shape myshape = ParamSurface(igesSurface, trans, uFact);

  if (!myshape.IsNull()) {
    shapeEnum = myshape.ShapeType();
    switch (shapeEnum) {
    case TopAbs_FACE :
      {
	face = TopoDS::Face(myshape);
	faceres = face;
	break;
      }
    case TopAbs_SHELL :
      {
	TopoDS_Iterator IT(myshape);
	Standard_Integer nbfaces = 0;
	for (; IT.More(); IT.Next()) {
	  nbfaces++;
	  face = TopoDS::Face(IT.Value());
	  faceres = face;
	}
	//szv#4:S4163:12Mar99 optimized
	if (nbfaces != 1) {
	  Message_Msg msg1156("IGES_1156");
	  const Standard_CString typeName("basis surface");
          Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSurface);
	  msg1156.Arg(typeName);
	  msg1156.Arg(label);
	  SendFail(st, msg1156);  // Not Implemented Trimmed Composite Surface.
	  return myshape;
	}
      }
      break;
    default:
      {
	Message_Msg msg1156("IGES_1156");
	const Standard_CString typeName("basis surface");
	Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSurface);
	msg1156.Arg(typeName);
	msg1156.Arg(label);
	SendFail(st, msg1156);  // Basis Surface Conversion Error.
	return res;
      }
    }
  }
  else {
    return res;
  }
  
  //obtaining a surface
  TopLoc_Location L;
  Handle(Geom_Surface) aSurf = BRep_Tool::Surface(face, L);
  TC.SetSurface(aSurf);
  
  if (st->HasOuterContour()) {
    face.EmptyCopy();
    TopoDS_Shape myshape1 = TC.TransferCurveOnFace (face, st->OuterContour(), trans, uFact, Standard_False);
    // si ca se passe mal , on recupere au moins la face avec NaturalRestriction
    if (myshape1 .IsNull()) face = faceres;
  }
  for (Standard_Integer i = 1; i <= st->NbInnerContours(); i++) {
    TopoDS_Shape myshape2 = TC.TransferCurveOnFace (face, st->InnerContour(i), trans, uFact, Standard_False);
  }
  BRepTools::Update ( face ); //:p4
  //%16 pdn 08.04.99
  return face;
}


//=======================================================================
//function : TransferBoundedSurface
//purpose  : 
//=======================================================================

TopoDS_Shape  IGESToBRep_TopoSurface::TransferBoundedSurface
  (const Handle(IGESGeom_BoundedSurface)&  st)
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////////
  TopoDS_Shape res;
  if (st.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
    return res;
  }

  if (st->RepresentationType()==0) {
    Message_Msg msg1275("IGES_1275");
    SendWarning(st, msg1275);
    // Model Space Representation Not Implemented : the result will be the basis surface
  }
  
  TopAbs_ShapeEnum shapeEnum;
  IGESToBRep_TopoCurve TC(*this);
  Handle (IGESData_IGESEntity) igesSrf = st->Surface();
  if (igesSrf.IsNull() || !IGESToBRep::IsTopoSurface(igesSrf) ) {
    Message_Msg msg166("XSTEP_166");
    SendFail( st, msg166);
    // Basis Surface Transfer Error : Null IGESEntity.
    // Basis Surface Transfer Error : Not Allowed IGESEntity.
    return res;
  }
  gp_Trsf2d trans;
  Standard_Real uFact;
  TopoDS_Face  face;

  TopoDS_Shape myshape = ParamSurface(igesSrf, trans, uFact);

  if (myshape.IsNull()) {
    //#55 rln 24.12.98 UKI60878 entity D593
#ifdef DEB
    cout << "Fail: IGESToBRep_TopoSurface::TransferBoundedSurface  UntrimmedSurface is translated into Null" << endl;
#endif
    return res;
  }
  else {
    shapeEnum = myshape.ShapeType();
    switch (shapeEnum) {
    case TopAbs_FACE :
      {
	face = TopoDS::Face(myshape);
      }
      break;
    case TopAbs_SHELL :
      {
	TopoDS_Iterator IT(myshape);
	Standard_Integer nbfaces = 0;
	for (; IT.More(); IT.Next()) {
	  nbfaces++;
	  face = TopoDS::Face(IT.Value());
	}
	//szv#4:S4163:12Mar99 optimized
	if (nbfaces != 1) {
	  Message_Msg msg1156("IGES_1156");
	  const Standard_CString typeName("basis surface");
	  Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
	  msg1156.Arg(typeName);
	  msg1156.Arg(label);
	  SendFail(st, msg1156);
	  // Not Implemented Trimmed Composite Surface.
	  return myshape;
	}
      }
      break;
    default:
      { 
	Message_Msg msg1156("IGES_1156");
	const Standard_CString typeName("basis surface");
	Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(igesSrf);
	msg1156.Arg(typeName);
	msg1156.Arg(label);
	SendFail(st, msg1156);
	return res;
      }
    }
  }
  
  face.EmptyCopy();
  for (Standard_Integer i = 1; i <= st->NbBoundaries(); i++) 
    TC.TransferBoundaryOnFace(face, st->Boundary(i), trans, uFact);
  
  BRepTools::Update ( face ); //:p4
  //#22 rln 01.06.98 UK3.igs entity 1279
//  ShapeFix_Face sff ( face );
//  sff.FixMissingSeam(); //:l1 abv 10 Jan 99: USA60022 7289: fix missing seam
//  if(sff.FixSmallAreaWire()) { //%14 pdn 24.02,99: USA60293: fix small area wires.
//    AddFail(st, "Small area wire detected, dropped"); 
//  }
//  sff.FixOrientation();
//  face = sff.Face();
  //%16 pdn 08.04.99
  return face;
}


//=======================================================================
//function : TransferPlane
//purpose  : 
//=======================================================================

TopoDS_Shape IGESToBRep_TopoSurface::TransferPlane
  (const Handle(IGESGeom_Plane)& st)
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////////
  TopoDS_Shape     res;
  if (st.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
    return res;
  }

  gp_Pln  pln;
  gp_Trsf trsf;
  res = TransferPlaneParts (st, pln,trsf,Standard_True);
//   res contient (en principe ...) une Face avec eventuellement un Wire
//   il reste a la mettre en position
  if (trsf.Form() != gp_Identity) {
    TopLoc_Location loc(trsf);
    res.Location(loc);
  }
  return res;
}


//=======================================================================
//function : TransferPlaneSurface
//purpose  : this function transferred into IGESToBRep_BasicSurface
//=======================================================================


//=======================================================================
//function : TransferPerforate
//purpose  : 
//=======================================================================

TopoDS_Shape  IGESToBRep_TopoSurface::TransferPerforate
  (const Handle(IGESBasic_SingleParent)& st)
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////////
  TopoDS_Shape     res;
  if (st.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
    return res;
  }

  //char mess[100];
  gp_Pln  pln;
  gp_Trsf trsf;
  DeclareAndCast(IGESGeom_Plane,p0,st->SingleParent());
  BRep_Builder B;
  if (p0.IsNull()) {
    Message_Msg msg206("XSTEP_206");   
    SendFail(st, msg206);
    // SingleParent does not describe a holed face
    return res;
  }
  res = TransferPlaneParts (p0,pln,trsf,Standard_True);
//res demarre avec la face et son contour externe
  Standard_Integer nb = st->NbChildren();
  for (Standard_Integer i = 1; i <= nb; i ++) {
    DeclareAndCast(IGESGeom_Plane,pi,st->Child(i));
    if (pi.IsNull()) {
      Message_Msg msg1285("IGES_1285");
      msg1285.Arg(i);
      // A child is not a Plane, skipped, n0 %d
      SendWarning(st,msg1285);
      continue;
    }
    gp_Pln  pli;
    gp_Trsf trsi;
    TopoDS_Shape wire = TransferPlaneParts (pi,pli,trsi,Standard_False);
//    si ce n est pas un Wire, sauter
    if (wire.ShapeType() != TopAbs_WIRE) {
      Message_Msg msg1156("IGES_1156");
      const Standard_CString typeName("hole");
      Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(pi);
      msg1156.Arg(typeName);
      msg1156.Arg(label);
      SendWarning(st, msg1156);
      // A hole could not be transferred, skipped, n0 %d
      continue;
    }
//    coplanaires ? verifier
    if (!pln.Position().IsCoplanar(pli.Position(),GetEpsGeom(),GetEpsilon())) {
      Message_Msg msg1295("IGES_1295");
      msg1295.Arg(i);
      SendWarning(st,msg1295);
      // "A hole is not well coplanar to the face, n0 %d",i);
    }
//    Ne pas oublier de composer la transformation locale a ce Wire
    if (trsi.Form() != gp_Identity) {
      TopLoc_Location locw(trsi);
      wire.Location(locw);
    }
    B.Add (res,wire);
  }
//    Enfin, appliquer la trsf globale
  if (trsf.Form() != gp_Identity) {
    TopLoc_Location loc(trsf);
    res.Location(loc);
  }
  return res;
}


//=======================================================================
//function : TransferPlaneParts
//purpose  : 
//=======================================================================
TopoDS_Shape IGESToBRep_TopoSurface::TransferPlaneParts(const Handle(IGESGeom_Plane)& st,
                                                        gp_Pln&  pln,  
                                                        gp_Trsf&  trsf,
                                                        const Standard_Boolean first)
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////////
  TopoDS_Shape res;
  if (st.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
    return res;
  }

  Standard_Real a, b, c, d;
  // equation de Geom : ax + by + cz + d = 0.0;
  // equation de IGES : ax + by + cz = d;
  st->Equation(a, b, c, d);
  pln = gp_Pln(a, b, c, -d);
  
  TopoDS_Face plane;
  TopoDS_Wire wire;
  BRep_Builder B;
  if (first) {
    B.MakeFace(plane);         // Just to create a empty Plane with a Tshape.
    Handle (Geom_Plane) geomPln = new Geom_Plane(pln);
    geomPln->Scale(gp_Pnt(0,0,0),GetUnitFactor());
//   ATTENTION, ici on CALCULE la trsf, on ne l`applique pas ...
    //S4054: B.UpdateFace (plane, geomPln, TopLoc_Location(), 
			   //GetEpsGeom()*GetUnitFactor());
    B.UpdateFace (plane, geomPln, TopLoc_Location(), Precision::Confusion());
    //:3 by ABV 5 Nov 97: set Infinite() flag (see below for unsetting)
    plane.Infinite ( Standard_True );  //:3
  }

//   ATTENTION, ici on CALCULE la trsf, on ne l'appliquera qu'a la fin !
  if (st->HasTransf()) {
    SetEpsilon(1.E-04);
    if (!IGESData_ToolLocation::ConvertLocation
	(GetEpsilon(), st->CompoundLocation(),trsf,GetUnitFactor())) { 
      Message_Msg msg1035("IGES_1035");
      SendWarning(st,msg1035); // Transformation : not a similarity
    }
  }

  if (st->HasBoundingCurve()) {
    IGESToBRep_TopoCurve TC(*this);
    Handle(IGESData_IGESEntity) crv = st->BoundingCurve();

    if (crv.IsNull()) {
      Message_Msg msg1300("IGES_1300");
      SendWarning(st,msg1300);
      //:4 by ABV 5 Nov 97: plane cannot be trimmed - let it be infinite
      //:4 NOTE: NB "else"
      //:4      return res;
    }
    else //:4
      
      if (IGESToBRep::IsTopoCurve(crv)) {
	gp_Trsf trans;
	if (crv->IsKind(STANDARD_TYPE(IGESGeom_CurveOnSurface))) {
	  DeclareAndCast(IGESGeom_CurveOnSurface, crv142, crv);
	  if(st->HasBoundingCurveHole()) {    
	    TopoDS_Shape myshape = TC.TransferCurveOnFace (plane, crv142, trans, TheULength, Standard_False);
	  }
	  else {
	    TopoDS_Shape myshape = TC.TransferCurveOnFace (plane, crv142, trans, TheULength, Standard_False);
	  }
	  //:3 by ABV 5 Nov 97: set plane to be finite
	  if ( first ) {
	    TopExp_Explorer ws ( plane, TopAbs_WIRE ); 
	    if ( ws.More() ) plane.Infinite ( Standard_False ); 
	  }
	}
	else {
	  TopoDS_Shape     shape = TC.TransferTopoCurve(crv);
	  TopAbs_ShapeEnum shapeEnum = shape.ShapeType();
	  switch (shapeEnum) {
	  case TopAbs_EDGE :
	    {
	      TopoDS_Edge edge = TopoDS::Edge(shape);
	      Handle(ShapeExtend_WireData) sewd = new ShapeExtend_WireData;
	      sewd->Add(edge);
	      wire = sewd->Wire();
	    }
	    break;
	  case TopAbs_WIRE :
	    {
	      wire = TopoDS::Wire(shape);	    
	    }
	  break;
	  default:
	    { 
	      Message_Msg msg1156("IGES_1156");
	      const Standard_CString typeName("Bounding curve");
	      Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(crv);
	      msg1156.Arg(typeName);
	      msg1156.Arg(label);
	      SendWarning(st, msg1156);
	      if (first) res = plane;
	      else       res = wire;
	      return res;
	    }
	  }
	  //S4054 CTS18953 entity 14
	  Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
	  sfw->Load (wire);
	  sfw->FixConnected (GetMaxTol());
	  wire = sfw->Wire();
	  BRepLib_MakeFace MF(pln, wire, Standard_False);
	  if (!MF.IsDone()) {
	    // AddFail(st, "Plane Construction Error.");
	    return res;
	  }
	  
	  TopoDS_Face F = MF.Face();
	  GProp_GProps G;
	  BRepGProp::SurfaceProperties(F,G);
	  if (G.Mass() < 0) {
	    if(!st->HasBoundingCurveHole())    
	      wire.Reverse();
	  }
	  else
	    if( st->HasBoundingCurveHole())
	      wire.Reverse();
	  //:3 by ABV 5 Nov 97: set plane to be finite
	  //:3        if (first) B.Add (plane,wire);
	  if ( first ) { 
	    B.Add ( plane, wire ); 
	    plane.Infinite ( Standard_False ); 
	  } 
	  //BRepLib_MakeFace MP(pln, wire);
	  //plane = MP.Face();
	}
      }
      else {
	Message_Msg msg1156("IGES_1156");
	const Standard_CString typeName("Bounding curve");
	Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(crv);
	msg1156.Arg(typeName);
	msg1156.Arg(label);
	SendWarning(st, msg1156);
	// Plane Cannot Be Trimmed.
      }
  }
  
  if (first) res = plane;
  else       res = wire;
  return res;
}


//=======================================================================
//function : ParamSurface
//purpose  : 
//=======================================================================
TopoDS_Shape IGESToBRep_TopoSurface::ParamSurface(const Handle(IGESData_IGESEntity)& st,
						  gp_Trsf2d& trans,
						  Standard_Real& uFact) 
{ // Declaration of messages// 
  // DCE 22/12/98
  //Message_Msg msg1005("IGES_1005");
  ////////////////////////////////

  TopoDS_Shape res;

  TopoDS_Shape basisSurface = TransferTopoSurface(st);
  Standard_Real uscale = 1.;
  Standard_Real cscale = TheULength;
  if (basisSurface.IsNull()) {
    Message_Msg msg1005("IGES_1005");
    SendFail(st, msg1005);
    return res;
  }

  TopAbs_ShapeEnum shapeEnum;
  shapeEnum = basisSurface.ShapeType();
  TopoDS_Face  face;
  switch (shapeEnum) {
  case TopAbs_FACE :
    {
      face = TopoDS::Face(basisSurface);
      break;
    }
  case TopAbs_SHELL :
    {
      TopoDS_Iterator IT(basisSurface);
      Standard_Integer nbfaces = 0;
      for (; IT.More(); IT.Next()) {
	nbfaces++;
	face = TopoDS::Face(IT.Value());
      }
      //szv#4:S4163:12Mar99 optimized
      if (nbfaces != 1) {
	 Message_Msg msg1156("IGES_1156");
	 const Standard_CString typeName("basis surface");
	 Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(st);
	 msg1156.Arg(typeName);
	 msg1156.Arg(label);
	 SendWarning(st, msg1156);
	 return basisSurface;
      }
    }
    break;
  default:
    {
      //AddFail(st, "Basis Surface Transfer Error.");
      return res;
    }
  }
  
  //S4181 pdn 19.04.99 defining shift of parametric space on base 
  // of CAS.CADE type of surface  
  Standard_Real paramu = 0., paramv = 0.;
  TopLoc_Location L;
  TopoDS_Edge theedge;
  Handle(Geom_Surface) Surf = BRep_Tool::Surface(face);

  if (Surf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { 
    DeclareAndCast(Geom_RectangularTrimmedSurface, rectang, Surf);
    Surf = rectang->BasisSurface();
  }

  if ((Surf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) ||
      (Surf->IsKind(STANDARD_TYPE(Geom_ConicalSurface)))     ||
      (Surf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)))    ||
      (Surf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)))) {
    TopExp_Explorer TE;
    for ( TE.Init(face,TopAbs_EDGE); TE.More(); TE.Next()){
      TopoDS_Edge myedge = TopoDS::Edge(TE.Current());
      Standard_Real First, Last;
      Handle(Geom2d_Curve) Curve2d = BRep_Tool::CurveOnSurface
	(myedge, face, First, Last);
      if ( Curve2d->IsKind(STANDARD_TYPE(Geom2d_Line))) {
	DeclareAndCast(Geom2d_Line, Line2d, Curve2d);	
	if (Line2d->Direction().IsParallel(gp::DY2d(),Precision::Angular())){
	  theedge = myedge;
	  break;
	}
      }
    }

    Standard_Real First, Last;
    Handle(Geom_Curve) Curve3d = BRep_Tool::Curve(theedge, First, Last); 
    if (Precision::IsNegativeInfinite(First)) First = 0.;  
    
    if (Surf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))){
      DeclareAndCast(Geom_CylindricalSurface, Cyl, Surf);
      gp_Cylinder TheCyl = Cyl->Cylinder();
      ElSLib::CylinderParameters(TheCyl.Position(), 
				 TheCyl.Radius(), 
				 Curve3d->Value(First), paramu , paramv );
    }

    else if (Surf->IsKind(STANDARD_TYPE(Geom_ConicalSurface))){
      DeclareAndCast(Geom_ConicalSurface, Cone, Surf);
      gp_Cone TheCone = Cone->Cone();
      ElSLib::ConeParameters(TheCone.Position(), 
			     TheCone.RefRadius(), 
			     TheCone.SemiAngle(), 
			     Curve3d->Value(First), paramu , paramv );
    }

    else if (Surf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))){
      DeclareAndCast(Geom_ToroidalSurface, Tore, Surf);
      gp_Torus TheTore = Tore->Torus();
      ElSLib::TorusParameters(TheTore.Position(), 
			      TheTore.MajorRadius(), 
			      TheTore.MinorRadius(), 
			      Curve3d->Value(First), paramu , paramv );
    }
    else if (Surf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) &&
             //: abv 18.06.02: loopback on s1.brep BRep mode, face 32 - the spherical surface (192)
             //: in IGES is from [-90,90] by V, i.e. similar to OCC, thus only scaling is enough
             ! st->IsKind (STANDARD_TYPE(IGESSolid_SphericalSurface)) ) {
      DeclareAndCast(Geom_SphericalSurface, Sphere, Surf);
      gp_Sphere TheSphere = Sphere->Sphere();
      ElSLib::SphereParameters(TheSphere.Position(), 
 			       TheSphere.Radius(), 
 			       Curve3d->Value(First), paramu , paramv );
    }
        
    //#88 rln 06.04.99 CTS60168, BLEND.IGS entity 68
    //Generatrix is Transformed Circular Arc. When creating CAS.CADE surface parameterization
    //has changed.
    if (st->IsKind (STANDARD_TYPE (IGESGeom_SurfaceOfRevolution))) {
      DeclareAndCast (IGESGeom_SurfaceOfRevolution, revol, st);
      Handle(IGESData_IGESEntity) generatrix = revol->Generatrix();
      if (generatrix->IsKind (STANDARD_TYPE (IGESGeom_CircularArc))) {
	DeclareAndCast (IGESGeom_CircularArc, circ, generatrix);
	gp_Pnt2d startpoint = circ->StartPoint();
	paramv -= ElCLib::Parameter (gp_Circ2d (gp_Ax2d (circ->Center(), gp_Dir2d(1,0)), circ->Radius()), startpoint);
	if (Surf->IsKind (STANDARD_TYPE(Geom_SphericalSurface)))
	  paramv += ShapeAnalysis::AdjustToPeriod(paramv, - PI, PI);
	else if (Surf->IsKind (STANDARD_TYPE(Geom_ToroidalSurface)))
	  paramv += ShapeAnalysis::AdjustToPeriod(paramv, 0, PI * 2);
      }
    }
    else if (st->IsKind (STANDARD_TYPE (IGESGeom_TabulatedCylinder))) {
      DeclareAndCast (IGESGeom_TabulatedCylinder, cylinder, st);
      Handle(IGESData_IGESEntity) directrix = cylinder->Directrix();
      if (directrix->IsKind (STANDARD_TYPE (IGESGeom_CircularArc))) {
	DeclareAndCast (IGESGeom_CircularArc, circ, directrix);
	gp_Pnt2d startpoint = circ->StartPoint();
	paramu -= ElCLib::Parameter (gp_Circ2d (gp_Ax2d (circ->Center(), gp_Dir2d(1,0)), circ->Radius()), startpoint);
	paramu += ShapeAnalysis::AdjustToPeriod(paramu, 0, PI * 2);
      }
    }

  }

  if ( Abs(paramu) <= Precision::Confusion()) paramu = 0.;
  if ( Abs(paramv) <= Precision::Confusion()) paramv = 0.;
  
  //S4181 pdn 16.04.99 computation of transformation depending on 
  //IGES Type of surface
  Handle(IGESData_IGESEntity) isrf = st;
  if (isrf->IsKind(STANDARD_TYPE(IGESGeom_OffsetSurface))){
    DeclareAndCast(IGESGeom_OffsetSurface, offsurf, isrf);
    isrf = offsurf->Surface();
  }
  if (isrf->IsKind(STANDARD_TYPE(IGESGeom_SurfaceOfRevolution))) {
    DeclareAndCast(IGESGeom_SurfaceOfRevolution, st120, isrf);
    //S4181 pdn 19.04.99 defining transformation matrix
    gp_Trsf2d tmp;
    tmp.SetTranslation(gp_Vec2d (0, -2 * PI));
    trans.PreMultiply(tmp);
    tmp.SetMirror(gp::OX2d());
    trans.PreMultiply(tmp);
    tmp.SetMirror(gp_Ax2d (gp::Origin2d(), gp_Dir2d (1.,1.)));
    trans.PreMultiply(tmp);
    uscale = 1./cscale;
    //#30 rln 19.10.98
    //CAS.CADE SA = 2*PI - IGES TA
    //paramu = st120->StartAngle();
    paramu = -(2 * PI - st120->EndAngle());
  }
  else
    paramu = 0.;
  
  if (isrf->IsKind(STANDARD_TYPE(IGESGeom_RuledSurface))) {
    uscale = 1./cscale;
  }
  
  // corrected skl 13.11.2001 for BUC61054
  if (isrf->IsKind(STANDARD_TYPE(IGESGeom_TabulatedCylinder))) {
    Handle(IGESGeom_TabulatedCylinder) igtc = Handle(IGESGeom_TabulatedCylinder)::DownCast(isrf);
    Handle(IGESData_IGESEntity) idie = igtc->Directrix();
    Standard_Real uln=1;
    if(idie->TypeNumber()==110) {
      Handle(IGESGeom_Line) igl = Handle(IGESGeom_Line)::DownCast(idie);
      gp_Pnt SP = igl->StartPoint();
      gp_Pnt EP = igl->EndPoint();
      // PTV OCC659 
      // PTV file D44-11325-6.igs. Faces with parametric curves need * GetUnitFactor();
      uln=SP.Distance(EP) * GetUnitFactor();
    }
    uscale = uln/cscale;
  }
  
  if (isrf->IsKind(STANDARD_TYPE(IGESSolid_CylindricalSurface))||
      isrf->IsKind(STANDARD_TYPE(IGESSolid_ConicalSurface))) {
    uscale = PI/180.;
  }
  
  if (isrf->IsKind(STANDARD_TYPE(IGESSolid_SphericalSurface))) {
    cscale = PI/180.;
    uscale = 1.;
  }
      
  if (isrf->IsKind(STANDARD_TYPE(IGESSolid_ToroidalSurface))) {
    gp_Trsf2d tmp;
    tmp.SetTranslation(gp_Vec2d (0, -360.)); // in IGES terms
    trans.PreMultiply(tmp);
    tmp.SetMirror(gp::OX2d());
    trans.PreMultiply(tmp);
    tmp.SetMirror(gp_Ax2d (gp::Origin2d(), gp_Dir2d (1.,1.)));
    trans.PreMultiply(tmp);
    if(paramv > 0)
      paramv = paramv*180./PI;
    cscale = PI/180.;
    uscale = 1.;
  } 
    
  gp_Trsf2d tmp;
  tmp.SetTranslation(gp_Pnt2d(0.,0.), gp_Pnt2d(paramu,paramv));
  trans.PreMultiply(tmp);
  
  tmp.SetScale(gp_Pnt2d(0,0),cscale);
  trans.PreMultiply(tmp);
  uFact = uscale;
  return face;
}