0024933: Inconsistent results of self-interferences checker in SALOME and DRAW Applic...
[occt.git] / src / BOPAlgo / BOPAlgo_CheckerSI.cxx
CommitLineData
b311480e 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
b311480e 6//
973c2be1 7// This file is part of Open CASCADE Technology software library.
b311480e 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.
b311480e 14//
973c2be1 15// Alternatively, this file may be used under the terms of Open CASCADE
16// commercial license or contractual agreement.
17
4e57c75e 18//
19#include <BOPAlgo_CheckerSI.ixx>
b311480e 20
b62b3e07 21#include <Standard_ErrorHandler.hxx>
22#include <Standard_Failure.hxx>
23
6f31882a 24#include <BRepBuilderAPI_Copy.hxx>
25#include <TopTools_ListOfShape.hxx>
26
27#include <BOPCol_MapOfShape.hxx>
28
4e57c75e 29#include <BOPDS_DS.hxx>
30#include <BOPDS_IteratorSI.hxx>
c1fe53c6 31#include <BOPDS_PIteratorSI.hxx>
7ff8f019 32#include <BOPDS_Interf.hxx>
33#include <BOPDS_MapOfPassKey.hxx>
34#include <BOPDS_PassKey.hxx>
35#include <BOPDS_VectorOfInterfVV.hxx>
36#include <BOPDS_VectorOfInterfVE.hxx>
37#include <BOPDS_VectorOfInterfVE.hxx>
38#include <BOPDS_VectorOfInterfVF.hxx>
39#include <BOPDS_VectorOfInterfEF.hxx>
40#include <BOPDS_VectorOfInterfFF.hxx>
6f31882a 41
42#include <BOPInt_Context.hxx>
43
44#include <BOPTools.hxx>
7ff8f019 45#include <BOPTools_AlgoTools.hxx>
46
7fd59977 47//=======================================================================
4e57c75e 48//function :
7fd59977 49//purpose :
50//=======================================================================
7ff8f019 51BOPAlgo_CheckerSI::BOPAlgo_CheckerSI()
7fd59977 52:
ceaa5e27 53 BOPAlgo_PaveFiller()
4e57c75e 54{
ceaa5e27 55 myLevelOfCheck=BOPDS_DS::NbInterfTypes()-1;
6f31882a 56 myNonDestructive=Standard_True;
4e57c75e 57}
7fd59977 58//=======================================================================
4e57c75e 59//function : ~
7fd59977 60//purpose :
61//=======================================================================
7ff8f019 62BOPAlgo_CheckerSI::~BOPAlgo_CheckerSI()
7fd59977 63{
7fd59977 64}
65//=======================================================================
c1fe53c6 66//function : SetLevelOfCheck
67//purpose :
68//=======================================================================
7ff8f019 69void BOPAlgo_CheckerSI::SetLevelOfCheck(const Standard_Integer theLevel)
c1fe53c6 70{
ceaa5e27 71 Standard_Integer aNbLists;
72 //
73 aNbLists=BOPDS_DS::NbInterfTypes();
74 if (theLevel >= 0 && theLevel < aNbLists) {
c1fe53c6 75 myLevelOfCheck = theLevel;
76 }
77}
78//=======================================================================
6f31882a 79//function : SetNonDestructive
80//purpose :
81//=======================================================================
82void BOPAlgo_CheckerSI::SetNonDestructive(const Standard_Boolean theFlag)
83{
84 myNonDestructive=theFlag;
85}
86//=======================================================================
87//function : NonDestructive
88//purpose :
89//=======================================================================
90Standard_Boolean BOPAlgo_CheckerSI::NonDestructive() const
91{
92 return myNonDestructive;
93}
94//=======================================================================
4e57c75e 95//function : Init
7fd59977 96//purpose :
97//=======================================================================
7ff8f019 98void BOPAlgo_CheckerSI::Init()
7fd59977 99{
6f31882a 100 myErrorStatus=0;
4e57c75e 101 //
102 Clear();
103 //
104 // 1. myDS
105 myDS=new BOPDS_DS(myAllocator);
106 myDS->SetArguments(myArguments);
107 myDS->Init();
108 //
109 // 2.myIterator
c1fe53c6 110 BOPDS_PIteratorSI theIterSI=new BOPDS_IteratorSI(myAllocator);
111 theIterSI->SetDS(myDS);
112 theIterSI->Prepare();
113 theIterSI->UpdateByLevelOfCheck(myLevelOfCheck);
114 //
115 myIterator=theIterSI;
4e57c75e 116 //
117 // 3 myContext
118 myContext=new BOPInt_Context;
119 //
120 myErrorStatus=0;
7fd59977 121}
7ff8f019 122//=======================================================================
123//function : Perform
124//purpose :
125//=======================================================================
126void BOPAlgo_CheckerSI::Perform()
127{
b62b3e07 128 try {
63def8e6 129 Standard_Integer iErr;
130 //
b62b3e07 131 OCC_CATCH_SIGNALS
132 //
6f31882a 133 myErrorStatus=0;
134 if (myArguments.Extent()!=1) {
135 myErrorStatus=10;
136 return;
137 }
138 //
139 if (myNonDestructive) {
140 PrepareCopy();
141 if (myErrorStatus) {
142 return;
143 }
144 }
145 //
b62b3e07 146 BOPAlgo_PaveFiller::Perform();
63def8e6 147 iErr=myErrorStatus;
b62b3e07 148 //
63def8e6 149 PerformVZ();
150 if (myErrorStatus) {
151 iErr=myErrorStatus;
ceaa5e27 152 }
153 //
63def8e6 154 PerformEZ();
155 if (myErrorStatus) {
156 iErr=myErrorStatus;
157 }
ceaa5e27 158 //
63def8e6 159 PerformFZ();
160 if (myErrorStatus) {
161 iErr=myErrorStatus;
ceaa5e27 162 }
163 //
63def8e6 164 PerformZZ();
165 if (myErrorStatus) {
166 iErr=myErrorStatus;
ceaa5e27 167 }
80db5701 168 //
63def8e6 169 PostTreat();
170 if (myErrorStatus) {
171 iErr=myErrorStatus;
6f31882a 172 }
173 //
80db5701 174 if (myNonDestructive) {
6f31882a 175 PostTreatCopy();
63def8e6 176 if (myErrorStatus) {
177 iErr=myErrorStatus;
80db5701 178 }
6f31882a 179 }
63def8e6 180 //
181 if (iErr) {
182 myErrorStatus=iErr;
183 }
b62b3e07 184 }
80db5701 185 //
b62b3e07 186 catch (Standard_Failure) {
80db5701 187 if (myNonDestructive) {
188 PostTreatCopy();
189 }
190 //
6f31882a 191 myErrorStatus=11;
80db5701 192 }
7ff8f019 193}
194//=======================================================================
195//function : PostTreat
196//purpose :
197//=======================================================================
198void BOPAlgo_CheckerSI::PostTreat()
199{
200 Standard_Integer i, aNb, n1, n2;
201 BOPDS_PassKey aPK;
202 //
6f31882a 203 myErrorStatus=0;
204 //
205 BOPDS_MapOfPassKey& aMPK=
206 *((BOPDS_MapOfPassKey*)&myDS->Interferences());
7ff8f019 207 aMPK.Clear();
208 //
209 // 0
210 BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
211 aNb=aVVs.Extent();
212 for (i=0; i!=aNb; ++i) {
213 const BOPDS_InterfVV& aVV=aVVs(i);
214 aVV.Indices(n1, n2);
80db5701 215 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
216 continue;
217 }
7ff8f019 218 aPK.SetIds(n1, n2);
219 aMPK.Add(aPK);
220 }
221 //
222 // 1
223 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
224 aNb=aVEs.Extent();
225 for (i=0; i!=aNb; ++i) {
226 const BOPDS_InterfVE& aVE=aVEs(i);
227 aVE.Indices(n1, n2);
80db5701 228 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
229 continue;
230 }
7ff8f019 231 aPK.SetIds(n1, n2);
232 aMPK.Add(aPK);
233 }
234 //
235 // 2
236 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
237 aNb=aEEs.Extent();
238 for (i=0; i!=aNb; ++i) {
239 const BOPDS_InterfEE& aEE=aEEs(i);
240 aEE.Indices(n1, n2);
80db5701 241 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
242 continue;
243 }
7ff8f019 244 aPK.SetIds(n1, n2);
245 aMPK.Add(aPK);
246 }
247 //
248 // 3
249 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
250 aNb=aVFs.Extent();
251 for (i=0; i!=aNb; ++i) {
252 const BOPDS_InterfVF& aVF=aVFs(i);
253 aVF.Indices(n1, n2);
80db5701 254 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
255 continue;
256 }
7ff8f019 257 aPK.SetIds(n1, n2);
258 aMPK.Add(aPK);
259 }
260 //
261 // 4
262 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
263 aNb=aEFs.Extent();
264 for (i=0; i!=aNb; ++i) {
265 const BOPDS_InterfEF& aEF=aEFs(i);
266 if (aEF.CommonPart().Type()==TopAbs_SHAPE) {
267 continue;
268 }
269 aEF.Indices(n1, n2);
80db5701 270 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
271 continue;
272 }
7ff8f019 273 aPK.SetIds(n1, n2);
274 aMPK.Add(aPK);
275 }
276 //
277 // 5
278 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
279 aNb=aFFs.Extent();
280 for (i=0; i!=aNb; ++i) {
281 Standard_Boolean bTangentFaces, bFlag;
282 Standard_Integer aNbC, aNbP, j, iFound;
283 //
284 const BOPDS_InterfFF& aFF=aFFs(i);
285 aFF.Indices(n1, n2);
286 //
287 bTangentFaces=aFF.TangentFaces();
288 aNbP=aFF.Points().Extent();
289 const BOPDS_VectorOfCurve& aVC=aFF.Curves();
290 aNbC=aVC.Extent();
291 if (!aNbP && !aNbC && !bTangentFaces) {
292 continue;
293 }
294 //
295 iFound=0;
296 if (bTangentFaces) {
6f31882a 297 const TopoDS_Face& aF1=*((TopoDS_Face*)&myDS->Shape(n1));
298 const TopoDS_Face& aF2=*((TopoDS_Face*)&myDS->Shape(n2));
299 bFlag=BOPTools_AlgoTools::AreFacesSameDomain
300 (aF1, aF2, myContext);
7ff8f019 301 if (bFlag) {
6f31882a 302 ++iFound;
7ff8f019 303 }
304 }
305 else {
306 for (j=0; j!=aNbC; ++j) {
6f31882a 307 const BOPDS_Curve& aNC=aVC(j);
308 const BOPDS_ListOfPaveBlock& aLPBC=aNC.PaveBlocks();
309 if (aLPBC.Extent()) {
310 ++iFound;
311 break;
312 }
7ff8f019 313 }
314 }
315 //
316 if (!iFound) {
317 continue;
318 }
319 //
320 aPK.SetIds(n1, n2);
321 aMPK.Add(aPK);
322 }
ceaa5e27 323 //
324 //
325 // 6
326 BOPDS_VectorOfInterfVZ& aVZs=myDS->InterfVZ();
327 aNb=aVZs.Extent();
328 for (i=0; i!=aNb; ++i) {
329 //
330 const BOPDS_InterfVZ& aVZ=aVZs(i);
331 aVZ.Indices(n1, n2);
80db5701 332 if (myDS->IsNewShape(n1) || myDS->IsNewShape(n2)) {
333 continue;
334 }
ceaa5e27 335 aPK.SetIds(n1, n2);
336 aMPK.Add(aPK);
337 }
338 //
339 // 7
340 BOPDS_VectorOfInterfEZ& aEZs=myDS->InterfEZ();
341 aNb=aEZs.Extent();
342 for (i=0; i!=aNb; ++i) {
343 //
344 const BOPDS_InterfEZ& aEZ=aEZs(i);
345 aEZ.Indices(n1, n2);
346 aPK.SetIds(n1, n2);
347 aMPK.Add(aPK);
348 }
349 //
350 // 8
351 BOPDS_VectorOfInterfFZ& aFZs=myDS->InterfFZ();
352 aNb=aFZs.Extent();
353 for (i=0; i!=aNb; ++i) {
354 //
355 const BOPDS_InterfFZ& aFZ=aFZs(i);
356 aFZ.Indices(n1, n2);
357 aPK.SetIds(n1, n2);
358 aMPK.Add(aPK);
359 }
360 //
361 // 9
362 BOPDS_VectorOfInterfZZ& aZZs=myDS->InterfZZ();
363 aNb=aZZs.Extent();
364 for (i=0; i!=aNb; ++i) {
365 //
366 const BOPDS_InterfZZ& aZZ=aZZs(i);
367 aZZ.Indices(n1, n2);
368 aPK.SetIds(n1, n2);
369 aMPK.Add(aPK);
370 }
7ff8f019 371}
6f31882a 372//=======================================================================
373//function : PrepareCopy
374//purpose :
375//=======================================================================
376void BOPAlgo_CheckerSI::PrepareCopy()
377{
378 Standard_Boolean bIsDone;
379 BRepBuilderAPI_Copy aCopier;
380 BOPCol_MapOfShape aMSA;
381 BOPCol_MapIteratorOfMapOfShape aItMS;
382 //
383 myErrorStatus=0;
384 //
385 myNewOldMap.Clear();
386 //
387 const TopoDS_Shape& aSA=myArguments.First();
388 //
389 BOPTools::MapShapes(aSA, aMSA);
390 //
391 aCopier.Perform(aSA, Standard_False);
392 bIsDone=aCopier.IsDone();
393 if (!bIsDone) {
394 myErrorStatus=12;
395 return;
396 }
397 //
398 const TopoDS_Shape& aSC=aCopier.Shape();
399 //
400 aItMS.Initialize(aMSA);
401 for(; aItMS.More(); aItMS.Next()) {
402 const TopoDS_Shape& aSAx=aItMS.Value();
403 const TopoDS_Shape& aSCx=aCopier.Modified(aSAx).First();
404 myNewOldMap.Bind(aSCx, aSAx);
405 }
406 //
407 myArguments.Clear();
408 myArguments.Append(aSC);
409}
410//=======================================================================
411//function : PostTreatCopy
412//purpose :
413//=======================================================================
414void BOPAlgo_CheckerSI::PostTreatCopy()
415{
416 Standard_Integer i, aNb;
417 //
418 myErrorStatus=0;
419 //
420 aNb=myDS->NbSourceShapes();
421 for (i=0; i!=aNb; ++i) {
422 BOPDS_ShapeInfo& aSI=myDS->ChangeShapeInfo(i);
423 const TopoDS_Shape& aSCi=aSI.Shape();
424 if (!myNewOldMap.IsBound(aSCi)) {
425 myErrorStatus=13;
426 return;
427 }
428 //
429 const TopoDS_Shape& aSAi=myNewOldMap.Find(aSCi);
430 aSI.SetShape(aSAi);
431 }
432}
433//
434// myErrorStatus:
435//
436// 10 - The number of the arguments is not 1
437// 11 - Exception is caught
438// 12 - BRepBuilderAPI_Copy is not done
439// 13 - myNewOldMap doe not contain DS shape
440