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 @ 332

History | View | Annotate | Download (9.22 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
        private boolean _isGeometryDirty = false ;
85
        
86
        // used by FLayers3D (3D group layer) to flag when they are actually hooked
87
        // to TOC or not
88
        private boolean _hooked = false;
89

    
90
        private boolean isEditing = false;
91

    
92
        private int option;
93

    
94
        private DelegatedDynObject _delegatedDynObject = null;
95

    
96
        private String _description = "";
97

    
98
        protected static DynClass DYNCLASS = null;
99

    
100
        public Layer3DPropsImpl() {
101

    
102
        }
103

    
104
        public Layer3DPropsImpl(FLayer layer) {
105

    
106
                _layer = layer;
107

    
108
        }
109

    
110
        // private VectorLayerMenu vectorLayerMenu;
111

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

    
129
        public String getClassName() {
130
                return this.getClass().getName();
131
        }
132

    
133
        public float getHeight() {
134
                return _height;
135
        }
136

    
137
        public boolean getHooked() {
138
                return _hooked;
139
        }
140

    
141
        public float getOpacity() {
142
                return _opacity;
143
        }
144

    
145
        public Layer getTerrainLayer() {
146
                return _terrainLayer;
147
        }
148

    
149
        public int getType() {
150
                return _type;
151
        }
152

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

    
162
        public boolean isEditing() {
163
                return isEditing;
164
        }
165

    
166
        public boolean isNewLayerOSG() {
167
                return newLayerOSG;
168
        }
169

    
170
        public boolean isZEnable() {
171
                return _zEnable;
172
        }
173

    
174
        public void setChooseType(boolean bChoose) {
175
                _bChooseType = bChoose;
176

    
177
        }
178

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

    
183
        public String getDescription() {
184
                return _description;
185
        }
186

    
187
        public void setEditing(boolean isEditing) {
188
                this.isEditing = isEditing;
189

    
190
        }
191

    
192
        public void setHeight(float heigth) {
193
                this._height = heigth;
194
                setDirtyGeometry(true);
195
        }
196

    
197
        public void setHooked(boolean hooked) {
198
                _hooked = hooked;
199
        }
200

    
201
        public void setLayer(FLayer layer) {
202
                if (_layer == layer)
203
                        return;
204

    
205
                _layer = layer;
206

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

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

    
260
        }
261

    
262
        public void setNewLayerOSG(boolean newLayerOSG) {
263
                this.newLayerOSG = newLayerOSG;
264

    
265
        }
266

    
267
        public void setOpacity(float mOpacity) {
268
                this._opacity = mOpacity;
269

    
270
        }
271

    
272
        public void setTerrainLayer(Layer terrainLayer) {
273
                _terrainLayer = terrainLayer;
274

    
275
        }
276

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

    
283
        public void setVerticalEx(float ex) {
284
                _verticalEx = ex;
285

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

    
294
        public void setZEnable(boolean zEnable) {
295
                _zEnable = zEnable;
296

    
297
        }
298

    
299
        public void setDrawVersion(long version) {
300
                drawVersion = version;
301

    
302
        }
303

    
304
        public long getDrawVersion() {
305

    
306
                return drawVersion;
307
        }
308

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

    
320
        }
321

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

    
335
        public static class RegisterPersistence implements Callable {
336

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

    
355
                        }
356
                        return Boolean.TRUE;
357
                }
358

    
359
        }
360

    
361
        public void setDirtyGeometry(boolean dirty) {
362
                _isGeometryDirty = dirty;        
363
        }
364
        public boolean isGeometryDirty()
365
        {
366
                return _isGeometryDirty;
367
        }
368
        
369
}