Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Intersection.cpp
index aa95218e08e118772d62fac93e579602d6afd92f..d7cc5aeb9e7dda0082538fef75a17afad5a88518 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2021  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 <ModelAPI_Document.h>
 #include <ModelAPI_BodyBuilder.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Tools.h>
 
 #include <GeomAlgoAPI_Intersection.h>
 #include <GeomAlgoAPI_MakeShapeList.h>
 
 #include <sstream>
 
+
 static const std::string INTERSECTION_VERSION_1("v9.5");
+static const double DEFAULT_FUZZY = 1.e-5;
+
 
 //=================================================================================================
 FeaturesPlugin_Intersection::FeaturesPlugin_Intersection()
@@ -45,6 +51,11 @@ void FeaturesPlugin_Intersection::initAttributes()
   AttributePtr anObjectsAttr = data()->addAttribute(OBJECT_LIST_ID(),
                        ModelAPI_AttributeSelectionList::typeId());
 
+  data()->addAttribute(USE_FUZZY_ID(), ModelAPI_AttributeBoolean::typeId());
+  data()->addAttribute(FUZZY_PARAM_ID(), ModelAPI_AttributeDouble::typeId());
+  boolean(USE_FUZZY_ID())->setValue(false); // Do NOT use the fuzzy parameter by default.
+  real(FUZZY_PARAM_ID())->setValue(DEFAULT_FUZZY);
+
   initVersion(INTERSECTION_VERSION_1, anObjectsAttr, AttributePtr());
 }
 
@@ -59,11 +70,17 @@ void FeaturesPlugin_Intersection::execute()
     return;
   }
 
+  // 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);
+
   int aResultIndex = 0;
 
   // Create result.
   const ListOfShape& anObjects = anObjectsHierarchy.objects();
-  GeomMakeShapePtr anIntersectionAlgo(new GeomAlgoAPI_Intersection(anObjects));
+  GeomMakeShapePtr anIntersectionAlgo(new GeomAlgoAPI_Intersection(anObjects, aFuzzy));
 
   // Checking that the algorithm worked properly.
   std::string anError;
@@ -84,19 +101,19 @@ void FeaturesPlugin_Intersection::execute()
   }
 
   std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
-  FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
-                                           anObjects,
-                                           ListOfShape(),
-                                           aMakeShapeList,
-                                           aResShape);
+  ModelAPI_Tools::loadModifiedShapes(aResultBody,
+                                     anObjects,
+                                     ListOfShape(),
+                                     aMakeShapeList,
+                                     aResShape);
   setResult(aResultBody, aResultIndex);
   aResultIndex++;
 
-  FeaturesPlugin_Tools::loadDeletedShapes(aResultBody,
-                                          GeomShapePtr(),
-                                          anObjects,
-                                          aMakeShapeList,
-                                          aResShape);
+  ModelAPI_Tools::loadDeletedShapes(aResultBody,
+                                    GeomShapePtr(),
+                                    anObjects,
+                                    aMakeShapeList,
+                                    aResShape);
 
   // remove the rest results if there were produced in the previous pass
   removeResults(aResultIndex);