Revision 387 2.1/trunk/org.gvsig.gvsig3d/org.gvsig.gvsig3d.lib/org.gvsig.gvsig3d.lib.impl/src/main/java/org/gvsig/gvsig3d/impl/map3d/Layer3DPropsImpl.java

View differences:

Layer3DPropsImpl.java
35 35
 * http://www.ai2.upv.es
36 36
 */
37 37

  
38

  
39 38
package org.gvsig.gvsig3d.impl.map3d;
40 39

  
40
import java.awt.Component;
41

  
42
import javax.swing.JOptionPane;
43

  
44
import org.gvsig.andami.PluginServices;
41 45
import org.gvsig.fmap.mapcontext.layers.FLayer;
42 46
import org.gvsig.gvsig3d.map3d.Layer3DProps;
43 47
import org.gvsig.osgvp.terrain.Layer;
48
import org.gvsig.raster.fmap.layers.FLyrRaster;
44 49
import org.gvsig.tools.ToolsLocator;
45 50
import org.gvsig.tools.dynobject.DelegatedDynObject;
46 51
import org.gvsig.tools.dynobject.DynClass;
......
54 59
/**
55 60
 * @author Jesus Zarzoso- jzarzoso@ai2.upv.es
56 61
 * @version $Id$
57
 * 
58 62
 */
