Warnings on vc14 were eliminated
[occt.git] / src / FilletSurf / FilletSurf_InternalBuilder.cxx
1 // Copyright (c) 1997-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <Adaptor3d_TopolTool.hxx>
17 #include <BRep_Tool.hxx>
18 #include <BRepAdaptor_HCurve.hxx>
19 #include <BRepAdaptor_HCurve2d.hxx>
20 #include <BRepAdaptor_HSurface.hxx>
21 #include <BRepBlend_ConstRad.hxx>
22 #include <BRepBlend_ConstRadInv.hxx>
23 #include <BRepBlend_Line.hxx>
24 #include <BRepExtrema_DistShapeShape.hxx>
25 #include <ChFi3d_Builder_0.hxx>
26 #include <ChFi3d_FilBuilder.hxx>
27 #include <ChFiDS_CircSection.hxx>
28 #include <ChFiDS_CommonPoint.hxx>
29 #include <ChFiDS_FaceInterference.hxx>
30 #include <ChFiDS_FilSpine.hxx>
31 #include <ChFiDS_HData.hxx>
32 #include <ChFiDS_HElSpine.hxx>
33 #include <ChFiDS_ListIteratorOfListOfStripe.hxx>
34 #include <ChFiDS_ListOfStripe.hxx>
35 #include <ChFiDS_SecHArray1.hxx>
36 #include <ChFiDS_SequenceOfSurfData.hxx>
37 #include <ChFiDS_Spine.hxx>
38 #include <ChFiDS_Stripe.hxx>
39 #include <ChFiDS_SurfData.hxx>
40 #include <ElSLib.hxx>
41 #include <FilletSurf_ErrorTypeStatus.hxx>
42 #include <FilletSurf_InternalBuilder.hxx>
43 #include <FilletSurf_StatusDone.hxx>
44 #include <FilletSurf_StatusType.hxx>
45 #include <Geom2d_Curve.hxx>
46 #include <Geom_Circle.hxx>
47 #include <Geom_Curve.hxx>
48 #include <Geom_Plane.hxx>
49 #include <Geom_Surface.hxx>
50 #include <Geom_TrimmedCurve.hxx>
51 #include <GeomAbs_Shape.hxx>
52 #include <GeomAdaptor_HCurve.hxx>
53 #include <GeomAdaptor_HSurface.hxx>
54 #include <GeomAdaptor_Surface.hxx>
55 #include <gp_Circ.hxx>
56 #include <gp_Pln.hxx>
57 #include <IntCurveSurface_HInter.hxx>
58 #include <IntCurveSurface_IntersectionPoint.hxx>
59 #include <Precision.hxx>
60 #include <Standard_ConstructionError.hxx>
61 #include <TopoDS.hxx>
62 #include <TopoDS_Face.hxx>
63 #include <TopoDS_Shape.hxx>
64 #include <TopOpeBRepDS_HDataStructure.hxx>
65 #include <TopTools_ListIteratorOfListOfShape.hxx>
66
67 static Standard_Boolean isinlist(const TopoDS_Shape&         E,
68                                  const TopTools_ListOfShape& L){
69   TopTools_ListIteratorOfListOfShape It;
70   for (It.Initialize(L); It.More(); It.Next()){
71     if(E.IsSame(It.Value())) return 1;
72   }
73   return 0;
74 }
75
76 static Standard_Boolean IntPlanEdge(Handle(BRepAdaptor_HCurve)& Ed,
77                                     const gp_Pln&               P,
78                                     Standard_Real&              w,
79                                     const Standard_Real         tol3d)
80 {
81   Standard_Boolean done = 0;
82   Standard_Real f = Ed->FirstParameter();
83   Standard_Real l = Ed->LastParameter();
84   gp_Pnt Or = P.Location();
85   Handle(Geom_Plane) Pln = new Geom_Plane(P);
86   Handle(GeomAdaptor_HSurface) 
87     Plan = new GeomAdaptor_HSurface(GeomAdaptor_Surface(Pln));
88
89   IntCurveSurface_HInter Intersection;
90   Standard_Integer nbp ,iip;
91   IntCurveSurface_IntersectionPoint IP;
92   Standard_Real dist = RealLast();
93   
94   Intersection.Perform(Ed,Plan);
95   
96   if(Intersection.IsDone()){
97     nbp = Intersection.NbPoints();
98     for (iip = 1; iip <= nbp; iip++){
99       IP = Intersection.Point(iip);
100       gp_Pnt pint = IP.Pnt();
101       Standard_Real d = pint.Distance(Or);
102       if(d<dist){
103         done = 1;
104         w = IP.W();
105         dist = d;
106       }
107     }
108   }
109   gp_Pnt pdeb = Ed->Value(f);
110   gp_Pnt pfin = Ed->Value(l);
111   Standard_Real u,v;
112   //check if the extremities are not solution
113   ElSLib::Parameters(P,pdeb,u,v);
114   gp_Pnt projdeb = ElSLib::Value(u,v,P);
115   Standard_Real dprojdeb = pdeb.Distance(projdeb);
116   if(dprojdeb<tol3d){
117     Standard_Real d = pdeb.Distance(Or);
118     if(d<dist){
119       done = 1;
120       w = f;
121       dist = d;
122     }
123   }
124   ElSLib::Parameters(P,pfin,u,v);
125   gp_Pnt projfin = ElSLib::Value(u,v,P);
126   Standard_Real dprojfin = pfin.Distance(projfin);
127   if(dprojfin<tol3d){
128     Standard_Real d = pfin.Distance(Or);
129     if(d<dist){
130       done = 1;
131       w = l;
132       dist = d;
133     }
134   }
135   return done;
136 }
137
138 static Standard_Boolean ComputeEdgeParameter(const Handle(ChFiDS_Spine)&    Spine, 
139                                              const Standard_Integer         ind,
140                                              const Standard_Real            pelsp,
141                                              Standard_Real&                 ped,
142                                              const Standard_Real            tol3d)
143 {
144   Handle(ChFiDS_HElSpine) Guide = Spine->ElSpine(ind);
145   gp_Pnt P; gp_Vec V;
146   Guide->D1(pelsp,P,V);
147   gp_Pln pln(P,V);
148   Handle(BRepAdaptor_HCurve) ed = new BRepAdaptor_HCurve();
149   ed->ChangeCurve() = Spine->CurrentElementarySpine(ind);
150   return IntPlanEdge(ed,pln,ped,tol3d);
151 }
152                                              
153 //=======================================================================
154 //function : FilletSurf_InternalBuilder
155 //purpose  : 
156 //=======================================================================
157
158 FilletSurf_InternalBuilder::FilletSurf_InternalBuilder
159 (const TopoDS_Shape&      S, 
160  const ChFi3d_FilletShape FShape, 
161  const Standard_Real      Ta,
162  const Standard_Real      Tapp3d,
163  const Standard_Real      Tapp2d):ChFi3d_FilBuilder(S,FShape,Ta)
164 {
165   SetParams(Ta,Tapp3d,Tapp2d,
166             Tapp3d,Tapp2d,1.e-3);
167   SetContinuity(GeomAbs_C2,Ta);
168 }
169
170 //=======================================================================
171 //function : Add
172 //purpose  : creation of spine on a set of edges
173 // 
174 //  0 : no problem  
175 //  1 : empty list 
176 //  2 : non g1 edges
177 //  3 : non G1 adjacent faces
178 //  4 : edge is not on the shape
179 //  5 : edge is not alive 
180 //=======================================================================
181
182 Standard_Integer  FilletSurf_InternalBuilder::Add(const TopTools_ListOfShape& E, 
183                                                   const Standard_Real R)
184 {
185   if(E.IsEmpty()) return 1;
186   TopTools_ListIteratorOfListOfShape It;
187   for(It.Initialize(E); It.More(); It.Next()){
188     TopoDS_Edge cured = TopoDS::Edge(It.Value());
189     if(cured.IsNull()) return 4;
190     if(!myEFMap.Contains(cured)) return 4;
191     //check if the edge is a fracture edge
192     TopoDS_Face ff1,ff2;  
193     for(It.Initialize(myEFMap(cured));It.More();It.Next()){  
194       if (ff1.IsNull()) {
195         ff1 = TopoDS::Face(It.Value());
196       }
197       else {
198         ff2 = TopoDS::Face(It.Value());
199         if(!ff2.IsSame(ff1)){
200           break;
201         }
202       }
203     }  
204     if(ff1.IsNull() || ff2.IsNull()) return 5;
205     if(ff1.IsSame(ff2)) return 5;
206     if(BRep_Tool::Continuity(cured,ff1,ff2) != GeomAbs_C0) return 5;
207   }  
208   TopoDS_Edge ed = TopoDS::Edge(E.First());
209   ed.Orientation(TopAbs_FORWARD);
210   ChFi3d_FilBuilder::Add(R,ed);
211   Handle(ChFiDS_Stripe) st = myListStripe.First();
212   Handle(ChFiDS_Spine)& sp = st->ChangeSpine();
213   Standard_Boolean periodic = sp->IsPeriodic();
214   
215   //It is checked if edges of list E are in the contour,
216   //the edges that arenot in the list are removed from the contour,
217   //it is checked that the remainder is monoblock.
218  
219   for(It.Initialize(E); It.More(); It.Next()){
220     TopoDS_Edge cured = TopoDS::Edge(It.Value());
221     if(!Contains(cured)) return 2;
222   }  
223         
224   Handle(ChFiDS_FilSpine) newsp = new ChFiDS_FilSpine();
225   Standard_Boolean debut = 0;
226   Standard_Integer premierquinyestpas = 0;
227   Standard_Integer yatrou = 0;
228   for(Standard_Integer i = 1; i <= sp->NbEdges(); i++){
229     TopoDS_Edge cured = sp->Edges(i);
230     if(isinlist(cured,E)){
231       debut = 1;
232       if(premierquinyestpas) {
233         yatrou = 1;
234         break;
235       }
236       newsp->SetEdges(cured);
237     }
238     else if(debut && !premierquinyestpas) premierquinyestpas = i;
239   }
240   if(!periodic && yatrou) return 2;
241   if(periodic && yatrou){
242     Standard_Boolean vraitrou = 0, aLocalDebut = 0;
243     for(Standard_Integer i = sp->NbEdges(); i > yatrou; i--){
244       TopoDS_Edge cured = sp->Edges(i);
245       if(isinlist(cured,E)){
246         if(vraitrou) return 2;
247         newsp->PutInFirst(cured);
248       }
249       else if(aLocalDebut) vraitrou = 1;
250       aLocalDebut = 1;
251     }
252   }
253
254   if(newsp->NbEdges() != sp->NbEdges()) {
255     newsp->Load();
256     newsp->SetRadius(R);
257     sp = newsp;
258   }
259
260   //ElSpine is immediately constructed
261   Handle(ChFiDS_HElSpine) hels =  new ChFiDS_HElSpine();
262   gp_Vec TFirst,TLast;
263   gp_Pnt PFirst,PLast;
264   sp->D1(sp->FirstParameter(),PFirst,TFirst);
265   sp->D1(sp->LastParameter(),PLast,TLast);
266   hels->ChangeCurve().FirstParameter(sp->FirstParameter());
267   hels->ChangeCurve().SetFirstPointAndTgt(PFirst,TFirst);
268   hels->ChangeCurve().LastParameter(sp->LastParameter());
269   hels->ChangeCurve().SetLastPointAndTgt(PLast,TLast);
270   ChFi3d_PerformElSpine(hels,sp,myConti,tolesp);
271   sp->AppendElSpine(hels);
272   sp->SplitDone(Standard_True);
273   return 0;
274 }
275
276 //=======================================================================
277 //function : Perform
278 //purpose  : 
279 //=======================================================================
280
281 void FilletSurf_InternalBuilder::Perform()
282 {
283   //PerformSetOfSurfOnElSpine is enough.
284   
285   Handle(ChFiDS_Stripe) Stripe = myListStripe.First();
286   Handle(ChFiDS_HData)&  HData  = Stripe->ChangeSetOfSurfData();
287   HData =  new ChFiDS_HData();
288   Handle(ChFiDS_Spine)& Spine = Stripe->ChangeSpine();
289   TopAbs_Orientation RefOr1,RefOr2;
290   Standard_Integer RefChoix;
291   StripeOrientations(Spine,RefOr1,RefOr2,RefChoix);
292   Stripe->OrientationOnFace1(RefOr1);
293   Stripe->OrientationOnFace2(RefOr2);
294   Stripe->Choix(RefChoix);
295   PerformSetOfKGen(Stripe,0);
296 }
297
298 //=======================================================================
299 //function : PerformSurf
300 //purpose  : 
301 //=======================================================================
302
303 Standard_Boolean
304  FilletSurf_InternalBuilder::PerformSurf(ChFiDS_SequenceOfSurfData& SeqData, 
305                                          const Handle(ChFiDS_HElSpine)& Guide, 
306                                          const Handle(ChFiDS_Spine)& Spine, 
307                                          const Standard_Integer Choix, 
308                                          const Handle(BRepAdaptor_HSurface)& S1, 
309                                          const Handle(Adaptor3d_TopolTool)& I1, 
310                                          const Handle(BRepAdaptor_HSurface)& S2, 
311                                          const Handle(Adaptor3d_TopolTool)& I2, 
312                                          const Standard_Real MaxStep, 
313                                          const Standard_Real Fleche, 
314                                          const Standard_Real TolGuide, 
315                                          Standard_Real& First, 
316                                          Standard_Real& Last, 
317                                          const Standard_Boolean Inside, 
318                                          const Standard_Boolean Appro, 
319                                          const Standard_Boolean Forward, 
320                                          const Standard_Boolean RecOnS1, 
321                                          const Standard_Boolean RecOnS2, 
322                                          const math_Vector& Soldep, 
323                                          Standard_Integer& Intf, 
324                                          Standard_Integer& Intl)
325 {
326   Handle(ChFiDS_SurfData) Data = SeqData(1);
327   Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(Spine);
328   if(fsp.IsNull()) throw Standard_ConstructionError("PerformSurf : this is not the spine of a fillet");
329   Handle(BRepBlend_Line) lin;
330   TopAbs_Orientation Or = S1->ChangeSurface().Face().Orientation();
331   if(!fsp->IsConstant()) throw Standard_ConstructionError("PerformSurf : no variable radiuses");
332   // Standard_Boolean maybesingular; //pour scinder les Surfdata singulieres 
333   
334   BRepBlend_ConstRad Func(S1,S2,Guide);
335   BRepBlend_ConstRadInv FInv(S1,S2,Guide);
336   Func.Set(fsp->Radius(),Choix);
337   FInv.Set(fsp->Radius(),Choix);
338   switch (GetFilletShape()) {
339   case ChFi3d_Rational:
340     Func.Set(BlendFunc_Rational);
341     break;
342   case ChFi3d_QuasiAngular:
343     Func.Set(BlendFunc_QuasiAngular);
344     break;
345   case ChFi3d_Polynomial:
346     Func.Set(BlendFunc_Polynomial);
347   }
348   Standard_Real PFirst = First;
349   done = SimulData(Data,Guide,lin,S1,I1,
350                    S2,I2,Func,FInv,PFirst,MaxStep,Fleche,
351                    TolGuide,First,Last,Inside,Appro,Forward,Soldep,
352                    20,RecOnS1,RecOnS2);
353   if(!done) return Standard_False;
354   if(lin->StartPointOnFirst().NbPointOnRst() !=0){
355     ChFi3d_FilCommonPoint(lin->StartPointOnFirst(),lin->TransitionOnS1(),
356                           Standard_True, Data->ChangeVertexFirstOnS1(), tolesp);
357   }
358   if(lin->EndPointOnFirst().NbPointOnRst() !=0){
359     ChFi3d_FilCommonPoint(lin->EndPointOnFirst(),lin->TransitionOnS1(),
360                           Standard_False,Data->ChangeVertexLastOnS1(), tolesp);
361   }
362   if(lin->StartPointOnSecond().NbPointOnRst() !=0){
363     ChFi3d_FilCommonPoint(lin->StartPointOnSecond(),lin->TransitionOnS2(),
364                           Standard_True, Data->ChangeVertexFirstOnS2(), tolesp);
365   }
366   if(lin->EndPointOnSecond().NbPointOnRst() !=0){
367     ChFi3d_FilCommonPoint(lin->EndPointOnSecond(),lin->TransitionOnS2(),
368                           Standard_False, Data->ChangeVertexLastOnS2(), tolesp);
369   }
370   done = CompleteData(Data,Func,lin,S1,S2,Or,0,0,0,0);
371   if(!done)  throw Standard_Failure("PerformSurf : Failed approximation!");
372 //  maybesingular = (Func.GetMinimalDistance()<=100*tolapp3d);
373   Standard_Boolean ok = Standard_False;
374   if(!Forward){
375     Intf = 0;
376     const ChFiDS_CommonPoint& cpf1 = Data->VertexFirstOnS1();
377     if(cpf1.IsOnArc()){
378       TopoDS_Face F1 = S1->ChangeSurface().Face();
379       TopoDS_Face bid;
380       Intf = !SearchFace(Spine,cpf1,F1,bid);
381       ok = Intf != 0;
382     }
383     const ChFiDS_CommonPoint& cpf2 = Data->VertexFirstOnS2();
384     if(cpf2.IsOnArc() && !ok){
385       TopoDS_Face F2 = S2->ChangeSurface().Face();
386       TopoDS_Face bid;
387       Intf = !SearchFace(Spine,cpf2,F2,bid);
388     }
389   }
390   Intl = 0;
391   ok = Standard_False;
392   const ChFiDS_CommonPoint& cpl1 = Data->VertexLastOnS1();
393   if(cpl1.IsOnArc()){
394     TopoDS_Face F1 = S1->ChangeSurface().Face();
395     TopoDS_Face bid;
396     Intl = !SearchFace(Spine,cpl1,F1,bid);
397     ok = Intl != 0;
398   }
399   const ChFiDS_CommonPoint& cpl2 = Data->VertexLastOnS2();
400   if(cpl2.IsOnArc() && !ok){
401     TopoDS_Face F2 = S2->ChangeSurface().Face();
402     TopoDS_Face bid;
403     Intl = !SearchFace(Spine,cpl2,F2,bid);
404   }
405   Data->FirstSpineParam(First);
406   Data->LastSpineParam (Last);
407
408 //  if (maybesingular) SplitSurf(SeqData, lin);
409 //  Necessite de trimer resultats : A faire
410   return Standard_True;
411 }
412
413 void FilletSurf_InternalBuilder::PerformSurf (ChFiDS_SequenceOfSurfData& , const Handle(ChFiDS_HElSpine)& , const Handle(ChFiDS_Spine)& , const Standard_Integer , const Handle(BRepAdaptor_HSurface)& , const Handle(Adaptor3d_TopolTool)& , const Handle(BRepAdaptor_HCurve2d)& , const Handle(BRepAdaptor_HSurface)& , const Handle(BRepAdaptor_HCurve2d)& , Standard_Boolean& , const Handle(BRepAdaptor_HSurface)& , const Handle(Adaptor3d_TopolTool)& , const TopAbs_Orientation , const Standard_Real , const Standard_Real , const Standard_Real , Standard_Real& , Standard_Real& , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const math_Vector& )
414 {
415  throw Standard_DomainError("BlendFunc_CSConstRad::Section : Not implemented");
416 }
417
418 void FilletSurf_InternalBuilder::PerformSurf (ChFiDS_SequenceOfSurfData& , const Handle(ChFiDS_HElSpine)& , const Handle(ChFiDS_Spine)& , const Standard_Integer , const Handle(BRepAdaptor_HSurface)& , const Handle(Adaptor3d_TopolTool)& , const TopAbs_Orientation , const Handle(BRepAdaptor_HSurface)& , const Handle(Adaptor3d_TopolTool)& , const Handle(BRepAdaptor_HCurve2d)& , const Handle(BRepAdaptor_HSurface)& , const Handle(BRepAdaptor_HCurve2d)& , Standard_Boolean& , const Standard_Real , const Standard_Real , const Standard_Real , Standard_Real& , Standard_Real& , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const math_Vector& )
419 {
420  throw Standard_DomainError("BlendFunc_CSConstRad::Section : Not implemented");
421 }
422
423 void FilletSurf_InternalBuilder::PerformSurf (ChFiDS_SequenceOfSurfData& , const Handle(ChFiDS_HElSpine)& , const Handle(ChFiDS_Spine)& , const Standard_Integer , const Handle(BRepAdaptor_HSurface)& , const Handle(Adaptor3d_TopolTool)& , const Handle(BRepAdaptor_HCurve2d)& , const Handle(BRepAdaptor_HSurface)& , const Handle(BRepAdaptor_HCurve2d)& , Standard_Boolean& , const TopAbs_Orientation , const Handle(BRepAdaptor_HSurface)& , const Handle(Adaptor3d_TopolTool)& , const Handle(BRepAdaptor_HCurve2d)& , const Handle(BRepAdaptor_HSurface)& , const Handle(BRepAdaptor_HCurve2d)& , Standard_Boolean& , const TopAbs_Orientation , const Standard_Real , const Standard_Real , const Standard_Real , Standard_Real& , Standard_Real& , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const Standard_Boolean , const math_Vector& )
424 {
425  throw Standard_DomainError("BlendFunc_CSConstRad::Section : Not implemented");
426 }
427
428 Standard_Boolean  FilletSurf_InternalBuilder::Done() const
429 {
430  return done;
431 }
432 //=======================================================================
433 //function : NbSurface
434 //purpose  :  gives the number of NUBS surfaces  of the Fillet
435 //=======================================================================
436
437 Standard_Integer FilletSurf_InternalBuilder::NbSurface() const 
438 {
439   return myListStripe.First()->SetOfSurfData()->Length();
440 }
441
442 //=======================================================================
443 //function : SurfaceFillet
444 //purpose  : gives the NUBS surface of index Index
445 //=======================================================================
446
447 const Handle(Geom_Surface)& FilletSurf_InternalBuilder::SurfaceFillet(const Standard_Integer Index) const 
448 {
449   Standard_Integer isurf = myListStripe.First()->SetOfSurfData()->Value(Index)->Surf();
450
451   return myDS->Surface(isurf).Surface();
452 }
453
454  //=======================================================================
455 //function : TolApp3d
456 //purpose  :  gives the 3d tolerance reached during approximation 
457 //=======================================================================
458
459 Standard_Real  FilletSurf_InternalBuilder::TolApp3d(const Standard_Integer Index) const 
460 {
461   Standard_Integer isurf = myListStripe.First()->SetOfSurfData()->Value(Index)->Surf();
462
463   return myDS->Surface(isurf).Tolerance();
464 }
465
466 //=======================================================================
467 //function : SupportFace1 
468 //purpose  : gives the first support  face relative to SurfaceFillet(Index)
469 //=======================================================================
470 const TopoDS_Face& FilletSurf_InternalBuilder::SupportFace1(const Standard_Integer Index) const
471 {
472   Standard_Integer isurf = myListStripe.First()->SetOfSurfData()->Value(Index)->IndexOfS1();
473
474   return TopoDS::Face(myDS->Shape(isurf));
475 }
476 //=======================================================================
477 //function : SupportFace2
478 //purpose  : gives the second support face relative to SurfaceFillet(Index)
479 //=======================================================================
480 const TopoDS_Face& FilletSurf_InternalBuilder::SupportFace2(const Standard_Integer Index) const 
481 {
482   Standard_Integer isurf = myListStripe.First()->SetOfSurfData()->Value(Index)->IndexOfS2();
483
484   return TopoDS::Face(myDS->Shape(isurf));
485 }
486 //===============================================================================
487 //function : CurveOnSup1 
488 //purpose  :  gives  the 3d curve  of SurfaceFillet(Index)  on SupportFace1(Index)
489 //===============================================================================
490
491 const Handle(Geom_Curve)& FilletSurf_InternalBuilder::CurveOnFace1(const Standard_Integer Index) const 
492 {
493   Standard_Integer icurv = myListStripe.First()->SetOfSurfData()->Value(Index)->
494     InterferenceOnS1().LineIndex();
495   return myDS->Curve(icurv).Curve();
496 }
497
498 //=======================================================================
499 //function : CurveOnSup2
500 //purpose  : gives the 3d  curve of  SurfaceFillet(Index) on SupportFace2(Index
501 //=======================================================================
502
503 const Handle(Geom_Curve)& FilletSurf_InternalBuilder::CurveOnFace2(const Standard_Integer Index) const 
504 {
505   Standard_Integer icurv=myListStripe.First()->SetOfSurfData()->Value(Index)->
506     InterferenceOnS2().LineIndex();
507   return myDS->Curve(icurv).Curve();
508 }
509 //=======================================================================
510 //function : PCurveOnFace1
511 //purpose  : gives the  PCurve associated to CurvOnSup1(Index)  on the support face
512 //=======================================================================
513 const Handle(Geom2d_Curve)& FilletSurf_InternalBuilder::PCurveOnFace1(const Standard_Integer Index) const 
514 {
515   return myListStripe.First()->SetOfSurfData()->Value(Index)->
516     InterferenceOnS1().PCurveOnFace();
517
518 }
519
520 //=======================================================================
521 //function : PCurveOnFillet1
522 //purpose  : gives the PCurve associated to CurveOnFace1(Index) on the Fillet
523 //=======================================================================
524
525 const Handle(Geom2d_Curve)& FilletSurf_InternalBuilder::PCurve1OnFillet(const Standard_Integer Index) const 
526 {return myListStripe.First()->SetOfSurfData()->Value(Index)->
527     InterferenceOnS1().PCurveOnSurf();
528  
529 }
530
531 //=======================================================================
532 //function : PCurveOnFace2
533 //purpose  : gives the  PCurve associated to CurvOnSup2(Index)  on the support face
534 //=======================================================================
535 const Handle(Geom2d_Curve)& FilletSurf_InternalBuilder::PCurveOnFace2(const Standard_Integer Index) const 
536 {
537   return myListStripe.First()->SetOfSurfData()->Value(Index)->
538     InterferenceOnS2().PCurveOnFace();
539 }
540
541 //=======================================================================
542 //function : PCurveOnFillet2
543 //purpose  : gives the PCurve associated to CurveOnFace2(Index) on the Fillet
544 //=======================================================================
545 const Handle(Geom2d_Curve)& FilletSurf_InternalBuilder::PCurve2OnFillet(const Standard_Integer Index) const 
546 {return myListStripe.First()->SetOfSurfData()->Value(Index)->
547     InterferenceOnS2().PCurveOnSurf();
548   
549 }
550
551 //=======================================================================
552 //function : FirstParameter 
553 //purpose  : gives the parameter of the fillet  on the first edge
554 //=======================================================================
555
556 Standard_Real FilletSurf_InternalBuilder::FirstParameter() const
557 {
558   const Handle(ChFiDS_Stripe)& st = myListStripe.First();
559   const Handle(ChFiDS_Spine)& sp = st->Spine();
560   const Handle(ChFiDS_SurfData)& sd = st->SetOfSurfData()->Value(1);
561   Standard_Real p = sd->FirstSpineParam();
562   Standard_Integer ind = 1;
563   if(sp->IsPeriodic()) ind = sp->Index(p);
564   Standard_Real ep;
565   if(ComputeEdgeParameter(sp,ind,p,ep,tolesp)) return ep;
566   return 0.0;
567 }
568 //=======================================================================
569 //function : LastParameter
570 //purpose  :  gives the parameter of the fillet  on the last edge
571 //=======================================================================
572 Standard_Real FilletSurf_InternalBuilder::LastParameter() const
573 {
574   const Handle(ChFiDS_Stripe)& st = myListStripe.First();
575   const Handle(ChFiDS_Spine)& sp = st->Spine();
576   const Handle(ChFiDS_SurfData)& sd = st->SetOfSurfData()->Value(NbSurface());
577   Standard_Real p = sd->LastSpineParam();
578   Standard_Integer ind = sp->NbEdges();
579   if(sp->IsPeriodic()) ind = sp->Index(p);
580   Standard_Real ep;
581   if(ComputeEdgeParameter(sp,ind,p,ep,tolesp)) return ep;
582   return 0.0;
583 }
584
585 //=======================================================================
586 //function : StatusStartSection
587 //purpose  :  returns: 
588 //       twoExtremityonEdge: each extremity of  start section of the Fillet is
589 //                        on the edge of  the corresponding support face.  
590 //       OneExtremityOnEdge:  only one  of  the extremities of  start  section  of the  Fillet 
591 //                           is on the  edge of the corresponding support face.  
592 //       NoExtremityOnEdge:  any extremity of  start  section  of the fillet is  on  
593 //                           the edge  of   the  corresponding support face.
594 //=======================================================================
595
596
597 FilletSurf_StatusType  FilletSurf_InternalBuilder::StartSectionStatus() const 
598
599  
600    Standard_Boolean isonedge1 = myListStripe.First()->SetOfSurfData()->Value(1)->
601                                 VertexFirstOnS1().IsOnArc();
602    Standard_Boolean isonedge2=  myListStripe.First()->SetOfSurfData()->Value(1)->
603                                 VertexFirstOnS2().IsOnArc();;
604
605   if (isonedge1 && isonedge2) 
606   {return FilletSurf_TwoExtremityOnEdge;}
607   else if ((!isonedge1)&& (!isonedge2)) 
608   {return FilletSurf_NoExtremityOnEdge ;}
609   else 
610     {return FilletSurf_OneExtremityOnEdge;}
611 }
612 //=======================================================================
613 //function : StatusEndSection()
614 //purpose  :  returns: 
615 //            twoExtremityonEdge: each extremity of  end section of the Fillet is
616 //                                on the edge of  the corresponding support face.  
617 //            OneExtremityOnEdge: only one  of  the extremities of  end section  of the  Fillet 
618 //                                is on the  edge of the corresponding support face.  
619 //            NoExtremityOnEdge:  any extremity of   end  section  of the fillet is  on  
620 //                                the edge  of   the  corresponding support face.
621 //=======================================================================
622 FilletSurf_StatusType  FilletSurf_InternalBuilder::EndSectionStatus() const 
623
624    Standard_Boolean isonedge1 = myListStripe.First()->SetOfSurfData()->Value(NbSurface())->
625                                 VertexLastOnS1().IsOnArc();
626    Standard_Boolean isonedge2=  myListStripe.First()->SetOfSurfData()->Value(NbSurface())->
627                                 VertexLastOnS2().IsOnArc();
628
629   if (isonedge1 && isonedge2) 
630   { return FilletSurf_TwoExtremityOnEdge;}
631   else if ((!isonedge1)&& (!isonedge2)) 
632    { return FilletSurf_NoExtremityOnEdge;}
633   else 
634     { return FilletSurf_OneExtremityOnEdge;}
635 }
636
637
638 //=======================================================================
639 //function : Simulate
640 //purpose  : computes only the sections used in the computation of the fillet
641 //=======================================================================
642 void FilletSurf_InternalBuilder::Simulate()
643 {
644  //ChFi3d_FilBuilder::Simulate(1);
645  Handle(ChFiDS_Stripe) Stripe = myListStripe.First();
646   Handle(ChFiDS_HData)&  HData  = Stripe->ChangeSetOfSurfData();
647   HData =  new ChFiDS_HData();
648   Handle(ChFiDS_Spine)& Spine = Stripe->ChangeSpine();
649   TopAbs_Orientation RefOr1,RefOr2;
650   Standard_Integer RefChoix;
651   StripeOrientations(Spine,RefOr1,RefOr2,RefChoix);
652   Stripe->OrientationOnFace1(RefOr1);
653   Stripe->OrientationOnFace2(RefOr2);
654   Stripe->Choix(RefChoix);
655   PerformSetOfKGen(Stripe,1);
656 }
657
658
659 //=======================================================================
660 //function : NbSection
661 //purpose  :  gives the number of sections relative to SurfaceFillet(IndexSurf)
662 //=======================================================================
663 Standard_Integer FilletSurf_InternalBuilder::NbSection(const Standard_Integer IndexSurf) const 
664 {
665 return Sect(1,IndexSurf)->Length();
666 }
667
668 //=======================================================================
669 //function : Section
670 //purpose  : gives the   arc of circle corresponding    to section number 
671 //           IndexSec  of  SurfaceFillet(IndexSurf)  (The   basis curve  of the 
672 //           trimmed curve is a Geom_Circle) 
673 //=======================================================================
674 void FilletSurf_InternalBuilder::Section(const Standard_Integer IndexSurf, const Standard_Integer IndexSec, Handle(Geom_TrimmedCurve)& Circ) const 
675 {
676  gp_Circ c;
677  Standard_Real deb,fin; 
678  Sect(1,IndexSurf)->Value(IndexSec).Get(c,deb,fin);
679  Handle(Geom_Circle) Gc = new Geom_Circle(c);
680  Circ= new Geom_TrimmedCurve(Gc,deb,fin);
681 }
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696