From: nds Date: Fri, 20 Mar 2015 14:57:28 +0000 (+0300) Subject: Union of validator and filter functionalities. X-Git-Tag: V_1.1.0~95 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2d7645749869716884dc121ff7898b41620b246d;p=modules%2Fshaper.git Union of validator and filter functionalities. Validator for NoConstructionSubShape filter --- diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml index 44f6f0e94..435a2e7b3 100644 --- a/src/ConstructionPlugin/axis_widget.xml +++ b/src/ConstructionPlugin/axis_widget.xml @@ -8,14 +8,14 @@ icon=":icons/point.png" tooltip="Select a first point" shape_types="vertex"> - + - + diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 0b76254af..5dcc40908 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -40,6 +40,7 @@ SET(PROJECT_HEADERS ModuleBase_ValidatorFace.h ModuleBase_ValidatorLinearEdge.h ModuleBase_ValidatorLinearEdgeOrVertex.h + ModuleBase_ValidatorNoConstructionSubShapes.h ModuleBase_ViewerFilters.h ModuleBase_ResultPrs.h ModuleBase_IViewWindow.h @@ -86,6 +87,7 @@ SET(PROJECT_SOURCES ModuleBase_ValidatorFace.cpp ModuleBase_ValidatorLinearEdge.cpp ModuleBase_ValidatorLinearEdgeOrVertex.cpp + ModuleBase_ValidatorNoConstructionSubShapes.cpp ModuleBase_ViewerFilters.cpp ModuleBase_ResultPrs.cpp ModuleBase_WidgetLabel.cpp diff --git a/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp new file mode 100644 index 000000000..7a6ab98c9 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp @@ -0,0 +1,48 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#include "ModuleBase_ValidatorNoConstructionSubShapes.h" + +#include "ModelAPI_AttributeSelection.h" +#include "ModelAPI_ResultConstruction.h" +#include "ModelAPI_CompositeFeature.h" + +bool ModuleBase_ValidatorNoConstructionSubShapes::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const +{ + bool aValid = false; + AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast + (theAttribute); + if (aSelectionAttr.get() == NULL) + return aValid; + + ResultPtr aResult = aSelectionAttr->context(); + GeomShapePtr aShape = aSelectionAttr->value(); + // global selection should be ignored, the filter processes only selected sub-shapes + // that means, that the shape of the context result is equal to the shape value + ///*ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); + if (aResult.get() != NULL) { + GeomShapePtr aShapePtr = aResult->shape(); + // it is important to call isEqual of the shape of result. + // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is + // GeomAPI_Shape. It is important to use the realization of the isEqual method from + // GeomAPI_Vertex class + aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape); + } + if (!aValid) { + ResultConstructionPtr aConstr = + std::dynamic_pointer_cast(aResult); + if (aConstr != NULL) { + // it provides selection only on compositie features, construction without composite + // feature is not selectable + FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr); + CompositeFeaturePtr aComposite = + std::dynamic_pointer_cast(aFeature); + aValid = aComposite && aComposite->numberOfSubs() > 0; + } + else { + // non-construction results should be accepted by this filter, e.g. body results + aValid = true; + } + } + return aValid; +} diff --git a/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h new file mode 100644 index 000000000..1338fcef7 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h @@ -0,0 +1,28 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_ValidatorNoConstructionSubShapes.h +// Created: 20 Mar 2015 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_ValidatorNoConstructionSubShapes_H +#define ModuleBase_ValidatorNoConstructionSubShapes_H + +#include "ModuleBase.h" +#include "ModelAPI_AttributeValidator.h" + +/** +* \ingroup Validators +* A validator of selection +*/ +class ModuleBase_ValidatorNoConstructionSubShapes : public ModelAPI_AttributeValidator +{ + public: + MODULEBASE_EXPORT ModuleBase_ValidatorNoConstructionSubShapes() {} + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index a5ddfb704..88c587aff 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -106,17 +106,19 @@ bool ModuleBase_WidgetValidated::isValid(ObjectPtr theObj, GeomShapePtr theShape 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; @@ -130,7 +132,8 @@ void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorksh aViewer->addSelectionFilter(aSelFilter); else aViewer->removeSelectionFilter(aSelFilter); - }*/ + } +#endif } void ModuleBase_WidgetValidated::selectionFilters(ModuleBase_IWorkshop* theWorkshop, diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 8406ad191..79d5b9664 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -135,6 +136,9 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex", new ModuleBase_ValidatorLinearEdgeOrVertex); aFactory->registerValidator("ModuleBase_ValidatorFace", new ModuleBase_ValidatorFace); + + aFactory->registerValidator("ModuleBase_ValidatorNoConstructionSubShapes", + new ModuleBase_ValidatorNoConstructionSubShapes); } void PartSet_Module::registerFilters()