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