summaryrefslogtreecommitdiff
path: root/src/ChFi3d/ChFi3d_Builder_C2.cxx
blob: a273f8284a683ad16d8cf33c771ab04fefc82315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
// File:	ChFi3d_Builder_C2.cxx
// Created:	Tue Aug 20 14:14:29 1996
// Author:	Stagiaire Xuan Tang PHAMPHU
//		<xpu@pomalox.paris1.matra-dtv.fr>

#include <ChFi3d_Builder.jxx>
#include <ChFi3d.hxx>
#include <ChFi3d_Builder_0.hxx>

#include <Precision.hxx>

#include <Standard_Failure.hxx>
#include <Standard_NotImplemented.hxx>
#include <StdFail_NotDone.hxx>


#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <gp_Ax3.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Vec2d.hxx>
#include <gp_Dir2d.hxx>
#include <GeomLib.hxx>
#include <Extrema_ExtPC.hxx>
#include <Geom_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom_BoundedCurve.hxx>

#include <Geom2dAdaptor_HCurve.hxx>
#include <GeomAbs_Shape.hxx>
#include <GeomAdaptor_HCurve.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <GeomAdaptor_HSurface.hxx>

#include <Adaptor3d_HCurveOnSurface.hxx>
#include <BRepAdaptor_HSurface.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_Curve2d.hxx>
#include <BRepAdaptor_HCurve.hxx>
#include <BRepAdaptor_Surface.hxx>

#include <BRep_Tool.hxx>

#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>

#include <TopAbs.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopAbs_Orientation.hxx>

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

#include <TopTools_ListIteratorOfListOfShape.hxx>

#include <TopOpeBRepDS_Point.hxx>
#include <TopOpeBRepDS_Curve.hxx>
#include <TopOpeBRepDS_Surface.hxx>
#include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
#include <TopOpeBRepDS_CurvePointInterference.hxx>
#include <TopOpeBRepDS_DataStructure.hxx>
#include <TopOpeBRepDS_ListOfInterference.hxx>

#include <ChFiDS_HData.hxx>
#include <ChFiDS_SurfData.hxx>
#include <ChFiDS_CommonPoint.hxx>
#include <ChFiDS_FaceInterference.hxx>
#include <ChFiDS_SequenceOfSurfData.hxx>
#include <ChFiDS_Stripe.hxx>
#include <ChFiDS_ListIteratorOfListOfStripe.hxx>

#include <TColStd_Array1OfReal.hxx>

static void Reduce(const Standard_Real& p1,
		   const Standard_Real& p2,
		   Handle(GeomAdaptor_HSurface)& hs1,
		   Handle(GeomAdaptor_HSurface)& hs2)
{
  GeomAdaptor_Surface& s1 = hs1->ChangeSurface();
  GeomAdaptor_Surface& s2 = hs2->ChangeSurface();
  const Handle(Geom_Surface&) surf = s1.Surface();
  Standard_Real ud,uf,vd,vf;
  surf->Bounds(ud,uf,vd,vf);
  Standard_Real milmoins = 0.51*vd+0.49*vf, milplus = 0.49*vd+0.51*vf;
  if(p1 < p2) {
    s1.Load(surf,ud,uf,vd,milmoins);
    s2.Load(surf,ud,uf,milplus,vf);
  }
  else{
    s1.Load(surf,ud,uf,milplus,vf);
    s2.Load(surf,ud,uf,vd,milmoins);
  }  
}

static void Reduce(const Standard_Real& p1,
		   const Standard_Real& p2,
		   Handle(GeomAdaptor_HCurve)& hc)
{
  GeomAdaptor_Curve& c = hc->ChangeCurve();
  Standard_Real f = c.FirstParameter();
  Standard_Real l = c.LastParameter();
  Standard_Real milmoins = 0.51*f+0.49*l, milplus = 0.49*f+0.51*l;
  if(p1 < p2) {
    c.Load(c.Curve(),f,milmoins);
  }
  else{
    c.Load(c.Curve(),milplus,l);
  }  
}


//=======================================================================
//function : PerformTwoCornerbyInter
//purpose  : Performs PerformTwoCorner by intersection.
//           In case of Biseau for all cases the 
//           path is used; 3D curve and 2 pcurves are approximated.
//=======================================================================

Standard_Integer ChFi3d_Builder::PerformTwoCornerbyInter(const Standard_Integer Index)

