]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[bos #24514] [CEA] When creating a group, be able to select the sub-shapes of display... CR24514
authorAlexey Kondratyev <alexey.kondratyev@opencascade.com>
Wed, 19 Jan 2022 11:53:09 +0000 (14:53 +0300)
committerazv <azv@opencascade.com>
Tue, 8 Feb 2022 04:17:31 +0000 (07:17 +0300)
* 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.

src/CollectionPlugin/CollectionPlugin_Plugin.cpp
src/CollectionPlugin/CollectionPlugin_Validators.cpp
src/CollectionPlugin/CollectionPlugin_Validators.h
src/CollectionPlugin/group_widget.xml
src/ModuleBase/ModuleBase_WidgetSelector.cpp

index faed9733ec07776877544799cc00ef74d9a87f1e..a5081639730b50777593e47cbbfb6e12dee3aa6b 100644 (file)
@@ -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);
index 7cee37457c819bd032ad3281def8418a3316bb36..2a96b71f07fe4a1cd48da155fbd6b21d371d33ba 100644 (file)
@@ -100,3 +100,27 @@ bool CollectionPlugin_GroupOperationAttributeValidator::isValid(
   }
   return true;
 }
+
+bool CollectionPlugin_GroupSelectionValidator::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& /*theArguments*/,
+    Events_InfoMessage& theError) const
+{
+  AttributeSelectionListPtr aSelList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(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;
+}
index 1e90232868b891d5d825d3a48c404f0e0f074771..c176330359d855f790476c37c0de749e6ce40130 100644 (file)
@@ -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<std::string>& theArguments,
+    Events_InfoMessage& theError) const;
+};
+
 #endif
\ No newline at end of file
index 6c304ade6eb852943c7dfe8d0ccbcaf2362ed787..b73c0bf4c176790f5f2e335e848c18243726370d 100644 (file)
@@ -6,11 +6,13 @@
   <multi_selector id="group_list"
     tooltip="Select a set of objects"
     shape_types="Vertices Edges Faces Solids"
+    allow_objects="Group"
     use_choice="true"
     use_filters="FiltersSelection"
     clear_in_neutral_point="false"
     filter_points="false"
     same_topology="true">
     <validator id="GeomValidators_BodyShapes"/>
-  </multi_selector>
+    <validator id="CollectionPlugin_GroupSelectionValidator"/>
+    </multi_selector>
 </source>
\ No newline at end of file
index 831fc4cb4c481ef3d1d188d3c4032d1dad688938..a4181dc5b8c480d24b3e037aef1865ee6cef7af5 100644 (file)
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultGroup.h>
 
 #include <Config_WidgetAPI.h>
 
 #include <TopoDS_Iterator.hxx>
 
+// 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