Salome HOME
fixed usage of fuzzy value as parameter in API
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_BooleanCommon.cpp
index 7b8fe4217c42b2b17904ffb9287fdd05b8cceb47..265e7c7fdc6692cc0cbc780ea2e11eefcbe5e781 100644 (file)
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
 
+
+static const double DEFAULT_FUZZY = 1.e-5;
+
+
 //==================================================================================================
 FeaturesAPI_BooleanCommon::FeaturesAPI_BooleanCommon(
   const std::shared_ptr<ModelAPI_Feature>& theFeature)
@@ -39,9 +43,17 @@ FeaturesAPI_BooleanCommon::FeaturesAPI_BooleanCommon(
 : ModelHighAPI_Interface(theFeature)
 {
   if(initialize()) {
-    fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE(), mycreationMethod);
-    fillAttribute(theMainObjects, mymainObjects);
-    fillAttribute(theFuzzy, myfuzzyValue);
+    fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE(), VAR_NAME(creationMethod));
+    fillAttribute(theMainObjects, VAR_NAME(mainObjects));
+    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);
   }
@@ -56,10 +68,18 @@ FeaturesAPI_BooleanCommon::FeaturesAPI_BooleanCommon(
 : ModelHighAPI_Interface(theFeature)
 {
   if(initialize()) {
-    fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), mycreationMethod);
-    fillAttribute(theMainObjects, mymainObjects);
-    fillAttribute(theToolObjects, mytoolObjects);
-    fillAttribute(theFuzzy, myfuzzyValue);
+    fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
+    fillAttribute(theMainObjects, VAR_NAME(mainObjects));
+    fillAttribute(theToolObjects, VAR_NAME(toolObjects));
+    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 +95,7 @@ FeaturesAPI_BooleanCommon::~FeaturesAPI_BooleanCommon()
 void FeaturesAPI_BooleanCommon::setMainObjects(
   const std::list<ModelHighAPI_Selection>& theMainObjects)
 {
-  fillAttribute(theMainObjects, mymainObjects);
+  fillAttribute(theMainObjects, VAR_NAME(mainObjects));
 
   execute();
 }
@@ -84,8 +104,16 @@ void FeaturesAPI_BooleanCommon::setMainObjects(
 void FeaturesAPI_BooleanCommon::setToolObjects(
   const std::list<ModelHighAPI_Selection>& theToolObjects)
 {
-  fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), mycreationMethod);
-  fillAttribute(theToolObjects, mytoolObjects);
+  fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
+  fillAttribute(theToolObjects, VAR_NAME(toolObjects));
+
+  execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_BooleanCommon::setUseFuzzy(bool theUseFuzzy)
+{
+  fillAttribute(theUseFuzzy, VAR_NAME(useFuzzy));
 
   execute();
 }
@@ -93,7 +121,7 @@ void FeaturesAPI_BooleanCommon::setToolObjects(
 //==================================================================================================
 void FeaturesAPI_BooleanCommon::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
 {
-  fillAttribute(theFuzzy, myfuzzyValue);
+  fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
 
   execute();
 }
@@ -102,9 +130,9 @@ void FeaturesAPI_BooleanCommon::setFuzzyValue(const ModelHighAPI_Double& theFuzz
 void FeaturesAPI_BooleanCommon::setAdvancedMode(const bool theMode)
 {
   if (theMode) {
-    fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), mycreationMethod);
+    fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
   } else {
-    fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE(), mycreationMethod);
+    fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE(), VAR_NAME(creationMethod));
   }
 
   execute();
@@ -123,7 +151,8 @@ void FeaturesAPI_BooleanCommon::dump(ModelHighAPI_Dumper& theDumper) const
     aBase->selectionList(FeaturesPlugin_BooleanCommon::OBJECT_LIST_ID());
   AttributeSelectionListPtr aTools =
     aBase->selectionList(FeaturesPlugin_BooleanCommon::TOOL_LIST_ID());
-  double aFuzzy = aBase->real(FeaturesPlugin_BooleanCommon::FUZZY_PARAM_ID())->value();
+  bool aUseFuzzy = aBase->boolean(FeaturesPlugin_BooleanCommon::USE_FUZZY_ID())->value();
+  AttributeDoublePtr aFuzzy = aBase->real(FeaturesPlugin_BooleanCommon::FUZZY_PARAM_ID());
 
   theDumper << "(" << aDocName << ", " << anObjects;
 
@@ -131,7 +160,8 @@ void FeaturesAPI_BooleanCommon::dump(ModelHighAPI_Dumper& theDumper) const
     theDumper << ", " << aTools;
   }
 
-  theDumper << ", fuzzyParam = " << aFuzzy;
+  if (aUseFuzzy)
+    theDumper << ", fuzzyParam = " << aFuzzy;
 
   if (!aBase->data()->version().empty())
     theDumper << ", keepSubResults = True";
@@ -143,7 +173,7 @@ void FeaturesAPI_BooleanCommon::dump(ModelHighAPI_Dumper& theDumper) const
 BooleanCommonPtr addCommon(const std::shared_ptr<ModelAPI_Document>& thePart,
                            const std::list<ModelHighAPI_Selection>& theMainObjects,
                            const std::list<ModelHighAPI_Selection>& theToolObjects,
-                           const ModelHighAPI_Double& fuzzyParam,
+                           const ModelHighAPI_Double& theFuzzy,
                            const bool keepSubResults)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanCommon::ID());
@@ -151,8 +181,8 @@ BooleanCommonPtr addCommon(const std::shared_ptr<ModelAPI_Document>& thePart,
     aFeature->data()->setVersion("");
   BooleanCommonPtr aCommon;
   if (theToolObjects.empty())
-    aCommon.reset(new FeaturesAPI_BooleanCommon(aFeature, theMainObjects, fuzzyParam));
+    aCommon.reset(new FeaturesAPI_BooleanCommon(aFeature, theMainObjects, theFuzzy));
   else
-    aCommon.reset(new FeaturesAPI_BooleanCommon(aFeature, theMainObjects, theToolObjects, fuzzyParam));
+    aCommon.reset(new FeaturesAPI_BooleanCommon(aFeature, theMainObjects, theToolObjects, theFuzzy));
   return aCommon;
 }