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