Salome HOME
Merge commit '4823245056426a9ccf9c7965daecf11459f58af5' into V9_11_BR
[modules/geom.git] / src / ShHealOper / ShHealOper_FillHoles.cxx
index 8e8eb61c003aac1288505535dd09752fc5d0c840..c8e7a5cb264a5e3c2cc98ef70773b4cf70026bd5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 // Created:   26.04.04 17:35:30
 // Author:    Galina KULIKOVA
 
-#include <Basics_OCCTVersion.hxx>
-
 #include <ShapeFix_Shell.hxx>
 #include <ShapeFix_Face.hxx>
 #include <ShHealOper_FillHoles.hxx>
 #include <ShapeAnalysis_FreeBounds.hxx>
 
+#include <Basics_OCCTVersion.hxx>
+
 #include <BRep_Tool.hxx>
 #include <BRepAdaptor_Curve.hxx>
+#if OCC_VERSION_LARGE < 0x07070000
 #include <BRepAdaptor_HCurve.hxx>
+#endif
 #include <BRep_Builder.hxx>
 #include <BRepFill_CurveConstraint.hxx>
 #include <BRepBuilderAPI_MakeFace.hxx>
@@ -186,7 +188,10 @@ Standard_Boolean ShHealOper_FillHoles::Fill(const TopTools_SequenceOfShape& theF
       myDone = (addFace(aSurf,aWire,aCurves2d,aOrders,aSenses) || myDone);
   }
   if(myDone)
+  {
     myResultShape = myContext->Apply(myResultShape);
+    myStatistics.AddModif( "Face created to fill hole" , aSeqWires->Length() );
+  }
   return myDone;
 }
 
@@ -229,7 +234,7 @@ Standard_Boolean ShHealOper_FillHoles::prepareWires(const TopTools_SequenceOfSha
       if (!BRep_Tool::Degenerated (TopoDS::Edge (aExp.Current())))
         if(myEdgeFaces.Contains(aExp.Current()) && myEdgeFaces.FindFromKey(aExp.Current()).Extent() >1)
           continue;
-        aSeqEdges->Append(aExp.Current());
+      aSeqEdges->Append(aExp.Current()); // to do: mustn't this clause be within if(!BRep_Tool::Degenerated...)?
     }
   }
 
