0028562: Replacement of old Boolean operations (BRepAlgo) with new ones (BRepAlgoAPI...
[occt.git] / src / BRepAlgo / BRepAlgo_NormalProjection.cxx
index a9a93e4..768ff46 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <BRepAlgo_NormalProjection.ixx>
-#include <ProjLib_CompProjectedCurve.hxx>
-#include <TopTools_HSequenceOfShape.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopAbs.hxx>
+
+#include <Adaptor3d_Curve.hxx>
+#include <Approx_CurveOnSurface.hxx>
+#include <BRep_Builder.hxx>
 #include <BRepAdaptor_Curve.hxx>
 #include <BRepAdaptor_HCurve.hxx>
-#include <BRepAdaptor_Surface.hxx>
 #include <BRepAdaptor_HSurface.hxx>
-#include <ProjLib_HCompProjectedCurve.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Shape.hxx>
-#include <Approx_CurveOnSurface.hxx>
-#include <TopoDS.hxx>
-#include <BRep_Builder.hxx>
+#include <BRepAdaptor_Surface.hxx>
+#include <BRepAlgo_NormalProjection.hxx>
+#include <BRepAlgo_SequenceOfSequenceOfInteger.hxx>
+#include <BRepAlgoAPI_Common.hxx>
+#include <BRepLib_MakeEdge.hxx>
 #include <BRepLib_MakeVertex.hxx>
 #include <BRepLib_MakeWire.hxx>
-#include <Geom2dAdaptor_HCurve.hxx>
+#include <BRepTools.hxx>
+#include <BRepTopAdaptor_FClass2d.hxx>
+#include <Geom2d_BSplineCurve.hxx>
 #include <Geom2d_Curve.hxx>
+#include <Geom2d_TrimmedCurve.hxx>
+#include <Geom2dAdaptor_HCurve.hxx>
 #include <Geom_BSplineCurve.hxx>
 #include <GeomAdaptor.hxx>
-#include <BRepLib_MakeEdge.hxx>
-#include <BRepAlgo_BooleanOperations.hxx>
-#include <TopOpeBRepBuild_HBuilder.hxx>
-#include <BRepTopAdaptor_FClass2d.hxx>
 #include <Precision.hxx>
-#include <BRepAlgo_SequenceOfSequenceOfInteger.hxx>
-#include <TopExp.hxx>
-#include <BRepTools.hxx>
+#include <ProjLib_CompProjectedCurve.hxx>
+#include <ProjLib_HCompProjectedCurve.hxx>
+#include <Standard_ConstructionError.hxx>
+#include <Standard_NoSuchObject.hxx>
+#include <StdFail_NotDone.hxx>
 #include <TColgp_Array1OfPnt2d.hxx>
-#include <TColStd_Array1OfReal.hxx>
 #include <TColStd_Array1OfInteger.hxx>
-#include <Geom2d_TrimmedCurve.hxx>
-#include <Geom2d_BSplineCurve.hxx>
+#include <TColStd_Array1OfReal.hxx>
+#include <TopAbs.hxx>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopTools_HSequenceOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 
-#ifdef __OCC_DEBUG_CHRONO
+#ifdef OCCT_DEBUG_CHRONO
 #include <OSD_Timer.hxx>
 
 OSD_Chronometer chr_total, chr_init, chr_approx, chr_booltool;
@@ -195,7 +199,7 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
 
  void BRepAlgo_NormalProjection::Build() 
 {
-#ifdef __OCC_DEBUG_CHRONO
+#ifdef OCCT_DEBUG_CHRONO
   Standard_Integer init_count = 0, approx_count = 0, booltool_count = 0;
   t_total = 0;
   t_init = 0;
@@ -266,12 +270,12 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
       TolU = hsur->UResolution(myTol3d)/20;
       TolV = hsur->VResolution(myTol3d)/20;
       // Projection
-#ifdef __OCC_DEBUG_CHRONO
+#ifdef OCCT_DEBUG_CHRONO
       InitChron(chr_init);
 #endif
       Projector = 
        ProjLib_CompProjectedCurve(hsur, hcur, TolU, TolV, myMaxDist);
-#ifdef __OCC_DEBUG_CHRONO
+#ifdef OCCT_DEBUG_CHRONO
       ResultChron(chr_init,t_init);
       init_count++;
 #endif
@@ -290,7 +294,7 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
       
       for(k = 1; k <= Projector.NbCurves(); k++){
        if(Projector.IsSinglePnt(k, P2d)){
-#ifdef BREPALGO_DEB
+#ifdef OCCT_DEBUG
          cout << "Projection of edge "<<i<<" on face "<<j;
          cout << " is punctual"<<endl<<endl;
 #endif
@@ -308,7 +312,7 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
          
          /**************************************************************/
          if (Projector.IsUIso(k, UIso)) {
-#ifdef BREPALGO_DEB
+#ifdef OCCT_DEBUG
            cout << "Projection of edge "<<i<<" on face "<<j;
            cout << " is U-isoparametric"<<endl<<endl;
 #endif
@@ -325,7 +329,7 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
            Only3d = Standard_True;
          }
          else if (Projector.IsVIso(k, VIso)) {
-#ifdef BREPALGO_DEB
+#ifdef OCCT_DEBUG
            cout << "Projection of edge "<<i<<" on face "<<j;
            cout << " is V-isoparametric"<<endl<<endl;
 #endif
@@ -359,13 +363,13 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
             BB.UpdateVertex(TopExp::LastVertex(TopoDS::Edge(prj)),myTol3d);
          }
          else {
-#ifdef __OCC_DEBUG_CHRONO
+#ifdef OCCT_DEBUG_CHRONO
            InitChron(chr_approx);
 #endif
            Approx_CurveOnSurface appr(HPCur, hsur, Udeb, Ufin, myTol3d, 
                                       myContinuity, myMaxDegree, myMaxSeg, 
                                       Only3d, Only2d);
-#ifdef __OCC_DEBUG_CHRONO
+#ifdef OCCT_DEBUG_CHRONO
            ResultChron(chr_approx,t_approx);
            approx_count++;
            
@@ -391,7 +395,7 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
             // points has less diameter than the tolerance 3D
               Degenerated = Standard_True;
               Standard_Real Dist;
-              Handle(Geom_BSplineCurve) BS3d  = Handle(Geom_BSplineCurve)::DownCast( appr.Curve3d());
+              Handle(Geom_BSplineCurve) BS3d = appr.Curve3d();
               gp_Pnt P1(0.,0.,0.),PP; // skl : I change "P" to "PP"
               Standard_Integer NbPoint,ii ; // skl : I change "i" to "ii"
               Standard_Real Par,DPar;
@@ -438,7 +442,7 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
                  }             
               }
              if (Degenerated) {
-#ifdef BREPALGO_DEB
+#ifdef OCCT_DEBUG
                  cout << "Projection of edge "<<i<<" on face "<<j;
                  cout << " is degenerated "<<endl<<endl;
 #endif
@@ -471,34 +475,26 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
          if(myFaceBounds) {
            // Trimming edges by face bounds 
             // if the solution is degenerated, use of BoolTool is avoided
-#ifdef __OCC_DEBUG_CHRONO
+#ifdef OCCT_DEBUG_CHRONO
            InitChron(chr_booltool);
 #endif
-            if(!Degenerated){
-              BRepAlgo_BooleanOperations BoolTool;
-              BoolTool.Shapes2d(Faces->Value(j),prj);
-              BoolTool.Common();
-              Handle(TopOpeBRepBuild_HBuilder) HB;
-              TopTools_ListOfShape LS;
-              TopTools_ListIteratorOfListOfShape Iter; 
-              HB = BoolTool.Builder();
-              LS.Clear();
-              if (HB->IsSplit(prj, TopAbs_IN))
-                LS = HB->Splits(prj, TopAbs_IN);
-              Iter.Initialize(LS);
-              if(Iter.More()) {
-#ifdef BREPALGO_DEB
-                  cout << " BooleanOperations :"  << Iter.More()<<" solutions " << endl; 
-#endif
-                 for(; Iter.More(); Iter.Next()) {
-                    BB.Add(myRes, Iter.Value());
-                    myAncestorMap.Bind(Iter.Value(), Edges->Value(i));
-                    myCorresp.Bind(Iter.Value(),Faces->Value(j));
-                 }
-              }
-
-              else {
-
+            if (!Degenerated) {
+              // Perform Boolean COMMON operation to get parts of projected edge
+              // inside the face
+              BRepAlgoAPI_Common aCommon(Faces->Value(j), prj);
+              if (aCommon.IsDone()) {
+                const TopoDS_Shape& aRC = aCommon.Shape();
+                //
+                TopExp_Explorer aExpE(aRC, TopAbs_EDGE);
+                for (; aExpE.More(); aExpE.Next()) {
+                  const TopoDS_Shape& aE = aExpE.Current();
+                  BB.Add(myRes, aE);
+                  myAncestorMap.Bind(aE, Edges->Value(i));
+                  myCorresp.Bind(aE, Faces->Value(j));
+                }
+              }
+              else {
+                // if the common operation has failed, try to classify the part
                 BRepTopAdaptor_FClass2d classifier(TopoDS::Face(Faces->Value(j)),
                                                    Precision::Confusion());
                 gp_Pnt2d Puv;
@@ -517,7 +513,7 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
               }
             }
             else {
-#ifdef BREPALGO_DEB
+#ifdef OCCT_DEBUG
                  cout << " BooleanOperations : no solution " << endl;
 #endif
 
@@ -536,7 +532,7 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
                 myAncestorMap.Bind(prj, Edges->Value(i));   
                 myCorresp.Bind(prj, Faces->Value(j));
              }
-#ifdef __OCC_DEBUG_CHRONO
+#ifdef OCCT_DEBUG_CHRONO
               ResultChron(chr_booltool,t_booltool);
               booltool_count++;
 #endif
@@ -561,7 +557,7 @@ void BRepAlgo_NormalProjection::SetDefaultParams()
   
   myIsDone = Standard_True; 
   
-#ifdef __OCC_DEBUG_CHRONO
+#ifdef OCCT_DEBUG_CHRONO
   ResultChron(chr_total,t_total);
   
   cout<<"Build - Total time  : "<<t_total<<" includes:" <<endl;