0025266: Debug statements in the source are getting flushed on to the console
[occt.git] / src / BinTools / BinTools_SurfaceSet.cxx
1 // Created on: 2004-05-20
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <BinTools_SurfaceSet.ixx>
17 #include <BinTools.hxx>
18
19 #include <BinTools_CurveSet.hxx>
20 #include <Geom_Plane.hxx>
21 #include <Geom_CylindricalSurface.hxx>
22 #include <Geom_ConicalSurface.hxx>
23 #include <Geom_SphericalSurface.hxx>
24 #include <Geom_ToroidalSurface.hxx>
25 #include <Geom_SurfaceOfLinearExtrusion.hxx>
26 #include <Geom_SurfaceOfRevolution.hxx>
27 #include <Geom_BezierSurface.hxx>
28 #include <Geom_BSplineSurface.hxx>
29 #include <Geom_RectangularTrimmedSurface.hxx>
30 #include <Geom_OffsetSurface.hxx>
31
32 #include <gp_Pln.hxx>
33 #include <gp_Cylinder.hxx>
34 #include <gp_Cone.hxx>
35 #include <gp_Sphere.hxx>
36 #include <gp_Torus.hxx>
37
38 #include <TColStd_Array1OfReal.hxx>
39 #include <TColStd_Array1OfInteger.hxx>
40 #include <TColgp_Array1OfPnt.hxx>
41 #include <TColStd_Array2OfReal.hxx>
42 #include <TColgp_Array2OfPnt.hxx>
43 #include <Standard_Failure.hxx>
44 #include <Standard_ErrorHandler.hxx>
45
46 #define PLANE           1
47 #define CYLINDER        2
48 #define CONE            3
49 #define SPHERE          4
50 #define TORUS           5
51 #define LINEAREXTRUSION 6
52 #define REVOLUTION      7
53 #define BEZIER          8
54 #define BSPLINE         9
55 #define RECTANGULAR     10
56 #define OFFSET          11
57
58 //=======================================================================
59 //function : BinTools_SurfaceSet
60 //purpose  : 
61 //=======================================================================
62
63 BinTools_SurfaceSet::BinTools_SurfaceSet() 
64 {
65 }
66
67
68 //=======================================================================
69 //function : Clear
70 //purpose  : 
71 //=======================================================================
72
73 void  BinTools_SurfaceSet::Clear()
74 {
75   myMap.Clear();
76 }
77
78
79 //=======================================================================
80 //function : Add
81 //purpose  : 
82 //=======================================================================
83
84 Standard_Integer  BinTools_SurfaceSet::Add(const Handle(Geom_Surface)& S)
85 {
86   return myMap.Add(S);
87 }
88
89
90 //=======================================================================
91 //function : Surface
92 //purpose  : 
93 //=======================================================================
94
95 Handle(Geom_Surface)  BinTools_SurfaceSet::Surface
96        (const Standard_Integer I)const 
97 {
98   return  Handle(Geom_Surface)::DownCast(myMap(I));
99 }
100
101
102 //=======================================================================
103 //function : Index
104 //purpose  : 
105 //=======================================================================
106
107 Standard_Integer  BinTools_SurfaceSet::Index
108   (const Handle(Geom_Surface)& S)const 
109 {
110   return myMap.FindIndex(S);
111 }
112
113 //=======================================================================
114 //function : operator << (gp_Pnt)
115 //purpose  : 
116 //=======================================================================
117
118 static Standard_OStream& operator <<(Standard_OStream& OS, const gp_Pnt P)
119 {
120   BinTools::PutReal(OS, P.X());
121   BinTools::PutReal(OS, P.Y());
122   BinTools::PutReal(OS, P.Z());
123   return OS;
124 }
125
126 //=======================================================================
127 //function : operator << (gp_Dir)
128 //purpose  : 
129 //=======================================================================
130
131 static Standard_OStream& operator <<(Standard_OStream& OS, const gp_Dir D)
132 {
133   BinTools::PutReal(OS, D.X());
134   BinTools::PutReal(OS, D.Y());
135   BinTools::PutReal(OS, D.Z());
136   return OS;
137 }
138
139
140 //=======================================================================
141 //function : operator <<(Geom_Plane)
142 //purpose  : 
143 //=======================================================================
144
145 static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom_Plane)& S)
146 {
147   OS << (Standard_Byte)PLANE;
148   gp_Pln P = S->Pln();
149   OS << P.Location();//Pnt
150   OS << P.Axis().Direction();
151   OS << P.XAxis().Direction();
152   OS << P.YAxis().Direction();
153   return OS;
154 }
155
156
157 //=======================================================================
158 //function : operator <<(Geom_CylindricalSurface)
159 //purpose  : 
160 //=======================================================================
161
162 static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom_CylindricalSurface)& S)
163 {
164   OS << (Standard_Byte)CYLINDER;
165   gp_Cylinder P = S->Cylinder();
166   OS << P.Location();//Pnt
167   OS << P.Axis().Direction();
168   OS << P.XAxis().Direction();
169   OS << P.YAxis().Direction();
170   BinTools::PutReal(OS, P.Radius());
171   return OS;
172 }
173
174
175 //=======================================================================
176 //function : operator <<(Geom_ConicalSurface)
177 //purpose  : 
178 //=======================================================================
179
180 static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom_ConicalSurface)& S)
181 {
182   OS << (Standard_Byte)CONE;
183   gp_Cone P = S->Cone();
184   OS << P.Location();//Pnt
185   OS << P.Axis().Direction();
186   OS << P.XAxis().Direction();
187   OS << P.YAxis().Direction();
188   BinTools::PutReal(OS, P.RefRadius());
189   BinTools::PutReal(OS, P.SemiAngle());
190   return OS;
191 }
192
193
194 //=======================================================================
195 //function : operator <<(Geom_SphericalSurface)
196 //purpose  : 
197 //=======================================================================
198
199 static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom_SphericalSurface)& S)
200 {
201   OS << (Standard_Byte)SPHERE;
202   gp_Sphere P = S->Sphere();
203   OS << P.Location();//Pnt
204   OS << P.Position().Axis().Direction();
205   OS << P.XAxis().Direction();
206   OS << P.YAxis().Direction();
207   BinTools::PutReal(OS, P.Radius());
208   return OS;
209 }
210
211
212 //=======================================================================
213 //function : operator <<(Geom_ToroidalSurface)
214 //purpose  : 
215 //=======================================================================
216
217 static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom_ToroidalSurface)& S)
218 {
219   OS << (Standard_Byte)TORUS;
220   gp_Torus P = S->Torus();
221   OS << P.Location();//Pnt
222   OS << P.Axis().Direction();
223   OS << P.XAxis().Direction();
224   OS << P.YAxis().Direction();
225   BinTools::PutReal(OS, P.MajorRadius());
226   BinTools::PutReal(OS, P.MinorRadius());
227   return OS;
228 }
229
230
231 //=======================================================================
232 //function : operator <<(Geom_SurfaceOfLinearExtrusion)
233 //purpose  : 
234 //=======================================================================
235
236 static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom_SurfaceOfLinearExtrusion)& S)
237 {
238   OS << (Standard_Byte)LINEAREXTRUSION;
239   OS << S->Direction();
240   BinTools_CurveSet::WriteCurve(S->BasisCurve(),OS);
241   return OS;
242 }
243
244
245 //=======================================================================
246 //function : operator <<(Geom_SurfaceOfRevolution)
247 //purpose  : 
248 //=======================================================================
249
250 static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom_SurfaceOfRevolution)& S)
251 {
252   OS << (Standard_Byte)REVOLUTION;
253   OS << S->Location();
254   OS << S->Direction();
255   BinTools_CurveSet::WriteCurve(S->BasisCurve(),OS);
256   return OS;
257 }
258
259
260 //=======================================================================
261 //function : operator <<(Geom_BezierSurface)
262 //purpose  : 
263 //=======================================================================
264
265 static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom_BezierSurface)& S)
266 {
267   OS << (Standard_Byte)BEZIER;
268   Standard_Boolean urational = S->IsURational() ? 1:0;
269   Standard_Boolean vrational = S->IsVRational() ? 1:0;
270   BinTools::PutBool(OS, urational); //rational
271   BinTools::PutBool(OS, vrational);
272 //  cout << "Bezier Surface:"<< endl;
273 //  cout << "\turational = "<<urational<<" vrational = " <<vrational<<endl;
274
275 // poles and weights
276   Standard_Integer i,j,udegree,vdegree;
277   udegree = S->UDegree();
278   vdegree = S->VDegree();
279   BinTools::PutExtChar(OS, (Standard_ExtCharacter)udegree);
280   BinTools::PutExtChar(OS, (Standard_ExtCharacter)vdegree);
281   for (i = 1; i <= udegree+1; i++) {
282     for (j = 1; j <= vdegree+1; j++) {
283       OS << S->Pole(i,j); //Pnt
284       if (urational || vrational) {
285         BinTools::PutReal(OS, S->Weight(i,j));//Real
286       }
287     }
288   }
289   return OS;
290 }
291
292
293 //=======================================================================
294 //function : operator <<(Geom_BSplineSurface)
295 //purpose  : 
296 //=======================================================================
297
298 static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom_BSplineSurface)& S)
299 {
300   OS << (Standard_Byte)BSPLINE;
301   Standard_Boolean urational = S->IsURational() ? 1:0;
302   Standard_Boolean vrational = S->IsVRational() ? 1:0;
303   Standard_Boolean uperiodic = S->IsUPeriodic() ? 1:0;
304   Standard_Boolean vperiodic = S->IsVPeriodic() ? 1:0;
305   BinTools::PutBool(OS, urational); 
306   BinTools::PutBool(OS, vrational); 
307   BinTools::PutBool(OS, uperiodic); 
308   BinTools::PutBool(OS, vperiodic); 
309
310 // poles and weights
311   Standard_Integer i,j,udegree,vdegree,nbupoles,nbvpoles,nbuknots,nbvknots;
312   udegree  = S->UDegree();
313   vdegree  = S->VDegree();
314   nbupoles = S->NbUPoles();
315   nbvpoles = S->NbVPoles();
316   nbuknots = S->NbUKnots();
317   nbvknots = S->NbVKnots();
318   BinTools::PutExtChar(OS, (Standard_ExtCharacter) udegree);
319   BinTools::PutExtChar(OS, (Standard_ExtCharacter) vdegree);
320   BinTools::PutInteger(OS, nbupoles);
321   BinTools::PutInteger(OS, nbvpoles);
322   BinTools::PutInteger(OS, nbuknots);
323   BinTools::PutInteger(OS, nbvknots);
324   for (i = 1; i <= nbupoles; i++) {
325     for (j = 1; j <= nbvpoles; j++) {
326       OS << S->Pole(i,j); //Pnt
327       if (urational || vrational)
328         BinTools::PutReal(OS, S->Weight(i,j));//Real    
329     }
330   }
331
332   for (i = 1; i <= nbuknots; i++) {
333     BinTools::PutReal(OS,S->UKnot(i));
334     BinTools::PutInteger(OS, S->UMultiplicity(i));
335   }
336
337   for (i = 1; i <= nbvknots; i++) {
338     BinTools::PutReal(OS,S->VKnot(i));
339     BinTools::PutInteger(OS, S->VMultiplicity(i));
340   }
341   return OS;
342 }
343
344
345 //=======================================================================
346 //function :  operator <<(Geom_RectangularTrimmedSurface)
347 //purpose  : 
348 //=======================================================================
349
350 static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom_RectangularTrimmedSurface)& S)
351 {
352   OS << (Standard_Byte)RECTANGULAR;
353   Standard_Real U1,U2,V1,V2;
354   S->Bounds(U1,U2,V1,V2);
355   BinTools::PutReal(OS, U1);
356   BinTools::PutReal(OS, U2);
357   BinTools::PutReal(OS, V1);
358   BinTools::PutReal(OS, V2);
359   BinTools_SurfaceSet::WriteSurface(S->BasisSurface(),OS);
360   return OS;
361 }
362
363
364 //=======================================================================
365 //function : operator <<(Geom_OffsetSurface)
366 //purpose  : 
367 //=======================================================================
368
369 static Standard_OStream& operator <<(Standard_OStream& OS, const Handle(Geom_OffsetSurface)& S)
370 {
371   OS << (Standard_Byte)OFFSET;
372   BinTools::PutReal(OS, S->Offset());
373   BinTools_SurfaceSet::WriteSurface(S->BasisSurface(),OS);
374   return OS;
375 }
376
377
378 //=======================================================================
379 //function : WriteSurface
380 //purpose  : 
381 //=======================================================================
382
383 void BinTools_SurfaceSet::WriteSurface(const Handle(Geom_Surface)& S,
384                                         Standard_OStream& OS)
385 {
386   Standard_SStream aMsg;
387   Handle(Standard_Type) TheType = S->DynamicType();
388   try {
389     OCC_CATCH_SIGNALS
390     if ( TheType ==  STANDARD_TYPE(Geom_Plane)) {
391       OS << Handle(Geom_Plane)::DownCast(S);
392     }
393     else if ( TheType ==  STANDARD_TYPE(Geom_CylindricalSurface)) {
394       OS << Handle(Geom_CylindricalSurface)::DownCast(S);
395     }
396     else if ( TheType ==  STANDARD_TYPE(Geom_ConicalSurface)) {
397       OS << Handle(Geom_ConicalSurface)::DownCast(S);
398     }
399     else if ( TheType ==  STANDARD_TYPE(Geom_SphericalSurface)) {
400       OS << Handle(Geom_SphericalSurface)::DownCast(S);
401     }
402     else if ( TheType ==  STANDARD_TYPE(Geom_ToroidalSurface)) {
403       OS << Handle(Geom_ToroidalSurface)::DownCast(S);
404     }
405     else if ( TheType ==  STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
406       OS << Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(S);
407     }
408     else if ( TheType ==  STANDARD_TYPE(Geom_SurfaceOfRevolution)) {
409       OS << Handle(Geom_SurfaceOfRevolution)::DownCast(S);
410     }
411     else if ( TheType ==  STANDARD_TYPE(Geom_BezierSurface)) {
412       OS << Handle(Geom_BezierSurface)::DownCast(S);
413     }
414     else if ( TheType ==  STANDARD_TYPE(Geom_BSplineSurface)) {
415       OS << Handle(Geom_BSplineSurface)::DownCast(S);
416     }
417     else if ( TheType ==  STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
418       OS << Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
419     }
420     else if ( TheType ==  STANDARD_TYPE(Geom_OffsetSurface)) {
421       OS << Handle(Geom_OffsetSurface)::DownCast(S);
422     }
423     else {
424       aMsg <<"UNKNOWN SURFACE TYPE" <<endl;
425       Standard_Failure::Raise(aMsg);
426     }
427   }
428    catch(Standard_Failure) {
429     aMsg << "EXCEPTION in BinTools_SurfaceSet::WriteSurface(..)" << endl;
430     Handle(Standard_Failure) anExc = Standard_Failure::Caught();
431     aMsg << anExc << endl;
432     Standard_Failure::Raise(aMsg);
433   }  
434 }
435
436 //=======================================================================
437 //function : Write
438 //purpose  : 
439 //=======================================================================
440
441 void  BinTools_SurfaceSet::Write(Standard_OStream& OS)const 
442 {
443
444   Standard_Integer i, nbsurf = myMap.Extent();
445   OS << "Surfaces "<< nbsurf << "\n";
446   for (i = 1; i <= nbsurf; i++) {
447     WriteSurface(Handle(Geom_Surface)::DownCast(myMap(i)),OS);
448   }
449
450 }
451
452
453 //=======================================================================
454 //function : ReadPnt
455 //purpose  : 
456 //=======================================================================
457
458 static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt& P)
459 {
460   Standard_Real X=0.,Y=0.,Z=0.;
461   BinTools::GetReal(IS, X);
462   BinTools::GetReal(IS, Y);
463   BinTools::GetReal(IS, Z);
464   P.SetCoord(X,Y,Z);
465   return IS;
466 }
467
468 //=======================================================================
469 //function : ReadDir
470 //purpose  : 
471 //=======================================================================
472
473 static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir& D)
474 {
475   Standard_Real X=0.,Y=0.,Z=0.;
476   BinTools::GetReal(IS, X);
477   BinTools::GetReal(IS, Y);
478   BinTools::GetReal(IS, Z);
479   D.SetCoord(X,Y,Z);
480   return IS;
481 }
482
483 //=======================================================================
484 //function : ReadAx3
485 //purpose  : 
486 //=======================================================================
487
488 static Standard_IStream& operator>>(Standard_IStream& IS, gp_Ax3& A3)
489 {
490   gp_Pnt P(0.,0.,0.);
491   gp_Dir A(1.,0.,0.),AX(1.,0.,0.),AY(1.,0.,0.);
492   IS >> P >> A >> AX >> AY;
493   gp_Ax3 ax3(P,A,AX);
494   if (AY.DotCross(A,AX) < 0)
495     ax3.YReverse();
496   A3 = ax3;
497   return IS;
498 }
499
500
501 //=======================================================================
502 //function : operator>>
503 //purpose  : 
504 //=======================================================================
505
506 static Standard_IStream& operator>>(Standard_IStream& IS,
507                                     Handle(Geom_Plane)& S)
508 {
509   gp_Ax3 A;
510   IS >> A;
511   S = new Geom_Plane(A);
512   return IS;
513 }
514
515 //=======================================================================
516 //function : operator>>
517 //purpose  : 
518 //=======================================================================
519
520 static Standard_IStream& operator>>(Standard_IStream& IS,
521                                     Handle(Geom_CylindricalSurface)& S)
522 {
523   gp_Ax3 A;
524   Standard_Real R=0.;
525   IS >> A;
526   BinTools::GetReal(IS, R);
527   S = new Geom_CylindricalSurface(A,R);
528   return IS;
529 }
530
531 //=======================================================================
532 //function : operator>>
533 //purpose  : 
534 //=======================================================================
535
536 static Standard_IStream& operator>>(Standard_IStream& IS,
537                                     Handle(Geom_ConicalSurface)& S)
538 {
539   gp_Ax3 A;
540   Standard_Real R=0.,Ang=0.;
541   IS >> A;
542   BinTools::GetReal(IS, R);
543   BinTools::GetReal(IS, Ang);
544   S = new Geom_ConicalSurface(A,Ang,R);
545   return IS;
546 }
547
548 //=======================================================================
549 //function : operator>>
550 //purpose  : 
551 //=======================================================================
552
553 static Standard_IStream& operator>>(Standard_IStream& IS,
554                                     Handle(Geom_SphericalSurface)& S)
555 {
556   gp_Ax3 A;
557   Standard_Real R=0.;
558   IS >> A;
559   BinTools::GetReal(IS, R);
560   S = new Geom_SphericalSurface(A,R);
561   return IS;
562 }
563
564 //=======================================================================
565 //function : operator>>
566 //purpose  : 
567 //=======================================================================
568
569 static Standard_IStream& operator>>(Standard_IStream& IS,
570                                     Handle(Geom_ToroidalSurface)& S)
571 {
572   gp_Ax3 A;
573   Standard_Real R1=0.,R2=0.;
574   IS >> A;
575   BinTools::GetReal(IS, R1);
576   BinTools::GetReal(IS, R2);
577   S = new Geom_ToroidalSurface(A,R1,R2);
578   return IS;
579 }
580
581 //=======================================================================
582 //function : operator>>
583 //purpose  : 
584 //=======================================================================
585
586 static Standard_IStream& operator>>(Standard_IStream& IS,
587                                     Handle(Geom_SurfaceOfLinearExtrusion)& S)
588 {
589   gp_Dir D(1.,0.,0.);
590   Handle(Geom_Curve) C;
591   IS >> D;
592   BinTools_CurveSet::ReadCurve(IS,C);
593   S = new Geom_SurfaceOfLinearExtrusion(C,D);
594   return IS;
595 }
596
597 //=======================================================================
598 //function : operator>>
599 //purpose  : 
600 //=======================================================================
601
602 static Standard_IStream& operator>>(Standard_IStream& IS,
603                                     Handle(Geom_SurfaceOfRevolution)& S)
604 {
605   gp_Pnt P(0.,0.,0.);
606   gp_Dir D(1.,0.,0.);
607   Handle(Geom_Curve) C;
608   IS >> P >> D;
609   BinTools_CurveSet::ReadCurve(IS, C);
610   S = new Geom_SurfaceOfRevolution(C,gp_Ax1(P,D));
611   return IS;
612 }
613
614 //=======================================================================
615 //function : operator>>
616 //purpose  : 
617 //=======================================================================
618
619 static Standard_IStream& operator>>(Standard_IStream& IS,
620                                     Handle(Geom_BezierSurface)& S)
621 {
622 //  cout << "BezierSurface:" <<endl;
623   Standard_Boolean urational=Standard_False, vrational=Standard_False;
624   BinTools::GetBool(IS, urational);
625   BinTools::GetBool(IS, vrational);
626
627 //  cout << "\turational = " << urational << " vrational = " << vrational<<endl;
628   Standard_Integer udegree=0, vdegree=0;
629   Standard_ExtCharacter aVal='\0';
630   BinTools::GetExtChar(IS, aVal);
631   
632   udegree = (Standard_Integer)aVal;
633   BinTools::GetExtChar(IS, aVal);
634   vdegree = (Standard_Integer)aVal;
635 //  cout << "\ttudegree  = " << udegree << ", vdegree = " << vdegree << endl;
636
637   TColgp_Array2OfPnt poles(1,udegree+1,1,vdegree+1);
638   TColStd_Array2OfReal weights(1,udegree+1,1,vdegree+1);
639   
640   Standard_Integer i,j;
641   for (i = 1; i <= udegree+1; i++) {
642     for (j = 1; j <= vdegree+1; j++) {
643       IS >> poles(i,j);//Pnt
644 //      cout <<"Pole X = " <<poles(i,j).X()<< " Y = " <<poles(i,j).Y()<< " Z = " << poles(i,j).Z()<<endl;
645       if (urational || vrational)
646         BinTools::GetReal(IS, weights(i,j));
647     }
648   }
649
650   if (urational || vrational)
651     S = new Geom_BezierSurface(poles,weights);
652   else
653     S = new Geom_BezierSurface(poles);
654   return IS;
655 }
656
657 //=======================================================================
658 //function : operator>>
659 //purpose  : 
660 //=======================================================================
661
662 static Standard_IStream& operator>>(Standard_IStream& IS,
663                                     Handle(Geom_BSplineSurface)& S)
664 {
665   Standard_Boolean urational=Standard_False, vrational=Standard_False,
666                    uperiodic=Standard_False, vperiodic=Standard_False;
667   BinTools::GetBool(IS, urational); 
668   BinTools::GetBool(IS, vrational); 
669   BinTools::GetBool(IS, uperiodic);
670   BinTools::GetBool(IS, vperiodic);
671
672   Standard_Integer udegree=0, vdegree=0,nbupoles=0,nbvpoles=0,nbuknots=0,nbvknots=0;
673   Standard_ExtCharacter aVal='\0';
674   BinTools::GetExtChar(IS, aVal);
675   udegree = (Standard_Integer)aVal;
676   BinTools::GetExtChar(IS, aVal);
677   vdegree = (Standard_Integer)aVal;
678   BinTools::GetInteger(IS, nbupoles);
679   BinTools::GetInteger(IS, nbvpoles);
680   BinTools::GetInteger(IS, nbuknots);
681   BinTools::GetInteger(IS, nbvknots);
682
683   TColgp_Array2OfPnt poles(1,nbupoles,1,nbvpoles);
684   TColStd_Array2OfReal weights(1,nbupoles,1,nbvpoles);
685   
686   Standard_Integer i,j;
687   for (i = 1; i <= nbupoles; i++) {
688     for (j = 1; j <= nbvpoles; j++) {
689       IS >> poles(i,j);//Pnt
690       if (urational || vrational)
691         BinTools::GetReal(IS, weights(i,j)); 
692     }
693   }
694
695   TColStd_Array1OfReal uknots(1,nbuknots);
696   TColStd_Array1OfInteger umults(1,nbuknots);
697   for (i = 1; i <= nbuknots; i++) {
698     BinTools::GetReal(IS, uknots(i));
699     BinTools::GetInteger(IS, umults(i));
700   }
701
702   TColStd_Array1OfReal vknots(1,nbvknots);
703   TColStd_Array1OfInteger vmults(1,nbvknots);
704   for (i = 1; i <= nbvknots; i++) {
705     BinTools::GetReal(IS, vknots(i));
706     BinTools::GetInteger(IS, vmults(i));
707   }
708
709   if (urational || vrational)
710     S = new Geom_BSplineSurface(poles,weights,uknots,vknots,umults,vmults,
711                                 udegree,vdegree,uperiodic,vperiodic);
712   else
713     S = new Geom_BSplineSurface(poles,uknots,vknots,umults,vmults,
714                                 udegree,vdegree,uperiodic,vperiodic);
715   return IS;
716 }
717
718 //=======================================================================
719 //function : operator>>
720 //purpose  : 
721 //=======================================================================
722
723 static Standard_IStream& operator>>(Standard_IStream& IS,
724                                     Handle(Geom_RectangularTrimmedSurface)& S)
725 {
726   Standard_Real U1=0.,U2=0.,V1=0.,V2=0.;
727   BinTools::GetReal(IS, U1);
728   BinTools::GetReal(IS, U2);
729   BinTools::GetReal(IS, V1);
730   BinTools::GetReal(IS, V2);
731   Handle(Geom_Surface) BS;
732   BinTools_SurfaceSet::ReadSurface(IS, BS);
733   S = new Geom_RectangularTrimmedSurface(BS,U1,U2,V1,V2);
734   return IS;
735 }
736
737 //=======================================================================
738 //function : operator>>
739 //purpose  : 
740 //=======================================================================
741
742 static Standard_IStream& operator>>(Standard_IStream& IS,
743                                     Handle(Geom_OffsetSurface)& S)
744 {
745   Standard_Real O=0.;
746   BinTools::GetReal(IS, O);
747   Handle(Geom_Surface) BS;
748   BinTools_SurfaceSet::ReadSurface(IS, BS);
749   S = new Geom_OffsetSurface(BS,O);
750   return IS;
751 }
752
753
754 //=======================================================================
755 //function : ReadSurface
756 //purpose  : 
757 //=======================================================================
758
759 Standard_IStream& BinTools_SurfaceSet::ReadSurface(Standard_IStream& IS,
760                                                     Handle(Geom_Surface)& S)
761 {
762   Standard_SStream aMsg;
763   try {
764     OCC_CATCH_SIGNALS
765     const Standard_Byte stype = (Standard_Byte) IS.get();
766     switch (stype) {
767
768     case PLANE :
769       {
770         Handle(Geom_Plane) SS;
771         IS >> SS;
772         S = SS;
773       }
774       break;
775
776     case CYLINDER :
777       {
778         Handle(Geom_CylindricalSurface) SS;
779         IS >> SS;
780         S = SS;
781       }
782       break;
783
784     case CONE :
785       {
786         Handle(Geom_ConicalSurface) SS;
787         IS >> SS;
788         S = SS;
789       }
790       break;
791
792     case SPHERE :
793       {
794         Handle(Geom_SphericalSurface) SS;
795         IS >> SS;
796         S = SS;
797       }
798       break;
799
800     case TORUS :
801       {
802         Handle(Geom_ToroidalSurface) SS;
803         IS >> SS;
804         S = SS;
805       }
806       break;
807
808     case LINEAREXTRUSION :
809       {
810         Handle(Geom_SurfaceOfLinearExtrusion) SS;
811         IS >> SS;
812         S = SS;
813       }
814       break;
815
816     case REVOLUTION :
817       {
818         Handle(Geom_SurfaceOfRevolution) SS;
819         IS >> SS;
820         S = SS;
821       }
822       break;
823
824     case BEZIER :
825       {
826         Handle(Geom_BezierSurface) SS;
827         IS >> SS;
828         S = SS;
829       }
830       break;
831
832     case BSPLINE :
833       {
834         Handle(Geom_BSplineSurface) SS;
835         IS >> SS;
836         S = SS;
837       }
838       break;
839
840     case RECTANGULAR :
841       {
842         Handle(Geom_RectangularTrimmedSurface) SS;
843         IS >> SS;
844         S = SS;
845       }
846       break;
847
848     case OFFSET :
849       {
850         Handle(Geom_OffsetSurface) SS;
851         IS >> SS;
852         S = SS;
853       }
854       break;
855       
856     default :
857       {
858         S = NULL;
859         aMsg << "UNKNOWN SURFACE TYPE" << endl;
860         Standard_Failure::Raise(aMsg);        
861       }
862       break;
863     }
864   }
865   catch(Standard_Failure) {
866     S = NULL;
867     aMsg << "EXCEPTION in BinTools_SurfaceSet::ReadSurface(..)" << endl;
868     Handle(Standard_Failure) anExc = Standard_Failure::Caught();
869     aMsg << anExc << endl;
870     Standard_Failure::Raise(aMsg);
871   }
872   return IS;
873 }
874
875 //=======================================================================
876 //function : Read
877 //purpose  : 
878 //=======================================================================
879
880 void  BinTools_SurfaceSet::Read(Standard_IStream& IS)
881 {
882   char buffer[255];
883   IS >> buffer;
884   if (IS.fail() || strcmp(buffer,"Surfaces")) {
885     Standard_SStream aMsg;
886     aMsg << "BinTools_SurfaceSet::Read:  Not a surface table"<<endl;
887 #ifdef BINTOOLS_DEB
888     cout <<"SurfaceSet buffer: " << buffer << endl;
889 #endif
890     Standard_Failure::Raise(aMsg);
891     return;
892   }
893
894   Handle(Geom_Surface) S;
895   Standard_Integer i, nbsurf;
896   IS >> nbsurf;
897   IS.get ();//remove <lf>
898   for (i = 1; i <= nbsurf; i++) {
899     BinTools_SurfaceSet::ReadSurface(IS,S);
900     myMap.Add(S);
901   }
902 }
903