// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-// File: GeomValidators_ZeroOffset.h
+// File: GeomValidators_ZeroOffset.cpp
// Created: 13 May 2015
// Author: Dmitry Bobylev
#include <GeomAPI_Shape.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeString.h>
//=================================================================================================
bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::list<std::string>& theArguments) const
+ const std::list<std::string>& theArguments,
+ std::string& theError) const
{
- if(theArguments.size() < 4) {
+ if(theArguments.size() != 8) {
return false;
}
std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
- std::shared_ptr<GeomAPI_Shape> aFromShape;
- std::shared_ptr<GeomAPI_Shape> aToShape;
+ std::string aSelectedMethod;
+ if(theFeature->string(*anIt)) {
+ aSelectedMethod = theFeature->string(*anIt)->value();
+ }
+ anIt++;
+ std::string aCreationMethod = *anIt;
+ anIt++;
+
+ double aToSize = 0.0;
+ double aFromSize = 0.0;
- std::shared_ptr<ModelAPI_AttributeSelection> anAttrSel = theFeature->selection(*anIt);
- if(anAttrSel) {
- aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
+ if(theFeature->real(*anIt)) {
+ aToSize = theFeature->real(*anIt)->value();
}
anIt++;
- anAttrSel = theFeature->selection(*anIt);
+ if(theFeature->real(*anIt)) {
+ aFromSize = theFeature->real(*anIt)->value();
+ }
+ anIt++;
+
+ if(aSelectedMethod == aCreationMethod) {
+ if(aToSize == -aFromSize) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ std::shared_ptr<GeomAPI_Shape> aToShape;
+ std::shared_ptr<GeomAPI_Shape> aFromShape;
+
+ std::shared_ptr<ModelAPI_AttributeSelection> anAttrSel = theFeature->selection(*anIt);
if(anAttrSel) {
aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
+ if(aToShape.get() == NULL && anAttrSel->context().get() != NULL) {
+ aToShape = anAttrSel->context()->shape();
+ }
}
anIt++;
- double aFromOffset = 0.0;
- double aToOffset = 0.0;
-
std::shared_ptr<ModelAPI_AttributeDouble> anAttrDouble = theFeature->real(*anIt);
if(anAttrDouble) {
- aFromOffset = anAttrDouble->value();
+ aToSize = anAttrDouble->value();
}
anIt++;
+
+ anAttrSel = theFeature->selection(*anIt);
+ if(anAttrSel) {
+ aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anAttrSel->value());
+ if(aFromShape.get() == NULL && anAttrSel->context().get() != NULL) {
+ aFromShape = anAttrSel->context()->shape();
+ }
+ }
+ anIt++;
+
anAttrDouble = theFeature->real(*anIt);
if(anAttrDouble) {
- aToOffset = anAttrDouble->value();
+ aFromSize = anAttrDouble->value();
}
if(((!aFromShape && !aToShape) || ((aFromShape && aToShape) && aFromShape->isEqual(aToShape)))
- && (aFromOffset == 0.0 && aToOffset == 0.0)) {
+ && (aFromSize == -aToSize)) {
return false;
}