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