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 bool CollectionPlugin_GroupOperationAttributeValidator::isValid(
49 const AttributePtr& theAttribute,
50 const std::list<std::string>& theArguments,
51 Events_InfoMessage& theError) const
53 AttributeSelectionListPtr aSelList =
54 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
56 theError = "Error: This validator can only work with selection list of attributes";
60 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
61 // check selected items
63 for (int anIndex = 0; anIndex < aSelList->size(); ++anIndex) {
64 AttributeSelectionPtr aCurSelection = aSelList->value(anIndex);
65 // applicable the groups only
66 ResultPtr aGroupResult = aCurSelection->context();
67 if (aGroupResult->groupName() != ModelAPI_ResultGroup::group()) {
68 theError = "Error: Groups can be selected only.";
71 // groups of same type can be selected only
72 FeaturePtr aGroupFeature = ModelAPI_Feature::feature(aGroupResult->data()->owner());
73 std::string aGroupType =
74 aGroupFeature->selectionList(CollectionPlugin_Group::LIST_ID())->selectionType();
77 else if (aType != aGroupType) {
78 theError = "Error: Groups should have same type";