Warnings on vc14 were eliminated
[occt.git] / src / ChFi3d / ChFi3d_ChBuilder.cxx
1 // Created on: 1995-04-26
2 // Created by: Flore Lantheaume
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
18 #include <Adaptor3d_TopolTool.hxx>
19 #include <Blend_Point.hxx>
20 #include <BlendFunc_SectionShape.hxx>
21 #include <BRepAdaptor_Curve2d.hxx>
22 #include <BRepAdaptor_HCurve2d.hxx>
23 #include <BRepAdaptor_HSurface.hxx>
24 #include <BRepAdaptor_Surface.hxx>
25 #include <BRepBlend_Chamfer.hxx>
26 #include <BRepBlend_ChamfInv.hxx>
27 #include <BRepBlend_ChAsym.hxx>
28 #include <BRepBlend_ChAsymInv.hxx>
29 #include <BRepBlend_Line.hxx>
30 #include <BRepBlend_Walking.hxx>
31 #include <BRepTools.hxx>
32 #include <ChFi3d.hxx>
33 #include <ChFi3d_Builder_0.hxx>
34 #include <ChFi3d_ChBuilder.hxx>
35 #include <ChFiDS_ChamfSpine.hxx>
36 #include <ChFiDS_CircSection.hxx>
37 #include <ChFiDS_HData.hxx>
38 #include <ChFiDS_HElSpine.hxx>
39 #include <ChFiDS_ListIteratorOfListOfStripe.hxx>
40 #include <ChFiDS_ListIteratorOfRegularities.hxx>
41 #include <ChFiDS_ListOfStripe.hxx>
42 #include <ChFiDS_Regul.hxx>
43 #include <ChFiDS_SecHArray1.hxx>
44 #include <ChFiDS_Spine.hxx>
45 #include <ChFiDS_Stripe.hxx>
46 #include <ChFiDS_SurfData.hxx>
47 #include <ElSLib.hxx>
48 #include <Extrema_GenLocateExtPS.hxx>
49 #include <GeomAdaptor_HCurve.hxx>
50 #include <Standard_ConstructionError.hxx>
51 #include <Standard_DomainError.hxx>
52 #include <Standard_NotImplemented.hxx>
53 #include <TopAbs.hxx>
54 #include <TopoDS_Edge.hxx>
55 #include <TopoDS_Face.hxx>
56 #include <TopoDS_Shape.hxx>
57 #include <TopoDS_Vertex.hxx>
58 #include <TopOpeBRepBuild_HBuilder.hxx>
59 #include <TopOpeBRepDS_HDataStructure.hxx>
60 #include <TopTools_ListIteratorOfListOfShape.hxx>
61
62 #ifdef OCCT_DEBUG
63 extern Standard_Boolean ChFi3d_GettraceCHRON();
64 #endif
65
66 //=======================================================================
67 //function : SearchCommonFaces
68 //purpose  : search the 2 common faces <F1> and <F2> of the edge <E>
69 //           uses the EFMap and take the 2 first good faces 
70 //=======================================================================
71
72 void SearchCommonFaces(const ChFiDS_Map& EFMap, 
73                        const TopoDS_Edge& E,
74                        TopoDS_Face& F1,
75                        TopoDS_Face& F2)
76 {
77   TopoDS_Face Fc;
78   TopTools_ListIteratorOfListOfShape It;
79   
80   F1.Nullify();
81   F2.Nullify();
82   for ( It.Initialize(EFMap(E)); It.More(); It.Next() ) {
83     Fc = TopoDS::Face(It.Value());
84     if ( F1.IsNull() )
85       F1 = Fc;
86     else if ( !Fc.IsSame(F1) ) {
87       F2 = Fc;
88       break;
89     }
90   }
91
92   if (!F1.IsNull() && F2.IsNull() && BRepTools::IsReallyClosed( E, F1 ))
93     F2 = F1;
94 }
95
96 //=======================================================================
97 //function : ExtentSpinesOnCommonFace
98 //purpose  : Extend spines of two chamfers by distance dis1,dis2
99 //           on their common face
100 //           Two guide lines Spine1 and Spine2 cross in V
101 //           isfirst(i) = False if Spine(i) is oriented to V (i = 1,2)
102 //=======================================================================
103
104 void ExtentSpineOnCommonFace(Handle(ChFiDS_Spine)&  Spine1,
105                              Handle(ChFiDS_Spine)&  Spine2,
106                              const TopoDS_Vertex&   V,
107                              const Standard_Real    dis1,
108                              const Standard_Real    dis2,
109                              const Standard_Boolean isfirst1,
110                              const Standard_Boolean isfirst2)
111 {                 
112   Standard_Real tolesp = 1.e-7;
113
114     // alpha, the opening angle between two 
115     // tangents of two guidelines in V is found
116     Standard_Real tga1,tga2;
117     Standard_Real d1plus = 0., d2plus = 0.;
118
119     gp_Pnt tmp;
120     gp_Vec tg1, tg2;
121     Spine1->D1(Spine1->Absc(V),tmp,tg1);
122     Spine2->D1(Spine2->Absc(V),tmp,tg2);
123     tg1.Normalize();
124     tg2.Normalize();
125     if (isfirst1)  
126       tg1.Reverse();
127     if (isfirst2)  
128       tg2.Reverse();
129
130     Standard_Real cosalpha,sinalpha;   
131     cosalpha = tg1.Dot(tg2);
132     sinalpha = sqrt(1-cosalpha*cosalpha);
133     
134     //a1+a2 = alpha
135     Standard_Real temp;
136     temp = cosalpha+dis2/dis1;
137     if( Abs(temp) > tolesp ){
138       tga1 = sinalpha/temp;
139       d1plus = dis1/tga1;
140     }
141     temp = cosalpha+dis1/dis2;
142     if( Abs(temp) > tolesp ){
143       tga2 = sinalpha/temp;
144       d2plus = dis2/tga2;
145     }
146
147     //extension by the calculated distance
148     if (d1plus > 0.) {
149       d1plus *= 3.;
150       if (isfirst1){
151         Spine1->SetFirstParameter(-d1plus);
152         Spine1->SetFirstTgt(0.);
153       }
154       else{
155         Standard_Real param = Spine1->LastParameter(Spine1->NbEdges());
156         Spine1->SetLastParameter(d1plus+param);
157         Spine1->SetLastTgt(param);
158       }
159     }
160     if (d2plus > 0.) {
161       d2plus *= 1.5;
162       if (isfirst2){
163         Spine2->SetFirstParameter(-d2plus);
164         Spine2->SetFirstTgt(0.);
165       }
166       else{
167         Standard_Real param = Spine2->LastParameter(Spine2->NbEdges());
168         Spine2->SetLastParameter(d2plus+param);
169         Spine2->SetLastTgt(param);
170       }
171     }
172 }
173
174 //=======================================================================
175 //function : ChFi3d_ChBuilder
176 //purpose  : 
177 //=======================================================================
178
179 ChFi3d_ChBuilder::ChFi3d_ChBuilder(const TopoDS_Shape& S,
180                                    const Standard_Real Ta) : 
181                                           ChFi3d_Builder(S, Ta)
182 {
183 }
184
185
186 //=======================================================================
187 //function : Add
188 //purpose  : create a new stripe with a spine containing the edge <E>
189 //           add on the spine the tangential edges to <E>
190 //=======================================================================
191
192 void  ChFi3d_ChBuilder::Add(const TopoDS_Edge& E)
193 {
194
195   if(!Contains(E) && myEFMap.Contains(E)){
196     Handle(ChFiDS_Stripe) Stripe = new ChFiDS_Stripe();
197     Handle(ChFiDS_Spine)& Sp = Stripe->ChangeSpine();
198     Sp = new ChFiDS_ChamfSpine(tolesp);
199     Handle(ChFiDS_ChamfSpine) Spine = Handle(ChFiDS_ChamfSpine)::DownCast(Sp);
200
201     TopoDS_Edge E_wnt = E;
202     E_wnt.Orientation(TopAbs_FORWARD);
203     Spine->SetEdges(E_wnt);
204     if(PerformElement(Spine)){
205       PerformExtremity(Spine);
206       Spine->Load();
207       myListStripe.Append(Stripe);
208     }
209   }
210 }
211
212
213 //=======================================================================
214 //function : Add
215 //purpose  : create a new stripe with a ChamfSpine containing the edge <E>
216 //           with the distance <Dis>   on the face <F> 
217 //           . Add the tangential edges continuous to E in the spine
218 //           
219 //=======================================================================
220
221 void  ChFi3d_ChBuilder::Add(const Standard_Real Dis,
222                             const TopoDS_Edge& E,
223                             const TopoDS_Face& F)
224 {
225   if (!Contains(E)  && myEFMap.Contains(E)) {
226      
227     // Take the 2 common faces of the egde <E>
228     TopoDS_Face F1,F2;
229     SearchCommonFaces(myEFMap,E,F1,F2);
230
231     if (! F1.IsSame(F) && F2.IsSame(F) ) {
232       F2 = F1;
233       F1 = F;
234     }
235
236     if ( F1.IsSame(F)) {
237       TopoDS_Edge E_wnt = E;
238       E_wnt.Orientation(TopAbs_FORWARD);
239       BRepAdaptor_Surface Sb1,Sb2;
240       Sb1.Initialize(F1);
241       Sb2.Initialize(F2);
242       TopAbs_Orientation Or1,Or2;
243       ChFi3d::ConcaveSide(Sb1,Sb2,E_wnt,Or1,Or2); 
244       Handle(ChFiDS_Stripe) Stripe = new ChFiDS_Stripe();
245       Handle(ChFiDS_Spine)& Sp = Stripe->ChangeSpine();
246       Sp = new ChFiDS_ChamfSpine(tolesp);
247       Handle(ChFiDS_ChamfSpine) 
248         Spine = Handle(ChFiDS_ChamfSpine)::DownCast(Sp);
249
250       Spine->SetEdges(E_wnt);
251       if(PerformElement(Spine)){
252         Spine->Load();
253         myListStripe.Append(Stripe);
254         
255         Spine->SetDist(Dis);
256
257         PerformExtremity(Spine);
258       }
259     }
260   }
261 }
262
263
264 //=======================================================================
265 //function : SetDist
266 //purpose  : set the distances <Dis>of the contour of 
267 //           index IC
268 //=======================================================================
269
270 void  ChFi3d_ChBuilder::SetDist(const Standard_Real    Dis,
271                                 const Standard_Integer IC,
272                                 const TopoDS_Face&     F)
273 {
274
275   if(IC <= NbElements()) {
276     Handle(ChFiDS_ChamfSpine) csp = Handle(ChFiDS_ChamfSpine)::DownCast(Value(IC));
277
278     // Search the first edge which has a common face equal to F
279     TopoDS_Face F1,F2,FirstF1,FirstF2;
280     //TopAbs_Orientation Or1,Or2;
281     //Standard_Integer Choix, ChoixConge;
282     BRepAdaptor_Surface Sb1,Sb2;
283     Standard_Integer i = 1;
284     Standard_Boolean Found = Standard_False;
285     while ( (i <= csp->NbEdges()) && (!Found) ) {
286       SearchCommonFaces(myEFMap,csp->Edges(i),F1,F2);
287       if ( i == 1) {
288         FirstF1 = F1;
289         FirstF2 = F2;
290       }
291       Found = ( F1.IsSame(F) || F2.IsSame(F) );
292       i++;
293     }
294
295     if (Found) {
296       if ( F2.IsSame(F) ) {
297         F2 = F1;
298         F1 = F;
299       }
300       csp->SetDist(Dis);
301
302     }
303     else
304       throw Standard_DomainError("the face is not common to any of edges of the contour");
305
306   }
307 }
308
309
310 //=======================================================================
311 //function : GetDist
312 //purpose  : 
313 //=======================================================================
314
315 void ChFi3d_ChBuilder::GetDist(const Standard_Integer  IC,
316                                Standard_Real&          Dis) const
317 {
318     Handle(ChFiDS_ChamfSpine) chsp = Handle(ChFiDS_ChamfSpine)::DownCast(Value(IC));
319     chsp->GetDist(Dis);
320
321 }
322
323
324 //=======================================================================
325 //function : Add
326 //purpose  : create a new stripe with a ChAsymSpine containing the edge <E>
327 //           with the distance <Dis> and the angle Angle  on the face <F> 
328 //           . Add the tangential edges continuous to E in the spine
329 //           
330 //=======================================================================
331
332 void  ChFi3d_ChBuilder::Add(const Standard_Real Dis1,
333                             const Standard_Real Dis2,
334                             const TopoDS_Edge& E,
335                             const TopoDS_Face& F)
336 {
337   if (!Contains(E)  && myEFMap.Contains(E)) {
338      
339     // Take the 2 common faces of the egde <E>
340     TopoDS_Face F1,F2;
341     SearchCommonFaces(myEFMap,E,F1,F2);
342
343     if (! F1.IsSame(F) && F2.IsSame(F) ) {
344       F2 = F1;
345       F1 = F;
346     }
347
348     if ( F1.IsSame(F)) {
349       TopoDS_Edge E_wnt = E;
350       E_wnt.Orientation(TopAbs_FORWARD);
351       BRepAdaptor_Surface Sb1,Sb2;
352       Sb1.Initialize(F1);
353       Sb2.Initialize(F2);
354       TopAbs_Orientation Or1,Or2;
355       Standard_Integer Choix = ChFi3d::ConcaveSide(Sb1,Sb2,E_wnt,Or1,Or2); 
356
357       Handle(ChFiDS_Stripe) Stripe = new ChFiDS_Stripe();
358       Handle(ChFiDS_Spine)& Sp = Stripe->ChangeSpine();
359       Sp = new ChFiDS_ChamfSpine(tolesp);
360       Handle(ChFiDS_ChamfSpine) 
361         Spine = Handle(ChFiDS_ChamfSpine)::DownCast(Sp);
362
363       Spine->SetEdges(E_wnt);
364       if(PerformElement(Spine)){
365         Spine->Load();
366         myListStripe.Append(Stripe);
367         
368         Standard_Integer ChoixConge;
369         SearchCommonFaces(myEFMap,Spine->Edges(1),F1,F2);
370         Sb1.Initialize(F1);
371         Sb2.Initialize(F2);
372         ChoixConge = ChFi3d::ConcaveSide(Sb1,Sb2,
373                                          Spine->Edges(1),
374                                          Or1,Or2);
375
376
377         // compare the 2 computed choices to know how to set the 
378         // distances of the Spine according to the choice done 
379         // on the added edge <e>
380         if ( ChoixConge%2 != Choix%2 )
381           Spine->SetDists(Dis2, Dis1);
382         else Spine->SetDists(Dis1, Dis2);
383
384         PerformExtremity(Spine);
385       }
386     }
387   }
388 }
389
390
391 //=======================================================================
392 //function : SetDists
393 //purpose  : set the distances <Dis1> and <Dis2> of the contour of 
394 //           index IC
395 //=======================================================================
396
397 void  ChFi3d_ChBuilder::SetDists(const Standard_Real    Dis1,
398                                  const Standard_Real    Dis2,
399                                  const Standard_Integer IC,
400                                  const TopoDS_Face&     F)
401 {
402
403   if(IC <= NbElements()) {
404     Handle(ChFiDS_ChamfSpine) csp = Handle(ChFiDS_ChamfSpine)::DownCast(Value(IC));
405
406     // Search the first edge which has a common face equal to F
407     TopoDS_Face F1,F2,FirstF1,FirstF2;
408     TopAbs_Orientation Or1,Or2;
409     Standard_Integer Choix, ChoixConge;
410     BRepAdaptor_Surface Sb1,Sb2;
411     Standard_Integer i = 1;
412     Standard_Boolean Found = Standard_False;
413     while ( (i <= csp->NbEdges()) && (!Found) ) {
414       SearchCommonFaces(myEFMap,csp->Edges(i),F1,F2);
415       if ( i == 1) {
416         FirstF1 = F1;
417         FirstF2 = F2;
418       }
419       Found = ( F1.IsSame(F) || F2.IsSame(F) );
420       i++;
421     }
422
423     if (Found) {
424       if ( F2.IsSame(F) ) {
425         F2 = F1;
426         F1 = F;
427       }
428       Sb1.Initialize(F1);
429       Sb2.Initialize(F2);
430       Choix = ChFi3d::ConcaveSide(Sb1,Sb2,
431                                   csp->Edges(i-1),
432                                   Or1,Or2);
433       Sb1.Initialize(FirstF1);
434       Sb2.Initialize(FirstF2);
435       ChoixConge = ChFi3d::ConcaveSide(Sb1,Sb2,
436                                        csp->Edges(1),
437                                        Or1,Or2);
438       if ( ChoixConge%2 != Choix%2 )
439         csp->SetDists(Dis2,Dis1);
440       else csp->SetDists(Dis1,Dis2);
441     }
442     else
443       throw Standard_DomainError("the face is not common to any of edges of the contour");
444
445   }
446 }
447
448
449 //=======================================================================
450 //function : Dists
451 //purpose  : 
452 //=======================================================================
453
454 void ChFi3d_ChBuilder::Dists(const Standard_Integer  IC,
455                              Standard_Real&          dis1,
456                              Standard_Real&          dis2) const
457 {
458     Handle(ChFiDS_ChamfSpine) chsp = Handle(ChFiDS_ChamfSpine)::DownCast(Value(IC));
459     Standard_Real temp1, temp2;
460     chsp->Dists(temp1,temp2);
461     dis1 = temp1;
462     dis2 = temp2;
463 }
464
465
466 //=======================================================================
467 //function : Add
468 //purpose  : create a new stripe with a ChAsymSpine containing the edge <E>
469 //           with the distance <Dis> and the angle Angle  on the face <F> 
470 //           . Add the tangential edges continuous to E in the spine
471 //           
472 //=======================================================================
473
474 void  ChFi3d_ChBuilder::AddDA(const Standard_Real Dis1,
475                               const Standard_Real Angle,
476                               const TopoDS_Edge& E,
477                               const TopoDS_Face& F)
478 {
479   if (!Contains(E)  && myEFMap.Contains(E)) {
480      
481     // Take the 2 common faces of the egde <E>
482     TopoDS_Face F1,F2;
483     SearchCommonFaces(myEFMap,E,F1,F2);
484  
485     if (! F1.IsSame(F) && F2.IsSame(F) ) {
486       F2 = F1;
487       F1 = F;
488     }
489
490     if ( F1.IsSame(F)) {
491       TopoDS_Edge E_wnt = E;
492       E_wnt.Orientation(TopAbs_FORWARD);
493       BRepAdaptor_Surface Sb1,Sb2;
494       Sb1.Initialize(F1);
495       Sb2.Initialize(F2);
496       TopAbs_Orientation Or1,Or2;
497       Standard_Integer Choix = ChFi3d::ConcaveSide(Sb1,Sb2,E_wnt,Or1,Or2); 
498
499       Handle(ChFiDS_Stripe) Stripe = new ChFiDS_Stripe();
500       Handle(ChFiDS_Spine)& Sp = Stripe->ChangeSpine();
501       Sp = new ChFiDS_ChamfSpine(tolesp);
502       Handle(ChFiDS_ChamfSpine) 
503         Spine = Handle(ChFiDS_ChamfSpine)::DownCast(Sp);
504
505       Spine->SetEdges(E_wnt);
506       if(PerformElement(Spine)){
507         Spine->Load();
508         myListStripe.Append(Stripe);
509         
510         Standard_Integer ChoixConge;
511         SearchCommonFaces(myEFMap,Spine->Edges(1),F1,F2);
512         Sb1.Initialize(F1);
513         Sb2.Initialize(F2);
514         ChoixConge = ChFi3d::ConcaveSide(Sb1,Sb2,
515                                          Spine->Edges(1),
516                                          Or1,Or2);
517
518         // compare the 2 computed choices to know how to set the 
519         // distances of the Spine according to the choice done 
520         // on the added edge <e>
521         if ( ChoixConge%2 != Choix%2 ) {
522           Spine->SetDistAngle(Dis1, Angle, Standard_False);
523         }
524         else { 
525           Spine->SetDistAngle(Dis1, Angle, Standard_True);
526         }
527         
528         PerformExtremity(Spine);
529       }
530     }
531   }
532 }
533
534
535 //=======================================================================
536 //function : SetDistAngle
537 //purpose  : set the distances <Dis> and <Angle> of the contour of 
538 //           index IC
539 //=======================================================================
540
541 void  ChFi3d_ChBuilder::SetDistAngle(const Standard_Real    Dis,
542                                      const Standard_Real    Angle,
543                                      const Standard_Integer IC,
544                                      const TopoDS_Face&     F)
545 {
546
547   if(IC <= NbElements()) {
548     Handle(ChFiDS_ChamfSpine) csp = Handle(ChFiDS_ChamfSpine)::DownCast(Value(IC));
549
550     // Search the first edge which has a common face equal to F
551     TopoDS_Face F1,F2,FirstF1,FirstF2;
552     TopAbs_Orientation Or1,Or2;
553     Standard_Integer Choix, ChoixConge;
554     BRepAdaptor_Surface Sb1,Sb2;
555     Standard_Integer i = 1;
556     Standard_Boolean Found = Standard_False;
557 //    Standard_Boolean DisOnF1 = Standard_True;
558
559     while ( (i <= csp->NbEdges()) && (!Found) ) {
560       SearchCommonFaces(myEFMap,csp->Edges(i),F1,F2);
561       if ( i == 1) {
562         FirstF1 = F1;
563         FirstF2 = F2;
564       }
565       Found = ( F1.IsSame(F) || F2.IsSame(F) );
566       i++;
567     }
568
569     if (Found) {
570       if ( F2.IsSame(F) ) {
571         F2 = F1;
572         F1 = F;
573       }
574       Sb1.Initialize(F1);
575       Sb2.Initialize(F2);
576       Choix = ChFi3d::ConcaveSide(Sb1,Sb2,
577                                   csp->Edges(i-1),
578                                   Or1,Or2);
579       Sb1.Initialize(FirstF1);
580       Sb2.Initialize(FirstF2);
581       ChoixConge = ChFi3d::ConcaveSide(Sb1,Sb2,
582                                        csp->Edges(1),
583                                        Or1,Or2);
584       if ( ChoixConge%2 != Choix%2 ) {
585         csp->SetDistAngle(Dis, Angle, Standard_False);
586       }
587       else {
588         csp->SetDistAngle(Dis, Angle, Standard_True);
589       }
590     }
591     else
592       throw Standard_DomainError("the face is not common to any edges of the contour");
593
594   }
595 }
596
597
598 //=======================================================================
599 //function : GetDistAngle
600 //purpose  : 
601 //=======================================================================
602
603 void ChFi3d_ChBuilder::GetDistAngle(const Standard_Integer  IC,
604                                     Standard_Real&          Dis,
605                                     Standard_Real&          Angle,
606                                     Standard_Boolean&       DisOnFace1) const
607 {
608     Handle(ChFiDS_ChamfSpine) chsp = Handle(ChFiDS_ChamfSpine)::DownCast(Value(IC));
609
610     chsp->GetDistAngle(Dis, Angle, DisOnFace1);
611 }
612
613 //=======================================================================
614 //function : IsChamfer
615 //purpose  : 
616 //=======================================================================
617 ChFiDS_ChamfMethod ChFi3d_ChBuilder::IsChamfer(const Standard_Integer  IC) const
618 {
619   Handle(ChFiDS_ChamfSpine) chsp = Handle(ChFiDS_ChamfSpine)::DownCast(Value(IC));
620     
621   ChFiDS_ChamfMethod ret = chsp->IsChamfer();
622
623   return ret;
624
625 }
626
627 //=======================================================================
628 //function : ResetContour
629 //purpose  : 
630 //=======================================================================
631
632 void  ChFi3d_ChBuilder::ResetContour(const Standard_Integer IC)
633 {
634   if(IC <= NbElements()) {
635     Handle(ChFiDS_ChamfSpine) chsp = Handle(ChFiDS_ChamfSpine)::DownCast(Value(IC));
636     chsp->Reset(Standard_True);
637   }
638 }
639
640 //--------------------------------AJOUT----------------------------------
641 //=======================================================================
642 //function : Simulate
643 //purpose  : 
644 //=======================================================================
645
646 void ChFi3d_ChBuilder::Simulate (const Standard_Integer IC)
647 {
648 #ifdef OCCT_DEBUG
649   if(ChFi3d_GettraceCHRON()){
650     simul.Reset();elspine.Reset();chemine.Reset();
651     simul.Start();
652   }
653 #endif
654   ChFiDS_ListIteratorOfListOfStripe itel;
655   Standard_Integer i = 1;
656   for (itel.Initialize(myListStripe);itel.More(); itel.Next(), i++) {
657     if(i == IC){
658       PerformSetOfSurf(itel.Value(), Standard_True);
659       break;
660     }
661   }
662 #ifdef OCCT_DEBUG
663   if(ChFi3d_GettraceCHRON()){
664     simul.Stop();
665     cout<<"Total simulation time : ";
666     simul.Show();
667     cout<<"Spine construction time : ";
668     elspine.Show();
669     cout<<"and progression time : ";
670     chemine.Show();
671   }
672 #endif
673 }
674
675 //---------------------------AJOUT---------------------------------------
676 //=======================================================================
677 //function : NbSurf
678 //purpose  : 
679 //=======================================================================
680
681 Standard_Integer ChFi3d_ChBuilder::NbSurf (const Standard_Integer IC) const 
682 {
683   ChFiDS_ListIteratorOfListOfStripe itel;
684   Standard_Integer i = 1;
685   for (itel.Initialize(myListStripe);itel.More(); itel.Next(), i++) {
686     if(i == IC){
687       return itel.Value()->SetOfSurfData()->Length();
688     }
689   }
690   return 0;
691 }
692
693
694 //--------------------------AJOUT---------------------------------------
695 //=======================================================================
696 //function : Sect
697 //purpose  : 
698 //=======================================================================
699
700 Handle(ChFiDS_SecHArray1) ChFi3d_ChBuilder::Sect (const Standard_Integer IC,
701                                                   const Standard_Integer IS) const 
702 {
703   ChFiDS_ListIteratorOfListOfStripe itel;
704   Standard_Integer i = 1;
705   Handle(ChFiDS_SecHArray1) res;
706   for (itel.Initialize(myListStripe);itel.More(); itel.Next(), i++) {
707     if(i == IC){
708       Handle(MMgt_TShared) bid = itel.Value()->SetOfSurfData()->Value(IS)->Simul();
709       res = Handle(ChFiDS_SecHArray1)::DownCast(bid);
710       return res;
711     }
712   }
713   return Handle(ChFiDS_SecHArray1)();
714 }
715
716
717 //-------------------MODIFS---------------------------------------------
718 //=======================================================================
719 //function : SimulKPart
720 //purpose  : Stores simulating sections in simul
721 //=======================================================================
722
723 void  ChFi3d_ChBuilder::SimulKPart(const Handle(ChFiDS_SurfData)& SD ) const 
724 {
725   TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
726   Handle(Geom_Surface) S = DStr.Surface(SD->Surf()).Surface();
727   gp_Pnt2d p1f = SD->InterferenceOnS1().PCurveOnSurf()->
728     Value(SD->InterferenceOnS1().FirstParameter());
729   gp_Pnt2d p1l = SD->InterferenceOnS1().PCurveOnSurf()->
730     Value(SD->InterferenceOnS1().LastParameter());
731   gp_Pnt2d p2f = SD->InterferenceOnS2().PCurveOnSurf()->
732     Value(SD->InterferenceOnS2().FirstParameter());
733   gp_Pnt2d p2l = SD->InterferenceOnS2().PCurveOnSurf()->
734     Value(SD->InterferenceOnS2().LastParameter());
735   GeomAdaptor_Surface AS(S);
736   Handle(ChFiDS_SecHArray1) sec;
737   Standard_Real u1,v1,u2,v2;
738   GeomAbs_SurfaceType typ = AS.GetType();
739   switch (typ){
740   case GeomAbs_Plane:
741     {
742       v1 = p1f.Y();
743       v2 = p2f.Y();
744       u1 = Max(p1f.X(),p2f.X());
745       u2 = Min(p1l.X(),p2l.X());
746       sec = new ChFiDS_SecHArray1(1,2); 
747       gp_Pln Pl = AS.Plane();
748       ChFiDS_CircSection& sec1 = sec->ChangeValue(1);
749       ChFiDS_CircSection& sec2 = sec->ChangeValue(2);
750       sec1.Set(ElSLib::PlaneUIso(Pl.Position(),u1),v1,v2);
751       sec2.Set(ElSLib::PlaneUIso(Pl.Position(),u2),v1,v2);
752     }
753     break;
754   case GeomAbs_Cone:
755     {
756       v1 = p1f.Y();
757       v2 = p2f.Y();
758       u1 = Max(p1f.X(),p2f.X());
759       u2 = Min(p1l.X(),p2l.X());
760       Standard_Real ang = (u2-u1);
761       gp_Cone Co = AS.Cone();
762       Standard_Real rad = Co.RefRadius(), sang = Co.SemiAngle();
763       Standard_Integer n = (Standard_Integer) (36.*ang/M_PI + 1);
764       if(n<2) n = 2;
765       sec = new ChFiDS_SecHArray1(1, n);
766       for (Standard_Integer i = 1; i <= n; i++) {
767         ChFiDS_CircSection& isec = sec->ChangeValue(i);
768         Standard_Real u = u1 + (i - 1)*(u2 - u1)/(n-1);
769         isec.Set(ElSLib::ConeUIso(Co.Position(), rad, sang, u), v1, v2);  
770       }
771     }
772     break;
773   default:
774     break;
775   }
776   SD->SetSimul(sec);
777 }
778
779 //------------------------MODIFS---------------------------------------
780 //=======================================================================
781 //function : SimulSurf
782 //purpose  : 
783 //=======================================================================
784
785 Standard_Boolean
786 ChFi3d_ChBuilder::SimulSurf(Handle(ChFiDS_SurfData)&            Data,
787                             const Handle(ChFiDS_HElSpine)&      HGuide,
788                             const Handle(ChFiDS_Spine)&         Spine,
789                             const Standard_Integer              Choix,
790                             const Handle(BRepAdaptor_HSurface)& S1,
791                             const Handle(Adaptor3d_TopolTool)&    I1,
792                             const Handle(BRepAdaptor_HSurface)& S2,
793                             const Handle(Adaptor3d_TopolTool)&    I2,
794                             const Standard_Real                 TolGuide,
795                             Standard_Real&                      First,
796                             Standard_Real&                      Last,
797                             const Standard_Boolean              Inside,
798                             const Standard_Boolean              Appro,
799                             const Standard_Boolean              Forward,
800                             const Standard_Boolean              RecOnS1,
801                             const Standard_Boolean              RecOnS2,
802                             const math_Vector&                  Soldep,
803                             Standard_Integer&                   intf,
804                             Standard_Integer&                   intl)
805      
806 {
807   Handle(ChFiDS_ChamfSpine) 
808     chsp = Handle(ChFiDS_ChamfSpine)::DownCast(Spine);
809   
810   if (chsp.IsNull()) 
811     throw Standard_ConstructionError("SimulSurf : this is not the spine of a chamfer");
812
813
814   Standard_Real radius;
815   // Flexible parameters!
816   Standard_Real la = HGuide->LastParameter(), fi = HGuide->FirstParameter();
817   Standard_Real longueur = la - fi;
818   Standard_Real MaxStep = longueur * 0.05;
819   Standard_Real radiusspine = 0, locfleche, w;
820   gp_Pnt Pbid;
821   gp_Vec d1,d2;
822   // As ElSpine is parameterized by a curvilinear quasi-abscissa,
823   // the min radius is estimated as 1/D2 max;
824   //for(Standard_Integer i = 0; i <= 20; i++){
825   Standard_Integer i;
826   for( i = 0; i <= 20; i++){ 
827     w = fi + i*MaxStep;
828     HGuide->D2(w,Pbid,d1,d2);
829     Standard_Real temp = d2.SquareMagnitude();
830     if(temp>radiusspine) radiusspine = temp;
831   }
832
833   Handle(BRepBlend_Line) lin;
834   Standard_Real PFirst = First;
835   if(intf) First = chsp->FirstParameter(1);
836   if(intl) Last = chsp->LastParameter(chsp->NbEdges());
837
838
839
840   if (chsp->IsChamfer() == ChFiDS_Sym) {
841     Standard_Real dis;
842     chsp->GetDist(dis);
843     radius = Max(dis, radiusspine);
844     locfleche = radius*1.e-2; //graphic criterion
845
846     BRepBlend_Chamfer Func(S1,S2,HGuide);
847     BRepBlend_ChamfInv FInv(S1,S2,HGuide); 
848     Func.Set(dis, dis, Choix);
849     FInv.Set(dis, dis, Choix);
850     
851     done = SimulData(Data,HGuide,lin,S1,I1,S2,I2,
852                      Func,FInv,PFirst,MaxStep,locfleche,
853                      TolGuide,First,Last,Inside,Appro,Forward,
854                      Soldep,4,RecOnS1,RecOnS2);
855
856     if ( !done ) return Standard_False;
857     Handle(ChFiDS_SecHArray1) sec;
858     gp_Pnt2d pf1,pl1,pf2,pl2;  
859     
860     Standard_Integer nbp = lin->NbPoints();
861     sec = new ChFiDS_SecHArray1(1,nbp);
862     for( i = 1; i <= nbp; i++ ){
863       ChFiDS_CircSection& isec = sec->ChangeValue(i);
864       Standard_Real u1,v1,u2,v2,ww,p1,p2;
865       gp_Lin line;
866       const Blend_Point& p = lin->Point(i);
867       p.ParametersOnS1(u1,v1);
868       p.ParametersOnS2(u2,v2);
869       ww = p.Parameter();
870       Func.Section(ww,u1,v1,u2,v2,p1,p2,line); 
871       isec.Set(line,p1,p2);
872       if(i == 1) {pf1.SetCoord(u1,v1); pf2.SetCoord(u2,v2);} 
873       if(i == nbp) {pl1.SetCoord(u1,v1); pl2.SetCoord(u2,v2);} 
874     }
875
876     Data->SetSimul(sec);
877     Data->Set2dPoints(pf1,pl1,pf2,pl2);
878     ChFi3d_FilCommonPoint(lin->StartPointOnFirst(),lin->TransitionOnS1(),
879                           Standard_True, Data->ChangeVertexFirstOnS1(),tolesp);
880     ChFi3d_FilCommonPoint(lin->EndPointOnFirst(),lin->TransitionOnS1(),
881                           Standard_False,Data->ChangeVertexLastOnS1(),tolesp);
882     ChFi3d_FilCommonPoint(lin->StartPointOnSecond(),lin->TransitionOnS2(),
883                           Standard_True, Data->ChangeVertexFirstOnS2(),tolesp);
884     ChFi3d_FilCommonPoint(lin->EndPointOnSecond(),lin->TransitionOnS2(),
885                           Standard_False, Data->ChangeVertexLastOnS2(),tolesp);
886     
887     Standard_Boolean reverse = (!Forward || Inside);
888     if(intf && reverse){
889       Standard_Boolean ok = Standard_False;
890       const ChFiDS_CommonPoint& cp1 = Data->VertexFirstOnS1();
891       if(cp1.IsOnArc()){
892         TopoDS_Face F1 = S1->ChangeSurface().Face();
893         TopoDS_Face bid;
894         intf = !SearchFace(Spine,cp1,F1,bid);
895         ok = intf != 0;
896       }
897       const ChFiDS_CommonPoint& cp2 = Data->VertexFirstOnS2();
898       if(cp2.IsOnArc() && !ok){
899         TopoDS_Face F2 = S2->ChangeSurface().Face();
900         TopoDS_Face bid;
901         intf = !SearchFace(Spine,cp2,F2,bid);
902       }
903     }
904     if(intl){
905       Standard_Boolean ok = Standard_False;
906       const ChFiDS_CommonPoint& cp1 = Data->VertexLastOnS1();
907       if(cp1.IsOnArc()){
908         TopoDS_Face F1 = S1->ChangeSurface().Face();
909         TopoDS_Face bid;
910         intl = !SearchFace(Spine,cp1,F1,bid);
911         ok = intl != 0;
912       }
913       const ChFiDS_CommonPoint& cp2 = Data->VertexLastOnS2();
914       if(cp2.IsOnArc() && !ok){
915         TopoDS_Face F2 = S2->ChangeSurface().Face();
916         TopoDS_Face bid;
917         intl = !SearchFace(Spine,cp2,F2,bid);
918       }
919     }
920   }
921   else if (chsp->IsChamfer() == ChFiDS_TwoDist) {
922     Standard_Real dis1, dis2;
923     chsp->Dists(dis1, dis2);
924     radius = Max(dis1, dis2);
925     radius = Max(radius, radiusspine);
926     locfleche = radius*1.e-2; //graphic criterion
927
928     BRepBlend_Chamfer Func(S1,S2,HGuide);
929     BRepBlend_ChamfInv FInv(S1,S2,HGuide); 
930     Func.Set(dis1,dis2,Choix);
931     FInv.Set(dis1,dis2,Choix);
932     
933     done = SimulData(Data,HGuide,lin,S1,I1,S2,I2,
934                      Func,FInv,PFirst,MaxStep,locfleche,
935                      TolGuide,First,Last,Inside,Appro,Forward,
936                      Soldep,4,RecOnS1,RecOnS2);
937
938     if ( !done ) return Standard_False;
939     Handle(ChFiDS_SecHArray1) sec;
940     gp_Pnt2d pf1,pl1,pf2,pl2;  
941     
942     Standard_Integer nbp = lin->NbPoints();
943     sec = new ChFiDS_SecHArray1(1,nbp);
944     for( i = 1; i <= nbp; i++ ){
945       ChFiDS_CircSection& isec = sec->ChangeValue(i);
946       Standard_Real u1,v1,u2,v2,ww,p1,p2;
947       gp_Lin line;
948       const Blend_Point& p = lin->Point(i);
949       p.ParametersOnS1(u1,v1);
950       p.ParametersOnS2(u2,v2);
951       ww = p.Parameter();
952       Func.Section(ww,u1,v1,u2,v2,p1,p2,line); 
953       isec.Set(line,p1,p2);
954       if(i == 1) {pf1.SetCoord(u1,v1); pf2.SetCoord(u2,v2);} 
955       if(i == nbp) {pl1.SetCoord(u1,v1); pl2.SetCoord(u2,v2);} 
956     }
957     
958     Data->SetSimul(sec);
959     Data->Set2dPoints(pf1,pl1,pf2,pl2);
960     ChFi3d_FilCommonPoint(lin->StartPointOnFirst(),lin->TransitionOnS1(),
961                         Standard_True, Data->ChangeVertexFirstOnS1(),tolesp);
962     ChFi3d_FilCommonPoint(lin->EndPointOnFirst(),lin->TransitionOnS1(),
963                           Standard_False,Data->ChangeVertexLastOnS1(),tolesp);
964     ChFi3d_FilCommonPoint(lin->StartPointOnSecond(),lin->TransitionOnS2(),
965                           Standard_True, Data->ChangeVertexFirstOnS2(),tolesp);
966     ChFi3d_FilCommonPoint(lin->EndPointOnSecond(),lin->TransitionOnS2(),
967                           Standard_False, Data->ChangeVertexLastOnS2(),tolesp);
968     
969     Standard_Boolean reverse = (!Forward || Inside);
970     if(intf && reverse){
971       Standard_Boolean ok = Standard_False;
972       const ChFiDS_CommonPoint& cp1 = Data->VertexFirstOnS1();
973       if(cp1.IsOnArc()){
974         TopoDS_Face F1 = S1->ChangeSurface().Face();
975         TopoDS_Face bid;
976         intf = !SearchFace(Spine,cp1,F1,bid);
977         ok = intf != 0;
978       }
979       const ChFiDS_CommonPoint& cp2 = Data->VertexFirstOnS2();
980       if(cp2.IsOnArc() && !ok){
981         TopoDS_Face F2 = S2->ChangeSurface().Face();
982         TopoDS_Face bid;
983         intf = !SearchFace(Spine,cp2,F2,bid);
984       }
985     }
986     if(intl){
987       Standard_Boolean ok = Standard_False;
988       const ChFiDS_CommonPoint& cp1 = Data->VertexLastOnS1();
989       if(cp1.IsOnArc()){
990         TopoDS_Face F1 = S1->ChangeSurface().Face();
991         TopoDS_Face bid;
992         intl = !SearchFace(Spine,cp1,F1,bid);
993         ok = intl != 0;
994       }
995       const ChFiDS_CommonPoint& cp2 = Data->VertexLastOnS2();
996       if(cp2.IsOnArc() && !ok){
997         TopoDS_Face F2 = S2->ChangeSurface().Face();
998         TopoDS_Face bid;
999         intl = !SearchFace(Spine,cp2,F2,bid);
1000       }
1001     }
1002   }
1003   else  {
1004     Standard_Real dis, angle;
1005     Standard_Boolean disonF1;  
1006     chsp->GetDistAngle(dis, angle, disonF1);
1007     radius = Max(dis, dis * tan(angle));
1008     radius = Max(radius, radiusspine);
1009     locfleche = radius*1.e-2; //graphic criterion
1010
1011     Standard_Integer Ch = FindChoiceDistAngle(Choix, disonF1);
1012
1013     if (disonF1)  {
1014       BRepBlend_ChAsym    Func(S1,S2,HGuide);
1015       BRepBlend_ChAsymInv FInv(S1,S2,HGuide); 
1016
1017       Func.Set(dis, angle, Ch);
1018       FInv.Set(dis, angle, Ch);
1019
1020       done = SimulData(Data,HGuide,lin,S1,I1,S2,I2,
1021                        Func,FInv,PFirst,MaxStep,locfleche,
1022                        TolGuide,First,Last,Inside,Appro,Forward,
1023                        Soldep,4,RecOnS1,RecOnS2);
1024     
1025       if ( !done ) return Standard_False;
1026       Handle(ChFiDS_SecHArray1) sec;
1027       gp_Pnt2d pf1,pl1,pf2,pl2;  
1028       
1029       Standard_Integer nbp = lin->NbPoints();
1030       sec = new ChFiDS_SecHArray1(1,nbp);
1031       for( i = 1; i <= nbp; i++ ){
1032         ChFiDS_CircSection& isec = sec->ChangeValue(i);
1033         Standard_Real u1,v1,u2,v2,ww,p1,p2;
1034         gp_Lin line;
1035         const Blend_Point& p = lin->Point(i);
1036         p.ParametersOnS1(u1,v1);
1037         p.ParametersOnS2(u2,v2);
1038         ww = p.Parameter();
1039         Func.Section(ww,u1,v1,u2,v2,p1,p2,line); 
1040         isec.Set(line,p1,p2);
1041         if(i == 1) {pf1.SetCoord(u1,v1); pf2.SetCoord(u2,v2);} 
1042         if(i == nbp) {pl1.SetCoord(u1,v1); pl2.SetCoord(u2,v2);} 
1043       }
1044     
1045       Data->SetSimul(sec);
1046       Data->Set2dPoints(pf1,pl1,pf2,pl2);
1047       ChFi3d_FilCommonPoint(lin->StartPointOnFirst(),lin->TransitionOnS1(),
1048                             Standard_True, Data->ChangeVertexFirstOnS1(),tolesp);
1049       ChFi3d_FilCommonPoint(lin->EndPointOnFirst(),lin->TransitionOnS1(),
1050                             Standard_False,Data->ChangeVertexLastOnS1(),tolesp);
1051       ChFi3d_FilCommonPoint(lin->StartPointOnSecond(),lin->TransitionOnS2(),
1052                             Standard_True, Data->ChangeVertexFirstOnS2(),tolesp);
1053       ChFi3d_FilCommonPoint(lin->EndPointOnSecond(),lin->TransitionOnS2(),
1054                             Standard_False, Data->ChangeVertexLastOnS2(),tolesp);
1055
1056       Standard_Boolean reverse = (!Forward || Inside);
1057       if(intf && reverse){
1058         Standard_Boolean ok = Standard_False;
1059         const ChFiDS_CommonPoint& cp1 = Data->VertexFirstOnS1();
1060         if(cp1.IsOnArc()){
1061           TopoDS_Face F1 = S1->ChangeSurface().Face();
1062           TopoDS_Face bid;
1063           intf = !SearchFace(Spine,cp1,F1,bid);
1064           ok = intf != 0;
1065         }
1066         const ChFiDS_CommonPoint& cp2 = Data->VertexFirstOnS2();
1067         if(cp2.IsOnArc() && !ok){
1068           TopoDS_Face F2 = S2->ChangeSurface().Face();
1069           TopoDS_Face bid;
1070           intf = !SearchFace(Spine,cp2,F2,bid);
1071         }
1072       }
1073       
1074       if(intl){
1075         Standard_Boolean ok = Standard_False;
1076         const ChFiDS_CommonPoint& cp1 = Data->VertexLastOnS1();
1077         if(cp1.IsOnArc()){
1078           TopoDS_Face F1 = S1->ChangeSurface().Face();
1079           TopoDS_Face bid;
1080           intl = !SearchFace(Spine,cp1,F1,bid);
1081           ok = intl != 0;
1082         }
1083         const ChFiDS_CommonPoint& cp2 = Data->VertexLastOnS2();
1084         if(cp2.IsOnArc() && !ok){
1085           TopoDS_Face F2 = S2->ChangeSurface().Face();
1086           TopoDS_Face bid;
1087           intl = !SearchFace(Spine,cp2,F2,bid);
1088         }
1089       }
1090     }
1091     else {
1092       BRepBlend_ChAsym    Func(S2,S1,HGuide);
1093       BRepBlend_ChAsymInv FInv(S2,S1,HGuide); 
1094
1095       Func.Set(dis, angle, Ch);
1096       FInv.Set(dis, angle, Ch);
1097
1098       Standard_Real Rtemp;
1099       Rtemp     = Soldep(1);
1100       Soldep(1) = Soldep(3);
1101       Soldep(3) = Rtemp;
1102       Rtemp     = Soldep(2);
1103       Soldep(2) = Soldep(4);
1104       Soldep(4) = Rtemp;
1105
1106       done = SimulData(Data,HGuide,lin,S2,I2,S1,I1,
1107                        Func,FInv,PFirst,MaxStep,locfleche,
1108                        TolGuide,First,Last,Inside,Appro,Forward,
1109                        Soldep,4,RecOnS2,RecOnS1);
1110     
1111       if ( !done ) return Standard_False;
1112       Handle(ChFiDS_SecHArray1) sec;
1113       gp_Pnt2d pf1,pl1,pf2,pl2;  
1114       
1115       Standard_Integer nbp = lin->NbPoints();
1116       sec = new ChFiDS_SecHArray1(1,nbp);
1117       for( i = 1; i <= nbp; i++ ){
1118         ChFiDS_CircSection& isec = sec->ChangeValue(i);
1119         Standard_Real u1,v1,u2,v2,ww,p1,p2;
1120         gp_Lin line;
1121         const Blend_Point& p = lin->Point(i);
1122         p.ParametersOnS1(u1,v1);
1123         p.ParametersOnS2(u2,v2);
1124         ww = p.Parameter();
1125         Func.Section(ww,u1,v1,u2,v2,p1,p2,line); 
1126         isec.Set(line,p1,p2);
1127         if(i == 1) {pf1.SetCoord(u1,v1); pf2.SetCoord(u2,v2);} 
1128         if(i == nbp) {pl1.SetCoord(u1,v1); pl2.SetCoord(u2,v2);} 
1129       }
1130     
1131       Data->SetSimul(sec);
1132       Data->Set2dPoints(pf1,pl1,pf2,pl2);
1133       ChFi3d_FilCommonPoint(lin->StartPointOnFirst(),lin->TransitionOnS1(),
1134                             Standard_True, Data->ChangeVertexFirstOnS1(),tolesp);
1135       ChFi3d_FilCommonPoint(lin->EndPointOnFirst(),lin->TransitionOnS1(),
1136                             Standard_False,Data->ChangeVertexLastOnS1(),tolesp);
1137       ChFi3d_FilCommonPoint(lin->StartPointOnSecond(),lin->TransitionOnS2(),
1138                             Standard_True, Data->ChangeVertexFirstOnS2(),tolesp);
1139       ChFi3d_FilCommonPoint(lin->EndPointOnSecond(),lin->TransitionOnS2(),
1140                             Standard_False, Data->ChangeVertexLastOnS2(),tolesp);
1141
1142       Standard_Boolean reverse = (!Forward || Inside);
1143       if(intf && reverse){
1144         Standard_Boolean ok = Standard_False;
1145         const ChFiDS_CommonPoint& cp1 = Data->VertexFirstOnS1();
1146         if(cp1.IsOnArc()){
1147           TopoDS_Face F1 = S1->ChangeSurface().Face();
1148           TopoDS_Face bid;
1149           intf = !SearchFace(Spine,cp1,F1,bid);
1150           ok = intf != 0;
1151         }
1152         const ChFiDS_CommonPoint& cp2 = Data->VertexFirstOnS2();
1153         if(cp2.IsOnArc() && !ok){
1154           TopoDS_Face F2 = S2->ChangeSurface().Face();
1155           TopoDS_Face bid;
1156           intf = !SearchFace(Spine,cp2,F2,bid);
1157         }
1158       }
1159       
1160       if(intl){
1161         Standard_Boolean ok = Standard_False;
1162         const ChFiDS_CommonPoint& cp1 = Data->VertexLastOnS1();
1163         if(cp1.IsOnArc()){
1164           TopoDS_Face F1 = S1->ChangeSurface().Face();
1165           TopoDS_Face bid;
1166           intl = !SearchFace(Spine,cp1,F1,bid);
1167           ok = intl != 0;
1168         }
1169         const ChFiDS_CommonPoint& cp2 = Data->VertexLastOnS2();
1170         if(cp2.IsOnArc() && !ok){
1171           TopoDS_Face F2 = S2->ChangeSurface().Face();
1172           TopoDS_Face bid;
1173           intl = !SearchFace(Spine,cp2,F2,bid);
1174         }
1175       }
1176     }
1177   }
1178   return Standard_True;
1179 }
1180
1181 void  ChFi3d_ChBuilder::SimulSurf(Handle(ChFiDS_SurfData)&            ,
1182                                 const Handle(ChFiDS_HElSpine)&      , 
1183                                 const Handle(ChFiDS_Spine)&         , 
1184                                 const Standard_Integer              ,
1185                                 const Handle(BRepAdaptor_HSurface)& ,
1186                                 const Handle(Adaptor3d_TopolTool)&    ,
1187                                 const Handle(BRepAdaptor_HCurve2d)& ,
1188                                 const Handle(BRepAdaptor_HSurface)& ,
1189                                 const Handle(BRepAdaptor_HCurve2d)& ,
1190                                 Standard_Boolean&                   ,
1191                                 const Handle(BRepAdaptor_HSurface)& ,
1192                                 const Handle(Adaptor3d_TopolTool)&    ,
1193                                 const TopAbs_Orientation            ,
1194                                 const Standard_Real                 ,
1195                                 const Standard_Real                 ,
1196                                 Standard_Real&                      ,
1197                                 Standard_Real&                      ,
1198                                 const Standard_Boolean              ,
1199                                 const Standard_Boolean              ,
1200                                 const Standard_Boolean              ,
1201                                 const Standard_Boolean              ,
1202                                 const Standard_Boolean              ,
1203                                 const Standard_Boolean              ,
1204                                 const math_Vector&                  )
1205 {
1206   throw Standard_Failure("SimulSurf Not Implemented");
1207 }
1208 void  ChFi3d_ChBuilder::SimulSurf(Handle(ChFiDS_SurfData)&            ,
1209                                 const Handle(ChFiDS_HElSpine)&      , 
1210                                 const Handle(ChFiDS_Spine)&         , 
1211                                 const Standard_Integer              ,
1212                                 const Handle(BRepAdaptor_HSurface)& ,
1213                                 const Handle(Adaptor3d_TopolTool)&    ,
1214                                 const TopAbs_Orientation            ,
1215                                 const Handle(BRepAdaptor_HSurface)& ,
1216                                 const Handle(Adaptor3d_TopolTool)&    ,
1217                                 const Handle(BRepAdaptor_HCurve2d)& ,
1218                                 const Handle(BRepAdaptor_HSurface)& ,
1219                                 const Handle(BRepAdaptor_HCurve2d)& ,
1220                                 Standard_Boolean&                   ,
1221                                 const Standard_Real                 ,
1222                                 const Standard_Real                 ,
1223                                 Standard_Real&                      ,
1224                                 Standard_Real&                      ,
1225                                 const Standard_Boolean              ,
1226                                 const Standard_Boolean              ,
1227                                 const Standard_Boolean              ,
1228                                 const Standard_Boolean              ,
1229                                 const Standard_Boolean              ,
1230                                 const Standard_Boolean              ,
1231                                 const math_Vector&                  )
1232 {
1233   throw Standard_Failure("SimulSurf Not Implemented");
1234 }
1235 void  ChFi3d_ChBuilder::SimulSurf(Handle(ChFiDS_SurfData)&            ,
1236                                 const Handle(ChFiDS_HElSpine)&      ,
1237                                 const Handle(ChFiDS_Spine)&         ,
1238                                 const Standard_Integer              ,
1239                                 const Handle(BRepAdaptor_HSurface)& ,
1240                                 const Handle(Adaptor3d_TopolTool)&    ,
1241                                 const Handle(BRepAdaptor_HCurve2d)& ,
1242                                 const Handle(BRepAdaptor_HSurface)& ,
1243                                 const Handle(BRepAdaptor_HCurve2d)& ,
1244                                 Standard_Boolean&                   ,
1245                                 const TopAbs_Orientation            ,
1246                                 const Handle(BRepAdaptor_HSurface)& ,
1247                                 const Handle(Adaptor3d_TopolTool)&    ,
1248                                 const Handle(BRepAdaptor_HCurve2d)& ,
1249                                 const Handle(BRepAdaptor_HSurface)& ,
1250                                 const Handle(BRepAdaptor_HCurve2d)& ,
1251                                 Standard_Boolean&                   ,
1252                                 const TopAbs_Orientation            ,
1253                                 const Standard_Real                 ,
1254                                 const Standard_Real                 ,
1255                                 Standard_Real&                      ,
1256                                 Standard_Real&                      ,
1257                                 const Standard_Boolean              ,
1258                                 const Standard_Boolean              ,
1259                                 const Standard_Boolean              ,
1260                                 const Standard_Boolean              ,
1261                                 const Standard_Boolean              ,
1262                                 const Standard_Boolean              ,
1263                                 const Standard_Boolean              ,
1264                                 const math_Vector&                  )
1265 {
1266   throw Standard_Failure("SimulSurf Not Implemented");
1267 }
1268 //------------------------MODIFS---------------------------------------
1269 //=======================================================================
1270 //function : PerformFirstSection
1271 //purpose  : to implement the first section if there is no KPart
1272 //=======================================================================
1273
1274 Standard_Boolean ChFi3d_ChBuilder::PerformFirstSection
1275 (const Handle(ChFiDS_Spine)&         Spine,
1276  const Handle(ChFiDS_HElSpine)&      HGuide,
1277  const Standard_Integer              Choix,
1278  Handle(BRepAdaptor_HSurface)&       S1,
1279  Handle(BRepAdaptor_HSurface)&       S2,
1280  const Handle(Adaptor3d_TopolTool)&    I1,
1281  const Handle(Adaptor3d_TopolTool)&    I2,
1282  const Standard_Real                 Par,
1283  math_Vector&                        SolDep,
1284  TopAbs_State&                       Pos1,
1285  TopAbs_State&                       Pos2) const 
1286 {
1287   Handle(ChFiDS_ChamfSpine) 
1288     chsp = Handle(ChFiDS_ChamfSpine)::DownCast(Spine);
1289   
1290   if (chsp.IsNull()) 
1291     throw Standard_ConstructionError("PerformSurf : this is not the spine of a chamfer");
1292
1293   Standard_Real TolGuide = HGuide->Resolution(tolesp) ;
1294
1295
1296   if (chsp->IsChamfer() == ChFiDS_Sym) {
1297     Standard_Real dis;
1298     chsp->GetDist(dis);
1299     
1300     BRepBlend_Chamfer Func(S1,S2,HGuide);
1301     Func.Set(dis,dis,Choix);
1302     BRepBlend_Walking TheWalk(S1,S2,I1,I2,HGuide);
1303     
1304     //calculate an approximate starting solution
1305     gp_Vec TgF, TgL, tmp1, tmp2, d1gui;
1306     gp_Pnt pt1, pt2, ptgui;
1307     gp_XYZ temp;
1308     
1309     ( HGuide->Curve() ).D1(Par,ptgui,d1gui);
1310     //  ptgui = (S1->Surface()).Value(SolDep(1),SolDep(2));
1311     
1312     Func.Set(Par);
1313     Func.Tangent(SolDep(1),SolDep(2),SolDep(3),SolDep(4),TgF,TgL,tmp1,tmp2);
1314     
1315     Standard_Boolean rev1 = Standard_False;
1316     Standard_Boolean rev2 = Standard_False;
1317     Standard_Real    sign = (TgF.Crossed(d1gui)).Dot(TgL);
1318   
1319     if( Choix%2 == 1 )
1320       rev1 = Standard_True;
1321     else
1322       rev2 = Standard_True;
1323     
1324     if( sign < 0. ){
1325       rev1 = !rev1;
1326       rev2 = !rev2;
1327     }
1328     
1329     if( rev1 )
1330       TgF.Reverse();
1331     if( rev2 )
1332       TgL.Reverse();
1333     
1334     temp = (TgF.XYZ()).Multiplied(dis);
1335     pt1.SetXYZ( (ptgui.XYZ()).Added(temp) );
1336     temp = (TgL.XYZ()).Multiplied(dis);
1337     pt2.SetXYZ( (ptgui.XYZ()).Added(temp) );
1338     
1339     Standard_Real tol = tolesp*1.e2;
1340 //    Standard_Real u,v;
1341     Extrema_GenLocateExtPS proj1(S1->Surface(), tol, tol);
1342     proj1.Perform(pt1, SolDep(1), SolDep(2));
1343     Extrema_GenLocateExtPS proj2(S2->Surface(), tol, tol);
1344     proj2.Perform(pt2, SolDep(3), SolDep(4));
1345
1346     if( proj1.IsDone() ){
1347       (proj1.Point()).Parameter(SolDep(1),SolDep(2)); 
1348     }
1349     if( proj2.IsDone() ){
1350       (proj2.Point()).Parameter(SolDep(3),SolDep(4)); 
1351     }
1352     
1353     return TheWalk.PerformFirstSection(Func,Par,SolDep,
1354                                        tolesp,TolGuide,Pos1,Pos2);
1355   }
1356   else if (chsp->IsChamfer() == ChFiDS_TwoDist)  {
1357     Standard_Real dis1, dis2;
1358     chsp->Dists(dis1, dis2);
1359     
1360     BRepBlend_Chamfer Func(S1,S2,HGuide);
1361     Func.Set(dis1,dis2,Choix);
1362     BRepBlend_Walking TheWalk(S1,S2,I1,I2,HGuide);
1363     
1364     //calculate an approximate starting solution
1365     gp_Vec TgF, TgL, tmp1, tmp2, d1gui;
1366     gp_Pnt pt1, pt2, ptgui;
1367     gp_XYZ temp;
1368     
1369     ( HGuide->Curve() ).D1(Par,ptgui,d1gui);
1370     //  ptgui = (S1->Surface()).Value(SolDep(1),SolDep(2));
1371     
1372     Func.Set(Par);
1373     Func.Tangent(SolDep(1),SolDep(2),SolDep(3),SolDep(4),TgF,TgL,tmp1,tmp2);
1374     
1375     Standard_Boolean rev1 = Standard_False;
1376     Standard_Boolean rev2 = Standard_False;
1377     Standard_Real    sign = (TgF.Crossed(d1gui)).Dot(TgL);
1378   
1379     if( Choix%2 == 1 )
1380       rev1 = Standard_True;
1381     else
1382       rev2 = Standard_True;
1383     
1384     if( sign < 0. ){
1385       rev1 = !rev1;
1386       rev2 = !rev2;
1387     }
1388     
1389     if( rev1 )
1390       TgF.Reverse();
1391     if( rev2 )
1392       TgL.Reverse();
1393     
1394     temp = (TgF.XYZ()).Multiplied(dis1);
1395     pt1.SetXYZ( (ptgui.XYZ()).Added(temp) );
1396     temp = (TgL.XYZ()).Multiplied(dis2);
1397     pt2.SetXYZ( (ptgui.XYZ()).Added(temp) );
1398     
1399     Standard_Real tol = tolesp*1.e2;
1400 //    Standard_Real u,v;
1401
1402     Extrema_GenLocateExtPS proj1(S1->Surface(), tol, tol);
1403     proj1.Perform(pt1, SolDep(1), SolDep(2));
1404     Extrema_GenLocateExtPS proj2(S2->Surface(), tol, tol);
1405     proj2.Perform(pt2, SolDep(3), SolDep(4));
1406
1407     if( proj1.IsDone() ){
1408       (proj1.Point()).Parameter(SolDep(1),SolDep(2)); 
1409     }
1410     if( proj2.IsDone() ){
1411       (proj2.Point()).Parameter(SolDep(3),SolDep(4)); 
1412     }
1413     
1414     return TheWalk.PerformFirstSection(Func,Par,SolDep,
1415                                        tolesp,TolGuide,Pos1,Pos2);
1416   }
1417   else {
1418     Standard_Real dis1, angle;
1419     Standard_Boolean disonF1; 
1420     chsp->GetDistAngle(dis1, angle, disonF1);
1421     
1422     Standard_Integer Ch = FindChoiceDistAngle(Choix, disonF1);
1423     
1424     if (disonF1)  {
1425       BRepBlend_ChAsym Func(S1,S2,HGuide);
1426       Func.Set(dis1, angle, Ch);
1427       BRepBlend_Walking TheWalk(S1,S2,I1,I2,HGuide);
1428     
1429     //calculate an approximate starting solution
1430       gp_Vec TgF, TgL, tmp1, tmp2, d1gui;
1431       gp_Pnt pt1, pt2, ptgui;
1432       gp_XYZ temp;
1433       
1434       ( HGuide->Curve() ).D1(Par,ptgui,d1gui);
1435       //  ptgui = (S1->Surface()).Value(SolDep(1),SolDep(2));
1436       
1437       Func.Set(Par);
1438       Func.Tangent(SolDep(1),SolDep(2),SolDep(3),SolDep(4),TgF,TgL,tmp1,tmp2);
1439       
1440       Standard_Boolean rev1 = Standard_False;
1441       Standard_Boolean rev2 = Standard_False;
1442       Standard_Real    sign = (TgF.Crossed(d1gui)).Dot(TgL);
1443       
1444       if( Ch%2 == 1 )
1445         rev1 = Standard_True;
1446       else
1447         rev2 = Standard_True;
1448       
1449       if( sign < 0. ){
1450         rev1 = !rev1;
1451         rev2 = !rev2;
1452       }
1453       
1454       if( rev1 )
1455         TgF.Reverse();
1456       if( rev2 )
1457         TgL.Reverse();
1458   
1459       temp = (TgF.XYZ()).Multiplied(dis1);
1460       pt1.SetXYZ( (ptgui.XYZ()).Added(temp) );
1461       
1462       Standard_Real dis2, tmpcos, tmpsin;
1463       tmpcos = TgF.Dot(TgL);
1464       tmpsin = sqrt(1. - tmpcos * tmpcos);  
1465       
1466       dis2   = dis1 / (tmpcos + tmpsin / tan(angle)); 
1467       
1468       temp = (TgL.XYZ()).Multiplied(dis2);
1469       pt2.SetXYZ( (ptgui.XYZ()).Added(temp) );
1470       
1471       Standard_Real tol = tolesp*1.e2;
1472 //      Standard_Real u,v;
1473       Extrema_GenLocateExtPS proj1(S1->Surface(), tol, tol);
1474       proj1.Perform(pt1, SolDep(1), SolDep(2));
1475       Extrema_GenLocateExtPS proj2(S2->Surface(), tol, tol);
1476       proj2.Perform(pt2, SolDep(3), SolDep(4));
1477       if( proj1.IsDone() ){
1478         (proj1.Point()).Parameter(SolDep(1),SolDep(2)); 
1479       }
1480       if( proj2.IsDone() ){
1481         (proj2.Point()).Parameter(SolDep(3),SolDep(4)); 
1482       }
1483       
1484       return TheWalk.PerformFirstSection(Func,Par,SolDep,
1485                                          tolesp,TolGuide,Pos1,Pos2);
1486     }
1487     else {
1488       Standard_Real Rtemp;
1489       BRepBlend_ChAsym Func(S2,S1,HGuide);
1490       Func.Set(dis1, angle, Ch);
1491       BRepBlend_Walking TheWalk(S2,S1,I2,I1,HGuide);
1492     
1493     //calculate an approximate starting solution
1494       gp_Vec TgF, TgL, tmp1, tmp2, d1gui;
1495       gp_Pnt pt1, pt2, ptgui;
1496       gp_XYZ temp;
1497       
1498       ( HGuide->Curve() ).D1(Par,ptgui,d1gui);
1499       //  ptgui = (S1->Surface()).Value(SolDep(1),SolDep(2));
1500       Rtemp     = SolDep(1);
1501       SolDep(1) = SolDep(3);
1502       SolDep(3) = Rtemp;
1503       Rtemp     = SolDep(2);
1504       SolDep(2) = SolDep(4);
1505       SolDep(4) = Rtemp;      
1506       Func.Set(Par);
1507
1508       Func.Tangent(SolDep(1),SolDep(2),SolDep(3),SolDep(4),TgF,TgL,tmp1,tmp2);
1509       
1510       Standard_Boolean rev1 = Standard_False;
1511       Standard_Boolean rev2 = Standard_False;
1512       Standard_Real    sign = (TgF.Crossed(d1gui)).Dot(TgL);
1513       
1514       if( Ch%2 == 1 )
1515         rev1 = Standard_True;
1516       else
1517         rev2 = Standard_True;
1518       
1519       if( sign < 0. ){
1520         rev1 = !rev1;
1521         rev2 = !rev2;
1522       }
1523       
1524       if( rev1 )
1525         TgF.Reverse();
1526       if( rev2 )
1527         TgL.Reverse();
1528   
1529       temp = (TgF.XYZ()).Multiplied(dis1);
1530       pt1.SetXYZ( (ptgui.XYZ()).Added(temp) );
1531       
1532       Standard_Real dis2, tmpcos, tmpsin;
1533       tmpcos = TgF.Dot(TgL);
1534       tmpsin = sqrt(1. - tmpcos * tmpcos);  
1535       
1536       dis2   = dis1 / (tmpcos + tmpsin / tan(angle)); 
1537       
1538       temp = (TgL.XYZ()).Multiplied(dis2);
1539       pt2.SetXYZ( (ptgui.XYZ()).Added(temp) );
1540       
1541       Standard_Real tol = tolesp*1.e2;
1542 //      Standard_Real u,v;
1543       Extrema_GenLocateExtPS proj1(S2->Surface(), tol, tol);
1544       proj1.Perform(pt1, SolDep(1), SolDep(2));
1545       Extrema_GenLocateExtPS proj2(S1->Surface(), tol, tol);
1546       proj2.Perform(pt2, SolDep(3), SolDep(4));
1547       if( proj1.IsDone() ) {
1548         (proj1.Point()).Parameter(SolDep(1),SolDep(2)); 
1549       }
1550       if( proj2.IsDone() ){
1551         (proj2.Point()).Parameter(SolDep(3),SolDep(4)); 
1552       }
1553       
1554       Standard_Boolean RetWalk =  TheWalk.PerformFirstSection(Func,Par,SolDep,
1555                                                               tolesp,TolGuide,Pos2,Pos1);
1556       Rtemp     = SolDep(1);
1557       SolDep(1) = SolDep(3);
1558       SolDep(3) = Rtemp;
1559       Rtemp     = SolDep(2);
1560       SolDep(2) = SolDep(4);
1561       SolDep(4) = Rtemp;
1562
1563       return RetWalk;
1564     }
1565   }
1566 }
1567
1568
1569 //=======================================================================
1570 //function : PerformSurf
1571 //purpose  : 
1572 //=======================================================================
1573
1574 Standard_Boolean  
1575 ChFi3d_ChBuilder::PerformSurf(ChFiDS_SequenceOfSurfData&          SeqData,
1576                               const Handle(ChFiDS_HElSpine)&      HGuide,
1577                               const Handle(ChFiDS_Spine)&         Spine,
1578                               const Standard_Integer              Choix,
1579                               const Handle(BRepAdaptor_HSurface)& S1,
1580                               const Handle(Adaptor3d_TopolTool)&    I1,
1581                               const Handle(BRepAdaptor_HSurface)& S2,
1582                               const Handle(Adaptor3d_TopolTool)&    I2,
1583                               const Standard_Real                 MaxStep,
1584                               const Standard_Real                 Fleche,
1585                               const Standard_Real                 TolGuide,
1586                               Standard_Real&                      First,
1587                               Standard_Real&                      Last,
1588                               const Standard_Boolean              Inside,
1589                               const Standard_Boolean              Appro,
1590                               const Standard_Boolean              Forward,
1591                               const Standard_Boolean              RecOnS1,
1592                               const Standard_Boolean              RecOnS2,
1593                               const math_Vector&                  Soldep,
1594                               Standard_Integer&                   intf,
1595                               Standard_Integer&                   intl)
1596      
1597 {
1598   Handle(ChFiDS_SurfData) Data = SeqData(1);
1599   Handle(ChFiDS_ChamfSpine) 
1600     chsp = Handle(ChFiDS_ChamfSpine)::DownCast(Spine);
1601   
1602   if (chsp.IsNull()) 
1603     throw Standard_ConstructionError("PerformSurf : this is not the spine of a chamfer");
1604   
1605   Standard_Boolean gd1,gd2,gf1,gf2;
1606   Handle(BRepBlend_Line) lin;
1607   TopAbs_Orientation Or = S1->ChangeSurface().Face().Orientation();
1608   Standard_Real PFirst = First;
1609   if(intf) First = chsp->FirstParameter(1);
1610   if(intl) Last = chsp->LastParameter(chsp->NbEdges());
1611
1612   if (chsp->IsChamfer() == ChFiDS_Sym) {
1613     BRepBlend_Chamfer  Func(S1,S2,HGuide);
1614     BRepBlend_ChamfInv FInv(S1,S2,HGuide);
1615     Standard_Real dis;
1616     chsp->GetDist(dis);
1617     Func.Set(dis, dis, Choix);
1618     FInv.Set(dis, dis, Choix);
1619       
1620     done = ComputeData(Data,HGuide,Spine,lin,S1,I1,S2,I2,Func,FInv,
1621                        PFirst,MaxStep,Fleche,TolGuide,First,Last,
1622                        Inside,Appro,Forward,Soldep,intf,intl,
1623                        gd1,gd2,gf1,gf2,RecOnS1,RecOnS2);
1624     if(!done) return Standard_False; // ratrappage possible PMN 14/05/1998
1625     done = CompleteData(Data,Func,lin,S1,S2,Or,gd1,gd2,gf1,gf2);
1626     if(!done) throw Standard_Failure("PerformSurf : Fail of approximation!");
1627   }
1628   else if (chsp->IsChamfer() == ChFiDS_TwoDist) {
1629     BRepBlend_Chamfer  Func(S1,S2,HGuide);
1630     BRepBlend_ChamfInv FInv(S1,S2,HGuide);
1631     Standard_Real d1, d2;
1632     chsp->Dists(d1,d2);
1633     Func.Set(d1,d2,Choix);
1634     FInv.Set(d1,d2,Choix);
1635     
1636     done = ComputeData(Data,HGuide,Spine,lin,S1,I1,S2,I2,Func,FInv,
1637                        PFirst,MaxStep,Fleche,TolGuide,First,Last,
1638                        Inside,Appro,Forward,Soldep,intf,intl,
1639                        gd1,gd2,gf1,gf2,RecOnS1,RecOnS2);
1640     if(!done) return Standard_False; // ratrappage possible PMN 14/05/1998
1641     done = CompleteData(Data,Func,lin,S1,S2,Or,gd1,gd2,gf1,gf2);
1642     if(!done) throw Standard_Failure("PerformSurf : Fail of approximation!");
1643   }
1644   else {
1645     Standard_Real d1, angle;
1646     Standard_Boolean disonF1;
1647     chsp->GetDistAngle(d1, angle, disonF1);
1648     
1649     Standard_Integer Ch = FindChoiceDistAngle(Choix, disonF1);
1650
1651     if (disonF1) {
1652       BRepBlend_ChAsym  Func(S1,S2,HGuide);
1653       BRepBlend_ChAsymInv FInv(S1,S2,HGuide);
1654       Func.Set(d1, angle, Ch);
1655       FInv.Set(d1, angle, Ch);
1656     
1657       done = ComputeData(Data,HGuide,Spine,lin,S1,I1,S2,I2,Func,FInv,
1658                          PFirst,MaxStep,Fleche,TolGuide,First,Last,
1659                          Inside,Appro,Forward,Soldep,intf,intl,
1660                          gd1,gd2,gf1,gf2,RecOnS1,RecOnS2);
1661
1662       if(!done) return Standard_False; // ratrappage possible PMN 14/05/1998
1663       done = CompleteData(Data,Func,lin,S1,S2,Or,gd1,gd2,gf1,gf2);
1664       if(!done) throw Standard_Failure("PerformSurf : Fail of approximation!");
1665     }
1666     else {
1667       Standard_Real Rtemp;
1668       BRepBlend_ChAsym  Func(S2, S1, HGuide);
1669       BRepBlend_ChAsymInv FInv(S2, S1,HGuide);
1670       Func.Set(d1, angle, Ch);
1671       FInv.Set(d1, angle, Ch);
1672
1673       Rtemp     = Soldep(1);
1674       Soldep(1) = Soldep(3);
1675       Soldep(3) = Rtemp;
1676       Rtemp     = Soldep(2);
1677       Soldep(2) = Soldep(4);
1678       Soldep(4) = Rtemp;
1679
1680       TopAbs_Orientation Or2 = S2->ChangeSurface().Face().Orientation();
1681
1682       done = ComputeData(Data,HGuide,Spine,lin,S2,I2,S1,I1,Func,FInv,
1683                          PFirst,MaxStep,Fleche,TolGuide,First,Last,
1684                          Inside,Appro,Forward,Soldep,intf,intl,
1685                          gd2,gd1,gf2,gf1,RecOnS2,RecOnS1);
1686
1687       ChFiDS_CommonPoint tmp = Data->VertexFirstOnS1();
1688       Data->ChangeVertexFirstOnS1() = Data->VertexFirstOnS2();
1689       Data->ChangeVertexFirstOnS2() = tmp;
1690       tmp = Data->VertexLastOnS1();
1691       Data->ChangeVertexLastOnS1() = Data->VertexLastOnS2();
1692       Data->ChangeVertexLastOnS2() = tmp;
1693       if(!done) return Standard_False; // ratrappage possible PMN 14/05/1998
1694       done = CompleteData(Data,Func,lin,S1,S2,Or2,gd1,gd2,gf1,gf2, Standard_True);
1695       if(!done) throw Standard_Failure("PerformSurf : Fail of approximation!");
1696     }      
1697
1698   }
1699   return Standard_True;
1700 }
1701 void  ChFi3d_ChBuilder::PerformSurf(ChFiDS_SequenceOfSurfData&          ,
1702                                   const Handle(ChFiDS_HElSpine)&      , 
1703                                   const Handle(ChFiDS_Spine)&         , 
1704                                   const Standard_Integer              ,
1705                                   const Handle(BRepAdaptor_HSurface)& ,
1706                                   const Handle(Adaptor3d_TopolTool)&    ,
1707                                   const Handle(BRepAdaptor_HCurve2d)& ,
1708                                   const Handle(BRepAdaptor_HSurface)& ,
1709                                   const Handle(BRepAdaptor_HCurve2d)& ,
1710                                   Standard_Boolean&                   ,
1711                                   const Handle(BRepAdaptor_HSurface)& ,
1712                                   const Handle(Adaptor3d_TopolTool)&    ,
1713                                   const TopAbs_Orientation            ,
1714                                   const Standard_Real                 ,
1715                                   const Standard_Real                 ,
1716                                   const Standard_Real                 ,
1717                                   Standard_Real&                      ,
1718                                   Standard_Real&                      ,
1719                                   const Standard_Boolean              ,
1720                                   const Standard_Boolean              ,
1721                                   const Standard_Boolean              ,
1722                                   const Standard_Boolean              ,
1723                                   const Standard_Boolean              ,
1724                                   const Standard_Boolean              ,
1725                                   const math_Vector&                  )
1726 {
1727   throw Standard_Failure("PerformSurf Not Implemented");
1728 }
1729 void  ChFi3d_ChBuilder::PerformSurf(ChFiDS_SequenceOfSurfData&          ,
1730                                   const Handle(ChFiDS_HElSpine)&      , 
1731                                   const Handle(ChFiDS_Spine)&         , 
1732                                   const Standard_Integer              ,
1733                                   const Handle(BRepAdaptor_HSurface)& ,
1734                                   const Handle(Adaptor3d_TopolTool)&    ,
1735                                   const TopAbs_Orientation            ,
1736                                   const Handle(BRepAdaptor_HSurface)& ,
1737                                   const Handle(Adaptor3d_TopolTool)&    ,
1738                                   const Handle(BRepAdaptor_HCurve2d)& ,
1739                                   const Handle(BRepAdaptor_HSurface)& ,
1740                                   const Handle(BRepAdaptor_HCurve2d)& ,
1741                                   Standard_Boolean&                   ,
1742                                   const Standard_Real                 ,
1743                                   const Standard_Real                 ,
1744                                   const Standard_Real                 ,
1745                                   Standard_Real&                      ,
1746                                   Standard_Real&                      ,
1747                                   const Standard_Boolean              ,
1748                                   const Standard_Boolean              ,
1749                                   const Standard_Boolean              ,
1750                                   const Standard_Boolean              ,
1751                                   const Standard_Boolean              ,
1752                                   const Standard_Boolean              ,
1753                                   const math_Vector&                  )
1754 {
1755   throw Standard_Failure("PerformSurf Not Implemented");
1756
1757 }
1758 void  ChFi3d_ChBuilder::PerformSurf(ChFiDS_SequenceOfSurfData&          ,
1759                                   const Handle(ChFiDS_HElSpine)&      ,
1760                                   const Handle(ChFiDS_Spine)&         ,
1761                                   const Standard_Integer              ,
1762                                   const Handle(BRepAdaptor_HSurface)& ,
1763                                   const Handle(Adaptor3d_TopolTool)&    ,
1764                                   const Handle(BRepAdaptor_HCurve2d)& ,
1765                                   const Handle(BRepAdaptor_HSurface)& ,
1766                                   const Handle(BRepAdaptor_HCurve2d)& ,
1767                                   Standard_Boolean&                   ,
1768                                   const TopAbs_Orientation            ,
1769                                   const Handle(BRepAdaptor_HSurface)& ,
1770                                   const Handle(Adaptor3d_TopolTool)&    ,
1771                                   const Handle(BRepAdaptor_HCurve2d)& ,
1772                                   const Handle(BRepAdaptor_HSurface)& ,
1773                                   const Handle(BRepAdaptor_HCurve2d)& ,
1774                                   Standard_Boolean&                   ,
1775                                   const TopAbs_Orientation            ,
1776                                   const Standard_Real                 ,
1777                                   const Standard_Real                 ,
1778                                   const Standard_Real                 ,
1779                                   Standard_Real&                      ,
1780                                   Standard_Real&                      ,
1781                                   const Standard_Boolean              ,
1782                                   const Standard_Boolean              ,
1783                                   const Standard_Boolean              ,
1784                                   const Standard_Boolean              ,
1785                                   const Standard_Boolean              ,
1786                                   const Standard_Boolean              ,
1787                                   const Standard_Boolean              ,
1788                                   const math_Vector&                  )
1789 {
1790   throw Standard_Failure("PerformSurf Not Implemented");
1791
1792 }
1793 //=======================================================================
1794 //function : ExtentOneCorner
1795 //purpose  : extends the spine of the stripe S on the side of the vertex V
1796 // PMN : 28/11/97 : Reproduces the code of fillets, and it seems to work better...
1797 //=======================================================================
1798
1799 void ChFi3d_ChBuilder::ExtentOneCorner(const TopoDS_Vertex&          V,
1800                                        const Handle(ChFiDS_Stripe)&  S)
1801 {
1802   Standard_Integer      Sens = 0;
1803   Standard_Real         Coeff = 0.5;
1804   Handle(ChFiDS_Spine)  Spine = S->Spine();
1805   ChFi3d_IndexOfSurfData(V,S,Sens);
1806   if (Spine->IsTangencyExtremity((Sens == 1))) return; //No extension on queue
1807   Standard_Real dU = Spine->LastParameter(Spine->NbEdges());
1808   if (Sens == 1) {
1809     Spine->SetFirstParameter(-dU*Coeff);
1810     Spine->SetFirstTgt(0.);
1811   }
1812   else {
1813     Spine->SetLastParameter(dU*(1.+Coeff));
1814     Spine->SetLastTgt(dU);
1815   }
1816 /*
1817   Standard_Integer Sens;
1818   Standard_Boolean isfirst;
1819   Standard_Integer Iedge = 1;
1820   Standard_Real d1, d2;
1821
1822   Handle(ChFiDS_Spine) Spine = S->Spine();
1823   Handle(ChFiDS_ChamfSpine)
1824       chsp = Handle(ChFiDS_ChamfSpine)::DownCast(Spine);
1825   chsp->Dists(d1,d2); 
1826   Standard_Integer IE = ChFi3d_IndexOfSurfData(V,S,Sens);
1827   isfirst = (Sens == 1);
1828   if (!isfirst)  
1829     Iedge = Spine->NbEdges();
1830  
1831   TopTools_ListIteratorOfListOfShape It, Jt;
1832   TopoDS_Edge E1, E2, Ec;
1833   TopoDS_Face F1, F2, Fc;
1834   TopoDS_Edge EdgeSp = Spine->Edges(Iedge);
1835
1836   ConexFaces(Spine,Iedge,F1,F2);
1837
1838   for (Jt.Initialize(myVEMap(V));Jt.More();Jt.Next()) {
1839     Ec = TopoDS::Edge(Jt.Value());
1840     if (!Ec.IsSame(EdgeSp)){
1841       for (It.Initialize(myEFMap(Ec));It.More();It.Next()) {
1842         Fc = TopoDS::Face(It.Value());
1843         if (Fc.IsSame(F1))
1844           E1 = Ec;
1845         else if (Fc.IsSame(F2))
1846           E2 = Ec;
1847       } 
1848     }
1849   }
1850
1851   gp_Vec tg1, tg2, tgsp;
1852   gp_Pnt tmp, ptgui;
1853   Spine->D1(Spine->Absc(V),ptgui,tgsp);
1854   if (isfirst)
1855     tgsp.Reverse();
1856
1857   // tg1
1858   BRepAdaptor_Curve curv;
1859   curv.Initialize(E1);
1860   curv.D1(curv.FirstParameter(),tmp,tg1); //pour eviter les projections
1861   tg1.Reverse();
1862     // pbm d'erreurs d'approx : baisser la tolerance
1863   if( !tmp.IsEqual(ptgui,tolesp*1.e2) )
1864     curv.D1(curv.LastParameter(),tmp,tg1);
1865
1866   // tg2
1867   curv.Initialize(E2);
1868   curv.D1(curv.FirstParameter(),tmp,tg2);
1869   tg2.Reverse();
1870   if( !tmp.IsEqual(ptgui,tolesp*1.e2) )
1871     curv.D1(curv.LastParameter(),tmp,tg2);
1872
1873   // calcul de dspine
1874   Standard_Real dspine;
1875   Standard_Real d1plus = 0.;
1876   Standard_Real d2plus = 0.;
1877
1878   Standard_Real sinalpha = tg1.Dot(tgsp);
1879   if (sinalpha < 0.){
1880     Standard_Real cosalpha = Sqrt(1 - sinalpha*sinalpha);
1881     d1plus = -d1*sinalpha/cosalpha;
1882   }
1883   sinalpha = tg2.Dot(tgsp);
1884   if (sinalpha < 0.){
1885     Standard_Real cosalpha = Sqrt(1 - sinalpha*sinalpha);
1886     d2plus = -d2*sinalpha/cosalpha;
1887   }
1888   dspine = d1plus;
1889   if (d2plus > d1plus)
1890     dspine = d2plus;
1891
1892   dspine *=1.5;
1893
1894   // ExtentOneCorner
1895   if (isfirst) {
1896     Spine->SetFirstParameter(-dspine);
1897     Spine->SetFirstTgt(0.);
1898   }
1899   else{
1900     Standard_Real param = Spine->LastParameter(Spine->NbEdges());
1901     Spine->SetLastParameter(param+dspine);
1902     Spine->SetLastTgt(param);
1903   } */
1904 }
1905
1906
1907
1908 //=======================================================================
1909 //function : ExtentTwoCorner
1910 //purpose  : extends the spines of the stripes contained in the list LS,
1911 //           on the side of the vertex V
1912 //=======================================================================
1913
1914
1915 void ChFi3d_ChBuilder::ExtentTwoCorner(const TopoDS_Vertex&        V,
1916                                        const ChFiDS_ListOfStripe&  LS)
1917 {
1918   Standard_Integer Sens = 0;
1919   ChFiDS_ListIteratorOfListOfStripe itel(LS);
1920   Standard_Boolean FF = Standard_True;
1921   Standard_Boolean isfirst[2];
1922   Standard_Integer Iedge[2];
1923   Iedge[0] = 1;
1924   Iedge[1] = 1;
1925   Handle(ChFiDS_Stripe) Stripe[2];
1926   Handle(ChFiDS_Spine) Spine[2];
1927
1928   Standard_Integer i = 0;
1929   for (; itel.More(); itel.Next(),i++) {    
1930   ChFi3d_IndexOfSurfData(V,itel.Value(),Sens);
1931     if (!FF)
1932       if ( Stripe[1] == itel.Value())
1933         Sens = -Sens; 
1934     
1935     Stripe[i] = itel.Value();
1936     isfirst[i] = (Sens == 1);
1937     Spine[i] = Stripe[i]->Spine();
1938     if( !isfirst[i] )
1939       Iedge[i] = Spine[i]->NbEdges();
1940     FF = Standard_False;
1941   }
1942
1943
1944   Handle(ChFiDS_ChamfSpine) chsp[2];
1945   Standard_Real d[4], dis[2] = { 0.0, 0.0 };
1946   Standard_Integer j;
1947   TopoDS_Face F[4];
1948   Standard_Real tmpang, tmd;
1949   Standard_Boolean disonF1;
1950
1951
1952   for (i=0, j=0; i<2; i++, j += 2) {
1953     chsp[i] = Handle(ChFiDS_ChamfSpine)::DownCast(Spine[i]);
1954     ConexFaces(Spine[i],Iedge[i],F[j],F[j+1]);
1955
1956     if (chsp[i]->IsChamfer() == ChFiDS_Sym) {
1957       chsp[i]->GetDist(d[j]);
1958       d[j+1] = d[j]; 
1959     }
1960     else if (chsp[i]->IsChamfer() == ChFiDS_TwoDist) {
1961       chsp[i]->Dists(d[j],d[j+1]); 
1962     }
1963     else {
1964       chsp[i]->GetDistAngle(tmd, tmpang, disonF1);
1965       // an approximate calculation of distance 2 is done
1966       if (disonF1) {
1967         d[j]   = tmd;
1968         d[j+1] = tmd * tan(tmpang); 
1969       }
1970       else
1971       {
1972         d[j]   = tmd * tan(tmpang);
1973         d[j+1] = tmd;
1974       }
1975     }
1976
1977   }
1978
1979   Standard_Boolean notfound = Standard_True;
1980   i = 0; 
1981   while (notfound && (i<2)) {
1982     j = 0;
1983     while (notfound && (j<2)) {
1984       if (F[i].IsSame(F[j+2])) {
1985         dis[0] = d[i];
1986 //      dOnArc[0] = d[(i+1)%2];
1987
1988         dis[1] = d[j + 2];
1989 //      dOnArc[1] = d[(j+1)%2 + 2];
1990         notfound = Standard_False;
1991       }
1992       j++;
1993     }
1994     i++;
1995   }
1996   // ExtentTwoCorner
1997
1998   ChFiDS_State State[2];
1999
2000   for (i=0; i<2; i++) {
2001     if (isfirst[i])
2002       State[i] = Spine[i]->FirstStatus();
2003     else
2004       State[i] = Spine[i]->LastStatus();
2005  }
2006   
2007   if (State[0] == ChFiDS_AllSame ){
2008 /*      
2009    // The greatest intersection of the chamfer is found (on the incident edge)
2010     // with the face at end
2011     i = 0;
2012     j = 1;
2013     if(dOnArc[j] > dOnArc[i]) {
2014       Standard_Integer temp = i;
2015       i = j;
2016       j = temp;
2017     }
2018     ExtentOneCorner( V, Stripe[i] ); */
2019
2020     // it is necessary that two chamfers touch the face at end 
2021     for (j=0; j<2; j++)
2022       ExtentOneCorner( V, Stripe[j] ); 
2023   }
2024   else if ((State[0] == ChFiDS_OnSame) && (State[1] == ChFiDS_OnSame)) {
2025
2026     ExtentSpineOnCommonFace(Spine[0],Spine[1],V,dis[0],dis[1],
2027                             isfirst[0],isfirst[1]);
2028   }
2029
2030 }
2031
2032 //=======================================================================
2033 //function : ExtentThreeCorner
2034 //purpose  : 
2035 //=======================================================================
2036
2037 void ChFi3d_ChBuilder::ExtentThreeCorner(const TopoDS_Vertex& V,
2038                                          const ChFiDS_ListOfStripe& LS)
2039 {
2040   Standard_Integer Sens = 0;
2041   ChFiDS_ListOfStripe check;
2042   Standard_Boolean isfirst[3];
2043   Standard_Integer Iedge[3];
2044   Iedge[0] = 1;
2045   Iedge[1] = 1;
2046   Iedge[2] = 1;  
2047   Handle(ChFiDS_Spine) Spine[3];
2048
2049   Standard_Integer i = 0;
2050   for(ChFiDS_ListIteratorOfListOfStripe itel(LS); itel.More(); itel.Next(), i++) {    
2051     Handle(ChFiDS_Stripe) Stripe = itel.Value(); 
2052     ChFi3d_IndexOfSurfData(V,Stripe,Sens);
2053     for(ChFiDS_ListIteratorOfListOfStripe ich(check); ich.More(); ich.Next()){
2054       if(Stripe == ich.Value()){
2055         Sens = -Sens;
2056         break;
2057       }
2058     }
2059
2060     isfirst[i] = (Sens == 1);
2061     Spine[i] = Stripe->Spine();
2062     if( !isfirst[i] )
2063       Iedge[i] = Spine[i]->NbEdges();
2064
2065     check.Append(Stripe);
2066   }
2067   
2068   Standard_Real d[3][2], tmd, tmpangle;
2069   Standard_Boolean disonF1;
2070   Standard_Integer j;
2071   TopoDS_Face F[3][2];
2072
2073   Handle(ChFiDS_ChamfSpine) chsp[3];
2074
2075   for (i=0; i<3; i++) {
2076     chsp[i] = Handle(ChFiDS_ChamfSpine)::DownCast(Spine[i]);
2077     ConexFaces(Spine[i],Iedge[i],F[i][0],F[i][1]);
2078
2079     if (chsp[i]->IsChamfer() == ChFiDS_Sym) {
2080       chsp[i]->GetDist(d[i][0]); 
2081       d[i][1] = d[i][0];
2082     }
2083     else if (chsp[i]->IsChamfer() == ChFiDS_TwoDist) {
2084        chsp[i]->Dists(d[i][0],d[i][1]); 
2085     }
2086     else {
2087       chsp[i]->GetDistAngle(tmd, tmpangle, disonF1);
2088       // an approximate calculation of distance 2 is done
2089
2090       if (disonF1) {
2091         d[i][0] = tmd;
2092         d[i][1] = tmd * tan(tmpangle); 
2093       }
2094       else {
2095         d[i][0] = tmd * tan(tmpangle);
2096         d[i][1] = tmd;
2097       }     
2098     }
2099   }
2100
2101
2102   // dis[i][j] distance from chamfer i on the common face with 
2103   // chamfer j
2104   Standard_Real dis[3][3];
2105
2106   for (i=0; i<3; i++) {
2107 //    for (Standard_Integer ii=0; ii<3; ii++) {
2108 //      j = (i+ii)%3;
2109       j = (i+1)%3;
2110       Standard_Boolean notfound = Standard_True;
2111       Standard_Integer k, l;
2112       k = 0;
2113       while (notfound && (k<2)) {
2114         l = 0;
2115         while (notfound && (l<2)) {
2116           if (F[i][k].IsSame(F[j][l])) {
2117             dis[i][j] = d[i][k];
2118             dis[j][i] = d[j][l];
2119             notfound = Standard_False;
2120           }
2121           l++;
2122         }
2123         k++;
2124       } 
2125 //    }
2126   }
2127    
2128   //ExtentThreeCorner
2129   for (i=0; i<3; i++) {
2130     j = (i+1)%3;
2131     ExtentSpineOnCommonFace(Spine[i],Spine[j],V,dis[i][j],dis[j][i],
2132                             isfirst[i],isfirst[j]);
2133   }
2134
2135 }
2136
2137 //=======================================================================
2138 //function : SetRegul
2139 //purpose  : 
2140 //=======================================================================
2141
2142 void ChFi3d_ChBuilder::SetRegul()
2143
2144 {
2145   ChFiDS_ListIteratorOfRegularities it;
2146   TopTools_ListIteratorOfListOfShape itc;
2147   TopTools_ListIteratorOfListOfShape its1;
2148   TopTools_ListIteratorOfListOfShape its2;
2149   BRepAdaptor_Surface S;
2150   BRepAdaptor_Curve2d PC;
2151   Standard_Real u,v,t;
2152   gp_Pnt p;
2153   gp_Vec n1,n2,du,dv;
2154   BRep_Builder B;
2155   Standard_Real Seuil = M_PI/360.;
2156   Standard_Real Seuil2 = Seuil * Seuil;
2157   for (it.Initialize(myRegul); it.More(); it.Next()){
2158     const ChFiDS_Regul& reg = it.Value();
2159     itc.Initialize(myCoup->NewEdges(reg.Curve()));
2160     if(itc.More()){
2161       TopoDS_Edge E = TopoDS::Edge(itc.Value());
2162       if(reg.IsSurface1() && reg.IsSurface2()){
2163         its1.Initialize(myCoup->NewFaces(reg.S1()));
2164         its2.Initialize(myCoup->NewFaces(reg.S2()));
2165         if(its1.More() && its2.More()){
2166           TopoDS_Face F1 = TopoDS::Face(its1.Value());
2167           TopoDS_Face F2 = TopoDS::Face(its2.Value());
2168           S.Initialize(F1,Standard_False);
2169           PC.Initialize(E,F1);
2170           t = 0.5*(PC.FirstParameter() + PC.LastParameter());
2171           PC.Value(t).Coord(u,v);
2172           S.D1(u,v,p,du,dv);
2173           n1 = du.Crossed(dv);
2174
2175           S.Initialize(F2,Standard_False);
2176           PC.Initialize(E,F2);
2177           PC.Value(t).Coord(u,v);
2178           S.D1(u,v,p,du,dv);
2179           n2 = du.Crossed(dv);
2180           
2181           if(n1.SquareMagnitude() > 1.e-14 && n2.SquareMagnitude() > 1.e-14){
2182             n1.Normalize();
2183             n2.Normalize();
2184             Standard_Real sina2 = n1.Crossed(n2).SquareMagnitude();
2185             if(sina2 < Seuil2) {
2186               GeomAbs_Shape cont = ChFi3d_evalconti(E,F1,F2);
2187               B.Continuity(E,F1,F2,cont);
2188             }
2189           }
2190         }
2191       }
2192     }
2193   }
2194 }
2195
2196 //=======================================================================
2197 //function : ConexFaces
2198 //purpose  : F1, F2 are connected to edge so that F1 corresponds to distance
2199 //=======================================================================
2200
2201 void ChFi3d_ChBuilder::ConexFaces (const Handle(ChFiDS_Spine)&  Spine,
2202                                    const Standard_Integer       IEdge,
2203                                    TopoDS_Face&                 F1,
2204                                    TopoDS_Face&                 F2) const
2205 {
2206   BRepAdaptor_Surface Sb1,Sb2;
2207   TopAbs_Orientation tmp1,tmp2;
2208   Standard_Integer RC,Choix;
2209   TopoDS_Face f1,f2,ff1,ff2;
2210
2211   //calculate the reference orientation
2212   // ChFi3d_Builder::StripeOrientations is private
2213   SearchCommonFaces(myEFMap,Spine->Edges(1),ff1,ff2);
2214   ff1.Orientation(TopAbs_FORWARD);
2215   Sb1.Initialize(ff1);
2216   ff2.Orientation(TopAbs_FORWARD);
2217   Sb2.Initialize(ff2);
2218   RC = ChFi3d::ConcaveSide(Sb1,Sb2,Spine->Edges(1),tmp1,tmp2);
2219                                   
2220   //calculate the connected faces
2221   SearchCommonFaces(myEFMap,Spine->Edges(IEdge),f1,f2);
2222   Sb1.Initialize(f1);
2223   Sb2.Initialize(f2);
2224   Choix = ChFi3d::ConcaveSide(Sb1,Sb2,Spine->Edges(IEdge),tmp1,tmp2);
2225
2226   if (RC%2 != Choix%2) {
2227     F1 = f2;
2228     F2 = f1;
2229   }
2230   else {
2231     F1 = f1;
2232     F2 = f2;
2233   }
2234 }
2235
2236
2237 //=======================================================================
2238 //function : FindChoiceDistAngle
2239 //purpose  : F1, F2 connected to the edge so that F1 corresponds to distance
2240 //=======================================================================
2241
2242 Standard_Integer ChFi3d_ChBuilder::FindChoiceDistAngle(const Standard_Integer Choice,
2243                                                        const Standard_Boolean DisOnF1) const
2244 {
2245   Standard_Integer ch = 0;  
2246   if (!DisOnF1) {
2247
2248     switch (Choice) {
2249       case 1 : ch = 2;
2250                break;
2251       case 2 : ch = 1;
2252                break;
2253       case 3 : ch = 8;
2254                break;
2255       case 4 : ch = 7;
2256                break;
2257       case 5 : ch = 6;
2258                break;
2259       case 6 : ch = 5;
2260                break;
2261       case 7 : ch = 4;
2262                break;
2263       case 8 : ch = 3;
2264                break;
2265     }
2266
2267   }
2268   else
2269     ch = Choice;
2270  
2271   return ch;
2272 }