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