1 // Created on: 2001-03-29
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.
22 #include <BOP_Builder.ixx>
24 #include <TopTools_ListIteratorOfListOfShape.hxx>
27 #include <BooleanOperations_ShapesDataStructure.hxx>
29 #include <BOPTools_SplitShapesPool.hxx>
30 #include <BOPTools_CommonBlockPool.hxx>
31 #include <BOPTools_ListOfPaveBlock.hxx>
32 #include <BOPTools_ListOfCommonBlock.hxx>
33 #include <TopTools_IndexedMapOfShape.hxx>
34 #include <BOPTools_ListIteratorOfListOfCommonBlock.hxx>
35 #include <BOPTools_CommonBlock.hxx>
36 #include <BOPTools_PaveBlock.hxx>
37 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
39 //=======================================================================
40 // function: BOP_Builder::BOP_Builder
42 //=======================================================================
43 BOP_Builder::BOP_Builder()
44 : myOperation(BOP_UNKNOWN),
45 myManifoldFlag(Standard_False),
46 myIsDone(Standard_False),
51 //=======================================================================
54 //=======================================================================
55 void BOP_Builder::Destroy()
59 //=======================================================================
60 // function: SetShapes
62 //=======================================================================
63 void BOP_Builder::SetShapes (const TopoDS_Shape& aS1,
64 const TopoDS_Shape& aS2)
69 //=======================================================================
70 // function: SetOperation
72 //=======================================================================
73 void BOP_Builder::SetOperation (const BOP_Operation anOp)
79 //=======================================================================
80 // function: SetManifoldFlag
82 //=======================================================================
83 void BOP_Builder::SetManifoldFlag (const Standard_Boolean aFlag)
87 //=======================================================================
90 //=======================================================================
91 const TopoDS_Shape& BOP_Builder::Shape1()const
96 //=======================================================================
99 //=======================================================================
100 const TopoDS_Shape& BOP_Builder::Shape2()const
104 //=======================================================================
105 // function: Operation
107 //=======================================================================
108 BOP_Operation BOP_Builder::Operation () const
113 //=======================================================================
114 // function: ManifoldFlag
116 //=======================================================================
117 Standard_Boolean BOP_Builder::ManifoldFlag () const
119 return myManifoldFlag;
121 //=======================================================================
124 //=======================================================================
125 Standard_Boolean BOP_Builder::IsDone() const
129 //=======================================================================
130 // function: ErrorStatus
132 //=======================================================================
133 Standard_Integer BOP_Builder::ErrorStatus() const
135 return myErrorStatus;
137 //=======================================================================
140 //=======================================================================
141 const TopoDS_Shape& BOP_Builder::Result()const
146 //=======================================================================
149 //=======================================================================
150 void BOP_Builder::Do()
153 //=======================================================================
154 // function: DoDoWithFiller
156 //=======================================================================
157 void BOP_Builder::DoWithFiller(const BOPTools_DSFiller& )
161 //=======================================================================
162 // function: BuildResult
164 //=======================================================================
165 void BOP_Builder::BuildResult()
170 //=======================================================================
171 // function: FillModified
173 //=======================================================================
174 void BOP_Builder::FillModified()
177 // Prepare myResultMap
179 TopExp::MapShapes(myResult, TopAbs_FACE, myResultMap);
180 TopExp::MapShapes(myResult, TopAbs_EDGE, myResultMap);
182 // Fill Modified for Edges
183 Standard_Integer i, aNbSources, aNbPaveBlocks, nSp, nFace;
185 const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
186 const BOPTools_SplitShapesPool& aSplitShapesPool= myDSFiller->SplitShapesPool();
187 const BOPTools_CommonBlockPool& aCommonBlockPool= myDSFiller->CommonBlockPool();
189 aNbSources=aDS.NumberOfSourceShapes();
190 for (i=1; i<=aNbSources; i++) {
192 if (aDS.GetShapeType(i) != TopAbs_EDGE){
196 const TopoDS_Shape& aE=aDS.Shape(i);
198 const BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool(aDS.RefEdge(i));
199 const BOPTools_ListOfCommonBlock& aCBlocks =aCommonBlockPool(aDS.RefEdge(i));
201 aNbPaveBlocks=aSplitEdges.Extent();
202 if (!aNbPaveBlocks) {
206 TopTools_IndexedMapOfShape aM;
208 BOPTools_ListIteratorOfListOfCommonBlock aCBIt(aCBlocks);
209 for (; aCBIt.More(); aCBIt.Next()) {
210 BOPTools_CommonBlock& aCB=aCBIt.Value();
215 BOPTools_PaveBlock& aPB=aCB.PaveBlock1(i);
217 const TopoDS_Shape& aSp=aDS.Shape(nSp);
219 if (aM.Contains(aSp)) {
224 if (myResultMap.Contains(aSp)) {
225 FillModified(aE, aSp);
230 const BOPTools_PaveBlock& aPB=aCB.PaveBlock1();
232 const TopoDS_Shape& aSp=aDS.Shape(nSp);
234 if (aM.Contains(aSp)) {
239 if (myResultMap.Contains(aSp)) {
240 FillModified(aE, aSp);
243 } // for (; aCBIt.More(); aCBIt.Next())
246 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);
247 for (; aPBIt.More(); aPBIt.Next()) {
248 const BOPTools_PaveBlock& aPB=aPBIt.Value();
250 const TopoDS_Shape& aSp=aDS.Shape(nSp);
252 if (aM.Contains(aSp)) {
257 if (myResultMap.Contains(aSp)) {
258 FillModified(aE, aSp);
260 }// for (; aPBIt.More(); aPBIt.Next())
263 //=======================================================================
264 // function: FillModified
266 //=======================================================================
267 void BOP_Builder::FillModified(const TopoDS_Shape& aE,
268 const TopoDS_Shape& aSp)
270 if (myModifiedMap.Contains(aE)) {
271 TopTools_ListOfShape& aLM=myModifiedMap.ChangeFromKey(aE);
275 TopTools_ListOfShape aLM;
277 myModifiedMap.Add(aE, aLM);
280 //=======================================================================
281 // function: FillModified
283 //=======================================================================
284 void BOP_Builder::FillModified(const TopoDS_Shape& aS,
285 const TopTools_ListOfShape& aLFx)
287 TopTools_ListIteratorOfListOfShape anIt(aLFx);
289 if (myModifiedMap.Contains(aS)) {
290 TopTools_ListOfShape& aLM=myModifiedMap.ChangeFromKey(aS);
291 anIt.Initialize(aLFx);
292 for (; anIt.More(); anIt.Next()) {
293 const TopoDS_Shape& aFx=anIt.Value();
299 TopTools_ListOfShape aLM;
300 anIt.Initialize(aLFx);
301 for (; anIt.More(); anIt.Next()) {
302 const TopoDS_Shape& aFx=anIt.Value();
305 myModifiedMap.Add(aS, aLM);
308 //=======================================================================
309 // function: Modified
311 //=======================================================================
312 const TopTools_ListOfShape& BOP_Builder::Modified(const TopoDS_Shape& aS)const
314 if (myModifiedMap.Contains(aS)) {
315 const TopTools_ListOfShape& aLM=myModifiedMap.FindFromKey(aS);
322 //=======================================================================
323 // function: IsDeleted
325 //=======================================================================
326 Standard_Boolean BOP_Builder::IsDeleted(const TopoDS_Shape& aS)const
328 Standard_Boolean bFlag=Standard_False;
330 if (myResultMap.Contains(aS)) {
334 const TopTools_ListOfShape& aLM=Modified(aS);
343 //=======================================================================
344 //function : SortTypes
346 //=======================================================================
347 void BOP_Builder::SortTypes(TopAbs_ShapeEnum& aType1,
348 TopAbs_ShapeEnum& aType2)
350 Standard_Integer iT1, iT2;
355 iT1=(Standard_Integer) aType1;
356 iT2=(Standard_Integer) aType2;
359 aType1=(TopAbs_ShapeEnum) iT2;
360 aType2=(TopAbs_ShapeEnum) iT1;
364 //=======================================================================
365 // function: SectionEdges
367 //=======================================================================
368 const TopTools_ListOfShape& BOP_Builder::SectionEdges()const
370 return mySectionEdges;
374 //=======================================================================
375 // function: SetHistoryCollector
377 //=======================================================================
378 void BOP_Builder::SetHistoryCollector(const Handle(BOP_HistoryCollector)& theHistory)
380 myHistory = theHistory;
383 //=======================================================================
384 // function: GetHistoryCollector
386 //=======================================================================
387 Handle(BOP_HistoryCollector) BOP_Builder::GetHistoryCollector() const