summaryrefslogtreecommitdiff
path: root/src/TopOpeBRepTool/TopOpeBRepTool_CORRISO.cxx
blob: ac6db99f061c319fac6c8cf5ec850ad16b08f80b (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
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
// File:	TopOpeBRepTool_CORRISO.cxx
// Created:	Wed Nov 25 17:23:50 1998
// Author:	Prestataire Xuan PHAM PHU
//		<xpu@poulopox.paris1.matra-dtv.fr>

#include <TopOpeBRepTool.hxx>
#include <TopOpeBRepTool_TOOL.hxx>
#include <TopOpeBRepTool_CORRISO.ixx>
#include <TopOpeBRepTool_define.hxx>
#include <TopOpeBRepTool_EXPORT.hxx>
#include <TopOpeBRepTool_PURGE.hxx>
#include <TopOpeBRepTool_2d.hxx>
#include <BRep_Tool.hxx>
#include <BRep_Builder.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_Array1OfShape.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <BndLib_Add2dCurve.hxx>
#include <TopoDS.hxx>

#include <BRep_TEdge.hxx>
#include <BRep_ListOfCurveRepresentation.hxx>
#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
#include <BRep_GCurve.hxx>

#ifdef DEB
Standard_IMPORT Standard_Boolean TopOpeBRepTool_GettraceCORRISO();
Standard_EXPORT TopTools_IndexedMapOfShape STATIC_PURGE_mapv;
Standard_EXPORT TopTools_IndexedMapOfOrientedShape STATIC_PURGE_mapeds;
#endif

static void FUN_RaiseError()
{
#ifdef DEB
//  Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO();
  FUN_REINIT(); 
//  if (trc) cout <<"*********failure in CORRISO***********\n";
#endif
}
static void FUN_Raise()
{
#ifdef DEB
//  cout <<"*********failure in CORRISO***********\n";
#endif
}

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

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

//=======================================================================
//function : TopOpeBRepTool_CORRISO
//purpose  : 
//=======================================================================

TopOpeBRepTool_CORRISO::TopOpeBRepTool_CORRISO()
{
}

//=======================================================================
//function : TopOpeBRepTool_CORRISO
//purpose  : 
//=======================================================================

TopOpeBRepTool_CORRISO::TopOpeBRepTool_CORRISO(const TopoDS_Face& Fref)
{
  myFref = Fref;
  FUN_tool_closedS(myFref,myUclosed,myUper,myVclosed,myVper);

  const Handle(Geom_Surface)& SU = BRep_Tool::Surface(myFref);
  myGAS = GeomAdaptor_Surface(SU);
}

//=======================================================================
//function : Fref
//purpose  : 
//=======================================================================

const TopoDS_Face& TopOpeBRepTool_CORRISO::Fref() const
{
  return myFref;
}

//=======================================================================
//function : GASref
//purpose  : 
//=======================================================================

const GeomAdaptor_Surface& TopOpeBRepTool_CORRISO::GASref() const 
{
  return myGAS;
}


//=======================================================================
//function : Refclosed
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::Refclosed(const Standard_Integer x, Standard_Real& xperiod) const
{
  if (x==1) {xperiod = myUper; return myUclosed;}
  if (x==2) {xperiod = myVper; return myVclosed;}
  return Standard_False;
}



//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::Init(const TopoDS_Shape& S)
{
#ifdef DRAW  
  Standard_Integer ie = 0;
  Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO();
  Standard_Boolean INIT = Standard_True;
  if (INIT) FUN_REINIT();
#endif

  myERep2d.Clear();
  myEds.Clear();
  myVEds.Clear();

  if (S.IsNull()) return Standard_False;
  myS = S;

  TopExp_Explorer ex(S, TopAbs_EDGE);
  for (; ex.More(); ex.Next()){
    const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
#ifdef DEB
    Standard_Integer iE = STATIC_PURGE_mapeds.Add(E);
#ifdef DRAW
    if (trc) {TCollection_AsciiString aa = TCollection_AsciiString("e"); FUN_tool_draw(aa,E,iE);}
#endif
#endif
    // myEds :
    myEds.Append(E);

    // myERep2d :
//    Standard_Real f,l,tol; Handle(Geom2d_Curve) PC = FC2D_CurveOnSurface(E,myFref,f,l,tol);
    Handle(Geom2d_Curve) PC; Standard_Real f,l,tol;
    Standard_Boolean hasold = FC2D_HasOldCurveOnSurface(E,myFref,PC);
    FC2D_HasNewCurveOnSurface(E,myFref,PC);
    PC = FC2D_EditableCurveOnSurface(E,myFref,f,l,tol);
    if (!hasold) FC2D_AddNewCurveOnSurface(PC,E,myFref,f,l,tol);
    if (PC.IsNull()) return Standard_False;
    TopOpeBRepTool_C2DF C2DF(PC,f,l,tol,myFref);
    myERep2d.Bind(E,C2DF);
        
    // myVEds :
    TopExp_Explorer exv(E, TopAbs_VERTEX);
    for (; exv.More(); exv.Next()){
      const TopoDS_Vertex& v = TopoDS::Vertex(exv.Current());   
#ifdef DEB
#ifdef DRAW
      Standard_Integer iv =
#endif
        STATIC_PURGE_mapv.Add(v);
#ifdef DRAW
      if (trc) {TCollection_AsciiString bb = TCollection_AsciiString("v"); FUN_tool_draw(bb,v,iv);}
#endif      
#endif
      Standard_Boolean isb = myVEds.IsBound(v);
      if (isb) myVEds.ChangeFind(v).Append(E);
      else     {TopTools_ListOfShape loe; loe.Append(E); myVEds.Bind(v,loe);}
    }//exv
  }
  return Standard_True;
}

//=======================================================================
//function : S
//purpose  : 
//=======================================================================

const TopoDS_Shape& TopOpeBRepTool_CORRISO::S() const 
{
  return myS;
}

//=======================================================================
//function : Eds
//purpose  : 
//=======================================================================

const TopTools_ListOfShape& TopOpeBRepTool_CORRISO::Eds() const 
{
  return myEds;
}

//=======================================================================
//function : UVRep
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::UVRep(const TopoDS_Edge& E, TopOpeBRepTool_C2DF& C2DF) const
{
  Standard_Boolean isb = myERep2d.IsBound(E);
  if (!isb) return Standard_False;
  
  C2DF = myERep2d.Find(E);
  return Standard_True;
}

//=======================================================================
//function : SetUVRep
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::SetUVRep(const TopoDS_Edge& E, const TopOpeBRepTool_C2DF& C2DF)
{
  Standard_Boolean isb = myERep2d.IsBound(E);
  if (!isb) return Standard_False;
  
  myERep2d.ChangeFind(E) = C2DF;
  return Standard_True;  
}

//=======================================================================
//function : Connexity
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::Connexity(const TopoDS_Vertex& V, TopTools_ListOfShape& Eds) const
{
  Standard_Boolean isb = myVEds.IsBound(V);
  if (!isb) return Standard_False;
  
  Eds = myVEds.Find(V);
  return Standard_True;
}

//=======================================================================
//function : SetConnexity
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::SetConnexity(const TopoDS_Vertex& V, const TopTools_ListOfShape& Eds) 
{
  Standard_Boolean isb = myVEds.IsBound(V);
  if (!isb) return Standard_False;
  
  myVEds.ChangeFind(V) = Eds;
  return Standard_True;
}

//=======================================================================
//function : UVClosed
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::UVClosed() const
{  
#ifdef DEB
  Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO();
  if (trc) cout<<"** UVClosed"<<endl;
#endif
  TopTools_DataMapOfOrientedShapeInteger lfyE; Standard_Integer nfybounds=3; Standard_Boolean stopatfirst = Standard_True;
  Standard_Boolean foundfaulty = EdgesWithFaultyUV(myEds,nfybounds,lfyE,stopatfirst);
  return !foundfaulty;
}

//=======================================================================
//function : Tol
//purpose  : 
//=======================================================================

Standard_Real TopOpeBRepTool_CORRISO::Tol(const Standard_Integer I, const Standard_Real tol3d) const
{
  Standard_Real tol = (I==1) ? myGAS.UResolution(tol3d) : myGAS.VResolution(tol3d);
  return tol;
}

//static Standard_Real FUN_getx(const TopoDS_Edge& E,
static Standard_Real FUN_getx(const TopoDS_Edge& ,
                              const TopOpeBRepTool_C2DF& c2df,
		              const Standard_Boolean uiso,
                              const Standard_Real par)
{ // prequesitory : E is uviso
  gp_Pnt2d uv = TopOpeBRepTool_TOOL::UVF(par,c2df);
  Standard_Real x = (uiso) ? uv.Y() : uv.X();
  return x;
}

/*static void FUN_getinfsupx(const TopoDS_Edge& E, const TopOpeBRepTool_C2DF& c2df,
			   const Standard_Boolean uiso,
			   Standard_Real& xf, Standard_Real& xl)
{ // prequesitory : E is uviso
  // 2drep(E) describes [xf,xl]*[yf,yl];
  // if (uiso) x = upar
  // if (viso) x = vpar
  Standard_Real f,l; FUN_tool_bounds(E, f,l);
  Standard_Real parf = FUN_getx(E,c2df,uiso, f);
  Standard_Real parl = FUN_getx(E,c2df,uiso, l);
  if (parf < parl) {xf = parf; xl = parl;}
  else             {xf = parl; xl = parf;}
}*/

#ifdef DEB
static Standard_Boolean FUN_isonOcE(const TopOpeBRepTool_CORRISO CO, const TopoDS_Edge& cE)
{
  TopTools_Array1OfShape vcE(1,2); TopOpeBRepTool_TOOL::Vertices(cE,vcE); 
  TopAbs_Orientation ocE = cE.Orientation(); 
  
  Standard_Real tttolcE = BRep_Tool::Tolerance(cE);
  Standard_Real tttuvcE = Max(CO.Tol(1,tttolcE),CO.Tol(2,tttolcE));
  TopOpeBRepTool_C2DF cE2d; Standard_Boolean isb = CO.UVRep(cE,cE2d);
  if (!isb) return Standard_False; // NYIRAISE
  
  // isonOcE2d :
  Standard_Boolean isonOcE2d = Standard_False;
  {
    // OcE (closing edge with complemented orientation):
    TopAbs_Orientation oOcE = TopAbs::Complement(ocE);
    TopoDS_Shape aLocalShape = cE.Oriented(oOcE);
    TopoDS_Edge OcE = TopoDS::Edge(aLocalShape);
//    TopoDS_Edge OcE = TopoDS::Edge(cE.Oriented(oOcE));
    TopTools_Array1OfShape vOcE(1,2); TopOpeBRepTool_TOOL::Vertices(OcE,vOcE); 
    Standard_Real tttolOcE = BRep_Tool::Tolerance(OcE);
    Standard_Real tttuvOcE = Max(CO.Tol(1,tttolOcE),CO.Tol(2,tttolOcE));
    TopOpeBRepTool_C2DF OcE2d; Standard_Boolean isOb = CO.UVRep(OcE,OcE2d);
    if (!isOb) return Standard_False; // NYIRAISE
    
    Standard_Real parvce1 = TopOpeBRepTool_TOOL::ParE(1,cE);   gp_Pnt2d UVvce1 = TopOpeBRepTool_TOOL::UVF(parvce1,cE2d);
    Standard_Real parvOcE2 = TopOpeBRepTool_TOOL::ParE(2,OcE); gp_Pnt2d UVvOcE2 = TopOpeBRepTool_TOOL::UVF(parvOcE2,OcE2d);
    Standard_Real tol = Max(tttuvcE,tttuvOcE);
    isonOcE2d = (UVvce1.Distance(UVvOcE2) < tol);
  }
  return isonOcE2d;
}
#endif

//=======================================================================
//function : PurgeFyClosingE
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::PurgeFyClosingE(const TopTools_ListOfShape& ClEds, TopTools_ListOfShape& fyClEds) const
{
  fyClEds.Clear();
#ifdef DEB
  Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO();
  if (trc) cout<<"* PurgeFyClosingE"<<endl;
#endif
//  Standard_Real xperiod = myUclosed ? myUper : myVper; 
  Standard_Real tttol = 1.e-8;
  Standard_Real tttolS = BRep_Tool::Tolerance(myFref);
  Standard_Real tolu = Tol(1,tttolS), tolv = Tol(2,tttolS);
  Standard_Real tttuvF = Max(tolu,tolv);

  TopTools_IndexedMapOfOrientedShape mapcl;
  TopTools_ListIteratorOfListOfShape itce(ClEds);
  for (; itce.More(); itce.Next()) mapcl.Add(itce.Value());

  //* one closing edge should be removed     
  itce.Initialize(ClEds);
  TopTools_DataMapOfOrientedShapeInteger fyceds; Standard_Boolean found = EdgesWithFaultyUV(ClEds,3,fyceds);
  if (!found) return Standard_False;  

  if      (fyceds.Extent() == 1) {// ivf == 3 : cto016G*
    TopTools_DataMapOfOrientedShapeInteger fyeds;
    EdgesWithFaultyUV(myEds,3,fyeds);
    Standard_Integer nfy = fyeds.Extent();

    TopTools_DataMapIteratorOfDataMapOfOrientedShapeInteger itm(fyceds);
    const TopoDS_Edge& cE = TopoDS::Edge(itm.Key());

    TopAbs_Orientation OocE = TopAbs::Complement(cE.Orientation());
    Standard_Boolean isoncE = mapcl.Contains(cE.Oriented(OocE));
    if (isoncE) {
      TopTools_Array1OfShape vcE(1,2); TopOpeBRepTool_TOOL::Vertices(cE,vcE); 
      TopAbs_Orientation ocE = cE.Orientation();       
      Standard_Real tttolcE = BRep_Tool::Tolerance(cE);
      Standard_Real tttuvcE = Max(Tol(1,tttolcE),Tol(2,tttolcE));
      TopOpeBRepTool_C2DF cE2d; Standard_Boolean isb = UVRep(cE,cE2d);
      if (!isb) return Standard_False; // NYIRAISE
  
      // isonOcE2d :
      // OcE (closing edge with complemented orientation):
      TopAbs_Orientation oOcE = TopAbs::Complement(ocE);
      TopoDS_Shape alocalShape = cE.Oriented(oOcE);     
      TopoDS_Edge OcE = TopoDS::Edge(alocalShape);
//      TopoDS_Edge OcE = TopoDS::Edge(cE.Oriented(oOcE));
      TopTools_Array1OfShape vOcE(1,2); TopOpeBRepTool_TOOL::Vertices(OcE,vOcE); 
      Standard_Real tttolOcE = BRep_Tool::Tolerance(OcE);
      Standard_Real tttuvOcE = Max(Tol(1,tttolOcE),Tol(2,tttolOcE));
      TopOpeBRepTool_C2DF OcE2d; Standard_Boolean isOb = UVRep(OcE,OcE2d);
      if (!isOb) return Standard_False; // NYIRAISE
      
      Standard_Real parvce1 = TopOpeBRepTool_TOOL::ParE(1,cE);   gp_Pnt2d UVvce1 = TopOpeBRepTool_TOOL::UVF(parvce1,cE2d);
      Standard_Real parvOcE2 = TopOpeBRepTool_TOOL::ParE(2,OcE); gp_Pnt2d UVvOcE2 = TopOpeBRepTool_TOOL::UVF(parvOcE2,OcE2d);
      Standard_Real tol = Max(tttuvcE,tttuvOcE);
      isoncE = (UVvce1.Distance(UVvOcE2) < tol);
      if (isoncE && (nfy != 1)) {// cto009L2
	return Standard_False; 
      }
    }

    Standard_Integer ivf = itm.Value();
    if (ivf == 3) {
      fyClEds.Append(cE); 
      return Standard_True;
    }
  }
  else if (fyceds.Extent() > 1) {// ivf == 1,2 : cto016E*
    // if {edges of fyceds} describe a closing edge with its first and last 
    // uvbounds non connexed -> we do remove these edges
    Standard_Boolean hasinit=Standard_False; Standard_Boolean isou=Standard_False,isov=Standard_False;
    gp_Pnt2d o2d; gp_Dir2d d2d; 
    Standard_Real xinf=1.e7,  xsup=-1.e7; // faulty inf and sup bounds
    Standard_Boolean infdef=Standard_False, supdef=Standard_False;
    TopTools_DataMapIteratorOfDataMapOfOrientedShapeInteger itm(fyceds);
    for (; itm.More(); itm.Next()){
      const TopoDS_Edge& cE = TopoDS::Edge(itm.Key());
      TopOpeBRepTool_C2DF c2df; Standard_Boolean isb = UVRep(cE,c2df);
      if (!isb) return Standard_False; // NYIRAISE

      Standard_Integer ivf = itm.Value();
      Standard_Boolean isoux,isovx; gp_Pnt2d o2dx; gp_Dir2d d2dx;
      Standard_Boolean uvisox = TopOpeBRepTool_TOOL::UVISO(c2df,isoux,isovx, d2dx, o2dx);
      if (!uvisox) return Standard_False;
      
      if (hasinit) {
	Standard_Boolean onsamline = (isou && isoux) || (isov && isovx);
	if (!onsamline) return Standard_False;
      }
      if (!hasinit) {
	isou=isoux; isov=isovx; 
	o2d=o2dx; d2d=d2dx;
	hasinit = Standard_True;
      }
      else {
	Standard_Boolean onsamline = Standard_False;
	if (isou && isoux) {
	  Standard_Real du = o2d.X()-o2dx.X();
	  onsamline = (Abs(du) < tolu);
	}
	if (isov && isovx) {
	  Standard_Real dv = o2d.Y()-o2dx.Y();
	  onsamline = (Abs(dv) < tolv);
	}
	if (!onsamline) return Standard_False;
      }        
      for (Standard_Integer i = 1; i <=2; i++) {
	Standard_Real pari = TopOpeBRepTool_TOOL::ParE(i,cE);
	Standard_Real xi = FUN_getx(cE,c2df,isou,pari);
	Standard_Boolean vifaulty = (ivf == i || ivf == 3);	
	Standard_Boolean inff = (xi < xinf);
	Standard_Boolean supl = (xi > xsup);
//	if (inff) xinf = (ivf == i || ivf == 3) ? xi : 1.e7;
//	if (supl) xsup = (ivf == i || ivf == 3) ? xi : -1.e7;
	if (inff) {xinf = xi; infdef = vifaulty;}
	if (supl) {xsup = xi; supdef = vifaulty;}
      }      
      fyClEds.Append(cE);
    }//itm
    Standard_Boolean toremove = infdef && supdef; // ie infx,supx are not "uv-connexed"
    if (!toremove) fyClEds.Clear();
  }
  if (!fyClEds.IsEmpty()) return Standard_True; // keeping only one closing edge

  //* the 2 closing edges have they 2drep "confunded"
  itce.Initialize(ClEds);
  for (; itce.More(); itce.Next()){
    // cE : 
    const TopoDS_Edge& cE = TopoDS::Edge(itce.Value());
    TopTools_Array1OfShape vcE(1,2); TopOpeBRepTool_TOOL::Vertices(cE,vcE); 
    TopAbs_Orientation ocE = cE.Orientation(); 

    Standard_Real tttolcE = BRep_Tool::Tolerance(cE);
    Standard_Real tttuvcE = Max(Tol(1,tttolcE),Tol(2,tttolcE));
    TopOpeBRepTool_C2DF cE2d; Standard_Boolean isb = UVRep(cE,cE2d);
    if (!isb) return Standard_False; // NYIRAISE
#ifdef DEB
    Standard_Integer icE = STATIC_PURGE_mapeds.Add(cE);
    if (trc) cout<<"? e"<<icE<<" :"<<endl;
#endif

    // isonOcE2d :
    Standard_Boolean isonOcE2d = Standard_False;
    {
      // OcE (closing edge with complemented orientation):
      TopAbs_Orientation oOcE = TopAbs::Complement(ocE);
      TopoDS_Shape aLocalShape = cE.Oriented(oOcE);
      TopoDS_Edge OcE = TopoDS::Edge(aLocalShape);
//      TopoDS_Edge OcE = TopoDS::Edge(cE.Oriented(oOcE));
      TopTools_Array1OfShape vOcE(1,2); TopOpeBRepTool_TOOL::Vertices(OcE,vOcE); 
      Standard_Boolean hasOcE = mapcl.Contains(OcE);
      if (!hasOcE) continue; // closing edge appears twice
      Standard_Real tttolOcE = BRep_Tool::Tolerance(OcE);
      Standard_Real tttuvOcE = Max(Tol(1,tttolOcE),Tol(2,tttolOcE));
      TopOpeBRepTool_C2DF OcE2d; Standard_Boolean isOb = UVRep(OcE,OcE2d);
      if (!isOb) return Standard_False; // NYIRAISE
      Standard_Real parvce1 = TopOpeBRepTool_TOOL::ParE(1,cE);   gp_Pnt2d UVvce1 = TopOpeBRepTool_TOOL::UVF(parvce1,cE2d);
      Standard_Real parvOcE2 = TopOpeBRepTool_TOOL::ParE(2,OcE); gp_Pnt2d UVvOcE2 = TopOpeBRepTool_TOOL::UVF(parvOcE2,OcE2d);
      Standard_Real tol = Max(tttuvcE,tttuvOcE);
      isonOcE2d = (UVvce1.Distance(UVvOcE2) < tol);
    }
    if (!isonOcE2d) {
#ifdef DEB
      if (trc) cout<<"-> valid edge"<<endl;
#endif
      continue;
    }

    Standard_Integer nvcEok = 0;   
    for (Standard_Integer ivce = 1; ivce <=2; ivce++) {
      // <vce> (boundary of <cE>):   
      const TopoDS_Vertex& vce = TopoDS::Vertex(vcE(ivce)); 
      TopTools_ListOfShape loe; isb = Connexity(vce,loe);
      if (!isb) return Standard_False; // NYIRAISE

      Standard_Real parvce = TopOpeBRepTool_TOOL::ParE(ivce,cE); gp_Pnt2d UVvce = TopOpeBRepTool_TOOL::UVF(parvce,cE2d);
#ifdef DEB
      // recall in one wire, there are 2 vertices for one non-degenerated closing edge
      Standard_Integer ivmapv = STATIC_PURGE_mapv.Add(vce);
      if (trc) {cout<<" connexity for v("<<ivce<<")=v"<<ivmapv;FUN_tool_trace(UVvce);}
#ifdef DRAW	
      if (trc) {TCollection_AsciiString bb("uv_");bb += TCollection_AsciiString(ivmapv);FUN_tool_draw(bb,UVvce);}
#endif
#endif	      
      Standard_Real tttolvce = BRep_Tool::Tolerance(vce); 
      Standard_Real tttuvvce = Max(Tol(1,tttolvce),Tol(2,tttolvce));

      Standard_Boolean vceok = Standard_False;
      for (TopTools_ListIteratorOfListOfShape ite(loe); ite.More(); ite.Next()) {
	const TopoDS_Edge& E = TopoDS::Edge(ite.Value());

#ifdef DEB
	Standard_Integer iE = STATIC_PURGE_mapeds.Add(E);
	if (trc) {cout<<"    : on e"<<iE<<endl;}
#endif
//	if (E.IsSame(cE)) continue;
	if (mapcl.Contains(E)) continue; // do NOT check connexity on closing edges 
	                                  // xpu090399 cto016E1

	TopOpeBRepTool_C2DF E2d; Standard_Boolean isb = UVRep(E,E2d);
	if (!isb) return Standard_False; // NYIRAISE
	
	Standard_Real tttolE = BRep_Tool::Tolerance(E);
	Standard_Real tttuvE = Max(Tol(1,tttolE),Tol(2,tttolE));
	
	TopTools_Array1OfShape vE(1,2); TopOpeBRepTool_TOOL::Vertices(E,vE);
	for (Standard_Integer ive = 1; ive <=2; ive++) {	 

	  const TopoDS_Vertex& ve = TopoDS::Vertex(vE(ive));		  
	  Standard_Boolean samev = ve.IsSame(vce);
	  if (!samev) continue; 
	  Standard_Real parve = TopOpeBRepTool_TOOL::ParE(ive,E); gp_Pnt2d UVve = TopOpeBRepTool_TOOL::UVF(parve,E2d);
#ifdef DEB
	  if (trc) {cout<<"    ve("<<ive<<")";FUN_tool_trace(UVve);}
#endif 
	  if (ive == ivce) continue; // vertex FORWARD connexed to REVERSED one
	  Standard_Real tttolve = BRep_Tool::Tolerance(ve);
	  Standard_Real tttuvve = Max(Tol(1,tttolve),Tol(2,tttolve));
	  
	  tttol = Max(tttol,Max(tttuvF,Max(tttuvE,Max(tttuvcE,Max(tttuvve,tttuvvce)))));
//	  Standard_Real dd = myUclosed ? (UVve.X()-UVvce.X()) : (UVve.Y()-UVvce.Y());
//	  Standard_Boolean xok = (Abs(dd)<tttol) || (Abs(Abs(dd)-xperiod)<tttol);
//	  if (xok) {
	  Standard_Real dd = UVve.Distance(UVvce);
	  Standard_Boolean sameuv = (dd < tttol);
	  if (myUclosed) {	    
	    Standard_Real xperiod = myUper;
	    dd = (UVve.X()-UVvce.X());
	    sameuv = sameuv || (Abs(Abs(dd)-xperiod)<tttol);
	  }
	  if (myVclosed) {	    
	    Standard_Real xperiod = myVper;
	    dd = (UVve.Y()-UVvce.Y());
	    sameuv = sameuv || (Abs(Abs(dd)-xperiod)<tttol);
	  }
	  if (sameuv) {
	    vceok = Standard_True;
#ifdef DEB
	    if (trc){cout<<" connexity->ok"<<endl;}
#endif	
	  }
	  break;
	} // ive=1..2
	if (vceok) break;	
      } //ite(loe)     
 
#ifdef DEB
      if (trc && !vceok) {cout<<" connexity->KO"<<endl;}	
#endif     
      if (vceok) nvcEok++;
    }// ivce=1..2

    Standard_Boolean isfycE = (nvcEok == 0); // each bound is not connexed to any non-closed edge

#ifdef DEB 
    if (trc) 
      {if (isfycE) cout<<"-> faulty edge"<<endl; 
       else        cout<<"-> valid edge"<<endl;}
#endif 
    if (isfycE) fyClEds.Append(cE);
  }//itce
  return (!fyClEds.IsEmpty());
}

#define SPLITEDGE (0)
#define INCREASE  (1)
#define DECREASE (-1)

static Standard_Integer FUN_tool_recadre(const Standard_Real minx,const Standard_Real maxx,
			    const Standard_Real xfirst,const Standard_Real xlast,const Standard_Real tolx,
			    Standard_Boolean& maxsup)
{
  Standard_Integer recadre = 10; // INIT  
  Standard_Boolean maxinf = (maxx < xfirst+tolx);    // permissive
  Standard_Boolean mininf   = (minx   < xfirst-tolx);// 
  maxsup = (maxx > xlast+tolx);     // 
  Standard_Boolean minsup   = (minx   > xlast-tolx); // permissive
  Standard_Boolean maxok  = (xfirst-tolx < maxx) && (maxx < xlast+tolx);// permissive
  Standard_Boolean minok    = (xfirst-tolx < minx) && (minx < xlast+tolx);    // permissive
  
  if      (maxinf)          recadre = INCREASE;
  else if (minsup)          recadre = DECREASE;
  else if (mininf && maxok) recadre = SPLITEDGE;
  else if (minok && maxsup) recadre = SPLITEDGE;
  return recadre;
}

//=======================================================================
//function : EdgeOUTofBoundsUV
//purpose  : 
//=======================================================================

Standard_Integer TopOpeBRepTool_CORRISO::EdgeOUTofBoundsUV(const TopoDS_Edge& E, const Standard_Boolean onU, const Standard_Real tolx, 
					      Standard_Real& parspE) const 
{
  Standard_Integer recadre = 10; parspE = -1.e7; // INIT
  Standard_Integer isb = myERep2d.IsBound(E);
  if (!isb) return Standard_False;
  
  const TopOpeBRepTool_C2DF& C2DF = myERep2d.Find(E);
  Standard_Real f,l,tol; const Handle(Geom2d_Curve)& PC = C2DF.PC(f,l,tol);
 
  Standard_Real xfirst  = onU ? myGAS.FirstUParameter() : myGAS.FirstVParameter();
  Standard_Real xlast   = onU ? myGAS.LastUParameter() : myGAS.LastVParameter(); // xlast=xfirst+xperiod
  Standard_Real xperiod = onU ? myUper : myVper;

  Standard_Boolean isou,isov; gp_Pnt2d o2d; gp_Dir2d d2d; 
  Standard_Boolean iso = TopOpeBRepTool_TOOL::UVISO(PC,isou,isov,d2d,o2d);

  if (iso) { // 2drep(E,myFref) is an ISO
             // -------------------------
    Standard_Boolean inX = (onU && isou) || ((!onU) && isov);
    if (inX) {
      // faulty u-iso : upar out of ubound
      Standard_Real xpar = onU ? o2d.X() : o2d.Y(); 
      Standard_Boolean toosmall = (xpar < xfirst-tolx); 
      Standard_Boolean tobig = (xpar > xfirst+xperiod+tolx);
      
      if (toosmall) recadre = INCREASE;
      if (tobig)    recadre = DECREASE;
      return recadre;
    } // inX
    Standard_Boolean inY = (onU && isov) || ((!onU) && isou); // inY = !inX
    if (inY) {
      // faulty u-iso : vpar describes (minv,maxv) out of vbounds
      // PC describes [minx,maxx] in x-space 
      // recadre = INCREASE : maxx < 0.
      //           DECREASE : minx > 2PI
      //           SPLITEDGE : minx<0.<maxx || minx<2PI<maxx
      Standard_Real d2ddir = onU? d2d.Y(): d2d.X();
      Standard_Boolean reverse = (d2ddir < 0.); Standard_Real xfactor = reverse? -1.: 1.;
      Standard_Real max = reverse? f: l;
      Standard_Real min   = reverse? l: f;
      gp_Pnt2d maxuv = PC->Value(max); 
      gp_Pnt2d minuv = PC->Value(min); 

      Standard_Real maxx = onU? maxuv.X(): maxuv.Y();
      Standard_Real minx = onU? minuv.X(): minuv.Y();

      Standard_Boolean maxsup;
      recadre = FUN_tool_recadre(minx,maxx,xfirst,xlast,tolx,
				 maxsup);      
      if (recadre == SPLITEDGE) {
	Standard_Real xbound = maxsup? xperiod: 0.;
	parspE = max - xfactor*(maxx-xbound);
      }      
      return recadre;
    } // inY
  } // iso
  else { // 2drep(E, myFref) is NOT an iso
         // ------------------------------
    Bnd_Box2d Bn2d;
    Geom2dAdaptor_Curve GC2d(PC,f,l);
    Standard_Real tolE = BRep_Tool::Tolerance(E);
    Standard_Real toladd = Max(tolE,tol);
    BndLib_Add2dCurve::Add(GC2d,toladd,Bn2d);
    Standard_Real umin,vmin,umax,vmax; Bn2d.Get(umin,vmin,umax,vmax);
    Standard_Real xmin = onU ? umin : vmin;
    Standard_Real xmax = onU ? umax : vmax;
    Standard_Boolean maxsup;
    recadre = FUN_tool_recadre(xmin,xmax,xfirst,xlast,tolx,
               		       maxsup);  
    if (recadre == SPLITEDGE) {
      // ================================================================
      //NYIxpu271198 : intersection PC avec xiso (x= maxsup? xperiod: 0.)
      // ================================================================
      return 10;
    }  
    return recadre;
  }  
  return recadre;
}

//=======================================================================
//function : EdgesOUTofBoundsUV
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::EdgesOUTofBoundsUV(const TopTools_ListOfShape& EdsToCheck, const Standard_Boolean onU, const Standard_Real tolx, 
					       TopTools_DataMapOfOrientedShapeInteger & FyEds) const 
{
  FyEds.Clear();
  TopTools_ListIteratorOfListOfShape it(EdsToCheck);
  for (; it.More(); it.Next()){
    const TopoDS_Edge& E = TopoDS::Edge(it.Value());
    Standard_Real sspar = -1.e7;
    Standard_Integer recadre = EdgeOUTofBoundsUV(E,onU,tolx,sspar);
    if (recadre == SPLITEDGE) FUN_Raise();
    if (recadre == INCREASE)  FyEds.Bind(E,1);
    if (recadre == DECREASE)  FyEds.Bind(E,-1);
  }
  return (!FyEds.IsEmpty());
}


//=======================================================================
//function : EdgeWithFaultyUV
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::EdgeWithFaultyUV(const TopoDS_Edge& E, Standard_Integer& Ivfaulty) const 
{
#ifdef DEB
  Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO();
  Standard_Integer iE = STATIC_PURGE_mapeds.Add(E);
  if (trc) cout<<"? e"<<iE<<" :"<<endl;
#endif
  Ivfaulty = 0;
  Standard_Real tttol = 1.e-8;
  Standard_Real tttolF = BRep_Tool::Tolerance(TopoDS::Face(myFref));
  Standard_Real tttuvF = Max(Tol(1,tttolF),Tol(2,tttolF));
  Standard_Real tttolE = BRep_Tool::Tolerance(E);
  Standard_Real tttuvE = Max(Tol(1,tttolE),Tol(2,tttolE));

  TopAbs_Orientation oE = E.Orientation();
  if (M_INTERNAL(oE) || M_EXTERNAL(oE)) return Standard_False;
    
  TopTools_Array1OfShape vEs(1,2); TopOpeBRepTool_TOOL::Vertices(E, vEs);
  Standard_Boolean closed = vEs(1).IsSame(vEs(2));
  if (closed) {
#ifdef DEB 
    if (trc) {cout<<"closed -> valid edge"<<endl;}
#endif     
    return Standard_False; // closed edge is assumed valid
  }
  
  Standard_Integer nfyv = 0;
  for (Standard_Integer ivE = 1; ivE <=2; ivE++) {
    
    // <vE> (boundary of <E>):      
    const TopoDS_Vertex& vE = TopoDS::Vertex(vEs(ivE)); 
    Standard_Real parvE = TopOpeBRepTool_TOOL::ParE(ivE,E);
    TopOpeBRepTool_C2DF C2DF; Standard_Boolean isb = UVRep(E,C2DF);
    if (!isb) return Standard_False; //NYIRAISE
    gp_Pnt2d UVvE = TopOpeBRepTool_TOOL::UVF(parvE,C2DF);
#ifdef DEB
      // recall in one wire, there are 2 vertices for one non-degenerated closing edge
    Standard_Integer ivmapv = STATIC_PURGE_mapv.Add(vE);
    if (trc) {cout<<" connexity for v("<<ivE<<")=v"<<ivmapv;FUN_tool_trace(UVvE);}
#ifdef DRAW	
    if (trc) {TCollection_AsciiString bb("uv_");bb += TCollection_AsciiString(ivmapv);FUN_tool_draw(bb,UVvE);}
#endif
#endif	
    
    Standard_Real tttolvE = BRep_Tool::Tolerance(vE);
    Standard_Real tttuvvE = Max(Tol(1,tttolvE),Tol(2,tttolvE));
    
    Standard_Boolean isbound = myVEds.IsBound(vE);
    if (!isbound) {FUN_RaiseError(); return Standard_False;}
    
    // <vEok> :
    Standard_Boolean vEok = Standard_False;
    const TopTools_ListOfShape& loe = myVEds.Find(vE);
    for (TopTools_ListIteratorOfListOfShape ite(loe); ite.More(); ite.Next()) {
      const TopoDS_Edge& e = TopoDS::Edge(ite.Value());
      TopAbs_Orientation oe = e.Orientation();
#ifdef DEB
      Standard_Integer ie = STATIC_PURGE_mapeds.Add(e);
      if (trc) {cout<<"    : on e"<<ie<<endl;}
#endif
      if (e.IsSame(E)) continue;      
      if (M_INTERNAL(oe) || M_EXTERNAL(oe)) continue;

      Standard_Boolean isb = myERep2d.IsBound(e);
      if (!isb) {FUN_RaiseError(); return Standard_False;}
      const TopOpeBRepTool_C2DF& C2DF = myERep2d.Find(e);
      
      TopTools_Array1OfShape ves(1,2); TopOpeBRepTool_TOOL::Vertices(e,ves);	
      for (Standard_Integer ive = 1; ive <=2; ive++) {	  
	const TopoDS_Vertex& ve = TopoDS::Vertex(ves(ive));	  
	Standard_Boolean samev = ve.IsSame(vE);
	if (!samev) continue;
	  
	Standard_Real pare = TopOpeBRepTool_TOOL::ParE(ive,e); gp_Pnt2d UVve = TopOpeBRepTool_TOOL::UVF(pare,C2DF);
#ifdef DEB
	if (trc) {cout<<"    ve("<<ive<<")";FUN_tool_trace(UVve);}
#endif 
	if (ive == ivE) continue;	
	
	Standard_Real tttolve = BRep_Tool::Tolerance(ve);
	Standard_Real tttuvve = Max(Tol(1,tttolve),Tol(2, tttolve));
	
	tttol = Max(tttol,Max(tttuvF,Max(tttuvE,Max(tttuvE,Max(tttuvve,tttuvvE)))));
	Standard_Boolean isequal = UVvE.IsEqual(UVve,tttol);
	if (isequal) {
	  vEok = Standard_True;
#ifdef DEB
	  if (trc){cout<<" connexity->ok"<<endl;}
#endif	
	  break;
	}
      } // ive	
      if (vEok) break;
    } // ite(loe)
      
    if (!vEok) {nfyv++; Ivfaulty = ivE;}      
#ifdef DEB
    if (trc && !vEok) {cout<<" connexity->KO"<<endl;}	
#endif      

  } // ivE = 1..2          
  if (nfyv == 2) Ivfaulty = 3;
#ifdef DEB 
  if (trc) {if (Ivfaulty == 0) cout<<"-> valid edge"<<endl; else cout<<"-> faulty edge"<<endl;}
#endif   
  return (Ivfaulty != 0);
}

//=======================================================================
//function : EdgesWithFaultyUV
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::EdgesWithFaultyUV(const TopTools_ListOfShape& EdsToCheck, const Standard_Integer nfybounds,
					      TopTools_DataMapOfOrientedShapeInteger& FyEds, const Standard_Boolean stopatfirst) const 
{
  FyEds.Clear();
#ifdef DEB
  Standard_Integer ifault = 0;
  Standard_Boolean trc = TopOpeBRepTool_GettraceCORRISO(); 
  if (trc) cout<<endl<<"* EdgesWithFaultyUV"<<endl;
#endif

  // fF's checking :
  // -----------------
  // An edge is valid if the first and last vertices are valid:
  // vertex <vEchk> is valid if there is an edge with bound <ve> such that :
  //   <vEchk> and <ve> share same UV geometry
  //   <vEchk> and <ve> are of opposite orientation.   
  TopTools_ListIteratorOfListOfShape itchk(EdsToCheck);
  for (; itchk.More(); itchk.Next()) {

    const TopoDS_Edge& Echk = TopoDS::Edge(itchk.Value());    
    Standard_Integer Ivfaulty=0; Standard_Boolean faulty = EdgeWithFaultyUV(Echk,Ivfaulty);
    if (!faulty) continue;
    Standard_Integer nfyv = (Ivfaulty == 3)? 2 : 1;

#ifdef DEB
    ifault++; 
    if (trc) cout<<"e"<<STATIC_PURGE_mapeds.FindIndex(Echk)<<" has ifyv="<<Ivfaulty<<endl;
#ifdef DRAW
    if (trc) {TCollection_AsciiString aa("fault"); FUN_tool_draw(aa,Echk,ifault);}
#endif
#endif

    Standard_Boolean found = Standard_False;
    if      (nfybounds == 1) found = (nfyv == nfybounds);
    else if (nfybounds == 2) found = (nfyv == nfybounds);
    else if (nfybounds == 3) found = (nfyv > 0);

    if (found) { 
      FyEds.Bind(Echk,Ivfaulty);
      if (stopatfirst) return Standard_True;
    }
  } // itchk
  Standard_Integer n = FyEds.Extent(); // DEB
  return (n != 0);   
}

//=======================================================================
//function : EdgeWithFaultyUV
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::EdgeWithFaultyUV(const TopTools_ListOfShape& EdsToCheck, const Standard_Integer nfybounds,
					     TopoDS_Shape& fyE, Standard_Integer& Ifaulty) const 
{
  TopTools_DataMapOfOrientedShapeInteger FyEds;
  Standard_Boolean found = EdgesWithFaultyUV(EdsToCheck,nfybounds,FyEds,Standard_True);
  if (!found) return Standard_False;

  TopTools_DataMapIteratorOfDataMapOfOrientedShapeInteger itm(FyEds);
  fyE = itm.Key();
  Ifaulty = itm.Value();
  return Standard_True;
}

//=======================================================================
//function : TrslUV
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::TrslUV(const Standard_Boolean onU, const TopTools_DataMapOfOrientedShapeInteger& FyEds)
{
  gp_Vec2d tt2d; 
  if (onU) {Standard_Real uper;
            Refclosed(1,uper);
            if (!uper) return Standard_False;
	    tt2d = gp_Vec2d(uper,0.);}
  else     {Standard_Real vper;
            Refclosed(2,vper);
            if (!vper) return Standard_False;
	    tt2d = gp_Vec2d(0.,vper);}
  TopTools_DataMapIteratorOfDataMapOfOrientedShapeInteger itm(FyEds);
  for (; itm.More(); itm.Next()){
    const TopoDS_Edge& E = TopoDS::Edge(itm.Key());
    TopOpeBRepTool_C2DF C2DF; Standard_Boolean isb = UVRep(E,C2DF);
    if (!isb) return Standard_False;

    Standard_Integer itt = itm.Value();
    if      (itt == SPLITEDGE) return Standard_False;
    else if (itt == INCREASE) TopOpeBRepTool_TOOL::TrslUV(tt2d,C2DF);
    else if (itt == DECREASE) TopOpeBRepTool_TOOL::TrslUV(tt2d.Multiplied(-1.),C2DF);
    else return Standard_False;
    SetUVRep(E,C2DF);
  }
  return Standard_True;
}

// modif in BRep_Builder031298
/*static void FUN_tool_correctdgE(const TopoDS_Edge& E)
{
  const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
  BRep_ListOfCurveRepresentation& lcr = TE->ChangeCurves();
  BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
  while (itcr.More()) {
    Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
    if (!GC.IsNull()) {
      if (GC->IsCurve3D()) lcr.Remove(itcr);
      else itcr.Next();
    }
  }
}*/

//=======================================================================
//function : GetnewS
//purpose  : 
//=======================================================================

Standard_Boolean TopOpeBRepTool_CORRISO::GetnewS(TopoDS_Face& newS) const 
{
  newS.Nullify();
  if (myS.ShapeType() != TopAbs_FACE) return Standard_False;

  newS = TopoDS::Face(myS);
  BRep_Builder BB;

  TopTools_ListIteratorOfListOfShape it(myEds);
  for (; it.More(); it.Next()){
    TopoDS_Edge E = TopoDS::Edge(it.Value());   
    TopAbs_Orientation oriE = E.Orientation();
    TopOpeBRepTool_C2DF C2DF; Standard_Boolean isb = UVRep(E,C2DF);
    if (!isb) return Standard_False;

    Standard_Real f,l,tol;const Handle(Geom2d_Curve)& PC = C2DF.PC(f,l,tol);
    Handle(Geom2d_TrimmedCurve) cu = new Geom2d_TrimmedCurve(PC,f,l);
    
    TopoDS_Shape aLocalShape = E.Oriented(TopAbs::Complement(oriE));
    TopoDS_Edge Err = TopoDS::Edge(aLocalShape);
//    TopoDS_Edge Err = TopoDS::Edge(E.Oriented(TopAbs::Complement(oriE)));
    TopOpeBRepTool_C2DF C2DFrr; Standard_Boolean isclo = UVRep(Err,C2DFrr);
    
//    Standard_Boolean isdgE = BRep_Tool::Degenerated(E);
    // !BUC60380 : degenerated edge has a 3d curve !!, remove it
//    if (isdgE) {FUN_tool_correctdgE(E);}     
		
    if (isclo) {
      Standard_Real frr,lrr,tolrr;const Handle(Geom2d_Curve)& PCrr = C2DFrr.PC(frr,lrr,tolrr);
      Handle(Geom2d_TrimmedCurve) curr = new Geom2d_TrimmedCurve(PCrr,frr,lrr);
      if (M_FORWARD(oriE)) BB.UpdateEdge(E,cu,curr,newS,tol);
    }
    else BB.UpdateEdge(E,cu,newS,tol);
  }
  return Standard_True;
}

//=======================================================================
//function : AddNewConnexity
//purpose  : 
//=======================================================================

//Standard_Boolean TopOpeBRepTool_CORRISO::AddNewConnexity(const TopoDS_Vertex& V,
Standard_Boolean TopOpeBRepTool_CORRISO::AddNewConnexity(const TopoDS_Vertex& ,
                                                         const TopoDS_Edge& E)
{
  // <myERep2d> : 
  Standard_Boolean isb = myERep2d.IsBound(E);
  if (!isb) {
    Handle(Geom2d_Curve) PC; Standard_Real f,l,tol;
    Standard_Boolean hasold = FC2D_HasOldCurveOnSurface(E,myFref,PC);
    FC2D_HasNewCurveOnSurface(E,myFref,PC);
    PC = FC2D_EditableCurveOnSurface(E,myFref,f,l,tol);
    if (!hasold) FC2D_AddNewCurveOnSurface(PC,E,myFref,f,l,tol);
    if (PC.IsNull()) return Standard_False;
    TopOpeBRepTool_C2DF C2DF(PC,f,l,tol,myFref);
    myERep2d.Bind(E,C2DF);  
  }

  // <myEds> : 
  if (!isb) myEds.Append(E);

  // <myVEds> :
  TopExp_Explorer exv(E, TopAbs_VERTEX);
  for (; exv.More(); exv.Next()){
    const TopoDS_Vertex& v = TopoDS::Vertex(exv.Current()); 
    Standard_Boolean isbb = myVEds.IsBound(v);
    if (isbb) myVEds.ChangeFind(v).Append(E);
    else      {TopTools_ListOfShape loe; loe.Append(E); myVEds.Bind(v,loe);}
  }//exv
  return Standard_True;
  
}

//=======================================================================
//function : RemoveOldConnexity
//purpose  : 
//=======================================================================

//Standard_Boolean TopOpeBRepTool_CORRISO::RemoveOldConnexity(const TopoDS_Vertex& V,
Standard_Boolean TopOpeBRepTool_CORRISO::RemoveOldConnexity(const TopoDS_Vertex& ,
                                                            const TopoDS_Edge& E)
{
  // <myERep2d> :
  Standard_Boolean isb = myERep2d.IsBound(E);
  if (isb) myERep2d.UnBind(E);

  // <myEds> : 
  if (isb) {
    TopTools_ListIteratorOfListOfShape it(myEds);
    while (it.More()) {
      if (it.Value().IsEqual(E)) {myEds.Remove(it);break;}
      else                       it.Next();
    }
  }

  // <myVEds> :
  Standard_Boolean done = Standard_False;
  TopExp_Explorer exv(E, TopAbs_VERTEX);
  for (; exv.More(); exv.Next()){
    const TopoDS_Vertex& v = TopoDS::Vertex(exv.Current()); 
    Standard_Boolean isb = myVEds.IsBound(v); 
    if (!isb) return Standard_False;
    TopTools_ListOfShape& loe = myVEds.ChangeFind(v);
    TopTools_ListIteratorOfListOfShape ite(loe);
    while (ite.More()) {
      if (ite.Value().IsEqual(E)) {done = Standard_True; loe.Remove(ite);break;}
      else                         ite.Next();
    }
  }//exv
  return done;
}