From 67b2608edb1ebdf0105f63bdd812f1b692453c68 Mon Sep 17 00:00:00 2001 From: azv Date: Mon, 22 Jan 2018 13:51:53 +0300 Subject: [PATCH] Issue #2405: Fatal error when create Length constraint on axis Created a validator to avoid selection of non-sketch features as objects of the Length constraints --- src/SketchPlugin/SketchPlugin_Plugin.cpp | 2 ++ src/SketchPlugin/SketchPlugin_Validators.cpp | 31 ++++++++++++++++++++ src/SketchPlugin/SketchPlugin_Validators.h | 16 ++++++++++ src/SketchPlugin/plugin-Sketch.xml | 1 + 4 files changed, 50 insertions(+) diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index ecc760c1e..3181dd460 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -136,6 +136,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() aFactory->registerValidator("SketchPlugin_HasNoConstraint", new SketchPlugin_HasNoConstraint); aFactory->registerValidator("SketchPlugin_ReplicationReference", new SketchPlugin_ReplicationReferenceValidator); + aFactory->registerValidator("SketchPlugin_SketchFeatureValidator", + new SketchPlugin_SketchFeatureValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 3c6fcc347..91728508f 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -1609,3 +1609,34 @@ bool SketchPlugin_ReplicationReferenceValidator::isValid( return true; } + +bool SketchPlugin_SketchFeatureValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) { + theError = "The attribute with the %1 type is not processed"; + theError.arg(theAttribute->attributeType()); + return false; + } + + // check the attribute refers to a sketch feature + AttributeRefAttrPtr aRefAttr = + std::dynamic_pointer_cast(theAttribute); + bool isSketchFeature = aRefAttr->isObject(); + if (isSketchFeature) { + FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); + isSketchFeature = aFeature; + if (isSketchFeature) { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(aFeature); + isSketchFeature = aSketchFeature; + } + } + + if (isSketchFeature) + return true; + + theError = "The object selected is not a sketch feature"; + return false; +} diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index d2cf26bbc..56ab74b7a 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -464,4 +464,20 @@ class SketchPlugin_ReplicationReferenceValidator: public ModelAPI_AttributeValid Events_InfoMessage& theError) const; }; +/**\class SketchPlugin_SketchFeatureValidator + * \ingroup Validators + * \brief Validator for checking whether the feature referred by attribute is a sketch feature. + */ +class SketchPlugin_SketchFeatureValidator: public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + //! \param theError error message + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const; +}; + #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 6b728d273..5da3a4645 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -769,6 +769,7 @@ email : webmaster.salome@opencascade.com + -- 2.39.2