0028786: Refactoring of the Warning/Error reporting system of Boolean Operations...
[occt.git] / src / BOPAlgo / BOPAlgo_Builder_1.cxx
CommitLineData
4e57c75e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 2010-2014 OPEN CASCADE SAS
4e57c75e 3// Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4// Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5// EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6//
973c2be1 7// This file is part of Open CASCADE Technology software library.
4e57c75e 8//
d5f74e42 9// This library is free software; you can redistribute it and/or modify it under
10// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 11// by the Free Software Foundation, with special exception defined in the file
12// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13// distribution for complete text of the license and disclaimer of any warranty.
4e57c75e 14//
973c2be1 15// Alternatively, this file may be used under the terms of Open CASCADE
16// commercial license or contractual agreement.
4e57c75e 17
4e57c75e 18
42cf5bc1 19#include <BOPAlgo_Builder.hxx>
20#include <BOPAlgo_PaveFiller.hxx>
4e57c75e 21#include <BOPCol_DataMapOfIntegerInteger.hxx>
22#include <BOPCol_ListOfShape.hxx>
23#include <BOPCol_MapOfShape.hxx>
4e57c75e 24#include <BOPDS_DS.hxx>
4e57c75e 25#include <BOPDS_ListOfPaveBlock.hxx>
42cf5bc1 26#include <BOPDS_PaveBlock.hxx>
4e57c75e 27#include <BOPDS_ShapeInfo.hxx>
42cf5bc1 28#include <BOPDS_VectorOfListOfPaveBlock.hxx>
4e57c75e 29#include <BOPTools_AlgoTools.hxx>
42cf5bc1 30#include <BRep_Builder.hxx>
c5d8782c 31#include <BRep_Tool.hxx>
42cf5bc1 32#include <IntTools_Context.hxx>
33#include <TopAbs_ShapeEnum.hxx>
34#include <TopoDS_Iterator.hxx>
35#include <TopoDS_Shape.hxx>
4e57c75e 36
37//=======================================================================
38//function : FillImagesVertices
39//purpose :
40//=======================================================================
b18a83d4 41void BOPAlgo_Builder::FillImagesVertices()
4e57c75e 42{
4e57c75e 43 Standard_Integer nV, nVSD;
44 BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aIt;
45 //
46 const BOPCol_DataMapOfIntegerInteger& aMSDV=myDS->ShapesSD();
47 aIt.Initialize(aMSDV);
48 for (; aIt.More(); aIt.Next()) {
49 nV=aIt.Key();
50 nVSD=aIt.Value();
51 const TopoDS_Shape& aV=myDS->Shape(nV);
52 const TopoDS_Shape& aVSD=myDS->Shape(nVSD);
53 //
54 BOPCol_ListOfShape aLVSD(myAllocator);
55 //
56 aLVSD.Append(aVSD);
57 myImages.Bind(aV, aLVSD);
58 //
59 myShapesSD.Bind(aV, aVSD);
b18a83d4 60 //
61 BOPCol_ListOfShape* pLOr = myOrigins.ChangeSeek(aVSD);
62 if (!pLOr) {
63 pLOr = myOrigins.Bound(aVSD, BOPCol_ListOfShape());
64 }
65 pLOr->Append(aV);
4e57c75e 66 }
67}
68//=======================================================================
69//function : FillImagesEdges
70//purpose :
71//=======================================================================
72 void BOPAlgo_Builder::FillImagesEdges()
73{
752f9d72 74 Standard_Integer i, aNbS = myDS->NbSourceShapes();
75 for (i = 0; i < aNbS; ++i) {
76 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(i);
77 if (aSI.ShapeType() != TopAbs_EDGE) {
78 continue;
79 }
80 //
81 // Check if the pave blocks for the edge have been initialized
82 if (!aSI.HasReference()) {
83 continue;
84 }
85 //
86 const TopoDS_Shape& aE = aSI.Shape();
87 const BOPDS_ListOfPaveBlock& aLPB = myDS->PaveBlocks(i);
88 //
89 // Fill the images of the edge from the list of its pave blocks.
90 // The small edges, having no pave blocks, will have the empty list
91 // of images and, thus, will be avoided in the result.
92 BOPCol_ListOfShape *pLS = myImages.Bound(aE, BOPCol_ListOfShape());
93 //
94 BOPDS_ListIteratorOfListOfPaveBlock aItPB(aLPB);
95 for (; aItPB.More(); aItPB.Next()) {
96 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
97 Handle(BOPDS_PaveBlock) aPBR = myDS->RealPaveBlock(aPB);
4e57c75e 98 //
752f9d72 99 Standard_Integer nSpR = aPBR->Edge();
100 const TopoDS_Shape& aSpR = myDS->Shape(nSpR);
101 pLS->Append(aSpR);
b18a83d4 102 //
103 BOPCol_ListOfShape* pLOr = myOrigins.ChangeSeek(aSpR);
104 if (!pLOr) {
105 pLOr = myOrigins.Bound(aSpR, BOPCol_ListOfShape());
106 }
107 pLOr->Append(aE);
4e57c75e 108 //
752f9d72 109 if (myDS->IsCommonBlockOnEdge(aPB)) {
110 Standard_Integer nSp = aPB->Edge();
111 const TopoDS_Shape& aSp = myDS->Shape(nSp);
112 myShapesSD.Bind(aSp, aSpR);
4e57c75e 113 }
4e57c75e 114 }
115 }
116}
117//=======================================================================
118// function: IsInterferred
119// purpose:
120//=======================================================================
121 Standard_Boolean BOPAlgo_Builder::IsInterferred(const TopoDS_Shape& theS)const
122{
123 Standard_Boolean bInterferred;
124 TopoDS_Iterator aIt;
125 //
126 bInterferred=Standard_False;
127 aIt.Initialize(theS);
128 for (; aIt.More(); aIt.Next()) {
129 const TopoDS_Shape& aSx=aIt.Value();
130 if (myImages.IsBound(aSx)) {
131 bInterferred=!bInterferred;
132 break;
133 }
134 }
135 return bInterferred;
136}
137//=======================================================================
138//function : BuildResult
139//purpose :
140//=======================================================================
141 void BOPAlgo_Builder::BuildResult(const TopAbs_ShapeEnum theType)
142{
4e57c75e 143 TopAbs_ShapeEnum aType;
144 BRep_Builder aBB;
145 BOPCol_MapOfShape aM;
146 BOPCol_ListIteratorOfListOfShape aIt, aItIm;
147 //
148 aIt.Initialize(myArguments);
149 for (; aIt.More(); aIt.Next()) {
150 const TopoDS_Shape& aS=aIt.Value();
151 aType=aS.ShapeType();
152 if (aType==theType) {
153 if (myImages.IsBound(aS)){
319da2e4 154 const BOPCol_ListOfShape& aLSIm=myImages.Find(aS);
155 aItIm.Initialize(aLSIm);
156 for (; aItIm.More(); aItIm.Next()) {
157 const TopoDS_Shape& aSIm=aItIm.Value();
158 if (aM.Add(aSIm)) {
159 aBB.Add(myShape, aSIm);
160 }
161 }
4e57c75e 162 }
163 else {
319da2e4 164 if (aM.Add(aS)) {
165 aBB.Add(myShape, aS);
166 }
4e57c75e 167 }
168 }
169 }
170}
171//=======================================================================
172// function: FillImagesContainers
173// purpose:
174//=======================================================================
175 void BOPAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType)
176{
4e57c75e 177 Standard_Integer i, aNbS;
178 BOPCol_MapOfShape aMFP(100, myAllocator);
179 //
180 aNbS=myDS->NbSourceShapes();
181 for (i=0; i<aNbS; ++i) {
182 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
183 if (aSI.ShapeType()==theType) {
184 const TopoDS_Shape& aC=aSI.Shape();
185 FillImagesContainer(aC, theType);
186 }
187 }// for (; aItS.More(); aItS.Next()) {
188}
189//=======================================================================
190// function: FillImagesCompounds
191// purpose:
192//=======================================================================
193 void BOPAlgo_Builder::FillImagesCompounds()
194{
4e57c75e 195 Standard_Integer i, aNbS;
196 BOPCol_MapOfShape aMFP(100, myAllocator);
197 //
198 aNbS=myDS->NbSourceShapes();
199 for (i=0; i<aNbS; ++i) {
200 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
201 if (aSI.ShapeType()==TopAbs_COMPOUND) {
202 const TopoDS_Shape& aC=aSI.Shape();
203 FillImagesCompound(aC, aMFP);
204 }
205 }// for (; aItS.More(); aItS.Next()) {
206}
207//=======================================================================
208//function : FillImagesContainer
209//purpose :
210//=======================================================================
211 void BOPAlgo_Builder::FillImagesContainer(const TopoDS_Shape& theS,
212 const TopAbs_ShapeEnum theType)
213{
214 Standard_Boolean bInterferred, bToReverse;
215 TopoDS_Iterator aIt;
216 BRep_Builder aBB;
217 BOPCol_ListIteratorOfListOfShape aItIm;
218 //
219 bInterferred=IsInterferred(theS);
220 if (!bInterferred){
221 return;
222 }
223 //
224 TopoDS_Shape aCIm;
225 BOPTools_AlgoTools::MakeContainer(theType, aCIm);
226 //
227 aIt.Initialize(theS);
228 for (; aIt.More(); aIt.Next()) {
229 const TopoDS_Shape& aSx=aIt.Value();
230 if (myImages.IsBound(aSx)) {
231 const BOPCol_ListOfShape& aLFIm=myImages.Find(aSx);
232 aItIm.Initialize(aLFIm);
233 for (; aItIm.More(); aItIm.Next()) {
234 TopoDS_Shape aSxIm=aItIm.Value();
235 //
236 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSxIm, aSx, myContext);
237 if (bToReverse) {
238 aSxIm.Reverse();
239 }
240 aBB.Add(aCIm, aSxIm);
241 }
242 }
243 else {
244 aBB.Add(aCIm, aSx);
245 }
246 }
247 //
c5d8782c 248 aCIm.Closed(BRep_Tool::IsClosed(aCIm));
249 //
4e57c75e 250 BOPCol_ListOfShape aLSIm(myAllocator);
251 aLSIm.Append(aCIm);
252 myImages.Bind(theS, aLSIm);
253}
254//=======================================================================
255//function : FillImagesCompound
256//purpose :
257//=======================================================================
258 void BOPAlgo_Builder::FillImagesCompound(const TopoDS_Shape& theS,
259 BOPCol_MapOfShape& theMFP)
260{
261 Standard_Boolean bInterferred;
262 TopAbs_Orientation aOrX;
263 TopoDS_Iterator aIt;
264 BRep_Builder aBB;
265 BOPCol_ListIteratorOfListOfShape aItIm;
266 //
267 if (!theMFP.Add(theS)) {
268 return;
269 }
270 //
271 bInterferred=Standard_False;
272 aIt.Initialize(theS);
273 for (; aIt.More(); aIt.Next()) {
274 const TopoDS_Shape& aSx=aIt.Value();
275 if (aSx.ShapeType()==TopAbs_COMPOUND) {
276 FillImagesCompound(aSx, theMFP);
277 }
278 if (myImages.IsBound(aSx)) {
279 bInterferred=Standard_True;
280 }
281 }
282 if (!bInterferred){
283 return;
284 }
285 //
286 TopoDS_Shape aCIm;
287 BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCIm);
288 //
289 aIt.Initialize(theS);
290 for (; aIt.More(); aIt.Next()) {
291 const TopoDS_Shape& aSX=aIt.Value();
292 aOrX=aSX.Orientation();
293 if (myImages.IsBound(aSX)) {
294 const BOPCol_ListOfShape& aLFIm=myImages.Find(aSX);
295 aItIm.Initialize(aLFIm);
296 for (; aItIm.More(); aItIm.Next()) {
319da2e4 297 TopoDS_Shape aSXIm=aItIm.Value();
298 aSXIm.Orientation(aOrX);
299 aBB.Add(aCIm, aSXIm);
4e57c75e 300 }
301 }
302 else {
303 aBB.Add(aCIm, aSX);
304 }
305 }
306 //
307 BOPCol_ListOfShape aLSIm(myAllocator);
308 aLSIm.Append(aCIm);
309 myImages.Bind(theS, aLSIm);
310}