0025072: Environment variable MMGT_REENTRANT is still mentioned in the Overview altho...
[occt.git] / src / BOPAlgo / BOPAlgo_Builder.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
18#include <BOPAlgo_Builder.ixx>
19
36f4947b 20#include <Standard_ErrorHandler.hxx>
21#include <Standard_Failure.hxx>
22
4e57c75e 23#include <NCollection_IncAllocator.hxx>
24
25#include <TopoDS_Compound.hxx>
26#include <BRep_Builder.hxx>
27
4e57c75e 28#include <BOPTools_AlgoTools.hxx>
29
30//=======================================================================
31//function :
32//purpose :
33//=======================================================================
796a784d 34BOPAlgo_Builder::BOPAlgo_Builder()
4e57c75e 35:
36 BOPAlgo_BuilderShape(),
37 myArguments(myAllocator),
38 myMapFence(100, myAllocator),
39 myPaveFiller(NULL),
40 myDS(NULL),
4e57c75e 41 myEntryPoint(0),
42 myImages(100, myAllocator),
43 myShapesSD(100, myAllocator),
44 mySplits(100, myAllocator),
db8e4b9a 45 myOrigins(100, myAllocator)
4e57c75e 46{
47}
48//=======================================================================
49//function :
50//purpose :
51//=======================================================================
796a784d 52BOPAlgo_Builder::BOPAlgo_Builder
53 (const Handle(NCollection_BaseAllocator)& theAllocator)
4e57c75e 54:
55 BOPAlgo_BuilderShape(theAllocator),
56 myArguments(myAllocator),
57 myMapFence(100, myAllocator),
58 myPaveFiller(NULL),
59 myDS(NULL),
4e57c75e 60 myEntryPoint(0),
61 myImages(100, myAllocator),
62 myShapesSD(100, myAllocator),
63 mySplits(100, myAllocator),
db8e4b9a 64 myOrigins(100, myAllocator)
4e57c75e 65{
66}
67//=======================================================================
68//function : ~
69//purpose :
70//=======================================================================
796a784d 71BOPAlgo_Builder::~BOPAlgo_Builder()
4e57c75e 72{
73 if (myEntryPoint==1) {
74 if (myPaveFiller) {
75 delete myPaveFiller;
76 myPaveFiller=NULL;
77 }
78 }
79}
80//=======================================================================
81//function : Clear
82//purpose :
83//=======================================================================
796a784d 84void BOPAlgo_Builder::Clear()
4e57c75e 85{
86 myArguments.Clear();
87 myMapFence.Clear();
88 myImages.Clear();
89 myShapesSD.Clear();
90 mySplits.Clear();
91 myOrigins.Clear();
92}
93//=======================================================================
94//function : AddArgument
95//purpose :
96//=======================================================================
796a784d 97void BOPAlgo_Builder::AddArgument(const TopoDS_Shape& theShape)
4e57c75e 98{
99 if (myMapFence.Add(theShape)) {
100 myArguments.Append(theShape);
101 }
102}
103//=======================================================================
104//function : Arguments
105//purpose :
106//=======================================================================
796a784d 107const BOPCol_ListOfShape& BOPAlgo_Builder::Arguments()const
4e57c75e 108{
109 return myArguments;
110}
111//=======================================================================
112//function : Images
113//purpose :
114//=======================================================================
796a784d 115const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Images()const
4e57c75e 116{
117 return myImages;
118}
119//=======================================================================
120//function : Origins
121//purpose :
122//=======================================================================
796a784d 123const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::Origins()const
4e57c75e 124{
125 return myOrigins;
126}
127
128//=======================================================================
129//function : ShapesSd
130//purpose :
131//=======================================================================
796a784d 132const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::ShapesSD()const
4e57c75e 133{
134 return myShapesSD;
135}
136//=======================================================================
137//function : Splits
138//purpose :
139//=======================================================================
796a784d 140const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Splits()const
4e57c75e 141{
142 return mySplits;
143}
144//=======================================================================
145//function : PPaveFiller
146//purpose :
147//=======================================================================
796a784d 148BOPAlgo_PPaveFiller BOPAlgo_Builder::PPaveFiller()
4e57c75e 149{
150 return myPaveFiller;
151}
152//=======================================================================
153//function : PDS
154//purpose :
155//=======================================================================
796a784d 156BOPDS_PDS BOPAlgo_Builder::PDS()
4e57c75e 157{
158 return myDS;
159}
160//=======================================================================
161// function: CheckData
162// purpose:
163//=======================================================================
796a784d 164void BOPAlgo_Builder::CheckData()
4e57c75e 165{
166 Standard_Integer aNb;
167 //
168 myErrorStatus=0;
169 //
170 aNb=myArguments.Extent();
171 if (aNb<2) {
172 myErrorStatus=100; // too few arguments to process
173 return;
174 }
175 //
176 // myPaveFiller
177 if (!myPaveFiller) {
178 myErrorStatus=101;
179 return;
180 }
181 //
182 myErrorStatus=myPaveFiller->ErrorStatus();
183 if (myErrorStatus) {
184 myErrorStatus=102; // PaveFiller is failed
185 return;
186 }
187}
188//=======================================================================
189//function : Prepare
190//purpose :
191//=======================================================================
796a784d 192void BOPAlgo_Builder::Prepare()
4e57c75e 193{
194 myErrorStatus=0;
195 //
196 BRep_Builder aBB;
197 TopoDS_Compound aC;
198 //
199 // 1. myShape is empty compound
200 aBB.MakeCompound(aC);
201 myShape=aC;
202 myFlagHistory=Standard_True;
203}
204//=======================================================================
205//function : Perform
206//purpose :
207//=======================================================================
796a784d 208void BOPAlgo_Builder::Perform()
4e57c75e 209{
210 myErrorStatus=0;
211 //
212 if (myEntryPoint==1) {
213 if (myPaveFiller) {
214 delete myPaveFiller;
215 myPaveFiller=NULL;
216 }
217 }
218 //
219 Handle(NCollection_BaseAllocator) aAllocator=new NCollection_IncAllocator;
220 //
221 BOPAlgo_PaveFiller* pPF=new BOPAlgo_PaveFiller(aAllocator);
222 //
223 pPF->SetArguments(myArguments);
224 //
225 pPF->Perform();
226 //
227 myEntryPoint=1;
228 PerformInternal(*pPF);
229}
230//=======================================================================
231//function : PerformWithFiller
232//purpose :
233//=======================================================================
796a784d 234void BOPAlgo_Builder::PerformWithFiller(const BOPAlgo_PaveFiller& theFiller)
4e57c75e 235{
236 myEntryPoint=0;
237 PerformInternal(theFiller);
238}
239//=======================================================================
240//function : PerformInternal
241//purpose :
242//=======================================================================
796a784d 243void BOPAlgo_Builder::PerformInternal(const BOPAlgo_PaveFiller& theFiller)
36f4947b 244{
245 try {
246 OCC_CATCH_SIGNALS
247 PerformInternal1(theFiller);
248 }
249 //
250 catch (Standard_Failure) {
251 myErrorStatus=191;
252 }
253}
254//=======================================================================
255//function : PerformInternal1
256//purpose :
257//=======================================================================
258void BOPAlgo_Builder::PerformInternal1(const BOPAlgo_PaveFiller& theFiller)
4e57c75e 259{
260 myErrorStatus=0;
261 //
262 myPaveFiller=(BOPAlgo_PaveFiller*)&theFiller;
263 myDS=myPaveFiller->PDS();
264 myContext=myPaveFiller->Context();
265 //
266 // 1. CheckData
267 CheckData();
268 if (myErrorStatus) {
269 return;
270 }
271 //
272 // 2. Prepare
273 Prepare();
274 if (myErrorStatus) {
275 return;
276 }
277 //
278 // 3. Fill Images
279 // 3.1 Vertice
280 FillImagesVertices();
281 if (myErrorStatus) {
282 return;
283 }
284 //
285 BuildResult(TopAbs_VERTEX);
286 if (myErrorStatus) {
287 return;
288 }
289 // 3.2 Edges
290 FillImagesEdges();
291 if (myErrorStatus) {
292 return;
293 }
294 //
295 BuildResult(TopAbs_EDGE);
296 if (myErrorStatus) {
297 return;
298 }
299 //
300 // 3.3 Wires
301 FillImagesContainers(TopAbs_WIRE);
302 if (myErrorStatus) {
303 return;
304 }
305 //
306 BuildResult(TopAbs_WIRE);
307 if (myErrorStatus) {
308 return;
309 }
310
311 // 3.4 Faces
312 FillImagesFaces();
313 if (myErrorStatus) {
314 return;
315 }
316 //
317 BuildResult(TopAbs_FACE);
318 if (myErrorStatus) {
319 return;
320 }
321 // 3.5 Shells
322 FillImagesContainers(TopAbs_SHELL);
323 if (myErrorStatus) {
324 return;
325 }
326
327 BuildResult(TopAbs_SHELL);
328 if (myErrorStatus) {
329 return;
330 }
331 // 3.6 Solids
332 FillImagesSolids();
333 if (myErrorStatus) {
334 return;
335 }
336
337 BuildResult(TopAbs_SOLID);
338 if (myErrorStatus) {
339 return;
340 }
341 // 3.7 CompSolids
342 FillImagesContainers(TopAbs_COMPSOLID);
343 if (myErrorStatus) {
344 return;
345 }
346
347 BuildResult(TopAbs_COMPSOLID);
348 if (myErrorStatus) {
349 return;
350 }
351
352 // 3.8 Compounds
353 FillImagesCompounds();
354 if (myErrorStatus) {
355 return;
356 }
357
358 BuildResult(TopAbs_COMPOUND);
359 if (myErrorStatus) {
360 return;
361 }
362 //
363 // 4.History
364 PrepareHistory();
365 //
366 //
367 // 5 Post-treatment
368 PostTreat();
369
370}
371//
372// myErrorStatus
373//
374// 0 - Ok
375//
376//=======================================================================
377//function : PostTreat
378//purpose :
379//=======================================================================
796a784d 380void BOPAlgo_Builder::PostTreat()
4e57c75e 381{
c26b5a34 382 BOPTools_AlgoTools::CorrectTolerances(myShape, 0.05, myRunParallel);
383 BOPTools_AlgoTools::CorrectShapeTolerances(myShape, myRunParallel);
4e57c75e 384}