-// 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
//
// 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<mailto: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 <ModuleBase_IModule.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IViewer.h>
+#include <ModuleBase_ListView.h>
+#include <ModuleBase_ResultPrs.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_SelectionFilterType.h>
#include <Config_PropManager.h>
#include <Events_Loop.h>
#include <ModelAPI_Events.h>
-#include <ModuleBase_ISelection.h>
-#include "ModuleBase_IWorkshop.h"
-#include "ModuleBase_ListView.h"
-#include "ModuleBase_ResultPrs.h"
-#include "ModuleBase_Tools.h"
-#include "ModuleBase_ViewerPrs.h"
-
-#include "XGUI_Tools.h"
-#include "XGUI_Workshop.h"
-
#include <QAction>
#include <QCheckBox>
#include <QFocusEvent>
//********************************************************************
void XGUI_FacesPanel::reset(const bool isToFlushRedisplay)
{
+ if (myLastItemIndex == 0) // do nothing because there was no activity in the pane after reset
+ return;
+
// clear internal containers
myListView->getControl()->clear();
myItems.clear();
// restore previous view of presentations
- bool isModified = redisplayObjects(myItemObjects, false);
- isModified = displayHiddenObjects(myHiddenObjects, false) || isModified;
- if (isModified && isToFlushRedisplay)
- Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ bool isModified = redisplayObjects(myItemObjects);
+ std::set<std::shared_ptr<ModelAPI_Object> > aHiddenObjects = myHiddenObjects;
+ isModified = displayHiddenObjects(aHiddenObjects, myHiddenObjects) || isModified;
+ if (isModified)// && isToFlushRedisplay) // flush signal immediatelly until container is filled
+ 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)
+{
+ theModes.append(TopAbs_FACE);
+}
+
+//********************************************************************
+void XGUI_FacesPanel::selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters)
+{
+ ModuleBase_IModule* aModule = myWorkshop->module();
+ QIntList aModuleSelectionFilters = myWorkshop->module()->selectionFilters();
+
+ theSelectionFilters.Append(aModule->selectionFilter(SF_GlobalFilter));
+ theSelectionFilters.Append(aModule->selectionFilter(SF_FilterInfinite));
+ theSelectionFilters.Append(aModule->selectionFilter(SF_ResultGroupNameFilter));
+}
+
//********************************************************************
bool XGUI_FacesPanel::eventFilter(QObject* theObject, QEvent *theEvent)
{
ModuleBase_Tools::setShadowEffect(myListView->getControl(), theIsActive);
myIsActive = theIsActive;
- if (myIsActive)
- {
+ if (myIsActive) {
emit activated();
- // selection should be activated after emit signal, that deactivates current widget(selection)
- activateSelection(theIsActive);
+ // selection should be cleared after emit of signal to do not process selection change
+ // event by the previous selector
+ // the selection is cleared by activating selection control
+ XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
}
else
- {
- // selection should be activated after emit signal, that deactivates current widget(selection)
- activateSelection(theIsActive);
emit deactivated();
- }
}
//********************************************************************
ModuleBase_ISelection::Viewer);
bool isModified = false;
static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+
+ std::map<ObjectPtr, NCollection_List<TopoDS_Shape> > anObjectToShapes;
+ std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
for (int i = 0; i < aSelected.size(); i++) {
ModuleBase_ViewerPrsPtr aPrs = aSelected[i];
ObjectPtr anObject = aPrs->object();
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))) // 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<TopoDS_Shape> aListOfShapes;
+ aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(aPrs));
+ anObjectToShapes[anObject] = aListOfShapes;
+ anObjectToPrs[anObject] = aResultPrs;
+ }
+ }
+ for (std::map<ObjectPtr, NCollection_List<TopoDS_Shape> >::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();
}
//********************************************************************
isModified = true;
}
if (isModified) {
- bool isRedisplayed = redisplayObjects(aRestoredObjects, false);
- isRedisplayed = displayHiddenObjects(aRestoredObjects, false) || isRedisplayed;
- if (isRedisplayed)
- Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ bool isRedisplayed = redisplayObjects(aRestoredObjects);
+ isRedisplayed = displayHiddenObjects(aRestoredObjects, myHiddenObjects)
+ || isRedisplayed;
+ if (isRedisplayed) {
+ flushRedisplay();
+ myWorkshop->viewer()->update();
+ }
// should be after flush of redisplay to have items object to be updated
updateProcessedObjects(myItems, myItemObjects);
+
}
myListView->removeSelectedItems();
//********************************************************************
bool XGUI_FacesPanel::redisplayObjects(
- const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects,
- const bool isToFlushRedisplay)
+ const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects)
{
if (theObjects.empty())
return false;
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<std::shared_ptr<ModelAPI_Object> >& theObjects,
- const bool isToFlushRedisplay)
+ std::set<std::shared_ptr<ModelAPI_Object> >& theHiddenObjects)
{
if (theObjects.empty())
return false;
{
ObjectPtr anObject = *anIt;
// if the object was hidden by this panel
- if (anObject->isDisplayed() || myHiddenObjects.find(anObject) == myHiddenObjects.end())
+ if (anObject->isDisplayed() || theHiddenObjects.find(anObject) == theHiddenObjects.end())
continue;
- myHiddenObjects.erase(anObject);
+ theHiddenObjects.erase(anObject);
anObject->setDisplayed(true); // it means that the object is hidden by hide all faces
ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent);
isModified = true;
}
-
- if (isModified && isToFlushRedisplay)
- Events_Loop::loop()->flush(aDispEvent);
return isModified;
}
+//********************************************************************
+bool XGUI_FacesPanel::hideEmptyObjects()
+{
+ bool isModified = false;
+ static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ std::map<ObjectPtr, NCollection_List<TopoDS_Shape> > anObjectToShapes;
+ std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
+
+ for (QMap<int, ModuleBase_ViewerPrsPtr>::const_iterator anIt = myItems.begin();
+ anIt != myItems.end(); anIt++) {
+ ModuleBase_ViewerPrsPtr aPrs = anIt.value();
+ ObjectPtr anObject = aPrs->object();
+ if (!anObject.get() || !anObject->isDisplayed())
+ continue;
+
+ Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(
+ aPrs->interactive());
+ if (aResultPrs.IsNull())
+ continue;
+
+ if (anObjectToShapes.find(anObject) != anObjectToShapes.end())
+ anObjectToShapes.at(anObject).Append(ModuleBase_Tools::getSelectedShape(aPrs));
+ else {
+ NCollection_List<TopoDS_Shape> aListOfShapes;
+ aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(aPrs));
+ anObjectToShapes[anObject] = aListOfShapes;
+ anObjectToPrs[anObject] = aResultPrs;
+ }
+ }
+ for (std::map<ObjectPtr, NCollection_List<TopoDS_Shape> >::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);
+ ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent);
+ isModified = true;
+ }
+ }
+ return isModified;
+}
//********************************************************************
void XGUI_FacesPanel::updateProcessedObjects(QMap<int, ModuleBase_ViewerPrsPtr> theItems,
emit closed();
}
-//********************************************************************
-void XGUI_FacesPanel::activateSelection(bool toActivate)
-{
- QIntList aShapeTypes;
- aShapeTypes.append(TopAbs_FACE);
-
- if (toActivate) {
- myWorkshop->activateSubShapesSelection(aShapeTypes);
- } else {
- myWorkshop->deactivateSubShapesSelection();
- }
- if (toActivate)
- activateSelectionFilters();
- else
- deactivateSelectionFilters();
-}
-
-//********************************************************************
-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<ModelAPI_Result>(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)
//********************************************************************
void XGUI_FacesPanel::onTransparencyChanged()
{
- bool isModified = redisplayObjects(myItemObjects, false);
- if (isModified)
- Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ bool isModified = false;
+ if (useTransparency()) {
+ std::set<std::shared_ptr<ModelAPI_Object> > aHiddenObjects = myHiddenObjects;
+ isModified = displayHiddenObjects(aHiddenObjects, myHiddenObjects);
+ }
+ else
+ isModified = hideEmptyObjects();
+ isModified = redisplayObjects(myItemObjects) || isModified;
+ if (isModified)
+ flushRedisplay();
}
//********************************************************************
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();
+}