Salome HOME
Make SHAPER STUDY fields exported in SMESH into MED file
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_BooleanFuse.cpp
index d92cd797673014dcf984cc385c7aae5191fb2393..a80b069082843fd50028d1f6d5ef34350cd8f5c2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // 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_BooleanFuse.h"
@@ -36,11 +35,13 @@ 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 int theVersion)
   : ModelHighAPI_Interface(theFeature)
 {
   if (initialize()) {
     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
+    fillAttribute(theVersion, theFeature->integer(FeaturesPlugin_Boolean::VERSION_ID()));
     fillAttribute(theMainObjects, mymainObjects);
     fillAttribute(theRemoveEdges, myremoveEdges);
 
@@ -53,11 +54,13 @@ 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 int theVersion)
 : ModelHighAPI_Interface(theFeature)
 {
   if(initialize()) {
     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
+    fillAttribute(theVersion, theFeature->integer(FeaturesPlugin_Boolean::VERSION_ID()));
     fillAttribute(theMainObjects, mymainObjects);
     fillAttribute(theToolObjects, mytoolObjects);
     fillAttribute(theRemoveEdges, myremoveEdges);
@@ -85,6 +88,7 @@ void FeaturesAPI_BooleanFuse::setMainObjects(
 void FeaturesAPI_BooleanFuse::setToolObjects(
   const std::list<ModelHighAPI_Selection>& theToolObjects)
 {
+  fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
   fillAttribute(theToolObjects, mytoolObjects);
 
   execute();
@@ -106,6 +110,8 @@ void FeaturesAPI_BooleanFuse::setAdvancedMode(const bool theMode)
   } else {
     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
   }
+
+  execute();
 }
 
 //==================================================================================================
@@ -123,6 +129,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());
+  AttributeIntegerPtr aVersion =
+    aBase->integer(FeaturesPlugin_BooleanFuse::VERSION_ID());
 
   theDumper << "(" << aDocName << ", " << anObjects;
 
@@ -131,32 +139,58 @@ void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
   }
 
   if (aRemoveEdges->value()) {
-    theDumper << ", " << true;
+    theDumper << ", removeEdges = True";
+  }
+
+  if (aVersion && aVersion->isInitialized() &&
+      aVersion->value() == FeaturesPlugin_VersionedBoolean::THE_VERSION_1) {
+    theDumper << ", keepSubResults = True";
   }
 
   theDumper << ")" << std::endl;
 }
 
 //==================================================================================================
-BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
-                       const std::list<ModelHighAPI_Selection>& theObjects,
-                       const bool theRemoveEdges)
+static BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
+                              const std::list<ModelHighAPI_Selection>& theObjects,
+                              const bool theRemoveEdges,
+                              const int theVersion)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
   return BooleanFusePtr(new FeaturesAPI_BooleanFuse(aFeature,
                                                     theObjects,
-                                                    theRemoveEdges));
+                                                    theRemoveEdges,
+                                                    theVersion));
 }
 
 //==================================================================================================
-BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
-                   const std::list<ModelHighAPI_Selection>& theMainObjects,
-                   const std::list<ModelHighAPI_Selection>& theToolObjects,
-                   const bool theRemoveEdges)
+static 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 int theVersion)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
   return BooleanFusePtr(new FeaturesAPI_BooleanFuse(aFeature,
                                                     theMainObjects,
                                                     theToolObjects,
-                                                    theRemoveEdges));
+                                                    theRemoveEdges,
+                                                    theVersion));
+}
+
+//==================================================================================================
+BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
+                       const std::list<ModelHighAPI_Selection>& theMainObjects,
+                       const std::pair<std::list<ModelHighAPI_Selection>, bool>& theToolObjects,
+                       const bool theRemoveEdges,
+                       const bool keepSubResults)
+{
+  int aVersion = keepSubResults ? FeaturesPlugin_VersionedBoolean::THE_VERSION_1
+                                : FeaturesPlugin_VersionedBoolean::THE_VERSION_0;
+  bool aRemoveEdges = theRemoveEdges;
+  if (theToolObjects.first.empty())
+    aRemoveEdges = aRemoveEdges || theToolObjects.second;
+  return theToolObjects.first.empty() ?
+      addFuse(thePart, theMainObjects, aRemoveEdges, aVersion) :
+      addFuse(thePart, theMainObjects, theToolObjects.first, aRemoveEdges, aVersion);
 }