Salome HOME
Issue #1739: Naming on faces not correct
[modules/shaper.git] / src / GeomValidators / GeomValidators_MinObjectsSelected.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomValidators_MinObjectsSelected.cpp
4 // Created:     30 June 2015
5 // Author:      Dmitry Bobylev
6
7 #include <GeomValidators_MinObjectsSelected.h>
8
9 #include <Events_InfoMessage.h>
10
11 #include <ModelAPI_AttributeInteger.h>
12 #include <ModelAPI_AttributeSelectionList.h>
13
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
18 {
19   if(theArguments.size() != 2) {
20     theError = "Error: Wrong number of arguments (expected 2): selection list id and min number of objects";
21     return false;
22   }
23
24   std::string aSelectionListId = theArguments.front();
25   AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(aSelectionListId);
26   if(!anAttrSelList.get()) {
27     theError = "Error: Could not get attribute \"%1\".";
28     theError.arg(aSelectionListId);
29     return false;
30   }
31   int anObjectsNb = anAttrSelList->size();
32
33   int aMinObjectsNb = atoi(theArguments.back().c_str());
34
35   if(anObjectsNb < aMinObjectsNb) {
36     theError = "Error: Attribute \"%1\" should contain at least %2 items.";
37     theError.arg(aSelectionListId).arg(theArguments.back());
38     return false;
39   }
40
41   return true;
42 }
43
44 //=================================================================================================
45 bool GeomValidators_MinObjectsSelected::isNotObligatory(std::string theFeature, std::string theAttribute)
46 {
47   return false;
48 }