]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Improvement #610: Fuse: tools or objects are not needed.
authordbv <dbv@opencascade.com>
Tue, 30 Jun 2015 10:47:50 +0000 (13:47 +0300)
committerdbv <dbv@opencascade.com>
Tue, 30 Jun 2015 10:54:37 +0000 (13:54 +0300)
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
src/FeaturesPlugin/boolean_widget.xml
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_BooleanArguments.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_BooleanArguments.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_ShapeType.cpp
src/GeomValidators/GeomValidators_ShapeType.h
src/PartSet/PartSet_Module.cpp

index bfb8655f400137167bffbb331412d2ac71297489..7fb46f2c998cac3abd103ee68124d04c81f45a1b 100644 (file)
@@ -12,6 +12,8 @@
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
 
 #include <GeomAlgoAPI_Boolean.h>
 #include <GeomAlgoAPI_MakeShapeList.h>
@@ -42,6 +44,9 @@ void FeaturesPlugin_Boolean::initAttributes()
     FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
   // extrusion works with faces always
   aSelection->setSelectionType("SOLID");
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
 }
 
 //=================================================================================================
@@ -72,9 +77,6 @@ void FeaturesPlugin_Boolean::execute()
 
   // Getting objects.
   AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID());
-  if (anObjectsSelList->size() == 0) {
-    return;
-  }
   for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
     std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr = anObjectsSelList->value(anObjectsIndex);
     std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
@@ -86,9 +88,6 @@ void FeaturesPlugin_Boolean::execute()
 
   // Getting tools.
   AttributeSelectionListPtr aToolsSelList = selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID());
