Warnings on vc14 were eliminated
[occt.git] / src / TestTopOpe / TestTopOpe_HDSCommands.cxx
1 // Created on: 1994-10-24
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TestTopOpe.hxx>
18 #include <TestTopOpe_HDSDisplayer.hxx>
19 #include <TestTopOpeDraw_DrawableSHA.hxx>
20 #include <TestTopOpeDraw_DrawableP3D.hxx>
21 #include <TestTopOpeDraw_DrawableC3D.hxx>
22 #include <TestTopOpeDraw_TTOT.hxx>
23 #include <TestTopOpeDraw_Displayer.hxx>
24 #include <TopOpeBRepDS_connex.hxx>
25 #include <TopOpeBRepDS_Point.hxx>
26 #include <TopOpeBRepDS_Curve.hxx>
27 #include <TopOpeBRepDS_PointIterator.hxx>
28 #include <TopOpeBRepDS_PointExplorer.hxx>
29 #include <TopOpeBRepDS_CurveExplorer.hxx>
30 #include <TopOpeBRepDS_Explorer.hxx>
31 #include <TopOpeBRepDS_TKI.hxx>
32 #include <TopOpeBRepDS_Check.hxx>
33 #include <TopOpeBRepDS_Dumper.hxx>
34 #include <TopOpeBRepDS.hxx>
35 #include <Geom_TrimmedCurve.hxx>
36 #include <BRep_Tool.hxx>
37 #include <TopoDS.hxx>
38 #include <TopLoc_Location.hxx>
39 #include <Geom_Curve.hxx>
40 #include <GeomAdaptor_Curve.hxx>
41 #include <GeomAbs_CurveType.hxx>
42 #include <GeomAdaptor_Surface.hxx>
43 #include <GeomAbs_SurfaceType.hxx>
44 #include <GeomAPI_ProjectPointOnCurve.hxx>
45 #include <BRepAdaptor_Curve.hxx>
46 #include <TColStd_ListOfInteger.hxx>
47 #include <TColStd_ListIteratorOfListOfInteger.hxx>
48 #include <TopOpeBRepDS_define.hxx>
49 #include <DBRep.hxx>
50 #include <Draw_Appli.hxx>
51 #include <DrawTrSurf_Curve.hxx>
52 #include <Draw_Interpretor.hxx>
53 #include <DrawTrSurf.hxx>
54 #include <Draw_Marker3D.hxx>
55
56 class TSEEpar {
57 public:
58   TSEEpar(const TCollection_AsciiString& s) { set(s); }
59   void set(const TCollection_AsciiString& s) {
60     miskind = misshap = misgeom = missect = misdege = misafev = misedcu = Standard_False; 
61     mTK = TopOpeBRepDS_UNKNOWN; mTS = TopAbs_SHAPE;
62     char* sK = (char *)s.ToCString();
63     miskind = TestTopOpeDraw_TTOT::StringToKind(s,mTK);
64     if ( miskind ) {
65       misshap = TopOpeBRepDS::IsTopology(mTK);
66       if (misshap) mTS = TopOpeBRepDS::KindToShape(mTK);
67       else misgeom = TopOpeBRepDS::IsGeometry(mTK);
68     }
69     else if ( ! strcasecmp(sK,"s") ) {
70       misshap = Standard_True; mTS = TopAbs_SHAPE;
71     }
72     else if ( ! strcasecmp(sK,"se") ) {
73       missect = Standard_True; mTK = TopOpeBRepDS_EDGE;
74     }
75     else if ( ! strcasecmp(sK,"de") ) {
76       misdege = Standard_True; mTK = TopOpeBRepDS_EDGE;
77     }
78     else if ( ! strcasecmp(sK,"fev") ) {
79       misafev = Standard_True;
80     }
81     else if ( ! strcasecmp(sK,"ec") ) {
82       misedcu = Standard_True;
83     }
84   }
85   Standard_Boolean iskind() { return miskind;}
86   Standard_Boolean isshap() { return misshap;}
87   Standard_Boolean isgeom() { return misgeom;}
88   Standard_Boolean issect() { return missect;}
89   Standard_Boolean isdege() { return misdege;}
90   Standard_Boolean isafev() { return misafev;}
91   Standard_Boolean isedcu() { return misedcu;}
92   TopOpeBRepDS_Kind TK() {return mTK;}
93   TopAbs_ShapeEnum TS() {return mTS;}
94 private:
95   Standard_Boolean miskind,misshap,misgeom,missect,misdege,misafev,misedcu;
96   TopOpeBRepDS_Kind mTK; TopAbs_ShapeEnum mTS;
97 };
98
99 class TDSpar : public TSEEpar {
100 public:
101   TDSpar(const TCollection_AsciiString& s) : TSEEpar(s) {}
102 };
103
104 #define ISINTEGER(MMstr) ((strspn((MMstr),"0123456789") == strlen((MMstr))))
105
106 TestTopOpe_HDSDisplayer* PHDSD = NULL;
107 static TestTopOpeDraw_Displayer* POCD = NULL;
108
109 static Standard_Boolean SFindKeep = Standard_False;
110 static Standard_Boolean GFindKeep = Standard_False;
111 static Standard_Boolean PrintDistancePP = Standard_False;
112 static Standard_Integer SelectRankShape = 0;
113 static Standard_Boolean DisOri = Standard_False;
114 static Standard_Boolean TolFlag = Standard_False;
115 static Standard_Real OldParFlag = -1.0;
116 static Standard_Real ParFlag = -1.0;
117
118 class tsee_entity {
119 public:
120   Standard_Boolean myEOK;
121   TestTopOpe_HDSDisplayer* myEPHDSD;
122   Handle(TopOpeBRepDS_HDataStructure) myEHDS; TopOpeBRepDS_DataStructure *myEPDS;
123   TopOpeBRepDS_Kind myETK;TopAbs_ShapeEnum myETS;Standard_Integer myEindex;
124   Standard_Boolean myEiskind,myEisshape,myEisgeome,myEissect;
125   TCollection_AsciiString myEnamedbrep,myEnamedisp; Draw_ColorKind myEnamecolor;
126   
127 //JR/Hp :
128   tsee_entity() {
129 //  tsee_entity::tsee_entity() {
130     myEOK = Standard_False;
131     if (PHDSD == NULL) return; myEPHDSD = PHDSD;
132     myEHDS = myEPHDSD->CurrentHDS(); myEPDS = (TopOpeBRepDS_DataStructure*)&myEHDS->ChangeDS();  
133     myETK = TopOpeBRepDS_UNKNOWN;myETS = TopAbs_SHAPE; myEindex = 0;
134     myEiskind = myEisshape = myEisgeome = myEissect = Standard_False;
135     myEnamedbrep = ""; myEnamedisp = ""; myEnamecolor = Draw_blanc;
136     myEOK = Standard_True;
137   }
138   
139   Standard_Boolean IsP() const { return (myETK == TopOpeBRepDS_POINT); }
140   Standard_Boolean IsV() const { return (myETK == TopOpeBRepDS_VERTEX); }
141   Standard_Boolean Is0() const { return IsP() || IsV(); }
142   Standard_Integer Set(Standard_Integer na,const char** a,Standard_Integer iargK,Standard_Integer iargI);
143
144   virtual ~tsee_entity() {}
145   void virtual See() = 0;
146 };
147
148 Standard_Integer tsee_entity::Set(Standard_Integer na,const char** a,Standard_Integer iargK,Standard_Integer iargI) {
149   myEOK = Standard_False;
150   if (iargK>=na) return 1; if (iargI>=na) return 1;
151   TCollection_AsciiString ascK = a[iargK]; myEindex = Draw::Atoi(a[iargI]);
152   myEiskind = TestTopOpeDraw_TTOT::StringToKind(ascK,myETK);
153   if (!myEiskind) return 1; if (myETK == TopOpeBRepDS_UNKNOWN) return 1;
154   
155   myEisshape = TopOpeBRepDS::IsTopology(myETK);
156   if (myEisshape) {
157     if ((myEindex < 1) || (myEindex > myEPDS->NbShapes())) return 0;
158     myETS = TopOpeBRepDS::KindToShape(myETK);
159     const TopoDS_Shape& S = myEPDS->Shape(myEindex);
160     if (myETS != S.ShapeType()) return 0;
161     myEPHDSD->ShapeName(myEindex,S,myEnamedbrep);
162     myEPHDSD->ShapeDisplayName(myEindex,S,myEnamedisp);
163   }
164   
165   myEisgeome = TopOpeBRepDS::IsGeometry(myETK);
166   if (myEisgeome) {
167     if (IsP()) {
168       TopOpeBRepDS_PointExplorer pex(myEHDS->DS());
169       if (!pex.IsPoint(myEindex)) return 1;
170     }
171     TestTopOpeDraw_TTOT::GeometryName(myEindex,myETK,myEnamedbrep);
172     myEPHDSD->GeometryDisplayName(myEindex,myETK,myEnamedisp);
173   }
174   
175   myEnamecolor = TestTopOpeDraw_TTOT::GeometryColor(myETK);
176   myEOK = Standard_True;
177   return 0;
178 }
179
180 class tsee_entity0 : public tsee_entity {
181 public:
182   gp_Pnt Pnt() const;
183   void See();
184 };
185
186 gp_Pnt tsee_entity0::Pnt() const
187 {
188   if (!Is0()) throw Standard_Failure("not 0d");
189   gp_Pnt P; 
190   if      (IsP()) P = myEPDS->Point(myEindex).Point();
191   else if (IsV()) P = BRep_Tool::Pnt(TopoDS::Vertex(myEPDS->Shape(myEindex)));
192   return P;
193 }
194
195 static void SetPoint
196 (const TCollection_AsciiString& namedbrep,const TCollection_AsciiString& namedisp,const Draw_Color& namecolor,const TopOpeBRepDS_Point& P)
197 {
198   Handle(TestTopOpeDraw_DrawableP3D) D;
199   if(TolFlag) {
200     D = new TestTopOpeDraw_DrawableP3D(P.Point(),Draw_CircleZoom,namecolor,
201                                          namedisp.ToCString(),namecolor,
202                                          P.Tolerance());
203   } else {
204     D = new TestTopOpeDraw_DrawableP3D(P.Point(),Draw_Square,namecolor,
205                                          namedisp.ToCString(),namecolor);
206   }
207   char *pname = (char *)namedbrep.ToCString();
208   Draw::Set(pname,D);
209   
210 }
211 void tsee_entity0::See() 
212 {
213   if (IsP()) ::SetPoint(myEnamedbrep,myEnamedisp,myEnamecolor,myEPDS->Point(myEindex));
214   if (IsV()) POCD->DisplayShape(myEnamedbrep,myEnamedisp,myEPDS->Shape(myEindex));
215 }
216
217 //-----------------------------------------------
218 static void SetCurve
219 //-----------------------------------------------
220 (const TCollection_AsciiString& namedbrep,
221  const TCollection_AsciiString& namedisp,
222  const Draw_Color& namecolor,
223  const TopOpeBRepDS_Curve& DSC,
224  const Standard_Integer iC)
225 {
226   if ( !PHDSD ) return;
227   const Handle(Geom_Curve) GC = DSC.Curve();
228   if ( GC.IsNull() ) { cout<<"Curve() nulle"<<endl; return; }
229   
230   Standard_Real f = GC->FirstParameter();
231   Standard_Real l = GC->LastParameter();
232   
233   GeomAdaptor_Curve GAC(GC);
234   GeomAbs_CurveType GACt = GAC.GetType();
235   if ( GACt == GeomAbs_Line ) {
236     Standard_Real fline = RealLast(),lline = RealFirst(); 
237     Standard_Integer imother = DSC.Mother(),igood;
238     if(imother) igood = imother;
239     else        igood = iC;
240     TopOpeBRepDS_PointIterator it = PHDSD->CurrentHDS()->CurvePoints(igood);
241     for(; it.More(); it.Next()) {
242       Standard_Real p = it.Parameter();
243       fline = Min(fline,p); lline = Max(fline,p);
244     }
245     f = fline;
246     l = lline;
247   }
248   
249   Handle(Geom_TrimmedCurve) GTC = new Geom_TrimmedCurve(GC,f,l);
250   Handle(TestTopOpeDraw_DrawableC3D) D;
251   D = new TestTopOpeDraw_DrawableC3D(GTC,namecolor,namedisp.ToCString(),namecolor);
252   char *pname = (char *)namedbrep.ToCString();
253   Draw::Set(pname,D);
254 }
255
256 static TopoDS_Shape bidbid;
257 static const TopoDS_Shape& GetShape(const Standard_Integer IS,const TopAbs_ShapeEnum TS)
258 {
259   Standard_Boolean TypeControl = Standard_True;
260   if ( !PHDSD ) return bidbid;
261   
262   static TopoDS_Shape ShapeNull;
263   const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
264   
265   // check on shape index and on shape kind if kind differs from TopAbs_SHAPE
266   Standard_Integer ns = BDS.NbShapes();
267   if ( IS < 1 || IS > ns) {
268     TopAbs::Print(TS,cout);cout<<" "<<IS<<" does not exist in DS"<<endl;
269     return ShapeNull;
270   }
271   else if ( !PHDSD->ShapeKind(IS,TS) ) {
272     if ( TypeControl ) {
273       cout<<"Shape "<<IS;
274       cout<<" is not a ";TopAbs::Print(TS,cout);
275       cout<<" but a "; TopAbs::Print(BDS.Shape(IS,SFindKeep).ShapeType(),cout);
276       cout<<endl;
277     }
278     return ShapeNull;
279   }
280   
281   const TopoDS_Shape& S = BDS.Shape(IS,SFindKeep);  
282   return S;
283 }
284
285 static const TopoDS_Shape& GetShape(const Standard_Integer IS)
286 {
287   if ( !PHDSD ) return bidbid;
288   const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
289   const TopoDS_Shape& S = BDS.Shape(IS);
290   return S;
291 }
292
293 //-----------------------------------------------------------------------
294 // SeeSectionEdge
295 //-----------------------------------------------------------------------
296 static Standard_Integer SeeSectionEdge(const Standard_Integer ISE)
297 {
298   if ( !PHDSD || !POCD ) return 0;
299   
300   Standard_Integer nse = PHDSD->CurrentBDS().NbSectionEdges();
301   if ( ISE < 1 || ISE > nse ) return 0;
302   const TopoDS_Shape& SE  = PHDSD->CurrentBDS().SectionEdge(ISE);
303   if (SE.IsNull()) return 0;
304   
305   TCollection_AsciiString namedbrep; PHDSD->SectionEdgeName(ISE,SE,namedbrep); 
306   TCollection_AsciiString namedisp; PHDSD->SectionEdgeDisplayName(ISE,SE,namedisp);
307   POCD->DisplayGeometry(Standard_True);
308   POCD->DisplayShape(namedbrep,namedisp,SE);
309   return 0;
310 }
311
312 //-----------------------------------------------------------------------
313 // SeeShapeIS
314 //-----------------------------------------------------------------------
315 Standard_Integer SeeShapeIS(const Standard_Integer I,const TopoDS_Shape& S)
316 {
317   if ( !PHDSD || !POCD) return 0;
318   
319   if (S.IsNull()) return 0;  
320   TCollection_AsciiString namedbrep; PHDSD->ShapeName(I,S,namedbrep);
321   TCollection_AsciiString namedisp = namedbrep;
322   // NameDisplay = *name/name* if S subshape of shape1/shape2
323   TCollection_AsciiString ast = "*";
324   const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
325   // if the Shape was removed from the DS, "*" is replaced by "~"
326   if(!BDS.HasShape(S))
327     ast = "~";
328   Standard_Boolean of1 = PHDSD->SubShape(S,1);if(of1) namedisp = ast+namedisp;
329   Standard_Boolean of2 = PHDSD->SubShape(S,2);if(of2) namedisp = namedisp+ast;
330   if (SelectRankShape == 1 && !of1) return 0;
331   if (SelectRankShape == 2 && !of2) return 0;
332   
333   if (S.ShapeType()==TopAbs_EDGE) POCD->DisplayGeometry(Standard_True);
334   else POCD->DisplayGeometry(DisOri);
335   if((S.ShapeType()==TopAbs_VERTEX) && TolFlag) {
336     const TopoDS_Vertex& V = TopoDS::Vertex(S);
337     Standard_Real Tol = BRep_Tool::Tolerance(V);
338     POCD->SetTol(Tol);
339   }
340   POCD->DisplayShape(namedbrep,namedisp,S);
341   
342   return 0;
343 }
344
345
346 //-----------------------------------------------------------------------
347 // SeeShape
348 //-----------------------------------------------------------------------
349 static Standard_Integer SeeShape(TCollection_AsciiString namedbrep)
350 {
351   if ( !PHDSD || !POCD ) return 0;
352   
353   const char* pname = (const char *)namedbrep.ToCString();
354   TopoDS_Shape S = DBRep::Get(pname);
355   if ( S.IsNull() ) return 0;
356   TCollection_AsciiString namedisp; 
357   PHDSD->ShapeDisplayName(namedbrep,S,namedisp);
358   POCD->DisplayShape(namedbrep,namedisp,S);
359   return 0;
360 }
361
362 //-----------------------------------------------------------------------
363 // SeePoint
364 //-----------------------------------------------------------------------
365 static Standard_Integer SeePoint(const Standard_Integer I)
366 {
367   if ( !PHDSD ) return 0;
368   
369   const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
370   if (I < 1 || I > BDS.NbPoints()) return 0;
371   
372   TopOpeBRepDS_PointExplorer pex(BDS);
373   Standard_Boolean isp = pex.IsPoint(I);
374   if (!isp) return 0;
375   
376   const TopOpeBRepDS_Point& P = BDS.Point(I);
377   TopOpeBRepDS_Kind K = TopOpeBRepDS_POINT;
378   TCollection_AsciiString namedbrep; TestTopOpeDraw_TTOT::GeometryName(I,K,namedbrep);
379   TCollection_AsciiString namedisp; PHDSD->GeometryDisplayName(I,K,namedisp);
380   Draw_ColorKind namecolor = TestTopOpeDraw_TTOT::GeometryColor(K);
381   SetPoint(namedbrep,namedisp,namecolor,P);
382   return 0;
383 }
384
385 //-----------------------------------------------------------------------
386 // SeeCurve
387 //-----------------------------------------------------------------------
388 static Standard_Integer SeeCurve(const Standard_Integer I)
389 {
390   if ( !PHDSD ) return 0;
391   
392   const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
393   if (I < 1 || I > BDS.NbCurves()) return 0;
394   
395   TopOpeBRepDS_CurveExplorer cex(BDS,GFindKeep);
396   Standard_Boolean isc = cex.IsCurve(I);
397   if (!isc) return 0;
398   
399   const TopOpeBRepDS_Curve& C = BDS.Curve(I);
400   TopOpeBRepDS_Kind K = TopOpeBRepDS_CURVE;
401   TCollection_AsciiString namedbrep; TestTopOpeDraw_TTOT::GeometryName(I,K,namedbrep);
402   TCollection_AsciiString namedisp; PHDSD->GeometryDisplayName(I,K,namedisp);
403   Draw_ColorKind namecolor = TestTopOpeDraw_TTOT::GeometryColor(K);
404   SetCurve(namedbrep,namedisp,namecolor,C,I);
405   return 0;
406 }
407
408
409 //-----------------------------------------------------------------------
410 // SeeSurface NYI
411 //-----------------------------------------------------------------------
412 Standard_Integer SeeSurface(const Standard_Integer I) // NYI
413 {
414   if ( !PHDSD ) return 0;
415   
416   const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
417   if (I < 1 || I > BDS.NbSurfaces()) return 0;
418   return 0;
419 }
420
421 //-----------------------------------------------------------------------
422 // SeeEdgeCurve
423 //-----------------------------------------------------------------------
424 static Standard_Integer SeeEdgeCurve(const Standard_Integer IE,const TopoDS_Shape& SE)
425 {
426   if ( !POCD ) return 0;
427   
428   if (SE.IsNull()) return 0;
429   const TopoDS_Edge& E = TopoDS::Edge(SE);
430   TopLoc_Location L;Standard_Real f,l;Handle(Geom_Curve) GC=BRep_Tool::Curve(E,L,f,l);  
431   TCollection_AsciiString namedbrep="E";TestTopOpeDraw_TTOT::CatCurveName(IE,namedbrep);
432   TCollection_AsciiString namedisp="E";TestTopOpeDraw_TTOT::CatCurveDisplayName(IE,GC,namedisp);
433   POCD->DisplayGeometry(Standard_True);
434   POCD->DisplayShape(namedbrep,namedisp,SE);
435   return 0;
436 }
437
438 //-----------------------------------------------------------------------
439 // SeeGeometry
440 //-----------------------------------------------------------------------
441 static Standard_Integer SeeGeometry(const Standard_Integer IG,const TopOpeBRepDS_Kind TK)
442
443   if      (TK == TopOpeBRepDS_POINT) return SeePoint(IG);
444   else if (TK == TopOpeBRepDS_CURVE) return SeeCurve(IG);
445   else if (TK == TopOpeBRepDS_SURFACE) return SeeSurface(IG);
446   return 0;
447 }
448
449 //-----------------------------------------------------------------------
450 // SeeGeometry
451 //-----------------------------------------------------------------------
452 static Standard_Integer SeeGeometry(const TopOpeBRepDS_Kind TK)
453 {
454   if ( !PHDSD ) return 0; 
455   
456   const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
457
458   if      (TK == TopOpeBRepDS_POINT) {
459     TopOpeBRepDS_PointExplorer pex(BDS,GFindKeep);
460     for (; pex.More(); pex.Next()) {
461       Standard_Integer ig = pex.Index();
462       SeeGeometry(ig,TK);
463     }
464   }
465   else if (TK == TopOpeBRepDS_CURVE) {
466     TopOpeBRepDS_CurveExplorer cex(BDS,GFindKeep);
467     for (; cex.More(); cex.Next()) {
468       Standard_Integer ig = cex.Index();
469       SeeGeometry(ig,TK);
470     }
471   }
472   else if (TK == TopOpeBRepDS_SURFACE) { //NYI
473   }
474   return 0;
475 }
476
477 //-----------------------------------------------------------------------
478 // TOPOPE_SeeShape
479 //-----------------------------------------------------------------------
480 Standard_Integer TOPOPE_SeeShape(char* name)
481 {
482   TCollection_AsciiString asc = name;
483   Standard_Integer res = SeeShape(asc);
484   return res;
485 }
486
487 //-----------------------------------------------------------------------
488 // suppressarg : remove a[d],modify na--
489 //-----------------------------------------------------------------------
490 void suppressarg(Standard_Integer& na,const char** a,const Standard_Integer d) 
491 {
492   for(Standard_Integer i=d;i<na;i++) {
493     a[i]=a[i+1];
494     a[i+1]=NULL;
495   }
496   na--;
497 }
498
499 //-----------------------------------------------------------------------
500 // suppressargs : remove a[*] from <f> to <l>,modify na = na - (l - f)
501 //-----------------------------------------------------------------------
502 Standard_EXPORT void suppressargs(Standard_Integer& na,const char** a,const Standard_Integer f,const Standard_Integer l) 
503 {
504   if(l == f) 
505     suppressarg(na,a,l);
506   if(l <= f) return;
507   for(Standard_Integer i=0;i<na-l;i++) {
508     a[i+f]=a[i+l+1];
509     a[i+l+1]=NULL;
510   }
511   na -= l-f+1;
512 }
513
514 //-----------------------------------------------------------------------
515 // tsee_flags
516 //-----------------------------------------------------------------------
517 static void tsee_flags(Standard_Integer& na,const char** a) {
518   GFindKeep = Standard_False;
519   PrintDistancePP = Standard_False;
520   SelectRankShape = 0;
521   
522   for (Standard_Integer ia = 1; ia < na; ia++) {
523     if (!strcasecmp(a[ia],"-k")) { 
524       suppressarg(na,a,ia);
525       GFindKeep = Standard_True;
526     }
527     else if (!strcasecmp(a[ia],"-d")) { 
528       // tsee -d p 4 7 : display p_4,p_7 + tds p 4 7 + calculate distance (p_4,p_7)
529       suppressarg(na,a,ia);
530       PrintDistancePP = Standard_True;
531     }
532     else if (!strcasecmp(a[ia],"-1")) { 
533       // tsee -1 s 4 : display s_4 <=> s_4 is subshape of the 1st argument
534       suppressarg(na,a,ia);
535       SelectRankShape = 1;
536     }
537     else if (!strcasecmp(a[ia],"-2")) { 
538       // tsee -2 s 4 : display s_4 <=> s_4 is subshape of the 2nd argument
539       suppressarg(na,a,ia);
540       SelectRankShape = 2;
541     }
542     else if (!strcasecmp(a[ia],"-p") && (ia < na-1)) {
543       suppressargs(na,a,ia,ia+1);
544       Standard_Real t = Draw::Atof(a[ia+1]);
545       if (t >= 0. && t <= 1.) {
546         OldParFlag = ParFlag; ParFlag = t;
547       }
548     }
549   }
550 }
551
552 void OthersCommands_help(const char* CommandName,const char* syntaxe = "");
553 //-----------------------------------------------------------------------
554 // tsee_help
555 //-----------------------------------------------------------------------
556 static void tsee_help(const char* CommandName, Draw_Interpretor& di)
557 {
558   di<<"\n";
559   di<<"tsee : Draw entities of data structure (DS) loaded by TestTopOpe::CurrentDS().\n";
560   di<<"DS entities are shapes and geometries accessed by a <type> and an <index>.\n";
561   di<<"basic usage :\n";
562   di<<"              tsee <type> <index1 index2 ...>\n";
563   di<<"<type>  = so sh f w e v s for solid/shell/face/wire/edge/vertex/shape\n";
564   di<<"          su cu p for surface/curve/point (N.B : su is NYI)\n";
565   di<<"<index> = integer\n";
566   di<<"example : 'tsee e 3' will draw the edge of index 3\n";
567   di<<"          'tsee e 3 6' will draw the edges of index 3 and 6\n";
568   di<<"          'tsee e' will draw all the edges.\n";
569   di<<"\n";
570   di<<"Index values of DS entities may be given by the 'tds' command which prints\n";
571   di<<"the content of the DS for each shape and geometry type.\n";
572   di<<"Entities are drawn with a specific color according to their type.\n";
573   di<<"\n";
574   di<<"Naming : \n";
575   di<<"'tsee <t> <i>' creates the drawable object named <t>_<i>.\n";
576   di<<"This name is displayed near the entity in one if the forms : \n";
577   di<<"     *<t>_<i> meaning entity belongs to the first shape of current operation.\n";
578   di<<"     <t>_<i>* meaning entity belongs to the second shape of current operation.\n";
579   di<<"\n";
580   di<<"Same Domain shapes : \n";
581   di<<"'tsee <type> sd' to display all shapes of <type> having same domain data.\n";
582   di<<"example : 'tsee e sd' to display all edges sharing a 1d geometric domain\n";
583   di<<"          with other edges.\n";
584   di<<"\n";
585   di<<"Optional flags :\n";
586   OthersCommands_help(CommandName);
587   di<<"Other types :\n";
588   di<<"'tsee fev' : displays all faces,then edges,then vertices.\n";
589   di<<"'tsee es <i>' displays edge described as section edge <i>.\n";
590   di<<"      The name of a section edge likes t_i<j>,where :\n";
591   di<<"         - i is the edge index in the set of section edge,\n";
592   di<<"         - j is edge index in the DS (as any edge).\n";
593   di<<"\n";
594 }
595
596 static void tseei_help(Draw_Interpretor& di)
597 {
598   di<<"\n";
599   di<<"tseei : Draws entities of data structure (DS) loaded by TestTopOpe::CurrentDS().\n";
600   di<<"Draws the objects appearing in interferences DS objects.\n";
601   di<<"See command 'tsee' for discussion about DS objects.\n";
602   di<<"\n";
603 }
604
605 static void tki_help(Draw_Interpretor& di)
606 {
607   di<<"\n";
608   di<<"tki,tkig,tkis : Groups interferences of DS objects\n";
609   di<<"  by geometry (g),or support (s),and index.\n";
610   di<<"See command 'tsee' for discussion about DS objects.\n";
611   di<<"(Test of class TopOpeBRepDS_TKI)\n";
612   di<<"\n";
613 }
614
615 static void tds_help(Draw_Interpretor& di)
616 {
617   di<<"\n";
618   di<<"tds : dump current DS (loaded by CurrentDS())\n";
619   di<<"basic usage : tds <-arg> type <index1 index2 ...>\n";
620   di<<"\n";
621   di<<"Description of curve geometry (type = c) : <-arg>  = -t -k -s -l\n";
622   di<<"\t-k : print only the curve with keep = Standard_True\n";
623   di<<"\t-l : (long) print all poles and knots for BSplines curves\n";
624   di<<"\t-s : (short) print only 4 poles and 4 knots for BSplines curves\n";
625   di<<"on shapes (type = s|so|sh|f|w|e|v) : <-arg>  = -ssi\n";
626   di<<"\t-ssi : print only ShapeShapeInterferences\n";
627   di<<"\n";
628   di<<"See command 'tsee' for discussion about type and <index1 index2 ...>.\n";
629   di<<"\n";
630 }
631
632 typedef Standard_Integer (*tf_SeeShape)(const Standard_Integer I,const TopoDS_Shape& S);
633 extern void OthersCommands_flags(Standard_Integer& na,const char** a,TestTopOpeDraw_Displayer& TD);
634 void COUTNOHDS(Draw_Interpretor& di) {di<<"no current HDS\n";}
635 Standard_Integer tsee_SeeShapefunc(Draw_Interpretor& di,Standard_Integer na_in,const char** a,tf_SeeShape SeeShapefunc)
636 {
637   if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
638     tsee_help(a[0], di);
639     return 0; 
640   }
641   
642   Standard_Integer na = na_in;
643   if ((PHDSD == NULL) || (POCD == NULL)) return 0;
644   
645   const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
646   if (HDS.IsNull()) { COUTNOHDS(di); return 0; }
647   if (na < 2) return 1;
648   const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
649   
650   POCD->InitDisplayer();
651   TolFlag = Standard_False;
652   tsee_flags(na,a);
653   OthersCommands_flags(na,a,*POCD);
654   TolFlag = POCD->TolIs();
655   DisOri = POCD->DisplayGeometry();
656   
657   Standard_Integer i1arg = 1;
658   TSEEpar Tpar(a[i1arg]);
659   
660 //  Standard_Integer ia,is,ig;
661   Standard_Integer ia,is;
662   
663   if ( PrintDistancePP ) {
664     tsee_entity0 E1,E2;    
665     if (na == 4) { // tsee p 3 4
666       if (E1.Set(na,a,i1arg+0,i1arg+1)) return 1;
667       if (E2.Set(na,a,i1arg+0,i1arg+2)) return 1;
668     }
669     else if (na == 5) { // tsee p 3 v 4
670       if (E1.Set(na,a,i1arg+0,i1arg+1)) return 1;
671       if (E2.Set(na,a,i1arg+2,i1arg+3)) return 1;
672     }
673     if (!E1.myEOK || !E2.myEOK) return 1;
674     
675     E1.See();E2.See();
676     di<<"Distance "<<E1.myEnamedbrep.ToCString()<<" "<<E2.myEnamedbrep.ToCString()<<" : "<<E1.Pnt().Distance(E2.Pnt())<<"\n";
677     
678   } // PrintDistancePP
679   
680   else if ( Tpar.isshap() ) {
681     // na == 2 : display all DS shapes of type TS
682     // na  > 2 : display DS shapes of type TS of index Draw::Atoi(a[2]..a[narg-1])
683     if (na == 2 ) {
684       TopOpeBRepDS_Explorer x(HDS,Tpar.TS(),Standard_False);
685       for(;x.More();x.Next()) (*SeeShapefunc)(x.Index(),x.Current());
686     }
687     else {
688       if ( !strcmp(a[i1arg+1],"sd") ) { // shapes HasSameDomain of type TS
689         TopOpeBRepDS_Explorer x(HDS,Tpar.TS(),Standard_False);
690         for (;x.More();x.Next()) {
691           Standard_Boolean isSsd = HDS->HasSameDomain(x.Current());
692           if (isSsd ) (*SeeShapefunc)(x.Index(),x.Current());
693         }
694       }
695       else if (Tpar.isshap() && (Tpar.TS() == TopAbs_EDGE) && (na>=2) && POCD->ParIs()) {
696         // see edges [4..na[ with of the name in t in [0..1] / range
697         if (na == 2) {
698           TopOpeBRepDS_Explorer x(HDS,TopAbs_EDGE,Standard_False);
699           for (;x.More();x.Next()) (*SeeShapefunc)(x.Index(),x.Current());
700         }
701         else {
702           for (ia = i1arg+1; ia < na; ia++) { 
703             is = Draw::Atoi(a[ia]);
704             (*SeeShapefunc)(is,GetShape(is,Tpar.TS()));
705           }
706         }
707         ParFlag = OldParFlag;
708       }
709       else {
710         for (ia = i1arg+1; ia < na; ia++) { 
711           is = Draw::Atoi(a[ia]);
712           (*SeeShapefunc)(is,GetShape(is,Tpar.TS()));
713         }
714       }
715     }
716   } // isshap
717   
718   else if ( Tpar.isgeom() ) { 
719     // na == 2 : display all DS geometries of type TK
720     // na  > 2 : display DS geometries of type TK index Draw::Atoi(a[2])..a[narg-1])
721     if (na == 2 ) SeeGeometry(Tpar.TK());
722     else for (ia = i1arg+1; ia < na; ia++) SeeGeometry(Standard_Integer(Draw::Atoi(a[ia])),Tpar.TK());
723   }
724   
725   else if ( Tpar.isafev() ) {
726     // faces then edges then vertices
727     TopOpeBRepDS_Explorer x;
728     for (x.Init(HDS,TopAbs_FACE,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
729     for (x.Init(HDS,TopAbs_EDGE,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
730     for (x.Init(HDS,TopAbs_VERTEX,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
731   }
732   
733   else if ( Tpar.isedcu() ) {
734     // na == 2 : display curves of all DS edges
735     // na  > 2 : display curve of DS edges index Draw::Atoi(a[2])..a[narg-1])
736     if ( na == 2 ) {
737       TopOpeBRepDS_Explorer x(HDS,TopAbs_EDGE,Standard_False);
738       for (;x.More();x.Next()) SeeEdgeCurve(x.Index(),x.Edge());
739     }
740     else {
741       for (ia = i1arg+1; ia < na; ia++) { 
742         is = Draw::Atoi(a[ia]);
743         SeeEdgeCurve(is,GetShape(is,TopAbs_EDGE));
744       }
745     }
746   }
747   
748   else if ( Tpar.issect() ) { // na=2 all section edges,na>2 section edges (a[2]..a[na-1])
749     Standard_Integer ise,nse = BDS.NbSectionEdges(); 
750     if (na == 2) for (ise = 1; ise<=nse; ise++) SeeSectionEdge(ise);
751     else         for (ia = i1arg+1; ia<na; ia++) SeeSectionEdge(Draw::Atoi(a[ia]));
752   }
753
754   else if (Tpar.isdege()) {      
755     TopOpeBRepDS_Explorer x;
756     for (x.Init(HDS,TopAbs_EDGE);x.More();x.Next()) {
757       if (BRep_Tool::Degenerated(x.Edge())) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
758     }
759   }
760   
761   return 0;
762 } // tsee_SeeShapefunc
763
764 //-----------------------------------------------------------------------
765 // tsee
766 //-----------------------------------------------------------------------
767 Standard_Integer tsee(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
768 {
769   if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
770     tsee_help(a[0],di);
771     return 0; 
772   }
773   tf_SeeShape ssf = (tf_SeeShape)SeeShapeIS;
774   Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
775   return r;
776 } // tsee
777
778 //-----------------------------------------------------------------------
779 // SeeAnyKI
780 //-----------------------------------------------------------------------
781 Standard_Integer SeeAnyKI(const TopOpeBRepDS_Kind TK,const Standard_Integer I) {
782   TopAbs_ShapeEnum TS = TopAbs_COMPOUND;
783   Standard_Boolean isshape,isgeome; isshape = isgeome = Standard_False;
784   isshape = TopOpeBRepDS::IsTopology(TK);
785   if (isshape) TS = TopOpeBRepDS::KindToShape(TK);
786   else isgeome = TopOpeBRepDS::IsGeometry(TK);
787   if      (isshape) SeeShapeIS(I,GetShape(I,TS));
788   else if (isgeome) SeeGeometry(I,TK);
789   return 0;
790 }
791
792 //-----------------------------------------------------------------------
793 void AddShapeKI
794 //-----------------------------------------------------------------------
795 (TColStd_ListOfInteger& LOK,TColStd_ListOfInteger& LOI,
796  const TopOpeBRepDS_Kind K,const Standard_Integer I)
797 {
798   Standard_Boolean isshape,isgeome; isshape = isgeome = Standard_False;
799   isshape = TopOpeBRepDS::IsTopology(K);
800   if (!isshape)
801     isgeome = TopOpeBRepDS::IsGeometry(K);
802   
803   if (LOK.IsEmpty() && LOI.IsEmpty()) { 
804     LOK.Append((Standard_Integer)K); LOI.Append(I); 
805     return; 
806   }
807   
808   // to sort, it is considered that : 
809   // POINT == VERTEX,CURVE == EDGE,SURFACE == FACE
810   
811   TopAbs_ShapeEnum SKtri=TopAbs_COMPOUND;
812
813   if (isshape) SKtri = TopOpeBRepDS::KindToShape(K);
814   else if (isgeome) {
815     if      (K == TopOpeBRepDS_POINT) SKtri = TopAbs_VERTEX; 
816     else if (K == TopOpeBRepDS_CURVE) SKtri = TopAbs_EDGE; 
817     else if (K == TopOpeBRepDS_SURFACE) SKtri = TopAbs_FACE; 
818   }
819   else return;
820   
821   TColStd_ListIteratorOfListOfInteger ITLOK(LOK);
822   TColStd_ListIteratorOfListOfInteger ITLOI(LOI);
823   Standard_Boolean equa = Standard_False;
824   for (; ITLOK.More(),ITLOI.More(); ITLOK.Next(),ITLOI.Next()) {
825 //JR/Hp
826     Standard_Integer ifK = ITLOK.Value() ;
827     TopOpeBRepDS_Kind fK = (TopOpeBRepDS_Kind) ifK ;
828     TopAbs_ShapeEnum fSK = TopOpeBRepDS::KindToShape(fK);
829 //    TopOpeBRepDS_Kind fK = (TopOpeBRepDS_Kind)ITLOK.Value(); TopAbs_ShapeEnum fSK = TopOpeBRepDS::KindToShape(fK);
830     Standard_Integer fI = ITLOI.Value();
831     if (SKtri == fSK && I == fI) {
832       equa = Standard_True;
833       break;
834     }
835     if (SKtri <= fSK) {
836       LOK.InsertBefore((Standard_Integer)K,ITLOK);
837       LOI.InsertBefore(I,ITLOI);
838       break;
839     }
840   }
841   if ( !ITLOK.More() && !equa) {
842     LOK.Append((Standard_Integer)K);
843     LOI.Append(I);
844   }
845 }
846
847 //-----------------------------------------------------------------------
848 // SeeShapeISI
849 //-----------------------------------------------------------------------
850 Standard_Integer SeeShapeISI(const Standard_Integer I,const TopoDS_Shape& S,Draw_Interpretor& di)
851 {
852   if ( !PHDSD ) return 0;
853   const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
854   if (S.IsNull()) return 0;  
855   SeeShapeIS(I,S);
856   
857   TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
858   const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
859   const TopOpeBRepDS_ListOfInterference& LOI = BDS.ShapeInterferences(S);
860   TopOpeBRepDS_ListIteratorOfListOfInterference ITLOI(LOI);
861   TColStd_ListOfInteger LOKK,LOII;
862   
863   for (;ITLOI.More();ITLOI.Next()) {
864     const Handle(TopOpeBRepDS_Interference)& HI = ITLOI.Value();
865     const TopOpeBRepDS_Transition& T = HI->Transition();
866     
867     TopAbs_ShapeEnum sb = T.ShapeBefore();TopOpeBRepDS_Kind sbk = TopOpeBRepDS::ShapeToKind(sb);
868     Standard_Integer sbi = T.IndexBefore();
869     TopAbs_ShapeEnum sa = T.ShapeAfter();TopOpeBRepDS_Kind sak = TopOpeBRepDS::ShapeToKind(sa);
870     Standard_Integer sai = T.IndexAfter();
871     TopOpeBRepDS_Kind gk,sk; Standard_Integer gi,si; HI->GKGSKS(gk,gi,sk,si);
872     
873     AddShapeKI(LOKK,LOII,sbk,sbi);
874     AddShapeKI(LOKK,LOII,sak,sai);
875     AddShapeKI(LOKK,LOII,gk,gi);
876     AddShapeKI(LOKK,LOII,sk,si);
877   }
878   
879   TColStd_ListIteratorOfListOfInteger ITLOKK,ITLOII;
880   
881   ITLOKK.Initialize(LOKK); ITLOII.Initialize(LOII);
882   Standard_Boolean ya = ITLOKK.More();
883   TopOpeBRepDS::Print(SK,I,cout,""," : ");
884   for(; ITLOKK.More(),ITLOII.More(); ITLOKK.Next(),ITLOII.Next()) {
885 //JR/Hp
886     Standard_Integer ikk = ITLOKK.Value() ;
887     TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind) ikk ;
888     Standard_Integer ii = ITLOII.Value();
889 //    TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind)ITLOKK.Value(); Standard_Integer ii = ITLOII.Value();
890     TopOpeBRepDS::Print(kk,ii,cout,""," ");
891   }
892   if (ya) di<<"\n"; else di<<"no shape interference\n";
893   
894   ITLOKK.Initialize(LOKK); ITLOII.Initialize(LOII);
895   for(; ITLOKK.More(),ITLOII.More(); ITLOKK.Next(),ITLOII.Next()) {
896 //JR/Hp
897     Standard_Integer ikk =ITLOKK.Value() ;
898     TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind) ikk ;
899     Standard_Integer ii = ITLOII.Value();
900 //    TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind)ITLOKK.Value(); Standard_Integer ii = ITLOII.Value();
901     SeeAnyKI(kk,ii);
902   }
903   //POP pour WNT
904   return 0;
905   
906 } // SeeShapeISI
907
908 //-----------------------------------------------------------------------
909 // SeeShapeTKIG
910 //-----------------------------------------------------------------------
911 Standard_Integer SeeShapeTKIG(const Standard_Integer I,const TopoDS_Shape& S)
912 {
913   if ( !PHDSD ) return 0;
914   const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
915   if (S.IsNull()) return 0;
916   SeeShapeIS(I,S);
917   
918   TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
919   const TopOpeBRepDS_ListOfInterference& LOI = HDS->DS().ShapeInterferences(S);
920   TopOpeBRepDS_TKI tki;
921   TCollection_AsciiString s1,s2;
922   
923   tki.Clear();
924   tki.FillOnGeometry(LOI);
925   s1=TopOpeBRepDS::SPrint(SK,I,""," by G : \n");
926   tki.Init();if (tki.More()) s2="\n";else s2="";
927   tki.DumpTKIIterator(s1,s2);
928   
929   return 0;
930 } // SeeShapeTKIG
931
932 //-----------------------------------------------------------------------
933 // SeeShapeTKIS
934 //-----------------------------------------------------------------------
935 Standard_Integer SeeShapeTKIS(const Standard_Integer I,const TopoDS_Shape& S)
936 {
937   if ( !PHDSD ) return 0;
938   const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
939   if (S.IsNull()) return 0;
940   SeeShapeIS(I,S);
941   
942   TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
943   const TopOpeBRepDS_ListOfInterference& LOI = HDS->DS().ShapeInterferences(S);
944   TopOpeBRepDS_TKI tki;
945   TCollection_AsciiString s1,s2;
946   
947   tki.Clear();
948   tki.FillOnSupport(LOI);
949   s1=TopOpeBRepDS::SPrint(SK,I,""," by S : \n");
950   tki.Init();if (tki.More()) s2="\n";else s2="";
951   tki.DumpTKIIterator(s1,s2); 
952   
953   return 0;
954 } // SeeShapeTKIS
955
956 //-----------------------------------------------------------------------
957 // SeeShapeTKI
958 //-----------------------------------------------------------------------
959 Standard_Integer SeeShapeTKI(const Standard_Integer I,const TopoDS_Shape& S,Draw_Interpretor& di)
960 {
961   di<<"\n";
962   SeeShapeTKIG(I,S);
963   SeeShapeTKIS(I,S);
964   return 0;
965 } // SeeShapeTKI
966
967 //-----------------------------------------------------------------------
968 // tseei
969 //-----------------------------------------------------------------------
970 Standard_Integer tseei(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
971 {
972   if (na_in == 1) { tseei_help(di); return 0; }
973   tf_SeeShape ssf = (tf_SeeShape)SeeShapeISI;
974   Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
975   return r;
976 } // tseei
977
978 //-----------------------------------------------------------------------
979 // tki
980 //-----------------------------------------------------------------------
981 Standard_Integer tki(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
982 {
983   if (na_in == 1) { tki_help(di); return 0; }
984   
985   tf_SeeShape ssf = NULL;
986   if      ( !strcasecmp(a[0],"tki") )  ssf = (tf_SeeShape)SeeShapeTKI;
987   else if ( !strcasecmp(a[0],"tkig") ) ssf = (tf_SeeShape)SeeShapeTKIG;
988   else if ( !strcasecmp(a[0],"tkis") ) ssf = (tf_SeeShape)SeeShapeTKIS;
989   if (ssf == NULL) return 0;
990   
991   Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
992   return r;
993 } // tki
994
995 //-----------------------------------------------------------------------
996 // 0 = tds
997 // 1 = kind of DS object to dump = [s] [so sh f w e v] [se] [su c p]
998 // 2,3 ... = [i1,i2 ...] = indices of DS object to see
999 //-----------------------------------------------------------------------
1000 Standard_Integer tds(Draw_Interpretor& di,Standard_Integer na,const char** a)
1001 {
1002   Standard_Integer ia ;
1003   for ( ia = 0; ia < na; ia++) {
1004     if (!strcasecmp(a[ia],"-ssi")) {
1005       suppressarg(na,a,ia);
1006       continue;
1007     }
1008     else if (!strncmp(a[ia],"-",1)) {
1009       TCollection_AsciiString as = a[ia];
1010       as.Remove(1,1);
1011       for(Standard_Integer i = 1;i <= as.Length(); i++) {
1012         if (as.Value(i) == 'h') { tds_help(di); return 0; }
1013       }
1014       suppressarg(na,a,ia);
1015     }
1016   }
1017   
1018   if (PHDSD == NULL) return 0;
1019   const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1020   if (HDS.IsNull()) {COUTNOHDS(di);return 0;}
1021   PHDSD->CurrentBDS();
1022
1023   return 0;
1024 }
1025
1026 Standard_Integer TPPE(Draw_Interpretor& di,Standard_Integer na,const char** a)
1027 {
1028   if (PHDSD == NULL) return 0;
1029   const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1030   if ( HDS.IsNull() ) { COUTNOHDS(di); return 0; }
1031   
1032   if (na != 5) return 1;
1033   Standard_Boolean ok = Standard_True;
1034   
1035   gp_Pnt pds;
1036   TopoDS_Edge ed;
1037   
1038   Standard_Integer ip = Draw::Atoi(a[2]);
1039   Standard_Integer ie = Draw::Atoi(a[4]);
1040   ok = ok && (ip >= 1); ok = ok && (ie >= 1);
1041   if (!ok) {
1042     di <<" bad data\n";
1043     return 1;
1044   }
1045   
1046   ok = Standard_False;
1047   if (!strcmp("p",a[1])){
1048     ok = Standard_True;
1049     ok = ok && (ip <= HDS->NbPoints());
1050     if (ok) pds = HDS->Point(ip).Point();
1051     if (!ok) di<<" geometry "<<ip<<" is not a point\n";
1052   }
1053   if (!strcmp("v",a[1])){
1054     ok = Standard_True;
1055     ok = ok && (ip <= HDS->NbShapes());
1056     if (ok) {
1057       TopoDS_Shape sh = HDS->Shape(ip,SFindKeep);
1058       ok = ok && (sh.ShapeType() == TopAbs_VERTEX);
1059       if (ok) pds =BRep_Tool::Pnt(TopoDS::Vertex(sh));
1060     }
1061     if (!ok) di<<" shape "<<ip<<" is not a vertex\n";
1062   } 
1063   if (!strcmp("e",a[3])){
1064     ok = ok && (ie <= HDS->NbShapes());
1065     if (ok) {
1066       TopoDS_Shape sh = HDS->Shape(ie,SFindKeep);
1067       ok = ok && (sh.ShapeType() == TopAbs_EDGE);
1068       if (ok) ed = TopoDS::Edge(sh);
1069     }
1070     if (!ok) di<<" shape "<<ie<<" is not an edge\n";
1071     
1072   } else ok = Standard_False;
1073   
1074   Standard_Real dmin=0;
1075   gp_Pnt pproj;
1076   if (ok) {
1077     Standard_Real f,l;
1078     Handle(Geom_Curve) cu = BRep_Tool::Curve(ed,f,l);
1079     GeomAPI_ProjectPointOnCurve ponc(pds,cu,f,l);
1080     ok = ponc.NbPoints() >= 1;
1081     
1082     if (ok) {
1083       dmin = ponc.LowerDistance();
1084       Standard_Real par = ponc.LowerDistanceParameter();
1085       BRepAdaptor_Curve bc(ed);
1086       pproj = bc.Value(par);
1087     } 
1088   }
1089   
1090   if (ok) {
1091     TCollection_AsciiString pp("p");
1092     pp.AssignCat(ip); pp.AssignCat("e"); pp.AssignCat(ie);
1093     char* ppp = (char *)pp.ToCString(); 
1094     DrawTrSurf::Set(ppp,pproj);
1095     di<<"dist point "<<ip<<" on edge "<<ie<<" = "<<dmin<<"\n";
1096   } else di<<"projection failed\n";
1097   
1098   return ok;
1099 } // TPPE
1100
1101 void FUN_ChkIntgInterf(Draw_Interpretor& di) //***Check Integrity Interference
1102 {
1103   if ( PHDSD == NULL ) return;
1104   PHDSD->CurrentHDS()->ChkIntg();
1105   di<<"Check interference integrity completed\n";
1106 }
1107
1108 void FUN_ChkIntgSamDomain(Draw_Interpretor& di) //***Check Integrity SameDomain
1109 {
1110   if ( PHDSD == NULL ) return;
1111   TopOpeBRepDS_Check C(PHDSD->CurrentHDS());
1112   if(C.ChkIntgSamDom())
1113     di<<"Check SameDomain integrity completed\n";
1114 }
1115
1116 void FUN_ChkIntg(Draw_Interpretor& di) //***Check Integrity
1117 {
1118   if ( PHDSD == NULL ) return;
1119   FUN_ChkIntgInterf(di);
1120   FUN_ChkIntgSamDomain(di);
1121 }
1122
1123 void FUN_ChkVertex(Draw_Interpretor& di) //***Check Vertex SameDomain
1124 {
1125   if ( PHDSD == NULL ) return;
1126   TopOpeBRepDS_Check C(PHDSD->CurrentHDS());
1127   if(C.OneVertexOnPnt())
1128     di<<"Check Structure Vertex SameDomain Complete\n";
1129 }
1130
1131 //---------------------------------------------------------
1132 Standard_Integer topochk(Draw_Interpretor& di,Standard_Integer na,const char** a)
1133 {
1134   if (strcmp(a[0],"topochk")) return 1;
1135   
1136   if(na < 2) {
1137     ::FUN_ChkIntg(di);
1138     ::FUN_ChkVertex(di);
1139   } 
1140   else if(na > 2) return 1;
1141   else if(!strcmp (a[1],"-i")) ::FUN_ChkIntg(di);
1142   else if(!strncmp(a[1],"-i",2)) {
1143     if     (!strcmp(a[1],"-ii"))  ::FUN_ChkIntgInterf(di);
1144     else if(!strcmp(a[1],"-isd")) ::FUN_ChkIntgSamDomain(di);
1145   }
1146   else if(!strcmp (a[1],"-s")) ::FUN_ChkVertex(di);
1147   else {
1148     di<<"option : -i   = check DS full integrity\n";
1149     di<<"option : -ii  = check only interferences\n";
1150     di<<"option : -isd = check only SameDomain data\n\n";
1151     di<<"option : -s   = check only SameDomain data on vertex\n";
1152     return 1;
1153   }
1154   return 0;
1155 }
1156
1157 //-----------------------------------------------------------------------
1158 // SeeShapeTCX
1159 //-----------------------------------------------------------------------
1160 Standard_Integer SeeShapeTCX(const Standard_Integer I,const TopoDS_Shape& S)
1161 {
1162   if ( !PHDSD ) return 0;
1163   const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1164   if (S.IsNull()) return 0;
1165   FDSCNX_Dump(HDS,I);
1166   return 0;
1167 } // SeeShapeTCX
1168
1169 static void tcx_help(Draw_Interpretor& di)
1170 {
1171   di<<"tcx : function not documented\n";
1172 }
1173
1174 //-----------------------------------------------------------------------
1175 // tcx
1176 //-----------------------------------------------------------------------
1177 Standard_Integer tcx(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
1178 {
1179   if (na_in == 1) { tcx_help(di); return 0; }
1180   Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,SeeShapeTCX);
1181   return r;
1182 } // tcx
1183
1184 #if 0
1185 //---------------------------------------------------------
1186 Standard_Integer tcx(Draw_Interpretor& di,Standard_Integer na,const char** a)
1187 {
1188   if (PHDSD == NULL) return 0;
1189   const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1190   if ( HDS.IsNull() ) { COUTNOHDS(di); return 0; }
1191   if      (na == 1) FDSCNX_Dump(HDS);
1192   else if (na == 2) {
1193     if   (ISINTEGER(a[1])) FDSCNX_Dump(HDS,Draw::Atoi(a[1]));
1194     else 
1195   }
1196   return 0;
1197 }
1198 #endif
1199
1200 //-----------------------------------------------------------------------
1201 Standard_Integer tdsri(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
1202 {
1203   if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
1204     tsee_help(a[0],di);
1205     return 0; 
1206   }
1207   Standard_Integer na = na_in;
1208   if ((PHDSD == NULL) || (POCD == NULL)) return 0;
1209   const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1210   if (HDS.IsNull()) { COUTNOHDS(di); return 0; }
1211   if (na < 5) return 1;
1212   TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
1213   
1214   Standard_Integer i1arg = 1;
1215   TDSpar Tpar(a[i1arg]);
1216   
1217   if ( strcasecmp(a[i1arg + 2],"i") ) return 0;
1218   Standard_Integer ii = Draw::Atoi(a[i1arg + 3]);  
1219 //  Standard_Integer ia,is,ig;
1220   Standard_Integer is;
1221   if ( Tpar.isshap() ) {
1222     is = Draw::Atoi(a[i1arg + 1]);
1223     const TopoDS_Shape& s = GetShape(is,Tpar.TS()); if (s.IsNull()) return 0;
1224     TopOpeBRepDS_ListOfInterference& li = BDS.ChangeShapeInterferences(is);
1225     Standard_Integer i=0; TopOpeBRepDS_ListIteratorOfListOfInterference it(li);
1226     while (it.More()) {
1227       if(++i == ii) {
1228         li.Remove(it);
1229       }
1230       else it.Next();
1231     }
1232   }
1233   return 0;
1234 } // tdsri
1235
1236 //=======================================================================
1237 //function : DSCommands
1238 //purpose  : 
1239 //=======================================================================
1240 void  TestTopOpe::HDSCommands(Draw_Interpretor& theCommands)
1241 {
1242   static Standard_Boolean done = Standard_False;
1243   if (done) return;
1244   done = Standard_True;
1245   PHDSD = (TestTopOpe_HDSDisplayer*) new (TestTopOpe_HDSDisplayer);
1246   POCD = (TestTopOpeDraw_Displayer*) new (TestTopOpeDraw_Displayer);
1247   
1248   const char* g = "Topological operation data structure commands";
1249   theCommands.Add("tseei","no args to get help",__FILE__,tseei,g);
1250   theCommands.Add("tsee","no args to get help ",__FILE__,tsee,g);
1251   theCommands.Add("tki","no args to get help ",__FILE__,tki,g);
1252   theCommands.Add("tkig","no args to get help ",__FILE__,tki,g);
1253   theCommands.Add("tkis","no args to get help ",__FILE__,tki,g);
1254   theCommands.Add("tds","-h to get help ",__FILE__,tds,g);
1255   theCommands.Add("tppe","tppe p/v <ip> e <ie>",__FILE__,TPPE);
1256   theCommands.Add("topochk","check current DS (loaded by CurrentDS()",__FILE__,topochk,g);
1257   theCommands.Add("tcx","dump connexity information",__FILE__,tcx,g);
1258   theCommands.Add("tdsri","remove interference : tdsri type itype iinterf",__FILE__,tdsri,g);
1259 }