Statistics
| Revision:

gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.lib / org.gvsig.gvsig3d.lib.impl / src / main / java / org / gvsig / gvsig3d / impl / map3d / Layer3DPropsImpl.java @ 324

History | View | Annotate | Download (9.01 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program 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
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.gvsig3d.impl.map3d;
23

    
24
import org.gvsig.fmap.mapcontext.layers.FLayer;
25
import org.gvsig.gvsig3d.map3d.Layer3DProps;
26
import org.gvsig.osgvp.terrain.Layer;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.dynobject.DelegatedDynObject;
29
import org.gvsig.tools.dynobject.DynClass;
30
import org.gvsig.tools.dynobject.DynStruct;
31
import org.gvsig.tools.persistence.PersistenceManager;
32
import org.gvsig.tools.persistence.Persistent;
33
import org.gvsig.tools.persistence.PersistentState;
34
import org.gvsig.tools.persistence.exception.PersistenceException;
35
import org.gvsig.tools.util.Callable;
36

    
37
/**
38
 * @author gvSIG Team
39
 * @version $Id$
40
 * 
41
 */
42
public class Layer3DPropsImpl implements Layer3DProps, Persistent {
43

    
44
        public static final String PARAMETERS_DEFINITION_NAME = "Layer3DPropsImpl";
45

    
46
        public static final String OPACITY = "opacity";
47

    
48
        public static final String VERTICAL_EX = "verticalExageration";
49

    
50
        public static final String HEIGHT = "height";
51

    
52
        public static final String TYPE = "type";
53

    
54
        public static final String TERRAIN_LAYER = "terrainLayer";
55

    
56
        public static final String LAYER = "layer";
57

    
58
        public static final String EDITING = "editing";
59

    
60
        private static final String FIELD_DESCRIPTION = "description";
61
        
62
        private static final String BAND_ELEVATION = "bandElevation";
63

    
64
        private long drawVersion = 0;
65

    
66
        private boolean newLayerOSG = false;
67

    
68
        protected float _opacity = 1.0f; // Opacity of layer default 1.0
69
        protected float _verticalEx = 1.0f; // Opacity of layer default 1.0
70
        protected int _bandElev = 0;
71
        protected float _height = 5; // Opacity of layer default 1.0
72
        protected int _type; // see type enumeration above
73

    
74
        protected Layer _terrainLayer;
75

    
76
        protected FLayer _layer;
77

    
78
        protected String _cacheName = "default";
79

    
80
        private boolean _bChooseType = true;
81

    
82
        private boolean _zEnable = false;
83

    
84
        // used by FLayers3D (3D group layer) to flag when they are actually hooked
85
        // to TOC or not
86
        private boolean _hooked = false;
87

    
88
        private boolean isEditing = false;
89

    
90
        private int option;
91

    
92
        private DelegatedDynObject _delegatedDynObject = null;
93

    
94
        private String _description = "";
95

    
96
        protected static DynClass DYNCLASS = null;
97

    
98
        public Layer3DPropsImpl() {
99

    
100
        }
101

    
102
        public Layer3DPropsImpl(FLayer layer) {
103

    
104
                _layer = layer;
105

    
106
        }
107

    
108
        // private VectorLayerMenu vectorLayerMenu;
109

    
110
        // TRY TO NOT USE STATIC METHODS. PROBLEMS WITH API/IMPL SEPARATION
111
        // public static Layer3DProps getLayer3DProps(FLayer layer) {
112
        // FLyrDefault baseLayer = (FLyrDefault) layer;
113
        // Object propsObj = baseLayer.getProperty("3DLayerExtension");
114
        // Layer3DPropsImpl props3D = null;
115
        // if (propsObj != null) {
116
        // try {
117
        // props3D = (Layer3DPropsImpl) propsObj;
118
        // if (props3D.drawVersion == 0)
119
        // props3D.drawVersion = layer.getDrawVersion();
120
        // } catch (Exception e) {
121
        // props3D = null;
122
        // }
123
        // }
124
        // return props3D;
125
        // }
126

    
127
        public String getClassName() {
128
                return this.getClass().getName();
129
        }
130

    
131
        public float getHeight() {
132
                return _height;
133
        }
134

    
135
        public boolean getHooked() {
136
                return _hooked;
137
        }
138

    
139
        public float getOpacity() {
140
                return _opacity;
141
        }
142

    
143
        public Layer getTerrainLayer() {
144
                return _terrainLayer;
145
        }
146

    
147
        public int getType() {
148
                return _type;
149
        }
150

    
151
        public float getVerticalEx() {
152
                return _verticalEx;
153
        }
154
        
155
        public int getElevationBand(){
156
                
157
                return _bandElev;
158
        }
159

    
160
        public boolean isEditing() {
161
                return isEditing;
162
        }
163

    
164
        public boolean isNewLayerOSG() {
165
                return newLayerOSG;
166
        }
167

    
168
        public boolean isZEnable() {
169
                return _zEnable;
170
        }
171

    
172
        public void setChooseType(boolean bChoose) {
173
                _bChooseType = bChoose;
174

    
175
        }
176

    
177
        public void setDescription(String desc) {
178
                this._description = desc;
179
        }
180

    
181
        public String getDescription() {
182
                return _description;
183
        }
184

    
185
        public void setEditing(boolean isEditing) {
186
                this.isEditing = isEditing;
187

    
188
        }
189

    
190
        public void setHeight(float heigth) {
191
                this._height = heigth;
192

    
193
        }
194

    
195
        public void setHooked(boolean hooked) {
196
                _hooked = hooked;
197
        }
198

    
199
        public void setLayer(FLayer layer) {
200
                if (_layer == layer)
201
                        return;
202

    
203
                _layer = layer;
204

    
205
                // find out data type
206
                if (_bChooseType) {
207
                        _bChooseType = false;
208
                        _type = layer3DImage;
209
                        boolean bCanBeElev = false;
210

    
211
                        // if (layer instanceof FLyrWMS) {
212
                        // FLyrWMS wmsLayer = (FLyrWMS) layer;
213
                        // String format = wmsLayer.getFormat();
214
                        // if (format.regionMatches(true, 0, "image/geotiff", 0, 13)
215
                        // || format.regionMatches(true, 0, "image/tiff", 0, 10))
216
                        // bCanBeElev = true;
217
                        // } else
218
                        // if (layer instanceof FLyrWCS) {
219
                        // FLyrWCS wcsLayer = (FLyrWCS) layer;
220
                        // Hashtable props = wcsLayer.getProperties();
221
                        // String format = (String) props.get("format");
222
                        // String params = (String) props.get("parameter");
223
                        // if (format.compareToIgnoreCase("GEOTIFF_INT16") == 0
224
                        // && params.compareToIgnoreCase("bands=1") == 0)
225
                        // bCanBeElev = true;
226
                        // }
227
                        // FEATURES
228
                        // else /**/if (layer instanceof ClassifiableVectorial) {
229
                        //
230
                        // if (this.getType() != layer3DOSG) {
231
                        // vectorLayerMenu = new VectorLayerMenu(this, layer.getName());
232
                        // vectorLayerMenu.setModal(true);
233
                        // vectorLayerMenu.pack();
234
                        // vectorLayerMenu.setVisible(true);
235
                        // }
236
                        //
237
                        // } else if (layer instanceof FLyrRasterSE) {
238
                        // FLyrRasterSE rasterLayer = (FLyrRasterSE) layer;
239
                        // if (rasterLayer.getBandCount() == 1)
240
                        // bCanBeElev = true;
241
                        //
242
                        // }
243
                        //
244
                        // if (_type == layer3DImage && bCanBeElev) {
245
                        // option = JOptionPane.showConfirmDialog(
246
                        // (Component) PluginServices.getMainFrame(),
247
                        // PluginServices
248
                        // .getText(this, "Elevation_layer_question"),
249
                        // PluginServices.getText(this, "Layer_options"),
250
                        // JOptionPane.YES_NO_OPTION);
251
                        //
252
                        // if (option == JOptionPane.YES_OPTION) {
253
                        // _type = layer3DElevation;
254
                        // }
255
                        // }
256
                }
257

    
258
        }
259

    
260
        public void setNewLayerOSG(boolean newLayerOSG) {
261
                this.newLayerOSG = newLayerOSG;
262

    
263
        }
264

    
265
        public void setOpacity(float mOpacity) {
266
                this._opacity = mOpacity;
267

    
268
        }
269

    
270
        public void setTerrainLayer(Layer terrainLayer) {
271
                _terrainLayer = terrainLayer;
272

    
273
        }
274

    
275
        public void setType(int type) {
276
                _type = type;
277
                //We need to persist in the layer properties if the layer is rasterized or not.
278
                _layer.setProperty("layerType", type);
279
        }
280

    
281
        public void setVerticalEx(float ex) {
282
                _verticalEx = ex;
283

    
284
        }
285
        
286
        public void setElevationBand(int band){
287
                
288
                _bandElev = band;
289
                
290
        }
291

    
292
        public void setZEnable(boolean zEnable) {
293
                _zEnable = zEnable;
294

    
295
        }
296

    
297
        public void setDrawVersion(long version) {
298
                drawVersion = version;
299

    
300
        }
301

    
302
        public long getDrawVersion() {
303

    
304
                return drawVersion;
305
        }
306

    
307
        public void loadFromState(PersistentState state)
308
                        throws PersistenceException {
309
                // setDescription(state.getString(FIELD_DESCRIPTION));
310
                _opacity = state.getFloat(OPACITY);
311
                _verticalEx = state.getFloat(VERTICAL_EX);
312
                _height = state.getFloat(HEIGHT);
313
                _type = state.getInt(TYPE);
314
//                _terrainLayer = (Layer) state.get(TERRAIN_LAYER);
315
                _layer = (FLayer) state.get(LAYER);
316
                isEditing = state.getBoolean(EDITING);
317

    
318
        }
319

    
320
        public void saveToState(PersistentState state) throws PersistenceException {
321
                // state.set(FIELD_DESCRIPTION, getDescription());
322
                state.set(OPACITY, _opacity);
323
                state.set(VERTICAL_EX, _verticalEx);
324
                state.set(HEIGHT, _height);
325
                state.set(TYPE, _type);
326
//                if (_terrainLayer != null)
327
//                        state.set(TERRAIN_LAYER, _terrainLayer);
328
                if (_layer != null)
329
                        state.set(LAYER, _layer);
330
                state.set(EDITING, isEditing);
331
        }
332

    
333
        public static class RegisterPersistence implements Callable {
334

    
335
                public Object call() throws Exception {
336
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
337
                        if (manager.getDefinition(PARAMETERS_DEFINITION_NAME) == null) {
338
                                DynStruct definition = manager.addDefinition(
339
                                                Layer3DPropsImpl.class, PARAMETERS_DEFINITION_NAME,
340
                                                PARAMETERS_DEFINITION_NAME + " Persistence definition",
341
                                                null, null);
342
                                // Description
343
                                definition.addDynFieldFloat(OPACITY).setMandatory(false);
344
                                definition.addDynFieldFloat(VERTICAL_EX).setMandatory(false);
345
                                definition.addDynFieldFloat(HEIGHT).setMandatory(false);
346
                                definition.addDynFieldInt(TYPE).setMandatory(false);
347
//                                definition.addDynFieldObject(TERRAIN_LAYER)
348
//                                                .setClassOfValue(Layer.class).setMandatory(false);
349
                                definition.addDynFieldObject(LAYER)
350
                                                .setClassOfValue(FLayer.class).setMandatory(false);
351
                                definition.addDynFieldBoolean(EDITING).setMandatory(false);
352

    
353
                        }
354
                        return Boolean.TRUE;
355
                }
356

    
357
        }
358

    
359
}