Salome HOME
Merge with Dev_1.5.0
[modules/shaper.git] / src / GeomValidators / GeomValidators_PartitionArguments.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomValidators_PartitionArguments.cpp
4 // Created:     17 September 2015
5 // Author:      Dmitry Bobylev
6
7 #include <GeomValidators_PartitionArguments.h>
8
9 #include <ModelAPI_AttributeBoolean.h>
10 #include <ModelAPI_AttributeSelectionList.h>
11
12 //=================================================================================================
13 bool GeomValidators_PartitionArguments::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   bool isCombine = true;
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_AttributeBoolean> anAttrBool = theFeature->boolean(*anIt);
40   if(anAttrBool) {
41     isCombine = anAttrBool->value();
42   }
43
44   if((anObjectsNb > 0 && aToolsNb > 0) || (isCombine && anObjectsNb != 0 && (anObjectsNb + aToolsNb > 1))) {
45     return true;
46   }
47
48   theError = "Not enough arguments";
49   return false;
50 }
51
52 //=================================================================================================
53 bool GeomValidators_PartitionArguments::isNotObligatory(std::string theFeature, std::string theAttribute)
54 {
55   if(theAttribute == "tool_objects") {
56     return true;
57   }
58
59   return false;
60 }