Salome HOME
Comment Split output
[modules/shaper.git] / src / GeomValidators / GeomValidators_BooleanArguments.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomValidators_BooleanArguments.cpp
4 // Created:     30 June 2015
5 // Author:      Dmitry Bobylev
6
7 #include <GeomValidators_BooleanArguments.h>
8
9 #include <Events_InfoMessage.h>
10
11 #include <ModelAPI_AttributeInteger.h>
12 #include <ModelAPI_AttributeSelectionList.h>
13
14 //=================================================================================================
15 bool GeomValidators_BooleanArguments::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() != 3) {
20     theError = "Wrong number of arguments (expected 3).";
21     return false;
22   }
23
24   int anObjectsNb = 0, aToolsNb = 0;
25   int anOperationType = 0;
26
27   std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
28
29   std::shared_ptr<ModelAPI_AttributeSelectionList> anAttrSelList = theFeature->selectionList(*anIt);
30   if(anAttrSelList) {
31     anObjectsNb = anAttrSelList->size();
32   }
33   anIt++;
34
35   anAttrSelList = theFeature->selectionList(*anIt);
36   if(anAttrSelList) {
37     aToolsNb = anAttrSelList->size();
38   }
39   anIt++;
40
41   std::shared_ptr<ModelAPI_AttributeInteger> anAttrInt = theFeature->integer(*anIt);
42   if(anAttrInt) {
43     anOperationType = anAttrInt->value();
44   }
45
46   if(anOperationType == 1 && (anObjectsNb + aToolsNb > 1)) {
47     return true;
48   } else if (anOperationType != 1 && anObjectsNb > 0 && aToolsNb > 0) {
49     return true;
50   }
51
52   theError = "Not enough arguments";
53   return false;
54 }
55
56 //=================================================================================================
57 bool GeomValidators_BooleanArguments::isNotObligatory(std::string theFeature, std::string theAttribute)
58 {
59   if(theAttribute == "main_objects" || theAttribute == "tool_objects") {
60     return true;
61   }
62
63   return false;
64 }