1 // Created on: 2001-02-20
2 // Created by: Peter KURNEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <BOPTools_DSFiller.ixx>
22 #include <BOPTools_PaveFiller.hxx>
24 #include <TopAbs_ShapeEnum.hxx>
26 #include <BRep_Builder.hxx>
28 #include <TopExp_Explorer.hxx>
31 #include <TopoDS_Iterator.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Wire.hxx>
34 #include <TopoDS_Shell.hxx>
35 #include <TopoDS_Solid.hxx>
36 #include <TopoDS_Edge.hxx>
38 #include <TopTools_ListOfShape.hxx>
39 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <BOPTools_Tools3D.hxx>
44 void FillList(const TopoDS_Shape& aS,
45 Standard_Boolean& bCompSolidFound,
46 TopTools_ListOfShape& aResultList);
48 void BuildSolid(const TopTools_ListOfShape& aRL, TopoDS_Shape& aS);
50 void BuildShell(const TopTools_ListOfShape& aRL, TopoDS_Shape& aS);
52 void BuildWire (const TopTools_ListOfShape& aRL, TopoDS_Shape& aS);
54 TopAbs_ShapeEnum GetTypeCurrent(const TopAbs_ShapeEnum aTypeX);
57 // Standard_Integer TreatCompound(const TopoDS_Shape& aS,
58 // TopoDS_Shape& aShapeResult);
61 // p-kurnev@opencascade.com
62 //=======================================================================
63 // function: BOPTools_PoolsFiller
65 //=======================================================================
66 BOPTools_DSFiller::BOPTools_DSFiller()
71 myNewFiller=Standard_True;
72 myIsDone=Standard_False;
74 //=======================================================================
77 //=======================================================================
78 void BOPTools_DSFiller::Clear()
80 if (myPaveFiller!=NULL) {
83 if (myInterfPool!=NULL) {
94 //=======================================================================
97 //=======================================================================
98 void BOPTools_DSFiller::Perform()
100 myIsDone=Standard_False;
102 if (myShape1.IsNull() || myShape2.IsNull()) {
106 // Clear contents of the DS if it was before
109 myNewFiller=Standard_True;
111 myDS = new BooleanOperations_ShapesDataStructure (myShape1, myShape2);
112 myInterfPool= new BOPTools_InterferencePool (*myDS);
114 // Build Vertices, Paves, splits,
115 myPaveFiller = new BOPTools_PaveFiller(*myInterfPool);
116 myPaveFiller->Perform();
117 myIsDone=myPaveFiller->IsDone();
120 //=======================================================================
121 // function: InitFillersAndPools
123 //=======================================================================
124 void BOPTools_DSFiller::InitFillersAndPools()
126 myIsDone=Standard_False;
128 if (myShape1.IsNull() || myShape2.IsNull()) {
132 // Clear contents of the DS if it was before
135 myNewFiller=Standard_True;
137 myDS = new BooleanOperations_ShapesDataStructure (myShape1, myShape2);
138 myInterfPool= new BOPTools_InterferencePool (*myDS);
140 myPaveFiller = new BOPTools_PaveFiller(*myInterfPool);
143 //=======================================================================
144 // function: PartialPerform
146 //=======================================================================
147 void BOPTools_DSFiller::PartialPerform(const TColStd_SetOfInteger& anObjSubSet,
148 const TColStd_SetOfInteger& aToolSubSet)
150 myIsDone=Standard_False;
153 // Build Vertices, Paves, splits,
154 myPaveFiller->PartialPerform(anObjSubSet, aToolSubSet);
155 myIsDone=myPaveFiller->IsDone();
159 //=======================================================================
160 // function: ToCompletePerform
162 //=======================================================================
163 void BOPTools_DSFiller::ToCompletePerform()
166 myIsDone=Standard_False;
168 myPaveFiller->ToCompletePerform();
169 myIsDone=myPaveFiller->IsDone();
171 // Check if any interference exists
172 myIsDone=Standard_False;
174 Standard_Integer nbs = myDS->NumberOfNewShapes();
176 myIsDone=Standard_True;
184 //=======================================================================
187 //=======================================================================
188 void BOPTools_DSFiller::Perform(const BOPTools_SSIntersectionAttribute& theSectionAttribute)
190 myIsDone=Standard_False;
192 if (myShape1.IsNull() || myShape2.IsNull()) {
196 // Clear contents of the DS if it was before
199 myNewFiller=Standard_True;
201 myDS = new BooleanOperations_ShapesDataStructure (myShape1, myShape2);
202 myInterfPool= new BOPTools_InterferencePool (*myDS);
204 // Build Vertices, Paves, splits,
205 myPaveFiller = new BOPTools_PaveFiller(*myInterfPool, theSectionAttribute);
206 myPaveFiller->Perform();
207 myIsDone=myPaveFiller->IsDone();
210 //=======================================================================
213 //=======================================================================
214 void BOPTools_DSFiller::Destroy()
219 //=======================================================================
220 // function: SetShapes
222 //=======================================================================
223 void BOPTools_DSFiller::SetShapes (const TopoDS_Shape& aS1,
224 const TopoDS_Shape& aS2)
229 Standard_Integer aNbShapes;
230 TopAbs_ShapeEnum aT1, aT2;
234 if (aT1==TopAbs_COMPOUND || aT2==TopAbs_COMPOUND) {
235 Standard_Boolean bIsEmptyShape1, bIsEmptyShape2;
237 bIsEmptyShape1=BOPTools_Tools3D::IsEmptyShape(myShape1);
238 bIsEmptyShape2=BOPTools_Tools3D::IsEmptyShape(myShape2);
239 if (bIsEmptyShape1 || bIsEmptyShape2) {
240 myIsDone=Standard_True;
246 TopoDS_Iterator anIt;
249 if (aT1==TopAbs_COMPOUND || aT1==TopAbs_COMPSOLID) {
251 anIt.Initialize(aS1);
252 for (; anIt.More(); anIt.Next()) {
262 if (aT1==TopAbs_COMPOUND) {
264 TreatCompound(aS1, aSTmp);
266 aT1=myShape1.ShapeType();
268 else if (aNbShapes>1) {
269 TreatCompound(aS1, aSTmp);
271 aT1=myShape1.ShapeType();
277 if (aT1==TopAbs_COMPOUND || aT1==TopAbs_COMPSOLID) {
278 myIsDone=Standard_False;
283 if (aT2==TopAbs_COMPOUND || aT2==TopAbs_COMPSOLID) {
285 anIt.Initialize(aS2);
286 for (; anIt.More(); anIt.Next()) {
296 if (aT2==TopAbs_COMPOUND) {
298 TreatCompound(aS2, aSTmp);
300 aT2=myShape2.ShapeType();
302 else if (aNbShapes>1) {
303 TreatCompound(aS2, aSTmp);
305 aT2=myShape2.ShapeType();
311 if (aT2==TopAbs_COMPOUND || aT2==TopAbs_COMPSOLID) {
312 myIsDone=Standard_False;
318 TopoDS_Shell aSh1, aSh2;
319 TopoDS_Wire aW1, aW2;
321 if (aT1==TopAbs_FACE) {
322 if (aT2==TopAbs_SOLID ||
328 BB.Add(aSh1, myShape1);
335 if (aT2==TopAbs_FACE) {
336 if (aT1==TopAbs_SOLID ||
341 BB.Add(aSh2, myShape2);
347 if (aT1==TopAbs_EDGE) {
348 if (aT2==TopAbs_SOLID ||
353 BB.Add(aW1, myShape1);
359 if (aT2==TopAbs_EDGE) {
360 if (aT1==TopAbs_SOLID ||
364 BB.Add(aW2, myShape2);
370 myIsDone=Standard_True;
373 //=======================================================================
376 //=======================================================================
377 const TopoDS_Shape& BOPTools_DSFiller::Shape1 () const
382 //=======================================================================
385 //=======================================================================
386 const TopoDS_Shape& BOPTools_DSFiller::Shape2 () const
390 //=======================================================================
393 //=======================================================================
394 const BooleanOperations_ShapesDataStructure& BOPTools_DSFiller::DS () const
398 //=======================================================================
399 // function: InterfPool
401 //=======================================================================
402 const BOPTools_InterferencePool& BOPTools_DSFiller::InterfPool () const
404 return *myInterfPool;
406 //=======================================================================
407 // function: PavePool
409 //=======================================================================
410 const BOPTools_PavePool& BOPTools_DSFiller::PavePool () const
412 return myPaveFiller->PavePool();
415 //=======================================================================
416 // function: CommonBlockPool
418 //=======================================================================
419 const BOPTools_CommonBlockPool& BOPTools_DSFiller::CommonBlockPool () const
421 return myPaveFiller->CommonBlockPool();
424 //=======================================================================
425 // function: SplitShapesPool
427 //=======================================================================
428 const BOPTools_SplitShapesPool& BOPTools_DSFiller::SplitShapesPool() const
430 return myPaveFiller->SplitShapesPool();
433 //=======================================================================
434 // function: PaveFiller
436 //=======================================================================
437 const BOPTools_PaveFiller& BOPTools_DSFiller::PaveFiller() const
439 return *myPaveFiller;
442 //=======================================================================
443 // function: IsNewFiller
445 //=======================================================================
446 Standard_Boolean BOPTools_DSFiller::IsNewFiller() const
452 //=======================================================================
453 // function: SetNewFiller
455 //=======================================================================
456 void BOPTools_DSFiller::SetNewFiller(const Standard_Boolean aFlag) const
458 BOPTools_DSFiller* pDSFiller=(BOPTools_DSFiller*)this;
459 pDSFiller->myNewFiller=aFlag;
461 //=======================================================================
464 //=======================================================================
465 Standard_Boolean BOPTools_DSFiller::IsDone()const
470 //=======================================================================
471 //function :TreatCompound
473 //=======================================================================
474 // Standard_Integer TreatCompound(const TopoDS_Shape& aS,
475 // TopoDS_Shape& aShapeResult)
476 Standard_Integer BOPTools_DSFiller::TreatCompound(const TopoDS_Shape& aS,
477 TopoDS_Shape& aShapeResult)
480 TopAbs_ShapeEnum aType, aTypeX;
482 aType=aS.ShapeType();
484 if (aType==TopAbs_COMPSOLID) {
489 if (aType!=TopAbs_COMPOUND) {
495 // 1 Fill the list by real shapes (solids, shells, wires, edges)
496 Standard_Boolean bCompSolidFound=Standard_False;
497 TopTools_ListOfShape aRL1, aRL;
498 FillList (aS, bCompSolidFound, aRL1);
499 if (bCompSolidFound) {
504 // Analyse the list and find the type
505 Standard_Integer i=0;
506 TopExp_Explorer anExp;
507 TopAbs_ShapeEnum aTypeCurrent=TopAbs_SHAPE,
510 //aTypeCurrent=TopAbs_SHAPE;
511 TopTools_ListIteratorOfListOfShape anItL(aRL1);
512 for (; anItL.More(); anItL.Next(), i++) {
513 const TopoDS_Shape& aSX=anItL.Value();
514 aTypeX=aSX.ShapeType();
516 aTypeCurrent=GetTypeCurrent(aTypeX);
520 if (aType0==TopAbs_SHAPE) {
521 // Unknown shape type;
528 if (aTypeCurrent!=aType0) {
529 // Heterogenous types occured;
536 if (aTypeCurrent==TopAbs_SOLID) {
537 anExp.Init(aSX, TopAbs_SHELL);
538 for (; anExp.More(); anExp.Next()) {
539 const TopoDS_Shape& aSY=anExp.Current();
544 else if (aTypeCurrent==TopAbs_SHELL) {
545 if (aTypeX==TopAbs_FACE) {
549 anExp.Init(aSX, TopAbs_FACE);
550 for (; anExp.More(); anExp.Next()) {
551 const TopoDS_Shape& aSY=anExp.Current();
557 else if (aTypeCurrent==TopAbs_WIRE) {
558 if (aTypeX==TopAbs_EDGE) {
562 anExp.Init(aSX, TopAbs_EDGE);
563 for (; anExp.More(); anExp.Next()) {
564 const TopoDS_Shape& aSY=anExp.Current();
571 // Make Composite shape
574 if (aType0==TopAbs_SOLID) {
575 BuildSolid(aRL, aShapeResult);
577 if (aType0==TopAbs_SHELL) {
578 BuildShell(aRL, aShapeResult);
580 if (aType0==TopAbs_WIRE) {
581 BuildWire(aRL, aShapeResult);
586 //=======================================================================
587 //function : BuildSolid
589 //=======================================================================
590 void BuildSolid(const TopTools_ListOfShape& aRL,
595 aBB.MakeSolid(aSolid);
596 TopTools_ListIteratorOfListOfShape anItL;
597 anItL.Initialize(aRL);
598 for (; anItL.More(); anItL.Next()) {
599 const TopoDS_Shape& aSX=anItL.Value();
600 aBB.Add(aSolid, TopoDS::Shell(aSX));
604 //=======================================================================
605 //function : BuildShell
607 //=======================================================================
608 void BuildShell(const TopTools_ListOfShape& aRL,
613 aBB.MakeShell(aShell);
614 TopTools_ListIteratorOfListOfShape anItL;
615 anItL.Initialize(aRL);
616 for (; anItL.More(); anItL.Next()) {
617 const TopoDS_Shape& aSX=anItL.Value();
618 aBB.Add(aShell, aSX);
622 //=======================================================================
623 //function : BuildWire
625 //=======================================================================
626 void BuildWire(const TopTools_ListOfShape& aRL,
632 TopTools_ListIteratorOfListOfShape anItL;
633 anItL.Initialize(aRL);
634 for (; anItL.More(); anItL.Next()) {
635 const TopoDS_Shape& aSX=anItL.Value();
640 //=======================================================================
643 //=======================================================================
644 void FillList(const TopoDS_Shape& aS,
645 Standard_Boolean& bCompSolidFound,
646 TopTools_ListOfShape& aResultList)
648 if (bCompSolidFound) {
651 TopAbs_ShapeEnum aTypeX;
652 TopoDS_Iterator anIt;
654 for (; anIt.More(); anIt.Next()) {
655 const TopoDS_Shape& aSX=anIt.Value();
656 aTypeX=aSX.ShapeType();
658 if (aTypeX==TopAbs_COMPSOLID) {
659 bCompSolidFound=Standard_True;
663 if (aTypeX==TopAbs_COMPOUND) {
664 FillList(aSX, bCompSolidFound, aResultList);
665 if (bCompSolidFound) {
669 if (aTypeX!=TopAbs_COMPOUND) {
670 aResultList.Append(aSX);
675 //=======================================================================
676 //function :GetTypeCurrent
678 //=======================================================================
679 TopAbs_ShapeEnum GetTypeCurrent(const TopAbs_ShapeEnum aTypeX)
681 TopAbs_ShapeEnum aTypeCurrent=TopAbs_SHAPE;
683 if (aTypeX==TopAbs_SOLID) {
684 aTypeCurrent=TopAbs_SOLID;
687 if (aTypeX==TopAbs_SHELL || aTypeX==TopAbs_FACE ) {
688 aTypeCurrent=TopAbs_SHELL;
691 if (aTypeX==TopAbs_WIRE || aTypeX==TopAbs_EDGE ) {
692 aTypeCurrent=TopAbs_WIRE;