summaryrefslogtreecommitdiff
path: root/src/TopOpeBRepBuild/TopOpeBRepBuild_GridEE.cxx
blob: a16878c1f93fb1253a256775a8229dca81a22ee5 (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
// file:	TopOpeBRepBuild_GridEE.cxx
// Created:	Thu Mar  7 10:49:33 1996
// Author:	Jean Yves LEBEY
//		<jyl@meteox>

#include <TopOpeBRepBuild_Builder.ixx>
#include <TopOpeBRepBuild_define.hxx>
#include <TopOpeBRepDS_EXPORT.hxx>

#ifdef DRAW
#include <TopOpeBRepDS_DRAW.hxx>
#endif

#include <TopOpeBRepDS_EXPORT.hxx>
#include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
#include <TopOpeBRepTool_EXPORT.hxx>
#include <TopOpeBRepTool_TOOL.hxx>
#include <TopOpeBRepDS_TKI.hxx>
#include <TopOpeBRepDS.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <Geom_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom_Plane.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
#include <ElCLib.hxx>
#include <ElSLib.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Precision.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <TopOpeBRepTool_2d.hxx>
#include <TopOpeBRepDS_Dumper.hxx>
#include <Standard_ProgramError.hxx>

#ifdef DEB
Standard_EXPORT Standard_Boolean TopOpeBRepBuild_GetcontextNOSG();
#endif

#define M_FORWARD(st) (st == TopAbs_FORWARD)
#define M_REVERSED(st) (st == TopAbs_REVERSED)
#define M_INTERNAL(st) (st == TopAbs_INTERNAL)
#define M_EXTERNAL(st) (st == TopAbs_EXTERNAL)

Standard_EXPORT Standard_Boolean TopOpeBRepBuild_FUN_aresamegeom(const TopoDS_Shape& S1,const TopoDS_Shape& S2);


//=======================================================================
//function : GMergeEdges
//purpose  : 
//=======================================================================
void TopOpeBRepBuild_Builder::GMergeEdges(const TopTools_ListOfShape& LE1,const TopTools_ListOfShape& LE2,const TopOpeBRepBuild_GTopo& G1)
{
  if ( LE1.IsEmpty() ) return;
  TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
  
  const TopoDS_Shape& E1 = LE1.First();
#ifdef DEB
  Standard_Integer iE; Standard_Boolean tSPS1 = GtraceSPS(E1,iE);
  if(tSPS1){
    cout<<endl;cout<<"--- GMergeEdges "<<endl;
    GdumpEDG(E1);
    GdumpSAMDOM(LE1, (char *) "1 : ");
    GdumpSAMDOM(LE2, (char *) "2 : ");
  }
#endif
  
  myEdgeReference = TopoDS::Edge(E1);
  TopOpeBRepBuild_PaveSet PVS(E1);
  
  GFillEdgesPVS(LE1,LE2,G1,PVS);
  
  // Create a edge builder EBU
  TopoDS_Shape E1F = LE1.First(); E1F.Orientation(TopAbs_FORWARD);
  TopOpeBRepBuild_PaveClassifier VCL(E1F);
  Standard_Boolean equalpar = PVS.HasEqualParameters();
  if (equalpar) VCL.SetFirstParameter(PVS.EqualParameters());
  TopOpeBRepBuild_EdgeBuilder EDBU(PVS,VCL);
  
  // Build the new edges LEM
  TopTools_ListOfShape LEM;
  GEDBUMakeEdges(E1F,EDBU,LEM);
  
  // connect new edges as edges built TB1 on LE1 edges
  TopTools_ListIteratorOfListOfShape it1;
  for (it1.Initialize(LE1); it1.More(); it1.Next()) {
    const TopoDS_Shape& E11 = it1.Value();
    ChangeMerged(E11,TB1) = LEM;
  }
  
  // connect new edges as edges built TB2 on LE2 edges
  TopTools_ListIteratorOfListOfShape it2;
  for (it2.Initialize(LE2); it2.More(); it2.Next()) {
    const TopoDS_Shape& E2 = it2.Value();
    ChangeMerged(E2,TB2) = LEM;
  }
  
} // GMergeEdges

//=======================================================================
//function : GFillEdgesPVS
//purpose  : 
//=======================================================================
void TopOpeBRepBuild_Builder::GFillEdgesPVS(const TopTools_ListOfShape& LE1,const TopTools_ListOfShape& LE2,const TopOpeBRepBuild_GTopo& G1,TopOpeBRepBuild_PaveSet& PVS)
{
  if ( LE1.IsEmpty() ) return;
  TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
  
  const TopoDS_Shape& E1 = LE1.First();
  myEdgeReference = TopoDS::Edge(E1);
  
  TopTools_ListIteratorOfListOfShape it1;
  for (it1.Initialize(LE1); it1.More(); it1.Next()) {
    const TopoDS_Shape& E11 = it1.Value();
    Standard_Boolean ismerged = IsMerged(E11,TB1);
    
#ifdef DEB
    Standard_Integer i1; Standard_Boolean tSPS1 = GtraceSPS(E11,i1);
    if(tSPS1){
      cout<<endl;cout<<"--- GFillEdgesPVS ";GdumpSHA(E11);
      cout<<" ismerged : "<<ismerged<<" ";TopAbs::Print(TB1,cout);cout<<endl;
    }
#endif
    
    if (!ismerged) GFillEdgePVS(E11,LE2,G1,PVS);
  }
  
  TopOpeBRepBuild_GTopo G2 = G1.CopyPermuted();
  
  TopTools_ListIteratorOfListOfShape it2;
  for (it2.Initialize(LE2); it2.More(); it2.Next() ) {
    const TopoDS_Shape& E2 = it2.Value();
    Standard_Boolean ismerged = IsMerged(E2,TB2);
    
#ifdef DEB
    Standard_Integer i2; Standard_Boolean tSPS2 = GtraceSPS(E2,i2);
    if(tSPS2){
      cout<<endl;
      cout<<"--- GFillEdgesPVS ";GdumpSHA(E2);
      cout<<" ismerged : "<<ismerged<<" ";TopAbs::Print(TB2,cout);cout<<endl;
    }
#endif
    
    if (!ismerged) GFillEdgePVS(E2,LE1,G2,PVS);
  }
  
} // GFillEdgesPVS

//=======================================================================
//function : GFillEdgePVS
//purpose  : 
//=======================================================================
void TopOpeBRepBuild_Builder::GFillEdgePVS(const TopoDS_Shape& E,
                                           const TopTools_ListOfShape& /*LE2*/,
                                           const TopOpeBRepBuild_GTopo& G,
                                           TopOpeBRepBuild_PaveSet& PVS)
{
  TopAbs_ShapeEnum t1,t2;
  G.Type(t1,t2);
  TopAbs_State TB1,TB2;
  G.StatesON(TB1,TB2);
  
  // work on a FORWARD edge EF
  TopoDS_Shape EF = E;
  EF.Orientation(TopAbs_FORWARD);
  // Add the point/vertex topology build/found on edge EF in PVS
  GFillPointTopologyPVS(EF,G,PVS);
  
} // GFillEdgePVS

// --- iterer sur EPit jusqu'a la prochaine interference dont la
// --- transition est definie sur un shape de type SHA Before et After
static Standard_Boolean FUN_MoreSHAINT(TopOpeBRepDS_PointIterator& EPit,
                                       const TopAbs_ShapeEnum SHA)
{
  Standard_Boolean more = Standard_False;
  while (EPit.More()) {
    const Handle(TopOpeBRepDS_Interference)& I = EPit.Value();
    const TopOpeBRepDS_Transition& T = I->Transition();
    TopOpeBRepDS_Kind GT,ST; Standard_Integer G,S; FDS_data(I,GT,G,ST,S);
    TopAbs_ShapeEnum SB,SA; Standard_Integer IB,IA; FDS_Tdata(I,SB,IB,SA,IA);
    
    TopAbs_ShapeEnum b = T.ShapeBefore(), a = T.ShapeAfter();
    Standard_Boolean rejet = ( (b != SHA) || (a != SHA) );
    if ( rejet ) EPit.Next();
    else {
      more = Standard_True;
      break;
    }
  }
  return more;
}

// Unused :
/*#ifdef DEB
static Standard_Integer FUN_getTRASHA(const Standard_Integer geti,
			  const TopOpeBRepDS_ListOfInterference& lFOR, const Standard_Integer FOR,
			  const TopOpeBRepDS_ListOfInterference& lREV, const Standard_Integer REV,
			  const TopOpeBRepDS_ListOfInterference& lINT, const Standard_Integer INT)
{
  Standard_Integer trasha = 0;
  if (geti == 1) { // get i before
    if (REV) trasha = lREV.First()->Transition().Before();
    if (INT) trasha = lINT.First()->Transition().Before();    
  }
  if (geti == 2) { // get i after
    if (FOR) trasha = lFOR.Last()->Transition().After();
    if (INT) trasha = lINT.Last()->Transition().After();
  }
  return trasha;
}
#endif*/

#ifdef DEB
void debfillp(const Standard_Integer i) {cout <<"+ + debfillp "<<i<<endl;}
void debfillpon(const Standard_Integer i) {cout <<"+ + debfillpon "<<i<<endl;}
void debfillpin(const Standard_Integer i) {cout <<"+ + debfillpin "<<i<<endl;}
void debfillpou(const Standard_Integer i) {cout <<"+ + debfillpou "<<i<<endl;}
void debfillp2(const Standard_Integer i) {cout <<"+ + debfillp2 "<<i<<endl;}
#endif

//Standard_IMPORT extern Standard_Boolean GLOBAL_faces2d;
extern Standard_Boolean GLOBAL_faces2d;

Standard_EXPORT Standard_Boolean FDS_SIisGIofIofSBAofTofI(const TopOpeBRepDS_DataStructure& BDS,const Standard_Integer SI,const Handle(TopOpeBRepDS_Interference)& I);
//Standard_IMPORT extern Standard_Boolean GLOBAL_IEtoMERGE; // xpu240498
Standard_IMPORT Standard_Boolean GLOBAL_IEtoMERGE; // xpu240498
//Standard_IMPORT extern Standard_Integer GLOBAL_issp;
extern Standard_Integer GLOBAL_issp;
//Standard_IMPORT extern Standard_Integer GLOBAL_hassd;
Standard_IMPORT Standard_Integer GLOBAL_hassd;

static Standard_Boolean FUN_isonbound(const Handle(TopOpeBRepDS_HDataStructure)& HDS,
                                      const Handle(TopOpeBRepDS_Interference)& I)
{
  Standard_Integer G = I->Geometry();
  TopOpeBRepDS_Kind KG =  I->GeometryType();
  Standard_Boolean Gb1 = (KG == TopOpeBRepDS_VERTEX); 
  if (Gb1) {
    Handle(TopOpeBRepDS_EdgeVertexInterference) EVI= Handle(TopOpeBRepDS_EdgeVertexInterference)::DownCast(I);
    Standard_Boolean vhassd = HDS->HasSameDomain(HDS->DS().Shape(G));
    Gb1 = (EVI.IsNull()) ? Standard_False : EVI->GBound();
    Gb1 = Gb1 && !vhassd;    
  }
  return Gb1;
}

#define TheIN (1)
#define TheON (2)
#define TheOUT (3)
#define HASSD2d (2)
#define HASSD3d (3)
#define FIRST (1)
#define LAST  (2)

//=======================================================================
//function : GFillPointTopologyPVS
//purpose  : 
//=======================================================================
void TopOpeBRepBuild_Builder::GFillPointTopologyPVS(const TopoDS_Shape& E,
                                                    const TopOpeBRepBuild_GTopo& G,
                                                    TopOpeBRepBuild_PaveSet& PVS)
{
#ifdef DEB
//  TopAbs_State TB1,TB2; 
//  G.StatesON(TB1,TB2);
//  TopOpeBRepDS_Config GConf1 = G.Config1();
//  TopOpeBRepDS_Config GConf2 = G.Config2();
#endif
  TopAbs_ShapeEnum t1,t2,ShapeInterf; 
  G.Type(t1,t2); 
  ShapeInterf = t1;
  const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
  const Standard_Integer iEDS = BDS.Shape(E);
#ifdef DEB
//  Standard_Integer rkE = BDS.AncestorRank(E); 
#endif
  Standard_Boolean isSE = BDS.IsSectionEdge(TopoDS::Edge(E));
  Standard_Boolean dgE = BRep_Tool::Degenerated(TopoDS::Edge(E));
  Standard_Boolean isEd;

  isEd = BRep_Tool::Degenerated(TopoDS::Edge(E));
#ifdef DEB
//  Standard_Boolean hsd = myDataStructure->HasSameDomain(E); //xpu170498
#endif
  Standard_Boolean isfafa = BDS.Isfafa(); //xpu120598

#ifdef DEB
  Standard_Boolean tSPSE=GtraceSPS(iEDS);
  TCollection_AsciiString striE=TopOpeBRepDS::SPrint(TopAbs_EDGE,iEDS);
  const TopoDS_Shape& EPVS=PVS.Edge();Standard_Integer iEPVS;Standard_Boolean tSPSEPVS=GtraceSPS(EPVS,iEPVS);
  Standard_Boolean tSPS = tSPSE || tSPSEPVS;
  if(tSPS){
    cout<<endl;
    cout<<"--- GFillPointTopologyPVS : ShapeInterf ";TopAbs::Print(ShapeInterf,cout);
    cout<<",efil ";GdumpSHA(E);cout<<",eref ";GdumpSHA(myEdgeReference);
    cout<<",ffil ";GdumpSHA(myFaceToFill);cout<<",fref ";GdumpSHA(myFaceReference);
    cout<<endl;
    debfillp(iEDS);
  }
#endif

  Standard_Boolean isspin=(GLOBAL_issp==TheIN), isspou=(GLOBAL_issp==TheOUT), isspon=(GLOBAL_issp==TheON);
  if (isSE && (GLOBAL_issp == 0)) return; // splits done in process ProcessSectionEdges

#ifdef DEB
//  Standard_Integer iefil = BDS.Shape(E);
//  Standard_Integer iffil = BDS.Shape(myFaceToFill);
//  Standard_Integer ieref = BDS.Shape(myEdgeReference);
//  Standard_Integer ifref = BDS.Shape(myFaceReference);
  if(tSPS) {
    if (isspon) debfillpon(iEDS);
    if (isspin) debfillpin(iEDS);
    if (isspou) debfillpou(iEDS);
  }
#endif

  // 0.
  //---
  const TopOpeBRepDS_ListOfInterference& lIE = BDS.ShapeInterferences(E);
  Standard_Boolean scanall = (isspin || isspou || isspon); // xpu161198: BUC60382 //xpu011098: CTS21180(e8on); cto900I7(e12on)

  // loiSHAINT = interferences avec les 2 proprietes 
  // - fournies par un PointIterator
  // - dont la transition est definie / shape = ShapeInterf
  TopOpeBRepDS_ListOfInterference loiSHAINT;
  if (scanall) FDS_assign(lIE,loiSHAINT);
  else { 
    TopOpeBRepDS_PointIterator EPit(lIE);
    EPit.Init(BDS.ShapeInterferences(E));
    Standard_Boolean addi = FUN_MoreSHAINT(EPit,ShapeInterf);
    while (addi) {
      const Handle(TopOpeBRepDS_Interference)& II = EPit.Value();
      loiSHAINT.Append(II);
      EPit.Next();
      addi = FUN_MoreSHAINT(EPit,ShapeInterf);
    }
  }

  TopOpeBRepDS_TKI tki;
  tki.FillOnGeometry(loiSHAINT);  // groupage par geometrie d'interference
  
  // - kp1 -
  // BUC60093 :  only 2 G : 1 point && 1 vertex  
  // deleting interfs on G = vertex sdm && closingE  
  TopoDS_Vertex vclo; Standard_Boolean closedE = TopOpeBRepTool_TOOL::ClosedE(TopoDS::Edge(E),vclo);
  Standard_Integer kp1 = 0;
  if (closedE) {
    tki.Init();
    Standard_Integer nG = 0;
    while (tki.More()) {
      nG++;
      TopOpeBRepDS_Kind Kcur;Standard_Integer Gcur;
      tki.Value(Kcur,Gcur);
      if (Kcur == TopOpeBRepDS_POINT) {tki.Next();continue;}
      const TopoDS_Shape& v = BDS.Shape(Gcur);
      TopoDS_Shape oov;
      FUN_ds_getoov(v,myDataStructure,oov);
      Standard_Boolean samev = v.IsSame(vclo), sameoov = oov.IsSame(vclo);
      if (samev || sameoov) {kp1 = Gcur;}
      tki.Next();
    }
    if (nG == 1) kp1 = 0; // we have only one interf on vGclo -> keep the interf
  } //kp1

  // - kp6 - nyiReducing
  // xpu250998    : cto900M5 (e5,p1) 
  // prequesitory : if we have I3d on Gb0 FORWARD or REVERSED, we do NOT need
  //                interference on Gb1 to determinate split IN/OUT of edge.
  Standard_Boolean kp6 = (!isSE); 
  if (kp6) {
    kp6 = Standard_False;
    TopOpeBRepDS_ListIteratorOfListOfInterference it(loiSHAINT);
    for (; it.More(); it.Next()){
      const Handle(TopOpeBRepDS_Interference)& I = it.Value();
      TopOpeBRepDS_Kind ST = I->SupportType();
      if (ST != TopOpeBRepDS_FACE) continue;
      TopAbs_Orientation O = I->Transition().Orientation(TopAbs_IN);
      Standard_Boolean FORREV = (O == TopAbs_FORWARD) || (O == TopAbs_REVERSED);
      if (!FORREV) continue;
      Standard_Boolean Gb1 = ::FUN_isonbound(myDataStructure,I);
      if (!Gb1) {kp6 = Standard_True; break;}
    } // it(l3dFOR+l3dREV)	
  }
    
  // 1.
  //---
  tki.Init();
  while (tki.More()) {
    
    // lieu courant : Kcur,Gcur; Interferences : LICur
    TopOpeBRepDS_Kind Kcur;
    Standard_Integer Gcur;
    const TopOpeBRepDS_ListOfInterference& LICur = tki.Value(Kcur,Gcur);
    Standard_Boolean point  = (Kcur == TopOpeBRepDS_POINT); //xpu170498
    Standard_Boolean vertex = (Kcur == TopOpeBRepDS_VERTEX);//xpu170498
#ifdef DEB
//    Standard_Integer nLICur = LICur.Extent();
    Standard_Boolean trcI = Standard_False;
    if(trcI) {TopOpeBRepDS_Dumper DSD(myDataStructure); TCollection_AsciiString aa("lI");
	      aa += TCollection_AsciiString(Gcur); DSD.DumpLOI(LICur,cout,aa);}
#endif

    TopoDS_Shape vGsd; 
    if (vertex) FUN_ds_getoov(BDS.Shape(Gcur), myDataStructure, vGsd); //xpu221098

    // recall : I3d=(I3dF,I3dFE) : I3dF=(T(F),G,F), I3dFE=(T(F),G,E)
    //          I2d=I2dFE
    //          I1d=(T(E),V,E)
    
    if ((Kcur == TopOpeBRepDS_VERTEX) && (kp1 == Gcur)) {tki.Next();continue;}
    const Handle(TopOpeBRepDS_Interference)& I = LICur.First();
    Standard_Real parSE = FDS_Parameter(I);
    TopOpeBRepDS_ListOfInterference LICurcopy; 
    TopOpeBRepDS_ListOfInterference l3dFcur; FDS_assign(LICur,LICurcopy); Standard_Integer n3d=FUN_selectSKinterference(LICurcopy,TopOpeBRepDS_FACE,l3dFcur);
    TopOpeBRepDS_ListOfInterference l2dFEcur; FDS_assign(LICur,LICurcopy); Standard_Integer n2d=FUN_ds_hasI2d(iEDS,LICurcopy,l2dFEcur);
    TopOpeBRepDS_ListOfInterference l1dEcur; FDS_assign(LICur,LICurcopy);
    FUN_selectTRASHAinterference(LICurcopy,TopAbs_EDGE,l1dEcur);

    TopAbs_State stb; Standard_Integer isb; Standard_Integer bdim;
    TopAbs_State sta; Standard_Integer isa; Standard_Integer adim;
    FUN_ds_GetTr(BDS,iEDS,Gcur,LICur,
                 stb,isb,bdim,
                 sta,isa,adim);    
    if (isSE) {
      // before
      Standard_Boolean bIN1d = (stb==TopAbs_IN)&&(bdim==1);
      Standard_Boolean bIN2d = (stb==TopAbs_IN)&&(bdim==2);
      Standard_Boolean bIN3d = (stb==TopAbs_IN)&&(bdim==3);

      Standard_Boolean bOUT2d = (stb==TopAbs_OUT)&&(bdim==2);
      Standard_Boolean bOUT3d = (stb==TopAbs_OUT)&&(bdim==3);
      // after
      Standard_Boolean aIN1d = (sta==TopAbs_IN)&&(adim==1);
      Standard_Boolean aIN2d = (sta==TopAbs_IN)&&(adim==2);
      Standard_Boolean aIN3d = (sta==TopAbs_IN)&&(adim==3);

      Standard_Boolean aOUT2d = (sta==TopAbs_OUT)&&(adim==2);
      Standard_Boolean aOUT3d = (sta==TopAbs_OUT)&&(adim==3);
      
      TopOpeBRepDS_Transition newT; Standard_Boolean INb=Standard_False,INa=Standard_False;
      if (isfafa) {
	if       (isspon) {
	  if ((stb == TopAbs_OUT)&&(sta == TopAbs_OUT)) {tki.Next(); continue;}
	  INb = bIN1d;
	  INa = aIN1d;
	  newT.Index(isb); newT.ShapeBefore(TopAbs_EDGE); newT.ShapeAfter(TopAbs_EDGE);
	} else if (isspin) {
	  INb = bIN2d;
	  INa = aIN2d;
	  newT.ShapeBefore(TopAbs_FACE); newT.ShapeAfter(TopAbs_FACE);
	} else if (isspou) {
	  INb = !bOUT2d;
	  INa = !aOUT2d;
	  newT.ShapeBefore(TopAbs_FACE); newT.ShapeAfter(TopAbs_FACE);
	}
      }
      else {
	if       (isspon) {
	  if ((stb == TopAbs_OUT)&&(sta == TopAbs_OUT)) {tki.Next(); continue;}
	  INb = bIN1d || bIN2d;
	  INa = aIN1d || aIN2d;
	  newT.Index(isb); newT.ShapeBefore(TopAbs_EDGE); newT.ShapeAfter(TopAbs_EDGE);
	} else if (isspin) {
	  if ((stb == TopAbs_OUT)&&(sta == TopAbs_OUT)) {tki.Next(); continue;}
	  INb = bIN3d;
	  INa = aIN3d;
	  if (INb) newT.Index(isb);
	  else     newT.Index(isa);
	  newT.ShapeBefore(TopAbs_FACE); newT.ShapeAfter(TopAbs_FACE);
	} else if (isspou) {
	  if ((stb == TopAbs_IN)&&(sta == TopAbs_IN)) {tki.Next(); continue;}
	  INb = !bOUT3d;
	  INa = !aOUT3d;
	  if (bOUT3d) newT.Index(isb);
	  else        newT.Index(isa);
	  newT.ShapeBefore(TopAbs_FACE); newT.ShapeAfter(TopAbs_FACE);
	}
      }
      TopAbs_State sb = INb ? TopAbs_IN : TopAbs_OUT;
      TopAbs_State sa = INa ? TopAbs_IN : TopAbs_OUT;
      newT.StateBefore(sb);newT.StateAfter(sa);
      Standard_Integer S=0; // dummy
      Standard_Boolean B = (Kcur == TopOpeBRepDS_POINT) ? Standard_False : (Handle(TopOpeBRepDS_EdgeVertexInterference)::DownCast(I)->GBound()); 
      Handle(TopOpeBRepDS_Interference) newI = MakeEPVInterference(newT,S,Gcur,parSE,Kcur,B);
      
      TopOpeBRepDS_ListOfInterference li; li.Append(newI); TopOpeBRepDS_PointIterator itCur(li);
      GFillPointTopologyPVS(E,itCur,G,PVS);
#ifdef DEB
      if(tSPS) {newI->Dump(cout,"\nnewinterf ","\n\n"); debfillp2(iEDS);}
#endif
      {tki.Next(); continue;}
    } // isSE    

    // - kp3 -
    // xpu200598 interference 2d at GPOINT
    Standard_Boolean kp3 = (n2d > 0) && point;
    if (kp3) l2dFEcur.First()->Transition().Orientation(TopAbs_IN);


    TopOpeBRepDS_PointIterator itCur(LICur); Standard_Integer iICur=0;
    while ( itCur.More() ) {
      iICur++;
      const Handle(TopOpeBRepDS_Interference)& I1=itCur.Value();
      const TopOpeBRepDS_Transition& T1=I1->Transition();
      T1.Orientation(TopAbs_IN);
      TopAbs_ShapeEnum SB1,SA1;Standard_Integer IB1,IA1;TopOpeBRepDS_Kind GT1,ST1;Standard_Integer G1,S1;
      FDS_Idata(I1,SB1,IB1,SA1,IA1,GT1,G1,ST1,S1);

#ifdef DEB
      if(tSPS) {I1->Dump(cout,"\n? keepinterf ","\n\n"); debfillp2(iEDS);}
#endif

      Standard_Boolean keepinterf1 = Standard_False;
      if      (isEd) {
	keepinterf1 = Standard_True;
      }
      else {
	if (GLOBAL_faces2d) {  // split 2d
	  Standard_Boolean has2d3d = (n2d >0 && n3d >0); // JYL300998
	  // JYL300998 : traitement correct de cto 100 K1 e27 (chanceux auparavant, schema d'I faux)
	  // e27 n'est PAS arete de section mais doit etre traitee comme telle.
	  // e27 possede des I de nature 2d et 3d en V8
	  // on privilegie l'info 3d 
	  if (has2d3d && !isSE) {
#ifdef DEB
	    const Handle(TopOpeBRepDS_Interference)& i2d =
#endif
                               l2dFEcur.First();
	    const Handle(TopOpeBRepDS_Interference)& i3d = l3dFcur.First();
	    Standard_Boolean id3d = (I1 == i3d);
#ifdef DEB
	    Standard_Boolean id2d = (I1 == i2d);
#endif
	    keepinterf1 = id3d;
#ifdef DEB
	    if (tSPS) {
	      cout<<"DEB : GFillPointTopologyPVS E"<<iEDS<<" has2d3d"<<endl;
	      i2d->Dump(cout,"2d : ","\n");
	      i3d->Dump(cout,"3d : ","\n");
	      I1->Dump (cout,"I1 : ","\n");
	      if (id3d) cout<<"--> Interference 3d ";
	      if (id2d) cout<<"--> Interference 2d ";
	      if (keepinterf1) cout<<" traitee"<<endl;
	      else             cout<<" non traitee"<<endl;
	      cout<<endl;
	    }
#endif
	  }
	  else {
	    keepinterf1 = Standard_True; // PRO13075 tspIN(e17)
	  }
	} // split 2d
	else { // split 3d
	  keepinterf1 = (ST1 == TopOpeBRepDS_FACE); // (iICur == 1);
	}
      }
      if ( keepinterf1 ) {
	if (kp6) {
	  Standard_Boolean Gb1 = ::FUN_isonbound(myDataStructure,I1);
	  if (!Gb1) GFillPointTopologyPVS(E,itCur,G,PVS);
	}
	else       {
	  GFillPointTopologyPVS(E,itCur,G,PVS);
	}
	if (!dgE) break; // xpu140498	
      } // keepinterf1
      itCur.Next();
    } // itCur.More

    tki.Next();
  } // tki.More()
}

//=======================================================================
//function : GFillPointTopologyPVS
//purpose  : 
//=======================================================================
void TopOpeBRepBuild_Builder::GFillPointTopologyPVS(const TopoDS_Shape& E,
                                                    const TopOpeBRepDS_PointIterator& EPit,
                                                    const TopOpeBRepBuild_GTopo& G1,
                                                    TopOpeBRepBuild_PaveSet& PVS) const
{
  const TopoDS_Shape& EPVS = PVS.Edge();
  
  //modified by NIZHNY-MZV  Mon Feb 21 14:47:34 2000
  const Handle(TopOpeBRepDS_Interference)& I1=EPit.Value();
  TopOpeBRepDS_Kind ST1 = I1->SupportType();
    
#ifdef DEB
  Standard_Integer iE; Standard_Boolean tSPSE = GtraceSPS(E,iE);
  Standard_Integer iEPVS; Standard_Boolean tSPSEPVS = GtraceSPS(EPVS,iEPVS);
  Standard_Boolean tSPS = tSPSE || tSPSEPVS;
  if ( tSPS ) debfillp(iE);
#endif
  
  TopAbs_State TB1,TB2; 
  G1.StatesON(TB1,TB2);
  TopOpeBRepDS_Config Conf = G1.Config1();
  TopAbs_State TB = TB1;
  
  // iG = index of new point or existing vertex
  Standard_Integer iG = EPit.Current();
  Standard_Boolean ispoint = EPit.IsPoint();
  TopoDS_Vertex VIG; // NYI pointer
  if (ispoint) VIG = TopoDS::Vertex(NewVertex(iG));
  else VIG = TopoDS::Vertex(myDataStructure->Shape(iG));

  if (VIG.IsNull()) return; //PMN 17/02/99 Nothing to add.
  
  Standard_Boolean hasVSD = Standard_False;
  Standard_Integer iVRE = 0; TopoDS_Shape VRE; // NYI pointer
  if (!ispoint) {
    hasVSD = myDataStructure->HasSameDomain(VIG);
    if (hasVSD) { // on prend VRE = vertex reference de VIG
      iVRE = myDataStructure->SameDomainReference(VIG);
      VRE = TopoDS::Vertex(myDataStructure->Shape(iVRE));
    }
  }
  
  TopoDS_Vertex VPV; // NYI pointer on VRE or VIG
  if (hasVSD) VPV = TopoDS::Vertex(VRE);
  else        VPV = VIG;
//  else        VPV = TopoDS::Vertex(VIG);
  
  Standard_Real      par = EPit.Parameter();
  TopAbs_Orientation ori = EPit.Orientation(TB);

#ifdef DEB
  if ( tSPS ) debfillp(iE);
#endif

  Standard_Boolean samegeom = ::TopOpeBRepBuild_FUN_aresamegeom(E,EPVS);
  if (Conf == TopOpeBRepDS_DIFFORIENTED) ori = TopAbs::Complement(ori);
#ifdef DEB
  if (!TopOpeBRepBuild_GetcontextNOSG()) {
#endif
    if (!samegeom) ori = TopAbs::Complement(ori);
#ifdef DEB
  }
#endif

  
  Standard_Boolean lesmemes = E.IsEqual(myEdgeReference);
  if ( !lesmemes ) {
    Standard_Real parref = par;
    const TopoDS_Edge& EE = TopoDS::Edge(E);
    GParamOnReference(VPV,EE,parref);
#ifdef DEB
    if(tSPS){
      cout<<"par "<<par<<" / ";GdumpSHA(E);cout<<" --> parref "<<parref<<" / ";GdumpSHA(EPVS);
      cout<<endl;
    }
#endif
    par = parref;
  }

  Standard_Boolean kpbound = Standard_False;
  {
    TopoDS_Vertex vclo; Standard_Boolean Eclosed = TopOpeBRepTool_TOOL::ClosedE(myEdgeReference,vclo);
#ifdef DEB
//    Standard_Integer ivclo = myDataStructure->Shape(vclo);
#endif
    TopAbs_Orientation oriI = EPit.Orientation(TopAbs_IN);
//    kpbound = lesmemes && Eclosed && hasVSD && (ori == TopAbs_INTERNAL) && (TB == TopAbs_OUT); -xpu140898
    // xpu110398 cto 009 L2 : e6ou en v11
    // xpu140898 USA60111 : e9ou (!=0) + e7ou(=0)
    Standard_Boolean INTEXT =       (oriI == TopAbs_INTERNAL) && (TB == TopAbs_IN);
    INTEXT = INTEXT || ((oriI == TopAbs_EXTERNAL) && (TB == TopAbs_OUT));
    kpbound = lesmemes && Eclosed && INTEXT; 
    if ( kpbound ) {
      kpbound = vclo.IsSame(VIG);
      if (!kpbound) {
	TopoDS_Shape VSD; Standard_Boolean ok = FUN_ds_getoov(VIG,myDataStructure->DS(),VSD);
	if (ok) kpbound = vclo.IsSame(VSD);
      }
    }
  }

  if (!kpbound) {
    VPV.Orientation(ori);
    Standard_Boolean vofe = Standard_False;
    Handle(TopOpeBRepBuild_Pave) PV = new TopOpeBRepBuild_Pave(VPV,par,vofe);
    if (hasVSD) {
      PV->HasSameDomain(Standard_True);
      const TopoDS_Shape& VSD = myDataStructure->SameDomain(VPV).Value();
      Standard_Integer iVSD = myDataStructure->Shape(VSD);
      if (iVSD == iVRE) PV->SameDomain(VIG);
      else              PV->SameDomain(VSD);
    }
    //modified by NIZHNY-MZV  Mon Feb 21 14:48:37 2000
    PV -> InterferenceType() = ST1;
    PVS.Append(PV);
    
    
#ifdef DEB
    gp_Pnt P = BRep_Tool::Pnt(VPV);
    if(tSPS){cout<<"+";if(ispoint)cout<<" PDS ";else cout<<" VDS ";}
    if(tSPS){cout<<iG<<" : ";GdumpORIPARPNT(ori,par,P);cout<<endl;}
    if(tSPS) {
//      Standard_Boolean trc = Standard_False;
#ifdef DRAW
      if (trc) {
	FUN_draw2d(par,TopoDS::Edge(E),myEdgeReference,myFaceReference);
	FUN_draw(VPV); FUN_draw(E); FUN_draw(myFaceReference);
      }
#endif
    }
#endif
  }
  else {
    Standard_Real parf,parl; FUN_tool_bounds(myEdgeReference,parf,parl);
    TopAbs_Orientation ovpv;
    ovpv = TopAbs_FORWARD;
    VPV.Orientation(ovpv);
    Standard_Boolean vfofe = Standard_False;
    Handle(TopOpeBRepBuild_Pave) PVF = new TopOpeBRepBuild_Pave(VPV,parf,vfofe);
    if (hasVSD) {
      PVF->HasSameDomain(Standard_True);
      const TopoDS_Shape& VSD = myDataStructure->SameDomain(VPV).Value();
      Standard_Integer iVSD = myDataStructure->Shape(VSD);
      if (iVSD == iVRE) PVF->SameDomain(VIG);
      else              PVF->SameDomain(VSD);
    }
    //modified by NIZHNY-MZV  Mon Feb 21 14:48:37 2000
    PVF -> InterferenceType() = ST1;
    PVS.Append(PVF);
    
#ifdef DEB
    gp_Pnt PF = BRep_Tool::Pnt(VPV);
    if(tSPS){cout<<"+";if(ispoint)cout<<" PDS ";else cout<<" VDS ";}
    if(tSPS){cout<<iG<<" : ";GdumpORIPARPNT(ovpv,parf,PF);cout<<endl;}
#endif

    ovpv = TopAbs_REVERSED;
    VPV.Orientation(ovpv);
    Standard_Boolean vrofe = Standard_False;
    Handle(TopOpeBRepBuild_Pave) PVR = new TopOpeBRepBuild_Pave(VPV,parl,vrofe);
    if (hasVSD) {
      PVR->HasSameDomain(Standard_True);
      const TopoDS_Shape& VSD = myDataStructure->SameDomain(VPV).Value();
      Standard_Integer iVSD = myDataStructure->Shape(VSD);
      if (iVSD == iVRE) PVR->SameDomain(VIG);
      else              PVR->SameDomain(VSD);
    }
    //modified by NIZHNY-MZV  Mon Feb 21 14:48:37 2000
    PVR -> InterferenceType() = ST1;
    PVS.Append(PVR);
#ifdef DEB
    gp_Pnt PR = BRep_Tool::Pnt(VPV);
    if(tSPS){cout<<"+";if(ispoint)cout<<" PDS ";else cout<<" VDS ";}
    if(tSPS){cout<<iG<<" : ";GdumpORIPARPNT(ovpv,parl,PR);cout<<endl;}
#endif

    PVS.RemovePV(Standard_False); // jyl + 980217
  }

}


//=======================================================================
//function : GParamOnReference
//purpose  : calcul du parametre de V sur myEdgeReference de myFaceReference
//           V est sur la surface de myFaceReference, 
//           V est un vertex de E
//           E est une arete samedomain de myEdgeReference
// retourne true si ok
//=======================================================================
Standard_Boolean TopOpeBRepBuild_Builder::GParamOnReference(const TopoDS_Vertex& V,
                                                            const TopoDS_Edge& /*E*/,
                                                            Standard_Real& P) const 
{
  Handle(Geom_Surface) su = BRep_Tool::Surface(myFaceReference);
  Handle(Geom_Plane) suplan = Handle(Geom_Plane)::DownCast(su);
  if ( suplan.IsNull() ) { 
#ifdef DEB
    cout<<"NYI : GParamOnReference : not planar"<<endl;
#endif
    return Standard_False;
  }

  gp_Pln pln = suplan->Pln(); gp_Pnt p3 = BRep_Tool::Pnt(V);
  Standard_Real u,v; ElSLib::Parameters(pln,p3,u,v); gp_Pnt2d p2(u,v);
  Standard_Real f,l,tolpc; Handle(Geom2d_Curve) C2D;
  C2D = FC2D_CurveOnSurface(myEdgeReference,myFaceReference,f,l,tolpc);
  if (C2D.IsNull()) Standard_ProgramError::Raise("TopOpeBRepBuild_Builder::GParamOnReference");
  
//  Standard_Real U;
  Geom2dAdaptor_Curve AC(C2D);
  switch ( AC.GetType() ) {
  case GeomAbs_Line: 
    P = ElCLib::Parameter(AC.Line(),p2); break;
  case GeomAbs_Circle: 
    P = ElCLib::Parameter(AC.Circle(),p2); break;
  case GeomAbs_Ellipse: 
    P = ElCLib::Parameter(AC.Ellipse(),p2); break;
  case GeomAbs_Hyperbola: 
    P = ElCLib::Parameter(AC.Hyperbola(),p2); break;
  case GeomAbs_Parabola:
    P = ElCLib::Parameter(AC.Parabola(),p2); break;
    default : 
#ifdef DEB
      cout<<"NYI : GParamOnReference : OtherCurve on planar surface"<<endl;
#endif
    return Standard_False;
  }
  
  return Standard_True;
}