summaryrefslogtreecommitdiff
path: root/src/TopOpeBRepBuild/TopOpeBRepBuild_HBuilder.cxx
blob: 89ecc6164ed1208d5471271f929f0f4ca751ec9b (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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
// File:	TopOpeBRepBuild_HBuilder.cxx
// Created:	Mon Jun 14 11:48:36 1993
// Author:	Jean Yves LEBEY
//		<jyl@zerox>

#include <TopOpeBRepBuild_HBuilder.ixx>
#include <TopOpeBRepDS_ListOfShapeOn1State.hxx>
#include <TopOpeBRepDS_DataMapIteratorOfDataMapOfShapeListOfShapeOn1State.hxx>
#include <TopOpeBRepDS_CurveIterator.hxx>
#include <TopOpeBRepDS_CurveExplorer.hxx>
#include <TopOpeBRepDS_Interference.hxx>
#include <TopOpeBRepDS_ShapeShapeInterference.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopoDS.hxx>
#include <Standard_ProgramError.hxx>
#include <TopOpeBRepBuild_define.hxx>

//=======================================================================
//function : TopOpeBRepBuild_HBuilder
//purpose  : 
//=======================================================================
TopOpeBRepBuild_HBuilder::TopOpeBRepBuild_HBuilder
(const TopOpeBRepDS_BuildTool& BT) 
: myBuilder(BT),
  myMakeEdgeAncestorIsDone(Standard_False),
  myMakeCurveAncestorIsDone(Standard_False),
  myMakePointAncestorIsDone(Standard_False)
{
}

//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================
void TopOpeBRepBuild_HBuilder::Perform
(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
{
  myBuilder.Perform(HDS);
}

//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================
void TopOpeBRepBuild_HBuilder::Perform(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const TopoDS_Shape& S1, const TopoDS_Shape& S2)
{
  myBuilder.Perform(HDS,S1,S2);
}

//=======================================================================
//function : Clear
//purpose  : 
//=======================================================================
void TopOpeBRepBuild_HBuilder::Clear()
{
  myBuilder.Clear();
  InitExtendedSectionDS();  
}

//=======================================================================
//function : DataStructure
//purpose  : 
//=======================================================================
Handle(TopOpeBRepDS_HDataStructure) TopOpeBRepBuild_HBuilder::DataStructure() const
{
  return myBuilder.DataStructure();
}

//=======================================================================
//function : ChangeBuildTool
//purpose  : 
//=======================================================================
TopOpeBRepDS_BuildTool& TopOpeBRepBuild_HBuilder::ChangeBuildTool() 
{
  TopOpeBRepDS_BuildTool& BT = myBuilder.ChangeBuildTool();
  return BT;
}

//=======================================================================
//function : BuildTool
//purpose  : 
//=======================================================================
const TopOpeBRepDS_BuildTool& TopOpeBRepBuild_HBuilder::BuildTool() const
{
  return myBuilder.BuildTool();
}

//=======================================================================
//function : MergeShapes
//purpose  : 
//=======================================================================

void TopOpeBRepBuild_HBuilder::MergeShapes
(const TopoDS_Shape& S1, const TopAbs_State ToBuild1,const TopoDS_Shape& S2, const TopAbs_State ToBuild2)
{
  myBuilder.MergeShapes(S1,ToBuild1,S2,ToBuild2);
}


//=======================================================================
//function : MergeSolids
//purpose  : 
//=======================================================================

void TopOpeBRepBuild_HBuilder::MergeSolids
(const TopoDS_Shape& S1, const TopAbs_State ToBuild1,const TopoDS_Shape& S2, const TopAbs_State ToBuild2)
{
  myBuilder.MergeSolids(S1,ToBuild1,S2,ToBuild2);
}


//=======================================================================
//function : MergeSolid
//purpose  : 
//=======================================================================

void TopOpeBRepBuild_HBuilder::MergeSolid(const TopoDS_Shape& S, const TopAbs_State ToBuild)
{
  myBuilder.MergeSolid(S,ToBuild);
}


//=======================================================================
//function : IsSplit
//purpose  : 
//=======================================================================
Standard_Boolean TopOpeBRepBuild_HBuilder::IsSplit(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
{
  Standard_Boolean res = myBuilder.IsSplit(S,ToBuild);
  return res;
}


//=======================================================================
//function : Splits
//purpose  : 
//=======================================================================
const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::Splits(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
{
  const TopTools_ListOfShape& L = myBuilder.Splits(S,ToBuild);
  return L;
}


//=======================================================================
//function : IsMerged
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepBuild_HBuilder::IsMerged(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
{
  Standard_Boolean res = myBuilder.IsMerged(S,ToBuild);
  return res;
}


//=======================================================================
//function : Merged
//purpose  : 
//=======================================================================

const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::Merged(const TopoDS_Shape& S, const TopAbs_State ToBuild) const
{
  const TopTools_ListOfShape& L = myBuilder.Merged(S,ToBuild);
  return L;
}


//=======================================================================
//function : NewVertex
//purpose  : 
//=======================================================================
const TopoDS_Shape& TopOpeBRepBuild_HBuilder::NewVertex(const Standard_Integer I) const
{
  const TopoDS_Shape& V = myBuilder.NewVertex(I);
  return V;
}


//=======================================================================
//function : NewEdges
//purpose  : 
//=======================================================================
const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::NewEdges(const Standard_Integer I) const
{
  const TopTools_ListOfShape& L = myBuilder.NewEdges(I);
  return L;
}

//=======================================================================
//function : ChangeNewEdges
//purpose  : 
//=======================================================================
TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::ChangeNewEdges(const Standard_Integer I)
{
  TopTools_ListOfShape& L = myBuilder.ChangeNewEdges(I);
  return L;
}


//=======================================================================
//function : NewFaces
//purpose  : 
//=======================================================================
const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::NewFaces(const Standard_Integer I) const
{
  const TopTools_ListOfShape& L = myBuilder.NewFaces(I);
  return L;
}


//=======================================================================
//function : Section
//purpose  : 
//=======================================================================

const TopTools_ListOfShape& TopOpeBRepBuild_HBuilder::Section()
{
  const TopTools_ListOfShape& L = myBuilder.Section();
  return L;
}

static TopTools_ListOfShape* PLE = NULL;
static TopTools_ListIteratorOfListOfShape* PITLE = NULL;
//=======================================================================
//function : InitExtendedSectionDS
//purpose  : 
//=======================================================================

void TopOpeBRepBuild_HBuilder::InitExtendedSectionDS(const Standard_Integer k)
{
  if      (k == 1) {
    myMakeCurveAncestorIsDone = Standard_False;
  }
  else if (k == 2) {
    myMakeEdgeAncestorIsDone = Standard_False;
  }
  else if (k == 3) {
    myMakeEdgeAncestorIsDone = Standard_False;
    myMakeCurveAncestorIsDone = Standard_False;
  }
  else return;
}

//=======================================================================
//function : InitSection
//purpose  : 
//=======================================================================

void TopOpeBRepBuild_HBuilder::InitSection(const Standard_Integer k)
{
  if (PLE == NULL) PLE = new TopTools_ListOfShape();
  if (PITLE == NULL) PITLE = new TopTools_ListIteratorOfListOfShape();
  PLE->Clear(); PITLE->Initialize(*PLE);
  InitExtendedSectionDS(k);
  if      (k == 1) myBuilder.SectionCurves(*PLE);
  else if (k == 2) myBuilder.SectionEdges(*PLE);
  else if (k == 3) myBuilder.Section(*PLE);
  else return;
  PITLE->Initialize(*PLE);
}

//=======================================================================
//function : MoreSection
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepBuild_HBuilder::MoreSection() const
{
  if (PITLE == NULL) return Standard_False;
  Standard_Boolean b = PITLE->More();
  return b;
}

//=======================================================================
//function : NextSection
//purpose  : 
//=======================================================================

void TopOpeBRepBuild_HBuilder::NextSection()
{
  if (PITLE == NULL) return;
  if (PITLE->More()) PITLE->Next();
}  

//=======================================================================
//function : CurrentSection
//purpose  : 
//=======================================================================

const TopoDS_Shape& TopOpeBRepBuild_HBuilder::CurrentSection() const
{
  if (PITLE == NULL) Standard_ProgramError::Raise("no more CurrentSection");
  if (!PITLE->More()) Standard_ProgramError::Raise("no more CurrentSection");
  return PITLE->Value();
}

//=======================================================================
//function : MakeEdgeAncestorMap
//purpose  : private
//=======================================================================

void TopOpeBRepBuild_HBuilder::MakeEdgeAncestorMap()
{
  if(myMakeEdgeAncestorIsDone)
    return;
  mySectEdgeDSEdges1.Clear();
  mySectEdgeDSEdges2.Clear();
  myDSEdgesDSFaces1.Clear();
  myDSEdgesDSFaces2.Clear();
  
  myMakeEdgeAncestorIsDone = Standard_True;
  TopTools_MapOfShape MF, ME;
  
  const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS();  
//  Standard_Integer ns = DS.NbShapes(),is;
  Standard_Integer ns = DS.NbShapes();
//  Standard_Integer ei, fi, re, rf ,gi, ise;
  Standard_Integer ei, fi, re, rf ,gi;
  
  TopOpeBRepDS_DataMapIteratorOfDataMapOfShapeListOfShapeOn1State
    it(myBuilder.mySplitON);
  TopTools_ListIteratorOfListOfShape its;
  for(;it.More(); it.Next()) {
    const TopoDS_Shape& ShaSpl = it.Key();
    ei = DS.Shape(ShaSpl);
    re = DS.AncestorRank(ShaSpl);
    if(!re) continue;
    TopOpeBRepDS_ListOfShapeOn1State& losos1s = 
      (*(TopOpeBRepDS_ListOfShapeOn1State*)&it.Value());
    TopTools_ListOfShape& los = losos1s.ChangeListOnState();
    its.Initialize(los);
    if(re == 1)
      for(; its.More(); its.Next()) {
	TopoDS_Shape& SecEdg = its.Value();
	if(!mySectEdgeDSEdges1.IsBound(SecEdg))
	  mySectEdgeDSEdges1.Bind(SecEdg, ei);
      }
    else if(re == 2)
      for(; its.More(); its.Next()) {
	TopoDS_Shape& SecEdg = its.Value();
	if(!mySectEdgeDSEdges2.IsBound(SecEdg))
	  mySectEdgeDSEdges2.Bind(SecEdg,ei);
      }
  }
  
//  Standard_Boolean gb;
  TopOpeBRepDS_Kind gk;
  for (fi=1;fi<=ns;fi++) {
    const TopoDS_Shape& fds = DS.Shape(fi);
    if(fds.IsNull())
      continue;
    if (fds.ShapeType() != TopAbs_FACE) continue;
    TopOpeBRepDS_ListIteratorOfListOfInterference 
      it1(DS.ShapeInterferences(fds));
    for (;it1.More();it1.Next()) {
      Handle(TopOpeBRepDS_ShapeShapeInterference) SSI = 
	Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(it1.Value());
      if (SSI.IsNull()) continue;
      gk = SSI->GeometryType();
      gi = SSI->Geometry();
      if (gk != TopOpeBRepDS_EDGE) continue;
      rf = DS.AncestorRank(fds);
      if(!rf) continue;
//      if (!MF.Contains(fds) ) {
//	MF.Add(fds);
      if(rf == 1) {
	if(!myDSEdgesDSFaces1.IsBound(gi)) {
          TColStd_ListOfInteger thelist;
	  myDSEdgesDSFaces1.Bind(gi,thelist );
        }
	myDSEdgesDSFaces1.ChangeFind(gi).Append(fi);
      }
      else if(rf == 2) {
	if(!myDSEdgesDSFaces2.IsBound(gi)){
          TColStd_ListOfInteger thelist1;
	  myDSEdgesDSFaces2.Bind(gi, thelist1);
        }
	myDSEdgesDSFaces2.ChangeFind(gi).Append(fi);
      }
      //      }
    }
  }
}

//=======================================================================
//function : GetDSEdgeFromSectEdge
//purpose  : 
//=======================================================================
Standard_Integer TopOpeBRepBuild_HBuilder::GetDSEdgeFromSectEdge(const TopoDS_Shape& E,const Standard_Integer rank)
{
  if(!myMakeEdgeAncestorIsDone)
    MakeEdgeAncestorMap();
  
  Standard_Integer i = 0;

  if(rank == 1) { 
    if(mySectEdgeDSEdges1.IsBound(E))
      i = mySectEdgeDSEdges1.Find(E);
  }

  if(rank == 2) { 
    if(mySectEdgeDSEdges2.IsBound(E))
      i = mySectEdgeDSEdges2.Find(E);
  }
  return i;
}

//=======================================================================
//function : GetDSFaceFromDSEdge
//purpose  : 
//=======================================================================
TColStd_ListOfInteger& TopOpeBRepBuild_HBuilder::GetDSFaceFromDSEdge
(const Standard_Integer indexEdg, const Standard_Integer rank)
{
  if(!myMakeEdgeAncestorIsDone)
    MakeEdgeAncestorMap();

  if(rank == 1) {
    if(myDSEdgesDSFaces1.IsBound(indexEdg)) {
      TColStd_ListOfInteger& loi = 
	myDSEdgesDSFaces1.ChangeFind(indexEdg);
      return loi;
    }
  }
  
  if(rank == 2) {
    if(myDSEdgesDSFaces2.IsBound(indexEdg)) {
      TColStd_ListOfInteger& loi = 
	myDSEdgesDSFaces2.ChangeFind(indexEdg);
      return loi;
    }
  }
  
  return myEmptyIntegerList;
}

//=======================================================================
//function : MakeCurveAncestorMap
//purpose  : 
//=======================================================================

void TopOpeBRepBuild_HBuilder::MakeCurveAncestorMap()
{
  if(myMakeCurveAncestorIsDone)
    return;
  mySectEdgeDSCurve.Clear();
  myMakeCurveAncestorIsDone = Standard_True;
#ifndef DEB  
//  static const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS();
  const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS(); // How to do static <--> const
#else
  const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS();
#endif
  TopTools_ListIteratorOfListOfShape itloe;
  TopOpeBRepDS_CurveExplorer cex(DS,Standard_True);
//  Standard_Integer ic, icm;
  Standard_Integer ic;
  for (; cex.More(); cex.Next()) {
    ic = cex.Index();
    const TopTools_ListOfShape& LOS = myBuilder.myNewEdges.Find(ic);
    itloe.Initialize(LOS);
    for(;itloe.More();itloe.Next()) {
      TopoDS_Shape& E = *((TopoDS_Shape*)(&itloe.Value()));
      if(mySectEdgeDSCurve.IsBound(E)) {
#ifdef DEB
	cout<<"BRepAlgo_DSAccess::MakeEdgeAncestorFromCurve : program error"<<endl;
#endif
      }
      mySectEdgeDSCurve.Bind(E, ic);
    }
  }
}

//=======================================================================
//function : GetDSCurveFromSectEdge
//purpose  : 
//=======================================================================

Standard_Integer TopOpeBRepBuild_HBuilder::GetDSCurveFromSectEdge(const TopoDS_Shape& SectEdge)
{
  Standard_Integer i = 0;
  if(!myMakeCurveAncestorIsDone)
    MakeCurveAncestorMap();
  
  if(mySectEdgeDSCurve.IsBound(SectEdge)) {
    i = mySectEdgeDSCurve.Find(SectEdge);
  }
  return i;
}

//=======================================================================
//function : GetDSFaceFromDSCurve
//purpose  : 
//=======================================================================

Standard_Integer TopOpeBRepBuild_HBuilder::GetDSFaceFromDSCurve(const Standard_Integer indexCur,const Standard_Integer rank)
{
  Standard_Integer i = 0;
  if(!myMakeCurveAncestorIsDone)
    MakeCurveAncestorMap();

  const TopOpeBRepDS_DataStructure& DS = DataStructure()->DS();
  if(rank == 1) {
    const TopOpeBRepDS_Curve& DSC = DS.Curve(indexCur);
    const TopoDS_Shape& F1 = DSC.Shape1();
    i = DS.Shape(F1);
  }
  
  if(rank == 2) {
    const TopOpeBRepDS_Curve& DSC = DS.Curve(indexCur);
    const TopoDS_Shape& F2 = DSC.Shape2();
    i = DS.Shape(F2);
  }

  return i;
}

//=======================================================================
//function : GetDSPointFromNewVertex
//purpose  : 
//=======================================================================

Standard_Integer TopOpeBRepBuild_HBuilder::GetDSPointFromNewVertex(const TopoDS_Shape& NewVert)
{
  if(!myMakePointAncestorIsDone) {
    myMakePointAncestorIsDone = Standard_True;
    TopOpeBRepDS_DataStructure& DS = DataStructure()->ChangeDS();
    Standard_Integer i, NbPoint = DS.NbPoints();
    for(i = 1; i <= NbPoint; i++) {
      const TopoDS_Shape& Vertex = NewVertex(i);
      if(!Vertex.IsNull())
	myNewVertexDSPoint.Bind(Vertex, i);
    }
  }
  
  Standard_Integer iPnt = 0;
  if(myNewVertexDSPoint.IsBound(NewVert))
    iPnt = myNewVertexDSPoint.Find(NewVert);
  return iPnt;
}

//=======================================================================
//function : EdgeCurveAncestors
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepBuild_HBuilder::EdgeCurveAncestors(const TopoDS_Shape& E,TopoDS_Shape& F1,TopoDS_Shape& F2,Standard_Integer& IC)
{
  F1.Nullify(); F2.Nullify(); IC = 0;

  const Handle(TopOpeBRepDS_HDataStructure)& HDS = myBuilder.DataStructure();
  const TopOpeBRepDS_DataStructure& DS = HDS->DS();

//  TopTools_ListIteratorOfListOfShape itloe;
  IC = GetDSCurveFromSectEdge(E);
  if(!IC)
    return Standard_False;

  Standard_Integer iF1, iF2;
  iF1 = GetDSFaceFromDSCurve(IC, 1);
  iF2 = GetDSFaceFromDSCurve(IC, 2);
  
  F1 = DS.Shape(iF1);
  F2 = DS.Shape(iF2);
  return Standard_True;
}

//=======================================================================
//function : EdgeSectionAncestors
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepBuild_HBuilder::EdgeSectionAncestors
(const TopoDS_Shape& E, TopTools_ListOfShape& LF1, TopTools_ListOfShape& LF2, TopTools_ListOfShape& LE1, TopTools_ListOfShape& LE2)
{
  if (E.ShapeType() != TopAbs_EDGE) return Standard_False;

  LF1.Clear(); LF2.Clear(); LE1.Clear(); LE2.Clear();
  TColStd_ListOfInteger f1, f2;
  f1.Clear(); f2.Clear();
  Standard_Integer ie1, ie2, curr;
  
  ie1 = GetDSEdgeFromSectEdge(E,1);
  ie2 = GetDSEdgeFromSectEdge(E,2);
  TColStd_ListIteratorOfListOfInteger it;
  
  if(ie1 && ie2) {
    TColStd_MapOfInteger moi;
    
    f1 = GetDSFaceFromDSEdge(ie1,1);
    it.Initialize(f1);
    moi.Clear();
    for(; it.More(); it.Next()) {
      moi.Add(it.Value());
    }
    it.Initialize(GetDSFaceFromDSEdge(ie2,1));
    for(; it.More(); it.Next()) {
      curr = it.Value();
      if(!moi.Contains(curr)) {
	moi.Add(curr);
	f1.Append(curr);
      }
    }
    f2 = GetDSFaceFromDSEdge(ie1,2);
    it.Initialize(f2);
    moi.Clear();
    for(; it.More(); it.Next()) {
      moi.Add(it.Value());
    }
    it.Initialize(GetDSFaceFromDSEdge(ie2,2));
    for(; it.More(); it.Next()) {
      curr = it.Value();
      if(!moi.Contains(curr)) {
	moi.Add(curr);
	f2.Append(curr);
      }
    }
  }
  else {
    if(ie1) {
      f1 = GetDSFaceFromDSEdge(ie1,1);
      f2 = GetDSFaceFromDSEdge(ie1,2);
    }
    else if(ie2) { 
      f1 = GetDSFaceFromDSEdge(ie2,1);
      f2 = GetDSFaceFromDSEdge(ie2,2);
    }  
  }
  
  const TopOpeBRepDS_DataStructure& DS = myBuilder.DataStructure()->DS();  

  if(ie1)
    LE1.Append(DS.Shape(ie1));
  if(ie2)
    LE2.Append(DS.Shape(ie2));

  for(it.Initialize(f1); it.More(); it.Next()) {
    curr = it.Value();
    LF1.Append(DS.Shape(curr));
  }
  for(it.Initialize(f2); it.More(); it.Next()) {
    curr = it.Value();
    LF2.Append(DS.Shape(curr));
  }
  
  Standard_Boolean r = (!LF1.IsEmpty() && !LF2.IsEmpty());
  r = r && (!LE1.IsEmpty() || !LE2.IsEmpty());
  return r;
}

//=======================================================================
//function : IsKPart
//purpose  : 
//=======================================================================

Standard_Integer TopOpeBRepBuild_HBuilder::IsKPart() 
{
  Standard_Integer kp = myBuilder.IsKPart();
  return kp;
}

//=======================================================================
//function : MergeKPart
//purpose  : 
//=======================================================================

void TopOpeBRepBuild_HBuilder::MergeKPart(const TopAbs_State TB1,const TopAbs_State TB2)
{
  Standard_Integer kp = IsKPart();
  if ( kp ) myBuilder.MergeKPart(TB1,TB2);
}

//=======================================================================
//function : ChangeBuilder
//purpose  : 
//=======================================================================

TopOpeBRepBuild_Builder& TopOpeBRepBuild_HBuilder::ChangeBuilder()
{
  return myBuilder;
}