-  if (aToolsSelList->size() == 0) {
-    return;
-  }
   for(int aToolsIndex = 0; aToolsIndex < aToolsSelList->size(); aToolsIndex++) {
     std::shared_ptr<ModelAPI_AttributeSelection> aToolAttr = aToolsSelList->value(aToolsIndex);
     std::shared_ptr<GeomAPI_Shape> aTool = aToolAttr->value();
@@ -103,6 +102,12 @@ void FeaturesPlugin_Boolean::execute()
   switch(aType) {
     case GeomAlgoAPI_Boolean::BOOL_CUT:
     case GeomAlgoAPI_Boolean::BOOL_COMMON:{
+      if(anObjects.empty() || aTools.empty()) {
+        std::string aFeatureError = "Not enough objects for boolean 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;
@@ -137,6 +142,20 @@ void FeaturesPlugin_Boolean::execute()
       break;
     }
     case GeomAlgoAPI_Boolean::BOOL_FUSE: {
+      if(anObjects.empty() && aTools.size() > 1) {
+        anObjects.push_back(aTools.back());
+        aTools.pop_back();
+      }else if(aTools.empty() && anObjects.size() > 1) {
+        aTools.push_back(anObjects.back());
+        anObjects.pop_back();
+      }
+
+      if(anObjects.empty() || aTools.empty()) {
+        std::string aFeatureError = "Not enough objects for boolean operation";
+        setError(aFeatureError);
+        return;
+      }
+
       // Fuse all objects and all tools.
       GeomAlgoAPI_Boolean aBoolAlgo(anObjects, aTools, aType);
 
index 22d958ccaf8a05e841ab17ecff88b4354727955b..8fc0925caf92ddcaa47fbb9ff07a5abfaf2a4230 100644 (file)
@@ -8,7 +8,7 @@
     type_choice="Solids"
     concealment="true">
     <validator id="PartSet_DifferentObjects"/>
-    <validator id="GeomValidators_ShapeType" parameters="solid"/>
+    <validator id="GeomValidators_ShapeType" parameters="empty,solid"/>
   </multi_selector>
   <multi_selector id="tool_objects" 
     label="Tool object" 
@@ -17,7 +17,7 @@
     type_choice="Solids"
     concealment="true" >
     <validator id="PartSet_DifferentObjects"/>
-    <validator id="GeomValidators_ShapeType" parameters="solid"/>
+    <validator id="GeomValidators_ShapeType" parameters="empty,solid"/>
   </multi_selector>
   <choice id="bool_type" 
     label="Type" 
@@ -25,4 +25,5 @@
     string_list="Cut Fuse Common"
     default="0"
   />
+  <validator id="GeomValidators_BooleanArguments" parameters="main_objects,tool_objects,bool_type"/>
 </source>
index 2c40e8cb8a7ba13d0925581c1312ca54724717c2..07004c22a5449c406343afea46af03dfe570f538 100644 (file)
@@ -4,6 +4,7 @@ INCLUDE(Common)
 
 SET(PROJECT_HEADERS
     GeomValidators.h
+    GeomValidators_BooleanArguments.h
     GeomValidators_ConstructionComposite.h
     GeomValidators_Face.h
     GeomValidators_Positive.h
@@ -13,6 +14,7 @@ SET(PROJECT_HEADERS
 )
 
 SET(PROJECT_SOURCES
+    GeomValidators_BooleanArguments.cpp
     GeomValidators_ConstructionComposite.cpp
     GeomValidators_Face.cpp
     GeomValidators_Positive.cpp
diff --git a/src/GeomValidators/GeomValidators_BooleanArguments.cpp b/src/GeomValidators/GeomValidators_BooleanArguments.cpp
new file mode 100644 (file)
index 0000000..738b1ec
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_BooleanArguments.h
+// Created:     30 June 2015
+// Author:      Dmitry Bobylev
+
+#include <GeomValidators_BooleanArguments.h>
+
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
+//=================================================================================================
+bool GeomValidators_BooleanArguments::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                              const std::list<std::string>& theArguments) const
+{
+  if(theArguments.size() != 3) {
+    return false;
+  }
+
+  int anObjectsNb = 0, aToolsNb = 0;
+  int anOperationType = 0;
+
+  std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+
+  std::shared_ptr<ModelAPI_AttributeSelectionList> anAttrSelList = theFeature->selectionList(*anIt);
+  if(anAttrSelList) {
+    anObjectsNb = anAttrSelList->size();
+  }
+  anIt++;
+
+  anAttrSelList = theFeature->selectionList(*anIt);
+  if(anAttrSelList) {
+    aToolsNb = anAttrSelList->size();
+  }
+  anIt++;
+
+  std::shared_ptr<ModelAPI_AttributeInteger> anAttrInt = theFeature->integer(*anIt);
+  if(anAttrInt) {
+    anOperationType = anAttrInt->value();
+  }
+
+  if(anOperationType == 1 && (anObjectsNb + aToolsNb > 1)) {
+    return true;
+  } else if (anOperationType != 1 && anObjectsNb > 0 && aToolsNb > 0) {
+    return true;
+  }
+
+  return false;
+}
+
+//=================================================================================================
+bool GeomValidators_BooleanArguments::isNotObligatory(std::string theFeature, std::string theAttribute)
+{
+  if(theAttribute == "main_objects" || theAttribute == "tool_objects") {
+    return true;
+  }
+
+  return false;
+}
diff --git a/src/GeomValidators/GeomValidators_BooleanArguments.h b/src/GeomValidators/GeomValidators_BooleanArguments.h
new file mode 100644 (file)
index 0000000..c713474
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_BooleanArguments.h
+// Created:     30 June 2015
+// Author:      Dmitry Bobylev
+
+#ifndef GeomValidators_BooleanArguments_H
+#define GeomValidators_BooleanArguments_H
+
+#include <GeomValidators.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_FeatureValidator.h>
+
+/** \class GeomValidators_BooleanArguments
+ *  \ingroup Validators
+ *  \brief Validates that boolean operation have enough arguments.
+ */
+class GeomValidators_BooleanArguments : public ModelAPI_FeatureValidator
+{
+public:
+  /** \brief Returns true if feature and/or attributes are valid.
+   *  \param[in] theFeature the validated feature.
+   *  \param[in] theArguments the arguments in the configuration file for this validator.
+   *  \returns true if feature is valid.
+   */
+  GEOMVALIDATORS_EXPORT virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                             const std::list<std::string>& theArguments) const;
+
+  /// \return true if the attribute in feature is not obligatory for the feature execution.
+  GEOMVALIDATORS_EXPORT virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
+};
+
+#endif
index 50c4bcdb232b93fa3d077c2e057713a41ed6b842..3d68f6a8f95e598efbf63c3c11401d6abfd504dc 100644 (file)
 
 
 typedef std::map<std::string, GeomValidators_ShapeType::TypeOfShape> EdgeTypes;
-static EdgeTypes MyEdgeTypes;
 
 GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const std::string& theType)
 {
-  if (MyEdgeTypes.size() == 0) {
-    MyEdgeTypes["vertex"] = Vertex;
-    MyEdgeTypes["edge"]   = Edge;
-    MyEdgeTypes["line"]   = Line;
-    MyEdgeTypes["circle"] = Circle;
-    MyEdgeTypes["solid"] = Solid;
-    MyEdgeTypes["face"]  = Face;
+  static EdgeTypes MyShapeTypes;
+
+  if (MyShapeTypes.size() == 0) {
+    MyShapeTypes["empty"]  = Empty;
+    MyShapeTypes["vertex"] = Vertex;
+    MyShapeTypes["edge"]   = Edge;
+    MyShapeTypes["line"]   = Line;
+    MyShapeTypes["circle"] = Circle;
+    MyShapeTypes["face"]   = Face;
+    MyShapeTypes["solid"]  = Solid;
   }
   std::string aType = std::string(theType.c_str());
-  if (MyEdgeTypes.find(aType) != MyEdgeTypes.end())
-    return MyEdgeTypes[aType];
+  if (MyShapeTypes.find(aType) != MyShapeTypes.end())
+    return MyShapeTypes[aType];
   
   Events_Error::send("Shape type defined in XML is not implemented!");
   return AnyShape;
@@ -63,6 +65,9 @@ bool GeomValidators_ShapeType::isValidArgument(const AttributePtr& theAttribute,
   AttributeSelectionListPtr aListAttr = 
            std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if (aListAttr.get()) {
+    if(aListAttr->size() == 0 && shapeType(theArgument) == Empty) {
+      return true;
+    }
     for (int i = 0; i < aListAttr->size(); i++) {
       aValid = isValidAttribute(aListAttr->value(i), aShapeType);
       if (!aValid) // if at least one attribute is invalid, the result is false
index de7fae9ba6575bec0ff18ab6243b30c0c9942a3a..782d9eaeb3b4f61888d85fb37b3ed0b99be39478 100644 (file)
@@ -26,14 +26,15 @@ class GeomValidators_ShapeType : public ModelAPI_AttributeValidator
   //  the edge type
   enum TypeOfShape
   {
-    AnyShape,
+    Empty,
     Vertex,
     Edge,
     Line,
     Circle,
-    Solid,
     Face,
-    Compound
+    Solid,
+    Compound,
+    AnyShape
   };
 
  public:
index 2e87de581af3bcee016128aca9a8507798fe59c6..cd842eedc73b8e1bb1cf974103ca9655b7af123f 100644 (file)
@@ -33,6 +33,7 @@
 #include <GeomValidators_Face.h>
 #include <GeomValidators_ConstructionComposite.h>
 #include <GeomValidators_ZeroOffset.h>
+#include <GeomValidators_BooleanArguments.h>
 
 
 #include <ModelAPI_Object.h>
@@ -196,6 +197,9 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("GeomValidators_ZeroOffset",
                               new GeomValidators_ZeroOffset);
 
+  aFactory->registerValidator("GeomValidators_BooleanArguments",
+                              new GeomValidators_BooleanArguments);
+
   aFactory->registerValidator("PartSet_SketchEntityValidator",
                               new PartSet_SketchEntityValidator);