0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / GeomTools / GeomTools_SurfaceSet.cxx
CommitLineData
b311480e 1// Created on: 1993-07-19
2// Created by: Remi LEQUETTE
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
42cf5bc1 18#include <Geom_BezierSurface.hxx>
19#include <Geom_BSplineSurface.hxx>
7fd59977 20#include <Geom_ConicalSurface.hxx>
42cf5bc1 21#include <Geom_CylindricalSurface.hxx>
22#include <Geom_OffsetSurface.hxx>
23#include <Geom_Plane.hxx>
24#include <Geom_RectangularTrimmedSurface.hxx>
7fd59977 25#include <Geom_SphericalSurface.hxx>
42cf5bc1 26#include <Geom_Surface.hxx>
7fd59977 27#include <Geom_SurfaceOfLinearExtrusion.hxx>
28#include <Geom_SurfaceOfRevolution.hxx>
42cf5bc1 29#include <Geom_ToroidalSurface.hxx>
30#include <GeomTools.hxx>
31#include <GeomTools_CurveSet.hxx>
32#include <GeomTools_SurfaceSet.hxx>
33#include <GeomTools_UndefinedTypeHandler.hxx>
7fd59977 34#include <gp_Cone.hxx>
42cf5bc1 35#include <gp_Cylinder.hxx>
36#include <gp_Pln.hxx>
7fd59977 37#include <gp_Sphere.hxx>
38#include <gp_Torus.hxx>
42cf5bc1 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>
7fd59977 45#include <TColgp_Array1OfPnt.hxx>
7fd59977 46#include <TColgp_Array2OfPnt.hxx>
42cf5bc1 47#include <TColStd_Array1OfInteger.hxx>
48#include <TColStd_Array1OfReal.hxx>
49#include <TColStd_Array2OfReal.hxx>
7fd59977 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
68GeomTools_SurfaceSet::GeomTools_SurfaceSet()
69{
70}
71
72
73//=======================================================================
74//function : Clear
75//purpose :
76//=======================================================================
77
78void GeomTools_SurfaceSet::Clear()
79{
80 myMap.Clear();
81}
82
83
84//=======================================================================
85//function : Add
86//purpose :
87//=======================================================================
88
89Standard_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
100Handle(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
114Standard_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
125static 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
144static 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
163static 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
191static 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
221static 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
254static 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
284static 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
314static 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
336static 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
360static 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 "<<setw(2)<<i<<", "<<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
422static 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 "<<setw(2)<<i<<", "<<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 "<<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 "<<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
520static 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
543static 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
564void 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 // cout << "***** Unknown Surface ********"<<endl;
609 }
610}
611
612//=======================================================================
613//function : Dump
614//purpose :
615//=======================================================================
616
617void 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 << 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
636void GeomTools_SurfaceSet::Write(Standard_OStream& OS)const
637{
60be1f9b 638 std::streamsize prec = OS.precision(17);
7fd59977 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);
7fd59977 645 for (i = 1; i <= nbsurf && PS.More(); i++, PS.Next()) {
7fd59977 646 PrintSurface(Handle(Geom_Surface)::DownCast(myMap(i)),OS,Standard_True);
647 }
7fd59977 648 OS.precision(prec);
649}
650
651
652//=======================================================================
653//function : ReadPnt
654//purpose :
655//=======================================================================
656
657static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt& P)
658{
659 Standard_Real X=0.,Y=0.,Z=0.;
71598a83 660 GeomTools::GetReal(IS, X);
661 GeomTools::GetReal(IS, Y);
662 GeomTools::GetReal(IS, Z);
7fd59977 663 P.SetCoord(X,Y,Z);
664 return IS;
665}
666
667//=======================================================================
668//function : ReadDir
669//purpose :
670//=======================================================================
671
672static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir& D)
673{
674 Standard_Real X=0.,Y=0.,Z=0.;
71598a83 675 GeomTools::GetReal(IS, X);
676 GeomTools::GetReal(IS, Y);
677 GeomTools::GetReal(IS, Z);
7fd59977 678 D.SetCoord(X,Y,Z);
679 return IS;
680}
681
682//=======================================================================
683//function : ReadAx3
684//purpose :
685//=======================================================================
686
687static 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
705static 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
719static Standard_IStream& operator>>(Standard_IStream& IS,
720 Handle(Geom_CylindricalSurface)& S)
721{
722 gp_Ax3 A;
723 Standard_Real R=0.;
71598a83 724 IS >> A;
725 GeomTools::GetReal(IS, R);
7fd59977 726 S = new Geom_CylindricalSurface(A,R);
727 return IS;
728}
729
730//=======================================================================
731//function : operator>>
732//purpose :
733//=======================================================================
734
735static Standard_IStream& operator>>(Standard_IStream& IS,
736 Handle(Geom_ConicalSurface)& S)
737{
738 gp_Ax3 A;
739 Standard_Real R=0.,Ang=0.;
71598a83 740 IS >> A;
741 GeomTools::GetReal(IS, R);
742 GeomTools::GetReal(IS, Ang);
7fd59977 743 S = new Geom_ConicalSurface(A,Ang,R);
744 return IS;
745}
746
747//=======================================================================
748//function : operator>>
749//purpose :
750//=======================================================================
751
752static Standard_IStream& operator>>(Standard_IStream& IS,
753 Handle(Geom_SphericalSurface)& S)
754{
755 gp_Ax3 A;
756 Standard_Real R=0.;
71598a83 757 IS >> A;
758 GeomTools::GetReal(IS, R);
7fd59977 759 S = new Geom_SphericalSurface(A,R);
760 return IS;
761}
762
763//=======================================================================
764//function : operator>>
765//purpose :
766//=======================================================================
767
768static Standard_IStream& operator>>(Standard_IStream& IS,
769 Handle(Geom_ToroidalSurface)& S)
770{
771 gp_Ax3 A;
772 Standard_Real R1=0.,R2=0.;
71598a83 773 IS >> A;
774 GeomTools::GetReal(IS, R1);
775 GeomTools::GetReal(IS, R2);
7fd59977 776 S = new Geom_ToroidalSurface(A,R1,R2);
777 return IS;
778}
779
780//=======================================================================
781//function : operator>>
782//purpose :
783//=======================================================================
784
785static Standard_IStream& operator>>(Standard_IStream& IS,
786 Handle(Geom_SurfaceOfLinearExtrusion)& S)
787{
788 gp_Dir D(1.,0.,0.);
789 Handle(Geom_Curve) C;
790 IS >> D;
791 GeomTools_CurveSet::ReadCurve(IS,C);
792 S = new Geom_SurfaceOfLinearExtrusion(C,D);
793 return IS;
794}
795
796//=======================================================================
797//function : operator>>
798//purpose :
799//=======================================================================
800
801static Standard_IStream& operator>>(Standard_IStream& IS,
802 Handle(Geom_SurfaceOfRevolution)& S)
803{
804 gp_Pnt P(0.,0.,0.);
805 gp_Dir D(1.,0.,0.);
806 Handle(Geom_Curve) C;
807 IS >> P >> D;
808 GeomTools_CurveSet::ReadCurve(IS,C);
809 S = new Geom_SurfaceOfRevolution(C,gp_Ax1(P,D));
810 return IS;
811}
812
813//=======================================================================
814//function : operator>>
815//purpose :
816//=======================================================================
817
818static Standard_IStream& operator>>(Standard_IStream& IS,
819 Handle(Geom_BezierSurface)& S)
820{
821 Standard_Boolean urational=Standard_False, vrational=Standard_False;
822 IS >> urational >> vrational;
823 Standard_Integer udegree=0, vdegree=0;
824 IS >> udegree >> vdegree;
825 TColgp_Array2OfPnt poles(1,udegree+1,1,vdegree+1);
826 TColStd_Array2OfReal weights(1,udegree+1,1,vdegree+1);
827
828 Standard_Integer i,j;
829 for (i = 1; i <= udegree+1; i++) {
830 for (j = 1; j <= vdegree+1; j++) {
831 IS >> poles(i,j);
832 if (urational || vrational)
71598a83 833 GeomTools::GetReal(IS, weights(i,j));
7fd59977 834 }
835 }
836
837 if (urational || vrational)
838 S = new Geom_BezierSurface(poles,weights);
839 else
840 S = new Geom_BezierSurface(poles);
841 return IS;
842}
843
844//=======================================================================
845//function : operator>>
846//purpose :
847//=======================================================================
848
849static Standard_IStream& operator>>(Standard_IStream& IS,
850 Handle(Geom_BSplineSurface)& S)
851{
852 Standard_Boolean urational=Standard_False, vrational=Standard_False,
853 uperiodic=Standard_False, vperiodic=Standard_False;
854 IS >> urational >> vrational;
855 IS >> uperiodic >> vperiodic;
856 Standard_Integer udegree=0, vdegree=0,nbupoles=0,nbvpoles=0,nbuknots=0,nbvknots=0;
857 IS >> udegree >> vdegree;
858 IS >> nbupoles >> nbvpoles;
859 IS >> nbuknots >> nbvknots;
860
861 TColgp_Array2OfPnt poles(1,nbupoles,1,nbvpoles);
862 TColStd_Array2OfReal weights(1,nbupoles,1,nbvpoles);
863
864 Standard_Integer i,j;
865 for (i = 1; i <= nbupoles; i++) {
866 for (j = 1; j <= nbvpoles; j++) {
867 IS >> poles(i,j);
868 if (urational || vrational)
71598a83 869 GeomTools::GetReal(IS, weights(i,j));
7fd59977 870 }
871 }
872
873 TColStd_Array1OfReal uknots(1,nbuknots);
874 TColStd_Array1OfInteger umults(1,nbuknots);
875 for (i = 1; i <= nbuknots; i++) {
71598a83 876 GeomTools::GetReal(IS, uknots(i));
877 IS >> umults(i);
7fd59977 878 }
879
880 TColStd_Array1OfReal vknots(1,nbvknots);
881 TColStd_Array1OfInteger vmults(1,nbvknots);
882 for (i = 1; i <= nbvknots; i++) {
71598a83 883 GeomTools::GetReal(IS, vknots(i));
884 IS >> vmults(i);
7fd59977 885 }
886
887 if (urational || vrational)
888 S = new Geom_BSplineSurface(poles,weights,uknots,vknots,umults,vmults,
889 udegree,vdegree,uperiodic,vperiodic);
890 else
891 S = new Geom_BSplineSurface(poles,uknots,vknots,umults,vmults,
892 udegree,vdegree,uperiodic,vperiodic);
893 return IS;
894}
895
896//=======================================================================
897//function : operator>>
898//purpose :
899//=======================================================================
900
901static Standard_IStream& operator>>(Standard_IStream& IS,
902 Handle(Geom_RectangularTrimmedSurface)& S)
903{
904 Standard_Real U1=0.,U2=0.,V1=0.,V2=0.;
71598a83 905 GeomTools::GetReal(IS, U1);
906 GeomTools::GetReal(IS, U2);
907 GeomTools::GetReal(IS, V1);
908 GeomTools::GetReal(IS, V2);
7fd59977 909 Handle(Geom_Surface) BS;
910 GeomTools_SurfaceSet::ReadSurface(IS,BS);
911 S = new Geom_RectangularTrimmedSurface(BS,U1,U2,V1,V2);
912 return IS;
913}
914
915//=======================================================================
916//function : operator>>
917//purpose :
918//=======================================================================
919
920static Standard_IStream& operator>>(Standard_IStream& IS,
921 Handle(Geom_OffsetSurface)& S)
922{
923 Standard_Real O=0.;
71598a83 924 GeomTools::GetReal(IS, O);
7fd59977 925 Handle(Geom_Surface) BS;
926 GeomTools_SurfaceSet::ReadSurface(IS,BS);
927 S = new Geom_OffsetSurface(BS,O);
928 return IS;
929}
930
931
932//=======================================================================
933//function : ReadSurface
934//purpose :
935//=======================================================================
936
937Standard_IStream& GeomTools_SurfaceSet::ReadSurface(Standard_IStream& IS,
938 Handle(Geom_Surface)& S)
939{
940 Standard_Integer stype;
941
942 try {
943 OCC_CATCH_SIGNALS
944 IS >> stype;
945 switch (stype) {
946
947 case PLANE :
948 {
949 Handle(Geom_Plane) SS;
950 IS >> SS;
951 S = SS;
952 }
953 break;
954
955 case CYLINDER :
956 {
957 Handle(Geom_CylindricalSurface) SS;
958 IS >> SS;
959 S = SS;
960 }
961 break;
962
963 case CONE :
964 {
965 Handle(Geom_ConicalSurface) SS;
966 IS >> SS;
967 S = SS;
968 }
969 break;
970
971 case SPHERE :
972 {
973 Handle(Geom_SphericalSurface) SS;
974 IS >> SS;
975 S = SS;
976 }
977 break;
978
979 case TORUS :
980 {
981 Handle(Geom_ToroidalSurface) SS;
982 IS >> SS;
983 S = SS;
984 }
985 break;
986
987 case LINEAREXTRUSION :
988 {
989 Handle(Geom_SurfaceOfLinearExtrusion) SS;
990 IS >> SS;
991 S = SS;
992 }
993 break;
994
995 case REVOLUTION :
996 {
997 Handle(Geom_SurfaceOfRevolution) SS;
998 IS >> SS;
999 S = SS;
1000 }
1001 break;
1002
1003 case BEZIER :
1004 {
1005 Handle(Geom_BezierSurface) SS;
1006 IS >> SS;
1007 S = SS;
1008 }
1009 break;
1010
1011 case BSPLINE :
1012 {
1013 Handle(Geom_BSplineSurface) SS;
1014 IS >> SS;
1015 S = SS;
1016 }
1017 break;
1018
1019 case RECTANGULAR :
1020 {
1021 Handle(Geom_RectangularTrimmedSurface) SS;
1022 IS >> SS;
1023 S = SS;
1024 }
1025 break;
1026
1027 case OFFSET :
1028 {
1029 Handle(Geom_OffsetSurface) SS;
1030 IS >> SS;
1031 S = SS;
1032 }
1033 break;
1034
1035 default :
1036 {
1037 Handle(Geom_Surface) SS;
1038 GeomTools::GetUndefinedTypeHandler()->ReadSurface(stype,IS,SS);
1039 S = SS;
1040 }
1041 break;
1042 }
1043 }
1044 catch(Standard_Failure) {
0797d9d3 1045#ifdef OCCT_DEBUG
7fd59977 1046 Handle(Standard_Failure) anExc = Standard_Failure::Caught();
1047 cout <<"EXCEPTION in GeomTools_SurfaceSet::ReadSurface(..)!!!" << endl;
1048 cout << anExc << endl;
1049#endif
1050 S = NULL;
1051 }
1052 return IS;
1053}
1054
1055//=======================================================================
1056//function : Read
1057//purpose :
1058//=======================================================================
1059
1060void GeomTools_SurfaceSet::Read(Standard_IStream& IS)
1061{
1062 char buffer[255];
1063 IS >> buffer;
1064 if (strcmp(buffer,"Surfaces")) {
1065 cout << "Not a surface table"<<endl;
1066 return;
1067 }
1068
1069 Handle(Geom_Surface) S;
1070 Standard_Integer i, nbsurf;
1071 IS >> nbsurf;
1072 //OCC19559
1073 Handle(Message_ProgressIndicator) progress = GetProgress();
1074 Message_ProgressSentry PS(progress, "Surfaces", 0, nbsurf, 1);
1075 for (i = 1; i <= nbsurf && PS.More(); i++, PS.Next()) {
7fd59977 1076 GeomTools_SurfaceSet::ReadSurface(IS,S);
1077 myMap.Add(S);
1078 }
1079}
1080
1081//=======================================================================
1082//function : GetProgress
1083//purpose :
1084//=======================================================================
1085
1086Handle(Message_ProgressIndicator) GeomTools_SurfaceSet::GetProgress() const
1087{
1088 return myProgress;
1089}
1090
1091//=======================================================================
1092//function : SetProgress
1093//purpose :
1094//=======================================================================
1095
1096void GeomTools_SurfaceSet::SetProgress(const Handle(Message_ProgressIndicator)& PR)
1097{
1098 myProgress = PR;
1099}
1100
1101
1102