summaryrefslogtreecommitdiff
path: root/src/TestTopOpe/TestTopOpe_HDSCommands.cxx
blob: 4e88adf51a32e8c1f1c1083845a9b502e9dcbafd (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
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
// File:	TestTopOpe_HDSCommands.cxx
// Created:	Mon Oct 24 10:33:48 1994
// Author:	Jean Yves LEBEY
//		<jyl@bravox>

#ifdef HAVE_CONFIG_H
# include <oce-config.h>
#endif
#include <TestTopOpe.hxx>
#include <TestTopOpe_HDSDisplayer.hxx>
#include <TestTopOpeDraw_DrawableSHA.hxx>
#include <TestTopOpeDraw_DrawableP3D.hxx>
#include <TestTopOpeDraw_DrawableC3D.hxx>
#include <TestTopOpeDraw_TTOT.hxx>
#include <TestTopOpeDraw_Displayer.hxx>
#include <TopOpeBRepDS_connex.hxx>
#include <TopOpeBRepDS_Point.hxx>
#include <TopOpeBRepDS_Curve.hxx>
#include <TopOpeBRepDS_PointIterator.hxx>
#include <TopOpeBRepDS_PointExplorer.hxx>
#include <TopOpeBRepDS_CurveExplorer.hxx>
#include <TopOpeBRepDS_Explorer.hxx>
#include <TopOpeBRepDS_TKI.hxx>
#include <TopOpeBRepDS_Check.hxx>
#include <TopOpeBRepDS_Dumper.hxx>
#include <TopOpeBRepDS.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <TopLoc_Location.hxx>
#include <Geom_Curve.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <GeomAbs_CurveType.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <GeomAbs_SurfaceType.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <TColStd_ListOfInteger.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <TopOpeBRepDS_define.hxx>
#include <DBRep.hxx>
#include <Draw_Appli.hxx>
#include <DrawTrSurf_Curve.hxx>
#include <Draw_Interpretor.hxx>
#include <DrawTrSurf.hxx>

#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif

class TSEEpar {
public:
  TSEEpar(const TCollection_AsciiString& s) { set(s); }
  void set(const TCollection_AsciiString& s) {
    miskind = misshap = misgeom = missect = misdege = misafev = misedcu = Standard_False; 
    mTK = TopOpeBRepDS_UNKNOWN; mTS = TopAbs_SHAPE;
    char* sK = (char *)s.ToCString();
    miskind = TestTopOpeDraw_TTOT::StringToKind(s,mTK);
    if ( miskind ) {
      misshap = TopOpeBRepDS::IsTopology(mTK);
      if (misshap) mTS = TopOpeBRepDS::KindToShape(mTK);
      else misgeom = TopOpeBRepDS::IsGeometry(mTK);
    }
    else if ( ! strcasecmp(sK,"s") ) {
      misshap = Standard_True; mTS = TopAbs_SHAPE;
    }
    else if ( ! strcasecmp(sK,"se") ) {
      missect = Standard_True; mTK = TopOpeBRepDS_EDGE;
    }
    else if ( ! strcasecmp(sK,"de") ) {
      misdege = Standard_True; mTK = TopOpeBRepDS_EDGE;
    }
    else if ( ! strcasecmp(sK,"fev") ) {
      misafev = Standard_True;
    }
    else if ( ! strcasecmp(sK,"ec") ) {
      misedcu = Standard_True;
    }
  }
  Standard_Boolean iskind() { return miskind;}
  Standard_Boolean isshap() { return misshap;}
  Standard_Boolean isgeom() { return misgeom;}
  Standard_Boolean issect() { return missect;}
  Standard_Boolean isdege() { return misdege;}
  Standard_Boolean isafev() { return misafev;}
  Standard_Boolean isedcu() { return misedcu;}
  TopOpeBRepDS_Kind TK() {return mTK;}
  TopAbs_ShapeEnum TS() {return mTS;}
private:
  Standard_Boolean miskind,misshap,misgeom,missect,misdege,misafev,misedcu;
  TopOpeBRepDS_Kind mTK; TopAbs_ShapeEnum mTS;
};

class TDSpar : public TSEEpar {
public:
  TDSpar(const TCollection_AsciiString& s) : TSEEpar(s) {}
};

#define ISINTEGER(MMstr) ((strspn((MMstr),"0123456789") == strlen((MMstr))))

Standard_EXPORT TestTopOpe_HDSDisplayer* PHDSD = NULL;
Standard_EXPORT TestTopOpeDraw_Displayer* POCD = NULL;
//Standard_IMPORT extern Standard_Integer TopOpeBRepDS_GLOBALHDSinterfselector;
Standard_IMPORT Standard_Integer TopOpeBRepDS_GLOBALHDSinterfselector;

static Standard_Boolean SFindKeep = Standard_False;
static Standard_Boolean GFindKeep = Standard_False;
static Standard_Boolean PrintDistancePP = Standard_False;
static Standard_Integer SelectRankShape = 0;
static Standard_Boolean DisOri = Standard_False;
static Standard_Boolean TolFlag = Standard_False;
static Standard_Real OldParFlag = -1.0;
static Standard_Real ParFlag = -1.0;

class tsee_entity {
public:
  Standard_Boolean myEOK;
  TestTopOpe_HDSDisplayer* myEPHDSD;
  Handle(TopOpeBRepDS_HDataStructure) myEHDS; TopOpeBRepDS_DataStructure *myEPDS;
  TopOpeBRepDS_Kind myETK;TopAbs_ShapeEnum myETS;Standard_Integer myEindex;
  Standard_Boolean myEiskind,myEisshape,myEisgeome,myEissect;
  TCollection_AsciiString myEnamedbrep,myEnamedisp; Draw_ColorKind myEnamecolor;
  
//JR/Hp :
  tsee_entity() {
//  tsee_entity::tsee_entity() {
    myEOK = Standard_False;
    if (PHDSD == NULL) return; myEPHDSD = PHDSD;
    myEHDS = myEPHDSD->CurrentHDS(); myEPDS = (TopOpeBRepDS_DataStructure*)&myEHDS->ChangeDS();  
    myETK = TopOpeBRepDS_UNKNOWN;myETS = TopAbs_SHAPE; myEindex = 0;
    myEiskind = myEisshape = myEisgeome = myEissect = Standard_False;
    myEnamedbrep = ""; myEnamedisp = ""; myEnamecolor = Draw_blanc;
    myEOK = Standard_True;
  }
  
  Standard_Boolean IsP() const { return (myETK == TopOpeBRepDS_POINT); }
  Standard_Boolean IsV() const { return (myETK == TopOpeBRepDS_VERTEX); }
  Standard_Boolean Is0() const { return IsP() || IsV(); }
  Standard_Integer Set(Standard_Integer na,const char** a,Standard_Integer iargK,Standard_Integer iargI);
  void Delete() ;
  Standard_EXPORT virtual ~tsee_entity() {Delete() ;} ;
  void virtual Dump() const;
  void virtual See() = 0;
};

void tsee_entity::Delete()
{}

Standard_Integer tsee_entity::Set(Standard_Integer na,const char** a,Standard_Integer iargK,Standard_Integer iargI) {
  myEOK = Standard_False;
  if (iargK>=na) return 1; if (iargI>=na) return 1;
  TCollection_AsciiString ascK = a[iargK]; myEindex = atoi(a[iargI]);
  myEiskind = TestTopOpeDraw_TTOT::StringToKind(ascK,myETK);
  if (!myEiskind) return 1; if (myETK == TopOpeBRepDS_UNKNOWN) return 1;
  
  myEisshape = TopOpeBRepDS::IsTopology(myETK);
  if (myEisshape) {
    if ((myEindex < 1) || (myEindex > myEPDS->NbShapes())) return 0;
    myETS = TopOpeBRepDS::KindToShape(myETK);
    const TopoDS_Shape& S = myEPDS->Shape(myEindex);
    if (myETS != S.ShapeType()) return 0;
    myEPHDSD->ShapeName(myEindex,S,myEnamedbrep);
    myEPHDSD->ShapeDisplayName(myEindex,S,myEnamedisp);
  }
  
  myEisgeome = TopOpeBRepDS::IsGeometry(myETK);
  if (myEisgeome) {
    if (IsP()) {
      TopOpeBRepDS_PointExplorer pex(myEHDS->DS());
      if (!pex.IsPoint(myEindex)) return 1;
    }
    TestTopOpeDraw_TTOT::GeometryName(myEindex,myETK,myEnamedbrep);
    myEPHDSD->GeometryDisplayName(myEindex,myETK,myEnamedisp);
  }
  
  myEnamecolor = TestTopOpeDraw_TTOT::GeometryColor(myETK);
  myEOK = Standard_True;
  return 0;
}

void tsee_entity::Dump() const { 
  TopOpeBRepDS_Dumper Dumper(myEHDS);
  if (myEisgeome) Dumper.DumpGeometry(myETK,myEindex,cout);
  if (myEisshape) Dumper.DumpTopology(myETK,myEindex,cout);
}

class tsee_entity0 : public tsee_entity {
public:
  
  gp_Pnt Pnt() const;  
  void See();
  
};

gp_Pnt tsee_entity0::Pnt() const
{
  if (!Is0()) Standard_Failure("not 0d");
  gp_Pnt P; 
  if      (IsP()) P = myEPDS->Point(myEindex).Point();
  else if (IsV()) P = BRep_Tool::Pnt(TopoDS::Vertex(myEPDS->Shape(myEindex)));
  return P;
}

static void SetPoint
(const TCollection_AsciiString& namedbrep,const TCollection_AsciiString& namedisp,const Draw_Color& namecolor,const TopOpeBRepDS_Point& P)
{
  Handle(TestTopOpeDraw_DrawableP3D) D;
  if(TolFlag) {
    D = new TestTopOpeDraw_DrawableP3D(P.Point(),Draw_CircleZoom,namecolor,
					 namedisp.ToCString(),namecolor,
					 P.Tolerance());
  } else {
    D = new TestTopOpeDraw_DrawableP3D(P.Point(),Draw_Square,namecolor,
					 namedisp.ToCString(),namecolor);
  }
  char *pname = (char *)namedbrep.ToCString();
  Draw::Set(pname,Handle(Draw_Marker3D)::DownCast(D));
  
}
void tsee_entity0::See() 
{
  if (IsP()) ::SetPoint(myEnamedbrep,myEnamedisp,myEnamecolor,myEPDS->Point(myEindex));
  if (IsV()) POCD->DisplayShape(myEnamedbrep,myEnamedisp,myEPDS->Shape(myEindex));
}

//-----------------------------------------------
static void SetCurve
//-----------------------------------------------
(const TCollection_AsciiString& namedbrep,
 const TCollection_AsciiString& namedisp,
 const Draw_Color& namecolor,
 const TopOpeBRepDS_Curve& DSC,
 const Standard_Integer iC)
{
  if ( !PHDSD ) return;
  const Handle(Geom_Curve) GC = DSC.Curve();
  if ( GC.IsNull() ) { cout<<"Curve() nulle"<<endl; return; }
  
  Standard_Real f = GC->FirstParameter();
  Standard_Real l = GC->LastParameter();
  
  GeomAdaptor_Curve GAC(GC);
  GeomAbs_CurveType GACt = GAC.GetType();
  if ( GACt == GeomAbs_Line ) {
    Standard_Real fline = RealLast(),lline = RealFirst(); 
    Standard_Integer imother = DSC.Mother(),igood;
    if(imother) igood = imother;
    else        igood = iC;
    TopOpeBRepDS_PointIterator it = PHDSD->CurrentHDS()->CurvePoints(igood);
    for(; it.More(); it.Next()) {
      Standard_Real p = it.Parameter();
      fline = Min(fline,p); lline = Max(fline,p);
    }
    f = fline;
    l = lline;
  }
  
  Handle(Geom_TrimmedCurve) GTC = new Geom_TrimmedCurve(GC,f,l);
  Handle(TestTopOpeDraw_DrawableC3D) D;
  D = new TestTopOpeDraw_DrawableC3D(GTC,namecolor,namedisp.ToCString(),namecolor);
  char *pname = (char *)namedbrep.ToCString();
  Draw::Set(pname,Handle(DrawTrSurf_Curve)::DownCast(D));
}

static TopoDS_Shape bidbid;
static const TopoDS_Shape& GetShape(const Standard_Integer IS,const TopAbs_ShapeEnum TS)
{
  Standard_Boolean TypeControl = Standard_True;
  if ( !PHDSD ) return bidbid;
  
  static TopoDS_Shape ShapeNull;
  const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
  
  // check on shape index and on shape kind if kind differs from TopAbs_SHAPE
  Standard_Integer ns = BDS.NbShapes();
  if ( IS < 1 || IS > ns) {
    TopAbs::Print(TS,cout);cout<<" "<<IS<<" does not exist in DS"<<endl;
    return ShapeNull;
  }
  else if ( !PHDSD->ShapeKind(IS,TS) ) {
    if ( TypeControl ) {
      cout<<"Shape "<<IS;
      cout<<" is not a ";TopAbs::Print(TS,cout);
      cout<<" but a "; TopAbs::Print(BDS.Shape(IS,SFindKeep).ShapeType(),cout);
      cout<<endl;
    }
    return ShapeNull;
  }
  
  const TopoDS_Shape& S = BDS.Shape(IS,SFindKeep);  
  return S;
}

static const TopoDS_Shape& GetShape(const Standard_Integer IS)
{
  if ( !PHDSD ) return bidbid;
  const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
  const TopoDS_Shape& S = BDS.Shape(IS);
  return S;
}

#ifdef DEB
static const TopoDS_Shape& GetShapeSameDomain
(const Standard_Integer IS,const TopAbs_ShapeEnum TS,const TCollection_AsciiString& pre = "");

//-----------------------------------------------------------------------
// GetShapeSameDomain IS = shape index,TS = shape kind
//-----------------------------------------------------------------------
static const TopoDS_Shape& GetShapeSameDomain(const Standard_Integer IS,const TopAbs_ShapeEnum TS,const TCollection_AsciiString& pre)
{
  Standard_Boolean TypeControl = Standard_True;
  if ( !PHDSD ) return bidbid;
  
  static TopoDS_Shape ShapeNull;
  const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
  const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
  
  // check on shape index and on shape kind if kind differs from TopAbs_SHAPE
  Standard_Integer ns = BDS.NbShapes();
  if ( IS < 1 || IS > ns) {
    TopAbs::Print(TS,cout);cout<<" "<<IS<<" does not exist in DS"<<endl;
    return ShapeNull;
  }
  else if ( !PHDSD->ShapeKind(IS,TS) ) {
    if ( TypeControl ) {
      cout<<"Shape "<<IS<<" is not a ";TopAbs::Print(TS,cout);
      cout<<" but a ";TopAbs::Print(BDS.Shape(IS,SFindKeep).ShapeType(),cout);
      cout<<endl;
    }
    return ShapeNull;
  }
  else if ( !HDS->HasSameDomain(HDS->Shape(IS,SFindKeep)) ) {
    if ( TypeControl ) cout<<"Shape "<<IS<<" is not HasSameDomain"<<endl;
    return ShapeNull;
  }
  
  // shape index <IS> ok : get shape <S> of index <IS>
  const TopoDS_Shape& S = BDS.Shape(IS,SFindKeep);
  TopOpeBRepDS_Dumper Dumper(HDS);
  TCollection_AsciiString sse = Dumper.SPrintShape(S);
  TCollection_AsciiString sor = TopOpeBRepDS::SPrint(S.Orientation());
  TCollection_AsciiString str;str=str+pre+sse+" is "+sor+"\n";
  cout<<str;cout.flush();
  
  return S;
}
#endif

//-----------------------------------------------------------------------
// SeeSectionEdge
//-----------------------------------------------------------------------
static Standard_Integer SeeSectionEdge(const Standard_Integer ISE)
{
  if ( !PHDSD || !POCD ) return 0;
  
  Standard_Integer nse = PHDSD->CurrentBDS().NbSectionEdges();
  if ( ISE < 1 || ISE > nse ) return 0;
  const TopoDS_Shape& SE  = PHDSD->CurrentBDS().SectionEdge(ISE);
  if (SE.IsNull()) return 0;
  PHDSD->CurrentBDS().Shape(SE,SFindKeep);
  
  TCollection_AsciiString namedbrep; PHDSD->SectionEdgeName(ISE,SE,namedbrep); 
  TCollection_AsciiString namedisp; PHDSD->SectionEdgeDisplayName(ISE,SE,namedisp);
  POCD->DisplayGeometry(Standard_True);
  POCD->DisplayShape(namedbrep,namedisp,SE);
  return 0;
}

//-----------------------------------------------------------------------
// SeeShapeIS
//-----------------------------------------------------------------------
Standard_Integer SeeShapeIS(const Standard_Integer I,const TopoDS_Shape& S)
{
  if ( !PHDSD || !POCD) return 0;
  
  if (S.IsNull()) return 0;  
  TCollection_AsciiString namedbrep; PHDSD->ShapeName(I,S,namedbrep);
  TCollection_AsciiString namedisp = namedbrep;
  // NameDisplay = *name/name* if S subshape of shape1/shape2
  TCollection_AsciiString ast = "*";
  const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
  // if the Shape was removed from the DS, "*" is replaced by "~"
  if(!BDS.HasShape(S))
    ast = "~";
  Standard_Boolean of1 = PHDSD->SubShape(S,1);if(of1) namedisp = ast+namedisp;
  Standard_Boolean of2 = PHDSD->SubShape(S,2);if(of2) namedisp = namedisp+ast;
  if (SelectRankShape == 1 && !of1) return 0;
  if (SelectRankShape == 2 && !of2) return 0;
  
  if (S.ShapeType()==TopAbs_EDGE) POCD->DisplayGeometry(Standard_True);
  else POCD->DisplayGeometry(DisOri);
  if((S.ShapeType()==TopAbs_VERTEX) && TolFlag) {
    const TopoDS_Vertex& V = TopoDS::Vertex(S);
    Standard_Real Tol = BRep_Tool::Tolerance(V);
    POCD->SetTol(Tol);
  }
  POCD->DisplayShape(namedbrep,namedisp,S);
  
  return 0;
}


//-----------------------------------------------------------------------
// SeeShape
//-----------------------------------------------------------------------
static Standard_Integer SeeShape(TCollection_AsciiString namedbrep)
{
  if ( !PHDSD || !POCD ) return 0;
  
  const char* pname = (const char *)namedbrep.ToCString();
  TopoDS_Shape S = DBRep::Get(pname);
  if ( S.IsNull() ) return 0;
  TCollection_AsciiString namedisp; 
  PHDSD->ShapeDisplayName(namedbrep,S,namedisp);
  POCD->DisplayShape(namedbrep,namedisp,S);
  return 0;
}

//-----------------------------------------------------------------------
// SeePoint
//-----------------------------------------------------------------------
static Standard_Integer SeePoint(const Standard_Integer I)
{
  if ( !PHDSD ) return 0;
  
  const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
  if (I < 1 || I > BDS.NbPoints()) return 0;
  
  TopOpeBRepDS_PointExplorer pex(BDS);
  Standard_Boolean isp = pex.IsPoint(I);
  if (!isp) return 0;
  
  const TopOpeBRepDS_Point& P = BDS.Point(I);
  TopOpeBRepDS_Kind K = TopOpeBRepDS_POINT;
  TCollection_AsciiString namedbrep; TestTopOpeDraw_TTOT::GeometryName(I,K,namedbrep);
  TCollection_AsciiString namedisp; PHDSD->GeometryDisplayName(I,K,namedisp);
  Draw_ColorKind namecolor = TestTopOpeDraw_TTOT::GeometryColor(K);
  SetPoint(namedbrep,namedisp,namecolor,P);
  return 0;
}

//-----------------------------------------------------------------------
// SeeCurve
//-----------------------------------------------------------------------
static Standard_Integer SeeCurve(const Standard_Integer I)
{
  if ( !PHDSD ) return 0;
  
  const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
  if (I < 1 || I > BDS.NbCurves()) return 0;
  
  TopOpeBRepDS_CurveExplorer cex(BDS,GFindKeep);
  Standard_Boolean isc = cex.IsCurve(I);
  if (!isc) return 0;
  
  const TopOpeBRepDS_Curve& C = BDS.Curve(I);
  TopOpeBRepDS_Kind K = TopOpeBRepDS_CURVE;
  TCollection_AsciiString namedbrep; TestTopOpeDraw_TTOT::GeometryName(I,K,namedbrep);
  TCollection_AsciiString namedisp; PHDSD->GeometryDisplayName(I,K,namedisp);
  Draw_ColorKind namecolor = TestTopOpeDraw_TTOT::GeometryColor(K);
  SetCurve(namedbrep,namedisp,namecolor,C,I);
  return 0;
}


//-----------------------------------------------------------------------
// SeeSurface NYI
//-----------------------------------------------------------------------
Standard_Integer SeeSurface(const Standard_Integer I) // NYI
{
  if ( !PHDSD ) return 0;
  
  const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
  if (I < 1 || I > BDS.NbSurfaces()) return 0;
  return 0;
}

//-----------------------------------------------------------------------
// SeeEdgeCurve
//-----------------------------------------------------------------------
static Standard_Integer SeeEdgeCurve(const Standard_Integer IE,const TopoDS_Shape& SE)
{
  if ( !POCD ) return 0;
  
  if (SE.IsNull()) return 0;
  const TopoDS_Edge& E = TopoDS::Edge(SE);
  TopLoc_Location L;Standard_Real f,l;Handle(Geom_Curve) GC=BRep_Tool::Curve(E,L,f,l);  
  TCollection_AsciiString namedbrep="E";TestTopOpeDraw_TTOT::CatCurveName(IE,namedbrep);
  TCollection_AsciiString namedisp="E";TestTopOpeDraw_TTOT::CatCurveDisplayName(IE,GC,namedisp);
  POCD->DisplayGeometry(Standard_True);
  POCD->DisplayShape(namedbrep,namedisp,SE);
  return 0;
}

//-----------------------------------------------------------------------
// SeeGeometry
//-----------------------------------------------------------------------
static Standard_Integer SeeGeometry(const Standard_Integer IG,const TopOpeBRepDS_Kind TK)
{ 
  if      (TK == TopOpeBRepDS_POINT) return SeePoint(IG);
  else if (TK == TopOpeBRepDS_CURVE) return SeeCurve(IG);
  else if (TK == TopOpeBRepDS_SURFACE) return SeeSurface(IG);
  return 0;
}

//-----------------------------------------------------------------------
// SeeGeometry
//-----------------------------------------------------------------------
// Unused :
#ifdef DEB
static Standard_Integer SeeGeometry(const tsee_entity& E) 
{ 
  if (!E.myEOK) return 0; 
  return SeeGeometry(E.myEindex,E.myETK);
}
#endif

//-----------------------------------------------------------------------
// SeeGeometry
//-----------------------------------------------------------------------
static Standard_Integer SeeGeometry(const TopOpeBRepDS_Kind TK)
{
  if ( !PHDSD ) return 0; 
  
  const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();

  if      (TK == TopOpeBRepDS_POINT) {
    TopOpeBRepDS_PointExplorer pex(BDS,GFindKeep);
    for (; pex.More(); pex.Next()) {
      Standard_Integer ig = pex.Index();
      SeeGeometry(ig,TK);
    }
  }
  else if (TK == TopOpeBRepDS_CURVE) {
    TopOpeBRepDS_CurveExplorer cex(BDS,GFindKeep);
    for (; cex.More(); cex.Next()) {
      Standard_Integer ig = cex.Index();
      SeeGeometry(ig,TK);
    }
  }
  else if (TK == TopOpeBRepDS_SURFACE) { //NYI
  }
  return 0;
}

//-----------------------------------------------------------------------
// TOPOPE_SeeShape
//-----------------------------------------------------------------------
Standard_Integer TOPOPE_SeeShape(char* name)
{
  TCollection_AsciiString asc = name;
  Standard_Integer res = SeeShape(asc);
  return res;
}

//-----------------------------------------------------------------------
// decalargs : shift a[*] from <-d>,modify na = na - deca
//-----------------------------------------------------------------------
// Unused :
#ifdef DEB
static void decalargs(Standard_Integer& na,const char** a,const Standard_Integer d) 
{for(Standard_Integer i=1;i<na;i++)a[i]=a[i+d];na-=d;}
#endif

//-----------------------------------------------------------------------
// suppressarg : remove a[d],modify na--
//-----------------------------------------------------------------------
Standard_EXPORT void suppressarg(Standard_Integer& na,const char** a,const Standard_Integer d) 
{
  for(Standard_Integer i=d;i<na;i++) {
    a[i]=a[i+1];
    a[i+1]=NULL;
  }
  na--;
}

//-----------------------------------------------------------------------
// suppressargs : remove a[*] from <f> to <l>,modify na = na - (l - f)
//-----------------------------------------------------------------------
Standard_EXPORT void suppressargs(Standard_Integer& na,const char** a,const Standard_Integer f,const Standard_Integer l) 
{
  if(l == f) 
    suppressarg(na,a,l);
  if(l <= f) return;
  for(Standard_Integer i=0;i<na-l;i++) {
    a[i+f]=a[i+l+1];
    a[i+l+1]=NULL;
  }
  na -= l-f+1;
}

//-----------------------------------------------------------------------
// SetTolFlag
//-----------------------------------------------------------------------
// Unused :
#ifdef DEB
static Standard_Boolean SetTolFlag(Standard_Integer& na,const char** a) { decalargs(na,a,1); return Standard_True; }
#endif

//-----------------------------------------------------------------------
// tsee_flags
//-----------------------------------------------------------------------
static void tsee_flags(Standard_Integer& na,const char** a) {
  GFindKeep = Standard_False;
  PrintDistancePP = Standard_False;
  SelectRankShape = 0;
  
  for (Standard_Integer ia = 1; ia < na; ia++) {
    if (!strcasecmp(a[ia],"-k")) { 
      suppressarg(na,a,ia);
      GFindKeep = Standard_True;
    }
    else if (!strcasecmp(a[ia],"-d")) { 
      // tsee -d p 4 7 : display p_4,p_7 + tds p 4 7 + calculate distance (p_4,p_7)
      suppressarg(na,a,ia);
      PrintDistancePP = Standard_True;
    }
    else if (!strcasecmp(a[ia],"-1")) { 
      // tsee -1 s 4 : display s_4 <=> s_4 is subshape of the 1st argument
      suppressarg(na,a,ia);
      SelectRankShape = 1;
    }
    else if (!strcasecmp(a[ia],"-2")) { 
      // tsee -2 s 4 : display s_4 <=> s_4 is subshape of the 2nd argument
      suppressarg(na,a,ia);
      SelectRankShape = 2;
    }
    else if (!strcasecmp(a[ia],"-p") && (ia < na-1)) {
      suppressargs(na,a,ia,ia+1);
      Standard_Real t = atof(a[ia+1]);
      if (t >= 0. && t <= 1.) {
	OldParFlag = ParFlag; ParFlag = t;
      }
    }
  }
}

void OthersCommands_help(const char* CommandName,const char* syntaxe = "");
//-----------------------------------------------------------------------
// tsee_help
//-----------------------------------------------------------------------
static void tsee_help(const char* CommandName, Draw_Interpretor& di)
{
  di<<""<<"\n";
  di<<"tsee : Draw entities of data structure (DS) loaded by TestTopOpe::CurrentDS()."<<"\n";
  di<<"DS entities are shapes and geometries accessed by a <type> and an <index>."<<"\n";
  di<<"basic usage :"<<"\n";
  di<<"              tsee <type> <index1 index2 ...>"<<"\n";
  di<<"<type>  = so sh f w e v s for solid/shell/face/wire/edge/vertex/shape"<<"\n";
  di<<"          su cu p for surface/curve/point (N.B : su is NYI)"<<"\n";
  di<<"<index> = integer"<<"\n";
  di<<"example : 'tsee e 3' will draw the edge of index 3"<<"\n";
  di<<"          'tsee e 3 6' will draw the edges of index 3 and 6"<<"\n";
  di<<"          'tsee e' will draw all the edges."<<"\n";
  di<<""<<"\n";
  di<<"Index values of DS entities may be given by the 'tds' command which prints"<<"\n";
  di<<"the content of the DS for each shape and geometry type."<<"\n";
  di<<"Entities are drawn with a specific color according to their type."<<"\n";
  di<<""<<"\n";
  di<<"Naming : "<<"\n";
  di<<"'tsee <t> <i>' creates the drawable object named <t>_<i>."<<"\n";
  di<<"This name is displayed near the entity in one if the forms : "<<"\n";
  di<<"     *<t>_<i> meaning entity belongs to the first shape of current operation."<<"\n";
  di<<"     <t>_<i>* meaning entity belongs to the second shape of current operation."<<"\n";
  di<<""<<"\n";
  di<<"Same Domain shapes : "<<"\n";
  di<<"'tsee <type> sd' to display all shapes of <type> having same domain data."<<"\n";
  di<<"example : 'tsee e sd' to display all edges sharing a 1d geometric domain"<<"\n";
  di<<"          with other edges."<<"\n";
  di<<""<<"\n";
  di<<"Optional flags :"<<"\n";
  OthersCommands_help(CommandName);
  di<<"Other types :"<<"\n";
  di<<"'tsee fev' : displays all faces,then edges,then vertices."<<"\n";
  di<<"'tsee es <i>' displays edge described as section edge <i>."<<"\n";
  di<<"      The name of a section edge likes t_i<j>,where :"<<"\n";
  di<<"         - i is the edge index in the set of section edge,"<<"\n";
  di<<"         - j is edge index in the DS (as any edge)."<<"\n";
  di<<""<<"\n";
}

static void tseei_help(Draw_Interpretor& di)
{
  di<<""<<"\n";
  di<<"tseei : Draws entities of data structure (DS) loaded by TestTopOpe::CurrentDS()."<<"\n";
  di<<"Draws the objects appearing in interferences DS objects."<<"\n";
  di<<"See command 'tsee' for discussion about DS objects."<<"\n";
  di<<"\n";
}

static void tki_help(Draw_Interpretor& di)
{
  di<<""<<"\n";
  di<<"tki,tkig,tkis : Groups interferences of DS objects"<<"\n";
  di<<"  by geometry (g),or support (s),and index."<<"\n";
  di<<"See command 'tsee' for discussion about DS objects."<<"\n";
  di<<"(Test of class TopOpeBRepDS_TKI)"<<"\n";
  di<<"\n";
}

static void tds_help(Draw_Interpretor& di)
{
  di<<""<<"\n";
  di<<"tds : dump current DS (loaded by CurrentDS())"<<"\n";
  di<<"basic usage : tds <-arg> type <index1 index2 ...>"<<"\n";
  di<<"\n";
  di<<"Description of curve geometry (type = c) : <-arg>  = -t -k -s -l"<<"\n";
  di<<"\t-k : print only the curve with keep = Standard_True"<<"\n";
  di<<"\t-l : (long) print all poles and knots for BSplines curves"<<"\n";
  di<<"\t-s : (short) print only 4 poles and 4 knots for BSplines curves"<<"\n";
  di<<"on shapes (type = s|so|sh|f|w|e|v) : <-arg>  = -ssi"<<"\n";
  di<<"\t-ssi : print only ShapeShapeInterferences"<<"\n";
  di<<""<<"\n";
  di<<"See command 'tsee' for discussion about type and <index1 index2 ...>."<<"\n";
  di<<"\n";
}

typedef Standard_Integer (*tf_SeeShape)(const Standard_Integer I,const TopoDS_Shape& S);
extern void OthersCommands_flags(Standard_Integer& na,const char** a,TestTopOpeDraw_Displayer& TD);
void COUTNOHDS(Draw_Interpretor& di) {di<<"no current HDS"<<"\n";}
Standard_Integer tsee_SeeShapefunc(Draw_Interpretor& di,Standard_Integer na_in,const char** a,tf_SeeShape SeeShapefunc)
{
  if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
    tsee_help(a[0], di);
    return 0; 
  }
  
  Standard_Integer na = na_in;
  if ((PHDSD == NULL) || (POCD == NULL)) return 0;
  
  const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
  if (HDS.IsNull()) { COUTNOHDS(di); return 0; }
  if (na < 2) return 1;
  const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
  
  POCD->InitDisplayer();
  TolFlag = Standard_False;
  tsee_flags(na,a);
  OthersCommands_flags(na,a,*POCD);
  TolFlag = POCD->TolIs();
  DisOri = POCD->DisplayGeometry();
  
  Standard_Integer i1arg = 1;
  TSEEpar Tpar(a[i1arg]);
  
//  Standard_Integer ia,is,ig;
  Standard_Integer ia,is;
  
  if ( PrintDistancePP ) {
    tsee_entity0 E1,E2;    
    if (na == 4) { // tsee p 3 4
      if (E1.Set(na,a,i1arg+0,i1arg+1)) return 1;
      if (E2.Set(na,a,i1arg+0,i1arg+2)) return 1;
    }
    else if (na == 5) { // tsee p 3 v 4
      if (E1.Set(na,a,i1arg+0,i1arg+1)) return 1;
      if (E2.Set(na,a,i1arg+2,i1arg+3)) return 1;
    }
    if (!E1.myEOK || !E2.myEOK) return 1;
    
    E1.See();E2.See();
    E1.Dump();E2.Dump();
    di<<"Distance "<<E1.myEnamedbrep.ToCString()<<" "<<E2.myEnamedbrep.ToCString()<<" : "<<E1.Pnt().Distance(E2.Pnt())<<"\n";
    
  } // PrintDistancePP
  
  else if ( Tpar.isshap() ) {
    // na == 2 : display all DS shapes of type TS
    // na  > 2 : display DS shapes of type TS of index atoi(a[2]..a[narg-1])
    if (na == 2 ) {
      TopOpeBRepDS_Explorer x(HDS,Tpar.TS(),Standard_False);
      for(;x.More();x.Next()) (*SeeShapefunc)(x.Index(),x.Current());
    }
    else {
      if ( !strcmp(a[i1arg+1],"sd") ) { // shapes HasSameDomain of type TS
	TopOpeBRepDS_Explorer x(HDS,Tpar.TS(),Standard_False);
	for (;x.More();x.Next()) {
	  Standard_Boolean isSsd = HDS->HasSameDomain(x.Current());
	  if (isSsd ) (*SeeShapefunc)(x.Index(),x.Current());
	}
      }
      else if (Tpar.isshap() && (Tpar.TS() == TopAbs_EDGE) && (na>=2) && POCD->ParIs()) {
	// see edges [4..na[ with of the name in t in [0..1] / range
	if (na == 2) {
	  TopOpeBRepDS_Explorer x(HDS,TopAbs_EDGE,Standard_False);
	  for (;x.More();x.Next()) (*SeeShapefunc)(x.Index(),x.Current());
	}
	else {
	  for (ia = i1arg+1; ia < na; ia++) { 
	    is = atoi(a[ia]);
	    (*SeeShapefunc)(is,GetShape(is,Tpar.TS()));
	  }
	}
	ParFlag = OldParFlag;
      }
      else {
	for (ia = i1arg+1; ia < na; ia++) { 
	  is = atoi(a[ia]);
	  (*SeeShapefunc)(is,GetShape(is,Tpar.TS()));
	}
      }
    }
  } // isshap
  
  else if ( Tpar.isgeom() ) { 
    // na == 2 : display all DS geometries of type TK
    // na  > 2 : display DS geometries of type TK index atoi(a[2])..a[narg-1])
    if (na == 2 ) SeeGeometry(Tpar.TK());
    else for (ia = i1arg+1; ia < na; ia++) SeeGeometry(Standard_Integer(atoi(a[ia])),Tpar.TK());
  }
  
  else if ( Tpar.isafev() ) {
    // faces then edges then vertices
    TopOpeBRepDS_Explorer x;
    for (x.Init(HDS,TopAbs_FACE,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
    for (x.Init(HDS,TopAbs_EDGE,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
    for (x.Init(HDS,TopAbs_VERTEX,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
  }
  
  else if ( Tpar.isedcu() ) {
    // na == 2 : display curves of all DS edges
    // na  > 2 : display curve of DS edges index atoi(a[2])..a[narg-1])
    if ( na == 2 ) {
      TopOpeBRepDS_Explorer x(HDS,TopAbs_EDGE,Standard_False);
      for (;x.More();x.Next()) SeeEdgeCurve(x.Index(),x.Edge());
    }
    else {
      for (ia = i1arg+1; ia < na; ia++) { 
	is = atoi(a[ia]);
	SeeEdgeCurve(is,GetShape(is,TopAbs_EDGE));
      }
    }
  }
  
  else if ( Tpar.issect() ) { // na=2 all section edges,na>2 section edges (a[2]..a[na-1])
    Standard_Integer ise,nse = BDS.NbSectionEdges(); 
    if (na == 2) for (ise = 1; ise<=nse; ise++) SeeSectionEdge(ise);
    else         for (ia = i1arg+1; ia<na; ia++) SeeSectionEdge(atoi(a[ia]));
  }

  else if (Tpar.isdege()) {      
    TopOpeBRepDS_Explorer x;
    for (x.Init(HDS,TopAbs_EDGE);x.More();x.Next()) {
      if (BRep_Tool::Degenerated(x.Edge())) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
    }
  }
  
  return 0;
} // tsee_SeeShapefunc

//-----------------------------------------------------------------------
// tsee
//-----------------------------------------------------------------------
Standard_Integer tsee(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
{
  if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
    tsee_help(a[0],di);
    return 0; 
  }
  tf_SeeShape ssf = (tf_SeeShape)SeeShapeIS;
  Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
  return r;
} // tsee

//-----------------------------------------------------------------------
// SeeAnyKI
//-----------------------------------------------------------------------
Standard_Integer SeeAnyKI(const TopOpeBRepDS_Kind TK,const Standard_Integer I) {
#ifndef DEB
  TopAbs_ShapeEnum TS = TopAbs_COMPOUND;
#else
  TopAbs_ShapeEnum TS;
#endif
  Standard_Boolean isshape,isgeome; isshape = isgeome = Standard_False;
  isshape = TopOpeBRepDS::IsTopology(TK);
  if (isshape) TS = TopOpeBRepDS::KindToShape(TK);
  else isgeome = TopOpeBRepDS::IsGeometry(TK);
  if      (isshape) SeeShapeIS(I,GetShape(I,TS));
  else if (isgeome) SeeGeometry(I,TK);
  return 0;
}

//-----------------------------------------------------------------------
void AddShapeKI
//-----------------------------------------------------------------------
(TColStd_ListOfInteger& LOK,TColStd_ListOfInteger& LOI,
 const TopOpeBRepDS_Kind K,const Standard_Integer I)
{
  Standard_Boolean isshape,isgeome; isshape = isgeome = Standard_False;
  isshape = TopOpeBRepDS::IsTopology(K);
  if (!isshape)
    isgeome = TopOpeBRepDS::IsGeometry(K);
  
  if (LOK.IsEmpty() && LOI.IsEmpty()) { 
    LOK.Append((Standard_Integer)K); LOI.Append(I); 
    return; 
  }
  
  // to sort, it is considered that : 
  // POINT == VERTEX,CURVE == EDGE,SURFACE == FACE
  
#ifdef DEB
  TopAbs_ShapeEnum SKtri;
#else
  TopAbs_ShapeEnum SKtri=TopAbs_COMPOUND;
#endif
  if (isshape) SKtri = TopOpeBRepDS::KindToShape(K);
  else if (isgeome) {
    if      (K == TopOpeBRepDS_POINT) SKtri = TopAbs_VERTEX; 
    else if (K == TopOpeBRepDS_CURVE) SKtri = TopAbs_EDGE; 
    else if (K == TopOpeBRepDS_SURFACE) SKtri = TopAbs_FACE; 
  }
  else return;
  
  TColStd_ListIteratorOfListOfInteger ITLOK(LOK);
  TColStd_ListIteratorOfListOfInteger ITLOI(LOI);
  Standard_Boolean equa = Standard_False;
  for (; ITLOK.More(),ITLOI.More(); ITLOK.Next(),ITLOI.Next()) {
//JR/Hp
    Standard_Integer ifK = ITLOK.Value() ;
    TopOpeBRepDS_Kind fK = (TopOpeBRepDS_Kind) ifK ;
    TopAbs_ShapeEnum fSK = TopOpeBRepDS::KindToShape(fK);
//    TopOpeBRepDS_Kind fK = (TopOpeBRepDS_Kind)ITLOK.Value(); TopAbs_ShapeEnum fSK = TopOpeBRepDS::KindToShape(fK);
    Standard_Integer fI = ITLOI.Value();
    if (SKtri == fSK && I == fI) {
      equa = Standard_True;
      break;
    }
    if (SKtri <= fSK) {
      LOK.InsertBefore((Standard_Integer)K,ITLOK);
      LOI.InsertBefore(I,ITLOI);
      break;
    }
  }
  if ( !ITLOK.More() && !equa) {
    LOK.Append((Standard_Integer)K);
    LOI.Append(I);
  }
}

//-----------------------------------------------------------------------
// SeeShapeISI
//-----------------------------------------------------------------------
Standard_Integer SeeShapeISI(const Standard_Integer I,const TopoDS_Shape& S,Draw_Interpretor& di)
{
  if ( !PHDSD ) return 0;
  const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
  if (S.IsNull()) return 0;  
  SeeShapeIS(I,S);
  
  TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
  const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
  const TopOpeBRepDS_ListOfInterference& LOI = BDS.ShapeInterferences(S);
  TopOpeBRepDS_ListIteratorOfListOfInterference ITLOI(LOI);
  TColStd_ListOfInteger LOKK,LOII;
  
  for (;ITLOI.More();ITLOI.Next()) {
    const Handle(TopOpeBRepDS_Interference)& HI = ITLOI.Value();
    const TopOpeBRepDS_Transition& T = HI->Transition();
    
    TopAbs_ShapeEnum sb = T.ShapeBefore();TopOpeBRepDS_Kind sbk = TopOpeBRepDS::ShapeToKind(sb);
    Standard_Integer sbi = T.IndexBefore();
    TopAbs_ShapeEnum sa = T.ShapeAfter();TopOpeBRepDS_Kind sak = TopOpeBRepDS::ShapeToKind(sa);
    Standard_Integer sai = T.IndexAfter();
    TopOpeBRepDS_Kind gk,sk; Standard_Integer gi,si; HI->GKGSKS(gk,gi,sk,si);
    
    AddShapeKI(LOKK,LOII,sbk,sbi);
    AddShapeKI(LOKK,LOII,sak,sai);
    AddShapeKI(LOKK,LOII,gk,gi);
    AddShapeKI(LOKK,LOII,sk,si);
  }
  
  TColStd_ListIteratorOfListOfInteger ITLOKK,ITLOII;
  
  ITLOKK.Initialize(LOKK); ITLOII.Initialize(LOII);
  Standard_Boolean ya = ITLOKK.More();
  TopOpeBRepDS::Print(SK,I,cout,""," : ");
  for(; ITLOKK.More(),ITLOII.More(); ITLOKK.Next(),ITLOII.Next()) {
//JR/Hp
    Standard_Integer ikk = ITLOKK.Value() ;
    TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind) ikk ;
    Standard_Integer ii = ITLOII.Value();
//    TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind)ITLOKK.Value(); Standard_Integer ii = ITLOII.Value();
    TopOpeBRepDS::Print(kk,ii,cout,""," ");
  }
  if (ya) di<<"\n"; else di<<"no shape interference"<<"\n";
  
  ITLOKK.Initialize(LOKK); ITLOII.Initialize(LOII);
  for(; ITLOKK.More(),ITLOII.More(); ITLOKK.Next(),ITLOII.Next()) {
//JR/Hp
    Standard_Integer ikk =ITLOKK.Value() ;
    TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind) ikk ;
    Standard_Integer ii = ITLOII.Value();
//    TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind)ITLOKK.Value(); Standard_Integer ii = ITLOII.Value();
    SeeAnyKI(kk,ii);
  }
  //POP pour WNT
  return 0;
  
} // SeeShapeISI

//-----------------------------------------------------------------------
// SeeShapeTKIG
//-----------------------------------------------------------------------
Standard_Integer SeeShapeTKIG(const Standard_Integer I,const TopoDS_Shape& S)
{
  if ( !PHDSD ) return 0;
  const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
  if (S.IsNull()) return 0;
  SeeShapeIS(I,S);
  
  TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
  const TopOpeBRepDS_ListOfInterference& LOI = HDS->DS().ShapeInterferences(S);
  TopOpeBRepDS_TKI tki;
  TCollection_AsciiString s1,s2;
  
  tki.Clear();
  tki.FillOnGeometry(LOI);
  s1=TopOpeBRepDS::SPrint(SK,I,""," by G : \n");
  tki.Init();if (tki.More()) s2="\n";else s2="";
  tki.DumpTKIIterator(s1,s2);
  
  return 0;
} // SeeShapeTKIG

//-----------------------------------------------------------------------
// SeeShapeTKIS
//-----------------------------------------------------------------------
Standard_Integer SeeShapeTKIS(const Standard_Integer I,const TopoDS_Shape& S)
{
  if ( !PHDSD ) return 0;
  const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
  if (S.IsNull()) return 0;
  SeeShapeIS(I,S);
  
  TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
  const TopOpeBRepDS_ListOfInterference& LOI = HDS->DS().ShapeInterferences(S);
  TopOpeBRepDS_TKI tki;
  TCollection_AsciiString s1,s2;
  
  tki.Clear();
  tki.FillOnSupport(LOI);
  s1=TopOpeBRepDS::SPrint(SK,I,""," by S : \n");
  tki.Init();if (tki.More()) s2="\n";else s2="";
  tki.DumpTKIIterator(s1,s2); 
  
  return 0;
} // SeeShapeTKIS

//-----------------------------------------------------------------------
// SeeShapeTKI
//-----------------------------------------------------------------------
Standard_Integer SeeShapeTKI(const Standard_Integer I,const TopoDS_Shape& S,Draw_Interpretor& di)
{
  di<<"\n";
  SeeShapeTKIG(I,S);
  SeeShapeTKIS(I,S);
  return 0;
} // SeeShapeTKI

//-----------------------------------------------------------------------
// tseei
//-----------------------------------------------------------------------
Standard_Integer tseei(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
{
  if (na_in == 1) { tseei_help(di); return 0; }
  tf_SeeShape ssf = (tf_SeeShape)SeeShapeISI;
  Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
  return r;
} // tseei

//-----------------------------------------------------------------------
// tki
//-----------------------------------------------------------------------
Standard_Integer tki(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
{
  if (na_in == 1) { tki_help(di); return 0; }
  
  tf_SeeShape ssf = NULL;
  if      ( !strcasecmp(a[0],"tki") )  ssf = (tf_SeeShape)SeeShapeTKI;
  else if ( !strcasecmp(a[0],"tkig") ) ssf = (tf_SeeShape)SeeShapeTKIG;
  else if ( !strcasecmp(a[0],"tkis") ) ssf = (tf_SeeShape)SeeShapeTKIS;
  if (ssf == NULL) return 0;
  
  Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
  return r;
} // tki

//-----------------------------------------------------------------------
// 0 = tds
// 1 = kind of DS object to dump = [s] [so sh f w e v] [se] [su c p]
// 2,3 ... = [i1,i2 ...] = indices of DS object to see
//-----------------------------------------------------------------------
Standard_Integer tds(Draw_Interpretor& di,Standard_Integer na,const char** a)
{
  Standard_Boolean TDSkeep,TDScompact; TDSkeep = TDScompact = Standard_False;
  TopOpeBRepDS_GLOBALHDSinterfselector = 0;

  Standard_Integer ia ;
  for ( ia = 0; ia < na; ia++) {
    if (!strcasecmp(a[ia],"-ssi")) {
      TopOpeBRepDS_GLOBALHDSinterfselector = 1;
      suppressarg(na,a,ia);
      continue;
    }
    else if (!strncmp(a[ia],"-",1)) {
      TCollection_AsciiString as = a[ia];
      as.Remove(1,1);
      for(Standard_Integer i = 1;i <= as.Length(); i++) {
	if     (as.Value(i) == 'k') TDSkeep = Standard_True;
	else if(as.Value(i) == 'l') TDScompact = Standard_False;
	else if(as.Value(i) == 's') TDScompact = Standard_True;
	else if(as.Value(i) == 'h') { tds_help(di); return 0; }
      }
      suppressarg(na,a,ia);
    }
  }
  
  if (PHDSD == NULL) return 0;
  const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
  if (HDS.IsNull()) {COUTNOHDS(di);return 0;}
  
  TopOpeBRepDS_Dumper Dumper(HDS);
  if ( na == 1 ) { Dumper.Dump(cout,TDSkeep,TDScompact); return 0; }
  
  TDSpar Tpar(a[1]);  
  Standard_Integer ids;
  
  if (na == 2) {
    if      (Tpar.isshap()) {
      if (Tpar.TS() != TopAbs_SHAPE) Dumper.DumpTopology(Tpar.TK(),cout);
      else                           Dumper.DumpTopology(cout);
    }
    else if (Tpar.isgeom()) {
      Dumper.DumpGeometry(Tpar.TK(),cout,TDSkeep,TDScompact);
    }
    else if (Tpar.issect()) {
      Dumper.DumpSectionEdge(Tpar.TK(),cout);
    }
    else if (Tpar.isafev()) {
      TopOpeBRepDS_Explorer x;
      for (x.Init(HDS,TopAbs_FACE,TDSkeep);x.More();x.Next()) Dumper.DumpTopology(x.Type(),x.Index(),cout);
      for (x.Init(HDS,TopAbs_EDGE,TDSkeep);x.More();x.Next()) Dumper.DumpTopology(x.Type(),x.Index(),cout);
      for (x.Init(HDS,TopAbs_VERTEX,TDSkeep);x.More();x.Next()) Dumper.DumpTopology(x.Type(),x.Index(),cout);
    }
    
    else if (Tpar.isdege()) {      
      TopOpeBRepDS_Explorer x;
      for (x.Init(HDS,TopAbs_EDGE,TDSkeep);x.More();x.Next()) {
	if (BRep_Tool::Degenerated(x.Edge())) Dumper.DumpTopology(x.Type(),x.Index(),cout);
      }
    }
    return 0;
  } // (na == 2)
  
  // nna  > 2 : dump DS entities of type TK index atoi(a[2])..a[narg-1])  
  for (ia = 2; ia < na; ia++) {
    
    if ( !strcmp(a[ia],"sd") ) { // dump all shapes HasSameDomain of type TS
      for (TopOpeBRepDS_Explorer x(HDS,Tpar.TS(),Standard_False);x.More();x.Next()) {
	Standard_Boolean isSsd = HDS->HasSameDomain(x.Current());
	if (isSsd ) Dumper.DumpTopology(Tpar.TK(),x.Index(),cout);
      }
    }
    else {
      ids = atoi(a[ia]); 
      if ( Tpar.isshap() ) {
	if (Tpar.TS() != TopAbs_SHAPE) Dumper.DumpTopology(Tpar.TK(),ids,cout);
	else {
	  TopAbs_ShapeEnum t = HDS->Shape(ids,SFindKeep).ShapeType();
	  TopOpeBRepDS_Kind k = TopOpeBRepDS::ShapeToKind(t);
	  Dumper.DumpTopology(k,ids,cout);
	}
      }
      else if ( Tpar.isgeom() ) {
	Dumper.DumpGeometry(Tpar.TK(),ids,cout,TDSkeep,TDScompact);
      }
      else if ( Tpar.issect() ) {
	Dumper.DumpSectionEdge(TopOpeBRepDS_EDGE,ids,cout);
      }
    }
  } // ia < na 
  
  return 0;
}

Standard_Integer TPPE(Draw_Interpretor& di,Standard_Integer na,const char** a)
{
  if (PHDSD == NULL) return 0;
  const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
  if ( HDS.IsNull() ) { COUTNOHDS(di); return 0; }
  
  if (na != 5) return 1;
  Standard_Boolean ok = Standard_True;
  
  gp_Pnt pds;
  TopoDS_Edge ed;
  
  Standard_Integer ip = atoi(a[2]);
  Standard_Integer ie = atoi(a[4]);
  ok = ok && (ip >= 1); ok = ok && (ie >= 1);
  if (!ok) {
    di <<" bad data"<<"\n";
    return 1;
  }
  
  ok = Standard_False;
  if (!strcmp("p",a[1])){
    ok = Standard_True;
    ok = ok && (ip <= HDS->NbPoints());
    if (ok) pds = HDS->Point(ip).Point();
    if (!ok) di<<" geometry "<<ip<<" is not a point"<<"\n";
  }
  if (!strcmp("v",a[1])){
    ok = Standard_True;
    ok = ok && (ip <= HDS->NbShapes());
    if (ok) {
      TopoDS_Shape sh = HDS->Shape(ip,SFindKeep);
      ok = ok && (sh.ShapeType() == TopAbs_VERTEX);
      if (ok) pds =BRep_Tool::Pnt(TopoDS::Vertex(sh));
    }
    if (!ok) di<<" shape "<<ip<<" is not a vertex"<<"\n";
  } 
  if (!strcmp("e",a[3])){
    ok = ok && (ie <= HDS->NbShapes());
    if (ok) {
      TopoDS_Shape sh = HDS->Shape(ie,SFindKeep);
      ok = ok && (sh.ShapeType() == TopAbs_EDGE);
      if (ok) ed = TopoDS::Edge(sh);
    }
    if (!ok) di<<" shape "<<ie<<" is not an edge"<<"\n";
    
  } else ok = Standard_False;
  
  Standard_Real dmin=0;
  gp_Pnt pproj;
  if (ok) {
    Standard_Real f,l;
    Handle(Geom_Curve) cu = BRep_Tool::Curve(ed,f,l);
    GeomAPI_ProjectPointOnCurve ponc(pds,cu,f,l);
    ok = ponc.NbPoints() >= 1;
    
    if (ok) {
      dmin = ponc.LowerDistance();
      Standard_Real par = ponc.LowerDistanceParameter();
      BRepAdaptor_Curve bc(ed);
      pproj = bc.Value(par);
    } 
  }
  
  if (ok) {
    TCollection_AsciiString pp("p");
    pp.AssignCat(ip); pp.AssignCat("e"); pp.AssignCat(ie);
    char* ppp = (char *)pp.ToCString(); 
    DrawTrSurf::Set(ppp,pproj);
    di<<"dist point "<<ip<<" on edge "<<ie<<" = "<<dmin<<"\n";
  } else di<<"projection failed"<<"\n";
  
  return ok;
} // TPPE

void FUN_ChkIntgInterf(Draw_Interpretor& di) //***Check Integrity Interference
{
  if ( PHDSD == NULL ) return;
  PHDSD->CurrentHDS()->ChkIntg();
  di<<"Check interference integrity completed"<<"\n";
}

void FUN_ChkIntgSamDomain(Draw_Interpretor& di) //***Check Integrity SameDomain
{
  if ( PHDSD == NULL ) return;
  TopOpeBRepDS_Check C(PHDSD->CurrentHDS());
  if(C.ChkIntgSamDom())
    di<<"Check SameDomain integrity completed"<<"\n";
}

void FUN_ChkIntg(Draw_Interpretor& di) //***Check Integrity
{
  if ( PHDSD == NULL ) return;
  FUN_ChkIntgInterf(di);
  FUN_ChkIntgSamDomain(di);
}

void FUN_ChkVertex(Draw_Interpretor& di) //***Check Vertex SameDomain
{
  if ( PHDSD == NULL ) return;
  TopOpeBRepDS_Check C(PHDSD->CurrentHDS());
  if(C.OneVertexOnPnt())
    di<<"Check Structure Vertex SameDomain Complete"<<"\n";
}

//---------------------------------------------------------
Standard_Integer topochk(Draw_Interpretor& di,Standard_Integer na,const char** a)
{
  if (strcmp(a[0],"topochk")) return 1;
  
  if(na < 2) {
    ::FUN_ChkIntg(di);
    ::FUN_ChkVertex(di);
  } 
  else if(na > 2) return 1;
  else if(!strcmp (a[1],"-i")) ::FUN_ChkIntg(di);
  else if(!strncmp(a[1],"-i",2)) {
    if     (!strcmp(a[1],"-ii"))  ::FUN_ChkIntgInterf(di);
    else if(!strcmp(a[1],"-isd")) ::FUN_ChkIntgSamDomain(di);
  }
  else if(!strcmp (a[1],"-s")) ::FUN_ChkVertex(di);
  else {
    di<<"option : -i   = check DS full integrity"<<"\n";
    di<<"option : -ii  = check only interferences"<<"\n";
    di<<"option : -isd = check only SameDomain data"<<"\n"<<"\n";
    di<<"option : -s   = check only SameDomain data on vertex"<<"\n";
    return 1;
  }
  return 0;
}

//-----------------------------------------------------------------------
// SeeShapeTCX
//-----------------------------------------------------------------------
Standard_Integer SeeShapeTCX(const Standard_Integer I,const TopoDS_Shape& S)
{
  if ( !PHDSD ) return 0;
  const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
  if (S.IsNull()) return 0;
  FDSCNX_Dump(HDS,I);
  return 0;
} // SeeShapeTCX

static void tcx_help(Draw_Interpretor& di)
{
  di<<"tcx : function not documented"<<"\n";
}

//-----------------------------------------------------------------------
// tcx
//-----------------------------------------------------------------------
Standard_Integer tcx(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
{
  if (na_in == 1) { tcx_help(di); return 0; }
  Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,SeeShapeTCX);
  return r;
} // tcx

#if 0
//---------------------------------------------------------
Standard_Integer tcx(Draw_Interpretor& di,Standard_Integer na,const char** a)
{
  if (PHDSD == NULL) return 0;
  const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
  if ( HDS.IsNull() ) { COUTNOHDS(di); return 0; }
  if      (na == 1) FDSCNX_Dump(HDS);
  else if (na == 2) {
    if   (ISINTEGER(a[1])) FDSCNX_Dump(HDS,atoi(a[1]));
    else 
  }
  return 0;
}
#endif

//-----------------------------------------------------------------------
Standard_Integer tdsri(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
{
  if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
    tsee_help(a[0],di);
    return 0; 
  }
  Standard_Integer na = na_in;
  if ((PHDSD == NULL) || (POCD == NULL)) return 0;
  const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
  if (HDS.IsNull()) { COUTNOHDS(di); return 0; }
  if (na < 5) return 1;
  TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
  
  Standard_Integer i1arg = 1;
  TDSpar Tpar(a[i1arg]);
  
  if ( strcasecmp(a[i1arg + 2],"i") ) return 0;
  Standard_Integer ii = atoi(a[i1arg + 3]);  
//  Standard_Integer ia,is,ig;
  Standard_Integer is;
  if ( Tpar.isshap() ) {
    is = atoi(a[i1arg + 1]);
    const TopoDS_Shape& s = GetShape(is,Tpar.TS()); if (s.IsNull()) return 0;
    TopOpeBRepDS_ListOfInterference& li = BDS.ChangeShapeInterferences(is);
    Standard_Integer i=0; TopOpeBRepDS_ListIteratorOfListOfInterference it(li);
    while (it.More()) {
      if(++i == ii) {
	it.Value()->Dump(cout,"\n--> remove ","\n");
	li.Remove(it);
      }
      else it.Next();
    }
  }
  return 0;
} // tdsri

//=======================================================================
//function : DSCommands
//purpose  : 
//=======================================================================
void  TestTopOpe::HDSCommands(Draw_Interpretor& theCommands)
{
  static Standard_Boolean done = Standard_False;
  if (done) return;
  done = Standard_True;
  PHDSD = (TestTopOpe_HDSDisplayer*) new (TestTopOpe_HDSDisplayer);
  POCD = (TestTopOpeDraw_Displayer*) new (TestTopOpeDraw_Displayer);
  
  const char* g = "Topological operation data structure commands";
  theCommands.Add("tseei","no args to get help",__FILE__,tseei,g);
  theCommands.Add("tsee","no args to get help ",__FILE__,tsee,g);
  theCommands.Add("tki","no args to get help ",__FILE__,tki,g);
  theCommands.Add("tkig","no args to get help ",__FILE__,tki,g);
  theCommands.Add("tkis","no args to get help ",__FILE__,tki,g);
  theCommands.Add("tds","-h to get help ",__FILE__,tds,g);
  theCommands.Add("tppe","tppe p/v <ip> e <ie>",__FILE__,TPPE);
  theCommands.Add("topochk","check current DS (loaded by CurrentDS()",__FILE__,topochk,g);
  theCommands.Add("tcx","dump connexity information",__FILE__,tcx,g);
  theCommands.Add("tdsri","remove interference : tdsri type itype iinterf",__FILE__,tdsri,g);
}