Salome HOME
Changed install paths for SALOME module
[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 <ModelAPI_AttributeInteger.h>
10 #include <ModelAPI_AttributeSelectionList.h>
11
12 //=================================================================================================
13 bool GeomValidators_BooleanArguments::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() != 3) {
18     theError = "Wrong number of arguments (expected 3).";
19     return false;
20   }
21
22   int anObjectsNb = 0, aToolsNb = 0;
23   int anOperationType = 0;
24
25   std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
26
27   std::shared_ptr<ModelAPI_AttributeSelectionList> anAttrSelList = theFeature->selectionList(*anIt);
28   if(anAttrSelList) {
29     anObjectsNb = anAttrSelList->size();
30   }
31   anIt++;
32
33   anAttrSelList = theFeature->selectionList(*anIt);
34   if(anAttrSelList) {
35     aToolsNb = anAttrSelList->size();
36   }
37   anIt++;
38
39   std::shared_ptr<ModelAPI_AttributeInteger> anAttrInt = theFeature->integer(*anIt);
40   if(anAttrInt) {
41     anOperationType = anAttrInt->value();
42   }
43
44   if(anOperationType == 1 && (anObjectsNb + aToolsNb > 1)) {
45     return true;
46   } else if (anOperationType != 1 && anObjectsNb > 0 && aToolsNb > 0) {
47     return true;
48   }
49
50   theError = "Not enough arguments";
51   return false;
52 }
53
54 //=================================================================================================
55 bool GeomValidators_BooleanArguments::isNotObligatory(std::string theFeature, std::string theAttribute)
56 {
57   if(theAttribute == "main_objects" || theAttribute == "tool_objects") {
58     return true;
59   }
60
61   return false;
62 }