Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Partition.cpp
index da32aac178c22a3cdeb4b15d3aae532d02c7a80a..8ba553f1a58cfb17e862e51110b2dc484e5e17eb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  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
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "FeaturesAPI_Partition.h"
 #include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
 
+
+static const double DEFAULT_FUZZY = 1.e-5;
+
+
 //==================================================================================================
 FeaturesAPI_Partition::FeaturesAPI_Partition(const std::shared_ptr<ModelAPI_Feature>& theFeature)
 : ModelHighAPI_Interface(theFeature)
@@ -31,12 +34,25 @@ FeaturesAPI_Partition::FeaturesAPI_Partition(const std::shared_ptr<ModelAPI_Feat
 }
 
 //==================================================================================================
-FeaturesAPI_Partition::FeaturesAPI_Partition(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                                          const std::list<ModelHighAPI_Selection>& theBaseObjects)
+FeaturesAPI_Partition::FeaturesAPI_Partition(
+    const std::shared_ptr<ModelAPI_Feature>& theFeature,
+    const std::list<ModelHighAPI_Selection>& theBaseObjects,
+    const ModelHighAPI_Double& theFuzzy)
 : ModelHighAPI_Interface(theFeature)
 {
   if(initialize()) {
-    setBase(theBaseObjects);
+    fillAttribute(theBaseObjects, VAR_NAME(baseObjects));
+    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();
   }
 }
 
@@ -49,7 +65,23 @@ FeaturesAPI_Partition::~FeaturesAPI_Partition()
 //==================================================================================================
 void FeaturesAPI_Partition::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
 {
-  fillAttribute(theBaseObjects, mybaseObjects);
+  fillAttribute(theBaseObjects, VAR_NAME(baseObjects));
+
+  execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_Partition::setUseFuzzy(bool theUseFuzzy)
+{
+  fillAttribute(theUseFuzzy, VAR_NAME(useFuzzy));
+
+  execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_Partition::setFuzzy(const ModelHighAPI_Double& theFuzzy)
+{
+  fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
 
   execute();
 }
@@ -62,15 +94,28 @@ void FeaturesAPI_Partition::dump(ModelHighAPI_Dumper& theDumper) const
 
   AttributeSelectionListPtr anAttrObjects =
     aBase->selectionList(FeaturesPlugin_Partition::BASE_OBJECTS_ID());
+  bool aUseFuzzy = aBase->boolean(FeaturesPlugin_Partition::USE_FUZZY_ID())->value();
+  AttributeDoublePtr aFuzzy = aBase->real(FeaturesPlugin_Partition::FUZZY_PARAM_ID());
+
+  theDumper << aBase << " = model.addPartition(" << aDocName << ", " << anAttrObjects;
+
+  if (aUseFuzzy)
+    theDumper << ", fuzzyParam = " << aFuzzy;
+
+  if (!aBase->data()->version().empty())
+    theDumper << ", keepSubResults = True";
 
-  theDumper << aBase << " = model.addPartition(" << aDocName <<
-    ", " << anAttrObjects << ")" << std::endl;
+  theDumper << ")" << std::endl;
 }
 
 //==================================================================================================
 PartitionPtr addPartition(const std::shared_ptr<ModelAPI_Document>& thePart,
-                          const std::list<ModelHighAPI_Selection>& theBaseObjects)
+                          const std::list<ModelHighAPI_Selection>& theBaseObjects,
+                          const ModelHighAPI_Double& theFuzzy,
+                          const bool keepSubResults)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Partition::ID());
-  return PartitionPtr(new FeaturesAPI_Partition(aFeature, theBaseObjects));
+  if (!keepSubResults)
+    aFeature->data()->setVersion("");
+  return PartitionPtr(new FeaturesAPI_Partition(aFeature, theBaseObjects, theFuzzy));
 }