@@ -276,49 +281,53 @@ Handle(Geom_Surface) ShHealOper_FillHoles::buildSurface(const TopoDS_Wire& theWi
 {
   Handle(Geom_BSplineSurface) aSurf;
   try {
-      GeomPlate_BuildPlateSurface aBuilder(myDegree, myNbPtsOnCur, myNbIter,
-                                                 myTol2d, myTol3d, myTolAng, myTolCrv);
-      TopoDS_Iterator aIter;
-      for(aIter.Initialize (theWire); aIter.More(); aIter.Next()) {
-
-        TopoDS_Edge ae = TopoDS::Edge(aIter.Value());
-        BRepAdaptor_Curve adC(ae);
-        Handle(BRepAdaptor_HCurve) aHAD= new BRepAdaptor_HCurve(adC);
-        Handle(BRepFill_CurveConstraint) aConst =
-            new BRepFill_CurveConstraint (aHAD, (Standard_Integer) GeomAbs_C0, myNbPtsOnCur, myTol3d);
-        //Handle(GeomPlate_CurveConstraint) aConst =
-         // new GeomPlate_CurveConstraint(aHAD, (Standard_Integer) GeomAbs_C0, myNbPtsOnCur, myTol3d);
-        aBuilder.Add (aConst);
-      }
-      aBuilder.Perform();
-      if(!aBuilder.IsDone())
-        return aSurf;
-      Handle(GeomPlate_Surface) aPlSurf = aBuilder.Surface();
-
-      //for filling holes without initial specified surface
-      //the initial surface should be build by GeomPlate itself
-      //following code was taken from BRepFill_Filling::Build
-
-      Standard_Real aDist = aBuilder.G0Error();
-      TColgp_SequenceOfXY S2d;
-      TColgp_SequenceOfXYZ S3d;
-      S2d.Clear();
-      S3d.Clear();
-      aBuilder.Disc2dContour(4,S2d);
-      aBuilder.Disc3dContour(4,0,S3d);
-      Standard_Real amaxTol = Max( myTol3d, 10* aDist);
-      GeomPlate_PlateG0Criterion Criterion( S2d, S3d, amaxTol );
-      GeomPlate_MakeApprox Approx( aPlSurf, Criterion, myTol3d, myMaxSeg, myMaxDeg );
-      aSurf = Approx.Surface();
-      if(aSurf.IsNull())
-        return aSurf;
-
-      theCurves2d = aBuilder.Curves2d();
-      theOrders    = aBuilder.Order();
-      theSenses    = aBuilder.Sense();
+    GeomPlate_BuildPlateSurface aBuilder(myDegree, myNbPtsOnCur, myNbIter,
+                                         myTol2d, myTol3d, myTolAng, myTolCrv);
+    TopoDS_Iterator aIter;
+    for(aIter.Initialize (theWire); aIter.More(); aIter.Next()) {
+
+      TopoDS_Edge ae = TopoDS::Edge(aIter.Value());
+      BRepAdaptor_Curve adC(ae);
+#if OCC_VERSION_LARGE < 0x07070000
+      Handle(BRepAdaptor_HCurve) aHAD = new BRepAdaptor_HCurve(adC);
+#else
+      Handle(BRepAdaptor_Curve) aHAD = new BRepAdaptor_Curve(adC);
+#endif
+      // Handle(BRepFill_CurveConstraint) aConst =
+      //     new BRepFill_CurveConstraint (Handle(Adaptor3d_HCurve)::DownCast(aHAD), (Standard_Integer) GeomAbs_C0, myNbPtsOnCur, myTol3d);
+      Handle(GeomPlate_CurveConstraint) aConst =
+        new GeomPlate_CurveConstraint(aHAD, (Standard_Integer) GeomAbs_C0, myNbPtsOnCur, myTol3d);
+      aBuilder.Add (aConst);
     }
+    aBuilder.Perform();
+    if(!aBuilder.IsDone())
+      return aSurf;
+    Handle(GeomPlate_Surface) aPlSurf = aBuilder.Surface();
+
+    //for filling holes without initial specified surface
+    //the initial surface should be build by GeomPlate itself
+    //following code was taken from BRepFill_Filling::Build
+
+    Standard_Real aDist = aBuilder.G0Error();
+    TColgp_SequenceOfXY S2d;
+    TColgp_SequenceOfXYZ S3d;
+    S2d.Clear();
+    S3d.Clear();
+    aBuilder.Disc2dContour(4,S2d);
+    aBuilder.Disc3dContour(4,0,S3d);
+    Standard_Real amaxTol = Max( myTol3d, 10* aDist);
+    GeomPlate_PlateG0Criterion Criterion( S2d, S3d, amaxTol );
+    GeomPlate_MakeApprox Approx( aPlSurf, Criterion, myTol3d, myMaxSeg, myMaxDeg );
+    aSurf = Approx.Surface();
+    if(aSurf.IsNull())
+      return aSurf;
 
-  catch (Standard_Failure) {
+    theCurves2d = aBuilder.Curves2d();
+    theOrders    = aBuilder.Order();
+    theSenses    = aBuilder.Sense();
+  }
+
+  catch (Standard_Failure&) {
     aSurf.Nullify();
     return aSurf;
   }
@@ -336,11 +345,7 @@ Standard_Boolean ShHealOper_FillHoles::addFace(const Handle(Geom_Surface)& theSu
                                                const Handle(TColStd_HArray1OfInteger)& theOrders,
                                                const Handle(TColStd_HArray1OfInteger)& theSenses)
 {
-#if OCC_VERSION_LARGE > 0x06050100 // for OCC-6.5.2 and higher version
   BRepBuilderAPI_MakeFace aMakeFace (theSurf, Precision::Confusion());
-#else
-  BRepBuilderAPI_MakeFace aMakeFace (theSurf);
-#endif
   TopoDS_Face aFace = aMakeFace.Face();
   aFace.EmptyCopy();
 
@@ -362,7 +367,7 @@ Standard_Boolean ShHealOper_FillHoles::addFace(const Handle(Geom_Surface)& theSu
     aB.Range (anEdge, aFace, aF, aL);
 
     // Set orientation of the edge: orientation should be changed
-    // if its orientation does not make sence with curve orientation
+    // if its orientation does not make sense with curve orientation
     // recommended by GeomPlate
     if ((anEdge.Orientation() == TopAbs_FORWARD) ==
         (theSenses->Value (theOrders->Value (aInd)) == 1)) {