From: vsv Date: Thu, 12 Dec 2019 11:08:36 +0000 (+0300) Subject: Fix for selection of groups features X-Git-Tag: V9_5_0a1~105 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=eb860f799eab680975365d8ce18cec6e04a6f391;p=modules%2Fshaper.git Fix for selection of groups features --- diff --git a/src/XGUI/XGUI_FacesPanel.cpp b/src/XGUI/XGUI_FacesPanel.cpp index f79eb6dba..b0d178196 100644 --- a/src/XGUI/XGUI_FacesPanel.cpp +++ b/src/XGUI/XGUI_FacesPanel.cpp @@ -42,7 +42,6 @@ #include #include -#include #include #include @@ -54,6 +53,26 @@ static const int LayoutMargin = 3; +//******************************************************************** +bool getGroup(ModuleBase_ViewerPrsPtr thePrs, ResultGroupPtr& theResGroup, + FeaturePtr& theGroupFeature) +{ + ObjectPtr anObject = thePrs->object(); + if (!anObject.get()) + return false; + + theResGroup = std::dynamic_pointer_cast(anObject); + if (theResGroup.get()) { + theGroupFeature = ModelAPI_Feature::feature(theResGroup); + } + else { + theGroupFeature = std::dynamic_pointer_cast(anObject); + if (theGroupFeature.get()) + theResGroup = std::dynamic_pointer_cast(theGroupFeature->firstResult()); + } + return true; +} + //******************************************************************** XGUI_FacesPanel::XGUI_FacesPanel(QWidget* theParent, XGUI_Workshop* theWorkshop) : QDockWidget(theParent), myIsActive(false), myWorkshop(theWorkshop) @@ -239,65 +258,79 @@ bool XGUI_FacesPanel::processAction(ModuleBase_ActionType theActionType) } //******************************************************************** -void XGUI_FacesPanel::getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs, +void XGUI_FacesPanel::getObjectsMapFromResult(ResultGroupPtr theResGroup, FeaturePtr theGroupFeature, std::map& theObjectToShapes, std::map& theObjectToPrs) { - ObjectPtr anObject = thePrs->object(); - if (!anObject.get()) - return; - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - ResultGroupPtr aResGroup = std::dynamic_pointer_cast(anObject); - if (aResGroup.get()) { - // Process a grouip result - FeaturePtr aGroupFeature = ModelAPI_Feature::feature(aResGroup); - AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list"); - AISObjectPtr aPrs; - for (int i = 0; i < aSelectionList->size(); i++) { - AttributeSelectionPtr aSelection = aSelectionList->value(i); - ResultPtr aRes = aSelection->context(); - aPrs = aDisplayer->getAISObject(aRes); - if (aPrs.get()) { - Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast( - aPrs->impl()); - if (!aResultPrs.IsNull()) { - GeomShapePtr aShape = aSelection->value(); - if (theObjectToShapes.find(aRes) != theObjectToShapes.end()) - theObjectToShapes.at(aRes).Append(aShape->impl()); - else { - TopoDS_ListOfShape aListOfShapes; - aListOfShapes.Append(aShape->impl()); - theObjectToShapes[aRes] = aListOfShapes; - theObjectToPrs[aRes] = aResultPrs; - } + // Process a grouip result + AttributeSelectionListPtr aSelectionList = theGroupFeature->selectionList("group_list"); + AISObjectPtr aPrs; + for (int i = 0; i < aSelectionList->size(); i++) { + AttributeSelectionPtr aSelection = aSelectionList->value(i); + ResultPtr aRes = aSelection->context(); + aPrs = aDisplayer->getAISObject(aRes); + if (aPrs.get()) { + Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast( + aPrs->impl()); + if (!aResultPrs.IsNull()) { + GeomShapePtr aShape = aSelection->value(); + if (theObjectToShapes.find(aRes) != theObjectToShapes.end()) + theObjectToShapes.at(aRes).Append(aShape->impl()); + else { + TopoDS_ListOfShape aListOfShapes; + aListOfShapes.Append(aShape->impl()); + theObjectToShapes[aRes] = aListOfShapes; + theObjectToPrs[aRes] = aResultPrs; } } } } +} + +//******************************************************************** +void objectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs, + std::map& theObjectToShapes, + std::map& theObjectToPrs) +{ + ObjectPtr anObject = thePrs->object(); + if (!anObject.get()) + return; + + // Process bodies + Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast( + thePrs->interactive()); + if (aResultPrs.IsNull()) + return; + + if (theObjectToShapes.find(anObject) != theObjectToShapes.end()) + theObjectToShapes.at(anObject).Append(ModuleBase_Tools::getSelectedShape(thePrs)); else { - // Process bodies - Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast( - thePrs->interactive()); - if (aResultPrs.IsNull()) - return; - - if (theObjectToShapes.find(anObject) != theObjectToShapes.end()) - theObjectToShapes.at(anObject).Append(ModuleBase_Tools::getSelectedShape(thePrs)); - else { - TopoDS_ListOfShape aListOfShapes; - aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(thePrs)); - theObjectToShapes[anObject] = aListOfShapes; - theObjectToPrs[anObject] = aResultPrs; - } + TopoDS_ListOfShape aListOfShapes; + aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(thePrs)); + theObjectToShapes[anObject] = aListOfShapes; + theObjectToPrs[anObject] = aResultPrs; } } +//******************************************************************** +void XGUI_FacesPanel::getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs, + std::map& theObjectToShapes, + std::map& theObjectToPrs) +{ + ResultGroupPtr aResGroup; + FeaturePtr aGroupFeature; + if (getGroup(thePrs, aResGroup, aGroupFeature)) + getObjectsMapFromResult(aResGroup, aGroupFeature, theObjectToShapes, theObjectToPrs); + else + objectsMapFromPrs(thePrs, theObjectToShapes, theObjectToPrs); +} + //******************************************************************** void XGUI_FacesPanel::processSelection() { QList aSelected = - myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Viewer); + myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::AllControls); if (aSelected.size() == 0) return; @@ -315,16 +348,14 @@ void XGUI_FacesPanel::processSelection() if (!anObject.get()) continue; - ResultGroupPtr aResGroup = std::dynamic_pointer_cast(anObject); - if (aResGroup.get()) { - FeaturePtr aFeature = ModelAPI_Feature::feature(aResGroup); - if (aFeature.get()) { - AttributeSelectionListPtr aSelectionListAttr = - aFeature->data()->selectionList("group_list"); - std::string aType = aSelectionListAttr->selectionType(); - if (aType != "Faces") - continue; - } + ResultGroupPtr aResGroup; + FeaturePtr aGroupFeature; + if (getGroup(aPrs, aResGroup, aGroupFeature)) { + AttributeSelectionListPtr aSelectionListAttr = + aGroupFeature->data()->selectionList("group_list"); + std::string aType = aSelectionListAttr->selectionType(); + if (aType != "Faces") + continue; } else { GeomShapePtr aShapePtr = aPrs->shape(); @@ -337,11 +368,15 @@ void XGUI_FacesPanel::processSelection() if (myListView->hasItem(aItemName)) continue; - getObjectsMapFromPrs(aPrs, anObjectToShapes, anObjectToPrs); - if (aResGroup.get() && aResGroup->isDisplayed()) { - aResGroup->setDisplayed(false); - myHiddenGroups.insert(aResGroup); + if (aResGroup.get()) { + if (aResGroup->isDisplayed()) { + aResGroup->setDisplayed(false); + myHiddenGroups.insert(aResGroup); + } + getObjectsMapFromResult(aResGroup, aGroupFeature, anObjectToShapes, anObjectToPrs); } + else + objectsMapFromPrs(aPrs, anObjectToShapes, anObjectToPrs); // The code is dedicated to remove already selected items if they are selected twice // It can happen in case of groups selection @@ -441,8 +476,9 @@ bool XGUI_FacesPanel::processDelete() std::set::const_iterator aIt; for (aIt = aRestored.cbegin(); aIt != aRestored.cend(); aIt++) { getObjectsMapFromPrs((*aIt), anObjectToShapes, anObjectToPrs); - ResultGroupPtr aResGroup = std::dynamic_pointer_cast((*aIt)->object()); - if (aResGroup.get()) { + ResultGroupPtr aResGroup; + FeaturePtr aGroupFeature; + if (getGroup((*aIt), aResGroup, aGroupFeature)) { std::set >::iterator aGrpIt = myHiddenGroups.find(aResGroup); if (aGrpIt != myHiddenGroups.end()) { aResGroup->setDisplayed(true); diff --git a/src/XGUI/XGUI_FacesPanel.h b/src/XGUI/XGUI_FacesPanel.h index d442ee6b8..50dfacc5d 100644 --- a/src/XGUI/XGUI_FacesPanel.h +++ b/src/XGUI/XGUI_FacesPanel.h @@ -22,13 +22,15 @@ #include "XGUI.h" -#include - #include #include #include #include +#include +#include +#include + #include #include @@ -155,10 +157,14 @@ private: /// \param thePrs a selected presintation /// \param theObjectsToShapes map of objects to shapes list /// \param theObjectToPrs map of objects to presentations - void getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs, + void getObjectsMapFromResult(ResultGroupPtr theResGroup, FeaturePtr theGroupFeature, std::map& theObjectsToShapes, std::map& theObjectToPrs); + void getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs, + std::map& theObjectToShapes, + std::map& theObjectToPrs); + /// Returns true if transparency choice is checked /// \return boolean value bool useTransparency() const;