Salome HOME
epaisseur des polylignes = 2
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZLayers.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROGUI_ZLayers.h>
20 #include <PrsMgr_PresentableObject.hxx>
21 #include <PrsMgr_ModedPresentation.hxx>
22 #include <TColStd_SequenceOfInteger.hxx>
23
24 void SetZLayerForPrs( const Handle(PrsMgr_Presentation)& thePrs, int theLayerId );
25
26 void SetPrsZLayer( const Handle_PrsMgr_PresentableObject& thePresentableObject,
27                    const int theMode, const int theLayerId )
28 {
29   PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
30   for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
31   {
32     Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation ();
33     if ( aPresentations (aIdx).Mode() == theMode )
34     {
35       SetZLayerForPrs( aPrs, theLayerId );
36     }
37   }
38 }
39
40 void SetZLayerSettings( const Handle_V3d_Viewer& theViewer3d, int theLayerId, bool theIsOrdered )
41 {
42   if ( theViewer3d.IsNull() /*|| theLayerId < 0*/ )
43   {
44     return;
45   }
46
47   Graphic3d_ZLayerSettings aSettings = theViewer3d->ZLayerSettings( theLayerId );
48   // enable depth write
49   aSettings.EnableSetting( Graphic3d_ZLayerDepthWrite );
50   // disable depth clear
51   aSettings.DisableSetting( Graphic3d_ZLayerDepthClear );
52   if ( theIsOrdered ) {
53     // disable depth test
54     aSettings.DisableSetting( Graphic3d_ZLayerDepthTest );
55     // disable depth offset
56     aSettings.DisableSetting( Graphic3d_ZLayerDepthOffset );
57   } else {
58     // enable depth test
59     aSettings.EnableSetting( Graphic3d_ZLayerDepthTest );
60     // set depth offset
61     aSettings.SetDepthOffsetPositive();
62   }
63
64   // set new settings
65   theViewer3d->SetZLayerSettings( theLayerId, aSettings );
66 }
67
68 int CreateTopZLayer( const Handle_V3d_Viewer& theViewer3d )
69 {
70   int aTopZLayer = -1;
71
72   if ( theViewer3d && !theViewer3d->AddZLayer( aTopZLayer ) ) {
73     aTopZLayer = -1;
74   }
75
76   return aTopZLayer;
77 }
78
79
80 HYDROGUI_ZLayersIterator::HYDROGUI_ZLayersIterator( const Handle_V3d_Viewer& theViewer )
81   : myIndex( 0 ), myNewZLayer( -1 ), myViewer( theViewer )
82 {
83   Init( theViewer );
84 }
85
86 HYDROGUI_ZLayersIterator::~HYDROGUI_ZLayersIterator()
87 {
88 }
89
90 void HYDROGUI_ZLayersIterator::Init( const Handle_V3d_Viewer& theViewer )
91 {
92   TColStd_SequenceOfInteger anExistingZLayers;
93   theViewer->GetAllZLayers( anExistingZLayers );
94   
95   int n = anExistingZLayers.Length();
96   for( int i=1; i<=n; i++ ) {
97     int aLayerId = anExistingZLayers( i );
98     if ( aLayerId >= 0 ) {
99       myZLayers.push_back( aLayerId );
100     }
101   }
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 }