From: vsv Date: Wed, 11 Sep 2019 12:31:17 +0000 (+0300) Subject: Replace selection from result by a one result X-Git-Tag: V9_4_0a2~4^2~112 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4c8000e288a5980fd34b2276a1aaaf8e52879027;p=modules%2Fshaper.git Replace selection from result by a one result --- diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp index 10437dca0..ed75e8671 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -572,12 +573,60 @@ void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate) } } +void replaceSubShapesByResult(QList& theResults, int theShapeType) +{ + QMap> myResShapes; + // Sort sub-shapes by result + foreach (ModuleBase_ViewerPrsPtr aPrs, theResults) { + if (myResShapes.contains(aPrs->object())) + myResShapes[aPrs->object()].append(aPrs->shape()); + else { + QList aShapes; + aShapes << aPrs->shape(); + myResShapes[aPrs->object()] = aShapes; + } + } + // Find Results to replace by whole result + QList aShapes; + QList aToReplace; + std::list aSubShapes; + foreach(ObjectPtr aObj, myResShapes.keys()) { + aShapes = myResShapes[aObj]; + ResultPtr aRes = std::dynamic_pointer_cast(aObj); + TopTools_MapOfShape aShapesMap; + if (aRes.get()) { + GeomShapePtr aSubShape = aRes->shape(); + const TopoDS_Shape& aShape = aSubShape->impl(); + for (TopExp_Explorer anExp(aShape, (TopAbs_ShapeEnum)theShapeType); + anExp.More(); anExp.Next()) { + aShapesMap.Add(anExp.Current()); + } + } + if (aShapes.count() == aShapesMap.Size()) + aToReplace.append(aObj); + } + // Replace the found results + QList::iterator aIt; + foreach(ObjectPtr aObj, aToReplace) { + for (aIt = theResults.begin(); aIt != theResults.end(); aIt++) { + if ((*aIt)->object() == aObj) { + theResults.removeAll(*aIt); + aIt--; + } + } + ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj)); + theResults.append(aValue); + } +} + void ModuleBase_WidgetSelectionFilter::onFeatureAccepted() { AttributePtr aAttr = mySelectorFeature->attribute(mySelectorAttribute); AttributeSelectionListPtr aSelListAttr = std::dynamic_pointer_cast(aAttr); aSelListAttr->clear(); + if (aSelListAttr->isWholeResultAllowed()) + replaceSubShapesByResult(myValues, selectionType(aSelListAttr->selectionType().c_str())); foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) { aSelListAttr->append(aPrs->object(), aPrs->shape()); }