From: vsv Date: Mon, 16 Dec 2019 08:51:45 +0000 (+0300) Subject: Issue #3100: Restore state of hidden faces on Hide/Show an object X-Git-Tag: V9_5_0a1~91 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c9c441afb404553dd086fff8adfc9aa6340b13c3;p=modules%2Fshaper.git Issue #3100: Restore state of hidden faces on Hide/Show an object --- diff --git a/src/XGUI/XGUI_FacesPanel.cpp b/src/XGUI/XGUI_FacesPanel.cpp index b9a5f5f41..414986d3a 100644 --- a/src/XGUI/XGUI_FacesPanel.cpp +++ b/src/XGUI/XGUI_FacesPanel.cpp @@ -50,6 +50,7 @@ #include #include #include +#include static const int LayoutMargin = 3; @@ -73,6 +74,18 @@ bool getGroup(ModuleBase_ViewerPrsPtr thePrs, ResultGroupPtr& theResGroup, return theGroupFeature.get() && theResGroup.get(); } +//******************************************************************** +void updateHiddenShapes(Handle(ModuleBase_ResultPrs) thePrs, const TopoDS_ListOfShape& theShapes) +{ + TopoDS_ListOfShape aAlreadyHidden = thePrs->hiddenSubShapes(); + TopoDS_ListOfShape::Iterator aShPIt(theShapes); + for (; aShPIt.More(); aShPIt.Next()) { + if (aAlreadyHidden.Contains(aShPIt.Value())) + aAlreadyHidden.Remove(aShPIt.Value()); + } + thePrs->setSubShapeHidden(aAlreadyHidden); +} + //******************************************************************** XGUI_FacesPanel::XGUI_FacesPanel(QWidget* theParent, XGUI_Workshop* theWorkshop) : QDockWidget(theParent), myIsActive(false), myWorkshop(theWorkshop) @@ -97,6 +110,10 @@ XGUI_FacesPanel::XGUI_FacesPanel(QWidget* theParent, XGUI_Workshop* theWorkshop) myListView->getControl()->setFocusPolicy(Qt::StrongFocus); myListView->getControl()->viewport()->installEventFilter(this); + + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)), + SLOT(onObjectDisplay(ObjectPtr, AISObjectPtr))); } //******************************************************************** @@ -107,7 +124,7 @@ void XGUI_FacesPanel::reset(const bool isToFlushRedisplay) std::map anObjectToShapes; std::map anObjectToPrs; - QMap >::const_iterator aIt; + QMap::const_iterator aIt; for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) { getObjectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs); } @@ -119,7 +136,7 @@ void XGUI_FacesPanel::reset(const bool isToFlushRedisplay) aObjects.insert(aPrsIt->first); aPrsIt->second->setSubShapeHidden(anEmpty); } - std::set >::const_iterator aGrpIt; + std::set::const_iterator aGrpIt; for (aGrpIt = myHiddenGroups.cbegin(); aGrpIt != myHiddenGroups.cend(); aGrpIt++) (*aGrpIt)->setDisplayed(true); myHiddenGroups.clear(); @@ -221,14 +238,9 @@ void XGUI_FacesPanel::restoreObjects(const std::set& theHiddenObjects } // remove from myItes container - for (std::set::const_iterator aToBeRemovedIt = anIndicesToBeRemoved.begin(); - aToBeRemovedIt != anIndicesToBeRemoved.end(); aToBeRemovedIt++) - { - myItems.remove(*aToBeRemovedIt); - } + removeItems(anIndicesToBeRemoved); if (!anIndicesToBeRemoved.empty()) // means that myItems has been changed updateProcessedObjects(myItems, myItemObjects); - myListView->removeItems(anIndicesToBeRemoved); // remove from container of hidden objects for (std::set::const_iterator aHiddenIt = theHiddenObjects.begin(); @@ -331,7 +343,7 @@ void XGUI_FacesPanel::getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs, void XGUI_FacesPanel::processSelection() { QList aSelected = - myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::AllControls); + myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Viewer); if (aSelected.size() == 0) return; @@ -437,12 +449,7 @@ void XGUI_FacesPanel::processSelection() } // Remove duplicate items - if (aToRemove.size() > 0) { - myListView->removeItems(aToRemove); - std::set::const_iterator aIntIt; - for (aIntIt = aToRemove.cbegin(); aIntIt != aToRemove.cend(); aIntIt++) - myItems.remove(*aIntIt); - } + removeItems(aToRemove); if (isModified) { updateProcessedObjects(myItems, myItemObjects); flushRedisplay(); @@ -480,7 +487,7 @@ bool XGUI_FacesPanel::processDelete() ResultGroupPtr aResGroup; FeaturePtr aGroupFeature; if (getGroup((*aIt), aResGroup, aGroupFeature)) { - std::set >::iterator aGrpIt = myHiddenGroups.find(aResGroup); + std::set::iterator aGrpIt = myHiddenGroups.find(aResGroup); if (aGrpIt != myHiddenGroups.end()) { aResGroup->setDisplayed(true); myHiddenGroups.erase(aGrpIt); @@ -511,7 +518,7 @@ bool XGUI_FacesPanel::processDelete() //******************************************************************** bool XGUI_FacesPanel::redisplayObjects( - const std::set >& theObjects) + const std::set& theObjects) { if (theObjects.empty()) return false; @@ -538,24 +545,21 @@ void XGUI_FacesPanel::updateProcessedObjects(QMap for (QMap::const_iterator anIt = theItems.begin(); anIt != theItems.end(); anIt++) { ModuleBase_ViewerPrsPtr aPrs = anIt.value(); - ObjectPtr anObject = aPrs.get() ? aPrs->object() : ObjectPtr(); - if (anObject.get()) { - ResultGroupPtr aResGroup = std::dynamic_pointer_cast(anObject); - if (aResGroup.get()) { - FeaturePtr aGroupFeature = ModelAPI_Feature::feature(aResGroup); - AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list"); - for (int i = 0; i < aSelectionList->size(); i++) { - AttributeSelectionPtr aSelection = aSelectionList->value(i); - ResultPtr aRes = aSelection->context(); - if (theObjects.find(aRes) == theObjects.end()) - theObjects.insert(aRes); - } - } - else { - if (theObjects.find(anObject) == theObjects.end()) - theObjects.insert(anObject); + ResultGroupPtr aResGroup; + FeaturePtr aGroupFeature; + if (getGroup(aPrs, aResGroup, aGroupFeature)) { + AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list"); + for (int i = 0; i < aSelectionList->size(); i++) { + AttributeSelectionPtr aSelection = aSelectionList->value(i); + ResultPtr aRes = aSelection->context(); + if (theObjects.find(aRes) == theObjects.end()) + theObjects.insert(aRes); } } + else { + if (theObjects.find(aPrs->object()) == theObjects.end()) + theObjects.insert(aPrs->object()); + } } } @@ -577,7 +581,7 @@ void XGUI_FacesPanel::onTransparencyChanged() { std::map anObjectToShapes; std::map anObjectToPrs; - QMap >::const_iterator aIt; + QMap::const_iterator aIt; for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) { getObjectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs); } @@ -610,3 +614,96 @@ void XGUI_FacesPanel::flushRedisplay() const anObjectBrowser->updateAllIndexes(); myWorkshop->viewer()->update(); } + + +//******************************************************************** +void XGUI_FacesPanel::onObjectDisplay(ObjectPtr theObject, AISObjectPtr theAIS) +{ + bool aContains = false; + QMap::iterator aIt; + for (aIt = myItems.begin(); aIt != myItems.end(); aIt++) { + ModuleBase_ViewerPrsPtr aPrs = aIt.value(); + if (aPrs->object() == theObject) { + aContains = true; + break; + } + } + if (aContains) { + ResultGroupPtr aResGroup; + FeaturePtr aGroupFeature; + std::map aObjectToShapes; + std::map aObjectToPrs; + std::set aObjects; + std::set aIdsToRem; + + TopoDS_ListOfShape aHideShapes; + std::map::const_iterator aSIt; + for (aIt = myItems.begin(); aIt != myItems.end(); aIt++) { + ModuleBase_ViewerPrsPtr aPrs = aIt.value(); + if (getGroup(aPrs, aResGroup, aGroupFeature)) { + getObjectsMapFromResult(aResGroup, aGroupFeature, aObjectToShapes, aObjectToPrs); + if (aResGroup == theObject) { + // If group is displayed it means that it has to be deleted from the Faces list and all + // corresponded faces have been restored + for (aSIt = aObjectToShapes.begin(); aSIt != aObjectToShapes.end(); aSIt++) { + TopoDS_ListOfShape aShapes = aSIt->second; + Handle(ModuleBase_ResultPrs) aPrs = aObjectToPrs[aSIt->first]; + TopoDS_ListOfShape aAlreadyHidden = aPrs->hiddenSubShapes(); + TopoDS_ListOfShape::Iterator aShPIt(aShapes); + for (; aShPIt.More(); aShPIt.Next()) { + if (aAlreadyHidden.Contains(aShPIt.Value())) + aAlreadyHidden.Remove(aShPIt.Value()); + } + aPrs->setSubShapeHidden(aAlreadyHidden); + aObjects.insert(aSIt->first); + } + aIdsToRem.insert(aIt.key()); + } + else { + std::map::iterator aPIt = aObjectToPrs.find(theObject); + if (aPIt != aObjectToPrs.end()) { + ObjectPtr aObj = aPIt->first; + if (aObj == theObject) { + Handle(ModuleBase_ResultPrs) aPrs = aPIt->second; + TopoDS_ListOfShape aShapes = aObjectToShapes[aObj]; + aHideShapes.Append(aShapes); + aObjects.insert(aObj); + } + } + } + } + else { + if (aPrs->object() == theObject) { + TopoDS_Shape aShape = aPrs->shape()->impl(); + if (!aShape.IsNull()) + aHideShapes.Append(aShape); + aPrs->setInteractive(theAIS->impl()); + } + } + } + double aTransp = transparency(); + if (aHideShapes.Size() > 0) { + Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast( + theAIS->impl()); + if (!aResultPrs.IsNull()) { + aResultPrs->setSubShapeHidden(aHideShapes); + aResultPrs->setHiddenSubShapeTransparency(aTransp); + aObjects.insert(theObject); + } + } + removeItems(aIdsToRem); + myWorkshop->selector()->clearSelection(); + if (redisplayObjects(aObjects)) + QTimer::singleShot(50, this, SLOT(flushRedisplay())); + } +} + +void XGUI_FacesPanel::removeItems(std::set theIds) +{ + if (theIds.empty()) + return; + myListView->removeItems(theIds); + std::set::const_iterator aRIt; + for (aRIt = theIds.begin(); aRIt != theIds.end(); aRIt++) + myItems.remove(*aRIt); +} diff --git a/src/XGUI/XGUI_FacesPanel.h b/src/XGUI/XGUI_FacesPanel.h index 50dfacc5d..fe9f02b17 100644 --- a/src/XGUI/XGUI_FacesPanel.h +++ b/src/XGUI/XGUI_FacesPanel.h @@ -31,6 +31,8 @@ #include #include +#include + #include #include @@ -102,12 +104,12 @@ public: /// Returns true if the object is in internal container of hidden objects by this panel /// \param theObject a checked object /// \return boolean value - bool isObjectHiddenByPanel(const std::shared_ptr& theObject) const + bool isObjectHiddenByPanel(const ObjectPtr& theObject) const { return myHiddenObjects.find(theObject) != myHiddenObjects.end(); } /// Removed faces of the objects from the panel /// \param container of objects - void restoreObjects(const std::set >& theHiddenObjects); + void restoreObjects(const std::set& theHiddenObjects); /// Returns true if the event is processed. The default implementation is empty, returns false. virtual bool processAction(ModuleBase_ActionType theActionType); @@ -126,6 +128,9 @@ public: XGUI_Workshop* workshop() const { return myWorkshop; } +public slots: + /// Slot called on an object erase + void onObjectDisplay(ObjectPtr theObject, AISObjectPtr theAIS); protected: /// Reimplementation to emit a signal about the panel close @@ -143,13 +148,13 @@ private: /// Redisplay objects. /// \param theObjects container of objects /// \return true if some of objects was redisplayed - static bool redisplayObjects(const std::set >& theObjects); + static bool redisplayObjects(const std::set& theObjects); /// Container of objects participating in the panel, it is filled by internal container /// \param theItems container of selected values /// \param theObjects [out] container of objects - static void updateProcessedObjects(QMap > theItems, - std::set >& theObjects); + static void updateProcessedObjects(QMap theItems, + std::set& theObjects); /// Returns maps of shapes and presentations. If object is a body result then it returns /// its ruslts. If it is a group then it returns result of shapes included into the gropup @@ -171,6 +176,8 @@ private: double transparency() const; + void removeItems(std::set theIds); + protected slots: /// Deletes element in list of items void onDeleteItem(); @@ -181,12 +188,12 @@ protected slots: /// Closes faces panel restore all hidden faces by calling reset() void onClosed(); -private: /// Flushes redisplay event and perform update of object browser icons /// (objects might be hidden/shown) void flushRedisplay() const; -protected: +private: + QCheckBox* myHiddenOrTransparent; ///< if checked - transparent, else hidden ModuleBase_ListView* myListView; ///< list control of processed faces XGUI_Workshop* myWorkshop; ///< workshop @@ -195,9 +202,9 @@ protected: int myLastItemIndex; ///< last index to be used in the map of items for the next added item QMap myItems; ///< selected face items - std::set > myItemObjects; ///< cached objects of myItems - std::set > myHiddenObjects; ///< hidden objects - std::set > myHiddenGroups; ///< hidden objects + std::set myItemObjects; ///< cached objects of myItems + std::set myHiddenObjects; ///< hidden objects + std::set myHiddenGroups; ///< hidden objects }; #endif \ No newline at end of file diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 5ed8b4527..56e784cb5 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -866,7 +866,7 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) { if (!theOperation->isHideFacesVisible()) - myFacesPanel->hide(); + myFacesPanel->close(); } }