Salome HOME
Issue #1367: Fill feature.
authordbv <dbv@opencascade.com>
Wed, 18 May 2016 09:25:10 +0000 (12:25 +0300)
committerdbv <dbv@opencascade.com>
Wed, 18 May 2016 09:25:31 +0000 (12:25 +0300)
22 files changed:
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
src/FeaturesPlugin/FeaturesPlugin_Boolean.h
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.h
src/FeaturesPlugin/boolean_widget.xml
src/FeaturesPlugin/icons/bool_common.png
src/FeaturesPlugin/icons/bool_cut.png
src/FeaturesPlugin/icons/bool_fill.png [new file with mode: 0644]
src/FeaturesPlugin/icons/bool_fuse.png
src/FeaturesPlugin/icons/bool_smash.png
src/GeomAlgoAPI/GeomAlgoAPI_Boolean.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Partition.cpp
src/GeomAlgoAPI/GeomAlgoAPI_PaveFiller.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Prism.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Revolution.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_BooleanSelection.cpp [deleted file]
src/GeomValidators/GeomValidators_BooleanSelection.h [deleted file]
src/GeomValidators/GeomValidators_Plugin.cpp

index 6e0d65be1e9ac60fd73112bfe13bc922b4e052f1..065e065fc0556781bc527c226bb086f8a0d94cb7 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <GeomAlgoAPI_Boolean.h>
 #include <GeomAlgoAPI_MakeShapeList.h>
+#include <GeomAlgoAPI_Partition.h>
 #include <GeomAlgoAPI_PaveFiller.h>
 #include <GeomAlgoAPI_ShapeTools.h>
 #include <GeomAPI_ShapeExplorer.h>
@@ -129,7 +130,8 @@ void FeaturesPlugin_Boolean::execute()
 
   switch(aType) {
     case BOOL_CUT:
-    case BOOL_COMMON:{
+    case BOOL_COMMON:
+    case BOOL_FILL: {
       if((anObjects.empty() && aCompSolidsObjects.empty()) || aTools.empty()) {
         std::string aFeatureError = "Error: Not enough objects for boolean operation.";
         setError(aFeatureError);
@@ -141,7 +143,13 @@ void FeaturesPlugin_Boolean::execute()
         std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
         ListOfShape aListWithObject;
         aListWithObject.push_back(anObject);
-        GeomAlgoAPI_Boolean aBoolAlgo(aListWithObject, aTools, (GeomAlgoAPI_Boolean::OperationType)aType);
+        GeomAlgoAPI_MakeShape aBoolAlgo; (aListWithObject, aTools, (GeomAlgoAPI_Boolean::OperationType)aType);
+
+        switch(aType) {
+          case BOOL_CUT:    aBoolAlgo = GeomAlgoAPI_Boolean(aListWithObject, aTools, GeomAlgoAPI_Boolean::BOOL_CUT); break;
+          case BOOL_COMMON: aBoolAlgo = GeomAlgoAPI_Boolean(aListWithObject, aTools, GeomAlgoAPI_Boolean::BOOL_COMMON); break;
+          case BOOL_FILL:   aBoolAlgo = GeomAlgoAPI_Partition(aListWithObject, aTools); break;
+        }
 
         // Checking that the algorithm worked properly.
         if(!aBoolAlgo.isDone()) {
@@ -189,9 +197,26 @@ void FeaturesPlugin_Boolean::execute()
           }
         }
 
-        std::shared_ptr<GeomAlgoAPI_Boolean> aBoolAlgo(new GeomAlgoAPI_Boolean(aUsedInOperationSolids,
-                                                                               aTools,
-                                                                               (GeomAlgoAPI_Boolean::OperationType)aType));
+        std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
+
+        switch(aType) {
+          case BOOL_CUT: {
+            aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aUsedInOperationSolids,
+                                                    aTools,
+                                                    GeomAlgoAPI_Boolean::BOOL_CUT));
+            break;
+          }
+          case BOOL_COMMON: {
+            aBoolAlgo.reset(new GeomAlgoAPI_Boolean(aUsedInOperationSolids,
+                                                    aTools,
+                                                    GeomAlgoAPI_Boolean::BOOL_COMMON));
+            break;
+          }
+          case BOOL_FILL: {
+            aBoolAlgo.reset(new GeomAlgoAPI_Partition(aUsedInOperationSolids, aTools));
+            break;
+          }
+        }
 
         // Checking that the algorithm worked properly.
         if(!aBoolAlgo->isDone()) {
index fd25cff88e439979e86532865f70d4be7c321e08..79d703174c72fae4afa847ed76a798e11263b17f 100644 (file)
@@ -24,6 +24,7 @@ public:
     BOOL_CUT,
     BOOL_FUSE,
     BOOL_COMMON,
+    BOOL_FILL,
     BOOL_SMASH
   };
 
index efb079e151c6b5243141c50f8c29d950320516e0..4bea20fc2c1bc1f763bb5248c69228c33b8fff85 100644 (file)
@@ -44,6 +44,8 @@ FeaturesPlugin_Plugin::FeaturesPlugin_Plugin()
                               new FeaturesPlugin_ValidatorPipeLocations);
   aFactory->registerValidator("FeaturesPlugin_ValidatorCanBeEmpty",
                               new FeaturesPlugin_ValidatorCanBeEmpty);
