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 | |
4e57c75e |
18 | |
42cf5bc1 |
19 | #include <BOPAlgo_Builder.hxx> |
20 | #include <BOPAlgo_PaveFiller.hxx> |
4e57c75e |
21 | #include <BOPCol_DataMapOfIntegerInteger.hxx> |
22 | #include <BOPCol_ListOfShape.hxx> |
23 | #include <BOPCol_MapOfShape.hxx> |
4e57c75e |
24 | #include <BOPDS_DS.hxx> |
4e57c75e |
25 | #include <BOPDS_ListOfPaveBlock.hxx> |
42cf5bc1 |
26 | #include <BOPDS_PaveBlock.hxx> |
4e57c75e |
27 | #include <BOPDS_ShapeInfo.hxx> |
42cf5bc1 |
28 | #include <BOPDS_VectorOfListOfPaveBlock.hxx> |
4e57c75e |
29 | #include <BOPTools_AlgoTools.hxx> |
42cf5bc1 |
30 | #include <BRep_Builder.hxx> |
c5d8782c |
31 | #include <BRep_Tool.hxx> |
42cf5bc1 |
32 | #include <IntTools_Context.hxx> |
33 | #include <TopAbs_ShapeEnum.hxx> |
34 | #include <TopoDS_Iterator.hxx> |
35 | #include <TopoDS_Shape.hxx> |
4e57c75e |
36 | |
37 | //======================================================================= |
38 | //function : FillImagesVertices |
39 | //purpose : |
40 | //======================================================================= |
41 | void BOPAlgo_Builder::FillImagesVertices() |
42 | { |
43 | myErrorStatus=0; |
44 | // |
45 | Standard_Integer nV, nVSD; |
46 | BOPCol_DataMapIteratorOfDataMapOfIntegerInteger aIt; |
47 | // |
48 | const BOPCol_DataMapOfIntegerInteger& aMSDV=myDS->ShapesSD(); |
49 | aIt.Initialize(aMSDV); |
50 | for (; aIt.More(); aIt.Next()) { |
51 | nV=aIt.Key(); |
52 | nVSD=aIt.Value(); |
53 | const TopoDS_Shape& aV=myDS->Shape(nV); |
54 | const TopoDS_Shape& aVSD=myDS->Shape(nVSD); |
55 | // |
56 | BOPCol_ListOfShape aLVSD(myAllocator); |
57 | // |
58 | aLVSD.Append(aVSD); |
59 | myImages.Bind(aV, aLVSD); |
60 | // |
61 | myShapesSD.Bind(aV, aVSD); |
62 | } |
63 | } |
64 | //======================================================================= |
65 | //function : FillImagesEdges |
66 | //purpose : |
67 | //======================================================================= |
68 | void BOPAlgo_Builder::FillImagesEdges() |
69 | { |
70 | myErrorStatus=0; |
71 | // |
72 | Standard_Integer i, aNbPBP, nE, nSp, nSpR; |
73 | BOPDS_ListIteratorOfListOfPaveBlock aItPB; |
74 | // |
75 | const BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->PaveBlocksPool(); |
76 | aNbPBP=aPBP.Extent(); |
77 | for (i=0; i<aNbPBP; ++i) { |
78 | const BOPDS_ListOfPaveBlock& aLPB=aPBP(i); |
79 | if (aLPB.Extent()) { |
80 | BOPCol_ListOfShape aLS(myAllocator); |
81 | // |
82 | const Handle(BOPDS_PaveBlock)& aPB1=aLPB.First(); |
83 | nE=aPB1->OriginalEdge(); |
84 | const TopoDS_Shape& aE=myDS->Shape(nE); |
85 | // |
86 | aItPB.Initialize(aLPB); |
87 | for (; aItPB.More(); aItPB.Next()) { |
88 | const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value(); |
3510db62 |
89 | Handle(BOPDS_PaveBlock) aPBR=myDS->RealPaveBlock(aPB); |
4e57c75e |
90 | // |
91 | nSpR=aPBR->Edge(); |
92 | const TopoDS_Shape& aSpR=myDS->Shape(nSpR); |
93 | aLS.Append(aSpR); |
94 | myOrigins.Bind(aSpR, aE); |
95 | // |
5a77460e |
96 | if (myDS->IsCommonBlockOnEdge(aPB)) { |
4e57c75e |
97 | nSp=aPB->Edge(); |
98 | const TopoDS_Shape& aSp=myDS->Shape(nSp); |
99 | myShapesSD.Bind(aSp, aSpR); |
100 | } |
101 | } |
102 | myImages.Bind(aE, aLS); |
103 | } |
104 | } |
105 | } |
106 | //======================================================================= |
107 | // function: IsInterferred |
108 | // purpose: |
109 | //======================================================================= |
110 | Standard_Boolean BOPAlgo_Builder::IsInterferred(const TopoDS_Shape& theS)const |
111 | { |
112 | Standard_Boolean bInterferred; |
113 | TopoDS_Iterator aIt; |
114 | // |
115 | bInterferred=Standard_False; |
116 | aIt.Initialize(theS); |
117 | for (; aIt.More(); aIt.Next()) { |
118 | const TopoDS_Shape& aSx=aIt.Value(); |
119 | if (myImages.IsBound(aSx)) { |
120 | bInterferred=!bInterferred; |
121 | break; |
122 | } |
123 | } |
124 | return bInterferred; |
125 | } |
126 | //======================================================================= |
127 | //function : BuildResult |
128 | //purpose : |
129 | //======================================================================= |
130 | void BOPAlgo_Builder::BuildResult(const TopAbs_ShapeEnum theType) |
131 | { |
132 | myErrorStatus=0; |
133 | // |
134 | TopAbs_ShapeEnum aType; |
135 | BRep_Builder aBB; |
136 | BOPCol_MapOfShape aM; |
137 | BOPCol_ListIteratorOfListOfShape aIt, aItIm; |
138 | // |
139 | aIt.Initialize(myArguments); |
140 | for (; aIt.More(); aIt.Next()) { |
141 | const TopoDS_Shape& aS=aIt.Value(); |
142 | aType=aS.ShapeType(); |
143 | if (aType==theType) { |
144 | if (myImages.IsBound(aS)){ |
319da2e4 |
145 | const BOPCol_ListOfShape& aLSIm=myImages.Find(aS); |
146 | aItIm.Initialize(aLSIm); |
147 | for (; aItIm.More(); aItIm.Next()) { |
148 | const TopoDS_Shape& aSIm=aItIm.Value(); |
149 | if (aM.Add(aSIm)) { |
150 | aBB.Add(myShape, aSIm); |
151 | } |
152 | } |
4e57c75e |
153 | } |
154 | else { |
319da2e4 |
155 | if (aM.Add(aS)) { |
156 | aBB.Add(myShape, aS); |
157 | } |
4e57c75e |
158 | } |
159 | } |
160 | } |
161 | } |
162 | //======================================================================= |
163 | // function: FillImagesContainers |
164 | // purpose: |
165 | //======================================================================= |
166 | void BOPAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType) |
167 | { |
168 | myErrorStatus=0; |
169 | // |
170 | Standard_Integer i, aNbS; |
171 | BOPCol_MapOfShape aMFP(100, myAllocator); |
172 | // |
173 | aNbS=myDS->NbSourceShapes(); |
174 | for (i=0; i<aNbS; ++i) { |
175 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
176 | if (aSI.ShapeType()==theType) { |
177 | const TopoDS_Shape& aC=aSI.Shape(); |
178 | FillImagesContainer(aC, theType); |
179 | } |
180 | }// for (; aItS.More(); aItS.Next()) { |
181 | } |
182 | //======================================================================= |
183 | // function: FillImagesCompounds |
184 | // purpose: |
185 | //======================================================================= |
186 | void BOPAlgo_Builder::FillImagesCompounds() |
187 | { |
188 | myErrorStatus=0; |
189 | // |
190 | Standard_Integer i, aNbS; |
191 | BOPCol_MapOfShape aMFP(100, myAllocator); |
192 | // |
193 | aNbS=myDS->NbSourceShapes(); |
194 | for (i=0; i<aNbS; ++i) { |
195 | const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i); |
196 | if (aSI.ShapeType()==TopAbs_COMPOUND) { |
197 | const TopoDS_Shape& aC=aSI.Shape(); |
198 | FillImagesCompound(aC, aMFP); |
199 | } |
200 | }// for (; aItS.More(); aItS.Next()) { |
201 | } |
202 | //======================================================================= |
203 | //function : FillImagesContainer |
204 | //purpose : |
205 | //======================================================================= |
206 | void BOPAlgo_Builder::FillImagesContainer(const TopoDS_Shape& theS, |
207 | const TopAbs_ShapeEnum theType) |
208 | { |
209 | Standard_Boolean bInterferred, bToReverse; |
210 | TopoDS_Iterator aIt; |
211 | BRep_Builder aBB; |
212 | BOPCol_ListIteratorOfListOfShape aItIm; |
213 | // |
214 | bInterferred=IsInterferred(theS); |
215 | if (!bInterferred){ |
216 | return; |
217 | } |
218 | // |
219 | TopoDS_Shape aCIm; |
220 | BOPTools_AlgoTools::MakeContainer(theType, aCIm); |
221 | // |
222 | aIt.Initialize(theS); |
223 | for (; aIt.More(); aIt.Next()) { |
224 | const TopoDS_Shape& aSx=aIt.Value(); |
225 | if (myImages.IsBound(aSx)) { |
226 | const BOPCol_ListOfShape& aLFIm=myImages.Find(aSx); |
227 | aItIm.Initialize(aLFIm); |
228 | for (; aItIm.More(); aItIm.Next()) { |
229 | TopoDS_Shape aSxIm=aItIm.Value(); |
230 | // |
231 | bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSxIm, aSx, myContext); |
232 | if (bToReverse) { |
233 | aSxIm.Reverse(); |
234 | } |
235 | aBB.Add(aCIm, aSxIm); |
236 | } |
237 | } |
238 | else { |
239 | aBB.Add(aCIm, aSx); |
240 | } |
241 | } |
242 | // |
c5d8782c |
243 | aCIm.Closed(BRep_Tool::IsClosed(aCIm)); |
244 | // |
4e57c75e |
245 | BOPCol_ListOfShape aLSIm(myAllocator); |
246 | aLSIm.Append(aCIm); |
247 | myImages.Bind(theS, aLSIm); |
248 | } |
249 | //======================================================================= |
250 | //function : FillImagesCompound |
251 | //purpose : |
252 | //======================================================================= |
253 | void BOPAlgo_Builder::FillImagesCompound(const TopoDS_Shape& theS, |
254 | BOPCol_MapOfShape& theMFP) |
255 | { |
256 | Standard_Boolean bInterferred; |
257 | TopAbs_Orientation aOrX; |
258 | TopoDS_Iterator aIt; |
259 | BRep_Builder aBB; |
260 | BOPCol_ListIteratorOfListOfShape aItIm; |
261 | // |
262 | if (!theMFP.Add(theS)) { |
263 | return; |
264 | } |
265 | // |
266 | bInterferred=Standard_False; |
267 | aIt.Initialize(theS); |
268 | for (; aIt.More(); aIt.Next()) { |
269 | const TopoDS_Shape& aSx=aIt.Value(); |
270 | if (aSx.ShapeType()==TopAbs_COMPOUND) { |
271 | FillImagesCompound(aSx, theMFP); |
272 | } |
273 | if (myImages.IsBound(aSx)) { |
274 | bInterferred=Standard_True; |
275 | } |
276 | } |
277 | if (!bInterferred){ |
278 | return; |
279 | } |
280 | // |
281 | TopoDS_Shape aCIm; |
282 | BOPTools_AlgoTools::MakeContainer(TopAbs_COMPOUND, aCIm); |
283 | // |
284 | aIt.Initialize(theS); |
285 | for (; aIt.More(); aIt.Next()) { |
286 | const TopoDS_Shape& aSX=aIt.Value(); |
287 | aOrX=aSX.Orientation(); |
288 | if (myImages.IsBound(aSX)) { |
289 | const BOPCol_ListOfShape& aLFIm=myImages.Find(aSX); |
290 | aItIm.Initialize(aLFIm); |
291 | for (; aItIm.More(); aItIm.Next()) { |
319da2e4 |
292 | TopoDS_Shape aSXIm=aItIm.Value(); |
293 | aSXIm.Orientation(aOrX); |
294 | aBB.Add(aCIm, aSXIm); |
4e57c75e |
295 | } |
296 | } |
297 | else { |
298 | aBB.Add(aCIm, aSX); |
299 | } |
300 | } |
301 | // |
302 | BOPCol_ListOfShape aLSIm(myAllocator); |
303 | aLSIm.Append(aCIm); |
304 | myImages.Bind(theS, aLSIm); |
305 | } |