0024059: Eliminate compiler warning C4701 in MSVC++ with warning level 4
[occt.git] / src / BRepTools / BRepTools_ShapeSet.cxx
1 // Created on: 1993-07-19
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-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 // Modifed:     Portage NT 7-5-97 DPF (strcasecmp)
22
23 #include <Standard_Stream.hxx>
24 #include <Precision.hxx>
25 #include <BRepTools_ShapeSet.ixx>
26
27 #include <BRepTools.hxx>
28 #include <Poly.hxx>
29 #include <TopoDS.hxx>
30 #include <TColStd_HArray1OfInteger.hxx>
31 #include <BRep_TFace.hxx>
32 #include <BRep_TEdge.hxx>
33 #include <BRep_TVertex.hxx>
34 #include <BRep_Tool.hxx>
35 #include <BRep_CurveRepresentation.hxx>
36 #include <Poly_Polygon3D.hxx>
37 #include <BRep_Polygon3D.hxx>
38 #include <BRep_PolygonOnSurface.hxx>
39 #include <BRep_PolygonOnClosedSurface.hxx>
40 #include <BRep_PolygonOnTriangulation.hxx>
41 #include <BRep_PolygonOnClosedTriangulation.hxx>
42 #include <BRep_CurveOnSurface.hxx>
43 #include <BRep_CurveOnClosedSurface.hxx>
44 #include <BRep_ListOfCurveRepresentation.hxx>
45 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
46 #include <BRep_PointOnCurve.hxx>
47 #include <BRep_PointOnCurveOnSurface.hxx>
48 #include <BRep_PointOnSurface.hxx>
49 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
50
51 #include <TopoDS_Vertex.hxx>
52
53 #include <TColgp_HArray1OfPnt.hxx>
54 #include <TColgp_HArray1OfPnt2d.hxx>
55 #include <TColStd_HArray1OfReal.hxx>
56 #include <Poly_Triangulation.hxx>
57 #include <Poly_PolygonOnTriangulation.hxx>
58
59 #include <Message_ProgressIndicator.hxx>
60 #include <Message_ProgressSentry.hxx>
61
62 #ifdef MacOS
63 #define strcasecmp(p,q) strcmp(p,q)
64 #elseif WNT
65 #define strcasecmp strcmp
66 #elseif AIX
67 #include <string.h>
68 #endif
69
70 // Modified:    02 Nov 2000: BUC60769. JMB, PTV.  In order to be able to read BRep 
71 //              files that came from a platform different from where CasCade 
72 //              is run, we need the following modifications.
73 //
74 //              On NT platforms (in BRepTools_ShapeSet):
75 //              ----------------
76 //                In Visual C++ 5 (or higher) the fstream::tellg method is not 
77 //                conform to Standard C++ because it modifies the file pointer
78 //                position and returns a wrong position. After that the next
79 //                readings are shifted and the reading process stop with errors.
80 //                
81 //                Workaround is following: Now we don`t use tellg for get position in stream.
82 //                Now able to read file (when reading TopAbs_FACE) without tellg. 
83 //                We simple check the next string if there are value that equal 2 
84 //               (It means a parametr for triangulation).
85
86
87 //=======================================================================
88 //function : BRepTools_ShapeSet
89 //purpose  : 
90 //=======================================================================
91
92 BRepTools_ShapeSet::BRepTools_ShapeSet(const Standard_Boolean isWithTriangles)
93      :myWithTriangles(isWithTriangles)
94 {
95 }
96
97 //=======================================================================
98 //function : BRepTools_ShapeSet
99 //purpose  : 
100 //=======================================================================
101
102 BRepTools_ShapeSet::BRepTools_ShapeSet (const BRep_Builder& B,
103                                         const Standard_Boolean isWithTriangles) :
104        myBuilder(B), myWithTriangles(isWithTriangles)
105 {
106 }
107
108
109 //=======================================================================
110 //function : Clear
111 //purpose  : 
112 //=======================================================================
113
114 void  BRepTools_ShapeSet::Clear()
115 {
116   mySurfaces.Clear();
117   myCurves.Clear();
118   myCurves2d.Clear();
119   myPolygons3D.Clear();
120   myPolygons2D.Clear();
121   myNodes.Clear();
122   myTriangulations.Clear();
123   TopTools_ShapeSet::Clear();
124 }
125
126
127 //=======================================================================
128 //function : AddGeometry
129 //purpose  : 
130 //=======================================================================
131
132 void BRepTools_ShapeSet::AddGeometry(const TopoDS_Shape& S)
133 {
134   // Add the geometry
135   
136   if (S.ShapeType() == TopAbs_VERTEX) {
137     
138     Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
139     BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
140     
141     while (itrp.More()) {
142       const Handle(BRep_PointRepresentation)& PR = itrp.Value();
143
144       if (PR->IsPointOnCurve()) {
145         myCurves.Add(PR->Curve());
146       }
147
148       else if (PR->IsPointOnCurveOnSurface()) {
149         myCurves2d.Add(PR->PCurve());
150         mySurfaces.Add(PR->Surface());
151       }
152
153       else if (PR->IsPointOnSurface()) {
154         mySurfaces.Add(PR->Surface());
155       }
156
157       ChangeLocations().Add(PR->Location());
158       itrp.Next();
159     }
160
161   }
162   else if (S.ShapeType() == TopAbs_EDGE) {
163
164     // Add the curve geometry
165     Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
166     BRep_ListIteratorOfListOfCurveRepresentation itrc(TE->Curves());
167
168     while (itrc.More()) {
169       const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
170       if (CR->IsCurve3D()) {
171         if (!CR->Curve3D().IsNull()) {
172           myCurves.Add(CR->Curve3D());
173           ChangeLocations().Add(CR->Location());
174         }
175       }
176       else if (CR->IsCurveOnSurface()) {
177         mySurfaces.Add(CR->Surface());
178         myCurves2d.Add(CR->PCurve());
179         ChangeLocations().Add(CR->Location());
180         if (CR->IsCurveOnClosedSurface())
181           myCurves2d.Add(CR->PCurve2());
182       }
183       else if (CR->IsRegularity()) {
184         mySurfaces.Add(CR->Surface());
185         ChangeLocations().Add(CR->Location());
186         mySurfaces.Add(CR->Surface2());
187         ChangeLocations().Add(CR->Location2());
188       }
189       else if (myWithTriangles) { // for XML Persistence
190         if (CR->IsPolygon3D()) {
191           if (!CR->Polygon3D().IsNull()) {
192             myPolygons3D.Add(CR->Polygon3D());
193             ChangeLocations().Add(CR->Location());
194           }
195         }
196         else if (CR->IsPolygonOnTriangulation()) {
197           myTriangulations.Add(CR->Triangulation());
198           myNodes.Add(CR->PolygonOnTriangulation());
199           ChangeLocations().Add(CR->Location());
200           if (CR->IsPolygonOnClosedTriangulation())
201             myNodes.Add(CR->PolygonOnTriangulation2());
202         }
203         else if (CR->IsPolygonOnSurface()) {
204           mySurfaces.Add(CR->Surface());
205           myPolygons2D.Add(CR->Polygon());
206           ChangeLocations().Add(CR->Location());
207           if (CR->IsPolygonOnClosedSurface())
208           myPolygons2D.Add(CR->Polygon2());
209         }
210       }
211       itrc.Next();
212     }
213   }
214
215   else if (S.ShapeType() == TopAbs_FACE) {
216
217     // Add the surface geometry
218     Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
219     if (!TF->Surface().IsNull())  mySurfaces.Add(TF->Surface());
220
221     if (myWithTriangles) { // for XML Persistence
222       Handle(Poly_Triangulation) Tr = TF->Triangulation();
223       if (!Tr.IsNull()) myTriangulations.Add(Tr);
224     }
225
226     ChangeLocations().Add(TF->Location());
227   }
228 }
229
230
231 //=======================================================================
232 //function : DumpGeometry
233 //purpose  : 
234 //=======================================================================
235
236 void  BRepTools_ShapeSet::DumpGeometry(Standard_OStream& OS)const 
237 {
238   myCurves2d.Dump(OS);
239   myCurves.Dump(OS);
240   DumpPolygon3D(OS);
241   DumpPolygonOnTriangulation(OS);
242   mySurfaces.Dump(OS);
243   DumpTriangulation(OS);
244 }
245
246
247 //=======================================================================
248 //function : WriteGeometry
249 //purpose  : 
250 //=======================================================================
251
252 void  BRepTools_ShapeSet::WriteGeometry(Standard_OStream& OS)
253 {
254   //OCC19559
255   myCurves2d.SetProgress(GetProgress());
256   myCurves.SetProgress(GetProgress());
257   mySurfaces.SetProgress(GetProgress());
258
259   if ( !GetProgress().IsNull()) {
260     if(GetProgress()->UserBreak() ) return;
261     GetProgress()->NewScope ( 15, "2D Curves" );
262   }
263   myCurves2d.Write(OS);
264   
265   if ( !GetProgress().IsNull()) {
266     if( GetProgress()->UserBreak() ) return;
267     GetProgress()->EndScope();
268     GetProgress()->Show();
269     
270     GetProgress()->NewScope ( 15, "3D Curves" );
271   }
272   myCurves.Write(OS);
273   
274   if ( !GetProgress().IsNull()) {
275     if( GetProgress()->UserBreak() ) return;
276     GetProgress()->EndScope();
277     GetProgress()->Show();
278   
279     GetProgress()->NewScope ( 10, "3D Polygons" );
280   }
281   WritePolygon3D(OS);
282   if ( !GetProgress().IsNull()) {
283     if( GetProgress()->UserBreak() ) return;
284     GetProgress()->EndScope();
285     GetProgress()->Show();
286
287     GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
288   }
289   WritePolygonOnTriangulation(OS);
290   if ( !GetProgress().IsNull()) {
291     if( GetProgress()->UserBreak() ) return;
292     GetProgress()->EndScope();
293     GetProgress()->Show();
294     
295     GetProgress()->NewScope ( 10, "Surfaces" );
296   }
297   mySurfaces.Write(OS);
298   if ( !GetProgress().IsNull()) {
299     if( GetProgress()->UserBreak() ) return;
300     GetProgress()->EndScope();
301     GetProgress()->Show();
302     
303     GetProgress()->NewScope ( 15, "Triangulations" );
304   }
305   WriteTriangulation(OS);
306   if ( !GetProgress().IsNull()) {
307     if( GetProgress()->UserBreak() ) return;
308     GetProgress()->EndScope();
309     GetProgress()->Show();
310   }
311 }
312
313
314 //=======================================================================
315 //function : ReadGeometry
316 //purpose  : 
317 //=======================================================================
318
319 void  BRepTools_ShapeSet::ReadGeometry(Standard_IStream& IS)
320 {
321   //OCC19559
322   myCurves2d.SetProgress(GetProgress());
323   myCurves.SetProgress(GetProgress());
324   mySurfaces.SetProgress(GetProgress());
325
326   if ( !GetProgress().IsNull()) {
327     if( GetProgress()->UserBreak() ) return;
328     GetProgress()->NewScope ( 15, "2D Curves" );
329   }
330   myCurves2d.Read(IS);
331
332   if ( !GetProgress().IsNull()) {
333     if( GetProgress()->UserBreak() ) return;
334     GetProgress()->EndScope();
335     GetProgress()->Show();
336     
337     GetProgress()->NewScope ( 15, "3D Curves" );
338   }
339   myCurves.Read(IS);
340
341   if ( !GetProgress().IsNull()) {
342     if( GetProgress()->UserBreak() ) return;
343     GetProgress()->EndScope();
344     GetProgress()->Show();
345     
346     GetProgress()->NewScope ( 10, "3D Polygons" );
347   }
348   ReadPolygon3D(IS);
349   if ( !GetProgress().IsNull() ) {
350     if( GetProgress()->UserBreak() ) return;
351     GetProgress()->EndScope();
352     GetProgress()->Show();
353
354     GetProgress()->NewScope ( 10, "Polygons On Triangulation" );
355   }
356   ReadPolygonOnTriangulation(IS);
357   if ( !GetProgress().IsNull()) {
358     if( GetProgress()->UserBreak() ) return;
359     GetProgress()->EndScope();
360     GetProgress()->Show();
361     
362     GetProgress()->NewScope ( 10, "Surfaces" );
363   }
364   mySurfaces.Read(IS);
365   if ( !GetProgress().IsNull() ) {
366     if( GetProgress()->UserBreak() ) return;
367     GetProgress()->EndScope();
368     GetProgress()->Show();
369
370     GetProgress()->NewScope ( 15, "Triangulations" );
371   }
372   ReadTriangulation(IS);
373   if ( !GetProgress().IsNull()) {
374     if( GetProgress()->UserBreak() ) return;
375     GetProgress()->EndScope();
376     GetProgress()->Show();
377   }
378 }
379
380 //=======================================================================
381 //function : PrintRegularity
382 //purpose  : 
383 //=======================================================================
384
385 static void PrintRegularity(const GeomAbs_Shape C,
386                             Standard_OStream& OS)
387 {
388   switch (C) {
389
390   case GeomAbs_C0 :
391     OS << "C0";
392     break;
393
394   case GeomAbs_G1 :
395     OS << "G1";
396     break;
397
398   case GeomAbs_C1 :
399     OS << "C1";
400     break;
401
402   case GeomAbs_G2 :
403     OS << "G2";
404     break;
405
406   case GeomAbs_C2 :
407     OS << "C2";
408     break;
409
410   case GeomAbs_C3 :
411     OS << "C3";
412     break;
413
414   case GeomAbs_CN :
415     OS << "CN";
416     break;
417
418   }
419 }
420
421 //=======================================================================
422 //function : DumpGeometry
423 //purpose  : 
424 //=======================================================================
425
426 void  BRepTools_ShapeSet::DumpGeometry(const TopoDS_Shape& S, 
427                                        Standard_OStream&   OS)const 
428 {
429   // Dump the geometry
430   
431   if (S.ShapeType() == TopAbs_VERTEX) {
432
433     // Dump the point geometry
434     TopoDS_Vertex V = TopoDS::Vertex(S);
435     OS << "    Tolerance : " << BRep_Tool::Tolerance(V) << "\n";
436     gp_Pnt p = BRep_Tool::Pnt(V);
437     OS << "    - Point 3D : "<<p.X()<<", "<<p.Y()<<", "<<p.Z()<<"\n";
438
439     Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
440     BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
441     
442     while (itrp.More()) {
443       const Handle(BRep_PointRepresentation)& PR = itrp.Value();
444
445       OS << "    - Parameter : "<< PR->Parameter();
446       if (PR->IsPointOnCurve()) {
447         OS << " on curve " << myCurves.Index(PR->Curve());
448       }
449
450       else if (PR->IsPointOnCurveOnSurface()) {
451         OS << " on pcurve " <<  myCurves2d.Index(PR->PCurve());
452         OS << " on surface " << mySurfaces.Index(PR->Surface());
453       }
454
455       else if (PR->IsPointOnSurface()) {
456         OS << ", " << PR->Parameter2() << " on surface ";
457         OS << mySurfaces.Index(PR->Surface());
458       }
459
460       if (!PR->Location().IsIdentity())
461         OS << " location " << Locations().Index(PR->Location());
462       OS << "\n";
463
464       itrp.Next();
465     }
466
467   }
468
469   else if (S.ShapeType() == TopAbs_EDGE) {
470
471     Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
472     gp_Pnt2d Pf,Pl;
473
474     // Dump the curve geometry 
475     OS << "    Tolerance : " << TE->Tolerance() << "\n";
476     if (TE->SameParameter()) OS << "     same parametrisation of curves\n";
477     if (TE->SameRange())     OS << "     same range on curves\n";
478     if (TE->Degenerated())   OS << "     degenerated\n";
479     
480     Standard_Real first, last;
481     BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
482     while (itrc.More()) {
483       const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
484       if (CR->IsCurve3D()) {
485         Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
486         GC->Range(first, last);
487         if (!CR->Curve3D().IsNull()) {
488           OS << "    - Curve 3D : "<<myCurves.Index(CR->Curve3D());
489           if (!CR->Location().IsIdentity())
490             OS << " location "<<Locations().Index(CR->Location());
491           OS <<", range : " << first << " " << last <<"\n";
492         }
493       }
494       else if (CR->IsCurveOnSurface()) {
495         Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
496         GC->Range(first, last);
497         OS <<"    - PCurve : "<<myCurves2d.Index(CR->PCurve());
498         if (CR->IsCurveOnClosedSurface()) {
499           OS <<", " << myCurves2d.Index(CR->PCurve2());
500           OS << " (";
501           PrintRegularity(CR->Continuity(),OS);
502           OS <<")";
503         }
504         OS << " on surface "<<mySurfaces.Index(CR->Surface());
505         if (!CR->Location().IsIdentity())
506           OS << " location "<<Locations().Index(CR->Location());
507         OS <<", range : " << first << " " << last <<"\n";
508         
509         Handle(BRep_CurveOnSurface) COS = 
510           Handle(BRep_CurveOnSurface)::DownCast(CR);
511         COS->UVPoints(Pf,Pl);
512         OS << "  UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
513         OS << Pl.X()<<", "<<Pl.Y()<<"\n";
514         if (CR->IsCurveOnClosedSurface()) {
515           Handle(BRep_CurveOnClosedSurface) COCS = 
516             Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
517           COCS->UVPoints2(Pf,Pl);
518           OS << "  UV Points : " <<Pf.X()<<", "<<Pf.Y()<<" ";
519           OS << Pl.X()<<", "<<Pl.Y()<<"\n";
520         }
521       }
522       else if (CR->IsRegularity()) {
523         OS << "    - Regularity ";
524         PrintRegularity(CR->Continuity(),OS);
525         OS << "   on surfaces : "<<mySurfaces.Index(CR->Surface());
526         if (!CR->Location().IsIdentity())
527           OS << " location "<<Locations().Index(CR->Location());
528         OS << ", "<<mySurfaces.Index(CR->Surface2());
529         if (!CR->Location2().IsIdentity())
530           OS << " location "<<Locations().Index(CR->Location2());
531         OS << "\n";
532       }
533       else if (CR->IsPolygon3D()) {
534         Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
535         if (!GC->Polygon3D().IsNull()) {
536           OS << "    - Polygon 3D : "<<myPolygons3D.FindIndex(CR->Polygon3D());
537           if (!CR->Location().IsIdentity())
538             OS << " location "<<Locations().Index(CR->Location());
539         }
540       }
541       else if (CR->IsPolygonOnTriangulation()) {
542         OS << "    - PolygonOnTriangulation " << myNodes.FindIndex(CR->PolygonOnTriangulation());
543         if (CR->IsPolygonOnClosedTriangulation()) {
544           OS << " " << myNodes.FindIndex(CR->PolygonOnTriangulation2());
545         }
546         OS << " on triangulation " << myTriangulations.FindIndex(CR->Triangulation());
547         if (!CR->Location().IsIdentity())
548           OS << " location "<<Locations().Index(CR->Location());
549         OS << endl;
550       }
551       itrc.Next();
552     }
553   }
554
555   else if (S.ShapeType() == TopAbs_FACE) {
556
557     const TopoDS_Face& F = TopoDS::Face(S);
558     if (BRep_Tool::NaturalRestriction(F))
559       OS << "NaturalRestriction\n";
560
561     // Dump the surface geometry
562     Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
563     if (!TF->Surface().IsNull()) {
564       OS << "    Tolerance : " <<TF->Tolerance() << "\n";
565       OS << "    - Surface : "<<mySurfaces.Index(TF->Surface());
566       if (!S.Location().IsIdentity())
567         OS << " location "<<Locations().Index(S.Location());
568       OS << "\n";
569     }
570     if (!(TF->Triangulation()).IsNull()) {
571       // Dump the triangulation
572       OS << "    - Triangulation : " <<myTriangulations.FindIndex(TF->Triangulation());
573       if (!S.Location().IsIdentity())
574         OS << " location " <<Locations().Index(TF->Location());
575       OS << "\n";
576     }
577   }
578  
579   OS << "\n";
580 }
581
582
583 //=======================================================================
584 //function : WriteGeometry
585 //purpose  : 
586 //=======================================================================
587
588 void  BRepTools_ShapeSet::WriteGeometry(const TopoDS_Shape& S, 
589                                         Standard_OStream&   OS)const 
590 {
591   // Write the geometry
592   
593   if (S.ShapeType() == TopAbs_VERTEX) {
594
595     // Write the point geometry
596     TopoDS_Vertex V = TopoDS::Vertex(S);
597     OS << BRep_Tool::Tolerance(V) << "\n";
598     gp_Pnt p = BRep_Tool::Pnt(V);
599     OS<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"\n";
600
601     Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(S.TShape());
602     BRep_ListIteratorOfListOfPointRepresentation itrp(TV->Points());
603     
604     while (itrp.More()) {
605       const Handle(BRep_PointRepresentation)& PR = itrp.Value();
606
607       OS << PR->Parameter();
608       if (PR->IsPointOnCurve()) {
609         OS << " 1 " << myCurves.Index(PR->Curve());
610       }
611
612       else if (PR->IsPointOnCurveOnSurface()) {
613         OS << " 2 " <<  myCurves2d.Index(PR->PCurve());
614         OS << " " << mySurfaces.Index(PR->Surface());
615       }
616
617       else if (PR->IsPointOnSurface()) {
618         OS << " 3 " << PR->Parameter2() << " ";
619         OS << mySurfaces.Index(PR->Surface());
620       }
621
622       OS << " " << Locations().Index(PR->Location());
623       OS << "\n";
624       
625       itrp.Next();
626     }
627     
628     OS << "0 0\n"; // end representations
629
630   }
631
632   else if (S.ShapeType() == TopAbs_EDGE) {
633
634     // Write the curve geometry 
635
636     Handle(BRep_TEdge) TE = Handle(BRep_TEdge)::DownCast(S.TShape());
637
638     OS << " " << TE->Tolerance() << " ";
639     OS << ((TE->SameParameter()) ? 1 : 0) << " ";
640     OS << ((TE->SameRange())     ? 1 : 0) << " ";
641     OS << ((TE->Degenerated())   ? 1 : 0) << "\n";
642     
643     Standard_Real first, last;
644     BRep_ListIteratorOfListOfCurveRepresentation itrc = TE->Curves();
645     while (itrc.More()) {
646       const Handle(BRep_CurveRepresentation)& CR = itrc.Value();
647       if (CR->IsCurve3D()) {
648         if (!CR->Curve3D().IsNull()) {
649           Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
650           GC->Range(first, last);
651           OS << "1 ";                               // -1- Curve 3D
652           OS << " "<<myCurves.Index(CR->Curve3D());
653           OS << " "<<Locations().Index(CR->Location());
654           OS << " "<<first<<" "<<last;
655           OS << "\n";
656         }
657       }
658       else if (CR->IsCurveOnSurface()) {
659         Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itrc.Value());
660         GC->Range(first, last);
661         if (!CR->IsCurveOnClosedSurface())
662           OS << "2 ";                             // -2- Curve on surf
663         else
664           OS << "3 ";                             // -3- Curve on closed surf
665         OS <<" "<<myCurves2d.Index(CR->PCurve());
666         if (CR->IsCurveOnClosedSurface()) {
667           OS <<" " << myCurves2d.Index(CR->PCurve2());
668           PrintRegularity(CR->Continuity(),OS);
669         }
670         OS << " " << mySurfaces.Index(CR->Surface());
671         OS << " " << Locations().Index(CR->Location());
672         OS << " "<<first<<" "<<last;
673         OS << "\n";
674
675         // Write UV Points // for XML Persistence higher performance
676         if (FormatNb() == 2)
677         {
678           gp_Pnt2d Pf,Pl;
679           if (CR->IsCurveOnClosedSurface()) {
680             Handle(BRep_CurveOnClosedSurface) COCS = 
681               Handle(BRep_CurveOnClosedSurface)::DownCast(CR);
682             COCS->UVPoints2(Pf,Pl);
683           }
684           else {
685             Handle(BRep_CurveOnSurface) COS = 
686               Handle(BRep_CurveOnSurface)::DownCast(CR);
687             COS->UVPoints(Pf,Pl);
688           }
689           OS << Pf.X() << " " << Pf.Y() << " " << Pl.X() << " " << Pl.Y() << "\n";
690         }
691       }
692       else if (CR->IsRegularity()) {
693         OS << "4 ";                              // -4- Regularity
694         PrintRegularity(CR->Continuity(),OS);
695         OS << " "<<mySurfaces.Index(CR->Surface());
696         OS << " "<<Locations().Index(CR->Location());
697         OS << " "<<mySurfaces.Index(CR->Surface2());
698         OS << " "<<Locations().Index(CR->Location2());
699         OS << "\n";
700       }
701
702       else if (myWithTriangles) { // for XML Persistence
703         if (CR->IsPolygon3D()) {
704           Handle(BRep_Polygon3D) GC = Handle(BRep_Polygon3D)::DownCast(itrc.Value());
705           if (!GC->Polygon3D().IsNull()) {
706             OS << "5 ";                            // -5- Polygon3D
707             OS << " "<<myPolygons3D.FindIndex(CR->Polygon3D());
708             OS << " "<<Locations().Index(CR->Location());
709             OS << "\n";
710           }
711         }
712         else if (CR->IsPolygonOnTriangulation()) {
713           Handle(BRep_PolygonOnTriangulation) PT = 
714             Handle(BRep_PolygonOnTriangulation)::DownCast(itrc.Value());
715           if (!CR->IsPolygonOnClosedTriangulation())
716             OS << "6 ";                            // -6- Polygon on triangulation
717           else
718             OS << "7 ";                            // -7- Polygon on closed triangulation
719           OS << " " <<  myNodes.FindIndex(PT->PolygonOnTriangulation());
720           if (CR->IsPolygonOnClosedTriangulation()) {
721             OS << " " << myNodes.FindIndex(PT->PolygonOnTriangulation2());
722           }
723           OS << " " << myTriangulations.FindIndex(PT->Triangulation());
724           OS << " "<<Locations().Index(CR->Location());
725           OS << "\n";
726         }
727       }
728       
729       itrc.Next();
730     }
731     OS << "0\n"; // end of the list of representations
732   }
733   
734   else if (S.ShapeType() == TopAbs_FACE) {
735
736     Handle(BRep_TFace) TF = Handle(BRep_TFace)::DownCast(S.TShape());
737     const TopoDS_Face& F = TopoDS::Face(S);
738
739     if (!(TF->Surface()).IsNull()) {
740       OS << ((BRep_Tool::NaturalRestriction(F)) ? 1 : 0);
741       OS << " ";
742       // Write the surface geometry
743       OS << " " <<TF->Tolerance();
744       OS << " " <<mySurfaces.Index(TF->Surface());
745       OS << " " <<Locations().Index(TF->Location());
746       OS << "\n";
747     }
748     else //For correct reading of null face
749       {
750         OS << 0;
751         OS << " ";
752         OS << " " <<TF->Tolerance();
753         OS << " " << 0;
754         OS << " " << 0;
755         OS << "\n";
756       }
757     if (myWithTriangles) { // for XML Persistence
758       if (!(TF->Triangulation()).IsNull()) {
759         OS << 2;
760         OS << " ";
761         // Write the triangulation
762         OS << " " <<myTriangulations.FindIndex(TF->Triangulation());
763       }
764     }
765   }
766   
767 }
768
769 //=======================================================================
770 //function : ReadRegularity
771 //purpose  : 
772 //=======================================================================
773
774 static GeomAbs_Shape ReadRegularity(Standard_IStream& IS)
775 {
776   char buffer[255];
777   IS >> buffer;
778   switch (buffer[0]) {
779
780   case 'C' :
781     switch (buffer[1]) {
782       
783     case '0' :
784       return GeomAbs_C0;
785       
786     case '1' :
787       return GeomAbs_C1;
788       
789     case '2' :
790       return GeomAbs_C2;
791       
792     case '3' :
793       return GeomAbs_C3;
794       
795     case 'N' :
796       return GeomAbs_CN;
797     }
798     break;
799
800   case 'G' :
801     switch (buffer[1]) {
802       
803     case '1' :
804       return GeomAbs_G1;
805       
806     case '2' :
807       return GeomAbs_G2;
808       
809     }
810     break;
811   }
812   return GeomAbs_C0;
813 }
814
815 //=======================================================================
816 //function : ReadGeometry
817 //purpose  : 
818 //=======================================================================
819
820 void  BRepTools_ShapeSet::ReadGeometry(const TopAbs_ShapeEnum T, 
821                                        Standard_IStream&      IS, 
822                                        TopoDS_Shape&          S)
823 {
824   // Read the geometry
825
826   Standard_Integer val,c,pc,pc2 = 0,s,s2,l,l2,t, pt, pt2 = 0;
827   Standard_Real tol,X,Y,Z,first,last,p1,p2;
828   Standard_Real PfX,PfY,PlX,PlY;
829   gp_Pnt2d aPf, aPl;
830   Standard_Boolean closed;
831   GeomAbs_Shape reg = GeomAbs_C0;
832   switch (T) {
833
834
835     //---------
836     // vertex
837     //---------
838
839   case TopAbs_VERTEX :
840     {
841       TopoDS_Vertex& V = TopoDS::Vertex(S);
842       
843       // Read the point geometry
844       IS >> tol;
845       IS >> X >> Y >> Z;
846       myBuilder.MakeVertex(V,gp_Pnt(X,Y,Z),tol);
847       Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V.TShape());
848
849       BRep_ListOfPointRepresentation& lpr = TV->ChangePoints();
850       TopLoc_Location L;
851
852       do {
853         IS >> p1 >> val;
854         
855         Handle(BRep_PointRepresentation) PR;
856         switch (val) {
857
858         case 1 :
859           {
860             IS >> c;
861
862 //  Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
863             if (myCurves.Curve(c).IsNull())
864               break;
865 //  Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
866
867             Handle(BRep_PointOnCurve) POC =
868               new BRep_PointOnCurve(p1,
869                                     myCurves.Curve(c),
870                                     L);
871             PR = POC;
872           }
873           break;
874
875         case 2 :
876           {
877             IS >> pc >> s;
878
879 //  Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
880             if (myCurves2d.Curve2d(pc).IsNull() ||
881                 mySurfaces.Surface(s).IsNull())
882               break;
883 //  Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
884
885             Handle(BRep_PointOnCurveOnSurface) POC =
886               new BRep_PointOnCurveOnSurface(p1,
887                                              myCurves2d.Curve2d(pc),
888                                              mySurfaces.Surface(s),
889                                              L);
890             PR = POC;
891           }
892           break;
893
894         case 3 :
895           {
896             IS >> p2 >> s;
897
898 //  Modified by Sergey KHROMOV - Wed Apr 24 13:59:09 2002 Begin
899             if (mySurfaces.Surface(s).IsNull())
900               break;
901 //  Modified by Sergey KHROMOV - Wed Apr 24 13:59:13 2002 End
902
903             Handle(BRep_PointOnSurface) POC =
904               new BRep_PointOnSurface(p1,p2,
905                                       mySurfaces.Surface(s),
906                                       L);
907             PR = POC;
908           }
909           break;
910         }
911
912         if (val > 0) {
913           IS >> l;
914           if (!PR.IsNull()) {
915             PR->Location(Locations().Location(l));
916             lpr.Append(PR);
917           }
918         }
919       } while (val > 0);
920     }
921     break;
922       
923
924     //---------
925     // edge
926     //---------
927
928
929     case TopAbs_EDGE :
930
931       // Create an edge
932       {
933         TopoDS_Edge& E = TopoDS::Edge(S);
934         
935         myBuilder.MakeEdge(E);
936         
937         // Read the curve geometry 
938         IS >> tol;
939         IS >> val;
940         myBuilder.SameParameter(E,(val == 1));
941         IS >> val;
942         myBuilder.SameRange(E,(val == 1));
943         IS >> val;
944         myBuilder.Degenerated(E,(val == 1));
945         
946         do {
947           IS >> val;
948           switch (val) {
949             
950           case 1 :                               // -1- Curve 3D
951             IS >> c >> l;
952             if (!myCurves.Curve(c).IsNull()) {
953               myBuilder.UpdateEdge(E,myCurves.Curve(c),
954                                    Locations().Location(l),tol);
955             }
956             IS >> first >> last;
957             if (!myCurves.Curve(c).IsNull()) {
958               Standard_Boolean Only3d = Standard_True;
959               myBuilder.Range(E,first,last,Only3d);
960             }
961             break;
962             
963             
964           case 2 :                               // -2- Curve on surf
965           case 3 :                               // -3- Curve on closed surf
966             closed = (val == 3);
967             IS >> pc;
968             if (closed) {
969               IS >> pc2;
970               reg = ReadRegularity(IS);
971             }
972
973             // surface, location
974             IS >> s >> l;
975
976             // range
977             IS >> first >> last;
978
979             // read UV Points // for XML Persistence higher performance
980             if (FormatNb() == 2)
981             {
982               IS >> PfX >> PfY >> PlX >> PlY;
983               aPf = gp_Pnt2d(PfX,PfY);
984               aPl = gp_Pnt2d(PlX,PlY);
985             }
986
987 //  Modified by Sergey KHROMOV - Wed Apr 24 12:11:16 2002 Begin
988             if (myCurves2d.Curve2d(pc).IsNull() ||
989                 (closed && myCurves2d.Curve2d(pc2).IsNull()) ||
990                 mySurfaces.Surface(s).IsNull())
991               break;
992 //  Modified by Sergey KHROMOV - Wed Apr 24 12:11:17 2002 End
993
994             if (closed) {
995               if (FormatNb() == 2)
996                 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
997                                      myCurves2d.Curve2d(pc2),
998                                      mySurfaces.Surface(s),
999                                      Locations().Location(l),tol,
1000                                      aPf, aPl);
1001               else
1002                 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1003                                      myCurves2d.Curve2d(pc2),
1004                                      mySurfaces.Surface(s),
1005                                      Locations().Location(l),tol);
1006
1007               myBuilder.Continuity(E,
1008                                    mySurfaces.Surface(s),
1009                                    mySurfaces.Surface(s),
1010                                    Locations().Location(l),
1011                                    Locations().Location(l),
1012                                    reg);
1013             }
1014             else
1015             {
1016               if (FormatNb() == 2)
1017                 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1018                                      mySurfaces.Surface(s),
1019                                      Locations().Location(l),tol,
1020                                      aPf, aPl);
1021               else
1022                 myBuilder.UpdateEdge(E,myCurves2d.Curve2d(pc),
1023                                      mySurfaces.Surface(s),
1024                                      Locations().Location(l),tol);
1025             }
1026             myBuilder.Range(E,
1027                             mySurfaces.Surface(s),
1028                             Locations().Location(l),
1029                             first,last);
1030             break;
1031             
1032           case 4 :                               // -4- Regularity
1033             reg = ReadRegularity(IS);
1034             IS >> s >> l >> s2 >> l2;
1035 //  Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1036             if (mySurfaces.Surface(s).IsNull() ||
1037                 mySurfaces.Surface(s2).IsNull())
1038               break;
1039 //  Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1040             myBuilder.Continuity(E,
1041                                  mySurfaces.Surface(s),
1042                                  mySurfaces.Surface(s2),
1043                                  Locations().Location(l),
1044                                  Locations().Location(l2),
1045                                  reg);
1046             break;
1047
1048           case 5 :   // -5- Polygon3D                            
1049             IS >> c >> l;
1050 //szy-02.05.2004            myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)));
1051                         if (c > 0 && c <= myPolygons3D.Extent())
1052                   myBuilder.UpdateEdge(E,Handle(Poly_Polygon3D)::DownCast(myPolygons3D(c)), Locations().Location(l));
1053             break;
1054
1055           case 6 :
1056           case 7 :
1057             closed = (val == 7);
1058             IS >> pt;
1059             if (closed) {
1060               IS >> pt2;
1061             }
1062             IS >> t >> l;
1063             if (closed) {
1064                       if (t > 0 && t <= myTriangulations.Extent() &&
1065                                   pt > 0 && pt <= myNodes.Extent() &&
1066                                   pt2 > 0 && pt2 <= myNodes.Extent())
1067                 myBuilder.UpdateEdge
1068                   (E, Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1069                    Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt2)),
1070                    Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1071                    Locations().Location(l));
1072             }
1073             else {
1074                       if (t > 0 && t <= myTriangulations.Extent() &&
1075                                   pt > 0 && pt <= myNodes.Extent())
1076                 myBuilder.UpdateEdge
1077                   (E,Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(pt)),
1078                    Handle(Poly_Triangulation)::DownCast(myTriangulations(t)),
1079                    Locations().Location(l));
1080             }
1081             // range
1082             
1083             break;
1084             
1085           }
1086         } while (val > 0);
1087       }
1088     break;
1089
1090
1091     //---------
1092     // wire
1093     //---------
1094
1095   case TopAbs_WIRE :
1096     myBuilder.MakeWire(TopoDS::Wire(S));
1097     break;
1098
1099
1100     //---------
1101     // face
1102     //---------
1103
1104   case TopAbs_FACE :
1105     {
1106     // create a face :
1107     TopoDS_Face& F = TopoDS::Face(S);
1108 //    streampos pos;
1109     myBuilder.MakeFace(F);
1110
1111     IS >> val; // natural restriction
1112     if (val == 0 || val == 1) {
1113       IS >> tol >> s >> l;
1114 //  Modified by Sergey KHROMOV - Wed Apr 24 12:39:13 2002 Begin
1115       if (!mySurfaces.Surface(s).IsNull()) {
1116 //  Modified by Sergey KHROMOV - Wed Apr 24 12:39:14 2002 End
1117         myBuilder.UpdateFace(TopoDS::Face(S),
1118                              mySurfaces.Surface(s),
1119                              Locations().Location(l),tol);
1120         myBuilder.NaturalRestriction(TopoDS::Face(S),(val == 1));
1121       }
1122 //      pos = IS.tellg();
1123 //      IS >> val;
1124     }
1125     else if(val == 2) {
1126       //only triangulation
1127       IS >> s;
1128       myBuilder.UpdateFace(TopoDS::Face(S),
1129                            Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1130     }
1131 //    else pos = IS.tellg();
1132     
1133     // BUC60769
1134
1135     if(val == 2) break;
1136
1137     char string[260];
1138     IS.getline ( string, 256, '\n' );
1139     IS.getline ( string, 256, '\n' );
1140
1141     if (string[0] == '2') {
1142       // cas triangulation
1143       s = atoi ( &string[2] );
1144           if (s > 0 && s <= myTriangulations.Extent())
1145         myBuilder.UpdateFace(TopoDS::Face(S),
1146                              Handle(Poly_Triangulation)::DownCast(myTriangulations(s)));
1147     }
1148 //    else IS.seekg(pos);
1149     }
1150     break;
1151
1152
1153     //---------
1154     // shell
1155     //---------
1156
1157   case TopAbs_SHELL :
1158     myBuilder.MakeShell(TopoDS::Shell(S));
1159     break;
1160
1161
1162     //---------
1163     // solid
1164     //---------
1165
1166   case TopAbs_SOLID :
1167     myBuilder.MakeSolid(TopoDS::Solid(S));
1168     break;
1169
1170
1171     //---------
1172     // compsolid
1173     //---------
1174
1175   case TopAbs_COMPSOLID :
1176     myBuilder.MakeCompSolid(TopoDS::CompSolid(S));
1177     break;
1178
1179
1180     //---------
1181     // compound
1182     //---------
1183
1184   case TopAbs_COMPOUND :
1185     myBuilder.MakeCompound(TopoDS::Compound(S));
1186     break;
1187
1188   default:
1189     break;
1190   }
1191   
1192 }
1193
1194
1195
1196 //=======================================================================
1197 //function : AddShapes
1198 //purpose  : 
1199 //=======================================================================
1200
1201 void  BRepTools_ShapeSet::AddShapes(TopoDS_Shape&       S1, 
1202                                     const TopoDS_Shape& S2)
1203 {
1204   myBuilder.Add(S1,S2);
1205 }
1206
1207 //=======================================================================
1208 //function : Check
1209 //purpose  : 
1210 //=======================================================================
1211
1212 void BRepTools_ShapeSet::Check(const TopAbs_ShapeEnum T,
1213                                TopoDS_Shape&          S)
1214 {
1215   if (T == TopAbs_FACE) {
1216     const TopoDS_Face& F = TopoDS::Face(S);
1217     BRepTools::Update(F);
1218   }
1219 }
1220
1221
1222
1223 //=======================================================================
1224 //function : WritePolygonOnTriangulation
1225 //purpose  : 
1226 //=======================================================================
1227
1228 void BRepTools_ShapeSet::WritePolygonOnTriangulation(Standard_OStream&      OS,
1229                                                      const Standard_Boolean Compact)const
1230 {
1231   Standard_Integer i, j, nbpOntri = myNodes.Extent();
1232
1233   Handle(Message_ProgressIndicator) progress = GetProgress();
1234   Message_ProgressSentry PS(progress, "Polygons On Triangulation", 0, nbpOntri, 1);
1235   if (Compact)
1236     OS << "PolygonOnTriangulations " << nbpOntri << endl;
1237   else {
1238     OS << " -------\n";
1239     OS <<"Dump of " << nbpOntri << " PolygonOnTriangulations\n";
1240     OS << " -------\n";
1241   }
1242
1243   Handle(Poly_PolygonOnTriangulation) Poly;
1244   Handle(TColStd_HArray1OfReal) Param;
1245
1246   for (i=1; i<=nbpOntri && PS.More(); i++, PS.Next()) {
1247     if ( !progress.IsNull() ) 
1248       progress->Show();
1249
1250     Poly = Handle(Poly_PolygonOnTriangulation)::DownCast(myNodes(i));
1251     const TColStd_Array1OfInteger& Nodes = Poly->Nodes();
1252     if (!Compact) {
1253       OS << "  "<< i << " : PolygonOnTriangulation with " << Nodes.Length() << " Nodes\n";
1254     }
1255     else OS << Nodes.Length()<<" ";
1256     if (!Compact) OS <<"  ";
1257     for (j=1; j <= Nodes.Length(); j++) OS << Nodes.Value(j) << " ";
1258     OS << "\n";
1259
1260     // writing parameters:
1261     Param = Poly->Parameters();
1262     if (Compact) OS <<"p ";
1263
1264     // write the deflection
1265     if (!Compact) OS << "  Deflection : ";
1266     OS <<Poly->Deflection() << " ";
1267     if (!Compact) OS << "\n";
1268     
1269     if (!Param.IsNull()) {
1270       if (!Compact) {
1271         OS << "  "<< "Parameters :";
1272       }
1273       else OS << "1 " ;
1274       if (!Compact) OS <<"  ";
1275       for (j=1; j <= Param->Length(); j++) OS << Param->Value(j) << " ";
1276       OS << "\n";
1277     }
1278     else OS <<"0 \n";
1279   }
1280 }
1281
1282 //=======================================================================
1283 //function : DumpPolygonOnTriangulation
1284 //purpose  : 
1285 //=======================================================================
1286
1287 void BRepTools_ShapeSet::DumpPolygonOnTriangulation(Standard_OStream& OS)const
1288 {
1289   WritePolygonOnTriangulation(OS, Standard_False);
1290 }
1291
1292 //=======================================================================
1293 //function : ReadPolygonOnTriangulation
1294 //purpose  : 
1295 //=======================================================================
1296
1297 void BRepTools_ShapeSet::ReadPolygonOnTriangulation(Standard_IStream& IS)
1298 {
1299   char buffer[255];
1300   IS >> buffer;
1301   if (strstr(buffer,"PolygonOnTriangulations") == NULL) return;
1302   Standard_Integer i, j, val, nbpol = 0, nbnodes =0;
1303   Standard_Integer hasparameters;
1304   Standard_Real par;
1305   Handle(TColStd_HArray1OfReal) Param;
1306   Handle(Poly_PolygonOnTriangulation) Poly;
1307   IS >> nbpol;
1308   //OCC19559
1309   Handle(Message_ProgressIndicator) progress = GetProgress();
1310   Message_ProgressSentry PS(progress, "Polygons On Triangulation", 0, nbpol, 1);
1311   for (i=1; i<=nbpol&& PS.More(); i++, PS.Next()) {
1312     if ( !progress.IsNull() ) 
1313       progress->Show();
1314
1315     IS >> nbnodes;
1316     TColStd_Array1OfInteger Nodes(1, nbnodes);
1317     for (j = 1; j <= nbnodes; j++) {
1318       IS >> val;
1319       Nodes(j) = val;
1320     }
1321     IS >> buffer;
1322 //      if (!strcasecmp(buffer, "p")) {
1323       Standard_Real def;
1324       IS >> def;
1325       IS >> hasparameters;
1326       if (hasparameters) {
1327         TColStd_Array1OfReal Param1(1, nbnodes);
1328         for (j = 1; j <= nbnodes; j++) {
1329           IS >> par;
1330           Param1(j) = par;
1331         }
1332         Poly = new Poly_PolygonOnTriangulation(Nodes, Param1);
1333       }
1334       else Poly = new Poly_PolygonOnTriangulation(Nodes);
1335       Poly->Deflection(def);
1336 //      }
1337 //      else {
1338 //      IS.seekg(ppp);
1339 //      Poly = new Poly_PolygonOnTriangulation(Nodes);
1340 //      }
1341     myNodes.Add(Poly);
1342   }
1343 //  }
1344 //  else IS.seekg(pos);
1345 }
1346
1347
1348
1349 //=======================================================================
1350 //function : WritePolygon3D
1351 //purpose  : 
1352 //=======================================================================
1353
1354 void BRepTools_ShapeSet::WritePolygon3D(Standard_OStream&      OS,
1355                                         const Standard_Boolean Compact)const
1356 {
1357   Standard_Integer i, j, nbpol = myPolygons3D.Extent();
1358   
1359   Handle(Message_ProgressIndicator) progress = GetProgress();
1360   Message_ProgressSentry PS(progress, "3D Poligons", 0, nbpol, 1);
1361
1362   if (Compact)
1363     OS << "Polygon3D " << nbpol << endl;
1364   else {
1365     OS << " -------\n";
1366     OS <<"Dump of " << nbpol << " Polygon3Ds\n";
1367     OS << " -------\n";
1368   }
1369   
1370   Handle(Poly_Polygon3D) P;
1371   for (i = 1; i <= nbpol && PS.More(); i++, PS.Next()) {
1372     if ( !progress.IsNull() ) 
1373       progress->Show();
1374
1375     P = Handle(Poly_Polygon3D)::DownCast(myPolygons3D(i));
1376     if (Compact) {
1377       OS << P->NbNodes() << " ";
1378       OS << ((P->HasParameters()) ? "1" : "0") << "\n";
1379     }
1380     else {
1381       OS << "  "<< i << " : Polygon3D with " << P->NbNodes() << " Nodes\n";
1382       OS << ((P->HasParameters()) ? "with" : "without") << " parameters\n";
1383     }
1384     
1385
1386     // write the deflection
1387     if (!Compact) OS << "Deflection : ";
1388     OS << P->Deflection() << "\n";
1389     
1390     // write the nodes
1391     if (!Compact) OS << "\nNodes :\n";
1392     
1393     Standard_Integer i1, nbNodes = P->NbNodes();
1394     const TColgp_Array1OfPnt& Nodes = P->Nodes();
1395     for (j = 1; j <= nbNodes; j++) {
1396       if (!Compact) OS << setw(10) << j << " : ";
1397       if (!Compact) OS << setw(17);
1398       OS << Nodes(j).X() << " ";
1399       if (!Compact) OS << setw(17);
1400       OS << Nodes(j).Y() << " ";
1401       if (!Compact) OS << setw(17);
1402       OS << Nodes(j).Z();
1403       if (!Compact) OS << "\n";
1404       else OS << " ";
1405     }
1406     OS <<"\n";
1407   
1408     if (P->HasParameters()) {
1409       if (!Compact) OS << "\nParameters :\n";
1410       const TColStd_Array1OfReal& Param = P->Parameters();
1411       for ( i1 = 1; i1 <= nbNodes; i1++ ) {
1412         OS << Param(i1) << " ";
1413       }
1414       OS <<"\n";
1415     }
1416   }
1417 }
1418
1419 //=======================================================================
1420 //function : DumpPolygon3D
1421 //purpose  : 
1422 //=======================================================================
1423
1424 void BRepTools_ShapeSet::DumpPolygon3D(Standard_OStream& OS)const
1425 {
1426   WritePolygon3D(OS, Standard_False);
1427 }
1428
1429
1430 //=======================================================================
1431 //function : ReadPolygon3D
1432 //purpose  : 
1433 //=======================================================================
1434
1435 void BRepTools_ShapeSet::ReadPolygon3D(Standard_IStream& IS)
1436 {
1437   char buffer[255];
1438   //  Standard_Integer i, j, p, val, nbpol, nbnodes, hasparameters;
1439   Standard_Integer i, j, p, nbpol=0, nbnodes =0, hasparameters = Standard_False;
1440   Standard_Real d, x, y, z;
1441
1442   IS >> buffer;
1443   if (strstr(buffer,"Polygon3D") == NULL) return;
1444   Handle(Poly_Polygon3D) P;
1445   IS >> nbpol;
1446   //OCC19559
1447   Handle(Message_ProgressIndicator) progress = GetProgress();
1448   Message_ProgressSentry PS(progress, "3D Polygons", 0, nbpol, 1);
1449   for (i=1; i<=nbpol && PS.More(); i++, PS.Next()) {
1450     if ( !progress.IsNull() ) 
1451       progress->Show();
1452
1453     IS >> nbnodes;
1454     IS >> hasparameters;
1455     TColgp_Array1OfPnt Nodes(1, nbnodes);
1456     IS >> d;
1457     for (j = 1; j <= nbnodes; j++) {
1458       IS >> x >> y >> z;
1459       Nodes(j).SetCoord(x,y,z);
1460     }
1461     if (hasparameters) {
1462       TColStd_Array1OfReal Param(1,nbnodes);
1463       for (p = 1; p <= nbnodes; p++) {
1464         IS >> Param(p);
1465       }
1466       P = new Poly_Polygon3D(Nodes, Param);
1467     }
1468     else P = new Poly_Polygon3D(Nodes);
1469     P->Deflection(d);
1470     myPolygons3D.Add(P);
1471   }
1472 }
1473
1474
1475
1476 //=======================================================================
1477 //function : WriteTriangulation
1478 //purpose  : 
1479 //=======================================================================
1480
1481 void BRepTools_ShapeSet::WriteTriangulation(Standard_OStream&      OS,
1482                                         const Standard_Boolean Compact)const
1483 {
1484   Standard_Integer i, j, nbNodes, nbtri = myTriangulations.Extent();
1485   Standard_Integer nbTriangles = 0, n1, n2, n3;
1486   
1487   Handle(Message_ProgressIndicator) progress = GetProgress();
1488   Message_ProgressSentry PS(progress, "Triangulations", 0, nbtri, 1);
1489
1490   if (Compact)
1491     OS << "Triangulations " << nbtri << endl;
1492   else {
1493     OS << " -------\n";
1494     OS <<"Dump of " << nbtri << " Triangulations\n";
1495     OS << " -------\n";
1496   }
1497   
1498   Handle(Poly_Triangulation) T;
1499   for (i = 1; i <= nbtri && PS.More(); i++, PS.Next()) {
1500     if ( !progress.IsNull() ) 
1501       progress->Show();
1502
1503     T = Handle(Poly_Triangulation)::DownCast(myTriangulations(i));
1504     if (Compact) {
1505       OS << T->NbNodes() << " " << T->NbTriangles() << " ";
1506       OS << ((T->HasUVNodes()) ? "1" : "0") << " ";
1507     }
1508     else {
1509       OS << "  "<< i << " : Triangulation with " << T->NbNodes() << " Nodes and "
1510          << T->NbTriangles() <<" Triangles\n";
1511       OS << "      "<<((T->HasUVNodes()) ? "with" : "without") << " UV nodes\n";
1512
1513     }
1514     
1515     // write the deflection
1516     
1517     if (!Compact) OS << "  Deflection : ";
1518     OS <<T->Deflection() << "\n";
1519     
1520     // write the 3d nodes
1521     
1522     if (!Compact) OS << "\n3D Nodes :\n";
1523     
1524     nbNodes = T->NbNodes();
1525     const TColgp_Array1OfPnt& Nodes = T->Nodes();
1526     for (j = 1; j <= nbNodes; j++) {
1527       if (!Compact) OS << setw(10) << j << " : ";
1528       if (!Compact) OS << setw(17);
1529       OS << Nodes(j).X() << " ";
1530       if (!Compact) OS << setw(17);
1531       OS << Nodes(j).Y() << " ";
1532       if (!Compact) OS << setw(17);
1533       OS << Nodes(j).Z();
1534       if (!Compact) OS << "\n";
1535       else OS << " ";
1536     }
1537     
1538     if (T->HasUVNodes()) {
1539       if (!Compact) OS << "\nUV Nodes :\n";
1540       const TColgp_Array1OfPnt2d& UVNodes = T->UVNodes();
1541       for (j = 1; j <= nbNodes; j++) {
1542         if (!Compact) OS << setw(10) << j << " : ";
1543         if (!Compact) OS << setw(17);
1544         OS << UVNodes(j).X() << " ";
1545         if (!Compact) OS << setw(17);
1546         OS << UVNodes(j).Y();
1547         if (!Compact) OS << "\n";
1548         else OS << " ";
1549       }
1550     }
1551     
1552     if (!Compact) OS << "\nTriangles :\n";
1553     nbTriangles = T->NbTriangles();
1554     const Poly_Array1OfTriangle& Triangles = T->Triangles();
1555     for (j = 1; j <= nbTriangles; j++) {
1556       if (!Compact) OS << setw(10) << j << " : ";
1557       Triangles(j).Get(n1, n2, n3);
1558       if (!Compact) OS << setw(10);
1559       OS << n1 << " ";
1560       if (!Compact) OS << setw(10);
1561       OS << n2 << " ";
1562       if (!Compact) OS << setw(10);
1563       OS << n3;
1564       if (!Compact) OS << "\n";
1565       else OS << " ";
1566     }
1567     OS << "\n";
1568   }
1569 }
1570
1571 //=======================================================================
1572 //function : DumpTriangulation
1573 //purpose  : 
1574 //=======================================================================
1575
1576 void BRepTools_ShapeSet::DumpTriangulation(Standard_OStream& OS)const
1577 {
1578   WriteTriangulation(OS, Standard_False);
1579 }
1580
1581
1582 //=======================================================================
1583 //function : ReadTriangulation
1584 //purpose  : 
1585 //=======================================================================
1586
1587 void BRepTools_ShapeSet::ReadTriangulation(Standard_IStream& IS)
1588 {
1589   char buffer[255];
1590   //  Standard_Integer i, j, val, nbtri;
1591   Standard_Integer i, j, nbtri =0;
1592   Standard_Real d, x, y, z;
1593   Standard_Integer nbNodes =0, nbTriangles=0;
1594   Standard_Boolean hasUV= Standard_False;
1595
1596   Handle(Poly_Triangulation) T;
1597
1598   IS >> buffer;
1599   if (strstr(buffer,"Triangulations") == NULL) return;
1600
1601   IS >> nbtri;
1602   //OCC19559
1603   Handle(Message_ProgressIndicator) progress = GetProgress();
1604   Message_ProgressSentry PS(progress, "Triangulations", 0, nbtri, 1);
1605   for (i=1; i<=nbtri && PS.More();i++, PS.Next()) {
1606     if ( !progress.IsNull() )  
1607       progress->Show();
1608
1609     IS >> nbNodes >> nbTriangles >> hasUV;
1610     IS >> d;
1611
1612     TColgp_Array1OfPnt Nodes(1, nbNodes);
1613     TColgp_Array1OfPnt2d UVNodes(1, nbNodes);
1614
1615     for (j = 1; j <= nbNodes; j++) {
1616       IS >> x >> y >> z;
1617       Nodes(j).SetCoord(x,y,z);
1618     }
1619
1620     if (hasUV) {
1621       for (j = 1; j <= nbNodes; j++) {
1622         IS >> x >> y;
1623         UVNodes(j).SetCoord(x,y);
1624       }
1625     }
1626       
1627     // read the triangles
1628     Standard_Integer n1,n2,n3;
1629     Poly_Array1OfTriangle Triangles(1, nbTriangles);
1630     for (j = 1; j <= nbTriangles; j++) {
1631       IS >> n1 >> n2 >> n3;
1632       Triangles(j).Set(n1,n2,n3);
1633     }
1634       
1635     if (hasUV) T =  new Poly_Triangulation(Nodes,UVNodes,Triangles);
1636     else T = new Poly_Triangulation(Nodes,Triangles);
1637       
1638     T->Deflection(d);
1639       
1640     myTriangulations.Add(T);
1641   }
1642 }
1643
1644