Salome HOME
Merge branch 'master' of salome:modules/shaper
[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 <Events_InfoMessage.h>
10
11 #include <ModelAPI_AttributeBoolean.h>
12 #include <ModelAPI_AttributeSelectionList.h>
13
14 //=================================================================================================
15 bool GeomValidators_PartitionArguments::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   bool isCombine = true;
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_AttributeBoolean> anAttrBool = theFeature->boolean(*anIt);
42   if(anAttrBool) {
43     isCombine = anAttrBool->value();
44   }
45
46   if((anObjectsNb > 0 && aToolsNb > 0) || (isCombine && anObjectsNb != 0 && (anObjectsNb + aToolsNb > 1))) {
47     return true;
48   }
49
50   theError = "Not enough arguments";
51   return false;
52 }
53
54 //=================================================================================================
55 bool GeomValidators_PartitionArguments::isNotObligatory(std::string theFeature, std::string theAttribute)
56 {
57   if(theAttribute == "tool_objects") {
58     return true;
59   }
60
61   return false;
62 }