From: nds Date: Fri, 27 Mar 2015 07:42:07 +0000 (+0300) Subject: Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0 X-Git-Tag: V_1.1.0~75^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=762c91644fd2b5eeb99e7ad783b844b565e9ae9d;hp=3e3d76500389cb3a5a6eeb09f229cd3c83730dac;p=modules%2Fshaper.git Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0 Conflicts: src/SketchPlugin/SketchPlugin_Validators.cpp --- diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 32a0b30b5..befd4cb15 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,72 @@ 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 6259c2bd6..11721fbd1 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -25,41 +25,23 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator virtual bool isValid(const AttributePtr& theAttribute, const std::list& theArguments) const; }; -// 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 GeomShapePtr& theShape) const; -// -// //! Returns true if the attribute is good for the feature attribute -// virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, -// const AttributePtr& theAttribute) const; -//}; -// commented in v1.0.2, master: -/**\class SketchPlugin_DifferentObjectsValidator + +/**\class SketchPlugin_TangentAttrValidator * \ingroup Validators + * \brief Validator for the tangent constraint input. * - * 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. + * It just checks that distance is greater than zero. */ -// Use PartSet_DifferentObjectsValidator instead -//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; -// //! Returns true if the attribute is good for the feature attribute -// virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, -// const AttributePtr& theAttribute) const; -//}; -// ======= end of todo +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