0022627: Change OCCT memory management defaults
[occt.git] / src / ChFi3d / ChFi3d_Builder_C2.cxx
CommitLineData
7fd59977 1// File: ChFi3d_Builder_C2.cxx
2// Created: Tue Aug 20 14:14:29 1996
3// Author: Stagiaire Xuan Tang PHAMPHU
4// <xpu@pomalox.paris1.matra-dtv.fr>
5
6#include <ChFi3d_Builder.jxx>
7#include <ChFi3d.hxx>
8#include <ChFi3d_Builder_0.hxx>
9
10#include <Precision.hxx>
11
12#include <Standard_Failure.hxx>
13#include <Standard_NotImplemented.hxx>
14#include <StdFail_NotDone.hxx>
15
16
17#include <gp_Pnt.hxx>
18#include <gp_Dir.hxx>
19#include <gp_Vec.hxx>
20#include <gp_Ax3.hxx>
21#include <gp_Pnt2d.hxx>
22#include <gp_Vec2d.hxx>
23#include <gp_Dir2d.hxx>
24#include <GeomLib.hxx>
25#include <Extrema_ExtPC.hxx>
26#include <Geom_Curve.hxx>
27#include <Geom2d_Curve.hxx>
28#include <Geom_BoundedCurve.hxx>
29
30#include <Geom2dAdaptor_HCurve.hxx>
31#include <GeomAbs_Shape.hxx>
32#include <GeomAdaptor_HCurve.hxx>
33#include <GeomAdaptor_Surface.hxx>
34#include <GeomAdaptor_HSurface.hxx>
35
36#include <Adaptor3d_HCurveOnSurface.hxx>
37#include <BRepAdaptor_HSurface.hxx>
38#include <BRepAdaptor_Curve.hxx>
39#include <BRepAdaptor_Curve2d.hxx>
40#include <BRepAdaptor_HCurve.hxx>
41#include <BRepAdaptor_Surface.hxx>
42
43#include <BRep_Tool.hxx>
44
45#include <TopoDS.hxx>
46#include <TopoDS_Shape.hxx>
47#include <TopoDS_Face.hxx>
48#include <TopoDS_Edge.hxx>
49#include <TopoDS_Vertex.hxx>
50
51#include <TopAbs.hxx>
52#include <TopAbs_ShapeEnum.hxx>
53#include <TopAbs_Orientation.hxx>
54
55#include <TopExp.hxx>
56#include <TopExp_Explorer.hxx>
57
58#include <TopTools_ListIteratorOfListOfShape.hxx>
59
60#include <TopOpeBRepDS_Point.hxx>
61#include <TopOpeBRepDS_Curve.hxx>
62#include <TopOpeBRepDS_Surface.hxx>
63#include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
64#include <TopOpeBRepDS_CurvePointInterference.hxx>
65#include <TopOpeBRepDS_DataStructure.hxx>
66#include <TopOpeBRepDS_ListOfInterference.hxx>
67
68#include <ChFiDS_HData.hxx>
69#include <ChFiDS_SurfData.hxx>
70#include <ChFiDS_CommonPoint.hxx>
71#include <ChFiDS_FaceInterference.hxx>
72#include <ChFiDS_SequenceOfSurfData.hxx>
73#include <ChFiDS_Stripe.hxx>
74#include <ChFiDS_ListIteratorOfListOfStripe.hxx>
75
76#include <TColStd_Array1OfReal.hxx>
77
78static void Reduce(const Standard_Real& p1,
79 const Standard_Real& p2,
80 Handle(GeomAdaptor_HSurface)& hs1,
81 Handle(GeomAdaptor_HSurface)& hs2)
82{
83 GeomAdaptor_Surface& s1 = hs1->ChangeSurface();
84 GeomAdaptor_Surface& s2 = hs2->ChangeSurface();
85 const Handle(Geom_Surface&) surf = s1.Surface();
86 Standard_Real ud,uf,vd,vf;
87 surf->Bounds(ud,uf,vd,vf);
88 Standard_Real milmoins = 0.51*vd+0.49*vf, milplus = 0.49*vd+0.51*vf;
89 if(p1 < p2) {
90 s1.Load(surf,ud,uf,vd,milmoins);
91 s2.Load(surf,ud,uf,milplus,vf);
92 }
93 else{
94 s1.Load(surf,ud,uf,milplus,vf);
95 s2.Load(surf,ud,uf,vd,milmoins);
96 }
97}
98
99static void Reduce(const Standard_Real& p1,
100 const Standard_Real& p2,
101 Handle(GeomAdaptor_HCurve)& hc)
102{
103 GeomAdaptor_Curve& c = hc->ChangeCurve();
104 Standard_Real f = c.FirstParameter();
105 Standard_Real l = c.LastParameter();
106 Standard_Real milmoins = 0.51*f+0.49*l, milplus = 0.49*f+0.51*l;
107 if(p1 < p2) {
108 c.Load(c.Curve(),f,milmoins);
109 }
110 else{
111 c.Load(c.Curve(),milplus,l);
112 }
113}
114
115
116//=======================================================================
117//function : PerformTwoCornerbyInter
81bba717 118//purpose : Performs PerformTwoCorner by intersection.
119// In case of Biseau for all cases the
120// path is used; 3D curve and 2 pcurves are approximated.
7fd59977 121//=======================================================================
122
123Standard_Integer ChFi3d_Builder::PerformTwoCornerbyInter(const Standard_Integer Index)
124
125{
126 done = 0;
127 const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index);
128 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
129
81bba717 130 //Information on fillets is extracted
7fd59977 131 //------------------------------------------------------
132
81bba717 133 //the first
7fd59977 134 //----------
135 ChFiDS_ListIteratorOfListOfStripe It;
136 It.Initialize(myVDataMap(Index));
137 Handle(ChFiDS_Stripe)& Corner1 = It.Value();
138 Standard_Integer Sens1;
139 Standard_Integer IFd1 =
140 ChFi3d_IndexOfSurfData(Vtx,Corner1,Sens1);
141 ChFiDS_SequenceOfSurfData& SeqFil1 =
142 Corner1->ChangeSetOfSurfData()->ChangeSequence();
143 Handle(ChFiDS_SurfData)& Fd1 = SeqFil1.ChangeValue(IFd1);
144
81bba717 145 //the second
7fd59977 146 //----------
147 It.Next();
148 Handle(ChFiDS_Stripe)& Corner2 = It.Value();
149 Standard_Integer Sens2;
150 Standard_Integer IFd2;
151 if(Corner2 == Corner1) {
152 Sens2 = -1;
153 IFd2 = Corner2->SetOfSurfData()->Length();
154 }
155 else{ IFd2 = ChFi3d_IndexOfSurfData(Vtx,Corner2,Sens2); }
156 ChFiDS_SequenceOfSurfData& SeqFil2 =
157 Corner2->ChangeSetOfSurfData()->ChangeSequence();
158 Handle(ChFiDS_SurfData)& Fd2 = SeqFil2.ChangeValue(IFd2);
159
81bba717 160 // The concavities are analysed in case of differents concavities,
161 // preview an evolutionary connection of type ThreeCorner of R to 0.
162 // Otherwise the opposite face
163 // and the eventual intersection of 2 pcurves on this face are found.
7fd59977 164
165 ChFiDS_State Stat1,Stat2;
166 Standard_Boolean isfirst1 = (Sens1 == 1);
167 Standard_Boolean isfirst2 = (Sens2 == 1);
168 Stat1 = Corner1->Spine()->Status(isfirst1);
169 Stat2 = Corner2->Spine()->Status(isfirst2);
170/*#ifdef DEB
171 Standard_Boolean evolcoin = ((Stat1 == ChFiDS_OnSame && Stat2 == ChFiDS_OnDiff) ||
172 (Stat2 == ChFiDS_OnSame && Stat1 == ChFiDS_OnDiff));
173#endif*/
174 Standard_Boolean OkinterCC,Okvisavis,SameSide;
175 Standard_Integer IFaCo1,IFaCo2;
176 Standard_Real UIntPC1,UIntPC2;
177 TopoDS_Face FaCo;
178 OkinterCC = ChFi3d_IsInFront(DStr,Corner1,Corner2,IFd1,IFd2,Sens1,Sens2,
179 UIntPC1,UIntPC2,FaCo,SameSide,
180 IFaCo1,IFaCo2,Okvisavis,Vtx,Standard_True);
181 if (!Okvisavis) {
182#if DEB
183 cout<<"TwoCorner : pas de face commune"<<endl;
184#endif
185 done=Standard_False;
186 return done;
187 }
188 if (!OkinterCC) {
81bba717 189 // The intersection of pcurves is calculated without restricting them by
190 // common points.
7fd59977 191 OkinterCC= ChFi3d_IsInFront(DStr,Corner1,Corner2,IFd1,IFd2,Sens1,Sens2,
192 UIntPC1,UIntPC2,FaCo,SameSide,
193 IFaCo1,IFaCo2,Okvisavis,Vtx,Standard_True,1);
194 }
195
196 if (!Okvisavis) {
197#if DEB
81bba717 198 cout<<"TwoCorner : no common face"<<endl;
7fd59977 199#endif
200 done=Standard_False;
201 return done;
202 }
203 if (!OkinterCC) {
204#if DEB
81bba717 205 cout<<"biseau : failed intersection of tangency lines on common face"<<endl;
7fd59977 206#endif
207 done=Standard_False;
208 return done;
209 }
210 Standard_Integer IFaArc1 = 3-IFaCo1, IFaArc2 = 3-IFaCo2;
211
81bba717 212 // It is checked if the fillets have a commonpoint on a common arc.
213 // This edge is the pivot of the bevel or of the kneecap.
7fd59977 214
215 ChFiDS_CommonPoint& CP1 = Fd1->ChangeVertex(isfirst1,IFaArc1);
216 ChFiDS_CommonPoint& CP2 = Fd2->ChangeVertex(isfirst2,IFaArc2);
217
218 if (!CP1.IsOnArc() || !CP2.IsOnArc()) {
219#if DEB
81bba717 220 cout<<"fail 1 of 2 fillets are not on arc"<<endl;
7fd59977 221#endif
222 done=Standard_False;
223 return done;
224 }
225 if ( ! CP1.Arc().IsSame( CP2.Arc()) ) {
226 // look like OnSame + OnDiff case (eap, Arp 9 2002, occ266)
227#if DEB
81bba717 228 cout<<"PerformTwoCornerbyInter(): fillets are not on the same arc"<<endl;
7fd59977 229#endif
230 done = Standard_True;
231 PerformMoreThreeCorner(Index, 2);
232 return done;
233 }
234
235 TopoDS_Edge pivot;
236 pivot = CP1.Arc();
237 Standard_Real parCP1 = CP1.ParameterOnArc();
238 Standard_Real parCP2 = CP2.ParameterOnArc();
239 Handle(BRepAdaptor_HCurve) Hpivot = new BRepAdaptor_HCurve(pivot);
240 if (!pivot.IsSame(CP2.Arc())){
241 Handle(Geom_Curve) csau;
242 Standard_Real ubid,vbid;
243 csau=BRep_Tool::Curve(pivot,ubid,vbid );
244 Handle(Geom_BoundedCurve) C1= Handle(Geom_BoundedCurve)::DownCast(csau);
245 if (! C1.IsNull()) {
246 GeomLib::ExtendCurveToPoint(C1,CP2.Point(),1,Standard_False);
247 GeomAdaptor_Curve cad;
248 cad.Load(C1);
249 Extrema_ExtPC ext(CP2.Point(),cad,1.e-4);
250 parCP2 = ext.Point(1).Parameter();
251 }
252 }
253 gp_Pnt psp1 = Hpivot->Value(parCP1);
254 gp_Pnt psp2 = Hpivot->Value(parCP2);
255 Standard_Real sameparam = (psp1.Distance(psp2) < 10 * tolesp);
256
257 TopoDS_Face FF1 = TopoDS::Face(DStr.Shape(Fd1->Index(IFaArc1)));
258 TopoDS_Face FF2 = TopoDS::Face(DStr.Shape(Fd2->Index(IFaArc2)));
259 TopTools_ListIteratorOfListOfShape Kt;
260 Standard_Boolean ok1 = Standard_False, ok2 = Standard_False;
261 for (Kt.Initialize(myEFMap(pivot)); Kt.More(); Kt.Next()){
262 TopoDS_Face F = TopoDS::Face(Kt.Value());
263 if(!ok1 && FF1.IsSame(F)){
264 ok1 = Standard_True;
265 }
266 if(!ok2 && FF2.IsSame(F)){
267 ok2 = Standard_True;
268 }
269 }
270 if(!ok1 || !ok2){
7fd59977 271#if DEB
81bba717 272 cout<<"fail one of surfaces has no common base face with the pivot edge"<<endl;
7fd59977 273#endif
274 done=Standard_False;
275 return done;
276 }
277
278 Handle(GeomAdaptor_HSurface) HS1, HS2;
279 HS1 = ChFi3d_BoundSurf (DStr,Fd1,IFaCo1,IFaArc1);
280 HS2 = ChFi3d_BoundSurf (DStr,Fd2,IFaCo2,IFaArc2);
281
282 TColStd_Array1OfReal Pardeb(1,4),Parfin(1,4);
283
284 Handle(Geom2d_Curve) PGc1,PGc2;
285 Handle(Geom_Curve) Gc;
286
287 if(sameparam) {
81bba717 288 // Side common face, calculation of Pardeb.
7fd59977 289 ChFi3d_ComputesIntPC (Fd1->Interference(IFaCo1),
290 Fd2->Interference(IFaCo2),
291 HS1,HS2,UIntPC1,UIntPC2);
292 gp_Pnt2d UV;
293 UV = Fd1->Interference(IFaCo1).PCurveOnSurf()->Value(UIntPC1);
294 Pardeb(1)= UV.X(); Pardeb(2)=UV.Y();
295 UV = Fd2->Interference(IFaCo2).PCurveOnSurf()->Value(UIntPC2);
296 Pardeb(3)= UV.X(); Pardeb(4)=UV.Y();
297 gp_Pnt PFaCo = HS1->Surface().Value(Pardeb(1),Pardeb(2));
298
81bba717 299 // Side arc, calculation of Parfin.
7fd59977 300 Standard_Real UIntArc1 = Fd1->Interference(IFaArc1).Parameter(isfirst1);
301 Standard_Real UIntArc2 = Fd2->Interference(IFaArc2).Parameter(isfirst2);
302
303 ChFi3d_ComputesIntPC (Fd1->Interference(IFaArc1),Fd2->Interference(IFaArc2),
304 HS1,HS2,UIntArc1,UIntArc2);
305 UV = Fd1->Interference(IFaArc1).PCurveOnSurf()->Value(UIntArc1);
306 Parfin(1)= UV.X(); Parfin(2)=UV.Y();
307 UV = Fd2->Interference(IFaArc2).PCurveOnSurf()->Value(UIntArc2);
308 Parfin(3)= UV.X(); Parfin(4)=UV.Y();
309
310 if(Fd1->Surf() == Fd2->Surf()){
311 Reduce(UIntPC1,UIntPC2,HS1,HS2);
312 }
313
314 Standard_Real tolreached;
315 if (IFaCo1 == 1 &&
316 !ChFi3d_ComputeCurves(HS1,HS2,Pardeb,Parfin,Gc,
317 PGc1,PGc2,tolesp,tol2d,tolreached)) {
318#if DEB
81bba717 319 cout<<"failed to calculate bevel error interSS"<<endl;
7fd59977 320#endif
321 done=Standard_False;
322 return done;
323 }
324 else if (IFaCo1 == 2 &&
325 !ChFi3d_ComputeCurves(HS1,HS2,Parfin,Pardeb,Gc,
326 PGc1,PGc2,tolesp,tol2d,tolreached)) {
327#if DEB
81bba717 328 cout<<"failed to calculate bevel error interSS"<<endl;
7fd59977 329#endif
330 done=Standard_False;
331 return done;
332 }
81bba717 333 // CornerData are updated with results of the intersection.
7fd59977 334 Standard_Real WFirst = Gc->FirstParameter();
335 Standard_Real WLast = Gc->LastParameter();
336 Standard_Integer Ipoin1;
337 Standard_Integer Ipoin2;
338 ChFiDS_CommonPoint& cpco1 = Fd1->ChangeVertex(isfirst1,IFaCo1);
339 ChFiDS_CommonPoint& cpco2 = Fd2->ChangeVertex(isfirst2,IFaCo2);
340 Standard_Real tolpco = Max(cpco1.Tolerance(),cpco2.Tolerance());
341 ChFiDS_CommonPoint& cparc1 = Fd1->ChangeVertex(isfirst1,IFaArc1);
342 ChFiDS_CommonPoint& cparc2 = Fd2->ChangeVertex(isfirst2,IFaArc2);
343 Standard_Real tolparc = Max(cparc1.Tolerance(),cparc2.Tolerance());
344 Standard_Integer ICurv = DStr.AddCurve(TopOpeBRepDS_Curve(Gc,tolreached));
345 //Corner1
346 Corner1->SetParameters(isfirst1,WFirst,WLast);
347 Corner1->SetCurve(ICurv,isfirst1);
348 Corner1->ChangePCurve(isfirst1) = PGc1;
349 cpco1.Reset();
350 cpco1.SetPoint(PFaCo);
351 cpco1.SetTolerance(Max(tolreached,tolpco));
352 Fd1->ChangeInterference(IFaCo1).SetParameter(UIntPC1,isfirst1);
353 tolparc = Max(tolparc,tolreached);
354 cparc1.SetTolerance(Max(tolparc,tolreached));
355 Ipoin1 = ChFi3d_IndexPointInDS(Fd1->Vertex(isfirst1,1),DStr);
356 Corner1->SetIndexPoint(Ipoin1,isfirst1,1);
357 Ipoin2 = ChFi3d_IndexPointInDS(Fd1->Vertex(isfirst1,2),DStr);
358 Corner1->SetIndexPoint(Ipoin2,isfirst1,2);
359 //Corner2
360 Corner2->SetParameters(isfirst2,WFirst,WLast);
361 Corner2->SetCurve(ICurv,isfirst2);
362 Corner2->ChangePCurve(isfirst2) = PGc2;
363 Fd2->ChangeInterference(IFaCo2).SetParameter(UIntPC2,isfirst2);
364 Fd2->ChangeVertex(isfirst2,IFaCo2) = Fd1->Vertex(isfirst1,IFaCo1);
365 Fd2->ChangeVertex(isfirst2,IFaArc2) = Fd1->Vertex(isfirst1,IFaArc1);
366 if (IFaCo1!=IFaCo2) Corner2->SetOrientation(TopAbs_REVERSED,isfirst2);
367 Corner2->SetIndexPoint(Corner1->IndexPoint(isfirst1,IFaCo1),
368 isfirst2,IFaCo2);
369 Corner2->SetIndexPoint(Corner1->IndexPoint(isfirst1,IFaArc1),
370 isfirst2,IFaArc2);
81bba717 371 //The tolerances of points are updated.
7fd59977 372 Bnd_Box bco,barc;
373 if(IFaCo1 == 1) ChFi3d_EnlargeBox(DStr,Corner1,Fd1,bco,barc,isfirst1);
374 else ChFi3d_EnlargeBox(DStr,Corner1,Fd1,barc,bco,isfirst1);
375 if(IFaCo2 == 1) ChFi3d_EnlargeBox(DStr,Corner2,Fd2,bco,barc,isfirst2);
376 else ChFi3d_EnlargeBox(DStr,Corner2,Fd2,barc,bco,isfirst2);
377 const ChFiDS_CommonPoint& cparc = Fd1->Vertex(isfirst1,IFaArc1);
378 ChFi3d_EnlargeBox(cparc.Arc(),myEFMap(cparc.Arc()),cparc.ParameterOnArc(),barc);
379 ChFi3d_SetPointTolerance(DStr,barc,Corner1->IndexPoint(isfirst1,IFaArc1));
380 ChFi3d_SetPointTolerance(DStr,bco,Corner1->IndexPoint(isfirst1,IFaCo1));
381 }
382 else {
81bba717 383 // It is necessary to identify the border surface,
384 // find the end point of the intersection Surf/Surf
385 // by the intersection of the tangency line of the small
386 // on the opposing face with the surface of the big,
387 // and finally intersect the big with the face at end
388 // between this point and the point on arc.
7fd59977 389#ifndef DEB
390 Standard_Boolean parcrois = Standard_False ;
391#else
392 Standard_Boolean parcrois;
393#endif
394 TopExp_Explorer Expl;
395 for(Expl.Init(pivot.Oriented(TopAbs_FORWARD),TopAbs_VERTEX);
396 Expl.More(); Expl.Next()){
397 if(Expl.Current().IsSame(Vtx)){
398 parcrois = (Expl.Current().Orientation() == TopAbs_FORWARD);
399 break;
400 }
401 }
402 Handle(ChFiDS_Stripe) BigCD, SmaCD;
403 Handle(ChFiDS_SurfData) BigFD, SmaFD;
404 Handle(GeomAdaptor_HSurface) BigHS, SmaHS;
405 Standard_Integer IFaCoBig, IFaCoSma, IFaArcBig, IFaArcSma;
406 Standard_Boolean isfirstBig, isfirstSma;
407 Standard_Real UIntPCBig, UIntPCSma;
408
409 if((parcrois && parCP2 > parCP1) || (!parcrois && parCP2 < parCP1)){
410 UIntPCBig = UIntPC2; UIntPCSma = UIntPC1;
411 BigHS = HS2; SmaHS = HS1;
412 BigCD = Corner2; SmaCD = Corner1;
413 BigFD = Fd2; SmaFD = Fd1;
414 IFaCoBig = IFaCo2; IFaCoSma = IFaCo1;
415 IFaArcBig = IFaArc2; IFaArcSma = IFaArc1;
416 isfirstBig = isfirst2; isfirstSma = isfirst1;
417 }
418 else{
419 UIntPCBig = UIntPC1, UIntPCSma = UIntPC2;
420 BigHS = HS1; SmaHS = HS2;
421 BigCD = Corner1; SmaCD = Corner2;
422 BigFD = Fd1; SmaFD = Fd2;
423 IFaCoBig = IFaCo1; IFaCoSma = IFaCo2;
424 IFaArcBig = IFaArc1; IFaArcSma = IFaArc2;
425 isfirstBig = isfirst1; isfirstSma = isfirst2;
426 }
427
81bba717 428 //Intersection of the big with the small :
7fd59977 429 //------------------------------------
430
81bba717 431 // Pardeb (parameters of point PFaCo)
432 // the intersection is checked
7fd59977 433 ChFi3d_ComputesIntPC (SmaFD->Interference(IFaCoSma),
434 BigFD->Interference(IFaCoBig),
435 SmaHS,BigHS,UIntPCSma,UIntPCBig);
436 gp_Pnt2d UVi;
437 UVi = BigFD->Interference(IFaCoBig).PCurveOnSurf()->Value(UIntPCBig);
438 Pardeb(3)= UVi.X(); Pardeb(4)=UVi.Y();
439 UVi = SmaFD->Interference(IFaCoSma).PCurveOnSurf()->Value(UIntPCSma);
440 Pardeb(1)= UVi.X(); Pardeb(2)=UVi.Y();
441 gp_Pnt PFaCo = SmaHS->Value(UVi.X(),UVi.Y());
442
81bba717 443 // Parfin (parameters of point PMil)
7fd59977 444 const ChFiDS_FaceInterference& FiArcSma = SmaFD->Interference(IFaArcSma);
445 Handle(Geom_Curve) ctg = DStr.Curve(FiArcSma.LineIndex()).Curve();
446 Handle(GeomAdaptor_HCurve) Hctg = new GeomAdaptor_HCurve();
447 GeomAdaptor_Curve& bid = Hctg->ChangeCurve();
448 Standard_Real temp,wi;
449
450 if (isfirstSma) {
451 wi = temp = FiArcSma.FirstParameter();
452 if (UIntPCSma < temp)
453 temp = UIntPCSma;
454 bid.Load(ctg,temp,FiArcSma.LastParameter());
455 }
456 else {
457 wi = temp = FiArcSma.LastParameter();
458 if (UIntPCSma > temp)
459 temp = UIntPCSma;
460 bid.Load(ctg,FiArcSma.FirstParameter(),temp);
461 }
462 if(SmaFD->Surf() == BigFD->Surf()){
463 Reduce(UIntPCSma,UIntPCBig,SmaHS,BigHS);
464 Reduce(UIntPCSma,UIntPCBig,Hctg);
465 }
466 if(!ChFi3d_IntCS(BigHS,Hctg,UVi,wi)){
467#if DEB
81bba717 468 cout<<"bevel : failed inter C S"<<endl;
7fd59977 469#endif
470 done=Standard_False;
471 return done;
472 }
473 Parfin(3) = UVi.X(); Parfin(4) = UVi.Y();
474 UVi = FiArcSma.PCurveOnSurf()->Value(wi);
475 Parfin(1) = UVi.X(); Parfin(2) = UVi.Y();
476 gp_Pnt PMil = SmaHS->Value(Parfin(1),Parfin(2));
477
478 Standard_Real tolreached;
479 if (!ChFi3d_ComputeCurves(SmaHS,BigHS,Pardeb,Parfin,Gc,
480 PGc1,PGc2,tolesp,tol2d,tolreached)) {
481#if DEB
81bba717 482 cout<<"failed to calculate bevel failed interSS"<<endl;
7fd59977 483#endif
484 done=Standard_False;
485 return done;
486 }
81bba717 487 // SmaCD is updated, for it this is all.
7fd59977 488 Standard_Real WFirst = Gc->FirstParameter();
489 Standard_Real WLast = Gc->LastParameter();
490 Standard_Integer IpointCo, IpointMil, IpointArc;
491 ChFiDS_CommonPoint& psmaco = SmaFD->ChangeVertex(isfirstSma,IFaCoSma);
492 ChFiDS_CommonPoint& pbigco = BigFD->ChangeVertex(isfirstBig,IFaCoBig);
493 Standard_Real tolpco = Max(psmaco.Tolerance(),pbigco.Tolerance());
494 ChFiDS_CommonPoint& psmamil = SmaFD->ChangeVertex(isfirstSma,IFaArcSma);
495 Standard_Real tolpmil = psmamil.Tolerance();
496 Standard_Integer ICurv = DStr.AddCurve(TopOpeBRepDS_Curve(Gc,tolreached));
497
498 SmaCD->SetParameters(isfirstSma,WFirst,WLast);
499 SmaCD->SetCurve(ICurv,isfirstSma);
500 SmaCD->ChangePCurve(isfirstSma) = PGc1;
501 psmaco.Reset();
502 psmaco.SetPoint(PFaCo);
503 psmaco.SetTolerance(Max(tolpco,tolreached));
504 SmaFD->ChangeInterference(IFaCoSma).SetParameter(UIntPCSma,isfirstSma);
505 psmamil.Reset();
506 psmamil.SetPoint(PMil);
507 psmamil.SetTolerance(Max(tolpmil,tolreached));
508 SmaFD->ChangeInterference(IFaArcSma).SetParameter(wi,isfirstSma);
509 IpointCo = ChFi3d_IndexPointInDS(psmaco,DStr);
510 SmaCD->SetIndexPoint(IpointCo,isfirstSma,IFaCoSma);
511 IpointMil = ChFi3d_IndexPointInDS(psmamil,DStr);
512 SmaCD->SetIndexPoint(IpointMil,isfirstSma,IFaArcSma);
513 if (IFaCoSma == 2) SmaCD->SetOrientation(TopAbs_REVERSED,isfirstSma);
514
81bba717 515 // For BigCD the first results are met in the DS.
7fd59977 516 BigCD->SetIndexPoint(IpointCo,isfirstBig,IFaCoBig);
517 BigFD->ChangeVertex(isfirstBig,IFaCoBig) = psmaco;
518 BigFD->ChangeInterference(IFaCoBig).SetParameter(UIntPCBig,isfirstBig);
519
520 TopOpeBRepDS_ListOfInterference& Li = DStr.ChangeCurveInterferences(ICurv);
521 Handle(TopOpeBRepDS_CurvePointInterference) Interfp;
522 Interfp = ChFi3d_FilPointInDS(TopAbs_FORWARD,ICurv,IpointCo,WFirst);
523 Li.Append(Interfp);
524 Interfp = ChFi3d_FilPointInDS(TopAbs_REVERSED,ICurv,IpointMil,WLast);
525 Li.Append(Interfp);
526
81bba717 527 // the transition of curves of intersection on the Big
7fd59977 528 TopAbs_Orientation tra = BigFD->InterferenceOnS1().Transition();
529 TopAbs_Orientation ofac = DStr.Shape(BigFD->IndexOfS1()).Orientation();
530 TopAbs_Orientation ofil = BigFD->Orientation();
531 TopAbs_Orientation tracurv = TopAbs::Compose(ofac,ofil);
532 tracurv = TopAbs::Compose(tracurv,tra);
533 if(!isfirstBig) tracurv = TopAbs::Reverse(tracurv);
534 if(IFaCoBig != 1) tracurv = TopAbs::Reverse(tracurv);
535
536 Handle(TopOpeBRepDS_SurfaceCurveInterference) Interfc;
537 Standard_Integer ISurf = BigFD->Surf();
538 Interfc = ChFi3d_FilCurveInDS (ICurv,ISurf,PGc2,tracurv);
539 DStr.ChangeSurfaceInterferences(ISurf).Append(Interfc);
540
81bba717 541 //The tolerances of points are updated (beginning).
7fd59977 542 Bnd_Box bco,bmil,barc;
543 if(IFaCoSma == 1) ChFi3d_EnlargeBox(DStr,SmaCD,SmaFD,bco,bmil,isfirstSma);
544 else ChFi3d_EnlargeBox(DStr,SmaCD,SmaFD,bmil,bco,isfirstSma);
545 ChFi3d_EnlargeBox(BigHS,PGc2,WFirst,WLast,bco,bmil);
546
81bba717 547 // Intersection of the big with the face at end :
7fd59977 548 // -------------------------------------------
549
81bba717 550 // Pardeb (parameters of PMil)
551 // The intersection curve surface is tried again, now with representation
552 // pcurve on face of the curve to be sure.
7fd59977 553 TopoDS_Face F = TopoDS::Face(DStr.Shape(SmaFD->Index(IFaArcSma)));
554 Handle(BRepAdaptor_HSurface) HF = new BRepAdaptor_HSurface(F);
555 Standard_Real fsma = FiArcSma.FirstParameter();
556 Standard_Real lsma = FiArcSma.LastParameter();
557 Standard_Real deltSma = 0.05 * (lsma - fsma);
558 Handle(Geom2d_Curve) pcpc = SmaFD->Interference(IFaArcSma).PCurveOnFace();
559 fsma = Max(pcpc->FirstParameter(),wi-deltSma);
560 lsma = Min(pcpc->LastParameter(),wi+deltSma);
561 if ( lsma<fsma ) {
562 done=Standard_False;
563 return done;
564 }
565 Handle(Geom2dAdaptor_HCurve) c2df =
566 new Geom2dAdaptor_HCurve(SmaFD->Interference(IFaArcSma).PCurveOnFace(),fsma,lsma);
567 Adaptor3d_CurveOnSurface consf(c2df,HF);
568 Handle(Adaptor3d_HCurveOnSurface) Hconsf = new Adaptor3d_HCurveOnSurface(consf);
569 if(!ChFi3d_IntCS(BigHS,Hconsf,UVi,wi)) {
570#if DEB
81bba717 571 cout<<"bevel : failed inter C S"<<endl;
7fd59977 572#endif
573 done=Standard_False;
574 return done;
575 }
576 Pardeb(3) = UVi.X(); Pardeb(4) = UVi.Y();
577 UVi = SmaFD->Interference(IFaArcSma).PCurveOnFace()->Value(wi);
578 Pardeb(1) = UVi.X(); Pardeb(2) = UVi.Y();
579 gp_Pnt2d ppff1 = UVi;
580
81bba717 581 // Parfin (parameters of the point cpend)
7fd59977 582 Standard_Real ptg = BigFD->Interference(IFaArcBig).Parameter(isfirstBig);
583 UVi = BigFD->Interference(IFaArcBig).PCurveOnSurf()->Value(ptg);
584 Parfin(3) = UVi.X(); Parfin(4) = UVi.Y();
585 ChFiDS_CommonPoint& cpend = BigFD->ChangeVertex(isfirstBig,IFaArcBig);
586 TopoDS_Edge etest = cpend.Arc();
587 if(BRep_Tool::IsClosed(etest,F)) etest.Reverse();
588 BRepAdaptor_Curve2d arc(etest,F);
589 UVi = arc.Value(cpend.ParameterOnArc());
590 Parfin(1) = UVi.X(); Parfin(2) = UVi.Y();
591 gp_Pnt2d ppff2 = UVi;
592
593 // Intersection.
594 Standard_Real uu1,uu2,vv1,vv2;
595 ChFi3d_Boite(ppff1,ppff2,uu1,uu2,vv1,vv2);
81bba717 596 // for the case when two chamfers are on two edges OnSame,
597 // it is necessary to extend the surface carrying F, or at least
598 // not to limit it.
7fd59977 599 ChFi3d_BoundFac(HF->ChangeSurface(),uu1,uu2,vv1,vv2,Standard_True);
600
601 if (!ChFi3d_ComputeCurves(HF,BigHS,Pardeb,Parfin,Gc,
602 PGc1,PGc2,tolesp,tol2d,tolreached)) {
603#if DEB
81bba717 604 cout<<"fail calculation bevel fail interSS"<<endl;
7fd59977 605#endif
606 done=Standard_False;
607 return done;
608 }
609
81bba717 610 // End of update of the BigCD and the DS.
7fd59977 611 WFirst = Gc->FirstParameter();
612 WLast = Gc->LastParameter();
613 ICurv = DStr.AddCurve(TopOpeBRepDS_Curve(Gc,tolreached));
614 cpend.SetTolerance(Max(cpend.Tolerance(),tolreached));
615 IpointArc = ChFi3d_IndexPointInDS(cpend,DStr);
616 BigCD->SetIndexPoint(IpointArc,isfirstBig,IFaArcBig);
617
618 TopOpeBRepDS_ListOfInterference& Li7 = DStr.ChangeCurveInterferences(ICurv);
619 Interfp = ChFi3d_FilPointInDS(TopAbs_FORWARD,ICurv,IpointMil,WFirst);
620 Li7.Append(Interfp);
621 Interfp = ChFi3d_FilPointInDS(TopAbs_REVERSED,ICurv,IpointArc,WLast);
622 Li7.Append(Interfp);
623 Interfc = ChFi3d_FilCurveInDS (ICurv,ISurf,PGc2,tracurv);
624 DStr.ChangeSurfaceInterferences(ISurf).Append(Interfc);
625 BigCD->InDS(isfirstBig);
626
81bba717 627 // Finally the information on faces is placed in the DS.
7fd59977 628 Standard_Integer IShape = DStr.AddShape(F);
629 if(SmaFD->Surf() == BigFD->Surf()){
630 tracurv = TopAbs::Compose(etest.Orientation(),
631 cpend.TransitionOnArc());
632 }
633 else {
634 TopExp_Explorer Exp;
635 for (Exp.Init(F.Oriented(TopAbs_FORWARD),
636 TopAbs_EDGE);Exp.More();Exp.Next()) {
637 if (Exp.Current().IsSame(etest)) {
638 tracurv = TopAbs::Compose(Exp.Current().Orientation(),
639 cpend.TransitionOnArc());
640 break;
641 }
642 }
643 }
644 Interfc = ChFi3d_FilCurveInDS(ICurv,IShape,PGc1,tracurv);
645 DStr.ChangeShapeInterferences(IShape).Append(Interfc);
646
81bba717 647 //The tolerances of points are updated (end).
7fd59977 648 Handle(ChFiDS_Stripe) bidst;
649 if(IFaCoBig == 1) ChFi3d_EnlargeBox(DStr,bidst,BigFD,bco,barc,isfirstBig);
650 else ChFi3d_EnlargeBox(DStr,bidst,BigFD,barc,bco,isfirstBig);
651 ChFi3d_EnlargeBox(BigHS,PGc2,WFirst,WLast,bmil,barc);
652 ChFi3d_EnlargeBox(HF,PGc1,WFirst,WLast,bmil,barc);
653 ChFi3d_EnlargeBox(Gc,WFirst,WLast,bmil,barc);
654 const ChFiDS_CommonPoint& cparc = BigFD->Vertex(isfirstBig,IFaArcBig);
655 ChFi3d_EnlargeBox(cparc.Arc(),myEFMap(cparc.Arc()),cparc.ParameterOnArc(),barc);
656
657 ChFi3d_SetPointTolerance(DStr,bco,SmaCD->IndexPoint(isfirstSma,IFaCoSma));
658 ChFi3d_SetPointTolerance(DStr,bmil,SmaCD->IndexPoint(isfirstSma,IFaArcSma));
659 ChFi3d_SetPointTolerance(DStr,barc,BigCD->IndexPoint(isfirstBig,IFaArcBig));
660 }
661 done = 1;
662
663 return done;
664}
665
666
667
668
669
670