X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetValidated.cpp;h=937464e3cf026cf0e2adc9151a95797bdca1378f;hb=4c74e5b864eef28128e27b3ece944990ca8f3fbe;hp=91713b65bdde0e49799647589065311d34c23e3b;hpb=1e2eaa713f139d2617c80eba9ede62d4e9976bb7;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 91713b65b..937464e3c 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include @@ -35,6 +34,7 @@ #include #include #include +#include #include #include @@ -116,10 +116,48 @@ bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr& myPresentedObject = aResult; } else { - FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object()); + //FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object()); + FeaturePtr aFeature = std::dynamic_pointer_cast(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(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(); + Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs); + anOwner = 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(); + AISObjectPtr aIOPtr = myWorkshop->findPresentation(aResult); + if (aIOPtr.get()) { + Handle(AIS_InteractiveObject) anIO = aIOPtr->impl(); + anOwner = new StdSelect_BRepOwner(aTDShape, anIO); + } + } + } + aValid = !anOwner.IsNull(); // only results with a shape can be filtered + } } else aValid = false; // only results with a shape can be filtered } @@ -405,12 +443,9 @@ QList ModuleBase_WidgetValidated::getFilteredSelected() void ModuleBase_WidgetValidated::filterPresentations(QList& theValues) { QList aValidatedValues; - - QList::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(); @@ -421,31 +456,42 @@ void ModuleBase_WidgetValidated::filterPresentations(QList& theValues) { - std::set aCompSolids; + std::set aFilterOut; // all objects that must be filtered out with their children QList aValidatedValues; // Collect compsolids. QList::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(); ResultBodyPtr aResultCompSolid = std::dynamic_pointer_cast(anObject); - if(aResultCompSolid.get() && aResultCompSolid->numberOfSubs() > 0) { - aCompSolids.insert(aResultCompSolid); + 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(anObject); + if (aFeature.get()) { + std::list::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(anObject); - ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(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); }