1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomValidators_ZeroOffset.cpp
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,
17 std::string& theError) const
19 if(theArguments.size() != 8) {
20 theError = "Wrong number of arguments (expected 8).";
24 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
26 std::string aSelectedMethod;
27 if(theFeature->string(*anIt)) {
28 aSelectedMethod = theFeature->string(*anIt)->value();
31 std::string aCreationMethod = *anIt;
35 double aFromSize = 0.0;
37 if(theFeature->real(*anIt)) {
38 aToSize = theFeature->real(*anIt)->value();
41 if(theFeature->real(*anIt)) {
42 aFromSize = theFeature->real(*anIt)->value();
46 if(aSelectedMethod == aCreationMethod) {
47 if(aToSize == -aFromSize) {
48 theError = "ToSize = -FromSize.";
55 std::shared_ptr<GeomAPI_Shape> aToShape;
56 std::shared_ptr<GeomAPI_Shape> aFromShape;
58 std::shared_ptr<ModelAPI_AttributeSelection> anAttrSel = theFeature->selection(*anIt);
60 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
61 if(aToShape.get() == NULL && anAttrSel->context().get() != NULL) {
62 aToShape = anAttrSel->context()->shape();
67 std::shared_ptr<ModelAPI_AttributeDouble> anAttrDouble = theFeature->real(*anIt);
69 aToSize = anAttrDouble->value();
73 anAttrSel = theFeature->selection(*anIt);
75 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
76 if(aFromShape.get() == NULL && anAttrSel->context().get() != NULL) {
77 aFromShape = anAttrSel->context()->shape();
82 anAttrDouble = theFeature->real(*anIt);
84 aFromSize = anAttrDouble->value();
87 if(((!aFromShape && !aToShape) || ((aFromShape && aToShape) && aFromShape->isEqual(aToShape)))
88 && (aFromSize == -aToSize)) {
89 theError = "FromSize = -ToSize and bounding planes are equal.";
96 //=================================================================================================
97 bool GeomValidators_ZeroOffset::isNotObligatory(std::string theFeature, std::string theAttribute)
99 if(theAttribute == "from_object" || theAttribute == "to_object") {