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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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>
27 #include <TopAbs_Orientation.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopTools_SequenceOfShape.hxx>
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):
41 myGenShape(aGenShape),
44 myGenShapeTool(aGenShape),
45 myDirShapeTool(aDirShape),
47 // *****************************************************************
49 // *****************************************************************
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())
58 myBuiltShapes.Init(Standard_False);
59 myUsedShapes.Init(Standard_False);
62 //=======================================================================
63 //function : ~BRepSweep_NumLinearRegularSweep
64 //purpose : Destructor
65 //=======================================================================
67 BRepSweep_NumLinearRegularSweep::~BRepSweep_NumLinearRegularSweep()
71 //=======================================================================
73 //purpose : Returns the global Shape.
74 //=======================================================================
76 TopoDS_Shape BRepSweep_NumLinearRegularSweep::Shape ()
78 if (HasShape(myGenShape,myDirWire)) return Shape(myGenShape,myDirWire);
86 //=======================================================================
88 //purpose : Returns the Shape generated with aGenS.
89 //=======================================================================
91 TopoDS_Shape BRepSweep_NumLinearRegularSweep::Shape (const TopoDS_Shape& aGenS)
93 if (myGenShapeTool.Index(aGenS) != 0 &&
94 HasShape(aGenS,myDirWire)) return Shape(aGenS,myDirWire);
102 //=======================================================================
104 //purpose : Returns the Shape indexed by the arguments.
105 //=======================================================================
107 TopoDS_Shape BRepSweep_NumLinearRegularSweep::Shape (const TopoDS_Shape& aGenS,
108 const Sweep_NumShape& aDirS)
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);
125 myShapes(iGenS,iDirS)=MakeEmptyVertex(aGenS,aDirS);
128 myShapes(iGenS,iDirS)=MakeEmptyGeneratingEdge(aGenS,aDirS);
131 myBuilder.MakeWire(myShapes(iGenS,iDirS));
134 myShapes(iGenS,iDirS)=MakeEmptyFace(aGenS,aDirS);
137 myBuilder.MakeShell(myShapes(iGenS,iDirS));
140 throw Standard_NoSuchObject("Solids are not Processed");
142 case TopAbs_COMPSOLID :
143 throw Standard_NoSuchObject("Solids are not Processed");
145 case TopAbs_COMPOUND :
146 myBuilder.MakeCompound(myShapes(iGenS,iDirS));
149 throw Standard_NoSuchObject("Unknown Shape");
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
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);
177 else if(subGenSType==TopAbs_EDGE){
178 SetPCurve(myShapes(iGenS,iDirS),newShape,
179 aGenS,subGenS,aDirS,Or);
181 else if(subGenSType==TopAbs_WIRE){
182 BRepSweep_Iterator Jt;
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);
196 else if(aGenSType==TopAbs_EDGE){
197 SetGeneratingParameter(myShapes(iGenS,iDirS),
198 newShape,bGenS,subGenS,aDirS);
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;
212 myShapes(iGenS,iDirS)=MakeEmptyDirectingEdge(aGenS,aDirS);
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);
223 myBuilder.MakeShell(myShapes(iGenS,iDirS));
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));
233 myBuilder.MakeCompSolid(myShapes(iGenS,iDirS));
236 throw Standard_NoSuchObject("Solids are not Processed");
238 case TopAbs_COMPSOLID :
239 throw Standard_NoSuchObject("Solids are not Processed");
241 case TopAbs_COMPOUND :
242 myBuilder.MakeCompound(myShapes(iGenS,iDirS));
245 throw Standard_NoSuchObject("Unknown Shape");
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;
265 myBuilder.MakeWire(wi);
266 myBuilder.Add(wi,newShape,Or);
267 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
268 wi.Closed(BRep_Tool::IsClosed(wi));
272 myBuilder.Add(newWire,newShape,Or);
273 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
275 SetDirectingPCurve (myShapes(iGenS,iDirS),
276 newShape,bGenS,subGenS,aDirS,Or);
278 else if (aGenSType==TopAbs_WIRE){
279 Or = It.Orientation();
280 myBuilder.Add(myShapes(iGenS,iDirS),newShape,Or);
281 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
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));
291 else if(subGenSType == TopAbs_EDGE) {
292 myBuilder.Add(newShell,newShape,Or);
293 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
296 else if(aGenSType == TopAbs_SHELL){
298 myBuilder.Add(myShapes(iGenS,iDirS),newShape,Or);
299 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
301 else if(aGenSType == TopAbs_COMPOUND){
303 myBuilder.Add(myShapes(iGenS,iDirS),newShape,Or);
304 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
307 Or = It.Orientation();
308 myBuilder.Add(myShapes(iGenS,iDirS),newShape,Or);
309 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
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;
328 (myShapes(iGenS,iDirS),newShape,aGenS,aDirS,subDirS,Or);
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);
337 else if(aGenSType==TopAbs_FACE){
338 Or = Kt.Orientation();
339 myBuilder.Add(newShell,newShape,Or);
340 myUsedShapes(iNewGenS, iNewDirS) = Standard_True;
345 if (aGenSType==TopAbs_EDGE){
347 for(Standard_Integer ij = 1;ij <= WireSeq.Length();ij++){
348 myBuilder.Add(myShapes(iGenS,iDirS),WireSeq.Value(ij));
352 newWire.Closed(BRep_Tool::IsClosed(newWire));
353 myBuilder.Add(myShapes(iGenS,iDirS),newWire);
355 myBuiltShapes(iGenS,iDirS) = Standard_True;
356 SetContinuity(aGenS,aDirS);
358 if (aGenSType==TopAbs_WIRE){
359 SetContinuity(aGenS,aDirS);
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);
366 if(Lt.More()) Lt.Next();
368 for (Lt.Init(temp);Lt.More();Lt.Next()){
369 myBuilder.Add(myShapes(iGenS,iDirS),Lt.Value(), ShellOri);
372 else myBuilder.Add(myShapes(iGenS,iDirS),newShell, ShellOri);
375 else if (myDirShapeTool.Type(aDirS)==TopAbs_WIRE){
376 TopAbs_ShapeEnum aGenSType = myGenShapeTool.Type(aGenS);
379 myBuilder.MakeWire(myShapes(iGenS,iDirS));
382 myBuilder.MakeShell(myShapes(iGenS,iDirS));
385 myBuilder.MakeShell(myShapes(iGenS,iDirS));
388 myBuilder.MakeCompSolid(myShapes(iGenS,iDirS));
391 myBuilder.MakeCompSolid(myShapes(iGenS,iDirS));
394 throw Standard_NoSuchObject("Solids are not Processed");
396 case TopAbs_COMPSOLID :
397 throw Standard_NoSuchObject("Solids are not Processed");
399 case TopAbs_COMPOUND :
400 myBuilder.MakeCompound(myShapes(iGenS,iDirS));
403 throw Standard_NoSuchObject("Unknown Shape");
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;
419 myBuiltShapes(iGenS,iDirS) = Standard_True;
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);
429 //=======================================================================
430 //function : FirstShape
431 //purpose : Returns the Shape indexed by the arguments.
432 //=======================================================================
434 TopoDS_Shape BRepSweep_NumLinearRegularSweep::FirstShape ()
437 if (myDirShapeTool.HasFirstVertex()){
438 if(HasShape(myGenShape,myDirShapeTool.FirstVertex()))
439 result = Shape(myGenShape,myDirShapeTool.FirstVertex());
445 //=======================================================================
446 //function : LastShape
447 //purpose : Returns the Shape indexed by the arguments.
448 //=======================================================================
450 TopoDS_Shape BRepSweep_NumLinearRegularSweep::LastShape ()
453 if (myDirShapeTool.HasLastVertex()){
454 if(HasShape(myGenShape,myDirShapeTool.LastVertex()))
455 result = Shape(myGenShape,myDirShapeTool.LastVertex());
461 //=======================================================================
462 //function : FirstShape
463 //purpose : Returns the Shape indexed by the arguments.
464 //=======================================================================
466 TopoDS_Shape BRepSweep_NumLinearRegularSweep::FirstShape (const TopoDS_Shape& aGenS)
469 if (myDirShapeTool.HasFirstVertex()){
470 if(HasShape(aGenS,myDirShapeTool.FirstVertex()))
471 result = Shape(aGenS,myDirShapeTool.FirstVertex());
477 //=======================================================================
478 //function : LastShape
479 //purpose : Returns the Shape indexed by the arguments.
480 //=======================================================================
482 TopoDS_Shape BRepSweep_NumLinearRegularSweep::LastShape (const TopoDS_Shape& aGenS)
485 if (myDirShapeTool.HasLastVertex()){
486 if(HasShape(aGenS,myDirShapeTool.LastVertex()))
487 result = Shape(aGenS,myDirShapeTool.LastVertex());
492 //=======================================================================
495 //=======================================================================
497 Standard_Boolean BRepSweep_NumLinearRegularSweep::Closed()const
499 return myDirWire.Closed();
502 //=======================================================================
503 //function : SplitShell
505 //=======================================================================
507 TopoDS_Shape BRepSweep_NumLinearRegularSweep::SplitShell(const TopoDS_Shape& aNewShape)const
510 myBuilder.MakeCompound(comp);
511 myBuilder.Add(comp,aNewShape);
515 //=======================================================================
518 //=======================================================================
519 Standard_Boolean BRepSweep_NumLinearRegularSweep::IsUsed(const TopoDS_Shape& aGenS) const
521 Standard_Integer iGenS = myGenShapeTool.Index(aGenS);
524 return Standard_False;
527 Standard_Boolean isBuilt = Standard_False;
528 Standard_Boolean isUsed = Standard_False;
529 for (j = 2; j <= myBuiltShapes.UpperCol(); ++j)
531 isBuilt = isBuilt || myBuiltShapes(iGenS, j);
532 isUsed = isUsed || myUsedShapes(iGenS, j);
536 if (aGenS.ShapeType() == TopAbs_VERTEX && IsInvariant(aGenS))
538 if (myUsedShapes(iGenS, 1) || !Closed())
544 return Standard_False;
553 if (isBuilt) //&& !IsUsed
555 if (!HasShape(aGenS, myDirWire) && !Closed())
557 return Standard_True;
559 else if (aGenS.ShapeType() == TopAbs_VERTEX && !Closed())
561 if (!myBuiltShapes(iGenS, 1))
563 return Standard_True;
570 //=======================================================================
571 //function : GenIsUsed
573 //=======================================================================
574 Standard_Boolean BRepSweep_NumLinearRegularSweep::GenIsUsed(const TopoDS_Shape& aGenS) const
576 Standard_Integer iGenS = myGenShapeTool.Index(aGenS);
579 return Standard_False;
583 return myBuiltShapes(iGenS, 1);
587 return myBuiltShapes(iGenS, 1) && myUsedShapes(iGenS, 1);