{
  done = 0;
  const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index);
  TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();

  //Information on fillets is extracted 
  //------------------------------------------------------

  //the first
  //----------
  ChFiDS_ListIteratorOfListOfStripe It;
  It.Initialize(myVDataMap(Index));
  Handle(ChFiDS_Stripe)& Corner1 = It.Value(); 
  Standard_Integer Sens1;
  Standard_Integer IFd1 = 
    ChFi3d_IndexOfSurfData(Vtx,Corner1,Sens1);
  ChFiDS_SequenceOfSurfData& SeqFil1 =    
    Corner1->ChangeSetOfSurfData()->ChangeSequence();
  Handle(ChFiDS_SurfData)& Fd1 = SeqFil1.ChangeValue(IFd1);

  //the second
  //----------
  It.Next();
  Handle(ChFiDS_Stripe)& Corner2 = It.Value(); 
  Standard_Integer Sens2;
  Standard_Integer IFd2;
  if(Corner2 == Corner1) {
    Sens2 = -1;
    IFd2 = Corner2->SetOfSurfData()->Length();
  }
  else{ IFd2 = ChFi3d_IndexOfSurfData(Vtx,Corner2,Sens2); }
  ChFiDS_SequenceOfSurfData& SeqFil2 =    
    Corner2->ChangeSetOfSurfData()->ChangeSequence();
  Handle(ChFiDS_SurfData)& Fd2 = SeqFil2.ChangeValue(IFd2);

  // The concavities are analysed in case of differents concavities, 
  // preview an evolutionary connection of type ThreeCorner of R to 0.
  // Otherwise the opposite face  
  // and the eventual intersection of 2 pcurves on this face are found.

  Standard_Boolean isfirst1 = (Sens1 == 1);
  Standard_Boolean isfirst2 = (Sens2 == 1);
