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