From 6d1cac039471a0944ffa4a28a784da4fa38ab33a Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 26 Apr 2017 12:17:01 +0300 Subject: [PATCH] =?utf8?q?Issue=20#1889=20Am=C3=A9lioration=20des=20contra?= =?utf8?q?intes=20H=20et=20V=20(Filter=20horizontal=20and=20vertical=20seg?= =?utf8?q?ments=20in=20H=20and=20V=20constraints)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/SketchPlugin/SketchPlugin_Plugin.cpp | 1 + src/SketchPlugin/SketchPlugin_Validators.cpp | 43 ++++++++++++++++++++ src/SketchPlugin/SketchPlugin_Validators.h | 20 +++++++++ src/SketchPlugin/plugin-Sketch.xml | 2 + 4 files changed, 66 insertions(+) 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 @@ + -- 2.39.2