From: mpv Date: Mon, 20 Aug 2018 10:06:33 +0000 (+0300) Subject: Adapt selection of features in the Booleans and Fillet operations X-Git-Tag: SHAPER_V9_1_0RC1~61 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ee02bb5257de5e7d86d1ba57dde7d76bc1eae8d9;p=modules%2Fshaper.git Adapt selection of features in the Booleans and Fillet operations --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp index eab8b03ca..8b0fdab81 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp @@ -112,8 +112,16 @@ void FeaturesPlugin_Fillet::execute() return; ResultPtr aContext = anObjectAttr->context(); - ResultBodyPtr aCtxOwner = ModelAPI_Tools::bodyOwner(aContext); - GeomShapePtr aParent = aCtxOwner ? aCtxOwner->shape() : aContext->shape(); + GeomShapePtr aParent; + if (aContext.get()) { + ResultBodyPtr aCtxOwner = ModelAPI_Tools::bodyOwner(aContext); + aParent = aCtxOwner ? aCtxOwner->shape() : aContext->shape(); + } else { // get it from a feature + FeaturePtr aFeature = anObjectAttr->contextFeature(); + if (aFeature.get()) { + aParent = aFeature->firstResult()->shape(); + } + } if (!aParent) return; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 0b33e4c1f..f68b80173 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -588,7 +588,7 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt ResultPtr aContext = anAttrSelection->context(); if(!aContext.get()) { FeaturePtr aContFeat = anAttrSelection->contextFeature(); - if (!aContFeat.get()) { + if (!aContFeat.get() || !aContFeat->results().size()) { theError = "Error: Empty selection context."; return false; } @@ -603,7 +603,7 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt } } std::shared_ptr aShape = anAttrSelection->value(); - if(!aShape.get()) { + if(!aShape.get() && aContext.get()) { GeomShapePtr aContextShape = aContext->shape(); aShape = aContextShape; } @@ -676,8 +676,18 @@ bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAtt } ResultPtr aContext = anAttrSelection->context(); if(!aContext.get()) { - theError = "Error: Empty selection context."; - return false; + FeaturePtr aContFeat = anAttrSelection->contextFeature(); + if (!aContFeat.get() || !aContFeat->results().size() || + aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) { + theError = "Error: Empty selection context."; + return false; + } + if (aContFeat->results().size() == 1) + aContext = aContFeat->firstResult(); + else { + theError = "Error: Too many shapes selected."; + return false; + } } ResultBodyPtr aContextOwner = ModelAPI_Tools::bodyOwner(aContext); @@ -685,7 +695,7 @@ bool FeaturesPlugin_ValidatorFilletSelection::isValid(const AttributePtr& theAtt if (anOwner->shapeType() != GeomAPI_Shape::SOLID && anOwner->shapeType() != GeomAPI_Shape::COMPSOLID) { - theError = "Error: Not all selected shapes are sub-shapes of solids"; + theError = "Error: Not all selected shapes are sub-shapes of solids."; return false; } @@ -1233,9 +1243,13 @@ bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid( return false; } ResultPtr aContext = anAttrSelection->context(); - if (!aContext.get()) { - theError = "Error: Empty selection context."; - return false; + if(!aContext.get()) { + FeaturePtr aContFeat = anAttrSelection->contextFeature(); + if (!aContFeat.get() || !aContFeat->results().size() || + aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) { + theError = "Error: Empty selection context."; + return false; + } } ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast(aContext); @@ -1325,11 +1339,16 @@ bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttrib return false; } ResultPtr aContext = anAttrSelection->context(); - if (!aContext.get()) { - theError = "Error: empty selection context."; - return false; + if(!aContext.get()) { + FeaturePtr aContFeat = anAttrSelection->contextFeature(); + if (!aContFeat.get() || !aContFeat->results().size() || + aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) { + theError = "Error: Empty selection context."; + return false; + } } - FeaturePtr aFeature = ModelAPI_Feature::feature(aContext); + FeaturePtr aFeature = anAttrSelection->contextFeature().get() ? + anAttrSelection->contextFeature() : ModelAPI_Feature::feature(aContext); if (!aFeature.get()) { theError = "Error: empty feature."; return false; @@ -1343,15 +1362,15 @@ bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttrib return false; } std::shared_ptr aShape = anAttrSelection->value(); - GeomShapePtr aContextShape = aContext->shape(); if (!aShape.get()) { + GeomShapePtr aContextShape = aContext->shape(); aShape = aContextShape; } if (!aShape.get()) { theError = "Error: empty shape."; return false; } - if (!aShape->isEqual(aContextShape)) { + if (aContext.get() && !aShape->isEqual(aContext->shape())) { theError = "Error: Local selection not allowed."; return false; } @@ -1392,9 +1411,13 @@ bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid( return false; } ResultPtr aContext = anAttrSelection->context(); - if (!aContext.get()) { - theError = "Error: Empty selection context."; - return false; + if(!aContext.get()) { + FeaturePtr aContFeat = anAttrSelection->contextFeature(); + if (!aContFeat.get() || !aContFeat->results().size() || + aContFeat->firstResult()->groupName() != ModelAPI_ResultBody::group()) { + theError = "Error: Empty selection context."; + return false; + } } ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast(aContext); @@ -1403,15 +1426,15 @@ bool FeaturesPlugin_ValidatorBooleanFuseSelection::isValid( return false; } std::shared_ptr aShape = anAttrSelection->value(); - GeomShapePtr aContextShape = aContext->shape(); if (!aShape.get()) { + GeomShapePtr aContextShape = aContext->shape(); aShape = aContextShape; } if (!aShape.get()) { theError = "Error: Empty shape."; return false; } - if (!aShape->isEqual(aContextShape)) { + if (aContext.get() && !aShape->isEqual(aContext->shape())) { theError = "Error: Local selection not allowed."; return false; }