59 63
public class Layer3DPropsImpl implements Layer3DProps, Persistent {
60 64

  
61
	public static final String PARAMETERS_DEFINITION_NAME = "Layer3DPropsImpl";
65
  public static final String PARAMETERS_DEFINITION_NAME = "Layer3DPropsImpl";
62 66

  
63
	public static final String OPACITY = "opacity";
67
  public static final String OPACITY = "opacity";
64 68

  
65
	public static final String VERTICAL_EX = "verticalExageration";
69
  public static final String VERTICAL_EX = "verticalExageration";
66 70

  
67
	public static final String HEIGHT = "height";
71
  public static final String HEIGHT = "height";
68 72

  
69
	public static final String TYPE = "type";
73
  public static final String TYPE = "type";
70 74

  
71
	public static final String TERRAIN_LAYER = "terrainLayer";
75
  public static final String TERRAIN_LAYER = "terrainLayer";
72 76

  
73
	public static final String LAYER = "layer";
77
  public static final String LAYER = "layer";
74 78

  
75
	public static final String EDITING = "editing";
79
  public static final String EDITING = "editing";
76 80

  
77
	private static final String FIELD_DESCRIPTION = "description";
78
	
79
	private static final String BAND_ELEVATION = "bandElevation";
81
  private static final String FIELD_DESCRIPTION = "description";
80 82

  
81
	private long drawVersion = 0;
83
  private static final String BAND_ELEVATION = "bandElevation";
82 84

  
83
	private boolean newLayerOSG = false;
85
  private long drawVersion = 0;
84 86

  
85
	protected float _opacity = 1.0f; // Opacity of layer default 1.0
86
	protected float _verticalEx = 1.0f; // Opacity of layer default 1.0
87
	protected int _bandElev = 0;
88
	protected float _height = 5; // Opacity of layer default 1.0
89
	protected int _type; // see type enumeration above
87
  private boolean newLayerOSG = false;
90 88

  
91
	protected Layer _terrainLayer;
89
  protected float _opacity = 1.0f; // Opacity of layer default 1.0
92 90

  
93
	protected FLayer _layer;
91
  protected float _verticalEx = 1.0f; // Opacity of layer default 1.0
94 92

  
95
	protected String _cacheName = "default";
93
  protected int _bandElev = 0;
96 94

  
97
	private boolean _bChooseType = true;
95
  protected float _height = 5; // Opacity of layer default 1.0
98 96

  
99
	private boolean _zEnable = false;
100
	
101
	private boolean _isGeometryDirty = false ;
102
	
103
	// used by FLayers3D (3D group layer) to flag when they are actually hooked
104
	// to TOC or not
105
	private boolean _hooked = false;
97
  protected int _type; // see type enumeration above
106 98

  
107
	private boolean isEditing = false;
99
  protected Layer _terrainLayer;
108 100

  
109
	private int option;
101
  protected FLayer _layer;
110 102

  
111
	private DelegatedDynObject _delegatedDynObject = null;
103
  protected String _cacheName = "default";
112 104

  
113
	private String _description = "";
105
  private boolean _bChooseType = true;
114 106

  
115
	protected static DynClass DYNCLASS = null;
107
  private boolean _zEnable = false;
116 108

  
117
	public Layer3DPropsImpl() {
109
  private boolean _isGeometryDirty = false;
118 110

  
119
	}
111
  // used by FLayers3D (3D group layer) to flag when they are actually hooked
112
  // to TOC or not
113
  private boolean _hooked = false;
120 114

  
121
	public Layer3DPropsImpl(FLayer layer) {
115
  private boolean isEditing = false;
122 116

  
123
		_layer = layer;
117
  private int option;
124 118

  
125
	}
119
  private DelegatedDynObject _delegatedDynObject = null;
126 120

  
127
	// private VectorLayerMenu vectorLayerMenu;
121
  private String _description = "";
128 122

  
129
	// TRY TO NOT USE STATIC METHODS. PROBLEMS WITH API/IMPL SEPARATION
130
	// public static Layer3DProps getLayer3DProps(FLayer layer) {
131
	// FLyrDefault baseLayer = (FLyrDefault) layer;
132
	// Object propsObj = baseLayer.getProperty("3DLayerExtension");
133
	// Layer3DPropsImpl props3D = null;
134
	// if (propsObj != null) {
135
	// try {
136
	// props3D = (Layer3DPropsImpl) propsObj;
137
	// if (props3D.drawVersion == 0)
138
	// props3D.drawVersion = layer.getDrawVersion();
139
	// } catch (Exception e) {
140
	// props3D = null;
141
	// }
142
	// }
143
	// return props3D;
144
	// }
123
  protected static DynClass DYNCLASS = null;
145 124

  
146
	public String getClassName() {
147
		return this.getClass().getName();
148
	}
125
  public Layer3DPropsImpl() {
149 126

  
150
	public float getHeight() {
151
		return _height;
152
	}
127
  }
153 128

  
154
	public boolean getHooked() {
155
		return _hooked;
156
	}
129
  public Layer3DPropsImpl(FLayer layer) {
157 130

  
158
	public float getOpacity() {
159
		return _opacity;
160
	}
131
    _layer = layer;
161 132

  
162
	public Layer getTerrainLayer() {
163
		return _terrainLayer;
164
	}
133
  }
165 134

  
166
	public int getType() {
167
		return _type;
168
	}
135
  // private VectorLayerMenu vectorLayerMenu;
169 136

  
170
	public float getVerticalEx() {
171
		return _verticalEx;
172
	}
173
	
174
	public int getElevationBand(){
175
		
176
		return _bandElev;
177
	}
137
  // TRY TO NOT USE STATIC METHODS. PROBLEMS WITH API/IMPL SEPARATION
138
  // public static Layer3DProps getLayer3DProps(FLayer layer) {
139
  // FLyrDefault baseLayer = (FLyrDefault) layer;
140
  // Object propsObj = baseLayer.getProperty("3DLayerExtension");
141
  // Layer3DPropsImpl props3D = null;
142
  // if (propsObj != null) {
143
  // try {
144
  // props3D = (Layer3DPropsImpl) propsObj;
145
  // if (props3D.drawVersion == 0)
146
  // props3D.drawVersion = layer.getDrawVersion();
147
  // } catch (Exception e) {
148
  // props3D = null;
149
  // }
150
  // }
151
  // return props3D;
152
  // }
178 153

  
179
	public boolean isEditing() {
180
		return isEditing;
181
	}
154
  public String getClassName() {
155
    return this.getClass().getName();
156
  }
182 157

  
183
	public boolean isNewLayerOSG() {
184
		return newLayerOSG;
185
	}
158
  public float getHeight() {
159
    return _height;
160
  }
186 161

  
187
	public boolean isZEnable() {
188
		return _zEnable;
189
	}
162
  public boolean getHooked() {
163
    return _hooked;
164
  }
190 165

  
191
	public void setChooseType(boolean bChoose) {
192
		_bChooseType = bChoose;
166
  public float getOpacity() {
167
    return _opacity;
168
  }
193 169

  
194
	}
170
  public Layer getTerrainLayer() {
171
    return _terrainLayer;
172
  }
195 173

  
196
	public void setDescription(String desc) {
197
		this._description = desc;
198
	}
174
  public int getType() {
175
    return _type;
176
  }
199 177

  
200
	public String getDescription() {
201
		return _description;
202
	}
178
  public float getVerticalEx() {
179
    return _verticalEx;
180
  }
203 181

  
204
	public void setEditing(boolean isEditing) {
205
		this.isEditing = isEditing;
182
  public int getElevationBand() {
206 183

  
207
	}
184
    return _bandElev;
185
  }
208 186

  
209
	public void setHeight(float heigth) {
210
		this._height = heigth;
211
		setDirtyGeometry(true);
212
	}
187
  public boolean isEditing() {
188
    return isEditing;
189
  }
213 190

  
214
	public void setHooked(boolean hooked) {
215
		_hooked = hooked;
216
	}
191
  public boolean isNewLayerOSG() {
192
    return newLayerOSG;
193
  }
217 194

  
218
	public void setLayer(FLayer layer) {
219
		if (_layer == layer)
220
			return;
195
  public boolean isZEnable() {
196
    return _zEnable;
197
  }
221 198

  
222
		_layer = layer;
199
  public void setChooseType(boolean bChoose) {
200
    _bChooseType = bChoose;
223 201

  
224
		// find out data type
225
		if (_bChooseType) {
226
			_bChooseType = false;
227
			_type = layer3DImage;
228
			boolean bCanBeElev = false;
202
  }
229 203

  
230
			// if (layer instanceof FLyrWMS) {
231
			// FLyrWMS wmsLayer = (FLyrWMS) layer;
232
			// String format = wmsLayer.getFormat();
233
			// if (format.regionMatches(true, 0, "image/geotiff", 0, 13)
234
			// || format.regionMatches(true, 0, "image/tiff", 0, 10))
235
			// bCanBeElev = true;
204
  public void setDescription(String desc) {
205
    this._description = desc;
206
  }
207

  
208
  public String getDescription() {
209
    return _description;
210
  }
211

  
212
  public void setEditing(boolean isEditing) {
213
    this.isEditing = isEditing;
214

  
215
  }
216

  
217
  public void setHeight(float heigth) {
218
    this._height = heigth;
219
    setDirtyGeometry(true);
220
  }
221

  
222
  public void setHooked(boolean hooked) {
223
    _hooked = hooked;
224
  }
225

  
226
  public void setLayer(FLayer layer) {
227
    // if (_layer == layer)
228
    // return;
229

  
230
    _layer = layer;
231

  
232
    // find out data type
233
    if (_bChooseType) {
234
      _bChooseType = false;
235
      _type = layer3DImage;
236
      boolean bCanBeElev = false;
237

  
238
      // if (layer instanceof FLyrWMS) {
239
      // FLyrWMS wmsLayer = (FLyrWMS) layer;
240
      // String format = wmsLayer.getFormat();
241
      // if (format.regionMatches(true, 0, "image/geotiff", 0, 13)
242
      // || format.regionMatches(true, 0, "image/tiff", 0, 10))
243
      // bCanBeElev = true;
236 244
			// } else
237 245
			// if (layer instanceof FLyrWCS) {
238
			// FLyrWCS wcsLayer = (FLyrWCS) layer;
239
			// Hashtable props = wcsLayer.getProperties();
240
			// String format = (String) props.get("format");
241
			// String params = (String) props.get("parameter");
242
			// if (format.compareToIgnoreCase("GEOTIFF_INT16") == 0
246
      // FLyrWCS wcsLayer = (FLyrWCS) layer;
247
      // Hashtable props = wcsLayer.getProperties();
248
      // String format = (String) props.get("format");
249
      // String params = (String) props.get("parameter");
250
      // if (format.compareToIgnoreCase("GEOTIFF_INT16") == 0
243 251
			// && params.compareToIgnoreCase("bands=1") == 0)
244 252
			// bCanBeElev = true;
245
			// }
253
      // }
246 254
			// FEATURES
247 255
			// else /**/if (layer instanceof ClassifiableVectorial) {
248
			//
249
			// if (this.getType() != layer3DOSG) {
250
			// vectorLayerMenu = new VectorLayerMenu(this, layer.getName());
251
			// vectorLayerMenu.setModal(true);
252
			// vectorLayerMenu.pack();
253
			// vectorLayerMenu.setVisible(true);
254
			// }
255
			//
256
			// } else if (layer instanceof FLyrRasterSE) {
257
			// FLyrRasterSE rasterLayer = (FLyrRasterSE) layer;
258
			// if (rasterLayer.getBandCount() == 1)
259
			// bCanBeElev = true;
260
			//
261
			// }
262
			//
263
			// if (_type == layer3DImage && bCanBeElev) {
264
			// option = JOptionPane.showConfirmDialog(
265
			// (Component) PluginServices.getMainFrame(),
266
			// PluginServices
267
			// .getText(this, "Elevation_layer_question"),
268
			// PluginServices.getText(this, "Layer_options"),
269
			// JOptionPane.YES_NO_OPTION);
270
			//
271
			// if (option == JOptionPane.YES_OPTION) {
272
			// _type = layer3DElevation;
273
			// }
274
			// }
275
		}
256
      //
257
      // if (this.getType() != layer3DOSG) {
258
      // vectorLayerMenu = new VectorLayerMenu(this, layer.getName());
259
      // vectorLayerMenu.setModal(true);
260
      // vectorLayerMenu.pack();
261
      // vectorLayerMenu.setVisible(true);
262
      // }
263
      //
264
      // }
265
      // else
266
      if (layer instanceof FLyrRaster) {
267
        FLyrRaster rasterLayer = (FLyrRaster) layer;
268
        if (rasterLayer.getDataStore().getBandCount() == 1)
269
          bCanBeElev = true;
276 270

  
277
	}
271
      }
272
      //
273
      if (_type == layer3DImage && bCanBeElev) {
274
        option = JOptionPane.showConfirmDialog(
275
            (Component) PluginServices.getMainFrame(),
276
            PluginServices.getText(this, "Elevation_layer_question"),
277
            PluginServices.getText(this, "Layer_options"),
278
            JOptionPane.YES_NO_OPTION);
278 279

  
279
	public void setNewLayerOSG(boolean newLayerOSG) {
280
		this.newLayerOSG = newLayerOSG;
280
        if (option == JOptionPane.YES_OPTION) {
281
          _type = layer3DElevation;
282
        }
283
      }
284
    }
281 285

  
282
	}
286
  }
283 287

  
284
	public void setOpacity(float mOpacity) {
285
		this._opacity = mOpacity;
288
  public void setNewLayerOSG(boolean newLayerOSG) {
289
    this.newLayerOSG = newLayerOSG;
286 290

  
287
	}
291
  }
288 292

  
289
	public void setTerrainLayer(Layer terrainLayer) {
290
		_terrainLayer = terrainLayer;
293
  public void setOpacity(float mOpacity) {
294
    this._opacity = mOpacity;
291 295

  
292
	}
296
  }
293 297

  
294
	public void setType(int type) {
295
		_type = type;
296
		//We need to persist in the layer properties if the layer is rasterized or not.
297
		_layer.setProperty("layerType", type);
298
	}
298
  public void setTerrainLayer(Layer terrainLayer) {
299
    _terrainLayer = terrainLayer;
299 300

  
300
	public void setVerticalEx(float ex) {
301
		_verticalEx = ex;
301
  }
302 302

  
303
	}
304
	
305
	public void setElevationBand(int band){
306
		
307
		_bandElev = band;
308
		
309
	}
303
  public void setType(int type) {
304
    _type = type;
305
    // We need to persist in the layer properties if the layer is rasterized or
306
    // not.
307
    _layer.setProperty("layerType", type);
308
  }
310 309

  
311
	public void setZEnable(boolean zEnable) {
312
		_zEnable = zEnable;
310
  public void setVerticalEx(float ex) {
311
    _verticalEx = ex;
313 312

  
314
	}
313
  }
315 314

  
316
	public void setDrawVersion(long version) {
317
		drawVersion = version;
315
  public void setElevationBand(int band) {
318 316

  
319
	}
317
    _bandElev = band;
320 318

  
321
	public long getDrawVersion() {
319
  }
322 320

  
323
		return drawVersion;
324
	}
321
  public void setZEnable(boolean zEnable) {
322
    _zEnable = zEnable;
325 323

  
326
	public void loadFromState(PersistentState state)
327
			throws PersistenceException {
328
		// setDescription(state.getString(FIELD_DESCRIPTION));
329
		_opacity = state.getFloat(OPACITY);
330
		_verticalEx = state.getFloat(VERTICAL_EX);
331
		_height = state.getFloat(HEIGHT);
332
		_type = state.getInt(TYPE);
333
//		_terrainLayer = (Layer) state.get(TERRAIN_LAYER);
334
		_layer = (FLayer) state.get(LAYER);
335
		isEditing = state.getBoolean(EDITING);
324
  }
336 325

  
337
	}
326
  public void setDrawVersion(long version) {
327
    drawVersion = version;
338 328

  
339
	public void saveToState(PersistentState state) throws PersistenceException {
340
		// state.set(FIELD_DESCRIPTION, getDescription());
341
		state.set(OPACITY, _opacity);
342
		state.set(VERTICAL_EX, _verticalEx);
343
		state.set(HEIGHT, _height);
344
		state.set(TYPE, _type);
345
//		if (_terrainLayer != null)
346
//			state.set(TERRAIN_LAYER, _terrainLayer);
347
		if (_layer != null)
348
			state.set(LAYER, _layer);
349
		state.set(EDITING, isEditing);
350
	}
329
  }
351 330

  
352
	public static class RegisterPersistence implements Callable {
331
  public long getDrawVersion() {
353 332

  
354
		public Object call() throws Exception {
355
			PersistenceManager manager = ToolsLocator.getPersistenceManager();
356
			if (manager.getDefinition(PARAMETERS_DEFINITION_NAME) == null) {
357
				DynStruct definition = manager.addDefinition(
358
						Layer3DPropsImpl.class, PARAMETERS_DEFINITION_NAME,
359
						PARAMETERS_DEFINITION_NAME + " Persistence definition",
360
						null, null);
361
				// Description
362
				definition.addDynFieldFloat(OPACITY).setMandatory(false);
363
				definition.addDynFieldFloat(VERTICAL_EX).setMandatory(false);
364
				definition.addDynFieldFloat(HEIGHT).setMandatory(false);
365
				definition.addDynFieldInt(TYPE).setMandatory(false);
366
//				definition.addDynFieldObject(TERRAIN_LAYER)
367
//						.setClassOfValue(Layer.class).setMandatory(false);
368
				definition.addDynFieldObject(LAYER)
369
						.setClassOfValue(FLayer.class).setMandatory(false);
370
				definition.addDynFieldBoolean(EDITING).setMandatory(false);
333
    return drawVersion;
334
  }
371 335

  
372
			}
373
			return Boolean.TRUE;
374
		}
336
  public void loadFromState(PersistentState state) throws PersistenceException {
337
    // setDescription(state.getString(FIELD_DESCRIPTION));
338
    _opacity = state.getFloat(OPACITY);
339
    _verticalEx = state.getFloat(VERTICAL_EX);
340
    _height = state.getFloat(HEIGHT);
341
    _type = state.getInt(TYPE);
342
    // _terrainLayer = (Layer) state.get(TERRAIN_LAYER);
343
    _layer = (FLayer) state.get(LAYER);
344
    isEditing = state.getBoolean(EDITING);
375 345

  
376
	}
346
  }
377 347

  
378
	public void setDirtyGeometry(boolean dirty) {
379
		_isGeometryDirty = dirty;	
380
	}
381
	public boolean isGeometryDirty()
382
	{
383
		return _isGeometryDirty;
384
	}
385
	
348
  public void saveToState(PersistentState state) throws PersistenceException {
349
    // state.set(FIELD_DESCRIPTION, getDescription());
350
    state.set(OPACITY, _opacity);
351
    state.set(VERTICAL_EX, _verticalEx);
352
    state.set(HEIGHT, _height);
353
    state.set(TYPE, _type);
354
    // if (_terrainLayer != null)
355
    // state.set(TERRAIN_LAYER, _terrainLayer);
356
    if (_layer != null) state.set(LAYER, _layer);
357
    state.set(EDITING, isEditing);
358
  }
359

  
360
  public static class RegisterPersistence implements Callable {
361

  
362
    public Object call() throws Exception {
363
      PersistenceManager manager = ToolsLocator.getPersistenceManager();
364
      if (manager.getDefinition(PARAMETERS_DEFINITION_NAME) == null) {
365
        DynStruct definition = manager.addDefinition(Layer3DPropsImpl.class,
366
            PARAMETERS_DEFINITION_NAME, PARAMETERS_DEFINITION_NAME
367
                + " Persistence definition", null, null);
368
        // Description
369
        definition.addDynFieldFloat(OPACITY).setMandatory(false);
370
        definition.addDynFieldFloat(VERTICAL_EX).setMandatory(false);
371
        definition.addDynFieldFloat(HEIGHT).setMandatory(false);
372
        definition.addDynFieldInt(TYPE).setMandatory(false);
373
        // definition.addDynFieldObject(TERRAIN_LAYER)
374
        // .setClassOfValue(Layer.class).setMandatory(false);
375
        definition.addDynFieldObject(LAYER).setClassOfValue(FLayer.class)
376
            .setMandatory(false);
377
        definition.addDynFieldBoolean(EDITING).setMandatory(false);
378

  
379
      }
380
      return Boolean.TRUE;
381
    }
382

  
383
  }
384

  
385
  public void setDirtyGeometry(boolean dirty) {
386
    _isGeometryDirty = dirty;
387
  }
388

  
389
  public boolean isGeometryDirty() {
390
    return _isGeometryDirty;
391
  }
392

  
386 393
}

Also available in: Unified diff