1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "CollectionPlugin_Validators.h"
21 #include "CollectionPlugin_Group.h"
22 #include "CollectionPlugin_Field.h"
23 #include <ModelAPI_AttributeSelectionList.h>
24 #include <ModelAPI_ResultGroup.h>
25 #include <Events_InfoMessage.h>
28 bool CollectionPlugin_FieldValidator::isValid(const FeaturePtr& theFeature,
29 const std::list<std::string>& theArguments,
30 Events_InfoMessage& theError) const
32 AttributeSelectionListPtr aSelList =
33 theFeature->selectionList(CollectionPlugin_Field::SELECTED_ID());
34 std::string aTypeStr = aSelList->selectionType();
35 if (aTypeStr == "part")
37 if (aSelList->isInitialized()) {
38 int aSize = aSelList->size();
39 bool aIsDefined = aSize > 0;
41 theError = "Selection list is not initialized";
44 theError = "Selection list is not initialized";
48 static bool isGroupTypeCorrect(const AttributeSelectionPtr& theSelection,
50 Events_InfoMessage& theError)
52 // applicable the groups only
53 ResultPtr aGroupResult = theSelection->context();
54 if (!aGroupResult.get() || aGroupResult->groupName() != ModelAPI_ResultGroup::group()) {
55 theError = "Error: Groups can be selected only.";
58 // groups of same type can be selected only
59 FeaturePtr aGroupFeature = ModelAPI_Feature::feature(aGroupResult->data()->owner());
60 std::string aGroupType =
61 aGroupFeature->selectionList(CollectionPlugin_Group::LIST_ID())->selectionType();
64 else if (theType != aGroupType) {
65 theError = "Error: Groups should have same type";
71 bool CollectionPlugin_GroupOperationAttributeValidator::isValid(
72 const AttributePtr& theAttribute,
73 const std::list<std::string>& theArguments,
74 Events_InfoMessage& theError) const
76 AttributeSelectionListPtr aSelList =
77 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
79 theError = "Error: This validator can only work with selection list of attributes";
83 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
84 // check selected items
86 for (int anIndex = 0; anIndex < aSelList->size(); ++anIndex) {
87 AttributeSelectionPtr aCurSelection = aSelList->value(anIndex);
88 if (!isGroupTypeCorrect(aCurSelection, aType, theError))
91 // check types of all selection lists are the same
92 for (std::list<std::string>::const_iterator aParIt = theArguments.begin();
93 aParIt != theArguments.end() && !aType.empty(); ++aParIt) {
94 AttributeSelectionListPtr aCurList = anOwner->selectionList(*aParIt);
95 if (aCurList->size() == 0)
97 AttributeSelectionPtr aCurSelection = aCurList->value(0);
98 if (!isGroupTypeCorrect(aCurSelection, aType, theError))