4e57c75e |
1 | // Created by: Peter KURNEV |
2 | // Copyright (c) 2010-2012 OPEN CASCADE SAS |
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 | // |
7 | // The content of this file is subject to the Open CASCADE Technology Public |
8 | // License Version 6.5 (the "License"). You may not use the content of this file |
9 | // except in compliance with the License. Please obtain a copy of the License |
10 | // at http://www.opencascade.org and read it completely before using this file. |
11 | // |
12 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
13 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
14 | // |
15 | // The Original Code and all software distributed under the License is |
16 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
17 | // Initial Developer hereby disclaims all such warranties, including without |
18 | // limitation, any warranties of merchantability, fitness for a particular |
19 | // purpose or non-infringement. Please see the License for the specific terms |
20 | // and conditions governing the rights and limitations under the License. |
21 | |
22 | |
23 | #include <BOPAlgo_Builder.ixx> |
24 | |
25 | #include <NCollection_IncAllocator.hxx> |
26 | |
27 | #include <TopoDS_Compound.hxx> |
28 | #include <BRep_Builder.hxx> |
29 | |
30 | |
31 | #include <BOPTools_AlgoTools.hxx> |
32 | |
33 | //======================================================================= |
34 | //function : |
35 | //purpose : |
36 | //======================================================================= |
796a784d |
37 | BOPAlgo_Builder::BOPAlgo_Builder() |
4e57c75e |
38 | : |
39 | BOPAlgo_BuilderShape(), |
40 | myArguments(myAllocator), |
41 | myMapFence(100, myAllocator), |
42 | myPaveFiller(NULL), |
43 | myDS(NULL), |
44 | //myContext(NULL), |
45 | myEntryPoint(0), |
46 | myImages(100, myAllocator), |
47 | myShapesSD(100, myAllocator), |
48 | mySplits(100, myAllocator), |
796a784d |
49 | myOrigins(100, myAllocator), |
50 | myRunParallel(Standard_False) |
4e57c75e |
51 | { |
52 | } |
53 | //======================================================================= |
54 | //function : |
55 | //purpose : |
56 | //======================================================================= |
796a784d |
57 | BOPAlgo_Builder::BOPAlgo_Builder |
58 | (const Handle(NCollection_BaseAllocator)& theAllocator) |
4e57c75e |
59 | : |
60 | BOPAlgo_BuilderShape(theAllocator), |
61 | myArguments(myAllocator), |
62 | myMapFence(100, myAllocator), |
63 | myPaveFiller(NULL), |
64 | myDS(NULL), |
65 | //myContext(NULL), |
66 | myEntryPoint(0), |
67 | myImages(100, myAllocator), |
68 | myShapesSD(100, myAllocator), |
69 | mySplits(100, myAllocator), |
796a784d |
70 | myOrigins(100, myAllocator), |
71 | myRunParallel(Standard_False) |
4e57c75e |
72 | { |
73 | } |
74 | //======================================================================= |
75 | //function : ~ |
76 | //purpose : |
77 | //======================================================================= |
796a784d |
78 | BOPAlgo_Builder::~BOPAlgo_Builder() |
4e57c75e |
79 | { |
80 | if (myEntryPoint==1) { |
81 | if (myPaveFiller) { |
82 | delete myPaveFiller; |
83 | myPaveFiller=NULL; |
84 | } |
85 | } |
86 | } |
87 | //======================================================================= |
88 | //function : Clear |
89 | //purpose : |
90 | //======================================================================= |
796a784d |
91 | void BOPAlgo_Builder::Clear() |
4e57c75e |
92 | { |
93 | myArguments.Clear(); |
94 | myMapFence.Clear(); |
95 | myImages.Clear(); |
96 | myShapesSD.Clear(); |
97 | mySplits.Clear(); |
98 | myOrigins.Clear(); |
99 | } |
100 | //======================================================================= |
796a784d |
101 | //function : SetRunParallel |
102 | //purpose : |
103 | //======================================================================= |
104 | void BOPAlgo_Builder::SetRunParallel(const Standard_Boolean theFlag) |
105 | { |
106 | myRunParallel=theFlag; |
107 | } |
108 | //======================================================================= |
109 | //function : RunParallel |
110 | //purpose : |
111 | //======================================================================= |
112 | Standard_Boolean BOPAlgo_Builder::RunParallel()const |
113 | { |
114 | return myRunParallel; |
115 | } |
116 | //======================================================================= |
4e57c75e |
117 | //function : AddArgument |
118 | //purpose : |
119 | //======================================================================= |
796a784d |
120 | void BOPAlgo_Builder::AddArgument(const TopoDS_Shape& theShape) |
4e57c75e |
121 | { |
122 | if (myMapFence.Add(theShape)) { |
123 | myArguments.Append(theShape); |
124 | } |
125 | } |
126 | //======================================================================= |
127 | //function : Arguments |
128 | //purpose : |
129 | //======================================================================= |
796a784d |
130 | const BOPCol_ListOfShape& BOPAlgo_Builder::Arguments()const |
4e57c75e |
131 | { |
132 | return myArguments; |
133 | } |
134 | //======================================================================= |
135 | //function : Images |
136 | //purpose : |
137 | //======================================================================= |
796a784d |
138 | const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Images()const |
4e57c75e |
139 | { |
140 | return myImages; |
141 | } |
142 | //======================================================================= |
143 | //function : Origins |
144 | //purpose : |
145 | //======================================================================= |
796a784d |
146 | const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::Origins()const |
4e57c75e |
147 | { |
148 | return myOrigins; |
149 | } |
150 | |
151 | //======================================================================= |
152 | //function : ShapesSd |
153 | //purpose : |
154 | //======================================================================= |
796a784d |
155 | const BOPCol_DataMapOfShapeShape& BOPAlgo_Builder::ShapesSD()const |
4e57c75e |
156 | { |
157 | return myShapesSD; |
158 | } |
159 | //======================================================================= |
160 | //function : Splits |
161 | //purpose : |
162 | //======================================================================= |
796a784d |
163 | const BOPCol_DataMapOfShapeListOfShape& BOPAlgo_Builder::Splits()const |
4e57c75e |
164 | { |
165 | return mySplits; |
166 | } |
167 | //======================================================================= |
168 | //function : PPaveFiller |
169 | //purpose : |
170 | //======================================================================= |
796a784d |
171 | BOPAlgo_PPaveFiller BOPAlgo_Builder::PPaveFiller() |
4e57c75e |
172 | { |
173 | return myPaveFiller; |
174 | } |
175 | //======================================================================= |
176 | //function : PDS |
177 | //purpose : |
178 | //======================================================================= |
796a784d |
179 | BOPDS_PDS BOPAlgo_Builder::PDS() |
4e57c75e |
180 | { |
181 | return myDS; |
182 | } |
183 | //======================================================================= |
184 | // function: CheckData |
185 | // purpose: |
186 | //======================================================================= |
796a784d |
187 | void BOPAlgo_Builder::CheckData() |
4e57c75e |
188 | { |
189 | Standard_Integer aNb; |
190 | // |
191 | myErrorStatus=0; |
192 | // |
193 | aNb=myArguments.Extent(); |
194 | if (aNb<2) { |
195 | myErrorStatus=100; // too few arguments to process |
196 | return; |
197 | } |
198 | // |
199 | // myPaveFiller |
200 | if (!myPaveFiller) { |
201 | myErrorStatus=101; |
202 | return; |
203 | } |
204 | // |
205 | myErrorStatus=myPaveFiller->ErrorStatus(); |
206 | if (myErrorStatus) { |
207 | myErrorStatus=102; // PaveFiller is failed |
208 | return; |
209 | } |
210 | } |
211 | //======================================================================= |
212 | //function : Prepare |
213 | //purpose : |
214 | //======================================================================= |
796a784d |
215 | void BOPAlgo_Builder::Prepare() |
4e57c75e |
216 | { |
217 | myErrorStatus=0; |
218 | // |
219 | BRep_Builder aBB; |
220 | TopoDS_Compound aC; |
221 | // |
222 | // 1. myShape is empty compound |
223 | aBB.MakeCompound(aC); |
224 | myShape=aC; |
225 | myFlagHistory=Standard_True; |
226 | } |
227 | //======================================================================= |
228 | //function : Perform |
229 | //purpose : |
230 | //======================================================================= |
796a784d |
231 | void BOPAlgo_Builder::Perform() |
4e57c75e |
232 | { |
233 | myErrorStatus=0; |
234 | // |
235 | if (myEntryPoint==1) { |
236 | if (myPaveFiller) { |
237 | delete myPaveFiller; |
238 | myPaveFiller=NULL; |
239 | } |
240 | } |
241 | // |
242 | Handle(NCollection_BaseAllocator) aAllocator=new NCollection_IncAllocator; |
243 | // |
244 | BOPAlgo_PaveFiller* pPF=new BOPAlgo_PaveFiller(aAllocator); |
245 | // |
246 | pPF->SetArguments(myArguments); |
247 | // |
248 | pPF->Perform(); |
249 | // |
250 | myEntryPoint=1; |
251 | PerformInternal(*pPF); |
252 | } |
253 | //======================================================================= |
254 | //function : PerformWithFiller |
255 | //purpose : |
256 | //======================================================================= |
796a784d |
257 | void BOPAlgo_Builder::PerformWithFiller(const BOPAlgo_PaveFiller& theFiller) |
4e57c75e |
258 | { |
259 | myEntryPoint=0; |
260 | PerformInternal(theFiller); |
261 | } |
262 | //======================================================================= |
263 | //function : PerformInternal |
264 | //purpose : |
265 | //======================================================================= |
796a784d |
266 | void BOPAlgo_Builder::PerformInternal(const BOPAlgo_PaveFiller& theFiller) |
4e57c75e |
267 | { |
268 | myErrorStatus=0; |
269 | // |
270 | myPaveFiller=(BOPAlgo_PaveFiller*)&theFiller; |
271 | myDS=myPaveFiller->PDS(); |
272 | myContext=myPaveFiller->Context(); |
273 | // |
274 | // 1. CheckData |
275 | CheckData(); |
276 | if (myErrorStatus) { |
277 | return; |
278 | } |
279 | // |
280 | // 2. Prepare |
281 | Prepare(); |
282 | if (myErrorStatus) { |
283 | return; |
284 | } |
285 | // |
286 | // 3. Fill Images |
287 | // 3.1 Vertice |
288 | FillImagesVertices(); |
289 | if (myErrorStatus) { |
290 | return; |
291 | } |
292 | // |
293 | BuildResult(TopAbs_VERTEX); |
294 | if (myErrorStatus) { |
295 | return; |
296 | } |
297 | // 3.2 Edges |
298 | FillImagesEdges(); |
299 | if (myErrorStatus) { |
300 | return; |
301 | } |
302 | // |
303 | BuildResult(TopAbs_EDGE); |
304 | if (myErrorStatus) { |
305 | return; |
306 | } |
307 | // |
308 | // 3.3 Wires |
309 | FillImagesContainers(TopAbs_WIRE); |
310 | if (myErrorStatus) { |
311 | return; |
312 | } |
313 | // |
314 | BuildResult(TopAbs_WIRE); |
315 | if (myErrorStatus) { |
316 | return; |
317 | } |
318 | |
319 | // 3.4 Faces |
320 | FillImagesFaces(); |
321 | if (myErrorStatus) { |
322 | return; |
323 | } |
324 | // |
325 | BuildResult(TopAbs_FACE); |
326 | if (myErrorStatus) { |
327 | return; |
328 | } |
329 | // 3.5 Shells |
330 | FillImagesContainers(TopAbs_SHELL); |
331 | if (myErrorStatus) { |
332 | return; |
333 | } |
334 | |
335 | BuildResult(TopAbs_SHELL); |
336 | if (myErrorStatus) { |
337 | return; |
338 | } |
339 | // 3.6 Solids |
340 | FillImagesSolids(); |
341 | if (myErrorStatus) { |
342 | return; |
343 | } |
344 | |
345 | BuildResult(TopAbs_SOLID); |
346 | if (myErrorStatus) { |
347 | return; |
348 | } |
349 | // 3.7 CompSolids |
350 | FillImagesContainers(TopAbs_COMPSOLID); |
351 | if (myErrorStatus) { |
352 | return; |
353 | } |
354 | |
355 | BuildResult(TopAbs_COMPSOLID); |
356 | if (myErrorStatus) { |
357 | return; |
358 | } |
359 | |
360 | // 3.8 Compounds |
361 | FillImagesCompounds(); |
362 | if (myErrorStatus) { |
363 | return; |
364 | } |
365 | |
366 | BuildResult(TopAbs_COMPOUND); |
367 | if (myErrorStatus) { |
368 | return; |
369 | } |
370 | // |
371 | // 4.History |
372 | PrepareHistory(); |
373 | // |
374 | // |
375 | // 5 Post-treatment |
376 | PostTreat(); |
377 | |
378 | } |
379 | // |
380 | // myErrorStatus |
381 | // |
382 | // 0 - Ok |
383 | // |
384 | //======================================================================= |
385 | //function : PostTreat |
386 | //purpose : |
387 | //======================================================================= |
796a784d |
388 | void BOPAlgo_Builder::PostTreat() |
4e57c75e |
389 | { |
390 | //BRepLib::SameParameter(myShape, 1.e-7, Standard_True); |
5f05c0a3 |
391 | BOPTools_AlgoTools::CorrectTolerances(myShape, 0.05); |
4e57c75e |
392 | BOPTools_AlgoTools::CorrectShapeTolerances(myShape); |
393 | } |