From: vsv Date: Wed, 11 Mar 2015 09:52:00 +0000 (+0300) Subject: Provide a different object validator with selected shape to check it X-Git-Tag: V_1.0.2~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=71c613d18c2aa77e10f5b62100b9a0e3d71d023f;p=modules%2Fshaper.git Provide a different object validator with selected shape to check it --- diff --git a/src/ModelAPI/ModelAPI_RefAttrValidator.h b/src/ModelAPI/ModelAPI_RefAttrValidator.h index ab8ffc6cd..cfa3886c7 100644 --- a/src/ModelAPI/ModelAPI_RefAttrValidator.h +++ b/src/ModelAPI/ModelAPI_RefAttrValidator.h @@ -11,6 +11,7 @@ #include #include #include +#include /**\class ModelAPI_RefAttrValidator * \ingroup DataModel @@ -21,7 +22,7 @@ class ModelAPI_RefAttrValidator : public ModelAPI_AttributeValidator public: //! Returns true if object is good for the feature attribute virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, - const ObjectPtr& theObject) const = 0; + const ObjectPtr& theObject, const GeomShapePtr& theShape) const = 0; //! Returns true if the attribute is good for the feature attribute virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 81e45ef0a..74bd7f61a 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -499,7 +499,7 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr(*aValidator); if (aAttrValidator) { - if (!aAttrValidator->isValid(myFeature, *aArgs, theObj)) { + if (!aAttrValidator->isValid(myFeature, *aArgs, theObj, theShape)) { return false; } } diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 30d95d472..f92793f71 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -112,7 +112,8 @@ bool PartSet_RigidValidator::isValid(const ModuleBase_ISelection* theSelection) bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, const std::list& theArguments, - const ObjectPtr& theObject) const + const ObjectPtr& theObject, + const GeomShapePtr& theShape) const { // Check RefAttr attributes std::list > anAttrs = @@ -138,8 +139,13 @@ bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, std::shared_ptr aRef = std::dynamic_pointer_cast(*anAttr); // check the object is already presented - if (aRef->isInitialized() && aRef->context() == theObject) - return false; + if (aRef->isInitialized() && aRef->context() == theObject) { + if (theShape.get() != NULL) { + if (aRef->value()->isEqual(theShape)) + return false; + } else + return false; + } } } } @@ -164,7 +170,22 @@ bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, const std::list& theArguments, const AttributePtr& theAttribute) const { - return PartSet_DifferentObjectsValidator::isValid(theAttribute, theArguments); + if (PartSet_DifferentObjectsValidator::isValid(theAttribute, theArguments)) { + std::list > anAttrs = + theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId()); + std::list >::iterator anAttr = anAttrs.begin(); + for(; anAttr != anAttrs.end(); anAttr++) { + if (*anAttr) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(*anAttr); + // check the object is already presented + if (!aRef->isObject() && aRef->attr() == theAttribute) + return false; + } + } + return true; + } + return false; } bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute, diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h index be1bb0ef5..0118dce90 100644 --- a/src/PartSet/PartSet_Validators.h +++ b/src/PartSet/PartSet_Validators.h @@ -78,7 +78,7 @@ class PartSet_DifferentObjectsValidator : public ModelAPI_RefAttrValidator /// \param theArguments a list of arguments (names of attributes to check) /// \param theObject a selected object virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, - const ObjectPtr& theObject) const; + const ObjectPtr& theObject, const GeomShapePtr& theShape) const; //! Returns true if the attribute is good for the feature attribute //! \param theFeature a feature to check diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index cd69a1998..d0b1f8bc1 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -116,7 +116,7 @@ bool PartSet_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptrisValid(myFeature, *aArgs, theObj)) { + if (!aAttrValidator->isValid(myFeature, *aArgs, theObj, theShape)) { return false; } } diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 030f786f1..21f74bc63 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -43,8 +43,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); aFactory->registerValidator("SketchPlugin_DistanceAttr", new SketchPlugin_DistanceAttrValidator); - aFactory->registerValidator("SketchPlugin_DifferentObjects", - new SketchPlugin_DifferentObjectsValidator); + //aFactory->registerValidator("SketchPlugin_DifferentObjects", + // new SketchPlugin_DifferentObjectsValidator); aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator); aFactory->registerValidator("SketchPlugin_ResultLine", new SketchPlugin_ResultLineValidator); aFactory->registerValidator("SketchPlugin_ResultArc", new SketchPlugin_ResultArcValidator); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index abef5066c..43186329b 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -16,7 +16,8 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature, const std::list& theArguments, - const ObjectPtr& theObject) const + const ObjectPtr& theObject, + const GeomShapePtr& theShape) const { std::string aParamA = theArguments.front(); SessionPtr aMgr = ModelAPI_Session::get(); @@ -57,64 +58,64 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature, return isValid(theAttribute, theArguments); } -bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, - const std::list& theArguments, - const ObjectPtr& theObject) const -{ - std::list > anAttrs = - theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId()); - std::list >::iterator anAttr = anAttrs.begin(); - for(; anAttr != anAttrs.end(); anAttr++) { - if (*anAttr) { - std::shared_ptr aRef = - std::dynamic_pointer_cast(*anAttr); - // check the object is already presented - if (aRef->isObject() && aRef->object() == theObject) - return false; - } - } - return true; -} - -bool SketchPlugin_DifferentObjectsValidator::isValid( - const AttributePtr& theAttribute, const std::list& theArguments ) const -{ - std::shared_ptr anOrigAttr = - std::dynamic_pointer_cast(theAttribute); - if (anOrigAttr && anOrigAttr->isObject()) { - const ObjectPtr& anObj = theAttribute->owner(); - const FeaturePtr aFeature = std::dynamic_pointer_cast(anObj); +//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, +// const std::list& theArguments, +// const ObjectPtr& theObject) const +//{ +// std::list > anAttrs = +// theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId()); +// std::list >::iterator anAttr = anAttrs.begin(); +// for(; anAttr != anAttrs.end(); anAttr++) { +// if (*anAttr) { +// std::shared_ptr aRef = +// std::dynamic_pointer_cast(*anAttr); +// // check the object is already presented +// if (aRef->isObject() && aRef->object() == theObject) +// return false; +// } +// } +// return true; +//} - std::list > anAttrs = - aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId()); - std::list >::iterator anAttr = anAttrs.begin(); - for(; anAttr != anAttrs.end(); anAttr++) { - if (*anAttr && *anAttr != theAttribute) { - std::shared_ptr aRef = - std::dynamic_pointer_cast(*anAttr); - // check the object is already presented - if (aRef->isObject() && aRef->object() == anOrigAttr->object()) - return false; - } - } - } - return true; -} +//bool SketchPlugin_DifferentObjectsValidator::isValid( +// const AttributePtr& theAttribute, const std::list& theArguments ) const +//{ +// std::shared_ptr anOrigAttr = +// std::dynamic_pointer_cast(theAttribute); +// if (anOrigAttr && anOrigAttr->isObject()) { +// const ObjectPtr& anObj = theAttribute->owner(); +// const FeaturePtr aFeature = std::dynamic_pointer_cast(anObj); +// +// std::list > anAttrs = +// aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId()); +// std::list >::iterator anAttr = anAttrs.begin(); +// for(; anAttr != anAttrs.end(); anAttr++) { +// if (*anAttr && *anAttr != theAttribute) { +// std::shared_ptr aRef = +// std::dynamic_pointer_cast(*anAttr); +// // check the object is already presented +// if (aRef->isObject() && aRef->object() == anOrigAttr->object()) +// return false; +// } +// } +// } +// return true; +//} -bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, - const std::list& theArguments, const AttributePtr& theAttribute) const -{ - std::list > anAttrs = - theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId()); - std::list >::iterator anAttr = anAttrs.begin(); - for(; anAttr != anAttrs.end(); anAttr++) { - if (*anAttr) { - std::shared_ptr aRef = - std::dynamic_pointer_cast(*anAttr); - // check the object is already presented - if (!aRef->isObject() && aRef->attr() == theAttribute) - return false; - } - } - return true; -} +//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, +// const std::list& theArguments, const AttributePtr& theAttribute) const +//{ +// std::list > anAttrs = +// theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId()); +// std::list >::iterator anAttr = anAttrs.begin(); +// for(; anAttr != anAttrs.end(); anAttr++) { +// if (*anAttr) { +// std::shared_ptr aRef = +// std::dynamic_pointer_cast(*anAttr); +// // check the object is already presented +// if (!aRef->isObject() && aRef->attr() == theAttribute) +// return false; +// } +// } +// return true; +//} diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index d6368a1eb..88c8d3a48 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -22,11 +22,12 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator //! 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; + 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; + 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, @@ -39,20 +40,21 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator * 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. */ -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; -}; +// 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; +//}; #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 0f6201227..81c396a77 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -57,7 +57,7 @@ label="Last object" tooltip="Select point, line end point, line, center of circle or arc." shape_types="edge vertex"> - + @@ -106,7 +106,7 @@ - + @@ -123,7 +123,7 @@ - +