Salome HOME
Fit All after was added stream selection and displaying in embedded viewer.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZLayers.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <HYDROGUI_ZLayers.h>
24 #include <PrsMgr_PresentableObject.hxx>
25 #include <PrsMgr_ModedPresentation.hxx>
26 #include <TColStd_SequenceOfInteger.hxx>
27
28 void SetZLayerForPrs( const Handle(PrsMgr_Presentation)& thePrs, int theLayerId );
29
30 void SetPrsZLayer( const Handle_PrsMgr_PresentableObject& thePresentableObject,
31                    const int theMode, const int theLayerId )
32 {
33   PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
34   for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
35   {
36     Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation ();
37     if ( aPresentations (aIdx).Mode() == theMode )
38     {
39       SetZLayerForPrs( aPrs, theLayerId );
40     }
41   }
42 }
43
44 void SetZLayerSettings( const Handle_V3d_Viewer& theViewer3d, int theLayerId, bool theIsOrdered )
45 {
46   if ( theViewer3d.IsNull() || theLayerId < 0 ) {
47     return;
48   }
49
50   Graphic3d_ZLayerSettings aSettings = theViewer3d->ZLayerSettings( theLayerId );
51   // enable depth write
52   aSettings.EnableSetting( Graphic3d_ZLayerDepthWrite );
53   // disable depth clear
54   aSettings.DisableSetting( Graphic3d_ZLayerDepthClear );
55   if ( theIsOrdered ) {
56     // disable depth test
57     aSettings.DisableSetting( Graphic3d_ZLayerDepthTest );
58     // disable depth offset
59     aSettings.DisableSetting( Graphic3d_ZLayerDepthOffset );
60   } else {
61     // enable depth test
62     aSettings.EnableSetting( Graphic3d_ZLayerDepthTest );
63     // set depth offset
64     aSettings.SetDepthOffsetPositive();
65   }
66
67   // set new settings
68   theViewer3d->SetZLayerSettings( theLayerId, aSettings );
69 }
70
71 int CreateTopZLayer( const Handle_V3d_Viewer& theViewer3d )
72 {
73   int aTopZLayer = -1;
74
75   if ( theViewer3d && !theViewer3d->AddZLayer( aTopZLayer ) ) {
76     aTopZLayer = -1;
77   }
78
79   return aTopZLayer;
80 }
81
82
83 HYDROGUI_ZLayersIterator::HYDROGUI_ZLayersIterator( const Handle_V3d_Viewer& theViewer )
84   : myIndex( 0 ), myNewZLayer( -1 ), myViewer( theViewer )
85 {
86   Init( theViewer );
87 }
88
89 HYDROGUI_ZLayersIterator::~HYDROGUI_ZLayersIterator()
90 {
91 }
92
93 void HYDROGUI_ZLayersIterator::Init( const Handle_V3d_Viewer& theViewer )
94 {
95   TColStd_SequenceOfInteger anExistingZLayers;
96   theViewer->GetAllZLayers( anExistingZLayers );
97   
98   int n = anExistingZLayers.Length();
99   myZLayers.resize( n );
100   for( int i=1; i<=n; i++ )
101     myZLayers[i-1] = anExistingZLayers( i );
102
103   myIndex = 0;
104 }
105
106 bool HYDROGUI_ZLayersIterator::More() const
107 {
108   return myIndex < (int)myZLayers.size() || myNewZLayer >= 0;
109 }
110
111 void HYDROGUI_ZLayersIterator::Next()
112 {
113   myIndex++;
114
115   if( myIndex >= (int)myZLayers.size() && 
116       !myViewer.IsNull() ) {
117     myNewZLayer = CreateTopZLayer( myViewer );
118   }
119 }
120
121 int HYDROGUI_ZLayersIterator::TopLayer() const
122 {
123   int aTopLayer = -1;
124
125   if ( myNewZLayer >= 0 ) {
126     aTopLayer = myNewZLayer;
127   } else if ( !myZLayers.empty() ) {
128     aTopLayer = myZLayers.back();
129   }
130
131   return aTopLayer;
132 }
133
134
135 int HYDROGUI_ZLayersIterator::LayerId() const
136 {
137   if( myIndex < (int)myZLayers.size() )
138     return myZLayers[myIndex];
139   else
140     return myNewZLayer;
141 }