+
+//=======================================================================
+//function : ChangeZLayer
+//purpose :
+//=======================================================================
+
+void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
+ const Standard_Integer theLayerId)
+{
+ if (!myLayerIds.Contains (theLayerId))
+ return;
+
+ // change display layer for structure in all views
+ if (MyDisplayedStructure.Contains (theStructure))
+ {
+ Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
+ for ( ; aViewIt.More (); aViewIt.Next ())
+ (aViewIt.Value ())->ChangeZLayer (theStructure, theLayerId);
+ }
+
+ // tell graphic driver to update the structure's display layer
+ MyGraphicDriver->ChangeZLayer (
+ (*(Graphic3d_CStructure*)theStructure->CStructure ()), theLayerId);
+}
+
+//=======================================================================
+//function : GetZLayer
+//purpose :
+//=======================================================================
+
+Standard_Integer Visual3d_ViewManager::GetZLayer (const Handle(Graphic3d_Structure)& theStructure) const
+{
+ Graphic3d_CStructure& aStructure =
+ (*(Graphic3d_CStructure*)theStructure->CStructure ());
+
+ return MyGraphicDriver->GetZLayer (aStructure);
+}
+
+//=======================================================================
+//function : AddZLayer
+//purpose :
+//=======================================================================
+
+Standard_Boolean Visual3d_ViewManager::AddZLayer (Standard_Integer& theLayerId)
+{
+ try
+ {
+ OCC_CATCH_SIGNALS
+ theLayerId = getZLayerGenId ().Next ();
+ myLayerIds.Add (theLayerId);
+ myLayerSeq.Append (theLayerId);
+ }
+ catch (Aspect_IdentDefinitionError)
+ {
+ // new index can't be generated
+ return Standard_False;
+ }
+
+ // tell all managed views to remove display layers
+ Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
+ for ( ; aViewIt.More (); aViewIt.Next ())
+ (aViewIt.Value ())->AddZLayer (theLayerId);
+
+ return Standard_True;
+}
+
+//=======================================================================
+//function : RemoveZLayer
+//purpose :
+//=======================================================================
+
+Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Standard_Integer theLayerId)
+{
+ if (!myLayerIds.Contains (theLayerId) || theLayerId == 0)
+ return Standard_False;
+
+ // tell all managed views to remove display layers
+ Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
+ for ( ; aViewIt.More (); aViewIt.Next ())
+ (aViewIt.Value ())->RemoveZLayer (theLayerId);
+
+ MyGraphicDriver->UnsetZLayer (theLayerId);
+
+ // remove index
+ for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
+ if (myLayerSeq(aIdx) == theLayerId)
+ {
+ myLayerSeq.Remove (aIdx);
+ break;
+ }
+
+ myLayerIds.Remove (theLayerId);
+ getZLayerGenId ().Free (theLayerId);
+
+ return Standard_True;
+}
+
+//=======================================================================
+//function : GetAllZLayers
+//purpose :
+//=======================================================================
+
+void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
+{
+ theLayerSeq.Assign (myLayerSeq);
+}
+
+//=======================================================================
+//function : getZLayerGenId
+//purpose :
+//=======================================================================
+
+Aspect_GenId& Visual3d_ViewManager::getZLayerGenId ()
+{
+ static Aspect_GenId aGenId (1, IntegerLast());
+ return aGenId;
+}
+
+//=======================================================================
+//function : InstallZLayers
+//purpose :
+//=======================================================================
+
+void Visual3d_ViewManager::InstallZLayers(const Handle(Visual3d_View)& theView) const
+{
+ if (!MyDefinedView.Contains (theView))
+ return;
+
+ // erase and insert layers iteratively to provide the same layer order as
+ // in the view manager's sequence. This approach bases on the layer insertion
+ // order: the new layers are always appended to the end of the list
+ // inside of view, while layer remove operation doesn't affect the order.
+ // Starting from second layer : no need to change the default z layer.
+ for (Standard_Integer aSeqIdx = 2; aSeqIdx <= myLayerSeq.Length (); aSeqIdx++)
+ {
+ Standard_Integer aLayerID = myLayerSeq.Value (aSeqIdx);
+ theView->RemoveZLayer (aLayerID);
+ theView->AddZLayer (aLayerID);
+ }
+}