0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / IGESToBRep / IGESToBRep_BasicCurve.cxx
1 //=======================================================================
2 //file    : IGESToBRep_BasicCurve
3 //modified: 
4 // 21.02.2002 skl
5 // 21.12.98 rln, gka S4054
6 //:k5 abv 25 Dec 98: PRO8803 1901: extending method of fixing Multi > Degree
7 // 28.12.98 dce S3767 New messaging system
8 //#61 rln 05.01.99
9 //#60 rln 29.12.98 PRO17015
10 //:l3 abv 11.01.99: CATIA01.igs: using less values for checking short lines
11 //%11 pdn 12.01.98 CTS22023 correcting used tolerances
12 //sln 29.12.2001 OCC90 : Method checkBSplineCurve and varification before creation of bspline curves were added
13 //=======================================================================
14
15
16 #include <IGESToBRep_BasicCurve.ixx>
17
18 #include <IGESToBRep.hxx>
19 #include <IGESToBRep_CurveAndSurface.hxx>
20   
21 #include <ElCLib.hxx>
22   
23 #include <Geom_BSplineCurve.hxx>
24 #include <Geom_Circle.hxx>
25 #include <Geom_Ellipse.hxx>
26 #include <Geom_Line.hxx>
27 #include <Geom_Hyperbola.hxx>
28 #include <Geom_Parabola.hxx>
29 #include <Geom_Transformation.hxx>
30 #include <Geom_TrimmedCurve.hxx>
31
32 #include <Geom2d_BSplineCurve.hxx>
33 #include <Geom2d_Circle.hxx>
34 #include <Geom2d_Ellipse.hxx>
35 #include <Geom2d_Hyperbola.hxx>
36 #include <Geom2d_Line.hxx>
37 #include <Geom2d_Parabola.hxx>
38 #include <Geom2d_TrimmedCurve.hxx>
39   
40 #include <gp_Ax2.hxx>
41 #include <gp_Ax2d.hxx>
42 #include <gp_Dir.hxx>
43 #include <gp_Dir2d.hxx>
44 #include <gp_GTrsf.hxx>
45 #include <gp_Pnt.hxx>
46 #include <gp_Pnt2d.hxx>
47 #include <gp_Trsf.hxx>
48 #include <gp_XY.hxx>
49 #include <gp_XYZ.hxx>
50
51   
52 #include <IGESData_IGESEntity.hxx>
53 #include <IGESData_ToolLocation.hxx>
54   
55 #include <IGESGeom_BSplineCurve.hxx>
56 #include <IGESGeom_CircularArc.hxx>
57 #include <IGESGeom_ConicArc.hxx>
58 #include <IGESGeom_Point.hxx>
59 #include <IGESGeom_SplineCurve.hxx>
60 #include <IGESGeom_TransformationMatrix.hxx>
61
62 #include <IGESConvGeom.hxx>
63
64 #include <Interface_Macros.hxx>
65
66 #include <Precision.hxx>  
67
68 #include <TColgp_Array1OfPnt2d.hxx>
69 #include <TColgp_HArray1OfPnt.hxx>
70 #include <TColgp_HArray2OfPnt.hxx>
71 #include <TColgp_HArray1OfPnt2d.hxx>
72
73 #include <TColGeom_SequenceOfCurve.hxx>
74   
75 #include <TColStd_Array1OfInteger.hxx>
76 #include <TColStd_Array1OfReal.hxx>
77 #include <TColStd_HArray1OfInteger.hxx>
78 #include <TColStd_HArray1OfReal.hxx>
79 #include <TColStd_SequenceOfInteger.hxx>
80
81 //:36
82 #include <Standard_ErrorHandler.hxx>
83 #include <Standard_Failure.hxx>
84 // S3767
85 #include <Message_Msg.hxx>  
86 #include <ShapeConstruct_Curve.hxx>
87 #include <gp_Hypr.hxx>
88
89 //=======================================================================
90 //function : CheckBSplineCurve
91 //purpose  : Check coincidede knots Check whether knots are in ascending 
92 //           order and difference between vaues of weights more than 1000. 
93 //           Send corresponding messages. The function returns Standard_False 
94 //           if curve can not be created, Standard_True otherwise.
95 //=======================================================================
96 static Standard_Boolean checkBSplineCurve(IGESToBRep_BasicCurve*               theCurve,
97                                           const Handle(IGESGeom_BSplineCurve)& theBSplineCurve,
98                                           TColStd_Array1OfReal&                CKnots,
99                                           const TColStd_Array1OfReal&          CWeights)
100 {
101   // check whether difference between vaues of weights more than 1000.
102   if(!theBSplineCurve->IsPolynomial()) {
103     Standard_Real aMinValue = CWeights.Value(CWeights.Lower());
104     Standard_Real aMaxValue = CWeights.Value(CWeights.Lower());
105     for(Standard_Integer i = CWeights.Lower()+1; i<= CWeights.Upper(); i++) {
106       if(CWeights.Value(i) < aMinValue) aMinValue = CWeights.Value(i);
107       if(CWeights.Value(i) > aMaxValue) aMaxValue = CWeights.Value(i);    
108     }
109     if(aMaxValue - aMinValue > 1000) {
110       Message_Msg msg1374("IGES_1374"); // WARNING - Difference between weights is too big.
111       theCurve->SendWarning(theBSplineCurve, msg1374);
112     }
113   }
114  
115   Standard_Boolean aResult = Standard_True;
116   
117   //check whether knots are in ascending order.
118   for (Standard_Integer i = CKnots.Lower(); i < CKnots.Upper(); i++) 
119     if(CKnots.Value (i+1) < CKnots.Value (i)) { 
120       Message_Msg msg1373("IGES_1373"); // FAIL - Knots are not in ascending order 
121       theCurve->SendFail(theBSplineCurve, msg1373);
122       aResult = Standard_False;
123     }
124   //Fix coincided knots
125   if(aResult) ShapeConstruct_Curve::FixKnots(CKnots);
126   
127   return aResult;
128
129 }
130
131
132
133 //=======================================================================
134 //function : IGESToBRep_BasicCurve
135 //purpose  : 
136 //=======================================================================
137 IGESToBRep_BasicCurve::IGESToBRep_BasicCurve()
138      :IGESToBRep_CurveAndSurface()
139 {  
140   SetModeTransfer(Standard_False);
141 }
142
143
144 //=======================================================================
145 //function : IGESToBRep_BasicCurve
146 //purpose  : 
147 //=======================================================================
148 IGESToBRep_BasicCurve::IGESToBRep_BasicCurve
149   (const IGESToBRep_CurveAndSurface& CS)
150      :IGESToBRep_CurveAndSurface(CS)
151 {  
152 }
153
154
155 //=======================================================================
156 //function : IGESToBRep_BasicCurve
157 //purpose  : 
158 //=======================================================================
159 IGESToBRep_BasicCurve::IGESToBRep_BasicCurve
160   (const Standard_Real    eps,
161    const Standard_Real    epsCoeff,
162    const Standard_Real    epsGeom,
163    const Standard_Boolean mode,
164    const Standard_Boolean modeapprox,
165    const Standard_Boolean optimized)
166      :IGESToBRep_CurveAndSurface(eps, epsCoeff, epsGeom, mode, 
167                                  modeapprox,optimized)
168 {  
169 }
170
171
172 //=======================================================================
173 //function : TransferBasicCurve
174 //purpose  : 
175 //=======================================================================
176
177 Handle(Geom_Curve) IGESToBRep_BasicCurve::TransferBasicCurve
178        (const Handle(IGESData_IGESEntity)& start)
179
180   Handle(Geom_Curve) res;
181   if (start.IsNull()) {
182     Message_Msg msg1005("IGES_1005");
183     SendFail(start, msg1005);
184     return res;
185   }
186   try { //:36 by abv 11.12.97: Geom_BSplineCurve fails if somw weights are <=0
187     OCC_CATCH_SIGNALS
188     //S4054
189     if (start->IsKind(STANDARD_TYPE(IGESGeom_BSplineCurve))) {
190       DeclareAndCast(IGESGeom_BSplineCurve, st126, start);
191       res = TransferBSplineCurve(st126);
192     }
193     else if (start->IsKind(STANDARD_TYPE(IGESGeom_Line))) {
194       DeclareAndCast(IGESGeom_Line, st110, start);
195       res = TransferLine(st110);
196     }
197     else if (start->IsKind(STANDARD_TYPE(IGESGeom_CircularArc))) {
198       DeclareAndCast(IGESGeom_CircularArc, st100, start);
199       res = TransferCircularArc(st100);
200     }
201     else if (start->IsKind(STANDARD_TYPE(IGESGeom_ConicArc))) {
202       DeclareAndCast(IGESGeom_ConicArc, st104, start);
203       res = TransferConicArc(st104);
204     }
205     else if (start->IsKind(STANDARD_TYPE(IGESGeom_CopiousData))) {
206       DeclareAndCast(IGESGeom_CopiousData, st106, start);
207       res = TransferCopiousData(st106);
208     }
209     else if (start->IsKind(STANDARD_TYPE(IGESGeom_SplineCurve))) {
210       DeclareAndCast(IGESGeom_SplineCurve, st112, start);
211       res = TransferSplineCurve(st112);
212     }
213     else {
214       // AddFail(start, "The IGESEntity is not a basic curve.");
215       // This case can not occur
216       return res;
217     }
218
219   } //:36
220   catch(Standard_Failure) {
221 #ifdef DEB
222     cout << "\n** Exception in IGESToBRep_BasicCurve::TransferBasicCurve : "; 
223     Standard_Failure::Caught()->Print(cout);
224 #endif
225   }
226   if (res.IsNull()) {
227     // AddFail(start, "The IGESEntity cannot be transfered.");
228     // The more specific function have ever add a fail message for this entity
229   }
230   else
231     res->Scale(gp_Pnt(0,0,0),GetUnitFactor());
232   return res;
233 }
234
235 //=======================================================================
236 //function : Transfer2dBasicCurve
237 //purpose  : 
238 //=======================================================================
239
240 Handle(Geom2d_Curve) IGESToBRep_BasicCurve::Transfer2dBasicCurve
241        (const Handle(IGESData_IGESEntity)& start)
242
243   Handle(Geom2d_Curve) res;
244   if (start.IsNull()) {
245     Message_Msg msg1005("IGES_1005");
246     SendFail(start, msg1005);
247     return res;
248   }
249   try { //:h8 abv 15 Jul 98: BUC60291 43693: Bspline Multiplicity > Degree+1 -> exception
250     OCC_CATCH_SIGNALS
251     
252     //S4054
253     if (start->IsKind(STANDARD_TYPE(IGESGeom_BSplineCurve))) {
254       DeclareAndCast(IGESGeom_BSplineCurve, st126, start);
255       res = Transfer2dBSplineCurve(st126);
256     }
257     else if (start->IsKind(STANDARD_TYPE(IGESGeom_Line))) {
258       DeclareAndCast(IGESGeom_Line, st110, start);
259       res = Transfer2dLine(st110);
260     }
261     else if (start->IsKind(STANDARD_TYPE(IGESGeom_CircularArc))) {
262       DeclareAndCast(IGESGeom_CircularArc, st100, start);
263       res = Transfer2dCircularArc(st100);
264     }
265     else if (start->IsKind(STANDARD_TYPE(IGESGeom_ConicArc))) {
266       DeclareAndCast(IGESGeom_ConicArc, st104, start);
267       res = Transfer2dConicArc(st104);
268     }
269     else if (start->IsKind(STANDARD_TYPE(IGESGeom_CopiousData))) {
270       DeclareAndCast(IGESGeom_CopiousData, st106, start);
271       res = Transfer2dCopiousData(st106);
272     }
273     else if (start->IsKind(STANDARD_TYPE(IGESGeom_SplineCurve))) {
274       DeclareAndCast(IGESGeom_SplineCurve, st112, start);
275       res = Transfer2dSplineCurve(st112);
276     }
277      else {
278       // AddFail(start, "The IGESEntity is not a basic curve.");
279       // This case can not occur
280       return res;
281     }
282   } //:h8
283   catch(Standard_Failure) {
284 #ifdef DEB
285     cout << "\n** Exception in IGESToBRep_BasicCurve::Transfer2dBasicCurve : "; 
286     Standard_Failure::Caught()->Print(cout);
287 #endif
288   }
289   return res;
290 }
291
292
293
294 //=======================================================================
295 //function : TransferConicArc
296 //purpose  : 
297 //=======================================================================
298 //
299 // A,B,C,D,E,F are the coefficients recorded in IGES. a,b,c,d,e,f are used to 
300 // simplify the equations of convertion. They are already used in Euclid. 
301
302 Handle(Geom_Curve) IGESToBRep_BasicCurve::TransferConicArc
303        (const Handle(IGESGeom_ConicArc)& st)
304
305   Handle(Geom_Curve) res;
306   if (st.IsNull()) {
307     Message_Msg msg1005("IGES_1005");
308     SendFail(st, msg1005);
309     return res;
310   }
311   // If the Conic is closed, the start and end points will be ignored.
312   if (!st->ComputedFormNumber()) {
313     Message_Msg msg1155("IGES_1155");
314     SendFail(st, msg1155);
315 //    AddFail(st, "Coefficients do not define correctly a conic.");
316     return res;
317   }
318   
319   // Conic = ax2+bxy+cy2+dx+ey+f=0 in the plane z=ZT.
320   Standard_Real a,b,c,d,e,f,ZT; 
321   st->Equation(a, b, c, d, e, f);
322
323   ZT = st->ZPlane();
324
325   gp_Pnt        center, startPoint, endPoint;
326   gp_Dir        mainAxis ,normAxis;
327   Standard_Real minorRadius, majorRadius;
328   
329   if (!GetModeTransfer() && st->HasTransf()) {
330
331     st->TransformedDefinition(center ,mainAxis, minorRadius, majorRadius);
332     normAxis = st->TransformedAxis();                            
333
334     startPoint = st->TransformedStartPoint();
335     endPoint   = st->TransformedEndPoint();
336   }
337   else {
338     st->Definition(center ,mainAxis, minorRadius, majorRadius);
339     normAxis = st->Axis();                            
340
341     startPoint.SetCoord(st->StartPoint().X(), st->StartPoint().Y(), ZT);
342     endPoint.SetCoord  (st->EndPoint().X()  , st->EndPoint().Y()  , ZT);
343   }
344   gp_Ax2 frame(center, normAxis, mainAxis);
345   Standard_Real t1 =0.0, t2 =0.0;
346   if (st->IsFromEllipse()) {
347
348     //#60 rln 29.12.98 PRO17015 reading back face#67: ellipse with big radii produces
349     //small coefficients
350     //The dimensions should be also obliged:
351     //[a]=[b]=[c]=L^-2
352     //if ( (Abs(a-c) <= GetEpsGeom()) && (Abs(b) < GetEpsCoeff()))
353     Standard_Real eps2 = Precision::PConfusion() * Precision::PConfusion();
354     if ( (Abs(a-c) <= eps2) && (Abs(b) < eps2)) {
355     
356 //                          =================
357 //                          ==  Circle 3D  ==
358 //                          =================
359
360       res = new Geom_Circle(frame, minorRadius);
361       
362       if (!st->IsClosed()) {
363
364         gp_Circ circ(frame, minorRadius);
365
366         t1 = ElCLib::Parameter(circ, startPoint);
367         t2 = ElCLib::Parameter(circ, endPoint);
368         if (t1 > t2 && (t1 - t2) > Precision::Confusion()) t2 += 2.*M_PI;
369         if (Abs(t1 - t2) <= Precision::Confusion())  { // t1 = t2
370           Message_Msg msg1160("IGES_1160");
371           SendWarning(st, msg1160);      
372         }
373         else
374           res = new Geom_TrimmedCurve(res, t1, t2);
375       }
376       return res;
377     }
378     else { 
379       // This is a no circular ellipse which will be computed with 
380       // the hyperbola at the end of this member.
381     }
382   }
383   else if (st->IsFromParabola()) {
384     
385     //                         ===================
386     //                         ==  Parabola 3D  ==
387     //                         ===================
388     
389     Standard_Real focal = minorRadius;
390     // PTV 26.03.2002
391     focal = focal/2.;
392     gp_Parab parab(frame, focal);
393     
394     res = new Geom_Parabola(frame, focal);
395     
396     t1 = ElCLib::Parameter(parab, startPoint);
397     t2 = ElCLib::Parameter(parab, endPoint);
398     if (Abs(t1 - t2) <= Precision::Confusion()) { // t1 = t2
399       Message_Msg msg1160("IGES_1160");
400       SendWarning(st, msg1160);      
401       //AddWarning(st, "The trim of the parabola is not correct.");
402     }
403     else 
404       // if t1 > t2, the course of the curve is going to be reversed.
405       res = new Geom_TrimmedCurve(res, t1, t2);
406     
407     return res;
408   }
409   
410   // Same computing for the ellipse and the hyperbola.
411   
412   //              =============================================
413   //              ==  Hyperbola or a no circular Ellipse 3D. ==
414   //              =============================================
415   
416   
417   if (st->IsFromEllipse()) {
418     res = new Geom_Ellipse(frame, majorRadius, minorRadius);
419     
420     if (!st->IsClosed()) {
421       gp_Elips  elips(frame, majorRadius, minorRadius);
422       
423       t1 = ElCLib::Parameter(elips, startPoint);
424       t2 = ElCLib::Parameter(elips, endPoint);
425       if (t2 < t1 && (t1 -t2) > Precision::Confusion()) t2 += 2.*M_PI;
426       if (Abs(t1 - t2) <= Precision::Confusion()) { // t1 = t2   
427         Message_Msg msg1160("IGES_1160");
428         SendWarning(st, msg1160);  
429         //AddWarning(st, "The trim of the ellipse is not correct, the result will be a ellipse.");
430       }
431       else
432         res = new Geom_TrimmedCurve(res, t1, t2);
433     }
434   }
435   else {
436       
437     gp_Hypr hpr(frame, majorRadius, minorRadius);
438     
439     t1 = ElCLib::Parameter(hpr, startPoint);
440     t2 = ElCLib::Parameter(hpr, endPoint);
441       
442     res = new Geom_Hyperbola(frame, majorRadius, minorRadius);
443     
444     //pdn taking PConfusion for parameters.
445     if (Abs(t1 - t2) <= Precision::PConfusion()) { // t1 = t2   
446         Message_Msg msg1160("IGES_1160");
447         SendWarning(st, msg1160);  
448       }
449     else if (t1 > t2)
450       res = new Geom_TrimmedCurve(res, t2, t1); // inversion des parametres.
451     else
452       res = new Geom_TrimmedCurve(res, t1, t2); 
453   }
454
455   return res;
456 }
457
458
459 //=======================================================================
460 //function : Transfer2dConicArc
461 //purpose  : Transfer 2d of a ConicArc to be used as a boundary of a Face
462 //=======================================================================
463
464 Handle(Geom2d_Curve) IGESToBRep_BasicCurve::Transfer2dConicArc
465        (const Handle(IGESGeom_ConicArc)& st)
466
467   Handle(Geom2d_Curve) res;
468   if (st.IsNull()) {
469     Message_Msg msg1005("IGES_1005");
470     SendFail(st, msg1005);
471     return res;
472   }
473
474  if (!st->ComputedFormNumber()) {
475     Message_Msg msg1155("IGES_1155");
476     SendFail(st, msg1155);
477     return res;
478   }
479
480   Standard_Real a,b,c,d,e,f;                          
481   // Conic = ax2+bxy+cy2+dx+ey+f=0.
482   st->Equation(a, b, c, d, e, f);
483
484   gp_Pnt        center3d;
485   gp_Dir        mainAxis3d;
486   gp_Pnt2d      startPoint, endPoint;
487   Standard_Real minorRadius, majorRadius;
488   
489   SetEpsilon(1.E-03);
490   if (!st->TransformedAxis().IsParallel /*#45 rln 23.11.98 IsEqual*/(st->Axis(), GetEpsilon())) {
491     SetModeTransfer(Standard_True); 
492     // Only not to use Trsf.
493     // the normal axis is not parallel with Z axis.
494     SendWarning(st, "The Trsf is not compatible with a transfer2d, it will not applied.");
495   } 
496
497   if (!GetModeTransfer() && st->HasTransf()) {
498
499     st->TransformedDefinition(center3d, 
500                               mainAxis3d, 
501                               minorRadius, 
502                               majorRadius);
503     startPoint.SetCoord(st->TransformedStartPoint().X(),
504                         st->TransformedStartPoint().Y());
505     endPoint.SetCoord(st->TransformedEndPoint().X(),
506                       st->TransformedEndPoint().Y());
507   }
508   else {
509     st->Definition(center3d, mainAxis3d, minorRadius, majorRadius);
510     startPoint = st->StartPoint();
511     endPoint   = st->EndPoint();
512   }
513   
514   gp_Pnt2d center(center3d.X(), center3d.Y());
515   gp_Dir2d mainAxis(mainAxis3d.X(), mainAxis3d.Y());
516   gp_Ax2d  frame(center, mainAxis);
517   Standard_Real t1 =0.0, t2=0.0;
518   if (st->IsFromEllipse()) {
519
520     //#60 rln 29.12.98 PRO17015
521     //if ( (Abs(a-c) <= GetEpsGeom()) && (Abs(b) < GetEpsCoeff()))
522     Standard_Real eps2 = Precision::PConfusion() * Precision::PConfusion();
523     if ( (Abs(a-c) <= eps2) && (Abs(b) < eps2)) {
524
525       //                          =================
526       //                          ==  Circle 2D  ==
527       //                          =================
528       
529       res = new Geom2d_Circle(frame, minorRadius);
530       //#45 rln 23.11.98
531       if (st->TransformedAxis().IsOpposite (st->Axis(), GetEpsilon()))
532         res->Reverse();
533       
534       if (!st->IsClosed()) {
535
536         gp_Circ2d circ = Handle(Geom2d_Circle)::DownCast(res)->Circ2d();//#45 rln (frame, minorRadius);
537         
538         t1 = ElCLib::Parameter(circ, startPoint);
539         t2 = ElCLib::Parameter(circ, endPoint);
540         
541         if (t2 < t1 && (t1 -t2) > Precision::PConfusion()) t2 += 2.*M_PI;
542         if (Abs(t1 - t2) <= Precision::PConfusion()) { // t1 = t2
543           Message_Msg msg1160("IGES_1160");
544           SendWarning(st, msg1160); 
545         }
546         else 
547           res = new Geom2d_TrimmedCurve(res, t1, t2);
548       }
549       return res; 
550     }
551     else { 
552       // This is a no circular ellipse, it will be computed with the hyperbola.
553     }
554   }  
555   else if (st->IsFromParabola()) {
556     
557     //                         ===================
558     //                         ==  Parabola 2D  ==
559     //                         ===================
560     
561     Standard_Real focal = minorRadius;
562     // PTV 26.03.2002
563     focal = focal/2.;
564     res = new Geom2d_Parabola(frame, focal);
565     //#45 rln 23.11.98
566     if (st->TransformedAxis().IsOpposite (st->Axis(), GetEpsilon()))
567       res->Reverse();
568     
569     gp_Parab2d parab = Handle(Geom2d_Parabola)::DownCast(res)->Parab2d();//#45 rln (frame, focal);
570     
571     t1  = ElCLib::Parameter(parab, startPoint);
572     t2  = ElCLib::Parameter(parab, endPoint);
573     if (Abs(t1 - t2) <= Precision::PConfusion())  { // t1 = t2   
574         Message_Msg msg1160("IGES_1160");
575         SendWarning(st, msg1160);  
576       }  
577     else if (t1 > t2)
578       res = new Geom2d_TrimmedCurve(res, t2, t1); // inversion des parametres.
579     else 
580       res = new Geom2d_TrimmedCurve(res, t1, t2);
581     return res;                      
582   }
583     
584   /* Same computing for the ellipse2d and the hyperbola2d. */
585   
586   //              ============================================
587   //              ==  Hyperbola or a no circular Ellipse 2D ==
588   //              ============================================
589     
590   if (st->IsFromEllipse()) {
591
592     res = new Geom2d_Ellipse(frame, majorRadius, minorRadius);
593     //#45 rln 23.11.98
594     if (st->TransformedAxis().IsOpposite (st->Axis(), GetEpsilon()))
595       res->Reverse();
596
597     if (!st->IsClosed()) {
598
599       gp_Elips2d elips = Handle(Geom2d_Ellipse)::DownCast(res)->Elips2d();//#45 rln (frame, majorRadius, minorRadius);
600       
601       t1  = ElCLib::Parameter(elips, startPoint);
602       t2  = ElCLib::Parameter(elips, endPoint);
603       if (t2 < t1 && (t1 - t2) > Precision::PConfusion()) t2 += 2.*M_PI;
604       if (Abs(t1 - t2) <= Precision::PConfusion())  { // t1 = t2   
605         Message_Msg msg1160("IGES_1160");
606         SendWarning(st, msg1160);  
607       }
608       else   
609         res = new Geom2d_TrimmedCurve(res, t1, t2);
610     }
611   }
612   else {
613
614     res = new Geom2d_Hyperbola(frame, majorRadius, minorRadius);
615     //#45 rln 23.11.98
616     if (st->TransformedAxis().IsOpposite (st->Axis(), GetEpsilon()))
617       res->Reverse();
618
619     gp_Hypr2d hpr = Handle(Geom2d_Hyperbola)::DownCast(res)->Hypr2d();//#45 rln (frame, majorRadius, minorRadius);
620    
621     t1 = ElCLib::Parameter(hpr, startPoint);
622     t2 = ElCLib::Parameter(hpr, endPoint);
623     
624     if (Abs(t1 - t2) <= Precision::PConfusion())   { // t1 = t2   
625         Message_Msg msg1160("IGES_1160");
626         SendWarning(st, msg1160);  
627       }
628     else if (t1 > t2)
629       res = new Geom2d_TrimmedCurve(res, t2, t1); // inversion des parametres.
630     else   
631       res = new Geom2d_TrimmedCurve(res, t1, t2);
632   }
633
634   return res;
635 }
636
637
638 //=======================================================================
639 //function : TransferCircularArc
640 //purpose  : 
641 //=======================================================================
642
643 Handle(Geom_Curve) IGESToBRep_BasicCurve::TransferCircularArc
644        (const Handle(IGESGeom_CircularArc)& st)
645
646   Handle(Geom_Curve) res;
647   if (st.IsNull()) {
648     Message_Msg msg1005("IGES_1005");
649     SendFail(st,msg1005);
650     return res;
651   }
652
653   gp_Dir tNormAxis, tMainAxis;
654   gp_Ax2 frame;
655   gp_Pnt startPoint, endPoint;
656
657   if (!GetModeTransfer() && st->HasTransf()) {
658
659     tNormAxis = st->TransformedAxis();
660
661     gp_GTrsf loc = st->Location();
662     loc.SetTranslationPart (gp_XYZ(0.,0.,0.));
663     gp_XYZ mainAxis(1., 0., 0.); 
664     loc.Transforms(mainAxis);
665     tMainAxis = gp_Dir(mainAxis);
666
667     startPoint = st->TransformedStartPoint();
668     endPoint   = st->TransformedEndPoint();
669     
670     frame = gp_Ax2(st->TransformedCenter(), tNormAxis, tMainAxis);
671   }
672   else {
673     tNormAxis  = st->Axis();
674     tMainAxis.SetCoord(1., 0., 0.);
675
676     Standard_Real ZT    = st->ZPlane();
677     startPoint.SetCoord(st->StartPoint().X(), st->StartPoint().Y(), ZT);
678     endPoint.SetCoord  (st->EndPoint().X()  , st->EndPoint().Y()  , ZT);
679     gp_Pnt centerPoint (st->Center().X()    , st->Center().Y()    , ZT);
680
681     frame = gp_Ax2(centerPoint, tNormAxis, tMainAxis);
682   }
683   
684   res = new Geom_Circle(frame, st->Radius());
685   
686   gp_Circ   circ(frame, st->Radius());
687   
688   Standard_Real t1 =0.0, t2 =0.0;
689  
690   t1 = ElCLib::Parameter(circ, startPoint);
691   t2 = ElCLib::Parameter(circ, endPoint);
692
693   if ( st->IsClosed() && t1>=GetEpsGeom()) t2 = t1 + 2.*M_PI;
694   if (!st->IsClosed() && fabs(t1 - t2) <=Precision::PConfusion()) {    
695     // micro-arc
696     // cky 27 Aout 1996 : t2-t1 vaut distance(start,end)/rayon
697     t2 = t1 + startPoint.Distance(endPoint)/st->Radius();
698   }
699   if (!st->IsClosed() || t1>=GetEpsGeom()) {
700     if (t2 < t1) t2 += 2.*M_PI;
701     res = new Geom_TrimmedCurve(res, t1, t2);
702   }
703
704   return res;      
705 }
706
707 //=======================================================================
708 //function : Transfer2dCircularArc
709 //purpose  : 
710 //=======================================================================
711
712 Handle(Geom2d_Curve) IGESToBRep_BasicCurve::Transfer2dCircularArc
713        (const Handle(IGESGeom_CircularArc)& st) 
714
715   Handle(Geom2d_Curve) res;     
716   if (st.IsNull()) {
717     Message_Msg msg1005("IGES_1005");
718     SendFail(st,msg1005);
719     return res;
720   }
721
722   gp_XYZ center(st->Center().X(), st->Center().Y(), 0.);
723   gp_XYZ mainAxis(1., 0., 0.); 
724
725   SetEpsilon(1.E-03);
726   if (!st->TransformedAxis().IsParallel /*#45 rln 23.11.98 IsEqual*/(st->Axis(), GetEpsilon())) {
727     SetModeTransfer(Standard_True);          // Only not to use Trsf
728     Message_Msg msg1165("IGES_1165");
729     SendWarning(st, msg1165); //"The Trsf is not compatible with a transfer2d, it will not applied."
730   }
731
732   if (!GetModeTransfer() && st->HasTransf()) {
733     gp_GTrsf loc = st->Location();
734     loc.Transforms(center);
735     loc.SetTranslationPart (gp_XYZ(0.,0.,0.));
736     loc.Transforms(mainAxis);
737   }
738   gp_Pnt2d tCenter(center.X(), center.Y());
739   gp_Dir2d tMainAxis(mainAxis.X(), mainAxis.Y());
740   gp_Ax2d  frame(tCenter, tMainAxis);
741   
742   res = new Geom2d_Circle(frame, st->Radius());
743   
744   gp_Pnt2d startPoint, endPoint;
745    if (!GetModeTransfer() && st->HasTransf()) {
746     startPoint.SetCoord(st->TransformedStartPoint().X(),
747                         st->TransformedStartPoint().Y());
748     endPoint.SetCoord(st->TransformedEndPoint().X(),
749                       st->TransformedEndPoint().Y());
750     //#45 rln 23.11.98
751     if (st->TransformedAxis().IsOpposite (st->Axis(), GetEpsilon()))
752       res->Reverse();
753   }
754   else {
755     startPoint = st->StartPoint();
756     endPoint   = st->EndPoint();
757   }
758
759   gp_Circ2d circ = Handle(Geom2d_Circle)::DownCast(res)->Circ2d();//#45 rln (frame, st->Radius());
760   
761   Standard_Real t1 =0.0, t2 =0.0;
762   
763   t1 = ElCLib::Parameter(circ, startPoint);
764   t2 = ElCLib::Parameter(circ, endPoint);
765     
766   if ( st->IsClosed() && t1>=GetEpsGeom()) t2 = t1 + 2.*M_PI;
767   if (!st->IsClosed() && fabs(t1 -t2) <= Precision::PConfusion()) { 
768     // micro-arc
769     // cky 27 Aout 1996 : t2-t1 vaut distance(start,end)/rayon
770     t2 = t1 + startPoint.Distance(endPoint)/st->Radius();
771   }
772   if (!st->IsClosed() || t1>= GetEpsGeom()) {
773     if (t2 < t1) t2 += 2.*M_PI;
774     res     = new Geom2d_TrimmedCurve(res, t1, t2);
775   }
776   return res;
777 }
778
779
780
781 //=======================================================================
782 //function : TransferSplineCurve
783 //purpose  : 
784 //=======================================================================
785
786 Handle(Geom_BSplineCurve) IGESToBRep_BasicCurve::TransferSplineCurve
787        (const Handle(IGESGeom_SplineCurve)& st)
788
789   Handle(Geom_BSplineCurve) resconv;
790   if (st.IsNull()) {
791     Message_Msg msg1005("IGES_1005");
792     SendFail(st,msg1005);
793     return resconv;
794   }
795   
796   Standard_Real epscoef = GetEpsCoeff();
797   Standard_Real epsgeom = GetEpsGeom();
798
799   Standard_Integer result = IGESConvGeom::SplineCurveFromIGES(st, epscoef, epsgeom, resconv);
800   
801   switch (result) {
802   case 5 : {
803     Message_Msg msg246("XSTEP_246");
804     SendFail(st, msg246);
805     // less than on segment (no result produced)
806     return resconv;
807   }
808   case 4 : {
809     Message_Msg msg1170("IGES_1170");
810     SendFail(st, msg1170);
811     // Polynomial equation is not correct ( no result produced
812     return resconv;}
813   case 3 :{
814     Message_Msg msg1175("IGES_1175");
815     SendFail(st, msg1175);
816     // Error during creation of control points ( no result produced)
817     return resconv;}
818   case 2 :{
819     Message_Msg msg1180("IGES_1180");
820    SendFail(st, msg1180);
821     //SplineType not processed (allowed : max 3) (no result produced)
822     return resconv;}
823   default :
824     break;
825   }
826
827   //  Checking C2 and C1 continuity :
828   //  ===============================
829   IGESConvGeom::IncreaseCurveContinuity (resconv, Min(Precision::Confusion(),epsgeom), GetContinuity());
830   return resconv;
831 }
832
833
834
835 //=======================================================================
836 //function : Transfer2dSplineCurve
837 //purpose  : 
838 //=======================================================================
839
840 Handle(Geom2d_BSplineCurve) IGESToBRep_BasicCurve::Transfer2dSplineCurve
841        (const Handle(IGESGeom_SplineCurve)& st)
842
843   Handle(Geom2d_BSplineCurve) res;
844   if (st.IsNull()) {
845     Message_Msg msg1005("IGES_1005");
846     SendFail(st, msg1005);
847     return res;
848   }
849
850   // 3d transfer First 
851   // =================
852   // The same Presision as in BSpline 2d is used
853   Standard_Real epsGeom = GetEpsGeom();
854   SetEpsGeom(Precision::PConfusion());
855   Handle(Geom_BSplineCurve) res3d = TransferSplineCurve(st);
856   SetEpsGeom(epsGeom);
857   if (res3d.IsNull()) 
858     return res;        // The transfer was not over the top.
859
860  
861   // 2d 
862   // ==
863   Standard_Integer nbPoles = res3d->NbPoles();
864   Standard_Integer nbKnots = res3d->NbKnots();
865  
866   TColgp_Array1OfPnt2d    bspoles2d(1, nbPoles);
867   TColStd_Array1OfReal    knots(1, nbKnots);
868   TColStd_Array1OfInteger multi(1, nbKnots);
869
870   res3d->Knots(knots);
871   res3d->Multiplicities(multi);
872
873   for (Standard_Integer i = bspoles2d.Lower(); i <= bspoles2d.Upper(); i++) 
874     bspoles2d.SetValue(i, gp_Pnt2d(res3d->Pole(i).X(), res3d->Pole(i).Y()));
875   
876   res = new Geom2d_BSplineCurve (bspoles2d, knots, multi, res3d->Degree());
877   return res;
878 }
879
880 //=======================================================================
881 //function : TransferBSplineCurve
882 //purpose  : 
883 //=======================================================================
884
885 Handle(Geom_Curve) IGESToBRep_BasicCurve::TransferBSplineCurve
886        (const Handle(IGESGeom_BSplineCurve)&  start)
887      
888
889   Handle(Geom_BSplineCurve)  BSplineRes;
890   Handle(Geom_Curve) res;
891   
892   if (start.IsNull()) {
893     Message_Msg msg1005("IGES_1005");
894     SendFail(start,msg1005);
895     return res;
896   }
897
898   Standard_Integer  Degree = start->Degree();
899
900   if (Degree<=0 || Degree>Geom_BSplineCurve::MaxDegree()) { 
901     Message_Msg msg1190("IGES_1190");
902     SendFail(start, msg1190);
903     // Improper degree either lower or equal to 0 or upper to MaxDegree
904       return res;
905   }
906   
907   
908   //  Filling poles array :
909   //  =====================
910   
911   Standard_Integer  NbPoles = start->NbPoles();
912   Standard_Integer  newNbPoles = NbPoles;
913   
914   if (NbPoles<2) {
915     Message_Msg msg1195("IGES_1195");
916     SendFail(start, msg1195);
917     // Transfer aborted for a BSpline Curve : Number of poles lower than 2
918     return res;
919   }
920
921   TColgp_Array1OfPnt   Pole(1,NbPoles);
922   Standard_Integer     PoleIndex = Pole.Lower();
923   Standard_Integer     i; //szv#4:S4163:12Mar99 j unused
924
925   if (!GetModeTransfer() && start->HasTransf()) 
926     for (i=0; i<=start->UpperIndex(); i++) 
927       Pole.SetValue(PoleIndex++, start->TransformedPole(i));
928   else
929     for (i=0; i<=start->UpperIndex(); i++) 
930       Pole.SetValue(PoleIndex++, start->Pole(i));
931   
932   
933   //  Filling knots & multiplicities arraies :
934   //  ========================================
935   
936   Standard_Integer          NbKnots = start->NbKnots();
937   TColStd_Array1OfReal      TempKnot(1,NbKnots);
938   TColStd_Array1OfInteger   TempMult(1,NbKnots); 
939   TempMult.Init(1);
940   Standard_Integer          KnotIndex = TempKnot.Lower();
941
942   TempKnot.SetValue(KnotIndex, start->Knot(-Degree));
943   
944   //  If several identical IGES knots are encountered, corresponding 
945   //  multiplicity is increased
946   //  ==============================================================
947
948   for (i=1-Degree; i<NbKnots-Degree; i++) {
949
950     Standard_Real Knot1 = start->Knot(i);
951     Standard_Real Knot2 = start->Knot(i-1);
952 //    Standard_Real ek    =  Epsilon(Knot1);
953
954     if (Abs(Knot1 - Knot2) <= Epsilon(Knot1))
955       TempMult.SetValue(KnotIndex, TempMult.Value(KnotIndex)+1);
956     else 
957       TempKnot.SetValue(++KnotIndex, Knot1);
958   }
959   
960
961   //  Final knots & multiplicities arraies are dimensionned so as to be fully 
962   //  filled
963   //  =======================================================================
964   
965   TColStd_Array1OfReal        Knot(1,KnotIndex);
966   TColStd_Array1OfInteger     Mult(1,KnotIndex);
967
968   Standard_Integer SumOfMult=0;
969   
970   TColStd_SequenceOfInteger SeqIndex;
971   Standard_Integer DelIndex;
972   Standard_Integer OldSumOfMult = 0;
973   for (i=1; i <= KnotIndex; i++) { //:k5 abv 25 Dec 98: cycle modified
974     Standard_Integer aMult = TempMult.Value(i);
975     Standard_Integer maxMult = ( i==1 || i == KnotIndex ? Degree + 1 : Degree );
976     if (aMult > maxMult) {
977     Message_Msg msg1200("IGES_1200");//#61 rln 05.01.99
978     const Standard_CString vide ("");
979     msg1200.Arg(vide);
980     msg1200.Arg(vide);
981     msg1200.Arg(vide);
982     SendWarning(start, msg1200);//Multiplicity > Degree (or Degree+1 at end); corrected
983       for ( DelIndex = OldSumOfMult + 1; aMult > maxMult; DelIndex++, aMult-- ) {
984         newNbPoles--;
985         SeqIndex.Append(DelIndex);
986       }
987     }
988     OldSumOfMult += TempMult.Value(i); 
989     Knot.SetValue(i, TempKnot.Value(i));
990     Mult.SetValue(i, aMult);
991     SumOfMult += aMult;
992   }
993
994   // Mise a jour du tableau des poles lors de la correction de la multiplicite
995   TColgp_Array1OfPnt Poles(1,newNbPoles);
996   TColStd_SequenceOfInteger PoleInd;
997
998   if ( newNbPoles < NbPoles) {
999     for (i=1; i<=NbPoles; i++) PoleInd.Append(i);
1000     Standard_Integer Offset = 0;
1001     for (Standard_Integer itab = 1; itab <= SeqIndex.Length(); itab++) {
1002       DelIndex = SeqIndex.Value(itab) - Offset;
1003       PoleInd.Remove(DelIndex);
1004       Offset++;
1005     }
1006     Standard_Integer nbseq = PoleInd.Length();
1007     if ( nbseq == newNbPoles) {
1008       Standard_Integer indj = 1;
1009       for ( i=1; i<= newNbPoles; i++) {
1010         Poles.SetValue(i, Pole.Value(PoleInd.Value(indj++)));
1011       }
1012     }
1013   }
1014
1015   else {
1016     for ( i=1; i<= newNbPoles; i++) {
1017       Poles.SetValue (i, Pole.Value(i));
1018     }
1019   }
1020     
1021
1022   if (! (SumOfMult  ==  newNbPoles + Degree + 1)) {
1023     Message_Msg msg1210("IGES_1210");
1024     const Standard_CString vide ("");
1025     msg1210.Arg(vide);
1026     msg1210.Arg(vide);
1027     SendWarning(start, msg1210);
1028     //Sum of multiplicities not equal to the sum : Count of poles + Degree + 1
1029   }
1030   
1031   //  Output BSpline curve with the array of pole weights if any :
1032   //  ============================================================
1033   
1034   TColStd_Array1OfReal Weight(1,newNbPoles);
1035
1036   if (start->IsPolynomial()) {
1037 //:5    BSplineC = new Geom_BSplineCurve(Poles, Knot, Mult, Degree);  
1038   }
1039   else {
1040     TColStd_Array1OfReal  PoleWeight(1,NbPoles);
1041     Standard_Boolean      polynomial               = Standard_True;
1042     Standard_Real         WeightReference          = start->Weight(0);
1043     Standard_Integer      WeightIndex              = PoleWeight.Lower();
1044     
1045     for (i=0; i <= start->UpperIndex(); i++) {
1046       polynomial = Abs(start->Weight(i) - WeightReference) <= 
1047         Epsilon(WeightReference) && polynomial;
1048       //:39 by abv 15.12.97
1049       Standard_Real weight = start->Weight(i);
1050       if ( weight < Precision::PConfusion() ) {
1051         Message_Msg msg1215("IGES_1215");
1052         SendFail(start, msg1215);
1053         // Some weights are not positive
1054         return res;
1055       }
1056       PoleWeight.SetValue(WeightIndex++, weight);
1057 //:39      PoleWeight.SetValue(WeightIndex++, start->Weight(i));
1058     }
1059     if (polynomial) {
1060       Message_Msg msg1220("IGES_1220");
1061       msg1220.Arg("curve");
1062       SendWarning(start, msg1220);
1063       // Rational curve is polynomial
1064     }
1065     // Mise a jour du tableau des Weight lors de la correction de la multiplicite
1066     if ( newNbPoles < NbPoles) {
1067       Standard_Integer indj = 1;
1068       for ( i=1; i<= newNbPoles; i++) {
1069         Weight.SetValue(i, PoleWeight.Value(PoleInd.Value(indj++)));
1070       }
1071     }
1072     else {
1073       for ( i=1; i<= newNbPoles; i++) {
1074         Weight.SetValue (i, PoleWeight.Value(i));
1075       }
1076     }
1077 //:5    BSplineC = new Geom_BSplineCurve(Poles, Weight, Knot, Mult, Degree); 
1078   }
1079   
1080   //sln 29.12.2001 OCC90 : If curve can not be created do nothing
1081   if(!checkBSplineCurve(this, start, Knot, Weight)) return BSplineRes;
1082
1083   {
1084     try {
1085       OCC_CATCH_SIGNALS
1086       if (start->IsPolynomial()) 
1087         BSplineRes = new Geom_BSplineCurve(Poles, Knot, Mult, Degree);  
1088       else 
1089         BSplineRes = new Geom_BSplineCurve(Poles, Weight, Knot, Mult, Degree); 
1090     }
1091     catch(Standard_Failure) {
1092 #ifdef DEB
1093       cout << "\n** Exception in IGESToBRep_BasicCurve::TransferBSplineCurve during creation of Geom_BSplineCurve : "; 
1094       Standard_Failure::Caught()->Print(cout);
1095 #endif
1096     }
1097   }
1098   
1099   Standard_Real First = BSplineRes->FirstParameter();
1100   Standard_Real Last  = BSplineRes->LastParameter();
1101   Standard_Real Udeb = start->UMin();
1102   Standard_Real Ufin = start->UMax();
1103   //%11 pdn 12.01.98 CTS22023 
1104   //if ( (Udeb-First) > Precision::PConfusion() || (Last-Ufin) > Precision::PConfusion() )
1105   //  BSplineRes->Segment(Udeb, Ufin);
1106   //res = BSplineRes;
1107
1108 //  IGESConvGeom::IncreaseCurveContinuity (BSplineRes,Min(Precision::Confusion(),GetEpsGeom()), GetContinuity());
1109   
1110   // skl 21.02.2002 (exception in OCC133 and for file
1111   //                 "/dn04/OS/USINOR/UIdev/src/IsoLim/dat/igs/ps1002-v5.igs")
1112   Handle(Geom_BSplineCurve) BSplineRes2 = BSplineRes;
1113   if (((Udeb-First)>-Precision::PConfusion() &&
1114        (Last-Ufin)>-Precision::PConfusion()) && Udeb<=Ufin ) {
1115     try {
1116       OCC_CATCH_SIGNALS
1117       BSplineRes->Segment(Udeb, Ufin);
1118       res = BSplineRes;
1119     }
1120     catch (Standard_Failure) {
1121       Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(BSplineRes2,Udeb,Ufin);
1122       res = gtc;
1123     }
1124   }
1125   else
1126     res = BSplineRes;
1127
1128   return res;
1129 }
1130
1131
1132
1133 //=======================================================================
1134 //function : Transfer2dBSplineCurve
1135 //purpose  : 
1136 //=======================================================================
1137
1138 Handle(Geom2d_Curve)  IGESToBRep_BasicCurve::Transfer2dBSplineCurve
1139        (const Handle(IGESGeom_BSplineCurve)& start)
1140
1141   Handle(Geom2d_Curve)  res;
1142   if (start.IsNull()) {
1143     Message_Msg msg1005("IGES_1005");
1144     SendFail(start, msg1005);
1145     return res;
1146   }
1147
1148   Handle(Geom2d_BSplineCurve)  BSplineC;
1149   Handle(Geom_BSplineCurve)  Bspline;
1150   Standard_Boolean IsTrimmed = Standard_False;
1151   Standard_Real Deb=0., Fin=0.;
1152
1153   //  3d transfer first :
1154   //  ===================
1155 //  Standard_Real epsGeom = GetEpsGeom();
1156 //  SetEpsGeom(Precision::PConfusion());
1157   Handle(Geom_Curve)  res3d = TransferBSplineCurve(start);
1158 //  SetEpsGeom(epsGeom);
1159   if (res3d.IsNull()) {
1160     return res;
1161   }
1162   
1163              
1164   if (res3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
1165     DeclareAndCast(Geom_TrimmedCurve, TrimC, res3d);
1166     Handle(Geom_Curve) BasicCurve = TrimC->BasisCurve();
1167     Deb = TrimC->FirstParameter();
1168     Fin = TrimC->LastParameter();
1169     IsTrimmed = Standard_True;
1170     if (BasicCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) {
1171       DeclareAndCast(Geom_BSplineCurve, BSpline, BasicCurve);
1172       Bspline = BSpline;
1173     }
1174     else {
1175       return res;
1176     }
1177   }
1178   else if (res3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) {
1179     DeclareAndCast(Geom_BSplineCurve, BSpline, res3d);
1180     Bspline = BSpline;
1181   }
1182
1183
1184   //  Creating 2d poles :
1185   //  ===================
1186
1187   Standard_Integer       NbPoles  =  Bspline->NbPoles();
1188   TColgp_Array1OfPnt2d   Pole(1,NbPoles);
1189
1190   for (Standard_Integer i=1; i<=NbPoles; i++){
1191     gp_Pnt2d aPole2d(Bspline->Pole(i).X(),Bspline->Pole(i).Y());
1192     Pole.SetValue(i,aPole2d);
1193   }
1194
1195   //  Knots and multiplicities are the same :
1196   //  =======================================
1197
1198   Standard_Integer  NbKnots = Bspline->NbKnots();
1199
1200   TColStd_Array1OfReal Knot(1,NbKnots);
1201   Bspline->Knots(Knot);
1202
1203   TColStd_Array1OfInteger Mult(1,NbKnots);
1204   Bspline->Multiplicities(Mult);
1205
1206   Standard_Integer  Degree = Bspline->Degree();
1207
1208   if (Bspline->IsRational()) {
1209     TColStd_Array1OfReal  Weight(1,NbPoles);
1210     Bspline->Weights(Weight);
1211     BSplineC = new Geom2d_BSplineCurve(Pole, Weight, Knot, Mult, Degree);
1212   }
1213   else BSplineC = new Geom2d_BSplineCurve(Pole, Knot, Mult, Degree);
1214   
1215   res = BSplineC;
1216
1217   // cas ou la Bspline est trimmee.
1218   if (IsTrimmed) {
1219     Handle(Geom2d_TrimmedCurve) TC = new Geom2d_TrimmedCurve
1220       (BSplineC, Deb, Fin, Standard_True);
1221     res = TC;
1222   }
1223   
1224   return res;
1225 }
1226
1227
1228
1229 //=======================================================================
1230 //function : TransferLine
1231 //purpose  : 
1232 //=======================================================================
1233
1234 Handle(Geom_Curve)  IGESToBRep_BasicCurve::TransferLine
1235        (const Handle(IGESGeom_Line)& start)
1236
1237   Handle(Geom_Curve)  res;
1238   if (start.IsNull()) {
1239     Message_Msg msg1005("IGES_1005");
1240     SendFail(start, msg1005);
1241     return res;
1242   }
1243
1244   gp_Pnt Ps,Pe;
1245   
1246   if (!GetModeTransfer() && start->HasTransf()) { 
1247     Ps = start->TransformedStartPoint();
1248     Pe = start->TransformedEndPoint();
1249   }
1250   else {
1251     Ps = start->StartPoint();
1252     Pe = start->EndPoint();
1253   }
1254
1255   // modif du 15/10/97  : test moins severe
1256   // beaucoup de points confondus a GetEpsGeom()*GetUnitFactor()
1257   if (!Ps.IsEqual(Pe,Precision::Confusion())) { //:l3 abv 11 Jan 99: GetEpsGeom()*GetUnitFactor()/10.)) {
1258     gp_Lin line(Ps, gp_Dir(gp_Vec(Ps,Pe)));
1259     Standard_Real t1 = ElCLib::Parameter(line, Ps);
1260     Standard_Real t2 = ElCLib::Parameter(line, Pe);
1261     Handle(Geom_Line)  Gline = new Geom_Line(line);
1262     if (Precision::IsNegativeInfinite(t1)) t1 = -Precision::Infinite();
1263     if (Precision::IsPositiveInfinite(t2)) t2 = Precision::Infinite();
1264     res = new Geom_TrimmedCurve(Gline, t1, t2);
1265   }
1266   else {
1267     Message_Msg msg1225("IGES_1225");
1268     SendFail(start, msg1225);
1269     // StartPoint and EndPoint of the line are the same Point
1270   }
1271
1272   return res;
1273 }
1274
1275
1276
1277 //=======================================================================
1278 //function : Transfer2dLine
1279 //purpose  : 
1280 //=======================================================================
1281
1282 Handle(Geom2d_Curve)  IGESToBRep_BasicCurve::Transfer2dLine
1283        (const Handle(IGESGeom_Line)& start)
1284
1285   Handle(Geom2d_Curve) res;
1286   if (start.IsNull()) {
1287     Message_Msg msg1005("IGES_1005");
1288     SendFail(start, msg1005);
1289     return res;
1290   }
1291
1292   gp_Pnt2d beg, end;
1293   
1294   if (!GetModeTransfer() && start->HasTransf()) {
1295     beg.SetCoord(start->TransformedStartPoint().X(),
1296                  start->TransformedStartPoint().Y());
1297     end.SetCoord(start->TransformedEndPoint().X(),
1298                  start->TransformedEndPoint().Y());
1299   }
1300   else {
1301     beg.SetCoord(start->StartPoint().X(),
1302                  start->StartPoint().Y());
1303     end.SetCoord(start->EndPoint().X(), 
1304                  start->EndPoint().Y());
1305   }
1306
1307   if (!beg.IsEqual(end,Precision::PConfusion())) { //:l3 abv 11 Jan 99: GetEpsCoeff())) {
1308     gp_Lin2d line2d(beg, gp_Dir2d(gp_Vec2d(beg,end)));
1309     Standard_Real t1 = ElCLib::Parameter(line2d, beg);
1310     Standard_Real t2 = ElCLib::Parameter(line2d, end);
1311     Handle(Geom2d_Line) Gline2d = new Geom2d_Line(line2d);
1312     if (Precision::IsNegativeInfinite(t1)) t1 = -Precision::Infinite();
1313     if (Precision::IsPositiveInfinite(t2)) t2 = Precision::Infinite();
1314     res = new Geom2d_TrimmedCurve(Gline2d, t1, t2);
1315   }
1316   //added by rln 18/12/97 CSR# CTS18544 entity 25168 and 31273
1317   //generating fail the same as above
1318   else { 
1319     Message_Msg msg1225("IGES_1225");
1320     SendFail(start, msg1225); // StartPoint and EndPoint of the 2d line are the same Point
1321   }
1322   return res;
1323 }
1324
1325
1326
1327 //=======================================================================
1328 //function : TransferTransformation
1329 //purpose  : 
1330 //=======================================================================
1331
1332 Handle(Geom_Transformation)  IGESToBRep_BasicCurve::TransferTransformation
1333        (const Handle(IGESGeom_TransformationMatrix)& start)
1334      
1335
1336   Handle(Geom_Transformation) res;
1337   if (start.IsNull()) {
1338     Message_Msg msg1005("IGES_1005");
1339     SendFail(start, msg1005);
1340     return res;
1341   }
1342   gp_Trsf resultat;
1343   SetEpsilon(1.E-05);  
1344   if ( IGESData_ToolLocation::ConvertLocation
1345       (GetEpsilon(),start->Value(),resultat) )
1346     res = new Geom_Transformation(resultat);
1347   else {
1348     Message_Msg msg1036("IGES_1036");
1349     SendFail(start, msg1036); // Transformation : not a similarity
1350   } 
1351   return res;
1352 }
1353
1354
1355
1356
1357 //=======================================================================
1358 //function : TransferCopiousData
1359 //purpose  : 
1360 //=======================================================================
1361
1362 Handle(Geom_BSplineCurve)  IGESToBRep_BasicCurve::TransferCopiousData
1363        (const Handle(IGESGeom_CopiousData)& start)
1364      
1365
1366   Handle(Geom_BSplineCurve)  res;
1367   if (start.IsNull()) {
1368     Message_Msg msg1005("IGES_1005");
1369     SendFail(start, msg1005);
1370     return res;
1371   }
1372   
1373   Standard_Integer  FormNb = start->FormNumber();
1374   if (!(FormNb==11 || FormNb==12 || FormNb==63)) {
1375     Message_Msg msg1240("IGES_1240");
1376     SendWarning( start, msg1240);
1377     // "Copious Data : Form number is different from 11, 12 or 63 so the vector treatement is skipped");
1378   }
1379
1380   Standard_Integer  NbPoints = start->NbPoints();
1381   if (NbPoints < 2) {
1382     Message_Msg msg1195("IGES_1195");
1383     SendFail(start, msg1195);  // Count of points lower than 2
1384     return res;
1385   }
1386
1387   //  Filling array of poles :
1388   //  ========================
1389
1390   TColgp_Array1OfPnt  TempPole(1,NbPoints);
1391   Standard_Integer    TempIndex = TempPole.Lower();
1392   
1393   if (!GetModeTransfer() && start->HasTransf()) {
1394     TempPole.SetValue(TempIndex,start->TransformedPoint(1));
1395   }
1396   else {
1397     TempPole.SetValue(TempIndex,start->Point(1));
1398   }    
1399   
1400   TempIndex++;
1401   Standard_Integer i;// svv Jan 10 2000 : porting on DEC
1402   for (i=2; i <= NbPoints; i++) {
1403     gp_Pnt  aPole;
1404     if (!GetModeTransfer() && start->HasTransf()) 
1405       aPole = start->TransformedPoint(i);
1406     else 
1407       aPole = start->Point(i);
1408     // #2 pdn 7 May 1998 BUC50028 
1409     //  delete GetUnitFactor()
1410     //   if (!aPole.IsEqual(TempPole(TempIndex-1),GetEpsGeom()))
1411     //S4054: some filter must be kept UKI60556 entity 7 (two equal points)
1412     if (!aPole.IsEqual(TempPole(TempIndex-1), gp::Resolution()))
1413       TempPole.SetValue(TempIndex++,aPole);
1414   }
1415
1416   NbPoints = TempIndex - TempPole.Lower();
1417
1418   // #1 pdn 7 May 1998  BUC50028 entity 6307
1419   if ( NbPoints == 1) {
1420     Message_Msg msg1235("IGES_1235");
1421     SendFail(start, msg1235);
1422     // The curve degenerates to a point");
1423     return res;
1424   }
1425   TColgp_Array1OfPnt  Pole(1,NbPoints);
1426
1427   TempIndex = TempPole.Lower();
1428   for (i=Pole.Lower(); i<=Pole.Upper(); i++)  
1429     Pole.SetValue(i,TempPole.Value(TempIndex++));
1430
1431   
1432   //  Filling array of knots :
1433   //  ========================
1434   
1435   TColStd_Array1OfReal  Knot(1,NbPoints);
1436   
1437   Knot.SetValue(Knot.Lower(),0.0);
1438
1439   for (i=Knot.Lower()+1; i <= Knot.Upper(); i++) {
1440     gp_Pnt  Pole1    =  Pole.Value(i);
1441     gp_Pnt  Pole2    =  Pole.Value(i-1);
1442     Standard_Real    KnotDist =  Pole1.Distance(Pole2);
1443     Knot.SetValue(i, Knot.Value(i-1)+KnotDist);
1444   }
1445   
1446   Standard_Integer  Degree = 1;
1447
1448   TColStd_Array1OfInteger  Mult(1, NbPoints);
1449   Mult.Init(Degree);
1450   Mult.SetValue(Mult.Lower(),Degree+1);
1451   Mult.SetValue(Mult.Upper(),Degree+1);
1452
1453   res = new Geom_BSplineCurve(Pole, Knot, Mult, Degree);
1454   
1455   IGESConvGeom::IncreaseCurveContinuity (res, Max(GetEpsGeom()/10.,Precision::Confusion()), GetContinuity());
1456   return res;
1457 }
1458
1459
1460 //                    ================================
1461 //                    ==  TRANSFER 2D Copious data  ==
1462 //                    ================================
1463
1464 Handle(Geom2d_BSplineCurve) IGESToBRep_BasicCurve::Transfer2dCopiousData(const Handle(IGESGeom_CopiousData)& start)
1465
1466   Handle(Geom2d_BSplineCurve)  res;
1467   if (start.IsNull()) {
1468     Message_Msg msg1005("IGES_1005");
1469     SendFail(start, msg1005);
1470     return res;
1471   }
1472   
1473   Standard_Integer  FormNb = start->FormNumber();
1474   if (!(FormNb==11 || FormNb==12 || FormNb==63)) {
1475     Message_Msg msg1240("IGES_1240");
1476     SendWarning( start, msg1240);
1477     // "Copious Data : Form number is different from 11, 12 or 63 so the vector treatement is skipped");
1478   }
1479   
1480   Standard_Integer  NbPoints = start->NbPoints();
1481   if (NbPoints < 2) {
1482     Message_Msg msg1195("IGES_1195");
1483     SendFail(start, msg1195);  // Count of points lower than 2
1484     return res;
1485   }
1486   
1487   //  Filling array of poles :
1488   //  ========================
1489   
1490   TColgp_Array1OfPnt2d  TempPole(1,NbPoints);
1491   Standard_Integer      TempIndex = TempPole.Lower();
1492   
1493   if (!GetModeTransfer() && start->HasTransf()) 
1494     TempPole.SetValue(TempIndex,gp_Pnt2d(start->TransformedPoint(1).X(),
1495                                          start->TransformedPoint(1).Y()));
1496   else 
1497     TempPole.SetValue(TempIndex,gp_Pnt2d(start->Point(1).X(),
1498                                          start->Point(1).Y()));
1499   
1500   
1501   TempIndex++;
1502   Standard_Integer i;//svv Jan 10 2000 : porting on DEC
1503   for  (i=2; i <= NbPoints; i++) {
1504     gp_Pnt2d  aPole;
1505     if (!GetModeTransfer() && start->HasTransf()) 
1506       aPole = gp_Pnt2d(start->TransformedPoint(i).X(),
1507                        start->TransformedPoint(i).Y());
1508     else 
1509       aPole = gp_Pnt2d(start->Point(i).X(),
1510                        start->Point(i).Y());
1511     //    if (!aPole.IsEqual(TempPole(TempIndex-1), GetEpsCoeff())) //modified by rln 16/12/97 CSR# PRO11641 entity 46GetEpsGeom()*GetUnitFactor()
1512     //S4054: some filter must be kept UKI60556 entity 7 (two equal points)
1513     if (!aPole.IsEqual(TempPole(TempIndex-1), gp::Resolution()))
1514       TempPole.SetValue(TempIndex++,aPole);
1515   }
1516
1517   NbPoints = TempIndex - TempPole.Lower();
1518   //added by rln on 26/12/97 to avoid exception when creating Bspline from one point
1519   if (NbPoints == 1) {
1520     Message_Msg msg1235("IGES_1235");
1521     SendFail(start, msg1235);
1522     // The curve degenerates to a point");
1523     return res;
1524   }
1525   TColgp_Array1OfPnt2d  Pole(1,NbPoints);
1526
1527   TempIndex = TempPole.Lower();
1528   for (i=Pole.Lower(); i<=Pole.Upper(); i++)  
1529     Pole.SetValue(i,TempPole.Value(TempIndex++));
1530
1531
1532   //  Filling array of knots :
1533   //  ========================
1534
1535   TColStd_Array1OfReal  Knot(1,NbPoints);
1536   
1537   Knot.SetValue(Knot.Lower(),0.0);
1538
1539   for (i=Knot.Lower()+1; i <= Knot.Upper(); i++) {
1540     gp_Pnt2d  Pole1    =  Pole.Value(i);
1541     gp_Pnt2d  Pole2    =  Pole.Value(i-1);
1542     Standard_Real      KnotDist =  Pole1.Distance(Pole2);
1543     Knot.SetValue(i, Knot.Value(i-1)+KnotDist);
1544   }
1545   
1546   const Standard_Integer  Degree = 1;
1547
1548   TColStd_Array1OfInteger  Mult(1, NbPoints);
1549   Mult.Init(Degree);
1550   Mult.SetValue(Mult.Lower(),Degree+1);
1551   Mult.SetValue(Mult.Upper(),Degree+1);
1552   
1553   res = new Geom2d_BSplineCurve(Pole, Knot, Mult, Degree);
1554   
1555   Standard_Real epsGeom = GetEpsGeom();
1556   Standard_Real anUVResolution = GetUVResolution();
1557   
1558   IGESConvGeom::IncreaseCurveContinuity (res, Max(Precision::Confusion(),epsGeom*anUVResolution), GetContinuity());
1559   return res;
1560 }