0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / ShapeConstruct / ShapeConstruct.cxx
index 8a139b2..ca873ab 100644 (file)
@@ -5,8 +5,8 @@
 //
 // This file is part of Open CASCADE Technology software library.
 //
-// This library is free software; you can redistribute it and / or modify it
-// under the terms of the GNU Lesser General Public version 2.1 as published
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
 // by the Free Software Foundation, with special exception defined in the file
 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
 // distribution for complete text of the license and disclaimer of any warranty.
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <ShapeConstruct.ixx>
-#include <Standard_Failure.hxx>
-#include <Standard_ErrorHandler.hxx>
-#include <Geom_Conic.hxx>
-#include <Geom_TrimmedCurve.hxx>
-#include <GeomConvert_ApproxCurve.hxx>
-#include <GeomConvert.hxx>
+
+#include <BRep_Builder.hxx>
+#include <BRep_Tool.hxx>
+#include <Geom2d_BSplineCurve.hxx>
 #include <Geom2d_Conic.hxx>
+#include <Geom2d_Curve.hxx>
 #include <Geom2d_TrimmedCurve.hxx>
-#include <Geom2dConvert_ApproxCurve.hxx>
 #include <Geom2dConvert.hxx>
+#include <Geom2dConvert_ApproxCurve.hxx>
+#include <Geom_BSplineCurve.hxx>
+#include <Geom_BSplineSurface.hxx>
+#include <Geom_Conic.hxx>
+#include <Geom_Curve.hxx>
+#include <Geom_ElementarySurface.hxx>
+#include <Geom_OffsetCurve.hxx>
+#include <Geom_Plane.hxx>
 #include <Geom_RectangularTrimmedSurface.hxx>
+#include <Geom_Surface.hxx>
 #include <Geom_SurfaceOfLinearExtrusion.hxx>
-#include <TColgp_Array1OfPnt.hxx>
-#include <TColStd_Array1OfReal.hxx>
-#include <TColStd_Array1OfInteger.hxx>
-#include <TColgp_Array2OfPnt.hxx>
-#include <TColStd_Array2OfReal.hxx>
-#include <GeomConvert_ApproxSurface.hxx>
 #include <Geom_SurfaceOfRevolution.hxx>
-#include <Geom_OffsetCurve.hxx>
-#include <ShapeConstruct_Curve.hxx>
-#include <Precision.hxx>
+#include <Geom_TrimmedCurve.hxx>
+#include <GeomAPI.hxx>
+#include <GeomConvert.hxx>
+#include <GeomConvert_ApproxCurve.hxx>
+#include <GeomConvert_ApproxSurface.hxx>
 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
 #include <gp_Pln.hxx>
 #include <gp_Vec.hxx>
-#include <GeomAPI.hxx>
-#include <TopTools_HSequenceOfShape.hxx>
+#include <Precision.hxx>
 #include <ShapeAnalysis_Edge.hxx>
-#include <BRep_Builder.hxx>
-#include <BRep_Tool.hxx>
-#include <Geom_Plane.hxx>
+#include <ShapeConstruct.hxx>
+#include <ShapeConstruct_Curve.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <Standard_Failure.hxx>
+#include <TColgp_Array1OfPnt.hxx>
+#include <TColgp_Array2OfPnt.hxx>
+#include <TColStd_Array1OfInteger.hxx>
+#include <TColStd_Array1OfReal.hxx>
+#include <TColStd_Array2OfReal.hxx>
 #include <TopAbs_Orientation.hxx>
 #include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopTools_HSequenceOfShape.hxx>
 
 //=======================================================================
 //function : ConvertCurveToBSpline
 //purpose  : 
 //=======================================================================
