summaryrefslogtreecommitdiff
path: root/src/BOP/BOP_Builder.cxx
blob: 826eed9e49996295da87c98ac897ceae16f7d29d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// File:	BOP_Builder.cxx
// Created:	Thu Mar 29 11:12:53 2001
// Author:	Peter KURNEV
//		<pkv@irinox>


#include <BOP_Builder.ixx>

#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopExp.hxx>

#include <BooleanOperations_ShapesDataStructure.hxx>

#include <BOPTools_SplitShapesPool.hxx>
#include <BOPTools_CommonBlockPool.hxx>
#include <BOPTools_ListOfPaveBlock.hxx>
#include <BOPTools_ListOfCommonBlock.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <BOPTools_ListIteratorOfListOfCommonBlock.hxx>
#include <BOPTools_CommonBlock.hxx>
#include <BOPTools_PaveBlock.hxx>
#include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>

//=======================================================================
// function: BOP_Builder::BOP_Builder
// purpose: 
//=======================================================================
  BOP_Builder::BOP_Builder() 
: myOperation(BOP_UNKNOWN),
  myManifoldFlag(Standard_False),
  myIsDone(Standard_False),
  myErrorStatus(1),
  myDraw(0)
{
}
//=======================================================================
// function: Destroy
// purpose: 
//=======================================================================
  void BOP_Builder::Destroy()
{
}

//=======================================================================
// function: SetShapes
// purpose: 
//=======================================================================
  void BOP_Builder::SetShapes (const TopoDS_Shape& aS1,
			       const TopoDS_Shape& aS2)
{
  myShape1=aS1;
  myShape2=aS2;
}
//=======================================================================
// function: SetOperation
// purpose: 
//=======================================================================
  void BOP_Builder::SetOperation (const BOP_Operation anOp) 
{
  myOperation=anOp;
}
	 

//=======================================================================
// function: SetManifoldFlag
// purpose: 
//=======================================================================
  void BOP_Builder::SetManifoldFlag (const Standard_Boolean aFlag)
{
  myManifoldFlag=aFlag;
}
//=======================================================================
// function: Shape1
// purpose: 
//=======================================================================
  const TopoDS_Shape& BOP_Builder::Shape1()const
{
  return myShape1;
}

//=======================================================================
// function: Shape2
// purpose: 
//=======================================================================
  const TopoDS_Shape& BOP_Builder::Shape2()const
{
  return myShape2;
}
//=======================================================================
// function: Operation
// purpose: 
//=======================================================================
  BOP_Operation BOP_Builder::Operation () const
{
  return myOperation;
}
	
//=======================================================================
// function: ManifoldFlag
// purpose: 
//=======================================================================
  Standard_Boolean BOP_Builder::ManifoldFlag () const 
{
  return myManifoldFlag;
}
//=======================================================================
// function: IsDone
// purpose: 
//=======================================================================
  Standard_Boolean BOP_Builder::IsDone() const 
{
  return myIsDone;
}
//=======================================================================
// function: ErrorStatus
// purpose: 
//=======================================================================
  Standard_Integer BOP_Builder::ErrorStatus() const 
{
  return myErrorStatus;
}
//=======================================================================
// function: Result
// purpose: 
//=======================================================================
  const TopoDS_Shape& BOP_Builder::Result()const
{
  return myResult;
}

//=======================================================================
// function: Do
// purpose: 
//=======================================================================
  void BOP_Builder::Do()
{
}
//=======================================================================
// function: DoDoWithFiller
// purpose: 
//=======================================================================
  void BOP_Builder::DoWithFiller(const BOPTools_DSFiller& )
{
} 

