0024023: Revamp the OCCT Handle -- general
[occt.git] / src / ChFi3d / ChFi3d_Builder_C2.cxx
CommitLineData
b311480e 1// Created on: 1996-08-20
2// Created by: Stagiaire Xuan Tang PHAMPHU
3// Copyright (c) 1996-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#include <ChFi3d_Builder.jxx>
18#include <ChFi3d.hxx>
19#include <ChFi3d_Builder_0.hxx>
20
21#include <Precision.hxx>
22
23#include <Standard_Failure.hxx>
24#include <Standard_NotImplemented.hxx>
25#include <StdFail_NotDone.hxx>
26
27
28#include <gp_Pnt.hxx>
29#include <gp_Dir.hxx>
30#include <gp_Vec.hxx>
31#include <gp_Ax3.hxx>
32#include <gp_Pnt2d.hxx>
33#include <gp_Vec2d.hxx>
34#include <gp_Dir2d.hxx>
35#include <GeomLib.hxx>
36#include <Extrema_ExtPC.hxx>
37#include <Geom_Curve.hxx>
38#include <Geom2d_Curve.hxx>
39#include <Geom_BoundedCurve.hxx>
40
41#include <Geom2dAdaptor_HCurve.hxx>
42#include <GeomAbs_Shape.hxx>
43#include <GeomAdaptor_HCurve.hxx>
44#include <GeomAdaptor_Surface.hxx>
45#include <GeomAdaptor_HSurface.hxx>
46
47#include <Adaptor3d_HCurveOnSurface.hxx>
48#include <BRepAdaptor_HSurface.hxx>
49#include <BRepAdaptor_Curve.hxx>
50#include <BRepAdaptor_Curve2d.hxx>
51#include <BRepAdaptor_HCurve.hxx>
52#include <BRepAdaptor_Surface.hxx>
53
54#include <BRep_Tool.hxx>
55
56#include <TopoDS.hxx>
57#include <TopoDS_Shape.hxx>
58#include <TopoDS_Face.hxx>
59#include <TopoDS_Edge.hxx>
60#include <TopoDS_Vertex.hxx>
61
62#include <TopAbs.hxx>
63#include <TopAbs_ShapeEnum.hxx>
64#include <TopAbs_Orientation.hxx>
65
66#include <TopExp.hxx>
67#include <TopExp_Explorer.hxx>
68
69#include <TopTools_ListIteratorOfListOfShape.hxx>
70
71#include <TopOpeBRepDS_Point.hxx>
72#include <TopOpeBRepDS_Curve.hxx>
73#include <TopOpeBRepDS_Surface.hxx>
74#include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
75#include <TopOpeBRepDS_CurvePointInterference.hxx>
76#include <TopOpeBRepDS_DataStructure.hxx>
77#include <TopOpeBRepDS_ListOfInterference.hxx>
78
79#include <ChFiDS_HData.hxx>
80#include <ChFiDS_SurfData.hxx>
81#include <ChFiDS_CommonPoint.hxx>
82#include <ChFiDS_FaceInterference.hxx>
83#include <ChFiDS_SequenceOfSurfData.hxx>
84#include <ChFiDS_Stripe.hxx>
85#include <ChFiDS_ListIteratorOfListOfStripe.hxx>
86
87#include <TColStd_Array1OfReal.hxx>
88
89static void Reduce(const Standard_Real& p1,
90 const Standard_Real& p2,
91 Handle(GeomAdaptor_HSurface)& hs1,
92 Handle(GeomAdaptor_HSurface)& hs2)
93{
94 GeomAdaptor_Surface& s1 = hs1->ChangeSurface();
95 GeomAdaptor_Surface& s2 = hs2->ChangeSurface();
c04c30b3 96 const Handle(Geom_Surface)& surf = s1.Surface();
7fd59977 97 Standard_Real ud,uf,vd,vf;
98 surf->Bounds(ud,uf,vd,vf);
99 Standard_Real milmoins = 0.51*vd+0.49*vf, milplus = 0.49*vd+0.51*vf;
100 if(p1 < p2) {
101 s1.Load(surf,ud,uf,vd,milmoins);
102 s2.Load(surf,ud,uf,milplus,vf);
103 }
104 else{
105 s1.Load(surf,ud,uf,milplus,vf);
106 s2.Load(surf,ud,uf,vd,milmoins);
107 }
108}
109
110static void Reduce(const Standard_Real& p1,
111 const Standard_Real& p2,
112 Handle(GeomAdaptor_HCurve)& hc)
113{
114 GeomAdaptor_Curve& c = hc->ChangeCurve();
115 Standard_Real f = c.FirstParameter();
116 Standard_Real l = c.LastParameter();
117 Standard_Real milmoins = 0.51*f+0.49*l, milplus = 0.49*f+0.51*l;
118 if(p1 < p2) {
119 c.Load(c.Curve(),f,milmoins);
120 }
121 else{
122 c.Load(c.Curve(),milplus,l);
123 }
124}
125
126
127//=======================================================================
128//function : PerformTwoCornerbyInter
81bba717 129//purpose : Performs PerformTwoCorner by intersection.
130// In case of Biseau for all cases the
131// path is used; 3D curve and 2 pcurves are approximated.
7fd59977 132//=======================================================================
133
134Standard_Integer ChFi3d_Builder::PerformTwoCornerbyInter(const Standard_Integer Index)
135
136{
137 done = 0;
138 const TopoDS_Vertex& Vtx = myVDataMap.FindKey(Index);
139 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
140
81bba717 141 //Information on fillets is extracted
7fd59977 142 //------------------------------------------------------
143
81bba717 144 //the first
7fd59977 145 //----------
146 ChFiDS_ListIteratorOfListOfStripe It;
147 It.Initialize(myVDataMap(Index));
148 Handle(ChFiDS_Stripe)& Corner1 = It.Value();
149 Standard_Integer Sens1;
150 Standard_Integer IFd1 =
151 ChFi3d_IndexOfSurfData(Vtx,Corner1,Sens1);
152 ChFiDS_SequenceOfSurfData& SeqFil1 =
153 Corner1->ChangeSetOfSurfData()->ChangeSequence();
154 Handle(ChFiDS_SurfData)& Fd1 = SeqFil1.ChangeValue(IFd1);
155
81bba717 156 //the second
7fd59977 157 //----------
158 It.Next();
159 Handle(ChFiDS_Stripe)& Corner2 = It.Value();
160 Standard_Integer Sens2;
161 Standard_Integer IFd2;
162 if(Corner2 == Corner1) {
163 Sens2 = -1;
164 IFd2 = Corner2->SetOfSurfData()->Length();
165 }
166 else{ IFd2 = ChFi3d_IndexOfSurfData(Vtx,Corner2,Sens2); }
167 ChFiDS_SequenceOfSurfData& SeqFil2 =
168 Corner2->ChangeSetOfSurfData()->ChangeSequence();
169 Handle(ChFiDS_SurfData)& Fd2 = SeqFil2.ChangeValue(IFd2);
170
81bba717 171 // The concavities are analysed in case of differents concavities,
172 // preview an evolutionary connection of type ThreeCorner of R to 0.
173 // Otherwise the opposite face
174 // and the eventual intersection of 2 pcurves on this face are found.
7fd59977 175
7fd59977 176 Standard_Boolean isfirst1 = (Sens1 == 1);
177 Standard_Boolean isfirst2 = (Sens2 == 1);
7fd59977 178 Standard_Boolean OkinterCC,Okvisavis,SameSide;
179 Standard_Integer IFaCo1,IFaCo2;
180 Standard_Real UIntPC1,UIntPC2;
181 TopoDS_Face FaCo;
182 OkinterCC = ChFi3d_IsInFront(DStr,Corner1,Corner2,IFd1,IFd2,Sens1,Sens2,
183 UIntPC1,UIntPC2,FaCo,SameSide,
184 IFaCo1,IFaCo2,Okvisavis,Vtx,Standard_True);
185 if (!Okvisavis) {
0797d9d3 186#ifdef OCCT_DEBUG
7fd59977 187 cout<<"TwoCorner : pas de face commune"<<endl;
188#endif
189 done=Standard_False;
190 return done;
191 }
192 if (!OkinterCC) {
81bba717 193 // The intersection of pcurves is calculated without restricting them by
194 // common points.
7fd59977 195 OkinterCC= ChFi3d_IsInFront(DStr,Corner1,Corner2,IFd1,IFd2,Sens1,Sens2,
196 UIntPC1,UIntPC2,FaCo,SameSide,
197 IFaCo1,IFaCo2,Okvisavis,Vtx,Standard_True,1);
198 }
199
200 if (!Okvisavis) {
0797d9d3 201#ifdef OCCT_DEBUG
81bba717 202 cout<<"TwoCorner : no common face"<<endl;
7fd59977 203#endif
204 done=Standard_False;
205 return done;
206 }
207 if (!OkinterCC) {
0797d9d3 208#ifdef OCCT_DEBUG
81bba717 209 cout<<"biseau : failed intersection of tangency lines on common face"<<endl;
7fd59977 210#endif
211 done=Standard_False;
212 return done;
213 }
214 Standard_Integer IFaArc1 = 3-IFaCo1, IFaArc2 = 3-IFaCo2;
215
81bba717 216 // It is checked if the fillets have a commonpoint on a common arc.
217 // This edge is the pivot of the bevel or of the kneecap.
7fd59977 218
219 ChFiDS_CommonPoint& CP1 = Fd1->ChangeVertex(isfirst1,IFaArc1);
220 ChFiDS_CommonPoint& CP2 = Fd2->ChangeVertex(isfirst2,IFaArc2);
221
222 if (!CP1.IsOnArc() || !CP2.IsOnArc()) {
0797d9d3 223#ifdef OCCT_DEBUG
81bba717 224 cout<<"fail 1 of 2 fillets are not on arc"<<endl;
7fd59977 225#endif
226 done=Standard_False;
227 return done;
228 }
229 if ( ! CP1.Arc().IsSame( CP2.Arc()) ) {
230 // look like OnSame + OnDiff case (eap, Arp 9 2002, occ266)
0797d9d3 231#ifdef OCCT_DEBUG
81bba717 232 cout<<"PerformTwoCornerbyInter(): fillets are not on the same arc"<<endl;
7fd59977 233#endif
234 done = Standard_True;
235 PerformMoreThreeCorner(Index, 2);
236 return done;
237 }
238
239 TopoDS_Edge pivot;
240 pivot = CP1.Arc();
241 Standard_Real parCP1 = CP1.ParameterOnArc();
242 Standard_Real parCP2 = CP2.ParameterOnArc();
243 Handle(BRepAdaptor_HCurve) Hpivot = new BRepAdaptor_HCurve(pivot);
244 if (!pivot.IsSame(CP2.Arc())){
245 Handle(Geom_Curve) csau;
246 Standard_Real ubid,vbid;
247 csau=BRep_Tool::Curve(pivot,ubid,vbid );
248 Handle(Geom_BoundedCurve) C1= Handle(Geom_BoundedCurve)::DownCast(csau);
249 if (! C1.IsNull()) {
250 GeomLib::ExtendCurveToPoint(C1,CP2.Point(),1,Standard_False);
251 GeomAdaptor_Curve cad;
252 cad.Load(C1);
253 Extrema_ExtPC ext(CP2.Point(),cad,1.e-4);
254 parCP2 = ext.Point(1).Parameter();
255 }
256 }
257 gp_Pnt psp1 = Hpivot->Value(parCP1);
258 gp_Pnt psp2 = Hpivot->Value(parCP2);
259 Standard_Real sameparam = (psp1.Distance(psp2) < 10 * tolesp);
260
261 TopoDS_Face FF1 = TopoDS::Face(DStr.Shape(Fd1->Index(IFaArc1)));
262 TopoDS_Face FF2 = TopoDS::Face(DStr.Shape(Fd2->Index(IFaArc2)));
263 TopTools_ListIteratorOfListOfShape Kt;
264 Standard_Boolean ok1 = Standard_False, ok2 = Standard_False;
265 for (Kt.Initialize(myEFMap(pivot)); Kt.More(); Kt.Next()){
266 TopoDS_Face F = TopoDS::Face(Kt.Value());
267 if(!ok1 && FF1.IsSame(F)){
268 ok1 = Standard_True;
269 }
270 if(!ok2 && FF2.IsSame(F)){
271 ok2 = Standard_True;
272 }
273 }
274 if(!ok1 || !ok2){
0797d9d3 275#ifdef OCCT_DEBUG
81bba717 276 cout<<"fail one of surfaces has no common base face with the pivot edge"<<endl;
7fd59977 277#endif
278 done=Standard_False;
279 return done;
280 }
281
282 Handle(GeomAdaptor_HSurface) HS1, HS2;
283 HS1 = ChFi3d_BoundSurf (DStr,Fd1,IFaCo1,IFaArc1);
284 HS2 = ChFi3d_BoundSurf (DStr,Fd2,IFaCo2,IFaArc2);
285
286 TColStd_Array1OfReal Pardeb(1,4),Parfin(1,4);
287
288 Handle(Geom2d_Curve) PGc1,PGc2;
289 Handle(Geom_Curve) Gc;
290
291 if(sameparam) {
81bba717 292 // Side common face, calculation of Pardeb.
7fd59977 293 ChFi3d_ComputesIntPC (Fd1->Interference(IFaCo1),
294 Fd2->Interference(IFaCo2),
295 HS1,HS2,UIntPC1,UIntPC2);
296 gp_Pnt2d UV;
297 UV = Fd1->Interference(IFaCo1).PCurveOnSurf()->Value(UIntPC1);
298 Pardeb(1)= UV.X(); Pardeb(2)=UV.Y();
299 UV = Fd2->Interference(IFaCo2).PCurveOnSurf()->Value(UIntPC2);
300 Pardeb(3)= UV.X(); Pardeb(4)=UV.Y();
301 gp_Pnt PFaCo = HS1->Surface().Value(Pardeb(1),Pardeb(2));
302
81bba717 303 // Side arc, calculation of Parfin.
7fd59977 304 Standard_Real UIntArc1 = Fd1->Interference(IFaArc1).Parameter(isfirst1);
305 Standard_Real UIntArc2 = Fd2->Interference(IFaArc2).Parameter(isfirst2);
306
307 ChFi3d_ComputesIntPC (Fd1->Interference(IFaArc1),Fd2->Interference(IFaArc2),
308 HS1,HS2,UIntArc1,UIntArc2);
309 UV = Fd1->Interference(IFaArc1).PCurveOnSurf()->Value(UIntArc1);
310 Parfin(1)= UV.X(); Parfin(2)=UV.Y();
311 UV = Fd2->Interference(IFaArc2).PCurveOnSurf()->Value(UIntArc2);
312 Parfin(3)= UV.X(); Parfin(4)=UV.Y();
313
314 if(Fd1->Surf() == Fd2->Surf()){
315 Reduce(UIntPC1,UIntPC2,HS1,HS2);
316 }
317
1d47d8d0 318 Standard_Real tolreached = tolesp;
7fd59977 319 if (IFaCo1 == 1 &&
320 !ChFi3d_ComputeCurves(HS1,HS2,Pardeb,Parfin,Gc,
321 PGc1,PGc2,tolesp,tol2d,tolreached)) {
0797d9d3 322#ifdef OCCT_DEBUG
81bba717 323 cout<<"failed to calculate bevel error interSS"<<endl;
7fd59977 324#endif
325 done=Standard_False;
326 return done;
327 }
328 else if (IFaCo1 == 2 &&
329 !ChFi3d_ComputeCurves(HS1,HS2,Parfin,Pardeb,Gc,
330 PGc1,PGc2,tolesp,tol2d,tolreached)) {
0797d9d3 331#ifdef OCCT_DEBUG
81bba717 332 cout<<"failed to calculate bevel error interSS"<<endl;
7fd59977 333#endif
334 done=Standard_False;
335 return done;
336 }
81bba717 337 // CornerData are updated with results of the intersection.
7fd59977 338 Standard_Real WFirst = Gc->FirstParameter();
339 Standard_Real WLast = Gc->LastParameter();
340 Standard_Integer Ipoin1;
341 Standard_Integer Ipoin2;
342 ChFiDS_CommonPoint& cpco1 = Fd1->ChangeVertex(isfirst1,IFaCo1);
343 ChFiDS_CommonPoint& cpco2 = Fd2->ChangeVertex(isfirst2,IFaCo2);
344 Standard_Real tolpco = Max(cpco1.Tolerance(),cpco2.Tolerance());
345 ChFiDS_CommonPoint& cparc1 = Fd1->ChangeVertex(isfirst1,IFaArc1);
346 ChFiDS_CommonPoint& cparc2 = Fd2->ChangeVertex(isfirst2,IFaArc2);
347 Standard_Real tolparc = Max(cparc1.Tolerance(),cparc2.Tolerance());
348 Standard_Integer ICurv = DStr.AddCurve(TopOpeBRepDS_Curve(Gc,tolreached));
349 //Corner1
350 Corner1->SetParameters(isfirst1,WFirst,WLast);
351 Corner1->SetCurve(ICurv,isfirst1);
352 Corner1->ChangePCurve(isfirst1) = PGc1;
353 cpco1.Reset();
354 cpco1.SetPoint(PFaCo);
355 cpco1.SetTolerance(Max(tolreached,tolpco));
356 Fd1->ChangeInterference(IFaCo1).SetParameter(UIntPC1,isfirst1);
357 tolparc = Max(tolparc,tolreached);
358 cparc1.SetTolerance(Max(tolparc,tolreached));
359 Ipoin1 = ChFi3d_IndexPointInDS(Fd1->Vertex(isfirst1,1),DStr);
360 Corner1->SetIndexPoint(Ipoin1,isfirst1,1);
361 Ipoin2 = ChFi3d_IndexPointInDS(Fd1->Vertex(isfirst1,2),DStr);
362 Corner1->SetIndexPoint(Ipoin2,isfirst1,2);
363 //Corner2
364 Corner2->SetParameters(isfirst2,WFirst,WLast);
365 Corner2->SetCurve(ICurv,isfirst2);
366 Corner2->ChangePCurve(isfirst2) = PGc2;
367 Fd2->ChangeInterference(IFaCo2).SetParameter(UIntPC2,isfirst2);
368 Fd2->ChangeVertex(isfirst2,IFaCo2) = Fd1->Vertex(isfirst1,IFaCo1);
369 Fd2->ChangeVertex(isfirst2,IFaArc2) = Fd1->Vertex(isfirst1,IFaArc1);
370 if (IFaCo1!=IFaCo2) Corner2->SetOrientation(TopAbs_REVERSED,isfirst2);
371 Corner2->SetIndexPoint(Corner1->IndexPoint(isfirst1,IFaCo1),
372 isfirst2,IFaCo2);
373 Corner2->SetIndexPoint(Corner1->IndexPoint(isfirst1,IFaArc1),
374 isfirst2,IFaArc2);
81bba717 375 //The tolerances of points are updated.
7fd59977 376 Bnd_Box bco,barc;
377 if(IFaCo1 == 1) ChFi3d_EnlargeBox(DStr,Corner1,Fd1,bco,barc,isfirst1);
378 else ChFi3d_EnlargeBox(DStr,Corner1,Fd1,barc,bco,isfirst1);
379 if(IFaCo2 == 1) ChFi3d_EnlargeBox(DStr,Corner2,Fd2,bco,barc,isfirst2);
380 else ChFi3d_EnlargeBox(DStr,Corner2,Fd2,barc,bco,isfirst2);
381 const ChFiDS_CommonPoint& cparc = Fd1->Vertex(isfirst1,IFaArc1);
382 ChFi3d_EnlargeBox(cparc.Arc(),myEFMap(cparc.Arc()),cparc.ParameterOnArc(),barc);
383 ChFi3d_SetPointTolerance(DStr,barc,Corner1->IndexPoint(isfirst1,IFaArc1));
384 ChFi3d_SetPointTolerance(DStr,bco,Corner1->IndexPoint(isfirst1,IFaCo1));
385 }
386 else {
81bba717 387 // It is necessary to identify the border surface,
388 // find the end point of the intersection Surf/Surf
389 // by the intersection of the tangency line of the small
390 // on the opposing face with the surface of the big,
391 // and finally intersect the big with the face at end
392 // between this point and the point on arc.
7fd59977 393 Standard_Boolean parcrois = Standard_False ;
7fd59977 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)){
0797d9d3 467#ifdef OCCT_DEBUG
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)) {
0797d9d3 481#ifdef OCCT_DEBUG
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)) {
0797d9d3 570#ifdef OCCT_DEBUG
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)) {
0797d9d3 603#ifdef OCCT_DEBUG
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