0027232: Configuration - fix mblen missing building issue on Android
[occt.git] / src / BRepFill / BRepFill_Generator.cxx
old mode 100755 (executable)
new mode 100644 (file)
index e660d66..6e70529
@@ -1,79 +1,71 @@
 // Created on: 1994-03-07
 // Created by: Bruno DUMORTIER
 // Copyright (c) 1994-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// 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.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 
-#include <BRepFill_Generator.ixx>
-
-#include <TopoDS_Face.hxx>
-#include <TopoDS_Wire.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Vertex.hxx>
 #include <BRep_Builder.hxx>
-#include <TopLoc_Location.hxx>
-#include <TopExp_Explorer.hxx>
-#include <gp_Pnt2d.hxx>
-#include <gp_Dir2d.hxx>
-#include <gp_Ax1.hxx>
-#include <gp_Ax3.hxx>
-#include <gp_Circ.hxx>
-#include <gp_Lin.hxx>
-#include <GeomAbs_Shape.hxx>
-#include <GeomAdaptor_Curve.hxx>
+#include <BRep_Tool.hxx>
+#include <BRepFill_Generator.hxx>
+#include <BRepLib.hxx>
+#include <BRepTools.hxx>
+#include <BRepTools_WireExplorer.hxx>
+#include <Geom2d_BezierCurve.hxx>
+#include <Geom2d_Line.hxx>
+#include <Geom_BezierCurve.hxx>
+#include <Geom_BSplineCurve.hxx>
 #include <Geom_Circle.hxx>
-#include <Geom_Line.hxx>
+#include <Geom_ConicalSurface.hxx>
 #include <Geom_Curve.hxx>
-#include <Geom_BezierCurve.hxx>
-#include <Geom_TrimmedCurve.hxx>
-#include <Geom_Surface.hxx>
-#include <Geom_Plane.hxx>
 #include <Geom_CylindricalSurface.hxx>
-#include <Geom_ConicalSurface.hxx>
+#include <Geom_Line.hxx>
+#include <Geom_Plane.hxx>
 #include <Geom_RectangularTrimmedSurface.hxx>
-#include <Geom2d_Line.hxx>
-#include <Geom2d_BezierCurve.hxx>
-#include <GeomFill_Generator.hxx>
-
-#include <TopTools_DataMapOfShapeShape.hxx>
+#include <Geom_Surface.hxx>
+#include <Geom_TrimmedCurve.hxx>
+#include <GeomAbs_Shape.hxx>
+#include <GeomAdaptor_Curve.hxx>
+#include <GeomConvert.hxx>
 #include <GeomFill.hxx>
-#include <BRep_Tool.hxx>
-#include <TopoDS.hxx>
-#include <TopExp.hxx>
-#include <Precision.hxx>
-#include <BRepLib.hxx>
-
-#include <TColgp_Array1OfPnt.hxx> 
-#include <TColgp_Array1OfPnt2d.hxx> 
-#include <Geom_BSplineCurve.hxx> 
+#include <GeomFill_Generator.hxx>
+#include <gp_Ax1.hxx>
+#include <gp_Ax3.hxx>
+#include <gp_Circ.hxx>
+#include <gp_Dir2d.hxx>
+#include <gp_Lin.hxx>
+#include <gp_Pnt2d.hxx>
 #include <gp_Vec.hxx>
-#include <GeomConvert.hxx>
-
-#include <BRepTools_WireExplorer.hxx>
-#include <BRepTools.hxx>
-
-
+#include <Precision.hxx>
+#include <Standard_NullObject.hxx>
+#include <TColgp_Array1OfPnt.hxx>
+#include <TColgp_Array1OfPnt2d.hxx>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopLoc_Location.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Shell.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopTools_DataMapOfShapeShape.hxx>
 
 //=======================================================================
 //function : DetectKPart
 //purpose  : 
 //=======================================================================
