Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_BooleanFuse.cpp
index c6cab27359d8ea39e5430f0ef364b05f3144c494..dee59777953abb895a130b38b6f2a9852c8d1beb 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 <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
 
+
+static const double DEFAULT_FUZZY = 1.e-5;
+
+
 //==================================================================================================
 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
   const std::shared_ptr<ModelAPI_Feature>& theFeature)
@@ -35,13 +39,23 @@ FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
   const std::shared_ptr<ModelAPI_Feature>& theFeature,
   const std::list<ModelHighAPI_Selection>& theMainObjects,
-  const bool theRemoveEdges)
+  const bool theRemoveEdges,
+  const ModelHighAPI_Double& theFuzzy)
   : ModelHighAPI_Interface(theFeature)
 {
   if (initialize()) {
-    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
-    fillAttribute(theMainObjects, mymainObjects);
-    fillAttribute(theRemoveEdges, myremoveEdges);
+    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), VAR_NAME(creationMethod));
+    fillAttribute(theMainObjects, VAR_NAME(mainObjects));
+    fillAttribute(theRemoveEdges, VAR_NAME(removeEdges));
+    fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
+
+    // Get the evaluated fuzzy parameter from the attribute!!
+    bool aUseFuzzy = (fuzzyParam()->value() > 0);
+    fillAttribute(aUseFuzzy, VAR_NAME(useFuzzy));
+    if (!aUseFuzzy) {
+      ModelHighAPI_Double aFuzzy(DEFAULT_FUZZY);
+      fillAttribute(aFuzzy, VAR_NAME(fuzzyParam));
+    }
 
     execute(false);
   }
@@ -52,14 +66,24 @@ FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
   const std::shared_ptr<ModelAPI_Feature>& theFeature,
   const std::list<ModelHighAPI_Selection>& theMainObjects,
   const std::list<ModelHighAPI_Selection>& theToolObjects,
