]> OCCT Git - occt-copy.git/commitdiff
0030788: Modeling Algorithms - BRepAlgoAPI_Defeaturing does not propagate progress... CR30788_1
authorakaftasev <akaftasev@opencascade.com>
Thu, 18 Mar 2021 16:44:11 +0000 (19:44 +0300)
committerakaftasev <akaftasev@opencascade.com>
Mon, 9 Aug 2021 12:45:20 +0000 (15:45 +0300)
src/BOPAlgo/BOPAlgo_RemoveFeatures.cxx
src/BOPAlgo/BOPAlgo_RemoveFeatures.hxx
src/BOPTest/BOPTest_RemoveFeaturesCommands.cxx
src/BRepAlgoAPI/BRepAlgoAPI_Defeaturing.cxx

index 7616e1d84146b5777040d7baf8aa8685f4bfef92..08ad10a6c8de069934b74e352d5f00beac70258f 100644 (file)
@@ -124,7 +124,7 @@ static void FindSolid(const TopoDS_Shape& theSolIn,
 // function: Perform
 // purpose: Performs the removal of the requested faces from the input shape
 //=======================================================================
-void BOPAlgo_RemoveFeatures::Perform(const Message_ProgressRange& /*theRange*/)
+void BOPAlgo_RemoveFeatures::Perform(const Message_ProgressRange& theRange)
 {
   try
   {
@@ -138,19 +138,27 @@ void BOPAlgo_RemoveFeatures::Perform(const Message_ProgressRange& /*theRange*/)
     if (HasErrors())
       return;
 
+    Message_ProgressScope aPS(theRange, "Removing features", 100);
+
     // Prepare the faces to remove.
-    PrepareFeatures();
+    PrepareFeatures(aPS.Next(10));
     if (HasErrors())
       return;
 
     // Remove the features and fill the created gaps
-    RemoveFeatures();
+    RemoveFeatures(aPS.Next(70));
+    if (HasErrors())
+      return;
 
     // Update history with the removed features
-    UpdateHistory();
+    UpdateHistory(aPS.Next(10));
+    if (HasErrors())
+      return;
 
     // Simplify the result
-    SimplifyResult();
+    SimplifyResult(aPS.Next(10));
+    if (HasErrors())
+      return;
 
     // Post treatment
     PostTreat();
@@ -243,7 +251,7 @@ void BOPAlgo_RemoveFeatures::CheckData()
 // function: PrepareFeatures
 // purpose: Prepares the features to remove
 //=======================================================================
-void BOPAlgo_RemoveFeatures::PrepareFeatures()
+void BOPAlgo_RemoveFeatures::PrepareFeatures(const Message_ProgressRange& theRange)
 {
   // Map all sub-shapes of the input solids
   TopExp::MapShapes(myInputShape, myInputsMap);
@@ -251,8 +259,13 @@ void BOPAlgo_RemoveFeatures::PrepareFeatures()
   // Collect all faces of the input shape requested for removal
   TopTools_ListOfShape aFacesToRemove;
   TopTools_ListIteratorOfListOfShape aIt(myFacesToRemove);
-  for (; aIt.More(); aIt.Next())
+  Message_ProgressScope aPS(theRange, "Preparing the faces to remove", myFacesToRemove.Size());
+  for (; aIt.More(); aIt.Next(), aPS.Next())
   {
+    if (UserBreak(aPS))
+    {
+      return;
+    }
     const TopoDS_Shape& aS = aIt.Value();
     TopExp_Explorer anExpF(aS, TopAbs_FACE);
     for (; anExpF.More(); anExpF.Next())
@@ -318,6 +331,11 @@ public: //! @name Setters/Getters
     myFSMap = (TopTools_IndexedDataMapOfShapeListOfShape*)&theFSMap;
   }
 
+  void SetRange(const Message_ProgressRange& theRange)
+  {
+    myRange = theRange;
+  }
+
   //! Defines the parallel processing mode
   void SetRunParallel(const Standard_Boolean bRunParallel) { myRunParallel = bRunParallel; }
 
@@ -333,6 +351,11 @@ public: //! @name Perform the operation
   //! then trims the extended faces to fill the gaps
   void Perform()
   {
+    Message_ProgressScope aPS(myRange, NULL, 1);
+    if (!aPS.More())
+    {
+      return;
+    }
     OCC_CATCH_SIGNALS
 
     try
@@ -705,6 +728,7 @@ private: //! @name Fields
   TopoDS_Shape myFeature;                             //!< Feature to remove
   TopTools_IndexedDataMapOfShapeListOfShape* myEFMap; //!< EF Connection map to find adjacent faces
   TopTools_IndexedDataMapOfShapeListOfShape* myFSMap; //!< FS Connection map to find solids participating in the feature removal
+  Message_ProgressRange                      myRange; //!< Indication of progress
 
   // Results
   TopTools_MapOfShape myFeatureFacesMap;              //!< Faces of the feature
@@ -721,7 +745,7 @@ typedef NCollection_Vector<FillGap> VectorOfFillGap;
 // purpose: Remove features by filling the gaps by extension of the
 //          adjacent faces
 //=======================================================================
-void BOPAlgo_RemoveFeatures::RemoveFeatures()
+void BOPAlgo_RemoveFeatures::RemoveFeatures(const Message_ProgressRange& theRange)
 {
   // For each feature:
   // - Find the faces adjacent to the feature;
@@ -730,6 +754,8 @@ void BOPAlgo_RemoveFeatures::RemoveFeatures()
   // - Rebuild the solids with reconstructed adjacent faces
   //   and avoiding the feature faces.
 
+  Message_ProgressScope aPSOuter(theRange, "Removing features", 100);
+
   // Make Edge-Face connection map of the input
   // shape to find faces adjacent to the feature
   TopTools_IndexedDataMapOfShapeListOfShape anEFMap;
@@ -755,8 +781,20 @@ void BOPAlgo_RemoveFeatures::RemoveFeatures()
     aFG.SetRunParallel(myRunParallel);
   }
 
+  const Standard_Integer aNbF = aVFG.Length();
+  Message_ProgressScope aPS(aPSOuter.Next(60), "Filling gaps", aNbF);
+  for (Standard_Integer i = 0; i < aNbF; ++i)
+  {
+    FillGap& aFG = aVFG.ChangeValue(i);
+    aFG.SetRange(aPS.Next());
+  }
+
   // Perform the reconstruction of the adjacent faces
   BOPTools_Parallel::Perform (myRunParallel, aVFG);
+  if (UserBreak(aPSOuter))
+  {
+    return;
+  }
 
   // Even if the history is not requested, it is necessary to track:
   // - The solids modification after each feature removal to find
@@ -769,9 +807,13 @@ void BOPAlgo_RemoveFeatures::RemoveFeatures()
   // Remove the features one by one.
   // It will allow removing the features even if there were
   // some problems with removal of the previous features.
-  const Standard_Integer aNbF = aVFG.Length();
-  for (Standard_Integer i = 0; i < aNbF; ++i)
+  Message_ProgressScope aPSLoop(aPSOuter.Next(40), "Removing features one by one", aNbF);
+  for (Standard_Integer i = 0; i < aNbF; ++i, aPSLoop.Next())
   {
+    if (UserBreak(aPSLoop))
+    {
+      return;
+    }
     FillGap& aFG = aVFG(i);
 
     // No need to fill the history for solids if the history is not
@@ -1029,7 +1071,7 @@ void BOPAlgo_RemoveFeatures::RemoveFeature
 // function: UpdateHistory
 // purpose: Update history with the removed features
 //=======================================================================
-void BOPAlgo_RemoveFeatures::UpdateHistory()
+void BOPAlgo_RemoveFeatures::UpdateHistory(const Message_ProgressRange& theRange)
 {
   if (!HasHistory())
     return;
@@ -1042,8 +1084,13 @@ void BOPAlgo_RemoveFeatures::UpdateHistory()
   BRepTools_History aHistory;
 
   const Standard_Integer aNbS = myInputsMap.Extent();
-  for (Standard_Integer i = 1; i <= aNbS; ++i)
+  Message_ProgressScope aPS(theRange, "Updating history", aNbS);
+  for (Standard_Integer i = 1; i <= aNbS; ++i, aPS.Next())
   {
+    if (UserBreak(aPS))
+    {
+      return;
+    }
     const TopoDS_Shape& aS = myInputsMap(i);
     if (!BRepTools_History::IsSupportedType(aS))
       continue;
@@ -1075,7 +1122,7 @@ void BOPAlgo_RemoveFeatures::UpdateHistory()
 // purpose: Simplifies the result by removing extra edges and vertices
 //          created during operation
 //=======================================================================
-void BOPAlgo_RemoveFeatures::SimplifyResult()
+void BOPAlgo_RemoveFeatures::SimplifyResult(const Message_ProgressRange& theRange)
 {
   if (myShape.IsSame(myInputShape))
     return;
@@ -1087,15 +1134,23 @@ void BOPAlgo_RemoveFeatures::SimplifyResult()
   if (myMapShape.IsEmpty())
     TopExp::MapShapes(myShape, myMapShape);
 
+  Message_ProgressScope aPSOuter(theRange, "Simplifyingthe result", 2);
+  
   const Standard_Integer aNbS = myInputsMap.Extent();
-  for (Standard_Integer i = 1; i <= aNbS; ++i)
+  Message_ProgressScope aPS(aPSOuter.Next(), NULL, aNbS);
+  for (Standard_Integer i = 1; i <= aNbS; ++i, aPS.Next())
   {
+    if (UserBreak(aPS))
+    {
+      return;
+    }
     if (myMapShape.Contains(myInputsMap(i)))
       aSDTool.KeepShape(myInputsMap(i));
   }
 
   // Perform unification
   aSDTool.Build();
+  aPSOuter.Next();
   myShape = aSDTool.Shape();
   if (HasHistory())
     myHistory->Merge(aSDTool.History());
index 7db54ffa8cb130606daa7315ad3eb9f14db9a811..33b52fd9f3ed34e15f930170ce1021505d86bcc4 100644 (file)
@@ -231,11 +231,11 @@ protected: //! @name Protected methods performing the removal
   //! Prepares the faces to remove:
   //! - Gets only faces contained in the input solids;
   //! - Builds connected blocks of faces creating separate features to remove.
-  Standard_EXPORT void PrepareFeatures();
+  Standard_EXPORT void PrepareFeatures(const Message_ProgressRange& theRange);
 
   //! Removes the features and fills the created gaps by extension of the adjacent faces.
   //! Processes each feature separately.
-  Standard_EXPORT void RemoveFeatures();
+  Standard_EXPORT void RemoveFeatures(const Message_ProgressRange& theRange);
 
   //! Remove the single feature from the shape.
   //! @param theFeature [in] The feature to remove;
@@ -256,11 +256,11 @@ protected: //! @name Protected methods performing the removal
                                      const Standard_Boolean theSolidsHistoryNeeded);
 
   //! Updates history with the removed features
-  Standard_EXPORT void UpdateHistory();
+  Standard_EXPORT void UpdateHistory(const Message_ProgressRange& theRange);
 
   //! Simplifies the result by removing extra edges and vertices created
   //! during removal of the features.
-  Standard_EXPORT void SimplifyResult();
+  Standard_EXPORT void SimplifyResult(const Message_ProgressRange& theRange);
 
   //! Post treatment - restore the type of the initial shape
   Standard_EXPORT void PostTreat();
index 7a85b1d099d1eda455ab6d7b15ee278c7725bcf7..6d8e4c2afa38905625b5db593910bb760e14c8e1 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <DBRep.hxx>
 #include <Draw.hxx>
+#include <Draw_ProgressIndicator.hxx>
 
 #include <TopoDS.hxx>
 #include <TopoDS_Compound.hxx>
@@ -99,8 +100,9 @@ Standard_Integer RemoveFeatures(Draw_Interpretor& theDI,
 
   aRF.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
 
+  Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
   // Perform the removal
-  aRF.Build();
+  aRF.Build(aProgress->Start());
 
   // Check for the errors/warnings
   BOPTest::ReportAlerts(aRF.GetReport());
index 2f4def8b8d62701566daa93b5109d20dac2c396f..04fa1a3dbd3c625ad35896edc0ef68074ff85ad9 100644 (file)
@@ -21,7 +21,7 @@
 //function : Build
 //purpose  : 
 //=======================================================================
-void BRepAlgoAPI_Defeaturing::Build(const Message_ProgressRange& /*theRange*/)
+void BRepAlgoAPI_Defeaturing::Build(const Message_ProgressRange& theRange)
 {
   // Set not done state for the operation
   NotDone();
@@ -36,7 +36,7 @@ void BRepAlgoAPI_Defeaturing::Build(const Message_ProgressRange& /*theRange*/)
   myFeatureRemovalTool.SetRunParallel(myRunParallel);
 
   // Perform the features removal
-  myFeatureRemovalTool.Perform();
+  myFeatureRemovalTool.Perform(theRange);
 
   // Merge the Errors/Warnings from the features removal tool
   GetReport()->Merge(myFeatureRemovalTool.GetReport());