]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/BRepTools_NurbsConvertModification_21423.cxx
Salome HOME
Mantis issue 0021465: EDF 2067 GEOM: Extrusion along a path leads to a self-intersect...
[modules/geom.git] / src / GEOMImpl / BRepTools_NurbsConvertModification_21423.cxx
1 // File:        BRepTools_NurbsConvertModification_21423.cxx
2 // Created:     Fri Jul 12 10:16:32 1996
3 // Author:      Stagiaire Mary FABIEN
4 //              <fbi@animax.paris1.matra-dtv.fr>
5
6 #include <BRepTools_NurbsConvertModification_21423.hxx>
7
8 #include <TopoDS_Edge.hxx>
9 #include <TopoDS_Face.hxx>
10 #include <TopoDS_Vertex.hxx>
11
12 #include <TopLoc_Location.hxx>
13
14 #include <Geom_Curve.hxx>
15 #include <Geom_Surface.hxx>
16
17 #include <Geom2d_Curve.hxx>
18
19 #include <gp_Pnt.hxx>
20
21 #ifndef _Standard_Type_HeaderFile
22 #include <Standard_Type.hxx>
23 #endif
24
25 IMPLEMENT_STANDARD_TYPE(BRepTools_NurbsConvertModification_21423)
26 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY()
27   STANDARD_TYPE(BRepTools_Modification),
28   STANDARD_TYPE(MMgt_TShared),
29   STANDARD_TYPE(Standard_Transient),
30
31 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END()
32 IMPLEMENT_STANDARD_TYPE_END(BRepTools_NurbsConvertModification_21423)
33
34 IMPLEMENT_DOWNCAST(BRepTools_NurbsConvertModification_21423,Standard_Transient)
35 IMPLEMENT_STANDARD_RTTI(BRepTools_NurbsConvertModification_21423)
36
37 #include <BRepTools.hxx>
38
39 #include <Standard_NoSuchObject.hxx>
40
41 #include <Geom_TrimmedCurve.hxx>
42 #include <Geom2d_TrimmedCurve.hxx>
43 #include <Geom_RectangularTrimmedSurface.hxx>
44 #include <Geom_BSplineSurface.hxx>
45 #include <Geom_BSplineCurve.hxx>
46 #include <Geom_BezierSurface.hxx>
47 #include <Geom_BezierCurve.hxx>
48 #include <Geom2d_BSplineCurve.hxx>
49 #include <GeomConvert.hxx>
50 #include <Geom2dConvert.hxx>
51 #include <Geom_Plane.hxx>
52 #include <Geom_Line.hxx>
53
54 #include <Geom2dAdaptor_Curve.hxx>
55 #include <GeomAdaptor_Curve.hxx>
56 #include <GeomAdaptor_Surface.hxx>
57 #include <Geom2dAdaptor_HCurve.hxx>
58 #include <Geom2dAdaptor_HCurve.hxx>
59 #include <GeomAdaptor_HCurve.hxx>
60 #include <GeomAdaptor_HSurface.hxx>
61
62 #include <BSplCLib.hxx>
63 #include <Approx_SameParameter.hxx>
64 #include <BRep_Tool.hxx>
65 #include <Extrema_LocateExtPC.hxx>
66 #include <OSD_Chronometer.hxx>
67 #include <gp_GTrsf2d.hxx>
68 #include <gp_TrsfForm.hxx>
69 #include <TopAbs.hxx>
70 #include <TopoDS.hxx>
71 #include <TopTools_ListIteratorOfListOfShape.hxx>
72 #include <TColStd_ListIteratorOfListOfTransient.hxx>
73 #include <ProjLib_ComputeApprox.hxx>
74 #include <ProjLib_ComputeApproxOnPolarSurface.hxx>
75 #include <ElSLib.hxx>
76 #include <BSplCLib.hxx>
77 #include <Geom_Circle.hxx>
78 #include <Geom_Ellipse.hxx>
79 #include <Geom_CylindricalSurface.hxx>
80
81 #include <TColStd_Array1OfReal.hxx>
82 #include <BRep_TEdge.hxx>
83 #include <BRep_GCurve.hxx>
84 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
85 #include <BRepAdaptor_Surface.hxx>
86
87 static void GeomLib_ChangeUBounds(Handle(Geom_BSplineSurface)& aSurface,
88                                   const Standard_Real newU1,
89                                   const Standard_Real newU2)
90 {
91   TColStd_Array1OfReal  knots(1,aSurface->NbUKnots()) ;
92   aSurface->UKnots(knots) ;
93   BSplCLib::Reparametrize(newU1,
94                           newU2,
95                           knots) ;
96   aSurface->SetUKnots(knots) ;
97 }
98 static void GeomLib_ChangeVBounds(Handle(Geom_BSplineSurface)& aSurface,
99                                   const Standard_Real newV1,
100                                   const Standard_Real newV2)
101 {
102   TColStd_Array1OfReal  knots(1,aSurface->NbVKnots()) ;
103   aSurface->VKnots(knots) ;
104   BSplCLib::Reparametrize(newV1,
105                           newV2,
106                           knots) ;
107   aSurface->SetVKnots(knots) ;
108 }
109
110 //=======================================================================
111 //function : BRepTools_NurbsConvertModification_21423
112 //purpose  : 
113 //=======================================================================
114
115 BRepTools_NurbsConvertModification_21423::BRepTools_NurbsConvertModification_21423()
116 {
117 }
118
119
120
121 //=======================================================================
122 //function : NewSurface
123 //purpose  : 
124 //=======================================================================
125
126 Standard_Boolean BRepTools_NurbsConvertModification_21423::NewSurface
127       (const TopoDS_Face& F,
128        Handle(Geom_Surface)& S,
129        TopLoc_Location& L,
130        Standard_Real& Tol,
131        Standard_Boolean& RevWires,
132        Standard_Boolean& RevFace)
133 {
134   Standard_Real U1, U2, curvU1, curvU2, surfU1, surfU2, UTol;
135   Standard_Real V1, V2, curvV1, curvV2, surfV1, surfV2, VTol;
136   RevWires = Standard_False;
137   RevFace = Standard_False;
138   Handle(Geom_Surface) SS = BRep_Tool::Surface(F,L);
139   Handle(Standard_Type) TheTypeSS = SS->DynamicType();
140   if ((TheTypeSS == STANDARD_TYPE(Geom_BSplineSurface)) ||
141       (TheTypeSS == STANDARD_TYPE(Geom_BezierSurface))) {
142     return Standard_False;
143   }
144   S = SS;
145   BRepTools::UVBounds(F,curvU1,curvU2,curvV1,curvV2);
146   Tol = BRep_Tool::Tolerance(F);
147   Standard_Real TolPar = 0.1*Tol;
148   Standard_Boolean IsUp = S->IsUPeriodic(), IsVp = S->IsVPeriodic();
149   //OCC466(apo)->
150   U1 = curvU1;  U2 = curvU2;  
151   V1 = curvV1;  V2 = curvV2;
152   SS->Bounds(surfU1,surfU2,surfV1,surfV2); 
153   if(!IsUp){
154     U1 = Max(surfU1,curvU1);
155     U2 = Min(surfU2,curvU2);
156   }
157   if(!IsVp){
158     V1 = Max(surfV1,curvV1);
159     V2 = Min(surfV2,curvV2);
160   }
161   //<-OCC466(apo)  
162   if(IsUp && IsVp) {
163     Standard_Real dU = Abs(U2 - U1), dV = Abs(V2 - V1);
164     Standard_Real Up = S->UPeriod(), Vp = S->VPeriod();
165     if(Abs(dU - Up) <= TolPar && U2 <= Up) {
166       if(Abs(dV - Vp) <= TolPar && V2 <= Vp) { }
167       else {
168         SS = new Geom_RectangularTrimmedSurface(S, V1+1e-9, V2-1e-9, Standard_False);
169       }
170     }
171     else {
172       if(Abs(dV - Vp) <= TolPar && V2 <= Vp) 
173         SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, Standard_True);
174       else
175         SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9);
176     }
177   }
178
179   if(IsUp && !IsVp) {
180     Standard_Real dU = Abs(U2 - U1);
181     Standard_Real Up = S->UPeriod();
182     if(Abs(dU - Up) <= TolPar && U2 <= Up) 
183       SS = new Geom_RectangularTrimmedSurface(S, V1+1e-9, V2-1e-9, Standard_False);
184     else 
185       SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9);
186   }
187         
188   if(!IsUp && IsVp) {
189     Standard_Real dV = Abs(V2 - V1);
190     Standard_Real Vp = S->VPeriod();
191     if(Abs(dV - Vp) <= TolPar && V2 <= Vp) 
192       SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, Standard_True);
193     else
194       SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9);
195   }
196
197   if(!IsUp && !IsVp) {
198     SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9);
199   }
200
201   SS->Bounds(surfU1,surfU2,surfV1,surfV2) ; 
202
203   S = GeomConvert::SurfaceToBSplineSurface(SS);
204   Handle(Geom_BSplineSurface) BS = Handle(Geom_BSplineSurface)::DownCast(S) ;
205   BS->Resolution(Tol, UTol, VTol) ;
206   
207   // 
208   // on recadre les bornes de S  sinon les anciennes PCurves sont aux fraises
209   //
210
211   if (Abs(curvU1-surfU1) > UTol && !BS->IsUPeriodic()) {
212     GeomLib_ChangeUBounds(BS, U1,U2) ;
213   }
214   if (Abs(curvV1-surfV1) > VTol && !BS->IsVPeriodic()) {
215     GeomLib_ChangeVBounds(BS, V1, V2) ;
216   }
217
218   ////modified by jgv, 17.11.11 for SALOME only, bug 21423////
219   BRepAdaptor_Surface BAsurf(F);
220   if (BAsurf.GetType() == GeomAbs_Sphere)
221   { //from OCC217
222     Standard_Real dTol = 1e-9/Sqrt(UTol*UTol+VTol*VTol)*2.0; 
223     Tol *= Max(dTol,1.0);
224   }
225   ////////////////////////////////////////////////////////////
226   
227   return Standard_True;
228 }
229
230 static Standard_Boolean IsConvert(const TopoDS_Edge& E)
231 {
232   Standard_Boolean isConvert = Standard_False;
233   Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
234   // iterate on pcurves
235   BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
236   for ( ; itcr.More() && !isConvert; itcr.Next() ) {
237     Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
238     if ( GC.IsNull() || ! GC->IsCurveOnSurface() ) continue;
239     Handle(Geom_Surface) aSurface = GC->Surface();
240     Handle(Geom2d_Curve) aCurve2d = GC->PCurve();
241     isConvert =((!aSurface->IsKind(STANDARD_TYPE(Geom_BSplineSurface)) && 
242                 !aSurface->IsKind(STANDARD_TYPE(Geom_BezierSurface))) ||
243                (!aCurve2d->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve)) &&
244                !aCurve2d->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))));
245      
246   }
247   return isConvert;
248   
249 }
250
251 //=======================================================================
252 //function : NewCurve
253 //purpose  : 
254 //=======================================================================
255
256 Standard_Boolean BRepTools_NurbsConvertModification_21423::NewCurve
257 (const TopoDS_Edge& E, 
258  Handle(Geom_Curve)& C,
259  TopLoc_Location& L,
260  Standard_Real& Tol)
261 {
262
263   Tol = BRep_Tool::Tolerance(E);
264   if(BRep_Tool::Degenerated(E)) {
265     C.Nullify();
266     L.Identity();
267     return Standard_True;
268   }
269   Standard_Real f, l;
270
271   Handle(Geom_Curve) Caux = BRep_Tool::Curve(E, L, f, l);
272
273   if ( Caux.IsNull()) {
274     L.Identity();    
275     return Standard_False;
276   }
277   Handle(Standard_Type) TheType = Caux->DynamicType();
278   if ((TheType == STANDARD_TYPE(Geom_BSplineCurve)) ||
279       (TheType == STANDARD_TYPE(Geom_BezierCurve))) {
280     if(IsConvert(E)) {
281       C = Handle(Geom_Curve)::DownCast(Caux->Copy());
282       return Standard_True;
283     }
284     return Standard_False;
285   } 
286
287   C = Caux; 
288
289   Standard_Real TolPar = Tol *.1;
290
291   if(C->IsPeriodic()) {
292     Standard_Real p = C->Period();
293     Standard_Real d = Abs(l - f);
294     if(Abs(d - p) <= TolPar && l <= p) {}
295     else
296       C = new Geom_TrimmedCurve(C, f, l);
297   } 
298   else 
299     C = new Geom_TrimmedCurve(C, f, l);
300
301 //modif WOK++ portage hp (fbi du 14/03/97)
302 //  gp_Trsf trsf(L);
303 //  gp_Trsf trsf = L.Transformation();
304
305 //  C = GeomConvert::CurveToBSplineCurve(C,Convert_QuasiAngular);
306
307   C = GeomConvert::CurveToBSplineCurve(C);
308
309   Standard_Real fnew = C->FirstParameter(), lnew = C->LastParameter(), UTol;
310
311   Handle(Geom_BSplineCurve) BC = Handle(Geom_BSplineCurve)::DownCast(C) ;
312
313   if(!BC->IsPeriodic()) {
314     BC->Resolution(Tol, UTol) ;
315     if(Abs(f - fnew) > UTol || Abs(l - lnew) > UTol) {
316       TColStd_Array1OfReal  knots(1,BC->NbKnots()) ;
317       BC->Knots(knots) ;
318       BSplCLib::Reparametrize(f, l, knots) ;
319       BC->SetKnots(knots) ;
320     }
321   }
322
323   if(!myMap.Contains(Caux)) {
324     myMap.Add(Caux,C);
325   }
326   return Standard_True ;
327 }
328
329 //=======================================================================
330 //function : NewPoint
331 //purpose  : 
332 //=======================================================================
333
334 Standard_Boolean BRepTools_NurbsConvertModification_21423::NewPoint
335 //(const TopoDS_Vertex& V, 
336 (const TopoDS_Vertex& , 
337 // gp_Pnt& P, 
338  gp_Pnt& , 
339 // Standard_Real& Tol)
340  Standard_Real& )
341 {  
342   return Standard_False;
343 }
344
345
346 //=======================================================================
347 //function : NewCurve2d
348 //purpose  : 
349 //=======================================================================
350
351 Standard_Boolean BRepTools_NurbsConvertModification_21423::NewCurve2d
352 (const TopoDS_Edge& E, 
353  const TopoDS_Face& F, 
354  const TopoDS_Edge& newE, 
355  const TopoDS_Face& newF, 
356  Handle(Geom2d_Curve)& Curve2d,
357  Standard_Real& Tol)
358 {
359   ////modified by jgv, 17.11.11 for SALOME only, bug 21423////
360   Tol = BRep_Tool::Tolerance(E);
361   BRepAdaptor_Surface BAsurf(F);
362   if (BAsurf.GetType() == GeomAbs_Sphere)
363     Tol = Max(Max(BRep_Tool::Tolerance(E),BRep_Tool::Tolerance(F)),
364               Max(BRep_Tool::Tolerance(newE),BRep_Tool::Tolerance(newF))
365               ); //from OCC217
366   ////////////////////////////////////////////////////////////
367   
368   Standard_Real f2d,l2d;
369   Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f2d,l2d);
370   Standard_Real f3d,l3d;
371   TopLoc_Location Loc;
372   Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, Loc, f3d,l3d);
373   Standard_Boolean isConvert2d = ((!C3d.IsNull() && !C3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) &&
374     !C3d->IsKind(STANDARD_TYPE(Geom_BezierCurve))) ||
375     IsConvert(E));
376   
377   if(BRep_Tool::Degenerated(E)) {
378     //Curve2d = C2d;
379     if(!C2d->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve)))
380     {
381       Handle(Geom2d_TrimmedCurve) aTrimC = new Geom2d_TrimmedCurve(C2d,f2d,l2d);
382       C2d = aTrimC;
383     }
384     Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d);
385     return Standard_True;
386   }
387   if(!BRepTools::IsReallyClosed(E,F)) {
388     Handle(Standard_Type) TheTypeC2d = C2d->DynamicType();
389
390     if(TheTypeC2d == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
391       Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve)::DownCast(C2d);
392       C2d = TC->BasisCurve();
393     }
394
395     Standard_Real fc = C2d->FirstParameter(), lc = C2d->LastParameter();
396
397     if(!C2d->IsPeriodic()) {
398       if(fc - f2d > Precision::PConfusion()) f2d = fc;
399       if(l2d - lc > Precision::PConfusion()) l2d = lc;
400     }
401
402     C2d = new Geom2d_TrimmedCurve(C2d, f2d, l2d);
403
404     Geom2dAdaptor_Curve   G2dAC(C2d, f2d, l2d);
405     Handle(Geom2dAdaptor_HCurve) G2dAHC = new Geom2dAdaptor_HCurve(G2dAC);
406     
407     TopLoc_Location Loc;
408     Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, Loc, f3d,l3d);
409     if(!newE.IsNull()) {
410       C3d = BRep_Tool::Curve(newE, f3d, l3d);
411     }
412     else {
413       C3d = BRep_Tool::Curve(E,f3d,l3d);
414     }
415     GeomAdaptor_Curve   G3dAC(C3d, f3d, l3d);
416     Handle(GeomAdaptor_HCurve) G3dAHC = new GeomAdaptor_HCurve(G3dAC);
417     
418     Standard_Real Uinf, Usup, Vinf, Vsup, u = 0, v = 0;
419     Handle(Geom_Surface) S = BRep_Tool::Surface(F);
420     Handle(Standard_Type) myT = S->DynamicType();
421     if(myT != STANDARD_TYPE(Geom_Plane)) {
422       if(newF.IsNull()) {
423         Handle(Standard_Type) st = C2d->DynamicType();
424         if ((st == STANDARD_TYPE(Geom2d_BSplineCurve)) ||
425             (st == STANDARD_TYPE(Geom2d_BezierCurve))) {
426           if(isConvert2d) {
427             Curve2d = Handle(Geom2d_Curve)::DownCast(C2d->Copy());
428             return Standard_True;
429           }
430           return Standard_False;
431         }
432       }
433       else {
434         S = BRep_Tool::Surface(newF);
435         
436       }
437       S->Bounds(Uinf, Usup, Vinf, Vsup);
438       Uinf -= 1e-9; Usup += 1e-9; Vinf -= 1e-9; Vsup += 1e-9;
439       u = (Usup - Uinf)*0.1;
440       v = (Vsup - Vinf)*0.1;
441       if(S->IsUPeriodic()) {
442         Standard_Real uperiod = S->UPeriod();
443         if(uperiod < (Usup+2*u-Uinf)) {
444           if(uperiod <= (Usup-Uinf))  {
445             u = 0;
446           } 
447           else {
448             u = (uperiod-(Usup-Uinf))*0.5;
449           }
450         }
451       }
452       if(S->IsVPeriodic()) {
453         Standard_Real vperiod = S->VPeriod();
454         if(vperiod < (Vsup+2*v-Vinf)) {
455           if(vperiod <= (Vsup-Vinf)) {
456             v = 0;
457           }
458           else {
459             v = (vperiod-(Vsup-Vinf))*0.5;
460           }
461         }
462       }
463     }
464     else {
465       S = BRep_Tool::Surface(F);// Si S est un plan, pas de changement de parametrisation
466       GeomAdaptor_Surface GAS(S);
467       Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(GAS);
468       ProjLib_ComputeApprox ProjOnCurve(G3dAHC,GAHS,Tol);
469       if(ProjOnCurve.BSpline().IsNull()) {
470         Curve2d = Geom2dConvert::CurveToBSplineCurve(ProjOnCurve.Bezier());
471         return Standard_True;
472       }
473       Curve2d = ProjOnCurve.BSpline();
474       return Standard_True;
475     }
476     GeomAdaptor_Surface GAS(S,Uinf-u,Usup+u,Vinf-v,Vsup+v);
477
478     Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(GAS);
479
480     ProjLib_ComputeApproxOnPolarSurface ProjOnCurve(G2dAHC,G3dAHC,GAHS,Tol);
481
482     if(ProjOnCurve.IsDone()) {
483       Curve2d = ProjOnCurve.BSpline();
484       
485       return Standard_True;
486     }
487     else {
488       Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d);
489       return Standard_True;
490     }
491   }
492   else  {
493     TopTools_ListIteratorOfListOfShape itled;
494     TColStd_ListIteratorOfListOfTransient itlcu;
495     
496     for (itled.Initialize(myled), itlcu.Initialize(mylcu);
497          itled.More(); // itlcu.More()
498          itled.Next(),itlcu.Next()) {
499       if (itled.Value().IsSame(E)) {
500         // deja traitee
501         break;
502       }
503     }
504     if (!itled.More()) { // on stocke l`edge et la curve2d
505       Handle(Geom2d_Curve) C2dBis;
506       Standard_Real f3d,l3d,f2dBis,l2dBis;
507       C2d = new Geom2d_TrimmedCurve(C2d, f2d, l2d);
508       Geom2dAdaptor_Curve G2dAC(C2d, f2d, l2d);
509       Handle(Geom2dAdaptor_HCurve) G2dAHC = new Geom2dAdaptor_HCurve(G2dAC);
510       TopoDS_Edge ERevers = E;
511       ERevers.Reverse();
512 //      TopoDS_Edge ERevers = TopoDS::Edge(E.Reversed());
513       C2dBis = BRep_Tool::CurveOnSurface(ERevers,F,f2dBis,l2dBis);      
514       Handle(Standard_Type) TheTypeC2dBis = C2dBis->DynamicType();
515       C2dBis = new Geom2d_TrimmedCurve(C2dBis,f2dBis, l2dBis);
516       Geom2dAdaptor_Curve   G2dACBis(C2dBis, f2dBis, l2dBis); 
517       Handle(Geom2dAdaptor_HCurve) G2dAHCBis = new Geom2dAdaptor_HCurve(G2dACBis);
518       
519       TopLoc_Location Loc;
520       Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, f3d,l3d);
521       if(C3d.IsNull()) {
522          if(isConvert2d) {
523            Curve2d = Handle(Geom2d_Curve)::DownCast(C2d->Copy());
524            return Standard_True;
525          }
526         
527         return Standard_False;
528       }
529       if(!newE.IsNull()) {
530         C3d = BRep_Tool::Curve(newE, f3d,l3d);
531       }
532       GeomAdaptor_Curve G3dAC(C3d, f3d, l3d);
533       Handle(GeomAdaptor_HCurve) G3dAHC = new GeomAdaptor_HCurve(G3dAC);
534       
535       Handle(Geom_Surface) S = BRep_Tool::Surface(F);
536       Handle(Standard_Type) myT = S->DynamicType();
537       if(newF.IsNull()) {
538         mylcu.Append(C2dBis);
539         Handle(Standard_Type) st = C2d->DynamicType();
540         if ((st == STANDARD_TYPE(Geom2d_BSplineCurve)) ||
541             (st == STANDARD_TYPE(Geom2d_BezierCurve))) {
542           if(isConvert2d) {
543             Curve2d = Handle(Geom2d_Curve)::DownCast(C2d->Copy());
544             return Standard_True;
545           }
546           return Standard_False;
547         }
548       }
549       else {
550         S = BRep_Tool::Surface(newF);// S est une BSplineSurface : pas besoin de la trimmed
551       }
552       Standard_Real Uinf, Usup, Vinf, Vsup, u = 0, v = 0;
553       S->Bounds(Uinf, Usup, Vinf, Vsup);
554       Uinf -= 1e-9; Usup += 1e-9; Vinf -= 1e-9; Vsup += 1e-9;
555       u = (Usup - Uinf)*0.1;
556       v = (Vsup - Vinf)*0.1;
557       if(S->IsUPeriodic()) {
558         Standard_Real uperiod = S->UPeriod();
559         if(uperiod < (Usup+2*u-Uinf))
560           if(uperiod <= (Usup-Uinf))
561             u = 0;
562           else
563             u = (uperiod-(Usup-Uinf))*0.5;
564       }
565       if(S->IsVPeriodic()) {
566         Standard_Real vperiod = S->VPeriod();
567         if(vperiod < (Vsup+2*v-Vinf))
568           if(vperiod <= (Vsup-Vinf))
569             v = 0;
570           else
571             v = (vperiod-(Vsup-Vinf))*0.5;
572       }
573       GeomAdaptor_Surface GAS(S, Uinf-u,Usup+u,Vinf-v,Vsup+v);
574       Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(GAS);
575       myled.Append(E);
576
577       ProjLib_ComputeApproxOnPolarSurface 
578         ProjOnCurve(G2dAHC,G2dAHCBis,G3dAHC,GAHS,Tol);
579
580       if(ProjOnCurve.IsDone()) {
581         Curve2d = ProjOnCurve.BSpline();
582         mylcu.Append(ProjOnCurve.Curve2d());
583         return Standard_True;
584       }
585       else {
586         Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d);
587         mylcu.Append(C2dBis);
588         return Standard_True;
589       }
590     }
591     else { // on est au 2ieme tour 
592       C2d = Handle(Geom2d_Curve)::DownCast(itlcu.Value());
593       Handle(Standard_Type) st = C2d->DynamicType();
594       if (!(st == STANDARD_TYPE(Geom2d_BSplineCurve)) &&
595           !(st == STANDARD_TYPE(Geom2d_BezierCurve))) {
596         return Standard_False;
597       }
598       Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d);
599       return Standard_True;
600     }
601   }
602   Curve2d = C2d;
603   return Standard_True;
604 }
605
606 //=======================================================================
607 //function : NewParameter
608 //purpose  : 
609 //=======================================================================
610
611 Standard_Boolean BRepTools_NurbsConvertModification_21423::NewParameter
612    (const TopoDS_Vertex& V, 
613     const TopoDS_Edge& E, 
614     Standard_Real& P, 
615     Standard_Real& Tol)
616 {
617   if(BRep_Tool::Degenerated(E))
618     return Standard_False;
619   Standard_Real f, l, param = BRep_Tool::Parameter(V,E);
620   TopLoc_Location L;
621
622   Handle(Geom_Curve) gc = BRep_Tool::Curve(E, L, f, l);
623   if(!myMap.Contains(gc))
624     return Standard_False;
625
626   Handle(Geom_BSplineCurve) gcc = 
627     Handle(Geom_BSplineCurve)::DownCast(myMap.FindFromKey(gc));
628
629   gcc = Handle(Geom_BSplineCurve)::DownCast(gcc->Transformed(L.Transformation()));
630
631   GeomAdaptor_Curve ac(gcc);
632   gp_Pnt pnt = BRep_Tool::Pnt(V);
633
634   Extrema_LocateExtPC proj(pnt, ac, param, f, l, Tol);
635   if(proj.IsDone()) {
636     Standard_Real Dist2Min = proj.SquareDistance();
637     if (Dist2Min < Tol*Tol) {
638 //      Standard_Real U_final_point,V_final_point;
639       P = proj.Point().Parameter();
640       return Standard_True;
641     }
642   }
643   return Standard_False;
644 }
645
646 //=======================================================================
647 //function : Continuity
648 //purpose  : 
649 //=======================================================================
650
651 GeomAbs_Shape BRepTools_NurbsConvertModification_21423::Continuity
652   (const TopoDS_Edge& E,
653    const TopoDS_Face& F1,
654    const TopoDS_Face& F2,
655    const TopoDS_Edge&,
656    const TopoDS_Face&,
657    const TopoDS_Face&)
658 {
659   return BRep_Tool::Continuity(E,F1,F2);
660 }
661
662