svn-gvsig-desktop / branches / gvSIG_19_ext3D_osgVP_2_2_0 / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / layer / properties / VectorialLayerListener3D.java @ 31685
History | View | Annotate | Download (6.21 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
|
20 |
|
21 |
|
22 |
package org.gvsig.gvsig3dgui.layer.properties; |
23 |
|
24 |
import java.awt.geom.Rectangle2D; |
25 |
|
26 |
import org.apache.log4j.Logger; |
27 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
28 |
import org.gvsig.osgvp.terrain.Extent; |
29 |
|
30 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
31 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
32 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
33 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
34 |
|
35 |
/**
|
36 |
*
|
37 |
* @version
|
38 |
* @author �ngel Fraile Gri��n.(angel.fraile@iver.es)
|
39 |
*/
|
40 |
|
41 |
public class VectorialLayerListener3D { |
42 |
|
43 |
private VectorialLayerPanel3D vectorialLayerPanel3D = null; |
44 |
private Layer3DProps props3D;
|
45 |
private MapContext3D context;
|
46 |
private FLayer flyr;
|
47 |
private static Logger logger = Logger.getLogger(VectorialLayerListener3D.class |
48 |
.getName()); |
49 |
|
50 |
public VectorialLayerListener3D(VectorialLayerPanel3D panel) {
|
51 |
this.vectorialLayerPanel3D = panel;
|
52 |
} |
53 |
|
54 |
/**
|
55 |
* Actions to execute when the accept option is pressed
|
56 |
*/
|
57 |
public void accept() { |
58 |
|
59 |
context = vectorialLayerPanel3D.getMapContext(); |
60 |
props3D = vectorialLayerPanel3D.getLayer3DProps(); |
61 |
flyr = vectorialLayerPanel3D.getLayer(); |
62 |
|
63 |
//Rastering the layer
|
64 |
if (vectorialLayerPanel3D.isRasterOptionSelected() && (props3D.getType()!=Layer3DProps.layer3DImage)) {
|
65 |
context.removeLayerToTerrain(flyr); |
66 |
props3D.setType(Layer3DProps.layer3DImage); |
67 |
props3D.setCacheService(null);
|
68 |
context.addLayerToTerrain(flyr, true);
|
69 |
} else if ((!vectorialLayerPanel3D.isZValueSelected())&&(!vectorialLayerPanel3D.isRasterOptionSelected())) { |
70 |
int new_h = 0; |
71 |
int actual_h = 0; |
72 |
|
73 |
try {
|
74 |
actual_h = (int)Double.parseDouble(vectorialLayerPanel3D.getMyHeight()); |
75 |
new_h = (int)Double.parseDouble(vectorialLayerPanel3D.getJTextFieldHeight()); |
76 |
} catch (NumberFormatException e) { |
77 |
logger.error("Command: "
|
78 |
+ "Error getting maximun range layer elevation value.", e);
|
79 |
} |
80 |
|
81 |
if ((new_h >= 0 && new_h!= actual_h) || (actual_h == vectorialLayerPanel3D.getDefaultElevation()) ) //aplicando una altura distinta, si es la misma no se hace nada |
82 |
{ |
83 |
context.removeLayerToTerrain(flyr); |
84 |
props3D.setZEnable(false);
|
85 |
props3D.setType(Layer3DProps.layer3DVector); |
86 |
props3D.setCacheService(null);
|
87 |
props3D.setHeigth(new_h); |
88 |
context.addLayerToTerrain(flyr, true);
|
89 |
}//if
|
90 |
//else if
|
91 |
} else if(vectorialLayerPanel3D.isZValueSelected() && props3D.getType()!= Layer3DProps.layer3DVector){//Value Z associated to the layer |
92 |
context.removeLayerToTerrain(flyr); |
93 |
props3D.setType(Layer3DProps.layer3DVector); |
94 |
props3D.setCacheService(null);
|
95 |
props3D.setZEnable(true);
|
96 |
context.addLayerToTerrain(flyr,true);
|
97 |
|
98 |
}//else
|
99 |
|
100 |
if(vectorialLayerPanel3D.isDetailOptionSelected()) {
|
101 |
Extent planetExtent = null;
|
102 |
Rectangle2D extentLayer = null; |
103 |
|
104 |
try {
|
105 |
planetExtent = context.getTerrain().getExtent(); |
106 |
extentLayer = flyr.getFullExtent(); |
107 |
} catch (ExpansionFileReadException e) {
|
108 |
e.printStackTrace(); |
109 |
} catch (ReadDriverException e) {
|
110 |
e.printStackTrace(); |
111 |
} |
112 |
double extPW = planetExtent.xMax() - planetExtent.xMin(); // planet width |
113 |
double extPH = planetExtent.yMax() - planetExtent.yMin();// planet hight |
114 |
double extW = extentLayer.getWidth(); // layer width |
115 |
double extH = extentLayer.getHeight(); // layer hight |
116 |
int depth = 0; |
117 |
|
118 |
while(extPW > extW && extPH > extH) {// Calculating level of depth (div x /(2 pow n)) |
119 |
|
120 |
extPW = extPW/2;
|
121 |
extPH = extPH/2;
|
122 |
|
123 |
depth++;//level of depth
|
124 |
}//while
|
125 |
|
126 |
int order = props3D.getTocOrder();
|
127 |
//TODO: CApas
|
128 |
//context.getTerrain().setMaxTextureResolution(order, depth);//setting new depth to the planet
|
129 |
}//if
|
130 |
else {
|
131 |
//TODO : CApas
|
132 |
int order = props3D.getTocOrder();
|
133 |
//context.getTerrain().setMaxTextureResolution(order, vectorialLayerPanel3D.getDefaultDepth());
|
134 |
} |
135 |
|
136 |
if(vectorialLayerPanel3D.isRangeOptionSelected()) {
|
137 |
|
138 |
int new_max = 0; |
139 |
int new_min = 0; |
140 |
|
141 |
int order = props3D.getTocOrder();
|
142 |
try {
|
143 |
new_max = (int)Double.parseDouble(vectorialLayerPanel3D.getJTextFieldRangeMax()); |
144 |
new_min = (int)Double.parseDouble(vectorialLayerPanel3D.getJTextFieldRangeMin()); |
145 |
} catch (NumberFormatException e) { |
146 |
logger.error("Command: "
|
147 |
+ "Number format must be a integer.", e);
|
148 |
} |
149 |
|
150 |
if ((new_min > vectorialLayerPanel3D.getDefaultMinRange() || new_max < vectorialLayerPanel3D.getDefaultMaxRange())) //aplicando una altura distinta, si es la misma no se hace nada |
151 |
{ |
152 |
order = props3D.getTocOrder(); |
153 |
|
154 |
//TODO: CApas
|
155 |
//context.getTerrain().setMaxTextureRange(order, new_max);
|
156 |
//context.getTerrain().setMinTextureRange(order, new_min);
|
157 |
}//if
|
158 |
|
159 |
}//if
|
160 |
else {
|
161 |
int order = props3D.getTocOrder();
|
162 |
//TODO: CApas
|
163 |
//context.getTerrain().setMaxTextureRange(order, vectorialLayerPanel3D.getDefaultMaxRange());
|
164 |
//context.getTerrain().setMinTextureRange(order, vectorialLayerPanel3D.getDefaultMinRange());
|
165 |
}//else
|
166 |
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* Actions to execute when the apply option is pressed
|
171 |
*/
|
172 |
|
173 |
public void apply() { |
174 |
|
175 |
accept(); |
176 |
} |
177 |
|
178 |
/**
|
179 |
* Actions to execute when the cancel option is pressed
|
180 |
*/
|
181 |
public void cancel() { |
182 |
|
183 |
} |
184 |
|
185 |
} |