From: mpv Date: Wed, 17 Sep 2014 12:11:52 +0000 (+0400) Subject: Make impossible selection of the same line twice for parallel and perpendicular const... X-Git-Tag: V_0.4.4~43^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=244f7eadf98c565ba0c1b3ea375491025604ad84;p=modules%2Fshaper.git Make impossible selection of the same line twice for parallel and perpendicular constrains --- diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 1b0730b76..40749b191 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -27,11 +27,13 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() { SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - aFactory->registerValidator("SketchPlugin_DistanceAttrValidator", + aFactory->registerValidator("SketchPlugin_DistanceAttr", new SketchPlugin_DistanceAttrValidator); - aFactory->registerValidator("SketchPlugin_ResultPointValidator", new SketchPlugin_ResultPointValidator); - aFactory->registerValidator("SketchPlugin_ResultLineValidator", new SketchPlugin_ResultLineValidator); - aFactory->registerValidator("SketchPlugin_ResultArcValidator", new SketchPlugin_ResultArcValidator); + aFactory->registerValidator("SketchPlugin_DifferentObjects", + new SketchPlugin_DifferentObjectsValidator); + aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator); + aFactory->registerValidator("SketchPlugin_ResultLine", new SketchPlugin_ResultLineValidator); + aFactory->registerValidator("SketchPlugin_ResultArc", new SketchPlugin_ResultArcValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 94e5676f5..855ac9ab0 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature, @@ -43,3 +44,47 @@ bool SketchPlugin_DistanceAttrValidator::isValid( } return true; // it may be not reference attribute, in this case, it is OK } + +bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, + const std::list& theArguments, + const ObjectPtr& theObject) 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->object() == theObject) + return false; + } + } + return true; +} + +bool SketchPlugin_DifferentObjectsValidator::isValid( + const AttributePtr& theAttribute, const std::list& theArguments ) const +{ + boost::shared_ptr anOrigAttr = + boost::dynamic_pointer_cast(theAttribute); + if (anOrigAttr && anOrigAttr->isObject()) { + const ObjectPtr& anObj = theAttribute->owner(); + const FeaturePtr aFeature = boost::dynamic_pointer_cast(anObj); + + std::list > anAttrs = + aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type()); + std::list >::iterator anAttr = anAttrs.begin(); + for(; anAttr != anAttrs.end(); anAttr++) { + if (*anAttr && *anAttr != theAttribute) { + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(*anAttr); + // check the object is already presented + if (aRef->isObject() && aRef->object() == anOrigAttr->object()) + return false; + } + } + } + return true; +} diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index ece17e599..d8dcba2e0 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -22,4 +22,22 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator }; +/** + * Check that there is no same object was already selected in the feature. + * For an example: to avoid perpendicularity on line and the same line. + */ +class SketchPlugin_DifferentObjectsValidator : public ModelAPI_RefAttrValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + virtual bool isValid( + const AttributePtr& theAttribute, const std::list& theArguments) const; + //! Returns true if object is good for the feature attribute + virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, + const ObjectPtr& theObject) const; + +}; + #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 47b2ccbe3..412944f03 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -31,13 +31,13 @@