+  aFactory->registerValidator("FeaturesPlugin_BooleanSelection",
+                              new FeaturesPlugin_BooleanSelection);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index 83ab5ed7515e82e4bd397422b2d8465bb47812ab..37d03e3a9476a17a8a9406e106dd921346da2b95 100644 (file)
@@ -7,10 +7,12 @@
 #include "FeaturesPlugin_Validators.h"
 
 #include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
-#include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultConstruction.h>
 
 #include <Events_Error.h>
 
@@ -22,7 +24,7 @@
 #include <GeomAPI_ShapeExplorer.h>
 #include <GeomAlgoAPI_WireBuilder.h>
 
-//=================================================================================================
+//==================================================================================================
 bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                                     const std::list<std::string>& theArguments,
                                                     std::string& theError) const
@@ -66,13 +68,13 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr<ModelA
   return true;
 }
 
-//=================================================================================================
+//==================================================================================================
 bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeature, std::string theAttribute)
 {
   return false;
 }
 
-//=================================================================================================
+//==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
                                                         std::string& theError) const
@@ -143,7 +145,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
   return true;
 }
 
-//=================================================================================================
+//==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
                                                                  const std::list<std::string>& theArguments,
                                                                  std::string& theError) const
@@ -231,7 +233,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
   return true;
 }
 
-//=================================================================================================
+//==================================================================================================
 bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
                                                         std::string& theError) const
@@ -276,7 +278,7 @@ bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theA
   return aValid;
 }
 
-//=================================================================================================
+//==================================================================================================
 bool FeaturesPlugin_ValidatorCanBeEmpty::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                                  const std::list<std::string>& theArguments,
                                                  std::string& theError) const
@@ -322,13 +324,13 @@ bool FeaturesPlugin_ValidatorCanBeEmpty::isValid(const std::shared_ptr<ModelAPI_
   return true;
 }
 
-//=================================================================================================
+//==================================================================================================
 bool FeaturesPlugin_ValidatorCanBeEmpty::isNotObligatory(std::string theFeature, std::string theAttribute)
 {
   return false;
 }
 
-//=================================================================================================
+//==================================================================================================
 bool FeaturesPlugin_ValidatorCanBeEmpty::isShapesCanBeEmpty(const AttributePtr& theAttribute,
                                                             std::string& theError) const
 {
@@ -374,7 +376,7 @@ bool FeaturesPlugin_ValidatorCanBeEmpty::isShapesCanBeEmpty(const AttributePtr&
   return true;
 }
 
-//=================================================================================================
+//==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
                                                   const std::list<std::string>& theArguments,
                                                   std::string& theError) const
@@ -456,4 +458,66 @@ bool FeaturesPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribu
   }
 
   return true;
