X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Validators.cpp;h=0de4d856a96de2bc262914492e50ad51b971cb81;hb=fb54db5e1466b16dfc029c4a7364a67a9a6a8c24;hp=0c0e893ba24e1eed4fa20274f3baf6e204a439b6;hpb=57e5ff999c4f23cc66bc2c91fc298c8acf63b2b2;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 0c0e893ba..0de4d856a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -10,7 +10,9 @@ #include #include #include +#include +#include #include //================================================================================================= @@ -153,7 +155,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute GeomValidators_ShapeType aShapeTypeValidator; if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) { theError = "Selected shape has unacceptable type. Acceptable types are: faces or wires on sketch, \ - whole sketch(if it has at least one face), and whole objects with shape types: "; +whole sketch(if it has at least one face), and whole objects with shape types: "; std::list::const_iterator anIt = theArguments.cbegin(); theError += *anIt; for(++anIt; anIt != theArguments.cend(); ++anIt) { @@ -175,23 +177,44 @@ bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theA const std::list& theArguments, std::string& theError) const { - FeaturesPlugin_ValidatorBaseForGeneration aBaseValidator; - - if(aBaseValidator.isValid(theAttribute, theArguments, theError)) { - return true; + if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) { + theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed"; + return false; + } + if (theArguments.size() != 2) { + theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type"; + return false; + } + // first argument is for the base attribute, second - for skipping feature kind + std::list::const_iterator anIt = theArguments.begin(); + std::string aBaseAttributeId = *anIt; + FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); + AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId); + if (!aBaseAttribute.get()) { + theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type"; + return false; } + if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled, + // this validator is not necessary anymore + return true; - // Check that face selected. - GeomValidators_ShapeType aShapeType; + anIt++; + std::string aFeatureAttributeKind = *anIt; + GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind(); + // check whether the selection is on the sketch std::list anArguments; - anArguments.push_back("face"); - if(aShapeType.isValid(theAttribute, anArguments, theError)) { - return true; - } + anArguments.push_back(aFeatureAttributeKind); - theError = "Selected shape is not suitable for this operation"; + bool aFeatureKind = aValidator->isValid(theAttribute, theArguments, theError); + bool aPlanarFace = false; + // check if selection has Face selected + GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType(); + anArguments.clear(); + anArguments.push_back("face"); + aPlanarFace = aShapeType->isValid(theAttribute, anArguments, theError); - return false; + bool aValid = !aFeatureKind && aPlanarFace; + return aValid; } //================================================================================================= @@ -199,21 +222,13 @@ bool FeaturesPlugin_ValidatorCanBeEmpty::isValid(const std::shared_ptr& theArguments, std::string& theError) const { - if(theArguments.size() != 5 && theArguments.size() != 6) { - theError = "Validator should be used with 6 parameters for extrusion and with 5 for revolution."; + if(theArguments.size() != 2) { + theError = "Validator should be used with 2 parameters for extrusion."; return false; } std::list::const_iterator anArgsIt = theArguments.begin(), aLast = theArguments.end(); - std::string aSelectedMethod; - if(theFeature->string(*anArgsIt)) { - aSelectedMethod = theFeature->string(*anArgsIt)->value(); - } - ++anArgsIt; - std::string aCreationMethod = *anArgsIt; - ++anArgsIt; - AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt); ++anArgsIt; @@ -221,33 +236,26 @@ bool FeaturesPlugin_ValidatorCanBeEmpty::isValid(const std::shared_ptrselection(*anArgsIt); + if(!aSelAttr.get()) { + theError = "Could not get selection attribute \"" + *anArgsIt + "\"."; + return false; } - for(; anArgsIt != theArguments.cend(); ++anArgsIt) { - AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt); - if(!aSelAttr.get()) { - theError = "Could not get selection attribute \"" + *anArgsIt + "\"."; + GeomShapePtr aShape = aSelAttr->value(); + if(!aShape.get()) { + ResultPtr aContext = aSelAttr->context(); + if(!aContext.get()) { + theError = "Selection attribute \"" + *anArgsIt + "\" can not be empty."; return false; } - GeomShapePtr aShape = aSelAttr->value(); - if(!aShape.get()) { - ResultPtr aContext = aSelAttr->context(); - if(!aContext.get()) { - theError = "Selection attribute \"" + *anArgsIt + "\" can not be empty."; - return false; - } - - aShape = aContext->shape(); - } + aShape = aContext->shape(); + } - if(!aShape.get()) { - theError = "Selection attribute \"" + *anArgsIt + "\" can not be empty."; - return false; - } + if(!aShape.get()) { + theError = "Selection attribute \"" + *anArgsIt + "\" can not be empty."; + return false; } return true;