0032781: Coding - get rid of unused headers [BRepCheck to ChFiKPart]
[occt.git] / src / BRepSweep / BRepSweep_NumLinearRegularSweep.cxx
1 // Created on: 1992-07-02
2 // Created by: Philippe DAUTRY
3 // Copyright (c) 1992-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 <BRepSweep_Iterator.hxx>
19 #include <BRepSweep_NumLinearRegularSweep.hxx>
20 #include <BRepSweep_Tool.hxx>
21 #include <Standard_NoMoreObject.hxx>
22 #include <Standard_NoSuchObject.hxx>
23 #include <Sweep_NumShape.hxx>
24 #include <Sweep_NumShapeIterator.hxx>
25 #include <Sweep_NumShapeTool.hxx>
26 #include <TopAbs.hxx>
27 #include <TopAbs_Orientation.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopTools_SequenceOfShape.hxx>
30
31 //=======================================================================
32 //function : BRepSweep_NumLinearRegularSweep
33 //purpose  : Create a Regular Sweep.
34 //=======================================================================
35 BRepSweep_NumLinearRegularSweep::BRepSweep_NumLinearRegularSweep
36   (const BRepSweep_Builder& aBuilder,
37   const TopoDS_Shape& aGenShape,
38   const Sweep_NumShape& aDirShape):
39
40 myBuilder(aBuilder),
41   myGenShape(aGenShape),
42   myDirWire(aDirShape),
43
44   myGenShapeTool(aGenShape),
45   myDirShapeTool(aDirShape),
46
47   // *****************************************************************
48   // Les Tableaux
49   // *****************************************************************
50
51   myShapes(1,myGenShapeTool.NbShapes(),
52   1,myDirShapeTool.NbShapes()),
53   myBuiltShapes(1,myGenShapeTool.NbShapes(),
54   1,myDirShapeTool.NbShapes()),
55   myUsedShapes(1, myGenShapeTool.NbShapes(),
56   1, myDirShapeTool.NbShapes())
57 {
58   myBuiltShapes.Init(Standard_False); 
59   myUsedShapes.Init(Standard_False);
60 }
61
62 //=======================================================================
63 //function : ~BRepSweep_NumLinearRegularSweep
64 //purpose  : Destructor
65 //=======================================================================
66
67 BRepSweep_NumLinearRegularSweep::~BRepSweep_NumLinearRegularSweep()
68 {
69 }
70
71 //=======================================================================
72 //function : Shape
73 //purpose  : Returns the global Shape.
74 //=======================================================================
75
76 TopoDS_Shape BRepSweep_NumLinearRegularSweep::Shape () 
77 {
78   if (HasShape(myGenShape,myDirWire)) return Shape(myGenShape,myDirWire);
79   else {
80     TopoDS_Shape bidon;
81     return bidon;
82   }
83 }
84
85
86 //=======================================================================
87 //function : Shape
88 //purpose  : Returns the Shape generated with aGenS.
89 //=======================================================================
90
91 TopoDS_Shape BRepSweep_NumLinearRegularSweep::Shape (const TopoDS_Shape& aGenS) 
92 {
93   if (myGenShapeTool.Index(aGenS) != 0 &&
94     HasShape(aGenS,myDirWire)) return Shape(aGenS,myDirWire);
95   else {
96     TopoDS_Shape bidon;
97     return bidon;
98   }
99 }
100
101
102 //=======================================================================
103 //function : Shape
104 //purpose  : Returns the Shape indexed by the arguments.
105 //=======================================================================
106
107 TopoDS_Shape BRepSweep_NumLinearRegularSweep::Shape (const TopoDS_Shape& aGenS, 
108   const Sweep_NumShape& aDirS)
109 {
110   Standard_Integer iGenS = myGenShapeTool.Index(aGenS);
111   Standard_Integer iDirS = myDirShapeTool.Index(aDirS);
112   if (!myBuiltShapes(iGenS,iDirS)){
113     TopoDS_Shape newShape;
114     TopoDS_Shape bGenS,cGenS,subGenS,subsubGenS;
115     Sweep_NumShape bDirS,subDirS;
116     BRepSweep_Iterator It;
117     Sweep_NumShapeIterator Kt;
118     BRepSweep_Iterator Lt;
119     TopAbs_Orientation Or,Pr;
120     if (myDirShapeTool.Type(aDirS)==TopAbs_VERTEX){
121       //Ici on construit les "planchers" du Shape.
122       TopAbs_ShapeEnum aGenSType = myGenShapeTool.Type(aGenS);
123       switch (aGenSType){
124       case TopAbs_VERTEX : 
125         myShapes(iGenS,iDirS)=MakeEmptyVertex(aGenS,aDirS);
126         break;
127       case TopAbs_EDGE :
128         myShapes(iGenS,iDirS)=MakeEmptyGeneratingEdge(aGenS,aDirS);
129         break;
130       case TopAbs_WIRE :
131         myBuilder.MakeWire(myShapes(iGenS,iDirS));
132         break;
133       case TopAbs_FACE :
134         myShapes(iGenS,iDirS)=MakeEmptyFace(aGenS,aDirS);
135         break;
136       case TopAbs_SHELL :
137         myBuilder.MakeShell(myShapes(iGenS,iDirS));
138         break;
139       case TopAbs_SOLID :
140         throw Standard_NoSuchObject("Solids are not Processed");
141         break;
142       case TopAbs_COMPSOLID :
143         throw Standard_NoSuchObject("Solids are not Processed");
144         break;
145       case TopAbs_COMPOUND :
146         myBuilder.MakeCompound(myShapes(iGenS,iDirS));
147         break;
148       default:
149         throw Standard_NoSuchObject("Unknown Shape");
150         break;
151       }
152       bGenS = aGenS;
153       myGenShapeTool.SetOrientation(bGenS,TopAbs_FORWARD);
154       for (It.Init(bGenS);It.More();It.Next()){
155         subGenS = It.Value();
156         Or = It.Orientation();
157         if(HasShape(subGenS,aDirS)){
158           newShape = Shape(subGenS,aDirS);
159           Standard_Integer iNewGenS = myGenShapeTool.Index(subGenS);
160           Standard_Integer iNewDirS = iDirS;
161           if (GGDShapeIsToAdd(myShapes(iGenS, iDirS), newShape,
162             aGenS,subGenS,aDirS)){
163               //Les "planchers" doivent etre construits par les 
164               //fonctions de construcion geometrique identiquement 
165               //au shape generateur.
166               //On leur recolle juste une orientation pour etre bien 
167               //sur.
168
169               myBuilder.Add(myShapes(iGenS,iDirS),newShape,Or);
170               myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
171               TopAbs_ShapeEnum subGenSType = myGenShapeTool.Type(subGenS);
172               if (aGenSType==TopAbs_FACE){   
173                 if(subGenSType==TopAbs_VERTEX){
174                   SetParameters(myShapes(iGenS,iDirS),
175                     newShape,aGenS,subGenS,aDirS);
176                 }
177                 else if(subGenSType==TopAbs_EDGE){
178                   SetPCurve(myShapes(iGenS,iDirS),newShape,
179                     aGenS,subGenS,aDirS,Or);
180                 }           
181                 else if(subGenSType==TopAbs_WIRE){
182                   BRepSweep_Iterator Jt;
183                   cGenS = subGenS;
184                   myGenShapeTool.SetOrientation(cGenS,TopAbs_FORWARD);
185                   for (Jt.Init(cGenS);Jt.More();Jt.Next()){
186                     subsubGenS = Jt.Value();
187                     Pr = Jt.Orientation();
188                     if(HasShape(subsubGenS,aDirS)){
189                       TopoDS_Shape newsubEdge = Shape(subsubGenS,aDirS);
190                       SetPCurve(myShapes(iGenS,iDirS),newsubEdge,
191                         aGenS,subsubGenS,aDirS,Pr);
192                     }
193                   }
194                 }
195               }
196               else if(aGenSType==TopAbs_EDGE){
197                 SetGeneratingParameter(myShapes(iGenS,iDirS),
198                   newShape,bGenS,subGenS,aDirS);
199               }
200           }
201         }
202       }
203     }
204     else if (myDirShapeTool.Type(aDirS)==TopAbs_EDGE){
205       //Ici on construit les murs du Shape.
206       TopAbs_ShapeEnum aGenSType = myGenShapeTool.Type(aGenS);
207       TopoDS_Shape newWire,newShell;
208       TopTools_SequenceOfShape WireSeq;
209       Standard_Boolean sepwires = Standard_False;
210       switch (aGenSType){
211       case TopAbs_VERTEX : 
212         myShapes(iGenS,iDirS)=MakeEmptyDirectingEdge(aGenS,aDirS);
213         break;
214       case TopAbs_EDGE :
215         //On cree un wire intermediaire qui contient tous les edges
216         //du montant (face) du Shape pour le cas standard, et une 
217         //sequence de wires pour les cas merdiques necessitant des
218         //wires independants.
219         myBuilder.MakeWire(newWire);
220         myShapes(iGenS,iDirS)=MakeEmptyFace(aGenS,aDirS);
221         break;
222       case TopAbs_WIRE :
223         myBuilder.MakeShell(myShapes(iGenS,iDirS));
224         break;
225       case TopAbs_FACE :
226         //On cree un shell intermediaire dans lequel on jette toutes 
227         //les faces en direct, pour eviter les empilages compliques 
228         //de shells et sous shells dans la structure du solide.
229         myBuilder.MakeShell(newShell);
230         myBuilder.MakeSolid(myShapes(iGenS,iDirS));
231         break;
232       case TopAbs_SHELL :
233         myBuilder.MakeCompSolid(myShapes(iGenS,iDirS));
234         break;
235       case TopAbs_SOLID :
236         throw Standard_NoSuchObject("Solids are not Processed");
237         break;
238       case TopAbs_COMPSOLID :
239         throw Standard_NoSuchObject("Solids are not Processed");
240         break;
241       case TopAbs_COMPOUND :
242         myBuilder.MakeCompound(myShapes(iGenS,iDirS));
243         break;
244       default:
245         throw Standard_NoSuchObject("Unknown Shape");
246         break;
247       }
248       bGenS = aGenS;
249       myGenShapeTool.SetOrientation(bGenS,TopAbs_FORWARD);
250       for (It.Init(bGenS);It.More();It.Next()){
251         subGenS = It.Value();
252         if(HasShape(subGenS,aDirS)){
253           newShape = Shape(subGenS,aDirS);
254           Standard_Integer iNewGenS = myGenShapeTool.Index(subGenS);
255           Standard_Integer iNewDirS = iDirS;
256           if (GGDShapeIsToAdd(myShapes(iGenS, iDirS), newShape,
257             aGenS,subGenS,aDirS)){
258               TopAbs_ShapeEnum subGenSType = myGenShapeTool.Type(subGenS);
259               if (aGenSType==TopAbs_EDGE){   
260                 Or = It.Orientation();
261                 if (SeparatedWires(myShapes(iGenS,iDirS),newShape,
262                   aGenS,subGenS,aDirS)){
263                     sepwires = Standard_True;
264                     TopoDS_Shape wi;
265                     myBuilder.MakeWire(wi);
266                     myBuilder.Add(wi,newShape,Or);
267                     myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
268                     wi.Closed(BRep_Tool::IsClosed(wi));
269                     WireSeq.Append(wi);
270                 }
271                 else{
272                   myBuilder.Add(newWire,newShape,Or);
273                   myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
274                 }
275                 SetDirectingPCurve (myShapes(iGenS,iDirS),
276                   newShape,bGenS,subGenS,aDirS,Or);
277               }
278               else if (aGenSType==TopAbs_WIRE){
279                 Or = It.Orientation();
280                 myBuilder.Add(myShapes(iGenS,iDirS),newShape,Or);
281                 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
282               }
283               else if (aGenSType==TopAbs_FACE){
284                 Or = It.Orientation();
285                 if(subGenSType == TopAbs_WIRE) {
286                   for (Lt.Init(newShape);Lt.More();Lt.Next()){
287                     myBuilder.Add(newShell,Lt.Value(),
288                       TopAbs::Compose(Lt.Orientation(),Or));
289                   }
290                 }
291                 else if(subGenSType == TopAbs_EDGE) {
292                   myBuilder.Add(newShell,newShape,Or);
293                   myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
294                 }
295               }
296               else if(aGenSType == TopAbs_SHELL){
297                 Or = TopAbs_FORWARD;
298                 myBuilder.Add(myShapes(iGenS,iDirS),newShape,Or);
299                 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
300               }
301               else if(aGenSType == TopAbs_COMPOUND){
302                 Or = TopAbs_FORWARD;
303                 myBuilder.Add(myShapes(iGenS,iDirS),newShape,Or);
304                 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
305               }
306               else{
307                 Or = It.Orientation();
308                 myBuilder.Add(myShapes(iGenS,iDirS),newShape,Or);
309                 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
310               }
311           }
312         }
313       }
314       bDirS = aDirS;
315       for (Kt.Init(bDirS);Kt.More();Kt.Next()){
316         subDirS = Kt.Value();
317         if(HasShape(aGenS,subDirS)){
318           newShape = Shape(aGenS,subDirS);
319           Standard_Integer iNewGenS = iGenS;
320           Standard_Integer iNewDirS = myDirShapeTool.Index(subDirS);
321           if (GDDShapeIsToAdd(myShapes(iGenS,iDirS),newShape,
322             aGenS,aDirS,subDirS)){
323               if (aGenSType==TopAbs_EDGE){   
324                 Or = TopAbs::Reverse(Kt.Orientation());
325                 myBuilder.Add(newWire,newShape,Or);
326                 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
327                 SetGeneratingPCurve
328                   (myShapes(iGenS,iDirS),newShape,aGenS,aDirS,subDirS,Or);
329               }
330               else if(aGenSType==TopAbs_VERTEX){
331                 Or = Kt.Orientation();
332                 myBuilder.Add(myShapes(iGenS,iDirS),newShape,Or);
333                 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
334                 SetDirectingParameter
335                   (myShapes(iGenS,iDirS),newShape,aGenS,aDirS,subDirS);
336               }
337               else if(aGenSType==TopAbs_FACE){
338                 Or = Kt.Orientation();
339                 myBuilder.Add(newShell,newShape,Or);
340                 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
341               }
342           }
343         }
344       }
345       if (aGenSType==TopAbs_EDGE){
346         if (sepwires){
347           for(Standard_Integer ij = 1;ij <= WireSeq.Length();ij++){
348             myBuilder.Add(myShapes(iGenS,iDirS),WireSeq.Value(ij));
349           }
350         }
351         else{
352           newWire.Closed(BRep_Tool::IsClosed(newWire));
353           myBuilder.Add(myShapes(iGenS,iDirS),newWire);
354         }
355         myBuiltShapes(iGenS,iDirS) = Standard_True;
356         SetContinuity(aGenS,aDirS);
357       }
358       if (aGenSType==TopAbs_WIRE){
359         SetContinuity(aGenS,aDirS);
360       } 
361       if (aGenSType==TopAbs_FACE){
362         newShell.Closed (BRep_Tool::IsClosed (newShell));
363         TopoDS_Shape temp = SplitShell(newShell);
364         TopAbs_Orientation ShellOri = DirectSolid(aGenS,aDirS);
365         Lt.Init(temp);
366         if(Lt.More()) Lt.Next();
367         if(Lt.More()){
368           for (Lt.Init(temp);Lt.More();Lt.Next()){
369             myBuilder.Add(myShapes(iGenS,iDirS),Lt.Value(), ShellOri);
370           }
371         }
372         else myBuilder.Add(myShapes(iGenS,iDirS),newShell, ShellOri);
373       }
374     }
375     else if (myDirShapeTool.Type(aDirS)==TopAbs_WIRE){
376       TopAbs_ShapeEnum aGenSType = myGenShapeTool.Type(aGenS);
377       switch (aGenSType){
378       case TopAbs_VERTEX : 
379         myBuilder.MakeWire(myShapes(iGenS,iDirS));
380         break;
381       case TopAbs_EDGE :
382         myBuilder.MakeShell(myShapes(iGenS,iDirS));
383         break;
384       case TopAbs_WIRE :
385         myBuilder.MakeShell(myShapes(iGenS,iDirS));
386         break;
387       case TopAbs_FACE :
388         myBuilder.MakeCompSolid(myShapes(iGenS,iDirS));
389         break;
390       case TopAbs_SHELL :
391         myBuilder.MakeCompSolid(myShapes(iGenS,iDirS));
392         break;
393       case TopAbs_SOLID :
394         throw Standard_NoSuchObject("Solids are not Processed");
395         break;
396       case TopAbs_COMPSOLID :
397         throw Standard_NoSuchObject("Solids are not Processed");
398         break;
399       case TopAbs_COMPOUND :
400         myBuilder.MakeCompound(myShapes(iGenS,iDirS));
401         break;
402       default:
403         throw Standard_NoSuchObject("Unknown Shape");
404         break;
405       }
406       bDirS = aDirS;
407       for (Kt.Init(aDirS);Kt.More();Kt.Next()){
408         subDirS = Kt.Value();
409         if(HasShape(aGenS,subDirS)){
410           Standard_Integer iNewGenS = iGenS;
411           Standard_Integer iNewDirS = myDirShapeTool.Index(subDirS);
412           Or = Kt.Orientation();
413           newShape = Shape(aGenS,subDirS);
414           myBuilder.Add(myShapes(iGenS,iDirS),newShape,Or);
415           myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
416         }
417       }
418     }
419     myBuiltShapes(iGenS,iDirS) = Standard_True;
420   }
421   // Change the "Closed" flag only for Wires and Shells
422   if (myShapes(iGenS, iDirS).ShapeType() == TopAbs_WIRE ||
423     myShapes(iGenS, iDirS).ShapeType() == TopAbs_SHELL)
424     myShapes(iGenS,iDirS).Closed (BRep_Tool::IsClosed (myShapes(iGenS,iDirS)));
425   return myShapes(iGenS,iDirS);
426 }
427
428
429 //=======================================================================
430 //function : FirstShape
431 //purpose  : Returns the Shape indexed by the arguments.
432 //=======================================================================
433
434 TopoDS_Shape BRepSweep_NumLinearRegularSweep::FirstShape ()
435 {
436   TopoDS_Shape result;
437   if (myDirShapeTool.HasFirstVertex()){
438     if(HasShape(myGenShape,myDirShapeTool.FirstVertex()))
439       result = Shape(myGenShape,myDirShapeTool.FirstVertex());
440   }
441   return result;
442 }
443
444
445 //=======================================================================
446 //function : LastShape
447 //purpose  : Returns the Shape indexed by the arguments.
448 //=======================================================================
449
450 TopoDS_Shape BRepSweep_NumLinearRegularSweep::LastShape ()
451 {
452   TopoDS_Shape result;
453   if (myDirShapeTool.HasLastVertex()){
454     if(HasShape(myGenShape,myDirShapeTool.LastVertex()))
455       result = Shape(myGenShape,myDirShapeTool.LastVertex());
456   }
457   return result;
458 }
459
460
461 //=======================================================================
462 //function : FirstShape
463 //purpose  : Returns the Shape indexed by the arguments.
464 //=======================================================================
465
466 TopoDS_Shape BRepSweep_NumLinearRegularSweep::FirstShape (const TopoDS_Shape& aGenS)
467 {
468   TopoDS_Shape result;
469   if (myDirShapeTool.HasFirstVertex()){
470     if(HasShape(aGenS,myDirShapeTool.FirstVertex()))
471       result = Shape(aGenS,myDirShapeTool.FirstVertex());
472   }
473   return result;
474 }
475
476
477 //=======================================================================
478 //function : LastShape
479 //purpose  : Returns the Shape indexed by the arguments.
480 //=======================================================================
481
482 TopoDS_Shape BRepSweep_NumLinearRegularSweep::LastShape (const TopoDS_Shape& aGenS)
483 {
484   TopoDS_Shape result;
485   if (myDirShapeTool.HasLastVertex()){
486     if(HasShape(aGenS,myDirShapeTool.LastVertex()))
487       result = Shape(aGenS,myDirShapeTool.LastVertex());
488   }
489   return result;
490 }
491
492 //=======================================================================
493 //function : Closed
494 //purpose  : 
495 //=======================================================================
496
497 Standard_Boolean BRepSweep_NumLinearRegularSweep::Closed()const 
498 {
499   return myDirWire.Closed();
500 }
501
502 //=======================================================================
503 //function : SplitShell
504 //purpose  : 
505 //=======================================================================
506
507 TopoDS_Shape BRepSweep_NumLinearRegularSweep::SplitShell(const TopoDS_Shape& aNewShape)const 
508 {
509   TopoDS_Shape comp;
510   myBuilder.MakeCompound(comp);
511   myBuilder.Add(comp,aNewShape);
512   return comp;
513 }
514
515 //=======================================================================
516 //function : IsUsed
517 //purpose  : 
518 //=======================================================================
519 Standard_Boolean BRepSweep_NumLinearRegularSweep::IsUsed(const TopoDS_Shape& aGenS) const
520 {
521   Standard_Integer iGenS = myGenShapeTool.Index(aGenS);
522   if (iGenS == 0)
523   {
524     return Standard_False;
525   }
526   Standard_Integer j;
527   Standard_Boolean isBuilt = Standard_False;
528   Standard_Boolean isUsed = Standard_False;
529   for (j = 2; j <= myBuiltShapes.UpperCol(); ++j)
530   {
531     isBuilt = isBuilt || myBuiltShapes(iGenS, j);
532     isUsed = isUsed || myUsedShapes(iGenS, j);
533   }
534   if (isUsed)
535   {
536     if (aGenS.ShapeType() == TopAbs_VERTEX && IsInvariant(aGenS))
537     {
538       if (myUsedShapes(iGenS, 1) || !Closed())
539       {
540         return isUsed;
541       }
542       else
543       {
544         return Standard_False;
545       }
546     }
547     else
548     {
549       return isUsed;
550     }
551   }
552   //
553   if (isBuilt) //&& !IsUsed
554   {
555     if (!HasShape(aGenS, myDirWire) && !Closed())
556     {
557       return Standard_True;
558     }
559     else if (aGenS.ShapeType() == TopAbs_VERTEX && !Closed())
560     {
561       if (!myBuiltShapes(iGenS, 1))
562       {
563         return Standard_True;
564       }
565     }
566   }
567   return isUsed;
568 }
569
570 //=======================================================================
571 //function : GenIsUsed
572 //purpose  : 
573 //=======================================================================
574 Standard_Boolean BRepSweep_NumLinearRegularSweep::GenIsUsed(const TopoDS_Shape& aGenS) const
575 {
576   Standard_Integer iGenS = myGenShapeTool.Index(aGenS);
577   if (iGenS == 0)
578   {
579     return Standard_False;
580   }
581   if (iGenS == 1)
582   {
583     return myBuiltShapes(iGenS, 1);
584   }
585   else
586   {
587     return myBuiltShapes(iGenS, 1) && myUsedShapes(iGenS, 1);
588   }
589 }