Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_BooleanFill.cpp
index a907823addc16bb4173a6e1982dfd4722f82f9e4..755893497e3b162d3dc3bba29717db78292553e0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 
 #include "FeaturesPlugin_BooleanFill.h"
-#include "FeaturesPlugin_Tools.h"
 
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Tools.h>
 
 #include <algorithm>
 #include <map>
 
+
 //=================================================================================================
 FeaturesPlugin_BooleanFill::FeaturesPlugin_BooleanFill()
   : FeaturesPlugin_Boolean(FeaturesPlugin_Boolean::BOOL_FILL)
 {
 }
 
+//=================================================================================================
+void FeaturesPlugin_BooleanFill::initAttributes()
+{
+  FeaturesPlugin_Boolean::initAttributes();
+  initVersion(BOP_VERSION_9_4(), selectionList(OBJECT_LIST_ID()), selectionList(TOOL_LIST_ID()));
+}
+
 //=================================================================================================
 void FeaturesPlugin_BooleanFill::execute()
 {
   std::string anError;
-  ObjectHierarchy anObjects, aTools;
+  GeomAPI_ShapeHierarchy anObjects, aTools;
   ListOfShape aPlanes;
 
   // Getting objects.
@@ -65,44 +74,67 @@ void FeaturesPlugin_BooleanFill::execute()
 
   int aResultIndex = 0;
 
-  if (anObjects.IsEmpty() || (aTools.IsEmpty() && aPlanes.empty())) {
+  if (anObjects.empty() || (aTools.empty() && aPlanes.empty())) {
     std::string aFeatureError = "Error: Not enough objects for boolean operation.";
     setError(aFeatureError);
     return;
   }
 
-  std::vector<FeaturesPlugin_Tools::ResultBaseAlgo> aResultBaseAlgoList;
+  std::vector<ModelAPI_Tools::ResultBaseAlgo> aResultBaseAlgoList;
   ListOfShape aResultShapesList;
 
+  std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
+
+  GeomShapePtr aResultCompound;
+  if (data()->version() == BOP_VERSION_9_4()) {
+    // merge hierarchies of compounds containing objects and tools
+    aResultCompound =
+        keepUnusedSubsOfCompound(GeomShapePtr(), anObjects, aTools, aMakeShapeList);
+  }
+
+  // Getting fuzzy parameter.
+  // Used as additional tolerance to eliminate tiny results.
+  // Using -1 as fuzzy value in the GeomAlgoAPI means to ignore it during the boolean operation!
+  bool aUseFuzzy = boolean(USE_FUZZY_ID())->value();
+  double aFuzzy = (aUseFuzzy ? real(FUZZY_PARAM_ID())->value() : -1);
+
   // For solids cut each object with all tools.
   bool isOk = true;
-  for (ObjectHierarchy::Iterator anObjectsIt = anObjects.Begin();
-       anObjectsIt != anObjects.End() && isOk;
+  for (GeomAPI_ShapeHierarchy::iterator anObjectsIt = anObjects.begin();
+       anObjectsIt != anObjects.end() && isOk;
        ++anObjectsIt) {
     GeomShapePtr anObject = *anObjectsIt;
-    GeomShapePtr aParent = anObjects.Parent(anObject, false);
+    GeomShapePtr aParent = anObjects.parent(anObject, false);
 
     if (aParent && aParent->shapeType() == GeomAPI_Shape::COMPSOLID) {
       // get parent once again to mark it and the subs as processed
-      aParent = anObjects.Parent(anObject);
+      aParent = anObjects.parent(anObject);
       // compsolid handling
       isOk = processCompsolid(GeomAlgoAPI_Tools::BOOL_PARTITION,
-                              anObjects, aParent, aTools.Objects(), aPlanes,
-                              aResultIndex, aResultBaseAlgoList, aResultShapesList);
+                              anObjects, aParent, aTools.objects(), aPlanes,
+                              aFuzzy,
+                              aResultIndex, aResultBaseAlgoList, aResultShapesList,
+                              aResultCompound);
     } else {
       // process object as is
       isOk = processObject(GeomAlgoAPI_Tools::BOOL_PARTITION,
-                           anObject, aTools.Objects(), aPlanes,
-                           aResultIndex, aResultBaseAlgoList, aResultShapesList);
+                           anObject, aTools.objects(), aPlanes,
+                           aFuzzy,
+                           aResultIndex, aResultBaseAlgoList, aResultShapesList,
+                           aResultCompound);
     }
   }
 
+  storeResult(anObjects.objects(), aTools.objects(), aResultCompound, aResultIndex,
+              aMakeShapeList, aResultBaseAlgoList);
+
   // Store deleted shapes after all results has been proceeded. This is to avoid issue when in one
   // result shape has been deleted, but in another it was modified or stayed.
-  GeomShapePtr aResultShapesCompound = GeomAlgoAPI_CompoundBuilder::compound(aResultShapesList);
-  FeaturesPlugin_Tools::loadDeletedShapes(aResultBaseAlgoList,
-                                          aTools.Objects(),
-                                          aResultShapesCompound);
+  if (!aResultCompound)
+    aResultCompound = GeomAlgoAPI_CompoundBuilder::compound(aResultShapesList);
+  ModelAPI_Tools::loadDeletedShapes(aResultBaseAlgoList,
+                                    aTools.objects(),
+                                    aResultCompound);
 
   // remove the rest results if there were produced in the previous pass
   removeResults(aResultIndex);