1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomValidators_MinObjectsSelected.cpp
4 // Created: 30 June 2015
5 // Author: Dmitry Bobylev
7 #include <GeomValidators_MinObjectsSelected.h>
9 #include <Events_InfoMessage.h>
11 #include <ModelAPI_AttributeInteger.h>
12 #include <ModelAPI_AttributeSelectionList.h>
14 //=================================================================================================
15 bool GeomValidators_MinObjectsSelected::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
16 const std::list<std::string>& theArguments,
17 Events_InfoMessage& theError) const
19 if(theArguments.size() != 2) {
21 "Error: Wrong number of arguments (expected 2): selection list id and min number of objects";
25 std::string aSelectionListId = theArguments.front();
26 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(aSelectionListId);
27 if(!anAttrSelList.get()) {
28 theError = "Error: Could not get attribute \"%1\".";
29 theError.arg(aSelectionListId);
32 int anObjectsNb = anAttrSelList->size();
34 int aMinObjectsNb = atoi(theArguments.back().c_str());
36 if(anObjectsNb < aMinObjectsNb) {
37 theError = "Error: Attribute \"%1\" should contain at least %2 items.";
38 theError.arg(aSelectionListId).arg(theArguments.back());
45 //================================================================================================
46 bool GeomValidators_MinObjectsSelected::isNotObligatory(std::string theFeature,
47 std::string theAttribute)