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