From: nds Date: Tue, 5 Apr 2016 11:54:49 +0000 (+0300) Subject: Issue #1343. Improvement of Extrusion and Revolution operations: sketch creator setSe... X-Git-Tag: V_2.3.0~300 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d44671b5418920fef3264b53af7e62a8f8cb2bb7;p=modules%2Fshaper.git Issue #1343. Improvement of Extrusion and Revolution operations: sketch creator setSelection in two ways(Sketch or Selection list), so the validators should be checked in the same manner, in two ways(call validator for Sektch after(if invalid) validator for Selection list). --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index b5f0d6944..1de58f332 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -36,10 +36,8 @@ FeaturesPlugin_Plugin::FeaturesPlugin_Plugin() ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); aFactory->registerValidator("FeaturesPlugin_ValidatorTransform", new FeaturesPlugin_ValidatorTransform); - aFactory->registerValidator("FeaturesPlugin_ValidatorCompositeLauncherE", - new FeaturesPlugin_ValidatorCompositeLauncher); aFactory->registerValidator("FeaturesPlugin_ValidatorCompositeLauncher", - new FeaturesPlugin_ValidatorCompositeLauncher_); + new FeaturesPlugin_ValidatorCompositeLauncher); aFactory->registerValidator("FeaturesPlugin_ValidatorBaseForGeneration", new FeaturesPlugin_ValidatorBaseForGeneration); aFactory->registerValidator("FeaturesPlugin_ValidatorPipeLocations", diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 1470d0353..2230d9eb2 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -181,43 +181,40 @@ bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theA theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed"; return false; } - - bool aValid = true; - GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind(); - // check whether the selection is on the sketch - bool aFeatureKindValid = aValidator->isValid(theAttribute, theArguments, theError); - if (!aFeatureKindValid) { - // check if selection has Face selected - GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType(); - std::list anArguments; - anArguments.push_back("face"); - aValid = aShapeType->isValid(theAttribute, anArguments, theError); + if (theArguments.size() != 2) { + theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type"; + return false; } - return aValid; -} - -//================================================================================================= -bool FeaturesPlugin_ValidatorCompositeLauncher_::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const -{ - FeaturesPlugin_ValidatorBaseForGeneration aBaseValidator; - - if(aBaseValidator.isValid(theAttribute, theArguments, theError)) { - return true; + // 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; } //================================================================================================= diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.h b/src/FeaturesPlugin/FeaturesPlugin_Validators.h index 87bd3228d..e02b2ee63 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.h @@ -64,21 +64,6 @@ public: std::string& theError) const; }; -/// \class FeaturesPlugin_ValidatorCompositeLauncher -/// \ingroup Validators -/// \brief A validator for selection at composite feature start -class FeaturesPlugin_ValidatorCompositeLauncher_: public ModelAPI_AttributeValidator -{ -public: - //! Returns true if attribute has selection type listed in the parameter arguments. - //! \param[in] theAttribute the checked attribute. - //! \param[in] theArguments arguments of the attribute. - //! \param[out] theError error message. - virtual bool isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const; -}; - /// \class FeaturesPlugin_ValidatorCanBeEmpty /// \ingroup Validators /// \brief A validator for extrusion direction attribute and bounding planes for extrusion and diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 350cac022..4c94677a1 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -8,7 +8,7 @@ 2. An existing sketch face or contour. Extrusion will be filled by it.<br /> 3. An existing result shape of kind: wires/edge/vertices.Extrusion will be filled by it." shape_types="faces objects"> - + + - + + - + + - + + - + + - + #include #include +#include #include #define DEBUG_EXTRUSION_INVALID_SKETCH @@ -102,6 +103,21 @@ bool GeomValidators_FeatureKind::isValid(const AttributePtr& theAttribute, } } } + if (anAttributeType == ModelAPI_AttributeReference::typeId()) { + AttributeReferencePtr aRefAttr = + std::dynamic_pointer_cast(theAttribute); + ObjectPtr anObject = aRefAttr->value(); + // a context of the selection attribute is a feature result. It can be a case when the result + // of the feature is null, e.g. the feature is modified and has not been executed yet. + // The validator returns an invalid result here. The case is an extrusion built on a sketch + // feature. A new sketch element creation leads to an empty result. + if (!anObject.get()) + isSketchEntities = false; + else { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); + } + } if (!isSketchEntities) { theError = "It refers to feature, which kind is not in the list: " + anEntityKindsStr; } diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp index 5ad27fc38..e6a96f355 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.cpp +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -34,6 +34,7 @@ GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const MyShapeTypes["face"] = Face; MyShapeTypes["solid"] = Solid; MyShapeTypes["plane"] = Plane; + MyShapeTypes["shell"] = Shell; } std::string aType = std::string(theType.c_str()); if (MyShapeTypes.find(aType) != MyShapeTypes.end()) @@ -220,6 +221,8 @@ bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape, aValid = theShape->isSolid() || theShape->isCompSolid() || theShape->isCompoundOfSolids(); break; + case Shell: + aValid = theShape->shapeType() == GeomAPI_Shape::SHELL; case Compound: aValid = theShape->isCompound(); break; diff --git a/src/GeomValidators/GeomValidators_ShapeType.h b/src/GeomValidators/GeomValidators_ShapeType.h index 50be8a5ec..93349a5e5 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.h +++ b/src/GeomValidators/GeomValidators_ShapeType.h @@ -35,6 +35,7 @@ class GeomValidators_ShapeType : public ModelAPI_AttributeValidator Face, Plane, Solid, + Shell, Compound, AnyShape }; diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index c6a0ebb08..48de5bdbd 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -129,21 +129,38 @@ AttributePtr PartSet_WidgetSketchCreator::attribute() const bool PartSet_WidgetSketchCreator::isValidSelection(const ModuleBase_ViewerPrs& theValue) { bool aValid = false; - if (getValidState(theValue, aValid)) { - return aValid; - } - // check selection to create new sketh (XML current attribute) - aValid = isValidSelectionForAttribute(theValue, attribute()); - if (!aValid) { - // check selection to fill list attribute (myAttributeListID) - myIsCustomAttribute = true; + if (myIsCustomAttribute) { + // check only suiting of the value to custom attribute (myAttributeListID) + // do not cash of validation to avoid using states, stored for XML attribute + // there is an alternative is to call clearValidatedCash() in setSelection() aValid = isValidSelectionForAttribute(theValue, attribute()); - myIsCustomAttribute = false; + } + else { /// if the validated attribute is already custom + if (getValidState(theValue, aValid)) { + return aValid; + } + aValid = isValidSelectionCustom(theValue); + if (!aValid) + // check selection to create new sketh (XML current attribute) + aValid = isValidSelectionForAttribute(theValue, attribute()); + if (!aValid) { + // check selection to fill list attribute (myAttributeListID) + bool isCustomAttribute = myIsCustomAttribute; + myIsCustomAttribute = true; + aValid = isValidSelectionForAttribute(theValue, attribute()); + myIsCustomAttribute = isCustomAttribute; + } } storeValidState(theValue, aValid); return aValid; } +//******************************************************************** +bool PartSet_WidgetSketchCreator::isValidSelectionCustom(const ModuleBase_ViewerPrs& theValue) +{ + return PartSet_WidgetSketchLabel::canFillSketch(theValue); +} + void PartSet_WidgetSketchCreator::activateSelectionControl() { setVisibleSelectionControl(true); @@ -286,7 +303,7 @@ bool PartSet_WidgetSketchCreator::setSelection(QList& theV if (!theToValidate || isValidInFilters(aValue)) aProcessed = setSelectionCustom(aValue) || aProcessed; } - myIsCustomAttribute = true; + myIsCustomAttribute = false; aDone = aProcessed; if (aProcessed) { emit valuesChanged(); diff --git a/src/PartSet/PartSet_WidgetSketchCreator.h b/src/PartSet/PartSet_WidgetSketchCreator.h index 8ccb24b25..a53166444 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.h +++ b/src/PartSet/PartSet_WidgetSketchCreator.h @@ -77,6 +77,11 @@ public: static bool canCommitCurrentSketch(ModuleBase_IWorkshop* theWorkshop); protected: + /// Checks whether the selection presentation contains preview planes + /// \param theValue a selection information + /// \return a boolean value + virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& theValue); + /// Saves the internal parameters to the given feature /// \return True in success virtual bool storeValueCustom() const;