-}
\ No newline at end of file
+}
+
+//==================================================================================================
+bool FeaturesPlugin_BooleanSelection::isValid(const AttributePtr& theAttribute,
+                                              const std::list<std::string>& theArguments,
+                                              std::string& theError) const
+{
+  AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if(!anAttrSelectionList.get()) {
+    theError = "Error: this validator can only work with selection list attributes in Boolean feature.";
+    return false;
+  }
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  int anOperationType = aFeature->integer("bool_type")->value();
+
+  for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+    if(!anAttrSelection.get()) {
+      theError = "Error: empty attribute selection.";
+      return false;
+    }
+    ResultPtr aContext = anAttrSelection->context();
+    if(!aContext.get()) {
+      theError = "Error: empty selection context.";
+      return false;
+    }
+    ResultConstructionPtr aResultConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    if(aResultConstruction.get()) {
+      theError = "Error: Result construction not allowed for selection.";
+      return false;
+    }
+    std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+    if(!aShape.get()) {
+      aShape = aContext->shape();
+    }
+    if(!aShape.get()) {
+      theError = "Error: empty shape.";
+      return false;
+    }
+    int aShapeType = aShape->shapeType();
+    if(anOperationType == 1) {
+      // Fuse operation. Allow to select edges, faces and solids.
+      if(aShapeType != GeomAPI_Shape::EDGE &&
+         aShapeType != GeomAPI_Shape::FACE &&
+         aShapeType != GeomAPI_Shape::SOLID &&
+         aShapeType != GeomAPI_Shape::COMPSOLID &&
+         aShapeType != GeomAPI_Shape::COMPOUND) {
+        theError = "Error: selected shape has the wrong type.";
+        return false;
+      }
+    } else {
+      if(aShapeType != GeomAPI_Shape::SOLID &&
+         aShapeType != GeomAPI_Shape::COMPSOLID &&
+         aShapeType != GeomAPI_Shape::COMPOUND) {
+        theError = "Error: selected shape has the wrong type.";
+        return false;
+      }
+    }
+  }
+
+  return true;
+}
index 66006583f85656277ed0d334283aa539eba35fbd..1b957a7772bd37f3a405bfdb74699e5025bcdab8 100644 (file)
@@ -66,9 +66,8 @@ public:
 
 /// \class FeaturesPlugin_ValidatorCanBeEmpty
 /// \ingroup Validators
-/// \brief A validator for extrusion direction attribute and bounding planes for extrusion and
-///        revolution. Allows them to be empty if base objects are planar and do not contain
-///        vertices and edges.
+/// \brief A validator for extrusion direction attribute. Allows it to be empty if base objects are
+///        planar and do not contain vertices and edges.
 class FeaturesPlugin_ValidatorCanBeEmpty: public ModelAPI_FeatureValidator
 {
 public:
@@ -104,4 +103,20 @@ public:
                         std::string& theError) const;
 };
 
+/// \class FeaturesPlugin_BooleanSelection
+/// \ingroup Validators
+/// \brief Validates selection for boolean operation.
+class FeaturesPlugin_BooleanSelection: public ModelAPI_AttributeValidator
+{
+public:
+  /// \return True if the attribute is valid. It checks whether the selection
+  /// is acceptable for boolean operation.
+  /// \param[in] theAttribute an attribute to check.
+  /// \param[in] theArguments a filter parameters.
+  /// \param[out] theError error message.
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments,
+                       std::string& theError) const;
+};
+
 #endif
index 53a10a97bb7b7239dff50bda2c9afe6c1a179b55..3d1a0ac58cd00c5d4598a13e4a680901c1ef4e9c 100644 (file)
@@ -6,9 +6,9 @@
     buttons_dir="horizontal"
     label="Operation type" 
     tooltip="Type of boolean operation"
-    string_list="Cut Fuse Common Smash"
+    string_list="Cut Fuse Common Fill Smash"
     use_in_title="true"
-    icons_list="icons/Features/bool_cut.png icons/Features/bool_fuse.png icons/Features/bool_common.png icons/Features/bool_smash.png"
+    icons_list="icons/Features/bool_cut.png icons/Features/bool_fuse.png icons/Features/bool_common.png icons/Features/bool_fill.png icons/Features/bool_smash.png"
     default="0"
   />
   <multi_selector id="main_objects"
@@ -19,8 +19,7 @@
     use_choice="false"
     concealment="true">
     <validator id="PartSet_DifferentObjects"/>
-    <!--<validator id="GeomValidators_ShapeType" parameters="empty,edge,face,solid"/>-->
-    <validator id="GeomValidators_BooleanSelection"/>
+    <validator id="FeaturesPlugin_BooleanSelection"/>
   </multi_selector>
   <multi_selector id="tool_objects"
     label="Tool objects"
