Salome HOME
write dbf with Hydro shapefiles, attribute string "PartName" with polyline name
[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_Presentations.hxx>
22 #include <TColStd_SequenceOfInteger.hxx>
23 #include <Graphic3d_ZLayerId.hxx>
24
25 void SetZLayerForPrs( const Handle(PrsMgr_Presentation)& thePrs, int theLayerId );
26
27 void SetPrsZLayer( const Handle(PrsMgr_PresentableObject)& thePresentableObject,
28                    const int theMode, const int theLayerId )
29 {
30   PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
31   for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
32   {
33     Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx);
34     if ( aPrs->Mode() == theMode )
35     {
36       SetZLayerForPrs( aPrs, theLayerId );
37     }
38   }
39 }
40
41 void SetZLayerSettings( const Handle(V3d_Viewer)& theViewer3d, int theLayerId, bool theIsOrdered )
42 {
43   if ( theViewer3d.IsNull() /*|| theLayerId < 0*/ )
44   {
45     return;
46   }
47
48   Graphic3d_ZLayerSettings aSettings = theViewer3d->ZLayerSettings( theLayerId );
49   // enable depth write
50   aSettings.EnableSetting( Graphic3d_ZLayerDepthWrite );
51   // disable depth clear
52   aSettings.DisableSetting( Graphic3d_ZLayerDepthClear );
53   if ( theIsOrdered ) {
54     // disable depth test
55     aSettings.DisableSetting( Graphic3d_ZLayerDepthTest );
56     // disable depth offset
57     aSettings.DisableSetting( Graphic3d_ZLayerDepthOffset );
58   } else {
59     // enable depth test
60     aSettings.EnableSetting( Graphic3d_ZLayerDepthTest );
61     // set depth offset
62     aSettings.SetDepthOffsetPositive();
63   }
64
65   // set new settings
66   theViewer3d->SetZLayerSettings( theLayerId, aSettings );
67 }
68
69 int CreateTopZLayer( const Handle(V3d_Viewer)& theViewer3d )
70 {
71   int aTopZLayer = Graphic3d_ZLayerId_Top;
72
73   if ( theViewer3d && !theViewer3d->AddZLayer( aTopZLayer ) ) {
74     aTopZLayer = Graphic3d_ZLayerId_Top;
75   }
76
77   return aTopZLayer;
78 }
79
80
81 HYDROGUI_ZLayersIterator::HYDROGUI_ZLayersIterator( const Handle(V3d_Viewer)& theViewer )
82   : myIndex( 0 ), myNewZLayer( Graphic3d_ZLayerId_Top ), myViewer( theViewer )
83 {
84   Init( theViewer );
85 }
86
87 HYDROGUI_ZLayersIterator::~HYDROGUI_ZLayersIterator()
88 {
89 }
90
91 void HYDROGUI_ZLayersIterator::Init( const Handle(V3d_Viewer)& theViewer )
92 {
93   TColStd_SequenceOfInteger anExistingZLayers;
94   theViewer->GetAllZLayers( anExistingZLayers );
95
96   int n = anExistingZLayers.Length();
97   for( int i=1; i<=n; i++ ) {
98     int aLayerId = anExistingZLayers( i );
99     if ( aLayerId >= 0 ) {
100       myZLayers.push_back( aLayerId );
101     }
102   }
103
104   myIndex = 0;
105 }
106
107 bool HYDROGUI_ZLayersIterator::More() const
108 {
109   return myIndex < (int)myZLayers.size() || myNewZLayer >= 0;
110 }
111
112 void HYDROGUI_ZLayersIterator::Next()
113 {
114   myIndex++;
115
116   if( myIndex >= (int)myZLayers.size() &&
117       !myViewer.IsNull() ) {
118     myNewZLayer = CreateTopZLayer( myViewer );
119   }
120 }
121
122 int HYDROGUI_ZLayersIterator::TopLayer() const
123 {
124   int aTopLayer = Graphic3d_ZLayerId_Top;
125
126   if ( myNewZLayer >= 0 ) {
127     aTopLayer = myNewZLayer;
128   } else if ( !myZLayers.empty() ) {
129     aTopLayer = myZLayers.back();
130   }
131
132   return aTopLayer;
133 }
134
135
136 int HYDROGUI_ZLayersIterator::LayerId() const
137 {
138   if( myIndex < (int)myZLayers.size() )
139     return myZLayers[myIndex];
140   else
141     return myNewZLayer;
142 }