Salome HOME
Add error descriptions for some feture and attribute validators
[modules/shaper.git] / src / GeomValidators / GeomValidators_ZeroOffset.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomValidators_ZeroOffset.cpp
4 // Created:     13 May 2015
5 // Author:      Dmitry Bobylev
6
7 #include <GeomValidators_ZeroOffset.h>
8
9 #include <GeomAPI_Shape.h>
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_AttributeString.h>
13
14 //=================================================================================================
15 bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
16                                         const std::list<std::string>& theArguments,
17                                         std::string& theError) const
18 {
19   if(theArguments.size() != 8) {
20     theError = "Wrong number of arguments (expected 8).";
21     return false;
22   }
23
24   std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
25
26   std::string aSelectedMethod;
27   if(theFeature->string(*anIt)) {
28     aSelectedMethod = theFeature->string(*anIt)->value();
29   }
30   anIt++;
31   std::string aCreationMethod = *anIt;
32   anIt++;
33   
34   double aToSize = 0.0;
35   double aFromSize = 0.0;
36
37   if(theFeature->real(*anIt)) {
38     aToSize = theFeature->real(*anIt)->value();
39   }
40   anIt++;
41   if(theFeature->real(*anIt)) {
42     aFromSize = theFeature->real(*anIt)->value();
43   }
44   anIt++;
45
46   if(aSelectedMethod == aCreationMethod) {
47     if(aToSize == -aFromSize) {
48       theError = "ToSize = -FromSize.";
49       return false;
50     } else {
51       return true;
52     }
53   }
54
55   std::shared_ptr<GeomAPI_Shape> aToShape;
56   std::shared_ptr<GeomAPI_Shape> aFromShape;
57
58   std::shared_ptr<ModelAPI_AttributeSelection> anAttrSel = theFeature->selection(*anIt);
59   if(anAttrSel) {
60     aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
61     if(aToShape.get() == NULL && anAttrSel->context().get() != NULL) {
62       aToShape =  anAttrSel->context()->shape();
63     }
64   }
65   anIt++;
66
67   std::shared_ptr<ModelAPI_AttributeDouble> anAttrDouble = theFeature->real(*anIt);
68   if(anAttrDouble) {
69     aToSize = anAttrDouble->value();
70   }
71   anIt++;
72
73   anAttrSel = theFeature->selection(*anIt);
74   if(anAttrSel) {
75     aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
76     if(aFromShape.get() == NULL && anAttrSel->context().get() != NULL) {
77       aFromShape = anAttrSel->context()->shape();
78     }
79   }
80   anIt++;
81
82   anAttrDouble = theFeature->real(*anIt);
83   if(anAttrDouble) {
84     aFromSize = anAttrDouble->value();
85   }
86
87   if(((!aFromShape && !aToShape) || ((aFromShape && aToShape) && aFromShape->isEqual(aToShape)))
88     && (aFromSize == -aToSize)) {
89     theError = "FromSize = -ToSize and bounding planes are equal.";
90     return false;
91   }
92
93   return true;
94 }
95
96 //=================================================================================================
97 bool GeomValidators_ZeroOffset::isNotObligatory(std::string theFeature, std::string theAttribute)
98 {
99   if(theAttribute == "from_object" || theAttribute == "to_object") {
100     return true;
101   }
102
103   return false;
104 }