From: nds Date: Tue, 11 Jul 2017 10:26:36 +0000 (+0300) Subject: Issue #1058 Crash when creating a distance between source and translated elements X-Git-Tag: V_2.7.2RC~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=24aceade221e4793c130ca0bdd3bfbb88c0b1b80;p=modules%2Fshaper.git Issue #1058 Crash when creating a distance between source and translated elements Additionally a new equal points validator is implemented for distance constraint to avoid crash on selection coincident(equal) points of different segments. --- diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index 93004ec36..e017a507d 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -102,7 +102,7 @@ bool ModuleBase_WidgetEditor::editedValue(double& outValue, QString& outText) bool ModuleBase_WidgetEditor::focusTo() { showPopupEditor(); - return true; + return false; } bool ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index bd8880387..3cc5c73ab 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -255,6 +255,7 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection); aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection); aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator); + aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator); aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr); aFactory->registerValidator("PartSet_MultyTranslationSelection", new PartSet_MultyTranslationSelection); diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 178a4bfd4..b2f95ddd3 100755 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -33,6 +33,9 @@ #include #include +#include +#include + #include #include @@ -48,6 +51,7 @@ #include #include #include +#include #include #include @@ -609,6 +613,56 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute return true; } +bool PartSet_DifferentPointsValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + + // the type of validated attributes should be equal, attributes with + // different types are not validated + // Check RefAttr attributes + std::string anAttrType = theAttribute->attributeType(); + std::list > anAttrs; + if (anAttrType != ModelAPI_AttributeRefAttr::typeId()) + return true; + + // obtain point of the given attribute + AttributePoint2DPtr anAttributePoint = getRefPointAttribute(theAttribute); + if (!anAttributePoint.get() || !anAttributePoint->isInitialized()) + return true; + + // obtain point of the parameter attribute + AttributePoint2DPtr anArgumentPoint = getRefPointAttribute + (aFeature->attribute(theArguments.front())); + + if (!anArgumentPoint.get() || !anArgumentPoint->isInitialized()) + return true; + + return !anAttributePoint->pnt()->isEqual(anArgumentPoint->pnt()); +} + +AttributePoint2DPtr PartSet_DifferentPointsValidator::getRefPointAttribute + (const AttributePtr& theAttribute) const +{ + AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); + + AttributePoint2DPtr aPointAttribute; + if (anAttr->isObject()) { + ObjectPtr anObject = anAttr->object(); + if (anObject.get()) { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + if (aFeature->getKind() == SketchPlugin_Point::ID()) + aPointAttribute = std::dynamic_pointer_cast + (aFeature->attribute(SketchPlugin_Point::COORD_ID())); + } + } + else { + aPointAttribute = std::dynamic_pointer_cast(anAttr->attr()); + } + return aPointAttribute; +} + bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h index a14456c4a..039d259ca 100644 --- a/src/PartSet/PartSet_Validators.h +++ b/src/PartSet/PartSet_Validators.h @@ -27,6 +27,8 @@ #include #include +class GeomDataAPI_Point2D; + /* * Selector validators */ @@ -220,6 +222,34 @@ private: }; +/** +* \ingroup Validators +* A validator which checks that Point2D selected for feature attributes are different (not the same) +* It iterates by the feature ModelAPI_AttributeRefAttr attributes, finds GeomDataAPI_Point2D attribute in +* value or attribute of the attributes and if the point of the given attribute is geometrical equal to +* a point of another attribute, returns false +*/ +class PartSet_DifferentPointsValidator : public ModelAPI_AttributeValidator +{ + public: + //! Returns true if the attribute is good for the feature attribute + //! \param theAttribute an attribute + //! \param theArguments a list of arguments (names of attributes to check) + //! \param theError an output error string + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const; +private: + //! Finds Point2D attribute by reference attribute. It might be: + //! - COORD_ID attribute of SketchPlugin_Point if object + //! - Attribute casted to point if attribute + //! \param theAttribute an attribute + //! \return point 2d attribute or NULL + std::shared_ptr getRefPointAttribute + (const AttributePtr& theAttribute) const; +}; + + /**\class PartSet_CoincidentAttr * \ingroup Validators * \brief Validator to check whether there is a coincident constraint between diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index d5b54374a..863d82531 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -545,6 +545,7 @@ email : webmaster.salome@opencascade.com + +