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