]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Validator for partition
authordbv <dbv@opencascade.com>
Thu, 17 Sep 2015 15:05:54 +0000 (18:05 +0300)
committerdbv <dbv@opencascade.com>
Thu, 17 Sep 2015 15:05:54 +0000 (18:05 +0300)
src/FeaturesPlugin/partition_widget.xml
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_PartitionArguments.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_PartitionArguments.h [new file with mode: 0644]
src/PartSet/PartSet_Module.cpp

index ef693d086a177a1d473d130c074153bb4cb39017..9f4cfe3bb6f3fe46f0c899d3604e52d5c44d6fb0 100755 (executable)
@@ -24,4 +24,5 @@
     label="Combine results"
     default="true"
     tooltip="If True combines all results to one. If False builds separate result for each object."/>
+  <validator id="GeomValidators_PartitionArguments" parameters="main_objects,tool_objects,partition_combine"/>
 </source>
index c23f5aa40d8a63e5b83c73e3e7e66fcfa94c72e8..2450cf38c23ba42dea837b6a252aedc2ac02f9e6 100644 (file)
@@ -9,6 +9,7 @@ SET(PROJECT_HEADERS
     GeomValidators_DifferentShapes.h
     GeomValidators_Face.h
     GeomValidators_Finite.h
+    GeomValidators_PartitionArguments.h
     GeomValidators_Positive.h
     GeomValidators_ShapeType.h
     GeomValidators_Tools.h
@@ -22,6 +23,7 @@ SET(PROJECT_SOURCES
     GeomValidators_DifferentShapes.cpp
     GeomValidators_Face.cpp
     GeomValidators_Finite.cpp
+    GeomValidators_PartitionArguments.cpp
     GeomValidators_Positive.cpp
     GeomValidators_ShapeType.cpp
     GeomValidators_Tools.cpp
diff --git a/src/GeomValidators/GeomValidators_PartitionArguments.cpp b/src/GeomValidators/GeomValidators_PartitionArguments.cpp
new file mode 100644 (file)
index 0000000..e94ebca
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_PartitionArguments.cpp
+// Created:     17 September 2015
+// Author:      Dmitry Bobylev
+
+#include <GeomValidators_PartitionArguments.h>
+
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
+//=================================================================================================
+bool GeomValidators_PartitionArguments::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                              const std::list<std::string>& theArguments,
+                                              std::string& theError) const
+{
+  if(theArguments.size() != 3) {
+    theError = "Wrong number of arguments (expected 3).";
+    return false;
+  }
+
+  int anObjectsNb = 0, aToolsNb = 0;
+  bool isCombine = true;
+
+  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_AttributeBoolean> anAttrBool = theFeature->boolean(*anIt);
+  if(anAttrBool) {
+    isCombine = anAttrBool->value();
+  }
+
+  if((anObjectsNb > 0 && aToolsNb > 0) || (isCombine && anObjectsNb != 0 && (anObjectsNb + aToolsNb > 1))) {
+    return true;
+  }
+
+  theError = "Not enough arguments";
+  return false;
+}
+
+//=================================================================================================
+bool GeomValidators_PartitionArguments::isNotObligatory(std::string theFeature, std::string theAttribute)
+{
+  if(theAttribute == "tool_objects") {
+    return true;
+  }
+
+  return false;
+}
diff --git a/src/GeomValidators/GeomValidators_PartitionArguments.h b/src/GeomValidators/GeomValidators_PartitionArguments.h
new file mode 100644 (file)
index 0000000..8233cbf
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_PartitionArguments.h
+// Created:     17 September 2015
+// Author:      Dmitry Bobylev
+
+#ifndef GeomValidators_PartitionArguments_H
+#define GeomValidators_PartitionArguments_H
+
+#include <GeomValidators.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_FeatureValidator.h>
+
+/** \class GeomValidators_PartitionArguments
+ *  \ingroup Validators
+ *  \brief Validates that partition operation have enough arguments.
+ */
+class GeomValidators_PartitionArguments : 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,
+                                             std::string& theError) 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 64674f19d028bb725ba9cf1c8cc3d5356a927c09..ac028364420d100387a6a8500b1e56d58cda7f95 100755 (executable)
@@ -42,6 +42,7 @@
 #include <GeomValidators_ZeroOffset.h>
 #include <GeomValidators_BooleanArguments.h>
 #include <GeomValidators_Different.h>
+#include <GeomValidators_PartitionArguments.h>
 
 
 #include <ModelAPI_Object.h>
@@ -226,6 +227,9 @@ void PartSet_Module::registerValidators()
 
   aFactory->registerValidator("GeomValidators_Different",
                               new GeomValidators_Different);
+
+  aFactory->registerValidator("GeomValidators_PartitionArguments",
+                              new GeomValidators_PartitionArguments);
 }
 
 void PartSet_Module::registerFilters()