-
 Handle(Geom_BSplineCurve) ShapeConstruct::ConvertCurveToBSpline(const Handle(Geom_Curve)& C3D,
                                                                const Standard_Real First,
                                                                const Standard_Real Last,
@@ -70,20 +79,21 @@ Handle(Geom_BSplineCurve) ShapeConstruct::ConvertCurveToBSpline(const Handle(Geo
     if(C3D->IsKind(STANDARD_TYPE(Geom_Conic))) 
       MaxDeg = Min(MaxDeg,6);
  
-    Handle(Geom_TrimmedCurve) tcurve = new Geom_TrimmedCurve(C3D,First,Last); //protection agains parabols ets
+    Handle(Geom_Curve) tcurve = new Geom_TrimmedCurve(C3D,First,Last); //protection agains parabols ets
     try {
       OCC_CATCH_SIGNALS
       GeomConvert_ApproxCurve approx (tcurve, Tol3d, Continuity, MaxSegments, MaxDeg);
       if ( approx.HasResult() )
-       aBSpline = Handle(Geom_BSplineCurve)::DownCast(approx.Curve());
+       aBSpline = approx.Curve();
       else
        aBSpline = GeomConvert::CurveToBSplineCurve(C3D,Convert_QuasiAngular);
     }
-    catch (Standard_Failure) {
-#ifdef DEB 
-           cout << "Warning: GeomConvert_ApproxSurface Exception:  ";
-           Standard_Failure::Caught()->Print(cout); cout << endl;
+    catch (Standard_Failure const& anException) {
+#ifdef OCCT_DEBUG
+           std::cout << "Warning: GeomConvert_ApproxSurface Exception:  ";
+           anException.Print(std::cout); std::cout << std::endl;
 #endif 
+           (void)anException;
            aBSpline = GeomConvert::CurveToBSplineCurve(C3D,Convert_QuasiAngular);    
          }
   }
@@ -105,10 +115,10 @@ Handle(Geom2d_BSplineCurve) ShapeConstruct::ConvertCurveToBSpline(const Handle(G
 {
   Handle(Geom2d_BSplineCurve) aBSpline2d;
   if(C2D->IsKind(STANDARD_TYPE(Geom2d_Conic))) {
-    Handle(Geom2d_TrimmedCurve) tcurve = new Geom2d_TrimmedCurve(C2D,First,Last); //protection agains parabols ets
+    Handle(Geom2d_Curve) tcurve = new Geom2d_TrimmedCurve(C2D,First,Last); //protection agains parabols ets
     Geom2dConvert_ApproxCurve approx (tcurve, Tol2d, Continuity, MaxSegments, MaxDegree);
     if ( approx.HasResult() )
-      aBSpline2d = Handle(Geom2d_BSplineCurve)::DownCast(approx.Curve());
+      aBSpline2d = approx.Curve();
     else 
       aBSpline2d = Geom2dConvert::CurveToBSplineCurve(tcurve,Convert_QuasiAngular);
   } 
@@ -211,14 +221,14 @@ Handle(Geom_BSplineSurface) ShapeConstruct::ConvertSurfaceToBSpline(const Handle
       Handle(Geom_BSplineCurve) bspl = ConvertCurveToBSpline(basis, VF, VL, Tol3d, cnt, MaxSegments, MaxDegree);
       gp_Ax1 axis = revol->Axis();
       Handle(Geom_SurfaceOfRevolution) newRevol = new Geom_SurfaceOfRevolution(bspl,axis);
-#ifdef DEB
-      cout <<" Revolution on offset converted" << endl;
+#ifdef OCCT_DEBUG
+      std::cout <<" Revolution on offset converted" << std::endl;
 #endif
       S = newRevol;
     }
   }
     
-  Handle(Geom_RectangularTrimmedSurface) aSurface = new Geom_RectangularTrimmedSurface(S,UF,UL,VF,VL);
+  Handle(Geom_Surface) aSurface = new Geom_RectangularTrimmedSurface(S,UF,UL,VF,VL);
   Handle(Geom_BSplineSurface) errSpl;
   for(Standard_Integer cnt = (Continuity > GeomAbs_C3 ? GeomAbs_C3: Continuity); cnt >= 0 ; ) {
     try {
@@ -228,10 +238,10 @@ Handle(Geom_BSplineSurface) ShapeConstruct::ConvertSurfaceToBSpline(const Handle
       Standard_Boolean Done = anApprox.IsDone();
       if (anApprox.MaxError() <= Tol3d && Done) {
        
-#ifdef DEB         
+#ifdef OCCT_DEBUG
        Standard_Integer nbOfSpan = (anApprox.Surface()->NbUKnots()-1)*(anApprox.Surface()->NbVKnots()-1);
-       cout << "\terror = " << anApprox.MaxError() << "\tspans = " << nbOfSpan << endl;
-       cout << " Surface is aproximated with continuity " << (GeomAbs_Shape)cnt <<endl;
+       std::cout << "\terror = " << anApprox.MaxError() << "\tspans = " << nbOfSpan << std::endl;
+       std::cout << " Surface is aproximated with continuity " << (GeomAbs_Shape)cnt <<std::endl;
 #endif
        S = anApprox.Surface();
        Handle(Geom_BSplineSurface) Bsc = Handle(Geom_BSplineSurface)::DownCast(S);
@@ -239,19 +249,20 @@ Handle(Geom_BSplineSurface) ShapeConstruct::ConvertSurfaceToBSpline(const Handle
       }
       else {
        if(anApprox.HasResult()) 
-         errSpl = Handle(Geom_BSplineSurface)::DownCast(anApprox.Surface());
-#ifdef DEB    
-       cout << "\terror = " << anApprox.MaxError() <<endl;
+         errSpl = anApprox.Surface();
+#ifdef OCCT_DEBUG
+       std::cout << "\terror = " << anApprox.MaxError() <<std::endl;
 #endif
        break;
       }
     }
        
-    catch (Standard_Failure) {
-#ifdef DEB 
-      cout << "Warning: GeomConvert_ApproxSurface Exception: try to decrease continuity ";
-      Standard_Failure::Caught()->Print(cout); cout << endl;
+    catch (Standard_Failure const& anException) {
+#ifdef OCCT_DEBUG
+      std::cout << "Warning: GeomConvert_ApproxSurface Exception: try to decrease continuity ";
+      anException.Print(std::cout); std::cout << std::endl;
 #endif
+      (void)anException;
       if(cnt > 0) cnt--;
       continue;
     }
@@ -351,11 +362,12 @@ Standard_Boolean ShapeConstruct::JoinPCurves(const Handle(TopTools_HSequenceOfSh
     B.SameParameter(theEdge,Standard_False);
     return (i <= edges->Length());
   }
-  catch ( Standard_Failure ) {
-#ifdef DEB 
-    cout<<"Error: ShapeConstruct::JoinPCurves Exception in GeomConvert_CompCurveToBSplineCurve: ";
-    Standard_Failure::Caught()->Print(cout); cout<<endl;
+  catch ( Standard_Failure const& anException) {
+#ifdef OCCT_DEBUG
+    std::cout<<"Error: ShapeConstruct::JoinPCurves Exception in GeomConvert_CompCurveToBSplineCurve: ";
+    anException.Print(std::cout); std::cout<<std::endl;
 #endif
+    (void)anException;
   }
   return Standard_False;
 }