From 5bca4c3cdc0e8fb3d6bd53b576c6ec6ad633d4b3 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 26 Mar 2015 16:26:48 +0300 Subject: [PATCH] Validator for tangent constraint --- src/PartSet/icons/tangent.png | Bin 433 -> 365 bytes src/SketchPlugin/SketchPlugin_Plugin.cpp | 2 + src/SketchPlugin/SketchPlugin_Validators.cpp | 75 +++++++++++++++++++ src/SketchPlugin/SketchPlugin_Validators.h | 17 +++++ src/SketchPlugin/plugin-Sketch.xml | 1 + 5 files changed, 95 insertions(+) diff --git a/src/PartSet/icons/tangent.png b/src/PartSet/icons/tangent.png index 4ca486e87c9a76f65b3061579dbc94a98ff77567..971e919d20d89067acd7429afb31d97cd48be709 100644 GIT binary patch delta 280 zcmV+z0q6d)1MLEkJPN@801m+cxRGn^kwzwe0P9IaK~y+Tg^?i=!Y~j;J5W(kiNIkx zIR&BzK=crZasvc{84kcvI06E}5fF$91QJhy=C%=;iDC z=rmk&q$mYzZ~!-f_uNZ|%sHq4^-v9&jqn5(U?TAT2zt%4XE`?JJ&5gd(Zpca6mCF& zU5-8+AR#}qt7Ck(XP_2yX8No%wDfk-H1rEMqq}F`30j4sxtJedYM=GdF3ig++S>gP z|Ba$T%y*F3q7Zt~UviOv(iMf!i=w5Nub}hiA=sP%9-9LSpC|+eY{Y!_35MVR{xS~8 eeS$C)eF34;ob;>S9Z3KH002ovPDHK)LSTYj<9s#% delta 348 zcmV-i0i*uy0;~~_tNZ`%ot~b` z%>JdS?LxeZA92~y%S1#4OD{CB7qgD1Or&IO199(#@E}IL-cF*nv3T~vqqr+Qk#^vJ z^V+(i_#ocImmuc*C>E`nP@LwaIHUL+Pa=)fH}9txe~Vi&^&d<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 @@ + -- 2.39.2