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