X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FCollectionPlugin%2FCollectionPlugin_Validators.cpp;h=4e55fd7339c24c8118c3242c00f9e14d54ed57b0;hb=9a06f255338dc4cd38cfcdf724fe72306cea29a3;hp=0c765092eebd034c7e34b5bf713508c0f61f7b6d;hpb=6e421e939851e0de46554ae45a3ca0e1f67cd91d;p=modules%2Fshaper.git diff --git a/src/CollectionPlugin/CollectionPlugin_Validators.cpp b/src/CollectionPlugin/CollectionPlugin_Validators.cpp index 0c765092e..4e55fd733 100644 --- a/src/CollectionPlugin/CollectionPlugin_Validators.cpp +++ b/src/CollectionPlugin/CollectionPlugin_Validators.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2022 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -18,29 +18,111 @@ // #include "CollectionPlugin_Validators.h" +#include "CollectionPlugin_Group.h" #include "CollectionPlugin_Field.h" #include +#include #include bool CollectionPlugin_FieldValidator::isValid(const FeaturePtr& theFeature, - const std::list& theArguments, + const std::list& /*theArguments*/, Events_InfoMessage& theError) const { AttributeSelectionListPtr aSelList = theFeature->selectionList(CollectionPlugin_Field::SELECTED_ID()); + std::string aTypeStr = aSelList->selectionType(); + if (aTypeStr == "part") + return true; if (aSelList->isInitialized()) { int aSize = aSelList->size(); - std::string aTypeStr = aSelList->selectionType(); - if (aTypeStr == "part") - return true; - else { - bool aIsDefined = aSize > 0; - if (!aIsDefined) - theError = "Selection list is not initialized"; - return aIsDefined; - } + bool aIsDefined = aSize > 0; + if (!aIsDefined) + theError = "Selection list is not initialized"; + return aIsDefined; } theError = "Selection list is not initialized"; return false; } + +static bool isGroupTypeCorrect(const AttributeSelectionPtr& theSelection, + std::string& theType, + Events_InfoMessage& theError) +{ + // applicable the groups only + ResultPtr aGroupResult = theSelection->context(); + if (!aGroupResult.get() || aGroupResult->groupName() != ModelAPI_ResultGroup::group()) { + theError = "Error: Groups can be selected only."; + return false; + } + // groups of same type can be selected only + FeaturePtr aGroupFeature = ModelAPI_Feature::feature(aGroupResult->data()->owner()); + std::string aGroupType = + aGroupFeature->selectionList(CollectionPlugin_Group::LIST_ID())->selectionType(); + if (theType.empty()) + theType = aGroupType; + else if (theType != aGroupType) { + theError = "Error: Groups should have same type"; + return false; + } + return true; +} + +bool CollectionPlugin_GroupOperationAttributeValidator::isValid( + const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + AttributeSelectionListPtr aSelList = + std::dynamic_pointer_cast(theAttribute); + if (!aSelList) { + theError = "Error: This validator can only work with selection list of attributes"; + return false; + } + + FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner()); + // check selected items + std::string aType; + for (int anIndex = 0; anIndex < aSelList->size(); ++anIndex) { + AttributeSelectionPtr aCurSelection = aSelList->value(anIndex); + if (!isGroupTypeCorrect(aCurSelection, aType, theError)) + return false; + } + // check types of all selection lists are the same + for (std::list::const_iterator aParIt = theArguments.begin(); + aParIt != theArguments.end() && !aType.empty(); ++aParIt) { + AttributeSelectionListPtr aCurList = anOwner->selectionList(*aParIt); + if (aCurList->size() == 0) + continue; + AttributeSelectionPtr aCurSelection = aCurList->value(0); + if (!isGroupTypeCorrect(aCurSelection, aType, theError)) + return false; + } + return true; +} + +bool CollectionPlugin_GroupSelectionValidator::isValid( + const AttributePtr& theAttribute, + const std::list& /*theArguments*/, + Events_InfoMessage& theError) const +{ + AttributeSelectionListPtr aSelList = + std::dynamic_pointer_cast(theAttribute); + if (!aSelList) { + theError = "Error: This validator can only work with selection list of attributes"; + return false; + } + + for (int anIndex = 0; anIndex < aSelList->size(); ++anIndex) { + AttributeSelectionPtr aCurSelection = aSelList->value(anIndex); + FeaturePtr aCurFeature = aCurSelection->contextFeature(); + ResultPtr aGroupResult = aCurFeature.get() ? aCurFeature->lastResult() + : aCurSelection->context(); + if (!aGroupResult.get() || aGroupResult->groupName() == ModelAPI_ResultGroup::group()) { + theError = "Error: Whole group mustn't be selected."; + return false; + } + } + + return true; +}