0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BRepFilletAPI / BRepFilletAPI_MakeFillet.cxx
1 // Created on: 1994-06-17
2 // Created by: Modeling
3 // Copyright (c) 1994-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 <BRepFilletAPI_MakeFillet.hxx>
19 #include <ChFiDS_ErrorStatus.hxx>
20 #include <ChFiDS_Spine.hxx>
21 #include <Geom_Surface.hxx>
22 #include <Law_Function.hxx>
23 #include <Law_Interpol.hxx>
24 #include <Law_Linear.hxx>
25 #include <Law_S.hxx>
26 #include <Precision.hxx>
27 #include <Standard_NoSuchObject.hxx>
28 #include <StdFail_NotDone.hxx>
29 #include <TopExp_Explorer.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Vertex.hxx>
33 #include <TopOpeBRepBuild_HBuilder.hxx>
34 #include <TopOpeBRepDS_HDataStructure.hxx>
35 #include <TopTools_ListIteratorOfListOfShape.hxx>
36
37 //=======================================================================
38 //function : BRepFilletAPI_MakeFillet
39 //purpose  : 
40 //=======================================================================
41 BRepFilletAPI_MakeFillet::BRepFilletAPI_MakeFillet(const TopoDS_Shape& S,
42                                        const ChFi3d_FilletShape FShape):
43    myBuilder(S,FShape)
44 {
45 }
46
47 //=======================================================================
48 //function : SetParams
49 //purpose  : 
50 //=======================================================================
51
52 void BRepFilletAPI_MakeFillet::SetParams(const Standard_Real Tang, 
53                                          const Standard_Real Tesp, 
54                                          const Standard_Real T2d, 
55                                          const Standard_Real TApp3d, 
56                                          const Standard_Real TolApp2d, 
57                                          const Standard_Real Fleche)
58 {
59   myBuilder.SetParams(Tang,Tesp, T2d, TApp3d, TolApp2d, Fleche);
60 }
61
62 //=======================================================================
63 //function : SetContinuity
64 //purpose  : 
65 //=======================================================================
66
67 void BRepFilletAPI_MakeFillet::SetContinuity(
68                               const GeomAbs_Shape InternalContinuity,
69                               const Standard_Real AngleTol)
70 {
71   myBuilder.SetContinuity(InternalContinuity, AngleTol );
72 }
73
74 //=======================================================================
75 //function : Add
76 //purpose  : 
77 //=======================================================================
78
79 void BRepFilletAPI_MakeFillet::Add(const TopoDS_Edge&  E)
80 {
81   myBuilder.Add(E);
82 }
83
84
85 //=======================================================================
86 //function : Add
87 //purpose  : 
88 //=======================================================================
89
90 void BRepFilletAPI_MakeFillet::Add(const Standard_Real Radius,
91                                    const TopoDS_Edge&  E)
92 {
93   //myBuilder.Add(Radius,E);
94   myBuilder.Add(E);
95   Standard_Integer IinC;
96   Standard_Integer IC = myBuilder.Contains(E, IinC);
97   if (IC)
98     SetRadius( Radius, IC, IinC );
99 }
100
101
102
103 //=======================================================================
104 //function : Add
105 //purpose  : 
106 //=======================================================================
107
108 void BRepFilletAPI_MakeFillet::Add(const Standard_Real R1,
109                                    const Standard_Real R2,
110                                    const TopoDS_Edge&  E)
111 {
112   myBuilder.Add(E);
113   Standard_Integer IinC;
114   Standard_Integer IC = myBuilder.Contains(E, IinC);
115   if (IC)
116     SetRadius(R1,R2,IC,IinC);
117 }
118
119
120 //=======================================================================
121 //function : Add
122 //purpose  : 
123 //=======================================================================
124
125 void BRepFilletAPI_MakeFillet::Add(const Handle(Law_Function)& L,
126                                    const TopoDS_Edge&  E)
127 {
128   //myBuilder.Add(L,E);
129   myBuilder.Add(E);
130   Standard_Integer IinC;
131   Standard_Integer IC = myBuilder.Contains(E, IinC);
132   if (IC)
133     SetRadius(L,IC,IinC);
134 }
135
136
137 //=======================================================================
138 //function : Add
139 //purpose  : 
140 //=======================================================================
141
142 void BRepFilletAPI_MakeFillet::Add(const TColgp_Array1OfPnt2d& UandR,
143                                    const TopoDS_Edge&  E)
144 {
145   myBuilder.Add(E);
146   Standard_Integer IinC;
147   Standard_Integer IC = myBuilder.Contains(E, IinC);
148   if (IC)
149     SetRadius( UandR, IC, IinC );
150 }
151
152
153 //=======================================================================
154 //function : SetRadius
155 //purpose  : 
156 //=======================================================================
157
158 void BRepFilletAPI_MakeFillet::SetRadius(const Standard_Real    Radius,
159                                          const Standard_Integer IC,
160                                          const Standard_Integer IinC)
161 {
162   gp_XY FirstUandR( 0., Radius ), LastUandR( 1., Radius );
163   myBuilder.SetRadius( FirstUandR, IC, IinC );
164   myBuilder.SetRadius( LastUandR,  IC, IinC );
165 }
166
167
168 //=======================================================================
169 //function : SetRadius
170 //purpose  : 
171 //=======================================================================
172
173 void BRepFilletAPI_MakeFillet::SetRadius(const Standard_Real R1,
174                                          const Standard_Real R2,
175                                          const Standard_Integer IC,
176                                          const Standard_Integer IinC)
177 {
178   Standard_Real r1, r2;
179
180   if(Abs(R1-R2) < Precision::Confusion())
181     r1 = r2 = (R1+R2)*0.5;
182   else
183     {
184       r1 = R1;
185       r2 = R2;
186     }
187   gp_XY FirstUandR( 0., r1 ), LastUandR( 1., r2 );
188   myBuilder.SetRadius( FirstUandR, IC, IinC );
189   myBuilder.SetRadius( LastUandR,  IC, IinC );
190 }
191
192
193 //=======================================================================
194 //function : SetRadius
195 //purpose  : 
196 //=======================================================================
197
198 void BRepFilletAPI_MakeFillet::SetRadius(const Handle(Law_Function)& L,
199                                          const Standard_Integer      IC,
200                                          const Standard_Integer      IinC)
201 {
202   myBuilder.SetRadius(L,IC,IinC);
203 }
204
205
206 //=======================================================================
207 //function : SetRadius
208 //purpose  : 
209 //=======================================================================
210
211 void BRepFilletAPI_MakeFillet::SetRadius(const TColgp_Array1OfPnt2d& UandR,
212                                          const Standard_Integer IC,
213                                          const Standard_Integer IinC)
214 {
215   if(UandR.Length() == 1)
216     SetRadius( UandR(UandR.Lower()).Y(), IC, IinC );
217   else if(UandR.Length() == 2)
218     SetRadius( UandR(UandR.Lower()).Y(), UandR(UandR.Upper()).Y(), IC, IinC );
219   else{
220     Standard_Real Uf = UandR(UandR.Lower()).X();
221     Standard_Real Ul = UandR(UandR.Upper()).X();
222     for(Standard_Integer i = UandR.Lower(); i <= UandR.Upper(); i++){
223       Standard_Real Ucur = UandR(i).X();
224       Ucur = ( Ucur - Uf ) / ( Ul - Uf );
225       gp_XY newUandR( Ucur, UandR(i).Y() );
226       myBuilder.SetRadius( newUandR, IC, IinC );
227     }
228   }
229 }
230
231
232 //=======================================================================
233 //function : IsConstant
234 //purpose  : 
235 //=======================================================================
236
237 Standard_Boolean BRepFilletAPI_MakeFillet::IsConstant(const Standard_Integer IC)
238 {
239   return myBuilder.IsConstant(IC);
240 }
241
242
243 //=======================================================================
244 //function : Radius
245 //purpose  : 
246 //=======================================================================
247
248 Standard_Real BRepFilletAPI_MakeFillet::Radius(const Standard_Integer IC)
249 {
250   return myBuilder.Radius(IC);
251 }
252
253
254 //=======================================================================
255 //function : ResetContour
256 //purpose  : 
257 //=======================================================================
258
259 void BRepFilletAPI_MakeFillet::ResetContour(const Standard_Integer IC)
260 {
261   myBuilder.ResetContour(IC);
262 }
263
264
265 //=======================================================================
266 //function : IsConstant
267 //purpose  : 
268 //=======================================================================
269
270 Standard_Boolean BRepFilletAPI_MakeFillet::IsConstant(const Standard_Integer IC,
271                                                       const TopoDS_Edge&     E)
272 {
273   return myBuilder.IsConstant(IC,E);
274 }
275
276
277 //=======================================================================
278 //function : Radius
279 //purpose  : 
280 //=======================================================================
281
282 Standard_Real BRepFilletAPI_MakeFillet::Radius(const Standard_Integer IC,
283                                                const TopoDS_Edge&     E)
284 {
285   return myBuilder.Radius(IC,E);
286 }
287
288
289 //=======================================================================
290 //function : SetRadius
291 //purpose  : 
292 //=======================================================================
293
294 void BRepFilletAPI_MakeFillet::SetRadius(const Standard_Real    Radius,
295                                          const Standard_Integer IC,
296                                          const TopoDS_Edge&     E)
297 {
298   myBuilder.SetRadius(Radius,IC,E);
299 }
300
301
302 //=======================================================================
303 //function : GetBounds
304 //purpose  : 
305 //=======================================================================
306
307 Standard_Boolean BRepFilletAPI_MakeFillet::GetBounds(const Standard_Integer IC,
308                                                      const TopoDS_Edge&     E,
309                                                      Standard_Real&         F,
310                                                      Standard_Real&         L)
311 {
312   return myBuilder.GetBounds(IC,E,F,L);
313 }
314
315
316 //=======================================================================
317 //function : GetLaw
318 //purpose  : 
319 //=======================================================================
320
321 Handle(Law_Function) BRepFilletAPI_MakeFillet::GetLaw(const Standard_Integer IC,
322                                                       const TopoDS_Edge&     E)
323 {
324   return myBuilder.GetLaw(IC,E);
325 }
326
327
328 //=======================================================================
329 //function : SetLaw
330 //purpose  : 
331 //=======================================================================
332
333 void BRepFilletAPI_MakeFillet::SetLaw(const Standard_Integer      IC,
334                                       const TopoDS_Edge&          E,
335                                       const Handle(Law_Function)& L)
336 {
337   myBuilder.SetLaw(IC,E, L);
338 }
339
340
341 //=======================================================================
342 //function : SetRadius
343 //purpose  : 
344 //=======================================================================
345
346 void BRepFilletAPI_MakeFillet::SetRadius(const Standard_Real    Radius,
347                                          const Standard_Integer IC,
348                                          const TopoDS_Vertex&   V)
349 {
350   myBuilder.SetRadius(Radius,IC,V);
351 }
352
353 //=======================================================================
354 //function : SetFilletShape
355 //purpose  : 
356 //=======================================================================
357
358 void BRepFilletAPI_MakeFillet::SetFilletShape(const ChFi3d_FilletShape FShape)
359 {
360   myBuilder.SetFilletShape(FShape);
361 }
362   
363
364 //=======================================================================
365 //function : GetFilletShape
366 //purpose  : 
367 //=======================================================================
368
369 ChFi3d_FilletShape BRepFilletAPI_MakeFillet::GetFilletShape() const
370 {
371   return myBuilder.GetFilletShape();
372 }
373   
374
375 //=======================================================================
376 //function : NbContours
377 //purpose  : 
378 //=======================================================================
379
380 Standard_Integer BRepFilletAPI_MakeFillet::NbContours()const
381 {
382   return myBuilder.NbElements();
383 }
384
385
386 //=======================================================================
387 //function : Contour
388 //purpose  : 
389 //=======================================================================
390
391 Standard_Integer BRepFilletAPI_MakeFillet::Contour(const TopoDS_Edge& E)const
392 {
393   return myBuilder.Contains(E);  
394 }
395
396
397 //=======================================================================
398 //function : NbEdges
399 //purpose  : 
400 //=======================================================================
401
402 Standard_Integer BRepFilletAPI_MakeFillet::NbEdges(const Standard_Integer I)const
403 {
404   const Handle(ChFiDS_Spine)& Spine = myBuilder.Value(I);
405   Standard_Integer n = Spine->NbEdges();
406   return n;
407 }
408
409 //=======================================================================
410 //function : Edge
411 //purpose  : 
412 //=======================================================================
413
414 const TopoDS_Edge& BRepFilletAPI_MakeFillet::Edge(const Standard_Integer I,
415                                                   const Standard_Integer J)const
416 {
417   const Handle(ChFiDS_Spine)& Spine = myBuilder.Value(I);
418   const TopoDS_Edge& S = Spine->Edges(J);
419   return S;
420 }
421
422
423 //=======================================================================
424 //function : Remove
425 //purpose  : 
426 //=======================================================================
427
428 void BRepFilletAPI_MakeFillet::Remove(const TopoDS_Edge& E)
429 {
430   myBuilder.Remove(E);
431 }
432
433
434 //=======================================================================
435 //function : Length
436 //purpose  : 
437 //=======================================================================
438
439 Standard_Real BRepFilletAPI_MakeFillet::Length(const Standard_Integer IC)const
440 {
441   return myBuilder.Length(IC);
442 }
443
444
445 //=======================================================================
446 //function : FirstVertex
447 //purpose  : 
448 //=======================================================================
449
450 TopoDS_Vertex BRepFilletAPI_MakeFillet::FirstVertex(const Standard_Integer IC)const
451 {
452   return myBuilder.FirstVertex(IC);
453 }
454
455
456 //=======================================================================
457 //function : LastVertex
458 //purpose  : 
459 //=======================================================================
460
461 TopoDS_Vertex BRepFilletAPI_MakeFillet::LastVertex(const Standard_Integer IC)const
462 {
463   return myBuilder.LastVertex(IC);
464 }
465
466
467 //=======================================================================
468 //function : Abscissa
469 //purpose  : 
470 //=======================================================================
471
472 Standard_Real BRepFilletAPI_MakeFillet::Abscissa(const Standard_Integer IC,
473                                                  const TopoDS_Vertex& V)const
474 {
475   return myBuilder.Abscissa(IC,V);
476 }
477
478
479 //=======================================================================
480 //function : RelativeAbscissa
481 //purpose  : 
482 //=======================================================================
483
484 Standard_Real BRepFilletAPI_MakeFillet::RelativeAbscissa(const Standard_Integer IC,
485                                                          const TopoDS_Vertex& V)const
486 {
487   return myBuilder.RelativeAbscissa(IC,V);
488 }
489
490
491 //=======================================================================
492 //function : ClosedAndTangent
493 //purpose  : 
494 //=======================================================================
495
496 Standard_Boolean BRepFilletAPI_MakeFillet::ClosedAndTangent
497 (const Standard_Integer IC)const
498 {
499   return myBuilder.ClosedAndTangent(IC);
500 }
501
502
503 //=======================================================================
504 //function : Closed
505 //purpose  : 
506 //=======================================================================
507
508 Standard_Boolean BRepFilletAPI_MakeFillet::Closed
509 (const Standard_Integer IC)const
510 {
511   return myBuilder.Closed(IC);
512 }
513
514
515 //=======================================================================
516 //function : Builder
517 //purpose  : 
518 //=======================================================================
519
520 Handle(TopOpeBRepBuild_HBuilder) BRepFilletAPI_MakeFillet::Builder()const 
521 {
522   return myBuilder.Builder();
523 }
524
525
526 //=======================================================================
527 //function : Build
528 //purpose  : 
529 //=======================================================================
530
531 void BRepFilletAPI_MakeFillet::Build()
532 {
533   myBuilder.Compute();
534   if(myBuilder.IsDone()) {
535     Done();
536     myShape = myBuilder.Shape();
537
538     // creation of the Map.
539     TopExp_Explorer ex;
540     for (ex.Init(myShape, TopAbs_FACE); ex.More(); ex.Next()) {
541       myMap.Add(ex.Current());
542     }
543   }
544 }
545
546
547 //=======================================================================
548 //function : Reset
549 //purpose  : 
550 //=======================================================================
551
552 void BRepFilletAPI_MakeFillet::Reset()
553 {
554   NotDone();
555   myBuilder.Reset();
556   myMap.Clear();
557 }
558
559 //=======================================================================
560 //function : NbSurfaces
561 //purpose  : 
562 //=======================================================================
563
564 Standard_Integer BRepFilletAPI_MakeFillet::NbSurfaces() const
565 {
566   return (myBuilder.Builder()->DataStructure())->NbSurfaces();
567 }
568
569 //=======================================================================
570 //function : NewFaces
571 //purpose  : 
572 //=======================================================================
573
574 const TopTools_ListOfShape& BRepFilletAPI_MakeFillet::NewFaces
575   (const Standard_Integer I)
576 {
577   return (*(TopTools_ListOfShape*)&(myBuilder.Builder()->NewFaces(I)));
578 }
579
580 //=======================================================================
581 //function : Simulate
582 //purpose  : 
583 //=======================================================================
584
585 void BRepFilletAPI_MakeFillet::Simulate(const Standard_Integer IC)
586 {
587   myBuilder.Simulate(IC);
588 }
589
590
591 //=======================================================================
592 //function : NbSurf
593 //purpose  : 
594 //=======================================================================
595
596 Standard_Integer  BRepFilletAPI_MakeFillet::NbSurf(const Standard_Integer IC)const
597 {
598   return myBuilder.NbSurf(IC);
599 }
600
601 //=======================================================================
602 //function : Sect
603 //purpose  : 
604 //=======================================================================
605
606 Handle(ChFiDS_SecHArray1) BRepFilletAPI_MakeFillet::Sect(const Standard_Integer IC,
607                                                          const Standard_Integer IS)const
608 {
609   return myBuilder.Sect(IC, IS);
610 }
611
612 //=======================================================================
613 //function : Generated
614 //purpose  : 
615 //=======================================================================
616
617 const TopTools_ListOfShape& BRepFilletAPI_MakeFillet::Generated
618   (const TopoDS_Shape& EorV)
619 {
620   return myBuilder.Generated(EorV);
621 }
622
623 //=======================================================================
624 //function : Modified
625 //purpose  : 
626 //=======================================================================
627
628 const TopTools_ListOfShape& BRepFilletAPI_MakeFillet::Modified
629   (const TopoDS_Shape& F)
630 {
631   myGenerated.Clear();
632
633   if (myBuilder.Builder()->IsSplit(F, TopAbs_OUT)) {
634     TopTools_ListIteratorOfListOfShape It(myBuilder.Builder()->Splits(F, TopAbs_OUT));
635     for(;It.More();It.Next()) {
636       myGenerated.Append(It.Value());
637     }
638   }
639   if (myBuilder.Builder()->IsSplit(F, TopAbs_IN)) {
640     TopTools_ListIteratorOfListOfShape It(myBuilder.Builder()->Splits(F, TopAbs_IN));
641     for(;It.More();It.Next()) {
642       myGenerated.Append(It.Value());
643     }
644   }
645   if (myBuilder.Builder()->IsSplit(F, TopAbs_ON)) {
646     TopTools_ListIteratorOfListOfShape It(myBuilder.Builder()->Splits(F, TopAbs_ON));
647     for(;It.More();It.Next()) {
648       myGenerated.Append(It.Value());
649     }
650   }
651   return myGenerated;
652 }
653
654 //=======================================================================
655 //function : IsDeleted
656 //purpose  : 
657 //=======================================================================
658
659 Standard_Boolean BRepFilletAPI_MakeFillet::IsDeleted(const TopoDS_Shape& F) 
660 {
661   if (myMap.Contains(F) || 
662       myBuilder.Builder()->IsSplit (F, TopAbs_OUT)  ||
663       myBuilder.Builder()->IsSplit (F, TopAbs_IN)   ||
664       myBuilder.Builder()->IsSplit (F, TopAbs_ON))
665     return Standard_False;
666   
667   return Standard_True;    
668 }
669
670 //=======================================================================
671 //function : NbFaultyContours
672 //purpose  : 
673 //=======================================================================
674
675 Standard_Integer BRepFilletAPI_MakeFillet::NbFaultyContours() const
676 {
677   return myBuilder.NbFaultyContours();
678 }
679 //=======================================================================
680 //function : FaultyContour
681 //purpose  : 
682 //=======================================================================
683
684 Standard_Integer BRepFilletAPI_MakeFillet::FaultyContour(const Standard_Integer I) const
685 {
686  return myBuilder.FaultyContour(I);
687 }
688
689 //=======================================================================
690 //function : NbComputedSurfaces
691 //purpose  : 
692 //=======================================================================
693
694 Standard_Integer BRepFilletAPI_MakeFillet::NbComputedSurfaces(const Standard_Integer IC) const
695 {
696   return myBuilder.NbComputedSurfaces (IC);
697 }
698
699 //=======================================================================
700 //function : ComputedSurface
701 //purpose  : 
702 //=======================================================================
703
704 Handle(Geom_Surface) BRepFilletAPI_MakeFillet::ComputedSurface(const Standard_Integer IC,
705                                                                const Standard_Integer IS) const
706 {
707   return myBuilder.ComputedSurface(IC,IS);
708 }
709
710 //=======================================================================
711 //function : NbFaultyVertices
712 //purpose  : 
713 //=======================================================================
714
715 Standard_Integer BRepFilletAPI_MakeFillet::NbFaultyVertices() const
716 {
717   return myBuilder.NbFaultyVertices();
718 }
719
720 //=======================================================================
721 //function : FaultyVertex
722 //purpose  : 
723 //=======================================================================
724
725 TopoDS_Vertex BRepFilletAPI_MakeFillet::FaultyVertex(const Standard_Integer IV) const
726 {
727   return myBuilder.FaultyVertex(IV);
728 }
729
730 //=======================================================================
731 //function : HasResult
732 //purpose  : 
733 //=======================================================================
734
735 Standard_Boolean BRepFilletAPI_MakeFillet::HasResult() const 
736 {
737    return myBuilder.HasResult();
738 }
739
740 //=======================================================================
741 //function : BadShape
742 //purpose  : 
743 //=======================================================================
744
745 TopoDS_Shape BRepFilletAPI_MakeFillet::BadShape()const
746 {
747  return myBuilder.BadShape();
748 }
749
750 //=======================================================================
751 //function : StripeStatus
752 //purpose  : 
753 //=======================================================================
754
755 ChFiDS_ErrorStatus BRepFilletAPI_MakeFillet::StripeStatus(const Standard_Integer IC)const
756 {
757  return myBuilder.StripeStatus(IC);
758 }
759
760
761