]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomValidators/GeomValidators_MinObjectsSelected.cpp
Salome HOME
Merge branch 'BR_internationalization'
[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 <ModelAPI_AttributeInteger.h>
10 #include <ModelAPI_AttributeSelectionList.h>
11
12 //=================================================================================================
13 bool GeomValidators_MinObjectsSelected::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
14                                                 const std::list<std::string>& theArguments,
15                                                 std::string& theError) const
16 {
17   if(theArguments.size() != 2) {
18     theError = "Error: Wrong number of arguments (expected 2): selection list id and min number of objects";
19     return false;
20   }
21
22   std::string aSelectionListId = theArguments.front();
23   AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(aSelectionListId);
24   if(!anAttrSelList.get()) {
25     theError = "Error: Could not get attribute \"" + aSelectionListId + "\".";
26     return false;
27   }
28   int anObjectsNb = anAttrSelList->size();
29
30   int aMinObjectsNb = atoi(theArguments.back().c_str());
31
32   if(anObjectsNb < aMinObjectsNb) {
33     theError = "Error: Attribute \"" + aSelectionListId + "\" should contain at least "
34       + theArguments.back() + " items.";
35     return false;
36   }
37
38   return true;
39 }
40
41 //=================================================================================================
42 bool GeomValidators_MinObjectsSelected::isNotObligatory(std::string theFeature, std::string theAttribute)
43 {
44   return false;
45 }