@@ -30,8 +29,7 @@
     use_choice="false"
     concealment="true" >
     <validator id="PartSet_DifferentObjects"/>
-    <!--<validator id="GeomValidators_ShapeType" parameters="empty,edge,face,solid"/>-->
-    <validator id="GeomValidators_BooleanSelection"/>
+    <validator id="FeaturesPlugin_BooleanSelection"/>
   </multi_selector>
   <validator id="GeomValidators_BooleanArguments" parameters="main_objects,tool_objects,bool_type"/>
 </source>
index 99812c5462d3b982f58000b90fb47f0fd3bc62c9..c8f86a1a3affb83365a20df6f61dab961249b6c6 100644 (file)
Binary files a/src/FeaturesPlugin/icons/bool_common.png and b/src/FeaturesPlugin/icons/bool_common.png differ
index dd494d7d8062adcfddb9978346b23552812a0618..8f52d3aaca65404f3abb45667f0efec565cedd37 100644 (file)
Binary files a/src/FeaturesPlugin/icons/bool_cut.png and b/src/FeaturesPlugin/icons/bool_cut.png differ
diff --git a/src/FeaturesPlugin/icons/bool_fill.png b/src/FeaturesPlugin/icons/bool_fill.png
new file mode 100644 (file)
index 0000000..5e03aa2
Binary files /dev/null and b/src/FeaturesPlugin/icons/bool_fill.png differ
index 5369a50a5159c73e42a900c55ad80de5e4bfb25a..b005af12d4b64db470f5e3a8b24e16ab99abe354 100644 (file)
Binary files a/src/FeaturesPlugin/icons/bool_fuse.png and b/src/FeaturesPlugin/icons/bool_fuse.png differ
index bf82ac2721784eeac71e0a10de1f69de36252a50..6a12a0a763be7843b2b7112f73888887fde3c307 100644 (file)
Binary files a/src/FeaturesPlugin/icons/bool_smash.png and b/src/FeaturesPlugin/icons/bool_smash.png differ
index 2fa01fadd233ebf49337a72921f286b9fec114b4..21458a9ce2ab14459e803371484d2342e0b391c5 100644 (file)
@@ -7,6 +7,7 @@
 #include "GeomAlgoAPI_Boolean.h"
 
 #include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 
 #include <BOPAlgo_BOP.hxx>
 #include <TopTools_ListOfShape.hxx>
@@ -77,6 +78,16 @@ void GeomAlgoAPI_Boolean::build(const ListOfShape& theObjects,
   if(aResult.ShapeType() == TopAbs_COMPOUND) {
     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
   }
+  if(aResult.ShapeType() == TopAbs_COMPOUND) {
+    std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+    aGeomShape->setImpl(new TopoDS_Shape(aResult));
+    ListOfShape aCompSolids, aFreeSolids;
+    aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
+                                                       GeomAPI_Shape::COMPSOLID,
+                                                       aCompSolids,
+                                                       aFreeSolids);
+    aResult = aGeomShape->impl<TopoDS_Shape>();
+  }
 
   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
   aShape->setImpl(new TopoDS_Shape(aResult));
index 55455220c3f2ecc2120d056c719c777e581fd56c..7034f9d4c853e4c52170b13c6a191e4c27545a5e 100644 (file)
@@ -69,24 +69,14 @@ void GeomAlgoAPI_Partition::build(const ListOfShape& theObjects,
     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
   }
   if(aResult.ShapeType() == TopAbs_COMPOUND) {
-    std::shared_ptr<GeomAPI_Shape> aCompound(new GeomAPI_Shape);
-    aCompound->setImpl(new TopoDS_Shape(aResult));
+    std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+    aGeomShape->setImpl(new TopoDS_Shape(aResult));
     ListOfShape aCompSolids, aFreeSolids;
-    GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCompSolids, aFreeSolids);
-    if(aCompSolids.size() == 1 && aFreeSolids.size() == 0) {
-      aResult = aCompSolids.front()->impl<TopoDS_Shape>();
-    } else if (aCompSolids.size() > 1 || (aCompSolids.size() >= 1 && aFreeSolids.size() >= 1)) {
-      TopoDS_Compound aResultComp;
-      TopoDS_Builder aBuilder;
-      aBuilder.MakeCompound(aResultComp);
-      for(ListOfShape::const_iterator anIter = aCompSolids.cbegin(); anIter != aCompSolids.cend(); anIter++) {
-        aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
-      }
-      for(ListOfShape::const_iterator anIter = aFreeSolids.cbegin(); anIter != aFreeSolids.cend(); anIter++) {
-        aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
-      }
-      aResult = aResultComp;
-    }
+    aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
+                                                       GeomAPI_Shape::COMPSOLID,
+                                                       aCompSolids,
+                                                       aFreeSolids);
+    aResult = aGeomShape->impl<TopoDS_Shape>();
   }
 
   // Setting result.
