Salome HOME
#refs 327 - Polyline is not shown during creation
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_OCCDisplayer.cxx
index b2316376c5af6c293bea39822b9b586cc0a92b2e..64ef551a60a040790e96827bb0cdf8c31a4715ab 100644 (file)
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_Shape.h"
+#include "HYDROGUI_Operation.h"
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <AIS_ListOfInteractive.hxx>
 
+#include <TColStd_SequenceOfInteger.hxx>
+
+#include <LightApp_Application.h>
+#include <SUIT_Study.h>
+
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
 #include <OCCViewer_ViewWindow.h>
@@ -65,6 +71,39 @@ void HYDROGUI_OCCDisplayer::SetToUpdate( const HYDROData_SequenceOfObjects& theO
   }
 }
 
+int HYDROGUI_OCCDisplayer::AddTopZLayer( OCCViewer_ViewManager* theMgr )
+{
+  int aLayer = -1;
+  OCCViewer_Viewer* aViewer = theMgr->getOCCViewer();
+  if ( !aViewer )
+    return aLayer;
+
+  Standard_Integer aNewId = -1;
+  if ( aViewer->getViewer3d()->AddZLayer( aNewId ) )
+    aLayer = aNewId;
+
+  return aLayer;
+}
+
+void HYDROGUI_OCCDisplayer::RemoveZLayer( OCCViewer_ViewManager* theMgr,
+                                          const int theLayer )
+{
+  if ( theLayer < 0 )
+    return;
+
+  OCCViewer_Viewer* aViewer = theMgr->getOCCViewer();
+  if ( !aViewer )
+    return;
+
+  // Get existing Z layers
+  TColStd_SequenceOfInteger anExistingZLayers;
+  aViewer->getViewer3d()->GetAllZLayers( anExistingZLayers );
+  int aNbLayers = anExistingZLayers.Length();
+  
+  if ( theLayer < aNbLayers )
+    aViewer->getViewer3d()->RemoveZLayer( theLayer );
+}
+
 void HYDROGUI_OCCDisplayer::EraseAll( const int theViewerId )
 {
   OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId );
@@ -100,16 +139,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_POLYLINEXY &&
-       anObjectKind != KIND_IMMERSIBLE_ZONE &&
-       anObjectKind != KIND_REGION &&
-       anObjectKind != KIND_ZONE &&
-       anObjectKind != KIND_OBSTACLE &&
-       anObjectKind != KIND_PROFILE &&
-       anObjectKind != KIND_STREAM &&
-       anObjectKind != KIND_CHANNEL )
+  if ( !HYDROGUI_Tool::IsObjectHasPresentation( theObject, OCCViewer_Viewer::Type() ) )
     return aResShape;
 
   aResShape = new HYDROGUI_Shape( theContext, theObject );
@@ -131,9 +161,34 @@ 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
+  int i = 1;
+  for ( int n = anObjects.Length(); i <= n; i++ )
+  {
+    Handle(HYDROData_Entity) anObj = anObjects.Value( i );
     if ( anObj.IsNull() || anObj->IsRemoved() )
       continue;
 
@@ -152,7 +207,37 @@ 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 );
+      }
+    }
+  }
+  // update Z layer of the active operation
+  HYDROGUI_Module* aModule = module();
+  SUIT_Operation* anOp = aModule->activeOperation();
+  HYDROGUI_Operation* aHOp = anOp ? dynamic_cast<HYDROGUI_Operation*>( anOp ) : 0;
+  if ( aHOp && aHOp->getPreviewZLayer() >= 0 ) {
+    Standard_Integer aLayerId = -1;
+    if ( i <= aNbLayers )
+      aLayerId = anExistingZLayers.Value( i );
+    else {
+      Standard_Integer aNewId = -1;
+      if ( aViewer->getViewer3d()->AddZLayer( aNewId ) ) {
+        aLayerId = aNewId;
+      }
     }
+    aHOp->updatePreviewZLayer( aLayerId );
   }
 
   if ( theDoFitAll )
@@ -169,6 +254,10 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs,
       }
     }
   }
+  else if ( aCtx.IsNull() )
+  {
+    aCtx->UpdateSelected();
+  }
 }
 
 void HYDROGUI_OCCDisplayer::purgeObjects( const int theViewerId )