Salome HOME
63e6d5f89a8f49a27b7f21ab8524db6dbcc02f50
[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     return false;
21   }
22
23   std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
24
25   std::string aSelectedMethod;
26   if(theFeature->string(*anIt)) {
27     aSelectedMethod = theFeature->string(*anIt)->value();
28   }
29   anIt++;
30   std::string aCreationMethod = *anIt;
31   anIt++;
32   
33   double aToSize = 0.0;
34   double aFromSize = 0.0;
35
36   if(theFeature->real(*anIt)) {
37     aToSize = theFeature->real(*anIt)->value();
38   }
39   anIt++;
40   if(theFeature->real(*anIt)) {
41     aFromSize = theFeature->real(*anIt)->value();
42   }
43   anIt++;
44
45   if(aSelectedMethod == aCreationMethod) {
46     if(aToSize == 0.0 && aFromSize == 0.0) {
47       return false;
48     } else {
49       return true;
50     }
51   }
52
53   std::shared_ptr<GeomAPI_Shape> aToShape;
54   std::shared_ptr<GeomAPI_Shape> aFromShape;
55
56   std::shared_ptr<ModelAPI_AttributeSelection> anAttrSel = theFeature->selection(*anIt);
57   if(anAttrSel) {
58     aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
59     if(aToShape.get() == NULL && anAttrSel->context().get() != NULL) {
60       aToShape =  anAttrSel->context()->shape();
61     }
62   }
63   anIt++;
64
65   std::shared_ptr<ModelAPI_AttributeDouble> anAttrDouble = theFeature->real(*anIt);
66   if(anAttrDouble) {
67     aToSize = anAttrDouble->value();
68   }
69   anIt++;
70
71   anAttrSel = theFeature->selection(*anIt);
72   if(anAttrSel) {
73     aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
74     if(aFromShape.get() == NULL && anAttrSel->context().get() != NULL) {
75       aFromShape = anAttrSel->context()->shape();
76     }
77   }
78   anIt++;
79
80   anAttrDouble = theFeature->real(*anIt);
81   if(anAttrDouble) {
82     aFromSize = anAttrDouble->value();
83   }
84
85   if(((!aFromShape && !aToShape) || ((aFromShape && aToShape) && aFromShape->isEqual(aToShape)))
86     && (aFromSize == 0.0 && aToSize == 0.0)) {
87     return false;
88   }
89
90   return true;
91 }
92
93 //=================================================================================================
94 bool GeomValidators_ZeroOffset::isNotObligatory(std::string theFeature, std::string theAttribute)
95 {
96   if(theAttribute == "from_object" || theAttribute == "to_object") {
97     return true;
98   }
99
100   return false;
101 }