0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / GeomTools / GeomTools_Curve2dSet.cxx
index a3feb3e..8115514 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <Standard_Stream.hxx>
-#include <GeomTools_Curve2dSet.ixx>
-#include <GeomTools.hxx>
-#include <GeomTools_UndefinedTypeHandler.hxx>
 
+#include <Geom2d_BezierCurve.hxx>
+#include <Geom2d_BSplineCurve.hxx>
 #include <Geom2d_Circle.hxx>
-#include <Geom2d_Line.hxx>
+#include <Geom2d_Curve.hxx>
 #include <Geom2d_Ellipse.hxx>
-#include <Geom2d_Parabola.hxx>
 #include <Geom2d_Hyperbola.hxx>
-#include <Geom2d_BezierCurve.hxx>
-#include <Geom2d_BSplineCurve.hxx>
-#include <Geom2d_TrimmedCurve.hxx>
+#include <Geom2d_Line.hxx>
 #include <Geom2d_OffsetCurve.hxx>
-
-#include <gp_Lin2d.hxx>
+#include <Geom2d_Parabola.hxx>
+#include <Geom2d_TrimmedCurve.hxx>
+#include <GeomTools.hxx>
+#include <GeomTools_Curve2dSet.hxx>
+#include <GeomTools_UndefinedTypeHandler.hxx>
 #include <gp_Circ2d.hxx>
 #include <gp_Elips2d.hxx>
-#include <gp_Parab2d.hxx>
 #include <gp_Hypr2d.hxx>
-
-#include <TColStd_Array1OfReal.hxx>
-#include <TColStd_Array1OfInteger.hxx>
-#include <TColgp_Array1OfPnt2d.hxx>
-#include <Standard_Failure.hxx>
-#include <Standard_ErrorHandler.hxx>
+#include <gp_Lin2d.hxx>
+#include <gp_Parab2d.hxx>
+#include <Message_ProgressIndicator.hxx>
 #include <Message_ProgressSentry.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <Standard_Failure.hxx>
+#include <Standard_OutOfRange.hxx>
+#include <Standard_Stream.hxx>
+#include <TColgp_Array1OfPnt2d.hxx>
+#include <TColStd_Array1OfInteger.hxx>
+#include <TColStd_Array1OfReal.hxx>
 
 #define LINE      1
 #define CIRCLE    2
@@ -308,7 +309,7 @@ static void Print(const Handle(Geom2d_BezierCurve)& B,
   OS << degree << " ";
   
   for (i = 1; i <= degree+1; i++) {
-    if (!compact) OS << "\n  "<<setw(2)<<i<<" : ";
+    if (!compact) OS << "\n  "<<std::setw(2)<<i<<" : ";
     Print(B->Pole(i),OS,compact);
     if (rational)
       OS << " " << B->Weight(i);
@@ -368,7 +369,7 @@ static void Print(const Handle(Geom2d_BSplineCurve)& B,
   
   if (!compact) OS << "Poles :\n";
   for (i = 1; i <= nbpoles; i++) {
-    if (!compact) OS << "\n  "<<setw(2)<<i<<" : ";
+    if (!compact) OS << "\n  "<<std::setw(2)<<i<<" : ";
     else OS << " ";
     Print(B->Pole(i),OS,compact);
     if (rational)
@@ -378,7 +379,7 @@ static void Print(const Handle(Geom2d_BSplineCurve)& B,
 
   if (!compact) OS << "Knots :\n";
   for (i = 1; i <= nbknots; i++) {
-    if (!compact) OS << "\n  "<<setw(2)<<i<<" : ";
+    if (!compact) OS << "\n  "<<std::setw(2)<<i<<" : ";
     else OS << " ";
     OS << B->Knot(i) << " " << B->Multiplicity(i);
   }
@@ -467,7 +468,7 @@ void GeomTools_Curve2dSet::PrintCurve2d(const Handle(Geom2d_Curve)& C,
     //if (!compact)
     //  OS << "****** UNKNOWN CURVE2d TYPE ******\n";
     //else 
-    //  cout << "****** UNKNOWN CURVE2d TYPE ******" << endl;
+    //  std::cout << "****** UNKNOWN CURVE2d TYPE ******" << std::endl;
   }
 }
 
@@ -484,7 +485,7 @@ void  GeomTools_Curve2dSet::Dump(Standard_OStream& OS)const
   OS << "\n -------\n\n";
 
   for (i = 1; i <= nbsurf; i++) {
-    OS << setw(4) << i << " : ";
+    OS << std::setw(4) << i << " : ";
     PrintCurve2d(Handle(Geom2d_Curve)::DownCast(myMap(i)),OS,Standard_False);
   }
 }
@@ -504,13 +505,9 @@ void  GeomTools_Curve2dSet::Write(Standard_OStream& OS)const
   //OCC19559
   Handle(Message_ProgressIndicator) progress = GetProgress();
   Message_ProgressSentry PS(progress, "2D Curves", 0, nbsurf, 1);
-
   for (i = 1; i <= nbsurf && PS.More(); i++, PS.Next()) {
-    if ( !myProgress.IsNull() ) 
-      progress->Show();
     PrintCurve2d(Handle(Geom2d_Curve)::DownCast(myMap(i)),OS,Standard_True);
   }
-
   OS.precision(prec);
 }
 
@@ -523,7 +520,8 @@ void  GeomTools_Curve2dSet::Write(Standard_OStream& OS)const
 static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt2d& P)
 {
   Standard_Real X=0.,Y=0.;
-  IS >> X >> Y;
+  GeomTools::GetReal(IS, X);
+  GeomTools::GetReal(IS, Y);
   P.SetCoord(X,Y);
   return IS;
 }
@@ -536,7 +534,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS, gp_Pnt2d& P)
 static Standard_IStream& operator>>(Standard_IStream& IS, gp_Dir2d& D)
 {
   Standard_Real X=0.,Y=0.;
-  IS >> X >> Y;
+  GeomTools::GetReal(IS, X);
+  GeomTools::GetReal(IS, Y);
   D.SetCoord(X,Y);
   return IS;
 }
