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