-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
#include <ModuleBase_WidgetValidated.h>
+#include <ModuleBase_IModule.h>
#include <ModuleBase_IViewer.h>
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_ISelection.h>
+#include <ModuleBase_ISelectionActivate.h>
#include <ModuleBase_WidgetSelectorStore.h>
#include <ModuleBase_ViewerPrs.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_Events.h>
-#include <ModelAPI_ResultCompSolid.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeSelection.h>
#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
#include <SelectMgr_EntityOwner.hxx>
return myPresentedObject;
}
+//********************************************************************
+void ModuleBase_WidgetValidated::deactivate()
+{
+ clearValidatedCash();
+}
+
//********************************************************************
void ModuleBase_WidgetValidated::clearValidatedCash()
{
myAttributeStore->restoreAttributeValue(theAttribute, myWorkshop);
}
+
+//********************************************************************
+void ModuleBase_WidgetValidated::collectSubBodies(const ResultBodyPtr& theBody,
+ AIS_NListOfEntityOwner& theList)
+{
+ AISObjectPtr aIOPtr;
+ TopoDS_Shape aTDShape;
+ int aNb = theBody->numberOfSubs();
+ for (int i = 0; i < aNb; i++) {
+ ResultBodyPtr aSub = theBody->subResult(i);
+ if (aSub->numberOfSubs() > 0)
+ collectSubBodies(aSub, theList);
+ else {
+ aTDShape = aSub->shape()->impl<TopoDS_Shape>();
+ aIOPtr = myWorkshop->findPresentation(aSub);
+ if (aIOPtr.get()) {
+ Handle(AIS_InteractiveObject) anIO = aIOPtr->impl<Handle(AIS_InteractiveObject)>();
+ theList.Append(new StdSelect_BRepOwner(aTDShape, anIO));
+ }
+ else
+ theList.Append(new StdSelect_BRepOwner(aTDShape));
+ }
+ }
+}
+
//********************************************************************
bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr& thePrs)
{
bool aValid = true;
- Handle(SelectMgr_EntityOwner) anOwner = thePrs->owner();
+ 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 (anOwner.IsNull() && thePrs->owner().IsNull() && thePrs->object().get()) {
+ 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);
- anOwner = new StdSelect_BRepOwner(aTDShape, anIO);
+ aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO));
myPresentedObject = aResult;
}
- else
- aValid = false; // only results with a shape can be filtered
+ 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 aShapePtr = aSelectAttr->value();
+ if (!aShapePtr.get() && aSelectAttr->contextFeature().get() &&
+ aSelectAttr->contextFeature()->firstResult().get()) {
+ aShapePtr = aSelectAttr->contextFeature()->firstResult()->shape();
+ }
+ if (aShapePtr.get()) {
+ const TopoDS_Shape aTDShape = aShapePtr->impl<TopoDS_Shape>();
+ Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs);
+ aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO));
+ }
+ }
+ else {
+ ResultPtr aFirstRes = aFeature->firstResult();
+ if (aFirstRes.get()) {
+ ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aFirstRes);
+ if (aBody.get() && (aBody->numberOfSubs() > 0))
+ collectSubBodies(aBody, aOwnersList);
+ else {
+ GeomShapePtr aShapePtr = ModelAPI_Tools::shape(aFirstRes);
+ if (aShapePtr.get()) {
+ TopoDS_Shape aTDShape = aShapePtr->impl<TopoDS_Shape>();
+ AISObjectPtr aIOPtr = myWorkshop->findPresentation(aFirstRes);
+ 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
+
// checks the owner by the AIS context activated filters
- if (!anOwner.IsNull()) {
+ 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)
- activateFilters(true);
+ 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);
+ }
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
if (!aContext.IsNull()) {
const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
+ AIS_NListOfEntityOwner::Iterator aOIt;
for (; anIt.More() && aValid; anIt.Next()) {
Handle(SelectMgr_Filter) aFilter = anIt.Value();
- aValid = aFilter->IsOk(anOwner);
+ for (aOIt.Init(aOwnersList); aOIt.More(); aOIt.Next()) {
+ aValid = aFilter->IsOk(aOIt.Value());
+ if (!aValid)
+ break;
+ }
+ if (!aValid)
+ break;
}
}
- if (!isActivated)
- activateFilters(false);
+ if (!isActivated) {
+ // reset filters set in activateSelectionFilters above
+ myWorkshop->selectionActivate()->updateSelectionFilters();
+ clearValidatedCash();
+ }
}
// removes created owner
- if (!anOwner.IsNull() && anOwner != thePrs->owner()) {
- anOwner.Nullify();
+ if (aOwnersList.Size() > 0 && thePrs->owner().IsNull()) {
myPresentedObject = ObjectPtr();
}
+ if (!aValid) {
+ // Clear attribute if it still has selection
+ AttributePtr anAttr = attribute();
+ std::string aType = anAttr->attributeType();
+ if (aType == ModelAPI_AttributeSelection::typeId()) {
+ AttributeSelectionPtr aSelectAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttr);
+ aSelectAttr->removeTemporaryValues();
+ }
+ }
return aValid;
}
return aFactory->validate(theAttribute, aValidatorID, anError);
}
+//********************************************************************
bool ModuleBase_WidgetValidated::isFilterActivated() const
{
- bool isActivated = false;
-
Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
ModuleBase_IViewer* aViewer = myWorkshop->viewer();
return aViewer->hasSelectionFilter(aSelFilter);
}
-bool ModuleBase_WidgetValidated::activateFilters(const bool toActivate)
+//********************************************************************
+void ModuleBase_WidgetValidated::selectionFilters(QIntList& theModuleSelectionFilters,
+ SelectMgr_ListOfFilter& theSelectionFilters)
{
- ModuleBase_IViewer* aViewer = myWorkshop->viewer();
-
- Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
- bool aHasSelectionFilter = aViewer->hasSelectionFilter(aSelFilter);
-
- if (toActivate)
- aViewer->addSelectionFilter(aSelFilter);
- else {
- aViewer->removeSelectionFilter(aSelFilter);
- clearValidatedCash();
- }
-
- return aHasSelectionFilter;
+ theSelectionFilters.Append(myWorkshop->validatorFilter());
}
//********************************************************************
void ModuleBase_WidgetValidated::filterPresentations(QList<ModuleBase_ViewerPrsPtr>& theValues)
{
QList<ModuleBase_ViewerPrsPtr> aValidatedValues;
-
- QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
- bool isDone = false;
- for (; anIt != aLast; anIt++) {
- if (isValidInFilters(*anIt))
- aValidatedValues.append(*anIt);
+ foreach(ModuleBase_ViewerPrsPtr aPrs, theValues) {
+ if (isValidInFilters(aPrs))
+ aValidatedValues.append(aPrs);
}
if (aValidatedValues.size() != theValues.size()) {
theValues.clear();
//********************************************************************
void ModuleBase_WidgetValidated::filterCompSolids(QList<ModuleBase_ViewerPrsPtr>& theValues)
{
- std::set<ResultCompSolidPtr> aCompSolids;
+ std::set<ResultPtr> aFilterOut; // all objects that must be filtered out with their children
QList<ModuleBase_ViewerPrsPtr> aValidatedValues;
// Collect compsolids.
QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
- for (; anIt != aLast; anIt++) {
+ for(; anIt != aLast; anIt++) {
const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt;
ObjectPtr anObject = aViewerPrs->object();
- ResultCompSolidPtr aResultCompSolid =
- std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(anObject);
- if(aResultCompSolid.get()) {
- aCompSolids.insert(aResultCompSolid);
+ ResultBodyPtr aResultCompSolid =
+ std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
+ if (aResultCompSolid.get()) {
+ for(int aSubIndex = 0; aSubIndex < aResultCompSolid->numberOfSubs(); aSubIndex++)
+ aFilterOut.insert(aResultCompSolid->subResult(aSubIndex));
+ } else { // it could be a whole feature selected, so, add all results of this feature
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
+ if (aFeature.get()) {
+ std::list<ResultPtr>::const_iterator aRes = aFeature->results().cbegin();
+ for(; aRes != aFeature->results().cend(); aRes++)
+ aFilterOut.insert(*aRes);
+ }
}
}
// Filter sub-solids of compsolids.
anIt = theValues.begin();
- for (; anIt != aLast; anIt++) {
+ for(; anIt != aLast; anIt++) {
const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt;
ObjectPtr anObject = aViewerPrs->object();
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aResult);
- if(aResCompSolidPtr.get() && (aCompSolids.find(aResCompSolidPtr) != aCompSolids.end())) {
- // Skip sub-solid of compsolid.
- continue;
+ while(aResult.get()) {
+ if (aFilterOut.find(aResult) != aFilterOut.end()) // skip if parent is filtered out
+ break;
+ aResult = ModelAPI_Tools::bodyOwner(aResult); // iterate all parents
+ }
+ if (aResult.get()) {
+ continue; // skip
} else {
aValidatedValues.append(*anIt);
}