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