Salome HOME
Exlude the user input during process events by application (Bug #325).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_OCCDisplayer.cxx
index 9d3e2cf440986c5aa72e19768981dc736f377f0a..3dbe862ccf5f9ab5d9b88fc8a76b5a526482f7dc 100644 (file)
@@ -31,6 +31,8 @@
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <AIS_ListOfInteractive.hxx>
 
+#include <TColStd_SequenceOfInteger.hxx>
+
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
 #include <OCCViewer_ViewWindow.h>
@@ -89,6 +91,7 @@ void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
 
     module()->removeObjectShape( (size_t)aViewer, anObj );
   }
+  aViewer->update();
 }
 
 HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int                             theViewerId,
@@ -99,13 +102,7 @@ HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int
   if ( theContext.IsNull() || theObject.IsNull() )
     return aResShape;
 
-  ObjectKind anObjectKind = theObject->GetKind();
-  if ( anObjectKind != KIND_IMAGE &&
-       anObjectKind != KIND_POLYLINE &&
-       anObjectKind != KIND_IMMERSIBLE_ZONE &&
-       anObjectKind != KIND_REGION &&
-       anObjectKind != KIND_ZONE &&
-       anObjectKind != KIND_OBSTACLE  )
+  if ( !HYDROGUI_Tool::IsObjectHasPresentation( theObject, OCCViewer_Viewer::Type() ) )
     return aResShape;
 
   aResShape = new HYDROGUI_Shape( theContext, theObject );
@@ -127,9 +124,33 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs,
   if( aCtx.IsNull() )
     return;
 
-  for ( int i = 1, n = theObjs.Length(); i <= n; i++ )
-  {
+  // Sort objects by display order ( needed for Z layers assignment only )
+  HYDROData_SequenceOfObjects anObjects;
+  int aMaxIndex = -1;
+  for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) {
     Handle(HYDROData_Entity) anObj = theObjs.Value( i );
+    if ( anObj.IsNull() || anObj->IsRemoved() ) {
+      continue;
+    }
+
+    int aDisplayOrderIndex = module()->getObjectDisplayOrder( (size_t)aViewer, anObj );
+    if ( aDisplayOrderIndex > aMaxIndex ) {
+      anObjects.Append( anObj );
+      aMaxIndex = aDisplayOrderIndex;
+    } else {
+      anObjects.Prepend( anObj );
+    }
+  }
+
+  // Get existing Z layers
+  TColStd_SequenceOfInteger anExistingZLayers;
+  aViewer->getViewer3d()->GetAllZLayers( anExistingZLayers );
+  int aNbLayers = anExistingZLayers.Length();
+
+  // Display
+  for ( int i = 1, n = anObjects.Length(); i <= n; i++ )
+  {
+    Handle(HYDROData_Entity) anObj = anObjects.Value( i );
     if ( anObj.IsNull() || anObj->IsRemoved() )
       continue;
 
@@ -148,6 +169,20 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs,
     {
       bool anIsVisible = module()->isObjectVisible( (size_t)aViewer, anObj );
       anObjShape->setVisible( anIsVisible, false );
+
+      // Set Z layer
+      Standard_Integer aLayerId = -1;
+      if ( i <= aNbLayers ) {
+        aLayerId = anExistingZLayers.Value( i );
+      } else {
+        Standard_Integer aNewId = -1;
+        if ( aViewer->getViewer3d()->AddZLayer( aNewId ) ) {
+          aLayerId = aNewId;
+        }
+      }
+      if ( aLayerId >= 0 ) {
+        aCtx->SetZLayer( anObjShape->getAISShape(), aLayerId );
+      }
     }
   }
 
@@ -194,4 +229,7 @@ void HYDROGUI_OCCDisplayer::purgeObjects( const int theViewerId )
   }
 }
 
-
+QString HYDROGUI_OCCDisplayer::GetType() const
+{
+  return OCCViewer_Viewer::Type();
+}