+ return myPresentedObject;
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidated::deactivate()
+{
+ clearValidatedCash();
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidated::clearValidatedCash()
+{
+#ifdef DEBUG_VALID_STATE
+ qDebug("clearValidatedCash");
+#endif
+ myValidPrs.Clear();
+ myInvalidPrs.Clear();
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidated::storeAttributeValue(const AttributePtr& theAttribute)
+{
+ myIsInValidate = true;
+ myAttributeStore->storeAttributeValue(theAttribute, myWorkshop);
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidated::restoreAttributeValue(const AttributePtr& theAttribute,
+ const bool theValid)
+{
+ myIsInValidate = false;
+ myAttributeStore->restoreAttributeValue(theAttribute, myWorkshop);
+}
+
+//********************************************************************
+bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr& thePrs)
+{
+ bool aValid = true;
+ AIS_NListOfEntityOwner aOwnersList;
+ if (!thePrs->owner().IsNull())
+ aOwnersList.Append(thePrs->owner());
+
+ // if an owner is null, the selection happens in the Object browser.
+ // creates a selection owner on the base of object shape and the object AIS object
+ if ((aOwnersList.Size() == 0) && thePrs->object().get()) {
+ ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
+ GeomShapePtr aShape = aResult.get() ? aResult->shape() : GeomShapePtr();
+ // some results have no shape, e.g. the parameter one. So, they should not be validated
+ if (aShape.get()) {
+ const TopoDS_Shape aTDShape = aShape->impl<TopoDS_Shape>();
+ Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs);
+ aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO));
+ myPresentedObject = aResult;
+ }
+ else {
+ //FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(thePrs->object());
+ if (aFeature.get()) {
+ // Use feature as a reference to all its results
+ myPresentedObject = aFeature;
+ AttributePtr anAttr = attribute();
+ std::string aType = anAttr->attributeType();
+
+ // Check that results of Feature is acceptable by filters for selection attribute
+ if (aType == ModelAPI_AttributeSelection::typeId()) {
+ AttributeSelectionPtr aSelectAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttr);
+ aSelectAttr->setValue(myPresentedObject, GeomShapePtr(), true);
+ GeomShapePtr aShape = aSelectAttr->value();
+ if (!aShape.get() && aSelectAttr->contextFeature().get() &&
+ aSelectAttr->contextFeature()->firstResult().get()) {
+ aShape = aSelectAttr->contextFeature()->firstResult()->shape();
+ }
+ if (aShape.get()) {
+ const TopoDS_Shape aTDShape = aShape->impl<TopoDS_Shape>();
+ Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs);
+ aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO));
+ }
+ else
+ aValid = false;
+ //aSelectAttr->setValue(ObjectPtr(), GeomShapePtr(), true);
+ }
+ else {
+ ResultPtr aResult = aFeature->firstResult();
+ if (aResult.get()) {
+ GeomShapePtr aShapePtr = ModelAPI_Tools::shape(aResult);
+ if (aShapePtr.get()) {
+ const TopoDS_Shape aTDShape = aShapePtr->impl<TopoDS_Shape>();
+ AISObjectPtr aIOPtr = myWorkshop->findPresentation(aResult);
+ if (aIOPtr.get()) {
+ Handle(AIS_InteractiveObject) anIO = aIOPtr->impl<Handle(AIS_InteractiveObject)>();
+ aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO));
+ }
+ else {
+ aOwnersList.Append(new StdSelect_BRepOwner(aTDShape));
+ }
+ }
+ }
+ aValid = (aOwnersList.Size() > 0); // only results with a shape can be filtered
+ }
+ } else
+ aValid = false; // only results with a shape can be filtered
+ }
+ }
+ // checks the owner by the AIS context activated filters
+ if (aOwnersList.Size() > 0) {
+ // the widget validator filter should be active, but during check by preselection
+ // it is not yet activated, so we need to activate/deactivate it manually
+ bool isActivated = isFilterActivated();
+ if (!isActivated) {
+ QIntList aModuleSelectionFilters = myWorkshop->module()->selectionFilters();
+ SelectMgr_ListOfFilter aSelectionFilters;
+ selectionFilters(aModuleSelectionFilters, aSelectionFilters);
+ /// after validation, the selection filters should be restored
+ myWorkshop->selectionActivate()->activateSelectionFilters(aSelectionFilters);
+ }