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