From: nds Date: Wed, 5 Nov 2014 10:01:48 +0000 (+0300) Subject: refs #222 - correction to do not select the same parameters in the distance constraint. X-Git-Tag: V_0.5~39 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c441722ea3b03a2800fec9967980727db7d93251;p=modules%2Fshaper.git refs #222 - correction to do not select the same parameters in the distance constraint. refs #196 - return an empty preview presentation if the parameters are invalid. --- diff --git a/src/ModelAPI/ModelAPI_RefAttrValidator.h b/src/ModelAPI/ModelAPI_RefAttrValidator.h index e5b1b6690..1f690ca47 100644 --- a/src/ModelAPI/ModelAPI_RefAttrValidator.h +++ b/src/ModelAPI/ModelAPI_RefAttrValidator.h @@ -7,6 +7,7 @@ #include #include +#include #include /* @@ -18,6 +19,11 @@ public: //! Returns true if object is good for the feature attribute virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, const ObjectPtr& theObject) const = 0; + + //! Returns true if the attribute is good for the feature attribute + virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, + const AttributePtr& theAttribute) const = 0; + }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp index d9674c4d4..cea8d1ec4 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.cpp @@ -7,6 +7,9 @@ #include #include +#include +#include + #include #include @@ -49,30 +52,16 @@ bool ModuleBase_WidgetFeatureOrAttribute::setValue(ModuleBase_WidgetValue* theVa ModuleBase_WidgetValueFeature* aFeatureValue = dynamic_cast(theValue); if (aFeatureValue) { - boost::shared_ptr aValuePoint = aFeatureValue->point(); ObjectPtr aObject = aFeatureValue->object(); - if (aObject) { - isDone = setObject(aObject, false); + + boost::shared_ptr anAttribute = findAttribute(aFeatureValue); + if (anAttribute) { + isDone = setAttribute(anAttribute, false); } - if (aValuePoint) { - FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); - if (aFeature) { - // find the given point in the feature attributes - std::list > anAttiributes = aFeature->data() - ->attributes(GeomDataAPI_Point2D::type()); - std::list >::const_iterator anIt = anAttiributes - .begin(), aLast = anAttiributes.end(); - boost::shared_ptr aFPoint; - for (; anIt != aLast && !aFPoint; anIt++) { - boost::shared_ptr aCurPoint = boost::dynamic_pointer_cast< - GeomDataAPI_Point2D>(*anIt); - if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion()) - aFPoint = aCurPoint; - } - if (aFPoint) - isDone = setAttribute(aFPoint, false); - } + else if (aObject) { + isDone = setObject(aObject, false); } + if (isDone) emit valuesChanged(); } @@ -125,12 +114,62 @@ bool ModuleBase_WidgetFeatureOrAttribute::restoreValue() return false; } +boost::shared_ptr ModuleBase_WidgetFeatureOrAttribute::findAttribute( + ModuleBase_WidgetValue* theValue) +{ + boost::shared_ptr anAttribute; + ModuleBase_WidgetValueFeature* aFeatureValue = + dynamic_cast(theValue); + if (!aFeatureValue) + return anAttribute; + + boost::shared_ptr aValuePoint = aFeatureValue->point(); + if (aValuePoint) { + ObjectPtr aObject = aFeatureValue->object(); + FeaturePtr aFeature = ModelAPI_Feature::feature(aObject); + if (aFeature) { + // find the given point in the feature attributes + std::list > anAttiributes = aFeature->data() + ->attributes(GeomDataAPI_Point2D::type()); + std::list >::const_iterator anIt = anAttiributes + .begin(), aLast = anAttiributes.end(); + for (; anIt != aLast && !anAttribute; anIt++) { + boost::shared_ptr aCurPoint = boost::dynamic_pointer_cast< + GeomDataAPI_Point2D>(*anIt); + if (aCurPoint && aCurPoint->pnt()->distance(aValuePoint) < Precision::Confusion()) + anAttribute = aCurPoint; + } + } + } + return anAttribute; +} + bool ModuleBase_WidgetFeatureOrAttribute::setAttribute( const boost::shared_ptr& theAttribute, bool theSendEvent) { if (!theAttribute) // || !featureKinds().contains(theAttribute->attributeType().c_str())) return false; + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + std::list aValidators; + std::list > anArguments; + aFactory->validators(parentID(), attributeID(), aValidators, anArguments); + + // Check the acceptability of the attribute + std::list::iterator aValidator = aValidators.begin(); + int aSize = aValidators.size(); + std::list >::iterator aArgs = anArguments.begin(); + for (; aValidator != aValidators.end(); aValidator++, aArgs++) { + const ModelAPI_RefAttrValidator* aAttrValidator = + dynamic_cast(*aValidator); + if (aAttrValidator) { + if (!aAttrValidator->isValid(myFeature, *aArgs, theAttribute)) { + return false; + } + } + } + myAttribute = theAttribute; editor()->setText(theAttribute ? theAttribute->attributeType().c_str() : ""); if (theSendEvent) diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h index 9774bd205..1dfd055ce 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h +++ b/src/ModuleBase/ModuleBase_WidgetFeatureOrAttribute.h @@ -44,6 +44,11 @@ Q_OBJECT virtual bool isViewerSelector() { return true; } protected: + /// Returns the feature attribute if it can be found by the given value + /// \param theValue the widget value + /// \return an attribute or null + boost::shared_ptr findAttribute(ModuleBase_WidgetValue* theValue); + /// Set the attribute /// \param theAttribute value /// \return the boolean result of the attribute set diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 0ce7f3558..031a3b98b 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -101,8 +101,8 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi aPnt_B = getProjectionPoint(aLine, aPnt_A); } } - if (!aPnt_A || !aPnt_B || aPnt_A->isEqual(aPnt_B)) - return thePrevious; + if (!aPnt_A || !aPnt_B) + return AISObjectPtr(); boost::shared_ptr aFlyOutAttr = boost::dynamic_pointer_cast< GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index b71d5adbd..822ddaf6c 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -89,3 +89,21 @@ bool SketchPlugin_DifferentObjectsValidator::isValid( } return true; } + +bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, + const std::list& theArguments, const AttributePtr& theAttribute) const +{ + std::list > anAttrs = + theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type()); + std::list >::iterator anAttr = anAttrs.begin(); + for(; anAttr != anAttrs.end(); anAttr++) { + if (*anAttr) { + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(*anAttr); + // check the object is already presented + if (!aRef->isObject() && aRef->attr() == theAttribute) + return false; + } + } + return true; +} diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index d8dcba2e0..14647fa71 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -20,6 +20,9 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, const ObjectPtr& theObject) const; + //! Returns true if the attribute is good for the feature attribute + virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, + const AttributePtr& theAttribute) const { return true; }; }; /** @@ -37,7 +40,9 @@ class SketchPlugin_DifferentObjectsValidator : public ModelAPI_RefAttrValidator //! Returns true if object is good for the feature attribute virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, const ObjectPtr& theObject) const; - + //! Returns true if the attribute is good for the feature attribute + virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, + const AttributePtr& theAttribute) const; }; #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 14deb7083..82ba507be 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -33,14 +33,16 @@ + + - +