From: nds Date: Mon, 23 Mar 2015 10:54:42 +0000 (+0300) Subject: Union of validator and filter functionalities. X-Git-Tag: V_1.1.0~85^2~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6d28a36fb686061215d8f1c895eeafbf5b1d00ef;p=modules%2Fshaper.git Union of validator and filter functionalities. It replaces ResultValidator to AttributeValidator in order to have a similar interface for most of validators. --- diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 1109883fb..adbe17b11 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -6,7 +6,7 @@ icon=":icons/sketch.png" tooltip="Select a sketch face" type_choice="Faces"> - + -#include -#include -#include - -/**\class ModelAPI_RefAttrValidator - * \ingroup DataModel - * Used for filtering out the object that can be used for reference attribute value - */ -class ModelAPI_RefAttrValidator : public ModelAPI_AttributeValidator -{ -public: -}; - -#endif diff --git a/src/ModelAPI/ModelAPI_ResultValidator.h b/src/ModelAPI/ModelAPI_ResultValidator.h deleted file mode 100644 index 01d73eaed..000000000 --- a/src/ModelAPI/ModelAPI_ResultValidator.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModelAPI_ResultValidators.h -// Created: 23 July 2014 -// Author: Vitaly SMETANNIKOV - -#ifndef ModelAPI_ResultValidators_H -#define ModelAPI_ResultValidators_H - -#include "ModelAPI_Validator.h" -#include "ModelAPI_Object.h" - -/**\class ModelAPI_ResultValidator - * \ingroup DataModel - * \brief The base class for selection filter for results of features. - * - * The referenced arguments of feature is normally results displayed in the viewer or by the - * selection attribute. This filter allows to filter out the results not usable as this argument. - */ -class ModelAPI_ResultValidator : public ModelAPI_Validator -{ -public: - /// The abstract method for implementation in the specific validator. - /// \param theObject the checked object as an argument - /// \returns true if object is OK for this filter - virtual bool isValid(const ObjectPtr theObject) const = 0; -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 9708a6ccd..265a9e42c 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 88c587aff..97723530b 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -80,74 +79,14 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const return aValid; } -//******************************************************************** -bool ModuleBase_WidgetValidated::isValid(ObjectPtr theObj, GeomShapePtr theShape) const -{ - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - std::list aValidators; - std::list > anArguments; - aFactory->validators(parentID(), attributeID(), aValidators, anArguments); - - // Check the type of selected object - std::list::iterator aValidator = aValidators.begin(); - bool isValid = true; - for (; aValidator != aValidators.end(); aValidator++) { - const ModelAPI_ResultValidator* aResValidator = - dynamic_cast(*aValidator); - if (aResValidator) { - isValid = false; - if (aResValidator->isValid(theObj)) { - isValid = true; - break; - } - } - } - return isValid; -} - -#define VALIDATOR_FILTER void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const { ModuleBase_IViewer* aViewer = theWorkshop->viewer(); -#ifdef VALIDATOR_FILTER Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter(); if (toActivate) aViewer->addSelectionFilter(aSelFilter); else aViewer->removeSelectionFilter(aSelFilter); -#else - // apply filters loaded from the XML definition of the widget - ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters(); - SelectMgr_ListOfFilter aFactoryFilters; - aFactory->filters(parentID(), attributeID(), aFactoryFilters); - SelectMgr_ListIteratorOfListOfFilter aFactoryIt(aFactoryFilters); - for (; aFactoryIt.More(); aFactoryIt.Next()) { - Handle(SelectMgr_Filter) aSelFilter = aFactoryIt.Value(); - if (aSelFilter.IsNull()) - continue; - if (toActivate) - aViewer->addSelectionFilter(aSelFilter); - else - aViewer->removeSelectionFilter(aSelFilter); - } -#endif -} - -void ModuleBase_WidgetValidated::selectionFilters(ModuleBase_IWorkshop* theWorkshop, - SelectMgr_ListOfFilter& theFilters) const -{ - ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters(); - SelectMgr_ListOfFilter aFilters; - aFactory->filters(parentID(), attributeID(), aFilters); - SelectMgr_ListIteratorOfListOfFilter aIt(aFilters); - for (; aIt.More(); aIt.Next()) { - Handle(SelectMgr_Filter) aSelFilter = aIt.Value(); - if (aSelFilter.IsNull()) - continue; - - theFilters.Append(aSelFilter); - } } diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index fdb094112..db28807d1 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -64,21 +64,10 @@ protected: // \return true if all validators return that the attribute is valid bool isValidAttribute() const; - /// Check the selected with validators if installed - /// \param theObj the object for checking - /// \param theShape the shape for checking - virtual bool isValid(ObjectPtr theObj, GeomShapePtr theShape) const; - /// It obtains selection filters from the workshop and activates them in the active viewer /// \param theWorkshop an active workshop /// \param toActivate a flag about activation or deactivation the filters virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const; - - /// Fills the given list with all widget filters. - /// \param theWorkshop an active workshop - /// \param theFilters a list of filters - void selectionFilters(ModuleBase_IWorkshop* theWorkshop, - SelectMgr_ListOfFilter& theFilters) const; }; #endif /* MODULEBASE_WIDGETVALIDATED_H_ */ diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 6299ff04a..9646b8398 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -130,7 +130,6 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator); aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator); aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator); - aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator); aFactory->registerValidator("ModuleBase_ValidatorLinearEdge", new ModuleBase_ValidatorLinearEdge); aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex", diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 305647650..b246046d5 100644 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -192,29 +192,41 @@ bool PartSet_DifferentObjectsValidator::featureHasReferences(const AttributePtr& bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute, const std::list& theArguments) const { - AttributeSelectionListPtr aSelectionListAttr = - std::dynamic_pointer_cast(theAttribute); - - // it filters only selection list attributes - if (aSelectionListAttr.get() == NULL) - return true; - - std::string aType = aSelectionListAttr->selectionType().c_str(); - - // all context objects should be sketch entities bool isSketchEntities = true; - int aSize = aSelectionListAttr->size(); - for (int i = 0; i < aSelectionListAttr->size(); i++) { - AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); - ObjectPtr anObject = aSelectAttr->context(); - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - isSketchEntities = aFeature->getKind() == SketchPlugin_Sketch::ID(); + std::set anEntityKinds; + std::list::const_iterator anIt = theArguments.begin(), aLast = theArguments.end(); + for (; anIt != aLast; anIt++) { + anEntityKinds.insert(*anIt); } - return isSketchEntities; -} -bool PartSet_SketchValidator::isValid(const ObjectPtr theObject) const -{ - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - return aFeature->getKind() == SketchPlugin_Sketch::ID(); + std::string anAttributeType = theAttribute->attributeType(); + if (anAttributeType == ModelAPI_AttributeSelectionList::type()) { + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(theAttribute); + // it filters only selection list attributes + std::string aType = aSelectionListAttr->selectionType().c_str(); + // all context objects should be sketch entities + int aSize = aSelectionListAttr->size(); + for (int i = 0; i < aSelectionListAttr->size() && isSketchEntities; i++) { + AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); + ObjectPtr anObject = aSelectAttr->context(); + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); + } + } + if (anAttributeType == ModelAPI_AttributeRefAttr::type()) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(theAttribute); + isSketchEntities = false; + if (aRef->isObject()) { + ObjectPtr anObject = aRef->object(); + if (anObject.get() != NULL) { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + if (aFeature.get() != NULL) + isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); + } + } + } + + return isSketchEntities; } diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h index 556c2ce06..389cc4fa2 100644 --- a/src/PartSet/PartSet_Validators.h +++ b/src/PartSet/PartSet_Validators.h @@ -11,8 +11,7 @@ #include #include -#include -#include +#include /* * Selector validators @@ -70,7 +69,7 @@ class PartSet_RigidValidator : public ModuleBase_SelectionValidator * \ingroup Validators * A validator which checks that objects selected for feature attributes are different (not the same) */ -class PartSet_DifferentObjectsValidator : public ModelAPI_RefAttrValidator +class PartSet_DifferentObjectsValidator : public ModelAPI_AttributeValidator { public: //! Returns true if the attribute is good for the feature attribute @@ -95,7 +94,7 @@ protected: * \ingroup Validators * A validator which checks that objects selected for feature attributes are different (not the same) */ -class PartSet_SketchEntityValidator : public ModelAPI_RefAttrValidator +class PartSet_SketchEntityValidator : public ModelAPI_AttributeValidator { public: //! Returns true if the attribute is good for the feature attribute @@ -105,16 +104,4 @@ class PartSet_SketchEntityValidator : public ModelAPI_RefAttrValidator const std::list& theArguments) const; }; -/** -* \ingroup Validators -* A Validator which validates tha selected object is a Sketch -*/ -class PartSet_SketchValidator : public ModelAPI_ResultValidator -{ - public: - /// Returns True if the given object is a sketch - /// \param theObject an object - virtual bool isValid(const ObjectPtr theObject) const; -}; - #endif \ No newline at end of file diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 726f8c160..45fe790e7 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -9,8 +9,6 @@ #include #include #include -#include -#include #include #include diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 298457133..992bd6bdb 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -30,7 +30,6 @@ SET(PROJECT_HEADERS SketchPlugin_ConstraintFillet.h SketchPlugin_ShapeValidator.h SketchPlugin_Validators.h - SketchPlugin_ResultValidators.h ) SET(PROJECT_SOURCES @@ -58,7 +57,6 @@ SET(PROJECT_SOURCES SketchPlugin_ConstraintFillet.cpp SketchPlugin_ShapeValidator.cpp SketchPlugin_Validators.cpp - SketchPlugin_ResultValidators.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 9bcc299bf..04347759e 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -54,9 +53,7 @@ SketchPlugin_Plugin::SketchPlugin_Plugin() new SketchPlugin_DistanceAttrValidator); //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); + aFactory->registerValidator("SketchPlugin_ShapeValidator", new SketchPlugin_ShapeValidator); diff --git a/src/SketchPlugin/SketchPlugin_ResultValidators.cpp b/src/SketchPlugin/SketchPlugin_ResultValidators.cpp deleted file mode 100644 index 15f8554a2..000000000 --- a/src/SketchPlugin/SketchPlugin_ResultValidators.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: Model_ResultValidators.cpp -// Created: 23 July 2014 -// Author: Vitaly SMETANNIKOV - -#include "SketchPlugin_ResultValidators.h" - -#include -#include -#include - -ResultPtr result(const ObjectPtr theObject) -{ - return std::dynamic_pointer_cast(theObject); -} - -bool SketchPlugin_ResultPointValidator::isValid(const ObjectPtr theObject) const -{ - ResultPtr aResult = result(theObject); - if (!aResult) - return false; - std::shared_ptr aShape = ModelAPI_Tools::shape(aResult); - return aShape && aShape->isVertex(); -} - -bool SketchPlugin_ResultLineValidator::isValid(const ObjectPtr theObject) const -{ - ResultPtr aResult = result(theObject); - if (!aResult) - return false; - std::shared_ptr aShape = ModelAPI_Tools::shape(aResult); - return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isLine(); -} - -bool SketchPlugin_ResultArcValidator::isValid(const ObjectPtr theObject) const -{ - ResultPtr aResult = result(theObject); - if (!aResult) - return false; - std::shared_ptr aShape = ModelAPI_Tools::shape(aResult); - return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isCircle(); -} diff --git a/src/SketchPlugin/SketchPlugin_ResultValidators.h b/src/SketchPlugin/SketchPlugin_ResultValidators.h deleted file mode 100644 index 6e328b175..000000000 --- a/src/SketchPlugin/SketchPlugin_ResultValidators.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: Model_ResultValidators.h -// Created: 23 July 2014 -// Author: Vitaly SMETANNIKOV - -#ifndef Model_ResultValidators_H -#define Model_ResultValidators_H - -#include -#include -#include - -/**\class SketchPlugin_ResultPointValidator - * \ingroup Validators - * \brief Validator for the points selection - * - * Allows to select points only. - */ -class SketchPlugin_ResultPointValidator : public ModelAPI_ResultValidator -{ -public: - /// Returns true if theObject is a point - SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const; -}; - -/**\class SketchPlugin_ResultLineValidator - * \ingroup Validators - * \brief Validator for the linear segments selection - * - * Allows to select linear segments only. - */ -class SketchPlugin_ResultLineValidator : public ModelAPI_ResultValidator -{ -public: - /// Returns true if theObject is a line - SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const; -}; - -/**\class SketchPlugin_ResultArcValidator - * \ingroup Validators - * \brief Validator for the circular segments selection - * - * Allows to select circular segments only. - */ -class SketchPlugin_ResultArcValidator : public ModelAPI_ResultValidator -{ - public: - /// Returns true if theObject is an arc - SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const; -}; - -#endif diff --git a/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp b/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp index e1dacf811..0722ce1b3 100644 --- a/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp +++ b/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp @@ -11,7 +11,6 @@ #include #include #include -#include bool SketchPlugin_ShapeValidator::isValid(const AttributePtr& theAttribute, const std::list& theArguments) const diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index e69dce246..ec5e929ab 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -8,10 +8,12 @@ #include "SketchPlugin_ConstraintDistance.h" #include #include -#include #include #include #include + +//#include + #include bool SketchPlugin_DistanceAttrValidator::isValid( @@ -33,8 +35,23 @@ bool SketchPlugin_DistanceAttrValidator::isValid( } else { // 1. check whether the references object is a linear ObjectPtr anObject = aRefAttr->object(); - const ModelAPI_ResultValidator* anArcValidator = - dynamic_cast(aFactory->validator("SketchPlugin_ResultArc")); + /* + const ModelAPI_AttributeValidator* aCircleValidator = + dynamic_cast(aFactory->validator("ModuleBase_ValidatorLinearEdge")); + std::list anArguments; + anArguments.push_back("circle"); + bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments); + if (anEdgeValid) + return false; + + anArguments.clear(); + anArguments.push_back("line"); + bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments); + if (!anEdgeValid) + return true;*/ + + /*const ModelAPI_ResultValidator* anArcValidator = aFactory->validator("ModuleBase_ValidatorLinearEdge"); + //dynamic_cast(aFactory->validator("SketchPlugin_ResultArc")); bool anArcValid = anArcValidator->isValid(anObject); if (anArcValid) return false; @@ -44,9 +61,9 @@ bool SketchPlugin_DistanceAttrValidator::isValid( dynamic_cast(aFactory->validator("SketchPlugin_ResultLine")); bool aLineValid = aLineValidator->isValid(anObject); if (!aLineValid) - return true; - FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + return true;*/ + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); // If it is a line then we have to check that first attribute id not a line std::shared_ptr aPoint = getFeaturePoint(aFeature->data(), aParamA); if (aPoint) diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index 9b732adee..ff2183425 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -8,7 +8,7 @@ #define SketchPlugin_Validators_H #include "SketchPlugin.h" -#include +#include /**\class SketchPlugin_DistanceAttrValidator * \ingroup Validators @@ -16,7 +16,7 @@ * * It just checks that distance is greater than zero. */ -class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator +class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator { public: //! returns true if attribute is valid diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 8d69365e2..498db23dd 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -82,9 +82,7 @@