svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / fmap / layers / FLyrPoints.java @ 4621
History | View | Annotate | Download (24.3 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Dimension; |
45 |
import java.awt.Graphics2D; |
46 |
import java.awt.geom.Point2D; |
47 |
import java.awt.geom.Rectangle2D; |
48 |
import java.awt.image.BufferedImage; |
49 |
import java.util.ArrayList; |
50 |
import java.util.Iterator; |
51 |
|
52 |
import javax.swing.table.DefaultTableModel; |
53 |
|
54 |
import com.iver.andami.PluginServices; |
55 |
import com.iver.cit.gvsig.GeoPointPersistence; |
56 |
import com.iver.cit.gvsig.fmap.DriverException; |
57 |
import com.iver.cit.gvsig.fmap.ViewPort; |
58 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
59 |
import com.iver.cit.gvsig.gui.View; |
60 |
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog; |
61 |
import com.iver.cit.gvsig.gui.Panels.AdjustGeorefPanel; |
62 |
import com.iver.cit.gvsig.gui.Panels.DataPointPanel; |
63 |
import com.iver.cit.gvsig.gui.Panels.SelectPointsPanel; |
64 |
import com.iver.cit.gvsig.gui.Panels.TablePointsPanel; |
65 |
import com.iver.cit.gvsig.gui.Panels.TablePointsPanel.PointTable; |
66 |
|
67 |
|
68 |
/**
|
69 |
* Clase de capa de marcado de puntos sobre una vista. Dibuja un puntero sobre
|
70 |
* cada punto en la vista.
|
71 |
*
|
72 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
73 |
*/
|
74 |
public class FLyrPoints extends FLyrDefault { |
75 |
|
76 |
/**
|
77 |
* Punto de la capa que representa una coordenada en pixeles de la imagen a
|
78 |
* georreferenciar, una coordenada de la vista, el viewPort de las mini imagenes
|
79 |
* ,el centro de estas y el flag activo que dice si el punto tiene que ser tomado en
|
80 |
* cuenta o no.
|
81 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
82 |
*
|
83 |
*/
|
84 |
public class GeoPoint{ |
85 |
public Point2D pixelPoint = null; |
86 |
public Point2D mapPoint = null; |
87 |
public ViewPort leftViewPort = null, rightViewPort = null; |
88 |
public Point2D leftCenterPoint = null, rightCenterPoint = null; |
89 |
public boolean active = true; |
90 |
|
91 |
/**
|
92 |
* Constructor
|
93 |
*/
|
94 |
public GeoPoint(){}
|
95 |
|
96 |
/**
|
97 |
* Constructor
|
98 |
* @param p pixelPoint
|
99 |
* @param m mapPoint
|
100 |
*/
|
101 |
public GeoPoint(Point2D p, Point2D m){ |
102 |
this.pixelPoint = p;
|
103 |
this.mapPoint = m;
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* Hace una copia de la instancia del punto.
|
108 |
* @return GeoPoint
|
109 |
*/
|
110 |
public GeoPoint cloneGeoPoint(){
|
111 |
Point2D pixel = null; |
112 |
Point2D map = null; |
113 |
if(pixelPoint != null) |
114 |
pixel = (Point2D)pixelPoint.clone();
|
115 |
if(mapPoint != null) |
116 |
map = (Point2D)mapPoint.clone();
|
117 |
|
118 |
GeoPoint gp = new GeoPoint(pixel, map);
|
119 |
|
120 |
if(leftViewPort != null){ |
121 |
gp.leftViewPort = new ViewPort(leftViewPort.getProjection());
|
122 |
gp.leftViewPort.setExtent((Rectangle2D)leftViewPort.getExtent().clone());
|
123 |
gp.leftViewPort.setImageSize((Dimension)leftViewPort.getImageSize().clone());
|
124 |
gp.leftViewPort.setScale(); |
125 |
} |
126 |
|
127 |
if(rightViewPort != null){ |
128 |
gp.rightViewPort = new ViewPort(rightViewPort.getProjection());
|
129 |
gp.rightViewPort.setExtent((Rectangle2D)rightViewPort.getExtent().clone());
|
130 |
gp.rightViewPort.setImageSize((Dimension)rightViewPort.getImageSize().clone());
|
131 |
gp.rightViewPort.setScale(); |
132 |
} |
133 |
|
134 |
if(leftCenterPoint != null) |
135 |
gp.leftCenterPoint = (Point2D)this.leftCenterPoint.clone(); |
136 |
if(rightCenterPoint != null) |
137 |
gp.rightCenterPoint = (Point2D)this.rightCenterPoint.clone(); |
138 |
gp.active = this.active;
|
139 |
return gp;
|
140 |
} |
141 |
|
142 |
} |
143 |
|
144 |
private ArrayList pointList = new ArrayList(); |
145 |
private final int DIAM_CIRCLE = 18; |
146 |
private String lastTool = "zoomIn"; |
147 |
private boolean showNumber = true; |
148 |
private FLyrPointsState state = null; |
149 |
private GeoPointPersistence geoPointPersistence = new GeoPointPersistence(this); |
150 |
private FLyrGeoRaster lyrGeoRaster = null; |
151 |
private ViewPort viewPort = null; |
152 |
|
153 |
/**
|
154 |
* Estado de la capa de puntos.
|
155 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
156 |
*/
|
157 |
public class FLyrPointsState{ |
158 |
public ArrayList pointList = new ArrayList(); |
159 |
public boolean showNumber = true; |
160 |
public String lastTool = "zoomIn"; |
161 |
} |
162 |
|
163 |
|
164 |
/**
|
165 |
* Constructor
|
166 |
* @param flyGeoRaster
|
167 |
*/
|
168 |
public FLyrPoints(FLyrGeoRaster lyGeoRaster){
|
169 |
this.lyrGeoRaster = lyGeoRaster;
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* Obtiene el array de puntos
|
174 |
* @return
|
175 |
*/
|
176 |
public ArrayList getListPoint(){ |
177 |
return pointList;
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* Salva el estado actual de la capa de puntos. Podr? ser recuperado
|
182 |
* este ?ltimo estado salvado con la funci?n recoveryState
|
183 |
*
|
184 |
*/
|
185 |
public void saveState(){ |
186 |
if(state == null) |
187 |
state = new FLyrPointsState();
|
188 |
else
|
189 |
state.pointList.clear(); |
190 |
|
191 |
for(int i=0;i<this.length();i++) |
192 |
state.pointList.add(((GeoPoint)pointList.get(i)).cloneGeoPoint()); |
193 |
|
194 |
state.showNumber = showNumber; |
195 |
state.lastTool = lastTool; |
196 |
} |
197 |
|
198 |
/**
|
199 |
* Recupera el estado de la capa de puntos desde la ?ltima vez que se
|
200 |
* ejecut? la funci?n saveState. Si no hay ning?n estdo salvado es que
|
201 |
* al principio estaba la capa vacia por lo que reiniciamos la capa de puntos.
|
202 |
*/
|
203 |
public void recoveryState(){ |
204 |
if(state != null){ |
205 |
pointList.clear(); |
206 |
for(int i=0;i<state.pointList.size();i++) |
207 |
pointList.add(((GeoPoint)state.pointList.get(i)).cloneGeoPoint()); |
208 |
|
209 |
showNumber = state.showNumber; |
210 |
lastTool = state.lastTool; |
211 |
} |
212 |
} |
213 |
|
214 |
/**
|
215 |
* Asigna el array de puntos
|
216 |
* @param list
|
217 |
*/
|
218 |
public void setListPoint(ArrayList list){ |
219 |
pointList = list; |
220 |
} |
221 |
|
222 |
/**
|
223 |
* Dibujado de la capa de raster georeferenciado aplicando la
|
224 |
* transformaci?n del viewPort.
|
225 |
*/
|
226 |
public void draw(BufferedImage image, Graphics2D g, ViewPort vp, |
227 |
Cancellable cancel,double scale) throws DriverException { |
228 |
|
229 |
View theView = (View)PluginServices.getMDIManager().getActiveView(); |
230 |
ViewPort vpView = theView.getMapControl().getMapContext().getViewPort(); |
231 |
|
232 |
Point2D pto = null; |
233 |
|
234 |
if(lyrGeoRaster != null){ |
235 |
//vp = lyrGeoRaster.toImageCoord(vp);
|
236 |
for(int i=0; i<pointList.size();i++){ |
237 |
//Punto de la imagen
|
238 |
pto = ((GeoPoint)pointList.get(i)).pixelPoint; |
239 |
|
240 |
if(((GeoPoint)pointList.get(i)).active){
|
241 |
if(pto != null){ |
242 |
Point2D p = lyrGeoRaster.img2World(pto);
|
243 |
if(this.viewPort != null) |
244 |
p = this.viewPort.fromMapPoint(p);
|
245 |
else
|
246 |
p = vpView.fromMapPoint(p); |
247 |
drawPixelCrux(g, p, i); |
248 |
} |
249 |
|
250 |
//Punto de la vista
|
251 |
pto = ((GeoPoint)pointList.get(i)).mapPoint; |
252 |
if(pto != null){ |
253 |
Point2D p = null; |
254 |
if(this.viewPort != null) |
255 |
p = this.viewPort.fromMapPoint(pto);
|
256 |
else
|
257 |
p = vpView.fromMapPoint(pto); |
258 |
drawMapCrux(g, p, i); |
259 |
} |
260 |
} |
261 |
} |
262 |
} |
263 |
this.viewPort = null; |
264 |
} |
265 |
|
266 |
/**
|
267 |
* Dibuja sobre el graphics pasado la cruz del punto que marca
|
268 |
* el pixel de la imagen.
|
269 |
* @param g Graphics
|
270 |
*/
|
271 |
private void drawPixelCrux(Graphics2D g, Point2D p, int pointNumber){ |
272 |
int dpto = (DIAM_CIRCLE >> 1); |
273 |
int incr = 5; |
274 |
g.setColor(Color.WHITE);
|
275 |
g.drawOval( (int)p.getX() - dpto + 1, |
276 |
(int)p.getY() - dpto + 1, |
277 |
DIAM_CIRCLE - 2,
|
278 |
DIAM_CIRCLE - 2);
|
279 |
g.drawLine((int)p.getX() - incr, (int)p.getY() - 1, (int)p.getX() - 1, (int)p.getY() - 1); |
280 |
g.drawLine((int)p.getX() - incr, (int)p.getY() + 1, (int)p.getX() - 1, (int)p.getY() + 1); |
281 |
|
282 |
g.drawLine((int)p.getX() + incr, (int)p.getY() - 1, (int)p.getX() + 1, (int)p.getY() - 1); |
283 |
g.drawLine((int)p.getX() + incr, (int)p.getY() + 1, (int)p.getX() + 1, (int)p.getY() + 1); |
284 |
|
285 |
g.drawLine((int)p.getX() - 1, (int)p.getY() - incr, (int)p.getX() - 1, (int)p.getY() - 1); |
286 |
g.drawLine((int)p.getX() + 1, (int)p.getY() - incr, (int)p.getX() + 1, (int)p.getY() - 1); |
287 |
|
288 |
g.drawLine((int)p.getX() - 1, (int)p.getY() + incr, (int)p.getX() - 1, (int)p.getY() + 1); |
289 |
g.drawLine((int)p.getX() + 1, (int)p.getY() + incr, (int)p.getX() + 1, (int)p.getY() + 1); |
290 |
|
291 |
g.setColor(Color.red);
|
292 |
g.drawOval( (int)p.getX() - dpto,
|
293 |
(int)p.getY() - dpto,
|
294 |
DIAM_CIRCLE, |
295 |
DIAM_CIRCLE); |
296 |
g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr); |
297 |
g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY()); |
298 |
//g.drawLine((int)p.getX() - dpto, (int)p.getY() - dpto , (int)p.getX() - dpto + DIAM_CIRCLE, (int)p.getY() - dpto + DIAM_CIRCLE);
|
299 |
//g.drawLine((int)p.getX() - dpto, (int)p.getY() - dpto + DIAM_CIRCLE, (int)p.getX() - dpto + DIAM_CIRCLE, (int)p.getY() - dpto);
|
300 |
|
301 |
if(showNumber){
|
302 |
g.setColor(Color.WHITE);
|
303 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 4), (int)(p.getY() - dpto - 4) ); |
304 |
g.setColor(Color.red);
|
305 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 1), (int)(p.getY() - dpto - 1) ); |
306 |
} |
307 |
} |
308 |
|
309 |
/**
|
310 |
* Dibuja sobre el graphics pasado la cruz del punto que marca
|
311 |
* la coordenada de la vista.
|
312 |
* @param g Graphics
|
313 |
*/
|
314 |
private void drawMapCrux(Graphics2D g, Point2D p, int pointNumber){ |
315 |
int dpto = (DIAM_CIRCLE >> 1); |
316 |
int incr = 5; |
317 |
g.setColor(Color.WHITE);
|
318 |
g.drawRect( (int)p.getX() - dpto + 1, |
319 |
(int)p.getY() - dpto + 1, |
320 |
DIAM_CIRCLE - 2,
|
321 |
DIAM_CIRCLE - 2);
|
322 |
g.drawLine((int)p.getX() - incr, (int)p.getY() - 1, (int)p.getX() - 1, (int)p.getY() - 1); |
323 |
g.drawLine((int)p.getX() - incr, (int)p.getY() + 1, (int)p.getX() - 1, (int)p.getY() + 1); |
324 |
|
325 |
g.drawLine((int)p.getX() + incr, (int)p.getY() - 1, (int)p.getX() + 1, (int)p.getY() - 1); |
326 |
g.drawLine((int)p.getX() + incr, (int)p.getY() + 1, (int)p.getX() + 1, (int)p.getY() + 1); |
327 |
|
328 |
g.drawLine((int)p.getX() - 1, (int)p.getY() - incr, (int)p.getX() - 1, (int)p.getY() - 1); |
329 |
g.drawLine((int)p.getX() + 1, (int)p.getY() - incr, (int)p.getX() + 1, (int)p.getY() - 1); |
330 |
|
331 |
g.drawLine((int)p.getX() - 1, (int)p.getY() + incr, (int)p.getX() - 1, (int)p.getY() + 1); |
332 |
g.drawLine((int)p.getX() + 1, (int)p.getY() + incr, (int)p.getX() + 1, (int)p.getY() + 1); |
333 |
|
334 |
g.setColor(new Color(45, 8 , 165)); |
335 |
g.drawRect( (int)p.getX() - dpto,
|
336 |
(int)p.getY() - dpto,
|
337 |
DIAM_CIRCLE, |
338 |
DIAM_CIRCLE); |
339 |
g.drawLine((int)p.getX(), (int)p.getY() - dpto - incr, (int)p.getX(), (int)p.getY() + dpto + incr); |
340 |
g.drawLine((int)p.getX() - dpto - incr, (int)p.getY(), (int)p.getX() + dpto + incr, (int)p.getY()); |
341 |
if(showNumber){
|
342 |
g.setColor(Color.WHITE);
|
343 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 4), (int)(p.getY() - dpto - 4) ); |
344 |
g.setColor(new Color(45, 8 , 165)); |
345 |
g.drawString(String.valueOf(pointNumber + 1), (int)(p.getX() + dpto + 1), (int)(p.getY() - dpto - 1) ); |
346 |
} |
347 |
} |
348 |
|
349 |
/* (non-Javadoc)
|
350 |
* @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)
|
351 |
*/
|
352 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
353 |
double scale) throws DriverException { |
354 |
// TODO Auto-generated method stub
|
355 |
|
356 |
} |
357 |
|
358 |
/**
|
359 |
* Elimina los puntos de la lista que no tiene las dos coordenadas asignadas.
|
360 |
*/
|
361 |
public void clean(){ |
362 |
Iterator iter = pointList.iterator();
|
363 |
while (iter.hasNext()) {
|
364 |
GeoPoint gp = (GeoPoint) iter.next(); |
365 |
if(gp.mapPoint == null || gp.pixelPoint == null) |
366 |
iter.remove(); |
367 |
} |
368 |
} |
369 |
/**
|
370 |
* A?ade un punto a la lista
|
371 |
* @param point punto para la lista
|
372 |
*/
|
373 |
public void addPoint(Point2D pixel, Point2D map){ |
374 |
pointList.add(new GeoPoint(pixel, map));
|
375 |
} |
376 |
|
377 |
/**
|
378 |
* Obtiene el punto de la posici?n pos
|
379 |
*/
|
380 |
public GeoPoint getPoint(int pos){ |
381 |
try{
|
382 |
return (GeoPoint)pointList.get(pos);
|
383 |
}catch(IndexOutOfBoundsException exc){ |
384 |
return null; |
385 |
} |
386 |
} |
387 |
|
388 |
/**
|
389 |
* Elimina la lista de puntos almacenada
|
390 |
*/
|
391 |
public void clear(){ |
392 |
pointList = new ArrayList(); |
393 |
} |
394 |
|
395 |
/**
|
396 |
* Elimina el punto de la posici?n indicada por el par?metro pos
|
397 |
* @param pos Posici?n del punto a eliminar
|
398 |
*/
|
399 |
public void remove(int pos){ |
400 |
pointList.remove(pos); |
401 |
} |
402 |
|
403 |
/**
|
404 |
*Elimina el ?ltimo punto de la lista.
|
405 |
*/
|
406 |
public void delLastPoint(){ |
407 |
pointList.remove(pointList.size() - 1);
|
408 |
} |
409 |
|
410 |
/**
|
411 |
* Obtiene le ?ltimo punto de la lista
|
412 |
* @return El ?ltimo punto georreferenciado de la lista
|
413 |
*/
|
414 |
public GeoPoint getLastPoint(){
|
415 |
return (GeoPoint)pointList.get(pointList.size());
|
416 |
} |
417 |
|
418 |
/**
|
419 |
* Devuelve el n?mero de puntos de la capa
|
420 |
* @return entero que representa el n?mero de puntos de la capa
|
421 |
*/
|
422 |
public int length(){ |
423 |
return pointList.size();
|
424 |
} |
425 |
|
426 |
/**
|
427 |
* Actualiza un punto de la lista de una posici?n determinada
|
428 |
* @param point punto para la lista
|
429 |
*/
|
430 |
public void updatePoint(Point2D pixel, Point2D map, int pos){ |
431 |
GeoPoint gp = (GeoPoint)pointList.get(pos); |
432 |
if(pixel != null) |
433 |
gp.pixelPoint = pixel; |
434 |
if(map != null) |
435 |
gp.mapPoint = map; |
436 |
} |
437 |
|
438 |
/**
|
439 |
* Devuelve el n?mero de puntos de la lista
|
440 |
* @return entero que representa el n?mero de puntos
|
441 |
*/
|
442 |
public int getCountPoints(){ |
443 |
if(pointList != null) |
444 |
return pointList.size();
|
445 |
else
|
446 |
return 0; |
447 |
} |
448 |
|
449 |
/**
|
450 |
* Activa o desactiva el punto de una posici?n de la lista
|
451 |
* @param n N?mero de punto
|
452 |
* @param active true activo, false desactivo
|
453 |
*/
|
454 |
public void setPointActive(int n, boolean active){ |
455 |
if(n < 0 || n >= this.length()) |
456 |
return;
|
457 |
((GeoPoint)pointList.get(n)).active = active; |
458 |
} |
459 |
|
460 |
/**
|
461 |
* Dice si un punto de la lista est? activo o no
|
462 |
* @param n Posici?n del punto
|
463 |
* @return true si est? activo y false si no lo est?.
|
464 |
*/
|
465 |
public boolean isPointActive(int n){ |
466 |
if(n < 0 || n >= this.length()) |
467 |
return false; |
468 |
return ((GeoPoint)pointList.get(n)).active;
|
469 |
} |
470 |
|
471 |
/**
|
472 |
* Obtiene el extent de la capa
|
473 |
* @return extent en Rectangle2D.
|
474 |
*/
|
475 |
public Rectangle2D getFullExtent()throws DriverException { |
476 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
477 |
return theView.getMapControl().getMapContext().getViewPort().getExtent();
|
478 |
} |
479 |
|
480 |
/**
|
481 |
* @return Returns the lastTool.
|
482 |
*/
|
483 |
public String getLastTool() { |
484 |
return lastTool;
|
485 |
} |
486 |
|
487 |
/**
|
488 |
* @param lastTool The lastTool to set.
|
489 |
*/
|
490 |
public void setLastTool(String lastTool) { |
491 |
this.lastTool = lastTool;
|
492 |
} |
493 |
|
494 |
/**
|
495 |
*Asigna el extent para las mini imagenes. Estas deben ser recuperadas cuando se selecciona
|
496 |
*un punto
|
497 |
*/
|
498 |
public void setMiniExtent(int nPoint, Point2D centerPoint, ViewPort vp, boolean isRight){ |
499 |
if(isRight){
|
500 |
((GeoPoint)pointList.get(nPoint)).rightCenterPoint = centerPoint; |
501 |
((GeoPoint)pointList.get(nPoint)).rightViewPort = vp; |
502 |
}else{
|
503 |
((GeoPoint)pointList.get(nPoint)).leftCenterPoint = centerPoint; |
504 |
((GeoPoint)pointList.get(nPoint)).leftViewPort = vp; |
505 |
} |
506 |
} |
507 |
|
508 |
/**
|
509 |
* Obtiene el extent de la mini imagen
|
510 |
* @param nPoint Punto de la lista
|
511 |
* @return
|
512 |
*/
|
513 |
public ViewPort getMiniExtent(int nPoint, boolean isRight){ |
514 |
if(isRight)
|
515 |
return ((GeoPoint)pointList.get(nPoint)).rightViewPort;
|
516 |
else
|
517 |
return ((GeoPoint)pointList.get(nPoint)).leftViewPort;
|
518 |
|
519 |
} |
520 |
|
521 |
/**
|
522 |
* Obtiene el punto central de la mini imagen
|
523 |
* @param nPoint Punto de la lista
|
524 |
* @return
|
525 |
*/
|
526 |
public Point2D getCenterPoint(int nPoint, boolean isRight){ |
527 |
if(isRight)
|
528 |
return ((GeoPoint)pointList.get(nPoint)).rightCenterPoint;
|
529 |
else
|
530 |
return ((GeoPoint)pointList.get(nPoint)).leftCenterPoint;
|
531 |
} |
532 |
|
533 |
/**
|
534 |
* Recorta los decimales para el visualizado en la selecci?n de puntos
|
535 |
* @param s Cadena de entrada
|
536 |
* @return Cadena de salida con decimales recortados
|
537 |
*/
|
538 |
public static String tailDecimal(String s){ |
539 |
int len = 5; |
540 |
int index = s.indexOf("."); |
541 |
if( index == -1) |
542 |
return s;
|
543 |
else{
|
544 |
if((index + len) >= s.length())
|
545 |
return s;
|
546 |
return s.substring(0, index + len + 1); |
547 |
} |
548 |
} |
549 |
|
550 |
/**
|
551 |
* Calcula el RMS para el punto de la posici?n pos
|
552 |
* @param pos Posici?n
|
553 |
* @return RMS en forma de String
|
554 |
*/
|
555 |
public String calcRMS(int pos){ |
556 |
return "0"; |
557 |
} |
558 |
|
559 |
/**
|
560 |
* Calcula el residuo en X para el punto de la posici?n pos
|
561 |
* @param pos Posici?n
|
562 |
* @return residuo Y en forma de String
|
563 |
*/
|
564 |
public String calcResX(int pos){ |
565 |
/*double resX = 0D;
|
566 |
GeoPoint gp = this.getPoint(pos);
|
567 |
resX = Math.sqrt((gp.mapPoint.getX() - gp.pixelPoint.getX()) * (gp.mapPoint.getX() - gp.pixelPoint.getX()));
|
568 |
return String.valueOf(resX);*/
|
569 |
return "0"; |
570 |
} |
571 |
|
572 |
/**
|
573 |
* Calcula el residuo en Y para el punto de la posici?n pos
|
574 |
* @param pos Posici?n
|
575 |
* @return residuo Y en forma de String
|
576 |
*/
|
577 |
public String calcResY(int pos){ |
578 |
return "0"; |
579 |
} |
580 |
|
581 |
/**
|
582 |
*
|
583 |
* @return
|
584 |
*/
|
585 |
public String calcTotal(){ |
586 |
return "0"; |
587 |
} |
588 |
|
589 |
/**
|
590 |
* Busca el punto en la capa FLyrPoint que corresponde con la posicion pos
|
591 |
* y carga la informaci?n de este en el panel de informaci?n pasado por par?metro.
|
592 |
* @param pos Posici?n del punto
|
593 |
* @param panel donde se carga la informaci?n
|
594 |
*/
|
595 |
public void loadVisualPoint(int pos, GeoreferencingDialog dialog){ |
596 |
GeoPoint pto = null;
|
597 |
try{
|
598 |
pto = this.getPoint(pos);
|
599 |
}catch(ArrayIndexOutOfBoundsException exc){ |
600 |
//Todavia no hay puntos por lo que no hacemos nada
|
601 |
return;
|
602 |
} |
603 |
DataPointPanel dpp = dialog.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getDataPointPanel(); |
604 |
|
605 |
//Llenamos los JTextField con los valores del punto
|
606 |
if(pto.pixelPoint != null){ |
607 |
dpp.getTX().setText(""+pto.pixelPoint.getX());
|
608 |
dpp.getTY().setText(""+pto.pixelPoint.getY());
|
609 |
} |
610 |
if(pto.mapPoint != null){ |
611 |
dpp.getLatitud().setText(tailDecimal(""+pto.mapPoint.getY()));
|
612 |
dpp.getLongitud().setText(tailDecimal(""+pto.mapPoint.getX()));
|
613 |
} |
614 |
|
615 |
//El Checkbox de activaci?n
|
616 |
dialog.getOptionsPanel().getCbActivePoint().setSelected(pto.active); |
617 |
|
618 |
//Seleccionamos la fila de la tabla
|
619 |
PointTable table = dialog.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getJTable(); |
620 |
try{
|
621 |
table.getTable().setRowSelectionInterval(pos, pos); |
622 |
}catch(IllegalArgumentException exc){ |
623 |
System.err.println("Intervalo erroneo "+pos); |
624 |
} |
625 |
|
626 |
//Cargamos las mini imagenes
|
627 |
dialog.getZoomControlLeft().setCenterPoint(getCenterPoint(pos, false));
|
628 |
dialog.getZoomControlLeft().setNewViewPort(getMiniExtent(pos, false));
|
629 |
dialog.getZoomControlLeft().draw(); |
630 |
|
631 |
dialog.getZoomControlRight().setCenterPoint(getCenterPoint(pos, true));
|
632 |
dialog.getZoomControlRight().setNewViewPort(getMiniExtent(pos, true));
|
633 |
dialog.getZoomControlRight().draw(); |
634 |
|
635 |
//Calculamos los errores
|
636 |
String s = calcRMS(pos);
|
637 |
int index = s.indexOf("."); |
638 |
if(index != -1) |
639 |
dialog.setRMS(s.substring(0, index + 7)); |
640 |
else
|
641 |
dialog.setRMS(s); |
642 |
|
643 |
s = calcResX(pos); |
644 |
index = s.indexOf(".");
|
645 |
if(index != -1) |
646 |
dialog.setResX(s.substring(0, index + 7)); |
647 |
else
|
648 |
dialog.setResX(s); |
649 |
|
650 |
s = calcResY(pos); |
651 |
index = s.indexOf(".");
|
652 |
if(index != -1) |
653 |
dialog.setResY(s.substring(0, index + 7)); |
654 |
else
|
655 |
dialog.setResY(s); |
656 |
|
657 |
s = calcTotal(); |
658 |
index = s.indexOf(".");
|
659 |
if(index != -1) |
660 |
dialog.setTotal(s.substring(0, index + 7)); |
661 |
else
|
662 |
dialog.setTotal(s); |
663 |
|
664 |
} |
665 |
|
666 |
/**
|
667 |
* Limpia la lista de puntos .
|
668 |
*/
|
669 |
public void clearVisualList(SelectPointsPanel spp, TablePointsPanel tpp, AdjustGeorefPanel agp){ |
670 |
//Limpiamos la lista de puntos
|
671 |
clear(); |
672 |
//Limpiamos los controles del Selector de puntos
|
673 |
spp.resetControls(false);
|
674 |
spp.getTableControlerPanel().resetControls(); |
675 |
|
676 |
//Limpiamos la tabla y sus controles
|
677 |
tpp.clearTable(); |
678 |
tpp.getTableControlerPanel().resetControls(); |
679 |
|
680 |
//Limpiamos las miniimagenes
|
681 |
agp.getZoomLeft().clear(); |
682 |
agp.getZoomRight().clear(); |
683 |
|
684 |
//Actualizamos la vista
|
685 |
View theView = null; |
686 |
try{
|
687 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
688 |
theView.getMapControl().getMapContext().invalidate(); |
689 |
}catch(ClassCastException exc){ |
690 |
return;
|
691 |
} |
692 |
} |
693 |
|
694 |
/**
|
695 |
* Elimina un punto de la lista y lo elimina del panel
|
696 |
* @param pos Posici?n del punto
|
697 |
* @param grd Panel a limpiar
|
698 |
*/
|
699 |
public void deleteVisualPoint(int pos, GeoreferencingDialog grd){ |
700 |
remove(pos); |
701 |
|
702 |
//Actualiza los controles de tabla y selector
|
703 |
grd.getSelectPointsPanel().getTableControlerPanel().setNItems(this.length());
|
704 |
grd.getConectorPanel().getDataPointsTabPanel(). |
705 |
getTablePointsPanel().getTableControlerPanel().setNItems(this.length());
|
706 |
|
707 |
//Elimina la fila de la tabla y renumera los puntos
|
708 |
try{
|
709 |
grd.removeTableValueAt(pos); |
710 |
|
711 |
for(int i=0;i<length();i++) |
712 |
grd.setTableValueAt(String.valueOf(i), i, 0); |
713 |
}catch(ArrayIndexOutOfBoundsException exc){ |
714 |
//Si intentamos eliminar una fila que no existe no hacemos nada, simplemente no la eliminamos
|
715 |
} |
716 |
|
717 |
//Carga los puntos
|
718 |
if(pos == 0){ |
719 |
grd.getSelectPointsPanel().getTableControlerPanel().setSelectedIndex(pos); |
720 |
loadVisualPoint(pos, grd); |
721 |
}else{
|
722 |
grd.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel().setSelectedIndex(pos - 1);
|
723 |
loadVisualPoint(pos - 1, grd);
|
724 |
} |
725 |
|
726 |
//Redibujamos la vista
|
727 |
View theView = null; |
728 |
try{
|
729 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
730 |
theView.getMapControl().getMapContext().invalidate(); |
731 |
}catch(ClassCastException exc){ |
732 |
return;
|
733 |
} |
734 |
} |
735 |
|
736 |
/**
|
737 |
* Muestra en consola los puntos de la capa
|
738 |
*/
|
739 |
public void showPoints(){ |
740 |
for(int i=0;i<pointList.size();i++){ |
741 |
if(((GeoPoint)pointList.get(i)).pixelPoint != null && ((GeoPoint)pointList.get(i)).mapPoint != null){ |
742 |
System.out.println("PUNTO "+i+": "); |
743 |
System.out.println("pix->"+((GeoPoint)pointList.get(i)).pixelPoint.getX()+" "+((GeoPoint)pointList.get(i)).pixelPoint.getY()); |
744 |
System.out.println("map->"+((GeoPoint)pointList.get(i)).mapPoint.getX()+" "+((GeoPoint)pointList.get(i)).mapPoint.getY()); |
745 |
System.out.println("extRight->"+((GeoPoint)pointList.get(i)).rightViewPort.getExtent()); |
746 |
System.out.println("extLeft->"+((GeoPoint)pointList.get(i)).leftViewPort.getExtent()); |
747 |
}else
|
748 |
System.out.println("PUNTO "+i+": NULL"); |
749 |
} |
750 |
} |
751 |
|
752 |
/**
|
753 |
* @return Returns the showNumber.
|
754 |
*/
|
755 |
public boolean isShowNumber() { |
756 |
return showNumber;
|
757 |
} |
758 |
|
759 |
/**
|
760 |
* @param showNumber The showNumber to set.
|
761 |
*/
|
762 |
public void setShowNumber(boolean showNumber) { |
763 |
this.showNumber = showNumber;
|
764 |
} |
765 |
|
766 |
/**
|
767 |
* Asigna el punto central de la mini imagen de la izquierda
|
768 |
* en el punto de la posici?n que se le pasa por par?metro
|
769 |
* @param pos Posici?n del punto
|
770 |
* @param p Punto asignado
|
771 |
*/
|
772 |
public void setLeftCenterPoint(int pos, Point2D p){ |
773 |
getPoint(pos).leftCenterPoint = p; |
774 |
} |
775 |
|
776 |
/**
|
777 |
* Asigna el punto central de la mini imagen de la derecha
|
778 |
* en el punto de la posici?n que se le pasa por par?metro
|
779 |
* @param pos Posici?n del punto
|
780 |
* @param p Punto asignado
|
781 |
*/
|
782 |
public void setRightCenterPoint(int pos, Point2D p){ |
783 |
getPoint(pos).rightCenterPoint = p; |
784 |
} |
785 |
|
786 |
/**
|
787 |
* Asigna el viewPort de la mini imagen de la izquierda en
|
788 |
* el punto de la posici?n que se le pasa por par?metro
|
789 |
* @param pos Posici?n del punto
|
790 |
* @param vp ViewPort asignado
|
791 |
*/
|
792 |
public void setLeftViewPort(int pos, ViewPort vp){ |
793 |
getPoint(pos).leftViewPort = vp; |
794 |
} |
795 |
|
796 |
/**
|
797 |
* Asigna el viewPort de la mini imagen de la derecha en
|
798 |
* el punto de la posici?n que se le pasa por par?metro
|
799 |
* @param pos Posici?n del punto
|
800 |
* @param vp ViewPort asignado
|
801 |
*/
|
802 |
public void setRightViewPort(int pos, ViewPort vp){ |
803 |
getPoint(pos).rightViewPort = vp; |
804 |
} |
805 |
|
806 |
/**
|
807 |
* Salva la lista de puntos sobre el fichero que se la pasa por
|
808 |
* par?metro
|
809 |
* @param file Nombre del fichero
|
810 |
*/
|
811 |
public void PointList2XML(String file){; |
812 |
geoPointPersistence.savePointList(file); |
813 |
} |
814 |
|
815 |
/**
|
816 |
* Recupera una lista de puntos desde un fichero XML
|
817 |
* @param file Nombre del fichero
|
818 |
*/
|
819 |
public void XML2PointList(String file){ |
820 |
geoPointPersistence.loadPointList(file); |
821 |
} |
822 |
|
823 |
/**
|
824 |
*
|
825 |
* @param geoDialog
|
826 |
*/
|
827 |
public void updateData(GeoreferencingDialog geoDialog){ |
828 |
geoPointPersistence.updateData(geoDialog); |
829 |
} |
830 |
|
831 |
/**
|
832 |
* Asigna el viewPort de la vista sobre la que se dibuja. Si no hay ninguna
|
833 |
* asignada se usar? el de la vista de gvSIG. Esta funci?n es util para cuando
|
834 |
* las miniimagenes tienen que dibujar sobre su propio graphics que tiene un
|
835 |
* viewPort distinto al de la vista.
|
836 |
* @param vp ViewPort sobre el que se dibuja
|
837 |
*/
|
838 |
public void setDrawView(ViewPort vp) { |
839 |
this.viewPort = vp;
|
840 |
} |
841 |
|
842 |
} |