From: vsv Date: Thu, 26 Mar 2015 14:12:58 +0000 (+0300) Subject: SameType object validator X-Git-Tag: V_1.1.0~77 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=324e003dfdc5e343baa124722c8a944df0276571;p=modules%2Fshaper.git SameType object validator --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index ad9296bc8..20cd41101 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -142,6 +142,9 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("PartSet_SketchEntityValidator", new PartSet_SketchEntityValidator); + + aFactory->registerValidator("PartSet_SameTypeAttr", + new PartSet_SameTypeAttrValidator); } void PartSet_Module::registerFilters() diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 0e2ca6f20..38bf03582 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -309,3 +310,32 @@ bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute, return isSketchEntities; } + + + +bool PartSet_SameTypeAttrValidator::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); + return aRefFea->getKind() == aOtherFea->getKind(); + } + return false; +} + diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h index 02e73de5f..45df48dfd 100644 --- a/src/PartSet/PartSet_Validators.h +++ b/src/PartSet/PartSet_Validators.h @@ -120,4 +120,21 @@ class PartSet_SketchEntityValidator : public ModelAPI_AttributeValidator const std::list& theArguments) const; }; +/**\class PartSet_SameTypeAttrValidator + * \ingroup Validators + * \brief Validator for the tangent constraint input. + * + * It just checks that distance is greater than zero. + */ +class PartSet_SameTypeAttrValidator : 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/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index b83ca9639..a61362076 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -135,3 +135,5 @@ bool SketchPlugin_TangentAttrValidator::isValid( return false; } + + diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index 17797fb8a..11721fbd1 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -25,42 +25,6 @@ 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 - * \ingroup Validators - * - * 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. - */ -// 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 @@ -79,4 +43,5 @@ class SketchPlugin_TangentAttrValidator : public ModelAPI_AttributeValidator const std::list& theArguments) const; }; + #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 353505c82..391738b8c 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -221,6 +221,8 @@ + +