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