]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomValidators/GeomValidators_BooleanArguments.cpp
Salome HOME
Fixed crash on when creating circle by 3 points.
[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       }
50     }
51   }
52   anIt++;
53
54
55   anAttrSelList = theFeature->selectionList(*anIt);
56   if(anAttrSelList) {
57     aToolsNb = anAttrSelList->size();
58     for(int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
59       AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
60       ResultPtr aContext = anAttr->context();
61       ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
62       if(aResCompSolidPtr.get()) {
63         if(aCompSolid.get()) {
64           isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
65         } else {
66           aCompSolid = aResCompSolidPtr;
67         }
68       } else {
69         isAllInSameCompSolid = false;
70       }
71     }
72   }
73   anIt++;
74
75   std::shared_ptr<ModelAPI_AttributeInteger> anAttrInt = theFeature->integer(*anIt);
76   if(anAttrInt) {
77     anOperationType = anAttrInt->value();
78   }
79
80   if(anOperationType == 1) {
81     // Fuse operation
82     if(anObjectsNb + aToolsNb < 2) {
83       theError = "Not enough arguments for Fuse operation.";
84       return false;
85     } else if(isAllInSameCompSolid) {
86       theError = "Operations only between sub-shapes of the same shape not allowed.";
87       return false;
88     }
89   } else {
90     if(anObjectsNb < 1) {
91       theError = "Objects not selected.";
92       return false;
93     }
94     if(aToolsNb < 1) {
95       theError = "Tools not selected.";
96       return false;
97     }
98     if(isAllInSameCompSolid) {
99       theError = "Operations only between sub-shapes of the same shape not allowed.";
100       return false;
101     }
102   }
103
104   return true;
105 }
106
107 //=================================================================================================
108 bool GeomValidators_BooleanArguments::isNotObligatory(std::string theFeature,
109                                                       std::string theAttribute)
110 {
111   if(theAttribute == "main_objects" || theAttribute == "tool_objects") {
112     return true;
113   }
114
115   return false;
116 }