X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_FacesPanel.cpp;h=d92ae5669053b9799e40617da2307bf3e1d137fb;hb=f421ab3932a5e09ae8082215c3eaaa8cc4944e02;hp=dcdeaa5972c62cb9009fb17e64b14d8a21e383bf;hpb=2da45598a74d685cd9e59c3857b618fc25f1dd1a;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_FacesPanel.cpp b/src/XGUI/XGUI_FacesPanel.cpp index dcdeaa597..d92ae5669 100644 --- a/src/XGUI/XGUI_FacesPanel.cpp +++ b/src/XGUI/XGUI_FacesPanel.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,13 +12,26 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "XGUI_FacesPanel.h" +#include "XGUI_ObjectsBrowser.h" +#include "XGUI_SelectionMgr.h" +#include "XGUI_Tools.h" +#include "XGUI_Workshop.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -26,19 +39,6 @@ #include -#include -#include -#include "ModuleBase_IWorkshop.h" -#include "ModuleBase_ListView.h" -#include "ModuleBase_ResultPrs.h" -#include "ModuleBase_Tools.h" -#include "ModuleBase_ViewerPrs.h" - -#include "XGUI_SelectionMgr.h" -#include "XGUI_SelectionFilterType.h" -#include "XGUI_Tools.h" -#include "XGUI_Workshop.h" - #include #include #include @@ -85,17 +85,23 @@ void XGUI_FacesPanel::reset(const bool isToFlushRedisplay) myItems.clear(); // restore previous view of presentations - bool isModified = redisplayObjects(myItemObjects, false); + bool isModified = redisplayObjects(myItemObjects); std::set > aHiddenObjects = myHiddenObjects; - isModified = displayHiddenObjects(aHiddenObjects, myHiddenObjects, false) || isModified; + isModified = displayHiddenObjects(aHiddenObjects, myHiddenObjects) || isModified; if (isModified)// && isToFlushRedisplay) // flush signal immediatelly until container is filled - Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); + flushRedisplay(); updateProcessedObjects(myItems, myItemObjects); myHiddenObjects.clear(); myLastItemIndex = 0; // it should be after redisplay as flag used in customize } +//******************************************************************** +bool XGUI_FacesPanel::isEmpty() const +{ + return myItems.size() == 0; +} + //******************************************************************** void XGUI_FacesPanel::selectionModes(QIntList& theModes) { @@ -210,6 +216,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(); @@ -222,26 +231,43 @@ void XGUI_FacesPanel::processSelection() aPrs->interactive()); if (aResultPrs.IsNull()) continue; + QString aItemName = XGUI_Tools::generateName(aPrs); + if (myListView->hasItem(aItemName)) + return; myItems.insert(myLastItemIndex, aPrs); - myListView->addItem(generateName(aPrs), myLastItemIndex); + myListView->addItem(aItemName, myLastItemIndex); myLastItemIndex++; isModified = true; - if (aResultPrs->hasSubShapeVisible(ModuleBase_Tools::getSelectedShape(aPrs)) || - useTransparency()) // redisplay - ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent); - else { // erase object because it is entirely hidden + 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)) { // redisplay + // erase object because it is entirely hidden anObject->setDisplayed(false); myHiddenObjects.insert(anObject); - ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent); } + ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent); } - if (isModified) - { + if (isModified) { updateProcessedObjects(myItems, myItemObjects); - Events_Loop::loop()->flush(aDispEvent); + flushRedisplay(); } + onTransparencyChanged(); } //******************************************************************** @@ -266,13 +292,16 @@ bool XGUI_FacesPanel::processDelete() isModified = true; } if (isModified) { - bool isRedisplayed = redisplayObjects(aRestoredObjects, false); - isRedisplayed = displayHiddenObjects(aRestoredObjects, myHiddenObjects, false) + bool isRedisplayed = redisplayObjects(aRestoredObjects); + isRedisplayed = displayHiddenObjects(aRestoredObjects, myHiddenObjects) || isRedisplayed; - if (isRedisplayed) - Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); + if (isRedisplayed) { + flushRedisplay(); + myWorkshop->viewer()->update(); + } // should be after flush of redisplay to have items object to be updated updateProcessedObjects(myItems, myItemObjects); + } myListView->removeSelectedItems(); @@ -284,8 +313,7 @@ bool XGUI_FacesPanel::processDelete() //******************************************************************** bool XGUI_FacesPanel::redisplayObjects( - const std::set >& theObjects, - const bool isToFlushRedisplay) + const std::set >& theObjects) { if (theObjects.empty()) return false; @@ -301,16 +329,13 @@ bool XGUI_FacesPanel::redisplayObjects( ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent); isModified = true; } - if (isModified && isToFlushRedisplay) - Events_Loop::loop()->flush(aDispEvent); return isModified; } //******************************************************************** bool XGUI_FacesPanel::displayHiddenObjects( const std::set >& theObjects, - std::set >& theHiddenObjects, - const bool isToFlushRedisplay) + std::set >& theHiddenObjects) { if (theObjects.empty()) return false; @@ -330,9 +355,6 @@ bool XGUI_FacesPanel::displayHiddenObjects( ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent); isModified = true; } - - if (isModified && isToFlushRedisplay) - Events_Loop::loop()->flush(aDispEvent); return isModified; } @@ -341,6 +363,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 +378,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); @@ -386,31 +427,6 @@ void XGUI_FacesPanel::closeEvent(QCloseEvent* theEvent) emit closed(); } -//******************************************************************** -QString XGUI_FacesPanel::generateName(const ModuleBase_ViewerPrsPtr& thePrs) -{ - if (!thePrs.get() || !thePrs->object().get()) - return "Undefined"; - - GeomShapePtr aContext; - ObjectPtr anObject = thePrs->object(); - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get()) - aContext = aResult->shape(); - else { - // TODO if there is this case - } - - QString aName = anObject->data()->name().c_str(); - if (aContext.get()) { - GeomShapePtr aSubShape(new GeomAPI_Shape()); - aSubShape->setImpl(new TopoDS_Shape(ModuleBase_Tools::getSelectedShape(thePrs))); - if (!aSubShape->isEqual(aContext)) - aName += QString("_%1").arg(GeomAlgoAPI_CompoundBuilder::id(aContext, aSubShape)); - } - return aName; -} - //******************************************************************** bool XGUI_FacesPanel::customizeObject(const ObjectPtr& theObject, const AISObjectPtr& thePresentation) @@ -463,15 +479,14 @@ void XGUI_FacesPanel::onTransparencyChanged() bool isModified = false; if (useTransparency()) { std::set > aHiddenObjects = myHiddenObjects; - isModified = displayHiddenObjects(aHiddenObjects, myHiddenObjects, false); + isModified = displayHiddenObjects(aHiddenObjects, myHiddenObjects); } else isModified = hideEmptyObjects(); - isModified = redisplayObjects(myItemObjects, false) || isModified; + isModified = redisplayObjects(myItemObjects) || isModified; if (isModified) - Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); - + flushRedisplay(); } //******************************************************************** @@ -480,3 +495,13 @@ void XGUI_FacesPanel::onClosed() setActivePanel(false); reset(true); } + +//******************************************************************** +void XGUI_FacesPanel::flushRedisplay() const +{ + Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); + // Necessary for update visibility icons in ObjectBrowser + XGUI_ObjectsBrowser* anObjectBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser(); + if (anObjectBrowser) + anObjectBrowser->updateAllIndexes(); +}