From: azv Date: Wed, 1 Apr 2015 11:10:00 +0000 (+0300) Subject: Issue #429: error when fix the same segment twice X-Git-Tag: V_1.1.0~66^2~2^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=96b3e7a48214b3247070b9e854681c5f49edc84f;p=modules%2Fshaper.git Issue #429: error when fix the same segment twice Implemented validator for the rigid constraint --- diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index c7ee95fcc..e0f06569f 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -55,6 +55,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_ExternalValidator); aFactory->registerValidator("SketchPlugin_TangentAttr", new SketchPlugin_TangentAttrValidator); + aFactory->registerValidator("SketchPlugin_NotFixed", + new SketchPlugin_NotFixedValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 358c82c1b..baace5c2a 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -7,6 +7,7 @@ #include "SketchPlugin_Validators.h" #include "SketchPlugin_ConstraintDistance.h" #include "SketchPlugin_ConstraintCoincidence.h" +#include "SketchPlugin_ConstraintRigid.h" #include "SketchPlugin_Line.h" #include "SketchPlugin_Arc.h" @@ -135,4 +136,32 @@ bool SketchPlugin_TangentAttrValidator::isValid( return false; } +bool SketchPlugin_NotFixedValidator::isValid( + const AttributePtr& theAttribute, const std::list& theArguments) const +{ + std::shared_ptr aFeature = + std::dynamic_pointer_cast(theAttribute->owner()); + if (!aFeature) + return true; + + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); + if (!aRefAttr) + return false; + + SketchPlugin_Sketch* aSketch = aFeature->sketch(); + int aNbFeatures = aSketch->numberOfSubs(); + for (int anInd = 0; anInd < aNbFeatures; anInd++) { + FeaturePtr aSubFeature = aSketch->subFeature(anInd); + if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature) + continue; + AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast( + aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A())); + if (aRefAttr->isObject()) { + if (aRefAttr->object() == aRAttr->object()) + return false; + } else if (aRefAttr->attr() == aRAttr->attr()) + return false; + } + return true; +} diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index 11721fbd1..21ad277f7 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -44,4 +44,21 @@ class SketchPlugin_TangentAttrValidator : public ModelAPI_AttributeValidator }; +/**\class SketchPlugin_NotFixed + * \ingroup Validators + * \brief Validator for the rigid constraint input. + * + * It just checks there is no rigid constraint for the current feature. + */ +class SketchPlugin_NotFixedValidator : public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is not used in another rigid constraint + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; +}; + + #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 7274cc18d..898546d74 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -151,6 +151,7 @@ +