@@ -568,7 +567,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS,
   gp_Pnt2d P(0.,0.);
   gp_Dir2d AX(1.,0.),AY(1.,0.);
   Standard_Real R=0.;
-  IS >> P >> AX >> AY >> R;
+  IS >> P >> AX >> AY;
+  GeomTools::GetReal(IS, R);
   C = new Geom2d_Circle(gp_Ax22d(P,AX,AY),R);
   return IS;
 }
@@ -584,7 +584,9 @@ static Standard_IStream& operator>>(Standard_IStream& IS,
   gp_Pnt2d P(0.,0.);
   gp_Dir2d AX(1.,0.),AY(1.,0.);
   Standard_Real R1=0.,R2=0.;
-  IS >> P >> AX >> AY >> R1 >> R2;
+  IS >> P >> AX >> AY;
+  GeomTools::GetReal(IS, R1);
+  GeomTools::GetReal(IS, R2);
   E = new Geom2d_Ellipse(gp_Ax22d(P,AX,AY),R1,R2);
   return IS;
 }
@@ -600,7 +602,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS,
   gp_Pnt2d P(0.,0.);
   gp_Dir2d AX(1.,0.),AY(1.,0.);
   Standard_Real R1=0.;
-  IS >> P >> AX >> AY >> R1;
+  IS >> P >> AX >> AY;
+  GeomTools::GetReal(IS, R1);
   C = new Geom2d_Parabola(gp_Ax22d(P,AX,AY),R1);
   return IS;
 }
@@ -616,7 +619,9 @@ static Standard_IStream& operator>>(Standard_IStream& IS,
   gp_Pnt2d P(0.,0.);
   gp_Dir2d AX(1.,0.),AY(1.,0.);
   Standard_Real R1=0.,R2=0.;
-  IS >> P >> AX >> AY >> R1 >> R2;
+  IS >> P >> AX >> AY;
+  GeomTools::GetReal(IS, R1);
+  GeomTools::GetReal(IS, R2);
   H = new Geom2d_Hyperbola(gp_Ax22d(P,AX,AY),R1,R2);
   return IS;
 }
