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) {
23 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
25 std::string aSelectedMethod;
26 if(theFeature->string(*anIt)) {
27 aSelectedMethod = theFeature->string(*anIt)->value();
30 std::string aCreationMethod = *anIt;
34 double aFromSize = 0.0;
36 if(theFeature->real(*anIt)) {
37 aToSize = theFeature->real(*anIt)->value();
40 if(theFeature->real(*anIt)) {
41 aFromSize = theFeature->real(*anIt)->value();
45 if(aSelectedMethod == aCreationMethod) {
46 if(aToSize == -aFromSize) {
53 std::shared_ptr<GeomAPI_Shape> aToShape;
54 std::shared_ptr<GeomAPI_Shape> aFromShape;
56 std::shared_ptr<ModelAPI_AttributeSelection> anAttrSel = theFeature->selection(*anIt);
58 aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
59 if(aToShape.get() == NULL && anAttrSel->context().get() != NULL) {
60 aToShape = anAttrSel->context()->shape();
65 std::shared_ptr<ModelAPI_AttributeDouble> anAttrDouble = theFeature->real(*anIt);
67 aToSize = anAttrDouble->value();
71 anAttrSel = theFeature->selection(*anIt);
73 aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
74 if(aFromShape.get() == NULL && anAttrSel->context().get() != NULL) {
75 aFromShape = anAttrSel->context()->shape();
80 anAttrDouble = theFeature->real(*anIt);
82 aFromSize = anAttrDouble->value();
85 if(((!aFromShape && !aToShape) || ((aFromShape && aToShape) && aFromShape->isEqual(aToShape)))
86 && (aFromSize == -aToSize)) {
93 //=================================================================================================
94 bool GeomValidators_ZeroOffset::isNotObligatory(std::string theFeature, std::string theAttribute)
96 if(theAttribute == "from_object" || theAttribute == "to_object") {