]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
New "Combine" flag for partition
authordbv <dbv@opencascade.com>
Thu, 17 Sep 2015 14:37:24 +0000 (17:37 +0300)
committerdbv <dbv@opencascade.com>
Thu, 17 Sep 2015 14:37:48 +0000 (17:37 +0300)
src/FeaturesPlugin/FeaturesPlugin_Partition.cpp
src/FeaturesPlugin/FeaturesPlugin_Partition.h
src/FeaturesPlugin/partition_widget.xml
src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp

index e165b5a760e3e7ad619a796e802d2e26a1a6a183..44ab7cc84a963cefda27dc903aa8b82d05137dce 100755 (executable)
@@ -8,6 +8,7 @@
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_BodyBuilder.h>
@@ -39,8 +40,9 @@ void FeaturesPlugin_Partition::initAttributes()
     FeaturesPlugin_Partition::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
   aSelection->setSelectionType("SOLID");
 
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
+
+  data()->addAttribute(COMBINE_ID(), ModelAPI_AttributeBoolean::typeId());
 }
 
 //=================================================================================================
@@ -97,19 +99,20 @@ void FeaturesPlugin_Partition::execute()
     }
   }
 
-  int aResultIndex = 0;
+  // Getting combine flag.
+  bool isCombine = boolean(COMBINE_ID())->value();
 
-  if (anObjects.empty() || aTools.empty()) {
+  if(anObjects.empty()/* || aTools.empty()*/) {
     std::string aFeatureError = "Not enough objects for partition operation";
     setError(aFeatureError);
     return;
   }
 
-  // Cut each object with all tools
-  for (ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
-    std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
-    ListOfShape aListWithObject; aListWithObject.push_back(anObject);
-    GeomAlgoAPI_Partition aPartitionAlgo(aListWithObject, aTools);
+  int aResultIndex = 0;
+
+  if(isCombine) {
+    // Create single result.
+    GeomAlgoAPI_Partition aPartitionAlgo(anObjects, aTools);
 
     // Checking that the algorithm worked properly.
     if (!aPartitionAlgo.isDone()) {
@@ -132,10 +135,43 @@ void FeaturesPlugin_Partition::execute()
       std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
       aMakeShapeList.append(aPartitionAlgo.makeShape());
       GeomAPI_DataMapOfShapeShape aMapOfShapes = *aPartitionAlgo.mapOfShapes().get();
-      loadNamingDS(aResultBody, anObject, aToolsForNaming, aPartitionAlgo.shape(), aMakeShapeList, aMapOfShapes);
+      loadNamingDS(aResultBody, anObjects.front(), aToolsForNaming, aPartitionAlgo.shape(), aMakeShapeList, aMapOfShapes);
       setResult(aResultBody, aResultIndex);
       aResultIndex++;
     }
+  } else {
+    // Create result for each object.
+    for (ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
+      std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
+      ListOfShape aListWithObject; aListWithObject.push_back(anObject);
+      GeomAlgoAPI_Partition aPartitionAlgo(aListWithObject, aTools);
+
+      // Checking that the algorithm worked properly.
+      if (!aPartitionAlgo.isDone()) {
+        static const std::string aFeatureError = "Partition algorithm failed";
+        setError(aFeatureError);
+        return;
+      }
+      if (aPartitionAlgo.shape()->isNull()) {
+        static const std::string aShapeError = "Resulting shape is Null";
+        setError(aShapeError);
+        return;
+      }
+      if (!aPartitionAlgo.isValid()) {
+        std::string aFeatureError = "Warning: resulting shape is not valid";
+        setError(aFeatureError);
+        return;
+      }
+
+      if (GeomAlgoAPI_ShapeTools::volume(aPartitionAlgo.shape()) > 1.e-7) {
+        std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
+        aMakeShapeList.append(aPartitionAlgo.makeShape());
+        GeomAPI_DataMapOfShapeShape aMapOfShapes = *aPartitionAlgo.mapOfShapes().get();
+        loadNamingDS(aResultBody, anObject, aToolsForNaming, aPartitionAlgo.shape(), aMakeShapeList, aMapOfShapes);
+        setResult(aResultBody, aResultIndex);
+        aResultIndex++;
+      }
+    }
   }
 
   // remove the rest results if there were produced in the previous pass
index 9ec475f44baadc8fdc4f7185ab9baae35bf933fb..eaa17dd232f7cecf63aec6bd0bd72f106c69deed 100755 (executable)
@@ -40,6 +40,13 @@ public:
     return MY_TOOL_LIST_ID;
   }
 
+  /// attribute name of combine flag
+  inline static const std::string& COMBINE_ID()
+  {
+    static const std::string MY_COMBINE_ID("partition_combine");
+    return MY_COMBINE_ID;
+  }
+
   /// Returns the kind of a feature
   FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
   {
index 7358bdc5b019901baca58142acf6d9a023b72526..ef693d086a177a1d473d130c074153bb4cb39017 100755 (executable)
     <validator id="PartSet_DifferentObjects"/>
     <validator id="GeomValidators_ShapeType" parameters="solid"/>
   </multi_selector>
-  <multi_selector id="tool_objects" 
-    label="Tool object" 
-    icon=":icons/cut_tool.png" 
+  <multi_selector id="tool_objects"
+    label="Tool object"
+    icon=":icons/cut_tool.png"
     tooltip="Select a tool face or solid"
     type_choice="Faces Solids"
     use_choice="false"
-    concealment="true" >
+    concealment="true">
     <validator id="PartSet_DifferentObjects"/>
-    <validator id="GeomValidators_ShapeType" parameters="solid,plane"/>
+    <validator id="GeomValidators_ShapeType" parameters="solid,plane,empty"/>
   </multi_selector>
+  <boolvalue id="partition_combine"
+    label="Combine results"
+    default="true"
+    tooltip="If True combines all results to one. If False builds separate result for each object."/>
 </source>
index edc34324b8242e98b05b1c721bd571a71c88f11e..cf5dd741a0c6af51645900fd3e420cfd1efaeebb 100644 (file)
@@ -40,7 +40,7 @@ GeomAlgoAPI_Partition::GeomAlgoAPI_Partition(const ListOfShape& theObjects,
 void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects,
                                   const ListOfShape& theTools)
 {
-  if (theObjects.empty() || theTools.empty()) {
+  if (theObjects.empty()) {
     return;
   }