From 59f45b7cefdfbbe8442fe35113530c3c0d21d2b6 Mon Sep 17 00:00:00 2001 From: kgv Date: Tue, 6 Mar 2012 15:03:34 +0400 Subject: [PATCH] 0022795: Make possible to display some presentable objects in overlay of others, groupped by display priority --- src/AIS/AIS_InteractiveContext.cdl | 20 ++ src/AIS/AIS_InteractiveContext.cxx | 51 ++++ src/AIS/AIS_LocalContext.cdl | 20 ++ src/AIS/AIS_LocalContext.cxx | 32 ++- src/Graphic3d/Graphic3d_GraphicDriver.cdl | 46 ++++ src/Graphic3d/Graphic3d_Structure.cdl | 13 + src/Graphic3d/Graphic3d_Structure.cxx | 24 ++ src/Graphic3d/Graphic3d_StructureManager.cdl | 38 +++ src/OpenGl/FILES | 4 +- src/OpenGl/OpenGl_GraphicDriver.hxx | 41 ++++ src/OpenGl/OpenGl_GraphicDriver_4.cxx | 71 ++++++ src/OpenGl/OpenGl_GraphicDriver_7.cxx | 26 ++ src/OpenGl/OpenGl_LayerList.cxx | 243 +++++++++++++++++++ src/OpenGl/OpenGl_LayerList.hxx | 85 +++++++ src/OpenGl/OpenGl_PriorityList.cxx | 41 +++- src/OpenGl/OpenGl_PriorityList.hxx | 15 +- src/OpenGl/OpenGl_Structure.cxx | 23 +- src/OpenGl/OpenGl_Structure.hxx | 9 +- src/OpenGl/OpenGl_View.hxx | 28 ++- src/OpenGl/OpenGl_View_2.cxx | 61 ++++- src/PrsMgr/PrsMgr_PresentableObject.cdl | 16 +- src/PrsMgr/PrsMgr_PresentableObject.cxx | 25 ++ src/PrsMgr/PrsMgr_Presentation.cdl | 9 + src/PrsMgr/PrsMgr_Presentation2d.cdl | 8 + src/PrsMgr/PrsMgr_Presentation2d.cxx | 19 ++ src/PrsMgr/PrsMgr_Presentation3d.cdl | 9 + src/PrsMgr/PrsMgr_Presentation3d.cxx | 20 ++ src/PrsMgr/PrsMgr_PresentationManager.cdl | 13 + src/PrsMgr/PrsMgr_PresentationManager.cxx | 42 ++++ src/SelectMgr/SelectMgr_EntityOwner.cdl | 6 + src/SelectMgr/SelectMgr_EntityOwner.cxx | 10 + src/SelectMgr/SelectMgr_SelectableObject.cdl | 13 +- src/SelectMgr/SelectMgr_SelectableObject.cxx | 39 +++ src/StdSelect/StdSelect_BRepOwner.cdl | 6 + src/StdSelect/StdSelect_BRepOwner.cxx | 68 ++++-- src/V3d/V3d_Viewer.cdl | 26 ++ src/V3d/V3d_Viewer.cxx | 30 +++ src/ViewerTest/ViewerTest_ObjectCommands.cxx | 69 ++++++ src/ViewerTest/ViewerTest_ViewerCommands.cxx | 85 ++++++- src/Visual3d/Visual3d_View.cdl | 21 ++ src/Visual3d/Visual3d_View.cxx | 32 +++ src/Visual3d/Visual3d_ViewManager.cdl | 50 +++- src/Visual3d/Visual3d_ViewManager.cxx | 127 +++++++++- 43 files changed, 1595 insertions(+), 39 deletions(-) create mode 100644 src/OpenGl/OpenGl_LayerList.cxx create mode 100644 src/OpenGl/OpenGl_LayerList.hxx diff --git a/src/AIS/AIS_InteractiveContext.cdl b/src/AIS/AIS_InteractiveContext.cdl index bbab4298c0..3a5ebe499d 100755 --- a/src/AIS/AIS_InteractiveContext.cdl +++ b/src/AIS/AIS_InteractiveContext.cdl @@ -406,6 +406,26 @@ is ---Purpose: Sets the display priority aPriority of the seen parts -- presentation of the entity anIobj. + SetZLayer( me : mutable; + theIObj : InteractiveObject from AIS; + theLayerId : Integer from Standard ); + ---Purpose: Set Z layer id for interactive object. The layer can be + -- specified for displayed object only. The Z layers can be used to display + -- temporarily presentations of some object in front of the other objects + -- in the scene. The ids for Z layers are generated by V3d_Viewer. + -- Note that Z layers differ from under-/overlayer in V3d_View: + -- under-/overlayer are intended for specific 2D drawings that appear + -- behind/in front of all 3D presentations, while SetZLayer() method + -- applies to regular 3D presentations and does not imply any specific + -- drawing methods. + + GetZLayer( me; + theIObj : InteractiveObject from AIS ) + returns Integer from Standard; + ---Purpose: Get Z layer id set for displayed interactive object. + -- If the object doesn't exists in context or has no computed presentations, + -- the method returns -1. + Redisplay(me : mutable; aniobj : InteractiveObject from AIS; updateviewer : Boolean from Standard = Standard_True; diff --git a/src/AIS/AIS_InteractiveContext.cxx b/src/AIS/AIS_InteractiveContext.cxx index 58515a6725..8372528d85 100755 --- a/src/AIS/AIS_InteractiveContext.cxx +++ b/src/AIS/AIS_InteractiveContext.cxx @@ -3147,3 +3147,54 @@ Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const { return myIsAutoActivateSelMode; } + +//======================================================================= +//function : SetZLayer +//purpose : +//======================================================================= + +void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj, + const Standard_Integer theLayerId) +{ + if (theIObj.IsNull ()) + return; + + if (myObjects.IsBound (theIObj)) + { + switch (myObjects (theIObj)->GraphicStatus ()) + { + case AIS_DS_Displayed: + { + theIObj->SetZLayer (myMainPM, theLayerId); + break; + } + case AIS_DS_Erased: + { + theIObj->SetZLayer (myCollectorPM, theLayerId); + break; + } + default: + break; + } + } + else if (HasOpenedContext ()) + { + myLocalContexts (myCurLocalIndex)->SetZLayer (theIObj, theLayerId); + } +} + +//======================================================================= +//function : GetZLayer +//purpose : +//======================================================================= + +Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const +{ + if (theIObj.IsNull ()) + return -1; + + if (myObjects.IsBound (theIObj)) + return theIObj->GetZLayer (myMainPM); + + return myLocalContexts (myCurLocalIndex)->GetZLayer (theIObj); +} diff --git a/src/AIS/AIS_LocalContext.cdl b/src/AIS/AIS_LocalContext.cdl index bb3a3cb673..4b66b26a17 100755 --- a/src/AIS/AIS_LocalContext.cdl +++ b/src/AIS/AIS_LocalContext.cdl @@ -373,6 +373,26 @@ is anObject: InteractiveObject from AIS; Prior : Integer from Standard); + SetZLayer( me : mutable; + theIObj : InteractiveObject from AIS; + theLayerId : Integer from Standard ); + ---Purpose: Set Z layer id for interactive object. The layer can be + -- specified for displayed object only. The Z layers can be used to display + -- temporarily presentations of some object in front of the other objects + -- in the scene. The ids for Z layers are generated by V3d_Viewer. + -- Note that Z layers differ from under-/overlayer in V3d_View: + -- under-/overlayer are intended for specific 2D drawings that appear + -- behind/in front of all 3D presentations, while SetZLayer() method + -- applies to regular 3D presentations and does not imply any specific + -- drawing methods. + + GetZLayer( me; + theIObj : InteractiveObject from AIS ) + returns Integer from Standard; + ---Purpose: Get Z layer id set for displayed interactive object. + -- If the object doesn't exists in context or has no computed presentations, + -- the method returns -1. + DisplayedObjects(me;theMapToFill : in out MapOfTransient from TColStd) returns Integer from Standard; diff --git a/src/AIS/AIS_LocalContext.cxx b/src/AIS/AIS_LocalContext.cxx index 1269634a78..3db148114d 100755 --- a/src/AIS/AIS_LocalContext.cxx +++ b/src/AIS/AIS_LocalContext.cxx @@ -881,7 +881,6 @@ void AIS_LocalContext::SetDisplayPriority(const Handle(AIS_InteractiveObject)& a } - //======================================================================= //function : DisplayedObjects //purpose : @@ -1220,3 +1219,34 @@ void AIS_LocalContext::SetSensitivity(const Standard_Integer aPrecision) { myMainVS->Set(aPrecision); } #endif + +//======================================================================= +//function : SetZLayer +//purpose : +//======================================================================= + +void AIS_LocalContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj, + const Standard_Integer theLayerId) +{ + if (!myActiveObjects.IsBound (theIObj)) + return; + + const Handle(AIS_LocalStatus)& aStatus = myActiveObjects (theIObj); + if (aStatus->DisplayMode () == -1) + return; + + theIObj->SetZLayer (myMainPM, theLayerId); +} + +//======================================================================= +//function : GetZLayer +//purpose : +//======================================================================= + +Standard_Integer AIS_LocalContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const +{ + if (!myActiveObjects.IsBound (theIObj)) + return -1; + + return theIObj->GetZLayer (myMainPM); +} diff --git a/src/Graphic3d/Graphic3d_GraphicDriver.cdl b/src/Graphic3d/Graphic3d_GraphicDriver.cdl index 63d3eedf96..ce6551ca16 100755 --- a/src/Graphic3d/Graphic3d_GraphicDriver.cdl +++ b/src/Graphic3d/Graphic3d_GraphicDriver.cdl @@ -1287,6 +1287,52 @@ is -- . This method is internal and should be used -- by Graphic3d_Group only. + AddZLayer( me : mutable; + theCView : CView from Graphic3d; + theLayerId : Integer from Standard ) + is deferred; + ---Purpose: Add a new top-level z layer with ID for + -- the view. Z layers allow drawing structures in higher layers + -- in foreground of structures in lower layers. To add a structure + -- to desired layer on display it is necessary to set the layer + -- ID for the structure. + + RemoveZLayer( me : mutable; + theCView : CView from Graphic3d; + theLayerId : Integer from Standard ) + is deferred; + ---Purpose: Remove Z layer from the specified view. All structures + -- displayed at the moment in layer will be displayed in default layer + -- ( the bottom-level z layer ). To unset layer ID from associated + -- structures use method UnsetZLayer (...). + + UnsetZLayer( me : mutable; + theLayerId : Integer from Standard ) + is deferred; + ---Purpose: Unset Z layer ID for all structures. The structure + -- indexes will be set to default layer ( the bottom-level z layer + -- with ID = 0 ). + + ChangeZLayer( me : mutable; + theCStructure : CStructure from Graphic3d; + theLayerId : Integer from Standard ) + is deferred; + ---Purpose: Change Z layer of a structure. The new z layer ID will + -- be used to define the associated layer for structure on display. + + ChangeZLayer( me : mutable; + theCStructure : CStructure from Graphic3d; + theCView : CView from Graphic3d; + theNewLayerId : Integer from Standard ) + is deferred; + ---Purpose: Change Z layer of a structure already presented in view. + + GetZLayer( me; + theCStructure : CStructure from Graphic3d ) + returns Integer from Standard is deferred; + ---Purpose: Get Z layer ID of structure. If the structure doesn't + -- exists in graphic driver, the method returns -1. + -------------------------- -- Category: Class methods -------------------------- diff --git a/src/Graphic3d/Graphic3d_Structure.cdl b/src/Graphic3d/Graphic3d_Structure.cdl index b9fd7bf3af..6533223383 100755 --- a/src/Graphic3d/Graphic3d_Structure.cdl +++ b/src/Graphic3d/Graphic3d_Structure.cdl @@ -241,6 +241,19 @@ is -- Warning: If is displayed then the SetDisplayPriority -- method erase and display with the -- previous priority. + + SetZLayer ( me : mutable; + theLayerId : Integer from Standard ) + is static; + ---Purpose: Set Z layer ID for the structure. The Z layer mechanism + -- allows to display structures presented in higher layers in overlay + -- of structures in lower layers by switching off z buffer depth + -- test between layers + + GetZLayer ( me ) + returns Integer from Standard is static; + ---Purpose: Get Z layer ID of displayed structure. The method + -- returns -1 if the structure has no ID (deleted from graphic driver). SetPick ( me : mutable; AValue : Boolean from Standard ) diff --git a/src/Graphic3d/Graphic3d_Structure.cxx b/src/Graphic3d/Graphic3d_Structure.cxx index 6d580f1dd0..cfb54ed512 100755 --- a/src/Graphic3d/Graphic3d_Structure.cxx +++ b/src/Graphic3d/Graphic3d_Structure.cxx @@ -2553,3 +2553,27 @@ Standard_Address Graphic3d_Structure::CStructure () const { return Standard_Address (&MyCStructure); } + +//======================================================================= +//function : SetZLayer +//purpose : +//======================================================================= + +void Graphic3d_Structure::SetZLayer (const Standard_Integer theLayerId) +{ + // if the structure is not displayed, unable to change its display layer + if (IsDeleted ()) + return; + + MyStructureManager->ChangeZLayer (this, theLayerId); +} + +//======================================================================= +//function : GetZLayer +//purpose : +//======================================================================= + +Standard_Integer Graphic3d_Structure::GetZLayer () const +{ + return MyStructureManager->GetZLayer (this); +} diff --git a/src/Graphic3d/Graphic3d_StructureManager.cdl b/src/Graphic3d/Graphic3d_StructureManager.cdl index 4821b91ced..4597f1bdb7 100755 --- a/src/Graphic3d/Graphic3d_StructureManager.cdl +++ b/src/Graphic3d/Graphic3d_StructureManager.cdl @@ -25,6 +25,7 @@ deferred class StructureManager from Graphic3d inherits TShared uses Array2OfReal from TColStd, + SequenceOfInteger from TColStd, GenId from Aspect, GraphicDevice from Aspect, @@ -272,6 +273,43 @@ is ---Purpose: Changes the display priority of the structure . ---Category: Private methods + ChangeZLayer ( me : mutable; + theStructure : Structure from Graphic3d; + theLayerId : Integer from Standard ) + is deferred; + ---Purpose: Change Z layer for structure. The z layer mechanism allows + -- to display structures in higher layers in overlay of structures in + -- lower layers. + + GetZLayer ( me; + theStructure : Structure from Graphic3d ) + returns Integer from Standard is deferred; + ---Purpose: Get Z layer ID assigned to structure. If the structure + -- has no layer ID (deleted from graphic driver), the method returns -1. + + AddZLayer ( me : mutable; + theLayerId : in out Integer from Standard ) + returns Boolean from Standard is deferred; + ---Purpose: Add a new top-level Z layer and get its ID as + -- value. The method returns Standard_False if the layer + -- can not be created. The z layer mechanism allows to display + -- structures in higher layers in overlay of structures in lower layers. + + RemoveZLayer ( me : mutable; + theLayerId : Integer from Standard ) + returns Boolean from Standard is deferred; + ---Purpose: Remove Z layer with ID . Method returns + -- Standard_False if the layer can not be removed or doesn't exists. + -- By default, there is always a default bottom-level layer that can't + -- be removed. + + GetAllZLayers ( me; + theLayerSeq : out SequenceOfInteger from TColStd ) + is deferred; + ---Purpose: Return all Z layer ids in sequence ordered by level + -- from lowest layer to highest. The first layer ID in sequence is + -- the default layer that can't be removed. + CurrentId ( myclass ) returns Integer from Standard; ---Level: Internal diff --git a/src/OpenGl/FILES b/src/OpenGl/FILES index 342136466f..6e2d405a3e 100755 --- a/src/OpenGl/FILES +++ b/src/OpenGl/FILES @@ -123,4 +123,6 @@ Handle_OpenGl_Context.hxx OpenGl_Context.hxx OpenGl_Context.cxx OpenGl_ArbVBO.hxx -OpenGl_ExtFBO.hxx \ No newline at end of file +OpenGl_ExtFBO.hxx +OpenGl_LayerList.cxx +OpenGl_LayerList.hxx \ No newline at end of file diff --git a/src/OpenGl/OpenGl_GraphicDriver.hxx b/src/OpenGl/OpenGl_GraphicDriver.hxx index c2e8420824..f09a9e7c3f 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.hxx +++ b/src/OpenGl/OpenGl_GraphicDriver.hxx @@ -284,6 +284,47 @@ public: Standard_EXPORT void FBOGetDimensions(const Graphic3d_CView& view,const Graphic3d_PtrFrameBuffer fboPtr,Standard_Integer& width,Standard_Integer& height,Standard_Integer& widthMax,Standard_Integer& heightMax); Standard_EXPORT void FBOChangeViewport(const Graphic3d_CView& view,Graphic3d_PtrFrameBuffer& fboPtr,const Standard_Integer width,const Standard_Integer height); Standard_EXPORT Standard_Boolean Export(const Standard_CString theFileName,const Graphic3d_ExportFormat theFormat,const Graphic3d_SortType theSortType,const Standard_Integer theWidth,const Standard_Integer theHeight,const Graphic3d_CView& theView,const Aspect_CLayer2d& theLayerUnder,const Aspect_CLayer2d& theLayerOver,const Standard_Real thePrecision = 0.005,const Standard_Address theProgressBarFunc = NULL,const Standard_Address theProgressObject = NULL); + + //! Add a new top-level z layer with ID for
+ //! the view. Z layers allow drawing structures in higher layers
+ //! in foreground of structures in lower layers. To add a structure
+ //! to desired layer on display it is necessary to set the layer
+ //! index for the structure.
+ Standard_EXPORT void AddZLayer(const Graphic3d_CView& theCView, + const Standard_Integer theLayerId); + + //! Remove Z layer from the specified view. All structures
+ //! displayed at the moment in layer will be displayed in default layer
+ //! ( the bottom-level z layer ). To unset layer index from associated
+ //! structures use method UnsetZLayer (...).
+ Standard_EXPORT void RemoveZLayer(const Graphic3d_CView& theCView, + const Standard_Integer theLayerId); + + //! Unset Z layer ID for all structures. The structure
+ //! indexes will be set to default layer ( the bottom-level z layer with
+ //! ID = 0 ).
+ Standard_EXPORT void UnsetZLayer(const Standard_Integer theLayerId); + + //! Change Z layer of a structure. The new z layer ID will
+ //! be used to define the associated layer for structure on display.
+ //! It is recommended to take care of redisplaying the structures already
+ //! presented in view with previously set layer index. This is usually
+ //! done by viewer manager. Z layers allow drawing structures in
+ //! higher layers in foreground of structures in lower layers.
+ Standard_EXPORT void ChangeZLayer(const Graphic3d_CStructure& theCStructure, + const Standard_Integer theLayerId); + + //! Change Z layer of a structure already presented in view.
+ //! It is recommended to update z layer of already
+ //! displayed structures with this method before setting new z layer
+ //! index to the structure. This is usually done by viewer manager.
+ Standard_EXPORT void ChangeZLayer(const Graphic3d_CStructure& theCStructure, + const Graphic3d_CView& theCView, + const Standard_Integer theNewLayerId); + + //! Get Z layer ID of the structure. If the structure doesn't exists in
+ //! graphic driver, the method returns -1.
+ Standard_EXPORT Standard_Integer GetZLayer(const Graphic3d_CStructure& theCStructure) const; public: diff --git a/src/OpenGl/OpenGl_GraphicDriver_4.cxx b/src/OpenGl/OpenGl_GraphicDriver_4.cxx index 0a939fed3d..6c960835c9 100755 --- a/src/OpenGl/OpenGl_GraphicDriver_4.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver_4.cxx @@ -115,3 +115,74 @@ void OpenGl_GraphicDriver::Structure (Graphic3d_CStructure& theCStructure) OpenGl_GraphicDriver::GetMapOfStructures().Bind (theCStructure.Id, aStructure); InvalidateAllWorkspaces(); } + +//======================================================================= +//function : ChangeZLayer +//purpose : +//======================================================================= + +void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure, + const Standard_Integer theLayer) +{ + if (!GetMapOfStructures().IsBound (theCStructure.Id)) + return; + + OpenGl_Structure* aStructure = + OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id); + + aStructure->SetZLayer (theLayer); +} + +//======================================================================= +//function : ChangeZLayer +//purpose : +//======================================================================= + +void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure, + const Graphic3d_CView& theCView, + const Standard_Integer theNewLayerId) +{ + const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView; + + if (!GetMapOfStructures().IsBound (theCStructure.Id) || !aCView) + return; + + OpenGl_Structure* aStructure = + OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id); + + aCView->View->ChangeZLayer (aStructure, theNewLayerId); +} + +//======================================================================= +//function : GetZLayer +//purpose : +//======================================================================= + +Standard_Integer OpenGl_GraphicDriver::GetZLayer (const Graphic3d_CStructure& theCStructure) const +{ + if (!GetMapOfStructures().IsBound (theCStructure.Id)) + return -1; + + OpenGl_Structure* aStructure = + OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id); + + return aStructure->GetZLayer(); +} + +//======================================================================= +//function : UnsetZLayer +//purpose : +//======================================================================= + +void OpenGl_GraphicDriver::UnsetZLayer (const Standard_Integer theLayerId) +{ + NCollection_DataMap::Iterator + aStructIt (GetMapOfStructures ()); + + for( ; aStructIt.More (); aStructIt.Next ()) + { + OpenGl_Structure* aStruct = aStructIt.ChangeValue (); + if (aStruct->GetZLayer () == theLayerId) + aStruct->SetZLayer (0); + } +} diff --git a/src/OpenGl/OpenGl_GraphicDriver_7.cxx b/src/OpenGl/OpenGl_GraphicDriver_7.cxx index 1ad1798f69..7205ed52f1 100755 --- a/src/OpenGl/OpenGl_GraphicDriver_7.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver_7.cxx @@ -496,3 +496,29 @@ void OpenGl_GraphicDriver::SetBackFacingModel (const Graphic3d_CView& ACView) if (aCView) aCView->View->SetBackfacing(ACView.Backfacing); } + +//======================================================================= +//function : AddZLayer +//purpose : +//======================================================================= + +void OpenGl_GraphicDriver::AddZLayer (const Graphic3d_CView& theCView, + const Standard_Integer theLayerId) +{ + const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView; + if (aCView) + aCView->View->AddZLayer (theLayerId); +} + +//======================================================================= +//function : RemoveZLayer +//purpose : +//======================================================================= + +void OpenGl_GraphicDriver::RemoveZLayer (const Graphic3d_CView& theCView, + const Standard_Integer theLayerId) +{ + const OpenGl_CView* aCView = (const OpenGl_CView *)theCView.ptrView; + if (aCView) + aCView->View->RemoveZLayer (theLayerId); +} diff --git a/src/OpenGl/OpenGl_LayerList.cxx b/src/OpenGl/OpenGl_LayerList.cxx new file mode 100644 index 0000000000..7ec589f501 --- /dev/null +++ b/src/OpenGl/OpenGl_LayerList.cxx @@ -0,0 +1,243 @@ +// File: OpenGl_LayerList.hxx +// Created: 2 February 2012 +// Author: Anton POLETAEV +// Copyright: OPEN CASCADE 2012 + +#include +#include +#include + +#include +#include + +//======================================================================= +//function : OpenGl_LayerList +//purpose : Constructor +//======================================================================= + +OpenGl_LayerList::OpenGl_LayerList (const Standard_Integer theNbPriorities) + : myNbPriorities (theNbPriorities), + myNbStructures (0) +{ + // insert default priority layer + myLayers.Append (OpenGl_PriorityList (myNbPriorities)); + myLayerIds.Bind (0, myLayers.Length()); +} + +//======================================================================= +//function : ~OpenGl_LayerList +//purpose : Destructor +//======================================================================= + +OpenGl_LayerList::~OpenGl_LayerList () +{ +} + +//======================================================================= +//function : defaultLayer +//purpose : +//======================================================================= + +OpenGl_PriorityList& OpenGl_LayerList::defaultLayer() +{ + return myLayers.ChangeValue (1); +} + +//======================================================================= +//function : NbPriorities +//purpose : Method returns the number of available priorities +//======================================================================= + +Standard_Integer OpenGl_LayerList::NbPriorities () const +{ + return myNbPriorities; +} + +//======================================================================= +//function : NbStructures +//purpose : Method returns the number of available structures +//======================================================================= + +Standard_Integer OpenGl_LayerList::NbStructures () const +{ + return myNbStructures; +} + +//======================================================================= +//function : AddLayer +//purpose : +//======================================================================= + +void OpenGl_LayerList::AddLayer (const Standard_Integer theLayerId) +{ + if (HasLayer (theLayerId)) + return; + + // add the new layer + myLayers.Append (OpenGl_PriorityList (myNbPriorities)); + myLayerIds.Bind (theLayerId, myLayers.Length()); +} + +//======================================================================= +//function : HasLayer +//purpose : +//======================================================================= + +Standard_Boolean OpenGl_LayerList::HasLayer + (const Standard_Integer theLayerId) const +{ + return myLayerIds.IsBound (theLayerId); +} + +//======================================================================= +//function : RemoveLayer +//purpose : +//======================================================================= + +void OpenGl_LayerList::RemoveLayer (const Standard_Integer theLayerId) +{ + if (!HasLayer (theLayerId) || theLayerId == 0) + return; + + Standard_Integer aRemovePos = myLayerIds.Find (theLayerId); + + // move all displayed structures to first layer + const OpenGl_PriorityList& aList = myLayers.Value (aRemovePos); + defaultLayer ().Append (aList); + + // remove layer + myLayers.Remove (aRemovePos); + myLayerIds.UnBind (theLayerId); + + // updated sequence indexes in map + OpenGl_LayerSeqIds::Iterator aMapIt (myLayerIds); + for ( ; aMapIt.More (); aMapIt.Next ()) + { + Standard_Integer& aSeqIdx = aMapIt.ChangeValue (); + if (aSeqIdx > aRemovePos) + aSeqIdx--; + } +} + +//======================================================================= +//function : AddStructure +//purpose : +//======================================================================= + +void OpenGl_LayerList::AddStructure (const OpenGl_Structure *theStructure, + const Standard_Integer theLayerId, + const Standard_Integer thePriority) +{ + // add structure to associated layer, + // if layer doesn't exists, display structure in default layer + OpenGl_PriorityList& aList = !HasLayer (theLayerId) ? defaultLayer () : + myLayers.ChangeValue (myLayerIds.Find (theLayerId)); + + aList.Add (theStructure, thePriority); + myNbStructures++; +} + +//======================================================================= +//function : RemoveStructure +//purpose : +//======================================================================= + +void OpenGl_LayerList::RemoveStructure (const OpenGl_Structure *theStructure, + const Standard_Integer theLayerId) +{ + Standard_Integer aSeqPos = !HasLayer (theLayerId) ? + 1 : myLayerIds.Find (theLayerId); + + OpenGl_PriorityList& aList = myLayers.ChangeValue (aSeqPos); + + // remove structure from associated list + // if the structure is not found there, + // scan through layers and remove it + if (aList.Remove (theStructure) >= 0) + { + myNbStructures--; + return; + } + + // scan through layers and remove it + Standard_Integer aSeqId = 1; + OpenGl_SequenceOfLayers::Iterator anIts; + for (anIts.Init (myLayers); anIts.More (); anIts.Next (), aSeqId++) + { + OpenGl_PriorityList& aScanList = anIts.ChangeValue (); + if (aSeqPos == aSeqId) + continue; + + if (aScanList.Remove (theStructure) >= 0) + { + myNbStructures--; + return; + } + } +} + +//======================================================================= +//function : ChangeLayer +//purpose : +//======================================================================= + +void OpenGl_LayerList::ChangeLayer (const OpenGl_Structure *theStructure, + const Standard_Integer theOldLayerId, + const Standard_Integer theNewLayerId) +{ + Standard_Integer aSeqPos = !HasLayer (theOldLayerId) ? + 1 : myLayerIds.Find (theOldLayerId); + + OpenGl_PriorityList& aList = myLayers.ChangeValue (aSeqPos); + Standard_Integer aPriority; + + // take priority and remove structure from list found by + // if the structure is not found there, scan through all other layers + if ((aPriority = aList.Remove (theStructure)) >= 0) + { + myNbStructures--; + AddStructure (theStructure, theNewLayerId, aPriority); + } + else + { + // scan through layers and remove it + Standard_Integer aSeqId = 1; + OpenGl_SequenceOfLayers::Iterator anIts; + for (anIts.Init (myLayers); anIts.More (); anIts.Next (), aSeqId++) + { + OpenGl_PriorityList& aScanList = anIts.ChangeValue (); + if (aSeqPos == aSeqId) + continue; + + // try to remove structure and get priority value from this layer + if ((aPriority = aList.Remove (theStructure)) >= 0) + { + myNbStructures--; + AddStructure (theStructure, theNewLayerId, aPriority); + break; + } + } + } +} + +//======================================================================= +//function : Render +//purpose : Render this element +//======================================================================= + +void OpenGl_LayerList::Render (const Handle(OpenGl_Workspace) &theWorkspace) const +{ + OpenGl_SequenceOfLayers::Iterator anIts; + for(anIts.Init (myLayers); anIts.More (); anIts.Next ()) + { + const OpenGl_PriorityList& aList = anIts.Value (); + if (aList.NbStructures () > 0) + { + // separate depth buffers + glClear (GL_DEPTH_BUFFER_BIT); + + // render priority list + aList.Render (theWorkspace); + } + } +} diff --git a/src/OpenGl/OpenGl_LayerList.hxx b/src/OpenGl/OpenGl_LayerList.hxx new file mode 100644 index 0000000000..6d149b485d --- /dev/null +++ b/src/OpenGl/OpenGl_LayerList.hxx @@ -0,0 +1,85 @@ +// File: OpenGl_LayerList.hxx +// Created: 2 February 2012 +// Author: Anton POLETAEV +// Copyright: OPEN CASCADE 2012 + +#ifndef _OpenGl_LayerList_Header +#define _OpenGl_LayerList_Header + +#include + +#include + +#include +#include + +class OpenGl_Structure; +class Handle(OpenGl_Workspace); + +typedef NCollection_Sequence OpenGl_SequenceOfLayers; +typedef NCollection_DataMap OpenGl_LayerSeqIds; + +class OpenGl_LayerList +{ + public: + + //! Constructor + OpenGl_LayerList (const Standard_Integer theNbPriorities = 11); + + //! Destructor + virtual ~OpenGl_LayerList (); + + //! Method returns the number of available priorities + Standard_Integer NbPriorities () const; + + //! Number of displayed structures + Standard_Integer NbStructures () const; + + //! Insert a new layer with id. + void AddLayer (const Standard_Integer theLayerId); + + //! Check whether the layer with given id is already created. + Standard_Boolean HasLayer (const Standard_Integer theLayerId) const; + + //! Remove layer by its id. + void RemoveLayer (const Standard_Integer theLayerId); + + //! Add structure to list with given priority. The structure will be inserted + //! to specified layer. If the layer isn't found, the structure will be put + //! to default bottom-level layer. + void AddStructure (const OpenGl_Structure *theStructure, + const Standard_Integer theLayerId, + const Standard_Integer thePriority); + + //! Remove structure from structure list and return its previous priority + void RemoveStructure (const OpenGl_Structure *theStructure, + const Standard_Integer theZLayerId); + + //! Change structure z layer + //! If the new layer is not presented, the structure will be displayed + //! in default z layer + void ChangeLayer (const OpenGl_Structure *theStructure, + const Standard_Integer theOldLayerId, + const Standard_Integer theNewLayerId); + + //! Render this element + void Render (const Handle(OpenGl_Workspace) &theWorkspace) const; + + private: + + //! Get default layer + OpenGl_PriorityList& defaultLayer (); + + protected: + + // number of structures temporary put to default layer + OpenGl_SequenceOfLayers myLayers; + OpenGl_LayerSeqIds myLayerIds; + Standard_Integer myNbPriorities; + Standard_Integer myNbStructures; + + public: + IMPLEMENT_MEMORY_OPERATORS +}; + +#endif //_OpenGl_LayerList_Header diff --git a/src/OpenGl/OpenGl_PriorityList.cxx b/src/OpenGl/OpenGl_PriorityList.cxx index 7ef24401e4..f35dcb8763 100644 --- a/src/OpenGl/OpenGl_PriorityList.cxx +++ b/src/OpenGl/OpenGl_PriorityList.cxx @@ -20,7 +20,7 @@ void OpenGl_PriorityList::Add (const OpenGl_Structure *AStructure,const Standard /*----------------------------------------------------------------------*/ -void OpenGl_PriorityList::Remove (const OpenGl_Structure *AStructure) +Standard_Integer OpenGl_PriorityList::Remove (const OpenGl_Structure *AStructure) { const Standard_Integer aNbPr = myArray.Length(); Standard_Integer i = 0; @@ -34,10 +34,12 @@ void OpenGl_PriorityList::Remove (const OpenGl_Structure *AStructure) { aSeq.Remove(its); myNbStructures--; - return; + return i; } } } + + return -1; } /*----------------------------------------------------------------------*/ @@ -54,4 +56,37 @@ void OpenGl_PriorityList::Render (const Handle(OpenGl_Workspace) &AWorkspace) co } } -/*----------------------------------------------------------------------*/ +//======================================================================= +//function : Append +//purpose : +//======================================================================= + +Standard_Boolean OpenGl_PriorityList::Append (const OpenGl_PriorityList& theOther) +{ + // the source priority list shouldn't have more priorities + const Standard_Integer aNbPriorities = theOther.NbPriorities (); + if (aNbPriorities > NbPriorities ()) + return Standard_False; + + // add all structures to destination priority list + Standard_Integer aIdx = 0; + OpenGl_SequenceOfStructure::Iterator anIts; + for (; aIdx < aNbPriorities; aIdx++) + { + const OpenGl_SequenceOfStructure& aSeq = theOther.myArray (aIdx); + for (anIts.Init (aSeq); anIts.More (); anIts.Next ()) + Add (anIts.Value (), aIdx); + } + + return Standard_True; +} + +//======================================================================= +//function : NbPriorities +//purpose : +//======================================================================= + +Standard_Integer OpenGl_PriorityList::NbPriorities() const +{ + return myArray.Length(); +} diff --git a/src/OpenGl/OpenGl_PriorityList.hxx b/src/OpenGl/OpenGl_PriorityList.hxx index 294cb9a41d..2928ea309e 100644 --- a/src/OpenGl/OpenGl_PriorityList.hxx +++ b/src/OpenGl/OpenGl_PriorityList.hxx @@ -23,19 +23,30 @@ class OpenGl_PriorityList public: OpenGl_PriorityList (const Standard_Integer ANbPriorities = 11) : myArray(0,(ANbPriorities-1)), myNbStructures(0) {} + virtual ~OpenGl_PriorityList () {} void Add (const OpenGl_Structure *AStructure, const Standard_Integer APriority); - void Remove (const OpenGl_Structure *AStructure); + + //! Remove structure and returns its priority, if the structure is not found, + //! method returns negative value + Standard_Integer Remove (const OpenGl_Structure *AStructure); Standard_Integer NbStructures () const { return myNbStructures; } void Render (const Handle(OpenGl_Workspace) &AWorkspace) const; + //! Returns the number of available priority levels + Standard_Integer NbPriorities() const; + + //! Append priority list of acceptable type (with similar number of priorities + //! or less). Returns Standard_False if the list can not be accepted. + Standard_Boolean Append (const OpenGl_PriorityList& theOther); + protected: OpenGl_ArrayOfStructure myArray; - Standard_Integer myNbStructures; + Standard_Integer myNbStructures; public: IMPLEMENT_MEMORY_OPERATORS diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx index 1421082d10..eb46d729a7 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -36,7 +36,8 @@ OpenGl_Structure::OpenGl_Structure () myAspectText(NULL), myHighlightBox(NULL), myHighlightColor(NULL), - myNamedStatus(0) + myNamedStatus(0), + myZLayer(0) { } @@ -445,4 +446,22 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &AWorkspace) const AWorkspace->NamedStatus = named_status; } -/*----------------------------------------------------------------------*/ +//======================================================================= +//function : SetZLayer +//purpose : +//======================================================================= + +void OpenGl_Structure::SetZLayer (const Standard_Integer theLayerIndex) +{ + myZLayer = theLayerIndex; +} + +//======================================================================= +//function : GetZLayer +//purpose : +//======================================================================= + +Standard_Integer OpenGl_Structure::GetZLayer () const +{ + return myZLayer; +} diff --git a/src/OpenGl/OpenGl_Structure.hxx b/src/OpenGl/OpenGl_Structure.hxx index 1c76d4be01..c1f3228722 100644 --- a/src/OpenGl/OpenGl_Structure.hxx +++ b/src/OpenGl/OpenGl_Structure.hxx @@ -52,8 +52,14 @@ class OpenGl_Structure : public OpenGl_Element void RemoveGroup (const OpenGl_Group *); void Clear (); - virtual void Render (const Handle(OpenGl_Workspace) &AWorkspace) const; + //! Set z layer ID to display the structure in specified layer + void SetZLayer (const Standard_Integer theLayerIndex); + + //! Get z layer ID + Standard_Integer GetZLayer () const; + virtual void Render (const Handle(OpenGl_Workspace) &AWorkspace) const; + protected: //Structure_LABBegin @@ -70,6 +76,7 @@ class OpenGl_Structure : public OpenGl_Element //Structure_LABVisibility //Structure_LABPick int myNamedStatus; //Structure_LABNameSet + int myZLayer; OpenGl_ListOfStructure myConnected; diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index 2ba36f7a79..ff86022c5c 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -26,9 +26,8 @@ #include #include - +#include #include -#include #include #include @@ -135,8 +134,27 @@ class OpenGl_View : public MMgt_TShared const TEL_TRANSFORM_PERSISTENCE * BeginTransformPersistence ( const TEL_TRANSFORM_PERSISTENCE *ATransPers ); void EndTransformPersistence (); - void DisplayStructure (const OpenGl_Structure *AStructure, const Standard_Integer APriority) { myStructures.Add(AStructure,APriority); } - void EraseStructure (const OpenGl_Structure *AStructure) { myStructures.Remove(AStructure); } + //! Add structure to display list with specified priority. + //! The structure will be added to associated with it z layer. + //! If the z layer is not presented in the view, the structure will + //! be displayed in default bottom-level z layer. + void DisplayStructure (const OpenGl_Structure *theStructure, + const Standard_Integer thePriority); + + //! Erase structure from display list. + void EraseStructure (const OpenGl_Structure *theStructure); + + //! Insert a new top-level z layer with ID + void AddZLayer (const Standard_Integer theLayerId); + + //! Remove a z layer with ID + void RemoveZLayer (const Standard_Integer theLayerId); + + //! Display structure in z layer with ID + //! If the layer with ID is not presented in the view, + //! the structure will be displayed in default bottom-level layer. + void ChangeZLayer (const OpenGl_Structure *theStructure, + const Standard_Integer theNewLayerId); void CreateBackgroundTexture (const Standard_CString AFileName, const Aspect_FillMethod AFillStyle); void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle); @@ -197,7 +215,7 @@ class OpenGl_View : public MMgt_TShared //View_LABDepthCueing - fixed index used - OpenGl_PriorityList myStructures; + OpenGl_LayerList myZLayers; int myAnimationListIndex; Standard_Boolean myAnimationListReady; diff --git a/src/OpenGl/OpenGl_View_2.cxx b/src/OpenGl/OpenGl_View_2.cxx index 1834b0fcf7..e90dc422b3 100644 --- a/src/OpenGl/OpenGl_View_2.cxx +++ b/src/OpenGl/OpenGl_View_2.cxx @@ -33,6 +33,7 @@ #include #include #include +#include /*----------------------------------------------------------------------*/ /* @@ -1231,7 +1232,8 @@ D = -[Px,Py,Pz] dot |Nx| //ExecuteViewDisplay void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace) { - if ( myStructures.NbStructures() <= 0 ) return; + if ( myZLayers.NbStructures() <= 0 ) + return; glPushAttrib ( GL_DEPTH_BUFFER_BIT ); @@ -1261,7 +1263,7 @@ void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace) } } - myStructures.Render(AWorkspace); + myZLayers.Render (AWorkspace); //TsmPopAttri(); /* restore previous graphics context; before update lights */ @@ -1511,4 +1513,57 @@ void OpenGl_View::SetBackgroundGradientType (const Aspect_GradientFillMethod ATy myBgGradient.type = AType; } -/*----------------------------------------------------------------------*/ +//======================================================================= +//function : AddZLayer +//purpose : +//======================================================================= + +void OpenGl_View::AddZLayer (const Standard_Integer theLayerId) +{ + myZLayers.AddLayer (theLayerId); +} + +//======================================================================= +//function : RemoveZLayer +//purpose : +//======================================================================= + +void OpenGl_View::RemoveZLayer (const Standard_Integer theLayerId) +{ + myZLayers.RemoveLayer (theLayerId); +} + +//======================================================================= +//function : DisplayStructure +//purpose : +//======================================================================= + +void OpenGl_View::DisplayStructure (const OpenGl_Structure *theStructure, + const Standard_Integer thePriority) +{ + Standard_Integer aZLayer = theStructure->GetZLayer (); + myZLayers.AddStructure (theStructure, aZLayer, thePriority); +} + +//======================================================================= +//function : EraseStructure +//purpose : +//======================================================================= + +void OpenGl_View::EraseStructure (const OpenGl_Structure *theStructure) +{ + Standard_Integer aZLayer = theStructure->GetZLayer (); + myZLayers.RemoveStructure (theStructure, aZLayer); +} + +//======================================================================= +//function : ChangeZLayer +//purpose : +//======================================================================= + +void OpenGl_View::ChangeZLayer (const OpenGl_Structure *theStructure, + const Standard_Integer theNewLayerId) +{ + Standard_Integer anOldLayer = theStructure->GetZLayer (); + myZLayers.ChangeLayer (theStructure, anOldLayer, theNewLayerId); +} diff --git a/src/PrsMgr/PrsMgr_PresentableObject.cdl b/src/PrsMgr/PrsMgr_PresentableObject.cdl index 7bd3e550e7..5cc4a8928e 100755 --- a/src/PrsMgr/PrsMgr_PresentableObject.cdl +++ b/src/PrsMgr/PrsMgr_PresentableObject.cdl @@ -234,8 +234,22 @@ is UpdateLocation(me:mutable;P : mutable Presentation from Prs3d) is virtual; + SetZLayer ( me : mutable; + thePrsMgr : PresentationManager from PrsMgr; + theLayerId : Integer from Standard ) + is virtual; + ---Purpose: Set Z layer ID and update all presentations of + -- the presentable object. The layer can be set only for displayed object. + -- If all object presentations are removed, the layer ID will be set to + -- default value when computing presentation. The layers mechanism allows + -- drawing objects in higher layers in overlay of objects in lower layers. - + GetZLayer ( me; + thePrsMgr : PresentationManager from PrsMgr ) + returns Integer from Standard is static; + ---Purpose: Get ID of Z layer. If no presentations of object is displayed, + -- and layer ID is unavailable, the -1 value is returned. + fields myPresentations: Presentations from PrsMgr is protected; myTypeOfPresentation3d: TypeOfPresentation3d from PrsMgr is protected; diff --git a/src/PrsMgr/PrsMgr_PresentableObject.cxx b/src/PrsMgr/PrsMgr_PresentableObject.cxx index 65e4af8b60..bd90106b0a 100755 --- a/src/PrsMgr/PrsMgr_PresentableObject.cxx +++ b/src/PrsMgr/PrsMgr_PresentableObject.cxx @@ -335,3 +335,28 @@ gp_Pnt PrsMgr_PresentableObject::GetTransformPersistencePoint() const { return gp_Pnt( myTransformPersistence.Point.x, myTransformPersistence.Point.y, myTransformPersistence.Point.z ); } + +//======================================================================= +//function : SetZLayer +//purpose : +//======================================================================= +void PrsMgr_PresentableObject::SetZLayer + (const Handle(PrsMgr_PresentationManager)& thePrsMgr, + const Standard_Integer theLayerId) +{ + if (!thePrsMgr.IsNull()) + thePrsMgr->SetZLayer (this, theLayerId); +} + +//======================================================================= +//function : GetZLayer +//purpose : +//======================================================================= +Standard_Integer PrsMgr_PresentableObject::GetZLayer + (const Handle(PrsMgr_PresentationManager)& thePrsMgr) const +{ + if (!thePrsMgr.IsNull()) + return thePrsMgr->GetZLayer (this); + + return -1; +} diff --git a/src/PrsMgr/PrsMgr_Presentation.cdl b/src/PrsMgr/PrsMgr_Presentation.cdl index 4f648532df..4e25408dc0 100755 --- a/src/PrsMgr/PrsMgr_Presentation.cdl +++ b/src/PrsMgr/PrsMgr_Presentation.cdl @@ -48,6 +48,15 @@ is SetDisplayPriority(me:mutable;aNewPrior:Integer from Standard) is deferred private; + SetZLayer ( me : mutable; + theLayerId : Integer from Standard ) + is deferred private; + ---Purpose: Set Z layer ID for the presentation + + GetZLayer ( me ) + returns Integer from Standard is deferred private; + ---Purpose: Get Z layer ID for the presentation + Clear(me: mutable) is deferred private; diff --git a/src/PrsMgr/PrsMgr_Presentation2d.cdl b/src/PrsMgr/PrsMgr_Presentation2d.cdl index 9be4da329f..ee152eed9b 100755 --- a/src/PrsMgr/PrsMgr_Presentation2d.cdl +++ b/src/PrsMgr/PrsMgr_Presentation2d.cdl @@ -51,6 +51,14 @@ is SetDisplayPriority(me:mutable;aNewPrior:Integer from Standard) is redefined static private; + SetZLayer ( me : mutable; + theLayerId : Integer from Standard ) + is redefined static private; + ---Purpose: Set Z layer ID for the presentation + + GetZLayer ( me ) + returns Integer from Standard is redefined static private; + ---Purpose: Get Z layer ID for the presentation Clear(me:mutable) ---Purpose: removes the whole content of the presentation. diff --git a/src/PrsMgr/PrsMgr_Presentation2d.cxx b/src/PrsMgr/PrsMgr_Presentation2d.cxx index b6e141ce22..213aaf2801 100755 --- a/src/PrsMgr/PrsMgr_Presentation2d.cxx +++ b/src/PrsMgr/PrsMgr_Presentation2d.cxx @@ -78,3 +78,22 @@ Standard_Integer PrsMgr_Presentation2d::Offset () const { void PrsMgr_Presentation2d::Destroy () { } + +//======================================================================= +//function : SetZLayer +//purpose : +//======================================================================= + +void PrsMgr_Presentation2d::SetZLayer (Standard_Integer theLayer) +{ +} + +//======================================================================= +//function : GetZLayer +//purpose : +//======================================================================= + +Standard_Integer PrsMgr_Presentation2d::GetZLayer () const +{ + return 0; +} diff --git a/src/PrsMgr/PrsMgr_Presentation3d.cdl b/src/PrsMgr/PrsMgr_Presentation3d.cdl index 55491dac79..0030074270 100755 --- a/src/PrsMgr/PrsMgr_Presentation3d.cdl +++ b/src/PrsMgr/PrsMgr_Presentation3d.cdl @@ -58,6 +58,15 @@ is SetDisplayPriority(me:mutable;aNewPrior:Integer from Standard) is redefined static private; + SetZLayer ( me : mutable; + theLayerId : Integer from Standard ) + is redefined static private; + ---Purpose: Set Z layer ID for the presentation + + GetZLayer ( me ) + returns Integer from Standard is redefined static private; + ---Purpose: Get Z layer ID for the presentation + Clear(me:mutable) ---Purpose: removes the whole content of the presentation. -- Does not remove the other connected presentations. diff --git a/src/PrsMgr/PrsMgr_Presentation3d.cxx b/src/PrsMgr/PrsMgr_Presentation3d.cxx index e60c05b6fc..9ce58852b2 100755 --- a/src/PrsMgr/PrsMgr_Presentation3d.cxx +++ b/src/PrsMgr/PrsMgr_Presentation3d.cxx @@ -308,3 +308,23 @@ void PrsMgr_Presentation3d::Destroy () { myStructure->Clear(); myStructure.Nullify(); } + +//======================================================================= +//function : SetZLayer +//purpose : +//======================================================================= + +void PrsMgr_Presentation3d::SetZLayer (Standard_Integer theLayerId) +{ + myStructure->SetZLayer (theLayerId); +} + +//======================================================================= +//function : GetZLayer +//purpose : +//======================================================================= + +Standard_Integer PrsMgr_Presentation3d::GetZLayer () const +{ + return myStructure->GetZLayer (); +} diff --git a/src/PrsMgr/PrsMgr_PresentationManager.cdl b/src/PrsMgr/PrsMgr_PresentationManager.cdl index 61e16aafe2..2d1d7e6088 100755 --- a/src/PrsMgr/PrsMgr_PresentationManager.cdl +++ b/src/PrsMgr/PrsMgr_PresentationManager.cdl @@ -79,6 +79,19 @@ is -- aPresentableObject in this framework with the -- display mode aMode. + SetZLayer ( me : mutable; + thePresentableObject : PresentableObject from PrsMgr; + theLayerId : Integer from Standard ) + is static; + ---Purpose: Set Z layer ID for all presentations of the object. + + GetZLayer ( me; + thePresentableObject : PresentableObject from PrsMgr ) + returns Integer from Standard is static; + ---Purpose: Get Z layer ID assigned to all presentations of the object. + -- Method returns -1 value if object has no presentations and is + -- impossible to get layer index. + IsDisplayed(me;aPresentableObject: PresentableObject from PrsMgr; aMode: Integer from Standard = 0) ---Purpose: Returns true if the presentation of the presentable diff --git a/src/PrsMgr/PrsMgr_PresentationManager.cxx b/src/PrsMgr/PrsMgr_PresentationManager.cxx index 70fbd984c4..2f54d59378 100755 --- a/src/PrsMgr/PrsMgr_PresentationManager.cxx +++ b/src/PrsMgr/PrsMgr_PresentationManager.cxx @@ -204,6 +204,12 @@ void PrsMgr_PresentationManager::AddPresentation Handle(PrsMgr_Presentation) P = newPresentation(aPresentableObject); aPresentableObject->Presentations().Append(PrsMgr_ModedPresentation(P,aMode)); aPresentableObject->Fill(this,P,aMode); + + // set layer index accordingly to object's presentations + Standard_Integer aZLayerId = GetZLayer (aPresentableObject); + if (aZLayerId >= 0) + P->SetZLayer (aZLayerId); + P->SetUpdateStatus(Standard_False); } @@ -222,3 +228,39 @@ void PrsMgr_PresentationManager::RemovePresentation(const Handle(PrsMgr_Presenta } } +//======================================================================= +//function : SetZLayer +//purpose : +//======================================================================= + +void PrsMgr_PresentationManager::SetZLayer + (const Handle(PrsMgr_PresentableObject)& thePresentableObject, + const Standard_Integer theLayerId) +{ + PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations(); + for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++) + { + Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation (); + if (aPrs->PresentationManager () == this) + aPrs->SetZLayer (theLayerId); + } +} + +//======================================================================= +//function : GetZLayer +//purpose : +//======================================================================= + +Standard_Integer PrsMgr_PresentationManager::GetZLayer + (const Handle(PrsMgr_PresentableObject)& thePresentableObject) const +{ + PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations(); + for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++) + { + Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation (); + if (aPrs->PresentationManager () == this) + return aPrs->GetZLayer (); + } + + return -1; +} diff --git a/src/SelectMgr/SelectMgr_EntityOwner.cdl b/src/SelectMgr/SelectMgr_EntityOwner.cdl index d75767d82b..e068258ec6 100755 --- a/src/SelectMgr/SelectMgr_EntityOwner.cdl +++ b/src/SelectMgr/SelectMgr_EntityOwner.cdl @@ -134,6 +134,12 @@ is -- Hilight for SelectableObject when the owner is detected. By default -- it always return FALSE. + SetZLayer ( me : mutable; + thePrsMgr : PresentationManager from PrsMgr; + theLayerId : Integer from Standard ) + is virtual; + ---Purpose: Set Z layer ID and update all presentations. + fields mySelectable : SOPtr; diff --git a/src/SelectMgr/SelectMgr_EntityOwner.cxx b/src/SelectMgr/SelectMgr_EntityOwner.cxx index c3984c9c63..cad2fe7809 100755 --- a/src/SelectMgr/SelectMgr_EntityOwner.cxx +++ b/src/SelectMgr/SelectMgr_EntityOwner.cxx @@ -134,3 +134,13 @@ Standard_Boolean SelectMgr_EntityOwner::IsForcedHilight () const { return Standard_False; } + +//======================================================================= +//function : SetZLayer +//purpose : +//======================================================================= +void SelectMgr_EntityOwner::SetZLayer + (const Handle(PrsMgr_PresentationManager)& thePrsMgr, + const Standard_Integer theLayerId) +{ +} diff --git a/src/SelectMgr/SelectMgr_SelectableObject.cdl b/src/SelectMgr/SelectMgr_SelectableObject.cdl index 9d8d5a72d8..f394e6f538 100755 --- a/src/SelectMgr/SelectMgr_SelectableObject.cdl +++ b/src/SelectMgr/SelectMgr_SelectableObject.cdl @@ -26,6 +26,7 @@ uses SequenceOfSelection from SelectMgr, TypeOfPresentation3d from PrsMgr, Presentation from Prs3d, + PresentationManager from PrsMgr, PresentationManager3d from PrsMgr, SequenceOfOwner from SelectMgr, NameOfColor from Quantity, @@ -169,7 +170,17 @@ is GetSelectPresentation( me: mutable; TheMgr: PresentationManager3d from PrsMgr ) returns Presentation from Prs3d is static; - + + SetZLayer ( me : mutable; + thePrsMgr : PresentationManager from PrsMgr; + theLayerId : Integer from Standard ) + is redefined virtual; + ---Purpose: Set Z layer ID and update all presentations of + -- the selectable object. The layer can be set only for displayed object. + -- If all object presentations are removed, the layer ID will be set to + -- default value when computing presentation. The layers mechanism allows + -- drawing objects in higher layers in overlay of objects in lower layers. + fields myselections : SequenceOfSelection is protected; diff --git a/src/SelectMgr/SelectMgr_SelectableObject.cxx b/src/SelectMgr/SelectMgr_SelectableObject.cxx index dec2fc8fac..7bd4402be7 100755 --- a/src/SelectMgr/SelectMgr_SelectableObject.cxx +++ b/src/SelectMgr/SelectMgr_SelectableObject.cxx @@ -307,3 +307,42 @@ Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation( co return mySelectionPrs; } +//======================================================================= +//function : SetZLayer +//purpose : +//======================================================================= +void SelectMgr_SelectableObject::SetZLayer + (const Handle(PrsMgr_PresentationManager)& thePrsMgr, + const Standard_Integer theLayerId) +{ + if (thePrsMgr.IsNull()) + return; + + // update own presentations + PrsMgr_PresentableObject::SetZLayer (thePrsMgr, theLayerId); + + // update selection presentations + if (!mySelectionPrs.IsNull()) + mySelectionPrs->SetZLayer (theLayerId); + + if (!myHilightPrs.IsNull()) + myHilightPrs->SetZLayer (theLayerId); + + // update all entity owner presentations + for (Init (); More () ;Next ()) + { + const Handle(SelectMgr_Selection)& aSel = CurrentSelection(); + for (aSel->Init (); aSel->More (); aSel->Next ()) + { + Handle(Select3D_SensitiveEntity) aEntity = + Handle(Select3D_SensitiveEntity)::DownCast (aSel->Sensitive()); + if (!aEntity.IsNull()) + { + Handle(SelectMgr_EntityOwner) aOwner = + Handle(SelectMgr_EntityOwner)::DownCast (aEntity->OwnerId()); + if (!aOwner.IsNull()) + aOwner->SetZLayer (thePrsMgr, theLayerId); + } + } + } +} diff --git a/src/StdSelect/StdSelect_BRepOwner.cdl b/src/StdSelect/StdSelect_BRepOwner.cdl index 391a2121b5..514fc50dda 100755 --- a/src/StdSelect/StdSelect_BRepOwner.cdl +++ b/src/StdSelect/StdSelect_BRepOwner.cdl @@ -134,6 +134,12 @@ is SetLocation(me:mutable; aLoc : Location from TopLoc) is redefined; ResetLocation(me:mutable) is redefined; + SetZLayer ( me : mutable; + thePrsMgr : PresentationManager from PrsMgr; + theLayerId : Integer from Standard ) + is redefined virtual; + ---Purpose: Set Z layer ID and update all presentations. + fields myPrsSh : Shape from StdSelect; myCurMode : Integer from Standard; diff --git a/src/StdSelect/StdSelect_BRepOwner.cxx b/src/StdSelect/StdSelect_BRepOwner.cxx index 706f5ffb5b..e6e0a0b47d 100755 --- a/src/StdSelect/StdSelect_BRepOwner.cxx +++ b/src/StdSelect/StdSelect_BRepOwner.cxx @@ -89,14 +89,27 @@ void StdSelect_BRepOwner::Hilight(const Handle(PrsMgr_PresentationManager)& PM, myPrsSh.Nullify(); } + // generate new presentable shape if(myPrsSh.IsNull()) myPrsSh = new StdSelect_Shape (myShape); - } - if(myPrsSh.IsNull()) - PM->Highlight(Selectable(),M); + // highlight and set layer + PM->Highlight (myPrsSh, M); + Handle(SelectMgr_SelectableObject) aSel = Selectable(); + if (!aSel.IsNull()) + { + Standard_Integer aLayer = aSel->GetZLayer (PM); + if (aLayer >= 0) + PM->SetZLayer (myPrsSh, aLayer); + } + } else - PM->Highlight(myPrsSh,M); + { + if(myPrsSh.IsNull()) + PM->Highlight(Selectable(),M); + else + PM->Highlight(myPrsSh,M); + } } void StdSelect_BRepOwner::Hilight() @@ -122,20 +135,36 @@ void StdSelect_BRepOwner::HilightWithColor(const Handle(PrsMgr_PresentationManag myPrsSh.Nullify(); } - if(myPrsSh.IsNull()){ - if(HasLocation()){ - TopLoc_Location lbid = Location() * myShape.Location(); - TopoDS_Shape ShBis = myShape.Located(lbid); - myPrsSh = new StdSelect_Shape(ShBis); + // generate new presentable shape + if(myPrsSh.IsNull()) + { + if(HasLocation()) + { + TopLoc_Location lbid = Location() * myShape.Location(); + TopoDS_Shape ShBis = myShape.Located(lbid); + myPrsSh = new StdSelect_Shape(ShBis); } else - myPrsSh = new StdSelect_Shape(myShape); + myPrsSh = new StdSelect_Shape(myShape); + } + + // highlight with color and set layer + PM->Color (myPrsSh, aCol, M); + Handle(SelectMgr_SelectableObject) aSel = Selectable(); + if (!aSel.IsNull()) + { + Standard_Integer aLayer = aSel->GetZLayer (PM); + if (aLayer >= 0) + PM->SetZLayer (myPrsSh, aLayer); } } - if(myPrsSh.IsNull()) - PM->Color(Selectable(),aCol,M); else - PM->Color(myPrsSh,aCol,M); + { + if(myPrsSh.IsNull()) + PM->Color(Selectable(),aCol,M); + else + PM->Color(myPrsSh,aCol,M); + } } void StdSelect_BRepOwner::Unhilight(const Handle(PrsMgr_PresentationManager)& PM, @@ -173,8 +202,8 @@ void StdSelect_BRepOwner::SetLocation(const TopLoc_Location& aLoc) // set the update flag and then recompute myPrsSh on hilighting if (!myPrsSh.IsNull()) myPrsSh->SetToUpdate(); - } + void StdSelect_BRepOwner::ResetLocation() { SelectMgr_EntityOwner::ResetLocation(); @@ -183,5 +212,16 @@ void StdSelect_BRepOwner::ResetLocation() // set the update flag and then recompute myPrsSh on hilighting if (!myPrsSh.IsNull()) myPrsSh->SetToUpdate(); +} +//======================================================================= +//function : SetZLayer +//purpose : +//======================================================================= +void StdSelect_BRepOwner::SetZLayer + (const Handle(PrsMgr_PresentationManager)& thePrsMgr, + const Standard_Integer theLayerId) +{ + if (!myPrsSh.IsNull()) + thePrsMgr->SetZLayer (myPrsSh, theLayerId); } diff --git a/src/V3d/V3d_Viewer.cdl b/src/V3d/V3d_Viewer.cdl index 7873c53b20..44cb6de409 100755 --- a/src/V3d/V3d_Viewer.cdl +++ b/src/V3d/V3d_Viewer.cdl @@ -43,6 +43,7 @@ uses Plane from V3d, ListOfTransient from V3d, ListIteratorOfListOfTransient from TColStd, + SequenceOfInteger from TColStd, TypeOfView from V3d, Vector from Graphic3d, ViewManager from Visual3d, @@ -656,6 +657,31 @@ is ---Purpose: -- Display grid echo at requested point in the view. + AddZLayer ( me : mutable; + theLayerId : in out Integer from Standard ) + returns Boolean from Standard is static; + ---Purpose: Add a new top-level Z layer to all managed views and get + -- its ID as value. The Z layers are controlled entirely + -- by viewer, it is not possible to add a layer to a + -- particular view. The method returns Standard_False if the layer can + -- not be created. The layer mechanism allows to display structures + -- in higher layers in overlay of structures in lower layers. + + RemoveZLayer ( me : mutable; + theLayerId : Integer from Standard ) + returns Boolean from Standard is static; + ---Purpose: Remove Z layer with ID . Method returns + -- Standard_False if the layer can not be removed or doesn't exists. + -- By default, there are always default bottom-level layer that can't + -- be removed. + + GetAllZLayers ( me; + theLayerSeq : out SequenceOfInteger from TColStd ) + is static; + ---Purpose: Return all Z layer ids in sequence ordered by overlay level + -- from lowest layer to highest ( foreground ). The first layer ID + -- in sequence is the default layer that can't be removed. + fields MyViewer: ViewManager from Visual3d ; diff --git a/src/V3d/V3d_Viewer.cxx b/src/V3d/V3d_Viewer.cxx index ea76711aa8..9221549183 100755 --- a/src/V3d/V3d_Viewer.cxx +++ b/src/V3d/V3d_Viewer.cxx @@ -366,3 +366,33 @@ void V3d_Viewer::DelPlane( const Handle(V3d_Plane)& ThePlane ) { MyDefinedPlanes.Remove(ThePlane); } + +//======================================================================= +//function : AddZLayer +//purpose : +//======================================================================= + +Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId) +{ + return MyViewer->AddZLayer (theLayerId); +} + +//======================================================================= +//function : RemoveZLayer +//purpose : +//======================================================================= + +Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId) +{ + return MyViewer->RemoveZLayer (theLayerId); +} + +//======================================================================= +//function : GetAllZLayers +//purpose : +//======================================================================= + +void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const +{ + MyViewer->GetAllZLayers (theLayerSeq); +} diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 8fd42873b7..330784d997 100755 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -4198,6 +4198,71 @@ static Standard_Integer VSegment (Draw_Interpretor& di, return 0; } +//======================================================================= +//function : VObjZLayer +//purpose : Set or get z layer id for presentable object +//======================================================================= + +static Standard_Integer VObjZLayer (Draw_Interpretor& di, + Standard_Integer argc, + const char ** argv) +{ + Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); + if (aContext.IsNull()) + { + di << argv[0] << "Call 'vinit' before!\n"; + return 1; + } + + // get operation + TCollection_AsciiString aOperation; + if (argc >= 2) + aOperation = TCollection_AsciiString (argv [1]); + + // check for correct arguments + if (!(argc == 4 && aOperation.IsEqual ("set")) && + !(argc == 3 && aOperation.IsEqual ("get"))) + { + di << "Usage : " << argv[0] << " set/get object [layerid]\n"; + di << " set - set layer id for interactive object, layerid - z layer id\n"; + di << " get - get layer id of interactive object\n"; + di << " argument layerid should be passed for set operation only\n"; + return 1; + } + + // find object + TCollection_AsciiString aName (argv[2]); + ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); + if (!aMap.IsBound2 (aName)) + { + di << "Use 'vdisplay' before" << "\n"; + return 1; + } + + // find interactive object + Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName); + Handle(AIS_InteractiveObject) anInterObj = + Handle(AIS_InteractiveObject)::DownCast (anObj); + if (anInterObj.IsNull()) + { + di << "Not an AIS interactive object!\n"; + return 1; + } + + // process operation + if (aOperation.IsEqual ("set")) + { + Standard_Integer aLayerId = atoi (argv [3]); + aContext->SetZLayer (anInterObj, aLayerId); + } + else if (aOperation.IsEqual ("get")) + { + di << "Z layer id: " << aContext->GetZLayer (anInterObj); + } + + return 0; +} + //======================================================================= //function : ObjectsCommands //purpose : @@ -4302,4 +4367,8 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) theCommands.Add("vsegment", "vsegment Name PointName PointName", __FILE__, VSegment,group); + + theCommands.Add("vobjzlayer", + "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object", + __FILE__, VObjZLayer, group); } diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index e8a7808ac0..778c786c6e 100755 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #ifndef WNT #include @@ -2060,6 +2061,86 @@ static int VPrintView (Draw_Interpretor& di, Standard_Integer argc, #endif } +//============================================================================== +//function : VZLayer +//purpose : Test z layer operations for v3d viewer +//============================================================================== +static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) +{ + Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext (); + if (aContextAIS.IsNull()) + { + di << "Call vinit before!\n"; + return 1; + } + else if (argc < 2) + { + di << "Use: vzlayer " << argv[0]; + di << " add/del/get [id]\n"; + di << " add - add new z layer to viewer and print its id\n"; + di << " del - del z layer by its id\n"; + di << " get - print sequence of z layers in increasing order of their overlay level\n"; + di << "id - the layer identificator value defined when removing z layer\n"; + return 1; + } + + const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); + if (aViewer.IsNull()) + { + di << "No active viewer!\n"; + return 1; + } + + // perform operation + TCollection_AsciiString anOp = TCollection_AsciiString (argv[1]); + if (anOp == "add") + { + Standard_Integer aNewId; + if (!aViewer->AddZLayer (aNewId)) + { + di << "Impossible to add new z layer!\n"; + return 1; + } + + di << "New z layer added with index: " << aNewId << "\n"; + } + else if (anOp == "del") + { + if (argc < 3) + { + di << "Please also provide as argument id of z layer to remove\n"; + return 1; + } + + Standard_Integer aDelId = atoi (argv[2]); + if (!aViewer->RemoveZLayer (aDelId)) + { + di << "Impossible to remove the z layer or invalid id!\n"; + return 1; + } + + di << "Z layer " << aDelId << " has been removed\n"; + } + else if (anOp == "get") + { + TColStd_SequenceOfInteger anIds; + aViewer->GetAllZLayers (anIds); + for (Standard_Integer aSeqIdx = 1; aSeqIdx <= anIds.Length(); aSeqIdx++) + { + di << anIds.Value (aSeqIdx) << " "; + } + + di << "\n"; + } + else + { + di << "Invalid operation, please use { add / del / get }\n"; + return 1; + } + + return 0; +} + //======================================================================= //function : ViewerCommands //purpose : @@ -2140,5 +2221,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) theCommands.Add("vprintview" , "vprintview : width height filename [algo=0] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile", __FILE__,VPrintView,group); - + theCommands.Add("vzlayer", + "vzlayer : add/del/get [id] : Z layer operations in v3d viewer: add new z layer, delete z layer, get z layer ids", + __FILE__,VZLayer,group); } diff --git a/src/Visual3d/Visual3d_View.cdl b/src/Visual3d/Visual3d_View.cdl index 476e1cb00b..659a49135c 100755 --- a/src/Visual3d/Visual3d_View.cdl +++ b/src/Visual3d/Visual3d_View.cdl @@ -887,6 +887,27 @@ is ---Purpose: Changes the display priority of the structure . ---Category: Private methods + AddZLayer ( me : mutable; + theLayerId : Integer from Standard ) + is static private; + ---Purpose: Add a new top-level Z layer to the view with ID + -- . The z layer mechanism allows to display + -- structures in higher layers in overlay of structures in lower layers. + -- The layers in a particular view should be managed centrally + -- by its view manager so to avoid IDs mismatching and provide correct + -- display of graphics in all views. + + RemoveZLayer ( me : mutable; + theLayerId : Integer from Standard ) + is static private; + ---Purpose: Remove z layer from the view by its ID. + + ChangeZLayer ( me : mutable; + theStructure : Structure from Graphic3d; + theLayerId : Integer from Standard ) + is static private; + ---Purpose: Change Z layer of already displayed structure in the view. + Clear ( me : mutable; AStructure : Structure from Graphic3d; WithDestruction : Boolean from Standard ) diff --git a/src/Visual3d/Visual3d_View.cxx b/src/Visual3d/Visual3d_View.cxx index 2be25e2d88..c49f9bb513 100755 --- a/src/Visual3d/Visual3d_View.cxx +++ b/src/Visual3d/Visual3d_View.cxx @@ -4311,3 +4311,35 @@ Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer, thePrecision, theProgressBarFunc, theProgressObject); } + +//======================================================================= +//function : AddZLayer +//purpose : +//======================================================================= + +void Visual3d_View::AddZLayer (const Standard_Integer theLayerId) +{ + MyGraphicDriver->AddZLayer (MyCView, theLayerId); +} + +//======================================================================= +//function : RemoveZLayer +//purpose : +//======================================================================= + +void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId) +{ + MyGraphicDriver->RemoveZLayer (MyCView, theLayerId); +} + +//======================================================================= +//function : ChangeZLayer +//purpose : +//======================================================================= + +void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, + const Standard_Integer theLayerId) +{ + MyGraphicDriver->ChangeZLayer ( + (*(Graphic3d_CStructure*)theStructure->CStructure()), MyCView, theLayerId); +} diff --git a/src/Visual3d/Visual3d_ViewManager.cdl b/src/Visual3d/Visual3d_ViewManager.cdl index 28451b4cf6..540f2e2632 100755 --- a/src/Visual3d/Visual3d_ViewManager.cdl +++ b/src/Visual3d/Visual3d_ViewManager.cdl @@ -18,6 +18,8 @@ class ViewManager from Visual3d inherits StructureManager from Graphic3d uses Array2OfReal from TColStd, + SequenceOfInteger from TColStd, + MapOfInteger from TColStd, GenId from Aspect, GraphicDevice from Aspect, @@ -275,6 +277,48 @@ is ---Purpose: Changes the display priority of the structure . ---Category: Private methods + ChangeZLayer ( me : mutable; + theStructure : Structure from Graphic3d; + theLayerId : Integer from Standard ) + is redefined static; + ---Purpose: Change Z layer for structure. The layer mechanism allows + -- to display structures in higher layers in overlay of structures in + -- lower layers. + + GetZLayer ( me; + theStructure : Structure from Graphic3d ) + returns Integer from Standard is redefined static; + ---Purpose: Get Z layer ID assigned for the structure. + + AddZLayer ( me : mutable; + theLayerId : in out Integer from Standard ) + returns Boolean from Standard is redefined static; + ---Purpose: Add a new top-level Z layer and get its ID as + -- value. The method returns Standard_False if the layer + -- can not be created. The layer mechanism allows to display + -- structures in higher layers in overlay of structures in lower layers. + + RemoveZLayer ( me : mutable; + theLayerId : Integer from Standard ) + returns Boolean from Standard is redefined static; + ---Purpose: Remove Z layer with ID . Method returns + -- Standard_False if the layer can not be removed or doesn't exists. + -- By default, there are always default bottom-level layer that can't + -- be removed. + + GetAllZLayers ( me; + theLayerSeq : out SequenceOfInteger from TColStd ) + is redefined static; + ---Purpose: Return all Z layer ids in sequence ordered by overlay level + -- from lowest layer to highest ( foreground ). The first layer ID + -- in sequence is the default layer that can't be removed. + + getZLayerGenId ( myclass ) + ---Purpose: Returns global instance of z layer ids generator. + ---C++: return & + returns GenId from Aspect is protected; + + Clear ( me : mutable; AStructure : Structure from Graphic3d; WithDestruction : Boolean from Standard ) @@ -431,7 +475,7 @@ is -- is managed automatically. -- Default Standard_False ---Category: Internal methods --- +-- fields @@ -460,6 +504,10 @@ fields MyZBufferAuto : Boolean from Standard; MyTransparency : Boolean from Standard; + -- Z layer indexes + myLayerIds : MapOfInteger from TColStd; + myLayerSeq : SequenceOfInteger from TColStd; + friends class View from Visual3d, diff --git a/src/Visual3d/Visual3d_ViewManager.cxx b/src/Visual3d/Visual3d_ViewManager.cxx index 8330001a7e..3c90fcb2dd 100755 --- a/src/Visual3d/Visual3d_ViewManager.cxx +++ b/src/Visual3d/Visual3d_ViewManager.cxx @@ -48,6 +48,7 @@ #include #include +#include #include #include @@ -81,11 +82,14 @@ MyViewGenId (View_IDMIN+((View_IDMIN+View_IDMAX)/(Visual3d_ViewManager::Limit () MyZBufferAuto (Standard_False), MyTransparency (Standard_False) { + // default layer is always presented in display layer sequence + // it can not be removed + myLayerIds.Add (0); + myLayerSeq.Append (0); -Handle(Aspect_GraphicDriver) agd = aDevice->GraphicDriver (); - - MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd; + Handle(Aspect_GraphicDriver) agd = aDevice->GraphicDriver (); + MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd; } //-Destructors @@ -1339,3 +1343,120 @@ const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const { return (MyOverLayer); } + +//======================================================================= +//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; +} -- 2.20.1