0023139: BRepFilletAPI_MakeFillet algorithm builds edges with wrong first and last...
[occt.git] / src / ChFi3d / ChFi3d_Builder_C1.cxx
1 // Created on: 1994-03-09
2 // Created by: Isabelle GRIGNON
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 //  Modified by skv - Mon Jun  7 18:38:57 2004 OCC5898
23 //  Modified by skv - Thu Aug 21 11:55:58 2008 OCC20222
24
25 #include <ChFi3d_Builder.jxx>
26 #include <ChFi3d.hxx>
27 #include <ChFi3d_Builder_0.hxx>
28
29 #include <Precision.hxx>
30
31 #include <Standard_Failure.hxx>
32 #include <Standard_NotImplemented.hxx>
33 #include <StdFail_NotDone.hxx>
34
35
36 #include <gp_Pnt.hxx>
37 #include <gp_Dir.hxx>
38 #include <gp_Vec.hxx>
39 #include <gp_Ax3.hxx>
40 #include <gp_Pnt2d.hxx>
41 #include <gp_Vec2d.hxx>
42 #include <gp_Dir2d.hxx>
43 #include <gp_Elips.hxx>
44 #include <gp_Circ.hxx>
45
46 #include <ElCLib.hxx>
47 #include <ElSLib.hxx>
48
49 #include <Geom_Line.hxx>
50 #include <Geom_Circle.hxx>
51 #include <Geom_Ellipse.hxx>
52 #include <Geom_RectangularTrimmedSurface.hxx>
53 #include <Geom_Curve.hxx>
54 #include <Geom2d_Line.hxx>
55 #include <Geom2d_Curve.hxx>
56 #include <Geom_BSplineCurve.hxx>
57 #include <Geom_BSplineSurface.hxx>
58 #include <Geom_BezierSurface.hxx>
59 #include <Geom2d_BSplineCurve.hxx>
60 #include <Geom2dAdaptor_HCurve.hxx>
61 #include <Geom2d_TrimmedCurve.hxx>
62 #include <Geom2dInt_GInter.hxx>
63 #include <Geom_TrimmedCurve.hxx>
64 #include <GeomAPI_ExtremaCurveCurve.hxx>
65 #include <GeomAbs_Shape.hxx>
66 #include <GeomAdaptor_HCurve.hxx>
67 #include <GeomAdaptor_Surface.hxx>
68 #include <GeomAdaptor_HSurface.hxx>
69 #include <Geom_BoundedCurve.hxx>
70 #include <GeomLib.hxx>
71 #include <GeomInt_IntSS.hxx>
72 #include <GeomProjLib.hxx>
73
74 #include <Adaptor3d_HCurveOnSurface.hxx>
75 #include <Adaptor3d_CurveOnSurface.hxx>
76 #include <BRepAdaptor_HSurface.hxx>
77 #include <BRepAdaptor_Curve.hxx>
78 #include <BRepAdaptor_Curve2d.hxx>
79 #include <BRepAdaptor_HCurve2d.hxx>
80 #include <BRepAdaptor_HCurve.hxx>
81 #include <BRepAdaptor_Surface.hxx>
82 #include <BRepLib_MakeEdge.hxx>
83 #include <BRepAlgo_NormalProjection.hxx>
84 #include <BRepExtrema_ExtCC.hxx>
85 #include <BRep_Tool.hxx>
86 #include <BRepTools.hxx>
87 #include <BRep_Builder.hxx>
88 #include <IntCurveSurface_HInter.hxx>
89 #include <IntCurveSurface_IntersectionPoint.hxx>
90 #include <IntRes2d_IntersectionPoint.hxx>
91 #include <IntRes2d_Transition.hxx>
92 #include <Extrema_LocateExtCC.hxx>
93 #include <Extrema_POnCurv.hxx>
94 #include <Extrema_ExtPC2d.hxx>
95 #include <Extrema_ExtPC.hxx>
96 #include <Extrema_ExtPS.hxx>
97 #include <Extrema_ExtCC.hxx>
98
99 #include <TopoDS.hxx>
100 #include <TopoDS_Shape.hxx>
101 #include <TopoDS_Face.hxx>
102 #include <TopoDS_Edge.hxx>
103 #include <TopoDS_Vertex.hxx>
104
105 #include <TopAbs.hxx>
106 #include <TopAbs_ShapeEnum.hxx>
107 #include <TopAbs_Orientation.hxx>
108 #include <TopExp.hxx>
109 #include <TopExp_Explorer.hxx>
110 #include <TopLoc_Location.hxx>
111 #include <TopTools_ListIteratorOfListOfShape.hxx>
112
113 #include <TopOpeBRepDS_Point.hxx>
114 #include <TopOpeBRepDS_Curve.hxx>
115 #include <TopOpeBRepDS_Surface.hxx>
116 #include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
117 #include <TopOpeBRepDS_CurvePointInterference.hxx>
118 #include <TopOpeBRepDS_DataStructure.hxx>
119 #include <TopOpeBRepDS_ListOfInterference.hxx>
120 #include <TopOpeBRepDS_ListIteratorOfListOfInterference.hxx>
121 #include <TopOpeBRepDS_SolidSurfaceInterference.hxx>
122 #include <TopOpeBRepDS_Kind.hxx>
123 #include <TopOpeBRepDS_Transition.hxx>
124 #include <TopTools_Array1OfShape.hxx>
125 #include <ChFiDS_HData.hxx>
126 #include <ChFiDS_SurfData.hxx>
127 #include <ChFiDS_CommonPoint.hxx>
128 #include <ChFiDS_FaceInterference.hxx>
129 #include <ChFiDS_SequenceOfSurfData.hxx>
130 #include <ChFiDS_Stripe.hxx>
131 #include <ChFiDS_ListIteratorOfListOfStripe.hxx>
132 #include <ChFiDS_Map.hxx>
133 #include <TColgp_Array1OfPnt.hxx>
134 #include <TColgp_Array1OfPnt2d.hxx>
135 #include <TColStd_Array1OfReal.hxx>
136 #include <TColStd_Array1OfInteger.hxx>
137
138 #ifdef DEB
139 # ifdef DRAW
140 #include <OSD_Chronometer.hxx>
141 #include <DrawTrSurf.hxx>
142 # endif //DRAW
143 //  Modified by Sergey KHROMOV - Thu Apr 11 12:23:40 2002 Begin
144 // The method
145 // ChFi3d_Builder::PerformMoreSurfdata(const Standard_Integer Index)
146 // is totally rewroted.
147 //  Modified by Sergey KHROMOV - Thu Apr 11 12:23:40 2002 End
148
149 extern Standard_Real  t_same,t_inter,t_sameinter;
150 extern void ChFi3d_InitChron(OSD_Chronometer& ch);
151 extern void ChFi3d_ResultChron(OSD_Chronometer & ch,Standard_Real& time);
152 #endif
153 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
154 #include <math_FunctionSample.hxx>
155 #include <Geom2dAdaptor_Curve.hxx>
156 #include <IntRes2d_IntersectionSegment.hxx>
157 //  Modified by Sergey KHROMOV - Fri Dec 21 17:08:19 2001 Begin
158 Standard_Boolean isTangentFaces(const TopoDS_Edge &theEdge,
159                                 const TopoDS_Face &theFace1,
160                                 const TopoDS_Face &theFace2);
161 //  Modified by Sergey KHROMOV - Fri Dec 21 17:08:19 2001 End
162
163 static Standard_Real recadre(const Standard_Real p,
164                              const Standard_Real ref,
165                              const Standard_Boolean isfirst,
166                              const Standard_Real first,
167                              const Standard_Real last)
168 {
169   Standard_Real pp = p;
170   if (isfirst) pp -= (last - first);
171   else pp += (last - first);
172   if (Abs(pp - ref) < Abs(p - ref)) return pp;
173   return p;
174 }
175
176 //=======================================================================
177 //function : Update
178 //purpose  : Calculate the intersection of the face at the end of 
179 //           the tangency line to update CommonPoint and its 
180 //           parameter in FaceInterference.
181 //=======================================================================
182
183 static Standard_Boolean Update(Handle(Adaptor3d_HSurface)& fb,
184                                Handle(Adaptor2d_HCurve2d)& pcfb,
185                                Handle(Adaptor3d_HSurface)& surf,
186                                ChFiDS_FaceInterference&  fi,
187                                ChFiDS_CommonPoint&       cp,
188                                gp_Pnt2d&                 p2dbout,
189                                const Standard_Boolean    isfirst,
190                                Standard_Real&            pared,
191                                Standard_Real&            wop,
192                                const Standard_Real       tol)
193 {
194   Adaptor3d_CurveOnSurface c1(pcfb,fb);
195   Handle(Geom2d_Curve) pc = fi.PCurveOnSurf();
196   Handle(Geom2dAdaptor_HCurve) hpc = new Geom2dAdaptor_HCurve(pc);
197   Adaptor3d_CurveOnSurface c2(hpc,surf);
198   Extrema_LocateExtCC ext(c1,c2,pared,wop);
199   if (ext.IsDone()) {
200     Standard_Real dist2 = ext.SquareDistance();
201     if (dist2 < tol * tol) {
202       Extrema_POnCurv ponc1,ponc2;
203       ext.Point(ponc1,ponc2);
204       Standard_Real parfb = ponc1.Parameter();
205       p2dbout = pcfb->Value(parfb);
206       pared = ponc1.Parameter();
207       wop = ponc2.Parameter();
208       fi.SetParameter(wop,isfirst);
209       cp.Reset();
210       cp.SetPoint(ponc1.Value());
211       return Standard_True;
212     }
213   }
214   return Standard_False;
215 }
216
217 //=======================================================================
218 //function : Update
219 //purpose  : Intersect surface <fb> and 3d curve <ct>
220 //           Update <isfirst> parameter of FaceInterference <fi> and point of
221 //           CommonPoint <cp>. Return new intersection parameters in <wop>
222 //           and <p2dbout>
223 //=======================================================================
224
225 static Standard_Boolean Update(Handle(Adaptor3d_HSurface)& fb,
226                                Handle(Adaptor3d_HCurve)&   ct,
227                                ChFiDS_FaceInterference&  fi,
228                                ChFiDS_CommonPoint&       cp,
229                                gp_Pnt2d&                 p2dbout,
230                                const Standard_Boolean    isfirst,
231                                Standard_Real&            wop)
232 {
233   IntCurveSurface_HInter Intersection;
234   //check if in KPart the limits of the tangency line 
235   //are already in place at this stage.
236   //Modif lvt : the periodic cases are reframed, espercially if nothing was found.
237   Standard_Real w,uf = ct->FirstParameter(),ul = ct->LastParameter();
238 #ifndef DEB
239   Standard_Real  wbis = 0.;
240 #else
241   Standard_Real  wbis;
242 #endif
243   Standard_Boolean isperiodic = ct->IsPeriodic(),recadrebis = Standard_False;
244   Intersection.Perform(ct,fb);
245   if (Intersection.IsDone()) {
246     Standard_Integer nbp = Intersection.NbPoints(),i,isol = 0,isolbis = 0;
247     Standard_Real dist = Precision::Infinite();
248     Standard_Real distbis = Precision::Infinite();
249     for (i = 1; i <= nbp; i++) {
250       w = Intersection.Point(i).W();
251       if (isperiodic) w = recadre(w,wop,isfirst,uf,ul);
252       if (uf <= w && ul >= w && Abs(w-wop) < dist) {
253         isol = i;
254         dist = Abs(w-wop);
255       }
256     }
257     if (isperiodic) {
258       for (i = 1; i <= nbp; i++) {
259         w = Intersection.Point(i).W();
260         if (uf <= w && ul >= w && Abs(w-wop) < distbis && (Abs(w-ul)<=0.01 || Abs(w-uf)<=0.01)) {
261           isolbis = i;
262           wbis = recadre(w,wop,isfirst,uf,ul);
263           distbis = Abs(wbis-wop);
264           recadrebis = Standard_True;
265         }
266       }
267     }
268     if (isol == 0 && isolbis == 0) {
269       return Standard_False;
270     }
271     if (!recadrebis) {
272       IntCurveSurface_IntersectionPoint pint = Intersection.Point(isol);
273       p2dbout.SetCoord(pint.U(),pint.V());
274       w = pint.W();
275       if (isperiodic) w = ElCLib::InPeriod(w,uf,ul);
276     }
277     else {
278       if (dist>distbis) {
279         IntCurveSurface_IntersectionPoint pint = Intersection.Point(isolbis);
280         p2dbout.SetCoord(pint.U(),pint.V());
281         w = wbis;
282       }
283       else {
284         IntCurveSurface_IntersectionPoint pint = Intersection.Point(isol);
285         p2dbout.SetCoord(pint.U(),pint.V());
286         w = pint.W();
287         w = ElCLib::InPeriod(w,uf,ul);
288       }
289     }
290     fi.SetParameter(w,isfirst);
291     cp.Reset();
292     cp.SetPoint(ct->Value(w));
293     wop = w;
294     return Standard_True;
295   }
296   return Standard_False;
297 }
298
299 //=======================================================================
300 //function : IntersUpdateOnSame
301 //purpose  : Intersect  curve <c3dFI> of ChFi-<Fop> interference with extended
302 //           surface <HBs> of <Fprol> . Return intersection parameters in
303 //           <FprolUV>, <c3dU> and updating <FIop> and <CPop>
304 //           <HGs> is a surface of ChFi
305 //           <Fop> is a face having 2 edges at corner with OnSame state
306 //           <Fprol> is a face non-adjacent to spine edge
307 //           <Vtx> is a corner vertex
308 //=======================================================================
309
310 static Standard_Boolean IntersUpdateOnSame(Handle(GeomAdaptor_HSurface)& HGs,
311                                            Handle(BRepAdaptor_HSurface)& HBs,
312                                            const Handle(Geom_Curve)&     c3dFI,
313                                            const TopoDS_Face&            Fop,
314                                            const TopoDS_Face&            Fprol,
315                                            const TopoDS_Edge&            Eprol,
316                                            const TopoDS_Vertex&          Vtx,
317                                            const Standard_Boolean        isFirst,
318                                            const Standard_Real           Tol,
319                                            ChFiDS_FaceInterference&      FIop,
320                                            ChFiDS_CommonPoint&           CPop,
321                                            gp_Pnt2d&                     FprolUV,
322                                            Standard_Real&                c3dU)
323 {
324   // add more or less restrictive criterions to
325   // decide if the intersection is done with the face at 
326   // extended end or if the end is sharp.
327   Standard_Real uf = FIop.FirstParameter();
328   Standard_Real ul = FIop.LastParameter();
329   Handle(GeomAdaptor_HCurve) Hc3df;
330   if (c3dFI->IsPeriodic()) Hc3df = new GeomAdaptor_HCurve(c3dFI);
331   else                     Hc3df = new GeomAdaptor_HCurve(c3dFI,uf,ul);
332
333   if ( Update(HBs,Hc3df,FIop,CPop,FprolUV,isFirst,c3dU) )
334     return Standard_True;
335
336   if (!isTangentFaces(Eprol,Fprol,Fop))
337     return Standard_False;
338
339   Handle(Geom2d_Curve) gpcprol = BRep_Tool::CurveOnSurface(Eprol,Fprol,uf,ul);
340   Handle(Geom2dAdaptor_HCurve) pcprol = new Geom2dAdaptor_HCurve(gpcprol);
341   Standard_Real partemp = BRep_Tool::Parameter(Vtx,Eprol);
342
343   return
344     Update(HBs,pcprol,HGs,FIop,CPop,FprolUV,isFirst,partemp,c3dU,Tol);
345 }
346
347 //=======================================================================
348 //function : Update
349 //purpose  : Calculate the extrema curveonsurf/curveonsurf to prefer 
350 //           the values concerning the trace on surf and the pcurve on the
351 //           face at end.
352 //=======================================================================
353
354 static Standard_Boolean Update(Handle(Adaptor3d_HSurface)& face,
355                                Handle(Adaptor2d_HCurve2d)& edonface,
356                                Handle(Adaptor3d_HSurface)& surf,
357                                ChFiDS_FaceInterference&  fi,
358                                ChFiDS_CommonPoint&       cp,
359                                const Standard_Boolean    isfirst)
360 {
361   if (!cp.IsOnArc()) return 0;
362   Adaptor3d_CurveOnSurface c1(edonface,face);
363   Standard_Real pared = cp.ParameterOnArc();
364   Standard_Real parltg = fi.Parameter(isfirst);
365   Handle(Geom2d_Curve) pc = fi.PCurveOnSurf();
366   Standard_Real f = fi.FirstParameter();
367   Standard_Real l = fi.LastParameter();
368   Standard_Real delta = 0.1 * ( l - f );
369   f = Max(f-delta,pc->FirstParameter());
370   l = Min(l+delta,pc->LastParameter());
371   Handle(Geom2dAdaptor_HCurve) hpc = new Geom2dAdaptor_HCurve(pc,f,l);
372   Adaptor3d_CurveOnSurface c2(hpc,surf);
373
374   Extrema_LocateExtCC ext(c1,c2,pared,parltg);
375   if (ext.IsDone()) {
376     Extrema_POnCurv ponc1,ponc2;
377     ext.Point(ponc1,ponc2);
378     pared = ponc1.Parameter();
379     parltg = ponc2.Parameter();
380     if ((parltg > f) && (parltg < l)) {
381 #ifdef OCC23139
382       ////modified by jgv, 10.05.2012 for the bug 23139////
383       Handle(Geom2d_Curve) PConF = fi.PCurveOnFace();
384       if (!PConF.IsNull())
385       {
386         Handle(Geom2d_TrimmedCurve) aTrCurve = Handle(Geom2d_TrimmedCurve)::DownCast(PConF);
387         if (!aTrCurve.IsNull())
388           PConF = aTrCurve->BasisCurve();
389         if (isfirst)
390         {
391           Standard_Real fpar = PConF->FirstParameter();
392           if (parltg < fpar)
393             parltg = fpar;
394         }
395         else
396         {
397           Standard_Real lpar = PConF->LastParameter();
398           if (parltg > lpar)
399             parltg = lpar;
400         }
401       }
402       /////////////////////////////////////////////////////
403 #endif
404       fi.SetParameter(parltg,isfirst);
405       cp.SetArc(cp.Tolerance(),cp.Arc(),pared,cp.TransitionOnArc());
406       return Standard_True;
407     }
408   }
409   return Standard_False;
410 }
411
412 //=======================================================================
413 //function : ChFi3d_ExtendSurface
414 //purpose  :
415 //=======================================================================
416
417 static void ChFi3d_ExtendSurface (Handle(Geom_Surface) & S ,
418                                   Standard_Integer & prol )
419 {
420   if (prol) return;
421   Handle(Geom_BSplineSurface) S1;
422   Handle(Geom_BezierSurface) S2;
423   Standard_Real length,umin,umax,vmin,vmax;
424   gp_Pnt P1,P2;
425   S->Bounds(umin,umax,vmin,vmax);
426   S->D0(umin,vmin,P1);
427   S->D0(umax,vmax,P2);
428   length=P1.Distance(P2);
429   prol=0;
430   S1=Handle(Geom_BSplineSurface)::DownCast(S);
431   S2=Handle(Geom_BezierSurface)::DownCast(S);
432   if (!S1.IsNull()) {
433                   GeomLib::ExtendSurfByLength(S1,length,1,Standard_False,
434                   Standard_True);
435                   GeomLib::ExtendSurfByLength(S1,length,1,Standard_True,
436                   Standard_True);
437                   GeomLib::ExtendSurfByLength(S1,length,1,Standard_False,
438                   Standard_False);
439                   GeomLib::ExtendSurfByLength(S1,length,1,Standard_True,
440                   Standard_False);
441                   S=S1;
442                   prol=1;
443    }
444    if (!S2.IsNull()) {
445                  GeomLib::ExtendSurfByLength(S2,length,1,Standard_False,
446                  Standard_True);
447                  GeomLib::ExtendSurfByLength(S2,length,1,Standard_True,
448                  Standard_True);
449                  GeomLib::ExtendSurfByLength(S2,length,1,Standard_False,
450                  Standard_False);
451                  GeomLib::ExtendSurfByLength(S2,length,1,Standard_True,
452                  Standard_False);
453                  S=S2;
454                  prol=2;
455
456   }
457 }
458
459 //=======================================================================
460 //function : ComputeCurve2d
461 //purpose  : calculate the 2d of the curve Ct on face Face
462 //=======================================================================
463
464 static void  ComputeCurve2d (Handle(Geom_Curve )& Ct,
465                        TopoDS_Face & Face,
466                        Handle(Geom2d_Curve) & C2d)
467 {
468   TopoDS_Edge E1;
469   TopTools_IndexedMapOfShape MapE1;
470   BRepLib_MakeEdge Bedge (Ct);
471   TopoDS_Edge edg =Bedge. Edge();
472   BRepAlgo_NormalProjection OrtProj;
473   OrtProj.Init(Face);
474   OrtProj.Add(edg);
475   OrtProj.SetParams(1.e-6, 1.e-6, GeomAbs_C1, 14, 16);
476   OrtProj.SetLimit(Standard_False);
477   OrtProj.Compute3d(Standard_False);
478   OrtProj.Build();
479   Standard_Real up1,up2;
480   if ( OrtProj.IsDone()) {
481     TopExp::MapShapes(OrtProj.Projection() ,TopAbs_EDGE, MapE1);
482     if (MapE1.Extent()!=0) {
483       TopoDS_Shape aLocalShape = TopoDS_Shape (MapE1(1));
484       E1=TopoDS::Edge(aLocalShape );
485 //      E1=TopoDS::Edge( TopoDS_Shape (MapE1(1)));
486       C2d=BRep_Tool::CurveOnSurface(E1,Face,up1,up2);
487     }
488   }
489 }
490
491 //=======================================================================
492 //function : ChFi3d_Recale
493 //purpose  :
494 //=======================================================================
495
496 static void ChFi3d_Recale(BRepAdaptor_Surface&   Bs,
497                           gp_Pnt2d&              p1,
498                           gp_Pnt2d&              p2,
499                           const Standard_Boolean refon1)
500 {
501   Handle(Geom_Surface) surf = Bs.ChangeSurface().Surface();
502   Handle(Geom_RectangularTrimmedSurface)
503     ts = Handle(Geom_RectangularTrimmedSurface)::DownCast(surf);
504   if (!ts.IsNull()) surf = ts->BasisSurface();
505   if (surf->IsUPeriodic()) {
506     Standard_Real u1 = p1.X(), u2 = p2.X();
507     Standard_Real uper = surf->UPeriod();
508     if (fabs(u2-u1) > 0.5*uper) {
509       if (u2<u1 && refon1) u2 += uper;
510       else if (u2<u1 && !refon1) u1 -= uper;
511       else if (u1<u2 && refon1) u2 -= uper;
512       else if (u1<u2 && !refon1) u1 += uper;
513     }
514     p1.SetX(u1); p2.SetX(u2);
515   }
516   if (surf->IsVPeriodic()) {
517     Standard_Real v1 = p1.Y(), v2 = p2.Y();
518     Standard_Real vper = surf->VPeriod();
519     if (fabs(v2-v1) > 0.5*vper) {
520       if (v2<v1 && refon1) v2 += vper;
521       else if (v2<v1 && !refon1) v1 -= vper;
522       else if (v1<v2 && refon1) v2 -= vper;
523       else if (v1<v2 && !refon1) v1 += vper;
524     }
525     p1.SetY(v1); p2.SetY(v2);
526   }
527 }
528
529 //=======================================================================
530 //function : ChFi3d_SelectStripe
531 //purpose  : find stripe with ChFiDS_OnSame state if <thePrepareOnSame> is True
532 //=======================================================================
533
534 Standard_Boolean ChFi3d_SelectStripe(ChFiDS_ListIteratorOfListOfStripe & It,
535                                      const TopoDS_Vertex& Vtx,
536                                      const Standard_Boolean thePrepareOnSame)
537 {
538   if (!thePrepareOnSame) return Standard_True;
539
540   for (; It.More(); It.Next()) {
541     Standard_Integer sens = 0;
542     Handle(ChFiDS_Stripe) stripe = It.Value();
543     ChFi3d_IndexOfSurfData(Vtx, stripe, sens);
544     ChFiDS_State stat;
545     if ( sens == 1 )
546       stat = stripe->Spine()->FirstStatus();
547     else
548       stat = stripe->Spine()->LastStatus();
549     if ( stat == ChFiDS_OnSame ) return Standard_True;
550   }
551
552   return Standard_False;
553 }
554 //=======================================================================
555 //function : PerformOneCorner
556 //purpose  : Calculate a corner with three edges and a fillet.
557 //           3 separate case: (22/07/94 only 1st is implemented)
558 //
559 //           - same concavity on three edges, intersection with the
560 //             face at end,
561 //           - concavity of 2 outgoing edges is opposite to the one of the fillet,
562 //             if the face at end is ready for that, the same in  case 1 on extended face,
563 //             otherwise a small cap is done with GeomFill,
564 //           - only one outgoing edge has concavity opposed to the edge of the
565 //             fillet and the third edge, the top of the corner is reread
566 //             in the empty of the fillet and closed, either by extending the face 
567 //             at end if it is plane and orthogonal to the
568 //             guiding edge, or by a cap of type GeomFill.
569 //
570 //           <thePrepareOnSame> means that only needed thing is redefinition
571 //           of intersection pameter of OnSame-Stripe with <Arcprol>
572 //           (eap, Arp 9 2002, occ266)
573 //=======================================================================
574
575 void ChFi3d_Builder::PerformOneCorner(const Standard_Integer Index,
576                                       const Standard_Boolean thePrepareOnSame)
577 {
578   TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
579
580 #ifdef DEB
581   OSD_Chronometer ch;// init perf for PerformSetOfKPart
582 #endif
583   // the top,
584   const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index);
585   // The fillet is returned,
586   ChFiDS_ListIteratorOfListOfStripe StrIt;
587   StrIt.Initialize(myVDataMap(Index));
588   if ( ! ChFi3d_SelectStripe (StrIt, Vtx, thePrepareOnSame)) return;
589   Handle(ChFiDS_Stripe) stripe = StrIt.Value();
590   const Handle(ChFiDS_Spine) spine = stripe->Spine();
591   ChFiDS_SequenceOfSurfData& SeqFil =
592     stripe->ChangeSetOfSurfData()->ChangeSequence();
593   // SurfData and its CommonPoints,
594   Standard_Integer sens = 0;
595
596   // Choose proper SurfData
597   Standard_Integer num = ChFi3d_IndexOfSurfData(Vtx,stripe,sens);
598   Standard_Boolean isfirst = (sens == 1);
599   if (isfirst) {
600     for (; num<SeqFil.Length() && (
601          (SeqFil.Value(num)->IndexOfS1()==0) ||
602          (SeqFil.Value(num)->IndexOfS2()==0) ); ) {
603       SeqFil.Remove(num); // The surplus is removed
604     }
605   }
606   else {
607    for (; num>1 && (
608          (SeqFil.Value(num)->IndexOfS1()==0) ||
609          (SeqFil.Value(num)->IndexOfS2()==0) ); ) {
610      SeqFil.Remove(num);// The surplus is removed
611      num--;
612     }
613   }
614
615   Handle(ChFiDS_SurfData)& Fd = SeqFil.ChangeValue(num);
616   ChFiDS_CommonPoint& CV1 = Fd->ChangeVertex(isfirst,1);
617   ChFiDS_CommonPoint& CV2 = Fd->ChangeVertex(isfirst,2);
618   //To evaluate the new points.
619   Bnd_Box box1,box2;
620
621   // The cases of cap and intersection are processed separately.
622   // ----------------------------------------------------------
623   ChFiDS_State stat;
624   if (isfirst) stat = spine->FirstStatus();
625   else         stat = spine->LastStatus();
626   Standard_Boolean onsame = (stat == ChFiDS_OnSame);
627   TopoDS_Face Fv,Fad,Fop;
628   TopoDS_Edge Arcpiv,Arcprol,Arcspine;
629   if (isfirst) Arcspine = spine->Edges(1);
630   else         Arcspine = spine->Edges(spine->NbEdges());
631 #ifndef DEB
632   TopAbs_Orientation OArcprolv = TopAbs_FORWARD, OArcprolop = TopAbs_FORWARD;
633 #else
634   TopAbs_Orientation OArcprolv,OArcprolop;
635 #endif
636   Standard_Integer ICurve;
637   Handle(BRepAdaptor_HSurface) HBs  = new BRepAdaptor_HSurface();
638   Handle(BRepAdaptor_HSurface) HBad = new BRepAdaptor_HSurface();
639   Handle(BRepAdaptor_HSurface) HBop = new BRepAdaptor_HSurface();
640   BRepAdaptor_Surface& Bs  = HBs->ChangeSurface();
641   BRepAdaptor_Surface& Bad = HBad->ChangeSurface();
642   BRepAdaptor_Surface& Bop = HBop->ChangeSurface();
643   Handle(Geom_Curve) Cc;
644   Handle(Geom2d_Curve) Pc,Ps;
645   Standard_Real Ubid,Vbid;//,mu,Mu,mv,Mv;
646 #ifndef DEB
647   Standard_Real Udeb = 0.,Ufin = 0.;
648 #else
649   Standard_Real Udeb,Ufin;
650 #endif
651 //  gp_Pnt2d UVf1,UVl1,UVf2,UVl2;
652 //  Standard_Real Du,Dv,Step;
653   Standard_Boolean inters = Standard_True;
654   Standard_Integer IFadArc = 1, IFopArc = 2;
655   Fop = TopoDS::Face(DStr.Shape(Fd->Index(IFopArc)));
656   TopExp_Explorer ex;
657
658 #ifdef DEB
659   ChFi3d_InitChron(ch); // init perf condition  if (onsame)
660 #endif
661
662   if (onsame) {
663     if (!CV1.IsOnArc() && !CV2.IsOnArc())
664       Standard_Failure::Raise("Corner OnSame : no point on arc");
665     else if (CV1.IsOnArc() && CV2.IsOnArc()) {
666        Standard_Boolean sur1 = 0, sur2 = 0;
667       for(ex.Init(CV1.Arc(),TopAbs_VERTEX); ex.More(); ex.Next()) {
668         if (Vtx.IsSame(ex.Current())) {
669           sur1 = 1;
670           break;
671         }
672       }
673       for(ex.Init(CV2.Arc(),TopAbs_VERTEX); ex.More(); ex.Next()) {
674         if (Vtx.IsSame(ex.Current())) {
675           sur2 = 1;
676           break;
677         }
678       }
679       if (sur1 && sur2) {
680         TopoDS_Edge E[3];
681         E[0] = CV1.Arc(); E[1] = CV2.Arc(); E[2] = Arcspine;
682         if (ChFi3d_EdgeState(E,myEFMap) != ChFiDS_OnDiff) IFadArc = 2;
683       }
684       else if (sur2) IFadArc = 2;
685     }
686     else if (CV2.IsOnArc()) IFadArc = 2;
687     IFopArc = 3-IFadArc;
688
689     Arcpiv = Fd->Vertex(isfirst,IFadArc).Arc();
690     Fad = TopoDS::Face(DStr.Shape(Fd->Index(IFadArc)));
691     Fop = TopoDS::Face(DStr.Shape(Fd->Index(IFopArc)));
692     TopTools_ListIteratorOfListOfShape It;
693     // The face at end is returned without check of its unicity.
694     for(It.Initialize(myEFMap(Arcpiv));It.More();It.Next()) {
695       if (!Fad.IsSame(It.Value())) {
696         Fv = TopoDS::Face(It.Value());
697         break;
698       }
699     }
700
701     // Does the face at bout contain the Vertex ?
702     Standard_Boolean isinface = Standard_False;
703     for (ex.Init(Fv,TopAbs_VERTEX); ex.More(); ex.Next()) {
704       if (ex.Current().IsSame(Vtx)) {
705         isinface = Standard_True;
706         break;
707       }
708     }
709     if (!isinface && Fd->Vertex(isfirst,3-IFadArc).IsOnArc()) {
710       IFadArc = 3-IFadArc;
711       IFopArc = 3-IFopArc;
712       Arcpiv = Fd->Vertex(isfirst,IFadArc).Arc();
713       Fad = TopoDS::Face(DStr.Shape(Fd->Index(IFadArc)));
714       Fop = TopoDS::Face(DStr.Shape(Fd->Index(IFopArc)));
715       //TopTools_ListIteratorOfListOfShape It;
716      // The face at end is returned without check of its unicity.
717       for(It.Initialize(myEFMap(Arcpiv));It.More();It.Next()) {
718         if (!Fad.IsSame(It.Value())) {
719           Fv = TopoDS::Face(It.Value());
720           break;
721         }
722       }
723     }
724
725     if (Fv.IsNull()) StdFail_NotDone::Raise
726       ("OneCorner : face at end not found");
727
728     Fv.Orientation(TopAbs_FORWARD);
729     Fad.Orientation(TopAbs_FORWARD);
730     Fop.Orientation(TopAbs_FORWARD);
731
732     // The edge that will be extended is returned.
733     for(It.Initialize(myVEMap(Vtx));It.More() && Arcprol.IsNull();It.Next()) {
734       if (!Arcpiv.IsSame(It.Value())) {
735         for(ex.Init(Fv,TopAbs_EDGE); ex.More(); ex.Next()) {
736           if (It.Value().IsSame(ex.Current())) {
737             Arcprol = TopoDS::Edge(It.Value());
738             OArcprolv = ex.Current().Orientation();
739             break;
740           }
741         }
742       }
743     }
744     if (Arcprol.IsNull()) /*StdFail_NotDone::Raise
745       ("OneCorner : edge a prolonger non trouve");*/
746     {
747       PerformIntersectionAtEnd(Index);
748       return;
749     }
750     for(ex.Init(Fop,TopAbs_EDGE); ex.More(); ex.Next()) {
751       if (Arcprol.IsSame(ex.Current())) {
752         OArcprolop = ex.Current().Orientation();
753         break;
754       }
755     }
756     TopoDS_Face FFv;
757     Standard_Real tol;
758     Standard_Integer prol=0;
759     BRep_Builder BRE;
760     Handle(Geom_Surface ) Sface;
761     Sface=BRep_Tool::Surface(Fv);
762     ChFi3d_ExtendSurface(Sface,prol);
763     tol=BRep_Tool::Tolerance(Fv);
764     BRE.MakeFace(FFv,Sface,tol);
765     if (prol) {
766       Bs.Initialize(FFv,Standard_False);
767       DStr.SetNewSurface(Fv,Sface);
768     }
769     else Bs.Initialize(Fv,Standard_False);
770     Bad.Initialize(Fad);
771     Bop.Initialize(Fop);
772   }
773   //in case of OnSame it is necessary to modify the CommonPoint
774   //in the empty and its parameter in the FaceInterference.
775   //They are both returned in non const references. Attention the modifications are done behind
776   //de CV1,CV2,Fi1,Fi2.
777   ChFiDS_CommonPoint& CPopArc = Fd->ChangeVertex(isfirst,IFopArc);
778   ChFiDS_FaceInterference& FiopArc = Fd->ChangeInterference(IFopArc);
779   ChFiDS_CommonPoint& CPadArc = Fd->ChangeVertex(isfirst,IFadArc);
780   ChFiDS_FaceInterference& FiadArc = Fd->ChangeInterference(IFadArc);
781   //the parameter of the vertex in the air is initialiced with the value of 
782   //its opposite (point on arc).
783   Standard_Real wop = Fd->ChangeInterference(IFadArc).Parameter(isfirst);
784   Handle(Geom_Curve) c3df;
785   Handle(GeomAdaptor_HSurface)
786     HGs = new GeomAdaptor_HSurface(DStr.Surface(Fd->Surf()).Surface());
787   gp_Pnt2d p2dbout;
788
789   if (onsame) {
790
791     ChFiDS_CommonPoint saveCPopArc = CPopArc;
792     c3df = DStr.Curve(FiopArc.LineIndex()).Curve();
793
794     inters = IntersUpdateOnSame (HGs,HBs,c3df,Fop,Fv,Arcprol,Vtx,isfirst,10*tolesp, // in
795                                  FiopArc,CPopArc,p2dbout,wop);   // out
796
797     Handle(BRepAdaptor_HCurve2d) pced = new BRepAdaptor_HCurve2d();
798     pced->ChangeCurve2d().Initialize(CPadArc.Arc(),Fv);
799     // in the case of degenerated Fi, parameter difference can be even negative (eap, occ293)
800     if ((FiadArc.LastParameter() - FiadArc.FirstParameter()) > 10*tolesp)
801       Update(HBs,pced,HGs,FiadArc,CPadArc,isfirst);
802
803     if (thePrepareOnSame) {
804       //saveCPopArc.SetParameter(wop);
805       saveCPopArc.SetPoint(CPopArc.Point());
806       CPopArc = saveCPopArc;
807       return;
808     }
809   }
810   else {
811     inters = FindFace(Vtx,CV1,CV2,Fv,Fop);
812     if (!inters) {
813       PerformIntersectionAtEnd(Index);
814       return;
815     }
816     Bs.Initialize(Fv);
817     Handle(BRepAdaptor_HCurve2d) pced = new BRepAdaptor_HCurve2d();
818     pced->ChangeCurve2d().Initialize(CV1.Arc(),Fv);
819     Update(HBs,pced,HGs,Fd->ChangeInterferenceOnS1(),CV1,isfirst);
820     pced->ChangeCurve2d().Initialize(CV2.Arc(),Fv);
821     Update(HBs,pced,HGs,Fd->ChangeInterferenceOnS2(),CV2,isfirst);
822   }
823
824
825 #ifdef DEB
826  ChFi3d_ResultChron(ch,t_same); // result perf condition if (same)
827  ChFi3d_InitChron(ch); // init perf condition if (inters)
828 #endif
829
830   TopoDS_Edge edgecouture;
831   Standard_Boolean couture,intcouture=Standard_False;;
832   Standard_Real tolreached;
833 #ifndef DEB
834   Standard_Real  par1 =0.,par2 =0.;
835   Standard_Integer indpt = 0,Icurv1 = 0,Icurv2 = 0;
836 #else
837   Standard_Real  par1,par2;
838   Standard_Integer indpt,Icurv1,Icurv2;
839 #endif
840   Handle(Geom_TrimmedCurve) curv1,curv2;
841   Handle(Geom2d_Curve) c2d1,c2d2;
842
843   Standard_Integer Isurf=Fd->Surf();
844
845   if (inters) {
846     HGs = ChFi3d_BoundSurf(DStr,Fd,1,2);
847     const ChFiDS_FaceInterference& Fi1 = Fd->InterferenceOnS1();
848     const ChFiDS_FaceInterference& Fi2 = Fd->InterferenceOnS2();
849     TColStd_Array1OfReal Pardeb(1,4),Parfin(1,4);
850     gp_Pnt2d pfil1,pfac1,pfil2,pfac2;
851     Handle(Geom2d_Curve) Hc1,Hc2;
852     if (onsame && IFopArc == 1) pfac1 = p2dbout;
853     else {
854       Hc1 = BRep_Tool::CurveOnSurface(CV1.Arc(),Fv,Ubid,Ubid);
855       pfac1 = Hc1->Value(CV1.ParameterOnArc());
856     }
857     if (onsame && IFopArc == 2) pfac2 = p2dbout;
858     else {
859       Hc2 = BRep_Tool::CurveOnSurface(CV2.Arc(),Fv,Ubid,Ubid);
860       pfac2 = Hc2->Value(CV2.ParameterOnArc());
861     }
862     if (Fi1.LineIndex() != 0) {
863       pfil1 = Fi1.PCurveOnSurf()->Value(Fi1.Parameter(isfirst));
864     }
865     else {
866       pfil1 = Fi1.PCurveOnSurf()->Value(Fi1.Parameter(!isfirst));
867     }
868     if (Fi2.LineIndex() != 0) {
869       pfil2 = Fi2.PCurveOnSurf()->Value(Fi2.Parameter(isfirst));
870     }
871     else {
872       pfil2 = Fi2.PCurveOnSurf()->Value(Fi2.Parameter(!isfirst));
873     }
874     if (onsame) ChFi3d_Recale(Bs,pfac1,pfac2,(IFadArc == 1));
875
876     Pardeb(1)= pfil1.X(); Pardeb(2) = pfil1.Y();
877     Pardeb(3)= pfac1.X(); Pardeb(4) = pfac1.Y();
878     Parfin(1)= pfil2.X(); Parfin(2) = pfil2.Y();
879     Parfin(3)= pfac2.X(); Parfin(4) = pfac2.Y();
880
881     Standard_Real uu1,uu2,vv1,vv2;
882     ChFi3d_Boite(pfac1,pfac2,uu1,uu2,vv1,vv2);
883     ChFi3d_BoundFac(Bs,uu1,uu2,vv1,vv2);
884
885     if (!ChFi3d_ComputeCurves(HGs,HBs,Pardeb,Parfin,Cc,
886                               Ps,
887                               Pc,tolesp,tol2d,tolreached))
888       Standard_Failure::Raise("OneCorner : echec calcul intersection");
889
890     Udeb = Cc->FirstParameter();
891     Ufin = Cc->LastParameter();
892
893     //  determine if the curve has an intersection with edge of sewing
894
895     ChFi3d_Couture(Fv,couture,edgecouture);
896
897     if (couture  && !BRep_Tool::Degenerated(edgecouture)) {
898
899       //Standard_Real Ubid,Vbid;
900       Handle (Geom_Curve) C=BRep_Tool::Curve(edgecouture,Ubid,Vbid);
901       Handle(Geom_TrimmedCurve) Ctrim=new Geom_TrimmedCurve (C,Ubid,Vbid);
902       GeomAdaptor_Curve cur1(Ctrim->BasisCurve());
903       GeomAdaptor_Curve cur2(Cc);
904       Extrema_ExtCC extCC (cur1,cur2);
905       if (extCC.IsDone()&&extCC.NbExt()!=0)
906       {
907         Standard_Integer imin=0;
908         Standard_Real distmin2 = RealLast();
909         for (Standard_Integer i = 1; i <= extCC.NbExt(); i++)
910           if (extCC.SquareDistance(i) < distmin2)
911           {
912             distmin2 = extCC.SquareDistance(i);
913             imin = i;
914           }
915         if (distmin2 <= Precision::SquareConfusion())
916         {
917           Extrema_POnCurv ponc1,ponc2;
918           extCC.Points( imin, ponc1, ponc2 );
919           par1 = ponc1.Parameter();
920           par2 = ponc2.Parameter();
921           Standard_Real Tol = 1.e-4;
922           if (Abs(par2-Udeb) > Tol && Abs(Ufin-par2) > Tol)
923           {
924             gp_Pnt P1 = ponc1.Value();
925             TopOpeBRepDS_Point tpoint( P1, Tol );
926             indpt = DStr.AddPoint(tpoint);
927             intcouture = Standard_True;
928             curv1 = new Geom_TrimmedCurve(Cc,Udeb,par2);
929             curv2 = new Geom_TrimmedCurve(Cc,par2,Ufin);
930             TopOpeBRepDS_Curve tcurv1(curv1,tolreached);
931             TopOpeBRepDS_Curve tcurv2(curv2,tolreached);
932             Icurv1=DStr.AddCurve(tcurv1);
933             Icurv2=DStr.AddCurve(tcurv2);
934           }
935         }
936       }
937     }
938   }
939   else { // (!inters)
940     Standard_NotImplemented::Raise("OneCorner : bouchon non ecrit");
941   }
942   Standard_Integer IShape = DStr.AddShape(Fv);
943 #ifndef DEB
944   TopAbs_Orientation Et = TopAbs_FORWARD;
945 #else
946   TopAbs_Orientation Et;
947 #endif
948   if (IFadArc == 1) {
949     TopExp_Explorer Exp;
950     for (Exp.Init(Fv.Oriented(TopAbs_FORWARD),
951                   TopAbs_EDGE);Exp.More();Exp.Next()) {
952       if (Exp.Current().IsSame(CV1.Arc())) {
953         Et = TopAbs::Reverse(TopAbs::Compose
954                              (Exp.Current().Orientation(),
955                               CV1.TransitionOnArc()));
956         break;
957       }
958     }
959   }
960   else {
961     TopExp_Explorer Exp;
962     for (Exp.Init(Fv.Oriented(TopAbs_FORWARD),
963                               TopAbs_EDGE);Exp.More();Exp.Next()) {
964       if (Exp.Current().IsSame(CV2.Arc())) {
965         Et = TopAbs::Compose(Exp.Current().Orientation(),
966                              CV2.TransitionOnArc());
967         break;
968       }
969     }
970
971 //
972
973
974   }
975
976 #ifdef DEB
977   ChFi3d_ResultChron(ch ,t_inter); //result perf condition if (inter)
978   ChFi3d_InitChron(ch); // init perf condition  if (onsame && inters)
979 #endif
980
981   stripe->SetIndexPoint(ChFi3d_IndexPointInDS(CV1,DStr),isfirst,1);
982   stripe->SetIndexPoint(ChFi3d_IndexPointInDS(CV2,DStr),isfirst,2);
983
984   if (!intcouture) {
985 // there is no intersection with the sewing edge
986 // the curve Cc is stored in the stripe
987 // the storage in the DS is not done by FILDS.
988
989     TopOpeBRepDS_Curve Tc(Cc,tolreached);
990     ICurve = DStr.AddCurve(Tc);
991     Handle(TopOpeBRepDS_SurfaceCurveInterference)
992       Interfc = ChFi3d_FilCurveInDS(ICurve,IShape,Pc,Et);
993
994     // 31/01/02 akm vvv : (OCC119) Prevent the builder from creating
995     //                    intersecting fillets - they are bad.
996     Geom2dInt_GInter anIntersector;
997     Geom2dAdaptor_Curve aCorkPCurve (Pc, Udeb, Ufin);
998
999     // Take all the interferences with faces from all the stripes
1000     // and look if their pcurves intersect our cork pcurve.
1001     // Unfortunately, by this moment they do not exist in DStr.
1002     ChFiDS_ListIteratorOfListOfStripe aStrIt(myListStripe);
1003     for (; aStrIt.More(); aStrIt.Next())
1004     {
1005       Handle(ChFiDS_Stripe) aCheckStripe = aStrIt.Value();
1006       Handle(ChFiDS_HData) aSeqData = aCheckStripe->SetOfSurfData();
1007       // Loop on parts of the stripe
1008       Standard_Integer iPart;
1009       for (iPart=1; iPart<=aSeqData->Length(); iPart++)
1010       {
1011         Handle(ChFiDS_SurfData) aData = aSeqData->Value(iPart);
1012         Geom2dAdaptor_Curve anOtherPCurve;
1013         if (IShape == aData->IndexOfS1())
1014         {
1015     const Handle(Geom2d_Curve)& aPCurve = aData->InterferenceOnS1().PCurveOnFace();
1016     if(aPCurve.IsNull())
1017       continue;
1018
1019           anOtherPCurve.Load (aPCurve,
1020                               aData->InterferenceOnS1().FirstParameter(),
1021                               aData->InterferenceOnS1().LastParameter());
1022         }
1023         else if (IShape == aData->IndexOfS2())
1024         {
1025     const Handle(Geom2d_Curve)& aPCurve = aData->InterferenceOnS2().PCurveOnFace();
1026     if(aPCurve.IsNull())
1027       continue;
1028
1029           anOtherPCurve.Load (aPCurve,
1030                               aData->InterferenceOnS2().FirstParameter(),
1031                               aData->InterferenceOnS2().LastParameter());
1032         }
1033         else
1034         {
1035           // Normal case - no common surface
1036           continue;
1037         }
1038         if (IsEqual(anOtherPCurve.LastParameter(),anOtherPCurve.FirstParameter()))
1039           // Degenerates
1040           continue;
1041         anIntersector.Perform (aCorkPCurve, anOtherPCurve,
1042                                tol2d, Precision::PConfusion());
1043         if (anIntersector.NbSegments() > 0 ||
1044             anIntersector.NbPoints() > 0)
1045           StdFail_NotDone::Raise ("OneCorner : fillets have too big radiuses");
1046       }
1047     }
1048     TopOpeBRepDS_ListIteratorOfListOfInterference
1049       anIter(DStr.ChangeShapeInterferences(IShape));
1050     for (; anIter.More(); anIter.Next())
1051     {
1052       Handle(TopOpeBRepDS_SurfaceCurveInterference) anOtherIntrf =
1053         Handle(TopOpeBRepDS_SurfaceCurveInterference)::DownCast(anIter.Value());
1054       // We need only interferences between cork face and curves
1055       // of intersection with another fillet surfaces
1056       if (anOtherIntrf.IsNull())
1057         continue;
1058       // Look if there is an intersection between pcurves
1059       Handle(Geom_TrimmedCurve) anOtherCur =
1060         Handle(Geom_TrimmedCurve)::DownCast(DStr.Curve (anOtherIntrf->Geometry()).Curve());
1061       if (anOtherCur.IsNull())
1062         continue;
1063       Geom2dAdaptor_Curve anOtherPCurve (anOtherIntrf->PCurve(),
1064                                          anOtherCur->FirstParameter(),
1065                                          anOtherCur->LastParameter());
1066       anIntersector.Perform (aCorkPCurve, anOtherPCurve,
1067                              tol2d, Precision::PConfusion());
1068       if (anIntersector.NbSegments() > 0 ||
1069           anIntersector.NbPoints() > 0)
1070         StdFail_NotDone::Raise ("OneCorner : fillets have too big radiuses");
1071     }
1072     // 31/01/02 akm ^^^
1073     DStr.ChangeShapeInterferences(IShape).Append(Interfc);
1074     //// modified by jgv, 26.03.02 for OCC32 ////
1075     ChFiDS_CommonPoint CV [2];
1076     CV[0] = CV1;
1077     CV[1] = CV2;
1078     for (Standard_Integer i = 0; i < 2; i++)
1079     {
1080       if (CV[i].IsOnArc() && ChFi3d_IsPseudoSeam( CV[i].Arc(), Fv ))
1081       {
1082         gp_Pnt2d pfac1, PcF, PcL;
1083         gp_Vec2d DerPc, DerHc;
1084         Standard_Real first, last, prm1, prm2;
1085         Standard_Boolean onfirst, FirstToPar;
1086         Handle(Geom2d_Curve) Hc = BRep_Tool::CurveOnSurface( CV[i].Arc(), Fv, first, last );
1087         pfac1 = Hc->Value( CV[i].ParameterOnArc() );
1088         PcF = Pc->Value( Udeb );
1089         PcL = Pc->Value( Ufin );
1090         onfirst = (pfac1.Distance(PcF) < pfac1.Distance(PcL))? Standard_True : Standard_False;
1091         if (onfirst)
1092           Pc->D1( Udeb, PcF, DerPc );
1093         else
1094         {
1095           Pc->D1( Ufin, PcL, DerPc );
1096           DerPc.Reverse();
1097         }
1098         Hc->D1( CV[i].ParameterOnArc(), pfac1, DerHc );
1099         if (DerHc.Dot(DerPc) > 0.)
1100         {
1101           prm1 = CV[i].ParameterOnArc();
1102           prm2 = last;
1103           FirstToPar = Standard_False;
1104         }
1105         else
1106         {
1107           prm1 = first;
1108           prm2 = CV[i].ParameterOnArc();
1109           FirstToPar = Standard_True;
1110         }
1111         Handle(Geom_Curve) Ct = BRep_Tool::Curve( CV[i].Arc(), first, last );
1112         Ct = new Geom_TrimmedCurve( Ct, prm1, prm2 );
1113         Standard_Real toled = BRep_Tool::Tolerance( CV[i].Arc() );
1114         TopOpeBRepDS_Curve tcurv( Ct, toled );
1115         Handle (TopOpeBRepDS_CurvePointInterference) Interfp1, Interfp2;
1116         Standard_Integer indcurv;
1117         indcurv = DStr.AddCurve( tcurv );
1118         Standard_Integer indpoint = (isfirst)? stripe->IndexFirstPointOnS1() : stripe->IndexLastPointOnS1();
1119         Standard_Integer indvertex = DStr.AddShape(Vtx);
1120         if (FirstToPar)
1121         {
1122           Interfp1 = ChFi3d_FilPointInDS( TopAbs_FORWARD,  indcurv, indvertex, prm1, Standard_True );
1123           Interfp2 = ChFi3d_FilPointInDS( TopAbs_REVERSED, indcurv, indpoint,  prm2, Standard_False );
1124         }
1125         else
1126         {
1127           Interfp1 = ChFi3d_FilPointInDS( TopAbs_FORWARD,  indcurv, indpoint,  prm1, Standard_False );
1128           Interfp2 = ChFi3d_FilPointInDS( TopAbs_REVERSED, indcurv, indvertex, prm2, Standard_True );
1129         }
1130         DStr.ChangeCurveInterferences(indcurv).Append(Interfp1);
1131         DStr.ChangeCurveInterferences(indcurv).Append(Interfp2);
1132         Standard_Integer indface = DStr.AddShape( Fv );
1133         Interfc = ChFi3d_FilCurveInDS( indcurv, indface, Hc, CV[i].Arc().Orientation() );
1134         DStr.ChangeShapeInterferences(indface).Append( Interfc );
1135         TopoDS_Edge aLocalEdge = CV[i].Arc();
1136         aLocalEdge.Reverse();
1137         Handle(Geom2d_Curve) HcR = BRep_Tool::CurveOnSurface( aLocalEdge, Fv, first, last );
1138         Interfc = ChFi3d_FilCurveInDS( indcurv, indface, HcR, aLocalEdge.Orientation() );
1139         DStr.ChangeShapeInterferences(indface).Append( Interfc );
1140         //modify degenerated edge
1141         Standard_Boolean DegenExist = Standard_False;
1142         TopoDS_Edge Edeg;
1143         TopExp_Explorer Explo( Fv, TopAbs_EDGE );
1144         for (; Explo.More(); Explo.Next())
1145         {
1146           const TopoDS_Edge& Ecur = TopoDS::Edge( Explo.Current() );
1147           if (BRep_Tool::Degenerated( Ecur ))
1148           {
1149             TopoDS_Vertex Vf, Vl;
1150             TopExp::Vertices( Ecur, Vf, Vl );
1151             if (Vf.IsSame(Vtx) || Vl.IsSame(Vtx))
1152             {
1153               DegenExist = Standard_True;
1154               Edeg = Ecur;
1155               break;
1156             }
1157           }
1158         }
1159         if (DegenExist)
1160         {
1161           Standard_Real fd, ld;
1162           Handle(Geom2d_Curve) Cd = BRep_Tool::CurveOnSurface( Edeg, Fv, fd, ld );
1163           Handle(Geom2d_TrimmedCurve) tCd = Handle(Geom2d_TrimmedCurve)::DownCast(Cd);
1164           if (! tCd.IsNull())
1165             Cd = tCd->BasisCurve();
1166           gp_Pnt2d P2d = (FirstToPar)? Hc->Value(first) : Hc->Value(last);
1167           Geom2dAPI_ProjectPointOnCurve Projector( P2d, Cd );
1168           Standard_Real par = Projector.LowerDistanceParameter();
1169           Standard_Integer Ideg = DStr.AddShape(Edeg);
1170           TopAbs_Orientation ori = (par < fd)? TopAbs_FORWARD : TopAbs_REVERSED; //if par<fd => par>ld
1171           Interfp1 = ChFi3d_FilPointInDS( ori, Ideg, indvertex, par, Standard_True );
1172           DStr.ChangeShapeInterferences(Ideg).Append(Interfp1);
1173         }
1174       }
1175     }
1176     /////////////////////////////////////////////
1177     stripe->ChangePCurve(isfirst)=Ps;
1178     stripe->SetCurve(ICurve,isfirst);
1179     stripe->SetParameters(isfirst,Udeb,Ufin);
1180   }
1181   else {
1182 // curves curv1 are curv2 stored in the DS
1183 // these curves will not be reconstructed by FILDS as
1184 // one places stripe->InDS(isfirst);
1185
1186     // interferences of curv1 and curv2 on Fv
1187     ComputeCurve2d(curv1,Fv,c2d1);
1188     Handle(TopOpeBRepDS_SurfaceCurveInterference) InterFv;
1189     InterFv = ChFi3d_FilCurveInDS(Icurv1,IShape,c2d1,Et);
1190     DStr.ChangeShapeInterferences(IShape).Append(InterFv);
1191     ComputeCurve2d(curv2,Fv,c2d2);
1192     InterFv = ChFi3d_FilCurveInDS(Icurv2,IShape,c2d2,Et);
1193     DStr.ChangeShapeInterferences(IShape).Append(InterFv);
1194      // interferences of curv1 and curv2 on Isurf
1195     if (Fd->Orientation()== Fv.Orientation()) Et=TopAbs::Reverse(Et);
1196     c2d1=new Geom2d_TrimmedCurve(Ps,Udeb,par2);
1197     InterFv = ChFi3d_FilCurveInDS(Icurv1,Isurf,c2d1,Et);
1198     DStr.ChangeSurfaceInterferences(Isurf).Append(InterFv);
1199     c2d2=new Geom2d_TrimmedCurve(Ps,par2,Ufin);
1200        InterFv = ChFi3d_FilCurveInDS(Icurv2,Isurf,c2d2,Et);
1201     DStr.ChangeSurfaceInterferences(Isurf).Append(InterFv);
1202
1203       // limitation of the sewing edge
1204     Standard_Integer Iarc=DStr.AddShape(edgecouture);
1205     Handle(TopOpeBRepDS_CurvePointInterference) Interfedge;
1206     TopAbs_Orientation ori;
1207     TopoDS_Vertex Vdeb,Vfin;
1208     Vdeb=TopExp::FirstVertex(edgecouture);
1209     Vfin=TopExp::LastVertex(edgecouture);
1210     Standard_Real pard,parf;
1211     pard=BRep_Tool::Parameter(Vdeb,edgecouture);
1212     parf=BRep_Tool::Parameter(Vfin,edgecouture);
1213     if (Abs(par1-pard)<Abs(parf-par1)) ori=TopAbs_FORWARD;
1214     else ori=TopAbs_REVERSED;
1215     Interfedge = ChFi3d_FilPointInDS(ori,Iarc,indpt,par1);
1216     DStr.ChangeShapeInterferences(Iarc).Append(Interfedge);
1217
1218     // creation of CurveInterferences from Icurv1 and Icurv2
1219     stripe->InDS(isfirst);
1220     Standard_Integer ind1= stripe->IndexPoint(isfirst,1);
1221     Standard_Integer ind2= stripe->IndexPoint(isfirst,2);
1222     Handle(TopOpeBRepDS_CurvePointInterference)
1223       interfprol = ChFi3d_FilPointInDS(TopAbs_FORWARD,Icurv1,ind1,Udeb);
1224     DStr.ChangeCurveInterferences(Icurv1).Append(interfprol);
1225     interfprol = ChFi3d_FilPointInDS(TopAbs_REVERSED,Icurv1,indpt,par2);
1226     DStr.ChangeCurveInterferences(Icurv1).Append(interfprol);
1227     interfprol = ChFi3d_FilPointInDS(TopAbs_FORWARD,Icurv2,indpt,par2);
1228     DStr.ChangeCurveInterferences(Icurv2).Append(interfprol);
1229     interfprol = ChFi3d_FilPointInDS(TopAbs_REVERSED,Icurv2,ind2,Ufin);
1230     DStr.ChangeCurveInterferences(Icurv2).Append(interfprol);
1231
1232   }
1233
1234   ChFi3d_EnlargeBox(HBs,Pc,Udeb,Ufin,box1,box2);
1235
1236   if (onsame && inters) {
1237     // VARIANT 1:
1238     // A small missing end of curve is added for the extension
1239     // of the face at end and the limitation of the opposing face.
1240
1241     //   VARIANT 2 : extend Arcprol, not create new small edge
1242     //   To do: modify for intcouture
1243     const Standard_Boolean variant1 = Standard_True;
1244
1245     // First of all the ponts are cut with the edge of the spine.
1246     Standard_Integer IArcspine = DStr.AddShape(Arcspine);
1247     Standard_Integer IVtx = DStr.AddShape(Vtx);
1248 #ifndef DEB
1249     TopAbs_Orientation OVtx = TopAbs_FORWARD;
1250 #else
1251     TopAbs_Orientation OVtx;
1252 #endif
1253     for(ex.Init(Arcspine.Oriented(TopAbs_FORWARD),TopAbs_VERTEX);
1254         ex.More(); ex.Next()) {
1255       if (Vtx.IsSame(ex.Current())) {
1256         OVtx = ex.Current().Orientation();
1257         break;
1258       }
1259     }
1260     OVtx = TopAbs::Reverse(OVtx);
1261     Standard_Real parVtx = BRep_Tool::Parameter(Vtx,Arcspine);
1262     Handle(TopOpeBRepDS_CurvePointInterference)
1263       interfv = ChFi3d_FilVertexInDS(OVtx,IArcspine,IVtx,parVtx);
1264     DStr.ChangeShapeInterferences(IArcspine).Append(interfv);
1265
1266     // Now the missing curves are constructed.
1267     TopoDS_Vertex V2;
1268     for(ex.Init(Arcprol.Oriented(TopAbs_FORWARD),TopAbs_VERTEX);
1269         ex.More(); ex.Next()) {
1270       if (Vtx.IsSame(ex.Current()))
1271         OVtx = ex.Current().Orientation();
1272       else
1273         V2 =  TopoDS::Vertex(ex.Current());
1274     }
1275
1276     Handle(Geom2d_Curve) Hc;
1277     if (variant1)
1278       parVtx = BRep_Tool::Parameter(Vtx,Arcprol);
1279     else
1280       parVtx = BRep_Tool::Parameter(V2,Arcprol);
1281     const ChFiDS_FaceInterference& Fiop = Fd->Interference(IFopArc);
1282     gp_Pnt2d pop1, pop2, pv1, pv2;
1283     Hc = BRep_Tool::CurveOnSurface(Arcprol,Fop,Ubid,Ubid);
1284     pop1 = Hc->Value(parVtx);
1285     pop2 = Fiop.PCurveOnFace()->Value(Fiop.Parameter(isfirst));
1286     Hc = BRep_Tool::CurveOnSurface(Arcprol,Fv,Ubid,Ubid);
1287     pv1 = Hc->Value(parVtx);
1288     pv2 = p2dbout;
1289     ChFi3d_Recale(Bs,pv1,pv2,1);
1290     TColStd_Array1OfReal Pardeb(1,4),Parfin(1,4);
1291     Pardeb(1) = pop1.X(); Pardeb(2) = pop1.Y();
1292     Pardeb(3) = pv1.X();  Pardeb(4) = pv1.Y();
1293     Parfin(1) = pop2.X(); Parfin(2) = pop2.Y();
1294     Parfin(3) = pv2.X();  Parfin(4) = pv2.Y();
1295     Standard_Real uu1,uu2,vv1,vv2;
1296     ChFi3d_Boite(pv1,pv2,uu1,uu2,vv1,vv2);
1297     ChFi3d_BoundFac(Bs,uu1,uu2,vv1,vv2);
1298     ChFi3d_Boite(pop1,pop2,uu1,uu2,vv1,vv2);
1299     ChFi3d_BoundFac(Bop,uu1,uu2,vv1,vv2);
1300
1301     Handle(Geom_Curve) zob3d;
1302     Handle(Geom2d_Curve) zob2dop, zob2dv;
1303     //Standard_Real tolreached;
1304     if (!ChFi3d_ComputeCurves(HBop,HBs,Pardeb,Parfin,zob3d,zob2dop,
1305                               zob2dv,tolesp,tol2d,tolreached))
1306       Standard_Failure::Raise("OneCorner : echec calcul intersection");
1307
1308     Udeb = zob3d->FirstParameter();
1309     Ufin = zob3d->LastParameter();
1310     TopOpeBRepDS_Curve Zob(zob3d,tolreached);
1311     Standard_Integer IZob = DStr.AddCurve(Zob);
1312
1313 // it is determined if Fop has an edge of sewing 
1314 // it is determined if the curve has an intersection with the edge of sewing
1315
1316     //TopoDS_Edge edgecouture;
1317     //Standard_Boolean couture;
1318     ChFi3d_Couture(Fop,couture,edgecouture);
1319
1320     if (couture  && !BRep_Tool::Degenerated(edgecouture)) {
1321       BRepLib_MakeEdge Bedge (zob3d);
1322       TopoDS_Edge edg =Bedge. Edge();
1323       BRepExtrema_ExtCC extCC (edgecouture,edg);
1324       if (extCC.IsDone()&&extCC.NbExt()!=0) {
1325         for (Standard_Integer i=1; i<=extCC.NbExt()&&!intcouture;i++) {
1326           if (extCC.SquareDistance(i)<=1.e-8) {
1327             par1=extCC.ParameterOnE1(i);
1328             par2=extCC.ParameterOnE2(i);
1329             gp_Pnt P1=extCC.PointOnE1(i);
1330             TopOpeBRepDS_Point tpoint(P1,1.e-4);
1331             indpt=DStr.AddPoint(tpoint);
1332             intcouture=Standard_True;
1333             curv1 = new Geom_TrimmedCurve(zob3d,Udeb,par2);
1334             curv2 = new Geom_TrimmedCurve(zob3d,par2,Ufin);
1335             TopOpeBRepDS_Curve tcurv1(curv1,tolreached);
1336             TopOpeBRepDS_Curve tcurv2(curv2,tolreached);
1337             Icurv1=DStr.AddCurve(tcurv1);
1338             Icurv2=DStr.AddCurve(tcurv2);
1339           }
1340         }
1341       }
1342     }
1343     if (intcouture) {
1344
1345 // interference of curv1 and curv2 on Ishape
1346       Et = TopAbs::Reverse(TopAbs::Compose(OVtx,OArcprolv));
1347       ComputeCurve2d(curv1,Fop,c2d1);
1348       Handle(TopOpeBRepDS_SurfaceCurveInterference)
1349         InterFv = ChFi3d_FilCurveInDS(Icurv1,IShape,/*zob2dv*/c2d1,Et);
1350       DStr.ChangeShapeInterferences(IShape).Append(InterFv);
1351       ComputeCurve2d(curv2,Fop,c2d2);
1352       InterFv = ChFi3d_FilCurveInDS(Icurv2,IShape,/*zob2dv*/c2d2,Et);
1353       DStr.ChangeShapeInterferences(IShape).Append(InterFv);
1354
1355       // limitation of the sewing edge
1356       Standard_Integer Iarc=DStr.AddShape(edgecouture);
1357       Handle(TopOpeBRepDS_CurvePointInterference) Interfedge;
1358       TopAbs_Orientation ori;
1359       TopoDS_Vertex Vdeb,Vfin;
1360       Vdeb=TopExp::FirstVertex(edgecouture);
1361       Vfin=TopExp::LastVertex(edgecouture);
1362       Standard_Real pard,parf;
1363       pard=BRep_Tool::Parameter(Vdeb,edgecouture);
1364       parf=BRep_Tool::Parameter(Vfin,edgecouture);
1365       if (Abs(par1-pard)<Abs(parf-par1)) ori=TopAbs_REVERSED;
1366       else ori=TopAbs_FORWARD;
1367       Interfedge = ChFi3d_FilPointInDS(ori,Iarc,indpt,par1);
1368       DStr.ChangeShapeInterferences(Iarc).Append(Interfedge);
1369
1370     //  interference of curv1 and curv2 on Iop
1371       Standard_Integer Iop = DStr.AddShape(Fop);
1372       Et = TopAbs::Reverse(TopAbs::Compose(OVtx,OArcprolop));
1373       Handle(TopOpeBRepDS_SurfaceCurveInterference)  Interfop;
1374       ComputeCurve2d(curv1,Fop,c2d1);
1375       Interfop  = ChFi3d_FilCurveInDS(Icurv1,Iop,c2d1,Et);
1376       DStr.ChangeShapeInterferences(Iop).Append(Interfop);
1377       ComputeCurve2d(curv2,Fop,c2d2);
1378       Interfop  = ChFi3d_FilCurveInDS(Icurv2,Iop,c2d2,Et);
1379       DStr.ChangeShapeInterferences(Iop).Append(Interfop);
1380       Handle(TopOpeBRepDS_CurvePointInterference)
1381         interfprol = ChFi3d_FilVertexInDS(TopAbs_FORWARD,Icurv1,IVtx,Udeb);
1382       DStr.ChangeCurveInterferences(Icurv1).Append(interfprol);
1383       interfprol = ChFi3d_FilPointInDS(TopAbs_REVERSED,Icurv1,indpt,par2);
1384       DStr.ChangeCurveInterferences(Icurv1).Append(interfprol);
1385       Standard_Integer icc = stripe->IndexPoint(isfirst,IFopArc);
1386       interfprol = ChFi3d_FilPointInDS(TopAbs_FORWARD,Icurv2,indpt,par2);
1387       DStr.ChangeCurveInterferences(Icurv2).Append(interfprol);
1388       interfprol = ChFi3d_FilPointInDS(TopAbs_REVERSED,Icurv2,icc,Ufin);
1389       DStr.ChangeCurveInterferences(Icurv2).Append(interfprol);
1390     }
1391     else {
1392       Et = TopAbs::Reverse(TopAbs::Compose(OVtx,OArcprolv));
1393       Handle(TopOpeBRepDS_SurfaceCurveInterference)
1394         InterFv = ChFi3d_FilCurveInDS(IZob,IShape,zob2dv,Et);
1395       DStr.ChangeShapeInterferences(IShape).Append(InterFv);
1396       Et = TopAbs::Reverse(TopAbs::Compose(OVtx,OArcprolop));
1397       Standard_Integer Iop = DStr.AddShape(Fop);
1398       Handle(TopOpeBRepDS_SurfaceCurveInterference)
1399         Interfop = ChFi3d_FilCurveInDS(IZob,Iop,zob2dop,Et);
1400       DStr.ChangeShapeInterferences(Iop).Append(Interfop);
1401       Handle(TopOpeBRepDS_CurvePointInterference) interfprol;
1402       if (variant1)
1403         interfprol = ChFi3d_FilVertexInDS(TopAbs_FORWARD,IZob,IVtx,Udeb);
1404       else {
1405         Standard_Integer IV2 = DStr.AddShape(V2); // VARIANT 2
1406         interfprol = ChFi3d_FilVertexInDS(TopAbs_FORWARD,IZob,IV2,Udeb);
1407       }
1408       DStr.ChangeCurveInterferences(IZob).Append(interfprol);
1409       Standard_Integer icc = stripe->IndexPoint(isfirst,IFopArc);
1410       interfprol = ChFi3d_FilPointInDS(TopAbs_REVERSED,IZob,icc,Ufin);
1411       DStr.ChangeCurveInterferences(IZob).Append(interfprol);
1412       if (variant1) {
1413         if (IFopArc == 1) box1.Add( zob3d->Value(Ufin) );
1414         else              box2.Add( zob3d->Value(Ufin) );
1415       }
1416       else {
1417         // cut off existing Arcprol
1418         Standard_Integer iArcprol = DStr.AddShape(Arcprol);
1419         interfprol = ChFi3d_FilPointInDS(OVtx,iArcprol,icc,Udeb);
1420         DStr.ChangeShapeInterferences(Arcprol).Append(interfprol);
1421       }
1422     }
1423   }
1424   ChFi3d_EnlargeBox(DStr,stripe,Fd,box1,box2,isfirst);
1425   if (CV1.IsOnArc()) {
1426     ChFi3d_EnlargeBox(CV1.Arc(),myEFMap(CV1.Arc()),CV1.ParameterOnArc(),box1);
1427   }
1428   if (CV2.IsOnArc()) {
1429     ChFi3d_EnlargeBox(CV2.Arc(),myEFMap(CV2.Arc()),CV2.ParameterOnArc(),box2);
1430   }
1431   if  (!CV1.IsVertex())
1432     ChFi3d_SetPointTolerance(DStr,box1,stripe->IndexPoint(isfirst,1));
1433   if (!CV2.IsVertex())
1434     ChFi3d_SetPointTolerance(DStr,box2,stripe->IndexPoint(isfirst,2));
1435
1436 #ifdef DEB
1437   ChFi3d_ResultChron(ch, t_sameinter);//result perf condition if (same &&inter)
1438 #endif
1439 }
1440
1441 //=======================================================================
1442 //function : cherche_face
1443 //purpose  : find face F belonging to the map, different from faces
1444 //           F1  F2 F3 and containing edge E
1445 //=======================================================================
1446
1447 static void cherche_face (const TopTools_ListOfShape & map,
1448                           const TopoDS_Edge & E,
1449                           const TopoDS_Face & F1,
1450                           const TopoDS_Face & F2,
1451                           const TopoDS_Face & F3,
1452                           TopoDS_Face &  F)
1453 { TopoDS_Face Fcur;
1454   Standard_Boolean trouve=Standard_False;
1455   TopTools_ListIteratorOfListOfShape It;
1456   Standard_Integer ie;
1457   for (It.Initialize(map);It.More()&&!trouve;It.Next())
1458   { Fcur=TopoDS::Face (It.Value());
1459     if (!Fcur.IsSame(F1) && !Fcur.IsSame(F2)&& !Fcur.IsSame(F3) )
1460     { TopTools_IndexedMapOfShape  MapE;
1461       TopExp::MapShapes( Fcur,TopAbs_EDGE,MapE);
1462       for ( ie=1; ie<= MapE.Extent()&&!trouve;  ie++)
1463       {
1464         TopoDS_Shape aLocalShape = TopoDS_Shape (MapE(ie));
1465         if (E.IsSame(TopoDS::Edge(aLocalShape)))
1466           //            if (E.IsSame(TopoDS::Edge(TopoDS_Shape (MapE(ie)))))
1467         { F= Fcur; trouve=Standard_True;}
1468       }
1469     }
1470   }
1471 }
1472
1473 //=======================================================================
1474 //function : cherche_edge1
1475 //purpose  : find common edge between faces F1 and F2
1476 //=======================================================================
1477
1478 static void cherche_edge1 (const TopoDS_Face & F1,
1479                     const TopoDS_Face & F2,
1480                           TopoDS_Edge & Edge)
1481 { Standard_Integer i,j;
1482   TopoDS_Edge Ecur1,Ecur2;
1483   Standard_Boolean trouve=Standard_False;
1484   TopTools_IndexedMapOfShape  MapE1,MapE2;
1485   TopExp::MapShapes( F1,TopAbs_EDGE,MapE1);
1486   TopExp::MapShapes( F2,TopAbs_EDGE,MapE2);
1487   for ( i=1; i<= MapE1.Extent()&&!trouve; i++)
1488       {
1489         TopoDS_Shape aLocalShape = TopoDS_Shape (MapE1(i));
1490         Ecur1=TopoDS::Edge(aLocalShape);
1491 //      Ecur1=TopoDS::Edge(TopoDS_Shape (MapE1(i)));
1492         for ( j=1; j<= MapE2.Extent()&&!trouve; j++)
1493             {
1494               aLocalShape = TopoDS_Shape (MapE2(j));
1495               Ecur2=TopoDS::Edge(aLocalShape);
1496 //            Ecur2=TopoDS::Edge(TopoDS_Shape (MapE2(j)));
1497             if (Ecur2.IsSame(Ecur1))
1498                {Edge=Ecur1;trouve=Standard_True;}
1499             }
1500       }
1501 }
1502
1503 //=======================================================================
1504 //function : containV
1505 //purpose  : return true if vertex V belongs to F1
1506 //=======================================================================
1507
1508 static Standard_Boolean  containV(const TopoDS_Face & F1,
1509                            const TopoDS_Vertex & V)
1510 { Standard_Integer i;
1511   TopoDS_Vertex Vcur;
1512   Standard_Boolean trouve=Standard_False;
1513   Standard_Boolean contain=Standard_False;
1514   TopTools_IndexedMapOfShape  MapV;
1515   TopExp::MapShapes( F1,TopAbs_VERTEX,MapV);
1516   for ( i=1; i<= MapV.Extent()&&!trouve; i++)
1517       {
1518         TopoDS_Shape aLocalShape = TopoDS_Shape (MapV(i));
1519         Vcur=TopoDS::Vertex(aLocalShape);
1520 //      Vcur=TopoDS::Vertex(TopoDS_Shape (MapV(i)));
1521         if (Vcur.IsSame(V) )
1522             {contain=Standard_True; trouve=Standard_True;}
1523       }
1524   return contain;
1525 }
1526
1527 //=======================================================================
1528 //function : containE
1529 //purpose  : return true if edge E belongs to F1
1530 //=======================================================================
1531
1532 static Standard_Boolean  containE(const TopoDS_Face & F1,
1533                            const TopoDS_Edge & E)
1534 { Standard_Integer i;
1535   TopoDS_Edge Ecur;
1536   Standard_Boolean trouve=Standard_False;
1537   Standard_Boolean contain=Standard_False;
1538   TopTools_IndexedMapOfShape  MapE;
1539   TopExp::MapShapes( F1,TopAbs_EDGE,MapE);
1540   for ( i=1; i<= MapE.Extent()&&!trouve; i++)
1541       {
1542         TopoDS_Shape aLocalShape = TopoDS_Shape (MapE(i));
1543         Ecur=TopoDS::Edge(aLocalShape);
1544 //      Ecur=TopoDS::Edge(TopoDS_Shape (MapE(i)));
1545         if (Ecur.IsSame(E) )
1546             {contain=Standard_True; trouve=Standard_True;}
1547       }
1548   return contain;
1549 }
1550
1551
1552 //=======================================================================
1553 //function : IsShrink
1554 //purpose  : check if U (if <isU>==True) or V of points of <PC> is within
1555 //           <tol> from <Param>, check points between <Pf> and <Pl>
1556 //=======================================================================
1557
1558 static Standard_Boolean IsShrink(const Geom2dAdaptor_Curve PC,
1559                                  const Standard_Real       Pf,
1560                                  const Standard_Real       Pl,
1561                                  const Standard_Real       Param,
1562                                  const Standard_Boolean    isU,
1563                                  const Standard_Real       tol)
1564 {
1565   switch (PC.GetType()) {
1566   case GeomAbs_Line: {
1567     gp_Pnt2d P1 = PC.Value(Pf);
1568     gp_Pnt2d P2 = PC.Value(Pl);
1569     if (Abs(P1.Coord(isU ? 1 : 2) - Param) <= tol &&
1570         Abs(P2.Coord(isU ? 1 : 2) - Param) <= tol )
1571       return Standard_True;
1572     else
1573       return Standard_False;
1574   }
1575   case GeomAbs_BezierCurve:
1576   case GeomAbs_BSplineCurve: {
1577     math_FunctionSample aSample (Pf,Pl,10);
1578     Standard_Integer i;
1579     for (i=1; i<=aSample.NbPoints(); i++) {
1580       gp_Pnt2d P = PC.Value(aSample.GetParameter(i));
1581       if (Abs(P.Coord(isU ? 1 : 2) - Param) > tol )
1582         return Standard_False;
1583     }
1584     return Standard_True;
1585   }
1586   default:;
1587   }
1588   return Standard_False;
1589 }
1590 //=======================================================================
1591 //function : PerformIntersectionAtEnd
1592 //purpose  :
1593 //=======================================================================
1594
1595 void ChFi3d_Builder::PerformIntersectionAtEnd(const Standard_Integer Index)
1596 {
1597
1598   // intersection at end of fillet with at least two faces
1599   // process the following cases:
1600   // - top has n (n>3) adjacent edges
1601   // - top has 3 edges and fillet on one of edges touches
1602   //   more than one face
1603
1604 #ifdef DEB
1605   OSD_Chronometer ch;// init perf
1606 #endif
1607
1608   TopOpeBRepDS_DataStructure& DStr= myDS->ChangeDS();
1609   const Standard_Integer nn=15;
1610   ChFiDS_ListIteratorOfListOfStripe It;
1611   It.Initialize(myVDataMap(Index));
1612   Handle(ChFiDS_Stripe) stripe = It.Value();
1613   const Handle(ChFiDS_Spine) spine = stripe->Spine();
1614   ChFiDS_SequenceOfSurfData& SeqFil =
1615     stripe->ChangeSetOfSurfData()->ChangeSequence();
1616   const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index);
1617   Standard_Integer sens = 0,num,num1;
1618   Standard_Boolean couture=Standard_False,isfirst;
1619   //Standard_Integer sense;
1620   TopoDS_Edge edgelibre1,edgelibre2,EdgeSpine;
1621   Standard_Boolean bordlibre;
1622   // determine the number of faces and edges
1623   TopTools_Array1OfShape tabedg(0,nn);
1624   TopoDS_Face F1,F2;
1625   Standard_Integer nface=ChFi3d_nbface(myVFMap(Vtx));
1626   TopTools_ListIteratorOfListOfShape ItF;
1627   Standard_Integer nbarete;
1628   nbarete=ChFi3d_NbNotDegeneratedEdges(Vtx,myVEMap);
1629   ChFi3d_ChercheBordsLibres(myVEMap,Vtx,bordlibre,edgelibre1,edgelibre2);
1630   if (bordlibre) nbarete=(nbarete-2)/2 +2;
1631   else           nbarete=nbarete/2;
1632   // it is determined if there is an edge of sewing and it face
1633
1634   TopoDS_Face facecouture;
1635   TopoDS_Edge edgecouture;
1636
1637   Standard_Boolean trouve=Standard_False;
1638   for(ItF.Initialize(myVFMap(Vtx));ItF.More()&&!couture;ItF.Next()) {
1639     TopoDS_Face fcur = TopoDS::Face(ItF.Value());
1640     ChFi3d_CoutureOnVertex(fcur,Vtx,couture,edgecouture);
1641     if (couture)
1642       facecouture=fcur;
1643   }
1644   // it is determined if one of edges adjacent to the fillet is regular
1645   Standard_Boolean reg1,reg2;
1646   TopoDS_Edge Ecur,Eadj1,Eadj2;
1647   TopoDS_Face Fga,Fdr;
1648   TopoDS_Vertex Vbid1;
1649   Standard_Integer nbsurf,nbedge;
1650   reg1=Standard_False;
1651   reg2=Standard_False;
1652   nbsurf= SeqFil.Length();
1653   nbedge = spine->NbEdges();
1654   num = ChFi3d_IndexOfSurfData(Vtx,stripe,sens);
1655   isfirst = (sens == 1);
1656   ChFiDS_State state;
1657   if (isfirst) {
1658     EdgeSpine=spine->Edges(1);
1659     num1=num+1;
1660     state = spine->FirstStatus();
1661   }
1662   else {
1663     EdgeSpine=spine->Edges(nbedge);
1664     num1=num-1;
1665     state = spine->LastStatus();
1666   }
1667   if (nbsurf!=nbedge && nbsurf!=1) {
1668     ChFi3d_edge_common_faces(myEFMap(EdgeSpine),F1,F2);
1669     if (F1.IsSame(facecouture)) Eadj1=edgecouture;
1670     else ChFi3d_cherche_element(Vtx,EdgeSpine,F1,Eadj1,Vbid1);
1671     ChFi3d_edge_common_faces(myEFMap(Eadj1),Fga,Fdr);
1672 //  Modified by Sergey KHROMOV - Fri Dec 21 17:57:32 2001 Begin
1673 //  reg1=BRep_Tool::Continuity(Eadj1,Fga,Fdr)!=GeomAbs_C0;
1674     reg1=isTangentFaces(Eadj1,Fga,Fdr);
1675 //  Modified by Sergey KHROMOV - Fri Dec 21 17:57:33 2001 End
1676     if (F2.IsSame(facecouture)) Eadj2=edgecouture;
1677     else ChFi3d_cherche_element(Vtx,EdgeSpine,F2,Eadj2,Vbid1);
1678     ChFi3d_edge_common_faces(myEFMap(Eadj2),Fga,Fdr);
1679 //  Modified by Sergey KHROMOV - Fri Dec 21 17:58:22 2001 Begin
1680 //  reg2=BRep_Tool::Continuity(Eadj2,Fga,Fdr)!=GeomAbs_C0;
1681     reg2=isTangentFaces(Eadj2,Fga,Fdr);
1682 //  Modified by Sergey KHROMOV - Fri Dec 21 17:58:24 2001 End
1683
1684 // two faces common to the edge are found
1685     if (reg1 || reg2) {
1686       Standard_Boolean compoint1=Standard_False;
1687       Standard_Boolean compoint2=Standard_False;
1688       ChFiDS_CommonPoint cp1, cp2;
1689       cp1 = SeqFil(num1)->ChangeVertex (isfirst,1);
1690       cp2 = SeqFil(num1)->ChangeVertex (isfirst,2);
1691       if (cp1.IsOnArc()) {
1692         if (cp1.Arc().IsSame(Eadj1)||cp1.Arc().IsSame(Eadj2))
1693           compoint1=Standard_True;
1694       }
1695       if (cp2.IsOnArc()) {
1696         if (cp2.Arc().IsSame(Eadj1)||cp2.Arc().IsSame(Eadj2))
1697           compoint2=Standard_True;
1698       }
1699       if (compoint1 && compoint2) {
1700         SeqFil.Remove(num);
1701         reg1=Standard_False; reg2=Standard_False;
1702       }
1703     }
1704   }
1705 // there is only one face at end if FindFace is true and if the face
1706 // is not the face with sewing edge
1707   TopoDS_Face face;
1708   Handle(ChFiDS_SurfData) Fd = SeqFil.ChangeValue(num);
1709   ChFiDS_CommonPoint& CV1 = Fd->ChangeVertex(isfirst,1);
1710   ChFiDS_CommonPoint& CV2 = Fd->ChangeVertex(isfirst,2);
1711   Standard_Boolean onecorner=Standard_False;
1712   if (FindFace(Vtx,CV1,CV2,face)) {
1713       if (!couture) onecorner =Standard_True;
1714       else if (!face.IsSame(facecouture))
1715             onecorner=Standard_True;
1716     }
1717   if (onecorner) {
1718     if (ChFi3d_Builder::MoreSurfdata(Index)) {
1719       ChFi3d_Builder::PerformMoreSurfdata(Index);
1720       return;
1721     }
1722   }
1723   if (!onecorner && (reg1||reg2) && !couture && state!=ChFiDS_OnSame) {
1724     PerformMoreThreeCorner (Index,1);
1725     return;
1726   }
1727   Handle(GeomAdaptor_HSurface) HGs = ChFi3d_BoundSurf(DStr,Fd,1,2);
1728   ChFiDS_FaceInterference Fi1 = Fd->InterferenceOnS1();
1729   ChFiDS_FaceInterference Fi2 = Fd->InterferenceOnS2();
1730   GeomAdaptor_Surface& Gs = HGs->ChangeSurface();
1731   Handle(BRepAdaptor_HSurface) HBs  = new BRepAdaptor_HSurface();
1732   BRepAdaptor_Surface& Bs  = HBs->ChangeSurface();
1733   Handle(Geom_Curve) Cc;
1734   Handle(Geom2d_Curve) Pc,Ps;
1735   Standard_Real Ubid,Vbid;
1736   TopAbs_Orientation orsurfdata;
1737   orsurfdata=Fd->Orientation();
1738   Standard_Integer IsurfPrev=0, Isurf=Fd->Surf();
1739   Handle(ChFiDS_SurfData) SDprev;
1740   if (num1>0 && num1<=SeqFil.Length()) {
1741     SDprev = SeqFil(num1);
1742     IsurfPrev = SDprev->Surf();
1743   }
1744   // calculate the orientation of curves at end
1745
1746   Standard_Real tolpt=1.e-4;
1747   Standard_Real tolreached;
1748   TopAbs_Orientation orcourbe,orface,orien;
1749
1750   stripe->SetIndexPoint(ChFi3d_IndexPointInDS(CV1,DStr),isfirst,1);
1751   stripe->SetIndexPoint(ChFi3d_IndexPointInDS(CV2,DStr),isfirst,2);
1752
1753 //  gp_Pnt p3d;
1754 //  gp_Pnt2d p2d;
1755   Standard_Real dist;
1756   Standard_Integer Ishape1=Fd->IndexOfS1();
1757 #ifndef DEB
1758   TopAbs_Orientation trafil1 = TopAbs_FORWARD;
1759 #else
1760   TopAbs_Orientation trafil1;
1761 #endif
1762   if (Ishape1 != 0) {
1763     if (Ishape1 > 0) {
1764       trafil1 = DStr.Shape(Ishape1).Orientation();
1765     }
1766 #ifdef DEB
1767     else {
1768       cout<<"erreur"<<endl;
1769     }
1770 #endif
1771     trafil1 = TopAbs::Compose(trafil1,Fd->Orientation());
1772
1773     trafil1 = TopAbs::Compose(TopAbs::Reverse(Fi1.Transition()),trafil1);
1774   }
1775 #ifdef DEB
1776   else cout<<"erreur"<<endl;
1777 #endif
1778   // eap, Apr 22 2002, occ 293
1779 //   Fi1.PCurveOnFace()->D0(Fi1.LastParameter(),p2d);
1780 //   const Handle(Geom_Surface) Stemp =
1781 //     BRep_Tool::Surface(TopoDS::Face(DStr.Shape(Ishape1)));
1782 //   Stemp ->D0(p2d.X(),p2d.Y(),p3d);
1783 //   dist=p3d.Distance(CV1.Point());
1784 //   if (dist<tolpt) orcourbe=trafil1;
1785 //   else            orcourbe=TopAbs::Reverse(trafil1);
1786   if (!isfirst) orcourbe=trafil1;
1787   else          orcourbe=TopAbs::Reverse(trafil1);
1788
1789   // eap, Apr 22 2002, occ 293
1790   // variables to show OnSame situation
1791   Standard_Boolean isOnSame1, isOnSame2;
1792   // In OnSame situation, the case of degenerated FaceInterference curve
1793   // is probable when a corner cuts the ChFi3d earlier built on OnSame edge.
1794   // In such a case, chamfer face can partially shrink to a line and we need
1795   // to cut off that shrinked part
1796   // If <isOnSame1>, FaceInterference with F2 can be degenerated
1797   Standard_Boolean checkShrink, isShrink, isUShrink;
1798   isShrink = isUShrink = isOnSame1 = isOnSame2 = Standard_False;
1799   Standard_Real checkShrParam=0., prevSDParam=0.;
1800   gp_Pnt2d midP2d;
1801   Standard_Integer midIpoint=0;
1802
1803   // find Fi1,Fi2 lengths used to extend ChFi surface
1804   // and by the way define necessity to check shrink
1805   gp_Pnt2d P2d1=Fi1.PCurveOnSurf()->Value(Fi1.Parameter(isfirst));
1806   gp_Pnt2d P2d2=Fi1.PCurveOnSurf()->Value(Fi1.Parameter(!isfirst));
1807   gp_Pnt aP1,aP2;
1808   HGs->D0( P2d1.X(),P2d1.Y(),aP1);
1809   HGs->D0( P2d2.X(),P2d2.Y(),aP2);
1810   Standard_Real Fi1Length=aP1.Distance(aP2);
1811 //  Standard_Real eps = Precision::Confusion();
1812   checkShrink = (Fi1Length <= Precision::Confusion());
1813   
1814   gp_Pnt2d P2d3=Fi2.PCurveOnSurf()->Value(Fi2.Parameter(isfirst));
1815   gp_Pnt2d P2d4=Fi2.PCurveOnSurf()->Value(Fi2.Parameter(!isfirst));
1816   HGs->D0( P2d3.X(),P2d3.Y(),aP1);
1817   HGs->D0( P2d4.X(),P2d4.Y(),aP2);
1818   Standard_Real Fi2Length=aP1.Distance(aP2);
1819   checkShrink = checkShrink || (Fi2Length <= Precision::Confusion());
1820
1821   if (checkShrink) {
1822     if (Abs(P2d2.Y()-P2d4.Y()) <= Precision::PConfusion()) {
1823       isUShrink = Standard_False;
1824       checkShrParam = P2d2.Y();
1825     } else if (Abs(P2d2.X()-P2d4.X()) <= Precision::PConfusion()) {
1826       isUShrink = Standard_True;
1827       checkShrParam = P2d2.X();
1828     }
1829     else
1830       checkShrink = Standard_False;
1831   }
1832
1833   /***********************************************************************/
1834   //  find faces intersecting with the fillet and edges limiting intersections
1835   //  nbface is the nb of faces intersected, Face[i] contais the faces
1836   // to intersect (i=0.. nbface-1). Edge[i] contains edges limiting
1837   // the intersections (i=0 ..nbface)
1838   /**********************************************************************/
1839
1840   Standard_Integer nb = 1,nbface;
1841   TopoDS_Edge E1 ,E2, Edge[nn],E,Ei,edgesau;
1842   TopoDS_Face  facesau;
1843   Standard_Boolean oneintersection1=Standard_False;
1844   Standard_Boolean oneintersection2=Standard_False;
1845   TopoDS_Face Face[nn],F,F3;
1846   TopoDS_Vertex V1,V2,V,Vfin;
1847   Standard_Boolean  findonf1=Standard_False,findonf2=Standard_False;
1848   TopTools_ListIteratorOfListOfShape It3;
1849   F1=TopoDS::Face(DStr.Shape(Fd->IndexOfS1()));
1850   F2=TopoDS::Face(DStr.Shape(Fd->IndexOfS2()));
1851   F3=F1;
1852   if (couture || bordlibre) nface=nface+1;
1853   if (nface==3) nbface=2;
1854   else nbface=nface-2;
1855   if (!CV1.IsOnArc()||!CV2.IsOnArc()) {
1856     PerformMoreThreeCorner(Index,1);
1857     return;
1858   }
1859
1860   Edge[0]=CV1.Arc();
1861   Edge[nbface]=CV2.Arc();
1862   tabedg.SetValue(0,Edge[0]);
1863   tabedg.SetValue(nbface,Edge[nbface]);
1864   // processing of a fillet arriving on a vertex
1865   // edge contained in CV.Arc is not inevitably good
1866   // the edge concerned by the intersection is found
1867
1868   Standard_Real dist1,dist2;
1869   if (CV1.IsVertex()) {
1870     trouve=Standard_False;
1871     /*TopoDS_Vertex */V=CV1.Vertex();
1872     for (It3.Initialize(myVEMap(V));It3.More()&&!trouve;It3.Next()) {
1873       E=TopoDS::Edge (It3.Value());
1874       if (!E.IsSame(Edge[0])&&(containE(F1,E)))
1875         trouve=Standard_True;
1876     }
1877     TopoDS_Vertex Vt,V3,V4;
1878     V1=TopExp::FirstVertex(Edge[0]);
1879     V2=TopExp::LastVertex(Edge[0]);
1880     if (V.IsSame(V1)) Vt=V2;
1881     else Vt=V1;
1882     dist1=(BRep_Tool::Pnt(Vt)).Distance(BRep_Tool::Pnt(Vtx));
1883     V3=TopExp::FirstVertex(E);
1884     V4=TopExp::LastVertex(E);
1885     if (V.IsSame(V3)) Vt=V4;
1886     else Vt=V3;
1887     dist2=(BRep_Tool::Pnt(Vt)).Distance(BRep_Tool::Pnt(Vtx));
1888     if (dist2<dist1) {
1889       Edge[0]=E;
1890       TopAbs_Orientation ori;
1891       if (V2.IsSame(V3)||V1.IsSame(V4)) ori=CV1.TransitionOnArc();
1892       else ori=TopAbs::Reverse(CV1.TransitionOnArc());
1893       Standard_Real par= BRep_Tool::Parameter(V,Edge[0]);
1894       Standard_Real tol= CV1.Tolerance();
1895       CV1.SetArc(tol,Edge[0],par,ori);
1896     }
1897   }
1898
1899   if (CV2.IsVertex()) {
1900     trouve=Standard_False;
1901     /*TopoDS_Vertex*/ V=CV2.Vertex();
1902     for (It3.Initialize(myVEMap(V));It3.More()&&!trouve;It3.Next()) {
1903       E=TopoDS::Edge (It3.Value());
1904       if (!E.IsSame(Edge[2])&&(containE(F2,E)))
1905         trouve=Standard_True;
1906     }
1907     TopoDS_Vertex Vt,V3,V4;
1908     V1=TopExp::FirstVertex(Edge[2]);
1909     V2=TopExp::LastVertex(Edge[2]);
1910     if (V.IsSame(V1)) Vt=V2;
1911     else Vt=V1;
1912     dist1=(BRep_Tool::Pnt(Vt)).Distance(BRep_Tool::Pnt(Vtx));
1913     V3=TopExp::FirstVertex(E);
1914     V4=TopExp::LastVertex(E);
1915     if (V.IsSame(V3)) Vt=V4;
1916     else Vt=V3;
1917     dist2=(BRep_Tool::Pnt(Vt)).Distance(BRep_Tool::Pnt(Vtx));
1918     if (dist2<dist1) {
1919       Edge[2]=E;
1920       TopAbs_Orientation ori;
1921       if (V2.IsSame(V3)||V1.IsSame(V4)) ori=CV2.TransitionOnArc();
1922       else ori=TopAbs::Reverse(CV2.TransitionOnArc());
1923       Standard_Real par= BRep_Tool::Parameter(V,Edge[2]);
1924       Standard_Real tol= CV2.Tolerance();
1925       CV2.SetArc(tol,Edge[2],par,ori);
1926     }
1927   }
1928   if (!onecorner) {
1929     // If there is a regular edge, the faces adjacent to it 
1930     // are not in Fd->IndexOfS1 or Fd->IndexOfS2
1931
1932 //     TopoDS_Face Find1 ,Find2;
1933 //     if (isfirst)
1934 //       edge=stripe->Spine()->Edges(1);
1935 //     else  edge=stripe->Spine()->Edges(stripe->Spine()->NbEdges());
1936 //     It3.Initialize(myEFMap(edge));
1937 //     Find1=TopoDS::Face(It3.Value());
1938 //     trouve=Standard_False;
1939 //     for (It3.Initialize(myEFMap(edge));It3.More()&&!trouve;It3.Next()) {
1940 //       F=TopoDS::Face (It3.Value());
1941 //       if (!F.IsSame(Find1)) {
1942 //      Find2=F;trouve=Standard_True;
1943 //       }
1944 //     }
1945
1946     // if nface =3 there is a top with 3 edges and a fillet 
1947     // and their common points are on different faces 
1948     // otherwise there is a case when a top has more than 3 edges
1949
1950     if (nface==3) {
1951       if (CV1.IsVertex ()) findonf1=Standard_True;
1952       if (CV2.IsVertex ()) findonf2=Standard_True;
1953       if (!findonf1) {
1954         TopTools_IndexedMapOfShape  MapV;
1955         TopExp::MapShapes(Edge[0], TopAbs_VERTEX, MapV);
1956         if (MapV.Extent()==2)
1957           if (!MapV(1).IsSame(Vtx) && !MapV(2).IsSame(Vtx))
1958             findonf1=Standard_True;
1959       }
1960       if (!findonf2) {
1961         TopTools_IndexedMapOfShape  MapV;
1962         TopExp::MapShapes(Edge[2], TopAbs_VERTEX, MapV);
1963         if (MapV.Extent()==2)
1964           if (!MapV(1).IsSame(Vtx) && !MapV(2).IsSame(Vtx))
1965             findonf2=Standard_True;
1966       }
1967
1968       // detect and process OnSame situatuation
1969       if (state == ChFiDS_OnSame) {
1970         TopoDS_Edge threeE[3];
1971         ChFi3d_cherche_element(Vtx,EdgeSpine, F1,threeE[0], V2);
1972         ChFi3d_cherche_element(Vtx,EdgeSpine, F2,threeE[1], V2);
1973         threeE[2] = EdgeSpine;
1974         if (ChFi3d_EdgeState(threeE,myEFMap) == ChFiDS_OnSame) {
1975           isOnSame1 = Standard_True;
1976           nb = 1;
1977           Edge[0] = threeE[0];
1978           ChFi3d_cherche_face1(myEFMap(Edge[0]),F1,Face[0]);
1979           if (findonf2)
1980             findonf1 = Standard_True; // not to look for Face[0] again
1981           else
1982             Edge[1]=CV2.Arc();
1983         }
1984         else {
1985           isOnSame2 = Standard_True;
1986         }
1987       }
1988
1989       // findonf1 findonf2 show if F1 and/or F2 are adjacent
1990       // to many faces at end
1991       // the faces at end and intersected edges are found
1992
1993       if (findonf1 && !isOnSame1) {
1994         if (CV1.TransitionOnArc()==TopAbs_FORWARD)
1995           V1=TopExp::FirstVertex(CV1.Arc());
1996         else
1997           V1=TopExp::LastVertex(CV1.Arc());
1998         ChFi3d_cherche_face1(myEFMap(CV1.Arc()),F1,Face[0]);
1999         nb=1;
2000         Ei=Edge[0];
2001         while (!V1.IsSame(Vtx)) {
2002           ChFi3d_cherche_element(V1,Ei,F1,E,V2);
2003           V1=V2; Ei=E;
2004           ChFi3d_cherche_face1(myEFMap(E),F1,Face[nb]);
2005           cherche_edge1(Face[nb-1],Face[nb],Edge[nb]);
2006           nb++;
2007           if (nb>=nn) Standard_Failure::Raise
2008             ("IntersectionAtEnd : the max number of faces reached");
2009         }
2010         if (!findonf2)  Edge[nb]=CV2.Arc();
2011       }
2012       if (findonf2  && !isOnSame2) {
2013         if (!findonf1 )  nb=1;
2014         V1=Vtx;
2015         if (CV2.TransitionOnArc()==TopAbs_FORWARD)
2016           Vfin=TopExp::LastVertex(CV2.Arc());
2017         else
2018           Vfin=TopExp::FirstVertex(CV2.Arc());
2019         if (!findonf1) ChFi3d_cherche_face1(myEFMap(CV1.Arc()),F1,Face[nb-1]);
2020         ChFi3d_cherche_element(V1,EdgeSpine,F2,E,V2);
2021         Ei=E;V1=V2;
2022         while (!V1.IsSame(Vfin)) {
2023           ChFi3d_cherche_element(V1,Ei,F2,E,V2);
2024           Ei=E;
2025           V1=V2;
2026           ChFi3d_cherche_face1(myEFMap(E),F2,Face[nb]);
2027           cherche_edge1(Face[nb-1],Face[nb],Edge[nb]);
2028           nb++;
2029           if (nb>=nn) Standard_Failure::Raise
2030             ("IntersectionAtEnd : the max number of faces reached");
2031         }
2032         Edge[nb]=CV2.Arc();
2033       }
2034       if (isOnSame2) {
2035         cherche_edge1(Face[nb-1],F2,Edge[nb]);
2036         Face[nb] = F2;
2037       }
2038
2039       nbface=nb;
2040     }
2041
2042     else {
2043
2044 //  this is the case when a top has more than three edges
2045 //  the faces and edges concerned are found
2046       Standard_Boolean /*trouve,*/possible1, possible2;
2047       trouve = possible1 = possible2 = Standard_False;
2048       TopExp_Explorer ex;
2049       nb=0;
2050       for (ex.Init(CV1.Arc(),TopAbs_VERTEX);ex.More();ex.Next()) {
2051         if (Vtx.IsSame(ex.Current())) possible1 = Standard_True;
2052       }
2053       for (ex.Init(CV2.Arc(),TopAbs_VERTEX);ex.More();ex.Next()) {
2054         if (Vtx.IsSame(ex.Current())) possible2 = Standard_True;
2055       }
2056       if ((possible1 && possible2) || (!possible1 && !possible2) || (nbarete > 4)) {
2057         while (!trouve) {
2058           nb++;
2059           if (nb!=1) F3=Face[nb-2];
2060           Face[nb-1]=F3;
2061           if (CV1.Arc().IsSame(edgelibre1))
2062             cherche_face(myVFMap(Vtx),edgelibre2,F1,F2,F3,Face[nb-1]);
2063           else if (CV1.Arc().IsSame(edgelibre2))
2064             cherche_face(myVFMap(Vtx),edgelibre1,F1,F2,F3,Face[nb-1]);
2065           else cherche_face(myVFMap(Vtx),Edge[nb-1],F1,F2,F3,Face[nb-1]);
2066           ChFi3d_cherche_edge(Vtx,tabedg,Face[nb-1],Edge[nb],V);
2067           tabedg.SetValue(nb,Edge[nb]);
2068           if (Edge[nb].IsSame(CV2.Arc())) trouve=Standard_True;
2069         }
2070         nbface=nb;
2071       }
2072       else {
2073         IntersectMoreCorner (Index);
2074         return;
2075       }
2076       if (nbarete==4) {
2077         // if two consecutive edges are G1 there is only one face of intersection
2078         Standard_Real ang1=0.0;
2079         TopoDS_Vertex Vcom;
2080         trouve=Standard_False;
2081         ChFi3d_cherche_vertex ( Edge[0],Edge[1],Vcom,trouve);
2082         if (Vcom.IsSame(Vtx)) ang1=ChFi3d_AngleEdge(Vtx,Edge[0],Edge[1]);
2083         if (Abs(ang1-M_PI)<0.01) {
2084           oneintersection1=Standard_True;
2085           facesau=Face[0];
2086           edgesau=Edge[1];
2087           Face[0]=Face[1];
2088           Edge[1]=Edge[2];
2089           nbface=1;
2090         }
2091
2092         if (!oneintersection1) {
2093           trouve=Standard_False;
2094           ChFi3d_cherche_vertex ( Edge[1],Edge[2],Vcom,trouve);
2095           if (Vcom.IsSame(Vtx)) ang1=ChFi3d_AngleEdge(Vtx,Edge[1],Edge[2]);
2096           if (Abs(ang1-M_PI)<0.01) {
2097             oneintersection2=Standard_True;
2098             facesau=Face[1];
2099             edgesau=Edge[1];
2100             Edge[1]=Edge[2];
2101             nbface=1;
2102           }
2103         }
2104       }
2105       else if (nbarete==5) {
2106         //pro15368
2107 //  Modified by Sergey KHROMOV - Fri Dec 21 18:07:43 2001 End
2108         Standard_Boolean isTangent0 = isTangentFaces(Edge[0],F1,Face[0]);
2109         Standard_Boolean isTangent1 = isTangentFaces(Edge[1],Face[0],Face[1]);
2110         Standard_Boolean isTangent2 = isTangentFaces(Edge[2],Face[1],Face[2]);
2111         if ((isTangent0 || isTangent2) && isTangent1) {
2112 //         GeomAbs_Shape cont0,cont1,cont2;
2113 //         cont0=BRep_Tool::Continuity(Edge[0],F1,Face[0]);
2114 //         cont1=BRep_Tool::Continuity(Edge[1],Face[0],Face[1]);
2115 //         cont2=BRep_Tool::Continuity(Edge[2],Face[1],Face[2]);
2116 //         if ((cont0!=GeomAbs_C0 || cont2!=GeomAbs_C0) && cont1!=GeomAbs_C0) {
2117 //  Modified by Sergey KHROMOV - Fri Dec 21 18:07:49 2001 Begin
2118           facesau=Face[0];
2119           edgesau=Edge[0];
2120           nbface=1;
2121           Edge[1]=Edge[3];
2122           Face[0]=Face[2];
2123           oneintersection1=Standard_True;
2124         }
2125       }
2126     }
2127   }
2128   else {
2129     nbface=1;
2130     Face[0]=face;
2131     Edge[1]=Edge[2];
2132   }
2133
2134   TColStd_Array1OfReal Pardeb(1,4),Parfin(1,4);
2135   gp_Pnt2d pfil1,pfac1,pfil2,pfac2,pint,pfildeb;
2136   Handle(Geom2d_Curve) Hc1,Hc2;
2137   IntCurveSurface_HInter inters;
2138   Standard_Integer proledge[nn],prolface[nn+1];// last prolface[nn] is for Fd
2139   Standard_Integer shrink[nn];
2140   TopoDS_Face faceprol[nn];
2141   Standard_Integer indcurve[nn],indpoint2=0,indpoint1 = 0;
2142   Handle (TopOpeBRepDS_CurvePointInterference) Interfp1, Interfp2, Interfedge[nn];
2143   Handle (TopOpeBRepDS_SurfaceCurveInterference) Interfc,InterfPC[nn],InterfPS[nn];
2144   Standard_Real u2,v2,p1,p2,paredge1;
2145   Standard_Real  paredge2 = 0.,tolex = 1.e-4;
2146   Standard_Boolean extend=Standard_False;
2147   Handle(Geom_Surface) Sfacemoins1,Sface;
2148   /***************************************************************************/
2149   // calculate intersection of the fillet and each face
2150   // and storage in the DS
2151   /***************************************************************************/
2152   for (nb=1;nb<=nbface;nb++) {
2153     prolface[nb-1]=0;
2154     proledge[nb-1]=0;
2155     shrink  [nb-1]=0;
2156   }
2157   proledge[nbface]=0;
2158   prolface[nn]=0;
2159   if (oneintersection1||oneintersection2) faceprol[1]=facesau;
2160   if (!isOnSame1 && !isOnSame2)
2161     checkShrink = Standard_False;
2162   // in OnSame situation we need intersect Fd with Edge[0] or Edge[nbface] as well
2163   if (isOnSame1) nb=0;
2164   else           nb=1;
2165   Standard_Boolean intersOnSameFailed = Standard_False;
2166   
2167   for ( ; nb<=nbface; nb++) {
2168     extend=Standard_False;
2169     E2=Edge[nb];
2170     if (!nb)
2171       F=F1;
2172     else {
2173       F=Face[nb-1];
2174       if (!prolface[nb-1]) faceprol[nb-1]=F;
2175     }
2176     Sfacemoins1=BRep_Tool::Surface(F);
2177     Handle(Geom_Curve) cint;
2178     Handle(Geom2d_Curve) C2dint1, C2dint2,cface,cfacemoins1;
2179
2180     ///////////////////////////////////////////////////////
2181     // determine intersections of edges and the fillet
2182     // to find limitations of intersections face - fillet
2183     ///////////////////////////////////////////////////////
2184
2185     if (nb==1) {
2186       Hc1 = BRep_Tool::CurveOnSurface(Edge[0],Face[0],Ubid,Ubid);
2187       if (isOnSame1) {
2188         // update interference param on Fi1 and point of CV1
2189         if (prolface[0]) Bs.Initialize(faceprol[0], Standard_False);
2190         else             Bs.Initialize(Face[0], Standard_False);
2191         const Handle(Geom_Curve)& c3df = DStr.Curve(Fi1.LineIndex()).Curve();
2192         Standard_Real Ufi= Fi2.Parameter(isfirst);
2193         ChFiDS_FaceInterference& Fi = Fd->ChangeInterferenceOnS1();
2194         if (!IntersUpdateOnSame (HGs,HBs,c3df,F1,Face[0],Edge[0],Vtx,isfirst,10*tolesp, // in
2195                                  Fi,CV1,pfac1,Ufi))   // out
2196           Standard_Failure::Raise("IntersectionAtEnd: pb intersection Face - Fi");
2197         Fi1 = Fi;
2198         if (intersOnSameFailed) { // probable at fillet building
2199           // look for paredge2
2200           Geom2dAPI_ProjectPointOnCurve proj;
2201           if (C2dint2.IsNull()) proj.Init(pfac1,Hc1);
2202           else                  proj.Init(pfac1,C2dint2);
2203           paredge2 = proj.LowerDistanceParameter();
2204         }
2205         // update stripe point
2206         TopOpeBRepDS_Point tpoint (CV1.Point(),tolesp);
2207         indpoint1=DStr.AddPoint(tpoint);
2208         stripe->SetIndexPoint(indpoint1,isfirst,1);
2209         // reset arc of CV1
2210         TopoDS_Vertex vert1,vert2;
2211         TopExp::Vertices(Edge[0],vert1,vert2);
2212         TopAbs_Orientation arcOri = Vtx.IsSame(vert1) ? TopAbs_FORWARD : TopAbs_REVERSED;
2213         CV1.SetArc(tolesp,Edge[0],paredge2,arcOri);
2214       }
2215       else {
2216         if (Hc1.IsNull()) {
2217           // curve 2d not found. Sfacemoins1 is extended and projection is done there
2218           // CV1.Point ()
2219           ChFi3d_ExtendSurface(Sfacemoins1,prolface[0]);
2220           if (prolface[0]) {
2221             extend=Standard_True;
2222             BRep_Builder BRE;
2223             Standard_Real tol=BRep_Tool::Tolerance(F);
2224             BRE.MakeFace(faceprol[0],Sfacemoins1,F.Location(),tol);
2225             if (!isOnSame1) {
2226               GeomAdaptor_Surface Asurf;
2227               Asurf.Load(Sfacemoins1);
2228               Extrema_ExtPS ext (CV1.Point(),Asurf, tol,tol);
2229               Standard_Real  uc1,vc1;
2230               if (ext.IsDone()) {
2231                 ext.Point(1).Parameter(uc1,vc1);
2232                 pfac1.SetX(uc1);
2233                 pfac1.SetY(vc1);
2234               }
2235             }
2236           }
2237         }
2238         else
2239           pfac1 = Hc1->Value(CV1.ParameterOnArc());
2240       }
2241       paredge1=CV1.ParameterOnArc();
2242       if (Fi1.LineIndex() != 0) {
2243         pfil1 = Fi1.PCurveOnSurf()->Value(Fi1.Parameter(isfirst));}
2244       else {
2245         pfil1 = Fi1.PCurveOnSurf()->Value(Fi1.Parameter(!isfirst));}
2246       pfildeb=pfil1;
2247     }
2248     else {
2249       pfil1=pfil2;
2250       paredge1=paredge2;
2251       pfac1=pint;
2252     }
2253
2254     if (nb!=nbface || isOnSame2) {
2255       Standard_Integer nbp;
2256
2257       Handle(Geom_Curve) C;
2258       C=BRep_Tool::Curve(E2,Ubid,Vbid);
2259       Handle(Geom_TrimmedCurve) Ctrim = new Geom_TrimmedCurve(C,Ubid,Vbid);
2260       Standard_Real Utrim,Vtrim;
2261       Utrim=Ctrim->BasisCurve()->FirstParameter();
2262       Vtrim=Ctrim->BasisCurve()->LastParameter();
2263       if (Ctrim->IsPeriodic()) {
2264         if (Ubid>Ctrim->Period()) {
2265           Ubid=(Utrim+Vtrim)/2;
2266           Vbid= Vtrim;
2267         }
2268         else {
2269           Ubid=Utrim;
2270           Vbid=(Utrim+Vtrim)/2;
2271         }
2272       }
2273       else {
2274         Ubid=Utrim;
2275         Vbid=Vtrim;
2276       }
2277       Handle(GeomAdaptor_HCurve) HC =
2278         new GeomAdaptor_HCurve(C,Ubid,Vbid);
2279       GeomAdaptor_Curve & Cad =HC->ChangeCurve();
2280       inters.Perform(HC, HGs);
2281       if ( !prolface[nn] && ( !inters.IsDone() || (inters.NbPoints()==0) )) {
2282         // extend surface of conge
2283         Handle(Geom_BSplineSurface) S1=
2284           Handle(Geom_BSplineSurface)::DownCast(DStr.Surface(Fd->Surf()).Surface());
2285         if (!S1.IsNull()) {
2286           Standard_Real length = 0.5 * Max(Fi1Length,Fi2Length);
2287           GeomLib::ExtendSurfByLength(S1,length,1,Standard_False,!isfirst);
2288           prolface[nn] = 1;
2289           if (!stripe->IsInDS(!isfirst)) {
2290             Gs.Load(S1);
2291             inters.Perform(HC, HGs);
2292             if (inters.IsDone()&& inters.NbPoints()!=0) {
2293               Fd->ChangeSurf(DStr.AddSurface(TopOpeBRepDS_Surface(S1, DStr.ChangeSurface(Isurf).Tolerance())));
2294               Isurf=Fd->Surf();
2295             }
2296           }
2297         }
2298       }
2299       if (!inters.IsDone() || (inters.NbPoints()==0)) {
2300         Handle(Geom_BSplineCurve) cd=Handle(Geom_BSplineCurve)::DownCast(C);
2301         Handle(Geom_BezierCurve) cd1=Handle(Geom_BezierCurve)::DownCast(C);
2302         if (!cd.IsNull() || !cd1.IsNull() ) {
2303           BRep_Builder BRE;
2304           Sface=BRep_Tool::Surface(Face[nb]);
2305           ChFi3d_ExtendSurface(Sface,prolface[nb]);
2306           Standard_Real tol=BRep_Tool::Tolerance(F);
2307           BRE.MakeFace(faceprol[nb],Sface,Face[nb].Location(),tol);
2308           if (nb && !prolface[nb-1]) {
2309             ChFi3d_ExtendSurface(Sfacemoins1,prolface[nb-1]);
2310             if (prolface[nb-1]) {
2311               tol=BRep_Tool::Tolerance(F);
2312               BRE.MakeFace(faceprol[nb-1],Sfacemoins1,F.Location(),tol);
2313             }
2314           }
2315           else {
2316             Standard_Integer prol = 0;
2317             ChFi3d_ExtendSurface(Sfacemoins1,prol);
2318           }
2319           GeomInt_IntSS InterSS(Sfacemoins1,Sface,1.e-7,1,1,1);
2320           if (InterSS.IsDone()) {
2321             trouve=Standard_False;
2322             for (Standard_Integer i=1; i<=InterSS.NbLines() && !trouve; i++) {
2323               extend=Standard_True;
2324               cint= InterSS.Line(i);
2325               C2dint1= InterSS.LineOnS1(i);
2326               C2dint2= InterSS.LineOnS2(i);
2327               Cad.Load(cint);
2328               inters.Perform(HC, HGs);
2329               trouve=inters.IsDone()&&inters.NbPoints()!=0;
2330               // eap occ293, eval tolex on finally trimmed curves
2331 //               Handle(GeomAdaptor_HSurface) H1=new GeomAdaptor_HSurface(Sfacemoins1);
2332 //               Handle(GeomAdaptor_HSurface) H2=new GeomAdaptor_HSurface(Sface);
2333 //              tolex=ChFi3d_EvalTolReached(H1,C2dint1,H2,C2dint2,cint);
2334               tolex = InterSS.TolReached3d();
2335             }
2336           }
2337         }
2338       }
2339       if (inters.IsDone()) {
2340         nbp = inters.NbPoints();
2341         if (nbp==0) {
2342           if (nb==0 || nb==nbface) 
2343             intersOnSameFailed = Standard_True;
2344           else {
2345             PerformMoreThreeCorner (Index,1);
2346             return;
2347           }
2348         }
2349         else {
2350           gp_Pnt P=BRep_Tool::Pnt(Vtx);
2351           Standard_Real distmin=P.Distance(inters.Point(1).Pnt());
2352           nbp=1;
2353           for (Standard_Integer i=2;i<=inters.NbPoints();i++) {
2354             dist=P.Distance(inters.Point(i).Pnt());
2355             if (dist<distmin) {
2356               distmin=dist;
2357               nbp=i;
2358             }
2359           }
2360           gp_Pnt2d pt2d (inters.Point(nbp).U(),inters.Point(nbp).V());
2361           pfil2=pt2d;
2362           paredge2=inters.Point(nbp).W();
2363           if (!extend) {
2364             cfacemoins1=BRep_Tool::CurveOnSurface(E2,F,u2,v2);
2365             cface=BRep_Tool::CurveOnSurface(E2,Face[nb],u2,v2);
2366             cfacemoins1->D0(paredge2,pfac2);
2367             cface->D0(paredge2,pint);
2368           }
2369           else {
2370             C2dint1->D0(paredge2,pfac2);
2371             C2dint2->D0(paredge2,pint);
2372           }
2373         }
2374       }
2375       else Standard_Failure::Raise("IntersectionAtEnd: pb intersection Face cb");
2376     }
2377     else {
2378       Hc2 = BRep_Tool::CurveOnSurface(E2,Face[nbface-1],Ubid,Ubid);
2379       if (Hc2.IsNull()) {
2380         // curve 2d is not found,  Sfacemoins1 is extended CV2.Point() is projected there
2381
2382         ChFi3d_ExtendSurface(Sfacemoins1,prolface[0]);
2383         if (prolface[0]) {
2384           BRep_Builder BRE;
2385           extend=Standard_True;
2386           Standard_Real tol=BRep_Tool::Tolerance(F);
2387           BRE.MakeFace(faceprol[nb-1],Sfacemoins1,F.Location(),tol);
2388           GeomAdaptor_Surface Asurf;
2389           Asurf.Load(Sfacemoins1);
2390           Extrema_ExtPS ext (CV2.Point(),Asurf,tol,tol);
2391           Standard_Real  uc2,vc2;
2392           if (ext.IsDone()) {
2393             ext.Point(1).Parameter(uc2,vc2);
2394             pfac2.SetX(uc2);
2395             pfac2.SetY(vc2);
2396           }
2397         }
2398       }
2399       else pfac2 = Hc2->Value(CV2.ParameterOnArc());
2400       paredge2=CV2.ParameterOnArc();
2401       if (Fi2.LineIndex() != 0) {
2402         pfil2 = Fi2.PCurveOnSurf()->Value(Fi2.Parameter(isfirst));
2403       }
2404       else {
2405         pfil2 = Fi2.PCurveOnSurf()->Value(Fi2.Parameter(!isfirst));
2406       }
2407     }
2408     if (!nb) continue; // found paredge1 on Edge[0] in OnSame situation on F1
2409
2410     if (nb==nbface && isOnSame2) {
2411       // update interference param on Fi2 and point of CV2
2412       if (prolface[nb-1]) Bs.Initialize(faceprol[nb-1]);
2413       else                Bs.Initialize(Face[nb-1]);
2414       const Handle(Geom_Curve)& c3df = DStr.Curve(Fi2.LineIndex()).Curve();
2415       Standard_Real Ufi= Fi1.Parameter(isfirst);
2416       ChFiDS_FaceInterference& Fi = Fd->ChangeInterferenceOnS2();
2417       if (!IntersUpdateOnSame (HGs,HBs,c3df,F2,F,Edge[nb],Vtx,isfirst,10*tolesp, // in
2418                                Fi,CV2,pfac2,Ufi))   // out
2419         Standard_Failure::Raise("IntersectionAtEnd: pb intersection Face - Fi");
2420       Fi2 = Fi;
2421       if (intersOnSameFailed) { // probable at fillet building
2422         // look for paredge2
2423         Geom2dAPI_ProjectPointOnCurve proj;
2424         if (extend)
2425           proj.Init(pfac2, C2dint2);
2426         else 
2427           proj.Init(pfac2, BRep_Tool::CurveOnSurface (E2,Face[nbface-1],Ubid,Ubid));
2428         paredge2 = proj.LowerDistanceParameter();
2429       }
2430       // update stripe point
2431       TopOpeBRepDS_Point tpoint (CV2.Point(),tolesp);
2432       indpoint2=DStr.AddPoint(tpoint);
2433       stripe->SetIndexPoint(indpoint2,isfirst,2);
2434       // reset arc of CV2
2435       TopoDS_Vertex vert1,vert2;
2436       TopExp::Vertices(Edge[nbface],vert1,vert2);
2437       TopAbs_Orientation arcOri = Vtx.IsSame(vert1) ? TopAbs_FORWARD : TopAbs_REVERSED;
2438       CV2.SetArc(tolesp,Edge[nbface],paredge2,arcOri);
2439     }
2440
2441
2442     if (prolface[nb-1]) Bs.Initialize(faceprol[nb-1]);
2443     else                Bs.Initialize(Face[nb-1]);
2444
2445     // offset of parameters if they are not in the same period
2446
2447     // commented by eap 30 May 2002 occ354
2448     // the following code may cause trimming a wrong part of periodic surface
2449     
2450 //     Standard_Real  deb,xx1,xx2;
2451 //     Standard_Boolean  moins2pi,moins2pi1,moins2pi2;
2452 //     if (DStr.Surface(Fd->Surf()).Surface()->IsUPeriodic()) {
2453 //       deb=pfildeb.X();
2454 //       xx1=pfil1.X();
2455 //       xx2=pfil2.X();
2456 //       moins2pi=Abs(deb)< Abs(Abs(deb)-2*M_PI);
2457 //       moins2pi1=Abs(xx1)< Abs(Abs(xx1)-2*M_PI);
2458 //       moins2pi2=Abs(xx2)< Abs(Abs(xx2)-2*M_PI);
2459 //       if (moins2pi1!=moins2pi2) {
2460 //         if  (moins2pi) {
2461 //           if (!moins2pi1) xx1=xx1-2*M_PI;
2462 //           if (!moins2pi2) xx2=xx2-2*M_PI;
2463 //         }
2464 //         else {
2465 //           if (moins2pi1) xx1=xx1+2*M_PI;
2466 //           if (moins2pi2) xx2=xx2+2*M_PI;
2467 //         }
2468 //       }
2469 //       pfil1.SetX(xx1);
2470 //       pfil2.SetX(xx2);
2471 //     }
2472 //     if (couture || Sfacemoins1->IsUPeriodic()) {
2473
2474 //       Standard_Real ufmin,ufmax,vfmin,vfmax;
2475 //       BRepTools::UVBounds(Face[nb-1],ufmin,ufmax,vfmin,vfmax);
2476 //       deb=ufmin;
2477 //       xx1=pfac1.X();
2478 //       xx2=pfac2.X();
2479 //       moins2pi=Abs(deb)< Abs(Abs(deb)-2*M_PI);
2480 //       moins2pi1=Abs(xx1)< Abs(Abs(xx1)-2*M_PI);
2481 //       moins2pi2=Abs(xx2)< Abs(Abs(xx2)-2*M_PI);
2482 //       if (moins2pi1!=moins2pi2) {
2483 //         if  (moins2pi) {
2484 //           if (!moins2pi1) xx1=xx1-2*M_PI;
2485 //           if (!moins2pi2) xx2=xx2-2*M_PI;
2486 //         }
2487 //         else {
2488 //           if (moins2pi1) xx1=xx1+2*M_PI;
2489 //           if (moins2pi2) xx2=xx2+2*M_PI;
2490 //         }
2491 //       }
2492 //       pfac1.SetX(xx1);
2493 //       pfac2.SetX(xx2);
2494 //     }
2495
2496     Pardeb(1)= pfil1.X();Pardeb(2) = pfil1.Y();
2497     Pardeb(3)= pfac1.X();Pardeb(4) = pfac1.Y();
2498     Parfin(1)= pfil2.X();Parfin(2) = pfil2.Y();
2499     Parfin(3)= pfac2.X();Parfin(4) = pfac2.Y();
2500
2501     Standard_Real uu1,uu2,vv1,vv2;
2502     ChFi3d_Boite(pfac1,pfac2,uu1,uu2,vv1,vv2);
2503     ChFi3d_BoundFac(Bs,uu1,uu2,vv1,vv2);
2504
2505
2506     //////////////////////////////////////////////////////////////////////
2507     // calculate intersections face - fillet
2508     //////////////////////////////////////////////////////////////////////
2509
2510     if (!ChFi3d_ComputeCurves(HGs,HBs,Pardeb,Parfin,Cc,
2511                               Ps,Pc,tolesp,tol2d,tolreached,nbface==1)) {
2512       PerformMoreThreeCorner (Index,1);
2513       return;
2514     }
2515     // storage of information in the data structure
2516
2517     // evaluate tolerances
2518     p1=Cc->FirstParameter();
2519     p2=Cc->LastParameter();
2520     Standard_Real to1,to2;
2521     gp_Pnt2d  p2d1,p2d2;
2522     gp_Pnt P1,P2,P3,P4,P5,P6,P7,P8;
2523     HGs->D0(Pardeb(1),Pardeb(2),P1);
2524     HGs->D0(Parfin(1),Parfin(2),P2);
2525     HBs->D0(Pardeb(3),Pardeb(4),P3);
2526     HBs->D0(Parfin(3),Parfin(4),P4);
2527     Pc->D0(p1,p2d1);
2528     Pc->D0(p2,p2d2);
2529     HBs->D0(p2d1.X(),p2d1.Y(),P7);
2530     HBs->D0(p2d2.X(),p2d2.Y(),P8);
2531     Ps->D0(p1,p2d1);
2532     Ps->D0(p2,p2d2);
2533     HGs->D0(p2d1.X(),p2d1.Y(),P5);
2534     HGs->D0(p2d2.X(),p2d2.Y(),P6);
2535     to1 = Max (P1.Distance(P5)+P3.Distance(P7), tolreached);
2536     to2 = Max (P2.Distance(P6)+P4.Distance(P8), tolreached);
2537
2538
2539     //////////////////////////////////////////////////////////////////////
2540     // storage in the DS of the intersection curve
2541     //////////////////////////////////////////////////////////////////////
2542
2543     Standard_Boolean Isvtx1=0;
2544     Standard_Boolean Isvtx2=0;
2545     Standard_Integer indice;
2546
2547     if (nb==1)
2548     {
2549       indpoint1 = stripe->IndexPoint(isfirst,1);
2550       if (!CV1.IsVertex()) {
2551         TopOpeBRepDS_Point& tpt= DStr.ChangePoint(indpoint1);
2552         tpt.Tolerance ( Max (tpt.Tolerance(), to1));
2553       }
2554       else  Isvtx1=1;
2555     }
2556     if (nb==nbface)
2557     {
2558       indpoint2 = stripe->IndexPoint(isfirst,2);
2559       if (!CV2.IsVertex()) {
2560         TopOpeBRepDS_Point& tpt= DStr.ChangePoint(indpoint2);
2561         tpt.Tolerance ( Max (tpt.Tolerance(), to2));
2562       }
2563       else Isvtx2=1;
2564     }
2565     else
2566     {
2567       gp_Pnt point =Cc->Value(Cc->LastParameter());
2568       TopOpeBRepDS_Point tpoint (point,to2);
2569       indpoint2=DStr.AddPoint(tpoint);
2570     }
2571     
2572     if (nb!=1)
2573     {
2574       TopOpeBRepDS_Point& tpt= DStr.ChangePoint(indpoint1);
2575       tpt.Tolerance ( Max (tpt.Tolerance(), to1));
2576     }
2577     TopOpeBRepDS_Curve tcurv3d( Cc,tolreached);
2578     indcurve[nb-1]= DStr.AddCurve(tcurv3d);
2579     Interfp1=ChFi3d_FilPointInDS(TopAbs_FORWARD,indcurve[nb-1],
2580                                  indpoint1,Cc->FirstParameter(),Isvtx1);
2581     Interfp2=ChFi3d_FilPointInDS(TopAbs_REVERSED,indcurve[nb-1],
2582                                  indpoint2,Cc->LastParameter(),Isvtx2);
2583
2584     DStr.ChangeCurveInterferences(indcurve[nb-1]).Append(Interfp1);
2585     DStr.ChangeCurveInterferences(indcurve[nb-1]).Append(Interfp2);
2586
2587     //////////////////////////////////////////////////////////////////////
2588     // storage for the face
2589     //////////////////////////////////////////////////////////////////////
2590
2591 #ifndef DEB
2592     TopAbs_Orientation ori = TopAbs_FORWARD;
2593 #else
2594     TopAbs_Orientation ori;
2595 #endif
2596     orface=Face[nb-1].Orientation();
2597     if (orface==orsurfdata ) orien = TopAbs::Reverse(orcourbe);
2598     else                     orien = orcourbe ;
2599     // limitation of edges of faces
2600     if (nb==1) {
2601       Standard_Integer Iarc1= DStr.AddShape(Edge[0]);
2602       Interfedge[0]= ChFi3d_FilPointInDS(CV1.TransitionOnArc(),Iarc1,
2603                                          indpoint1,paredge1,Isvtx1);
2604       //DStr.ChangeShapeInterferences(Edge[0]).Append(Interfp1);
2605     }
2606     if (nb==nbface) {
2607       Standard_Integer Iarc2= DStr.AddShape(Edge[nb]);
2608       Interfedge[nb]= ChFi3d_FilPointInDS(CV2.TransitionOnArc() ,Iarc2,
2609                                           indpoint2,paredge2,Isvtx2);
2610       //DStr.ChangeShapeInterferences(Edge[nb]).Append(Interfp2);
2611     }
2612
2613     if (nb!=nbface || oneintersection1 || oneintersection2) {
2614       if (nface==3) {
2615         V1= TopExp::FirstVertex(Edge[nb]);
2616         V2= TopExp::LastVertex(Edge[nb]);
2617         if (containV(F1,V1) || containV(F2,V1))
2618           ori=TopAbs_FORWARD;
2619         else if (containV(F1,V2) || containV(F2,V2))
2620           ori=TopAbs_REVERSED;
2621         else
2622           Standard_Failure::Raise("IntersectionAtEnd : pb orientation");
2623
2624         if (containV(F1,V1) && containV(F1,V2)) {
2625           dist1=(BRep_Tool::Pnt(V1)).Distance(BRep_Tool::Pnt(Vtx));
2626           dist2=(BRep_Tool::Pnt(V2)).Distance(BRep_Tool::Pnt(Vtx));
2627           if (dist1<dist2)  ori=TopAbs_FORWARD;
2628           else              ori=TopAbs_REVERSED;
2629         }
2630         if (containV(F2,V1) && containV(F2,V2)) {
2631           dist1=(BRep_Tool::Pnt(V1)).Distance(BRep_Tool::Pnt(Vtx));
2632           dist2=(BRep_Tool::Pnt(V2)).Distance(BRep_Tool::Pnt(Vtx));
2633           if (dist1<dist2)  ori=TopAbs_FORWARD;
2634           else              ori=TopAbs_REVERSED;
2635         }
2636       }
2637       else {
2638         if (TopExp::FirstVertex(Edge[nb]).IsSame(Vtx))
2639           ori= TopAbs_FORWARD;
2640         else ori=TopAbs_REVERSED;
2641       }
2642       if (!extend && !(oneintersection1 || oneintersection2)) {
2643         Standard_Integer Iarc2= DStr.AddShape(Edge[nb]);
2644         Interfedge[nb]= ChFi3d_FilPointInDS(ori,Iarc2,
2645                                             indpoint2,paredge2);
2646         //  DStr.ChangeShapeInterferences(Edge[nb]).Append(Interfp2);
2647       }
2648       else {
2649         if (!(oneintersection1 || oneintersection2) ) proledge[nb]=Standard_True;
2650         Standard_Integer indp1,indp2,ind;
2651         gp_Pnt pext;
2652         Standard_Real ubid,vbid;
2653         pext=BRep_Tool::Pnt(Vtx);
2654         GeomAdaptor_Curve cad;
2655         Handle(Geom_Curve) csau;
2656         if ( ! (oneintersection1 || oneintersection2)) {
2657           cad.Load(cint);
2658           csau=cint;
2659         }
2660         else {
2661           csau=BRep_Tool::Curve(edgesau,ubid,vbid );
2662           Handle(Geom_BoundedCurve) C1=
2663             Handle(Geom_BoundedCurve)::DownCast(csau);
2664           if (oneintersection1&&extend) {
2665             if (!C1.IsNull()) {
2666               gp_Pnt Pl;
2667               Pl=C1->Value(C1->LastParameter());
2668               //Standard_Boolean sens;
2669               sens=Pl.Distance(pext)<tolpt;
2670               GeomLib::ExtendCurveToPoint(C1,CV1.Point(),1,sens);
2671               csau=C1;
2672             }
2673           }
2674           else if (oneintersection2&&extend) {
2675             if (!C1.IsNull()) {
2676               gp_Pnt Pl;
2677               Pl=C1->Value(C1->LastParameter());
2678               //Standard_Boolean sens;
2679               sens=Pl.Distance(pext)<tolpt;
2680               GeomLib::ExtendCurveToPoint(C1,CV2.Point(),1,sens);
2681               csau=C1;
2682             }
2683           }
2684           cad.Load(csau);
2685         }
2686         Extrema_ExtPC ext(pext,cad,tolpt);
2687         Standard_Real par1, par2, par, ParVtx;
2688         Standard_Boolean vtx1=Standard_False;
2689         Standard_Boolean vtx2=Standard_False;
2690         par1=ext.Point(1).Parameter();
2691         ParVtx = par1;
2692         if (oneintersection1 || oneintersection2 ) {
2693           if (oneintersection2) {
2694             pext=CV2.Point();
2695             ind=indpoint2;
2696           }
2697           else {
2698             pext=CV1.Point();
2699             ind=indpoint1;
2700           }
2701           Extrema_ExtPC ext2(pext,cad,tolpt);
2702           par2=ext2.Point(1).Parameter();
2703         }
2704         else {
2705           par2=paredge2;
2706           ind=indpoint2;
2707         }
2708         if (par1>par2) {
2709           indp1=ind;
2710           indp2=DStr.AddShape(Vtx);
2711           vtx2=Standard_True;
2712           par=par1;
2713           par1=par2;
2714           par2=par;
2715         }
2716         else {
2717           indp1=DStr.AddShape(Vtx);
2718           indp2=ind;
2719           vtx1=Standard_True;
2720         }
2721         Handle(Geom_Curve) Ct=new Geom_TrimmedCurve (csau,par1,par2);
2722         TopAbs_Orientation orient;
2723         Cc->D0(Cc->FirstParameter(),P1);
2724         Cc->D0(Cc->LastParameter(),P2);
2725         Ct->D0(Ct->FirstParameter(),P3);
2726         Ct->D0(Ct->LastParameter(),P4);
2727         if (P2.Distance(P3)<tolpt || P1.Distance(P4)<tolpt) orient=orien;
2728         else orient=TopAbs::Reverse(orien);
2729         if (oneintersection1||oneintersection2) {
2730           indice=DStr.AddShape(Face[0]);
2731           if (extend) {
2732             DStr.SetNewSurface(Face[0],Sfacemoins1);
2733             ComputeCurve2d(Ct,faceprol[0],C2dint1);
2734           }
2735           else
2736           {
2737             TopoDS_Edge aLocalEdge = edgesau;
2738             if (edgesau.Orientation() != orient)
2739               aLocalEdge.Reverse();
2740             C2dint1 = BRep_Tool::CurveOnSurface(aLocalEdge,Face[0],ubid,vbid);
2741           }
2742         }
2743         else {
2744           indice=DStr.AddShape(Face[nb-1]);
2745           DStr.SetNewSurface(Face[nb-1],Sfacemoins1);
2746         }
2747         //// for periodic 3d curves ////
2748         if (cad.IsPeriodic())
2749         {
2750           gp_Pnt2d P2d = BRep_Tool::Parameters( Vtx, Face[0] );
2751           Geom2dAPI_ProjectPointOnCurve Projector( P2d, C2dint1 );
2752           par = Projector.LowerDistanceParameter();
2753           Standard_Real shift = par-ParVtx;
2754           if (Abs(shift) > Precision::Confusion())
2755           {
2756             par1 += shift;
2757             par2 += shift;
2758           }
2759         }
2760         ////////////////////////////////
2761
2762         Ct=new Geom_TrimmedCurve (csau,par1,par2);
2763         if (oneintersection1||oneintersection2) tolex=10*BRep_Tool::Tolerance(edgesau);
2764         if (extend) {
2765           Handle(GeomAdaptor_HSurface) H1, H2;
2766           H1=new GeomAdaptor_HSurface(Sfacemoins1);
2767           if (Sface.IsNull()) 
2768             tolex = Max (tolex, ChFi3d_EvalTolReached(H1,C2dint1,H1,C2dint1,Ct));
2769           else {
2770             H2=new GeomAdaptor_HSurface(Sface);
2771             tolex = Max (tolex, ChFi3d_EvalTolReached(H1,C2dint1,H2,C2dint2,Ct));
2772           }
2773         }
2774         TopOpeBRepDS_Curve tcurv( Ct,tolex);
2775         Standard_Integer indcurv;
2776         indcurv=DStr.AddCurve(tcurv);
2777         Interfp1=ChFi3d_FilPointInDS(TopAbs_FORWARD,indcurv,indp1,par1,vtx1);
2778         Interfp2=ChFi3d_FilPointInDS(TopAbs_REVERSED,indcurv,indp2,par2,vtx2);
2779         DStr.ChangeCurveInterferences(indcurv).Append(Interfp1);
2780         DStr.ChangeCurveInterferences(indcurv).Append(Interfp2);
2781
2782         Interfc=ChFi3d_FilCurveInDS(indcurv,indice ,C2dint1,orient);
2783         DStr.ChangeShapeInterferences(indice).Append(Interfc);
2784         if (oneintersection1||oneintersection2) {
2785           indice=DStr.AddShape(facesau);
2786           if (facesau.Orientation()==Face[0].Orientation())
2787             orient=TopAbs::Reverse(orient);
2788           if (extend) {
2789             ComputeCurve2d(Ct,faceprol[1],C2dint2);
2790
2791           }
2792           else
2793           {
2794             TopoDS_Edge aLocalEdge = edgesau;
2795             if (edgesau.Orientation() != orient)
2796               aLocalEdge.Reverse();
2797             C2dint2 = BRep_Tool::CurveOnSurface(aLocalEdge,facesau,ubid,vbid);
2798             //Reverse for case of edgesau on closed surface (Face[0] is equal to facesau)
2799           }
2800         }
2801         else {
2802           indice=DStr.AddShape(Face[nb]);
2803           DStr.SetNewSurface(Face[nb],Sface);
2804           if (Face[nb].Orientation()==Face[nb-1].Orientation())
2805             orient= TopAbs::Reverse(orient);
2806         }
2807         if (!bordlibre) {
2808           Interfc=ChFi3d_FilCurveInDS(indcurv,indice,C2dint2,orient);
2809           DStr.ChangeShapeInterferences(indice).Append(Interfc);
2810         }
2811       }
2812     }
2813
2814     if (checkShrink &&
2815         IsShrink(Ps,p1,p2,checkShrParam,isUShrink,Precision::Parametric(tolreached)))
2816     {
2817       shrink [nb-1] = 1;
2818       // store section face-chamf curve for previous SurfData
2819       // Suppose Fd and SDprev are parametrized similarly
2820       if (!isShrink) { // first time
2821         const ChFiDS_FaceInterference& Fi = SDprev->InterferenceOnS1();
2822         gp_Pnt2d UV = Fi.PCurveOnSurf()->Value(Fi.Parameter(isfirst));
2823         prevSDParam = isUShrink ? UV.X() : UV.Y();
2824       }
2825       gp_Pnt2d UV1=p2d1,UV2=p2d2;
2826       UV1.SetCoord(isUShrink ? 1 : 2, prevSDParam);
2827       UV2.SetCoord(isUShrink ? 1 : 2, prevSDParam);
2828       Standard_Real aTolreached;
2829       ChFi3d_ComputePCurv(Cc,UV1,UV2,Ps,
2830                           DStr.Surface(SDprev->Surf()).Surface(),
2831                           p1,p2,tolesp,aTolreached);
2832       TopOpeBRepDS_Curve& TCurv = DStr.ChangeCurve(indcurve[nb-1]);
2833       TCurv.Tolerance(Max(TCurv.Tolerance(),aTolreached));
2834
2835       InterfPS[nb-1]=ChFi3d_FilCurveInDS(indcurve[nb-1],IsurfPrev,Ps,orcourbe);
2836       DStr.ChangeSurfaceInterferences(IsurfPrev).Append(InterfPS[nb-1]);
2837
2838       if (isOnSame2) {
2839         midP2d = p2d2;
2840         midIpoint = indpoint2;
2841       }
2842       else if (!isShrink) {
2843         midP2d = p2d1;
2844         midIpoint = indpoint1;
2845       }
2846       isShrink = Standard_True;
2847     } // end if shrink
2848
2849     
2850     indice=DStr.AddShape(Face[nb-1]);
2851     InterfPC[nb-1]=ChFi3d_FilCurveInDS(indcurve[nb-1],indice ,Pc,orien);
2852     if (!shrink [nb-1])
2853       InterfPS[nb-1]=ChFi3d_FilCurveInDS(indcurve[nb-1],Isurf,Ps,orcourbe);
2854     indpoint1=indpoint2;
2855
2856   } // end loop on faces being intersected with ChFi
2857
2858   
2859   if (isOnSame1) CV1.Reset();
2860   if (isOnSame2) CV2.Reset();
2861
2862   for(nb=1;nb<=nbface;nb++) {
2863     Standard_Integer indice=DStr.AddShape(Face[nb-1]);
2864     DStr.ChangeShapeInterferences(indice).Append(InterfPC[nb-1]);
2865     if (!shrink [nb-1])
2866       DStr.ChangeSurfaceInterferences(Isurf).Append(InterfPS[nb-1]);
2867     if (!proledge[nb-1])
2868       DStr.ChangeShapeInterferences(Edge[nb-1]).Append(Interfedge[nb-1]);
2869   }
2870   DStr.ChangeShapeInterferences(Edge[nbface]).Append(Interfedge[nbface]);
2871
2872   if (!isShrink)
2873     stripe->InDS(isfirst);
2874   else {
2875     // compute curves for !<isfirst> end of <Fd> and <isfirst> end of previous <SurfData>
2876
2877     // for Fd
2878     //Bnd_Box box;
2879     gp_Pnt2d UV, UV1 = midP2d, UV2 = midP2d;
2880     if (isOnSame1) 
2881       UV = UV2 = Fi1.PCurveOnSurf()->Value(Fi1.Parameter(!isfirst));
2882     else 
2883       UV = UV1 = Fi2.PCurveOnSurf()->Value(Fi2.Parameter(!isfirst));
2884     Standard_Real aTolreached;
2885     Handle(Geom_Curve) C3d;
2886     Handle(Geom_Surface) aSurf = DStr.Surface(Fd->Surf()).Surface();
2887     //box.Add(aSurf->Value(UV.X(), UV.Y()));
2888     
2889     ChFi3d_ComputeArete(CV1,UV1,CV2,UV2,aSurf, // in 
2890                         C3d,Ps,p1,p2,tolesp,tol2d,aTolreached,0); // out except tolers
2891
2892     indpoint1 = indpoint2 = midIpoint;
2893     gp_Pnt point;
2894     if (isOnSame1) {
2895       point = C3d->Value(p2);
2896       TopOpeBRepDS_Point tpoint (point,aTolreached);
2897       indpoint2=DStr.AddPoint(tpoint);
2898       UV = Ps->Value(p2);
2899     } else {
2900       point = C3d->Value(p1);
2901       TopOpeBRepDS_Point tpoint (point,aTolreached);
2902       indpoint1=DStr.AddPoint(tpoint);
2903       UV = Ps->Value(p1);
2904     }
2905     //box.Add(point);
2906     //box.Add(aSurf->Value(UV.X(), UV.Y()));
2907     
2908     TopOpeBRepDS_Curve Crv = TopOpeBRepDS_Curve(C3d,aTolreached);
2909     Standard_Integer Icurv = DStr.AddCurve(Crv);
2910     Interfp1 = ChFi3d_FilPointInDS(TopAbs_FORWARD,Icurv,indpoint1,p1, Standard_False);
2911     Interfp2 = ChFi3d_FilPointInDS(TopAbs_REVERSED,Icurv,indpoint2,p2, Standard_False);
2912     Interfc = ChFi3d_FilCurveInDS(Icurv,Isurf,Ps,orcourbe);
2913     DStr.ChangeCurveInterferences(Icurv).Append(Interfp1);
2914     DStr.ChangeCurveInterferences(Icurv).Append(Interfp2);
2915     DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc);
2916
2917     // for SDprev
2918     aSurf = DStr.Surface(SDprev->Surf()).Surface();
2919     UV1.SetCoord(isUShrink ? 1 : 2, prevSDParam);
2920     UV2.SetCoord(isUShrink ? 1 : 2, prevSDParam);
2921     
2922     ChFi3d_ComputePCurv(C3d,UV1,UV2,Pc,aSurf,p1,p2,tolesp,aTolreached);
2923     
2924     Crv.Tolerance(Max(Crv.Tolerance(),aTolreached));
2925     Interfc= ChFi3d_FilCurveInDS (Icurv,IsurfPrev,Pc,TopAbs::Reverse(orcourbe));
2926     DStr.ChangeSurfaceInterferences(IsurfPrev).Append(Interfc);
2927
2928     //UV = isOnSame1 ? UV2 : UV1;
2929     //box.Add(aSurf->Value(UV.X(), UV.Y()));
2930     //UV = Ps->Value(isOnSame1 ? p2 : p1);
2931     //box.Add(aSurf->Value(UV.X(), UV.Y()));
2932     //ChFi3d_SetPointTolerance(DStr,box, isOnSame1 ? indpoint2 : indpoint1);
2933     
2934     // to process properly this case in ChFi3d_FilDS()
2935     stripe->InDS(isfirst, 2);
2936     Fd->ChangeInterference(isOnSame1 ? 2 : 1).SetLineIndex(0);
2937     ChFiDS_CommonPoint& CPprev1 = SDprev->ChangeVertex( isfirst,isOnSame1 ? 2 : 1);
2938     ChFiDS_CommonPoint& CPlast1 = Fd->    ChangeVertex( isfirst,isOnSame1 ? 2 : 1);
2939     ChFiDS_CommonPoint& CPlast2 = Fd->    ChangeVertex(!isfirst,isOnSame1 ? 2 : 1);
2940     if (CPprev1.IsOnArc()) {
2941       CPlast1 = CPprev1;
2942       CPprev1.Reset();
2943       CPprev1.SetPoint(CPlast1.Point());
2944       CPlast2.Reset();
2945       CPlast2.SetPoint(CPlast1.Point());
2946     }
2947
2948     // in shrink case, self intersection is possible at <midIpoint>,
2949     // eval its tolerance intersecting Ps and Pcurve at end.
2950     // Find end curves closest to shrinked part
2951     for (nb=0; nb < nbface; nb++)
2952       if (isOnSame1 ? shrink [nb+1] : !shrink [nb]) break;
2953     Handle(Geom_Curve)   Cend = DStr.Curve(indcurve[nb]).Curve();
2954     Handle(Geom2d_Curve) PCend = InterfPS[nb]->PCurve();
2955     // point near which self intersection may occure
2956     TopOpeBRepDS_Point& Pds = DStr.ChangePoint(midIpoint);
2957     const gp_Pnt& Pvert = Pds.Point();
2958     Standard_Real tol = Pds.Tolerance();
2959
2960     Geom2dAdaptor_Curve PC1(Ps), PC2(PCend);
2961     Geom2dInt_GInter Intersector(PC1,PC2,Precision::PConfusion(),Precision::PConfusion());
2962     if (!Intersector.IsDone()) return;
2963     for (nb=1; nb <= Intersector.NbPoints(); nb++) {
2964       const IntRes2d_IntersectionPoint& ip = Intersector.Point(nb);
2965       gp_Pnt Pint = C3d->Value(ip.ParamOnFirst());
2966       tol = Max(tol, Pvert.Distance(Pint));
2967       Pint = Cend->Value(ip.ParamOnSecond());
2968       tol = Max(tol, Pvert.Distance(Pint));
2969     }
2970     for (nb=1; nb <= Intersector.NbSegments(); nb++) {
2971       const IntRes2d_IntersectionSegment& is = Intersector.Segment(nb);
2972       if (is.HasFirstPoint()) {
2973         const IntRes2d_IntersectionPoint& ip = is.FirstPoint();
2974         gp_Pnt Pint = C3d->Value(ip.ParamOnFirst());
2975         tol = Max(tol, Pvert.Distance(Pint));
2976         Pint = Cend->Value(ip.ParamOnSecond());
2977         tol = Max(tol, Pvert.Distance(Pint));
2978       }
2979       if (is.HasLastPoint()) {
2980         const IntRes2d_IntersectionPoint& ip = is.LastPoint();
2981         gp_Pnt Pint = C3d->Value(ip.ParamOnFirst());
2982         tol = Max(tol, Pvert.Distance(Pint));
2983         Pint = Cend->Value(ip.ParamOnSecond());
2984         tol = Max(tol, Pvert.Distance(Pint));
2985       }
2986     }
2987     Pds.Tolerance(tol);
2988   }
2989 }
2990
2991 //  Modified by Sergey KHROMOV - Thu Apr 11 12:23:40 2002 Begin
2992
2993 //=======================================================================
2994 //function : PerformMoreSurfdata
2995 //purpose  :  determine intersections at end on several surfdata
2996 //=======================================================================
2997 void ChFi3d_Builder::PerformMoreSurfdata(const Standard_Integer Index)
2998 {
2999   TopOpeBRepDS_DataStructure &DStr = myDS->ChangeDS();
3000   const ChFiDS_ListOfStripe  &aLOfStripe = myVDataMap(Index);
3001   Handle(ChFiDS_Stripe)       aStripe;
3002   Handle(ChFiDS_Spine)        aSpine;
3003   Standard_Real               aTol3d = 1.e-4;
3004
3005
3006   if (aLOfStripe.IsEmpty())
3007     return;
3008
3009   aStripe = aLOfStripe.First();
3010   aSpine  = aStripe->Spine();
3011
3012   ChFiDS_SequenceOfSurfData &aSeqSurfData =
3013                                aStripe->ChangeSetOfSurfData()->ChangeSequence();
3014   const TopoDS_Vertex       &aVtx         = myVDataMap.FindKey(Index);
3015   Standard_Integer           aSens        = 0;
3016   Standard_Integer           anInd        =
3017                                ChFi3d_IndexOfSurfData(aVtx,aStripe,aSens);
3018   Standard_Boolean           isFirst      = (aSens == 1);
3019   Standard_Integer           anIndPrev;
3020   Handle(ChFiDS_SurfData)    aSurfData;
3021   ChFiDS_CommonPoint         aCP1;
3022   ChFiDS_CommonPoint         aCP2;
3023
3024   aSurfData = aSeqSurfData.Value(anInd);
3025
3026   aCP1 = aSurfData->Vertex(isFirst,1);
3027   aCP2 = aSurfData->Vertex(isFirst,2);
3028
3029   Handle(Geom_Surface) aSurfPrev;
3030   Handle(Geom_Surface) aSurf;
3031   TopoDS_Face          aFace;
3032   TopoDS_Face          aNeighborFace;
3033
3034   FindFace(aVtx, aCP1, aCP2, aFace);
3035   aSurfPrev = BRep_Tool::Surface(aFace);
3036
3037   if (aSens==1) anIndPrev=anInd+1;
3038   else  anIndPrev=anInd-1;
3039
3040   TopoDS_Edge                        anArc1;
3041   TopoDS_Edge                        anArc2;
3042   TopTools_ListIteratorOfListOfShape anIter(myVEMap(aVtx));
3043   Standard_Boolean                   isFound = Standard_False;
3044
3045   for(; anIter.More() && !isFound; anIter.Next()) {
3046     anArc1 = TopoDS::Edge(anIter.Value());
3047
3048     if (containE(aFace, anArc1))
3049       isFound = Standard_True;
3050   }
3051
3052   isFound = Standard_False;
3053   anIter.Initialize(myVEMap(aVtx));
3054
3055   for(; anIter.More() && !isFound; anIter.Next()) {
3056     anArc2 = TopoDS::Edge(anIter.Value());
3057
3058     if (containE(aFace,anArc2) && !anArc2.IsSame(anArc1))
3059       isFound = Standard_True;
3060   }
3061
3062   // determination of common points aCP1onArc, aCP2onArc and aCP2NotonArc
3063   // aCP1onArc    is the point on arc of index anInd
3064   // aCP2onArc    is the point on arc of index anIndPrev
3065   // aCP2NotonArc is the point of index anIndPrev which is not on arc.
3066
3067   Standard_Boolean   is1stCP1OnArc;
3068   Standard_Boolean   is2ndCP1OnArc;
3069   ChFiDS_CommonPoint aCP1onArc;
3070   ChFiDS_CommonPoint aCP2onArc;
3071   ChFiDS_CommonPoint aCP2NotonArc;
3072
3073   aSurfData = aSeqSurfData.Value(anIndPrev);
3074   aCP1      = aSurfData->Vertex(isFirst,1);
3075   aCP2      = aSurfData->Vertex(isFirst,2);
3076
3077   if (aCP1.IsOnArc() &&
3078       (aCP1.Arc().IsSame(anArc1) || aCP1.Arc().IsSame(anArc2))) {
3079       aCP2onArc     = aCP1;
3080       aCP2NotonArc  = aCP2;
3081       is2ndCP1OnArc = Standard_True;
3082   } else if (aCP2.IsOnArc() &&
3083              (aCP2.Arc().IsSame(anArc1) || aCP2.Arc().IsSame(anArc2))) {
3084       aCP2onArc     = aCP2;
3085       aCP2NotonArc  = aCP1;
3086       is2ndCP1OnArc = Standard_False;
3087   } else
3088     return;
3089
3090   aSurfData = aSeqSurfData.Value(anInd);
3091   aCP1      = aSurfData->Vertex(isFirst,1);
3092   aCP2      = aSurfData->Vertex(isFirst,2);
3093
3094   if (aCP1.Point().Distance(aCP2onArc.Point()) <= aTol3d){
3095     aCP1onArc     = aCP2;
3096     is1stCP1OnArc = Standard_False;
3097   }
3098   else {
3099     aCP1onArc     = aCP1;
3100     is1stCP1OnArc = Standard_True;
3101   }
3102
3103   if (!aCP1onArc.IsOnArc())
3104     return;
3105
3106 // determination of neighbor surface
3107   Standard_Integer indSurface;
3108   if (is1stCP1OnArc)
3109     indSurface = myListStripe.First()->SetOfSurfData()->Value(anInd)->IndexOfS1();
3110   else
3111     indSurface = myListStripe.First()->SetOfSurfData()->Value(anInd)->IndexOfS2();
3112
3113   aNeighborFace = TopoDS::Face(myDS->Shape(indSurface));
3114
3115 // calculation of intersections
3116   Handle(Geom_Curve)   aCracc;
3117   Handle(Geom2d_Curve) aPCurv1;
3118   Standard_Real        aParf;
3119   Standard_Real        aParl;
3120   Standard_Real        aTolReached;
3121
3122   aSurfData = aSeqSurfData.Value(anInd);
3123
3124   if (isFirst)
3125     ChFi3d_ComputeArete(aSurfData->VertexLastOnS1(),
3126                         aSurfData->InterferenceOnS1().PCurveOnSurf()->
3127                         Value(aSurfData->InterferenceOnS1().LastParameter()),
3128                         aSurfData->VertexLastOnS2(),
3129                         aSurfData->InterferenceOnS2().PCurveOnSurf()->
3130                         Value(aSurfData->InterferenceOnS2().LastParameter()),
3131                         DStr.Surface(aSurfData->Surf()).Surface(),aCracc,aPCurv1,
3132                         aParf,aParl,aTol3d,tol2d,aTolReached,0);
3133   else
3134     ChFi3d_ComputeArete(aSurfData->VertexFirstOnS1(),
3135                         aSurfData->InterferenceOnS1().PCurveOnSurf()->
3136                         Value(aSurfData->InterferenceOnS1().FirstParameter()),
3137                         aSurfData->VertexFirstOnS2(),
3138                         aSurfData->InterferenceOnS2().PCurveOnSurf()->
3139                         Value(aSurfData->InterferenceOnS2().FirstParameter()),
3140                         DStr.Surface(aSurfData->Surf()).Surface(),aCracc,aPCurv1,
3141                         aParf,aParl,aTol3d,tol2d,aTolReached,0);
3142
3143 // calculation of the index of the line on anInd.
3144 // aPClineOnSurf is the pcurve on anInd.
3145 // aPClineOnFace is the pcurve on face.
3146   ChFiDS_FaceInterference  aFI;
3147
3148   if (is1stCP1OnArc)
3149     aFI = aSurfData->InterferenceOnS1();
3150   else
3151     aFI = aSurfData->InterferenceOnS2();
3152
3153   Handle(Geom_Curve)   aCline;
3154   Handle(Geom2d_Curve) aPClineOnSurf;
3155   Handle(Geom2d_Curve) aPClineOnFace;
3156   Standard_Integer     indLine;
3157
3158   indLine       = aFI.LineIndex();
3159   aCline        = DStr.Curve(aFI.LineIndex()).Curve();
3160   aPClineOnSurf = aFI.PCurveOnSurf();
3161   aPClineOnFace = aFI.PCurveOnFace();
3162
3163 // intersection between the SurfData number anInd and the Face aFace.
3164 // Obtaining of curves aCint1, aPCint11 and aPCint12.
3165   aSurf = DStr.Surface(aSurfData->Surf()).Surface();
3166
3167   GeomInt_IntSS                anInterSS(aSurfPrev,aSurf,1.e-7,1,1,1);
3168   Handle(Geom_Curve)           aCint1;
3169   Handle(Geom2d_Curve)         aPCint11;
3170   Handle(Geom2d_Curve)         aPCint12;
3171   Handle(GeomAdaptor_HSurface) H1 = new GeomAdaptor_HSurface(aSurfPrev);
3172   Handle(GeomAdaptor_HSurface) H2 = new GeomAdaptor_HSurface(aSurf);
3173   Standard_Real                aTolex1=0.;
3174   Standard_Integer             i;
3175   gp_Pnt                       aPext1;
3176   gp_Pnt                       aPext2;
3177   gp_Pnt                       aPext;
3178   Standard_Boolean             isPextFound;
3179
3180
3181   if (!anInterSS.IsDone())
3182     return;
3183
3184   isFound = Standard_False;
3185
3186   for (i = 1; i <= anInterSS.NbLines() && !isFound; i++) {
3187     aCint1   = anInterSS.Line(i);
3188     aPCint11 = anInterSS.LineOnS1(i);
3189     aPCint12 = anInterSS.LineOnS2(i);
3190     aTolex1  = ChFi3d_EvalTolReached(H1, aPCint11, H2, aPCint12, aCint1);
3191
3192     aCint1->D0(aCint1->FirstParameter(), aPext1);
3193     aCint1->D0(aCint1->LastParameter(),  aPext2);
3194
3195 //  Modified by skv - Mon Jun  7 18:38:57 2004 OCC5898 Begin
3196 //     if (aPext1.Distance(aCP1onArc.Point()) <= aTol3d ||
3197 //      aPext2.Distance(aCP1onArc.Point()))
3198     if (aPext1.Distance(aCP1onArc.Point()) <= aTol3d ||
3199         aPext2.Distance(aCP1onArc.Point()) <= aTol3d)
3200 //  Modified by skv - Mon Jun  7 18:38:58 2004 OCC5898 End
3201       isFound = Standard_True;
3202   }
3203
3204   if (!isFound)
3205     return;
3206
3207   if (aPext1.Distance(aCP2onArc.Point()) > aTol3d &&
3208       aPext1.Distance(aCP1onArc.Point()) > aTol3d) {
3209     aPext       = aPext1;
3210     isPextFound = Standard_True;
3211   } else if (aPext2.Distance(aCP2onArc.Point()) > aTol3d &&
3212              aPext2.Distance(aCP1onArc.Point()) > aTol3d) {
3213     aPext       = aPext2;
3214     isPextFound = Standard_True;
3215   } else {
3216     isPextFound = Standard_False;
3217   }
3218
3219
3220   Standard_Boolean  isDoSecondSection = Standard_False;
3221   Standard_Real     aPar=0.;
3222
3223   if (isPextFound) {
3224     GeomAdaptor_Curve aCad(aCracc);
3225     Extrema_ExtPC     anExt(aPext, aCad, aTol3d);
3226
3227     if (!anExt.IsDone())
3228       return;
3229
3230     isFound = Standard_False;
3231     for (i = 1; i <= anExt.NbExt() && !isFound; i++) {
3232       if (anExt.IsMin(i)) {
3233         gp_Pnt aProjPnt = anExt.Point(i).Value();
3234
3235         if (aPext.Distance(aProjPnt) <= aTol3d) {
3236           aPar              = anExt.Point(i).Parameter();
3237           isDoSecondSection = Standard_True;
3238         }
3239       }
3240     }
3241   }
3242
3243   Handle(Geom_Curve) aTrCracc;
3244   TopAbs_Orientation anOrSD1;
3245   TopAbs_Orientation anOrSD2;
3246   Standard_Integer   indShape;
3247
3248   anOrSD1   = aSurfData->Orientation();
3249   aSurfData = aSeqSurfData.Value(anIndPrev);
3250   anOrSD2   = aSurfData->Orientation();
3251   aSurf     = DStr.Surface(aSurfData->Surf()).Surface();
3252
3253 // The following variables will be used if isDoSecondSection is true
3254   Handle(Geom_Curve)           aCint2;
3255   Handle(Geom2d_Curve)         aPCint21;
3256   Handle(Geom2d_Curve)         aPCint22;
3257   Standard_Real                aTolex2=0.;
3258
3259   if (isDoSecondSection) {
3260     Standard_Real aPar1;
3261
3262     aCracc->D0(aCracc->FirstParameter(), aPext1);
3263
3264     if (aPext1.Distance(aCP2NotonArc.Point()) <= aTol3d)
3265       aPar1 = aCracc->FirstParameter();
3266     else
3267       aPar1 = aCracc->LastParameter();
3268
3269     if (aPar1 < aPar)
3270       aTrCracc = new Geom_TrimmedCurve (aCracc, aPar1, aPar);
3271     else
3272       aTrCracc = new Geom_TrimmedCurve (aCracc, aPar,  aPar1);
3273
3274 // Second section
3275     GeomInt_IntSS anInterSS2(aSurfPrev,aSurf,1.e-7,1,1,1);
3276
3277     if (!anInterSS2.IsDone())
3278       return;
3279
3280     H1 = new GeomAdaptor_HSurface(aSurfPrev);
3281     H2 = new GeomAdaptor_HSurface(aSurf);
3282
3283     isFound = Standard_False;
3284
3285     for (i = 1; i <= anInterSS2.NbLines() && !isFound; i++) {
3286       aCint2   = anInterSS2.Line(i);
3287       aPCint21 = anInterSS2.LineOnS1(i);
3288       aPCint22 = anInterSS2.LineOnS2(i);
3289       aTolex2  = ChFi3d_EvalTolReached(H1, aPCint21, H2, aPCint22, aCint2);
3290
3291       aCint2->D0(aCint2->FirstParameter(), aPext1);
3292       aCint2->D0(aCint2->LastParameter(),  aPext2);
3293
3294       if (aPext1.Distance(aCP2onArc.Point()) <= aTol3d ||
3295           aPext2.Distance(aCP2onArc.Point()) <= aTol3d)
3296         isFound = Standard_True;
3297     }
3298
3299     if (!isFound)
3300       return;
3301
3302   } else {
3303     aTrCracc = new Geom_TrimmedCurve(aCracc,
3304                                      aCracc->FirstParameter(),
3305                                      aCracc->LastParameter());
3306   }
3307
3308 // Storage of the data structure
3309
3310 // calculation of the orientation of line of surfdata number
3311 // anIndPrev which contains aCP2onArc
3312
3313   Handle(Geom2d_Curve) aPCraccS = GeomProjLib::Curve2d(aTrCracc,aSurf);
3314
3315   if (is2ndCP1OnArc) {
3316     aFI      = aSurfData->InterferenceOnS1();
3317     indShape = aSurfData->IndexOfS1();
3318   } else {
3319     aFI      = aSurfData->InterferenceOnS2();
3320     indShape = aSurfData->IndexOfS2();
3321   }
3322
3323   if (indShape <= 0)
3324     return;
3325
3326
3327
3328   TopAbs_Orientation aCurOrient;
3329
3330   aCurOrient = DStr.Shape(indShape).Orientation();
3331   aCurOrient = TopAbs::Compose(aCurOrient, aSurfData->Orientation());
3332   aCurOrient = TopAbs::Compose(TopAbs::Reverse(aFI.Transition()), aCurOrient);
3333
3334
3335 // Filling the data structure
3336   aSurfData   = aSeqSurfData.Value(anInd);
3337
3338   TopOpeBRepDS_Point aPtCP1(aCP1onArc.Point(),aCP1onArc.Tolerance());
3339   Standard_Integer   indCP1onArc = DStr.AddPoint(aPtCP1);
3340   Standard_Integer   indSurf1    = aSurfData->Surf();
3341   Standard_Integer   indArc1     = DStr.AddShape(aCP1onArc.Arc());
3342   Standard_Integer   indSol      = aStripe->SolidIndex();
3343
3344   Handle (TopOpeBRepDS_CurvePointInterference) anInterfp1;
3345   Handle (TopOpeBRepDS_CurvePointInterference) anInterfp2;
3346
3347   anInterfp1= ChFi3d_FilPointInDS(aCP1onArc.TransitionOnArc(), indArc1,
3348                                   indCP1onArc, aCP1onArc.ParameterOnArc());
3349   DStr.ChangeShapeInterferences(aCP1onArc.Arc()).Append(anInterfp1);
3350
3351   TopOpeBRepDS_ListOfInterference &SolidInterfs  =
3352                                    DStr.ChangeShapeInterferences(indSol);
3353   Handle(TopOpeBRepDS_SolidSurfaceInterference) SSI =
3354     new TopOpeBRepDS_SolidSurfaceInterference
3355                                       (TopOpeBRepDS_Transition(anOrSD1),
3356                                        TopOpeBRepDS_SOLID, indSol,
3357                                        TopOpeBRepDS_SURFACE, indSurf1);
3358   SolidInterfs.Append(SSI);
3359
3360 // deletion of Surface Data.
3361   aSeqSurfData.Remove(anInd);
3362
3363   if (!isFirst)
3364     anInd--;
3365
3366   aSurfData = aSeqSurfData.Value(anInd);
3367
3368 // definition of indices of common points in Data Structure
3369
3370   Standard_Integer indCP2onArc;
3371   Standard_Integer indCP2NotonArc;
3372
3373   if (is2ndCP1OnArc) {
3374     aStripe->SetIndexPoint(ChFi3d_IndexPointInDS(aCP2onArc,   DStr),isFirst,1);
3375     aStripe->SetIndexPoint(ChFi3d_IndexPointInDS(aCP2NotonArc,DStr),isFirst,2);
3376
3377     if (isFirst) {
3378       indCP2onArc    = aStripe->IndexFirstPointOnS1();
3379       indCP2NotonArc = aStripe->IndexFirstPointOnS2();
3380     } else {
3381       indCP2onArc    = aStripe->IndexLastPointOnS1();
3382       indCP2NotonArc = aStripe->IndexLastPointOnS2();
3383     }
3384   } else {
3385     aStripe->SetIndexPoint(ChFi3d_IndexPointInDS(aCP2onArc,   DStr),isFirst,2);
3386     aStripe->SetIndexPoint(ChFi3d_IndexPointInDS(aCP2NotonArc,DStr),isFirst,1);
3387
3388     if (isFirst) {
3389       indCP2onArc    = aStripe->IndexFirstPointOnS2();
3390       indCP2NotonArc = aStripe->IndexFirstPointOnS1();
3391     }
3392     else {
3393       indCP2onArc    = aStripe->IndexLastPointOnS2();
3394       indCP2NotonArc = aStripe->IndexLastPointOnS1();
3395     }
3396   }
3397
3398   Standard_Integer indPoint1;
3399   Standard_Integer indPoint2;
3400   gp_Pnt           aPoint1;
3401   gp_Pnt           aPoint2;
3402
3403   if (is2ndCP1OnArc)  {
3404     aFI      = aSurfData->InterferenceOnS1();
3405     indShape = aSurfData->IndexOfS1();
3406   } else {
3407     aFI      = aSurfData->InterferenceOnS2();
3408     indShape = aSurfData->IndexOfS2();
3409   }
3410
3411   gp_Pnt2d                                       aP2d;
3412   Handle (TopOpeBRepDS_SurfaceCurveInterference) anInterfc;
3413   TopAbs_Orientation                             anOrSurf = aCurOrient;
3414   TopAbs_Orientation                             anOrFace = aFace.Orientation();
3415   Standard_Integer                               indaFace = DStr.AddShape(aFace);
3416   Standard_Integer                               indPoint = indCP2onArc;
3417   Standard_Integer                               indCurve;
3418
3419   aFI.PCurveOnFace()->D0(aFI.LastParameter(), aP2d);
3420   Handle(Geom_Surface) Stemp2 =
3421                        BRep_Tool::Surface(TopoDS::Face(DStr.Shape(indShape)));
3422   Stemp2->D0(aP2d.X(), aP2d.Y(), aPoint2);
3423   aFI.PCurveOnFace()->D0(aFI.FirstParameter(), aP2d);
3424   Stemp2->D0(aP2d.X(), aP2d.Y(), aPoint1);
3425
3426   if (isDoSecondSection) {
3427     TopOpeBRepDS_Point tpoint(aPext,  aTolex2);
3428     TopOpeBRepDS_Curve tcint2(aCint2, aTolex2);
3429
3430     indPoint = DStr.AddPoint(tpoint);
3431     indCurve = DStr.AddCurve(tcint2);
3432
3433     aCint2->D0(aCint2->FirstParameter(), aPext1);
3434     aCint2->D0(aCint2->LastParameter(),  aPext2);
3435
3436     if (aPext1.Distance(aPext) <= aTol3d){
3437       indPoint1 = indPoint;
3438       indPoint2 = indCP2onArc;
3439     } else {
3440       indPoint1 = indCP2onArc;
3441       indPoint2 = indPoint;
3442     }
3443
3444 // define the orientation of aCint2
3445     if (aPext1.Distance(aPoint2) > aTol3d && aPext2.Distance(aPoint1) > aTol3d)
3446       anOrSurf = TopAbs::Reverse(anOrSurf);
3447
3448 // ---------------------------------------------------------------
3449 // storage of aCint2
3450     anInterfp1 = ChFi3d_FilPointInDS(TopAbs_FORWARD, indCurve,
3451                                      indPoint1, aCint2->FirstParameter());
3452     anInterfp2 = ChFi3d_FilPointInDS(TopAbs_REVERSED, indCurve,
3453                                      indPoint2, aCint2->LastParameter());
3454     DStr.ChangeCurveInterferences(indCurve).Append(anInterfp1);
3455     DStr.ChangeCurveInterferences(indCurve).Append(anInterfp2);
3456
3457   // interference of aCint2 on the SurfData number anIndPrev
3458     anInterfc = ChFi3d_FilCurveInDS(indCurve, aSurfData->Surf(),
3459                                     aPCint22, anOrSurf);
3460
3461     DStr.ChangeSurfaceInterferences(aSurfData->Surf()).Append(anInterfc);
3462   // interference of aCint2 on aFace
3463
3464     if (anOrFace == anOrSD2)
3465       anOrFace = TopAbs::Reverse(anOrSurf);
3466     else
3467       anOrFace = anOrSurf;
3468
3469     anInterfc = ChFi3d_FilCurveInDS(indCurve, indaFace, aPCint21, anOrFace);
3470     DStr.ChangeShapeInterferences(indaFace).Append(anInterfc);
3471   }
3472
3473   aTrCracc->D0(aTrCracc->FirstParameter(), aPext1);
3474   aTrCracc->D0(aTrCracc->LastParameter(),  aPext2);
3475   if (aPext1.Distance(aCP2NotonArc.Point()) <= aTol3d){
3476     indPoint1 = indCP2NotonArc;
3477     indPoint2 = indPoint;
3478   } else {
3479     indPoint1 = indPoint;
3480     indPoint2 = indCP2NotonArc;
3481   }
3482
3483 // Define the orientation of aTrCracc
3484   Standard_Boolean isToReverse;
3485   gp_Pnt           aP1;
3486   gp_Pnt           aP2;
3487   gp_Pnt           aP3;
3488   gp_Pnt           aP4;
3489
3490
3491   if (isDoSecondSection) {
3492     aTrCracc->D0(aTrCracc->FirstParameter(), aP1);
3493     aTrCracc->D0(aTrCracc->LastParameter(),  aP2);
3494     aCint2->D0(aCint2->FirstParameter(), aP3);
3495     aCint2->D0(aCint2->LastParameter(),  aP4);
3496     isToReverse = (aP1.Distance(aP4) > aTol3d && aP2.Distance(aP3) > aTol3d);
3497   } else {
3498     isToReverse = (aPext1.Distance(aPoint2) > aTol3d &&
3499                    aPext2.Distance(aPoint1) > aTol3d);
3500   }
3501
3502   if (isToReverse)
3503     anOrSurf = TopAbs::Reverse(anOrSurf);
3504
3505 // ---------------------------------------------------------------
3506 // storage of aTrCracc
3507   TopOpeBRepDS_Curve tct2(aTrCracc, aTolReached);
3508
3509   indCurve = DStr.AddCurve(tct2);
3510   anInterfp1 = ChFi3d_FilPointInDS(TopAbs_FORWARD,indCurve,
3511                                    indPoint1, aTrCracc->FirstParameter());
3512   anInterfp2 = ChFi3d_FilPointInDS(TopAbs_REVERSED,indCurve,
3513                                    indPoint2, aTrCracc->LastParameter());
3514   DStr.ChangeCurveInterferences(indCurve).Append(anInterfp1);
3515   DStr.ChangeCurveInterferences(indCurve).Append(anInterfp2);
3516
3517   // interference of aTrCracc on the SurfData number anIndPrev
3518
3519   anInterfc = ChFi3d_FilCurveInDS(indCurve,aSurfData->Surf(),aPCraccS, anOrSurf);
3520   DStr.ChangeSurfaceInterferences(aSurfData->Surf()).Append(anInterfc);
3521   aStripe->InDS(isFirst);
3522
3523   // interference of aTrCracc on the SurfData number anInd
3524   if (anOrSD1 == anOrSD2)
3525     anOrSurf = TopAbs::Reverse(anOrSurf);
3526
3527   anInterfc = ChFi3d_FilCurveInDS(indCurve, indSurf1, aPCurv1, anOrSurf);
3528   DStr.ChangeSurfaceInterferences(indSurf1).Append(anInterfc);
3529
3530 // ---------------------------------------------------------------
3531 // storage of aCint1
3532
3533   aCint1->D0(aCint1->FirstParameter(),aPext1);
3534   if (aPext1.Distance(aCP1onArc.Point()) <= aTol3d){
3535     indPoint1 = indCP1onArc;
3536     indPoint2 = indPoint;
3537   } else {
3538     indPoint1 = indPoint;
3539     indPoint2 = indCP1onArc;
3540   }
3541
3542   //  definition of the orientation of aCint1
3543
3544   aCint1->D0(aCint1->FirstParameter(), aP1);
3545   aCint1->D0(aCint1->LastParameter(),  aP2);
3546   aTrCracc->D0(aTrCracc->FirstParameter(), aP3);
3547   aTrCracc->D0(aTrCracc->LastParameter(),  aP4);
3548
3549   if (aP1.Distance(aP4) > aTol3d && aP2.Distance(aP3) > aTol3d)
3550     anOrSurf=TopAbs::Reverse(anOrSurf);
3551
3552   TopOpeBRepDS_Curve aTCint1(aCint1, aTolex1);
3553   indCurve= DStr.AddCurve(aTCint1);
3554   anInterfp1 = ChFi3d_FilPointInDS(TopAbs_FORWARD, indCurve,
3555                                    indPoint1, aCint1->FirstParameter());
3556   anInterfp2 = ChFi3d_FilPointInDS(TopAbs_REVERSED, indCurve,
3557                                    indPoint2, aCint1->LastParameter());
3558   DStr.ChangeCurveInterferences(indCurve).Append(anInterfp1);
3559   DStr.ChangeCurveInterferences(indCurve).Append(anInterfp2);
3560
3561   // interference of aCint1 on the SurfData number anInd
3562
3563   anInterfc = ChFi3d_FilCurveInDS(indCurve, indSurf1, aPCint12, anOrSurf);
3564   DStr.ChangeSurfaceInterferences(indSurf1).Append(anInterfc);
3565
3566   // interference of aCint1 on aFace
3567
3568   anOrFace = aFace.Orientation();
3569
3570   if (anOrFace == anOrSD1)
3571     anOrFace = TopAbs::Reverse(anOrSurf);
3572   else
3573     anOrFace = anOrSurf;
3574
3575   anInterfc = ChFi3d_FilCurveInDS(indCurve, indaFace, aPCint11, anOrFace);
3576   DStr.ChangeShapeInterferences(indaFace).Append(anInterfc);
3577 // ---------------------------------------------------------------
3578 // storage of aCline passing through aCP1onArc and aCP2NotonArc
3579
3580   Handle(Geom_Curve) aTrCline   =
3581                      new Geom_TrimmedCurve(aCline, aCline->FirstParameter(),
3582                                                    aCline->LastParameter());
3583   Standard_Real      aTolerance = DStr.Curve(indLine).Tolerance();
3584   TopOpeBRepDS_Curve aTct3(aTrCline, aTolerance);
3585
3586   indCurve = DStr.AddCurve(aTct3);
3587
3588   aTrCline->D0(aTrCline->FirstParameter(),aPext1);
3589
3590   if (aPext1.Distance(aCP1onArc.Point()) < aTol3d) {
3591     indPoint1 = indCP1onArc;
3592     indPoint2 = indCP2NotonArc;
3593   } else {
3594     indPoint1 = indCP2NotonArc;
3595     indPoint2 = indCP1onArc;
3596   }
3597   //  definition of the orientation of aTrCline
3598
3599   aTrCline->D0(aTrCline->FirstParameter(), aP1);
3600   aTrCline->D0(aTrCline->LastParameter(),  aP2);
3601   aCint1->D0(aCint1->FirstParameter(), aP3);
3602   aCint1->D0(aCint1->LastParameter(),  aP4);
3603
3604   if (aP1.Distance(aP4) > aTol3d && aP2.Distance(aP3) > aTol3d)
3605     anOrSurf = TopAbs::Reverse(anOrSurf);
3606
3607   anInterfp1 = ChFi3d_FilPointInDS(TopAbs_FORWARD,indCurve,
3608                                    indPoint1,aTrCline->FirstParameter());
3609   anInterfp2 = ChFi3d_FilPointInDS(TopAbs_REVERSED,indCurve,
3610                                    indPoint2,aTrCline->LastParameter());
3611   DStr.ChangeCurveInterferences(indCurve).Append(anInterfp1);
3612   DStr.ChangeCurveInterferences(indCurve).Append(anInterfp2);
3613
3614   // interference of aTrCline on the SurfData number anInd
3615
3616   anInterfc = ChFi3d_FilCurveInDS(indCurve, indSurf1, aPClineOnSurf, anOrSurf);
3617   DStr.ChangeSurfaceInterferences(indSurf1).Append(anInterfc);
3618
3619   // interference de ctlin par rapport a Fvoisin
3620   indShape = DStr.AddShape(aNeighborFace);
3621   anOrFace = aNeighborFace.Orientation();
3622
3623   if (anOrFace == anOrSD1)
3624     anOrFace = TopAbs::Reverse(anOrSurf);
3625   else
3626     anOrFace = anOrSurf;
3627
3628   anInterfc = ChFi3d_FilCurveInDS(indCurve, indShape, aPClineOnFace, anOrFace);
3629   DStr.ChangeShapeInterferences(indShape).Append(anInterfc);
3630 }
3631 //  Modified by Sergey KHROMOV - Thu Apr 11 12:23:40 2002 End
3632
3633 //==============================================================
3634 //function : FindFace
3635 //purpose  : attention it works only if there is only one common face 
3636 //           between P1,P2,V
3637 //===========================================================
3638
3639
3640 Standard_Boolean ChFi3d_Builder::FindFace(const TopoDS_Vertex& V,
3641                                           const ChFiDS_CommonPoint& P1,
3642                                           const ChFiDS_CommonPoint& P2,
3643                                           TopoDS_Face& Fv) const
3644 {
3645   TopoDS_Face Favoid;
3646   return FindFace(V,P1,P2,Fv,Favoid);
3647 }
3648
3649 Standard_Boolean ChFi3d_Builder::FindFace(const TopoDS_Vertex& V,
3650                                           const ChFiDS_CommonPoint& P1,
3651                                           const ChFiDS_CommonPoint& P2,
3652                                           TopoDS_Face& Fv,
3653                                           const TopoDS_Face& Favoid) const
3654 {
3655   if (P1.IsVertex() || P2.IsVertex()) {
3656 #ifdef DEB
3657     cout<<"change of face on vertex"<<endl;
3658 #endif
3659   }
3660   if (!(P1.IsOnArc() && P2.IsOnArc())) {
3661     return Standard_False;
3662   }
3663   TopTools_ListIteratorOfListOfShape It,Jt;
3664   Standard_Boolean Found = Standard_False, ContainsV = Standard_False;
3665   for(It.Initialize(myEFMap(P1.Arc()));It.More() && !Found;It.Next()) {
3666     Fv = TopoDS::Face(It.Value());
3667     if(!Fv.IsSame(Favoid)){
3668       for(Jt.Initialize(myEFMap(P2.Arc()));Jt.More() && !Found ;Jt.Next()) {
3669         if (TopoDS::Face(Jt.Value()).IsSame(Fv)) Found = Standard_True;
3670       }
3671     }
3672   }
3673   if (Found) {
3674     for(It.Initialize(myVFMap(V));It.More();It.Next()) {
3675       if (TopoDS::Face(It.Value()).IsSame(Fv)) {
3676         ContainsV = Standard_True;
3677         break;
3678       }
3679     }
3680   }
3681 #ifdef DEB
3682   if(!ContainsV){
3683     cout<<"FindFace : the extremity of the spine is not in the end face"<<endl;
3684   }
3685 #endif
3686   return Found;
3687 }
3688
3689 //=======================================================================
3690 //function : MoreSurfdata
3691 //purpose  : detects if the intersection at end concerns several Surfdata
3692 //=======================================================================
3693 Standard_Boolean ChFi3d_Builder::MoreSurfdata(const Standard_Integer Index) const
3694 {
3695   // intersection at end is created on several surfdata if :
3696   // - the number of surfdata concerning the vertex is more than 1.
3697   // - and if the last but one surfdata has one of commonpoints on one of 
3698   // two arcs, which constitute the intersections of the face at end and of the fillet
3699
3700   ChFiDS_ListIteratorOfListOfStripe It;
3701   It.Initialize(myVDataMap(Index));
3702   Handle(ChFiDS_Stripe)& stripe = It.Value();
3703   ChFiDS_SequenceOfSurfData& SeqFil =
3704     stripe->ChangeSetOfSurfData()->ChangeSequence();
3705   const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index);
3706   Standard_Integer sens = 0;
3707   Standard_Integer num = ChFi3d_IndexOfSurfData(Vtx,stripe,sens);
3708   Standard_Boolean isfirst = (sens == 1);
3709   Handle(ChFiDS_SurfData)& Fd = SeqFil.ChangeValue(num);
3710   ChFiDS_CommonPoint& CV1 = Fd->ChangeVertex(isfirst,1);
3711   ChFiDS_CommonPoint& CV2 = Fd->ChangeVertex(isfirst,2);
3712
3713   Standard_Integer num1,num2,nbsurf;
3714   TopoDS_Face Fv;
3715   Standard_Boolean inters,oksurf;
3716   nbsurf= stripe->SetOfSurfData()->Length();
3717   // Fv is the face at end
3718   inters = FindFace(Vtx,CV1,CV2,Fv);
3719   if (sens==1)  {
3720     num1=1;
3721     num2=num1+1;
3722   }
3723   else {
3724     num1=nbsurf;
3725     num2=num1-1;
3726   }
3727
3728   oksurf=Standard_False;
3729
3730   if (nbsurf!=1 && inters) {
3731
3732     // determination of arc1 and arc2 intersection of the fillet and the face at end
3733
3734     TopoDS_Edge arc1,arc2;
3735     TopTools_ListIteratorOfListOfShape ItE;
3736     Standard_Boolean trouve=Standard_False;
3737     for(ItE.Initialize(myVEMap(Vtx));ItE.More()&&!trouve;ItE.Next()) {
3738       arc1=TopoDS::Edge(ItE.Value());
3739       if (containE(Fv,arc1)) trouve=Standard_True;
3740     }
3741     trouve=Standard_False;
3742     for(ItE.Initialize(myVEMap(Vtx));ItE.More()&&!trouve;ItE.Next()) {
3743       arc2=TopoDS::Edge(ItE.Value());
3744       if (containE(Fv,arc2)&& !arc2.IsSame(arc1)) trouve=Standard_True;
3745     }
3746
3747     Handle(ChFiDS_SurfData) Fd1 = SeqFil.ChangeValue(num2);
3748     ChFiDS_CommonPoint& CV3 = Fd1->ChangeVertex(isfirst,1);
3749     ChFiDS_CommonPoint& CV4 = Fd1->ChangeVertex(isfirst,2);
3750
3751     if (CV3.IsOnArc()) {
3752       if (CV3.Arc().IsSame(arc1) ){
3753         if (CV1.Point().Distance(CV3.Point())<1.e-4)
3754           oksurf=Standard_True;
3755       }
3756       else if (CV3.Arc().IsSame(arc2)){
3757         if (CV2.Point().Distance(CV3.Point())<1.e-4)
3758           oksurf=Standard_True;
3759       }
3760     }
3761
3762     if (CV4.IsOnArc()) {
3763       if (CV1.Point().Distance(CV4.Point())<1.e-4)
3764         oksurf=Standard_True;
3765       else if  (CV4.Arc().IsSame(arc2)){
3766         if (CV2.Point().Distance(CV4.Point())<1.e-4)
3767           oksurf=Standard_True;
3768       }
3769     }
3770   }
3771   return oksurf;
3772 }
3773
3774
3775 //Case of fillets on top with 4 edges, one of them is on the same geometry as the edgeof the fillet
3776
3777
3778 void ChFi3d_Builder::IntersectMoreCorner(const Standard_Integer Index)
3779 {
3780   TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
3781
3782 #ifdef DEB
3783   OSD_Chronometer ch;// init perf pour PerformSetOfKPart
3784 #endif
3785   // The fillet is returned,
3786   ChFiDS_ListIteratorOfListOfStripe StrIt;
3787   StrIt.Initialize(myVDataMap(Index));
3788   Handle(ChFiDS_Stripe) stripe = StrIt.Value();
3789   const Handle(ChFiDS_Spine) spine = stripe->Spine();
3790   ChFiDS_SequenceOfSurfData& SeqFil =
3791     stripe->ChangeSetOfSurfData()->ChangeSequence();
3792   // the top,
3793   const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index);
3794   // the SurfData concerned and its CommonPoints,
3795   Standard_Integer sens = 0;
3796
3797   // Choose the proper SurfData
3798   Standard_Integer num = ChFi3d_IndexOfSurfData(Vtx,stripe,sens);
3799   Standard_Boolean isfirst = (sens == 1);
3800   if (isfirst) {
3801     for (; num<SeqFil.Length() && (
3802          (SeqFil.Value(num)->IndexOfS1()==0) ||
3803          (SeqFil.Value(num)->IndexOfS2()==0) ); ) {
3804       SeqFil.Remove(num); // The surplus is removed
3805     }
3806   }
3807   else {
3808    for (; num>1 && (
3809          (SeqFil.Value(num)->IndexOfS1()==0) ||
3810          (SeqFil.Value(num)->IndexOfS2()==0) ); ) {
3811      SeqFil.Remove(num);// The surplus is removed
3812      num--;
3813     }
3814   }
3815
3816   Handle(ChFiDS_SurfData)& Fd = SeqFil.ChangeValue(num);
3817   ChFiDS_CommonPoint& CV1 = Fd->ChangeVertex(isfirst,1);
3818   ChFiDS_CommonPoint& CV2 = Fd->ChangeVertex(isfirst,2);
3819   //To evaluate the cloud of new points.
3820   Bnd_Box box1,box2;
3821
3822   // The cases of cap are processed separately from intersection.
3823   // ----------------------------------------------------------
3824
3825   TopoDS_Face Fv,Fad,Fop,Fopbis;
3826   TopoDS_Edge Arcpiv,Arcprol,Arcspine,Arcprolbis;
3827   if(isfirst) Arcspine = spine->Edges(1);
3828   else Arcspine = spine->Edges(spine->NbEdges());
3829   TopAbs_Orientation OArcprolbis;
3830 #ifndef DEB
3831   TopAbs_Orientation OArcprolv = TopAbs_FORWARD, OArcprolop = TopAbs_FORWARD;
3832 #else
3833   TopAbs_Orientation OArcprolv, OArcprolop;
3834 #endif
3835   Standard_Integer ICurve;
3836   Handle(BRepAdaptor_HSurface) HBs  = new BRepAdaptor_HSurface();
3837   Handle(BRepAdaptor_HSurface) HBad = new BRepAdaptor_HSurface();
3838   Handle(BRepAdaptor_HSurface) HBop = new BRepAdaptor_HSurface();
3839   BRepAdaptor_Surface& Bs  = HBs->ChangeSurface();
3840   BRepAdaptor_Surface& Bad = HBad->ChangeSurface();
3841   BRepAdaptor_Surface& Bop = HBop->ChangeSurface();
3842   Handle(Geom_Curve) Cc;
3843   Handle(Geom2d_Curve) Pc,Ps;
3844   Standard_Real Ubid,Vbid;//,mu,Mu,mv,Mv;
3845 #ifndef DEB
3846   Standard_Real Udeb = 0.,Ufin = 0.;
3847 #else
3848   Standard_Real Udeb,Ufin;
3849 #endif
3850   //gp_Pnt2d UVf1,UVl1,UVf2,UVl2;
3851   //Standard_Real Du,Dv,Step;
3852   Standard_Boolean inters = Standard_True;
3853   Standard_Integer IFadArc = 1, IFopArc = 2;
3854   Fop = TopoDS::Face(DStr.Shape(Fd->Index(IFopArc)));
3855   TopExp_Explorer ex;
3856
3857 #ifdef DEB
3858   ChFi3d_InitChron(ch); // init perf condition
3859 #endif
3860   {
3861     if(!CV1.IsOnArc() && !CV2.IsOnArc())
3862       Standard_Failure::Raise("Corner intersmore : no point on arc");
3863     else if(CV1.IsOnArc() && CV2.IsOnArc()){
3864       Standard_Boolean sur1 = 0, sur2 = 0;
3865       for(ex.Init(CV1.Arc(),TopAbs_VERTEX); ex.More(); ex.Next()){
3866         if(Vtx.IsSame(ex.Current())) {
3867           sur1 = 1;
3868           break;
3869         }
3870       }
3871       for(ex.Init(CV2.Arc(),TopAbs_VERTEX); ex.More(); ex.Next()){
3872         if(Vtx.IsSame(ex.Current())){
3873           sur2 = 1;
3874           break;
3875         }
3876       }
3877       if(sur2) IFadArc = 2;
3878     }
3879     else if(CV2.IsOnArc()) IFadArc = 2;
3880     IFopArc = 3-IFadArc;
3881
3882     Arcpiv = Fd->Vertex(isfirst,IFadArc).Arc();
3883     Fad = TopoDS::Face(DStr.Shape(Fd->Index(IFadArc)));
3884     Fop = TopoDS::Face(DStr.Shape(Fd->Index(IFopArc)));
3885     TopTools_ListIteratorOfListOfShape It;
3886     // The face at end is returned without control of its unicity.
3887     for(It.Initialize(myEFMap(Arcpiv));It.More();It.Next()) {
3888       if(!Fad.IsSame(It.Value())){
3889         Fv = TopoDS::Face(It.Value());
3890         break;
3891       }
3892     }
3893
3894     // does the face at end contain the Vertex ?
3895     Standard_Boolean isinface = Standard_False;
3896     for (ex.Init(Fv,TopAbs_VERTEX); ex.More(); ex.Next()){
3897       if (ex.Current().IsSame(Vtx)) {
3898         isinface = Standard_True;
3899         break;
3900       }
3901     }
3902     if (!isinface) {
3903       IFadArc = 3-IFadArc;
3904       IFopArc = 3-IFopArc;
3905       Arcpiv = Fd->Vertex(isfirst,IFadArc).Arc();
3906       Fad = TopoDS::Face(DStr.Shape(Fd->Index(IFadArc)));
3907       Fop = TopoDS::Face(DStr.Shape(Fd->Index(IFopArc)));
3908       //TopTools_ListIteratorOfListOfShape It;
3909     // The face at end is returned without control of its unicity.
3910      for(It.Initialize(myEFMap(Arcpiv));It.More();It.Next()) {
3911         if(!Fad.IsSame(It.Value())){
3912           Fv = TopoDS::Face(It.Value());
3913           break;
3914         }
3915       }
3916     }
3917
3918     if(Fv.IsNull()) StdFail_NotDone::Raise
3919       ("OneCorner : face at end is not found");
3920
3921     Fv.Orientation(TopAbs_FORWARD);
3922     Fad.Orientation(TopAbs_FORWARD);
3923
3924     // In the same way the edge to be extended is returned.
3925     for(It.Initialize(myVEMap(Vtx));It.More() && Arcprol.IsNull();It.Next()){
3926       if(!Arcpiv.IsSame(It.Value())){
3927         for(ex.Init(Fv,TopAbs_EDGE); ex.More(); ex.Next()){
3928           if(It.Value().IsSame(ex.Current())) {
3929             Arcprol = TopoDS::Edge(It.Value());
3930             OArcprolv = ex.Current().Orientation();
3931             break;
3932           }
3933         }
3934       }
3935     }
3936
3937     //Fopbis is the face containing the trace of fillet CP.Arc() which of does not contain Vtx.
3938     //Normallly Fobis is either the same as Fop (cylinder), or Fobis is G1 with Fop.
3939     Fopbis.Orientation(TopAbs_FORWARD);
3940
3941     //Fop calls the 4th face non-used for the vertex
3942     cherche_face(myVFMap(Vtx),Arcprol,Fad,Fv,Fv,Fopbis);
3943     Fop.Orientation(TopAbs_FORWARD);
3944
3945     if(Arcprol.IsNull()) StdFail_NotDone::Raise
3946       ("OneCorner : edge to be extended is not found");
3947     for(ex.Init(Fopbis,TopAbs_EDGE); ex.More(); ex.Next()){
3948       if(Arcprol.IsSame(ex.Current())) {
3949         OArcprolop = ex.Current().Orientation();
3950         break;
3951       }
3952     }
3953     TopoDS_Face FFv;
3954     Standard_Real tol;
3955     Standard_Integer prol;
3956     BRep_Builder BRE;
3957     Handle(Geom_Surface ) Sface;
3958     Sface=BRep_Tool::Surface(Fv);
3959     ChFi3d_ExtendSurface(Sface,prol);
3960     tol=BRep_Tool::Tolerance(Fv);
3961     BRE.MakeFace(FFv,Sface,tol);
3962     if (prol) {
3963       Bs.Initialize(FFv,Standard_False);
3964       DStr.SetNewSurface(Fv,Sface);
3965     }
3966     else Bs.Initialize(Fv,Standard_False);
3967     Bad.Initialize(Fad);
3968     Bop.Initialize(Fop);
3969   }
3970   // it is necessary to modify the CommonPoint
3971   // in the space and its parameter in FaceInterference.
3972   // So both of them are returned in references
3973   // non const. Attention the modifications are done behind
3974   // CV1,CV2,Fi1,Fi2.
3975   ChFiDS_CommonPoint& CPopArc = Fd->ChangeVertex(isfirst,IFopArc);
3976   ChFiDS_FaceInterference& FiopArc = Fd->ChangeInterference(IFopArc);
3977   ChFiDS_CommonPoint& CPadArc = Fd->ChangeVertex(isfirst,IFadArc);
3978   ChFiDS_FaceInterference& FiadArc = Fd->ChangeInterference(IFadArc);
3979   // the parameter of the vertex is initialized with the value 
3980   // of its opposing vertex (point on arc).
3981   Standard_Real wop = Fd->ChangeInterference(IFadArc).Parameter(isfirst);
3982   Handle(Geom_Curve) c3df;
3983   Handle(GeomAdaptor_HSurface)
3984     HGs = new GeomAdaptor_HSurface(DStr.Surface(Fd->Surf()).Surface());
3985   gp_Pnt2d p2dbout;
3986   {
3987
3988     // add here more or less restrictive criteria to
3989     // decide if the intersection with face is done at the
3990     // extended end or if there will be a cap on sharp end.
3991     c3df = DStr.Curve(FiopArc.LineIndex()).Curve();
3992     Standard_Real uf = FiopArc.FirstParameter();
3993     Standard_Real ul = FiopArc.LastParameter();
3994       Handle(GeomAdaptor_HCurve) Hc3df;
3995     if(c3df->IsPeriodic()){
3996       Hc3df = new GeomAdaptor_HCurve(c3df);
3997     }
3998     else{
3999       Hc3df = new GeomAdaptor_HCurve(c3df,uf,ul);
4000     }
4001     inters = Update(HBs,Hc3df,FiopArc,CPopArc,p2dbout,isfirst,wop);
4002 //  Modified by Sergey KHROMOV - Fri Dec 21 18:08:27 2001 Begin
4003 //  if(!inters && BRep_Tool::Continuity(Arcprol,Fv,Fop) != GeomAbs_C0){
4004     if(!inters && isTangentFaces(Arcprol,Fv,Fop)){
4005 //  Modified by Sergey KHROMOV - Fri Dec 21 18:08:29 2001 End
4006       // Arcprol is an edge of tangency, ultimate adjustment by an extrema curve/curve is attempted.
4007       Standard_Real ff,ll;
4008       Handle(Geom2d_Curve) gpcprol = BRep_Tool::CurveOnSurface(Arcprol,Fv,ff,ll);
4009       Handle(Geom2dAdaptor_HCurve) pcprol = new Geom2dAdaptor_HCurve(gpcprol);
4010       Standard_Real partemp = BRep_Tool::Parameter(Vtx,Arcprol);
4011       inters = Update(HBs,pcprol,HGs,FiopArc,CPopArc,p2dbout,
4012                       isfirst,partemp,wop,10*tolesp);
4013     }
4014     Handle(BRepAdaptor_HCurve2d) pced = new BRepAdaptor_HCurve2d();
4015     pced->ChangeCurve2d().Initialize(CPadArc.Arc(),Fv);
4016     Update(HBs,pced,HGs,FiadArc,CPadArc,isfirst);
4017   }
4018 #ifdef DEB
4019   ChFi3d_ResultChron(ch,t_same); // result perf condition if (same)
4020   ChFi3d_InitChron(ch); // init perf condition if (inters)
4021 #endif
4022
4023   TopoDS_Edge edgecouture;
4024   Standard_Boolean couture,intcouture=Standard_False;;
4025   Standard_Real tolreached;
4026 #ifndef DEB
4027   Standard_Real par1 = 0.,par2 = 0.;
4028   Standard_Integer indpt =0,Icurv1 =0,Icurv2 =0;
4029 #else
4030   Standard_Real par1,par2;
4031   Standard_Integer indpt,Icurv1,Icurv2;
4032 #endif
4033   Handle(Geom_TrimmedCurve) curv1,curv2;
4034   Handle(Geom2d_Curve) c2d1,c2d2;
4035
4036   Standard_Integer Isurf=Fd->Surf();
4037
4038   if (inters){
4039     HGs = ChFi3d_BoundSurf(DStr,Fd,1,2);
4040     const ChFiDS_FaceInterference& Fi1 = Fd->InterferenceOnS1();
4041     const ChFiDS_FaceInterference& Fi2 = Fd->InterferenceOnS2();
4042     TColStd_Array1OfReal Pardeb(1,4),Parfin(1,4);
4043     gp_Pnt2d pfil1,pfac1,pfil2,pfac2;
4044     Handle(Geom2d_Curve) Hc1,Hc2;
4045     if( IFopArc == 1) pfac1 = p2dbout;
4046     else {
4047       Hc1 = BRep_Tool::CurveOnSurface(CV1.Arc(),Fv,Ubid,Ubid);
4048       pfac1 = Hc1->Value(CV1.ParameterOnArc());
4049     }
4050     if(IFopArc == 2) pfac2 = p2dbout;
4051     else {
4052       Hc2 = BRep_Tool::CurveOnSurface(CV2.Arc(),Fv,Ubid,Ubid);
4053       pfac2 = Hc2->Value(CV2.ParameterOnArc());
4054     }
4055     if(Fi1.LineIndex() != 0){
4056       pfil1 = Fi1.PCurveOnSurf()->Value(Fi1.Parameter(isfirst));
4057     }
4058     else{
4059       pfil1 = Fi1.PCurveOnSurf()->Value(Fi1.Parameter(!isfirst));
4060     }
4061     if(Fi2.LineIndex() != 0){
4062       pfil2 = Fi2.PCurveOnSurf()->Value(Fi2.Parameter(isfirst));
4063     }
4064     else{
4065       pfil2 = Fi2.PCurveOnSurf()->Value(Fi2.Parameter(!isfirst));
4066     }
4067     ChFi3d_Recale(Bs,pfac1,pfac2,(IFadArc == 1));
4068     Pardeb(1)= pfil1.X();Pardeb(2) = pfil1.Y();
4069     Pardeb(3)= pfac1.X();Pardeb(4) = pfac1.Y();
4070     Parfin(1)= pfil2.X();Parfin(2) = pfil2.Y();
4071     Parfin(3)= pfac2.X();Parfin(4) = pfac2.Y();
4072     Standard_Real uu1,uu2,vv1,vv2;
4073     ChFi3d_Boite(pfac1,pfac2,uu1,uu2,vv1,vv2);
4074     ChFi3d_BoundFac(Bs,uu1,uu2,vv1,vv2);
4075
4076     if (!ChFi3d_ComputeCurves(HGs,HBs,Pardeb,Parfin,Cc,
4077                               Ps,
4078                               Pc,tolesp,tol2d,tolreached))
4079     Standard_Failure::Raise("OneCorner : failed calculation intersection");
4080
4081     Udeb = Cc->FirstParameter();
4082     Ufin = Cc->LastParameter();
4083
4084     // check if the curve has an intersection with sewing edge
4085
4086     ChFi3d_Couture(Fv,couture,edgecouture);
4087
4088     if (couture  && !BRep_Tool::Degenerated(edgecouture)) {
4089
4090       //Standard_Real Ubid,Vbid;
4091       Handle (Geom_Curve) C=BRep_Tool::Curve(edgecouture,Ubid,Vbid);
4092       Handle(Geom_TrimmedCurve) Ctrim=new Geom_TrimmedCurve (C,Ubid,Vbid);
4093       GeomAdaptor_Curve cur1(Ctrim->BasisCurve());
4094       GeomAdaptor_Curve cur2(Cc);
4095       Extrema_ExtCC extCC (cur1,cur2);
4096       if (extCC.IsDone()&&extCC.NbExt()!=0)
4097         {
4098           Standard_Integer imin=0;
4099           Standard_Real dist2min = RealLast();
4100           for (Standard_Integer i = 1; i <= extCC.NbExt(); i++)
4101             if (extCC.SquareDistance(i) < dist2min)
4102               {
4103                 dist2min = extCC.SquareDistance(i);
4104                 imin = i;
4105               }
4106       if (dist2min <= Precision::SquareConfusion())
4107             {
4108               Extrema_POnCurv ponc1,ponc2;
4109               extCC.Points( imin, ponc1, ponc2 );
4110               par1 = ponc1.Parameter();
4111               par2 = ponc2.Parameter();
4112               Standard_Real Tol = 1.e-4;
4113               if (Abs(par2-Udeb) > Tol && Abs(Ufin-par2) > Tol)
4114                 {
4115                   gp_Pnt P1=ponc1.Value();
4116                   TopOpeBRepDS_Point tpoint( P1, Tol );
4117                   indpt = DStr.AddPoint(tpoint);
4118                   intcouture = Standard_True;
4119                   curv1 = new Geom_TrimmedCurve(Cc,Udeb,par2);
4120                   curv2 = new Geom_TrimmedCurve(Cc,par2,Ufin);
4121                   TopOpeBRepDS_Curve tcurv1(curv1,tolreached);
4122                   TopOpeBRepDS_Curve tcurv2(curv2,tolreached);
4123                   Icurv1=DStr.AddCurve(tcurv1);
4124                   Icurv2=DStr.AddCurve(tcurv2);
4125                 }
4126             }
4127         }
4128     }
4129   }
4130
4131   else{
4132     Standard_NotImplemented::Raise("OneCorner : cap not written");
4133   }
4134   Standard_Integer IShape = DStr.AddShape(Fv);
4135 #ifndef DEB
4136   TopAbs_Orientation Et = TopAbs_FORWARD;
4137 #else
4138   TopAbs_Orientation Et;
4139 #endif
4140   if(IFadArc == 1){
4141     TopExp_Explorer Exp;
4142     for (Exp.Init(Fv.Oriented(TopAbs_FORWARD),
4143                   TopAbs_EDGE);Exp.More();Exp.Next()) {
4144       if (Exp.Current().IsSame(CV1.Arc())) {
4145         Et = TopAbs::Reverse(TopAbs::Compose
4146                              (Exp.Current().Orientation(),
4147                               CV1.TransitionOnArc()));
4148         break;
4149       }
4150     }
4151   }
4152   else{
4153     TopExp_Explorer Exp;
4154     for (Exp.Init(Fv.Oriented(TopAbs_FORWARD),
4155                   TopAbs_EDGE);Exp.More();Exp.Next()) {
4156       if (Exp.Current().IsSame(CV2.Arc())) {
4157         Et = TopAbs::Compose(Exp.Current().Orientation(),
4158                              CV2.TransitionOnArc());
4159         break;
4160       }
4161     }
4162
4163 //
4164
4165
4166   }
4167
4168 #ifdef DEB
4169   ChFi3d_ResultChron(ch ,t_inter); //result perf condition if (inter)
4170   ChFi3d_InitChron(ch); // init perf condition  if ( inters)
4171 #endif
4172
4173   stripe->SetIndexPoint(ChFi3d_IndexPointInDS(CV1,DStr),isfirst,1);
4174   stripe->SetIndexPoint(ChFi3d_IndexPointInDS(CV2,DStr),isfirst,2);
4175
4176   if (!intcouture) {
4177 // there is no intersection with edge of sewing
4178 // curve Cc is stored in the stripe
4179 // the storage in the DS is done by FILDS.
4180
4181     TopOpeBRepDS_Curve Tc(Cc,tolreached);
4182     ICurve = DStr.AddCurve(Tc);
4183     Handle(TopOpeBRepDS_SurfaceCurveInterference)
4184       Interfc = ChFi3d_FilCurveInDS(ICurve,IShape,Pc,Et);
4185     DStr.ChangeShapeInterferences(IShape).Append(Interfc);
4186     stripe->ChangePCurve(isfirst)=Ps;
4187     stripe->SetCurve(ICurve,isfirst);
4188     stripe->SetParameters(isfirst,Udeb,Ufin);
4189    }
4190   else {
4191 // curves curv1 and curv2 are stored in the DS
4192 // these curves are not reconstructed by FILDS as
4193 // stripe->InDS(isfirst) is placed;
4194
4195     // interferences of curv1 and curv2 on Fv
4196     ComputeCurve2d(curv1,Fv,c2d1);
4197     Handle(TopOpeBRepDS_SurfaceCurveInterference) InterFv;
4198     InterFv = ChFi3d_FilCurveInDS(Icurv1,IShape,c2d1,Et);
4199     DStr.ChangeShapeInterferences(IShape).Append(InterFv);
4200     ComputeCurve2d(curv2,Fv,c2d2);
4201     InterFv = ChFi3d_FilCurveInDS(Icurv2,IShape,c2d2,Et);
4202     DStr.ChangeShapeInterferences(IShape).Append(InterFv);
4203      // interferences of curv1 and curv2 on Isurf
4204     if (Fd->Orientation()== Fv.Orientation()) Et=TopAbs::Reverse(Et);
4205     c2d1=new Geom2d_TrimmedCurve(Ps,Udeb,par2);
4206     InterFv = ChFi3d_FilCurveInDS(Icurv1,Isurf,c2d1,Et);
4207     DStr.ChangeSurfaceInterferences(Isurf).Append(InterFv);
4208     c2d2=new Geom2d_TrimmedCurve(Ps,par2,Ufin);
4209        InterFv = ChFi3d_FilCurveInDS(Icurv2,Isurf,c2d2,Et);
4210     DStr.ChangeSurfaceInterferences(Isurf).Append(InterFv);
4211
4212       // limitation of the sewing edge
4213     Standard_Integer Iarc=DStr.AddShape(edgecouture);
4214     Handle(TopOpeBRepDS_CurvePointInterference) Interfedge;
4215     TopAbs_Orientation ori;
4216     TopoDS_Vertex Vdeb,Vfin;
4217     Vdeb=TopExp::FirstVertex(edgecouture);
4218     Vfin=TopExp::LastVertex(edgecouture);
4219     Standard_Real pard,parf;
4220     pard=BRep_Tool::Parameter(Vdeb,edgecouture);
4221     parf=BRep_Tool::Parameter(Vfin,edgecouture);
4222     if (Abs(par1-pard)<Abs(parf-par1)) ori=TopAbs_FORWARD;
4223     else ori=TopAbs_REVERSED;
4224     Interfedge = ChFi3d_FilPointInDS(ori,Iarc,indpt,par1);
4225     DStr.ChangeShapeInterferences(Iarc).Append(Interfedge);
4226
4227     // creation of CurveInterferences from Icurv1 and Icurv2
4228     stripe->InDS(isfirst);
4229     Standard_Integer ind1= stripe->IndexPoint(isfirst,1);
4230     Standard_Integer ind2= stripe->IndexPoint(isfirst,2);
4231     Handle(TopOpeBRepDS_CurvePointInterference)
4232       interfprol = ChFi3d_FilPointInDS(TopAbs_FORWARD,Icurv1,ind1,Udeb);
4233     DStr.ChangeCurveInterferences(Icurv1).Append(interfprol);
4234     interfprol = ChFi3d_FilPointInDS(TopAbs_REVERSED,Icurv1,indpt,par2);
4235     DStr.ChangeCurveInterferences(Icurv1).Append(interfprol);
4236     interfprol = ChFi3d_FilPointInDS(TopAbs_FORWARD,Icurv2,indpt,par2);
4237     DStr.ChangeCurveInterferences(Icurv2).Append(interfprol);
4238     interfprol = ChFi3d_FilPointInDS(TopAbs_REVERSED,Icurv2,ind2,Ufin);
4239     DStr.ChangeCurveInterferences(Icurv2).Append(interfprol);
4240
4241   }
4242
4243   ChFi3d_EnlargeBox(HBs,Pc,Udeb,Ufin,box1,box2);
4244
4245   if( inters){
4246 //
4247
4248     // The small end of curve missing for the extension
4249     // of the face at end and the limitation of the opposing face is added.
4250
4251     // Above all the points cut the points with the edge of the spine.
4252     Standard_Integer IArcspine = DStr.AddShape(Arcspine);
4253     Standard_Integer IVtx = DStr.AddShape(Vtx);
4254     TopAbs_Orientation OVtx2;
4255 #ifndef DEB
4256     TopAbs_Orientation OVtx = TopAbs_FORWARD;
4257 #else
4258     TopAbs_Orientation OVtx;
4259 #endif
4260     for(ex.Init(Arcspine.Oriented(TopAbs_FORWARD),TopAbs_VERTEX);
4261         ex.More(); ex.Next()){
4262       if(Vtx.IsSame(ex.Current())) {
4263         OVtx = ex.Current().Orientation();
4264         break;
4265       }
4266     }
4267     OVtx = TopAbs::Reverse(OVtx);
4268     Standard_Real parVtx = BRep_Tool::Parameter(Vtx,Arcspine);
4269     Handle(TopOpeBRepDS_CurvePointInterference)
4270       interfv = ChFi3d_FilVertexInDS(OVtx,IArcspine,IVtx,parVtx);
4271     DStr.ChangeShapeInterferences(IArcspine).Append(interfv);
4272
4273
4274     //Modif of lvt to find the suite of Arcprol in the other face
4275     {
4276       TopTools_ListIteratorOfListOfShape It;
4277       for (It.Initialize(myVEMap(Vtx)); It.More(); It.Next()){
4278         if (!(Arcprol.IsSame(It.Value()) ||
4279               Arcspine.IsSame(It.Value()) ||
4280               Arcpiv.IsSame(It.Value()))) {
4281           Arcprolbis = TopoDS::Edge(It.Value());
4282           break;
4283         }
4284       }
4285     }
4286     //end of modif
4287
4288     //Now the missing curves are constructed.
4289     for(ex.Init(Arcprolbis.Oriented(TopAbs_FORWARD),TopAbs_VERTEX);
4290         ex.More(); ex.Next()){
4291       if(Vtx.IsSame(ex.Current())) {
4292         OVtx2 = ex.Current().Orientation();
4293         break;
4294       }
4295     }
4296     for(ex.Init(Arcprol.Oriented(TopAbs_FORWARD),TopAbs_VERTEX);
4297         ex.More(); ex.Next()){
4298       if(Vtx.IsSame(ex.Current())) {
4299         OVtx = ex.Current().Orientation();
4300         break;
4301       }
4302     }
4303 // it is checked if Fop has a sewing edge
4304
4305 //     TopoDS_Edge edgecouture;
4306 //     Standard_Boolean couture;
4307     ChFi3d_Couture(Fop,couture,edgecouture);
4308     Handle(Geom2d_Curve) Hc;
4309 //    parVtx = BRep_Tool::Parameter(Vtx,Arcprol);
4310     const ChFiDS_FaceInterference& Fiop = Fd->Interference(IFopArc);
4311     gp_Pnt2d pop1, pop2, pv1, pv2;
4312     //deb modif
4313     parVtx = BRep_Tool::Parameter(Vtx,Arcprolbis);
4314 //  Modified by skv - Thu Aug 21 11:55:58 2008 OCC20222 Begin
4315 //    if(Fop.IsSame(Fopbis)) OArcprolbis = OArcprolop;
4316 //    else OArcprolbis = Arcprolbis.Orientation();
4317     if(Fop.IsSame(Fopbis)) {
4318       OArcprolbis = OArcprolop;
4319     } else {
4320       for(ex.Init(Fop,TopAbs_EDGE); ex.More(); ex.Next()){
4321         if(Arcprolbis.IsSame(ex.Current())) {
4322           OArcprolbis = ex.Current().Orientation();
4323           break;
4324         }
4325       }
4326     }
4327 //  Modified by skv - Thu Aug 21 11:55:58 2008 OCC20222 End
4328     //fin modif
4329     Hc = BRep_Tool::CurveOnSurface(Arcprolbis,Fop,Ubid,Ubid);
4330     pop1 = Hc->Value(parVtx);
4331     pop2 = Fiop.PCurveOnFace()->Value(Fiop.Parameter(isfirst));
4332     Hc = BRep_Tool::CurveOnSurface(Arcprol,Fv,Ubid,Ubid);
4333     //modif
4334     parVtx = BRep_Tool::Parameter(Vtx,Arcprol);
4335     //fin modif
4336     pv1 = Hc->Value(parVtx);
4337     pv2 = p2dbout;
4338     ChFi3d_Recale(Bs,pv1,pv2,1);
4339     TColStd_Array1OfReal Pardeb(1,4),Parfin(1,4);
4340     Pardeb(1) = pop1.X(); Pardeb(2) = pop1.Y();
4341     Pardeb(3) = pv1.X();  Pardeb(4) = pv1.Y();
4342     Parfin(1) = pop2.X(); Parfin(2) = pop2.Y();
4343     Parfin(3) = pv2.X();  Parfin(4) = pv2.Y();
4344     Standard_Real uu1,uu2,vv1,vv2;
4345     ChFi3d_Boite(pv1,pv2,uu1,uu2,vv1,vv2);
4346     ChFi3d_BoundFac(Bs,uu1,uu2,vv1,vv2);
4347     ChFi3d_Boite(pop1,pop2,uu1,uu2,vv1,vv2);
4348     ChFi3d_BoundFac(Bop,uu1,uu2,vv1,vv2);
4349
4350     Handle(Geom_Curve) zob3d;
4351     Handle(Geom2d_Curve) zob2dop, zob2dv;
4352 //    Standard_Real tolreached;
4353     if (!ChFi3d_ComputeCurves(HBop,HBs,Pardeb,Parfin,zob3d,zob2dop,
4354                               zob2dv,tolesp,tol2d,tolreached))
4355       Standard_Failure::Raise("OneCorner : echec calcul intersection");
4356
4357     Udeb = zob3d->FirstParameter();
4358     Ufin = zob3d->LastParameter();
4359     TopOpeBRepDS_Curve Zob(zob3d,tolreached);
4360     Standard_Integer IZob = DStr.AddCurve(Zob);
4361
4362     // it is not determined if the curve has an intersection with the sewing edge
4363
4364
4365     {
4366       Et = TopAbs::Reverse(TopAbs::Compose(OVtx,OArcprolv));
4367       Standard_Integer Iop = DStr.AddShape(Fop);
4368       Handle(TopOpeBRepDS_SurfaceCurveInterference)
4369         InterFv = ChFi3d_FilCurveInDS(IZob,IShape,zob2dv,Et);
4370       DStr.ChangeShapeInterferences(IShape).Append(InterFv);
4371       //OVtx = TopAbs::Reverse(OVtx);
4372 //  Modified by skv - Thu Aug 21 11:55:58 2008 OCC20222 Begin
4373 //      Et = TopAbs::Reverse(TopAbs::Compose(OVtx,OArcprolbis));
4374       Et = TopAbs::Reverse(TopAbs::Compose(OVtx2,OArcprolbis));
4375 //  Modified by skv - Thu Aug 21 11:55:58 2008 OCC20222 End
4376       //OVtx = TopAbs::Reverse(OVtx);
4377 //      Et = TopAbs::Reverse(Et);
4378       Handle(TopOpeBRepDS_SurfaceCurveInterference)
4379         Interfop = ChFi3d_FilCurveInDS(IZob,Iop,zob2dop,Et);
4380       DStr.ChangeShapeInterferences(Iop).Append(Interfop);
4381       Handle(TopOpeBRepDS_CurvePointInterference)
4382         interfprol = ChFi3d_FilVertexInDS(TopAbs_FORWARD,IZob,IVtx,Udeb);
4383       DStr.ChangeCurveInterferences(IZob).Append(interfprol);
4384       Standard_Integer icc = stripe->IndexPoint(isfirst,IFopArc);
4385       interfprol = ChFi3d_FilPointInDS(TopAbs_REVERSED,IZob,icc,Ufin);
4386       DStr.ChangeCurveInterferences(IZob).Append(interfprol);
4387
4388     }
4389   }
4390   ChFi3d_EnlargeBox(DStr,stripe,Fd,box1,box2,isfirst);
4391   if(CV1.IsOnArc()){
4392     ChFi3d_EnlargeBox(CV1.Arc(),myEFMap(CV1.Arc()),CV1.ParameterOnArc(),box1);
4393   }
4394   if(CV2.IsOnArc()){
4395     ChFi3d_EnlargeBox(CV2.Arc(),myEFMap(CV2.Arc()),CV2.ParameterOnArc(),box2);
4396   }
4397   if  (!CV1.IsVertex())
4398     ChFi3d_SetPointTolerance(DStr,box1,stripe->IndexPoint(isfirst,1));
4399   if (!CV2.IsVertex())
4400     ChFi3d_SetPointTolerance(DStr,box2,stripe->IndexPoint(isfirst,2));
4401
4402 #ifdef DEB
4403    ChFi3d_ResultChron(ch, t_sameinter);//result perf condition if (same &&inter)
4404 #endif
4405 }