@@ -642,7 +647,7 @@ static Standard_IStream& operator>>(Standard_IStream& IS,
   for (i = 1; i <= degree+1; i++) {
     IS >> poles(i);
     if (rational)
-      IS >> weights(i);
+      GeomTools::GetReal(IS, weights(i));
   }
 
   if (rational)
@@ -674,14 +679,15 @@ static Standard_IStream& operator>>(Standard_IStream& IS,
   for (i = 1; i <= nbpoles; i++) {
     IS >> poles(i);
     if (rational)
-      IS >> weights(i);
+      GeomTools::GetReal(IS, weights(i));
   }
 
   TColStd_Array1OfReal knots(1,nbknots);
   TColStd_Array1OfInteger mults(1,nbknots);
 
   for (i = 1; i <= nbknots; i++) {
-    IS >> knots(i) >> mults(i);
+    GeomTools::GetReal(IS, knots(i)); 
+    IS >> mults(i);
   }
 
   if (rational)
@@ -701,9 +707,9 @@ static Standard_IStream& operator>>(Standard_IStream& IS,
                                    Handle(Geom2d_TrimmedCurve)& C)
 {
   Standard_Real p1=0.,p2=0.;
-  IS >> p1 >> p2;
-  Handle(Geom2d_Curve) BC;
-  GeomTools_Curve2dSet::ReadCurve2d(IS,BC);
+  GeomTools::GetReal(IS, p1);
+  GeomTools::GetReal(IS, p2);
+  Handle(Geom2d_Curve) BC = GeomTools_Curve2dSet::ReadCurve2d(IS);
   C = new Geom2d_TrimmedCurve(BC,p1,p2);
   return IS;
 }
@@ -717,9 +723,8 @@ static Standard_IStream& operator>>(Standard_IStream& IS,
                                    Handle(Geom2d_OffsetCurve)& C)
 {
   Standard_Real p=0.;
-  IS >> p;
-  Handle(Geom2d_Curve) BC;
-  GeomTools_Curve2dSet::ReadCurve2d(IS,BC);
+  GeomTools::GetReal(IS, p);
+  Handle(Geom2d_Curve) BC = GeomTools_Curve2dSet::ReadCurve2d(IS);
   C = new Geom2d_OffsetCurve(BC,p);
   return IS;
 }
@@ -729,11 +734,11 @@ static Standard_IStream& operator>>(Standard_IStream& IS,
 //purpose  : 
 //=======================================================================
 
-Standard_IStream& GeomTools_Curve2dSet::ReadCurve2d(Standard_IStream& IS,
-                                                   Handle(Geom2d_Curve)& C)
+Handle(Geom2d_Curve) GeomTools_Curve2dSet::ReadCurve2d(Standard_IStream& IS)
 {
   Standard_Integer ctype;
 
+  Handle(Geom2d_Curve) C;
   try {
     OCC_CATCH_SIGNALS
     IS >> ctype;
@@ -820,15 +825,14 @@ Standard_IStream& GeomTools_Curve2dSet::ReadCurve2d(Standard_IStream& IS,
       break;
     }
   }
-  catch(Standard_Failure) {
-#ifdef DEB
-    Handle(Standard_Failure) anExc = Standard_Failure::Caught();
-    cout <<"EXCEPTION in GeomTools_Curve2dSet::ReadCurve2d(..)!!!" << endl;
-    cout << anExc << endl;
+  catch(Standard_Failure const& anException) {
+#ifdef OCCT_DEBUG
+    std::cout <<"EXCEPTION in GeomTools_Curve2dSet::ReadCurve2d(..)!!!" << std::endl;
+    std::cout << anException << std::endl;
 #endif
-    C = NULL;
+    (void)anException;
   }
-  return IS;
+  return C;
 }
 
 //=======================================================================
@@ -841,22 +845,17 @@ void  GeomTools_Curve2dSet::Read(Standard_IStream& IS)
   char buffer[255];
   IS >> buffer;
   if (strcmp(buffer,"Curve2ds")) {
-    cout << "Not a Curve2d table"<<endl;
+    std::cout << "Not a Curve2d table"<<std::endl;
     return;
   }
 
-  Handle(Geom2d_Curve) C;
   Standard_Integer i, nbcurve;
   IS >> nbcurve;
   //OCC19559
   Handle(Message_ProgressIndicator) progress = GetProgress();
   Message_ProgressSentry PS(progress, "2D Curves", 0, nbcurve, 1);
-
   for (i = 1; i <= nbcurve && PS.More(); i++, PS.Next()) {
-    if ( !myProgress.IsNull() ) 
-      progress->Show();
-    
-    GeomTools_Curve2dSet::ReadCurve2d(IS,C);
+    Handle(Geom2d_Curve) C = GeomTools_Curve2dSet::ReadCurve2d (IS);
     myMap.Add(C);
   }
 }