Salome HOME
Issue #1834: Fix length of lines
[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 = 
21       "Error: Wrong number of arguments (expected 2): selection list id and min number of objects";
22     return false;
23   }
24
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);
30     return false;
31   }
32   int anObjectsNb = anAttrSelList->size();
33
34   int aMinObjectsNb = atoi(theArguments.back().c_str());
35
36   if(anObjectsNb < aMinObjectsNb) {
37     theError = "Error: Attribute \"%1\" should contain at least %2 items.";
38     theError.arg(aSelectionListId).arg(theArguments.back());
39     return false;
40   }
41
42   return true;
43 }
44
45 //================================================================================================
46 bool GeomValidators_MinObjectsSelected::isNotObligatory(std::string theFeature, 
47                                                         std::string theAttribute)
48 {
49   return false;
50 }