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