-  const bool theRemoveEdges)
+  const bool theRemoveEdges,
+  const ModelHighAPI_Double& theFuzzy)
 : ModelHighAPI_Interface(theFeature)
 {
   if(initialize()) {
-    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
-    fillAttribute(theMainObjects, mymainObjects);
-    fillAttribute(theToolObjects, mytoolObjects);
-    fillAttribute(theRemoveEdges, myremoveEdges);
+    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
+    fillAttribute(theMainObjects, VAR_NAME(mainObjects));
+    fillAttribute(theToolObjects, VAR_NAME(toolObjects));
+    fillAttribute(theRemoveEdges, VAR_NAME(removeEdges));
+    fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
+
+    // Get the evaluated fuzzy parameter from the attribute!!
+    bool aUseFuzzy = (fuzzyParam()->value() > 0);
+    fillAttribute(aUseFuzzy, VAR_NAME(useFuzzy));
+    if (!aUseFuzzy) {
+      ModelHighAPI_Double aFuzzy(DEFAULT_FUZZY);
+      fillAttribute(aFuzzy, VAR_NAME(fuzzyParam));
+    }
 
     execute(false);
   }
@@ -75,7 +99,7 @@ FeaturesAPI_BooleanFuse::~FeaturesAPI_BooleanFuse()
 void FeaturesAPI_BooleanFuse::setMainObjects(
   const std::list<ModelHighAPI_Selection>& theMainObjects)
 {
-  fillAttribute(theMainObjects, mymainObjects);
+  fillAttribute(theMainObjects, VAR_NAME(mainObjects));
 
   execute();
 }
@@ -84,8 +108,8 @@ void FeaturesAPI_BooleanFuse::setMainObjects(
 void FeaturesAPI_BooleanFuse::setToolObjects(
   const std::list<ModelHighAPI_Selection>& theToolObjects)
 {
-  fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
-  fillAttribute(theToolObjects, mytoolObjects);
+  fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
+  fillAttribute(theToolObjects, VAR_NAME(toolObjects));
 
   execute();
 }
@@ -93,7 +117,23 @@ void FeaturesAPI_BooleanFuse::setToolObjects(
 //==================================================================================================
 void FeaturesAPI_BooleanFuse::setRemoveEdges(const bool theRemoveEdges)
 {
-  fillAttribute(theRemoveEdges, myremoveEdges);
+  fillAttribute(theRemoveEdges, VAR_NAME(removeEdges));
+
+  execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_BooleanFuse::setUseFuzzy(bool theUseFuzzy)
+{
+  fillAttribute(theUseFuzzy, VAR_NAME(useFuzzy));
+
+  execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_BooleanFuse::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
+{
+  fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
 
   execute();
 }
@@ -102,9 +142,9 @@ void FeaturesAPI_BooleanFuse::setRemoveEdges(const bool theRemoveEdges)
 void FeaturesAPI_BooleanFuse::setAdvancedMode(const bool theMode)
 {
   if (theMode) {
-    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
+    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
   } else {
-    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
+    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), VAR_NAME(creationMethod));
   }
 
   execute();
@@ -125,6 +165,8 @@ void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
     aBase->selectionList(FeaturesPlugin_BooleanFuse::TOOL_LIST_ID());
   AttributeBooleanPtr aRemoveEdges =
     aBase->boolean(FeaturesPlugin_BooleanFuse::REMOVE_INTERSECTION_EDGES_ID());
+  bool aUseFuzzy = aBase->boolean(FeaturesPlugin_BooleanFuse::USE_FUZZY_ID())->value();
+  AttributeDoublePtr aFuzzy = aBase->real(FeaturesPlugin_BooleanFuse::FUZZY_PARAM_ID());
 
   theDumper << "(" << aDocName << ", " << anObjects;
 
@@ -133,32 +175,40 @@ void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
   }
 
   if (aRemoveEdges->value()) {
-    theDumper << ", " << true;
+    theDumper << ", removeEdges = True";
   }
 
-  theDumper << ")" << std::endl;
-}
+  if (aUseFuzzy)
+    theDumper << ", fuzzyParam = " << aFuzzy;
 
-//==================================================================================================
-BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
-                       const std::list<ModelHighAPI_Selection>& theObjects,
-                       const bool theRemoveEdges)
-{
-  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
-  return BooleanFusePtr(new FeaturesAPI_BooleanFuse(aFeature,
-                                                    theObjects,
-                                                    theRemoveEdges));
+  if (!aBase->data()->version().empty())
+    theDumper << ", keepSubResults = True";
+
+  theDumper << ")" << std::endl;
 }
 
 //==================================================================================================
 BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
-                   const std::list<ModelHighAPI_Selection>& theMainObjects,
-                   const std::list<ModelHighAPI_Selection>& theToolObjects,
-                   const bool theRemoveEdges)
+                       const std::list<ModelHighAPI_Selection>& theMainObjects,
+                       const std::pair<std::list<ModelHighAPI_Selection>, bool>& theToolObjects,
+                       const bool theRemoveEdges,
+                       const ModelHighAPI_Double& theFuzzy,
+                       const bool keepSubResults)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
-  return BooleanFusePtr(new FeaturesAPI_BooleanFuse(aFeature,
-                                                    theMainObjects,
-                                                    theToolObjects,
-                                                    theRemoveEdges));
+  if (!keepSubResults)
+    aFeature->data()->setVersion("");
+
+  bool aRemoveEdges = theRemoveEdges;
+  if (theToolObjects.first.empty())
+    aRemoveEdges = aRemoveEdges || theToolObjects.second;
+
+  BooleanFusePtr aFuse;
+  if (theToolObjects.first.empty())
+    aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, aRemoveEdges, theFuzzy));
+  else {
+    aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, theToolObjects.first,
+                                            aRemoveEdges, theFuzzy));
+  }
+  return aFuse;
 }