1a4976fc74ce35401cc9aefe091d46e03da07de5
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_Dumper.cxx
1 // Created on: 1994-08-04
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
18 #include <Geom2d_BezierCurve.hxx>
19 #include <Geom2d_BSplineCurve.hxx>
20 #include <Geom2d_Circle.hxx>
21 #include <Geom2d_Curve.hxx>
22 #include <Geom2d_Ellipse.hxx>
23 #include <Geom2d_Hyperbola.hxx>
24 #include <Geom2d_Line.hxx>
25 #include <Geom2d_OffsetCurve.hxx>
26 #include <Geom2d_Parabola.hxx>
27 #include <Geom2d_TrimmedCurve.hxx>
28 #include <Geom_BezierCurve.hxx>
29 #include <Geom_BSplineCurve.hxx>
30 #include <Geom_Circle.hxx>
31 #include <Geom_Curve.hxx>
32 #include <Geom_Ellipse.hxx>
33 #include <Geom_Hyperbola.hxx>
34 #include <Geom_Line.hxx>
35 #include <Geom_OffsetCurve.hxx>
36 #include <Geom_Parabola.hxx>
37 #include <Geom_TrimmedCurve.hxx>
38 #include <GeomTools_Curve2dSet.hxx>
39 #include <GeomTools_CurveSet.hxx>
40 #include <gp_Pnt.hxx>
41 #include <gp_Pnt2d.hxx>
42 #include <Standard_Stream.hxx>
43 #include <TCollection_AsciiString.hxx>
44 #include <TopAbs.hxx>
45 #include <TopoDS_Edge.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <TopOpeBRepDS.hxx>
48 #include <TopOpeBRepDS_Curve.hxx>
49 #include <TopOpeBRepDS_CurveExplorer.hxx>
50 #include <TopOpeBRepDS_CurveIterator.hxx>
51 #include <TopOpeBRepDS_define.hxx>
52 #include <TopOpeBRepDS_Dumper.hxx>
53 #include <TopOpeBRepDS_HDataStructure.hxx>
54 #include <TopOpeBRepDS_Interference.hxx>
55 #include <TopOpeBRepDS_Point.hxx>
56 #include <TopOpeBRepDS_PointExplorer.hxx>
57 #include <TopOpeBRepDS_ShapeShapeInterference.hxx>
58 #include <TopOpeBRepDS_Surface.hxx>
59 #include <TopOpeBRepDS_SurfaceCurveInterference.hxx>
60 #include <TopOpeBRepDS_SurfaceExplorer.hxx>
61 #include <TopOpeBRepTool_ShapeTool.hxx>
62
63 #include <string.h>
64 //=======================================================================
65 //function : TopOpeBRepDS_Dumper::TopOpeBRepDS_Dumper
66 //purpose  : 
67 //=======================================================================
68 TopOpeBRepDS_Dumper::TopOpeBRepDS_Dumper(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
69 {
70   myHDS = HDS;
71 }
72
73 //=======================================================================
74 //function : PrintType
75 //purpose  : 
76 //=======================================================================
77
78 Standard_OStream& TopOpeBRepDS_Dumper::PrintType(const Handle(Geom_Curve)&
79 #ifdef OCCT_DEBUG
80                                                                            C
81 #endif
82                                                  ,Standard_OStream& OS)
83 {
84 #ifdef OCCT_DEBUG
85   if (C.IsNull()) {
86     OS<<"NULL CURVE";
87     return OS;
88   }
89   Handle(Standard_Type) T = C->DynamicType();
90   if      (T==STANDARD_TYPE(Geom_Circle))       OS<<"CIRCLE";
91   else if (T==STANDARD_TYPE(Geom_Line))         OS<<"LINE";
92   else if (T==STANDARD_TYPE(Geom_Ellipse))      OS<<"ELLIPSE";
93   else if (T==STANDARD_TYPE(Geom_Parabola))     OS<<"ELLIPSE";
94   else if (T==STANDARD_TYPE(Geom_Hyperbola))    OS<<"HYPERBOLA";
95   else if (T==STANDARD_TYPE(Geom_BezierCurve))  OS<<"BEZIER";
96   else if (T==STANDARD_TYPE(Geom_BSplineCurve)) 
97     OS<<"BSPLINE("<<Handle(Geom_BSplineCurve)::DownCast (C)->Degree()<<")";
98   else if (T==STANDARD_TYPE(Geom_TrimmedCurve))
99     {OS<<"TRIMMED ";PrintType(Handle(Geom_TrimmedCurve)::DownCast(C)->BasisCurve(),OS);}
100   else if (T==STANDARD_TYPE(Geom_OffsetCurve))  OS<<"OFFSETCURVE";
101   else                                 OS<<"***UNKNOWN***";
102   if (T!=STANDARD_TYPE(Geom_TrimmedCurve)) OS<<"3D";
103 #endif
104   
105   return OS;
106 }
107
108 //=======================================================================
109 //function : PrintType
110 //purpose  : 
111 //=======================================================================
112
113 Standard_OStream& TopOpeBRepDS_Dumper::PrintType(const Handle(Geom2d_Curve)&
114 #ifdef OCCT_DEBUG
115                                                                              C
116 #endif
117                                                  ,Standard_OStream& OS)
118 {
119 #ifdef OCCT_DEBUG
120   if (C.IsNull()) {
121     OS<<"NULL CURVE2d";
122     return OS;
123   }
124   Handle(Standard_Type) T = C->DynamicType();
125   if      (T==STANDARD_TYPE(Geom2d_Circle))       OS<<"CIRCLE";
126   else if (T==STANDARD_TYPE(Geom2d_Line))         OS<<"LINE";
127   else if (T==STANDARD_TYPE(Geom2d_Ellipse))      OS<<"ELLIPSE";
128   else if (T==STANDARD_TYPE(Geom2d_Parabola))     OS<<"ELLIPSE";
129   else if (T==STANDARD_TYPE(Geom2d_Hyperbola))    OS<<"HYPERBOLA";
130   else if (T==STANDARD_TYPE(Geom2d_BezierCurve))  OS<<"BEZIER";
131   else if (T==STANDARD_TYPE(Geom2d_BSplineCurve)) 
132     OS<<"BSPLINE("<<Handle(Geom2d_BSplineCurve)::DownCast (C)->Degree()<<")";
133   else if (T==STANDARD_TYPE(Geom2d_TrimmedCurve)) 
134     {OS<<"TRIMMED ";PrintType(Handle(Geom2d_TrimmedCurve)::DownCast(C)->BasisCurve(),OS);}
135   else if (T==STANDARD_TYPE(Geom2d_OffsetCurve))  OS<<"OFFSETCURVE";
136   else                                   OS<<"***UNKNOWN***";
137   if (T!=STANDARD_TYPE(Geom2d_TrimmedCurve)) OS<<"2D";
138 #endif
139   
140   return OS;
141 }
142
143 //=======================================================================
144 //function : Print
145 //purpose  : 
146 //=======================================================================
147
148 Standard_OStream& TopOpeBRepDS_Dumper::Print(const gp_Pnt&
149 #ifdef OCCT_DEBUG
150                                                            P
151 #endif
152                                              ,Standard_OStream& OS)
153 {
154 #ifdef OCCT_DEBUG
155   OS<<P.X()<<" "<<P.Y()<<" "<<P.Z()<<" ";
156 #endif
157   
158   return OS;
159 }
160
161
162 //=======================================================================
163 //function : Print
164 //purpose  : 
165 //=======================================================================
166
167 Standard_OStream& TopOpeBRepDS_Dumper::Print(const gp_Pnt2d&
168 #ifdef OCCT_DEBUG
169                                                              P
170 #endif
171                                              ,Standard_OStream& OS)
172 {
173 #ifdef OCCT_DEBUG
174   OS<<P.X()<<" "<<P.Y()<<" ";
175 #endif
176   
177   return OS;
178 }
179
180
181 //=======================================================================
182 //function : Print
183 //purpose  : 
184 //=======================================================================
185
186 Standard_OStream& TopOpeBRepDS_Dumper::Print(const Handle(Geom_BSplineCurve)&
187 #ifdef OCCT_DEBUG
188                                                                             B
189 #endif
190                                              ,Standard_OStream& OS
191                                              ,const Standard_Boolean
192 #ifdef OCCT_DEBUG
193                                                                      compact
194 #endif
195                                              )
196 {
197 #ifdef OCCT_DEBUG
198   Standard_Integer i,l,lb = 0,n;
199   
200   Standard_Integer degree   = B->Degree();
201   Standard_Integer nbpoles  = B->NbPoles();
202   Standard_Integer nbknots  = B->NbKnots();
203   Standard_Boolean rational = B->IsRational();
204   Standard_Boolean periodic = B->IsPeriodic();
205   
206   OS<<"BSplineCurve : "; 
207   if (periodic) OS<<"periodic, ";
208   OS<<"degree "<<degree<<", "<<nbpoles<<" poles, "<<nbknots<<" knots"<<endl;
209   
210   //l = strlen("poles : ") + 1
211   for (i = 1,OS<<"poles : ",l = 9,n = nbpoles; 
212        i<=n; 
213        i++) {
214     if (!compact)      { if (i == 1) lb = 0; else lb = l; }
215     else if (i == 1)   lb = 0; 
216     else if (i == 2)   lb = l;
217     else if (i == n-1) {
218       lb = l; 
219       if(n > 4) OS << setw(lb) << "\t  ...\n";
220     }
221     else if (i == n)   lb = l;
222     else continue;
223     
224     OS<<setw(lb)<<i<<" : ";
225     TopOpeBRepDS_Dumper::Print(B->Pole(i),OS);
226     if (rational) OS<<" "<<B->Weight(i);
227     
228     OS<<endl;
229   }
230   
231   //l = strlen("knots : ") + 1
232   for (i = 1,OS<<"knots : ",l = 9,n = nbknots;
233        i<=n;
234        i++) {
235     if (!compact)      { if (i == 1) lb = 0; else lb = l; }
236     else if (i == 1)   lb = 0;
237     else if (i == 2)   lb = l;
238     else if (i == n-1) {
239       if(n > 4) OS << setw(lb) << "\t  ...\n";
240       lb = l;
241     }
242     else if (i == n)   lb = l;
243     else continue;
244     
245     OS<<setw(lb)<<i<<" : ";
246     OS<<B->Knot(i)<<" "<<B->Multiplicity(i);
247     
248     OS<<endl;
249   }
250 #endif
251   
252   return OS;
253 }
254
255
256 //=======================================================================
257 //function : Print
258 //purpose  : 
259 //=======================================================================
260
261 Standard_OStream& TopOpeBRepDS_Dumper::Print(const Handle(Geom2d_BSplineCurve)&
262 #ifdef OCCT_DEBUG
263                                                                                 B
264 #endif
265                                              ,Standard_OStream& OS
266                                              ,const Standard_Boolean
267 #ifdef OCCT_DEBUG
268                                                                      compact
269 #endif
270                                              )
271 {
272 #ifdef OCCT_DEBUG
273   Standard_Integer i,l,lb=-1,n;
274   
275   Standard_Integer degree   = B->Degree();
276   Standard_Integer nbpoles  = B->NbPoles();
277   Standard_Integer nbknots  = B->NbKnots();
278   Standard_Boolean rational = B->IsRational();
279   Standard_Boolean periodic = B->IsPeriodic();
280   
281   OS<<"BSplineCurve : "; 
282   if (periodic) OS<<"periodic, ";
283   OS<<"degree "<<degree<<", "<<nbpoles<<" poles, "<<nbknots<<" knots"<<endl;
284   
285   //l = strlen("poles : ") + 1
286   for (i = 1,OS<<"poles : ",l = 9,n = nbpoles; 
287        i<=n; 
288        i++) {
289     if (!compact)      { if (i == 1) lb = 0; else lb = l; }
290     else if (i == 1)   lb = 0; 
291     else if (i == 2)   lb = l;
292     else if (i == n-1) {
293       lb = l;
294       if(n > 4) OS << setw(lb) << "\t  ...\n";
295     }
296     else if (i == n)   lb = l;
297     else continue;
298     
299     OS<<setw(lb)<<i<<" : ";
300     TopOpeBRepDS_Dumper::Print(B->Pole(i),OS);
301     if (rational) OS<<" "<<B->Weight(i);
302     
303     OS<<endl;
304   }
305   
306   //l = strlen("knots : ") + 1
307   for (i = 1,OS<<"knots : ",l = 9,n = nbknots; 
308        i<=n; 
309        i++) {
310     if (!compact)      { if (i == 1) lb = 0; else lb = l; }
311     else if (i == 1)   lb = 0;
312     else if (i == 2)   lb = l;
313     else if (i == n-1) {
314       lb = l;
315       if(n > 4) OS << setw(lb) << "\t  ...\n";
316     }
317     else if (i == n)   lb = l;
318     else continue;
319     
320     OS<<setw(lb)<<i<<" : "; 
321     OS<<B->Knot(i)<<" "<<B->Multiplicity(i);
322     
323     OS<<endl;
324   }
325 #endif
326   
327   return OS;
328 }
329
330
331 //=======================================================================
332 //function : Print
333 //purpose  : 
334 //=======================================================================
335
336 Standard_OStream& TopOpeBRepDS_Dumper::Print(const Handle(Geom_Curve)&
337 #ifdef OCCT_DEBUG
338                                                                        C
339 #endif
340                                              ,Standard_OStream& OS
341                                              ,const Standard_Boolean
342 #ifdef OCCT_DEBUG
343                                                                       compact
344 #endif
345                                              )
346 {
347 #ifdef OCCT_DEBUG
348 #define DBSP3D(tut) (*((Handle(Geom_BSplineCurve)*)&(tut)))
349   if (!C.IsNull()) {
350     if (C->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve))
351       TopOpeBRepDS_Dumper::Print(DBSP3D(C),OS,compact);
352     else 
353       GeomTools_CurveSet::PrintCurve(C,OS,Standard_False);
354   }
355 #endif
356   
357   return OS;
358 }
359
360
361 //=======================================================================
362 //function : Print
363 //purpose  : 
364 //=======================================================================
365
366 #ifdef OCCT_DEBUG
367 Standard_OStream& TopOpeBRepDS_Dumper::Print(const Handle(Geom2d_Curve)& C,
368                                 Standard_OStream& OS,const Standard_Boolean compact)
369 {
370 #define DBSP2D(tut) (*((Handle(Geom2d_BSplineCurve)*)&(tut)))
371   if (!C.IsNull()) {
372     if (C->DynamicType() == STANDARD_TYPE(Geom2d_BSplineCurve)) 
373       TopOpeBRepDS_Dumper::Print(DBSP2D(C),OS,compact);
374     else 
375       GeomTools_Curve2dSet::PrintCurve2d(C,OS,Standard_False);
376   }
377   
378   return OS;
379 }
380 #endif
381
382 // DUMP OF HDATASTRUCTURE
383
384 //-----------------------------------------------------------------------
385 #ifdef OCCT_DEBUG
386 //unreferenced function, commented
387 /*static void souligne(const TCollection_AsciiString& t,Standard_OStream& OS,const char c = '-') 
388 { for(char i=0;i<t.Length();i++)OS<<c; }*/
389 //-----------------------------------------------------------------------
390 // print the name of a Kind on a AsciiString.
391 static TCollection_AsciiString& Print(const TopOpeBRepDS_Kind k,TCollection_AsciiString& s)
392 {
393   switch(k) {
394   case TopOpeBRepDS_SURFACE : s.AssignCat("SURFACE");break;
395   case TopOpeBRepDS_CURVE   : s.AssignCat("CURVE");break;
396   case TopOpeBRepDS_POINT   : s.AssignCat("POINT");break;
397   case TopOpeBRepDS_SOLID   : s.AssignCat("SOLID");break;
398   case TopOpeBRepDS_SHELL   : s.AssignCat("SHELL");break;
399   case TopOpeBRepDS_FACE    : s.AssignCat("FACE");break;
400   case TopOpeBRepDS_WIRE    : s.AssignCat("WIRE");break;
401   case TopOpeBRepDS_EDGE    : s.AssignCat("EDGE");break;
402   case TopOpeBRepDS_VERTEX  : s.AssignCat("VERTEX");break;
403   default:
404     break ;
405   }
406   return s;
407 }
408 #endif
409
410
411 //=======================================================================
412 //function : Dump
413 //purpose  : 
414 //=======================================================================
415
416 Standard_OStream& TopOpeBRepDS_Dumper::Dump(Standard_OStream& OS
417                                             ,const Standard_Boolean
418 #ifdef OCCT_DEBUG
419                                                                     findkeep
420 #endif
421                                             ,const Standard_Boolean
422 #ifdef OCCT_DEBUG
423                                                                     compact
424 #endif
425                                             ) const
426 {
427 #ifdef OCCT_DEBUG
428   OS<<endl<<"==== HDS start filling resume"<<endl;
429   DumpGeometry(OS,findkeep,compact);
430   DumpTopology(OS);
431   OS<<endl<<"==== HDS end filling resume"<<endl;
432 #endif
433   return OS;
434 }
435
436
437 //=======================================================================
438 //function : DumpGeometry
439 //purpose  : 
440 //=======================================================================
441 Standard_OStream& TopOpeBRepDS_Dumper::DumpGeometry(Standard_OStream& OS
442                                                     ,const Standard_Boolean
443 #ifdef OCCT_DEBUG
444                                                                             findkeep
445 #endif
446                                                     ,const Standard_Boolean
447 #ifdef OCCT_DEBUG
448                                                                             compact
449 #endif
450                                                     ) const
451 {
452 #ifdef OCCT_DEBUG
453   DumpGeometry(TopOpeBRepDS_POINT,OS,findkeep,compact);
454   DumpGeometry(TopOpeBRepDS_CURVE,OS,findkeep,compact);
455   DumpGeometry(TopOpeBRepDS_SURFACE,OS,findkeep,compact);
456 #endif
457   return OS;
458 }
459
460
461 //=======================================================================
462 //function : DumpGeometry
463 //purpose  : 
464 //=======================================================================
465
466 Standard_OStream& TopOpeBRepDS_Dumper::DumpGeometry
467                                        (const TopOpeBRepDS_Kind
468 #ifdef OCCT_DEBUG
469                                                                 K
470 #endif
471                                         ,Standard_OStream& OS
472                                         ,const Standard_Boolean
473 #ifdef OCCT_DEBUG
474                                                                 findkeep
475 #endif
476                                         ,const Standard_Boolean
477 #ifdef OCCT_DEBUG
478                                                                 compact
479 #endif
480                                         ) const
481 {
482 #ifdef OCCT_DEBUG
483   if ( ! TopOpeBRepDS::IsGeometry(K) ) return OS;
484   Standard_Integer nt = myHDS->NbGeometry(K);
485   if (!nt) return OS;
486   
487   Standard_Integer n=0;
488   if     (K==TopOpeBRepDS_POINT){TopOpeBRepDS_PointExplorer ex(myHDS->DS(),findkeep);n=ex.NbPoint();}
489   else if(K==TopOpeBRepDS_CURVE){TopOpeBRepDS_CurveExplorer ex(myHDS->DS());n=ex.NbCurve();}
490   else if(K==TopOpeBRepDS_SURFACE){TopOpeBRepDS_SurfaceExplorer ex(myHDS->DS());n=ex.NbSurface();}
491   if (!n) return OS;
492   TCollection_AsciiString s = "---- "; ::Print(K,s);
493   OS<<endl<<s<<" : "<<n<<endl;
494   for(Standard_Integer i=1;i<=nt;i++) DumpGeometry(K,i,OS,findkeep,compact);
495 #endif
496   return OS;
497 }
498
499 //=======================================================================
500 //function : DumpGeometry
501 //purpose  : 
502 //=======================================================================
503
504 Standard_OStream& TopOpeBRepDS_Dumper::DumpGeometry(const TopOpeBRepDS_Kind
505 #ifdef OCCT_DEBUG
506                                                                             K
507 #endif
508                                                     ,const Standard_Integer
509 #ifdef OCCT_DEBUG
510                                                                             I
511 #endif
512                                                     ,Standard_OStream& OS,
513                                                     const Standard_Boolean
514 #ifdef OCCT_DEBUG
515                                                                            findkeep
516 #endif
517                                                     ,const Standard_Boolean
518 #ifdef OCCT_DEBUG
519                                                                             compact
520 #endif
521                                                      ) const
522 {
523 #ifdef OCCT_DEBUG
524   if ( ! TopOpeBRepDS::IsGeometry(K) ) return OS;
525   
526   if      ( K == TopOpeBRepDS_POINT ) {
527     TopOpeBRepDS_PointExplorer pex(myHDS->DS());
528     Standard_Boolean isp = pex.IsPoint(I);
529     Standard_Boolean isk = pex.IsPointKeep(I);
530     if(!findkeep || isk) {
531       TCollection_AsciiString kstr;::Print(K,kstr);kstr=kstr+" "+I+" :";
532       Standard_Integer lk = kstr.Length();
533       OS<<kstr;
534       if (isp) {
535         const TopOpeBRepDS_Point& PDS = pex.Point(I);
536         OS<<" (K:"<<((isk)?"1":"0") <<")"<<endl;
537         OS<<"tol = "<<PDS.Tolerance()<<endl; 
538         TCollection_AsciiString istr(lk,' ');
539         const gp_Pnt& P = PDS.Point();
540         OS<<istr; OS<<P.X()<<" "<<P.Y()<<" "<<P.Z()<<endl;
541       }
542       else OS<<"unbounded"<<endl;
543     }
544   }
545   else if ( K == TopOpeBRepDS_CURVE ) {
546     TopOpeBRepDS_CurveExplorer cex(myHDS->DS());
547     Standard_Boolean isc = cex.IsCurve(I);
548     Standard_Boolean isk = cex.IsCurveKeep(I);
549     if(!findkeep || isk) {
550       TCollection_AsciiString kstr;::Print(K,kstr);kstr=kstr+" "+I+" :";
551       Standard_Integer lk = kstr.Length();
552       OS<<kstr;
553       if (isc) {
554         const TopOpeBRepDS_Curve& CDS = cex.Curve(I);
555         OS<<" (K:"<<((isk)?"1":"0")<<")";
556         OS<<" (M:"<<CDS.Mother()<<")"<<endl;
557         TCollection_AsciiString istr(lk+1,' ');
558         OS<<istr;PrintType(CDS.Curve(),OS);
559         OS<<" tol = "<<CDS.Tolerance()<<endl;
560         Standard_Real first,last;
561         if(CDS.Range(first,last))
562           OS<<istr<<"first = "<<first<<"  last = "<<last<<endl;
563         TopOpeBRepDS_InterferenceIterator it(myHDS->DS().CurveInterferences(I));
564         for (;it.More();it.Next()) it.Value()->Dump(OS,istr,"\n");
565         {
566           const Handle(TopOpeBRepDS_Interference)& SCI1 = CDS.GetSCI1();
567           const Handle(TopOpeBRepDS_Interference)& SCI2 = CDS.GetSCI2();
568           Handle(Geom2d_Curve) PC1,PC2;
569           if ( !SCI1.IsNull())
570             PC1 = Handle(TopOpeBRepDS_SurfaceCurveInterference)::DownCast(SCI1)->PCurve();
571           if ( !SCI2.IsNull())
572             PC2 = Handle(TopOpeBRepDS_SurfaceCurveInterference)::DownCast(SCI2)->PCurve();
573           
574           OS<<istr;OS<<"PC(SCI1) : ";Print(PC1,cout,compact);
575           OS<<istr;OS<<"PC(SCI2) : ";Print(PC2,cout,compact);
576           OS<<endl;
577         }
578       }
579       else OS<<"unbounded"<<endl;
580     }
581   }
582   
583   else if ( K == TopOpeBRepDS_SURFACE ) {
584     TopOpeBRepDS_SurfaceExplorer sex(myHDS->DS());
585     Standard_Boolean iss = sex.IsSurface(I);
586     Standard_Boolean isk = sex.IsSurfaceKeep(I);
587     if(!findkeep || isk) {
588       TCollection_AsciiString kstr; ::Print(K,kstr); kstr=kstr+" "+I+" : ";
589       Standard_Integer lk = kstr.Length();
590       OS<<kstr;
591       if (iss) {
592         const TopOpeBRepDS_Surface& SDS = sex.Surface(I);
593         OS<<" (K:"<<((isk)?"1":"0") <<")"<<endl;
594         OS<<"tol = "<<SDS.Tolerance()<<endl; 
595         {
596           TCollection_AsciiString istr(lk,' ');
597           TopOpeBRepDS_InterferenceIterator it(myHDS->SurfaceCurves(I));
598           for (;it.More();it.Next()) { 
599             OS<<istr; it.Value()->Dump(OS);OS<<endl; 
600           }
601         }
602       }
603       else OS<<"unbounded"<<endl;
604     }
605   }
606   else {
607     return OS;
608   }
609   
610 #endif
611   return OS;
612 }
613
614 // = = = = = = =  T O P O L O G Y
615
616 //=======================================================================
617 //function : DumpTopology
618 //purpose  : 
619 //=======================================================================
620 Standard_OStream& TopOpeBRepDS_Dumper::DumpTopology(Standard_OStream& OS) const
621 {
622 #ifdef OCCT_DEBUG
623   DumpTopology(TopOpeBRepDS_VERTEX,OS);
624   DumpTopology(TopOpeBRepDS_EDGE,OS);
625   DumpTopology(TopOpeBRepDS_WIRE,OS);
626   DumpTopology(TopOpeBRepDS_FACE,OS);
627   DumpTopology(TopOpeBRepDS_SHELL,OS);
628   DumpTopology(TopOpeBRepDS_SOLID,OS);
629   DumpSectionEdge(TopOpeBRepDS_EDGE,OS);
630 #endif
631   return OS;
632 }
633
634 //=======================================================================
635 //function : DumpTopology
636 //purpose  : 
637 //=======================================================================
638 Standard_OStream& TopOpeBRepDS_Dumper::DumpTopology(const TopOpeBRepDS_Kind
639 #ifdef OCCT_DEBUG
640                                                                             K
641 #endif
642                                                     ,Standard_OStream& OS) const
643 {
644 #ifdef OCCT_DEBUG
645   if ( ! TopOpeBRepDS::IsTopology(K) ) return OS;
646   Standard_Integer nk = myHDS->NbTopology(K);
647   if ( ! nk ) return OS;
648   
649   OS<<endl;
650   TCollection_AsciiString s = "---- "; ::Print(K,s); 
651   Standard_Integer nt = myHDS->NbTopology();
652   OS<<s<<" : "<<nk<<"/"<<nt<<" shapes"<<endl;
653   for(Standard_Integer i = 1; i <= nt; i++) DumpTopology(K,i,OS);
654 #endif
655   return OS;
656 }
657
658 //=======================================================================
659 //function : DumpTopology
660 //purpose  : 
661 //=======================================================================
662 Standard_OStream& TopOpeBRepDS_Dumper::DumpTopology(const TopAbs_ShapeEnum
663 #ifdef OCCT_DEBUG
664                                                                            T
665 #endif
666                                                     ,Standard_OStream& OS) const
667 {
668 #ifdef OCCT_DEBUG
669   DumpTopology(TopOpeBRepDS::ShapeToKind(T),OS);
670 #endif
671   return OS;
672 }
673
674 //=======================================================================
675 //function : DumpSectionEdge
676 //purpose  : 
677 //=======================================================================
678
679 Standard_OStream& TopOpeBRepDS_Dumper::DumpSectionEdge(const TopOpeBRepDS_Kind
680 #ifdef OCCT_DEBUG
681                                                                                K
682 #endif
683                                                        ,Standard_OStream& OS) const
684 {
685 #ifdef OCCT_DEBUG
686   Standard_Integer nse = myHDS->DS().NbSectionEdges();
687   if ( ! nse ) return OS;
688   
689   OS<<endl;
690   TCollection_AsciiString s = "---- ";
691   OS<<s<<"Section Edges : "<<nse<<" edges"<<endl;
692   for(Standard_Integer i = 1; i <= nse; i++) {
693     DumpSectionEdge(K,i,OS);
694   }
695 #endif
696   return OS;
697 }
698
699 //=======================================================================
700 //function : DumpSectionEdge
701 //purpose  : 
702 //=======================================================================
703 Standard_OStream& TopOpeBRepDS_Dumper::DumpSectionEdge(const TopOpeBRepDS_Kind K,const Standard_Integer I,Standard_OStream& OS) const
704 {
705   Standard_Boolean SEFindKeep = Standard_False;
706   const TopOpeBRepDS_DataStructure& DS = myHDS->DS();
707   const TopoDS_Shape& E = DS.SectionEdge(I,SEFindKeep);
708   if(E.IsNull()) return OS;
709   Standard_Integer it = myHDS->DS().Shape(E,SEFindKeep);
710   if (it == 0) {
711     // E trouvee "Restriction" par les intersections n'est pas dans la DS.
712     OS<<endl<<"EDGE section "<<I<<" non Shape()"<<endl;
713   }
714   else DumpTopology(K,it,OS);
715   return OS;
716 }
717
718 Standard_EXPORT Standard_Integer TopOpeBRepDS_GLOBALHDSinterfselector = 0; // NYI arg of Dump method
719
720 //=======================================================================
721 //function : DumpTopology
722 //purpose  : 
723 //=======================================================================
724 Standard_OStream& TopOpeBRepDS_Dumper::DumpTopology(const TopOpeBRepDS_Kind
725 #ifdef OCCT_DEBUG
726                                                                             K
727 #endif
728                                                     ,const Standard_Integer
729 #ifdef OCCT_DEBUG
730                                                                             I
731 #endif
732                                                     ,Standard_OStream& OS) const
733 {
734 #ifdef OCCT_DEBUG
735   Standard_Boolean fk = Standard_False;
736   const TopOpeBRepDS_DataStructure& DS = myHDS->DS();
737   if ( ! TopOpeBRepDS::IsTopology(K) ) return OS;
738   if ( I <= 0 ) return OS;
739   TopAbs_ShapeEnum t = TopOpeBRepDS::KindToShape(K);
740   
741   if ( DS.Shape(I,fk).ShapeType() != t ) return OS;
742   Standard_Integer rankI = DS.AncestorRank(I);
743   TCollection_AsciiString s1,s2;
744   if(DS.KeepShape(I)) {
745     s1 = ((rankI == 1) ? (char*) "*" : (char*) "");
746     s2 = ((rankI == 2) ? (char*) "*" : (char*) "");
747   }
748   else {
749     s1 = ((rankI == 1) ? (char*) "~" : (char*) "");
750     s2 = ((rankI == 2) ? (char*) "~" : (char*) "");
751   }
752   TCollection_AsciiString ss = TopOpeBRepDS::SPrint(K,I,s1,s2);
753   
754   if ( t == TopAbs_VERTEX ) {
755     Standard_Integer lk = ss.Length() + 3;
756     TCollection_AsciiString istr(lk,' ');
757     gp_Pnt P = TopOpeBRepTool_ShapeTool::Pnt(DS.Shape(I,fk));
758     Standard_Real tol = TopOpeBRepTool_ShapeTool::Tolerance(DS.Shape(I,fk));
759     OS<<"\n"<<ss<<" : ";
760     OS<<"tol = "<<tol<<endl;
761     OS<<istr; OS<<P.X()<<" "<<P.Y()<<" "<<P.Z()<<endl;
762   }
763   
764   Standard_Integer lss = ss.Length();TCollection_AsciiString bss(lss,' ');
765   OS<<ss;OS.flush();
766   
767   // Interferences
768   TopOpeBRepDS_InterferenceIterator it; it.Init(DS.ShapeInterferences(I));
769   if (it.More()) {
770     OS<<" interferences :\n";
771     for (;it.More();it.Next()) {
772       const Handle(TopOpeBRepDS_Interference)& IR = it.Value(); Standard_Boolean s = Standard_True;
773       if (TopOpeBRepDS_GLOBALHDSinterfselector == 1)
774         s = !(Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(IR)).IsNull();
775       if (s) IR->Dump(OS,"","\n");
776     }
777   }
778   else OS<<" has no interference\n";
779   
780   // SameDomain
781   const TopoDS_Shape& S = myHDS->Shape(I,fk);
782   if ( myHDS->HasSameDomain(S) ) {
783     const TopTools_ListOfShape& L = myHDS->DS().ShapeSameDomain(S); 
784     if ( L.Extent() ) {
785       OS<<ss<<" same domain (r,o)  : "<<SDumpRefOri(S)<<endl;
786       OS<<SPrintShapeRefOri(L,bss+" same domain shapes : ");
787     }
788   }
789   
790   OS.flush();
791 #endif
792   return OS;
793 }
794
795 //=======================================================================
796 //function : DumpTopology
797 //purpose  : 
798 //=======================================================================
799 Standard_OStream& TopOpeBRepDS_Dumper::DumpTopology(const TopAbs_ShapeEnum
800 #ifdef OCCT_DEBUG
801                                                                            T
802 #endif
803                                                     ,const Standard_Integer
804 #ifdef OCCT_DEBUG
805                                                                             I
806 #endif
807                                                     ,Standard_OStream& OS) const
808 {
809 #ifdef OCCT_DEBUG
810   DumpTopology(TopOpeBRepDS::ShapeToKind(T),I,OS);
811 #endif
812   return OS;
813 }
814
815 //=======================================================================
816 //function : SDumpRefOri
817 //purpose  : 
818 //=======================================================================
819
820 TCollection_AsciiString TopOpeBRepDS_Dumper::SDumpRefOri(const TopOpeBRepDS_Kind K,const Standard_Integer I) const
821 {
822   TCollection_AsciiString SS;
823   Standard_Boolean fk = Standard_False;
824   const TopOpeBRepDS_DataStructure& DS = myHDS->DS();
825   if ( ! TopOpeBRepDS::IsTopology(K) ) return SS;
826   TopAbs_ShapeEnum t = TopOpeBRepDS::KindToShape(K);
827   if ( DS.Shape(I,fk).ShapeType() != t ) return SS;
828   const TopoDS_Shape& S = myHDS->Shape(I,fk);
829   Standard_Integer  r = myHDS->SameDomainReference(S);
830   TopOpeBRepDS_Config o = myHDS->SameDomainOrientation(S);
831   SS=SS+"("+SPrintShape(r)+","+TopOpeBRepDS::SPrint(o)+")";
832   return SS;
833 }
834
835 //=======================================================================
836 //function : SDumpRefOri
837 //purpose  : 
838 //=======================================================================
839
840 TCollection_AsciiString TopOpeBRepDS_Dumper::SDumpRefOri(const TopoDS_Shape& S) const
841 {
842   TCollection_AsciiString SS;
843   TopOpeBRepDS_Kind k = TopOpeBRepDS::ShapeToKind(S.ShapeType());
844   Standard_Boolean fk = Standard_False;
845   Standard_Integer i = myHDS->Shape(S,fk);
846   SS = SDumpRefOri(k,i);
847   return SS;
848 }
849
850 //=======================================================================
851 //function : DumpRefOri
852 //purpose  : 
853 //=======================================================================
854
855 Standard_OStream& TopOpeBRepDS_Dumper::DumpRefOri(const TopOpeBRepDS_Kind
856 #ifdef OCCT_DEBUG
857                                                                           K
858 #endif
859                                                   ,const Standard_Integer
860 #ifdef OCCT_DEBUG
861                                                                           I
862 #endif
863                                                   ,Standard_OStream& OS) const
864 {
865 #ifdef OCCT_DEBUG
866   OS<<SDumpRefOri(K,I);OS.flush();
867 #endif
868   return OS;
869 }
870
871 //=======================================================================
872 //function : DumpRefOri
873 //purpose  : 
874 //=======================================================================
875
876 Standard_OStream& TopOpeBRepDS_Dumper::DumpRefOri(const TopoDS_Shape&
877 #ifdef OCCT_DEBUG
878                                                                       S
879 #endif
880                                                   ,Standard_OStream& OS) const
881 {
882 #ifdef OCCT_DEBUG
883   OS<<SDumpRefOri(S);OS.flush();
884 #endif
885   return OS;
886 }
887
888 //=======================================================================
889 //function : DumpLOI
890 //purpose  : 
891 //=======================================================================
892
893 Standard_OStream& TopOpeBRepDS_Dumper::DumpLOI(
894                                 const TopOpeBRepDS_ListOfInterference&
895 #ifdef OCCT_DEBUG
896                                                                        L
897 #endif
898                                 ,Standard_OStream& OS,
899                                 const TCollection_AsciiString&
900 #ifdef OCCT_DEBUG
901                                                                str
902 #endif
903                                                                    ) const
904 {
905 #ifdef OCCT_DEBUG
906   OS<<str;
907   TopOpeBRepDS_InterferenceIterator IT(L); if (!IT.More()) { OS<<"NO INTERFERENCE"<<endl; return OS; }
908   OS<<endl;
909   for (Standard_Integer ip = 1; IT.More(); IT.Next(),ip++ ) {
910     const Handle(TopOpeBRepDS_Interference)& I = IT.Value();
911     TCollection_AsciiString s(ip); s = s + "/ ";
912     DumpI(I,OS,s,"\n");
913   }
914   OS<<endl;
915 #endif
916   return OS;
917 }
918
919 //=======================================================================
920 //function : DumpI
921 //purpose  : 
922 //=======================================================================
923 Standard_OStream& TopOpeBRepDS_Dumper::DumpI(
924                                 const Handle(TopOpeBRepDS_Interference)&
925 #ifdef OCCT_DEBUG
926                                                                          I
927 #endif
928                                 ,Standard_OStream& OS
929                                 ,const TCollection_AsciiString&
930 #ifdef OCCT_DEBUG
931                                                                 str1
932 #endif
933                                 ,const TCollection_AsciiString&
934 #ifdef OCCT_DEBUG
935                                                                 str2
936 #endif
937                                                                      ) const
938 {
939 #ifdef OCCT_DEBUG
940   Standard_Boolean fk = Standard_False;
941   OS<<str1;  
942   if (I.IsNull()) { OS<<"NULL INTERFERENCE"<<str2; return OS; }
943   Standard_Integer G = I->Geometry(); TopOpeBRepDS_Kind GK = I->GeometryType();
944   I->Dump(OS);
945   if      (GK == TopOpeBRepDS_POINT) { 
946     gp_Pnt P = myHDS->Point(G).Point();
947     OS<<" P = "<<P.X()<<" "<<P.Y()<<" "<<P.Z();
948   }
949   else if (GK == TopOpeBRepDS_VERTEX) { 
950     gp_Pnt P = TopOpeBRepTool_ShapeTool::Pnt(myHDS->Shape(G,fk));
951     OS<<" V = "<<P.X()<<" "<<P.Y()<<" "<<P.Z();
952   }
953   OS<<str2;
954   OS.flush();
955 #endif
956   return OS;
957 }
958
959 //=======================================================================
960 //function : SPrintShape
961 //purpose  : 
962 //=======================================================================
963
964 TCollection_AsciiString TopOpeBRepDS_Dumper::SPrintShape(const Standard_Integer IS) const
965 {
966   TCollection_AsciiString SS;
967   const TopOpeBRepDS_DataStructure& BDS = myHDS->DS(); if ( IS<1 || IS>BDS.NbShapes()) return SS;
968   SS = SPrintShape(BDS.Shape(IS));
969   return SS;
970 }
971
972 //=======================================================================
973 //function : SPrintShape
974 //purpose  : 
975 //=======================================================================
976
977 TCollection_AsciiString TopOpeBRepDS_Dumper::SPrintShape(const TopoDS_Shape& S) const
978 {
979   const TopOpeBRepDS_DataStructure& BDS = myHDS->DS();
980   const Standard_Integer IS = myHDS->DS().Shape(S);
981   Standard_Integer rankIS = BDS.AncestorRank(IS);
982 //JR/Hp  TCollection_AsciiString s1,s2;
983   Standard_CString s1,s2;
984   if(BDS.KeepShape(IS)) {
985     s1 = (Standard_CString ) ((rankIS == 1) ? "*" : "");
986     s2 = (Standard_CString ) ((rankIS == 2) ? "*" : "");
987   }
988   else {
989     s1 = (Standard_CString ) ((rankIS == 1) ? "~" : "");
990     s2 = (Standard_CString ) ((rankIS == 2) ? "~" : "");
991   }
992   TCollection_AsciiString sse = TopOpeBRepDS::SPrint(TopOpeBRepDS::ShapeToKind(S.ShapeType()),IS,s1,s2);
993   return sse;
994 }
995
996 //=======================================================================
997 //function : SPrintShapeRefOri
998 //purpose  : 
999 //=======================================================================
1000
1001 TCollection_AsciiString TopOpeBRepDS_Dumper::SPrintShapeRefOri(const TopoDS_Shape& S,const TCollection_AsciiString& astr) const
1002 { TCollection_AsciiString SS=astr+SPrintShape(S)+" "+SDumpRefOri(S); return SS; }
1003
1004 //=======================================================================
1005 //function : SPrintShapeRefOri
1006 //purpose  : 
1007 //=======================================================================
1008
1009 TCollection_AsciiString TopOpeBRepDS_Dumper::SPrintShapeRefOri(const TopTools_ListOfShape& L,const TCollection_AsciiString& astr) const
1010 {
1011   TCollection_AsciiString SS;TopTools_ListIteratorOfListOfShape it(L); if (!it.More()) return SS;
1012   SS=SS+astr; TCollection_AsciiString bst(astr.Length(),' ');
1013   for(Standard_Integer il = 0; it.More(); it.Next(),il++) {
1014     TCollection_AsciiString ss=SPrintShapeRefOri(it.Value());if (il) ss=bst+ss; SS=SS+ss+"\n";
1015   }
1016   return SS;
1017 }