index 3dd1cb0b0b7fffd70f4918754dee048bacc0e34b..6f9d183aa051b982da4108e6d5c6ff1619bc5d95 100644 (file)
@@ -58,24 +58,14 @@ void GeomAlgoAPI_PaveFiller::build(const ListOfShape& theListOfShape, const bool
     aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
   }
   if(theIsMakeCompSolids && aResult.ShapeType() == TopAbs_COMPOUND) {
-    std::shared_ptr<GeomAPI_Shape> aCompound(new GeomAPI_Shape);
-    aCompound->setImpl(new TopoDS_Shape(aResult));
+    std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+    aGeomShape->setImpl(new TopoDS_Shape(aResult));
     ListOfShape aCompSolids, aFreeSolids;
-    GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCompSolids, aFreeSolids);
-    if(aCompSolids.size() == 1 && aFreeSolids.size() == 0) {
-      aResult = aCompSolids.front()->impl<TopoDS_Shape>();
-    } else if (aCompSolids.size() > 1 || (aCompSolids.size() >= 1 && aFreeSolids.size() >= 1)) {
-      TopoDS_Compound aResultComp;
-      TopoDS_Builder aBuilder;
-      aBuilder.MakeCompound(aResultComp);
-      for(ListOfShape::const_iterator anIter = aCompSolids.cbegin(); anIter != aCompSolids.cend(); anIter++) {
-        aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
-      }
-      for(ListOfShape::const_iterator anIter = aFreeSolids.cbegin(); anIter != aFreeSolids.cend(); anIter++) {
-        aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
-      }
-      aResult = aResultComp;
-    }
+    aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
+                                                       GeomAPI_Shape::COMPSOLID,
+                                                       aCompSolids,
+                                                       aFreeSolids);
+    aResult = aGeomShape->impl<TopoDS_Shape>();
   }
 
   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
index 7f2bd0b49e97e2742956682f097b0c32d4e4306b..0c0136f170cc35a52f49a55d343703fdbe55711c 100644 (file)
@@ -417,24 +417,14 @@ void GeomAlgoAPI_Prism::build(const GeomShapePtr&                theBaseShape,
     }
 
     if(aResult.ShapeType() == TopAbs_COMPOUND) {
-      GeomShapePtr aCompound(new GeomAPI_Shape);
-      aCompound->setImpl(new TopoDS_Shape(aResult));
+      std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+      aGeomShape->setImpl(new TopoDS_Shape(aResult));
       ListOfShape aCompSolids, aFreeSolids;
-      GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCompSolids, aFreeSolids);
-      if(aCompSolids.size() == 1 && aFreeSolids.size() == 0) {
-        aResult = aCompSolids.front()->impl<TopoDS_Shape>();
-      } else if (aCompSolids.size() > 1 || (aCompSolids.size() >= 1 && aFreeSolids.size() >= 1)) {
-        TopoDS_Compound aResultComp;
-        TopoDS_Builder aBuilder;
-        aBuilder.MakeCompound(aResultComp);
-        for(ListOfShape::const_iterator anIter = aCompSolids.cbegin(); anIter != aCompSolids.cend(); anIter++) {
-          aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
-        }
-        for(ListOfShape::const_iterator anIter = aFreeSolids.cbegin(); anIter != aFreeSolids.cend(); anIter++) {
-          aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
-        }
-        aResult = aResultComp;
-      }
+      aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
+                                                         GeomAPI_Shape::COMPSOLID,
+                                                         aCompSolids,
+                                                         aFreeSolids);
+      aResult = aGeomShape->impl<TopoDS_Shape>();
     }
   }
 
