1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROGUI_ZLayers.h>
20 #include <PrsMgr_PresentableObject.hxx>
21 #include <PrsMgr_ModedPresentation.hxx>
22 #include <TColStd_SequenceOfInteger.hxx>
24 void SetZLayerForPrs( const Handle(PrsMgr_Presentation)& thePrs, int theLayerId );
26 void SetPrsZLayer( const Handle_PrsMgr_PresentableObject& thePresentableObject,
27 const int theMode, const int theLayerId )
29 PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
30 for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
32 Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation ();
33 if ( aPresentations (aIdx).Mode() == theMode )
35 SetZLayerForPrs( aPrs, theLayerId );
40 void SetZLayerSettings( const Handle_V3d_Viewer& theViewer3d, int theLayerId, bool theIsOrdered )
42 if ( theViewer3d.IsNull() || theLayerId < 0 ) {
46 Graphic3d_ZLayerSettings aSettings = theViewer3d->ZLayerSettings( theLayerId );
48 aSettings.EnableSetting( Graphic3d_ZLayerDepthWrite );
49 // disable depth clear
50 aSettings.DisableSetting( Graphic3d_ZLayerDepthClear );
53 aSettings.DisableSetting( Graphic3d_ZLayerDepthTest );
54 // disable depth offset
55 aSettings.DisableSetting( Graphic3d_ZLayerDepthOffset );
58 aSettings.EnableSetting( Graphic3d_ZLayerDepthTest );
60 aSettings.SetDepthOffsetPositive();
64 theViewer3d->SetZLayerSettings( theLayerId, aSettings );
67 int CreateTopZLayer( const Handle_V3d_Viewer& theViewer3d )
71 if ( theViewer3d && !theViewer3d->AddZLayer( aTopZLayer ) ) {
79 HYDROGUI_ZLayersIterator::HYDROGUI_ZLayersIterator( const Handle_V3d_Viewer& theViewer )
80 : myIndex( 0 ), myNewZLayer( -1 ), myViewer( theViewer )
85 HYDROGUI_ZLayersIterator::~HYDROGUI_ZLayersIterator()
89 void HYDROGUI_ZLayersIterator::Init( const Handle_V3d_Viewer& theViewer )
91 TColStd_SequenceOfInteger anExistingZLayers;
92 theViewer->GetAllZLayers( anExistingZLayers );
94 int n = anExistingZLayers.Length();
95 myZLayers.resize( n );
96 for( int i=1; i<=n; i++ )
97 myZLayers[i-1] = anExistingZLayers( i );
102 bool HYDROGUI_ZLayersIterator::More() const
104 return myIndex < (int)myZLayers.size() || myNewZLayer >= 0;
107 void HYDROGUI_ZLayersIterator::Next()
111 if( myIndex >= (int)myZLayers.size() &&
112 !myViewer.IsNull() ) {
113 myNewZLayer = CreateTopZLayer( myViewer );
117 int HYDROGUI_ZLayersIterator::TopLayer() const
121 if ( myNewZLayer >= 0 ) {
122 aTopLayer = myNewZLayer;
123 } else if ( !myZLayers.empty() ) {
124 aTopLayer = myZLayers.back();
131 int HYDROGUI_ZLayersIterator::LayerId() const
133 if( myIndex < (int)myZLayers.size() )
134 return myZLayers[myIndex];