0025418: Debug output to be limited to OCC development environment
[occt.git] / src / GeomTools / GeomTools_SurfaceSet.cxx
1 // Created on: 1993-07-19
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Standard_Stream.hxx>
18 #include <GeomTools_SurfaceSet.ixx>
19 #include <GeomTools.hxx>
20 #include <GeomTools_UndefinedTypeHandler.hxx>
21
22 #include <GeomTools_CurveSet.hxx>
23 #include <Geom_Plane.hxx>
24 #include <Geom_CylindricalSurface.hxx>
25 #include <Geom_ConicalSurface.hxx>
26 #include <Geom_SphericalSurface.hxx>
27 #include <Geom_ToroidalSurface.hxx>
28 #include <Geom_SurfaceOfLinearExtrusion.hxx>
29 #include <Geom_SurfaceOfRevolution.hxx>
30 #include <Geom_BezierSurface.hxx>
31 #include <Geom_BSplineSurface.hxx>
32 #include <Geom_RectangularTrimmedSurface.hxx>
33 #include <Geom_OffsetSurface.hxx>
34
35 #include <gp_Pln.hxx>
36 #include <gp_Cylinder.hxx>
37 #include <gp_Cone.hxx>
38 #include <gp_Sphere.hxx>
39 #include <gp_Torus.hxx>
40
41 #include <TColStd_Array1OfReal.hxx>
42 #include <TColStd_Array1OfInteger.hxx>
43 #include <TColgp_Array1OfPnt.hxx>
44 #include <TColStd_Array2OfReal.hxx>
45 #include <TColgp_Array2OfPnt.hxx>
46 #include <Standard_Failure.hxx>
47 #include <Standard_ErrorHandler.hxx>
48 #include <Message_ProgressSentry.hxx>
49
50 #define PLANE           1
51 #define CYLINDER        2
52 #define CONE            3
53 #define SPHERE          4
54 #define TORUS           5
55 #define LINEAREXTRUSION 6
56 #define REVOLUTION      7
57 #define BEZIER          8
58 #define BSPLINE         9
59 #define RECTANGULAR     10
60 #define OFFSET          11
61
62 //=======================================================================
63 //function : GeomTools_SurfaceSet
64 //purpose  : 
65 //=======================================================================
66
67 GeomTools_SurfaceSet::GeomTools_SurfaceSet() 
68 {
69 }
70
71
72 //=======================================================================
73 //function : Clear
74 //purpose  : 
75 //=======================================================================
76
77 void  GeomTools_SurfaceSet::Clear()
78 {
79   myMap.Clear();
80 }
81
82
83 //=======================================================================
84 //function : Add
85 //purpose  : 
86 //=======================================================================
87
88 Standard_Integer  GeomTools_SurfaceSet::Add(const Handle(Geom_Surface)& S)
89 {
90   return myMap.Add(S);
91 }
92
93
94 //=======================================================================
95 //function : Surface
96 //purpose  : 
97 //=======================================================================
98
99 Handle(Geom_Surface)  GeomTools_SurfaceSet::Surface
100        (const Standard_Integer I)const 
101 {
102   if (I <= 0 || I > myMap.Extent())
103     return Handle(Geom_Surface)();
104   return Handle(Geom_Surface)::DownCast(myMap(I));
105 }
106
107
108 //=======================================================================
109 //function : Index
110 //purpose  : 
111 //=======================================================================
112
113 Standard_Integer  GeomTools_SurfaceSet::Index
114   (const Handle(Geom_Surface)& S)const 
115 {
116   return myMap.FindIndex(S);
117 }
118
119 //=======================================================================
120 //function : Print
121 //purpose  : 
122 //=======================================================================
123
124 static void Print(const gp_Pnt P,
125                   Standard_OStream& OS,
126                   const Standard_Boolean compact)
127 {
128   OS << P.X();
129   if (!compact) OS << ",";
130   OS << " ";
131   OS << P.Y();
132   if (!compact) OS << ",";
133   OS << " ";
134   OS << P.Z();
135   OS << " ";
136 }
137
138 //=======================================================================
139 //function : Print
140 //purpose  : 
141 //=======================================================================
142
143 static void Print(const gp_Dir D,
144                   Standard_OStream& OS,
145                   const Standard_Boolean compact)
146 {
147   OS << D.X();
148   if (!compact) OS << ",";
149   OS << " ";
150   OS << D.Y();
151   if (!compact) OS << ",";
152   OS << " ";
153   OS << D.Z();
154   OS << " ";
155 }
156
157 //=======================================================================
158 //function : Print
159 //purpose  : 
160 //=======================================================================
161
162 static void Print(const Handle(Geom_Plane)& S,
163                          Standard_OStream& OS,
164                          const Standard_Boolean compact)
165 {
166   if (compact)
167     OS << PLANE << " ";
168   else
169     OS << "Plane";
170   
171   gp_Pln P = S->Pln();
172   if (!compact) OS << "\n  Origin :";
173   Print(P.Location(),OS,compact);
174   if (!compact) OS << "\n  Axis   :";
175   Print(P.Axis().Direction(),OS,compact);
176   if (!compact) OS << "\n  XAxis  :";
177   Print(P.XAxis().Direction(),OS,compact);
178   if (!compact) OS << "\n  YAxis  :";
179   Print(P.YAxis().Direction(),OS,compact);
180   OS << "\n";
181   if (!compact) OS << "\n";
182 }
183
184
185 //=======================================================================
186 //function : Print
187 //purpose  : 
188 //=======================================================================
189
190 static void Print(const Handle(Geom_CylindricalSurface)& S,
191                          Standard_OStream& OS,
192                          const Standard_Boolean compact)
193 {
194   if (compact)
195     OS << CYLINDER << " ";
196   else
197     OS << "CylindricalSurface";
198   
199   gp_Cylinder P = S->Cylinder();
200   if (!compact) OS << "\n  Origin :";
201   Print(P.Location(),OS,compact);
202   if (!compact) OS << "\n  Axis   :";
203   Print(P.Axis().Direction(),OS,compact);
204   if (!compact) OS << "\n  XAxis  :";
205   Print(P.XAxis().Direction(),OS,compact);
206   if (!compact) OS << "\n  YAxis  :";
207   Print(P.YAxis().Direction(),OS,compact);
208   if (!compact) OS << "\n  Radius :";
209   OS << P.Radius();
210   OS << "\n";
211   if (!compact) OS << "\n";
212 }
213
214
215 //=======================================================================
216 //function : Print
217 //purpose  : 
218 //=======================================================================
219
220 static void Print(const Handle(Geom_ConicalSurface)& S,
221                          Standard_OStream& OS,
222                          const Standard_Boolean compact)
223 {
224   if (compact)
225     OS << CONE << " ";
226   else
227     OS << "ConicalSurface";
228   
229   gp_Cone P = S->Cone();
230   if (!compact) OS << "\n  Origin :";
231   Print(P.Location(),OS,compact);
232   if (!compact) OS << "\n  Axis   :";
233   Print(P.Axis().Direction(),OS,compact);
234   if (!compact) OS << "\n  XAxis  :";
235   Print(P.XAxis().Direction(),OS,compact);
236   if (!compact) OS << "\n  YAxis  :";
237   Print(P.YAxis().Direction(),OS,compact);
238   if (!compact) OS << "\n  Radius :";
239   OS << P.RefRadius();
240   OS << "\n";
241   if (!compact) OS << "\n  Angle :";
242   OS << P.SemiAngle();
243   OS << "\n";
244   if (!compact) OS << "\n";
245 }
246
247
248 //=======================================================================
249 //function : Print
250 //purpose  : 
251 //=======================================================================
252
253 static void Print(const Handle(Geom_SphericalSurface)& S,
254                          Standard_OStream& OS,
255                          const Standard_Boolean compact)
256 {
257   if (compact)
258     OS << SPHERE << " ";
259   else
260     OS << "SphericalSurface";
261
262   gp_Sphere P = S->Sphere();
263   if (!compact) OS << "\n  Center :";
264   Print(P.Location(),OS,compact);
265   if (!compact) OS << "\n  Axis   :";
266   Print(P.Position().Axis().Direction(),OS,compact);
267   if (!compact) OS << "\n  XAxis  :";
268   Print(P.XAxis().Direction(),OS,compact);
269   if (!compact) OS << "\n  YAxis  :";
270   Print(P.YAxis().Direction(),OS,compact);
271   if (!compact) OS << "\n  Radius :";
272   OS << P.Radius();
273   OS << "\n";
274   if (!compact) OS << "\n";
275 }
276
277
278 //=======================================================================
279 //function : Print
280 //purpose  : 
281 //=======================================================================
282
283 static void Print(const Handle(Geom_ToroidalSurface)& S,
284                          Standard_OStream& OS,
285                          const Standard_Boolean compact)
286 {
287   if (compact)
288     OS << TORUS << " ";
289   else
290     OS << "ToroidalSurface";
291   
292   gp_Torus P = S->Torus();
293   if (!compact) OS << "\n  Origin :";
294   Print(P.Location(),OS,compact);
295   if (!compact) OS << "\n  Axis   :";
296   Print(P.Axis().Direction(),OS,compact);
297   if (!compact) OS << "\n  XAxis  :";
298   Print(P.XAxis().Direction(),OS,compact);
299   if (!compact) OS << "\n  YAxis  :";
300   Print(P.YAxis().Direction(),OS,compact);
301   if (!compact) OS << "\n  Radii  :";
302   OS << P.MajorRadius() << " " << P.MinorRadius();
303   OS << "\n";
304   if (!compact) OS << "\n";
305 }
306
307
308 //=======================================================================
309 //function : Print
310 //purpose  : 
311 //=======================================================================
312
313 static void Print(const Handle(Geom_SurfaceOfLinearExtrusion)& S,
314                          Standard_OStream& OS,
315                          const Standard_Boolean compact)
316 {
317   if (compact)
318     OS << LINEAREXTRUSION << " ";
319   else
320     OS << "SurfaceOfLinearExtrusion";
321
322   if (!compact) OS << "\n  Direction :";
323   Print(S->Direction(),OS,compact);
324   if (!compact) OS << "\n  Basis curve : ";
325   OS << "\n";
326   GeomTools_CurveSet::PrintCurve(S->BasisCurve(),OS,compact);
327 }
328
329
330 //=======================================================================
331 //function : Print
332 //purpose  : 
333 //=======================================================================
334
335 static void Print(const Handle(Geom_SurfaceOfRevolution)& S,
336                          Standard_OStream& OS,
337                          const Standard_Boolean compact)
338 {
339   if (compact)
340     OS << REVOLUTION <<" ";
341   else
342     OS << "SurfaceOfRevolution";
343
344   if (!compact) OS << "\n  Origin    :";
345   Print(S->Location(),OS,compact);
346   if (!compact) OS << "\n  Direction :";
347   Print(S->Direction(),OS,compact);
348   if (!compact) OS << "\n  Basis curve : ";
349   OS << "\n";
350   GeomTools_CurveSet::PrintCurve(S->BasisCurve(),OS,compact);
351 }
352
353
354 //=======================================================================
355 //function : Print
356 //purpose  : 
357 //=======================================================================
358
359 static void Print(const Handle(Geom_BezierSurface)& S,
360                          Standard_OStream& OS,
361                          const Standard_Boolean compact)
362 {
363   if (compact)
364     OS << BEZIER << " ";
365   else
366     OS << "BezierSurface";
367
368
369   Standard_Boolean urational = S->IsURational();
370   Standard_Boolean vrational = S->IsVRational();
371   if (compact)
372     OS << (urational ? 1 : 0) << " ";
373   else {
374     if (urational) 
375       OS << " urational";
376   }
377   if (compact)
378     OS << (vrational ? 1 : 0) << " ";
379   else {
380     if (vrational) 
381       OS << " vrational";
382   }
383
384   if (!compact) {
385     Standard_Boolean uclosed = S->IsUClosed();
386     Standard_Boolean vclosed = S->IsVClosed();
387     if (uclosed) 
388       OS << " uclosed";
389     if (vclosed)
390       OS << " vclosed";
391   }
392
393   // poles and weights
394   Standard_Integer i,j,udegree,vdegree;
395   udegree = S->UDegree();
396   vdegree = S->VDegree();
397   if (!compact) OS << "\n  Degrees :";
398   OS << udegree << " " << vdegree << " ";
399   
400   for (i = 1; i <= udegree+1; i++) {
401     for (j = 1; j <= vdegree+1; j++) {
402       if (!compact) OS << "\n  "<<setw(2)<<i<<", "<<setw(2)<<j<<" : ";
403       Print(S->Pole(i,j),OS,compact);
404       if (urational || vrational)
405         OS << " " << S->Weight(i,j);
406       if (compact)
407         OS << " ";
408     }
409     OS << "\n";
410   }
411   OS << "\n";
412   if (!compact) OS << "\n";
413 }
414
415
416 //=======================================================================
417 //function : Print
418 //purpose  : 
419 //=======================================================================
420
421 static void Print(const Handle(Geom_BSplineSurface)& S,
422                          Standard_OStream& OS,
423                          const Standard_Boolean compact)
424 {
425   if (compact)
426     OS << BSPLINE << " ";
427   else
428     OS << "BSplineSurface";
429
430   Standard_Boolean urational = S->IsURational();
431   Standard_Boolean vrational = S->IsVRational();
432   if (compact)
433     OS << (urational ? 1 : 0) << " ";
434   else {
435     if (urational) 
436       OS << " urational";
437   }
438   if (compact)
439     OS << (vrational ? 1 : 0) << " ";
440   else {
441     if (vrational) 
442       OS << " vrational";
443   }
444
445   Standard_Boolean uperiodic = S->IsUPeriodic();
446   Standard_Boolean vperiodic = S->IsVPeriodic();
447   if (compact)
448     OS << (uperiodic ? 1 : 0) << " ";
449   else {
450     if (uperiodic) 
451       OS << " uperiodic";
452   }
453   if (compact)
454     OS << (vperiodic ? 1 : 0) << " ";
455   else {
456     if (vperiodic) 
457       OS << " vperiodic";
458   }
459
460   if (!compact) {
461     Standard_Boolean uclosed = S->IsUClosed();
462     Standard_Boolean vclosed = S->IsVClosed();
463     if (uclosed) 
464       OS << " uclosed";
465     if (vclosed)
466       OS << " vclosed";
467   }
468   
469
470   // poles and weights
471   Standard_Integer i,j,udegree,vdegree,nbupoles,nbvpoles,nbuknots,nbvknots;
472   udegree = S->UDegree();
473   vdegree = S->VDegree();
474   nbupoles = S->NbUPoles();
475   nbvpoles = S->NbVPoles();
476   nbuknots = S->NbUKnots();
477   nbvknots = S->NbVKnots();
478   if (!compact) OS << "\n  Degrees :";
479   OS << udegree << " " << vdegree << " ";
480   if (!compact) OS << "\n  NbPoles :";
481   OS << nbupoles << " " << nbvpoles << " ";
482   if (!compact) OS << "\n  NbKnots :";
483   OS << nbuknots << " " << nbvknots << " ";
484
485   if (!compact) OS << "\n Poles :\n";
486   for (i = 1; i <= nbupoles; i++) {
487     for (j = 1; j <= nbvpoles; j++) {
488       if (!compact) OS << "\n  "<<setw(2)<<i<<", "<<setw(2)<<j<<" : ";
489       Print(S->Pole(i,j),OS,compact);
490       if (urational || vrational)
491         OS << " " << S->Weight(i,j);
492       if (compact)
493         OS << " ";
494     }
495     OS << "\n";
496   }
497   OS << "\n";
498   if (!compact) OS << "\n UKnots :\n";
499   for (i = 1; i <= nbuknots; i++) {
500     if (!compact) OS << "\n  "<<setw(2)<<i<<" : ";
501     OS << S->UKnot(i) << " " << S->UMultiplicity(i) <<"\n";
502   }
503   OS << "\n";
504   if (!compact) OS << "\n VKnots :\n";
505   for (i = 1; i <= nbvknots; i++) {
506     if (!compact) OS << "\n  "<<setw(2)<<i<<" : ";
507     OS << S->VKnot(i) << " " << S->VMultiplicity(i) <<"\n";
508   }
509   OS << "\n";
510   if (!compact) OS << "\n";
511 }
512
513
514 //=======================================================================
515 //function : Print
516 //purpose  : 
517 //=======================================================================
518
519 static void Print(const Handle(Geom_RectangularTrimmedSurface)& S,
520                          Standard_OStream& OS,
521                          const Standard_Boolean compact)
522 {
523   if (compact)
524     OS << RECTANGULAR << " ";
525   else
526     OS << "RectangularTrimmedSurface";
527
528   Standard_Real U1,U2,V1,V2;
529   S->Bounds(U1,U2,V1,V2);
530   if (!compact) OS << "\nParameters : ";
531   OS << U1 << " " << U2 << " " << V1 << " " << V2 <<"\n";
532   if (!compact) OS << "BasisSurface :\n";
533   GeomTools_SurfaceSet::PrintSurface(S->BasisSurface(),OS,compact);
534 }
535
536
537 //=======================================================================
538 //function : Print
539 //purpose  : 
540 //=======================================================================
541
542 static void Print(const Handle(Geom_OffsetSurface)& S,
543                          Standard_OStream& OS,
544                          const Standard_Boolean compact)
545 {
546   if (compact)
547     OS << OFFSET << " ";
548   else
549     OS << "OffsetSurface";
550
551   if (!compact) OS << "\nOffset : ";
552   OS << S->Offset() <<"\n";
553   if (!compact) OS << "BasisSurface :\n";
554   GeomTools_SurfaceSet::PrintSurface(S->BasisSurface(),OS,compact);
555 }
556
557
558 //=======================================================================
559 //function : PrintSurface
560 //purpose  : 
561 //=======================================================================
562
563 void GeomTools_SurfaceSet::PrintSurface(const Handle(Geom_Surface)& S,
564                                         Standard_OStream& OS,
565                                         const Standard_Boolean compact)
566 {
567   Handle(Standard_Type) TheType = S->DynamicType();
568
569   if ( TheType ==  STANDARD_TYPE(Geom_Plane)) {
570     Print(Handle(Geom_Plane)::DownCast(S),OS,compact);
571   }
572   else if ( TheType ==  STANDARD_TYPE(Geom_CylindricalSurface)) {
573     Print(Handle(Geom_CylindricalSurface)::DownCast(S),OS,compact);
574   }
575   else if ( TheType ==  STANDARD_TYPE(Geom_ConicalSurface)) {
576     Print(Handle(Geom_ConicalSurface)::DownCast(S),OS,compact);
577   }
578   else if ( TheType ==  STANDARD_TYPE(Geom_SphericalSurface)) {
579     Print(Handle(Geom_SphericalSurface)::DownCast(S),OS,compact);
580   }
581   else if ( TheType ==  STANDARD_TYPE(Geom_ToroidalSurface)) {
582     Print(Handle(Geom_ToroidalSurface)::DownCast(S),OS,compact);
583   }
584   else if ( TheType ==  STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
585     Print(Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(S),OS,compact);
586   }
587   else if ( TheType ==  STANDARD_TYPE(Geom_SurfaceOfRevolution)) {
588     Print(Handle(Geom_SurfaceOfRevolution)::DownCast(S),OS,compact);
589   }
590   else if ( TheType ==  STANDARD_TYPE(Geom_BezierSurface)) {
591     Print(Handle(Geom_BezierSurface)::DownCast(S),OS,compact);
592   }
593   else if ( TheType ==  STANDARD_TYPE(Geom_BSplineSurface)) {
594     Print(Handle(Geom_BSplineSurface)::DownCast(S),OS,compact);
595   }
596   else if ( TheType ==  STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
597     Print(Handle(Geom_RectangularTrimmedSurface)::DownCast(S),OS,compact);
598   }
599   else if ( TheType ==  STANDARD_TYPE(Geom_OffsetSurface)) {
600     Print(Handle(Geom_OffsetSurface)::DownCast(S),OS,compact);
601   }
602   else {
603     GeomTools::GetUndefinedTypeHandler()->PrintSurface(S,OS,compact);
604     //if (!compact)
605     //  OS << "***** Unknown Surface ********\n";
606     //else
607     //  cout << "***** Unknown Surface ********"<<endl;
608   }
609 }
610
611 //=======================================================================
612 //function : Dump
613 //purpose  : 
614 //=======================================================================
615
616 void  GeomTools_SurfaceSet::Dump(Standard_OStream& OS)const 
617 {
618   Standard_Integer i, nbsurf = myMap.Extent();
619   OS << "\n -------\n";
620   OS << "Dump of "<< nbsurf << " surfaces ";
621   OS << "\n -------\n\n";
622
623   for (i = 1; i <= nbsurf; i++) {
624     OS << setw(4) << i << " : ";
625     PrintSurface(Handle(Geom_Surface)::DownCast(myMap(i)),OS,Standard_False);
626   }
627 }
628
629
630 //=======================================================================
631 //function : Write
632 //purpose  : 
633 //=======================================================================
634
635 void  GeomTools_SurfaceSet::Write(Standard_OStream& OS)const 
636 {
637   std::streamsize  prec = OS.precision(17);
638
639   Standard_Integer i, nbsurf = myMap.Extent();
640   OS << "Surfaces "<< nbsurf << "\n";
641   //OCC19559
642   Handle(Message_ProgressIndicator) progress = GetProgress();
643   Message_ProgressSentry PS(progress, "Surfaces", 0, nbsurf, 1);
644   for (i = 1; i <= nbsurf && PS.More(); i++, PS.Next()) {
645     PrintSurface(Handle(Geom_Surface)::DownCast(myMap(i)),OS,Standard_True);
646   }
647   OS.precision(prec);
648 }
649
650
651 //=======================================================================
652 //function : ReadPnt
653 //purpose  : 
654 //=======================================================================
655
656 static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt& P)
657 {
658   Standard_Real X=0.,Y=0.,Z=0.;
659   GeomTools::GetReal(IS, X);
660   GeomTools::GetReal(IS, Y);
661   GeomTools::GetReal(IS, Z);
662   P.SetCoord(X,Y,Z);
663   return IS;
664 }
665
666 //=======================================================================
667 //function : ReadDir
668 //purpose  : 
669 //=======================================================================
670
671 static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir& D)
672 {
673   Standard_Real X=0.,Y=0.,Z=0.;
674   GeomTools::GetReal(IS, X);
675   GeomTools::GetReal(IS, Y);
676   GeomTools::GetReal(IS, Z);
677   D.SetCoord(X,Y,Z);
678   return IS;
679 }
680
681 //=======================================================================
682 //function : ReadAx3
683 //purpose  : 
684 //=======================================================================
685
686 static Standard_IStream& operator>>(Standard_IStream& IS, gp_Ax3& A3)
687 {
688   gp_Pnt P(0.,0.,0.);
689   gp_Dir A(1.,0.,0.),AX(1.,0.,0.),AY(1.,0.,0.);
690   IS >> P >> A >> AX >> AY;
691   gp_Ax3 ax3(P,A,AX);
692   if (AY.DotCross(A,AX) < 0)
693     ax3.YReverse();
694   A3 = ax3;
695   return IS;
696 }
697
698
699 //=======================================================================
700 //function : operator>>
701 //purpose  : 
702 //=======================================================================
703
704 static Standard_IStream& operator>>(Standard_IStream& IS,
705                                     Handle(Geom_Plane)& S)
706 {
707   gp_Ax3 A;
708   IS >> A;
709   S = new Geom_Plane(A);
710   return IS;
711 }
712
713 //=======================================================================
714 //function : operator>>
715 //purpose  : 
716 //=======================================================================
717
718 static Standard_IStream& operator>>(Standard_IStream& IS,
719                                     Handle(Geom_CylindricalSurface)& S)
720 {
721   gp_Ax3 A;
722   Standard_Real R=0.;
723   IS >> A;
724   GeomTools::GetReal(IS, R);
725   S = new Geom_CylindricalSurface(A,R);
726   return IS;
727 }
728
729 //=======================================================================
730 //function : operator>>
731 //purpose  : 
732 //=======================================================================
733
734 static Standard_IStream& operator>>(Standard_IStream& IS,
735                                     Handle(Geom_ConicalSurface)& S)
736 {
737   gp_Ax3 A;
738   Standard_Real R=0.,Ang=0.;
739   IS >> A;
740   GeomTools::GetReal(IS, R);
741   GeomTools::GetReal(IS, Ang);
742   S = new Geom_ConicalSurface(A,Ang,R);
743   return IS;
744 }
745
746 //=======================================================================
747 //function : operator>>
748 //purpose  : 
749 //=======================================================================
750
751 static Standard_IStream& operator>>(Standard_IStream& IS,
752                                     Handle(Geom_SphericalSurface)& S)
753 {
754   gp_Ax3 A;
755   Standard_Real R=0.;
756   IS >> A;
757   GeomTools::GetReal(IS, R);
758   S = new Geom_SphericalSurface(A,R);
759   return IS;
760 }
761
762 //=======================================================================
763 //function : operator>>
764 //purpose  : 
765 //=======================================================================
766
767 static Standard_IStream& operator>>(Standard_IStream& IS,
768                                     Handle(Geom_ToroidalSurface)& S)
769 {
770   gp_Ax3 A;
771   Standard_Real R1=0.,R2=0.;
772   IS >> A;
773   GeomTools::GetReal(IS, R1);
774   GeomTools::GetReal(IS, R2);
775   S = new Geom_ToroidalSurface(A,R1,R2);
776   return IS;
777 }
778
779 //=======================================================================
780 //function : operator>>
781 //purpose  : 
782 //=======================================================================
783
784 static Standard_IStream& operator>>(Standard_IStream& IS,
785                                     Handle(Geom_SurfaceOfLinearExtrusion)& S)
786 {
787   gp_Dir D(1.,0.,0.);
788   Handle(Geom_Curve) C;
789   IS >> D;
790   GeomTools_CurveSet::ReadCurve(IS,C);
791   S = new Geom_SurfaceOfLinearExtrusion(C,D);
792   return IS;
793 }
794
795 //=======================================================================
796 //function : operator>>
797 //purpose  : 
798 //=======================================================================
799
800 static Standard_IStream& operator>>(Standard_IStream& IS,
801                                     Handle(Geom_SurfaceOfRevolution)& S)
802 {
803   gp_Pnt P(0.,0.,0.);
804   gp_Dir D(1.,0.,0.);
805   Handle(Geom_Curve) C;
806   IS >> P >> D;
807   GeomTools_CurveSet::ReadCurve(IS,C);
808   S = new Geom_SurfaceOfRevolution(C,gp_Ax1(P,D));
809   return IS;
810 }
811
812 //=======================================================================
813 //function : operator>>
814 //purpose  : 
815 //=======================================================================
816
817 static Standard_IStream& operator>>(Standard_IStream& IS,
818                                     Handle(Geom_BezierSurface)& S)
819 {
820   Standard_Boolean urational=Standard_False, vrational=Standard_False;
821   IS >> urational >> vrational;
822   Standard_Integer udegree=0, vdegree=0;
823   IS >> udegree >> vdegree;
824   TColgp_Array2OfPnt poles(1,udegree+1,1,vdegree+1);
825   TColStd_Array2OfReal weights(1,udegree+1,1,vdegree+1);
826   
827   Standard_Integer i,j;
828   for (i = 1; i <= udegree+1; i++) {
829     for (j = 1; j <= vdegree+1; j++) {
830       IS >> poles(i,j);
831       if (urational || vrational)
832         GeomTools::GetReal(IS, weights(i,j));
833     }
834   }
835
836   if (urational || vrational)
837     S = new Geom_BezierSurface(poles,weights);
838   else
839     S = new Geom_BezierSurface(poles);
840   return IS;
841 }
842
843 //=======================================================================
844 //function : operator>>
845 //purpose  : 
846 //=======================================================================
847
848 static Standard_IStream& operator>>(Standard_IStream& IS,
849                                     Handle(Geom_BSplineSurface)& S)
850 {
851   Standard_Boolean urational=Standard_False, vrational=Standard_False,
852                    uperiodic=Standard_False, vperiodic=Standard_False;
853   IS >> urational >> vrational;
854   IS >> uperiodic >> vperiodic;
855   Standard_Integer udegree=0, vdegree=0,nbupoles=0,nbvpoles=0,nbuknots=0,nbvknots=0;
856   IS >> udegree >> vdegree;
857   IS >> nbupoles >> nbvpoles;
858   IS >> nbuknots >> nbvknots;
859
860   TColgp_Array2OfPnt poles(1,nbupoles,1,nbvpoles);
861   TColStd_Array2OfReal weights(1,nbupoles,1,nbvpoles);
862   
863   Standard_Integer i,j;
864   for (i = 1; i <= nbupoles; i++) {
865     for (j = 1; j <= nbvpoles; j++) {
866       IS >> poles(i,j);
867       if (urational || vrational)
868         GeomTools::GetReal(IS, weights(i,j));
869     }
870   }
871
872   TColStd_Array1OfReal uknots(1,nbuknots);
873   TColStd_Array1OfInteger umults(1,nbuknots);
874   for (i = 1; i <= nbuknots; i++) {
875     GeomTools::GetReal(IS, uknots(i)); 
876     IS >> umults(i);
877   }
878
879   TColStd_Array1OfReal vknots(1,nbvknots);
880   TColStd_Array1OfInteger vmults(1,nbvknots);
881   for (i = 1; i <= nbvknots; i++) {
882     GeomTools::GetReal(IS, vknots(i));
883     IS >> vmults(i);
884   }
885
886   if (urational || vrational)
887     S = new Geom_BSplineSurface(poles,weights,uknots,vknots,umults,vmults,
888                                 udegree,vdegree,uperiodic,vperiodic);
889   else
890     S = new Geom_BSplineSurface(poles,uknots,vknots,umults,vmults,
891                                 udegree,vdegree,uperiodic,vperiodic);
892   return IS;
893 }
894
895 //=======================================================================
896 //function : operator>>
897 //purpose  : 
898 //=======================================================================
899
900 static Standard_IStream& operator>>(Standard_IStream& IS,
901                                     Handle(Geom_RectangularTrimmedSurface)& S)
902 {
903   Standard_Real U1=0.,U2=0.,V1=0.,V2=0.;
904   GeomTools::GetReal(IS, U1);
905   GeomTools::GetReal(IS, U2);
906   GeomTools::GetReal(IS, V1);
907   GeomTools::GetReal(IS, V2);
908   Handle(Geom_Surface) BS;
909   GeomTools_SurfaceSet::ReadSurface(IS,BS);
910   S = new Geom_RectangularTrimmedSurface(BS,U1,U2,V1,V2);
911   return IS;
912 }
913
914 //=======================================================================
915 //function : operator>>
916 //purpose  : 
917 //=======================================================================
918
919 static Standard_IStream& operator>>(Standard_IStream& IS,
920                                     Handle(Geom_OffsetSurface)& S)
921 {
922   Standard_Real O=0.;
923   GeomTools::GetReal(IS, O);
924   Handle(Geom_Surface) BS;
925   GeomTools_SurfaceSet::ReadSurface(IS,BS);
926   S = new Geom_OffsetSurface(BS,O);
927   return IS;
928 }
929
930
931 //=======================================================================
932 //function : ReadSurface
933 //purpose  : 
934 //=======================================================================
935
936 Standard_IStream& GeomTools_SurfaceSet::ReadSurface(Standard_IStream& IS,
937                                                     Handle(Geom_Surface)& S)
938 {
939   Standard_Integer stype;
940
941   try {
942     OCC_CATCH_SIGNALS
943     IS >> stype;
944     switch (stype) {
945
946     case PLANE :
947       {
948         Handle(Geom_Plane) SS;
949         IS >> SS;
950         S = SS;
951       }
952       break;
953
954     case CYLINDER :
955       {
956         Handle(Geom_CylindricalSurface) SS;
957         IS >> SS;
958         S = SS;
959       }
960       break;
961
962     case CONE :
963       {
964         Handle(Geom_ConicalSurface) SS;
965         IS >> SS;
966         S = SS;
967       }
968       break;
969
970     case SPHERE :
971       {
972         Handle(Geom_SphericalSurface) SS;
973         IS >> SS;
974         S = SS;
975       }
976       break;
977
978     case TORUS :
979       {
980         Handle(Geom_ToroidalSurface) SS;
981         IS >> SS;
982         S = SS;
983       }
984       break;
985
986     case LINEAREXTRUSION :
987       {
988         Handle(Geom_SurfaceOfLinearExtrusion) SS;
989         IS >> SS;
990         S = SS;
991       }
992       break;
993
994     case REVOLUTION :
995       {
996         Handle(Geom_SurfaceOfRevolution) SS;
997         IS >> SS;
998         S = SS;
999       }
1000       break;
1001
1002     case BEZIER :
1003       {
1004         Handle(Geom_BezierSurface) SS;
1005         IS >> SS;
1006         S = SS;
1007       }
1008       break;
1009
1010     case BSPLINE :
1011       {
1012         Handle(Geom_BSplineSurface) SS;
1013         IS >> SS;
1014         S = SS;
1015       }
1016       break;
1017
1018     case RECTANGULAR :
1019       {
1020         Handle(Geom_RectangularTrimmedSurface) SS;
1021         IS >> SS;
1022         S = SS;
1023       }
1024       break;
1025
1026     case OFFSET :
1027       {
1028         Handle(Geom_OffsetSurface) SS;
1029         IS >> SS;
1030         S = SS;
1031       }
1032       break;
1033       
1034     default :
1035       {
1036         Handle(Geom_Surface) SS;
1037         GeomTools::GetUndefinedTypeHandler()->ReadSurface(stype,IS,SS);
1038         S = SS;
1039       }
1040       break;
1041     }
1042   }
1043   catch(Standard_Failure) {
1044 #ifdef OCCT_DEBUG
1045     Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1046     cout <<"EXCEPTION in GeomTools_SurfaceSet::ReadSurface(..)!!!" << endl;
1047     cout << anExc << endl;
1048 #endif
1049     S = NULL;
1050   }
1051   return IS;
1052 }
1053
1054 //=======================================================================
1055 //function : Read
1056 //purpose  : 
1057 //=======================================================================
1058
1059 void  GeomTools_SurfaceSet::Read(Standard_IStream& IS)
1060 {
1061   char buffer[255];
1062   IS >> buffer;
1063   if (strcmp(buffer,"Surfaces")) {
1064     cout << "Not a surface table"<<endl;
1065     return;
1066   }
1067
1068   Handle(Geom_Surface) S;
1069   Standard_Integer i, nbsurf;
1070   IS >> nbsurf;
1071   //OCC19559
1072   Handle(Message_ProgressIndicator) progress = GetProgress();
1073   Message_ProgressSentry PS(progress, "Surfaces", 0, nbsurf, 1);
1074   for (i = 1; i <= nbsurf && PS.More(); i++, PS.Next()) {
1075     GeomTools_SurfaceSet::ReadSurface(IS,S);
1076     myMap.Add(S);
1077   }
1078 }
1079
1080 //=======================================================================
1081 //function : GetProgress
1082 //purpose  : 
1083 //=======================================================================
1084
1085 Handle(Message_ProgressIndicator) GeomTools_SurfaceSet::GetProgress() const
1086 {
1087   return myProgress;
1088 }
1089
1090 //=======================================================================
1091 //function : SetProgress
1092 //purpose  : 
1093 //=======================================================================
1094
1095 void GeomTools_SurfaceSet::SetProgress(const Handle(Message_ProgressIndicator)& PR)
1096 {
1097   myProgress = PR;
1098 }
1099
1100
1101