index 889cce3525eb00c6d3c9969290bcdd043349b5b2..50f49e2f9e9c2d859d54551607f446054988bac4 100644 (file)
@@ -271,24 +271,14 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr&                 theBaseSh
       aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
     }
     if(aResult.ShapeType() == TopAbs_COMPOUND) {
-      GeomShapePtr aCompound(new GeomAPI_Shape);
-      aCompound->setImpl(new TopoDS_Shape(aResult));
+      std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+      aGeomShape->setImpl(new TopoDS_Shape(aResult));
       ListOfShape aCompSolids, aFreeSolids;
-      GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCompSolids, aFreeSolids);
-      if(aCompSolids.size() == 1 && aFreeSolids.size() == 0) {
-        aResult = aCompSolids.front()->impl<TopoDS_Shape>();
-      } else if (aCompSolids.size() > 1 || (aCompSolids.size() >= 1 && aFreeSolids.size() >= 1)) {
-        TopoDS_Compound aResultComp;
-        TopoDS_Builder aBuilder;
-        aBuilder.MakeCompound(aResultComp);
-        for(ListOfShape::const_iterator anIter = aCompSolids.cbegin(); anIter != aCompSolids.cend(); anIter++) {
-          aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
-        }
-        for(ListOfShape::const_iterator anIter = aFreeSolids.cbegin(); anIter != aFreeSolids.cend(); anIter++) {
-          aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
-        }
-        aResult = aResultComp;
-      }
+      aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
+                                                         GeomAPI_Shape::COMPSOLID,
+                                                         aCompSolids,
+                                                         aFreeSolids);
+      aResult = aGeomShape->impl<TopoDS_Shape>();
     }
 
     // If after cut we got more than one solids then take closest to the center of mass of the base face.
@@ -477,24 +467,14 @@ void GeomAlgoAPI_Revolution::build(const GeomShapePtr&                 theBaseSh
     }
 
     if(aResult.ShapeType() == TopAbs_COMPOUND) {
-      GeomShapePtr aCompound(new GeomAPI_Shape);
-      aCompound->setImpl(new TopoDS_Shape(aResult));
+      std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+      aGeomShape->setImpl(new TopoDS_Shape(aResult));
       ListOfShape aCompSolids, aFreeSolids;
-      GeomAlgoAPI_ShapeTools::combineShapes(aCompound, GeomAPI_Shape::COMPSOLID, aCompSolids, aFreeSolids);
-      if(aCompSolids.size() == 1 && aFreeSolids.size() == 0) {
-        aResult = aCompSolids.front()->impl<TopoDS_Shape>();
-      } else if (aCompSolids.size() > 1 || (aCompSolids.size() >= 1 && aFreeSolids.size() >= 1)) {
-        TopoDS_Compound aResultComp;
-        TopoDS_Builder aBuilder;
-        aBuilder.MakeCompound(aResultComp);
-        for(ListOfShape::const_iterator anIter = aCompSolids.cbegin(); anIter != aCompSolids.cend(); anIter++) {
-          aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
-        }
-        for(ListOfShape::const_iterator anIter = aFreeSolids.cbegin(); anIter != aFreeSolids.cend(); anIter++) {
-          aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
-        }
-        aResult = aResultComp;
-      }
+      aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
+                                                         GeomAPI_Shape::COMPSOLID,
+                                                         aCompSolids,
+                                                         aFreeSolids);
+      aResult = aGeomShape->impl<TopoDS_Shape>();
     }
 
     // If after cut we got more than one solids then take closest to the center of mass of the base face.
index 4ce4640ef188df4daa0740fcecfa1471f4d9d053..87e6d83c210e11c32c19f7afe222ecc0534f5bd3 100644 (file)
@@ -90,17 +90,19 @@ std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeTools::centreOfMass(const std::sha
 }
 
 //=================================================================================================
