0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / ShapeConstruct / ShapeConstruct.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 43aa941..b8b6b1f
@@ -1,49 +1,68 @@
-// File:       ShapeConstruct.cxx
-// Created:    Thu Jun 17 16:21:27 1999
-// Author:     data exchange team
-//             <det@lenox>
+// Created on: 1999-06-17
+// Created by: data exchange team
+// Copyright (c) 1999-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// 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 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,
@@ -60,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 
+    catch (Standard_Failure const& anException) {
+#ifdef OCCT_DEBUG
            cout << "Warning: GeomConvert_ApproxSurface Exception:  ";
-           Standard_Failure::Caught()->Print(cout); cout << endl;
+           anException.Print(cout); cout << endl;
 #endif 
+           (void)anException;
            aBSpline = GeomConvert::CurveToBSplineCurve(C3D,Convert_QuasiAngular);    
          }
   }
@@ -95,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);
   } 
@@ -201,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
+#ifdef OCCT_DEBUG
       cout <<" Revolution on offset converted" << 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 {
@@ -218,7 +238,7 @@ 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;
@@ -229,19 +249,20 @@ Handle(Geom_BSplineSurface) ShapeConstruct::ConvertSurfaceToBSpline(const Handle
       }
       else {
        if(anApprox.HasResult()) 
-         errSpl = Handle(Geom_BSplineSurface)::DownCast(anApprox.Surface());
-#ifdef DEB    
+         errSpl = anApprox.Surface();
+#ifdef OCCT_DEBUG
        cout << "\terror = " << anApprox.MaxError() <<endl;
 #endif
        break;
       }
     }
        
-    catch (Standard_Failure) {
-#ifdef DEB 
+    catch (Standard_Failure const& anException) {
+#ifdef OCCT_DEBUG
       cout << "Warning: GeomConvert_ApproxSurface Exception: try to decrease continuity ";
-      Standard_Failure::Caught()->Print(cout); cout << endl;
+      anException.Print(cout); cout << endl;
 #endif
+      (void)anException;
       if(cnt > 0) cnt--;
       continue;
     }
@@ -277,7 +298,7 @@ Standard_Boolean ShapeConstruct::JoinPCurves(const Handle(TopTools_HSequenceOfSh
     Standard_Boolean IsEdgeSeam = Standard_False;
     Handle(Geom2d_Curve) aCrvRes1, aCrvRes2;
     TopAbs_Orientation resOrient;
-    Standard_Real newf,newl;
+    Standard_Real newf = 0.,newl = 0.;
     // iterates on edges
     Standard_Integer i = 1;
     for(; i <= edges->Length(); i++) {
@@ -341,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 
+  catch ( Standard_Failure const& anException) {
+#ifdef OCCT_DEBUG
     cout<<"Error: ShapeConstruct::JoinPCurves Exception in GeomConvert_CompCurveToBSplineCurve: ";
-    Standard_Failure::Caught()->Print(cout); cout<<endl;
+    anException.Print(cout); cout<<endl;
 #endif
+    (void)anException;
   }
   return Standard_False;
 }