* 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.
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);
}
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;
+}
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
<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
#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)
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);
+ }
}
//********************************************************************
}
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