-void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
-                                           const GeomAPI_Shape::ShapeType theType,
-                                           ListOfShape& theCombinedShapes,
-                                           ListOfShape& theFreeShapes)
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
+                                                                     const GeomAPI_Shape::ShapeType theType,
+                                                                     ListOfShape& theCombinedShapes,
+                                                                     ListOfShape& theFreeShapes)
 {
+  GeomShapePtr aResult = theCompound;
+
   if(!theCompound.get()) {
-    return;
+    return aResult;
   }
 
   if(theType != GeomAPI_Shape::SHELL && theType != GeomAPI_Shape::COMPSOLID) {
-    return;
+    return aResult;
   }
 
   TopAbs_ShapeEnum aTS = TopAbs_EDGE;
@@ -125,7 +127,7 @@ void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape>
   BOPCol_IndexedDataMapOfShapeListOfShape aMapSA;
   BOPTools::MapShapesAndAncestors(aShapesComp, aTS, aTA, aMapSA);
   if(aMapSA.IsEmpty()) {
-    return;
+    return aResult;
   }
 
   // Get all shapes with common subshapes and free shapes.
@@ -213,6 +215,23 @@ void GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape>
       theFreeShapes.push_back(aGeomShape);
     }
   }
+
+  if(theCombinedShapes.size() == 1 && theFreeShapes.size() == 0) {
+    aResult = theCombinedShapes.front();
+  } else if (theCombinedShapes.size() > 1 || (theCombinedShapes.size() >= 1 && theFreeShapes.size() >= 1)) {
+    TopoDS_Compound aResultComp;
+    TopoDS_Builder aBuilder;
+    aBuilder.MakeCompound(aResultComp);
+    for(ListOfShape::const_iterator anIter = theCombinedShapes.cbegin(); anIter != theCombinedShapes.cend(); anIter++) {
+      aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
+    }
+    for(ListOfShape::const_iterator anIter = theFreeShapes.cbegin(); anIter != theFreeShapes.cend(); anIter++) {
+      aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
+    }
+    aResult->setImpl(new TopoDS_Shape(aResultComp));
+  }
+
+  return aResult;
 }
 
 //=================================================================================================
index 3fdee67c5d9380bee37f4938ab7f2e6a6099f326..9b08fe8a1fed3a9c1c4e8dbc6e1f90fc0ef9688a 100644 (file)
@@ -35,10 +35,10 @@ public:
   /// \param[in] theType type of combine.
   /// \param[out] theCombinedShapes resulting shapes.
   /// \param[out] theFreeShapes shapes that does not have common subshapes.
-  static void combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
-                            const GeomAPI_Shape::ShapeType theType,
-                            ListOfShape& theCombinedShapes,
-                            ListOfShape& theFreeShapes);
+  static std::shared_ptr<GeomAPI_Shape> combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
+                                                      const GeomAPI_Shape::ShapeType theType,
+                                                      ListOfShape& theCombinedShapes,
+                                                      ListOfShape& theFreeShapes);
 
   /// \brief Calculates bounding box for theShapes
   /// \return list of eight points.
index c64d2a557c272cba75a5286c8b05c5a77d50686f..03b6952b6fda0ea3ff3ae5e627295f905f483fb5 100644 (file)
@@ -18,7 +18,6 @@ SET(PROJECT_HEADERS
     GeomValidators_Tools.h
     GeomValidators_ZeroOffset.h
     GeomValidators_Different.h
-    GeomValidators_BooleanSelection.h
     GeomValidators_IntersectionSelection.h
 )
 
@@ -37,7 +36,6 @@ SET(PROJECT_SOURCES
     GeomValidators_Tools.cpp
     GeomValidators_ZeroOffset.cpp
     GeomValidators_Different.cpp
-    GeomValidators_BooleanSelection.cpp
     GeomValidators_IntersectionSelection.cpp
 )
 
