X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_FacesPanel.cpp;h=ced3592a2b541c1a3aaa475149f27a79b295bf70;hb=4de8d53fef7532b6843d79c970f55ad46f98da62;hp=28a35884cae02eeadc21c594ddc2d29d952ee136;hpb=f1fc33a9e4acec558eb5b5802a6fce5e6ad724f6;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_FacesPanel.cpp b/src/XGUI/XGUI_FacesPanel.cpp index 28a35884c..ced3592a2 100644 --- a/src/XGUI/XGUI_FacesPanel.cpp +++ b/src/XGUI/XGUI_FacesPanel.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2024 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -42,24 +42,71 @@ #include #include -#include #include +#include +#include +#include + #include #include #include #include #include #include +#include + +#ifdef WIN32 +#pragma warning(disable : 4189) // for skipping MAYBE_UNUSED on Win +#endif static const int LayoutMargin = 3; +//******************************************************************** +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); +} + +//******************************************************************** +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 { + TopoDS_ListOfShape aListOfShapes; + aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(thePrs)); + theObjectToShapes[anObject] = aListOfShapes; + theObjectToPrs[anObject] = aResultPrs; + } +} + //******************************************************************** XGUI_FacesPanel::XGUI_FacesPanel(QWidget* theParent, XGUI_Workshop* theWorkshop) - : QDockWidget(theParent), myIsActive(false), myWorkshop(theWorkshop) + : QDockWidget(theParent), myWorkshop(theWorkshop), myIsActive(false), myLastItemIndex(0) { setWindowTitle(tr("Hide Faces")); - QAction* aViewAct = toggleViewAction(); + setObjectName("Hide Faces"); + + MAYBE_UNUSED QAction* aViewAct = toggleViewAction(); setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }"); QWidget* aContent = new QWidget(this); @@ -78,6 +125,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))); } //******************************************************************** @@ -88,9 +139,9 @@ 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); + objectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs); } std::set aObjects; @@ -100,10 +151,6 @@ void XGUI_FacesPanel::reset(const bool isToFlushRedisplay) aObjects.insert(aPrsIt->first); aPrsIt->second->setSubShapeHidden(anEmpty); } - std::set >::const_iterator aGrpIt; - for (aGrpIt = myHiddenGroups.cbegin(); aGrpIt != myHiddenGroups.cend(); aGrpIt++) - (*aGrpIt)->setDisplayed(true); - myHiddenGroups.clear(); if (redisplayObjects(aObjects)) flushRedisplay(); @@ -169,8 +216,10 @@ void XGUI_FacesPanel::setActivePanel(const bool theIsActive) // the selection is cleared by activating selection control myWorkshop->selector()->clearSelection(); } - else + else{ emit deactivated(); + myUndoList.clear(); + } } //******************************************************************** @@ -202,14 +251,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(); @@ -238,60 +282,6 @@ bool XGUI_FacesPanel::processAction(ModuleBase_ActionType theActionType) } } -//******************************************************************** -void XGUI_FacesPanel::getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs, - 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; - } - } - } - } - } - 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; - } - } -} //******************************************************************** void XGUI_FacesPanel::processSelection() @@ -315,46 +305,25 @@ 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; - } - } - else { - GeomShapePtr aShapePtr = aPrs->shape(); - if (!aShapePtr.get() || !aShapePtr->isFace()) - continue; - } + GeomShapePtr aShapePtr = aPrs->shape(); + if (!aShapePtr.get() || !aShapePtr->isFace()) + continue; - QString aItemName = aResGroup.get()? - aResGroup->data()->name().c_str() : XGUI_Tools::generateName(aPrs); + QString aItemName = XGUI_Tools::generateName(aPrs); if (myListView->hasItem(aItemName)) continue; - getObjectsMapFromPrs(aPrs, anObjectToShapes, anObjectToPrs); - if (aResGroup.get() && aResGroup->isDisplayed()) { - aResGroup->setDisplayed(false); - myHiddenGroups.insert(aResGroup); - } + 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 QMap::const_iterator aIt; for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) { - ModuleBase_ViewerPrsPtr aPrs = aIt.value(); - ObjectPtr aObject = aPrs->object(); - ResultGroupPtr aResGroup = std::dynamic_pointer_cast(aObject); - if (aResGroup.get()) - continue; + ModuleBase_ViewerPrsPtr aCurPrs = aIt.value(); + ObjectPtr aObject = aCurPrs->object(); if (anObjectToShapes.find(aObject) != anObjectToShapes.end()) { TopoDS_ListOfShape aShapes = anObjectToShapes[aObject]; - GeomShapePtr aShapePtr = aPrs->shape(); + GeomShapePtr aShapePtr = aCurPrs->shape(); if (aShapes.Contains(aShapePtr->impl())) { aToRemove.insert(aIt.key()); } @@ -363,6 +332,8 @@ void XGUI_FacesPanel::processSelection() myItems.insert(myLastItemIndex, aPrs); myListView->addItem(aItemName, myLastItemIndex); + // add in undo list + myUndoList.push_back(myLastItemIndex); myLastItemIndex++; isModified = true; } @@ -401,12 +372,8 @@ 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); + myWorkshop->selector()->clearSelection(); if (isModified) { updateProcessedObjects(myItems, myItemObjects); flushRedisplay(); @@ -417,14 +384,13 @@ void XGUI_FacesPanel::processSelection() bool XGUI_FacesPanel::processDelete() { //appendFirstSelectionInHistory(); - QModelIndexList anIndices = myListView->getControl()->selectionModel()->selectedIndexes(); + //QModelIndexList anIndices = myListView->getControl()->selectionModel()->selectedIndexes(); std::set aSelectedIds; myListView->getSelectedIndices(aSelectedIds); if (aSelectedIds.empty()) return false; - bool isModified = false; std::set aRestored; std::set::const_iterator anIt; for (anIt = aSelectedIds.begin(); anIt != aSelectedIds.end(); anIt++) { @@ -432,7 +398,6 @@ bool XGUI_FacesPanel::processDelete() if (aRestored.find(aPrs) == aRestored.end()) { aRestored.insert(aPrs); myItems.remove(*anIt); - isModified = true; } } std::map anObjectToShapes; @@ -440,15 +405,7 @@ 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()) { - std::set >::iterator aGrpIt = myHiddenGroups.find(aResGroup); - if (aGrpIt != myHiddenGroups.end()) { - aResGroup->setDisplayed(true); - myHiddenGroups.erase(aGrpIt); - } - } + objectsMapFromPrs((*aIt), anObjectToShapes, anObjectToPrs); } std::set aRestoredObjects; @@ -474,7 +431,7 @@ bool XGUI_FacesPanel::processDelete() //******************************************************************** bool XGUI_FacesPanel::redisplayObjects( - const std::set >& theObjects) + const std::set& theObjects) { if (theObjects.empty()) return false; @@ -501,24 +458,8 @@ 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); - } - } + if (theObjects.find(aPrs->object()) == theObjects.end()) + theObjects.insert(aPrs->object()); } } @@ -529,13 +470,6 @@ void XGUI_FacesPanel::closeEvent(QCloseEvent* theEvent) emit closed(); } -//******************************************************************** -bool XGUI_FacesPanel::customizeObject(const ObjectPtr& theObject, - const AISObjectPtr& thePresentation) -{ - return myItems.size() > 0; -} - //******************************************************************** void XGUI_FacesPanel::onDeleteItem() { @@ -547,9 +481,9 @@ 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); + objectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs); } double aTransp = Config_PropManager::real("Visualization", "hidden_face_transparency"); @@ -570,6 +504,18 @@ void XGUI_FacesPanel::onClosed() reset(true); } +//******************************************************************** + +void XGUI_FacesPanel::processUndo() +{ + if(!myUndoList.size()) + return; + + myListView->selectIndices({myUndoList.back()}); + processDelete(); + myUndoList.pop_back(); +} + //******************************************************************** void XGUI_FacesPanel::flushRedisplay() const { @@ -580,3 +526,60 @@ 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) { + 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 (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); +}