Salome HOME
Issue #2309 Possibility to hide faces : display hidden objects by panel if it uses...
authornds <nds@opencascade.com>
Thu, 7 Dec 2017 07:02:42 +0000 (10:02 +0300)
committernds <nds@opencascade.com>
Thu, 7 Dec 2017 07:04:24 +0000 (10:04 +0300)
src/ModuleBase/ModuleBase_ResultPrs.cpp
src/XGUI/XGUI_FacesPanel.cpp
src/XGUI/XGUI_FacesPanel.h

index 63a571ca7e25a2c4671a8e402cb6cb8b49170688..ad9ca2febdeae5b830ca78d4ee4c119f4215015a 100755 (executable)
@@ -207,6 +207,7 @@ void ModuleBase_ResultPrs::Compute(
   if (myTransparency < 1 && !myHiddenSubShapes.IsEmpty())
   {
     StdPrs_ShadedShape::Add (thePresentation, myHiddenCompound, myHiddenSubShapesDrawer);
+    aReadyToDisplay = true;
   }
 
   if (!aReadyToDisplay) {
index 55b0c17864d4bde8a87ac716025f2ba246ceb633..565f611f5d55505b3ca7925698eec16285a0ea3c 100644 (file)
@@ -207,7 +207,8 @@ void XGUI_FacesPanel::processSelection()
     myLastItemIndex++;
     isModified = true;
 
-    if (aResultPrs->hasSubShapeVisible(ModuleBase_Tools::getSelectedShape(aPrs))) // redisplay
+    if (aResultPrs->hasSubShapeVisible(ModuleBase_Tools::getSelectedShape(aPrs)) ||
+        useTransparency()) // redisplay
       ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent);
     else { // erase object because it is entirely hidden
       anObject->setDisplayed(false);
@@ -312,6 +313,33 @@ bool XGUI_FacesPanel::displayHiddenObjects(
   return isModified;
 }
 
+//********************************************************************
+bool XGUI_FacesPanel::hideEmptyObjects()
+{
+  bool isModified = false;
+  static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  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 (!aResultPrs->hasSubShapeVisible(ModuleBase_Tools::getSelectedShape(aPrs))) {
+      // 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,
@@ -426,7 +454,15 @@ void XGUI_FacesPanel::onDeleteItem()
 //********************************************************************
 void XGUI_FacesPanel::onTransparencyChanged()
 {
-  bool isModified = redisplayObjects(myItemObjects, false);
+  bool isModified = false;
+  if (useTransparency()) {
+    std::set<std::shared_ptr<ModelAPI_Object> > aHiddenObjects = myHiddenObjects;
+    isModified = displayHiddenObjects(aHiddenObjects, false);
+  }
+  else
+    isModified = hideEmptyObjects();
+
+  isModified = redisplayObjects(myItemObjects, false) || isModified;
   if (isModified)
     Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
 
index 1679bdc3e7daaeec338d7f0719525e51c97abe1b..8b5d71a6b4b24f2367b448bcb548e6e6b33ba755 100644 (file)
@@ -158,6 +158,10 @@ private:
   bool displayHiddenObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects,
                             const bool isToFlushRedisplay);
 
+  /// Iterates by items and hide objects where all sub-shapes are hidden
+  /// \return true if some of objects was redisplayed
+  bool hideEmptyObjects();
+
   /// 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