Salome HOME
Feature #524: 4.01. Revolution feature (not complete!)
[modules/shaper.git] / src / GeomValidators / GeomValidators_ZeroOffset.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomValidators_ZeroOffset.h
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
13 //=================================================================================================
14 bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
15                                         const std::list<std::string>& theArguments) const
16 {
17   if(theArguments.size() < 4) {
18     return false;
19   }
20
21   std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
22
23   std::shared_ptr<GeomAPI_Shape> aFromShape;
24   std::shared_ptr<GeomAPI_Shape> aToShape;
25
26   std::shared_ptr<ModelAPI_AttributeSelection> anAttrSel = theFeature->selection(*anIt);
27   if(anAttrSel) {
28     aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
29   }
30   anIt++;
31   anAttrSel = theFeature->selection(*anIt);
32   if(anAttrSel) {
33     aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
34   }
35   anIt++;
36
37   double aFromOffset = 0.0;
38   double aToOffset = 0.0;
39
40   std::shared_ptr<ModelAPI_AttributeDouble> anAttrDouble = theFeature->real(*anIt);
41   if(anAttrDouble) {
42     aFromOffset = anAttrDouble->value();
43   }
44   anIt++;
45   anAttrDouble = theFeature->real(*anIt);
46   if(anAttrDouble) {
47     aToOffset = anAttrDouble->value();
48   }
49
50   if(((!aFromShape && !aToShape) || ((aFromShape && aToShape) && aFromShape->isEqual(aToShape)))
51     && (aFromOffset == 0.0 && aToOffset == 0.0)) {
52     return false;
53   }
54
55   return true;
56 }
57
58 //=================================================================================================
59 bool GeomValidators_ZeroOffset::isNotObligatory(std::string theFeature, std::string theAttribute)
60 {
61   if(theAttribute == "from_object" || theAttribute == "to_object") {
62     return true;
63   }
64
65   return false;
66 }