85915310 |
1 | // Created by: Peter KURNEV |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
3 | // |
4 | // This file is part of Open CASCADE Technology software library. |
5 | // |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
11 | // |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
14 | |
85915310 |
15 | |
42cf5bc1 |
16 | #include <BOPAlgo_BuilderSolid.hxx> |
17 | #include <BOPAlgo_PaveFiller.hxx> |
18 | #include <BOPAlgo_Section.hxx> |
19 | #include <BOPCol_DataMapOfShapeShape.hxx> |
20 | #include <BOPCol_IndexedDataMapOfShapeListOfShape.hxx> |
21 | #include <BOPCol_IndexedMapOfShape.hxx> |
85915310 |
22 | #include <BOPCol_ListOfShape.hxx> |
23 | #include <BOPCol_MapOfShape.hxx> |
85915310 |
24 | #include <BOPDS_CommonBlock.hxx> |
42cf5bc1 |
25 | #include <BOPDS_DS.hxx> |
85915310 |
26 | #include <BOPDS_FaceInfo.hxx> |
27 | #include <BOPDS_ListOfPaveBlock.hxx> |
28 | #include <BOPDS_MapOfPaveBlock.hxx> |
42cf5bc1 |
29 | #include <BOPDS_PaveBlock.hxx> |
85915310 |
30 | #include <BOPDS_VectorOfFaceInfo.hxx> |
42cf5bc1 |
31 | #include <BOPDS_VectorOfListOfPaveBlock.hxx> |
85915310 |
32 | #include <BOPTools.hxx> |
33 | #include <BOPTools_AlgoTools.hxx> |
34 | #include <BOPTools_AlgoTools3D.hxx> |
42cf5bc1 |
35 | #include <BRep_Builder.hxx> |
36 | #include <BRep_Tool.hxx> |
37 | #include <NCollection_IncAllocator.hxx> |
38 | #include <TopAbs_ShapeEnum.hxx> |
39 | #include <TopExp_Explorer.hxx> |
40 | #include <TopoDS_Compound.hxx> |
41 | #include <TopoDS_Edge.hxx> |
42 | #include <TopoDS_Iterator.hxx> |
43 | #include <TopoDS_Shape.hxx> |
85915310 |
44 | |
42cf5bc1 |
45 | // |
46 | // |
85915310 |
47 | //======================================================================= |
48 | //function : |
49 | //purpose : |
50 | //======================================================================= |
51 | BOPAlgo_Section::BOPAlgo_Section() |
52 | : |
53 | BOPAlgo_Builder() |
54 | { |
55 | Clear(); |
56 | } |
57 | //======================================================================= |
58 | //function : |
59 | //purpose : |
60 | //======================================================================= |
61 | BOPAlgo_Section::BOPAlgo_Section |
62 | (const Handle(NCollection_BaseAllocator)& theAllocator) |
63 | : |
64 | BOPAlgo_Builder(theAllocator) |
65 | { |
66 | Clear(); |
67 | } |
68 | //======================================================================= |
69 | //function : ~ |
70 | //purpose : |
71 | //======================================================================= |
72 | BOPAlgo_Section::~BOPAlgo_Section() |
73 | { |
74 | } |
75 | //======================================================================= |
76 | //function : CheckData |
77 | //purpose : |
78 | //======================================================================= |
79 | void BOPAlgo_Section::CheckData() |
80 | { |
81 | Standard_Integer aNbArgs; |
82 | // |
83 | myErrorStatus=0; |
84 | // |
85 | aNbArgs=myArguments.Extent(); |
86 | if (!aNbArgs) { |
87 | myErrorStatus=100; // invalid number of Arguments |
88 | return; |
89 | } |
90 | // |
91 | if (!myPaveFiller) { |
92 | myErrorStatus=101; |
93 | return; |
94 | } |
95 | // |
96 | myErrorStatus=myPaveFiller->ErrorStatus(); |
97 | if (myErrorStatus) { |
98 | return; |
99 | } |
100 | } |
101 | //======================================================================= |
102 | //function : PerformInternal1 |
103 | //purpose : |
104 | //======================================================================= |
105 | void BOPAlgo_Section::PerformInternal1 |
106 | (const BOPAlgo_PaveFiller& theFiller) |
107 | { |
108 | myErrorStatus=0; |
109 | myWarningStatus=0; |
110 | // |
111 | myPaveFiller=(BOPAlgo_PaveFiller*)&theFiller; |
112 | myDS=myPaveFiller->PDS(); |
113 | myContext=myPaveFiller->Context(); |
114 | // |
115 | // 1. CheckData |
116 | CheckData(); |
117 | if (myErrorStatus && !myWarningStatus) { |
118 | return; |
119 | } |
120 | // |
121 | // 2. Prepare |
122 | Prepare(); |
123 | if (myErrorStatus) { |
124 | return; |
125 | } |
126 | // |
127 | if(myWarningStatus == 2) { |
128 | return; |
129 | } |
130 | // 3. Fill Images |
131 | // 3.1 Vertices |
132 | FillImagesVertices(); |
133 | if (myErrorStatus) { |
134 | return; |
135 | } |
136 | // |
137 | BuildResult(TopAbs_VERTEX); |
138 | if (myErrorStatus) { |
139 | return; |
140 | } |
141 | // 3.2 Edges |
142 | FillImagesEdges(); |
143 | if (myErrorStatus) { |
144 | return; |
145 | } |
146 | // |
147 | BuildResult(TopAbs_EDGE); |
148 | if (myErrorStatus) { |
149 | return; |
150 | } |
151 | // 4. Section |
152 | BuildSection(); |
153 | // |
154 | if (myErrorStatus) { |
155 | return; |
156 | } |
157 | // 5.History |
158 | PrepareHistory(); |
159 | // |
160 | if (myErrorStatus) { |
161 | return; |
162 | } |
163 | // 6. Post-treatment |
164 | PostTreat(); |
165 | } |
166 | //======================================================================= |
167 | //function : BuildSection |
168 | //purpose : |
169 | //======================================================================= |
170 | void BOPAlgo_Section::BuildSection() |
171 | { |
172 | Standard_Integer i, aNbMS, aNbLE; |
173 | Standard_Integer j, nE, nV, aNb, aNbF, aNbPBSc; |
174 | TopoDS_Shape aRC, aRC1; |
175 | BRep_Builder aBB; |
176 | TopExp_Explorer aExp; |
177 | BOPCol_ListOfShape aLSA, aLS; |
178 | BOPCol_ListIteratorOfListOfShape aIt, aItIm, aItLS; |
179 | BOPCol_IndexedDataMapOfShapeInteger aMSI(100, myAllocator); |
180 | BOPCol_IndexedMapOfShape aMS(100, myAllocator); |
181 | BOPCol_MapOfShape aMFence(100, myAllocator); |
182 | BOPCol_MapIteratorOfMapOfInteger aItMI; |
183 | BOPDS_ListIteratorOfListOfPaveBlock aItPB; |
184 | // |
185 | myErrorStatus=0; |
186 | // |
187 | BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aRC1); |
188 | // |
189 | // 1. aRC1 |
190 | aNb=myDS->NbSourceShapes(); |
191 | for (i=0; i<aNb; ++i) { |
192 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
193 | if (aSI.ShapeType()!=TopAbs_FACE) { |
194 | continue; |
195 | } |
196 | // |
197 | const BOPDS_FaceInfo& aFI=myDS->FaceInfo(i); |
198 | // |
199 | // 1.1 Vertices that are section vertices |
200 | const BOPCol_MapOfInteger& aMVSc=aFI.VerticesSc(); |
201 | aItMI.Initialize(aMVSc); |
202 | for(; aItMI.More(); aItMI.Next()) { |
203 | nV=aItMI.Key(); |
204 | const TopoDS_Shape& aV=myDS->Shape(nV); |
205 | aBB.Add(aRC1, aV); |
206 | } |
207 | // |
208 | // 1.2 Vertices that are in a face |
209 | const BOPCol_MapOfInteger& aMI=aFI.VerticesIn(); |
210 | aItMI.Initialize(aMI); |
211 | for(; aItMI.More(); aItMI.Next()) { |
212 | nV=aItMI.Key(); |
213 | if (nV<0) { |
214 | continue; |
215 | } |
216 | if (myDS->IsNewShape(nV) || myDS->HasInterf(nV)) { |
217 | const TopoDS_Shape& aV=myDS->Shape(nV); |
218 | aBB.Add(aRC1, aV); |
219 | } |
220 | } |
221 | // |
222 | // 1.3 Section edges |
223 | const BOPDS_IndexedMapOfPaveBlock& aMPBSc=aFI.PaveBlocksSc(); |
224 | // |
225 | aNbPBSc=aMPBSc.Extent(); |
226 | for (j=1; j<=aNbPBSc; ++j) { |
227 | const Handle(BOPDS_PaveBlock)& aPB=aMPBSc(j); |
228 | nE=aPB->Edge(); |
229 | const TopoDS_Shape& aE=myDS->Shape(nE); |
230 | aBB.Add(aRC1, aE); |
231 | } |
232 | } |
233 | // |
234 | // 2. Common blocks between an edge and a face |
235 | const BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->PaveBlocksPool(); |
236 | // |
237 | aNb=aPBP.Size(); |
238 | for (i=0; i<aNb; ++i) { |
239 | const BOPDS_ListOfPaveBlock& aLPB=aPBP(i); |
240 | aItPB.Initialize(aLPB); |
241 | for (; aItPB.More(); aItPB.Next()) { |
242 | const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value(); |
243 | Handle(BOPDS_CommonBlock) aCB=myDS->CommonBlock(aPB); |
244 | if (!aCB.IsNull()) { |
245 | const BOPCol_ListOfInteger& aLF=aCB->Faces(); |
246 | aNbF=aLF.Extent(); |
247 | if (aNbF) { |
248 | const Handle(BOPDS_PaveBlock)& aPBR=aCB->PaveBlock1(); |
249 | nE=aPBR->Edge(); |
250 | const TopoDS_Shape& aE=myDS->Shape(nE); |
251 | aBB.Add(aRC1, aE); |
252 | } |
253 | } |
254 | } |
255 | } |
256 | // |
257 | aIt.Initialize(myArguments); |
258 | for (; aIt.More(); aIt.Next()) { |
259 | const TopoDS_Shape& aSA=aIt.Value(); |
260 | if (aMFence.Add(aSA)) { |
261 | aLSA.Append(aSA); |
262 | } |
263 | } |
264 | // |
265 | aMFence.Clear(); |
266 | // |
267 | // 3. Treatment boundaries of arguments |
268 | // |
269 | // 3.1 Set to treat => aLS |
270 | aIt.Initialize(aLSA); |
271 | for (; aIt.More(); aIt.Next()) { |
272 | const TopoDS_Shape& aSA=aIt.Value(); |
273 | // |
274 | aLS.Clear(); |
275 | aMS.Clear(); |
276 | aMFence.Clear(); |
277 | // |
278 | aExp.Init (aSA, TopAbs_EDGE); |
279 | for (; aExp.More(); aExp.Next()) { |
280 | const TopoDS_Shape& aE=aExp.Current(); |
281 | if (aMFence.Add(aE)) { |
282 | aLS.Append(aE); |
283 | } |
284 | } |
285 | aExp.Init (aSA, TopAbs_VERTEX); |
286 | for (; aExp.More(); aExp.Next()) { |
287 | const TopoDS_Shape& aE=aExp.Current(); |
288 | if (aMFence.Add(aE)) { |
289 | aLS.Append(aE); |
290 | } |
291 | } |
292 | // |
293 | // 3.2 aMSI |
294 | aItLS.Initialize(aLS); |
295 | for (; aItLS.More(); aItLS.Next()) { |
296 | const TopoDS_Shape& aS=aItLS.Value(); |
297 | // |
298 | if (myImages.IsBound(aS)){ |
299 | const BOPCol_ListOfShape& aLSIm=myImages.Find(aS); |
300 | aItIm.Initialize(aLSIm); |
301 | for (; aItIm.More(); aItIm.Next()) { |
302 | const TopoDS_Shape& aSIm=aItIm.Value(); |
303 | BOPTools::MapShapes(aSIm, TopAbs_VERTEX, aMS); |
304 | BOPTools::MapShapes(aSIm, TopAbs_EDGE , aMS); |
305 | } |
306 | }// if (myImages.IsBound(aF)){ |
307 | else { |
308 | BOPTools::MapShapes(aS, TopAbs_VERTEX, aMS); |
309 | BOPTools::MapShapes(aS, TopAbs_EDGE , aMS); |
310 | } |
311 | }//for (; aItLS.More(); aItLS.Next()) { |
312 | // |
313 | aNbMS=aMS.Extent(); |
314 | for (i=1; i<=aNbMS; ++i) { |
315 | const TopoDS_Shape& aS=aMS(i); |
316 | if (aMSI.Contains(aS)) { |
317 | Standard_Integer& iCnt=aMSI.ChangeFromKey(aS); |
318 | ++iCnt; |
319 | } |
320 | else { |
321 | aMSI.Add(aS, 1); |
322 | } |
323 | } |
324 | } //for (; aIt.More(); aIt.Next()) { |
325 | // |
326 | aMS.Clear(); |
327 | aMFence.Clear(); |
328 | // |
329 | // 4. Build the result |
330 | BOPCol_IndexedDataMapOfShapeListOfShape aMVE(100, myAllocator); |
331 | // |
332 | BOPTools::MapShapesAndAncestors(aRC1, |
333 | TopAbs_VERTEX, |
334 | TopAbs_EDGE, |
335 | aMVE); |
336 | // |
337 | aNbMS=aMSI.Extent(); |
338 | for (i=1; i<=aNbMS; ++i) { |
339 | const TopoDS_Shape& aV=aMSI.FindKey(i); |
340 | const Standard_Integer& iCnt=aMSI.FindFromIndex(i); |
341 | if (iCnt>1) { |
342 | BOPTools::MapShapesAndAncestors(aV, |
343 | TopAbs_VERTEX, |
344 | TopAbs_EDGE, |
345 | aMVE); |
346 | } |
347 | } |
348 | // |
349 | BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aRC); |
350 | // |
351 | aNbMS=aMVE.Extent(); |
352 | for (i=1; i<=aNbMS; ++i) { |
353 | const TopoDS_Shape& aV=aMVE.FindKey(i); |
354 | const BOPCol_ListOfShape& aLE=aMVE.FindFromIndex(i); |
355 | aNbLE=aLE.Extent(); |
356 | if (!aNbLE) { |
357 | // alone vertices |
358 | if (aMFence.Add(aV)) { |
359 | aBB.Add(aRC, aV); |
360 | } |
361 | } |
362 | else { |
363 | // edges |
364 | aIt.Initialize(aLE); |
365 | for (; aIt.More(); aIt.Next()) { |
366 | const TopoDS_Shape& aE=aIt.Value(); |
367 | if (aMFence.Add(aE)) { |
368 | aBB.Add(aRC, aE); |
369 | } |
370 | } |
371 | } |
372 | } |
373 | // |
374 | myShape=aRC; |
375 | } |
376 | //======================================================================= |
377 | //function : Generated |
378 | //purpose : |
379 | //======================================================================= |
380 | const TopTools_ListOfShape& BOPAlgo_Section::Generated |
381 | (const TopoDS_Shape& theS) |
382 | { |
383 | myHistShapes.Clear(); |
384 | if (theS.IsNull()) { |
385 | return myHistShapes; |
386 | } |
387 | // |
388 | TopAbs_ShapeEnum aType = theS.ShapeType(); |
389 | if (aType != TopAbs_FACE) { |
390 | return myHistShapes; |
391 | } |
392 | // |
393 | Standard_Integer nS = myDS->Index(theS); |
394 | if (nS < 0) { |
395 | return myHistShapes; |
396 | } |
397 | // |
398 | if (!myDS->HasFaceInfo(nS)) { |
399 | return myHistShapes; |
400 | } |
401 | // |
402 | //collect section edges of the face theS |
403 | Standard_Integer i, aNb, nSp; |
404 | // |
405 | const BOPDS_FaceInfo& aFI = myDS->FaceInfo(nS); |
406 | const BOPDS_IndexedMapOfPaveBlock& aMPBSc = aFI.PaveBlocksSc(); |
407 | aNb = aMPBSc.Extent(); |
408 | for (i = 1; i <= aNb; ++i) { |
409 | const Handle(BOPDS_PaveBlock)& aPB = aMPBSc(i); |
410 | nSp = aPB->Edge(); |
411 | const TopoDS_Shape& aSp = myDS->Shape(nSp); |
412 | myHistShapes.Append(aSp); |
413 | } |
414 | // |
415 | return myHistShapes; |
416 | } |
417 | |