From: nds Date: Wed, 26 Apr 2017 09:17:01 +0000 (+0300) Subject: Issue #1889 Amélioration des contraintes H et V (Filter horizontal and vertical segme... X-Git-Tag: V_2.7.1.1~3^2~21 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6d1cac039471a0944ffa4a28a784da4fa38ab33a;p=modules%2Fshaper.git Issue #1889 Amélioration des contraintes H et V (Filter horizontal and vertical segments in H and V constraints) --- diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 65a5cf662..e6451367d 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -108,6 +108,7 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_ArcEndPointValidator); aFactory->registerValidator("SketchPlugin_ArcEndPointIntersectionValidator", new SketchPlugin_ArcEndPointIntersectionValidator); + aFactory->registerValidator("SketchPlugin_HasNoConstraint", new SketchPlugin_HasNoConstraint); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index d6229b0d5..4aa4095f7 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -1493,3 +1493,46 @@ bool SketchPlugin_ArcEndPointIntersectionValidator::isValid( return false; } + +bool SketchPlugin_HasNoConstraint::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + std::set aFeatureKinds; + for (std::list::const_iterator anArgIt = theArguments.begin(); + anArgIt != theArguments.end(); anArgIt++) { + aFeatureKinds.insert(*anArgIt); + } + + if (theAttribute->attributeType() != ModelAPI_AttributeRefAttr::typeId()) { + theError = "The attribute with the %1 type is not processed"; + theError.arg(theAttribute->attributeType()); + return false; + } + + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast + (theAttribute); + bool isObject = aRefAttr->isObject(); + if (!isObject) { + theError = "It uses an empty object"; + return false; + } + ObjectPtr anObject = aRefAttr->object(); + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + if (!aFeature.get()) { + theError = "The feature of the checked attribute is empty"; + return false; + } + + FeaturePtr aCurrentFeature = ModelAPI_Feature::feature(aRefAttr->owner()); + + std::set aRefsList = anObject->data()->refsToMe(); + std::set::const_iterator anIt = aRefsList.begin(); + for (; anIt != aRefsList.end(); anIt++) { + FeaturePtr aRefFeature = ModelAPI_Feature::feature((*anIt)->owner()); + if (aRefFeature.get() && aCurrentFeature != aRefFeature && + aFeatureKinds.find(aRefFeature->getKind()) != aFeatureKinds.end()) + return false; // constraint is found, that means that the check is not valid + } + return true; +} diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index bc74e092b..998d13d7d 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -413,4 +413,24 @@ class SketchPlugin_ArcEndPointIntersectionValidator: public ModelAPI_AttributeVa Events_InfoMessage& theError) const; }; +/**\class SketchPlugin_HasNoConstraint + * \ingroup Validators + * \brief Validator for checking whether the feature has constraint. + * + * Checks that feature of the attribute does not have constraint with some kinds. + * The kinds of constraints should be described in parameters of the validator + * Validator processes the ModelAPI_AttributeRefAttr attribute kind + */ +class SketchPlugin_HasNoConstraint: 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 444209e88..45cb3cec8 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -608,6 +608,7 @@ + @@ -617,6 +618,7 @@ +