From 3b3c5155d7923f2c798e4a0d849f41d9149ae1ef Mon Sep 17 00:00:00 2001 From: Alexey Kondratyev Date: Wed, 19 Jan 2022 14:53:09 +0300 Subject: [PATCH] [bos #24514] [CEA] When creating a group, be able to select the sub-shapes of displayed groups (even if no result is displayed) * Update algorithm to select sub-shapes of displayed groups and add this in the created group as shape from results. * Add validator for prevent adding whole group in other group. --- .../CollectionPlugin_Plugin.cpp | 2 ++ .../CollectionPlugin_Validators.cpp | 24 ++++++++++++++ .../CollectionPlugin_Validators.h | 15 +++++++++ src/CollectionPlugin/group_widget.xml | 4 ++- src/ModuleBase/ModuleBase_WidgetSelector.cpp | 31 +++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/CollectionPlugin/CollectionPlugin_Plugin.cpp b/src/CollectionPlugin/CollectionPlugin_Plugin.cpp index faed9733e..a50816397 100644 --- a/src/CollectionPlugin/CollectionPlugin_Plugin.cpp +++ b/src/CollectionPlugin/CollectionPlugin_Plugin.cpp @@ -51,6 +51,8 @@ CollectionPlugin_Plugin::CollectionPlugin_Plugin() new CollectionPlugin_FieldValidator); aFactory->registerValidator("CollectionPlugin_OperationAttribute", new CollectionPlugin_GroupOperationAttributeValidator); + aFactory->registerValidator("CollectionPlugin_GroupSelectionValidator", + new CollectionPlugin_GroupSelectionValidator); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/CollectionPlugin/CollectionPlugin_Validators.cpp b/src/CollectionPlugin/CollectionPlugin_Validators.cpp index 7cee37457..2a96b71f0 100644 --- a/src/CollectionPlugin/CollectionPlugin_Validators.cpp +++ b/src/CollectionPlugin/CollectionPlugin_Validators.cpp @@ -100,3 +100,27 @@ bool CollectionPlugin_GroupOperationAttributeValidator::isValid( } return true; } + +bool CollectionPlugin_GroupSelectionValidator::isValid( + const AttributePtr& theAttribute, + const std::list& /*theArguments*/, + Events_InfoMessage& theError) const +{ + AttributeSelectionListPtr aSelList = + std::dynamic_pointer_cast(theAttribute); + if (!aSelList) { + theError = "Error: This validator can only work with selection list of attributes"; + return false; + } + + for (int anIndex = 0; anIndex < aSelList->size(); ++anIndex) { + AttributeSelectionPtr aCurSelection = aSelList->value(anIndex); + ResultPtr aGroupResult = aCurSelection->context(); + if (!aGroupResult.get() || aGroupResult->groupName() == ModelAPI_ResultGroup::group()) { + theError = "Error: Whole group mustn't be selected."; + return false; + } + } + + return true; +} diff --git a/src/CollectionPlugin/CollectionPlugin_Validators.h b/src/CollectionPlugin/CollectionPlugin_Validators.h index 1e9023286..c17633035 100644 --- a/src/CollectionPlugin/CollectionPlugin_Validators.h +++ b/src/CollectionPlugin/CollectionPlugin_Validators.h @@ -55,4 +55,19 @@ class CollectionPlugin_GroupOperationAttributeValidator : public ModelAPI_Attrib Events_InfoMessage& theError) const; }; +/**\class CollectionPlugin_GroupSelectionValidator +* \ingroup Validators +* \brief Validator for prevent adding whole group in other group. +*/ +class CollectionPlugin_GroupSelectionValidator : public ModelAPI_AttributeValidator +{ + //! Returns true if attribute is ok. + //! \param[in] theAttribute the checked attribute. + //! \param[in] theArguments arguments of the attribute (not used). + //! \param[out] theError error message. + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const; +}; + #endif \ No newline at end of file diff --git a/src/CollectionPlugin/group_widget.xml b/src/CollectionPlugin/group_widget.xml index 6c304ade6..b73c0bf4c 100644 --- a/src/CollectionPlugin/group_widget.xml +++ b/src/CollectionPlugin/group_widget.xml @@ -6,11 +6,13 @@ - + + \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 831fc4cb4..a4181dc5b 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -35,11 +35,16 @@ #include #include #include +#include #include #include +// Get object from group +// Return true if find object +static bool getObjectFromGroup(ObjectPtr& theObject, GeomShapePtr& theShape); + ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData) @@ -66,6 +71,15 @@ void ModuleBase_WidgetSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& if (!theObject.get()) theObject = thePrs->object(); theShape = aSelection->getShape(thePrs); + + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + while (aFeature && aFeature->lastResult()->groupName() == ModelAPI_ResultGroup::group()) { + if (!getObjectFromGroup(theObject, theShape)) + break; + aFeature = ModelAPI_Feature::feature(theObject); + + thePrs->setObject(theObject); + } } //******************************************************************** @@ -267,3 +281,20 @@ bool ModuleBase_WidgetSelector::isWholeResultAllowed() const } return false; } + +bool getObjectFromGroup(ObjectPtr& theObject, GeomShapePtr& theShape) +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + + AttributeSelectionListPtr anAttrList = aFeature->selectionList("group_list"); + + for (int anIndex = 0; anIndex < anAttrList->size(); ++anIndex) { + AttributeSelectionPtr aSelect = anAttrList->value(anIndex); + if (aSelect->context()->shape()->isSubShape(theShape) || + aSelect->context()->shape()->isEqual(theShape)) { + theObject = aSelect->contextObject(); + return true; + } + } + return false; +} \ No newline at end of file -- 2.30.2