-
 Standard_Integer DetectKPart(const TopoDS_Edge& Edge1,
                             const TopoDS_Edge& Edge2)
 {
@@ -81,7 +73,7 @@ Standard_Integer DetectKPart(const TopoDS_Edge& Edge1,
   Standard_Integer IType = 0;
 
   // characteristics of the first edge
-  Standard_Real first1, last1, first2, last2, ff, ll;
+  Standard_Real first1 = 0., last1 = 0., first2, last2, ff, ll;
   TopLoc_Location loc;
   TopoDS_Vertex V1, V2;
   Handle(Geom_Curve) curv1, curv;
@@ -101,6 +93,8 @@ Standard_Integer DetectKPart(const TopoDS_Edge& Edge1,
   }
   else {
     curv1 = BRep_Tool::Curve(Edge1, loc, first1, last1);
+    if (curv1.IsNull())
+      Standard_NullObject::Raise("Null 3D curve in edge");
     curv1 = 
       Handle(Geom_Curve)::DownCast(curv1->Transformed(loc.Transformation()));
     ff = first1;
@@ -166,6 +160,8 @@ Standard_Integer DetectKPart(const TopoDS_Edge& Edge1,
     }
     else {
       curv = BRep_Tool::Curve(Edge2, loc, first2, last2);
+      if (curv.IsNull())
+        Standard_NullObject::Raise("Null 3D curve in edge");
       curv = 
        Handle(Geom_Curve)::DownCast(curv->Transformed(loc.Transformation()));
       ff = first2;
@@ -255,8 +251,8 @@ Standard_Integer DetectKPart(const TopoDS_Edge& Edge1,
          pos = AdC.Line().Location();
          dist = AdC.Value(first2).Distance(AdC.Value(last2));
          gp_Vec vec(AdC.Value(first2),AdC.Value(last2));
-         gp_Dir dir(vec);
-         axe = gp_Ax1(AdC.Value(first2),dir);
+         gp_Dir aDir(vec);
+         axe = gp_Ax1(AdC.Value(first2), aDir);
          if (axe.IsParallel(axe1,Precision::Angular())) {
            // parallel straight line
            if (Abs(dist-dist1)<Precision::Confusion()) {
@@ -344,6 +340,8 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
   }
   else {
     C1 = BRep_Tool::Curve(Edge1, loc, a1, b1);
+    if (C1.IsNull())
+      Standard_NullObject::Raise("Null 3D curve in edge");
     C1 = Handle(Geom_Curve)::DownCast(C1->Transformed(loc.Transformation()));
     aa = a1;
     bb = b1;
@@ -367,6 +365,8 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
   }
   else {
     C2 = BRep_Tool::Curve(Edge2, loc, a1, b1);
+    if (C2.IsNull())
+      Standard_NullObject::Raise("Null 3D curve in edge");
     C2 = Handle(Geom_Curve)::DownCast(C2->Transformed(loc.Transformation()));
     if (Edge2.Orientation() == TopAbs_REVERSED) {
       C2->Reverse();
@@ -386,27 +386,29 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
   }
 
   // create the new surface
-  TopoDS_Shell shell;
   TopoDS_Face face;
   TopoDS_Wire W;
   TopoDS_Edge edge1, edge2, edge3, edge4, couture;
 
-  BRep_Builder B;
-  B.MakeShell(shell);
-
   TopoDS_Wire newW1, newW2;
   BRep_Builder BW1, BW2;
   BW1.MakeWire(newW1);
   BW2.MakeWire(newW2);
 
+  GeomAdaptor_Curve aC1Adaptor;
+  if (!C1.IsNull())
+    aC1Adaptor.Load(C1);
+  GeomAdaptor_Curve aC2Adaptor;
+  if (!C2.IsNull())
+    aC2Adaptor.Load(C2);
 
   // calculate the surface
   Handle(Geom_Surface) surface;
   Standard_Real V, Rad;
   if (IType==1) {
     // cylindrical surface
-    gp_Circ c1 = (Handle(Geom_Circle)::DownCast(C1))->Circ();
-    gp_Circ c2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
+    gp_Circ c1 = aC1Adaptor.Circle();
+    gp_Circ c2 = aC2Adaptor.Circle();
     gp_Ax3 Ac1 = c1.Position();
     V = gp_Vec( c1.Location(),c2.Location()).Dot(gp_Vec(Ac1.Direction()));
     if ( V < 0.) {
@@ -420,7 +422,7 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
   }
   else if (IType==2) {
     // conical surface
-    gp_Circ k1 = (Handle(Geom_Circle)::DownCast(C1))->Circ();
+    gp_Circ k1 = aC1Adaptor.Circle();
     gp_Ax3 Ak1 = k1.Position();
     if (degen2) {
       V = gp_Vec( k1.Location(),BRep_Tool::Pnt(v2f))
@@ -428,7 +430,7 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
       Rad = - k1.Radius();
     }
     else {
-      gp_Circ k2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
+      gp_Circ k2 = aC2Adaptor.Circle();
       V = gp_Vec( k1.Location(),k2.Location()).Dot(gp_Vec(Ak1.Direction()));
       Rad = k2.Radius() - k1.Radius();
     }
@@ -446,7 +448,7 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
   }
   else if (IType==-2) {
     // conical surface with the top at the beginning (degen1 is true)
-    gp_Circ k2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
+    gp_Circ k2 = aC2Adaptor.Circle();
     gp_Ax3 Ak2 = k2.Position();
     Ak2.SetLocation(BRep_Tool::Pnt(v1f));
     V = gp_Vec(BRep_Tool::Pnt(v1f),k2.Location())
@@ -470,15 +472,15 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
     // surface plane
     gp_Lin L1, L2, aLine;
     if (!degen1)
-      {
-       L1 = (Handle(Geom_Line)::DownCast(C1))->Lin();
-       aLine = L1;
-      }
+    {
+      L1 = aC1Adaptor.Line();
+      aLine = L1;
+    }
     if (!degen2)
-      {
-       L2 = (Handle(Geom_Line)::DownCast(C2))->Lin();
-       aLine = L2;
-      }
+    {
+      L2 = aC2Adaptor.Line();
+      aLine = L2;
+    }
 
     gp_Pnt P1 = (degen1)? BRep_Tool::Pnt(v1f) : L1.Location();
     gp_Pnt P2 = (degen2)? BRep_Tool::Pnt(v2f) : L2.Location();
@@ -542,7 +544,7 @@ void BRepFill_Generator::Perform()
 
   BRepTools_WireExplorer ex1,ex2;
 
-  Standard_Boolean wPoint1, wPoint2, uClosed, DegenFirst, DegenLast;
+  Standard_Boolean wPoint1, wPoint2, uClosed = Standard_False, DegenFirst = Standard_False, DegenLast = Standard_False;
   
   for ( Standard_Integer i = 1; i <= Nb-1; i++) {
 
@@ -621,8 +623,8 @@ void BRepFill_Generator::Perform()
        Edge2 = TopoDS::Edge(ex2.Current());
       }
 
-      Standard_Boolean Periodic
-       = (Edge1.Closed() || degen1) && (Edge2.Closed() || degen2);
+      Standard_Boolean Periodic = (BRep_Tool::IsClosed(Edge1) || degen1) &&
+                                  (BRep_Tool::IsClosed(Edge2) || degen2);
       // ATTENTION : a non-punctual wire should not 
       //             contain a punctual edge
       if (!wPoint1) ex1.Next();
@@ -649,13 +651,7 @@ void BRepFill_Generator::Perform()
          Vf_toMap = V1f;
          Vl_toMap = V1l;
        }
-      
-      if(Periodic) {
-       Standard_Boolean E1IsReallyClosed = BRepTools::Compare(V1f,V1l);
-       Standard_Boolean E2IsReallyClosed = BRepTools::Compare(V2f,V2l);
-       Periodic 
-         = (E1IsReallyClosed || degen1) && (E2IsReallyClosed || degen2);
-      }
+
       // processing of KPart
       Standard_Integer IType = DetectKPart(Edge1,Edge2);
       if (IType==0) {
@@ -672,6 +668,8 @@ void BRepFill_Generator::Perform()
        }
        else {
          C1 = BRep_Tool::Curve(Edge1,L1,f1,l1);
+          if (C1.IsNull())
+            Standard_NullObject::Raise("Null 3D curve in edge");
        }
        if (degen2) {
          Extremities(1) = BRep_Tool::Pnt(V2l);
@@ -680,6 +678,8 @@ void BRepFill_Generator::Perform()
        }
        else {
          C2 = BRep_Tool::Curve(Edge2,L2,f2,l2);
+          if (C2.IsNull())
+            Standard_NullObject::Raise("Null 3D curve in edge");
        }
        
        // compute the location