0026872: Coding - pointless instantiations of local variables in BinTools
[occt.git] / src / BinTools / BinTools_SurfaceSet.cxx
CommitLineData
b311480e 1// Created on: 2004-05-20
2// Created by: Sergey ZARITCHNY
973c2be1 3// Copyright (c) 2004-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
42cf5bc1 17#include <BinTools.hxx>
7fd59977 18#include <BinTools_CurveSet.hxx>
42cf5bc1 19#include <BinTools_SurfaceSet.hxx>
20#include <Geom_BezierSurface.hxx>
21#include <Geom_BSplineSurface.hxx>
7fd59977 22#include <Geom_ConicalSurface.hxx>
42cf5bc1 23#include <Geom_CylindricalSurface.hxx>
24#include <Geom_OffsetSurface.hxx>
25#include <Geom_Plane.hxx>
26#include <Geom_RectangularTrimmedSurface.hxx>
7fd59977 27#include <Geom_SphericalSurface.hxx>
42cf5bc1 28#include <Geom_Surface.hxx>
7fd59977 29#include <Geom_SurfaceOfLinearExtrusion.hxx>
30#include <Geom_SurfaceOfRevolution.hxx>
42cf5bc1 31#include <Geom_ToroidalSurface.hxx>
7fd59977 32#include <gp_Cone.hxx>
42cf5bc1 33#include <gp_Cylinder.hxx>
34#include <gp_Pln.hxx>
7fd59977 35#include <gp_Sphere.hxx>
36#include <gp_Torus.hxx>
42cf5bc1 37#include <Standard_ErrorHandler.hxx>
38#include <Standard_Failure.hxx>
39#include <Standard_OutOfRange.hxx>
7fd59977 40#include <TColgp_Array1OfPnt.hxx>
7fd59977 41#include <TColgp_Array2OfPnt.hxx>
42cf5bc1 42#include <TColStd_Array1OfInteger.hxx>
43#include <TColStd_Array1OfReal.hxx>
44#include <TColStd_Array2OfReal.hxx>
7fd59977 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
63BinTools_SurfaceSet::BinTools_SurfaceSet()
64{
65}
66
67
68//=======================================================================
69//function : Clear
70//purpose :
71//=======================================================================
72
73void BinTools_SurfaceSet::Clear()
74{
75 myMap.Clear();
76}
77
78
79//=======================================================================
80//function : Add
81//purpose :
82//=======================================================================
83
84Standard_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
95Handle(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
107Standard_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
118static 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
131static 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
145static 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
162static 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
180static 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
199static 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
217static 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
236static 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
250static 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
265static 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();
7fd59977 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
7fd59977 284 if (urational || vrational) {
285 BinTools::PutReal(OS, S->Weight(i,j));//Real
7fd59977 286 }
287 }
288 }
7fd59977 289 return OS;
290}
291
292
293//=======================================================================
294//function : operator <<(Geom_BSplineSurface)
295//purpose :
296//=======================================================================
297
298static 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
350static 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
369static 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
383void BinTools_SurfaceSet::WriteSurface(const Handle(Geom_Surface)& S,
384 Standard_OStream& OS)
385{
7fd59977 386 Handle(Standard_Type) TheType = S->DynamicType();
387 try {
388 OCC_CATCH_SIGNALS
389 if ( TheType == STANDARD_TYPE(Geom_Plane)) {
390 OS << Handle(Geom_Plane)::DownCast(S);
391 }
392 else if ( TheType == STANDARD_TYPE(Geom_CylindricalSurface)) {
393 OS << Handle(Geom_CylindricalSurface)::DownCast(S);
394 }
395 else if ( TheType == STANDARD_TYPE(Geom_ConicalSurface)) {
396 OS << Handle(Geom_ConicalSurface)::DownCast(S);
397 }
398 else if ( TheType == STANDARD_TYPE(Geom_SphericalSurface)) {
399 OS << Handle(Geom_SphericalSurface)::DownCast(S);
400 }
401 else if ( TheType == STANDARD_TYPE(Geom_ToroidalSurface)) {
402 OS << Handle(Geom_ToroidalSurface)::DownCast(S);
403 }
404 else if ( TheType == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) {
405 OS << Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(S);
406 }
407 else if ( TheType == STANDARD_TYPE(Geom_SurfaceOfRevolution)) {
408 OS << Handle(Geom_SurfaceOfRevolution)::DownCast(S);
409 }
410 else if ( TheType == STANDARD_TYPE(Geom_BezierSurface)) {
411 OS << Handle(Geom_BezierSurface)::DownCast(S);
412 }
413 else if ( TheType == STANDARD_TYPE(Geom_BSplineSurface)) {
414 OS << Handle(Geom_BSplineSurface)::DownCast(S);
415 }
416 else if ( TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
417 OS << Handle(Geom_RectangularTrimmedSurface)::DownCast(S);
418 }
419 else if ( TheType == STANDARD_TYPE(Geom_OffsetSurface)) {
420 OS << Handle(Geom_OffsetSurface)::DownCast(S);
421 }
422 else {
4525373b 423 Standard_Failure::Raise("UNKNOWN SURFACE TYPE");
7fd59977 424 }
425 }
426 catch(Standard_Failure) {
4525373b 427 Standard_SStream aMsg;
7fd59977 428 aMsg << "EXCEPTION in BinTools_SurfaceSet::WriteSurface(..)" << endl;
429 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
430 aMsg << anExc << endl;
431 Standard_Failure::Raise(aMsg);
432 }
433}
434
435//=======================================================================
436//function : Write
437//purpose :
438//=======================================================================
439
440void BinTools_SurfaceSet::Write(Standard_OStream& OS)const
441{
442
443 Standard_Integer i, nbsurf = myMap.Extent();
444 OS << "Surfaces "<< nbsurf << "\n";
445 for (i = 1; i <= nbsurf; i++) {
446 WriteSurface(Handle(Geom_Surface)::DownCast(myMap(i)),OS);
447 }
448
449}
450
451
452//=======================================================================
453//function : ReadPnt
454//purpose :
455//=======================================================================
456
457static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt& P)
458{
459 Standard_Real X=0.,Y=0.,Z=0.;
460 BinTools::GetReal(IS, X);
461 BinTools::GetReal(IS, Y);
462 BinTools::GetReal(IS, Z);
463 P.SetCoord(X,Y,Z);
464 return IS;
465}
466
467//=======================================================================
468//function : ReadDir
469//purpose :
470//=======================================================================
471
472static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir& D)
473{
474 Standard_Real X=0.,Y=0.,Z=0.;
475 BinTools::GetReal(IS, X);
476 BinTools::GetReal(IS, Y);
477 BinTools::GetReal(IS, Z);
478 D.SetCoord(X,Y,Z);
479 return IS;
480}
481
482//=======================================================================
483//function : ReadAx3
484//purpose :
485//=======================================================================
486
487static Standard_IStream& operator>>(Standard_IStream& IS, gp_Ax3& A3)
488{
489 gp_Pnt P(0.,0.,0.);
490 gp_Dir A(1.,0.,0.),AX(1.,0.,0.),AY(1.,0.,0.);
491 IS >> P >> A >> AX >> AY;
492 gp_Ax3 ax3(P,A,AX);
493 if (AY.DotCross(A,AX) < 0)
494 ax3.YReverse();
495 A3 = ax3;
496 return IS;
497}
498
499
500//=======================================================================
501//function : operator>>
502//purpose :
503//=======================================================================
504
505static Standard_IStream& operator>>(Standard_IStream& IS,
506 Handle(Geom_Plane)& S)
507{
508 gp_Ax3 A;
509 IS >> A;
510 S = new Geom_Plane(A);
511 return IS;
512}
513
514//=======================================================================
515//function : operator>>
516//purpose :
517//=======================================================================
518
519static Standard_IStream& operator>>(Standard_IStream& IS,
520 Handle(Geom_CylindricalSurface)& S)
521{
522 gp_Ax3 A;
523 Standard_Real R=0.;
524 IS >> A;
525 BinTools::GetReal(IS, R);
526 S = new Geom_CylindricalSurface(A,R);
527 return IS;
528}
529
530//=======================================================================
531//function : operator>>
532//purpose :
533//=======================================================================
534
535static Standard_IStream& operator>>(Standard_IStream& IS,
536 Handle(Geom_ConicalSurface)& S)
537{
538 gp_Ax3 A;
539 Standard_Real R=0.,Ang=0.;
540 IS >> A;
541 BinTools::GetReal(IS, R);
542 BinTools::GetReal(IS, Ang);
543 S = new Geom_ConicalSurface(A,Ang,R);
544 return IS;
545}
546
547//=======================================================================
548//function : operator>>
549//purpose :
550//=======================================================================
551
552static Standard_IStream& operator>>(Standard_IStream& IS,
553 Handle(Geom_SphericalSurface)& S)
554{
555 gp_Ax3 A;
556 Standard_Real R=0.;
557 IS >> A;
558 BinTools::GetReal(IS, R);
559 S = new Geom_SphericalSurface(A,R);
560 return IS;
561}
562
563//=======================================================================
564//function : operator>>
565//purpose :
566//=======================================================================
567
568static Standard_IStream& operator>>(Standard_IStream& IS,
569 Handle(Geom_ToroidalSurface)& S)
570{
571 gp_Ax3 A;
572 Standard_Real R1=0.,R2=0.;
573 IS >> A;
574 BinTools::GetReal(IS, R1);
575 BinTools::GetReal(IS, R2);
576 S = new Geom_ToroidalSurface(A,R1,R2);
577 return IS;
578}
579
580//=======================================================================
581//function : operator>>
582//purpose :
583//=======================================================================
584
585static Standard_IStream& operator>>(Standard_IStream& IS,
586 Handle(Geom_SurfaceOfLinearExtrusion)& S)
587{
588 gp_Dir D(1.,0.,0.);
589 Handle(Geom_Curve) C;
590 IS >> D;
591 BinTools_CurveSet::ReadCurve(IS,C);
592 S = new Geom_SurfaceOfLinearExtrusion(C,D);
593 return IS;
594}
595
596//=======================================================================
597//function : operator>>
598//purpose :
599//=======================================================================
600
601static Standard_IStream& operator>>(Standard_IStream& IS,
602 Handle(Geom_SurfaceOfRevolution)& S)
603{
604 gp_Pnt P(0.,0.,0.);
605 gp_Dir D(1.,0.,0.);
606 Handle(Geom_Curve) C;
607 IS >> P >> D;
608 BinTools_CurveSet::ReadCurve(IS, C);
609 S = new Geom_SurfaceOfRevolution(C,gp_Ax1(P,D));
610 return IS;
611}
612
613//=======================================================================
614//function : operator>>
615//purpose :
616//=======================================================================
617
618static Standard_IStream& operator>>(Standard_IStream& IS,
619 Handle(Geom_BezierSurface)& S)
620{
621// cout << "BezierSurface:" <<endl;
622 Standard_Boolean urational=Standard_False, vrational=Standard_False;
623 BinTools::GetBool(IS, urational);
624 BinTools::GetBool(IS, vrational);
625
626// cout << "\turational = " << urational << " vrational = " << vrational<<endl;
627 Standard_Integer udegree=0, vdegree=0;
628 Standard_ExtCharacter aVal='\0';
629 BinTools::GetExtChar(IS, aVal);
630
631 udegree = (Standard_Integer)aVal;
632 BinTools::GetExtChar(IS, aVal);
633 vdegree = (Standard_Integer)aVal;
634// cout << "\ttudegree = " << udegree << ", vdegree = " << vdegree << endl;
635
636 TColgp_Array2OfPnt poles(1,udegree+1,1,vdegree+1);
637 TColStd_Array2OfReal weights(1,udegree+1,1,vdegree+1);
638
639 Standard_Integer i,j;
640 for (i = 1; i <= udegree+1; i++) {
641 for (j = 1; j <= vdegree+1; j++) {
642 IS >> poles(i,j);//Pnt
643// cout <<"Pole X = " <<poles(i,j).X()<< " Y = " <<poles(i,j).Y()<< " Z = " << poles(i,j).Z()<<endl;
644 if (urational || vrational)
645 BinTools::GetReal(IS, weights(i,j));
646 }
647 }
648
649 if (urational || vrational)
650 S = new Geom_BezierSurface(poles,weights);
651 else
652 S = new Geom_BezierSurface(poles);
653 return IS;
654}
655
656//=======================================================================
657//function : operator>>
658//purpose :
659//=======================================================================
660
661static Standard_IStream& operator>>(Standard_IStream& IS,
662 Handle(Geom_BSplineSurface)& S)
663{
664 Standard_Boolean urational=Standard_False, vrational=Standard_False,
665 uperiodic=Standard_False, vperiodic=Standard_False;
666 BinTools::GetBool(IS, urational);
667 BinTools::GetBool(IS, vrational);
668 BinTools::GetBool(IS, uperiodic);
669 BinTools::GetBool(IS, vperiodic);
670
671 Standard_Integer udegree=0, vdegree=0,nbupoles=0,nbvpoles=0,nbuknots=0,nbvknots=0;
672 Standard_ExtCharacter aVal='\0';
673 BinTools::GetExtChar(IS, aVal);
674 udegree = (Standard_Integer)aVal;
675 BinTools::GetExtChar(IS, aVal);
676 vdegree = (Standard_Integer)aVal;
677 BinTools::GetInteger(IS, nbupoles);
678 BinTools::GetInteger(IS, nbvpoles);
679 BinTools::GetInteger(IS, nbuknots);
680 BinTools::GetInteger(IS, nbvknots);
681
682 TColgp_Array2OfPnt poles(1,nbupoles,1,nbvpoles);
683 TColStd_Array2OfReal weights(1,nbupoles,1,nbvpoles);
684
685 Standard_Integer i,j;
686 for (i = 1; i <= nbupoles; i++) {
687 for (j = 1; j <= nbvpoles; j++) {
688 IS >> poles(i,j);//Pnt
689 if (urational || vrational)
690 BinTools::GetReal(IS, weights(i,j));
691 }
692 }
693
694 TColStd_Array1OfReal uknots(1,nbuknots);
695 TColStd_Array1OfInteger umults(1,nbuknots);
696 for (i = 1; i <= nbuknots; i++) {
697 BinTools::GetReal(IS, uknots(i));
698 BinTools::GetInteger(IS, umults(i));
699 }
700
701 TColStd_Array1OfReal vknots(1,nbvknots);
702 TColStd_Array1OfInteger vmults(1,nbvknots);
703 for (i = 1; i <= nbvknots; i++) {
704 BinTools::GetReal(IS, vknots(i));
705 BinTools::GetInteger(IS, vmults(i));
706 }
707
708 if (urational || vrational)
709 S = new Geom_BSplineSurface(poles,weights,uknots,vknots,umults,vmults,
710 udegree,vdegree,uperiodic,vperiodic);
711 else
712 S = new Geom_BSplineSurface(poles,uknots,vknots,umults,vmults,
713 udegree,vdegree,uperiodic,vperiodic);
714 return IS;
715}
716
717//=======================================================================
718//function : operator>>
719//purpose :
720//=======================================================================
721
722static Standard_IStream& operator>>(Standard_IStream& IS,
723 Handle(Geom_RectangularTrimmedSurface)& S)
724{
725 Standard_Real U1=0.,U2=0.,V1=0.,V2=0.;
726 BinTools::GetReal(IS, U1);
727 BinTools::GetReal(IS, U2);
728 BinTools::GetReal(IS, V1);
729 BinTools::GetReal(IS, V2);
730 Handle(Geom_Surface) BS;
731 BinTools_SurfaceSet::ReadSurface(IS, BS);
732 S = new Geom_RectangularTrimmedSurface(BS,U1,U2,V1,V2);
733 return IS;
734}
735
736//=======================================================================
737//function : operator>>
738//purpose :
739//=======================================================================
740
741static Standard_IStream& operator>>(Standard_IStream& IS,
742 Handle(Geom_OffsetSurface)& S)
743{
744 Standard_Real O=0.;
745 BinTools::GetReal(IS, O);
746 Handle(Geom_Surface) BS;
747 BinTools_SurfaceSet::ReadSurface(IS, BS);
748 S = new Geom_OffsetSurface(BS,O);
749 return IS;
750}
751
752
753//=======================================================================
754//function : ReadSurface
755//purpose :
756//=======================================================================
757
758Standard_IStream& BinTools_SurfaceSet::ReadSurface(Standard_IStream& IS,
759 Handle(Geom_Surface)& S)
760{
7fd59977 761 try {
762 OCC_CATCH_SIGNALS
763 const Standard_Byte stype = (Standard_Byte) IS.get();
7fd59977 764 switch (stype) {
765
766 case PLANE :
767 {
768 Handle(Geom_Plane) SS;
769 IS >> SS;
770 S = SS;
771 }
772 break;
773
774 case CYLINDER :
775 {
776 Handle(Geom_CylindricalSurface) SS;
777 IS >> SS;
778 S = SS;
779 }
780 break;
781
782 case CONE :
783 {
784 Handle(Geom_ConicalSurface) SS;
785 IS >> SS;
786 S = SS;
787 }
788 break;
789
790 case SPHERE :
791 {
792 Handle(Geom_SphericalSurface) SS;
793 IS >> SS;
794 S = SS;
795 }
796 break;
797
798 case TORUS :
799 {
800 Handle(Geom_ToroidalSurface) SS;
801 IS >> SS;
802 S = SS;
803 }
804 break;
805
806 case LINEAREXTRUSION :
807 {
808 Handle(Geom_SurfaceOfLinearExtrusion) SS;
809 IS >> SS;
810 S = SS;
811 }
812 break;
813
814 case REVOLUTION :
815 {
816 Handle(Geom_SurfaceOfRevolution) SS;
817 IS >> SS;
818 S = SS;
819 }
820 break;
821
822 case BEZIER :
823 {
824 Handle(Geom_BezierSurface) SS;
825 IS >> SS;
826 S = SS;
827 }
828 break;
829
830 case BSPLINE :
831 {
832 Handle(Geom_BSplineSurface) SS;
833 IS >> SS;
834 S = SS;
835 }
836 break;
837
838 case RECTANGULAR :
839 {
840 Handle(Geom_RectangularTrimmedSurface) SS;
841 IS >> SS;
842 S = SS;
843 }
844 break;
845
846 case OFFSET :
847 {
848 Handle(Geom_OffsetSurface) SS;
849 IS >> SS;
850 S = SS;
851 }
852 break;
853
854 default :
855 {
856 S = NULL;
4525373b 857 Standard_Failure::Raise("UNKNOWN SURFACE TYPE");
7fd59977 858 }
859 break;
860 }
861 }
862 catch(Standard_Failure) {
863 S = NULL;
4525373b 864 Standard_SStream aMsg;
7fd59977 865 aMsg << "EXCEPTION in BinTools_SurfaceSet::ReadSurface(..)" << endl;
866 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
867 aMsg << anExc << endl;
868 Standard_Failure::Raise(aMsg);
869 }
870 return IS;
871}
872
873//=======================================================================
874//function : Read
875//purpose :
876//=======================================================================
877
878void BinTools_SurfaceSet::Read(Standard_IStream& IS)
879{
880 char buffer[255];
881 IS >> buffer;
882 if (IS.fail() || strcmp(buffer,"Surfaces")) {
883 Standard_SStream aMsg;
884 aMsg << "BinTools_SurfaceSet::Read: Not a surface table"<<endl;
0797d9d3 885#ifdef OCCT_DEBUG
7fd59977 886 cout <<"SurfaceSet buffer: " << buffer << endl;
887#endif
888 Standard_Failure::Raise(aMsg);
889 return;
890 }
891
892 Handle(Geom_Surface) S;
893 Standard_Integer i, nbsurf;
894 IS >> nbsurf;
895 IS.get ();//remove <lf>
896 for (i = 1; i <= nbsurf; i++) {
897 BinTools_SurfaceSet::ReadSurface(IS,S);
898 myMap.Add(S);
899 }
900}
901