From: dbv Date: Thu, 26 May 2016 16:33:06 +0000 (+0300) Subject: Issue #1366: validator for Partition objects selection list. X-Git-Tag: V_2.3.1~46 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1d864d8beda4d31de109734a9f7f006cb361e91c;p=modules%2Fshaper.git Issue #1366: validator for Partition objects selection list. --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp index 7d5e2e90c..ec16dd41e 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp @@ -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 > aBoundingPoints = GeomAlgoAPI_ShapeTools::getBoundingBox(anObjects, 1.0); // Resize planes. diff --git a/src/FeaturesPlugin/partition_widget.xml b/src/FeaturesPlugin/partition_widget.xml index 593b19864..b2c8250cc 100755 --- a/src/FeaturesPlugin/partition_widget.xml +++ b/src/FeaturesPlugin/partition_widget.xml @@ -8,4 +8,5 @@ concealment="true"> + diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt index 03b6952b6..f7f7d29e0 100644 --- a/src/GeomValidators/CMakeLists.txt +++ b/src/GeomValidators/CMakeLists.txt @@ -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 index 000000000..58e39b3a0 --- /dev/null +++ b/src/GeomValidators/GeomValidators_MinObjectsSelected.cpp @@ -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 + +#include +#include + +//================================================================================================= +bool GeomValidators_MinObjectsSelected::isValid(const std::shared_ptr& theFeature, + const std::list& 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 index 000000000..cdcb20a27 --- /dev/null +++ b/src/GeomValidators/GeomValidators_MinObjectsSelected.h @@ -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 +#include +#include + +/// \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& theFeature, + const std::list& 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 diff --git a/src/GeomValidators/GeomValidators_Plugin.cpp b/src/GeomValidators/GeomValidators_Plugin.cpp index fcdd134e1..9b99ffc85 100644 --- a/src/GeomValidators/GeomValidators_Plugin.cpp +++ b/src/GeomValidators/GeomValidators_Plugin.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -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);