b311480e |
1 | // Created on: 2001-01-26 |
2 | // Created by: Peter KURNEV |
3 | // Copyright (c) 2001-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | |
21 | |
22 | #include <BOPTools_InterferencePool.ixx> |
23 | |
24 | #include <BRep_Tool.hxx> |
25 | |
26 | #include <TopoDS.hxx> |
27 | #include <TopoDS_Shape.hxx> |
28 | #include <TopoDS_Vertex.hxx> |
29 | #include <TopoDS_Edge.hxx> |
30 | #include <TopoDS_Face.hxx> |
31 | |
32 | #include <IntTools_Tools.hxx> |
33 | #include <IntTools_EdgeEdge.hxx> |
34 | #include <IntTools_SequenceOfCommonPrts.hxx> |
35 | #include <IntTools_CommonPrt.hxx> |
36 | |
37 | #include <BOPTools_VEInterference.hxx> |
38 | #include <BOPTools_VVInterference.hxx> |
39 | #include <BOPTools_VSInterference.hxx> |
40 | #include <BOPTools_EEInterference.hxx> |
41 | #include <BOPTools_SSInterference.hxx> |
42 | #include <BOPTools_InterferenceLine.hxx> |
43 | #include <IntTools_EdgeFace.hxx> |
44 | #include <BOPTools_ESInterference.hxx> |
45 | |
46 | |
47 | //======================================================================= |
48 | //function : BOPTools_InterferencePool |
49 | //purpose : |
50 | //======================================================================= |
b311480e |
51 | BOPTools_InterferencePool::BOPTools_InterferencePool() |
7fd59977 |
52 | { |
53 | myDS=NULL; |
54 | myNbSourceShapes=0; |
55 | } |
56 | //======================================================================= |
57 | //function : BOPTools_InterferencePool |
58 | //purpose : |
59 | //======================================================================= |
60 | BOPTools_InterferencePool::BOPTools_InterferencePool (const BooleanOperations_ShapesDataStructure& aDS) |
61 | { |
62 | SetDS(aDS); |
63 | } |
64 | //======================================================================= |
65 | //function : SetDS |
66 | //purpose : |
67 | //======================================================================= |
68 | void BOPTools_InterferencePool::SetDS(const BooleanOperations_ShapesDataStructure& aDS) |
69 | { |
70 | void* p=(void*) &aDS; |
71 | myDS=(BooleanOperations_ShapesDataStructure*) p; |
72 | myNbSourceShapes= myDS->NumberOfShapesOfTheObject()+myDS->NumberOfShapesOfTheTool(); |
73 | myInterferenceTable.Resize (myNbSourceShapes); |
74 | } |
75 | //======================================================================= |
76 | //function : DS |
77 | //purpose : |
78 | //======================================================================= |
79 | BooleanOperations_PShapesDataStructure BOPTools_InterferencePool::DS() const |
80 | { |
81 | return myDS; |
82 | } |
83 | //======================================================================= |
84 | //function : HasInterference |
85 | //purpose : |
86 | //======================================================================= |
87 | Standard_Boolean BOPTools_InterferencePool::HasInterference(const Standard_Integer anInd1)const |
88 | { |
89 | const BOPTools_InterferenceLine& aWhatLine=myInterferenceTable(anInd1); |
90 | Standard_Boolean bFlag=aWhatLine.HasInterference(); |
91 | return bFlag; |
92 | } |
93 | //======================================================================= |
94 | //function : IsComputed |
95 | //purpose : |
96 | //======================================================================= |
97 | Standard_Boolean BOPTools_InterferencePool::IsComputed(const Standard_Integer anInd1, |
98 | const Standard_Integer anInd2) const |
99 | { |
100 | BooleanOperations_KindOfInterference theType; |
101 | |
102 | theType=InterferenceType(anInd1, anInd2); |
103 | |
104 | if (theType==BooleanOperations_UnknownInterference) { |
105 | return Standard_False; |
106 | } |
107 | |
108 | const BOPTools_InterferenceLine& aWhatLine=myInterferenceTable(anInd1); |
109 | Standard_Boolean aFlag=aWhatLine.IsComputed(anInd2, theType); |
110 | return aFlag; |
111 | } |
112 | |
113 | |
114 | //=========================================================================== |
115 | //function : AddInterference |
116 | //purpose : |
117 | //=========================================================================== |
118 | void BOPTools_InterferencePool::AddInterference (const Standard_Integer theWhat, |
119 | const Standard_Integer theWith, |
120 | const BooleanOperations_KindOfInterference theType, |
121 | const Standard_Integer theIndexOfInterference) |
122 | { |
123 | BOPTools_InterferenceLine& aWhatLine=myInterferenceTable(theWhat); |
124 | aWhatLine.AddInterference(theWith, theType, theIndexOfInterference); |
125 | |
126 | BOPTools_InterferenceLine& aWithLine=myInterferenceTable(theWith); |
127 | aWithLine.AddInterference(theWhat, theType, theIndexOfInterference); |
128 | } |
129 | |
130 | //======================================================================= |
131 | //function : InterferenceType |
132 | //purpose : |
133 | //======================================================================= |
134 | BooleanOperations_KindOfInterference |
135 | BOPTools_InterferencePool::InterferenceType(const Standard_Integer theWhat, |
136 | const Standard_Integer theWith) const |
137 | { |
138 | BooleanOperations_KindOfInterference theType; |
139 | Standard_Integer aWhat, aWith; |
140 | TopAbs_ShapeEnum aType1, aType2; |
141 | |
142 | aWhat=theWhat; |
143 | aWith=theWith; |
144 | SortTypes(aWhat, aWith); |
145 | |
146 | aType1= myDS->GetShapeType(aWhat), |
147 | aType2= myDS->GetShapeType(aWith); |
148 | |
149 | if (aType1==TopAbs_VERTEX && aType2==TopAbs_VERTEX) { |
150 | theType=BooleanOperations_VertexVertex; |
151 | } |
152 | else if (aType1==TopAbs_VERTEX && aType2==TopAbs_EDGE) { |
153 | theType=BooleanOperations_VertexEdge; |
154 | } |
155 | else if (aType1==TopAbs_VERTEX && aType2==TopAbs_FACE) { |
156 | theType=BooleanOperations_VertexSurface; |
157 | } |
158 | else if (aType1==TopAbs_EDGE && aType2==TopAbs_EDGE) { |
159 | theType=BooleanOperations_EdgeEdge; |
160 | } |
161 | else if (aType1==TopAbs_EDGE && aType2==TopAbs_FACE) { |
162 | theType=BooleanOperations_EdgeSurface; |
163 | } |
164 | else if (aType1==TopAbs_FACE && aType2==TopAbs_FACE) { |
165 | theType=BooleanOperations_SurfaceSurface; |
166 | } |
167 | else { |
168 | theType=BooleanOperations_UnknownInterference; |
169 | } |
170 | |
171 | return theType; |
172 | } |
173 | |
174 | //======================================================================= |
175 | //function : SortTypes |
176 | //purpose : |
177 | //======================================================================= |
178 | void BOPTools_InterferencePool::SortTypes(Standard_Integer& theWhat, |
179 | Standard_Integer& theWith) const |
180 | { |
181 | Standard_Boolean aReverseFlag=Standard_True; |
182 | |
183 | TopAbs_ShapeEnum aType1= myDS->GetShapeType(theWhat), |
184 | aType2= myDS->GetShapeType(theWith); |
185 | |
186 | if (aType1==aType2) |
187 | return; |
188 | |
189 | if (aType1==TopAbs_EDGE && aType2==TopAbs_FACE){ |
190 | aReverseFlag=Standard_False; |
191 | } |
192 | |
193 | if (aType1==TopAbs_VERTEX && |
194 | (aType2==TopAbs_FACE || aType2==TopAbs_EDGE)) { |
195 | aReverseFlag=Standard_False; |
196 | } |
197 | |
198 | Standard_Integer aWhat, aWith; |
199 | aWhat=(aReverseFlag) ? theWith : theWhat; |
200 | aWith=(aReverseFlag) ? theWhat : theWith; |
201 | |
202 | theWhat=aWhat; |
203 | theWith=aWith; |
204 | } |
205 | |
206 | //=========================================================================== |
207 | //function : InterferenceTable |
208 | //purpose : |
209 | //=========================================================================== |
210 | const BOPTools_CArray1OfInterferenceLine& |
211 | BOPTools_InterferencePool::InterferenceTable()const |
212 | { |
213 | return myInterferenceTable; |
214 | } |
215 | |
216 | //=========================================================================== |
217 | //function : SSInterferences |
218 | //purpose : |
219 | //=========================================================================== |
220 | BOPTools_CArray1OfSSInterference& BOPTools_InterferencePool::SSInterferences() |
221 | { |
222 | return mySSInterferences; |
223 | } |
224 | //=========================================================================== |
225 | //function : ESInterferences |
226 | //purpose : |
227 | //=========================================================================== |
228 | BOPTools_CArray1OfESInterference& BOPTools_InterferencePool::ESInterferences() |
229 | { |
230 | return myESInterferences; |
231 | } |
232 | //=========================================================================== |
233 | //function : VSInterferences |
234 | //purpose : |
235 | //=========================================================================== |
236 | BOPTools_CArray1OfVSInterference& BOPTools_InterferencePool::VSInterferences() |
237 | { |
238 | return myVSInterferences; |
239 | } |
240 | //=========================================================================== |
241 | //function : EEInterferences |
242 | //purpose : |
243 | //=========================================================================== |
244 | BOPTools_CArray1OfEEInterference& BOPTools_InterferencePool::EEInterferences() |
245 | { |
246 | return myEEInterferences; |
247 | } |
248 | //=========================================================================== |
249 | //function : VEInterferences |
250 | //purpose : |
251 | //=========================================================================== |
252 | BOPTools_CArray1OfVEInterference& BOPTools_InterferencePool::VEInterferences() |
253 | { |
254 | return myVEInterferences; |
255 | } |
256 | |
257 | //=========================================================================== |
258 | //function : VVInterferences |
259 | //purpose : |
260 | //=========================================================================== |
261 | BOPTools_CArray1OfVVInterference& BOPTools_InterferencePool::VVInterferences() |
262 | { |
263 | return myVVInterferences; |
264 | } |
265 | //////////////////////// |
266 | |
267 | //=========================================================================== |
268 | //function : SSInterfs |
269 | //purpose : |
270 | //=========================================================================== |
271 | const BOPTools_CArray1OfSSInterference& BOPTools_InterferencePool::SSInterfs()const |
272 | { |
273 | return mySSInterferences; |
274 | } |
275 | //=========================================================================== |
276 | //function : ESInterfs |
277 | //purpose : |
278 | //=========================================================================== |
279 | const BOPTools_CArray1OfESInterference& BOPTools_InterferencePool::ESInterfs()const |
280 | { |
281 | return myESInterferences; |
282 | } |
283 | //=========================================================================== |
284 | //function : VSInterfs |
285 | //purpose : |
286 | //=========================================================================== |
287 | const BOPTools_CArray1OfVSInterference& BOPTools_InterferencePool::VSInterfs()const |
288 | { |
289 | return myVSInterferences; |
290 | } |
291 | //=========================================================================== |
292 | //function : EEInterfs |
293 | //purpose : |
294 | //=========================================================================== |
295 | const BOPTools_CArray1OfEEInterference& BOPTools_InterferencePool::EEInterfs()const |
296 | { |
297 | return myEEInterferences; |
298 | } |
299 | //=========================================================================== |
300 | //function : VEInterfs |
301 | //purpose : |
302 | //=========================================================================== |
303 | const BOPTools_CArray1OfVEInterference& BOPTools_InterferencePool::VEInterfs()const |
304 | { |
305 | return myVEInterferences; |
306 | } |
307 | |
308 | //=========================================================================== |
309 | //function : VVInterfs |
310 | //purpose : |
311 | //=========================================================================== |
312 | const BOPTools_CArray1OfVVInterference& BOPTools_InterferencePool::VVInterfs()const |
313 | { |
314 | return myVVInterferences; |
315 | } |
316 | //=========================================================================== |
317 | //function : GetInterference |
318 | //purpose : |
319 | //=========================================================================== |
320 | BOPTools_PShapeShapeInterference |
321 | BOPTools_InterferencePool::GetInterference(const Standard_Integer anIndex, |
322 | const BooleanOperations_KindOfInterference aType)const |
323 | { |
324 | Standard_Integer aNb; |
325 | BOPTools_PShapeShapeInterference pI=NULL; |
326 | |
327 | switch (aType) { |
328 | // |
329 | case BooleanOperations_SurfaceSurface: |
330 | aNb=mySSInterferences.Extent(); |
331 | if (anIndex > 0 && anIndex <= aNb) { |
332 | pI=(BOPTools_PShapeShapeInterference)&mySSInterferences(anIndex); |
333 | } |
334 | break; |
335 | // |
336 | case BooleanOperations_EdgeSurface: |
337 | aNb=myESInterferences.Extent(); |
338 | if (anIndex > 0 && anIndex <= aNb) { |
339 | pI=(BOPTools_PShapeShapeInterference)&myESInterferences(anIndex); |
340 | } |
341 | break; |
342 | // |
343 | case BooleanOperations_VertexSurface: |
344 | aNb=myVSInterferences.Extent(); |
345 | if (anIndex > 0 && anIndex <= aNb) { |
346 | pI=(BOPTools_PShapeShapeInterference)&myVSInterferences(anIndex); |
347 | } |
348 | break; |
349 | // |
350 | case BooleanOperations_EdgeEdge: |
351 | aNb=myEEInterferences.Extent(); |
352 | if (anIndex > 0 && anIndex <= aNb) { |
353 | pI=(BOPTools_PShapeShapeInterference)&myEEInterferences(anIndex); |
354 | } |
355 | break; |
356 | // |
357 | case BooleanOperations_VertexEdge: |
358 | aNb=myVEInterferences.Extent(); |
359 | if (anIndex > 0 && anIndex <= aNb) { |
360 | pI=(BOPTools_PShapeShapeInterference)&myVEInterferences(anIndex); |
361 | } |
362 | break; |
363 | // |
364 | case BooleanOperations_VertexVertex: |
365 | aNb=myVVInterferences.Extent(); |
366 | if (anIndex > 0 && anIndex <= aNb) { |
367 | pI=(BOPTools_PShapeShapeInterference)&myVVInterferences(anIndex); |
368 | } |
369 | break; |
370 | // |
371 | case BooleanOperations_UnknownInterference: |
372 | default: |
373 | break; |
374 | } |
375 | return pI; |
376 | } |
377 | |