root / trunk / libraries / lib3DMap-share / src / main / java / com / iver / ai2 / gvsig3d / map3d / layers / Layer3DProps.java @ 22417
History | View | Annotate | Download (11.7 KB)
1 |
package com.iver.ai2.gvsig3d.map3d.layers; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.io.File; |
5 |
import java.io.FileNotFoundException; |
6 |
import java.io.FileReader; |
7 |
import java.io.FileWriter; |
8 |
import java.util.HashMap; |
9 |
import java.util.Hashtable; |
10 |
import java.util.Vector; |
11 |
|
12 |
import javax.swing.JOptionPane; |
13 |
|
14 |
import org.cresques.cts.IProjection; |
15 |
import org.exolab.castor.xml.Marshaller; |
16 |
import org.gvsig.cacheservice.CacheService; |
17 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
18 |
|
19 |
import com.iver.ai2.gvsig3d.gui.VectorLayerMenu; |
20 |
import com.iver.andami.PluginServices; |
21 |
import com.iver.andami.messages.NotificationManager; |
22 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
23 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
24 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
25 |
import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
26 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
27 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
28 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
29 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
30 |
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend; |
31 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
32 |
import com.iver.utiles.IPersistence; |
33 |
import com.iver.utiles.XMLEntity; |
34 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
35 |
|
36 |
public class Layer3DProps implements IPersistence { |
37 |
|
38 |
// types of 3D layers
|
39 |
public static final int layer3DImage = 0; |
40 |
public static final int layer3DElevation = 1; |
41 |
public static final int layer3DVector = 2; |
42 |
public static final int layer3DOSG = 3; |
43 |
|
44 |
|
45 |
// public static String m_cacheDir = "c:/data/cache"; // TEST
|
46 |
// Create a .data directorio in user home for caching elements
|
47 |
public static String m_cacheDir = System.getProperty("user.home") |
48 |
+ "/gvSIG/.data/cache";
|
49 |
|
50 |
protected int m_tocOrder; // index of layer in TOC (drawing priority) |
51 |
protected int m_planetOrder; // current stage of layer in planet. |
52 |
// Can be temporarily different from the TOC order while moving groups of layers
|
53 |
|
54 |
protected float m_opacity = 1.0f; // Opacity of layer default 1.0 |
55 |
protected float m_verticalEx = 10.0f; // Opacity of layer default 1.0 |
56 |
protected float m_heigth = 100; // Opacity of layer default 1.0 |
57 |
protected int m_type; // see type enumeration above |
58 |
protected String m_cacheName = "default"; |
59 |
protected FLayer m_layer;
|
60 |
protected CacheService m_cacheService;
|
61 |
private boolean m_bChooseType = true; |
62 |
|
63 |
private boolean m_Zenable = false; |
64 |
|
65 |
// used by FLayers3D (3D group layer) to flag when they are actually hooked to TOC or not
|
66 |
private boolean m_hooked = false; |
67 |
|
68 |
private int option; |
69 |
|
70 |
private VectorLayerMenu vectorLayerMenu;
|
71 |
|
72 |
public Layer3DProps() {
|
73 |
m_tocOrder = -1; // not set |
74 |
m_planetOrder = -1;
|
75 |
} |
76 |
|
77 |
public static Layer3DProps getLayer3DProps(FLayer layer) { |
78 |
FLyrDefault baseLayer = (FLyrDefault) layer; |
79 |
Object propsObj = baseLayer.getProperty("3DLayerExtension"); |
80 |
Layer3DProps props3D = null;
|
81 |
if (propsObj != null) { |
82 |
try {
|
83 |
props3D = (Layer3DProps) propsObj; |
84 |
} catch (Exception e) { |
85 |
props3D = null;
|
86 |
} |
87 |
} |
88 |
return props3D;
|
89 |
} |
90 |
|
91 |
public void setChooseType(boolean bChoose) { |
92 |
m_bChooseType = bChoose; |
93 |
} |
94 |
|
95 |
public boolean getHooked() { |
96 |
return m_hooked;
|
97 |
} |
98 |
|
99 |
public void setHooked(boolean hooked) { |
100 |
m_hooked = hooked; |
101 |
} |
102 |
|
103 |
public void setLayer(FLayer layer) { |
104 |
|
105 |
if (m_layer == layer)
|
106 |
return;
|
107 |
|
108 |
m_layer = layer; |
109 |
|
110 |
// find out data type
|
111 |
if (m_bChooseType) {
|
112 |
m_bChooseType = false;
|
113 |
m_type = layer3DImage; |
114 |
boolean bCanBeElev = false; |
115 |
|
116 |
// TODO Un toggle this comment to use WMS extensions
|
117 |
|
118 |
if (layer instanceof FLyrWMS) { |
119 |
FLyrWMS wmsLayer = (FLyrWMS) layer; |
120 |
String format = wmsLayer.getFormat();
|
121 |
if (format.regionMatches(true, 0, "image/geotiff", 0, 13) || |
122 |
format.regionMatches(true, 0, "image/tiff", 0, 10)) |
123 |
bCanBeElev = true;
|
124 |
} else if (layer instanceof FLyrWCS) { |
125 |
FLyrWCS wcsLayer = (FLyrWCS) layer; |
126 |
String format = wcsLayer.getFileFormat();
|
127 |
Hashtable props = wcsLayer.getProperties();
|
128 |
String params = (String) props.get("parameter"); |
129 |
if (format.compareToIgnoreCase("GEOTIFF_INT16") == 0 |
130 |
&& params.length() == 0)
|
131 |
bCanBeElev = true;
|
132 |
} |
133 |
// FEATURES
|
134 |
else /**/ if (layer instanceof ClassifiableVectorial) { |
135 |
|
136 |
vectorLayerMenu = new VectorLayerMenu(this,layer.getName()); |
137 |
vectorLayerMenu.setModal(true);
|
138 |
vectorLayerMenu.pack(); |
139 |
vectorLayerMenu.setVisible(true);
|
140 |
|
141 |
|
142 |
// PluginServices.getMDIManager().addWindow(vectorLayerMenu);
|
143 |
|
144 |
|
145 |
// // choose rasterization of 3D
|
146 |
// option = JOptionPane.showConfirmDialog(
|
147 |
// (Component) PluginServices.getMainFrame(),
|
148 |
// PluginServices
|
149 |
// .getText(this, "Rasterize_layer_question"),
|
150 |
// PluginServices.getText(this, "Layer_options"),
|
151 |
// JOptionPane.YES_NO_OPTION);
|
152 |
//
|
153 |
// if (option == JOptionPane.YES_OPTION)
|
154 |
// m_type = layer3DImage;
|
155 |
// else
|
156 |
// m_type = layer3DVector;
|
157 |
//
|
158 |
// if (m_type == layer3DVector) {
|
159 |
// String Altura = JOptionPane.showInputDialog(PluginServices
|
160 |
// .getText(this, PluginServices.getText(this,
|
161 |
// "Heigth_layer_question")), "1000");
|
162 |
//
|
163 |
// if (Altura != null) {
|
164 |
// int h = Integer.parseInt(Altura);
|
165 |
// if (h >= 0)
|
166 |
// m_heigth = h;
|
167 |
// }
|
168 |
// }
|
169 |
|
170 |
} else if (layer instanceof FLyrRasterSE) { |
171 |
FLyrRasterSE rasterLayer = (FLyrRasterSE) layer; |
172 |
if (rasterLayer.getBandCount() == 1) |
173 |
bCanBeElev = true;
|
174 |
|
175 |
} |
176 |
|
177 |
if (m_type == layer3DImage && bCanBeElev) {
|
178 |
option = JOptionPane.showConfirmDialog(
|
179 |
(Component) PluginServices.getMainFrame(),
|
180 |
PluginServices |
181 |
.getText(this, "Elevation_layer_question"), |
182 |
PluginServices.getText(this, "Layer_options"), |
183 |
JOptionPane.YES_NO_OPTION);
|
184 |
|
185 |
if (option == JOptionPane.YES_OPTION) |
186 |
m_type = layer3DElevation; |
187 |
} |
188 |
|
189 |
} |
190 |
} |
191 |
|
192 |
public void initCacheName(int planetType, IProjection viewProj,int geocentricCoordinates) { |
193 |
// TODO: use full path of source or service, not just layer name
|
194 |
|
195 |
String typeStr;
|
196 |
if (planetType == geocentricCoordinates)
|
197 |
typeStr = "Sph";
|
198 |
else
|
199 |
typeStr = "Pla" + viewProj.getAbrev();
|
200 |
|
201 |
if (m_type == layer3DElevation)
|
202 |
typeStr += "Elev";
|
203 |
else if (m_type == layer3DVector) |
204 |
typeStr += "Vect";
|
205 |
|
206 |
String layerInfo = m_layer.getName();
|
207 |
// TODO Un toggle this comment to use WMS extension
|
208 |
|
209 |
if (m_layer instanceof FLyrWMS) { |
210 |
FLyrWMS wmsLayer = (FLyrWMS) m_layer; |
211 |
|
212 |
// Getting wms layer properties
|
213 |
HashMap props = wmsLayer.getProperties();
|
214 |
Vector styles;
|
215 |
// Getting styles
|
216 |
styles = (Vector) (props.get("styles")); |
217 |
|
218 |
// Adding styles to cache path
|
219 |
String layerStyle = ""; |
220 |
if (styles != null) { |
221 |
styles.size(); |
222 |
for (int i = 0; i < styles.size(); i++) { |
223 |
String ele = (String) styles.get(i); |
224 |
layerStyle += ele; |
225 |
} |
226 |
} |
227 |
|
228 |
layerInfo = wmsLayer.getHost().toString() |
229 |
+ wmsLayer.getLayerQuery() + "_" + layerStyle;
|
230 |
|
231 |
} else {
|
232 |
layerInfo = m_layer.getName(); |
233 |
} |
234 |
/**/
|
235 |
m_cacheName = typeStr + "_" + layerInfo;
|
236 |
|
237 |
m_cacheName = m_cacheName.replace('/', '_'); |
238 |
m_cacheName = m_cacheName.replace(':', '_'); |
239 |
m_cacheName = m_cacheName.replace('\\', '_'); |
240 |
m_cacheName = m_cacheName.replace('*', '_'); |
241 |
m_cacheName = m_cacheName.replace('<', '_'); |
242 |
m_cacheName = m_cacheName.replace('>', '_'); |
243 |
m_cacheName = m_cacheName.replace('?', '_'); |
244 |
m_cacheName = m_cacheName.replace('"', '_'); |
245 |
m_cacheName = m_cacheName.replace('|', '_'); |
246 |
|
247 |
// filter strange characters out of the cache name
|
248 |
int iChar;
|
249 |
for (iChar = 0; iChar < m_cacheName.length(); iChar++) { |
250 |
char c = m_cacheName.charAt(iChar);
|
251 |
boolean bIsLow = (c >= 'a') && (c <= 'z'); |
252 |
boolean bIsUp = (c >= 'A') && (c <= 'Z'); |
253 |
boolean bIsNum = (c >= '0') && (c <= '9'); |
254 |
if (!bIsLow && !bIsUp && !bIsNum && c != '_' && c != '.') { |
255 |
int newCInt = java.lang.Math.abs((int) (c) - (int) 'A'); |
256 |
newCInt = (newCInt % 26) + (int) 'A'; |
257 |
char newC = (char) newCInt; |
258 |
m_cacheName = m_cacheName.replace(c, newC); |
259 |
} |
260 |
} |
261 |
} |
262 |
|
263 |
public CacheService getCacheService() {
|
264 |
return m_cacheService;
|
265 |
} |
266 |
|
267 |
public void setCacheService(CacheService srv) { |
268 |
m_cacheService = srv; |
269 |
} |
270 |
|
271 |
public void setType(int type) { |
272 |
m_type = type; |
273 |
} |
274 |
|
275 |
public int getType() { |
276 |
return m_type;
|
277 |
} |
278 |
|
279 |
public void setTocOrder(int order) { |
280 |
m_tocOrder = order; |
281 |
} |
282 |
|
283 |
public int getTocOrder() { |
284 |
return m_tocOrder;
|
285 |
} |
286 |
|
287 |
public void setPlanetOrder(int order) { |
288 |
m_planetOrder = order; |
289 |
} |
290 |
|
291 |
public int getPlanetOrder() { |
292 |
return m_planetOrder;
|
293 |
} |
294 |
|
295 |
public String getCacheName() { |
296 |
return m_cacheName;
|
297 |
} |
298 |
|
299 |
/**
|
300 |
* Verifies that the vector layer's legend matches the one in the cache
|
301 |
* folder
|
302 |
*/
|
303 |
public void VerifyLegend(String planetName) { |
304 |
|
305 |
NotificationManager.addInfo("Estoy aki", null); |
306 |
NotificationManager.addInfo(m_cacheDir, null);
|
307 |
if (m_layer instanceof Classifiable) { |
308 |
Classifiable legendLyr = (Classifiable) m_layer; |
309 |
String cacheFolder = m_cacheDir + "/" + planetName |
310 |
+ "/" + m_cacheName;
|
311 |
File cacheFolderFile = new File(cacheFolder); |
312 |
if (!cacheFolderFile.exists())
|
313 |
cacheFolderFile.mkdir(); |
314 |
|
315 |
String legendFileName = cacheFolder + "/" + "legend.xml"; |
316 |
File legendFile = new File(legendFileName); |
317 |
|
318 |
if (legendFile.exists()) { // read legend |
319 |
NotificationManager.addInfo("el fichero existe", null); |
320 |
FileReader reader = null; |
321 |
try {
|
322 |
reader = new FileReader(legendFile); |
323 |
} catch (FileNotFoundException e) { |
324 |
return;
|
325 |
} |
326 |
try {
|
327 |
XmlTag tag = (XmlTag) XmlTag.unmarshal(reader); |
328 |
XMLEntity legendXml = new XMLEntity(tag);
|
329 |
ILegend legend = LegendFactory.createFromXML(legendXml); |
330 |
if (m_layer instanceof FLyrVect) { |
331 |
((FLyrVect) m_layer) |
332 |
.setLegend((IVectorLegend) legend); |
333 |
} |
334 |
|
335 |
} catch (Exception e) { |
336 |
e.printStackTrace(); |
337 |
} |
338 |
|
339 |
} else { // write legend |
340 |
NotificationManager.addInfo("el fichero no existe", null); |
341 |
ILegend legend = legendLyr.getLegend(); |
342 |
if (legend == null) |
343 |
return;
|
344 |
|
345 |
XMLEntity xmlLegend = legend.getXMLEntity(); |
346 |
|
347 |
try {
|
348 |
FileWriter writer = new FileWriter(legendFileName); |
349 |
Marshaller m = new Marshaller(writer);
|
350 |
m.setEncoding("ISO-8859-1");
|
351 |
m.marshal(xmlLegend.getXmlTag()); |
352 |
|
353 |
} catch (Exception e) { |
354 |
e.printStackTrace(); |
355 |
} |
356 |
} |
357 |
} |
358 |
} |
359 |
|
360 |
// IPersistance
|
361 |
|
362 |
public String getClassName() { |
363 |
return this.getClass().getName(); |
364 |
} |
365 |
|
366 |
public XMLEntity getXMLEntity() {
|
367 |
XMLEntity xml = new XMLEntity();
|
368 |
|
369 |
xml.putProperty("type", m_type);
|
370 |
xml.putProperty("order", m_tocOrder);
|
371 |
xml.putProperty("opacity", m_opacity);
|
372 |
xml.putProperty("heigth", m_heigth);
|
373 |
xml.putProperty("cacheName", m_cacheName);
|
374 |
|
375 |
return xml;
|
376 |
} |
377 |
|
378 |
public void setXMLEntity(XMLEntity xml) { |
379 |
if (xml.contains("type")) { |
380 |
m_bChooseType = false;
|
381 |
m_type = xml.getIntProperty("type");
|
382 |
} |
383 |
if (xml.contains("order")) |
384 |
m_tocOrder = xml.getIntProperty("order");
|
385 |
if (xml.contains("opacity")) |
386 |
m_opacity = Float.parseFloat(xml.getStringProperty("opacity")); |
387 |
if (xml.contains("heigth")) |
388 |
m_heigth = Float.parseFloat(xml.getStringProperty("heigth")); |
389 |
if (xml.contains("cacheName")) |
390 |
m_cacheName = xml.getStringProperty("cacheName");
|
391 |
} |
392 |
|
393 |
public float getOpacity() { |
394 |
return m_opacity;
|
395 |
} |
396 |
|
397 |
public void setOpacity(float m_opacity) { |
398 |
this.m_opacity = m_opacity;
|
399 |
} |
400 |
|
401 |
public float getVerticalEx() { |
402 |
return m_verticalEx;
|
403 |
} |
404 |
|
405 |
public void setVerticalEx(float ex) { |
406 |
m_verticalEx = ex; |
407 |
} |
408 |
|
409 |
public float getHeigth() { |
410 |
return m_heigth;
|
411 |
} |
412 |
|
413 |
public void setHeigth(float m_heigth) { |
414 |
this.m_heigth = m_heigth;
|
415 |
} |
416 |
|
417 |
public boolean isZEnable() { |
418 |
return m_Zenable;
|
419 |
} |
420 |
|
421 |
public void setZEnable(boolean zenable) { |
422 |
m_Zenable = zenable; |
423 |
} |
424 |
|
425 |
} |