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