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