svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / fmap / layers / FLyrPoints.java @ 4841
History | View | Annotate | Download (28.2 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
package com.iver.cit.gvsig.fmap.layers; |
20 |
|
21 |
import java.awt.Color; |
22 |
import java.awt.Dimension; |
23 |
import java.awt.Graphics2D; |
24 |
import java.awt.geom.Point2D; |
25 |
import java.awt.geom.Rectangle2D; |
26 |
import java.awt.image.BufferedImage; |
27 |
import java.util.ArrayList; |
28 |
import java.util.Iterator; |
29 |
|
30 |
import org.cresques.cts.ProjectionPool; |
31 |
|
32 |
import com.iver.andami.PluginServices; |
33 |
import com.iver.cit.gvsig.fmap.DriverException; |
34 |
import com.iver.cit.gvsig.fmap.ViewPort; |
35 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
36 |
import com.iver.cit.gvsig.gui.View; |
37 |
import com.iver.cit.gvsig.gui.dialogs.GeoreferencingDialog; |
38 |
import com.iver.cit.gvsig.utils.GeoPointPersistence; |
39 |
import com.iver.cit.gvsig.utils.PointManager; |
40 |
import com.iver.utiles.XMLEntity; |
41 |
|
42 |
|
43 |
/**
|
44 |
* Clase de capa de marcado de puntos sobre una vista. Dibuja un puntero sobre
|
45 |
* cada punto en la vista. Esta capa hereda de GraphicLayer que es una capa que est?
|
46 |
* metida de forma fija en FMap. Con esto conseguimos que nuestra capa de puntos
|
47 |
* no aparezca en el TOC y siempre se dibuje por encima de todas las capas. Tiene
|
48 |
* el inconveniente de que est? en FMap y si hacemos un dibujado de las capas
|
49 |
* sobre un panel que no sea la vista de gvSIG este GraphicLayer no aparece.
|
50 |
* Si queremos hacer este tipo de dibujados tendremos que dibujar todas las capas
|
51 |
* con el draw de FLayers y al final llamar al draw de FLyrPoints.
|
52 |
*
|
53 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
54 |
*/
|
55 |
public class FLyrPoints extends GraphicLayer { |
56 |
|
57 |
//**********************Params********************************
|
58 |
/**
|
59 |
* Diametro del centro de la cruz
|
60 |
*/
|
61 |
private final int DIAM_CIRCLE = 18; |
62 |
/**
|
63 |
* ?ltima herramienta seleccionada. Despu?s de marcar el segundo punto en la vista ser? la
|
64 |
* herramienta por defecto.
|
65 |
*/
|
66 |
private String lastTool = "zoomIn"; |
67 |
//**********************End Params****************************
|
68 |
|
69 |
//**********************Vars**********************************
|
70 |
private ArrayList pointList = new ArrayList(); |
71 |
private boolean showNumber = true; |
72 |
private FLyrPointsState state = null; |
73 |
private GeoPointPersistence geoPointPersistence = null; |
74 |
private FLyrGeoRaster lyrGeoRaster = null; |
75 |
public static boolean isDrawing = false; |
76 |
private PointManager pointManager = null; |
77 |
private boolean lyrVisible = true; |
78 |
//**********************End Vars**********************************
|
79 |
|
80 |
//**********************Classes***********************************
|
81 |
/**
|
82 |
* Estado de la capa de puntos.
|
83 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
84 |
*/
|
85 |
public class FLyrPointsState{ |
86 |
public ArrayList pointList = new ArrayList(); |
87 |
public boolean showNumber = true; |
88 |
public String lastTool = "zoomIn"; |
89 |
} |
90 |
//**********************End Classes*******************************
|
91 |
|
92 |
//**********************Methods***********************************
|
93 |
/**
|
94 |
* Constructor
|
95 |
* @param flyGeoRaster
|
96 |
*/
|
97 |
public FLyrPoints(FLyrGeoRaster lyGeoRaster){
|
98 |
this.lyrGeoRaster = lyGeoRaster;
|
99 |
geoPointPersistence = new GeoPointPersistence(this); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Crea una capa FLyrPoints a partir de los par?metros de entrada.
|
104 |
* @param lyGeoRaster Capa a georreferenciar
|
105 |
* @param pixel Coordenadas relativas a la imagen a georreferenciar en pixels
|
106 |
* @param map Coordenadas de destino
|
107 |
* @param active True o false si el punto est? activo o no
|
108 |
* @param leftCenter Punto central del viewport de la miniimagen de coordenadas reales
|
109 |
* @param rightCenter Punto central del viewport de la miniimagen de coordenadas en pixels
|
110 |
* @param leftViewPort ViewPort de la miniimagen de coordenadas reales
|
111 |
* @param rightViewPort ViewPort de la miniimagen de coordenadas en pixels
|
112 |
* @return Capa de puntos creada.
|
113 |
*/
|
114 |
public static FLyrPoints createFLyrPoints( FLyrGeoRaster lyGeoRaster, |
115 |
Point2D[] pixel, |
116 |
Point2D[] map, |
117 |
boolean[] active, |
118 |
Point2D[] leftCenter, |
119 |
Point2D[] rightCenter, |
120 |
ViewPort[] leftViewPort,
|
121 |
ViewPort[] rightViewPort){
|
122 |
FLyrPoints lyrPoints = new FLyrPoints(lyGeoRaster);
|
123 |
|
124 |
lyrPoints.getPointManager().newEmptyPoint(); |
125 |
View theView = null; |
126 |
try{
|
127 |
theView = (View)PluginServices.getMDIManager().getActiveView();
|
128 |
}catch(ClassCastException exc){ |
129 |
return null; |
130 |
} |
131 |
int pos = lyrPoints.getCountPoints() -1; |
132 |
for(int i = 0;i < pixel.length;i++){ |
133 |
lyrPoints.setPointActive(pos, active[i]); |
134 |
lyrPoints.setLeftCenterPoint(pos,leftCenter[i]); |
135 |
lyrPoints.setRightCenterPoint(pos, rightCenter[i]); |
136 |
lyrPoints.setLeftViewPort(pos, leftViewPort[i]); |
137 |
lyrPoints.setRightViewPort(pos, rightViewPort[i]); |
138 |
lyrPoints.getPointManager().updateData(pos + 1, pixel[i], map[i], lyrPoints.getPointManager().getDialog(), theView);
|
139 |
} |
140 |
|
141 |
if(lyrPoints.getCountPoints() > 0){ |
142 |
GeoreferencingDialog grd = lyrPoints.getPointManager().getDialog(); |
143 |
grd.getConectorPanel().getDataPointsTabPanel(). |
144 |
getSelectPointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints()); |
145 |
grd.getConectorPanel().getDataPointsTabPanel(). |
146 |
getTablePointsPanel().getTableControlerPanel().setNItems(lyrPoints.getCountPoints()); |
147 |
lyrPoints.getPointManager().selectPoint(0, grd);
|
148 |
} |
149 |
return lyrPoints;
|
150 |
} |
151 |
|
152 |
/**
|
153 |
* Salva el estado actual de la capa de puntos. Podr? ser recuperado
|
154 |
* este ?ltimo estado salvado con la funci?n recoveryState
|
155 |
*
|
156 |
*/
|
157 |
public void saveState(){ |
158 |
if(state == null) |
159 |
state = new FLyrPointsState();
|
160 |
else
|
161 |
state.pointList.clear(); |
162 |
|
163 |
for(int i=0;i<this.length();i++) |
164 |
state.pointList.add(((GeoPoint)pointList.get(i)).cloneGeoPoint()); |
165 |
|
166 |
state.showNumber = showNumber; |
167 |
state.lastTool = lastTool; |
168 |
} |
169 |
|
170 |
/**
|
171 |
* Recupera el estado de la capa de puntos desde la ?ltima vez que se
|
172 |
* ejecut? la funci?n saveState. Si no hay ning?n estdo salvado es que
|
173 |
* al principio estaba la capa vacia por lo que reiniciamos la capa de puntos.
|
174 |
*/
|
175 |
public void recoveryState(){ |
176 |
if(state != null){ |
177 |
pointList.clear(); |
178 |
for(int i=0;i<state.pointList.size();i++) |
179 |
pointList.add(((GeoPoint)state.pointList.get(i)).cloneGeoPoint()); |
180 |
|
181 |
showNumber = state.showNumber; |
182 |
lastTool = state.lastTool; |
183 |
} |
184 |
} |
185 |
|
186 |
/**
|
187 |
* Asigna el array de puntos
|
188 |
* @param list
|
189 |
*/
|
190 |
public void setListPoint(ArrayList list){ |
191 |
pointList = list; |
192 |
} |
193 |
|
194 |
/**
|
195 |
* Dibujado de la capa de raster georeferenciado aplicando la
|
196 |
* transformaci?n del viewPort.
|
197 |
*/
|
198 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
199 |
Cancellable cancel,double scale) throws DriverException { |
200 |
|
201 |
Point2D pto = null; |
202 |
|
203 |
if(lyrVisible && lyrGeoRaster != null){ |
204 |
//vp = lyrGeoRaster.toImageCoord(vp);
|
205 |
synchronized (this) { |
206 |
for(int i=0; i<pointList.size();i++){ |
207 |
//Punto de la imagen
|
208 |
if(((GeoPoint)pointList.get(i)).active){
|
209 |
pto = ((GeoPoint)pointList.get(i)).pixelPoint; |
210 |
if(pto != null){ |
211 |
Point2D p = lyrGeoRaster.img2World(pto);
|
212 |
p = vp.fromMapPoint(p); |
213 |
drawPixelCrux(g, p, i); |
214 |
} |
215 |
|
216 |
//Punto de la vista
|
217 |
pto = ((GeoPoint)pointList.get(i)).mapPoint; |
218 |
if(pto != null){ |
219 |
Point2D p = null; |
220 |
p = vp.fromMapPoint(pto); |
221 |
drawMapCrux(g, p, i); |
222 |
} |
223 |
} |
224 |
} |
225 |
} |
226 |
} |
227 |
} |
228 |
|
229 |
/**
|
230 |
* Dibuja sobre el graphics pasado la cruz del punto que marca
|
231 |
* el pixel de la imagen.
|
232 |
* @param g Graphics
|
233 |
*/
|
234 |
private void drawPixelCrux(Graphics2D g, Point2D p, int pointNumber){ |
235 |
int dpto = (DIAM_CIRCLE >> 1); |
236 |
int incr = 5; |
237 |
g.setColor(Color.WHITE);
|
238 |
g.drawOval( (int)p.getX() - dpto + 1, |
239 |
(int)p.getY() - dpto + 1, |
240 |
DIAM_CIRCLE - 2,
|
241 |
DIAM_CIRCLE - 2);
|
242 |
g.drawLine((int)p.getX() - incr, (int)p.getY() - 1, (int)p.getX() - 1, (int)p.getY() - 1); |
243 |
g.drawLine((int)p.getX() - incr, (int)p.getY() + 1, (int)p.getX() - 1, (int)p.getY() + 1); |
244 |
|
245 |
g.drawLine((int)p.getX() + incr, (int)p.getY() - 1, (int)p.getX() + 1, (int)p.getY() - 1); |
246 |
g.drawLine((int)p.getX() + incr, (int)p.getY() + 1, (int)p.getX() + 1, (int)p.getY() + 1); |
247 |
|
248 |
g.drawLine((int)p.getX() - 1, (int)p.getY() - incr, (int)p.getX() - 1, (int)p.getY() - 1); |
249 |
g.drawLine((int)p.getX() + 1, (int)p.getY() - incr, (int)p.getX() + 1, (int)p.getY() - 1); |
250 |
|
251 |
g.drawLine((int)p.getX() - 1, (int)p.getY() + incr, (int)p.getX() - 1, (int)p.getY() + 1); |
252 |
g.drawLine((int)p.getX() + 1, (int)p.getY() + incr, (int)p.getX() + 1, (int)p.getY() + 1); |
253 |
|
254 |
g.setColor(Color.red);
|
255 |
g.drawOval( (int)p.getX() - dpto,
|
256 |
(int)p.getY() - dpto,
|
257 |
DIAM_CIRCLE, |
258 |
DIAM_CIRCLE); |
259 |
g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr); |
260 |
g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY()); |
261 |
|
262 |
if(showNumber){
|
263 |
g.setColor(Color.WHITE);
|
264 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 4), (int)(p.getY() - dpto - 4) ); |
265 |
g.setColor(Color.red);
|
266 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 1), (int)(p.getY() - dpto - 1) ); |
267 |
} |
268 |
} |
269 |
|
270 |
/**
|
271 |
* Dibuja sobre el graphics pasado la cruz del punto que marca
|
272 |
* la coordenada de la vista.
|
273 |
* @param g Graphics
|
274 |
*/
|
275 |
private void drawMapCrux(Graphics2D g, Point2D p, int pointNumber){ |
276 |
int dpto = (DIAM_CIRCLE >> 1); |
277 |
int incr = 5; |
278 |
g.setColor(Color.WHITE);
|
279 |
g.drawRect( (int)p.getX() - dpto + 1, |
280 |
(int)p.getY() - dpto + 1, |
281 |
DIAM_CIRCLE - 2,
|
282 |
DIAM_CIRCLE - 2);
|
283 |
g.drawLine((int)p.getX() - incr, (int)p.getY() - 1, (int)p.getX() - 1, (int)p.getY() - 1); |
284 |
g.drawLine((int)p.getX() - incr, (int)p.getY() + 1, (int)p.getX() - 1, (int)p.getY() + 1); |
285 |
|
286 |
g.drawLine((int)p.getX() + incr, (int)p.getY() - 1, (int)p.getX() + 1, (int)p.getY() - 1); |
287 |
g.drawLine((int)p.getX() + incr, (int)p.getY() + 1, (int)p.getX() + 1, (int)p.getY() + 1); |
288 |
|
289 |
g.drawLine((int)p.getX() - 1, (int)p.getY() - incr, (int)p.getX() - 1, (int)p.getY() - 1); |
290 |
g.drawLine((int)p.getX() + 1, (int)p.getY() - incr, (int)p.getX() + 1, (int)p.getY() - 1); |
291 |
|
292 |
g.drawLine((int)p.getX() - 1, (int)p.getY() + incr, (int)p.getX() - 1, (int)p.getY() + 1); |
293 |
g.drawLine((int)p.getX() + 1, (int)p.getY() + incr, (int)p.getX() + 1, (int)p.getY() + 1); |
294 |
|
295 |
g.setColor(new Color(45, 8 , 165)); |
296 |
g.drawRect( (int)p.getX() - dpto,
|
297 |
(int)p.getY() - dpto,
|
298 |
DIAM_CIRCLE, |
299 |
DIAM_CIRCLE); |
300 |
g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr); |
301 |
g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY()); |
302 |
if(showNumber){
|
303 |
g.setColor(Color.WHITE);
|
304 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 4), (int)(p.getY() - dpto - 4) ); |
305 |
g.setColor(new Color(45, 8 , 165)); |
306 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 1), (int)(p.getY() - dpto - 1) ); |
307 |
} |
308 |
} |
309 |
|
310 |
/* (non-Javadoc)
|
311 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable, double)
|
312 |
*/
|
313 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
314 |
double scale) throws DriverException { |
315 |
// TODO Auto-generated method stub
|
316 |
|
317 |
} |
318 |
|
319 |
/**
|
320 |
* Elimina los puntos de la lista que no tiene las dos coordenadas asignadas.
|
321 |
*/
|
322 |
public void clean(){ |
323 |
Iterator iter = pointList.iterator();
|
324 |
while (iter.hasNext()) {
|
325 |
GeoPoint gp = (GeoPoint) iter.next(); |
326 |
if(gp.mapPoint == null || gp.pixelPoint == null) |
327 |
iter.remove(); |
328 |
} |
329 |
} |
330 |
/**
|
331 |
* A?ade un punto a la lista
|
332 |
* @param point punto para la lista
|
333 |
*/
|
334 |
public GeoPoint addPoint(Point2D pixel, Point2D map){ |
335 |
GeoPoint p = new GeoPoint(pixel, map);
|
336 |
pointList.add(p); |
337 |
return p;
|
338 |
} |
339 |
|
340 |
/**
|
341 |
* Obtiene el punto de la posici?n pos
|
342 |
*/
|
343 |
public GeoPoint getPoint(int pos){ |
344 |
try{
|
345 |
return (GeoPoint)pointList.get(pos);
|
346 |
}catch(IndexOutOfBoundsException exc){ |
347 |
return null; |
348 |
} |
349 |
} |
350 |
|
351 |
/**
|
352 |
* Elimina la lista de puntos almacenada
|
353 |
*/
|
354 |
public void clear(){ |
355 |
pointList = new ArrayList(); |
356 |
} |
357 |
|
358 |
/**
|
359 |
* Elimina el punto de la posici?n indicada por el par?metro pos
|
360 |
* @param pos Posici?n del punto a eliminar
|
361 |
*/
|
362 |
public void remove(int pos){ |
363 |
pointList.remove(pos); |
364 |
} |
365 |
|
366 |
/**
|
367 |
*Elimina el ?ltimo punto de la lista.
|
368 |
*/
|
369 |
public void delLastPoint(){ |
370 |
pointList.remove(pointList.size() - 1);
|
371 |
} |
372 |
|
373 |
/**
|
374 |
* Funci?n que obtiene si un punto es nuevo o no. Un punto es nuevo si todavia
|
375 |
* no han sido asignadas todas sus coordenadas.
|
376 |
* @param n N?mero de punto a obtener si es nuevo
|
377 |
* @return true si es nuevo o false si no lo es
|
378 |
*/
|
379 |
public boolean isNewPoint(int n){ |
380 |
if(this.getPoint(n) == null) |
381 |
return false; |
382 |
if(this.getPoint(n).pixelPoint == null || this.getPoint(n).mapPoint == null) |
383 |
return true; |
384 |
return false; |
385 |
} |
386 |
|
387 |
/**
|
388 |
* Devuelve el n?mero de puntos de la capa
|
389 |
* @return entero que representa el n?mero de puntos de la capa
|
390 |
*/
|
391 |
public int length(){ |
392 |
return pointList.size();
|
393 |
} |
394 |
|
395 |
/**
|
396 |
* Actualiza un punto de la lista de una posici?n determinada
|
397 |
* @param point punto para la lista
|
398 |
*/
|
399 |
public void updatePoint(Point2D pixel, Point2D map, int pos){ |
400 |
GeoPoint gp = (GeoPoint)pointList.get(pos); |
401 |
if(pixel != null) |
402 |
gp.pixelPoint = pixel; |
403 |
if(map != null) |
404 |
gp.mapPoint = map; |
405 |
} |
406 |
|
407 |
/**
|
408 |
* Calcula el RMS para el punto de la posici?n pos
|
409 |
* @param pos Posici?n
|
410 |
* @return RMS en forma de String
|
411 |
*/
|
412 |
public String calcRMS(int pos){ |
413 |
return "0"; |
414 |
} |
415 |
|
416 |
/**
|
417 |
* Calcula el residuo en X para el punto de la posici?n pos
|
418 |
* @param pos Posici?n
|
419 |
* @return residuo Y en forma de String
|
420 |
*/
|
421 |
public String calcResX(int pos){ |
422 |
/*double resX = 0D;
|
423 |
GeoPoint gp = this.getPoint(pos);
|
424 |
resX = Math.sqrt((gp.mapPoint.getX() - gp.pixelPoint.getX()) * (gp.mapPoint.getX() - gp.pixelPoint.getX()));
|
425 |
return String.valueOf(resX);*/
|
426 |
return "0"; |
427 |
} |
428 |
|
429 |
/**
|
430 |
* Calcula el residuo en Y para el punto de la posici?n pos
|
431 |
* @param pos Posici?n
|
432 |
* @return residuo Y en forma de String
|
433 |
*/
|
434 |
public String calcResY(int pos){ |
435 |
return "0"; |
436 |
} |
437 |
|
438 |
/**
|
439 |
*
|
440 |
* @return
|
441 |
*/
|
442 |
public String calcTotal(){ |
443 |
return "0"; |
444 |
} |
445 |
|
446 |
/**
|
447 |
* Muestra en consola los puntos de la capa
|
448 |
*/
|
449 |
public void showPoints(){ |
450 |
for(int i=0;i<pointList.size();i++){ |
451 |
if(((GeoPoint)pointList.get(i)).pixelPoint != null && ((GeoPoint)pointList.get(i)).mapPoint != null){ |
452 |
System.out.println("PUNTO "+i+": "); |
453 |
System.out.println("pix->"+((GeoPoint)pointList.get(i)).pixelPoint.getX()+" "+((GeoPoint)pointList.get(i)).pixelPoint.getY()); |
454 |
System.out.println("map->"+((GeoPoint)pointList.get(i)).mapPoint.getX()+" "+((GeoPoint)pointList.get(i)).mapPoint.getY()); |
455 |
System.out.println("extRight->"+((GeoPoint)pointList.get(i)).rightViewPort.getExtent()); |
456 |
System.out.println("extLeft->"+((GeoPoint)pointList.get(i)).leftViewPort.getExtent()); |
457 |
}else
|
458 |
System.out.println("PUNTO "+i+": NULL"); |
459 |
} |
460 |
} |
461 |
|
462 |
/**
|
463 |
* Salva la lista de puntos sobre el fichero que se la pasa por
|
464 |
* par?metro
|
465 |
* @param file Nombre del fichero
|
466 |
*/
|
467 |
public void PointList2XML(String file){; |
468 |
geoPointPersistence.savePointList(file); |
469 |
} |
470 |
|
471 |
/**
|
472 |
* Recupera una lista de puntos desde un fichero XML
|
473 |
* @param file Nombre del fichero
|
474 |
*/
|
475 |
public void XML2PointList(String file){ |
476 |
geoPointPersistence.loadPointList(file); |
477 |
} |
478 |
|
479 |
/**
|
480 |
* Salva la lista de puntos en forma tabular sobre el fichero que se la pasa por
|
481 |
* par?metro
|
482 |
* @param file Nombre del fichero
|
483 |
*/
|
484 |
public void PointList2Ascii(String file){; |
485 |
geoPointPersistence.saveAsciiPointList(file); |
486 |
} |
487 |
|
488 |
/* (non-Javadoc)
|
489 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#setXMLEntity(com.iver.utiles.XMLEntity)
|
490 |
*/
|
491 |
public void setXMLEntity(XMLEntity xml)throws XMLException { |
492 |
int nPoints = -1; |
493 |
if (xml.contains("raster.geoPoints.nPoints")) { |
494 |
nPoints = xml.getIntProperty("raster.geoPoints.nPoints");
|
495 |
GeoPoint point = null;
|
496 |
Point2D pixel = new Point2D.Double(), map = new Point2D.Double(); |
497 |
if(nPoints > 0){ |
498 |
|
499 |
for(int i = 0;i<nPoints;i++){ |
500 |
|
501 |
if (xml.contains("raster.geoPoint."+i+".pixelX") && xml.contains("raster.geoPoint."+i+".pixelY")) |
502 |
pixel.setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".pixelX"), xml.getDoubleProperty("raster.geoPoint."+i+".pixelY")); |
503 |
|
504 |
if (xml.contains("raster.geoPoint."+i+".mapX") && xml.contains("raster.geoPoint."+i+".mapY")) |
505 |
map.setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".mapX"), xml.getDoubleProperty("raster.geoPoint."+i+".mapY")); |
506 |
|
507 |
point = this.addPoint(pixel, map);
|
508 |
|
509 |
if (xml.contains("raster.geoPoint."+i+".active")) |
510 |
point.active = xml.getBooleanProperty("raster.geoPoint."+i+".active"); |
511 |
|
512 |
point.leftCenterPoint = new Point2D.Double(); |
513 |
if (xml.contains("raster.geoPoint."+i+".leftCenterX") && xml.contains("raster.geoPoint."+i+".leftCenterY")) |
514 |
point.leftCenterPoint.setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".leftCenterX"), xml.getDoubleProperty("raster.geoPoint."+i+".leftCenterY")); |
515 |
|
516 |
point.rightCenterPoint = new Point2D.Double(); |
517 |
if (xml.contains("raster.geoPoint."+i+".rightCenterX") && xml.contains("raster.geoPoint."+i+".rightCenterY")) |
518 |
point.rightCenterPoint.setLocation(xml.getDoubleProperty("raster.geoPoint."+i+".rightCenterX"), xml.getDoubleProperty("raster.geoPoint."+i+".rightCenterY")); |
519 |
|
520 |
point.leftViewPort = new ViewPort(null); |
521 |
point.rightViewPort = new ViewPort(null); |
522 |
|
523 |
double x = 0D, y = 0D, w = 0D, h = 0D; |
524 |
int width = 0, height = 0; |
525 |
Rectangle2D r = new Rectangle2D.Double(); |
526 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.proj")) |
527 |
point.leftViewPort.setProjection(ProjectionPool.get(xml.getStringProperty("raster.geoPoint."+i+".leftViewPort.proj"))); |
528 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.x")) |
529 |
x = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.x"); |
530 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.y")) |
531 |
y = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.y"); |
532 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.w")) |
533 |
w = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.w"); |
534 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.h")) |
535 |
h = xml.getDoubleProperty("raster.geoPoint."+i+".leftViewPort.h"); |
536 |
r.setRect(x, y, w, h); |
537 |
point.leftViewPort.setExtent(r); |
538 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.imgWidth")) |
539 |
width = xml.getIntProperty("raster.geoPoint."+i+".leftViewPort.imgWidth"); |
540 |
if (xml.contains("raster.geoPoint."+i+".leftViewPort.imgHeight")) |
541 |
height = xml.getIntProperty("raster.geoPoint."+i+".leftViewPort.imgHeight"); |
542 |
point.leftViewPort.setImageSize(new Dimension(width, height)); |
543 |
|
544 |
r = new Rectangle2D.Double(); |
545 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.proj")) |
546 |
point.rightViewPort.setProjection(ProjectionPool.get(xml.getStringProperty("raster.geoPoint."+i+".rightViewPort.proj"))); |
547 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.x")) |
548 |
x = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.x"); |
549 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.y")) |
550 |
y = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.y"); |
551 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.w")) |
552 |
w = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.w"); |
553 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.h")) |
554 |
h = xml.getDoubleProperty("raster.geoPoint."+i+".rightViewPort.h"); |
555 |
r.setRect(x, y, w, h); |
556 |
point.rightViewPort.setExtent(r); |
557 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.imgWidth")) |
558 |
width = xml.getIntProperty("raster.geoPoint."+i+".rightViewPort.imgWidth"); |
559 |
if (xml.contains("raster.geoPoint."+i+".rightViewPort.imgHeight")) |
560 |
height = xml.getIntProperty("raster.geoPoint."+i+".rightViewPort.imgHeight"); |
561 |
point.rightViewPort.setImageSize(new Dimension(width, height)); |
562 |
|
563 |
} |
564 |
} |
565 |
} |
566 |
} |
567 |
|
568 |
/* (non-Javadoc)
|
569 |
* @see com.iver.cit.gvsig.fmap.layers.StatusRasterInterface#getXMLEntity(com.iver.utiles.XMLEntity)
|
570 |
*/
|
571 |
public void getXMLEntity(XMLEntity xml) throws XMLException { |
572 |
xml.putProperty("raster.geoPoints.nPoints", getCountPoints());
|
573 |
for(int i=0;i<this.getCountPoints();i++){ |
574 |
xml.putProperty("raster.geoPoint."+i+".pixelX", getPoint(i).pixelPoint.getX()); |
575 |
xml.putProperty("raster.geoPoint."+i+".pixelY", getPoint(i).pixelPoint.getY()); |
576 |
xml.putProperty("raster.geoPoint."+i+".mapX", getPoint(i).mapPoint.getX()); |
577 |
xml.putProperty("raster.geoPoint."+i+".mapY", getPoint(i).mapPoint.getX()); |
578 |
|
579 |
xml.putProperty("raster.geoPoint."+i+".active", getPoint(i).active); |
580 |
|
581 |
xml.putProperty("raster.geoPoint."+i+".leftCenterX", getPoint(i).leftCenterPoint.getX()); |
582 |
xml.putProperty("raster.geoPoint."+i+".leftCenterY", getPoint(i).leftCenterPoint.getY()); |
583 |
xml.putProperty("raster.geoPoint."+i+".rightCenterX", getPoint(i).rightCenterPoint.getX()); |
584 |
xml.putProperty("raster.geoPoint."+i+".rightCenterY", getPoint(i).rightCenterPoint.getY()); |
585 |
|
586 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.proj", getPoint(i).leftViewPort.getProjection().getAbrev()); |
587 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.x", getPoint(i).leftViewPort.getExtent().getX()); |
588 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.y", getPoint(i).leftViewPort.getExtent().getY()); |
589 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.w", getPoint(i).leftViewPort.getExtent().getWidth()); |
590 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.h", getPoint(i).leftViewPort.getExtent().getHeight()); |
591 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.imgWidth", getPoint(i).leftViewPort.getImageWidth()); |
592 |
xml.putProperty("raster.geoPoint."+i+".leftViewPort.imgHeight", getPoint(i).leftViewPort.getImageHeight()); |
593 |
|
594 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.proj", getPoint(i).rightViewPort.getProjection().getAbrev()); |
595 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.x", getPoint(i).rightViewPort.getExtent().getX()); |
596 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.y", getPoint(i).rightViewPort.getExtent().getY()); |
597 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.w", getPoint(i).rightViewPort.getExtent().getWidth()); |
598 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.h", getPoint(i).rightViewPort.getExtent().getHeight()); |
599 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.imgWidth", getPoint(i).rightViewPort.getImageWidth()); |
600 |
xml.putProperty("raster.geoPoint."+i+".rightViewPort.imgHeight", getPoint(i).rightViewPort.getImageHeight()); |
601 |
} |
602 |
} |
603 |
//**********************End Methods********************************
|
604 |
|
605 |
//**********************Setters & Getters**************************
|
606 |
/**
|
607 |
* Asigna el viewPort de la mini imagen de la derecha en
|
608 |
* el punto de la posici?n que se le pasa por par?metro
|
609 |
* @param pos Posici?n del punto
|
610 |
* @param vp ViewPort asignado
|
611 |
*/
|
612 |
public void setRightViewPort(int pos, ViewPort vp){ |
613 |
getPoint(pos).rightViewPort = vp; |
614 |
} |
615 |
/**
|
616 |
* @return Returns the showNumber.
|
617 |
*/
|
618 |
public boolean isShowNumber() { |
619 |
return showNumber;
|
620 |
} |
621 |
|
622 |
/**
|
623 |
* @param showNumber The showNumber to set.
|
624 |
*/
|
625 |
public void setShowNumber(boolean showNumber) { |
626 |
this.showNumber = showNumber;
|
627 |
} |
628 |
|
629 |
/**
|
630 |
* Asigna el punto central de la mini imagen de la izquierda
|
631 |
* en el punto de la posici?n que se le pasa por par?metro
|
632 |
* @param pos Posici?n del punto
|
633 |
* @param p Punto asignado
|
634 |
*/
|
635 |
public void setLeftCenterPoint(int pos, Point2D p){ |
636 |
getPoint(pos).leftCenterPoint = p; |
637 |
} |
638 |
|
639 |
/**
|
640 |
* Asigna el punto central de la mini imagen de la derecha
|
641 |
* en el punto de la posici?n que se le pasa por par?metro
|
642 |
* @param pos Posici?n del punto
|
643 |
* @param p Punto asignado
|
644 |
*/
|
645 |
public void setRightCenterPoint(int pos, Point2D p){ |
646 |
getPoint(pos).rightCenterPoint = p; |
647 |
} |
648 |
|
649 |
/**
|
650 |
* Asigna el viewPort de la mini imagen de la izquierda en
|
651 |
* el punto de la posici?n que se le pasa por par?metro
|
652 |
* @param pos Posici?n del punto
|
653 |
* @param vp ViewPort asignado
|
654 |
*/
|
655 |
public void setLeftViewPort(int pos, ViewPort vp){ |
656 |
getPoint(pos).leftViewPort = vp; |
657 |
} |
658 |
|
659 |
/**
|
660 |
* Devuelve el n?mero de puntos de la lista
|
661 |
* @return entero que representa el n?mero de puntos
|
662 |
*/
|
663 |
public int getCountPoints(){ |
664 |
if(pointList != null) |
665 |
return pointList.size();
|
666 |
else
|
667 |
return 0; |
668 |
} |
669 |
|
670 |
/**
|
671 |
* Activa o desactiva el punto de una posici?n de la lista
|
672 |
* @param n N?mero de punto
|
673 |
* @param active true activo, false desactivo
|
674 |
*/
|
675 |
public void setPointActive(int n, boolean active){ |
676 |
if(n < 0 || n >= this.length()) |
677 |
return;
|
678 |
((GeoPoint)pointList.get(n)).active = active; |
679 |
} |
680 |
|
681 |
/**
|
682 |
* Dice si un punto de la lista est? activo o no
|
683 |
* @param n Posici?n del punto
|
684 |
* @return true si est? activo y false si no lo est?.
|
685 |
*/
|
686 |
public boolean isPointActive(int n){ |
687 |
if(n < 0 || n >= this.length()) |
688 |
return false; |
689 |
return ((GeoPoint)pointList.get(n)).active;
|
690 |
} |
691 |
|
692 |
/**
|
693 |
* Obtiene el extent de la capa
|
694 |
* @return extent en Rectangle2D.
|
695 |
*/
|
696 |
public Rectangle2D getFullExtent()throws DriverException { |
697 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
698 |
return theView.getMapControl().getMapContext().getViewPort().getExtent();
|
699 |
} |
700 |
|
701 |
/**
|
702 |
* @return Returns the lastTool.
|
703 |
*/
|
704 |
public String getLastTool() { |
705 |
return lastTool;
|
706 |
} |
707 |
|
708 |
/**
|
709 |
* @param lastTool The lastTool to set.
|
710 |
*/
|
711 |
public void setLastTool(String lastTool) { |
712 |
this.lastTool = lastTool;
|
713 |
} |
714 |
|
715 |
/**
|
716 |
*Asigna el extent para las mini imagenes. Estas deben ser recuperadas cuando se selecciona
|
717 |
*un punto
|
718 |
*/
|
719 |
public void setMiniExtent(int nPoint, Point2D centerPoint, ViewPort vp, boolean isRight){ |
720 |
if(isRight){
|
721 |
((GeoPoint)pointList.get(nPoint)).rightCenterPoint = centerPoint; |
722 |
((GeoPoint)pointList.get(nPoint)).rightViewPort = vp; |
723 |
}else{
|
724 |
((GeoPoint)pointList.get(nPoint)).leftCenterPoint = centerPoint; |
725 |
((GeoPoint)pointList.get(nPoint)).leftViewPort = vp; |
726 |
} |
727 |
} |
728 |
|
729 |
/**
|
730 |
* Obtiene el extent de la mini imagen
|
731 |
* @param nPoint Punto de la lista
|
732 |
* @return
|
733 |
*/
|
734 |
public ViewPort getMiniExtent(int nPoint, boolean isRight){ |
735 |
if(isRight)
|
736 |
return ((GeoPoint)pointList.get(nPoint)).rightViewPort;
|
737 |
else
|
738 |
return ((GeoPoint)pointList.get(nPoint)).leftViewPort;
|
739 |
|
740 |
} |
741 |
|
742 |
/**
|
743 |
* Obtiene el punto central de la mini imagen
|
744 |
* @param nPoint Punto de la lista
|
745 |
* @return
|
746 |
*/
|
747 |
public Point2D getCenterPoint(int nPoint, boolean isRight){ |
748 |
if(isRight)
|
749 |
return ((GeoPoint)pointList.get(nPoint)).rightCenterPoint;
|
750 |
else
|
751 |
return ((GeoPoint)pointList.get(nPoint)).leftCenterPoint;
|
752 |
} |
753 |
|
754 |
/**
|
755 |
* Obtiene le ?ltimo punto de la lista
|
756 |
* @return El ?ltimo punto georreferenciado de la lista
|
757 |
*/
|
758 |
public GeoPoint getLastPoint(){
|
759 |
return (GeoPoint)pointList.get(pointList.size());
|
760 |
} |
761 |
|
762 |
/**
|
763 |
* Obtiene el array de puntos
|
764 |
* @return
|
765 |
*/
|
766 |
public ArrayList getListPoint(){ |
767 |
return pointList;
|
768 |
} |
769 |
|
770 |
/**
|
771 |
* Obtiene el gestor de puntos
|
772 |
* @return PointManager
|
773 |
*/
|
774 |
public PointManager getPointManager() {
|
775 |
return pointManager;
|
776 |
} |
777 |
|
778 |
/**
|
779 |
* Asigna el gestor de puntos
|
780 |
* @param PointManager
|
781 |
*/
|
782 |
public void setPointManager(PointManager pointManager) { |
783 |
this.pointManager = pointManager;
|
784 |
} |
785 |
|
786 |
/**
|
787 |
* Obtiene la capa de la imagen a georreferenciar
|
788 |
* @return FLyrGeoRaster
|
789 |
*/
|
790 |
public FLyrGeoRaster getLyrGeoRaster() {
|
791 |
return lyrGeoRaster;
|
792 |
} |
793 |
|
794 |
/**
|
795 |
* Asigna la capa de la imagen a georreferenciar
|
796 |
* @param flyGeoRaster
|
797 |
*/
|
798 |
public void setLyrGeoRaster(FLyrGeoRaster lyGeoRaster){ |
799 |
this.lyrGeoRaster = lyGeoRaster;
|
800 |
if(geoPointPersistence == null) |
801 |
geoPointPersistence = new GeoPointPersistence(this); |
802 |
} |
803 |
|
804 |
/**
|
805 |
* Asigna el flag de visibilidad a true o false. Si est? a true la capa
|
806 |
* es visible normalmente y si est? a false no se mostrar?
|
807 |
* @param visible flag de visibilidad
|
808 |
*/
|
809 |
public void setVisible(boolean visible){ |
810 |
this.lyrVisible = visible;
|
811 |
} |
812 |
|
813 |
/**
|
814 |
* Obtiene el flag de visibilidad true o false. Si est? a true la capa
|
815 |
* es visible normalmente y si est? a false no se muestra
|
816 |
* @return flag de visibilidad
|
817 |
*/
|
818 |
public boolean isVisible(){ |
819 |
return this.lyrVisible; |
820 |
} |
821 |
//**********************End Setters & Getters*********************
|
822 |
} |