0028786: Refactoring of the Warning/Error reporting system of Boolean Operations...
[occt.git] / src / BOPAlgo / BOPAlgo_CheckerSI_1.cxx
CommitLineData
25dfc507 1// Created by: Peter KURNEV
2// Copyright (c) 2010-2014 OPEN CASCADE SAS
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//
7// This file is part of Open CASCADE Technology software library.
8//
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
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.
14//
15// Alternatively, this file may be used under the terms of Open CASCADE
16// commercial license or contractual agreement.
17
18#include <BOPAlgo_CheckerSI.hxx>
19
20#include <BOPDS_DS.hxx>
21#include <BOPDS_Interf.hxx>
22#include <BOPDS_IteratorSI.hxx>
23
24#include <BOPCol_NCVector.hxx>
25#include <BOPCol_Parallel.hxx>
26
27#include <BRep_Tool.hxx>
28#include <BRepClass3d_SolidClassifier.hxx>
29
30#include <IntTools_Context.hxx>
31
32#include <gp_Pnt.hxx>
33#include <TopoDS_Vertex.hxx>
34#include <TopAbs_State.hxx>
35#include <TopoDS_Face.hxx>
36#include <TopoDS_Solid.hxx>
37
38/////////////////////////////////////////////////////////////////////////
39//=======================================================================
40//class : BOPAlgo_VertexSolid
41//purpose :
42//=======================================================================
43class BOPAlgo_VertexSolid {
44 public:
45 DEFINE_STANDARD_ALLOC
46
47 BOPAlgo_VertexSolid()
48 : myIV(-1), myIZ(-1), myState(TopAbs_UNKNOWN) {
49 };
50 //
51 virtual ~BOPAlgo_VertexSolid(){
52 };
53 //
54 void SetIndices(const Standard_Integer nV,
55 const Standard_Integer nZ){
56 myIV=nV;
57 myIZ=nZ;
58 }
59 //
60 void Indices(Standard_Integer& nV,
61 Standard_Integer& nZ) const {
62 nV=myIV;
63 nZ=myIZ;
64 }
65 //
66 void SetVertex(const TopoDS_Vertex& aV) {
67 myV=aV;
68 }
69 //
70 const TopoDS_Vertex& Vertex()const {
71 return myV;
72 }
73 //
74 void SetSolid(const TopoDS_Solid& aZ) {
75 myZ=aZ;
76 }
77 //
78 const TopoDS_Solid& Solid()const {
79 return myZ;
80 }
81 //
82 void SetContext(const Handle(IntTools_Context)& aContext) {
83 myContext=aContext;
84 }
85 //
86 const Handle(IntTools_Context)& Context()const {
87 return myContext;
88 }
89 //
90 TopAbs_State State() const{
91 return myState;
92 };
93 //
94 void Perform() {
95 Standard_Real aTol;
96 gp_Pnt aPV;
97 //
98 BRepClass3d_SolidClassifier& aSC=myContext->SolidClassifier(myZ);
99 //
100 aPV=BRep_Tool::Pnt(myV);
101 aTol=BRep_Tool::Tolerance(myV);
102 //
103 aSC.Perform(aPV, aTol);
104 //
105 myState=aSC.State();
106 };
107 //
108 protected:
109 Standard_Integer myIV;
110 Standard_Integer myIZ;
111 TopAbs_State myState;
112 TopoDS_Vertex myV;
113 TopoDS_Solid myZ;
114 Handle(IntTools_Context) myContext;
115};
116//=======================================================================
117typedef BOPCol_NCVector
118 <BOPAlgo_VertexSolid> BOPAlgo_VectorOfVertexSolid;
119//
120typedef BOPCol_ContextFunctor
121 <BOPAlgo_VertexSolid,
122 BOPAlgo_VectorOfVertexSolid,
123 Handle(IntTools_Context),
124 IntTools_Context> BOPAlgo_VertexSolidFunctor;
125//
126typedef BOPCol_ContextCnt
127 <BOPAlgo_VertexSolidFunctor,
128 BOPAlgo_VectorOfVertexSolid,
129 Handle(IntTools_Context)> BOPAlgo_VertexSolidCnt;
130/////////////////////////////////////////////////////////////////////////
131//=======================================================================
132//class : BOPAlgo_ShapeSolid
133//purpose :
134//=======================================================================
135class BOPAlgo_ShapeSolid {
136 public:
137 DEFINE_STANDARD_ALLOC
138
139 BOPAlgo_ShapeSolid() :
140 myIE(-1),
141 myIZ(-1),
142 myHasInterf(Standard_False),
143 myDS(NULL) {
144 };
145 //
146 virtual ~BOPAlgo_ShapeSolid(){
147 };
148 //
149 void SetIndices(const Standard_Integer nE,
150 const Standard_Integer nZ){
151 myIE=nE;
152 myIZ=nZ;
153 }
154 //
155 void Indices(Standard_Integer& nE,
156 Standard_Integer& nZ) const {
157 nE=myIE;
158 nZ=myIZ;
159 }
160 //
161 void SetDS(BOPDS_DS* pDS) {
162 myDS=pDS;
163 }
164 //
165 Standard_Boolean HasInterf() const{
166 return myHasInterf;
167 };
168 //
169 virtual void Perform() {
170 Standard_Boolean bHasInterf;
171 //
172 myHasInterf=Standard_False;
173 //
174 bHasInterf=myDS->HasInterfShapeSubShapes(myIE, myIZ);
175 if (!bHasInterf) {
176 myHasInterf=myDS->HasInterfShapeSubShapes(myIZ, myIE);
177 }
178 };
179 //
180 protected:
181 Standard_Integer myIE;
182 Standard_Integer myIZ;
183 Standard_Boolean myHasInterf;
184 BOPDS_DS* myDS;
185};
186//=======================================================================
187typedef BOPCol_NCVector
188 <BOPAlgo_ShapeSolid> BOPAlgo_VectorOfShapeSolid;
189//
190typedef BOPCol_Functor
191 <BOPAlgo_ShapeSolid,
192 BOPAlgo_VectorOfShapeSolid> BOPAlgo_ShapeSolidFunctor;
193//
194typedef BOPCol_Cnt
195 <BOPAlgo_ShapeSolidFunctor,
196 BOPAlgo_VectorOfShapeSolid> BOPAlgo_ShapeSolidCnt;
197//
198/////////////////////////////////////////////////////////////////////////
199//=======================================================================
200//class : BOPAlgo_SolidSolid
201//purpose :
202//=======================================================================
203class BOPAlgo_SolidSolid : public BOPAlgo_ShapeSolid {
204 public:
205 DEFINE_STANDARD_ALLOC
206
207 BOPAlgo_SolidSolid() :
208 BOPAlgo_ShapeSolid() {
209 };
210 //
211 virtual ~BOPAlgo_SolidSolid(){
212 };
213 //
214 virtual void Perform() {
215 Standard_Boolean bFlag;
216 //
217 bFlag=Standard_False;
218 myHasInterf=Standard_False;
219 //
220 myHasInterf=myDS->HasInterfShapeSubShapes(myIZ, myIE, bFlag);
221 if (!myHasInterf) {
222 myHasInterf=myDS->HasInterfShapeSubShapes(myIE, myIZ, bFlag);
223 }
224 };
225};
226//=======================================================================
227typedef BOPCol_NCVector
228 <BOPAlgo_SolidSolid> BOPAlgo_VectorOfSolidSolid;
229//
230typedef BOPCol_Functor
231 <BOPAlgo_SolidSolid,
232 BOPAlgo_VectorOfSolidSolid> BOPAlgo_SolidSolidFunctor;
233//
234typedef BOPCol_Cnt
235 <BOPAlgo_SolidSolidFunctor,
236 BOPAlgo_VectorOfSolidSolid> BOPAlgo_SolidSolidCnt;
237//
238/////////////////////////////////////////////////////////////////////////
239
240//=======================================================================
241//function : PerformVZ
242//purpose :
243//=======================================================================
244void BOPAlgo_CheckerSI::PerformVZ()
245{
246 Standard_Integer iSize, nV, nZ, k, aNbVVS;
247 TopAbs_State aState;
248 BOPDS_MapOfPair aMPK;
249 //
25dfc507 250 myIterator->Initialize(TopAbs_VERTEX, TopAbs_SOLID);
251 iSize=myIterator->ExpectedLength();
252 if (!iSize) {
253 return;
254 }
255 //
256 BOPDS_VectorOfInterfVZ& aVZs=myDS->InterfVZ();
257 aVZs.SetIncrement(iSize);
258 //
259 BOPAlgo_VectorOfVertexSolid aVVS;
260 //
261 for (; myIterator->More(); myIterator->Next()) {
262 myIterator->Value(nV, nZ);
263 //
264 if (myDS->HasInterfShapeSubShapes(nV, nZ)) {
265 continue;
266 }
267 //
268 Standard_Integer nVSD = nV;
269 myDS->HasShapeSD(nV, nVSD);
270 //
271 BOPDS_Pair aPK;
272 aPK.SetIndices(nVSD, nZ);
273 if (!aMPK.Add(aPK)) {
274 continue;
275 }
276 //
277 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nVSD));
278 const TopoDS_Solid& aZ=*((TopoDS_Solid*)&myDS->Shape(nZ));
279 //
280 BOPAlgo_VertexSolid& aVertexSolid=aVVS.Append1();
281 aVertexSolid.SetIndices(nV, nZ);
282 aVertexSolid.SetVertex(aV);
283 aVertexSolid.SetSolid(aZ);
284 }
285 //
286 aNbVVS=aVVS.Extent();
287 //=============================================================
288 BOPAlgo_VertexSolidCnt::Perform(myRunParallel, aVVS, myContext);
289 //=============================================================
290 for (k=0; k < aNbVVS; ++k) {
291 const BOPAlgo_VertexSolid& aVertexSolid=aVVS(k);
292 aState=aVertexSolid.State();
293 if (aState==TopAbs_IN) {
294 aVertexSolid.Indices(nV, nZ);
295 //
296 BOPDS_InterfVZ& aVZ=aVZs.Append1();
297 aVZ.SetIndices(nV, nZ);
298 //
299 myDS->AddInterf(nV, nZ);
300 }
301 }
302}
303//=======================================================================
304//function : PerformEZ
305//purpose :
306//=======================================================================
307void BOPAlgo_CheckerSI::PerformEZ()
308{
309 PerformSZ(TopAbs_EDGE);
310}
311//=======================================================================
312//function : PerformFZ
313//purpose :
314//=======================================================================
315void BOPAlgo_CheckerSI::PerformFZ()
316{
317 PerformSZ(TopAbs_FACE);
318}
319//=======================================================================
320//function : PerformZZ
321//purpose :
322//=======================================================================
323void BOPAlgo_CheckerSI::PerformZZ()
324{
325 Standard_Boolean bHasInterf;
326 Standard_Integer iSize, nZ1, nZ, k, aNbSolidSolid;
327 //
25dfc507 328 myIterator->Initialize(TopAbs_SOLID, TopAbs_SOLID);
329 iSize=myIterator->ExpectedLength();
330 if (!iSize) {
331 return;
332 }
333 //
334 BOPAlgo_VectorOfSolidSolid aVSolidSolid;
335 //
336 for (; myIterator->More(); myIterator->Next()) {
337 myIterator->Value(nZ1, nZ);
338 //
339 BOPAlgo_SolidSolid& aSolidSolid=aVSolidSolid.Append1();
340 aSolidSolid.SetIndices(nZ1, nZ);
341 aSolidSolid.SetDS(myDS);
342 }
343 //
344 aNbSolidSolid=aVSolidSolid.Extent();
345 //======================================================
346 BOPAlgo_SolidSolidCnt::Perform(myRunParallel, aVSolidSolid);
347 //======================================================
348 //
349 BOPDS_VectorOfInterfZZ& aZZs=myDS->InterfZZ();
350 //
351 aZZs.SetIncrement(iSize);
352 //
353 for (k=0; k < aNbSolidSolid; ++k) {
354 const BOPAlgo_SolidSolid& aSolidSolid=aVSolidSolid(k);
355 bHasInterf=aSolidSolid.HasInterf();
356 if (bHasInterf) {
357 aSolidSolid.Indices(nZ1, nZ);
358 //
359 BOPDS_InterfZZ& aZZ=aZZs.Append1();
360 aZZ.SetIndices(nZ1, nZ);
361 //
362 myDS->AddInterf(nZ1, nZ);
363 }
364 }
365}
366//=======================================================================
367//function : PerformSZ
368//purpose :
369//=======================================================================
370void BOPAlgo_CheckerSI::PerformSZ(const TopAbs_ShapeEnum aTS)
371{
372 Standard_Boolean bHasInterf;
373 Standard_Integer iSize, nS, nZ, k, aNbShapeSolid;
374 //
25dfc507 375 myIterator->Initialize(aTS, TopAbs_SOLID);
376 iSize=myIterator->ExpectedLength();
377 if (!iSize) {
378 return;
379 }
380 //
381 BOPAlgo_VectorOfShapeSolid aVShapeSolid;
382 //
383 for (; myIterator->More(); myIterator->Next()) {
384 myIterator->Value(nS, nZ);
385 //
386 BOPAlgo_ShapeSolid& aShapeSolid=aVShapeSolid.Append1();
387 aShapeSolid.SetIndices(nS, nZ);
388 aShapeSolid.SetDS(myDS);
389 }
390 //
391 aNbShapeSolid=aVShapeSolid.Extent();
392 //======================================================
393 BOPAlgo_ShapeSolidCnt::Perform(myRunParallel, aVShapeSolid);
394 //======================================================
395 //
396 BOPDS_VectorOfInterfEZ& aEZs=myDS->InterfEZ();
397 BOPDS_VectorOfInterfFZ& aFZs=myDS->InterfFZ();
398 //
399 if (aTS==TopAbs_EDGE) {
400 aEZs.SetIncrement(iSize);
401 }
402 else {//if (aTS==TopAbs_FACE)
403 aFZs.SetIncrement(iSize);
404 }
405 //
406 for (k=0; k < aNbShapeSolid; ++k) {
407 const BOPAlgo_ShapeSolid& aShapeSolid=aVShapeSolid(k);
408 bHasInterf=aShapeSolid.HasInterf();
409 if (bHasInterf) {
410 aShapeSolid.Indices(nS, nZ);
411 //
412 if (aTS==TopAbs_EDGE) {
413 BOPDS_InterfEZ& aEZ=aEZs.Append1();
414 aEZ.SetIndices(nS, nZ);
415 }
416 else {//if (aTS==TopAbs_FACE)
417 BOPDS_InterfFZ& aFZ=aFZs.Append1();
418 aFZ.SetIndices(nS, nZ);
419 }
420 //
421 myDS->AddInterf(nS, nZ);
422 }
423 }
424}