diff --git a/src/GeomValidators/GeomValidators_BooleanSelection.cpp b/src/GeomValidators/GeomValidators_BooleanSelection.cpp
deleted file mode 100644 (file)
index cc8823f..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        GeomValidators_BooleanSelection.cpp
-// Created:     3 Feb 2016
-// Author:      Dmitry Bobylev
-
-#include "GeomValidators_BooleanSelection.h"
-
-#include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_Feature.h>
-
-bool GeomValidators_BooleanSelection::isValid(const AttributePtr& theAttribute,
-                                              const std::list<std::string>& theArguments,
-                                              std::string& theError) const
-{
-  if(!theAttribute.get()) {
-    theError = "Error: empty selection.";
-    return false;
-  }
-  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
-  int anOperationType = aFeature->integer("bool_type")->value();
-  AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
-  for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
-    AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
-    if(!anAttrSelection.get()) {
-      theError = "Error: empty attribute selection.";
-      return false;
-    }
-    ResultPtr aContext = anAttrSelection->context();
-    if(!aContext.get()) {
-      theError = "Error: empty selection context.";
-      return false;
-    }
-    FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
-    if(!aFeature.get()) {
-      theError = "Error: empty feature.";
-      return false;
-    }
-    std::string aFeatureKind = aFeature->getKind();
-    if(aFeatureKind == "Sketch" || 
-        aFeatureKind == "Plane" ||
-        aFeatureKind == "Axis") {
-      theError = "Error: ";
-      theError += aFeatureKind;
-      theError += " shape is not allowed for selection.";
-      return false;
-    }
-    std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
-    if(!aShape.get()) {
-      aShape = aContext->shape();
-    }
-    if(!aShape.get()) {
-      theError = "Error: empty shape.";
-      return false;
-    }
-    int aShapeType = aShape->shapeType();
-    if(anOperationType == 1) {
-      // Fuse operation. Allow to select edges, faces and solids.
-      if(aShapeType != GeomAPI_Shape::EDGE &&
-         aShapeType != GeomAPI_Shape::FACE &&
-         aShapeType != GeomAPI_Shape::SOLID &&
-         aShapeType != GeomAPI_Shape::COMPSOLID &&
-         aShapeType != GeomAPI_Shape::COMPOUND) {
-        theError = "Error: selected shape has the wrong type.";
-        return false;
-      }
-    } else {
-      if(aShapeType != GeomAPI_Shape::SOLID &&
-         aShapeType != GeomAPI_Shape::COMPSOLID &&
-         aShapeType != GeomAPI_Shape::COMPOUND) {
-        theError = "Error: selected shape has the wrong type.";
-        return false;
-      }
-    }
-  }
-
-  return true;
-}
diff --git a/src/GeomValidators/GeomValidators_BooleanSelection.h b/src/GeomValidators/GeomValidators_BooleanSelection.h
deleted file mode 100644 (file)
index 8271288..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        GeomValidators_BooleanSelection.h
-// Created:     3 Feb 2016
-// Author:      Dmitry Bobylev
-
-#ifndef GeomValidators_BooleanSelection_H
-#define GeomValidators_BooleanSelection_H
-
-#include <GeomValidators.h>
-
-#include <ModelAPI_AttributeValidator.h>
-#include <ModelAPI_Attribute.h>
-
-/// \class GeomValidators_BooleanSelection
-/// \ingroup Validators
-/// \brief Validates selection for boolean operation.
-class GeomValidators_BooleanSelection: public ModelAPI_AttributeValidator
-{
-public:
-  /// \return True if the attribute is valid. It checks whether the selection
-  /// is acceptable for boolean operation.
-  /// \param[in] theAttribute an attribute to check.
-  /// \param[in] theArguments a filter parameters.
-  /// \param[out] theError error message.
-  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
-                                             const std::list<std::string>& theArguments,
-                                             std::string& theError) const;
-};
-
-#endif
index 831ad0dc922d540fc4f5e8aec02f19bb139df4c7..fcdd134e12e97ed10ce5d365abef95ab97f25d20 100644 (file)
@@ -4,7 +4,6 @@
 
 #include <GeomValidators_BodyShapes.h>
 #include <GeomValidators_BooleanArguments.h>
-#include <GeomValidators_BooleanSelection.h>
 #include <GeomValidators_ConstructionComposite.h>
 #include <GeomValidators_Different.h>
 #include <GeomValidators_DifferentShapes.h>
@@ -38,7 +37,6 @@ GeomValidators_Plugin::GeomValidators_Plugin()
   aFactory->registerValidator("GeomValidators_PartitionArguments", new GeomValidators_PartitionArguments);
   aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
   aFactory->registerValidator("GeomValidators_ZeroOffset", new GeomValidators_ZeroOffset);
-  aFactory->registerValidator("GeomValidators_BooleanSelection", new GeomValidators_BooleanSelection);
   aFactory->registerValidator("GeomValidators_IntersectionSelection", new GeomValidators_IntersectionSelection);
   aFactory->registerValidator("GeomValidators_FeatureKind", new GeomValidators_FeatureKind);