summaryrefslogtreecommitdiff
path: root/src/BOP/BOP_ShellSolid_1.cxx
blob: 2e1c89073a87955fe5a414aae04dc5a670379674 (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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
// File:	BOP_ShellSolid_1.cxx
// Created:	Fri Nov  2 12:36:51 2001
// Author:	Peter KURNEV
//		<pkv@irinox>


#include <BOP_ShellSolid.ixx>

#include <TColStd_ListOfInteger.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>

#include <TopoDS_Face.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Shape.hxx>

#include <TopAbs_Orientation.hxx>

#include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_IndexedMapOfOrientedShape.hxx>

#include <TopExp_Explorer.hxx>

#include <BRep_Tool.hxx>

#include <BooleanOperations_ShapesDataStructure.hxx>
#include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>

#include <IntTools_Context.hxx>

#include <BOPTools_InterferencePool.hxx>
#include <BOPTools_CArray1OfSSInterference.hxx>
#include <BOPTools_SSInterference.hxx>

#include <BOPTools_SequenceOfCurves.hxx>
#include <BOPTools_Curve.hxx>
#include <BOPTools_ListOfPaveBlock.hxx>
#include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
#include <BOPTools_PaveBlock.hxx>
#include <BOPTools_PaveFiller.hxx>
#include <BOPTools_CommonBlockPool.hxx>

#include <BOPTools_ListOfCommonBlock.hxx>
#include <BOPTools_ListIteratorOfListOfCommonBlock.hxx>
#include <BOPTools_CommonBlock.hxx>
#include <BOPTools_Tools3D.hxx>
#include <BOPTools_InterferencePool.hxx>
#include <BOPTools_CArray1OfSSInterference.hxx>

#include <BOP_SDFWESFiller.hxx>

#include <GeomAPI_ProjectPointOnSurf.hxx>
#include <TopExp.hxx>

static 
  Standard_Boolean CheckSplitToAvoid(const TopoDS_Edge&          theSplit,
				     const BOPTools_CommonBlock& theCB, 
				     const Standard_Integer      theEdgeIndex,
				     const Standard_Integer      theFaceIndex,
				     const BOPTools_PDSFiller&   theDSFiller, 
				     const BOP_Operation&        theOperation,
				     IntTools_Context&           theContext);

//=======================================================================
// 
// the WES components for a shell
//
//=======================================================================
// function: AddSectionPartsSh
// purpose: 
//=======================================================================
  void BOP_ShellSolid::AddSectionPartsSh (const Standard_Integer nF1, 
					  const Standard_Integer iFF,
					  BOP_WireEdgeSet& aWES)
{
  const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
  BOPTools_InterferencePool* pIntrPool=(BOPTools_InterferencePool*)&myDSFiller->InterfPool();
  BOPTools_CArray1OfSSInterference& aFFs=pIntrPool->SSInterferences();
  //
  Standard_Integer i, aNbCurves, nE;
  //
  BOPTools_SSInterference& aFF=aFFs(iFF);
  //
  BOPTools_SequenceOfCurves& aSC=aFF.Curves();
  aNbCurves=aSC.Length();
  for (i=1; i<=aNbCurves; i++) {
    const BOPTools_Curve& aBC=aSC(i);
    const BOPTools_ListOfPaveBlock& aLPB=aBC.NewPaveBlocks();
    BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
    for (; anIt.More(); anIt.Next()) {
      const BOPTools_PaveBlock& aPB=anIt.Value();
      nE=aPB.Edge();
      const TopoDS_Edge& aE=TopoDS::Edge(aDS.Shape(nE));
      
      TopoDS_Edge aES=aE;
      
      if (myOperation==BOP_FUSE) {
	aWES.AddStartElement (aES);
	aES.Reverse();
	aWES.AddStartElement (aES);
      }
	
    }
  }
}
//=======================================================================
// function: AddSplitPartsONSh
// purpose: 
//=======================================================================
  void BOP_ShellSolid::AddSplitPartsONSh(const Standard_Integer nF1,
					 BOP_WireEdgeSet& aWES)
{
  const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
  const BOPTools_PaveFiller& aPaveFiller=myDSFiller->PaveFiller();
  
  BOPTools_PaveFiller* pPaveFiller=(BOPTools_PaveFiller*)&aPaveFiller;
  BOPTools_CommonBlockPool& aCBPool=pPaveFiller->ChangeCommonBlockPool();
  //
  IntTools_Context& aContext=pPaveFiller->ChangeContext();
  //
  Standard_Integer nEF1, nF2, nSpF1, nSpF2, nEF2, nSpTaken, iRankF1;
  Standard_Boolean bToReverse;
  TopAbs_Orientation anOrEF1, anOrEF2;
  TopExp_Explorer anExp;
  TopTools_IndexedMapOfShape aM;
  TopoDS_Edge aSSF1, aSSF2;
  //
  iRankF1=aDS.Rank(nF1);
  //
  anExp.Init(myFace, TopAbs_EDGE);
  for (; anExp.More(); anExp.Next()) {
    const TopoDS_Edge& anEF1=TopoDS::Edge(anExp.Current());
    anOrEF1=anEF1.Orientation();
    nEF1=aDS.ShapeIndex(anEF1, iRankF1);
    
    BOPTools_ListOfCommonBlock& aLCB=aCBPool(aDS.RefEdge(nEF1));
    
    BOPTools_ListIteratorOfListOfCommonBlock anItCB(aLCB);
    for (; anItCB.More(); anItCB.Next()) {
      BOPTools_CommonBlock& aCB=anItCB.Value();

      BOPTools_PaveBlock& aPBEF1=aCB.PaveBlock1(nEF1);
      BOPTools_PaveBlock& aPBEF2=aCB.PaveBlock2(nEF1);
      nF2=aCB.Face();
      if (nF2) { 
	// Splits that are ON (IN 2D) for other Face (aF2)
	nSpF1=aPBEF1.Edge();
	const TopoDS_Shape& aSplit=aDS.Shape(nSpF1);
	aSSF1=TopoDS::Edge(aSplit);
	//
	//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
	// Internal edges treatment
	{
	  if (anOrEF1==TopAbs_INTERNAL) {
	    if (myOperation==BOP_FUSE) {
	      aSSF1.Orientation(TopAbs_FORWARD);
	      aWES.AddStartElement (aSSF1);
	      aSSF1.Reverse();
	      aWES.AddStartElement (aSSF1);
	    }
	    else if (myOperation==BOP_CUT) {
	      if (iRankF1==1) {
		aWES.AddStartElement (aSSF1);
	      }
	    }
	    else if (myOperation==BOP_CUT21) {
	      if (iRankF1==2) {
		aWES.AddStartElement (aSSF1);
	      }
	    }
	    continue;
	  }
	}
	//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
	//
	aSSF1.Orientation(anOrEF1);
	aWES.AddStartElement (aSSF1);
      }

      else {
	// Splits that are ON other Edge from other Face
	nSpF1=aPBEF1.Edge();
	nSpF2=aPBEF2.Edge();
	nEF2=aPBEF2.OriginalEdge();
	
	const TopoDS_Edge& anEF2=TopoDS::Edge(aDS.Shape(nEF2));
	anOrEF2=anEF2.Orientation();

	const TopoDS_Shape& aSpF1=aDS.Shape(nSpF1);
	const TopoDS_Shape& aSpF2=aDS.Shape(nSpF2);
	//
	// Pave Block from which new edge will be taken
	const BOPTools_PaveBlock& aPB=aCB.PaveBlock1();
	nSpTaken=aPB.Edge();
	//
	//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
	// Internal edges treatment
	{
	  Standard_Boolean bInternal1, bInternal2;
	  bInternal1=(anOrEF1==TopAbs_INTERNAL);
	  bInternal2=(anOrEF2==TopAbs_INTERNAL);
	  
	  if (bInternal1) {
	    aSSF1=TopoDS::Edge(aDS.Shape(nSpTaken));

	    if (myOperation==BOP_FUSE) {
	      aSSF1.Orientation(TopAbs_FORWARD);
	      aWES.AddStartElement (aSSF1);
	      aSSF1.Reverse();
	      aWES.AddStartElement (aSSF1);
	      continue;
	    }

	    if (myOperation==BOP_CUT && iRankF1==1) {
	      aSSF1.Orientation(TopAbs_INTERNAL);
	      aWES.AddStartElement (aSSF1);
	      continue;
	    }

	    if (myOperation==BOP_CUT21 && iRankF1==2) {
	      aSSF1.Orientation(TopAbs_INTERNAL);
	      aWES.AddStartElement (aSSF1);
	      continue;
	    }
	  }
	  
	  else if (!bInternal1 && bInternal2) {
	    if (nSpTaken!=nSpF1) {
	      
	      if ((myOperation==BOP_FUSE)||
		  (myOperation==BOP_CUT && iRankF1==1) ||
		  (myOperation==BOP_CUT21 && iRankF1==2)) { 
	      
		aSSF1=TopoDS::Edge(aSpF1);
		aSSF1.Orientation(anOrEF1);
		
		aSSF2=TopoDS::Edge(aSpF2);
	      
		aSSF2.Orientation(TopAbs_FORWARD);
		bToReverse=BOPTools_Tools3D::IsSplitToReverse1 (aSSF1, aSSF2, aContext);
		if (bToReverse) {
		  aSSF2.Reverse();
		}
	      
		aWES.AddStartElement (aSSF2);
		continue;
	      }
	    }
	  }
	}
	//
	aSSF1=TopoDS::Edge(aSpF1);
	aSSF1.Orientation(anOrEF1);
	
	if (nSpTaken==nSpF1) {
	  // Common Edge is from nEF1
	  if(CheckSplitToAvoid(aSSF1, aCB, nEF1, nF1, myDSFiller, myOperation, aContext)){
	    continue;
	  }
	  aWES.AddStartElement (aSSF1);
	}
	
	else {
	  // Common Edge is from nEF2 nSpTaken!=nSpF2
	  aSSF2=TopoDS::Edge(aSpF2);
	  
	  bToReverse=BOPTools_Tools3D::IsSplitToReverse1 (aSSF1, aSSF2, aContext);
	  if (bToReverse) {
	    aSSF2.Reverse();
	  }
	  //
	  if (BRep_Tool::IsClosed(aSSF1, myFace)) {
	    if (aM.Contains(aSSF2)){
	      continue;
	    }
	    aM.Add(aSSF2);
	    //
	    if (!BRep_Tool::IsClosed(aSSF2, myFace)) {
	      BOPTools_Tools3D::DoSplitSEAMOnFace (aSSF2, myFace);
	    }

	    aWES.AddStartElement (aSSF2);
	    aSSF2.Reverse();
	    aWES.AddStartElement (aSSF2);
	    continue;  
	  }
	  //
	  if(CheckSplitToAvoid(aSSF2, aCB, nEF1, nF1, myDSFiller, myOperation, aContext)) {
	    continue;
	  }
	  aWES.AddStartElement (aSSF2);
	}
      }
    }
  }
}
//=======================================================================
// function: AddPartsEFSh
// purpose: 
//=======================================================================
  void BOP_ShellSolid::AddPartsEFSh (const Standard_Integer nF1, 
				     const Standard_Integer iFF,
				     TopTools_IndexedMapOfShape& anEMap,
				     BOP_WireEdgeSet& aWES)
{
  const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
  BOPTools_InterferencePool* pIntrPool=(BOPTools_InterferencePool*)&myDSFiller->InterfPool();
  BOPTools_CArray1OfSSInterference& aFFs=pIntrPool->SSInterferences();
  
  const BOPTools_PaveFiller& aPF=myDSFiller->PaveFiller();
  BOPTools_PaveFiller* pPaveFiller=(BOPTools_PaveFiller*)&aPF;
  BOPTools_CommonBlockPool& aCBPool=pPaveFiller->ChangeCommonBlockPool();
  //
  Standard_Integer iRankF2, nF2, nSpEF2, nEF2,  nFace;
  TopExp_Explorer anExp2;
  TopAbs_Orientation anOrEF2;
  //
  BOPTools_SSInterference& aFF=aFFs(iFF);
  nF2=aFF.OppositeIndex(nF1);
  //
  const TopoDS_Face& aF2=TopoDS::Face(aDS.Shape(nF2));
  //
  iRankF2=aDS.Rank(nF2);
  //
  // EF2\F1 Processing
  anExp2.Init (aF2, TopAbs_EDGE);
  for (; anExp2.More(); anExp2.Next()) {
    const TopoDS_Edge& aEF2= TopoDS::Edge(anExp2.Current());
    anOrEF2=aEF2.Orientation();

    nEF2=aDS.ShapeIndex (aEF2, iRankF2);

    BOPTools_ListOfCommonBlock& aLCB=aCBPool(aDS.RefEdge(nEF2));
    
    BOPTools_ListIteratorOfListOfCommonBlock anItCB(aLCB);
    for (; anItCB.More(); anItCB.Next()) {
      BOPTools_CommonBlock& aCB=anItCB.Value();
      nFace=aCB.Face();
      if (nFace==nF1) {
	BOPTools_PaveBlock& aPB=aCB.PaveBlock1(nEF2);

	nSpEF2=aPB.Edge();
	const TopoDS_Shape& aSpEF2=aDS.Shape(nSpEF2);
	
	if (anEMap.Contains(aSpEF2)) {
	  continue;// next CB
	}
	anEMap.Add(aSpEF2);
	
	TopoDS_Edge aSS=TopoDS::Edge(aSpEF2);
	//
	//
	//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
	// Internal edges treatment
	{
	  if (anOrEF2==TopAbs_INTERNAL) {
	    aSS.Orientation(TopAbs_FORWARD);
	  }
	}
	//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
	//
	if (myOperation== BOP_FUSE) {
	  aWES.AddStartElement (aSS);
	  aSS.Reverse();
	  aWES.AddStartElement (aSS);
	}
      }
    } // next CB on nEF2
  }
}
//xf
//=======================================================================
// function: AddINON2DPartsSh
// purpose: 
//=======================================================================
  void BOP_ShellSolid::AddINON2DPartsSh(const Standard_Integer nF1,
					const Standard_Integer iFF,
					BOP_WireEdgeSet& aWES)
{
  TopTools_IndexedMapOfShape anEMap;
  AddINON2DPartsSh(nF1, iFF, aWES, anEMap);
}
//xt
//=======================================================================
// function: AddINON2DPartsSh
// purpose: 
//=======================================================================
  void BOP_ShellSolid::AddINON2DPartsSh(const Standard_Integer nF1,
					const Standard_Integer iFF,
					BOP_WireEdgeSet& aWES,
					TopTools_IndexedMapOfShape& anEMap) //xft
{
  const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
  BOPTools_InterferencePool* pIntrPool=(BOPTools_InterferencePool*)&myDSFiller->InterfPool();
  BOPTools_CArray1OfSSInterference& aFFs=pIntrPool->SSInterferences();
  //
  Standard_Integer iRankF1, nF2, iSenseFlag;

  iRankF1=aDS.Rank(nF1);
  
  BOPTools_SSInterference& aFF=aFFs(iFF);
  nF2=aFF.OppositeIndex(nF1);
  //
  iSenseFlag=aFF.SenseFlag();
  //
  BOP_SDFWESFiller aWESFiller;
  
  aWESFiller.SetDSFiller(*myDSFiller);
  aWESFiller.SetFaces(nF1, nF2);
  aWESFiller.SetStatesMap(aFF.StatesMap());
  //
  aWESFiller.SetSenseFlag(iSenseFlag);
 
  switch (myOperation) {
  
  case BOP_FUSE: 
    if (myRank==2) {
      //shell\solid case when the solid is the first arg.
      iRankF1=1;
    }
    if (iRankF1==1) {
      aWESFiller.SetOperation(BOP_CUT);	
      aWESFiller.Do(aWES);
      aWESFiller.SetOperation(BOP_COMMON);	
      aWESFiller.Do(aWES);
    }
    else {
      aWESFiller.SetOperation(BOP_CUT);	
      aWESFiller.Do(aWES);
    }
    break;
    
  case BOP_COMMON:
    if (myRank==2) {
      //shell\solid case when the solid is the first arg.
      iRankF1=1;
    }
    if (iRankF1==1) {
      aWESFiller.SetOperation(BOP_COMMON);	
      aWESFiller.Do(aWES);
    }
    break;
    
  case BOP_CUT: 
    if (iRankF1==1) {
      aWESFiller.SetOperation(BOP_CUT);	
      aWESFiller.Do(aWES);
    }
    break;
    
  case BOP_CUT21: 
    if (iRankF1==2) {
      aWESFiller.SetOperation(BOP_CUT);	
      aWESFiller.Do(aWES);
    }
    break;
    
  default:
    break;
  }
  //
  //xf
  // Collect all split edges of nF1 that are CB with 
  // splis of all SD faces to nFx,
  // but not included in aWES (RejectedOnParts).
  // This is necessary to prevent inclusion these splits in 
  // AddPartsEENonSDSh(...) 
  // see BOP_SDFWESFiller,  BOP_ShellSolid::DoNewFaces()
  //  for more details;
  TopTools_ListIteratorOfListOfShape aIt;
  //
  const TopTools_ListOfShape& aLRE=aWESFiller.RejectedOnParts();
  aIt.Initialize(aLRE);
  for(; aIt.More(); aIt.Next()) {
    const TopoDS_Shape& aE=aIt.Value();
    anEMap.Add(aE);
  }
  //xt
}
//=======================================================================
// function: AddPartsEFNonSDSh
// purpose: 
//=======================================================================
  void BOP_ShellSolid::AddPartsEFNonSDSh (const Standard_Integer nF1, 
					  const Standard_Integer iFF,
					  TopTools_IndexedMapOfShape& anEMap,
					  BOP_WireEdgeSet& aWES)
{
  const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
  BOPTools_InterferencePool* pIntrPool=(BOPTools_InterferencePool*)&myDSFiller->InterfPool();
  BOPTools_CArray1OfSSInterference& aFFs=pIntrPool->SSInterferences();
  
  const BOPTools_PaveFiller& aPF=myDSFiller->PaveFiller();
  BOPTools_PaveFiller* pPaveFiller=(BOPTools_PaveFiller*)&aPF;
  BOPTools_CommonBlockPool& aCBPool=pPaveFiller->ChangeCommonBlockPool();
  //
  Standard_Integer nF2, nSpEF2, nEF2,  nFace, iRankF2;
  TopExp_Explorer anExp2;
  TopAbs_Orientation anOrEF2 = TopAbs_FORWARD;
  //
  BOPTools_SSInterference& aFF=aFFs(iFF);
  nF2=aFF.OppositeIndex(nF1);
  //
  const TopoDS_Face& aF2=TopoDS::Face(aDS.Shape(nF2));

  iRankF2=aDS.Rank(nF2);
  //
  TopTools_IndexedMapOfOrientedShape aWESMap;
  {
    const TopTools_ListOfShape& aWESList=aWES.StartElements();
    TopTools_ListIteratorOfListOfShape anIt(aWESList);
    for (; anIt.More(); anIt.Next()) {
      const TopoDS_Shape& aS=anIt.Value();
      aWESMap.Add(aS);
    }
  }
  //
  // EF2\F1 Processing
  anExp2.Init (aF2, TopAbs_EDGE);
  for (; anExp2.More(); anExp2.Next()) {
    const TopoDS_Edge& aEF2= TopoDS::Edge(anExp2.Current());

    nEF2=aDS.ShapeIndex(aEF2, iRankF2);

    BOPTools_ListOfCommonBlock& aLCB=aCBPool(aDS.RefEdge(nEF2));
    
    BOPTools_ListIteratorOfListOfCommonBlock anItCB(aLCB);
    for (; anItCB.More(); anItCB.Next()) {
      BOPTools_CommonBlock& aCB=anItCB.Value();
      nFace=aCB.Face();
      
      if (nFace==nF1) {
	BOPTools_PaveBlock& aPB=aCB.PaveBlock1(nEF2);

	nSpEF2=aPB.Edge();
	const TopoDS_Shape& aSpEF2=aDS.Shape(nSpEF2);
	//
	if (anEMap.Contains(aSpEF2)) {
	  continue;// next CB
	}
	anEMap.Add(aSpEF2);
	//
	if (aWESMap.Contains(aSpEF2)) {
	  continue;// next CB
	}
	aWESMap.Add(aSpEF2);
	//
	TopoDS_Edge aSS=TopoDS::Edge(aSpEF2);
	//
	//
	//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
	// Internal edges treatment
	{
	  if (anOrEF2==TopAbs_INTERNAL) {
	    aSS.Orientation(TopAbs_FORWARD);
	  }
	}
	//iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
	//
	if (myOperation==BOP_FUSE) {
	  aWES.AddStartElement(aSS);
	  aSS.Reverse();
	  aWES.AddStartElement(aSS);
	}
	//
      } //if (nFace==nF1) {
    } // next CB on nEF2
  }
}
//=======================================================================
// function: AddPartsEENonSDSh
// purpose: 
//=======================================================================
  void BOP_ShellSolid::AddPartsEENonSDSh (const Standard_Integer nF1, 
					  const Standard_Integer iFF,
					  TopTools_IndexedMapOfShape& anEMap,
					  BOP_WireEdgeSet& aWES)
{
  const BooleanOperations_ShapesDataStructure& aDS=myDSFiller->DS();
  BOPTools_InterferencePool* pIntrPool=(BOPTools_InterferencePool*)&myDSFiller->InterfPool();
  BOPTools_CArray1OfSSInterference& aFFs=pIntrPool->SSInterferences();
  
  const BOPTools_PaveFiller& aPF=myDSFiller->PaveFiller();
  BOPTools_PaveFiller* pPaveFiller=(BOPTools_PaveFiller*)&aPF;
  BOPTools_CommonBlockPool& aCBPool=pPaveFiller->ChangeCommonBlockPool();
  //
  IntTools_Context& aContext=pPaveFiller->ChangeContext();
  //
  Standard_Integer nEF1, nF2, nSpF1, nSpF2, nEF2, nSpTaken, nF2x, iRankF1;
  Standard_Boolean bToReverse;
  TopAbs_Orientation anOrEF1, anOrEF2;
  TopExp_Explorer anExp;
  TopTools_IndexedMapOfShape aM;
  TColStd_ListOfInteger aSplitsOnF1;
  TColStd_ListIteratorOfListOfInteger anItSp;
  TColStd_IndexedMapOfInteger aMSplitsOnF1;
  TopoDS_Edge aSSF1, aSSF2;
  //
  // nF1
  iRankF1=aDS.Rank(nF1);
  //
  // nF2
  BOPTools_SSInterference& aFF=aFFs(iFF);
  nF2=aFF.OppositeIndex(nF1);
  //
  pPaveFiller->SplitsOnFace(0, nF1, nF2, aSplitsOnF1);
  anItSp.Initialize(aSplitsOnF1);
  for (; anItSp.More(); anItSp.Next()) {
    nSpF1=anItSp.Value();
    aMSplitsOnF1.Add(nSpF1);
  }
  //
  TopTools_IndexedMapOfOrientedShape aWESMap;
  {
    const TopTools_ListOfShape& aWESList=aWES.StartElements();
    TopTools_ListIteratorOfListOfShape anIt(aWESList);
    for (; anIt.More(); anIt.Next()) {
      const TopoDS_Shape& aS=anIt.Value();
      aWESMap.Add(aS);
    }
  }
  //
  anExp.Init(myFace, TopAbs_EDGE);
  for (; anExp.More(); anExp.Next()) {
    const TopoDS_Edge& anEF1=TopoDS::Edge(anExp.Current());
    anOrEF1=anEF1.Orientation();
    nEF1=aDS.ShapeIndex(anEF1, iRankF1);
    
    BOPTools_ListOfCommonBlock& aLCB=aCBPool(aDS.RefEdge(nEF1));
    
    BOPTools_ListIteratorOfListOfCommonBlock anItCB(aLCB);
    for (; anItCB.More(); anItCB.Next()) {
      BOPTools_CommonBlock& aCB=anItCB.Value();
    
      BOPTools_PaveBlock& aPBEF1=aCB.PaveBlock1(nEF1);
      BOPTools_PaveBlock& aPBEF2=aCB.PaveBlock2(nEF1);
      
      nF2x=aCB.Face();
      if (nF2x) {
	continue;
      }
      // Splits that are ON other Edge from other Face
      nSpF1=aPBEF1.Edge();
      //
      if (!aMSplitsOnF1.Contains(nSpF1)) {
	continue;// next CB
      }
      //
      nSpF2=aPBEF2.Edge();
      nEF2=aPBEF2.OriginalEdge();

      const TopoDS_Edge& anEF2=TopoDS::Edge(aDS.Shape(nEF2));
      anOrEF2=anEF2.Orientation();
      
      const TopoDS_Shape& aSpF1=aDS.Shape(nSpF1);
      const TopoDS_Shape& aSpF2=aDS.Shape(nSpF2);
      
      //
      if (anEMap.Contains(aSpF1)) {
	continue;// next CB
      }
      anEMap.Add(aSpF1);
      //
      if (anEMap.Contains(aSpF2)) {
	continue;// next CB
      }
      anEMap.Add(aSpF2);
      //
      
      // Pave Block from which new edge will be taken
      const BOPTools_PaveBlock& aPB=aCB.PaveBlock1();
      nSpTaken=aPB.Edge();
      //
      //iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
      // Internal edges treatment
      {
	Standard_Boolean bInternal1, bInternal2;
	bInternal1=(anOrEF1==TopAbs_INTERNAL);
	bInternal2=(anOrEF2==TopAbs_INTERNAL);
	
	if (bInternal1) {
	  aSSF1=TopoDS::Edge(aDS.Shape(nSpTaken));
	  
	  if (myOperation==BOP_FUSE) {
	    aSSF1.Orientation(TopAbs_FORWARD);
	    aWES.AddStartElement (aSSF1);
	    aSSF1.Reverse();
	    aWES.AddStartElement (aSSF1);
	    continue;
	  }
	  
	  if (myOperation==BOP_CUT && iRankF1==1) {
	    aSSF1.Orientation(TopAbs_INTERNAL);
	    aWES.AddStartElement (aSSF1);
	    continue;
	  }
	  
	  if (myOperation==BOP_CUT21 && iRankF1==2) {
	    aSSF1.Orientation(TopAbs_INTERNAL);
	    aWES.AddStartElement (aSSF1);
	    continue;
	  }
	}
	  
	else if (!bInternal1 && bInternal2) {
	  if (nSpTaken!=nSpF1) {
	    
	    if ((myOperation==BOP_FUSE)||
		(myOperation==BOP_CUT && iRankF1==1) ||
		(myOperation==BOP_CUT21 && iRankF1==2)) { 
	      
	      aSSF1=TopoDS::Edge(aSpF1);
	      aSSF1.Orientation(anOrEF1);
	      
	      aSSF2=TopoDS::Edge(aSpF2);
	      
	      aSSF2.Orientation(TopAbs_FORWARD);
	      bToReverse=BOPTools_Tools3D::IsSplitToReverse1 (aSSF1, aSSF2, aContext);
	      if (bToReverse) {
		aSSF2.Reverse();
	      }
	      
	      aWES.AddStartElement (aSSF2);
	      continue;
	    }
	  }
	}
      }
      //iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
      //
      aSSF1=TopoDS::Edge(aSpF1);
      aSSF1.Orientation(anOrEF1);
      
      if (nSpTaken==nSpF1) {
	// Common Edge is from nEF1
	aWES.AddStartElement (aSSF1);
      }
      else  {
	// Common Edge is from nEF2 nSpTaken!=nSpF2
	aSSF2=TopoDS::Edge(aSpF2);
	
	bToReverse=BOPTools_Tools3D::IsSplitToReverse1 (aSSF1, aSSF2, aContext);
	if (bToReverse) {
	  aSSF2.Reverse();
	}
	//
	if (BRep_Tool::IsClosed(aSSF1, myFace)) {
	  if (aM.Contains(aSSF2)){
	    continue;
	  }
	  aM.Add(aSSF2);
	  //
	  if (!BRep_Tool::IsClosed(aSSF2, myFace)) {
	    BOPTools_Tools3D::DoSplitSEAMOnFace (aSSF2, myFace);
	  }
	  aWES.AddStartElement (aSSF2);
	  aSSF2.Reverse();
	  aWES.AddStartElement (aSSF2);
	  continue;  
	}
	//
	aWES.AddStartElement (aSSF2);
      }// else /*if (nSpTaken==nSpF2)*/ {
    }// for (; anItCB.More(); anItCB.Next())
  }// for (; anExp.More(); anExp.Next())
}
//=======================================================================
//function : CheckSplitToAvoid
//purpose  : 
//=======================================================================
Standard_Boolean CheckSplitToAvoid(const TopoDS_Edge&          theSplit,
				   const BOPTools_CommonBlock& theCB, 
				   const Standard_Integer      theEdgeIndex,
				   const Standard_Integer      theFaceIndex,
				   const BOPTools_PDSFiller&   theDSFiller, 
				   const BOP_Operation&        theOperation,
				   IntTools_Context&           theContext) {

  Standard_Integer anE = -1;

  if(theCB.PaveBlock1().OriginalEdge() == theEdgeIndex) {
    anE = theCB.PaveBlock2().OriginalEdge();
  }
  else if(theCB.PaveBlock2().OriginalEdge() == theEdgeIndex) {
    anE = theCB.PaveBlock1().OriginalEdge();
  }

  if(anE >= 0) {
    const TopoDS_Shape& anEdge = theDSFiller->DS().Shape(anE);
    TopoDS_Face aFaceCur = TopoDS::Face(theDSFiller->DS().Shape(theFaceIndex));
    aFaceCur.Orientation(TopAbs_FORWARD);

    TopTools_IndexedDataMapOfShapeListOfShape aMapEF;
    Standard_Integer aRank = theDSFiller->DS().Rank(anE);
    TopoDS_Shape aSource = (aRank == 1) ? theDSFiller->Shape1() : theDSFiller->Shape2();
    TopExp::MapShapesAndAncestors(aSource, TopAbs_EDGE, TopAbs_FACE, aMapEF);

    if(aMapEF.Contains(anEdge)) {
      const TopTools_ListOfShape& aLF = aMapEF.FindFromKey(anEdge);

      if(!aLF.IsEmpty()) {
	TopTools_ListIteratorOfListOfShape anIt(aLF);
	Standard_Boolean avoid = Standard_True;

	for(; anIt.More(); anIt.Next()) {
	  const TopoDS_Face& aFace = TopoDS::Face(anIt.Value());
	  Standard_Real f = 0., l = 0.;
	  Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(theSplit, aFaceCur, f, l);

	  if(!aCurve.IsNull()) {
	    Standard_Real amidpar = (f + l) * 0.5;

	    if(theOperation == BOP_COMMON) {
	      gp_Pnt2d aPoint2d;
	      gp_Pnt aPoint3d;
	      Standard_Real aTolerance = BRep_Tool::Tolerance(theSplit); //???
	      BOPTools_Tools3D::PointNearEdge(theSplit, aFaceCur, amidpar, aTolerance, aPoint2d, aPoint3d);
	      GeomAPI_ProjectPointOnSurf& aProjector =  theContext.ProjPS(aFace);
	      aProjector.Perform(aPoint3d);

	      if(aProjector.IsDone()) {
		Standard_Real U = 0., V = 0.;
		Standard_Real adist = aProjector.LowerDistance();

		if(adist < BRep_Tool::Tolerance(aFace)) {
		  aProjector.LowerDistanceParameters(U, V);

		  if(theContext.IsPointInFace(aFace, gp_Pnt2d(U, V))) {
		    avoid = Standard_False;
		    break;
		  }
		  else {
		  }
		}
	      }
	    }
	    else if(theOperation == BOP_CUT) {
	      if(theDSFiller->DS().Rank(theFaceIndex) != 2) {
		avoid = Standard_False;
		continue;
	      }
	      gp_Pnt2d aPoint2d;
	      gp_Pnt aPoint3d;
	      Standard_Real aTolerance = BRep_Tool::Tolerance(theSplit); //???
	      BOPTools_Tools3D::PointNearEdge(theSplit, aFaceCur, amidpar, aTolerance, aPoint2d, aPoint3d);
	      GeomAPI_ProjectPointOnSurf& aProjector =  theContext.ProjPS(aFace);
	      aProjector.Perform(aPoint3d);

	      if(aProjector.IsDone()) {
		Standard_Real U = 0., V = 0.;
		Standard_Real adist = aProjector.LowerDistance();

		if(adist < BRep_Tool::Tolerance(aFace)) {
		  aProjector.LowerDistanceParameters(U, V);

		  if(theContext.IsPointInFace(aFace, gp_Pnt2d(U, V))) {
		    avoid = Standard_False;
		    break;
		  }
		  else {
		  }
		}
	      }
	    }
	    else if(theOperation == BOP_CUT21) {
	      if(theDSFiller->DS().Rank(theFaceIndex) != 1) {
		avoid = Standard_False;
		continue;
	      }
	      gp_Pnt2d aPoint2d;
	      gp_Pnt aPoint3d;
	      Standard_Real aTolerance = BRep_Tool::Tolerance(theSplit); //???
	      BOPTools_Tools3D::PointNearEdge(theSplit, aFaceCur, amidpar, aTolerance, aPoint2d, aPoint3d);
	      GeomAPI_ProjectPointOnSurf& aProjector =  theContext.ProjPS(aFace);
	      aProjector.Perform(aPoint3d);

	      if(aProjector.IsDone()) {
		Standard_Real U = 0., V = 0.;
		Standard_Real adist = aProjector.LowerDistance();

		if(adist < BRep_Tool::Tolerance(aFace)) {
		  aProjector.LowerDistanceParameters(U, V);

		  if(theContext.IsPointInFace(aFace, gp_Pnt2d(U, V))) {
		    avoid = Standard_False;
		    break;
		  }
		  else {
		  }
		}
	      }
	    }
	    // end if(theOperation == BOP_CUT21...
	    else {
	      avoid = Standard_False;
	      break;
	    }
	  }
	}

	if(avoid) {
	  return Standard_True;
	}
      }
      // end if(!aLF.IsEmpty...
    }
  }

  return Standard_False;
}