Salome HOME
Validators return InfoMessage instead of string as an error
[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 \"" + aSelectionListId + "\".";
28     return false;
29   }
30   int anObjectsNb = anAttrSelList->size();
31
32   int aMinObjectsNb = atoi(theArguments.back().c_str());
33
34   if(anObjectsNb < aMinObjectsNb) {
35     theError = "Error: Attribute \"" + aSelectionListId + "\" should contain at least "
36       + theArguments.back() + " items.";
37     return false;
38   }
39
40   return true;
41 }
42
43 //=================================================================================================
44 bool GeomValidators_MinObjectsSelected::isNotObligatory(std::string theFeature, std::string theAttribute)
45 {
46   return false;
47 }