/*#ifdef DEB
  Standard_Boolean evolcoin = ((Stat1 == ChFiDS_OnSame && Stat2 == ChFiDS_OnDiff) || 
			       (Stat2 == ChFiDS_OnSame && Stat1 == ChFiDS_OnDiff));
#endif*/
  Standard_Boolean  OkinterCC,Okvisavis,SameSide;
  Standard_Integer IFaCo1,IFaCo2;
  Standard_Real UIntPC1,UIntPC2;
  TopoDS_Face FaCo;
  OkinterCC = ChFi3d_IsInFront(DStr,Corner1,Corner2,IFd1,IFd2,Sens1,Sens2,
			       UIntPC1,UIntPC2,FaCo,SameSide,
			       IFaCo1,IFaCo2,Okvisavis,Vtx,Standard_True);
  if (!Okvisavis) {
#if DEB
    cout<<"TwoCorner : pas de face commune"<<endl;
#endif
    done=Standard_False;
    return done;
  }
  if (!OkinterCC) {
     // The intersection of pcurves is calculated without restricting them by  
    // common points.
    OkinterCC= ChFi3d_IsInFront(DStr,Corner1,Corner2,IFd1,IFd2,Sens1,Sens2,
				 UIntPC1,UIntPC2,FaCo,SameSide,
				 IFaCo1,IFaCo2,Okvisavis,Vtx,Standard_True,1);
  }
  
  if (!Okvisavis) {
#if DEB
    cout<<"TwoCorner : no common face"<<endl;
#endif
    done=Standard_False;
    return done;
  }   
  if (!OkinterCC) {
#if DEB
    cout<<"biseau : failed intersection of tangency lines on common face"<<endl;
#endif
    done=Standard_False;
    return done;
  }
  Standard_Integer IFaArc1 = 3-IFaCo1, IFaArc2 = 3-IFaCo2;
  
  // It is checked if the fillets have a commonpoint on a common arc.
  // This edge is the pivot of the bevel or of the kneecap.
  
  ChFiDS_CommonPoint& CP1 = Fd1->ChangeVertex(isfirst1,IFaArc1);
  ChFiDS_CommonPoint& CP2 = Fd2->ChangeVertex(isfirst2,IFaArc2);

  if (!CP1.IsOnArc() || !CP2.IsOnArc()) {
#if DEB
    cout<<"fail 1 of 2 fillets are not on arc"<<endl;
#endif
    done=Standard_False;
    return done;
  }
  if ( ! CP1.Arc().IsSame( CP2.Arc()) ) {
    // look like OnSame + OnDiff case (eap, Arp 9 2002, occ266)
#if DEB
    cout<<"PerformTwoCornerbyInter(): fillets are not on the same arc"<<endl;
#endif
    done = Standard_True;
    PerformMoreThreeCorner(Index, 2);
    return done;
  }
    
  TopoDS_Edge pivot;
  pivot = CP1.Arc();
  Standard_Real parCP1 = CP1.ParameterOnArc();
  Standard_Real parCP2 = CP2.ParameterOnArc();
  Handle(BRepAdaptor_HCurve) Hpivot = new BRepAdaptor_HCurve(pivot);
  if (!pivot.IsSame(CP2.Arc())){ 
    Handle(Geom_Curve) csau;
    Standard_Real ubid,vbid;
    csau=BRep_Tool::Curve(pivot,ubid,vbid );
    Handle(Geom_BoundedCurve) C1= Handle(Geom_BoundedCurve)::DownCast(csau);
    if (! C1.IsNull()) {
      GeomLib::ExtendCurveToPoint(C1,CP2.Point(),1,Standard_False);
      GeomAdaptor_Curve cad;
      cad.Load(C1);
      Extrema_ExtPC ext(CP2.Point(),cad,1.e-4);   
      parCP2 = ext.Point(1).Parameter();
    }
  }
  gp_Pnt psp1 = Hpivot->Value(parCP1);
  gp_Pnt psp2 = Hpivot->Value(parCP2);
  Standard_Real sameparam = (psp1.Distance(psp2) < 10 * tolesp);
   
  TopoDS_Face FF1 = TopoDS::Face(DStr.Shape(Fd1->Index(IFaArc1)));
  TopoDS_Face FF2 = TopoDS::Face(DStr.Shape(Fd2->Index(IFaArc2)));
  TopTools_ListIteratorOfListOfShape Kt;
  Standard_Boolean ok1 = Standard_False, ok2 = Standard_False;
  for (Kt.Initialize(myEFMap(pivot)); Kt.More(); Kt.Next()){
    TopoDS_Face F = TopoDS::Face(Kt.Value());
    if(!ok1 && FF1.IsSame(F)){
      ok1 = Standard_True;
    }
    if(!ok2 && FF2.IsSame(F)){
      ok2 = Standard_True;
    }
  }
  if(!ok1 || !ok2){
#if DEB
    cout<<"fail one of surfaces has no common base face with the pivot edge"<<endl;
#endif
    done=Standard_False;
    return done;
  }

  Handle(GeomAdaptor_HSurface) HS1, HS2;
  HS1 = ChFi3d_BoundSurf (DStr,Fd1,IFaCo1,IFaArc1);
  HS2 = ChFi3d_BoundSurf (DStr,Fd2,IFaCo2,IFaArc2);
  
  TColStd_Array1OfReal Pardeb(1,4),Parfin(1,4);
  
  Handle(Geom2d_Curve) PGc1,PGc2;
  Handle(Geom_Curve) Gc;
  
  if(sameparam) {
    // Side common face, calculation of Pardeb.
    ChFi3d_ComputesIntPC (Fd1->Interference(IFaCo1),
			  Fd2->Interference(IFaCo2),
			  HS1,HS2,UIntPC1,UIntPC2);
    gp_Pnt2d UV;
    UV = Fd1->Interference(IFaCo1).PCurveOnSurf()->Value(UIntPC1);
    Pardeb(1)= UV.X(); Pardeb(2)=UV.Y();
    UV = Fd2->Interference(IFaCo2).PCurveOnSurf()->Value(UIntPC2);
    Pardeb(3)= UV.X(); Pardeb(4)=UV.Y();
    gp_Pnt PFaCo = HS1->Surface().Value(Pardeb(1),Pardeb(2));
    
    // Side arc, calculation of Parfin.
    Standard_Real UIntArc1 = Fd1->Interference(IFaArc1).Parameter(isfirst1);
    Standard_Real UIntArc2 = Fd2->Interference(IFaArc2).Parameter(isfirst2);
    
    ChFi3d_ComputesIntPC (Fd1->Interference(IFaArc1),Fd2->Interference(IFaArc2),
			  HS1,HS2,UIntArc1,UIntArc2);
    UV = Fd1->Interference(IFaArc1).PCurveOnSurf()->Value(UIntArc1);
    Parfin(1)= UV.X(); Parfin(2)=UV.Y();
    UV = Fd2->Interference(IFaArc2).PCurveOnSurf()->Value(UIntArc2);
    Parfin(3)= UV.X(); Parfin(4)=UV.Y();
    
    if(Fd1->Surf() == Fd2->Surf()){
      Reduce(UIntPC1,UIntPC2,HS1,HS2);
    }
    
    Standard_Real tolreached = 0.0;
    if (IFaCo1 == 1 && 
	!ChFi3d_ComputeCurves(HS1,HS2,Pardeb,Parfin,Gc,
			      PGc1,PGc2,tolesp,tol2d,tolreached)) {
#if DEB
      cout<<"failed to calculate bevel error interSS"<<endl;
#endif
      done=Standard_False;
      return done;
    }
    else if (IFaCo1 == 2 && 
	     !ChFi3d_ComputeCurves(HS1,HS2,Parfin,Pardeb,Gc,
				   PGc1,PGc2,tolesp,tol2d,tolreached)) {
#if DEB
      cout<<"failed to calculate bevel error interSS"<<endl;
#endif
      done=Standard_False;
      return done;	
    }
    // CornerData are updated with results of the intersection. 
    Standard_Real WFirst = Gc->FirstParameter();
    Standard_Real WLast = Gc->LastParameter();
    Standard_Integer Ipoin1;
    Standard_Integer Ipoin2;
    ChFiDS_CommonPoint& cpco1 = Fd1->ChangeVertex(isfirst1,IFaCo1);
    ChFiDS_CommonPoint& cpco2 = Fd2->ChangeVertex(isfirst2,IFaCo2);
    Standard_Real tolpco = Max(cpco1.Tolerance(),cpco2.Tolerance());
    ChFiDS_CommonPoint& cparc1 = Fd1->ChangeVertex(isfirst1,IFaArc1);
    ChFiDS_CommonPoint& cparc2 = Fd2->ChangeVertex(isfirst2,IFaArc2);
    Standard_Real tolparc = Max(cparc1.Tolerance(),cparc2.Tolerance());
    Standard_Integer ICurv = DStr.AddCurve(TopOpeBRepDS_Curve(Gc,tolreached));
    //Corner1
    Corner1->SetParameters(isfirst1,WFirst,WLast);
    Corner1->SetCurve(ICurv,isfirst1);
    Corner1->ChangePCurve(isfirst1) = PGc1;
    cpco1.Reset();
    cpco1.SetPoint(PFaCo);
    cpco1.SetTolerance(Max(tolreached,tolpco));
    Fd1->ChangeInterference(IFaCo1).SetParameter(UIntPC1,isfirst1);
    tolparc = Max(tolparc,tolreached);
    cparc1.SetTolerance(Max(tolparc,tolreached));
    Ipoin1 = ChFi3d_IndexPointInDS(Fd1->Vertex(isfirst1,1),DStr);
    Corner1->SetIndexPoint(Ipoin1,isfirst1,1);
    Ipoin2 = ChFi3d_IndexPointInDS(Fd1->Vertex(isfirst1,2),DStr);
    Corner1->SetIndexPoint(Ipoin2,isfirst1,2);
    //Corner2
    Corner2->SetParameters(isfirst2,WFirst,WLast);
    Corner2->SetCurve(ICurv,isfirst2);
    Corner2->ChangePCurve(isfirst2) = PGc2;
    Fd2->ChangeInterference(IFaCo2).SetParameter(UIntPC2,isfirst2);
    Fd2->ChangeVertex(isfirst2,IFaCo2) = Fd1->Vertex(isfirst1,IFaCo1);
    Fd2->ChangeVertex(isfirst2,IFaArc2) = Fd1->Vertex(isfirst1,IFaArc1);
    if (IFaCo1!=IFaCo2) Corner2->SetOrientation(TopAbs_REVERSED,isfirst2);
    Corner2->SetIndexPoint(Corner1->IndexPoint(isfirst1,IFaCo1),
			   isfirst2,IFaCo2);
    Corner2->SetIndexPoint(Corner1->IndexPoint(isfirst1,IFaArc1),
			   isfirst2,IFaArc2);
    //The tolerances of points are updated.
    Bnd_Box bco,barc;
    if(IFaCo1 == 1) ChFi3d_EnlargeBox(DStr,Corner1,Fd1,bco,barc,isfirst1);
    else ChFi3d_EnlargeBox(DStr,Corner1,Fd1,barc,bco,isfirst1);
    if(IFaCo2 == 1) ChFi3d_EnlargeBox(DStr,Corner2,Fd2,bco,barc,isfirst2);
    else ChFi3d_EnlargeBox(DStr,Corner2,Fd2,barc,bco,isfirst2);
    const ChFiDS_CommonPoint& cparc = Fd1->Vertex(isfirst1,IFaArc1);
    ChFi3d_EnlargeBox(cparc.Arc(),myEFMap(cparc.Arc()),cparc.ParameterOnArc(),barc);
    ChFi3d_SetPointTolerance(DStr,barc,Corner1->IndexPoint(isfirst1,IFaArc1));
    ChFi3d_SetPointTolerance(DStr,bco,Corner1->IndexPoint(isfirst1,IFaCo1));
  }
  else {
    // It is necessary to identify the border surface,
    // find the end point of the intersection Surf/Surf 
    // by the intersection of the tangency line of the small
    // on the opposing face with the surface of the big,
    // and finally intersect the big with the face at end 
    // between this point and the point on arc.
#ifndef DEB
    Standard_Boolean parcrois = Standard_False ;
#else
    Standard_Boolean parcrois;
#endif
    TopExp_Explorer Expl;
    for(Expl.Init(pivot.Oriented(TopAbs_FORWARD),TopAbs_VERTEX); 
	Expl.More(); Expl.Next()){
      if(Expl.Current().IsSame(Vtx)){
	parcrois = (Expl.Current().Orientation() == TopAbs_FORWARD);
	break;
      }
    }
    Handle(ChFiDS_Stripe) BigCD, SmaCD;
    Handle(ChFiDS_SurfData) BigFD, SmaFD;
    Handle(GeomAdaptor_HSurface) BigHS, SmaHS;
    Standard_Integer IFaCoBig, IFaCoSma, IFaArcBig, IFaArcSma;
    Standard_Boolean isfirstBig, isfirstSma;
    Standard_Real UIntPCBig, UIntPCSma;
    
    if((parcrois && parCP2 > parCP1) || (!parcrois && parCP2 < parCP1)){
      UIntPCBig = UIntPC2; UIntPCSma = UIntPC1; 
      BigHS = HS2; SmaHS = HS1;
      BigCD = Corner2; SmaCD = Corner1; 
      BigFD = Fd2; SmaFD = Fd1;
      IFaCoBig = IFaCo2; IFaCoSma = IFaCo1;
      IFaArcBig = IFaArc2; IFaArcSma = IFaArc1;
      isfirstBig = isfirst2; isfirstSma = isfirst1;
    }
    else{
      UIntPCBig = UIntPC1, UIntPCSma = UIntPC2; 
      BigHS = HS1; SmaHS = HS2;
      BigCD = Corner1; SmaCD = Corner2; 
      BigFD = Fd1; SmaFD = Fd2;
      IFaCoBig = IFaCo1; IFaCoSma = IFaCo2;
      IFaArcBig = IFaArc1; IFaArcSma = IFaArc2;
      isfirstBig = isfirst1; isfirstSma = isfirst2;
    }
    
    //Intersection of the big with the small :
    //------------------------------------

    // Pardeb (parameters of point PFaCo)
    // the intersection is checked
    ChFi3d_ComputesIntPC (SmaFD->Interference(IFaCoSma),
			  BigFD->Interference(IFaCoBig),
			  SmaHS,BigHS,UIntPCSma,UIntPCBig);
    gp_Pnt2d UVi;
    UVi = BigFD->Interference(IFaCoBig).PCurveOnSurf()->Value(UIntPCBig);
    Pardeb(3)= UVi.X(); Pardeb(4)=UVi.Y();
    UVi = SmaFD->Interference(IFaCoSma).PCurveOnSurf()->Value(UIntPCSma);
    Pardeb(1)= UVi.X(); Pardeb(2)=UVi.Y();
    gp_Pnt PFaCo = SmaHS->Value(UVi.X(),UVi.Y());

      // Parfin (parameters of point PMil)
    const ChFiDS_FaceInterference& FiArcSma = SmaFD->Interference(IFaArcSma);
    Handle(Geom_Curve) ctg = DStr.Curve(FiArcSma.LineIndex()).Curve();
    Handle(GeomAdaptor_HCurve) Hctg = new GeomAdaptor_HCurve();
    GeomAdaptor_Curve& bid = Hctg->ChangeCurve();
    Standard_Real temp,wi;

    if (isfirstSma) {
      wi = temp =  FiArcSma.FirstParameter();
      if (UIntPCSma < temp)
	temp = UIntPCSma;
      bid.Load(ctg,temp,FiArcSma.LastParameter());
    }
    else {
      wi = temp =  FiArcSma.LastParameter();
      if (UIntPCSma > temp)
	temp = UIntPCSma;
      bid.Load(ctg,FiArcSma.FirstParameter(),temp);
    }
    if(SmaFD->Surf() == BigFD->Surf()){
      Reduce(UIntPCSma,UIntPCBig,SmaHS,BigHS);
      Reduce(UIntPCSma,UIntPCBig,Hctg);
    }
    if(!ChFi3d_IntCS(BigHS,Hctg,UVi,wi)){
#if DEB
      cout<<"bevel : failed inter C S"<<endl;
#endif
      done=Standard_False;
      return done;
    }
    Parfin(3) = UVi.X(); Parfin(4) = UVi.Y();
    UVi = FiArcSma.PCurveOnSurf()->Value(wi);
    Parfin(1) = UVi.X(); Parfin(2) = UVi.Y();
    gp_Pnt PMil = SmaHS->Value(Parfin(1),Parfin(2));
    
    Standard_Real tolreached;
    if (!ChFi3d_ComputeCurves(SmaHS,BigHS,Pardeb,Parfin,Gc,
			      PGc1,PGc2,tolesp,tol2d,tolreached)) {
#if DEB
      cout<<"failed to calculate bevel failed interSS"<<endl;
#endif
      done=Standard_False;
      return done;
    }
      // SmaCD is updated, for it this is all. 
    Standard_Real WFirst = Gc->FirstParameter();
    Standard_Real WLast = Gc->LastParameter();
    Standard_Integer IpointCo, IpointMil, IpointArc;
    ChFiDS_CommonPoint& psmaco = SmaFD->ChangeVertex(isfirstSma,IFaCoSma);
    ChFiDS_CommonPoint& pbigco = BigFD->ChangeVertex(isfirstBig,IFaCoBig);
    Standard_Real tolpco = Max(psmaco.Tolerance(),pbigco.Tolerance());
    ChFiDS_CommonPoint& psmamil = SmaFD->ChangeVertex(isfirstSma,IFaArcSma);
    Standard_Real tolpmil = psmamil.Tolerance();
    Standard_Integer ICurv = DStr.AddCurve(TopOpeBRepDS_Curve(Gc,tolreached));
    
    SmaCD->SetParameters(isfirstSma,WFirst,WLast);
    SmaCD->SetCurve(ICurv,isfirstSma);
    SmaCD->ChangePCurve(isfirstSma) = PGc1;
    psmaco.Reset();
    psmaco.SetPoint(PFaCo);
    psmaco.SetTolerance(Max(tolpco,tolreached));
    SmaFD->ChangeInterference(IFaCoSma).SetParameter(UIntPCSma,isfirstSma);
    psmamil.Reset();
    psmamil.SetPoint(PMil);
    psmamil.SetTolerance(Max(tolpmil,tolreached));
    SmaFD->ChangeInterference(IFaArcSma).SetParameter(wi,isfirstSma);
    IpointCo = ChFi3d_IndexPointInDS(psmaco,DStr);
    SmaCD->SetIndexPoint(IpointCo,isfirstSma,IFaCoSma);
    IpointMil = ChFi3d_IndexPointInDS(psmamil,DStr);
    SmaCD->SetIndexPoint(IpointMil,isfirstSma,IFaArcSma);
    if (IFaCoSma == 2) SmaCD->SetOrientation(TopAbs_REVERSED,isfirstSma);

    // For BigCD the first results are met in the DS.
    BigCD->SetIndexPoint(IpointCo,isfirstBig,IFaCoBig);
    BigFD->ChangeVertex(isfirstBig,IFaCoBig) = psmaco;
    BigFD->ChangeInterference(IFaCoBig).SetParameter(UIntPCBig,isfirstBig);
    
    TopOpeBRepDS_ListOfInterference& Li = DStr.ChangeCurveInterferences(ICurv);
    Handle(TopOpeBRepDS_CurvePointInterference) Interfp;
    Interfp = ChFi3d_FilPointInDS(TopAbs_FORWARD,ICurv,IpointCo,WFirst);
    Li.Append(Interfp);
    Interfp = ChFi3d_FilPointInDS(TopAbs_REVERSED,ICurv,IpointMil,WLast);
    Li.Append(Interfp);
    
    // the transition of curves of intersection on the Big
    TopAbs_Orientation tra = BigFD->InterferenceOnS1().Transition();
    TopAbs_Orientation ofac = DStr.Shape(BigFD->IndexOfS1()).Orientation();
    TopAbs_Orientation ofil = BigFD->Orientation();
    TopAbs_Orientation tracurv = TopAbs::Compose(ofac,ofil);
    tracurv = TopAbs::Compose(tracurv,tra);
    if(!isfirstBig) tracurv = TopAbs::Reverse(tracurv);
    if(IFaCoBig != 1) tracurv = TopAbs::Reverse(tracurv);
    
    Handle(TopOpeBRepDS_SurfaceCurveInterference) Interfc;
    Standard_Integer ISurf = BigFD->Surf();
    Interfc = ChFi3d_FilCurveInDS (ICurv,ISurf,PGc2,tracurv);
    DStr.ChangeSurfaceInterferences(ISurf).Append(Interfc);
    
    //The tolerances of points are updated (beginning).
    Bnd_Box bco,bmil,barc;
    if(IFaCoSma == 1) ChFi3d_EnlargeBox(DStr,SmaCD,SmaFD,bco,bmil,isfirstSma);
    else ChFi3d_EnlargeBox(DStr,SmaCD,SmaFD,bmil,bco,isfirstSma);
    ChFi3d_EnlargeBox(BigHS,PGc2,WFirst,WLast,bco,bmil);
    
    // Intersection of the big with the face at end :
    // -------------------------------------------

    // Pardeb (parameters of PMil)
    // The intersection curve surface is tried again, now with representation
    // pcurve on face of the curve to be sure.
    TopoDS_Face F = TopoDS::Face(DStr.Shape(SmaFD->Index(IFaArcSma)));
    Handle(BRepAdaptor_HSurface) HF = new BRepAdaptor_HSurface(F);
    Standard_Real fsma = FiArcSma.FirstParameter();
    Standard_Real lsma = FiArcSma.LastParameter();
    Standard_Real deltSma = 0.05 * (lsma - fsma);
    Handle(Geom2d_Curve) pcpc = SmaFD->Interference(IFaArcSma).PCurveOnFace();
    fsma = Max(pcpc->FirstParameter(),wi-deltSma);
    lsma = Min(pcpc->LastParameter(),wi+deltSma);
    if ( lsma<fsma ) {
       done=Standard_False;
       return done;
    }
    Handle(Geom2dAdaptor_HCurve) c2df = 
      new Geom2dAdaptor_HCurve(SmaFD->Interference(IFaArcSma).PCurveOnFace(),fsma,lsma);
    Adaptor3d_CurveOnSurface consf(c2df,HF);
    Handle(Adaptor3d_HCurveOnSurface) Hconsf = new Adaptor3d_HCurveOnSurface(consf);
    if(!ChFi3d_IntCS(BigHS,Hconsf,UVi,wi)) {
#if DEB
      cout<<"bevel : failed inter C S"<<endl;
#endif
      done=Standard_False;
      return done;
    }
    Pardeb(3) = UVi.X(); Pardeb(4) = UVi.Y();
    UVi = SmaFD->Interference(IFaArcSma).PCurveOnFace()->Value(wi);
    Pardeb(1) = UVi.X(); Pardeb(2) = UVi.Y(); 
    gp_Pnt2d ppff1 = UVi;

      // Parfin (parameters of the point cpend)
    Standard_Real ptg = BigFD->Interference(IFaArcBig).Parameter(isfirstBig);
    UVi = BigFD->Interference(IFaArcBig).PCurveOnSurf()->Value(ptg);
    Parfin(3) = UVi.X(); Parfin(4) = UVi.Y();
    ChFiDS_CommonPoint& cpend = BigFD->ChangeVertex(isfirstBig,IFaArcBig);
    TopoDS_Edge etest = cpend.Arc();
    if(BRep_Tool::IsClosed(etest,F)) etest.Reverse();
    BRepAdaptor_Curve2d arc(etest,F);
    UVi = arc.Value(cpend.ParameterOnArc());
    Parfin(1) = UVi.X(); Parfin(2) = UVi.Y();
    gp_Pnt2d ppff2 = UVi;
    
      // Intersection. 
    Standard_Real uu1,uu2,vv1,vv2;
    ChFi3d_Boite(ppff1,ppff2,uu1,uu2,vv1,vv2);
    // for the case when two chamfers are on two edges OnSame,
    // it is necessary to extend the surface carrying F, or at least
    // not to limit it.
    ChFi3d_BoundFac(HF->ChangeSurface(),uu1,uu2,vv1,vv2,Standard_True);

    if (!ChFi3d_ComputeCurves(HF,BigHS,Pardeb,Parfin,Gc,
			      PGc1,PGc2,tolesp,tol2d,tolreached)) {
#if DEB
      cout<<"fail calculation bevel fail interSS"<<endl;
#endif
      done=Standard_False;
      return done;
    }
    
      // End of update of the BigCD and the DS.
    WFirst = Gc->FirstParameter();
    WLast = Gc->LastParameter();
    ICurv = DStr.AddCurve(TopOpeBRepDS_Curve(Gc,tolreached));
    cpend.SetTolerance(Max(cpend.Tolerance(),tolreached));
    IpointArc = ChFi3d_IndexPointInDS(cpend,DStr);
    BigCD->SetIndexPoint(IpointArc,isfirstBig,IFaArcBig);
    
    TopOpeBRepDS_ListOfInterference& Li7 = DStr.ChangeCurveInterferences(ICurv);
    Interfp = ChFi3d_FilPointInDS(TopAbs_FORWARD,ICurv,IpointMil,WFirst);
    Li7.Append(Interfp);
    Interfp = ChFi3d_FilPointInDS(TopAbs_REVERSED,ICurv,IpointArc,WLast);
    Li7.Append(Interfp);
    Interfc = ChFi3d_FilCurveInDS (ICurv,ISurf,PGc2,tracurv);
    DStr.ChangeSurfaceInterferences(ISurf).Append(Interfc);
    BigCD->InDS(isfirstBig);
    
    // Finally the information on faces is placed in the DS.
    Standard_Integer IShape = DStr.AddShape(F);
    if(SmaFD->Surf() == BigFD->Surf()){
      tracurv = TopAbs::Compose(etest.Orientation(),
				cpend.TransitionOnArc());
    }
    else {
      TopExp_Explorer Exp;
      for (Exp.Init(F.Oriented(TopAbs_FORWARD),
		    TopAbs_EDGE);Exp.More();Exp.Next()) {
	if (Exp.Current().IsSame(etest)) {
	  tracurv = TopAbs::Compose(Exp.Current().Orientation(),
				    cpend.TransitionOnArc());
	  break;
	}
      }
    }
    Interfc = ChFi3d_FilCurveInDS(ICurv,IShape,PGc1,tracurv);
    DStr.ChangeShapeInterferences(IShape).Append(Interfc);

    //The tolerances of points are updated (end).
    Handle(ChFiDS_Stripe) bidst;
    if(IFaCoBig == 1) ChFi3d_EnlargeBox(DStr,bidst,BigFD,bco,barc,isfirstBig);
    else ChFi3d_EnlargeBox(DStr,bidst,BigFD,barc,bco,isfirstBig);
    ChFi3d_EnlargeBox(BigHS,PGc2,WFirst,WLast,bmil,barc);
    ChFi3d_EnlargeBox(HF,PGc1,WFirst,WLast,bmil,barc);
    ChFi3d_EnlargeBox(Gc,WFirst,WLast,bmil,barc);
    const ChFiDS_CommonPoint& cparc = BigFD->Vertex(isfirstBig,IFaArcBig);
    ChFi3d_EnlargeBox(cparc.Arc(),myEFMap(cparc.Arc()),cparc.ParameterOnArc(),barc);

    ChFi3d_SetPointTolerance(DStr,bco,SmaCD->IndexPoint(isfirstSma,IFaCoSma));
    ChFi3d_SetPointTolerance(DStr,bmil,SmaCD->IndexPoint(isfirstSma,IFaArcSma));
    ChFi3d_SetPointTolerance(DStr,barc,BigCD->IndexPoint(isfirstBig,IFaArcBig));
  }
  done = 1;
  
  return done;
}