Salome HOME
Copyright update 2021
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_BooleanFuse.cpp
index c1a043d6746f0eadb7dc34e3b82c2d98cb074352..34c47f3bd630d6dd33f01790facf09d54668dc48 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  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,12 +35,31 @@ FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
 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)
+  : ModelHighAPI_Interface(theFeature)
+{
+  if (initialize()) {
+    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
+    fillAttribute(theMainObjects, mymainObjects);
+    fillAttribute(theRemoveEdges, myremoveEdges);
+
+    execute(false);
+  }
+}
+
+//==================================================================================================
+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)
 : ModelHighAPI_Interface(theFeature)
 {
   if(initialize()) {
+    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
     fillAttribute(theMainObjects, mymainObjects);
     fillAttribute(theToolObjects, mytoolObjects);
+    fillAttribute(theRemoveEdges, myremoveEdges);
 
     execute(false);
   }
@@ -66,11 +84,32 @@ 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();
 }
 
+//==================================================================================================
+void FeaturesAPI_BooleanFuse::setRemoveEdges(const bool theRemoveEdges)
+{
+  fillAttribute(theRemoveEdges, myremoveEdges);
+
+  execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_BooleanFuse::setAdvancedMode(const bool theMode)
+{
+  if (theMode) {
+    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
+  } else {
+    fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
+  }
+
+  execute();
+}
+
 //==================================================================================================
 void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
 {
@@ -79,32 +118,51 @@ void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
   theDumper << aBase << " = model.addFuse";
 
   const std::string& aDocName = theDumper.name(aBase->document());
+  AttributeStringPtr aMode = aBase->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD());
   AttributeSelectionListPtr anObjects =
     aBase->selectionList(FeaturesPlugin_BooleanFuse::OBJECT_LIST_ID());
   AttributeSelectionListPtr aTools =
     aBase->selectionList(FeaturesPlugin_BooleanFuse::TOOL_LIST_ID());
+  AttributeBooleanPtr aRemoveEdges =
+    aBase->boolean(FeaturesPlugin_BooleanFuse::REMOVE_INTERSECTION_EDGES_ID());
 
-  theDumper << "(" << aDocName << ", " << anObjects << ", " << aTools << ")" << std::endl;
-}
+  theDumper << "(" << aDocName << ", " << anObjects;
 
-//==================================================================================================
-BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
-                       const std::list<ModelHighAPI_Selection>& theObjects)
-{
-  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
-  std::list<ModelHighAPI_Selection> aToolObjects;
-  return BooleanFusePtr(new FeaturesAPI_BooleanFuse(aFeature,
-                                                    theObjects,
-                                                    aToolObjects));
+  if (aMode->value() == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
+    theDumper << ", " << aTools;
+  }
+
+  if (aRemoveEdges->value()) {
+    theDumper << ", removeEdges = True";
+  }
+
+  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 std::list<ModelHighAPI_Selection>& theMainObjects,
+                       const std::pair<std::list<ModelHighAPI_Selection>, bool>& theToolObjects,
+                       const bool theRemoveEdges,
+                       const bool keepSubResults)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
-  return BooleanFusePtr(new FeaturesAPI_BooleanFuse(aFeature,
-                                                    theMainObjects,
-                                                    theToolObjects));
+  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));
+  else {
+    aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, theToolObjects.first,
+                                            aRemoveEdges));
+  }
+  return aFuse;
 }