1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomValidators_ZeroOffset.h
4 // Created: 13 May 2015
5 // Author: Dmitry Bobylev
7 #include <GeomValidators_ZeroOffset.h>
9 #include <GeomAPI_Shape.h>
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_AttributeSelection.h>
12 #include <ModelAPI_AttributeString.h>
14 //=================================================================================================
15 bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
16 const std::list<std::string>& theArguments) const
18 if(theArguments.size() != 8) {
22 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
24 std::string aSelectedMethod;
25 if(theFeature->string(*anIt)) {
26 aSelectedMethod = theFeature->string(*anIt)->value();
29 std::string aCreationMethod = *anIt;
33 double aFromSize = 0.0;
35 if(theFeature->real(*anIt)) {
36 aToSize = theFeature->real(*anIt)->value();
39 if(theFeature->real(*anIt)) {
40 aFromSize = theFeature->real(*anIt)->value();
44 if(aSelectedMethod == aCreationMethod) {
45 if(aToSize == 0.0 && aFromSize == 0.0) {
52 std::shared_ptr<GeomAPI_Shape> aToShape;
53 std::shared_ptr<GeomAPI_Shape> aFromShape;
55 std::shared_ptr<ModelAPI_AttributeSelection> anAttrSel = theFeature->selection(*anIt);
57 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
58 if(aToShape.get() == NULL && anAttrSel->context().get() != NULL) {
59 aToShape = anAttrSel->context()->shape();
64 std::shared_ptr<ModelAPI_AttributeDouble> anAttrDouble = theFeature->real(*anIt);
66 aToSize = anAttrDouble->value();
70 anAttrSel = theFeature->selection(*anIt);
72 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
73 if(aFromShape.get() == NULL && anAttrSel->context().get() != NULL) {
74 aFromShape = anAttrSel->context()->shape();
79 anAttrDouble = theFeature->real(*anIt);
81 aFromSize = anAttrDouble->value();
84 if(((!aFromShape && !aToShape) || ((aFromShape && aToShape) && aFromShape->isEqual(aToShape)))
85 && (aFromSize == 0.0 && aToSize == 0.0)) {
92 //=================================================================================================
93 bool GeomValidators_ZeroOffset::isNotObligatory(std::string theFeature, std::string theAttribute)
95 if(theAttribute == "from_object" || theAttribute == "to_object") {