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