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