]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1366: validator for Partition objects selection list.
authordbv <dbv@opencascade.com>
Thu, 26 May 2016 16:33:06 +0000 (19:33 +0300)
committerdbv <dbv@opencascade.com>
Thu, 26 May 2016 16:33:06 +0000 (19:33 +0300)
src/FeaturesPlugin/FeaturesPlugin_Partition.cpp
src/FeaturesPlugin/partition_widget.xml
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_MinObjectsSelected.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_MinObjectsSelected.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Plugin.cpp

index 7d5e2e90c5f23d1e5f5ad882df715cc45b17f50f..ec16dd41e37acba5405c9690906c7aaa7a8fd210 100755 (executable)
@@ -56,6 +56,13 @@ void FeaturesPlugin_Partition::execute()
       anObjects.push_back(anObject);
     }
   }
+
+  if(anObjects.empty()) {
+    static const std::string aFeatureError = "Error: No objects for partition.";
+    setError(aFeatureError);
+    return;
+  }
+
   std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints = GeomAlgoAPI_ShapeTools::getBoundingBox(anObjects, 1.0);
 
   // Resize planes.
index 593b19864311b7cea196634a60867dd6336c8c41..b2c8250cc5aad90c1dca8206a221e31e32f85941 100755 (executable)
@@ -8,4 +8,5 @@
     concealment="true">
     <validator id="FeaturesPlugin_ValidatorPartitionSelection" parameters="Plane"/>
   </multi_selector>
+  <validator id="GeomValidators_MinObjectsSelected" parameters="base_objects,2"/>
 </source>
index 03b6952b6fda0ea3ff3ae5e627295f905f483fb5..f7f7d29e030018018a58814ad059ba06500ec9da 100644 (file)
@@ -19,6 +19,7 @@ SET(PROJECT_HEADERS
     GeomValidators_ZeroOffset.h
     GeomValidators_Different.h
     GeomValidators_IntersectionSelection.h
+    GeomValidators_MinObjectsSelected.h
 )
 
 SET(PROJECT_SOURCES
@@ -37,6 +38,7 @@ SET(PROJECT_SOURCES
     GeomValidators_ZeroOffset.cpp
     GeomValidators_Different.cpp
     GeomValidators_IntersectionSelection.cpp
+    GeomValidators_MinObjectsSelected.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/GeomValidators/GeomValidators_MinObjectsSelected.cpp b/src/GeomValidators/GeomValidators_MinObjectsSelected.cpp
new file mode 100644 (file)
index 0000000..58e39b3
--- /dev/null
@@ -0,0 +1,45 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_MinObjectsSelected.cpp
+// Created:     30 June 2015
+// Author:      Dmitry Bobylev
+
+#include <GeomValidators_MinObjectsSelected.h>
+
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
+//=================================================================================================
+bool GeomValidators_MinObjectsSelected::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                                const std::list<std::string>& theArguments,
+                                                std::string& theError) const
+{
+  if(theArguments.size() != 2) {
+    theError = "Error: Wrong number of arguments (expected 2): selection list id and min number of objects";
+    return false;
+  }
+
+  std::string aSelectionListId = theArguments.front();
+  AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(aSelectionListId);
+  if(!anAttrSelList.get()) {
+    theError = "Error: Could not get attribute \"" + aSelectionListId + "\".";
+    return false;
+  }
+  int anObjectsNb = anAttrSelList->size();
+
+  int aMinObjectsNb = atoi(theArguments.back().c_str());
+
+  if(anObjectsNb < aMinObjectsNb) {
+    theError = "Error: Attribute \"" + aSelectionListId + "\" should contain at least "
+      + theArguments.back() + " items.";
+    return false;
+  }
+
+  return true;
+}
+
+//=================================================================================================
+bool GeomValidators_MinObjectsSelected::isNotObligatory(std::string theFeature, std::string theAttribute)
+{
+  return false;
+}
diff --git a/src/GeomValidators/GeomValidators_MinObjectsSelected.h b/src/GeomValidators/GeomValidators_MinObjectsSelected.h
new file mode 100644 (file)
index 0000000..cdcb20a
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_MinObjectsSelected.h
+// Created:     30 June 2015
+// Author:      Dmitry Bobylev
+
+#ifndef GeomValidators_MinObjectsSelected_H
+#define GeomValidators_MinObjectsSelected_H
+
+#include <GeomValidators.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_FeatureValidator.h>
+
+/// \class GeomValidators_MinObjectsSelected
+/// \ingroup Validators
+/// \brief Validates number of objects in selection list.
+class GeomValidators_MinObjectsSelected : public ModelAPI_FeatureValidator
+{
+public:
+  /// \return true if selection list has enough objects.
+  /// \param[in] theFeature the validated feature.
+  /// \param[in] theArguments the arguments in the configuration file for this validator.
+  /// \param[out] theError error message.
+  /// \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 fcdd134e12e97ed10ce5d365abef95ab97f25d20..9b99ffc852230d5d43f259e6262172cfe818016a 100644 (file)
@@ -14,6 +14,7 @@
 #include <GeomValidators_ZeroOffset.h>
 #include <GeomValidators_IntersectionSelection.h>
 #include <GeomValidators_FeatureKind.h>
+#include <GeomValidators_MinObjectsSelected.h>
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
@@ -39,6 +40,7 @@ GeomValidators_Plugin::GeomValidators_Plugin()
   aFactory->registerValidator("GeomValidators_ZeroOffset", new GeomValidators_ZeroOffset);
   aFactory->registerValidator("GeomValidators_IntersectionSelection", new GeomValidators_IntersectionSelection);
   aFactory->registerValidator("GeomValidators_FeatureKind", new GeomValidators_FeatureKind);
+  aFactory->registerValidator("GeomValidators_MinObjectsSelected", new GeomValidators_MinObjectsSelected);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);