From: vsv Date: Thu, 26 Mar 2015 13:26:48 +0000 (+0300) Subject: Validator for tangent constraint X-Git-Tag: V_1.1.0~79 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5bca4c3cdc0e8fb3d6bd53b576c6ec6ad633d4b3;p=modules%2Fshaper.git Validator for tangent constraint --- diff --git a/src/PartSet/icons/tangent.png b/src/PartSet/icons/tangent.png index 4ca486e87..971e919d2 100644 Binary files a/src/PartSet/icons/tangent.png and b/src/PartSet/icons/tangent.png differ diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 68302fee1..c7ee95fcc 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -53,6 +53,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_DistanceAttrValidator); aFactory->registerValidator("SketchPlugin_ExternalValidator", new SketchPlugin_ExternalValidator); + aFactory->registerValidator("SketchPlugin_TangentAttr", + new SketchPlugin_TangentAttrValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 32a0b30b5..b83ca9639 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -6,6 +6,10 @@ #include "SketchPlugin_Validators.h" #include "SketchPlugin_ConstraintDistance.h" +#include "SketchPlugin_ConstraintCoincidence.h" +#include "SketchPlugin_Line.h" +#include "SketchPlugin_Arc.h" + #include #include #include @@ -60,3 +64,74 @@ bool SketchPlugin_DistanceAttrValidator::isValid( } return false; } + + + +bool SketchPlugin_TangentAttrValidator::isValid( + const AttributePtr& theAttribute, const std::list& theArguments ) const +{ + // there is a check whether the feature contains a point and a linear edge or two point values + std::string aParamA = theArguments.front(); + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); + if (!aRefAttr) + return false; + + bool isObject = aRefAttr->isObject(); + ObjectPtr anObject = aRefAttr->object(); + if (isObject && anObject) { + FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject); + + AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA); + ObjectPtr aOtherObject = aOtherAttr->object(); + FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject); + + if (aRefFea->getKind() == SketchPlugin_Line::ID()) { + if (aOtherFea->getKind() != SketchPlugin_Arc::ID()) + return false; + } else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) { + if (aOtherFea->getKind() != SketchPlugin_Line::ID()) + return false; + } else + return false; + + // check that both have coincidence + FeaturePtr aConstrFeature; + std::set aCoinList; + const std::set>& aRefsList = aRefFea->data()->refsToMe(); + std::set>::const_iterator aIt; + for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { + std::shared_ptr aAttr = (*aIt); + aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); + if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { + AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast(aAttr); + AttributePtr aAR = aRAttr->attr(); + if (aAR->id() != SketchPlugin_Arc::CENTER_ID()) // ignore constraint to center of arc + aCoinList.insert(aConstrFeature); + } + } + // if there is no coincidence then it is not valid + if (aCoinList.size() == 0) + return false; + + // find that coincedence is the same + const std::set>& aOtherList = aOtherFea->data()->refsToMe(); + std::set::const_iterator aCoinsIt; + for (aIt = aOtherList.cbegin(); aIt != aOtherList.cend(); ++aIt) { + std::shared_ptr aAttr = (*aIt); + aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); + aCoinsIt = aCoinList.find(aConstrFeature); + if (aCoinsIt != aCoinList.end()) { + AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast(aAttr); + AttributePtr aAR = aRAttr->attr(); + if (aAR->id() != SketchPlugin_Arc::CENTER_ID()) + return true; + } + } + } + return false; +} + diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index f686d3e6e..88f042bd7 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -26,4 +26,21 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator const std::list& theArguments) const; }; + +/**\class SketchPlugin_TangentAttrValidator + * \ingroup Validators + * \brief Validator for the tangent constraint input. + * + * It just checks that distance is greater than zero. + */ +class SketchPlugin_TangentAttrValidator : public ModelAPI_AttributeValidator +{ + 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; +}; + #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 2d5e884e1..f5199b534 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -190,6 +190,7 @@ +