//=======================================================================
// function: BuildResult
// purpose: 
//=======================================================================
  void BOP_Builder::BuildResult()
{
}
//
//
//=======================================================================
// function: FillModified
// purpose: 
//=======================================================================
  void BOP_Builder::FillModified()
{
  //
  // Prepare myResultMap
  myResultMap.Clear();
  TopExp::MapShapes(myResult, TopAbs_FACE, myResultMap);
  TopExp::MapShapes(myResult, TopAbs_EDGE, myResultMap);
  //
  // Fill Modified for Edges
  Standard_Integer i, aNbSources, aNbPaveBlocks, nSp, nFace;
  //
  const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
  const BOPTools_SplitShapesPool& aSplitShapesPool= myDSFiller->SplitShapesPool();
  const BOPTools_CommonBlockPool& aCommonBlockPool= myDSFiller->CommonBlockPool();
  //
  aNbSources=aDS.NumberOfSourceShapes();
  for (i=1; i<=aNbSources; i++) {
    
    if (aDS.GetShapeType(i) != TopAbs_EDGE){
      continue;
    }
    //
    const TopoDS_Shape& aE=aDS.Shape(i);
    //
    const BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool(aDS.RefEdge(i));
    const BOPTools_ListOfCommonBlock& aCBlocks =aCommonBlockPool(aDS.RefEdge(i));
    //
    aNbPaveBlocks=aSplitEdges.Extent();
    if (!aNbPaveBlocks) {
      continue;
    }
    //
    TopTools_IndexedMapOfShape aM;
    
    BOPTools_ListIteratorOfListOfCommonBlock aCBIt(aCBlocks);
    for (; aCBIt.More(); aCBIt.Next()) {
      BOPTools_CommonBlock& aCB=aCBIt.Value();
      //
      nFace=aCB.Face();
      //
      if (nFace) {
	BOPTools_PaveBlock& aPB=aCB.PaveBlock1(i);
	nSp=aPB.Edge();
	const TopoDS_Shape& aSp=aDS.Shape(nSp);
	//
	if (aM.Contains(aSp)) {
	  continue;
	}
	aM.Add(aSp);
	//
	if (myResultMap.Contains(aSp)) {
	  FillModified(aE, aSp);
	}
      }
      //
      else {
	const BOPTools_PaveBlock& aPB=aCB.PaveBlock1();
	nSp=aPB.Edge();
	const TopoDS_Shape& aSp=aDS.Shape(nSp);
	//
	if (aM.Contains(aSp)) {
	  continue;
	}
	aM.Add(aSp);
	//
	if (myResultMap.Contains(aSp)) {
	  FillModified(aE, aSp);
	}
      }
    } // for (; aCBIt.More(); aCBIt.Next())
    
    
    BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);
    for (; aPBIt.More(); aPBIt.Next()) {
      const BOPTools_PaveBlock& aPB=aPBIt.Value();
      nSp=aPB.Edge();
      const TopoDS_Shape& aSp=aDS.Shape(nSp);
      //
      if (aM.Contains(aSp)) {
	continue;
      }
      aM.Add(aSp);
      //
      if (myResultMap.Contains(aSp)) {
	FillModified(aE, aSp);
      }
    }// for (; aPBIt.More(); aPBIt.Next())
  }
}
//=======================================================================
// function: FillModified
// purpose: 
//=======================================================================
  void BOP_Builder::FillModified(const TopoDS_Shape& aE,
				 const TopoDS_Shape& aSp)
{
  if (myModifiedMap.Contains(aE)) {
    TopTools_ListOfShape& aLM=myModifiedMap.ChangeFromKey(aE);
    aLM.Append(aSp);
  }
  else {
    TopTools_ListOfShape aLM;
    aLM.Append(aSp);
    myModifiedMap.Add(aE, aLM);
  }
}
//=======================================================================
// function: FillModified
// purpose: 
//=======================================================================
  void BOP_Builder::FillModified(const TopoDS_Shape& aS,
				 const TopTools_ListOfShape& aLFx)
{
  TopTools_ListIteratorOfListOfShape anIt(aLFx);
  //
  if (myModifiedMap.Contains(aS)) {
    TopTools_ListOfShape& aLM=myModifiedMap.ChangeFromKey(aS);
    anIt.Initialize(aLFx);
    for (; anIt.More(); anIt.Next()) {
      const TopoDS_Shape& aFx=anIt.Value();
      aLM.Append(aFx);
    }
  }
  
  else {
    TopTools_ListOfShape aLM;
    anIt.Initialize(aLFx);
    for (; anIt.More(); anIt.Next()) {
      const TopoDS_Shape& aFx=anIt.Value();
      aLM.Append(aFx);
    }
    myModifiedMap.Add(aS, aLM);
  }
}
//=======================================================================
// function: Modified
// purpose: 
//=======================================================================
  const TopTools_ListOfShape& BOP_Builder::Modified(const TopoDS_Shape& aS)const
{
  if (myModifiedMap.Contains(aS)) {
    const TopTools_ListOfShape& aLM=myModifiedMap.FindFromKey(aS);
    return aLM;
  }
  else {
    return myEmptyList;
  }
}
//=======================================================================
// function: IsDeleted
// purpose: 
//=======================================================================
  Standard_Boolean BOP_Builder::IsDeleted(const TopoDS_Shape& aS)const
{
  Standard_Boolean bFlag=Standard_False;
  //
  if (myResultMap.Contains(aS)) {
    return bFlag;
  }
  //
  const TopTools_ListOfShape& aLM=Modified(aS);
  if (aLM.Extent()) {
    return bFlag;
  }
  //
  return !bFlag;
}


//=======================================================================
//function : SortTypes
//purpose  : 
//=======================================================================
  void BOP_Builder::SortTypes(TopAbs_ShapeEnum& aType1,
			      TopAbs_ShapeEnum& aType2)
{ 
  Standard_Integer iT1, iT2;

  if (aType1==aType2)
    return;
  
  iT1=(Standard_Integer) aType1;
  iT2=(Standard_Integer) aType2;
  
  if (iT1 < iT2) {
    aType1=(TopAbs_ShapeEnum) iT2;
    aType2=(TopAbs_ShapeEnum) iT1;
  }
}

//=======================================================================
// function: SectionEdges
// purpose: 
//=======================================================================
  const TopTools_ListOfShape& BOP_Builder::SectionEdges()const
{
  return mySectionEdges;
}


//=======================================================================
// function: SetHistoryCollector
// purpose: 
//=======================================================================
void BOP_Builder::SetHistoryCollector(const Handle(BOP_HistoryCollector)& theHistory) 
{
  myHistory = theHistory;
}

//=======================================================================
// function: GetHistoryCollector
// purpose: 
//=======================================================================
Handle(BOP_HistoryCollector) BOP_Builder::GetHistoryCollector() const
{
  return myHistory;
}