From 8ffc4361cab5e109ff95ef0f258a8a10670b7b21 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 14 Dec 2017 16:39:43 +0300 Subject: [PATCH] Hide faces: checking presentation on having any shapes using a whole container of shapes to be hidden. --- src/ModuleBase/ModuleBase_ResultPrs.cpp | 14 ++------ src/ModuleBase/ModuleBase_ResultPrs.h | 4 +-- src/XGUI/XGUI_FacesPanel.cpp | 43 +++++++++++++++++++++++-- src/XGUI/XGUI_Workshop.cpp | 4 +-- 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index 33708cb51..c1ce983e0 100755 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -140,21 +140,13 @@ bool ModuleBase_ResultPrs::setSubShapeHidden(const NCollection_List& theShapesToSkip) { - int aNbOfHiddenSubShapes = myHiddenSubShapes.Size(); - - if (!myHiddenSubShapes.Contains(theShape)) - aNbOfHiddenSubShapes++; // the shape to be hidden later - - //const TopoDS_Shape aCurrentShape = Shape(); - NCollection_List aHiddenSubShapes = myHiddenSubShapes; - aHiddenSubShapes.Append(theShape); - TopoDS_Compound aCompound; BRep_Builder aBuilder; aBuilder.MakeCompound (aCompound); - collectSubShapes(aBuilder, aCompound, myOriginalShape, aHiddenSubShapes); + collectSubShapes(aBuilder, aCompound, myOriginalShape, theShapesToSkip); return !BOPTools_AlgoTools3D::IsEmptyShape(aCompound); } diff --git a/src/ModuleBase/ModuleBase_ResultPrs.h b/src/ModuleBase/ModuleBase_ResultPrs.h index 3fb1e1906..f3c42bc9e 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.h +++ b/src/ModuleBase/ModuleBase_ResultPrs.h @@ -94,9 +94,9 @@ public: Standard_EXPORT bool setSubShapeHidden(const NCollection_List& theShapes); /// Returns true if there are no hidden sub shapes or original shape has at least one not hidden - /// \param theShapeToSkip the shape should be interpreted as additional hidden in the presentation + /// \param theShapesToSkip container of shape to be hidden in the presentation (faces) /// \return boolean value - Standard_EXPORT bool hasSubShapeVisible(const TopoDS_Shape& theShapeToSkip); + Standard_EXPORT bool hasSubShapeVisible(const NCollection_List& theShapesToSkip); /// Set transparency of hidden sub shapes: if value is 1, shapes are entirely hidden /// \param theTransparency transparency value diff --git a/src/XGUI/XGUI_FacesPanel.cpp b/src/XGUI/XGUI_FacesPanel.cpp index dcdeaa597..c3ab2ec0b 100644 --- a/src/XGUI/XGUI_FacesPanel.cpp +++ b/src/XGUI/XGUI_FacesPanel.cpp @@ -210,6 +210,9 @@ void XGUI_FacesPanel::processSelection() ModuleBase_ISelection::Viewer); bool isModified = false; static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); + + std::map > anObjectToShapes; + std::map anObjectToPrs; for (int i = 0; i < aSelected.size(); i++) { ModuleBase_ViewerPrsPtr aPrs = aSelected[i]; ObjectPtr anObject = aPrs->object(); @@ -228,8 +231,23 @@ void XGUI_FacesPanel::processSelection() myLastItemIndex++; isModified = true; - if (aResultPrs->hasSubShapeVisible(ModuleBase_Tools::getSelectedShape(aPrs)) || - useTransparency()) // redisplay + if (anObjectToShapes.find(anObject) != anObjectToShapes.end()) + anObjectToShapes.at(anObject).Append(ModuleBase_Tools::getSelectedShape(aPrs)); + else { + NCollection_List aListOfShapes; + aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(aPrs)); + anObjectToShapes[anObject] = aListOfShapes; + anObjectToPrs[anObject] = aResultPrs; + } + } + for (std::map >::const_iterator anIt = anObjectToShapes.begin(); + anIt != anObjectToShapes.end(); anIt++) { + ObjectPtr anObject = anIt->first; + if (!anObject.get() || anObjectToPrs.find(anObject) == anObjectToPrs.end()) + continue; + Handle(ModuleBase_ResultPrs) aResultPrs = anObjectToPrs.at(anObject); + + if (aResultPrs->hasSubShapeVisible(anIt->second) || useTransparency()) // redisplay ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent); else { // erase object because it is entirely hidden anObject->setDisplayed(false); @@ -341,6 +359,9 @@ bool XGUI_FacesPanel::hideEmptyObjects() { bool isModified = false; static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); + std::map > anObjectToShapes; + std::map anObjectToPrs; + for (QMap::const_iterator anIt = myItems.begin(); anIt != myItems.end(); anIt++) { ModuleBase_ViewerPrsPtr aPrs = anIt.value(); @@ -353,7 +374,23 @@ bool XGUI_FacesPanel::hideEmptyObjects() if (aResultPrs.IsNull()) continue; - if (!aResultPrs->hasSubShapeVisible(ModuleBase_Tools::getSelectedShape(aPrs))) { + if (anObjectToShapes.find(anObject) != anObjectToShapes.end()) + anObjectToShapes.at(anObject).Append(ModuleBase_Tools::getSelectedShape(aPrs)); + else { + NCollection_List aListOfShapes; + aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(aPrs)); + anObjectToShapes[anObject] = aListOfShapes; + anObjectToPrs[anObject] = aResultPrs; + } + } + for (std::map >::const_iterator anIt = anObjectToShapes.begin(); + anIt != anObjectToShapes.end(); anIt++) { + ObjectPtr anObject = anIt->first; + if (!anObject.get() || anObjectToPrs.find(anObject) == anObjectToPrs.end()) + continue; + Handle(ModuleBase_ResultPrs) aResultPrs = anObjectToPrs.at(anObject); + + if (!aResultPrs->hasSubShapeVisible(anIt->second)) { // erase object because it is entirely hidden anObject->setDisplayed(false); myHiddenObjects.insert(anObject); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 89c21c6cf..7e9b3a97a 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1631,8 +1631,8 @@ bool XGUI_Workshop::prepareForDisplay(const std::set& theObjects) con int anAnswer = QMessageBox::question( desktop(), tr("Show object"), tr("'%1'\n are hidden by %2:\nRemove objects from the panel to be displayed?") - .arg(aHiddenObjectNames.join(',')).arg(facesPanel()->windowTitle(), - QMessageBox::Yes | QMessageBox::No, QMessageBox::No)); + .arg(aHiddenObjectNames.join(',')).arg(facesPanel()->windowTitle()), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); bool aToBeDisplayed = anAnswer == QMessageBox::Yes; if (aToBeDisplayed) -- 2.39.2