]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomValidators/GeomValidators_BooleanArguments.cpp
Salome HOME
7890550f28b1b658b72b516be3fe0e98b25358f2
[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 #include <ModelAPI_ResultCompSolid.h>
14 #include <ModelAPI_Tools.h>
15
16 //=================================================================================================
17 bool GeomValidators_BooleanArguments::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
18                                               const std::list<std::string>& theArguments,
19                                               Events_InfoMessage& theError) const
20 {
21   if(theArguments.size() != 3) {
22     theError = "Wrong number of arguments (expected 3).";
23     return false;
24   }
25
26   int anObjectsNb = 0, aToolsNb = 0;
27   int anOperationType = 0;
28
29   std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
30
31   bool isAllInSameCompSolid = true;
32   ResultCompSolidPtr aCompSolid;
33
34   AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
35   if(anAttrSelList) {
36     anObjectsNb = anAttrSelList->size();
37     for(int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
38       AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
39       ResultPtr aContext = anAttr->context();
40       ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
41       if(aResCompSolidPtr.get()) {
42         if(aCompSolid.get()) {
43           isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
44         } else {
45           aCompSolid = aResCompSolidPtr;
46         }
47       } else {
48         isAllInSameCompSolid = false;
49         break;
50       }
51     }
52   }
53   anIt++;
54
55
56   anAttrSelList = theFeature->selectionList(*anIt);
57   if(anAttrSelList) {
58     aToolsNb = anAttrSelList->size();
59     if(isAllInSameCompSolid) {
60       for(int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
61         AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
62         ResultPtr aContext = anAttr->context();
63         ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
64         if(aResCompSolidPtr.get()) {
65           if(aCompSolid.get()) {
66             isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
67           } else {
68             aCompSolid = aResCompSolidPtr;
69           }
70         } else {
71           isAllInSameCompSolid = false;
72           break;
73         }
74       }
75     }
76   }
77   anIt++;
78
79   std::shared_ptr<ModelAPI_AttributeInteger> anAttrInt = theFeature->integer(*anIt);
80   if(anAttrInt) {
81     anOperationType = anAttrInt->value();
82   }
83
84   if(anOperationType == 1) {
85     // Fuse operation
86     if(anObjectsNb + aToolsNb < 2) {
87       theError = "Not enough arguments for Fuse operation.";
88       return false;
89     } else if(isAllInSameCompSolid) {
90       theError = "Operations only between sub-shapes of the same shape not allowed.";
91       return false;
92     }
93   } else {
94     if(anObjectsNb < 1) {
95       theError = "Objects not selected.";
96       return false;
97     }
98     if(aToolsNb < 1) {
99       theError = "Tools not selected.";
100       return false;
101     }
102     if(isAllInSameCompSolid) {
103       theError = "Operations only between sub-shapes of the same shape not allowed.";
104       return false;
105     }
106   }
107
108   return true;
109 }
110
111 //=================================================================================================
112 bool GeomValidators_BooleanArguments::isNotObligatory(std::string theFeature,
113                                                       std::string theAttribute)
114 {
115   if(theAttribute == "main_objects" || theAttribute == "tool_objects") {
116     return true;
117   }
118
119   return false;
120 }