0027772: Foundation Classes - define Standard_Boolean using C++ type "bool" instead...
[occt.git] / src / ChFi3d / ChFi3d_FilBuilder.cxx
1 // Created on: 1995-04-25
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 // Modified:    MPS :  (10-04-97) portage WNT pour GetFilletShape
18
19 #include <Adaptor3d_TopolTool.hxx>
20 #include <Blend_Point.hxx>
21 #include <BRepAdaptor_HCurve2d.hxx>
22 #include <BRepAdaptor_HSurface.hxx>
23 #include <BRepBlend_ConstRad.hxx>
24 #include <BRepBlend_ConstRadInv.hxx>
25 #include <BRepBlend_CurvPointRadInv.hxx>
26 #include <BRepBlend_EvolRad.hxx>
27 #include <BRepBlend_EvolRadInv.hxx>
28 #include <BRepBlend_Line.hxx>
29 #include <BRepBlend_RstRstConstRad.hxx>
30 #include <BRepBlend_RstRstEvolRad.hxx>
31 #include <BRepBlend_SurfCurvConstRadInv.hxx>
32 #include <BRepBlend_SurfCurvEvolRadInv.hxx>
33 #include <BRepBlend_SurfPointConstRadInv.hxx>
34 #include <BRepBlend_SurfPointEvolRadInv.hxx>
35 #include <BRepBlend_SurfRstConstRad.hxx>
36 #include <BRepBlend_SurfRstEvolRad.hxx>
37 #include <BRepBlend_Walking.hxx>
38 #include <ChFi3d_Builder_0.hxx>
39 #include <ChFi3d_FilBuilder.hxx>
40 #include <ChFi3d_SearchSing.hxx>
41 #include <ChFiDS_ErrorStatus.hxx>
42 #include <ChFiDS_FilSpine.hxx>
43 #include <ChFiDS_HData.hxx>
44 #include <ChFiDS_HElSpine.hxx>
45 #include <ChFiDS_ListIteratorOfListOfStripe.hxx>
46 #include <ChFiDS_ListIteratorOfRegularities.hxx>
47 #include <ChFiDS_ListOfStripe.hxx>
48 #include <ChFiDS_Regul.hxx>
49 #include <ChFiDS_SecHArray1.hxx>
50 #include <ChFiDS_Spine.hxx>
51 #include <ChFiDS_Stripe.hxx>
52 #include <ChFiDS_SurfData.hxx>
53 #include <ElSLib.hxx>
54 #include <Geom_Curve.hxx>
55 #include <GeomAdaptor_HCurve.hxx>
56 #include <gp_XY.hxx>
57 #include <Law_Composite.hxx>
58 #include <Law_Function.hxx>
59 #include <math_FunctionRoot.hxx>
60 #include <Precision.hxx>
61 #include <Standard_ConstructionError.hxx>
62 #include <Standard_Failure.hxx>
63 #include <TColStd_SequenceOfReal.hxx>
64 #include <TopoDS_Edge.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Vertex.hxx>
67 #include <TopOpeBRepBuild_HBuilder.hxx>
68 #include <TopOpeBRepDS_Curve.hxx>
69 #include <TopOpeBRepDS_HDataStructure.hxx>
70 #include <TopOpeBRepDS_Surface.hxx>
71 #include <TopTools_ListIteratorOfListOfShape.hxx>
72
73 #ifdef OCCT_DEBUG
74 #include <OSD_Chronometer.hxx>
75 extern Standard_Boolean ChFi3d_GettraceCHRON();
76 extern Standard_Real  t_computedata ,t_completedata; 
77                     
78 extern void ChFi3d_InitChron(OSD_Chronometer& ch);
79 extern void ChFi3d_ResultChron(OSD_Chronometer & ch,Standard_Real& time);
80 #endif
81
82 static Standard_Real MaxRad(const Handle(ChFiDS_FilSpine)& fsp,
83         
84                             const TopoDS_Edge& E) 
85 {
86   Standard_Integer IE = fsp->Index(E);
87
88   // 1: case of constant R
89   if (fsp->IsConstant(IE))
90     return (fsp->Radius(IE));
91   else // 2,3: case of sequence ParAndRad and(or) Laws
92     return (fsp->MaxRadFromSeqAndLaws());
93
94 /*
95  Handle(ChFiDS_HElSpine) HGuide = fsp->ElSpine(IE);
96  Standard_Real la = HGuide->LastParameter(), fi = HGuide->FirstParameter();
97  Standard_Real longueur = la - fi,  temp, w;
98 //#ifndef OCCT_DEBUG
99  Standard_Real radiussect = 0.;
100 //#else
101 // Standard_Real radiussect;
102 //#endif
103  Handle(Law_Composite) lc = fsp->Law(HGuide);
104  for(Standard_Integer i = 0; i <= 5; i++){ 
105    w = fi + i*longueur*0.2;
106    temp = lc->Value(w);
107    if(temp>radiussect) radiussect = temp;
108  }
109  return  radiussect;
110 */
111 }
112
113 static void SimulParams(const Handle(ChFiDS_HElSpine)& HGuide,
114                         const Handle(ChFiDS_FilSpine)& fsp,
115                         Standard_Real&                 MaxStep,
116                         Standard_Real&                 Fleche)
117 {
118   Standard_Real la = HGuide->LastParameter(), fi = HGuide->FirstParameter();
119   Standard_Real longueur = la - fi;
120   MaxStep = longueur * 0.05;
121   Standard_Real w;
122   //gp_Pnt Pbid;
123   //gp_Vec d1,d2;
124   Standard_Real radiussect;
125   if(fsp->IsConstant()) radiussect = fsp->Radius();
126   else {
127     radiussect = 0.;
128     Handle(Law_Composite) lc = fsp->Law(HGuide);
129     for(Standard_Integer i = 0; i <= 5; i++){ 
130       w = fi + i*longueur*0.2;
131       Standard_Real temp = lc->Value(w);
132       if(temp>radiussect) radiussect = temp;
133     }
134   }
135   Fleche = radiussect * 0.05;
136 }
137
138 //=======================================================================
139 //function : ChFi3d_FilBuilder
140 //purpose  : 
141 //=======================================================================
142
143 ChFi3d_FilBuilder::ChFi3d_FilBuilder(const TopoDS_Shape& S,
144                                      const ChFi3d_FilletShape FShape,
145                                      const Standard_Real Ta):
146                                      ChFi3d_Builder(S, Ta)
147 {
148   SetFilletShape(FShape);
149 }
150
151 //=======================================================================
152 //function : SetFilletShape
153 //purpose  : 
154 //=======================================================================
155
156 void ChFi3d_FilBuilder::SetFilletShape(const ChFi3d_FilletShape FShape)
157 {
158   switch (FShape) {
159   case ChFi3d_Rational:
160     myShape = BlendFunc_Rational;
161     break;
162   case ChFi3d_QuasiAngular:
163     myShape = BlendFunc_QuasiAngular;
164     break;
165   case ChFi3d_Polynomial:
166     myShape = BlendFunc_Polynomial;
167     break;
168   }
169 }
170
171 //=======================================================================
172 //function : GetFilletShape
173 //purpose  : 
174 //=======================================================================
175
176 ChFi3d_FilletShape ChFi3d_FilBuilder::GetFilletShape() const
177 {
178   ChFi3d_FilletShape filshape = ChFi3d_Rational; //  need to set default value
179   switch (myShape) {
180   case BlendFunc_Rational:
181     filshape= ChFi3d_Rational;
182     break;
183   case BlendFunc_QuasiAngular:
184     filshape= ChFi3d_QuasiAngular;
185     break;
186   case BlendFunc_Polynomial:
187     filshape= ChFi3d_Polynomial;
188     break;
189   default:
190     break;
191   }
192   return filshape;
193 }
194
195 //=======================================================================
196 //function : Add
197 //purpose  : 
198 //=======================================================================
199
200 void  ChFi3d_FilBuilder::Add(const TopoDS_Edge& E)
201 {
202   if(!Contains(E) && myEFMap.Contains(E)){
203     Handle(ChFiDS_Stripe) Stripe = new ChFiDS_Stripe();
204     Handle(ChFiDS_Spine)& Sp = Stripe->ChangeSpine();
205     Sp = new ChFiDS_FilSpine(tolesp);
206     Handle(ChFiDS_FilSpine) Spine = Handle(ChFiDS_FilSpine)::DownCast(Sp);
207
208     TopoDS_Edge E_wnt = E;
209     E_wnt.Orientation(TopAbs_FORWARD);
210     Spine->SetEdges(E_wnt);
211     if(PerformElement(Spine)){
212       PerformExtremity(Spine);
213       Spine->Load();
214       myListStripe.Append(Stripe);
215     }
216   }
217 }
218
219 //=======================================================================
220 //function : Add
221 //purpose  : 
222 //=======================================================================
223
224 void  ChFi3d_FilBuilder::Add(const Standard_Real Radius, const TopoDS_Edge& E)
225 {
226   Add(E);
227   Standard_Integer IC = Contains(E);
228   if (IC)
229     SetRadius( Radius, IC, E );
230 }
231
232 //=======================================================================
233 //function : SetRadius
234 //purpose  : 
235 //=======================================================================
236
237 void  ChFi3d_FilBuilder::SetRadius(const Handle(Law_Function)& C, 
238                                    const Standard_Integer IC,
239                                    const Standard_Integer IinC)
240 {
241   if(IC <= NbElements()) {
242     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
243     fsp->SetRadius(C, IinC);
244   }
245 }
246
247 //=======================================================================
248 //function : IsConstant
249 //purpose  : 
250 //=======================================================================
251
252 Standard_Boolean ChFi3d_FilBuilder::IsConstant(const Standard_Integer IC)
253 {
254   if(IC <= NbElements()) {
255     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
256     return fsp->IsConstant();
257   }
258   return 0;
259 }
260
261 //=======================================================================
262 //function : Radius
263 //purpose  : 
264 //=======================================================================
265
266 Standard_Real ChFi3d_FilBuilder::Radius(const Standard_Integer IC)
267 {
268   if(IC <= NbElements()) {
269     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
270     return fsp->Radius();
271   }
272   return -1.;
273 }
274
275 //=======================================================================
276 //function : ResetContour
277 //purpose  : 
278 //=======================================================================
279
280 void  ChFi3d_FilBuilder::ResetContour(const Standard_Integer IC)
281 {
282   if(IC <= NbElements()) {
283     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
284     fsp->Reset(Standard_True);
285   }
286 }
287
288 //=======================================================================
289 //function : SetRadius
290 //purpose  : 
291 //=======================================================================
292
293 void  ChFi3d_FilBuilder::SetRadius(const Standard_Real    Radius, 
294                                    const Standard_Integer IC,
295                                    const TopoDS_Edge&     E)
296 {
297   if(IC <= NbElements()) {
298     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
299     fsp->SetRadius(Radius, E);
300   }
301 }
302
303 //=======================================================================
304 //function : UnSet
305 //purpose  : 
306 //=======================================================================
307
308 void  ChFi3d_FilBuilder::UnSet(const Standard_Integer IC,
309                                const TopoDS_Edge&     E)
310 {
311   if(IC <= NbElements()) {
312     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
313     fsp->UnSetRadius(E);
314   }
315 }
316
317 //=======================================================================
318 //function : SetRadius
319 //purpose  : 
320 //=======================================================================
321
322 void  ChFi3d_FilBuilder::SetRadius(const Standard_Real    Radius, 
323                                    const Standard_Integer IC,
324                                    const TopoDS_Vertex&   V)
325 {
326   if(IC <= NbElements()) {
327     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
328     fsp->SetRadius(Radius, V);
329   }
330 }
331
332 //=======================================================================
333 //function : UnSet
334 //purpose  : 
335 //=======================================================================
336
337 void  ChFi3d_FilBuilder::UnSet(const Standard_Integer IC,
338                                const TopoDS_Vertex&   V)
339 {
340   if(IC <= NbElements()) {
341     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
342     fsp->UnSetRadius(V);
343   }
344 }
345
346 //=======================================================================
347 //function : SetRadius
348 //purpose  : 
349 //=======================================================================
350
351 void  ChFi3d_FilBuilder::SetRadius(const gp_XY&           UandR, 
352                                    const Standard_Integer IC,
353                                    const Standard_Integer IinC)
354 {
355   if(IC <= NbElements()) {
356     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
357     fsp->SetRadius( UandR, IinC );
358   }
359 }
360
361 //=======================================================================
362 //function : IsConstant
363 //purpose  : 
364 //=======================================================================
365
366 Standard_Boolean ChFi3d_FilBuilder::IsConstant(const Standard_Integer IC,
367                                                const TopoDS_Edge&     E)
368 {
369   if(IC <= NbElements()) {
370     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
371     return fsp->IsConstant(fsp->Index(E));
372   }
373   return 0;
374 }
375
376 //=======================================================================
377 //function : Radius
378 //purpose  : 
379 //=======================================================================
380
381 Standard_Real ChFi3d_FilBuilder::Radius(const Standard_Integer IC,
382                                         const TopoDS_Edge&     E)
383 {
384   if(IC <= NbElements()) {
385     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
386     return fsp->Radius(E);
387   }
388   return -1.;
389 }
390
391 //=======================================================================
392 //function : GetBounds
393 //purpose  : 
394 //=======================================================================
395
396 Standard_Boolean ChFi3d_FilBuilder::GetBounds(const Standard_Integer IC,
397                                               const TopoDS_Edge&     E,
398                                               Standard_Real&         F,
399                                               Standard_Real&         L)
400 {
401   if(IC <= NbElements()) {
402     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
403     Handle(Law_Function)& loi = fsp->ChangeLaw(E);
404     if(!loi.IsNull()){
405       loi->Bounds(F,L);
406       return Standard_True;
407     }
408   }
409   return Standard_False;
410 }
411
412 //=======================================================================
413 //function : GetLaw
414 //purpose  : 
415 //=======================================================================
416
417 Handle(Law_Function) ChFi3d_FilBuilder::GetLaw(const Standard_Integer IC,
418                                                const TopoDS_Edge&     E)
419 {
420   if(IC <= NbElements()) {
421     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
422     return fsp->ChangeLaw(E);
423   }
424   return Handle(Law_Function)();
425 }
426
427 //=======================================================================
428 //function : SetLaw
429 //purpose  : 
430 //=======================================================================
431
432 void ChFi3d_FilBuilder::SetLaw(const Standard_Integer      IC,
433                                const TopoDS_Edge&          E,
434                                const Handle(Law_Function)& L)
435 {
436   // Check if it is necessary to check borders!
437   if(IC <= NbElements()) {
438     Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Value(IC));
439     fsp->ChangeLaw(E) = L;
440   }
441 }
442
443 //=======================================================================
444 //function : Simulate
445 //purpose  : 
446 //=======================================================================
447
448 void ChFi3d_FilBuilder::Simulate (const Standard_Integer IC)
449 {
450 #ifdef OCCT_DEBUG
451   if(ChFi3d_GettraceCHRON()){
452     simul.Reset();elspine.Reset();chemine.Reset();
453     simul.Start();
454   }
455 #endif
456   ChFiDS_ListIteratorOfListOfStripe itel;
457   Standard_Integer i = 1;
458   for (itel.Initialize(myListStripe);itel.More(); itel.Next(), i++) {
459     if(i == IC){
460       PerformSetOfSurf(itel.Value(), Standard_True);
461       break;
462     }
463   }
464 #ifdef OCCT_DEBUG
465   if(ChFi3d_GettraceCHRON()){
466     simul.Stop();
467     cout<<"Total simulation time : ";
468     simul.Show();
469     cout<<"Spine construction time : ";
470     elspine.Show();
471     cout<<"and process time : ";
472     chemine.Show();
473   }
474 #endif
475 }
476
477 //=======================================================================
478 //function : NbSurf
479 //purpose  : 
480 //=======================================================================
481
482 Standard_Integer ChFi3d_FilBuilder::NbSurf (const Standard_Integer IC) const 
483 {
484   ChFiDS_ListIteratorOfListOfStripe itel;
485   Standard_Integer i = 1;
486   for (itel.Initialize(myListStripe);itel.More(); itel.Next(), i++) {
487     if(i == IC){
488       return itel.Value()->SetOfSurfData()->Length();
489     }
490   }
491   return 0;
492 }
493
494 //=======================================================================
495 //function : Sect
496 //purpose  : 
497 //=======================================================================
498
499 Handle(ChFiDS_SecHArray1) ChFi3d_FilBuilder::Sect (const Standard_Integer IC,
500                                                    const Standard_Integer IS) const 
501 {
502   ChFiDS_ListIteratorOfListOfStripe itel;
503   Standard_Integer i = 1;
504   Handle(ChFiDS_SecHArray1) res;
505   for (itel.Initialize(myListStripe);itel.More(); itel.Next(), i++) {
506     if(i == IC){
507       Handle(MMgt_TShared) bid = itel.Value()->SetOfSurfData()->Value(IS)->Simul();
508       res = Handle(ChFiDS_SecHArray1)::DownCast(bid);
509       return res;
510     }
511   }
512   return Handle(ChFiDS_SecHArray1)();
513 }
514
515 //=======================================================================
516 //function : SimulKPart
517 //purpose  : 
518 //=======================================================================
519
520 void  ChFi3d_FilBuilder::SimulKPart(const Handle(ChFiDS_SurfData)& SD) const 
521 {
522   TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
523   Handle(Geom_Surface) S = DStr.Surface(SD->Surf()).Surface();
524   gp_Pnt2d p1f = SD->InterferenceOnS1().PCurveOnSurf()->
525     Value(SD->InterferenceOnS1().FirstParameter());
526   gp_Pnt2d p1l = SD->InterferenceOnS1().PCurveOnSurf()->
527     Value(SD->InterferenceOnS1().LastParameter());
528   gp_Pnt2d p2f = SD->InterferenceOnS2().PCurveOnSurf()->
529     Value(SD->InterferenceOnS2().FirstParameter());
530   gp_Pnt2d p2l = SD->InterferenceOnS2().PCurveOnSurf()->
531     Value(SD->InterferenceOnS2().LastParameter());
532   GeomAdaptor_Surface AS(S);
533   Handle(ChFiDS_SecHArray1) sec;
534   Standard_Real u1,v1,u2,v2;
535   GeomAbs_SurfaceType typ = AS.GetType();
536   switch (typ){
537   case GeomAbs_Cylinder: 
538     {
539       u1 = p1f.X();
540       u2 = p2f.X();
541       v1 = Max(p1f.Y(),p2f.Y());
542       v2 = Min(p1l.Y(),p2l.Y());
543       sec = new ChFiDS_SecHArray1(1,2);
544       gp_Cylinder Cy = AS.Cylinder();
545       ChFiDS_CircSection& sec1 = sec->ChangeValue(1);
546       ChFiDS_CircSection& sec2 = sec->ChangeValue(2);
547       sec1.Set(ElSLib::CylinderVIso(Cy.Position(), Cy.Radius(), v1), u1, u2);  
548       sec2.Set(ElSLib::CylinderVIso(Cy.Position(), Cy.Radius(), v2), u1, u2);  
549     }
550     break;
551   case GeomAbs_Torus:
552     {
553       v1 = p1f.Y();
554       v2 = p2f.Y();
555       u1 = Max(p1f.X(),p2f.X());
556       u2 = Min(p1l.X(),p2l.X());
557       Standard_Real ang = (u2-u1);
558       gp_Torus To = AS.Torus();
559       Standard_Real majr = To.MajorRadius(), minr = To.MinorRadius();
560       Standard_Integer n = (Standard_Integer) (36.*ang/M_PI + 1);
561       if(n<2) n = 2;
562       sec = new ChFiDS_SecHArray1(1, n);
563       for (Standard_Integer i = 1; i <= n; i++) {
564         ChFiDS_CircSection& isec = sec->ChangeValue(i);
565         Standard_Real u = u1 + (i - 1)*(u2 - u1)/(n-1);
566         isec.Set(ElSLib::TorusUIso(To.Position(), majr, minr, u), v1, v2);  
567       }
568     }
569     break;
570   case GeomAbs_Sphere:
571     {
572       v1 = p1f.Y();
573       v2 = p2f.Y();
574       u1 = Max(p1f.X(),p2f.X());
575       u2 = Min(p1l.X(),p2l.X());
576       Standard_Real ang = (u2-u1);
577       gp_Sphere Sp = AS.Sphere();
578       Standard_Real rad = Sp.Radius();
579       Standard_Integer n = (Standard_Integer) (36.*ang/M_PI + 1);
580       if(n<2) n = 2;
581       sec = new ChFiDS_SecHArray1(1, n);
582       for (Standard_Integer i = 1; i <= n; i++) {
583         ChFiDS_CircSection& isec = sec->ChangeValue(i);
584         Standard_Real u = u1 + (i - 1)*(u2 - u1)/(n-1);
585         isec.Set(ElSLib::SphereUIso(Sp.Position(), rad, u), v1, v2);  
586       }
587     }
588     break;
589   default:
590     break;
591   }
592   SD->SetSimul(sec);
593 }
594
595
596 //=======================================================================
597 //function : SimulSurf
598 //purpose  : 
599 //=======================================================================
600
601 Standard_Boolean  
602 ChFi3d_FilBuilder::SimulSurf(Handle(ChFiDS_SurfData)&            Data,
603                              const Handle(ChFiDS_HElSpine)&      HGuide,
604                              const Handle(ChFiDS_Spine)&         Spine,
605                              const Standard_Integer              Choix,
606                              const Handle(BRepAdaptor_HSurface)& S1,
607                              const Handle(Adaptor3d_TopolTool)&    I1,
608                              const Handle(BRepAdaptor_HSurface)& S2,
609                              const Handle(Adaptor3d_TopolTool)&    I2,
610                              const Standard_Real                 TolGuide,
611                              Standard_Real&                      First,
612                              Standard_Real&                      Last,
613                              const Standard_Boolean              Inside,
614                              const Standard_Boolean              Appro,
615                              const Standard_Boolean              Forward,
616                              const Standard_Boolean              RecOnS1,
617                              const Standard_Boolean              RecOnS2,
618                              const math_Vector&                  Soldep,
619                              Standard_Integer&                   intf,
620                              Standard_Integer&                   intl)
621 {
622   Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Spine);
623   if(fsp.IsNull()) Standard_ConstructionError::Raise
624     ("SimulSurf : this is not the spine of the fillet");
625   Handle(BRepBlend_Line) lin;
626 #ifdef OCCT_DEBUG
627 //  TopAbs_Orientation Or = S1->ChangeSurface().Face().Orientation();
628 #endif
629   // Flexible parameters!!!
630   Standard_Real locfleche, MaxStep;
631   SimulParams(HGuide,fsp,MaxStep,locfleche);
632   Handle(ChFiDS_SecHArray1) sec;
633   gp_Pnt2d pf1,pl1,pf2,pl2;
634
635   Standard_Real PFirst = First;
636   if(intf) First = fsp->FirstParameter(1);
637   if(intl) Last = fsp->LastParameter(fsp->NbEdges());
638   if (fsp->IsConstant()) {
639     BRepBlend_ConstRad Func(S1,S2,HGuide);
640     BRepBlend_ConstRadInv FInv(S1,S2,HGuide);
641     Func.Set(fsp->Radius(),Choix);
642     FInv.Set(fsp->Radius(),Choix);
643     Func.Set(myShape);
644     done = SimulData(Data,HGuide,lin,S1,I1 ,
645                      S2,I2,Func,FInv,PFirst,MaxStep,locfleche,
646                      TolGuide,First,Last,Inside,Appro,Forward,
647                      Soldep,4,RecOnS1,RecOnS2);
648     if(!done) return Standard_False;
649     Standard_Integer nbp = lin->NbPoints();
650     sec = new ChFiDS_SecHArray1(1,nbp);
651     for(Standard_Integer i = 1; i <= nbp; i++){
652       ChFiDS_CircSection& isec = sec->ChangeValue(i);
653       Standard_Real u1,v1,u2,v2,w,p1,p2;
654       gp_Circ ci;
655       const Blend_Point& p = lin->Point(i);
656       p.ParametersOnS1(u1,v1);
657       p.ParametersOnS2(u2,v2);
658       w = p.Parameter();
659       Func.Section(w,u1,v1,u2,v2,p1,p2,ci);
660       isec.Set(ci,p1,p2);
661       if(i == 1) {pf1.SetCoord(u1,v1); pf2.SetCoord(u2,v2);} 
662       if(i == nbp) {pl1.SetCoord(u1,v1); pl2.SetCoord(u2,v2);} 
663     }
664   }
665   else{
666     BRepBlend_EvolRad Func(S1,S2,HGuide,fsp->Law(HGuide));
667     BRepBlend_EvolRadInv FInv(S1,S2,HGuide,fsp->Law(HGuide));
668     Func.Set(Choix);
669     FInv.Set(Choix);
670     Func.Set(myShape);
671     done = SimulData(Data,HGuide,lin,S1,I1 ,
672                      S2,I2,Func,FInv,PFirst,MaxStep,locfleche,
673                      TolGuide,First,Last,Inside,Appro,Forward,
674                      Soldep,4,RecOnS1,RecOnS2);
675     if(!done) return Standard_False;
676     Standard_Integer nbp = lin->NbPoints();
677     sec = new ChFiDS_SecHArray1(1,nbp);
678     for(Standard_Integer i = 1; i <= nbp; i++){
679       ChFiDS_CircSection& isec = sec->ChangeValue(i);
680       Standard_Real u1,v1,u2,v2,w,p1,p2;
681       gp_Circ ci;
682       const Blend_Point& p = lin->Point(i);
683       p.ParametersOnS1(u1,v1);
684       p.ParametersOnS2(u2,v2);
685       w = p.Parameter();
686       Func.Section(w,u1,v1,u2,v2,p1,p2,ci);
687       isec.Set(ci,p1,p2);
688       if(i == 1) {pf1.SetCoord(u1,v1); pf2.SetCoord(u2,v2);} 
689       if(i == nbp) {pl1.SetCoord(u1,v1); pl2.SetCoord(u2,v2);} 
690     }
691   }
692   Data->SetSimul(sec);
693   Data->Set2dPoints(pf1,pl1,pf2,pl2);
694   ChFi3d_FilCommonPoint(lin->StartPointOnFirst(),lin->TransitionOnS1(),
695                         Standard_True, Data->ChangeVertexFirstOnS1(),tolesp);
696   ChFi3d_FilCommonPoint(lin->EndPointOnFirst(),lin->TransitionOnS1(),
697                         Standard_False,Data->ChangeVertexLastOnS1(),tolesp);
698   ChFi3d_FilCommonPoint(lin->StartPointOnSecond(),lin->TransitionOnS2(),
699                         Standard_True, Data->ChangeVertexFirstOnS2(),tolesp);
700   ChFi3d_FilCommonPoint(lin->EndPointOnSecond(),lin->TransitionOnS2(),
701                         Standard_False, Data->ChangeVertexLastOnS2(),tolesp);
702   Standard_Boolean reverse = (!Forward || Inside);
703   if(intf && reverse){
704     Standard_Boolean ok = Standard_False;
705     const ChFiDS_CommonPoint& cp1 = Data->VertexFirstOnS1();
706     if(cp1.IsOnArc()){
707       TopoDS_Face F1 = S1->ChangeSurface().Face();
708       TopoDS_Face bid;
709       intf = !SearchFace(Spine,cp1,F1,bid);
710       ok = intf != 0;
711     }
712     const ChFiDS_CommonPoint& cp2 = Data->VertexFirstOnS2();
713     if(cp2.IsOnArc() && !ok){
714       TopoDS_Face F2 = S2->ChangeSurface().Face();
715       TopoDS_Face bid;
716       intf = !SearchFace(Spine,cp2,F2,bid);
717     }
718   }
719   if(intl){
720     Standard_Boolean ok = 0;
721     const ChFiDS_CommonPoint& cp1 = Data->VertexLastOnS1();
722     if(cp1.IsOnArc()){
723       TopoDS_Face F1 = S1->ChangeSurface().Face();
724       TopoDS_Face bid;
725       intl = !SearchFace(Spine,cp1,F1,bid);
726       ok = intl != 0;
727     }
728     const ChFiDS_CommonPoint& cp2 = Data->VertexLastOnS2();
729     if(cp2.IsOnArc() && !ok){
730       TopoDS_Face F2 = S2->ChangeSurface().Face();
731       TopoDS_Face bid;
732       intl = !SearchFace(Spine,cp2,F2,bid);
733     }
734   }
735   return Standard_True;
736 }
737
738 //=======================================================================
739 //function : SimulSurf
740 //purpose  : 
741 //=======================================================================
742
743 void  ChFi3d_FilBuilder::SimulSurf(Handle(ChFiDS_SurfData)&            Data,
744                                    const Handle(ChFiDS_HElSpine)&      HGuide,
745                                    const Handle(ChFiDS_Spine)&         Spine,
746                                    const Standard_Integer              Choix,
747                                    const Handle(BRepAdaptor_HSurface)& HS1,
748                                    const Handle(Adaptor3d_TopolTool)&    I1,
749                                    const Handle(BRepAdaptor_HCurve2d)& PC1,
750                                    const Handle(BRepAdaptor_HSurface)& HSref1,
751                                    const Handle(BRepAdaptor_HCurve2d)& PCref1,
752                                    Standard_Boolean&                   Decroch1,
753                                    const Handle(BRepAdaptor_HSurface)& HS2,
754                                    const Handle(Adaptor3d_TopolTool)&    I2,
755                                    const TopAbs_Orientation            Or2,
756                                    const Standard_Real                 /*Fleche*/,
757                                    const Standard_Real                 TolGuide,
758                                    Standard_Real&                      First,
759                                    Standard_Real&                      Last,
760                                    const Standard_Boolean              Inside,
761                                    const Standard_Boolean              Appro,
762                                    const Standard_Boolean              Forward,
763                                    const Standard_Boolean              RecP,
764                                    const Standard_Boolean              RecS,
765                                    const Standard_Boolean              RecRst,
766                                    const math_Vector&                  Soldep)
767 {
768   Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Spine);
769   if(fsp.IsNull()) Standard_ConstructionError::Raise
770     ("PerformSurf : this is not the spine of the fillet");
771   Handle(BRepBlend_Line) lin;
772   
773   // Flexible parameters!
774   Standard_Real locfleche, MaxStep;
775   SimulParams(HGuide,fsp,MaxStep,locfleche);
776   Handle(ChFiDS_SecHArray1) sec;
777   gp_Pnt2d pf,pl,ppcf,ppcl;
778   
779   Standard_Real PFirst = First;
780   if(fsp->IsConstant()){
781     BRepBlend_SurfRstConstRad func(HS2,HS1,PC1,HGuide);
782     func.Set(HSref1,PCref1);
783     Handle(Adaptor3d_HCurveOnSurface) HC = new Adaptor3d_HCurveOnSurface();
784     HC->ChangeCurve().Load(PC1, HS1);
785     BRepBlend_SurfCurvConstRadInv finvc(HS2,HC,HGuide);
786     BRepBlend_SurfPointConstRadInv finvp(HS2,HGuide);
787     BRepBlend_ConstRadInv finv(HS2,HSref1,HGuide);
788     finv.Set(Standard_False,PCref1);
789     
790     Standard_Real rad = fsp->Radius();
791     Standard_Integer petitchoix = 1;
792     if(Or2 == TopAbs_REVERSED) petitchoix = 3;
793     if(Choix%2 == 0) petitchoix++;
794     finv.Set(rad,Choix);
795     finvc.Set(rad,petitchoix);
796     finvp.Set(rad,petitchoix);
797     func.Set(rad,petitchoix);
798     func.Set(myShape);
799     
800     done = SimulData(Data,HGuide,lin,HS2,I2,HS1,PC1,I1,Decroch1,
801                      func,finv,finvp,finvc,
802                      PFirst,MaxStep,locfleche,TolGuide,First,Last,
803                      Soldep,4,Inside,Appro,Forward,RecP,RecS,RecRst);
804     if(!done) {
805       Standard_Failure::Raise("SimulSurf : Failed process!");
806     }
807     Standard_Integer nbp = lin->NbPoints();
808     sec = new ChFiDS_SecHArray1(1,nbp);
809     for(Standard_Integer i = 1; i <= nbp; i++){
810       ChFiDS_CircSection& isec = sec->ChangeValue(i);
811       Standard_Real u,v,w,param,p1,p2;
812       gp_Circ ci;
813       const Blend_Point& p = lin->Point(i);
814       p.ParametersOnS(u,v);
815       w = p.ParameterOnC();
816       param = p.Parameter();
817       func.Section(param,u,v,w,p1,p2,ci);
818       isec.Set(ci,p1,p2);
819       if(i == 1) {pf.SetCoord(u,v);p.ParametersOnS2(u,v);ppcf.SetCoord(u,v);} 
820       if(i == nbp) {pl.SetCoord(u,v);p.ParametersOnS2(u,v);ppcl.SetCoord(u,v);} 
821     }
822   }
823   else {
824     BRepBlend_SurfRstEvolRad func(HS2,HS1,PC1,HGuide,fsp->Law(HGuide));
825     Handle(Adaptor3d_HCurveOnSurface) HC = new Adaptor3d_HCurveOnSurface();
826     HC->ChangeCurve().Load(PC1, HS1);
827     BRepBlend_SurfCurvEvolRadInv finvc(HS2,HC,HGuide,fsp->Law(HGuide));
828     BRepBlend_SurfPointEvolRadInv finvp(HS2,HGuide,fsp->Law(HGuide));
829     BRepBlend_EvolRadInv finv(HS2,HSref1,HGuide,fsp->Law(HGuide));
830     finv.Set(Standard_False,PCref1);
831     Standard_Integer petitchoix = 1;
832     if(Or2 == TopAbs_REVERSED) petitchoix = 3;
833     if(Choix%2 == 0) petitchoix++;
834     finv.Set(Choix);
835     finvc.Set(petitchoix);
836     finvp.Set(petitchoix);
837     func.Set(petitchoix);
838     func.Set(myShape);
839     done = SimulData(Data,HGuide,lin,HS2,I2,HS1,PC1,I1,Decroch1,
840                      func,finv,finvp,finvc,
841                      PFirst,MaxStep,locfleche,TolGuide,First,Last,
842                      Soldep,4,Inside,Appro,Forward,RecP,RecS,RecRst);
843     if(!done) Standard_Failure::Raise("SimulSurf : Fail !");
844     Standard_Integer nbp = lin->NbPoints();
845     sec = new ChFiDS_SecHArray1(1,nbp);
846     for(Standard_Integer i = 1; i <= nbp; i++){
847       ChFiDS_CircSection& isec = sec->ChangeValue(i);
848       Standard_Real u,v,w,param,p1,p2;
849       gp_Circ ci;
850       const Blend_Point& p = lin->Point(i);
851       p.ParametersOnS(u,v);
852       w = p.ParameterOnC();
853       param = p.Parameter();
854       func.Section(param,u,v,w,p1,p2,ci);
855       isec.Set(ci,p1,p2);
856       if(i == 1) {pf.SetCoord(u,v);p.ParametersOnS2(u,v);ppcf.SetCoord(u,v);} 
857       if(i == nbp) {pl.SetCoord(u,v);p.ParametersOnS2(u,v);ppcl.SetCoord(u,v);} 
858     }
859   }
860   Data->SetSimul(sec);
861 //  gp_Pnt2d pbid;
862   Data->Set2dPoints(ppcf,ppcl,pf,pl);
863   ChFi3d_FilCommonPoint(lin->StartPointOnFirst(),lin->TransitionOnS1(),
864                         Standard_True, Data->ChangeVertexFirstOnS2(),tolesp);
865   ChFi3d_FilCommonPoint(lin->EndPointOnFirst(),lin->TransitionOnS1(),
866                         Standard_False,Data->ChangeVertexLastOnS2(),tolesp);
867   ChFi3d_FilCommonPoint(lin->StartPointOnSecond(),lin->TransitionOnS2(),
868                         Standard_True, Data->ChangeVertexFirstOnS1(),tolesp);
869   ChFi3d_FilCommonPoint(lin->EndPointOnSecond(),lin->TransitionOnS2(),
870                         Standard_False, Data->ChangeVertexLastOnS1(),tolesp);
871 }
872
873 //=======================================================================
874 //function : SimulSurf
875 //purpose  : 
876 //=======================================================================
877
878 void  ChFi3d_FilBuilder::SimulSurf(Handle(ChFiDS_SurfData)&            Data,
879                                    const Handle(ChFiDS_HElSpine)&      HGuide,
880                                    const Handle(ChFiDS_Spine)&         Spine,
881                                    const Standard_Integer              Choix,
882                                    const Handle(BRepAdaptor_HSurface)& HS1,
883                                    const Handle(Adaptor3d_TopolTool)&    I1,
884                                    const TopAbs_Orientation            Or1,
885                                    const Handle(BRepAdaptor_HSurface)& HS2,
886                                    const Handle(Adaptor3d_TopolTool)&    I2,
887                                    const Handle(BRepAdaptor_HCurve2d)& PC2,
888                                    const Handle(BRepAdaptor_HSurface)& HSref2,
889                                    const Handle(BRepAdaptor_HCurve2d)& PCref2,
890                                    Standard_Boolean&                   Decroch2,
891                                    const Standard_Real                 /*Arrow*/,
892                                    const Standard_Real                 TolGuide,
893                                    Standard_Real&                      First,
894                                    Standard_Real&                      Last,
895                                    const Standard_Boolean              Inside,
896                                    const Standard_Boolean              Appro,
897                                    const Standard_Boolean              Forward,
898                                    const Standard_Boolean              RecP,
899                                    const Standard_Boolean              RecS,
900                                    const Standard_Boolean              RecRst,
901                                    const math_Vector&                  Soldep)
902 {
903   Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Spine);
904   if(fsp.IsNull()) Standard_ConstructionError::Raise
905     ("PerformSurf : it is not the spine of a fillet");
906   Handle(BRepBlend_Line) lin;
907   
908   // Flexible parameters!
909   Standard_Real locfleche, MaxStep;
910   SimulParams(HGuide,fsp,MaxStep,locfleche);
911   Handle(ChFiDS_SecHArray1) sec;
912   gp_Pnt2d pf,pl,ppcf,ppcl;
913   
914   Standard_Real PFirst = First;
915   if(fsp->IsConstant()){
916     BRepBlend_SurfRstConstRad func(HS1,HS2,PC2,HGuide);
917     func.Set(HSref2,PCref2);
918     Handle(Adaptor3d_HCurveOnSurface) HC = new Adaptor3d_HCurveOnSurface();
919     HC->ChangeCurve().Load(PC2, HS2);
920     BRepBlend_SurfCurvConstRadInv finvc(HS1,HC,HGuide);
921     BRepBlend_SurfPointConstRadInv finvp(HS1,HGuide);
922     BRepBlend_ConstRadInv finv(HS1,HSref2,HGuide);
923     finv.Set(Standard_False,PCref2);
924     
925     Standard_Real rad = fsp->Radius();
926     Standard_Integer petitchoix = 1;
927     if(Or1 == TopAbs_REVERSED) petitchoix = 3;
928     if(Choix%2 == 0) petitchoix++;
929     finv.Set(rad,Choix);
930     finvc.Set(rad,petitchoix);
931     finvp.Set(rad,petitchoix);
932     func.Set(rad,petitchoix);
933     func.Set(myShape);
934     
935     done = SimulData(Data,HGuide,lin,HS1,I1,HS2,PC2,I2,Decroch2,
936                      func,finv,finvp,finvc,
937                      PFirst,MaxStep,locfleche,TolGuide,First,Last,
938                      Soldep,4,Inside,Appro,Forward,RecP,RecS,RecRst);
939     if(!done) Standard_Failure::Raise("SimulSurf : Failed Processing!");
940     Standard_Integer nbp = lin->NbPoints();
941     sec = new ChFiDS_SecHArray1(1,nbp);
942     for(Standard_Integer i = 1; i <= nbp; i++){
943       ChFiDS_CircSection& isec = sec->ChangeValue(i);
944       Standard_Real u,v,w,param,p1,p2;
945       gp_Circ ci;
946       const Blend_Point& p = lin->Point(i);
947       p.ParametersOnS(u,v);
948       w = p.ParameterOnC();
949       param = p.Parameter();
950       func.Section(param,u,v,w,p1,p2,ci);
951       isec.Set(ci,p1,p2);
952       if(i == 1) {pf.SetCoord(u,v);p.ParametersOnS2(u,v);ppcf.SetCoord(u,v);} 
953       if(i == nbp) {pl.SetCoord(u,v);p.ParametersOnS2(u,v);ppcl.SetCoord(u,v);} 
954     }
955   }
956   else {
957     BRepBlend_SurfRstEvolRad func(HS1,HS2,PC2,HGuide,fsp->Law(HGuide));
958     Handle(Adaptor3d_HCurveOnSurface) HC = new Adaptor3d_HCurveOnSurface();
959     HC->ChangeCurve().Load(PC2, HS2);
960     BRepBlend_SurfCurvEvolRadInv finvc(HS1,HC,HGuide,fsp->Law(HGuide));
961     BRepBlend_SurfPointEvolRadInv finvp(HS1,HGuide,fsp->Law(HGuide));
962     BRepBlend_EvolRadInv finv(HS1,HSref2,HGuide,fsp->Law(HGuide));
963     finv.Set(Standard_False,PCref2);
964     Standard_Integer petitchoix = 1;
965     if(Or1 == TopAbs_REVERSED) petitchoix = 3;
966     if(Choix%2 == 0) petitchoix++;
967     finv.Set(Choix);
968     finvc.Set(petitchoix);
969     finvp.Set(petitchoix);
970     func.Set(petitchoix);
971     func.Set(myShape);
972     done = SimulData(Data,HGuide,lin,HS1,I1,HS2,PC2,I2,Decroch2,
973                      func,finv,finvp,finvc,
974                      PFirst,MaxStep,locfleche,TolGuide,First,Last,
975                      Soldep,4,Inside,Appro,Forward,RecP,RecS,RecRst);
976     if(!done) Standard_Failure::Raise("SimulSurf : Fail !");
977     Standard_Integer nbp = lin->NbPoints();
978     sec = new ChFiDS_SecHArray1(1,nbp);
979     for(Standard_Integer i = 1; i <= nbp; i++){
980       ChFiDS_CircSection& isec = sec->ChangeValue(i);
981       Standard_Real u,v,w,param,p1,p2;
982       gp_Circ ci;
983       const Blend_Point& p = lin->Point(i);
984       p.ParametersOnS(u,v);
985       w = p.ParameterOnC();
986       param = p.Parameter();
987       func.Section(param,u,v,w,p1,p2,ci);
988       isec.Set(ci,p1,p2);
989       if(i == 1) {pf.SetCoord(u,v);p.ParametersOnS2(u,v);ppcf.SetCoord(u,v);} 
990       if(i == nbp) {pl.SetCoord(u,v);p.ParametersOnS2(u,v);ppcl.SetCoord(u,v);} 
991     }
992   }
993   Data->SetSimul(sec);
994   //gp_Pnt2d pbid;
995   Data->Set2dPoints(pf,pl,ppcf,ppcl);
996   ChFi3d_FilCommonPoint(lin->StartPointOnFirst(),lin->TransitionOnS1(),
997                         Standard_True, Data->ChangeVertexFirstOnS1(),tolesp);
998   ChFi3d_FilCommonPoint(lin->EndPointOnFirst(),lin->TransitionOnS1(),
999                         Standard_False,Data->ChangeVertexLastOnS1(),tolesp);
1000   ChFi3d_FilCommonPoint(lin->StartPointOnSecond(),lin->TransitionOnS2(),
1001                         Standard_True, Data->ChangeVertexFirstOnS2(),tolesp);
1002   ChFi3d_FilCommonPoint(lin->EndPointOnSecond(),lin->TransitionOnS2(),
1003                         Standard_False, Data->ChangeVertexLastOnS2(),tolesp);
1004 }
1005
1006
1007
1008 //=======================================================================
1009 //function : SimulSurf
1010 //purpose  : 
1011 //=======================================================================
1012
1013 void  ChFi3d_FilBuilder::SimulSurf(Handle(ChFiDS_SurfData)&            Data,
1014                                    const Handle(ChFiDS_HElSpine)&      HGuide,
1015                                    const Handle(ChFiDS_Spine)&         Spine,
1016                                    const Standard_Integer              Choix,
1017                                    const Handle(BRepAdaptor_HSurface)& HS1,
1018                                    const Handle(Adaptor3d_TopolTool)&    I1,
1019                                    const Handle(BRepAdaptor_HCurve2d)& PC1,
1020                                    const Handle(BRepAdaptor_HSurface)& HSref1,
1021                                    const Handle(BRepAdaptor_HCurve2d)& PCref1,
1022                                    Standard_Boolean&                   Decroch1,
1023                                    const TopAbs_Orientation            Or1,
1024                                    const Handle(BRepAdaptor_HSurface)& HS2,
1025                                    const Handle(Adaptor3d_TopolTool)&    I2,
1026                                    const Handle(BRepAdaptor_HCurve2d)& PC2,
1027                                    const Handle(BRepAdaptor_HSurface)& HSref2,
1028                                    const Handle(BRepAdaptor_HCurve2d)& PCref2,
1029                                    Standard_Boolean&                   Decroch2,
1030                                    const TopAbs_Orientation            Or2,
1031                                    const Standard_Real                 /*Fleche*/,
1032                                    const Standard_Real                 TolGuide,
1033                                    Standard_Real&                      First,
1034                                    Standard_Real&                      Last,
1035                                    const Standard_Boolean              Inside,
1036                                    const Standard_Boolean              Appro,
1037                                    const Standard_Boolean              Forward,
1038                                    const Standard_Boolean              RecP1,
1039                                    const Standard_Boolean              RecRst1,
1040                                    const Standard_Boolean              RecP2,
1041                                    const Standard_Boolean              RecRst2,
1042                                    const math_Vector&                  Soldep)
1043 {
1044   Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Spine);
1045   if(fsp.IsNull()) Standard_ConstructionError::Raise
1046     ("PerformSurf : it is not the spine of a fillet");
1047   Handle(BRepBlend_Line) lin;
1048   
1049   // Flexible parameters!
1050   Standard_Real locfleche, MaxStep;
1051   SimulParams(HGuide,fsp,MaxStep,locfleche);
1052   Handle(ChFiDS_SecHArray1) sec;
1053 //  gp_Pnt2d pf,pl;
1054
1055   Standard_Integer ch1 = 1, ch2 = 2;      
1056   Standard_Real PFirst = First;
1057
1058   if(fsp->IsConstant()){
1059     BRepBlend_RstRstConstRad func(HS1, PC1, HS2, PC2, HGuide);
1060     func.Set(HSref1, PCref1, HSref2, PCref2);
1061     Handle(Adaptor3d_HCurveOnSurface) HC1 = new Adaptor3d_HCurveOnSurface();
1062     HC1->ChangeCurve().Load(PC1, HS1);
1063     Handle(Adaptor3d_HCurveOnSurface) HC2 = new Adaptor3d_HCurveOnSurface();
1064     HC2->ChangeCurve().Load(PC2, HS2);
1065     BRepBlend_SurfCurvConstRadInv finv1(HSref1, HC2, HGuide);
1066     BRepBlend_CurvPointRadInv     finvp1(HGuide, HC2);
1067     BRepBlend_SurfCurvConstRadInv finv2(HSref2, HC1, HGuide);
1068     BRepBlend_CurvPointRadInv     finvp2(HGuide, HC1);
1069
1070     finv1.Set(PCref1);
1071     finv2.Set(PCref2);
1072
1073
1074     Standard_Real rad = fsp->Radius();
1075     if(Or1 == TopAbs_REVERSED) ch1 = 3;
1076     if(Or2 == TopAbs_REVERSED) ch2 = 3;
1077
1078     finv1.Set(rad, ch1);
1079     finvp1.Set(Choix);
1080     finv2.Set(rad, ch2);
1081     finvp2.Set(Choix);
1082     func.Set(rad, Choix);
1083     func.Set(myShape);
1084     
1085     done = SimulData(Data, HGuide, lin, HS1, PC1, I1, Decroch1, HS2, PC2, I2, Decroch2,
1086                      func, finv1, finvp1, finv2, finvp2,
1087                      PFirst, MaxStep, locfleche, TolGuide, First, Last,
1088                      Soldep, 4, Inside, Appro, Forward, RecP1, RecRst1, RecP2, RecRst2);
1089     if(!done) Standard_Failure::Raise("SimulSurf : Failed processing!");
1090     Standard_Integer nbp = lin->NbPoints();
1091     sec = new ChFiDS_SecHArray1(1,nbp);
1092     for(Standard_Integer i = 1; i <= nbp; i++){
1093       ChFiDS_CircSection& isec = sec->ChangeValue(i);
1094       Standard_Real u, v, param, p1, p2;
1095       gp_Circ ci;
1096       const Blend_Point& p = lin->Point(i);
1097       u = p.ParameterOnC1();
1098       v = p.ParameterOnC2();
1099       param = p.Parameter();
1100       func.Section(param, u, v, p1, p2, ci);
1101       isec.Set(ci, p1, p2);
1102 //      if(i == 1) {pf.SetCoord(u,v);} 
1103 //      if(i == nbp) {pl.SetCoord(u,v);} 
1104     }
1105   }
1106   else {
1107     BRepBlend_RstRstEvolRad func(HS1,PC1, HS2, PC2, HGuide, fsp->Law(HGuide));
1108     func.Set(HSref1, PCref1, HSref2, PCref2);
1109     Handle(Adaptor3d_HCurveOnSurface) HC1 = new Adaptor3d_HCurveOnSurface();
1110     HC1->ChangeCurve().Load(PC1, HS1);
1111     Handle(Adaptor3d_HCurveOnSurface) HC2 = new Adaptor3d_HCurveOnSurface();
1112     HC2->ChangeCurve().Load(PC2, HS2);
1113
1114     BRepBlend_SurfCurvEvolRadInv  finv1(HSref1, HC2, HGuide, fsp->Law(HGuide));
1115     BRepBlend_CurvPointRadInv     finvp1(HGuide, HC2);
1116     BRepBlend_SurfCurvEvolRadInv  finv2(HSref2, HC1, HGuide, fsp->Law(HGuide));
1117     BRepBlend_CurvPointRadInv     finvp2(HGuide, HC1);
1118
1119     finv1.Set(PCref1);
1120     finv2.Set(PCref2);
1121
1122     Standard_Integer ch11 = 1, ch22 = 2;    
1123
1124     if(Or1 == TopAbs_REVERSED) ch11 = 3;
1125     if(Or2 == TopAbs_REVERSED) ch22 = 3;
1126
1127
1128     finv1.Set(ch11);
1129     finvp1.Set(Choix);
1130     finv2.Set(ch22);
1131     finvp2.Set(Choix);
1132     func.Set(Choix);
1133     func.Set(myShape);
1134
1135     done = SimulData(Data, HGuide, lin, HS1, PC1, I1, Decroch1, HS2, PC2, I2, Decroch2,
1136                      func, finv1, finvp1, finv2, finvp2,
1137                      PFirst, MaxStep, locfleche, TolGuide, First, Last,
1138                      Soldep, 4, Inside, Appro, Forward, RecP1, RecRst1, RecP2, RecRst2);
1139
1140     if(!done) Standard_Failure::Raise("SimulSurf : Fail !");
1141     Standard_Integer nbp = lin->NbPoints();
1142     sec = new ChFiDS_SecHArray1(1, nbp);
1143     for(Standard_Integer i = 1; i <= nbp; i++){
1144       ChFiDS_CircSection& isec = sec->ChangeValue(i);
1145       Standard_Real u, v, param, p1, p2;
1146       gp_Circ ci;
1147       const Blend_Point& p = lin->Point(i);
1148       u = p.ParameterOnC1();
1149       v = p.ParameterOnC2();
1150       param = p.Parameter();
1151       func.Section(param, u, v, p1, p2, ci);
1152       isec.Set(ci, p1, p2);
1153 //      if(i == 1) {pf.SetCoord(u,v);} 
1154 //      if(i == nbp) {pl.SetCoord(u,v);} 
1155     }
1156   }
1157   Data->SetSimul(sec);
1158 //  gp_Pnt2d pbid;
1159 //  Data->Set2dPoints(pf,pl,pbid,pbid);
1160
1161   ChFi3d_FilCommonPoint(lin->StartPointOnFirst(),lin->TransitionOnS1(),
1162                         Standard_True, Data->ChangeVertexFirstOnS1(),tolesp);
1163   ChFi3d_FilCommonPoint(lin->EndPointOnFirst(),lin->TransitionOnS1(),
1164                         Standard_False,Data->ChangeVertexLastOnS1(),tolesp);
1165   ChFi3d_FilCommonPoint(lin->StartPointOnSecond(),lin->TransitionOnS2(),
1166                         Standard_True, Data->ChangeVertexFirstOnS2(),tolesp);
1167   ChFi3d_FilCommonPoint(lin->EndPointOnSecond(),lin->TransitionOnS2(),
1168                         Standard_False, Data->ChangeVertexLastOnS2(),tolesp);
1169 }
1170
1171
1172
1173
1174
1175
1176
1177 //=======================================================================
1178 //function : PerformFirstSection
1179 //purpose  : 
1180 //=======================================================================
1181
1182 Standard_Boolean ChFi3d_FilBuilder::PerformFirstSection
1183 (const Handle(ChFiDS_Spine)&         Spine,
1184  const Handle(ChFiDS_HElSpine)&      HGuide,
1185  const Standard_Integer              Choix,
1186  Handle(BRepAdaptor_HSurface)& S1,
1187  Handle(BRepAdaptor_HSurface)& S2,
1188  const Handle(Adaptor3d_TopolTool)&    I1,
1189  const Handle(Adaptor3d_TopolTool)&    I2,
1190  const Standard_Real                 Par,
1191  math_Vector&                        SolDep,
1192  TopAbs_State&                       Pos1,
1193  TopAbs_State&                       Pos2) const 
1194 {
1195   Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Spine);
1196   if(fsp.IsNull()) Standard_ConstructionError::Raise
1197     ("PerformSurf : this is not the spine of a fillet");
1198   Standard_Real TolGuide = HGuide->Resolution(tolesp);
1199   if(fsp->IsConstant()){
1200     BRepBlend_ConstRad Func(S1,S2,HGuide);
1201     Func.Set(fsp->Radius(),Choix);
1202     Func.Set(myShape);
1203     BRepBlend_Walking TheWalk(S1,S2,I1,I2,HGuide);
1204     return TheWalk.PerformFirstSection(Func,Par,SolDep,
1205                                        tolesp,TolGuide,Pos1,Pos2);
1206   }
1207   else {
1208     BRepBlend_EvolRad Func(S1,S2,HGuide,fsp->Law(HGuide));
1209     Func.Set(Choix);
1210     Func.Set(myShape);
1211     BRepBlend_Walking TheWalk(S1,S2,I1,I2,HGuide);
1212     return TheWalk.PerformFirstSection(Func,Par,SolDep,
1213                                        tolesp,TolGuide,Pos1,Pos2);
1214   }
1215 }
1216
1217 //=======================================================================
1218 //function : PerformSurf
1219 //purpose  : 
1220 //=======================================================================
1221
1222 Standard_Boolean 
1223 ChFi3d_FilBuilder::PerformSurf(ChFiDS_SequenceOfSurfData&          SeqData,
1224                                const Handle(ChFiDS_HElSpine)&      HGuide,
1225                                const Handle(ChFiDS_Spine)&         Spine,
1226                                const Standard_Integer              Choix,
1227                                const Handle(BRepAdaptor_HSurface)& S1,
1228                                const Handle(Adaptor3d_TopolTool)&    I1,
1229                                const Handle(BRepAdaptor_HSurface)& S2,
1230                                const Handle(Adaptor3d_TopolTool)&    I2,
1231                                const Standard_Real                 MaxStep,
1232                                const Standard_Real                 Fleche,
1233                                const Standard_Real                 TolGuide,
1234                                Standard_Real&                      First,
1235                                Standard_Real&                      Last,
1236                                const Standard_Boolean              Inside,
1237                                const Standard_Boolean              Appro,
1238                                const Standard_Boolean              Forward,
1239                                const Standard_Boolean              RecOnS1,
1240                                const Standard_Boolean              RecOnS2,
1241                                const math_Vector&                  Soldep,
1242                                Standard_Integer&                   intf,
1243                                Standard_Integer&                   intl)
1244 {
1245 #ifdef OCCT_DEBUG
1246   OSD_Chronometer ch;
1247 #endif
1248   Handle(ChFiDS_SurfData) Data = SeqData(1);
1249   Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Spine);
1250   if(fsp.IsNull()) Standard_ConstructionError::Raise
1251     ("PerformSurf : this is not the spine of a fillet");
1252   Standard_Boolean gd1,gd2,gf1,gf2, maybesingular;
1253   Handle(BRepBlend_Line) lin;
1254   TopAbs_Orientation Or = S1->ChangeSurface().Face().Orientation();
1255   Standard_Real PFirst = First;
1256   if(intf) First = fsp->FirstParameter(1);
1257   if(intl) Last = fsp->LastParameter(fsp->NbEdges());
1258   if(fsp->IsConstant()){
1259     BRepBlend_ConstRad Func(S1,S2,HGuide);
1260     BRepBlend_ConstRadInv FInv(S1,S2,HGuide);
1261     Func.Set(fsp->Radius(),Choix);
1262     FInv.Set(fsp->Radius(),Choix);
1263     Func.Set(myShape);
1264
1265 #ifdef OCCT_DEBUG
1266         ChFi3d_InitChron(ch); //init perf ComputeData
1267 #endif
1268
1269     done = ComputeData(Data,HGuide,Spine,lin,S1,I1,S2,I2,Func,FInv,
1270                        PFirst,MaxStep,Fleche,TolGuide,First,Last,
1271                        Inside,Appro,Forward,Soldep,intf,intl,
1272                        gd1,gd2,gf1,gf2,RecOnS1,RecOnS2);
1273
1274 #ifdef OCCT_DEBUG
1275         ChFi3d_ResultChron(ch , t_computedata);// result perf ComputeData
1276 #endif 
1277
1278     if(!done) return Standard_False; // recovery is possible PMN 14/05/1998
1279
1280 #ifdef OCCT_DEBUG
1281           ChFi3d_InitChron(ch);// init  perf  CompleteData
1282 #endif
1283
1284     done = CompleteData(Data,Func,lin,S1,S2,Or,gd1,gd2,gf1,gf2);
1285
1286 #ifdef OCCT_DEBUG
1287          ChFi3d_ResultChron(ch , t_completedata);// result perf CompleteData
1288 #endif 
1289
1290     if(!done) Standard_Failure::Raise("PerformSurf : Failed approximation!");
1291     maybesingular = (Func.GetMinimalDistance()<=100*tolapp3d);
1292   }
1293   else {
1294     BRepBlend_EvolRad Func(S1, S2, HGuide, fsp->Law(HGuide));
1295     BRepBlend_EvolRadInv FInv(S1, S2, HGuide, fsp->Law(HGuide));
1296     Func.Set(Choix);
1297     FInv.Set(Choix);
1298     Func.Set(myShape);
1299
1300 #ifdef OCCT_DEBUG
1301           ChFi3d_InitChron(ch);// init perf ComputeData
1302 #endif
1303
1304     done = ComputeData(Data,HGuide,Spine,lin,S1,I1,S2,I2,Func,FInv,
1305                        PFirst,MaxStep,Fleche,TolGuide,First,Last,
1306                        Inside,Appro,Forward,Soldep,intf,intl,
1307                        gd1,gd2,gf1,gf2,RecOnS1,RecOnS2);
1308 #ifdef OCCT_DEBUG
1309          ChFi3d_ResultChron(ch , t_computedata); //result perf ComputeData
1310 #endif 
1311
1312     if(!done) return Standard_False;
1313
1314 #ifdef OCCT_DEBUG
1315           ChFi3d_InitChron(ch);// init perf CompleteData
1316 #endif
1317
1318     done = CompleteData(Data,Func,lin,S1,S2,Or,gd1,gd2,gf1,gf2);
1319
1320 #ifdef OCCT_DEBUG
1321          ChFi3d_ResultChron(ch , t_completedata);// result perf CompleteData
1322 #endif 
1323
1324     if(!done) Standard_Failure::Raise("PerformSurf : Failed approximation!");
1325     maybesingular = (Func.GetMinimalDistance()<=100*tolapp3d); 
1326   }
1327   if (maybesingular) SplitSurf(SeqData, lin);
1328   return Standard_True;
1329 }
1330
1331 //=======================================================================
1332 //function : PerformSurf
1333 //purpose  : 
1334 //=======================================================================
1335
1336 void  ChFi3d_FilBuilder::PerformSurf(ChFiDS_SequenceOfSurfData&          SeqData,
1337                                      const Handle(ChFiDS_HElSpine)&      HGuide,
1338                                      const Handle(ChFiDS_Spine)&         Spine,
1339                                      const Standard_Integer              Choix,
1340                                      const Handle(BRepAdaptor_HSurface)& HS1,
1341                                      const Handle(Adaptor3d_TopolTool)&    I1,
1342                                      const Handle(BRepAdaptor_HCurve2d)& PC1,
1343                                      const Handle(BRepAdaptor_HSurface)& HSref1,
1344                                      const Handle(BRepAdaptor_HCurve2d)& PCref1,
1345                                      Standard_Boolean&                   Decroch1,
1346                                      const Handle(BRepAdaptor_HSurface)& HS2,
1347                                      const Handle(Adaptor3d_TopolTool)&    I2,
1348                                      const TopAbs_Orientation            Or2,
1349                                      const Standard_Real                 MaxStep,
1350                                      const Standard_Real                 Fleche,
1351                                      const Standard_Real                 TolGuide,
1352                                      Standard_Real&                      First,
1353                                      Standard_Real&                      Last,
1354                                      const Standard_Boolean              Inside,
1355                                      const Standard_Boolean              Appro,
1356                                      const Standard_Boolean              Forward,
1357                                      const Standard_Boolean              RecP,
1358                                      const Standard_Boolean              RecS,
1359                                      const Standard_Boolean              RecRst,
1360                                      const math_Vector&                  Soldep)
1361 {
1362   Handle(ChFiDS_SurfData)  Data = SeqData(1);
1363   Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Spine);
1364   if(fsp.IsNull()) Standard_ConstructionError::Raise
1365     ("PerformSurf : this is not the spine of a fillet");
1366   Handle(BRepBlend_Line) lin;
1367   Standard_Real PFirst = First;
1368   Standard_Boolean maybesingular;
1369
1370   if(fsp->IsConstant()){
1371     BRepBlend_SurfRstConstRad func(HS2,HS1,PC1,HGuide);
1372     func.Set(HSref1,PCref1);
1373     Handle(Adaptor3d_HCurveOnSurface) HC = new Adaptor3d_HCurveOnSurface();
1374     HC->ChangeCurve().Load(PC1, HS1);
1375     BRepBlend_SurfCurvConstRadInv finvc(HS2,HC,HGuide);
1376     BRepBlend_SurfPointConstRadInv finvp(HS2,HGuide);
1377     BRepBlend_ConstRadInv finv(HS2,HSref1,HGuide);
1378     finv.Set(Standard_False,PCref1);
1379      
1380     Standard_Real rad = fsp->Radius();
1381     Standard_Integer petitchoix = 1;
1382     if(Or2 == TopAbs_REVERSED) petitchoix = 3;
1383     if(Choix%2 == 0) petitchoix++;
1384     finv.Set(rad,Choix);
1385     finvc.Set(rad,petitchoix);
1386     finvp.Set(rad,petitchoix);
1387     func.Set(rad,petitchoix);
1388     func.Set(myShape);
1389     
1390     done = ComputeData(Data,HGuide,lin,HS2,I2,HS1,PC1,I1,Decroch1,
1391                        func,finv,finvp,finvc,
1392                        PFirst,MaxStep,Fleche,TolGuide,First,Last,
1393                        Soldep,Inside,Appro,Forward,RecP,RecS,RecRst);
1394     if(!done) {
1395        Spine->SetErrorStatus(ChFiDS_WalkingFailure); 
1396        Standard_Failure::Raise("PerformSurf : Failed processing!");
1397     }
1398     TopAbs_Orientation Or = HS2->ChangeSurface().Face().Orientation();
1399     done = CompleteData(Data,func,lin,HS1,HS2,Or,1);
1400     if(!done) Standard_Failure::Raise("PerformSurf : Failed approximation!");
1401     maybesingular = (func.GetMinimalDistance()<=100*tolapp3d); 
1402   }
1403   else {
1404     BRepBlend_SurfRstEvolRad func(HS2,HS1,PC1,HGuide,fsp->Law(HGuide));
1405     func.Set(HSref1,PCref1);
1406     Handle(Adaptor3d_HCurveOnSurface) HC = new Adaptor3d_HCurveOnSurface();
1407     HC->ChangeCurve().Load(PC1, HS1);
1408     BRepBlend_SurfCurvEvolRadInv finvc(HS2,HC,HGuide,fsp->Law(HGuide));
1409     BRepBlend_SurfPointEvolRadInv finvp(HS2,HGuide,fsp->Law(HGuide));
1410     BRepBlend_EvolRadInv finv(HS2,HSref1,HGuide,fsp->Law(HGuide));
1411     finv.Set(Standard_False,PCref1);
1412     Standard_Integer petitchoix = 1;
1413     if(Or2 == TopAbs_REVERSED) petitchoix = 3;
1414     if(Choix%2 == 0) petitchoix++;
1415     finv.Set(Choix);
1416     finvc.Set(petitchoix);
1417     finvp.Set(petitchoix);
1418     func.Set(petitchoix);
1419     func.Set(myShape);
1420     done = ComputeData(Data,HGuide,lin,HS2,I2,HS1,PC1,I1,Decroch1,
1421                        func,finv,finvp,finvc,
1422                        PFirst,MaxStep,Fleche,TolGuide,First,Last,
1423                        Soldep,Inside,Appro,Forward,RecP,RecS,RecRst);
1424     if(!done) {
1425       Spine->SetErrorStatus(ChFiDS_WalkingFailure);
1426       Standard_Failure::Raise("PerformSurf : Failed processing!");
1427     }
1428     TopAbs_Orientation Or = HS2->ChangeSurface().Face().Orientation();
1429     done = CompleteData(Data,func,lin,HS1,HS2,Or,1);
1430     if(!done) Standard_Failure::Raise("PerformSurf : Failed approximation!");
1431    maybesingular = (func.GetMinimalDistance()<=100*tolapp3d); 
1432   }
1433   if (maybesingular) SplitSurf(SeqData, lin);
1434 }
1435
1436 //=======================================================================
1437 //function : PerformSurf
1438 //purpose  : 
1439 //=======================================================================
1440
1441 void  ChFi3d_FilBuilder::PerformSurf(ChFiDS_SequenceOfSurfData&          SeqData,
1442                                      const Handle(ChFiDS_HElSpine)&      HGuide,
1443                                      const Handle(ChFiDS_Spine)&         Spine,
1444                                      const Standard_Integer              Choix,
1445                                      const Handle(BRepAdaptor_HSurface)& HS1,
1446                                      const Handle(Adaptor3d_TopolTool)&    I1,
1447                                      const TopAbs_Orientation            Or1,
1448                                      const Handle(BRepAdaptor_HSurface)& HS2,
1449                                      const Handle(Adaptor3d_TopolTool)&    I2,
1450                                      const Handle(BRepAdaptor_HCurve2d)& PC2,
1451                                      const Handle(BRepAdaptor_HSurface)& HSref2,
1452                                      const Handle(BRepAdaptor_HCurve2d)& PCref2,
1453                                      Standard_Boolean&                   Decroch2,
1454                                      const Standard_Real                 MaxStep,
1455                                      const Standard_Real                 Fleche,
1456                                      const Standard_Real                 TolGuide,
1457                                      Standard_Real&                      First,
1458                                      Standard_Real&                      Last,
1459                                      const Standard_Boolean              Inside,
1460                                      const Standard_Boolean              Appro,
1461                                      const Standard_Boolean              Forward,
1462                                      const Standard_Boolean              RecP,
1463                                      const Standard_Boolean              RecS,
1464                                      const Standard_Boolean              RecRst,
1465                                      const math_Vector&                  Soldep)
1466 {
1467   Handle(ChFiDS_SurfData) Data = SeqData(1);;
1468   Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Spine);
1469   if(fsp.IsNull()) Standard_ConstructionError::Raise
1470     ("PerformSurf : this is not the spine of a fillet");
1471   Handle(BRepBlend_Line) lin;
1472   Standard_Real PFirst = First;
1473   Standard_Boolean maybesingular;
1474
1475   if(fsp->IsConstant()){
1476     BRepBlend_SurfRstConstRad func(HS1,HS2,PC2,HGuide);
1477     func.Set(HSref2,PCref2);
1478     Handle(Adaptor3d_HCurveOnSurface) HC = new Adaptor3d_HCurveOnSurface();
1479     HC->ChangeCurve().Load(PC2, HS2);
1480     BRepBlend_SurfCurvConstRadInv finvc(HS1,HC,HGuide);
1481     BRepBlend_SurfPointConstRadInv finvp(HS1,HGuide);
1482     BRepBlend_ConstRadInv finv(HS1,HSref2,HGuide);
1483     finv.Set(Standard_False,PCref2);
1484     
1485     Standard_Real rad = fsp->Radius();
1486     Standard_Integer petitchoix = 1;
1487     if(Or1 == TopAbs_REVERSED) petitchoix = 3;
1488     if(Choix%2 == 0) petitchoix++;
1489     finv.Set(rad,Choix);
1490     finvc.Set(rad,petitchoix);
1491     finvp.Set(rad,petitchoix);
1492     func.Set(rad,petitchoix);
1493     func.Set(myShape);
1494     
1495     done = ComputeData(Data,HGuide,lin,HS1,I1,HS2,PC2,I2,Decroch2,
1496                        func,finv,finvp,finvc,
1497                        PFirst,MaxStep,Fleche,TolGuide,First,Last,
1498                        Soldep,Inside,Appro,Forward,RecP,RecS,RecRst);
1499     if(!done) {
1500       Spine->SetErrorStatus(ChFiDS_WalkingFailure);
1501       Standard_Failure::Raise("PerformSurf : Failed processing!");
1502     }
1503     TopAbs_Orientation Or = HS1->ChangeSurface().Face().Orientation();
1504     done = CompleteData(Data,func,lin,HS1,HS2,Or,0);
1505     if(!done) Standard_Failure::Raise("PerformSurf : Failed approximation!");
1506     maybesingular = (func.GetMinimalDistance()<=100*tolapp3d); 
1507   }
1508   else {
1509     BRepBlend_SurfRstEvolRad func(HS1,HS2,PC2,HGuide,fsp->Law(HGuide));
1510     func.Set(HSref2,PCref2);
1511     Handle(Adaptor3d_HCurveOnSurface) HC = new Adaptor3d_HCurveOnSurface();
1512     HC->ChangeCurve().Load(PC2, HS2);
1513     BRepBlend_SurfCurvEvolRadInv finvc(HS1,HC,HGuide,fsp->Law(HGuide));
1514     BRepBlend_SurfPointEvolRadInv finvp(HS1,HGuide,fsp->Law(HGuide));
1515     BRepBlend_EvolRadInv finv(HS1,HSref2,HGuide,fsp->Law(HGuide));
1516     finv.Set(Standard_False,PCref2);
1517     Standard_Integer petitchoix = 1;
1518     if(Or1 == TopAbs_REVERSED) petitchoix = 3;
1519     if(Choix%2 == 0) petitchoix++;
1520     finv.Set(Choix);
1521     finvc.Set(petitchoix);
1522     finvp.Set(petitchoix);
1523     func.Set(petitchoix);
1524     func.Set(myShape);
1525
1526     done = ComputeData(Data,HGuide,lin,HS1,I1,HS2,PC2,I2,Decroch2,
1527                        func,finv,finvp,finvc,
1528                        PFirst,MaxStep,Fleche,TolGuide,First,Last,
1529                        Soldep,Inside,Appro,Forward,RecP,RecS,RecRst);
1530     if(!done) {
1531       Spine->SetErrorStatus(ChFiDS_WalkingFailure);
1532       Standard_Failure::Raise("PerformSurf : Failed processing!");
1533     }
1534     TopAbs_Orientation Or = HS1->ChangeSurface().Face().Orientation();
1535     done = CompleteData(Data,func,lin,HS1,HS2,Or,0);
1536     if(!done) Standard_Failure::Raise("PerformSurf : Failed approximation!");
1537     maybesingular = (func.GetMinimalDistance()<=100*tolapp3d); 
1538   }
1539   if (maybesingular) SplitSurf(SeqData, lin); 
1540 }
1541
1542
1543
1544
1545
1546
1547 //=======================================================================
1548 //function : PerformSurf
1549 //purpose  : 
1550 //=======================================================================
1551
1552 void  ChFi3d_FilBuilder::PerformSurf(ChFiDS_SequenceOfSurfData&          SeqData,
1553                                      const Handle(ChFiDS_HElSpine)&      HGuide,
1554                                      const Handle(ChFiDS_Spine)&         Spine,
1555                                      const Standard_Integer              Choix,
1556                                      const Handle(BRepAdaptor_HSurface)& HS1,
1557                                      const Handle(Adaptor3d_TopolTool)&    I1,
1558                                      const Handle(BRepAdaptor_HCurve2d)& PC1,
1559                                      const Handle(BRepAdaptor_HSurface)& HSref1,
1560                                      const Handle(BRepAdaptor_HCurve2d)& PCref1,
1561                                      Standard_Boolean&                   Decroch1,
1562                                      const TopAbs_Orientation            Or1,
1563                                      const Handle(BRepAdaptor_HSurface)& HS2,
1564                                      const Handle(Adaptor3d_TopolTool)&    I2,
1565                                      const Handle(BRepAdaptor_HCurve2d)& PC2,
1566                                      const Handle(BRepAdaptor_HSurface)& HSref2,
1567                                      const Handle(BRepAdaptor_HCurve2d)& PCref2,
1568                                      Standard_Boolean&                   Decroch2,
1569                                      const TopAbs_Orientation            Or2,
1570                                      const Standard_Real                 MaxStep,
1571                                      const Standard_Real                 Fleche,
1572                                      const Standard_Real                 TolGuide,
1573                                      Standard_Real&                      First,
1574                                      Standard_Real&                      Last,
1575                                      const Standard_Boolean              Inside,
1576                                      const Standard_Boolean              Appro,
1577                                      const Standard_Boolean              Forward,
1578                                      const Standard_Boolean              RecP1,
1579                                      const Standard_Boolean              RecRst1,
1580                                      const Standard_Boolean              RecP2,
1581                                      const Standard_Boolean              RecRst2,
1582                                      const math_Vector&                  Soldep)
1583 {
1584   Handle(ChFiDS_SurfData) Data = SeqData(1);;
1585   Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Spine);
1586   if(fsp.IsNull()) Standard_ConstructionError::Raise
1587     ("PerformSurf : this is not the spine of a fillet");
1588   Handle(BRepBlend_Line) lin;
1589   Standard_Real PFirst = First;
1590   Standard_Boolean maybesingular;
1591
1592   if(fsp->IsConstant()){
1593     BRepBlend_RstRstConstRad func(HS1, PC1, HS2, PC2, HGuide);
1594     func.Set(HSref1, PCref1, HSref2, PCref2);
1595     Handle(Adaptor3d_HCurveOnSurface) HC1 = new Adaptor3d_HCurveOnSurface();
1596     HC1->ChangeCurve().Load(PC1, HS1);
1597     Handle(Adaptor3d_HCurveOnSurface) HC2 = new Adaptor3d_HCurveOnSurface();
1598     HC2->ChangeCurve().Load(PC2, HS2);
1599     BRepBlend_SurfCurvConstRadInv finv1(HSref1, HC2, HGuide);
1600     BRepBlend_CurvPointRadInv     finvp1(HGuide, HC2);
1601     BRepBlend_SurfCurvConstRadInv finv2(HSref2, HC1, HGuide);
1602     BRepBlend_CurvPointRadInv     finvp2(HGuide, HC1);
1603
1604     finv1.Set(PCref1);
1605     finv2.Set(PCref2);
1606
1607     Standard_Integer ch1 = 1, ch2 = 2;    
1608     Standard_Real rad = fsp->Radius();
1609     if(Or1 == TopAbs_REVERSED) ch1 = 3;
1610     if(Or2 == TopAbs_REVERSED) ch2 = 3;
1611
1612     finv1.Set(rad, ch1);
1613     finvp1.Set(Choix);
1614     finv2.Set(rad, ch2);
1615     finvp2.Set(Choix);
1616     func.Set(rad, Choix);
1617     func.Set(myShape);
1618     
1619     done = ComputeData(Data, HGuide, lin, HS1, PC1, I1, Decroch1, HS2, PC2, I2, Decroch2,
1620                        func, finv1, finvp1, finv2, finvp2,
1621                        PFirst, MaxStep, Fleche, TolGuide, First, Last,
1622                        Soldep, Inside, Appro, Forward, RecP1, RecRst1, RecP2, RecRst2);
1623     if(!done) {
1624        Spine->SetErrorStatus(ChFiDS_WalkingFailure);
1625        Standard_Failure::Raise("PerformSurf : Failed processing!");
1626     }
1627     TopAbs_Orientation Or = HS1->ChangeSurface().Face().Orientation();
1628     done = CompleteData(Data, func, lin, HS1, HS2, Or);
1629     if(!done) Standard_Failure::Raise("PerformSurf : Failed approximation!");
1630     maybesingular = (func.GetMinimalDistance()<=100*tolapp3d); 
1631   }
1632   else {
1633     BRepBlend_RstRstEvolRad func(HS1,PC1, HS2, PC2, HGuide, fsp->Law(HGuide));
1634     func.Set(HSref1, PCref1, HSref2, PCref2);
1635     Handle(Adaptor3d_HCurveOnSurface) HC1 = new Adaptor3d_HCurveOnSurface();
1636     HC1->ChangeCurve().Load(PC1, HS1);
1637     Handle(Adaptor3d_HCurveOnSurface) HC2 = new Adaptor3d_HCurveOnSurface();
1638     HC2->ChangeCurve().Load(PC2, HS2);
1639
1640     BRepBlend_SurfCurvEvolRadInv finv1(HSref1, HC2, HGuide, fsp->Law(HGuide));
1641     BRepBlend_CurvPointRadInv     finvp1(HGuide, HC2);
1642     BRepBlend_SurfCurvEvolRadInv  finv2(HSref2, HC1, HGuide, fsp->Law(HGuide));
1643     BRepBlend_CurvPointRadInv     finvp2(HGuide, HC1);
1644
1645     finv1.Set(PCref1);
1646     finv2.Set(PCref2);
1647
1648     Standard_Integer ch1 = 1, ch2 = 2;    
1649
1650     if(Or1 == TopAbs_REVERSED) ch1 = 3;
1651     if(Or2 == TopAbs_REVERSED) ch2 = 3;
1652
1653
1654     finv1.Set(ch1);
1655     finvp1.Set(Choix);
1656     finv2.Set(ch2);
1657     finvp2.Set(Choix);
1658     func.Set(Choix);
1659     func.Set(myShape);
1660     
1661     done = ComputeData(Data, HGuide, lin, HS1, PC1,  I1, Decroch1, HS2, PC2,I2, Decroch2,
1662                        func, finv1, finvp1, finv2, finvp2,
1663                        PFirst, MaxStep, Fleche, TolGuide, First, Last,
1664                        Soldep, Inside, Appro, Forward, RecP1, RecRst1, RecP2, RecRst2);
1665
1666     if(!done) {
1667       Spine->SetErrorStatus(ChFiDS_WalkingFailure);
1668       Standard_Failure::Raise("PerformSurf : Failed processing!");
1669     }
1670     TopAbs_Orientation Or = HS1->ChangeSurface().Face().Orientation();
1671     done = CompleteData(Data, func, lin, HS1, HS2, Or);
1672     if(!done) Standard_Failure::Raise("PerformSurf : Failed approximation!");
1673     maybesingular = (func.GetMinimalDistance()<=100*tolapp3d); 
1674
1675
1676   }
1677   if (maybesingular) SplitSurf(SeqData, lin); 
1678 }
1679
1680
1681
1682
1683 //=======================================================================
1684 //function : SplitSurf
1685 //purpose  : 
1686 //=======================================================================
1687
1688 void ChFi3d_FilBuilder::SplitSurf(ChFiDS_SequenceOfSurfData&    SeqData,
1689                                   const Handle(BRepBlend_Line)& Line)
1690 {
1691   Standard_Integer ii, Nbpnt=Line->NbPoints();
1692   if (Nbpnt <3) return;
1693   Standard_Real UFirst,ULast,VFirst,VLast;
1694   TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
1695   Standard_Integer ISurf;
1696   Handle(ChFiDS_SurfData) ref =  SeqData(1);
1697   Blend_Point P; 
1698
1699   ISurf= ref->Surf(); 
1700   Handle(Geom_Surface) Surf = DStr.Surface(ISurf).Surface();
1701   Surf->Bounds(UFirst,ULast,VFirst,VLast);
1702   Handle(Geom_Curve) Courbe1 = Surf->UIso(UFirst);
1703   Handle(Geom_Curve) Courbe2 = Surf->UIso(ULast);
1704   ChFi3d_SearchSing Fonc(Courbe1, Courbe2);
1705
1706   TColStd_SequenceOfReal LesVi;
1707   Standard_Real precedant, suivant, courant;
1708   Standard_Real a, b, c;
1709   
1710   // (1) Finds vi so that iso v=vi is punctual
1711   VFirst = Min( ref->InterferenceOnS1().FirstParameter(),
1712                 ref->InterferenceOnS2().FirstParameter() );
1713   VLast  = Max( ref->InterferenceOnS1().LastParameter(),
1714                 ref->InterferenceOnS2().LastParameter() );
1715
1716   // (1.1) Finds the first point inside
1717   for (ii=1; ii<=Nbpnt && Line->Point(ii).Parameter()<VFirst; ii++) {}
1718   if (ii==1) ii++;
1719   P =  Line->Point(ii);
1720   b = P.Parameter();
1721   courant = P.PointOnS1().Distance(P.PointOnS2());
1722   P = Line->Point(ii-1);
1723   a = P.Parameter();    
1724   precedant = P.PointOnS1().Distance(P.PointOnS2());
1725   ii ++;
1726
1727   // (1.2) Find a minimum by "points"
1728   for ( ; ii<=Nbpnt && Line->Point(ii).Parameter()<=VLast; ii++) {
1729     for (;ii<=Nbpnt && 
1730          Line->Point(ii).Parameter()<VLast &&
1731          Line->Point(ii).Parameter()-b<Precision::PConfusion(); ii++) {}
1732
1733     const Blend_Point& pnt =  Line->Point(ii);
1734     c = pnt.Parameter();    
1735     suivant = pnt.PointOnS1().Distance(pnt.PointOnS2());
1736     if ( (courant <  precedant) && (courant < suivant) ) {
1737       // (1.3) Find the exact minimum
1738       math_FunctionRoot Resol(Fonc, (a+c)/2,
1739                               tol2d,//Surf->VResolution(toleps), 
1740                               a, c,
1741                               50);
1742       if (Resol.IsDone()) {
1743         Standard_Real Val, racine=Resol.Root();
1744         
1745         Fonc.Value(Resol.Root(), Val);
1746         if (Val< tolapp3d) { 
1747           // the solution (avoiding the risks of confusion)
1748           if (LesVi.Length()==0) {
1749             if ( (racine > VFirst+tol2d) &&
1750                  (racine < VLast -tol2d) ) {
1751                    LesVi.Append(racine);
1752                  }
1753           }
1754           else {
1755             if ( (racine > LesVi(LesVi.Length()) + tol2d) &&
1756                  (racine < VLast-tol2d) ) {
1757                    LesVi.Append(racine);
1758                  }
1759           }
1760         }
1761       }
1762       else {
1763 # if CHFI3D_DEB
1764         cout << "Failed calculation of the minimum length" << endl;
1765 # endif
1766       }
1767     }
1768     // update if non duplication
1769     a = b;
1770     precedant = courant;
1771     b = c;
1772     courant = suivant;
1773   }
1774
1775   // (2) Update of the sequence of SurfData
1776   if (LesVi.Length()>0) {
1777     TopOpeBRepDS_DataStructure& DStru = myDS->ChangeDS();
1778     Handle(ChFiDS_SurfData) SD;
1779     TopOpeBRepDS_Surface S;
1780     TopOpeBRepDS_Curve C1, C2;
1781     Standard_Real T, VertexTol;
1782     gp_Pnt P3d, P1, P2;
1783     ChFiDS_CommonPoint LePoint;
1784     for (ii=1 ; ii<=LesVi.Length(); ii++) {
1785
1786       T = LesVi(ii);
1787       // (2.0) copy and insertion
1788       SD = new (ChFiDS_SurfData);
1789       SD->Copy(ref);
1790       SeqData.InsertBefore(ii, SD);
1791       S = DStru.Surface(ref->Surf());
1792       SD->ChangeSurf(DStru.AddSurface(S));
1793       C1 = DStru.Curve(SD->InterferenceOnS1().LineIndex());
1794       SD->ChangeInterferenceOnS1().SetLineIndex( DStru.AddCurve(C1));
1795       C2 = DStru.Curve(SD->InterferenceOnS2().LineIndex());
1796       SD->ChangeInterferenceOnS2().SetLineIndex(DStru.AddCurve(C2));
1797
1798       // (2.1) Modification of common Point
1799       SD-> ChangeVertexLastOnS1().Reset();
1800       SD-> ChangeVertexLastOnS2().Reset();
1801       ref->ChangeVertexFirstOnS1().Reset();
1802       ref->ChangeVertexFirstOnS2().Reset();
1803       Courbe1->D0(T, P1);
1804       Courbe2->D0(T, P2);
1805       P3d.SetXYZ((P1.XYZ()+ P2.XYZ())/2);
1806       VertexTol = P1.Distance(P2);
1807       VertexTol += Max(C1.Tolerance(), C2.Tolerance());
1808
1809       SD->ChangeVertexLastOnS1().SetPoint(P3d);
1810       SD->ChangeVertexLastOnS2().SetPoint(P3d);
1811       ref->ChangeVertexFirstOnS1().SetPoint(P3d);
1812       ref->ChangeVertexFirstOnS2().SetPoint(P3d);
1813       SD->ChangeVertexLastOnS1().SetTolerance(VertexTol);
1814       SD->ChangeVertexLastOnS2().SetTolerance(VertexTol);
1815       ref->ChangeVertexFirstOnS1().SetTolerance(VertexTol);
1816       ref->ChangeVertexFirstOnS2().SetTolerance(VertexTol);     
1817
1818       // (2.2) Modification of interferences
1819       SD->ChangeInterferenceOnS1().SetLastParameter(T);
1820       SD->ChangeInterferenceOnS2().SetLastParameter(T);
1821       ref->ChangeInterferenceOnS1().SetFirstParameter(T);
1822       ref->ChangeInterferenceOnS2().SetFirstParameter(T);
1823
1824       // Parameters on ElSpine
1825       SD->LastSpineParam(T);
1826       ref->FirstSpineParam(T);
1827     }
1828   }
1829 }
1830
1831 //=======================================================================
1832 //function : ExtentOneCorner
1833 //purpose  : 
1834 //=======================================================================
1835
1836 void ChFi3d_FilBuilder::ExtentOneCorner(const TopoDS_Vertex& V,
1837                                         const Handle(ChFiDS_Stripe)& S)
1838 {
1839   // review by using the data at end of fillets (point, radius, normal
1840   // to the faces and tangents of the guideline).
1841   Standard_Integer      Sens = 0;
1842   Standard_Real         Coeff = 0.5;
1843   Handle(ChFiDS_Spine)  Spine = S->Spine();
1844   ChFi3d_IndexOfSurfData(V,S,Sens);
1845   Standard_Real dU = Spine->LastParameter(Spine->NbEdges());
1846   if (Spine->IsTangencyExtremity((Sens == 1))) 
1847     return; //No extension in the queue
1848
1849   if (Spine->Status((Sens == 1)) == ChFiDS_FreeBoundary) {
1850     Coeff *= 2; // It is necessary to go to the end and to evaluate the length
1851   }
1852
1853   if (Sens == 1) {
1854     Spine->SetFirstParameter(-dU*Coeff);
1855     Spine->SetFirstTgt(0.);
1856   }
1857   else{
1858     Spine->SetLastParameter(dU*(1.+Coeff));
1859     Spine->SetLastTgt(dU);
1860   }
1861 }
1862
1863 //=======================================================================
1864 //function : ExtentTwoCorner
1865 //purpose  : 
1866 //=======================================================================
1867
1868 void ChFi3d_FilBuilder::ExtentTwoCorner(const TopoDS_Vertex& V,
1869                                         const ChFiDS_ListOfStripe& LS)
1870 {
1871   // Review by using the data at end of fillets (point, radius, normal
1872   // to faces and tangents to the guideline.
1873   Standard_Integer Sens;
1874   Standard_Real    Coeff = 0.3, Eval=0.0, dU, rad;
1875   ChFiDS_ListIteratorOfListOfStripe itel(LS);
1876   Standard_Boolean FF = Standard_True;
1877   Handle(ChFiDS_Stripe) Stripe;
1878   Handle(ChFiDS_Spine)  Spine;
1879
1880   // A value of symetric extension is calculated
1881   for ( ; itel.More(); itel.Next()) {    
1882    Stripe = itel.Value();
1883    Spine = Stripe->Spine();
1884    dU = Spine->LastParameter(Spine->NbEdges())*Coeff;
1885    Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Spine);
1886    if (fsp->IsConstant()) 
1887      rad =  fsp->Radius();
1888    else
1889      {
1890        TopoDS_Edge E = ChFi3d_EdgeFromV1( V, itel.Value(), Sens);
1891        rad = MaxRad( fsp, E );
1892        /*
1893        IE = ChFi3d_IndexOfSurfData(V,itel.Value(),Sens);
1894        rad = MaxRad(fsp, IE);
1895        */
1896      }
1897    rad *= 1.5;
1898    if (rad > dU) dU = rad;
1899    if (dU > Eval) Eval = dU;
1900  }
1901
1902   // One applies
1903   for (itel.Initialize(LS) ; itel.More(); itel.Next()) {    
1904     ChFi3d_IndexOfSurfData(V,itel.Value(),Sens);
1905     if (!FF && Stripe == itel.Value()) Sens = -Sens;
1906     Stripe = itel.Value();
1907     Spine = Stripe->Spine();
1908     if (! Spine->IsTangencyExtremity((Sens == 1))) { //No extension on queue
1909       if (Sens == 1){ 
1910         Spine->SetFirstParameter(-Eval);
1911         Spine->SetFirstTgt(0.);
1912       }
1913       else{
1914         dU = Spine->LastParameter(Spine->NbEdges());
1915         Spine->SetLastParameter(dU+Eval);
1916         Spine->SetLastTgt(dU);
1917       }
1918       FF = Standard_False;
1919     }
1920   }
1921 }
1922
1923
1924 //=======================================================================
1925 //function : ExtentThreeCorner
1926 //purpose  : 
1927 //=======================================================================
1928
1929 void ChFi3d_FilBuilder::ExtentThreeCorner(const TopoDS_Vertex& V,
1930                                           const ChFiDS_ListOfStripe& LS)
1931 {
1932   // Review by using the data at end of fillets (point, radius, normal
1933   // to faces and tangents to the guideline.
1934   Standard_Integer Sens = 0;
1935   Standard_Real    Coeff = 0.1;
1936   ChFiDS_ListOfStripe check;
1937 //  Standard_Boolean FF = Standard_True;
1938   for(ChFiDS_ListIteratorOfListOfStripe itel(LS); itel.More(); itel.Next()) {    
1939     Handle(ChFiDS_Stripe) Stripe = itel.Value(); 
1940     ChFi3d_IndexOfSurfData(V,Stripe,Sens);
1941     for(ChFiDS_ListIteratorOfListOfStripe ich(check); ich.More(); ich.Next()){
1942       if(Stripe == ich.Value()){
1943         Sens = -Sens;
1944         break;
1945       }
1946     }
1947     Handle(ChFiDS_Spine) Spine = Stripe->Spine();
1948     if (Spine->IsTangencyExtremity((Sens == 1))) return; //No extension on queue
1949     Standard_Real dU = Spine->LastParameter(Spine->NbEdges());
1950     if (Sens == 1){ 
1951       Spine->SetFirstParameter(-dU*Coeff);
1952       Spine->SetFirstTgt(0.);
1953     }
1954     else{
1955       Spine->SetLastParameter(dU*(1.+Coeff));
1956       Spine->SetLastTgt(dU);
1957     }
1958     check.Append(Stripe);
1959   }
1960 }
1961
1962
1963 //=======================================================================
1964 //function : SetRegul
1965 //purpose  : 
1966 //=======================================================================
1967
1968 void ChFi3d_FilBuilder::SetRegul()
1969
1970 {
1971   ChFiDS_ListIteratorOfRegularities it;
1972   TopTools_ListIteratorOfListOfShape itc;
1973   TopTools_ListIteratorOfListOfShape its1;
1974   TopTools_ListIteratorOfListOfShape its2;
1975   BRep_Builder B;
1976   for (it.Initialize(myRegul); it.More(); it.Next()){
1977     const ChFiDS_Regul& reg = it.Value();
1978     itc.Initialize(myCoup->NewEdges(reg.Curve()));
1979     if(itc.More()){
1980       TopoDS_Edge E = TopoDS::Edge(itc.Value());
1981       if(reg.IsSurface1()) its1.Initialize(myCoup->NewFaces(reg.S1()));
1982       else its1.Initialize(myCoup->Merged(myDS->Shape(reg.S1()),TopAbs_IN));
1983       if(reg.IsSurface2()) its2.Initialize(myCoup->NewFaces(reg.S2()));
1984       else its2.Initialize(myCoup->Merged(myDS->Shape(reg.S2()),TopAbs_IN));
1985       if(its1.More() && its2.More()){
1986         TopoDS_Face F1 = TopoDS::Face(its1.Value());
1987         TopoDS_Face F2 = TopoDS::Face(its2.Value());
1988         GeomAbs_Shape cont = ChFi3d_evalconti(E,F1,F2);
1989         B.Continuity(E,F1,F2,cont);
1990       }
1991     }
1992   }
1993 }