From: dbv Date: Thu, 17 Sep 2015 15:05:54 +0000 (+0300) Subject: Validator for partition X-Git-Tag: V_1.4.0~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=020e7187ee88afbd18286f149536cdef61d9f61e;p=modules%2Fshaper.git Validator for partition --- diff --git a/src/FeaturesPlugin/partition_widget.xml b/src/FeaturesPlugin/partition_widget.xml index ef693d086..9f4cfe3bb 100755 --- a/src/FeaturesPlugin/partition_widget.xml +++ b/src/FeaturesPlugin/partition_widget.xml @@ -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."/> + diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt index c23f5aa40..2450cf38c 100644 --- a/src/GeomValidators/CMakeLists.txt +++ b/src/GeomValidators/CMakeLists.txt @@ -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 index 000000000..e94ebca48 --- /dev/null +++ b/src/GeomValidators/GeomValidators_PartitionArguments.cpp @@ -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 + +#include +#include + +//================================================================================================= +bool GeomValidators_PartitionArguments::isValid(const std::shared_ptr& theFeature, + const std::list& 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::const_iterator anIt = theArguments.begin(), aLast = theArguments.end(); + + std::shared_ptr anAttrSelList = theFeature->selectionList(*anIt); + if(anAttrSelList) { + anObjectsNb = anAttrSelList->size(); + } + anIt++; + + anAttrSelList = theFeature->selectionList(*anIt); + if(anAttrSelList) { + aToolsNb = anAttrSelList->size(); + } + anIt++; + + std::shared_ptr 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 index 000000000..8233cbfbc --- /dev/null +++ b/src/GeomValidators/GeomValidators_PartitionArguments.h @@ -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 +#include +#include + +/** \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& 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/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 64674f19d..ac0283644 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include @@ -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()