root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / main / LayersPointManager.java @ 18756
History | View | Annotate | Download (15.2 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 |
package org.gvsig.georeferencing.main; |
20 |
|
21 |
import java.awt.geom.Point2D; |
22 |
import java.util.ArrayList; |
23 |
|
24 |
import org.gvsig.georeferencing.ui.table.GCPTablePanel; |
25 |
import org.gvsig.georeferencing.ui.zoom.ViewMapRequestManager; |
26 |
import org.gvsig.georeferencing.ui.zoom.ViewRasterRequestManager; |
27 |
import org.gvsig.georeferencing.ui.zoom.layers.GCPsGraphicLayer; |
28 |
import org.gvsig.georeferencing.ui.zoom.layers.GPGraphic; |
29 |
import org.gvsig.georeferencing.ui.zoom.tools.PanTool; |
30 |
import org.gvsig.georeferencing.ui.zoom.tools.SelectPointTool; |
31 |
import org.gvsig.georeferencing.ui.zoom.tools.ZoomRectangleTool; |
32 |
import org.gvsig.georeferencing.view.BaseZoomView; |
33 |
import org.gvsig.georeferencing.view.ViewDialog; |
34 |
import org.gvsig.georeferencing.view.ZoomDialog; |
35 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
36 |
import org.gvsig.raster.datastruct.GeoPoint; |
37 |
|
38 |
/**
|
39 |
* Clase para realizar operaciones y mantener la sincronizaci?n entre las
|
40 |
* capas de puntos de las dos vistas y las dos ventanas de zoom.
|
41 |
*
|
42 |
* 04/02/2008
|
43 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
44 |
*/
|
45 |
public class LayersPointManager { |
46 |
private Georeferencing appMain = null; |
47 |
//Vistas
|
48 |
private ViewDialog viewRaster = null; |
49 |
private ViewDialog viewMap = null; |
50 |
private ZoomDialog zoomMap = null; |
51 |
private ZoomDialog zoomRaster = null; |
52 |
|
53 |
//Capas de puntos
|
54 |
private GCPsGraphicLayer viewRasterGCPs = null; |
55 |
private GCPsGraphicLayer viewMapGCPs = null; |
56 |
private GCPsGraphicLayer viewRasterGCPsZoom = null; |
57 |
private GCPsGraphicLayer viewMapGCPsZoom = null; |
58 |
|
59 |
//Herramientas de selecci?n
|
60 |
private SelectPointTool viewRasterSelectPointTool = null; |
61 |
private SelectPointTool viewMapSelectPointTool = null; |
62 |
private SelectPointTool zoomRasterSelectPointTool = null; |
63 |
private SelectPointTool zoomMapSelectPointTool = null; |
64 |
|
65 |
/**
|
66 |
* Constructor. Asigna la clase de georreferenciaci?n
|
67 |
* @param appMain
|
68 |
*/
|
69 |
public LayersPointManager(Georeferencing appMain) {
|
70 |
this.appMain = appMain;
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Asigna las vistas
|
75 |
* @param vRaster
|
76 |
* @param vMap
|
77 |
* @param zRaster
|
78 |
* @param zMap
|
79 |
*/
|
80 |
public void setViews(ViewDialog vRaster, ViewDialog vMap, ZoomDialog zRaster, ZoomDialog zMap) { |
81 |
viewRaster = vRaster; |
82 |
viewMap = vMap; |
83 |
zoomMap = zMap; |
84 |
zoomRaster = zRaster; |
85 |
} |
86 |
|
87 |
/**
|
88 |
* Asigna las capas de puntos
|
89 |
* @param vRaster
|
90 |
* @param vMap
|
91 |
* @param zRaster
|
92 |
* @param zMap
|
93 |
*/
|
94 |
public void setLayerPoints(GCPsGraphicLayer vRaster, GCPsGraphicLayer vMap, GCPsGraphicLayer zRaster, GCPsGraphicLayer zMap) { |
95 |
viewRasterGCPs = vRaster; |
96 |
viewMapGCPs = vMap; |
97 |
viewRasterGCPsZoom = zRaster; |
98 |
viewMapGCPsZoom = zMap; |
99 |
} |
100 |
|
101 |
/**
|
102 |
* Asigna las herramientas de selecci?n de puntos
|
103 |
* @param vRaster
|
104 |
* @param vMap
|
105 |
* @param zRaster
|
106 |
* @param zMap
|
107 |
*/
|
108 |
public void setTools(SelectPointTool vRaster, SelectPointTool vMap, SelectPointTool zRaster, SelectPointTool zMap) { |
109 |
viewRasterSelectPointTool = vRaster; |
110 |
viewMapSelectPointTool = vMap; |
111 |
zoomRasterSelectPointTool = zRaster; |
112 |
zoomMapSelectPointTool = zMap; |
113 |
} |
114 |
|
115 |
/**
|
116 |
* Activa o desactiva la capa de puntos
|
117 |
* @param active
|
118 |
*/
|
119 |
public void setActiveLayerZoomCursor(boolean active) { |
120 |
if(viewRaster != null && viewRaster.getZoomCursorGraphicLayer() != null) |
121 |
viewRaster.getZoomCursorGraphicLayer().setActive(active); |
122 |
if(viewMap != null && viewMap.getZoomCursorGraphicLayer() != null) |
123 |
viewMap.getZoomCursorGraphicLayer().setActive(active); |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Recalcula las coordenadas de dibujado de los puntos de control
|
128 |
* y redibuja estos en todas las vistas
|
129 |
*/
|
130 |
public void redrawPoints() { |
131 |
if(viewMapGCPs != null) |
132 |
viewMapGCPs.recalcMapDrawCoordinates(); |
133 |
if(viewRasterGCPs != null) |
134 |
viewRasterGCPs.recalcPixelDrawCoordinates(); |
135 |
if(viewMapGCPsZoom != null) |
136 |
viewMapGCPsZoom.recalcMapDrawCoordinates(); |
137 |
if(viewRasterGCPsZoom != null) |
138 |
viewRasterGCPsZoom.recalcPixelDrawCoordinates(); |
139 |
repaint(); |
140 |
} |
141 |
|
142 |
/**
|
143 |
* Redibuja el canvas de todas las vistas
|
144 |
*/
|
145 |
private void repaint() { |
146 |
if(viewRaster != null) |
147 |
viewRaster.getCanvas().repaint(); |
148 |
if(viewMap != null) |
149 |
viewMap.getCanvas().repaint(); |
150 |
if(zoomMap != null) |
151 |
zoomMap.getCanvas().repaint(); |
152 |
if(zoomRaster != null) |
153 |
zoomRaster.getCanvas().repaint(); |
154 |
} |
155 |
|
156 |
/**
|
157 |
* Registra el listener para la herramienta de selecci?n de puntos de control
|
158 |
*/
|
159 |
public void registerPointToolListener() { |
160 |
if(zoomMap != null) { |
161 |
zoomMapSelectPointTool.setActive(false);
|
162 |
zoomMap.getControl().addTool(zoomMapSelectPointTool); |
163 |
zoomMap.getControl().registerToolListener(ZoomRectangleTool.class, appMain); |
164 |
zoomMap.getControl().registerToolListener(PanTool.class, appMain); |
165 |
} |
166 |
if(zoomRaster != null) { |
167 |
zoomRasterSelectPointTool.setActive(false);
|
168 |
zoomRaster.getControl().addTool(zoomRasterSelectPointTool); |
169 |
zoomRaster.getControl().registerToolListener(ZoomRectangleTool.class, appMain); |
170 |
zoomRaster.getControl().registerToolListener(PanTool.class, appMain); |
171 |
} |
172 |
if(viewRaster != null) { |
173 |
viewRasterSelectPointTool.setActive(false);
|
174 |
viewRaster.getControl().addTool(viewRasterSelectPointTool); |
175 |
viewRaster.getControl().registerToolListener(ZoomRectangleTool.class, appMain); |
176 |
viewRaster.getControl().registerToolListener(PanTool.class, appMain); |
177 |
} |
178 |
if(viewMap != null) { |
179 |
viewMapSelectPointTool.setActive(false);
|
180 |
viewMap.getControl().addTool(viewMapSelectPointTool); |
181 |
viewMap.getControl().registerToolListener(ZoomRectangleTool.class, appMain); |
182 |
viewMap.getControl().registerToolListener(PanTool.class, appMain); |
183 |
} |
184 |
} |
185 |
|
186 |
/**
|
187 |
* A?ade un punto a las capas gr?ficas
|
188 |
* @param map Coordenadas del mapa del punto
|
189 |
* @param raster Coordenadas pixel del punto
|
190 |
* @return identificador del punto a?adido
|
191 |
*/
|
192 |
public long addPoint(Point2D map, Point2D raster) { |
193 |
GeoPoint gp = new GeoPoint(raster, map);
|
194 |
long id = System.currentTimeMillis(); |
195 |
if(viewRasterGCPs != null) |
196 |
viewRasterGCPs.addPixelGeoPoint(gp, id); |
197 |
if(viewMapGCPs != null) |
198 |
viewMapGCPs.addMapGeoPoint(gp, id); |
199 |
if(viewRasterGCPsZoom != null) |
200 |
viewRasterGCPsZoom.addPixelGeoPoint(gp, id); |
201 |
if(viewMapGCPsZoom != null) |
202 |
viewMapGCPsZoom.addMapGeoPoint(gp, id); |
203 |
return id;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* Elimina todos los puntos gr?ficos de las capas
|
208 |
*
|
209 |
*/
|
210 |
public void removeAllPoints() { |
211 |
if(viewRasterGCPs != null) |
212 |
viewRasterGCPs.removeAllPoints(); |
213 |
if(viewMapGCPs != null) |
214 |
viewMapGCPs.removeAllPoints(); |
215 |
if(viewRasterGCPsZoom != null) |
216 |
viewRasterGCPsZoom.removeAllPoints(); |
217 |
if(viewMapGCPsZoom != null) |
218 |
viewMapGCPsZoom.removeAllPoints(); |
219 |
} |
220 |
|
221 |
/**
|
222 |
* Asigna las coordenadas del mundo real y raster al punto indicado en el par?metro.
|
223 |
* @param point Punto a asignar las nuevas coordenadas
|
224 |
* @param xMap Coordenada real en X
|
225 |
* @param yMap Coordenada real en Y
|
226 |
* @param xRaster Coordenada pixel en X
|
227 |
* @param yRaster Coordenada pixel en Y
|
228 |
*/
|
229 |
public void setCoordinates(int point, double xMap, double yMap, double xRaster, double yRaster) { |
230 |
setXMapCoordinate(point, xMap); |
231 |
setYMapCoordinate(point, yMap); |
232 |
setXRasterCoordinate(point, xRaster); |
233 |
setYRasterCoordinate(point, yRaster); |
234 |
redrawPoints(); |
235 |
} |
236 |
|
237 |
/**
|
238 |
* Asigna la coordenada del mundo real X
|
239 |
* @param point
|
240 |
* @param xMap
|
241 |
*/
|
242 |
public void setXMapCoordinate(int point, double xMap) { |
243 |
double oldMapY = viewRasterGCPs.getPoint(point).getGeoPoint().mapPoint.getY();
|
244 |
viewRasterGCPs.getPoint(point).getGeoPoint().mapPoint.setLocation(xMap, oldMapY); |
245 |
} |
246 |
|
247 |
/**
|
248 |
* Asigna la coordenada del mundo real Y
|
249 |
* @param point
|
250 |
* @param yMap
|
251 |
*/
|
252 |
public void setYMapCoordinate(int point, double yMap) { |
253 |
double oldMapX = viewRasterGCPs.getPoint(point).getGeoPoint().mapPoint.getX();
|
254 |
viewRasterGCPs.getPoint(point).getGeoPoint().mapPoint.setLocation(oldMapX, yMap); |
255 |
} |
256 |
|
257 |
/**
|
258 |
* Asigna la coordenada raster X
|
259 |
* @param point
|
260 |
* @param xRaster
|
261 |
*/
|
262 |
public void setXRasterCoordinate(int point, double xRaster) { |
263 |
double oldRasterY = viewRasterGCPs.getPoint(point).getGeoPoint().pixelPoint.getY();
|
264 |
viewRasterGCPs.getPoint(point).getGeoPoint().pixelPoint.setLocation(xRaster, oldRasterY); |
265 |
} |
266 |
|
267 |
/**
|
268 |
* Asigna la coordenada raster Y
|
269 |
* @param point
|
270 |
* @param xRaster
|
271 |
*/
|
272 |
public void setYRasterCoordinate(int point, double yRaster) { |
273 |
double oldRasterX = viewRasterGCPs.getPoint(point).getGeoPoint().pixelPoint.getX();
|
274 |
viewRasterGCPs.getPoint(point).getGeoPoint().pixelPoint.setLocation(oldRasterX, yRaster); |
275 |
} |
276 |
|
277 |
/**
|
278 |
* Elimina un punto de la lista a partir de su posici?n
|
279 |
* @param position
|
280 |
*/
|
281 |
public void removePoint(int position) { |
282 |
if(viewRasterGCPs != null) |
283 |
viewRasterGCPs.removePixelGeoPoint(position); |
284 |
if(viewMapGCPs != null) |
285 |
viewMapGCPs.removePixelGeoPoint(position); |
286 |
if(viewRasterGCPsZoom != null) |
287 |
viewRasterGCPsZoom.removePixelGeoPoint(position); |
288 |
if(viewMapGCPsZoom != null) |
289 |
viewMapGCPsZoom.removePixelGeoPoint(position); |
290 |
} |
291 |
|
292 |
/**
|
293 |
* Informa de si la tool de selecci?n de puntos est? activa o no
|
294 |
* @return true si est? activa y false si no lo est?
|
295 |
*/
|
296 |
public boolean isSelectPointToolSelected() { |
297 |
if(viewRaster != null) |
298 |
if(viewRaster.getControl().getToolSelected() instanceof SelectPointTool) |
299 |
return true; |
300 |
return false; |
301 |
} |
302 |
|
303 |
/**
|
304 |
* Obtiene la lista de puntos
|
305 |
* @return ArrayList
|
306 |
*/
|
307 |
public ArrayList getPointList() { |
308 |
if(viewRasterGCPs != null) |
309 |
return viewRasterGCPs.getPointList();
|
310 |
return null; |
311 |
} |
312 |
|
313 |
/**
|
314 |
* Obtiene un array con la lista de puntos
|
315 |
* @return GeoPoint[]
|
316 |
*/
|
317 |
public GeoPoint[] getGeoPoints() { |
318 |
ArrayList pointList = getPointList();
|
319 |
GeoPoint[] gpList = new GeoPoint[pointList.size()]; |
320 |
for (int i = 0; i < pointList.size(); i++) |
321 |
gpList[i] = ((GPGraphic)pointList.get(i)).getGeoPoint(); |
322 |
return gpList;
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* Activa o desactiva la visualizaci?n de un punto.
|
327 |
* @param active true para activarlo y false para desactivarlo
|
328 |
* @param position Posici?n del punto
|
329 |
*/
|
330 |
public void setVisiblePoint(boolean visible, int position) { |
331 |
if(viewRasterGCPs != null) |
332 |
((GPGraphic)viewRasterGCPs.getPointList().get(position)).setDraw(visible); |
333 |
if(viewMapGCPs != null) |
334 |
((GPGraphic)viewMapGCPs.getPointList().get(position)).setDraw(visible); |
335 |
if(viewRasterGCPsZoom != null) |
336 |
((GPGraphic)viewRasterGCPsZoom.getPointList().get(position)).setDraw(visible); |
337 |
if(viewMapGCPsZoom != null) |
338 |
((GPGraphic)viewMapGCPsZoom.getPointList().get(position)).setDraw(visible); |
339 |
} |
340 |
|
341 |
/**
|
342 |
* Asigna la numeraci?n a los puntos de control. Tanto a la tabla como
|
343 |
* a los GeoPuntos
|
344 |
* @throws NotInitializeException
|
345 |
*/
|
346 |
public void calcPointsNumeration(GCPTablePanel table) throws NotInitializeException { |
347 |
ArrayList pointList = getPointList();
|
348 |
|
349 |
for (int i = 0; i < table.getRowCount(); i++) { |
350 |
table.setValueAt(new Integer(i), i, 1); |
351 |
long id = (long)((Long)table.getValueAt(i, table.getColumnCount() - 1)).longValue(); |
352 |
|
353 |
if(i < pointList.size()) {
|
354 |
for (int j = 0; j < pointList.size(); j++) { |
355 |
GPGraphic gpg = ((GPGraphic)pointList.get(j)); |
356 |
if(id == gpg.getId()) {
|
357 |
((GPGraphic)pointList.get(j)).getGeoPoint().number = i; |
358 |
break;
|
359 |
} |
360 |
} |
361 |
} |
362 |
} |
363 |
redrawPoints(); |
364 |
} |
365 |
|
366 |
/**
|
367 |
* Crea una capa de puntos de control y la a?ade a la vista
|
368 |
* que se le indica por par?metro
|
369 |
* @param view
|
370 |
*/
|
371 |
public GCPsGraphicLayer createGCPPIxelLayer(BaseZoomView view,
|
372 |
ViewRasterRequestManager viewRasterRequestManager, |
373 |
ViewRasterRequestManager zoomRasterRequestManager) { |
374 |
viewRasterGCPs = new GCPsGraphicLayer(GPGraphic.PIXEL, appMain);
|
375 |
viewRasterGCPs.setCanvas(view.getCanvas()); |
376 |
view.addGraphicLayer(viewRasterGCPs); |
377 |
viewRasterRequestManager.setGCPsGraphicLayer(viewRasterGCPs); |
378 |
|
379 |
viewRasterGCPsZoom = new GCPsGraphicLayer(GPGraphic.PIXEL, appMain);
|
380 |
viewRasterGCPsZoom.setCanvas(zoomRaster.getCanvas()); |
381 |
zoomRaster.addGraphicLayer(viewRasterGCPsZoom); |
382 |
zoomRasterRequestManager.setGCPsGraphicLayer(viewRasterGCPsZoom); |
383 |
|
384 |
return viewRasterGCPs;
|
385 |
} |
386 |
|
387 |
/**
|
388 |
* Crea una capa de puntos de control y la a?ade a la vista
|
389 |
* que se le indica por par?metro
|
390 |
* @param view
|
391 |
*/
|
392 |
public GCPsGraphicLayer createGCPMapLayer(BaseZoomView view,
|
393 |
ViewMapRequestManager viewMapRequestManager, |
394 |
ViewMapRequestManager zoomMapRequestManager) { |
395 |
viewMapGCPs = new GCPsGraphicLayer(GPGraphic.MAP, appMain);
|
396 |
viewMapGCPs.setCanvas(view.getCanvas()); |
397 |
view.addGraphicLayer(viewMapGCPs); |
398 |
viewMapRequestManager.setGCPsGraphicLayer(viewMapGCPs); |
399 |
|
400 |
viewMapGCPsZoom = new GCPsGraphicLayer(GPGraphic.MAP, appMain);
|
401 |
viewMapGCPsZoom.setCanvas(zoomMap.getCanvas()); |
402 |
zoomMap.addGraphicLayer(viewMapGCPsZoom); |
403 |
zoomMapRequestManager.setGCPsGraphicLayer(viewMapGCPsZoom); |
404 |
|
405 |
return viewMapGCPs;
|
406 |
} |
407 |
|
408 |
/**
|
409 |
* Activa y desactiva los n?meros de punto de las capas gr?ficas
|
410 |
* @param active
|
411 |
*/
|
412 |
public void setActiveNumberPoint(boolean active) { |
413 |
if(viewMapGCPs != null) |
414 |
viewMapGCPs.setShowNumber(active); |
415 |
if(viewRasterGCPs != null) |
416 |
viewRasterGCPs.setShowNumber(active); |
417 |
if(viewMapGCPsZoom != null) |
418 |
viewMapGCPsZoom.setShowNumber(active); |
419 |
if(viewRasterGCPsZoom != null) |
420 |
viewRasterGCPsZoom.setShowNumber(active); |
421 |
} |
422 |
|
423 |
/**
|
424 |
* Activa o desactiva la capa de puntos
|
425 |
* @param active
|
426 |
*/
|
427 |
public void setActiveLayerPoints(boolean active) { |
428 |
if(viewRasterGCPs != null) |
429 |
viewRasterGCPs.setActive(active); |
430 |
if(viewMapGCPs != null) |
431 |
viewMapGCPs.setActive(active); |
432 |
if(viewRasterGCPsZoom != null) |
433 |
viewRasterGCPsZoom.setActive(active); |
434 |
if(viewMapGCPsZoom != null) |
435 |
viewMapGCPsZoom.setActive(active); |
436 |
} |
437 |
|
438 |
/**
|
439 |
* Obtiene un punto (GeoPoint) a partir de su n?mero. Hay que tener en cuenta que el n?mero de
|
440 |
* punto puede no coincidir con su posici?n en el array.
|
441 |
* @return GeoPoint
|
442 |
*/
|
443 |
public GeoPoint getPointByNumber(int number) { |
444 |
ArrayList pointList = getPointList();
|
445 |
for (int i = 0; i < pointList.size(); i++) { |
446 |
GeoPoint p = ((GPGraphic)pointList.get(i)).getGeoPoint(); |
447 |
if(p.number == number)
|
448 |
return p;
|
449 |
} |
450 |
return null; |
451 |
} |
452 |
|
453 |
/**
|
454 |
* Obtiene la posici?n de un punto a partir de su n?mero. Hay que tener en cuenta que el n?mero de
|
455 |
* punto puede no coincidir con su posici?n en el array.
|
456 |
* @return entero con la posici?n o -1 si no existe
|
457 |
*/
|
458 |
public int getPointPositionByNumber(int number) { |
459 |
ArrayList pointList = getPointList();
|
460 |
for (int i = 0; i < pointList.size(); i++) { |
461 |
GeoPoint p = ((GPGraphic)pointList.get(i)).getGeoPoint(); |
462 |
if(p.number == number)
|
463 |
return i;
|
464 |
} |
465 |
return -1; |
466 |
} |
467 |
} |