root / branches / v2_0_0_prep / extensions / extGeoreferencing / src / org / gvsig / georeferencing / main / Georeferencing.java @ 31496
History | View | Annotate | Download (27 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.AffineTransform; |
22 |
import java.awt.geom.Point2D; |
23 |
import java.awt.geom.Rectangle2D; |
24 |
import java.util.List; |
25 |
|
26 |
import org.gvsig.andami.PluginServices; |
27 |
import org.gvsig.andami.ui.mdiFrame.MDIFrame; |
28 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
29 |
import org.gvsig.app.extension.ProjectExtension; |
30 |
import org.gvsig.app.project.Project; |
31 |
import org.gvsig.app.project.Project; |
32 |
import org.gvsig.app.project.ProjectManager; |
33 |
import org.gvsig.app.project.documents.Document; |
34 |
import org.gvsig.app.project.documents.view.DefaultViewDocument; |
35 |
import org.gvsig.app.project.documents.view.ViewManager; |
36 |
import org.gvsig.app.project.documents.view.gui.IView; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
38 |
import org.gvsig.fmap.mapcontrol.MapControl; |
39 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
40 |
import org.gvsig.georeferencing.ui.launcher.GeorefLauncherDialog; |
41 |
import org.gvsig.georeferencing.ui.table.GCPTablePanel; |
42 |
import org.gvsig.georeferencing.ui.zoom.InvalidRequestException; |
43 |
import org.gvsig.georeferencing.ui.zoom.ViewEvent; |
44 |
import org.gvsig.georeferencing.ui.zoom.ViewListener; |
45 |
import org.gvsig.georeferencing.ui.zoom.ViewMapRequestManager; |
46 |
import org.gvsig.georeferencing.ui.zoom.ViewRasterRequestManager; |
47 |
import org.gvsig.georeferencing.ui.zoom.layers.GCPsGraphicLayer; |
48 |
import org.gvsig.georeferencing.ui.zoom.layers.GPGraphic; |
49 |
import org.gvsig.georeferencing.ui.zoom.layers.ZoomCursorGraphicLayer; |
50 |
import org.gvsig.georeferencing.ui.zoom.tools.PanTool; |
51 |
import org.gvsig.georeferencing.ui.zoom.tools.SelectPointTool; |
52 |
import org.gvsig.georeferencing.ui.zoom.tools.ToolEvent; |
53 |
import org.gvsig.georeferencing.ui.zoom.tools.ToolListener; |
54 |
import org.gvsig.georeferencing.ui.zoom.tools.ZoomRectangleTool; |
55 |
import org.gvsig.georeferencing.view.ViewDialog; |
56 |
import org.gvsig.georeferencing.view.ZoomDialog; |
57 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
58 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
59 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
60 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
61 |
import org.gvsig.raster.datastruct.GeoPoint; |
62 |
import org.gvsig.raster.util.RasterToolsUtil; |
63 |
|
64 |
|
65 |
/**
|
66 |
* Clase principal para la georreferenciaci?n. Se encarga de la inicializaci?n
|
67 |
* de la funcionalidad. Las acciones a realizar son:
|
68 |
* <UL>
|
69 |
* <LI>Lanzamiento del dialogo de inicializaci?n.</LI>
|
70 |
* <LI>Carga de la capa raster a georreferenciar.</LI>
|
71 |
* <LI>Creaci?n de las ventanas si no han sido creadas previamente.</LI>
|
72 |
* <LI>Asignaci?n de tama?os y posiciones a las ventanas.</LI>
|
73 |
* </UL>
|
74 |
* 26/12/2007
|
75 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
76 |
*/
|
77 |
public class Georeferencing implements ButtonsPanelListener, ToolListener, ViewListener { |
78 |
public static final int UNDEFINED = -1; |
79 |
//Algoritmo
|
80 |
public static final int POLYNOMIAL = 0; |
81 |
public static final int AFFINE = 1; |
82 |
|
83 |
//Tipo de georreferenciacion
|
84 |
public static final int WITH_MAP = 0; |
85 |
public static final int WITHOUT_MAP = 1; |
86 |
|
87 |
public static int DEFAULT_DEGREE = 5; |
88 |
public static int ZOOM_RATIO = 5; |
89 |
|
90 |
private FLyrRasterSE lyrToGeoref = null; |
91 |
private String selectedView = null; |
92 |
|
93 |
private static final int smallWindowsHeight = 100; |
94 |
private static final double smallWindowsWidthPercent = 0.5; |
95 |
|
96 |
//Dialogos
|
97 |
private GeorefLauncherDialog initDialog = null; |
98 |
private ViewDialog viewRaster = null; |
99 |
private ViewDialog viewMap = null; |
100 |
private ZoomDialog zoomMap = null; |
101 |
private ZoomDialog zoomRaster = null; |
102 |
|
103 |
//Herramientas de selecci?n
|
104 |
private SelectPointTool viewRasterSelectPointTool = null; |
105 |
private SelectPointTool viewMapSelectPointTool = null; |
106 |
private SelectPointTool zoomRasterSelectPointTool = null; |
107 |
private SelectPointTool zoomMapSelectPointTool = null; |
108 |
|
109 |
private GCPTablePanel table = null; |
110 |
private ApplicationControlsListener buttonsListener = null; |
111 |
private GeorefOptions options = null; |
112 |
|
113 |
private LayersPointManager layersPointManager = null; |
114 |
private ViewsManager viewsManager = null; |
115 |
|
116 |
public void initialize() { |
117 |
getLayerPointManager(); |
118 |
getViewsManager(); |
119 |
launcher(); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Obtiene el gestor para capas de puntos de la aplicaci?n,
|
124 |
* @return LayersPointManager
|
125 |
*/
|
126 |
public LayersPointManager getLayerPointManager() {
|
127 |
if(layersPointManager == null) |
128 |
layersPointManager = new LayersPointManager(this); |
129 |
return layersPointManager;
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* Obtiene el gestor para las vistas de la aplicaci?n,
|
134 |
* @return ViewsManager
|
135 |
*/
|
136 |
public ViewsManager getViewsManager() {
|
137 |
if(viewsManager == null) |
138 |
viewsManager = new ViewsManager();
|
139 |
return viewsManager;
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* Obtiene la clase con las opciones de georreferenciaci?n
|
144 |
* @return
|
145 |
*/
|
146 |
public GeorefOptions getOptions() {
|
147 |
if(options == null) |
148 |
options = new GeorefOptions();
|
149 |
return options;
|
150 |
} |
151 |
|
152 |
/**
|
153 |
* Obtiene la lista de capas de la vista de gvSIG
|
154 |
* @return
|
155 |
*/
|
156 |
public FLayers getLayers() {
|
157 |
MapControl mapControl = null;
|
158 |
IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
|
159 |
for (int i = 0; i < windowList.length; i++) { |
160 |
if(windowList[i] instanceof IView) |
161 |
mapControl = ((IView)windowList[i]).getMapControl(); |
162 |
} |
163 |
if(mapControl != null) |
164 |
return mapControl.getMapContext().getLayers();
|
165 |
return null; |
166 |
} |
167 |
|
168 |
/**
|
169 |
* Colocaci?n inicial de las ventanas del espacio de trabajo. Carga la configuraci?n
|
170 |
* de ventanas con cartograf?a de referencia.
|
171 |
*/
|
172 |
private void initWindowsWithoutMap() { |
173 |
MDIFrame p = (MDIFrame)PluginServices.getMainFrame(); |
174 |
int totalWidth = p.getWidth();
|
175 |
int wViews = totalWidth;
|
176 |
int hViews = p.getHeight() - 178 - smallWindowsHeight; |
177 |
int posYViews = p.getHeight() - 138 - smallWindowsHeight; |
178 |
int smallWindowsWidth = (int)(totalWidth * 0.25); |
179 |
int tableWidth = (int)(totalWidth * 0.75); |
180 |
|
181 |
getOptions().setType(WITHOUT_MAP); |
182 |
|
183 |
//Si hay ventanas de georreferenciaci?n abiertas las cerramos
|
184 |
closeAllWindows(); |
185 |
|
186 |
//Inicializaci?n de la tabla
|
187 |
table = new GCPTablePanel(0, posYViews, tableWidth, smallWindowsHeight, this); |
188 |
buttonsListener = new ApplicationControlsListener(table, this); |
189 |
table.initialize(buttonsListener); |
190 |
|
191 |
//Inicializaci?n de la ventana con la vista raster
|
192 |
viewRaster = new ViewDialog(0, 0, wViews, hViews, this); |
193 |
viewRaster.setViewListener(this);
|
194 |
viewRaster.setMinxMaxyUL(false);
|
195 |
viewRaster.setShowInfo(true);
|
196 |
ViewRasterRequestManager viewRasterRequestManager = new ViewRasterRequestManager(viewRaster, lyrToGeoref);
|
197 |
viewRaster.setExtensionRequest(viewRasterRequestManager); |
198 |
viewRasterSelectPointTool = new SelectPointTool(viewRaster.getCanvas(), this); |
199 |
|
200 |
//Inicializaci?n de la ventana del zoom de la vista raster
|
201 |
zoomRaster = new ZoomDialog(tableWidth, posYViews, smallWindowsWidth, smallWindowsHeight);
|
202 |
zoomRaster.setMinxMaxyUL(false);
|
203 |
ViewRasterRequestManager zoomRasterRequestManager = new ViewRasterRequestManager(zoomRaster, lyrToGeoref);
|
204 |
zoomRaster.setExtensionRequest(zoomRasterRequestManager); |
205 |
zoomRasterSelectPointTool = new SelectPointTool(zoomRaster.getCanvas(), this); |
206 |
|
207 |
//A?adimos las ventanas a gvSIG
|
208 |
PluginServices.getMDIManager().addWindow(viewRaster); |
209 |
PluginServices.getMDIManager().addWindow(table); |
210 |
PluginServices.getMDIManager().addWindow(zoomRaster); |
211 |
|
212 |
layersPointManager.setViews(viewRaster, null, zoomRaster, null); |
213 |
layersPointManager.setTools(viewRasterSelectPointTool, null, zoomRasterSelectPointTool, null); |
214 |
layersPointManager.registerPointToolListener(); |
215 |
|
216 |
viewsManager.setViews(viewRaster, null, zoomRaster, null); |
217 |
viewsManager.setRequestsManager(viewRasterRequestManager, null, zoomRasterRequestManager, null); |
218 |
viewsManager.setTablePanel(table); |
219 |
|
220 |
try {
|
221 |
viewRaster.setCursorSize(zoomRaster.getCanvasWidth() / ZOOM_RATIO, zoomRaster.getCanvasHeight() / ZOOM_RATIO); |
222 |
viewRaster.setCursorPosition(viewRaster.getCanvasWidth() / 2, viewRaster.getCanvasHeight() / 2); |
223 |
|
224 |
//Inicializamos la vista de raster
|
225 |
viewRasterRequestManager.initRequest(lyrToGeoref.getFullEnvelope()); |
226 |
|
227 |
//Inicializamos el zoom de raster
|
228 |
Rectangle2D ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight());
|
229 |
zoomRasterRequestManager.initRequest(lyrToGeoref.getFullEnvelope()); |
230 |
zoomRasterRequestManager.request(ext); |
231 |
|
232 |
layersPointManager.createGCPPIxelLayer(viewRaster, viewRasterRequestManager, zoomRasterRequestManager); |
233 |
|
234 |
} catch (InvalidRequestException e1) {
|
235 |
RasterToolsUtil.messageBoxError("error_setview_preview", this, e1); |
236 |
closeAllWindows(); |
237 |
}catch (Exception e1) { |
238 |
RasterToolsUtil.messageBoxError("error_setview_preview", this, e1); |
239 |
closeAllWindows(); |
240 |
} |
241 |
} |
242 |
|
243 |
/**
|
244 |
* Colocaci?n inicial de las ventanas del espacio de trabajo. Carga la configuraci?n
|
245 |
* de ventanas con cartograf?a de referencia.
|
246 |
*/
|
247 |
private void initWindowsWithMap() { |
248 |
MDIFrame p = (MDIFrame)PluginServices.getMainFrame(); |
249 |
int wViews = p.getWidth() >> 1; |
250 |
int hViews = p.getHeight() - 178 - smallWindowsHeight; |
251 |
int posYViews = p.getHeight() - 138 - smallWindowsHeight; |
252 |
int smallWindowsWidth = (int)(p.getWidth() * (smallWindowsWidthPercent * 0.5)); |
253 |
int tableWidth = (int)(p.getWidth() * (1 - smallWindowsWidthPercent)); |
254 |
|
255 |
getOptions().setType(WITH_MAP); |
256 |
|
257 |
//Si hay ventanas de georreferenciaci?n abiertas las cerramos
|
258 |
closeAllWindows(); |
259 |
|
260 |
MapControl mapControl = null;
|
261 |
IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
|
262 |
for (int i = 0; i < windowList.length; i++) { |
263 |
if(windowList[i] instanceof IView && windowList[i].getWindowInfo().getTitle().endsWith(": " + selectedView)) |
264 |
mapControl = ((IView)windowList[i]).getMapControl(); |
265 |
} |
266 |
|
267 |
if(mapControl == null) { |
268 |
RasterToolsUtil.messageBoxError("error_lookingfor_view", this); |
269 |
return;
|
270 |
} |
271 |
|
272 |
//Inicializamos el control de tabla
|
273 |
table = new GCPTablePanel(smallWindowsWidth, posYViews, tableWidth, smallWindowsHeight, this); |
274 |
buttonsListener = new ApplicationControlsListener(table, this); |
275 |
table.initialize(buttonsListener); |
276 |
|
277 |
//Inicializaci?n de la ventana con la vista mapa
|
278 |
viewMap = new ViewDialog(0, 0, wViews, hViews, this); |
279 |
viewMap.setViewListener(this);
|
280 |
viewMap.setShowInfo(true);
|
281 |
ViewMapRequestManager viewMapRequestManager = new ViewMapRequestManager(viewMap, mapControl);
|
282 |
viewMap.setExtensionRequest(viewMapRequestManager); |
283 |
viewMapSelectPointTool = new SelectPointTool(viewMap.getCanvas(), this); |
284 |
|
285 |
//Inicializaci?n de la ventana con la vista raster
|
286 |
viewRaster = new ViewDialog(wViews, 0, wViews, hViews, this); |
287 |
viewRaster.setViewListener(this);
|
288 |
viewRaster.setMinxMaxyUL(false);
|
289 |
viewRaster.setShowInfo(true);
|
290 |
ViewRasterRequestManager viewRasterRequestManager = new ViewRasterRequestManager(viewRaster, lyrToGeoref);
|
291 |
viewRaster.setExtensionRequest(viewRasterRequestManager); |
292 |
viewRasterSelectPointTool = new SelectPointTool(viewRaster.getCanvas(), this); |
293 |
|
294 |
//Inicializaci?n de la ventana del zoom de la vista raster
|
295 |
zoomRaster = new ZoomDialog(smallWindowsWidth + tableWidth, posYViews, smallWindowsWidth, smallWindowsHeight);
|
296 |
zoomRaster.setMinxMaxyUL(false);
|
297 |
zoomRaster.setShowInfo(true);
|
298 |
ViewRasterRequestManager zoomRasterRequestManager = new ViewRasterRequestManager(zoomRaster, lyrToGeoref);
|
299 |
zoomRaster.setExtensionRequest(zoomRasterRequestManager); |
300 |
zoomRasterSelectPointTool = new SelectPointTool(zoomRaster.getCanvas(), this); |
301 |
|
302 |
//Inicializaci?n de la ventana del zoom de la vista de referencia
|
303 |
zoomMap = new ZoomDialog(0, posYViews, smallWindowsWidth, smallWindowsHeight); |
304 |
zoomMap.setShowInfo(true);
|
305 |
ViewMapRequestManager zoomMapRequestManager = new ViewMapRequestManager(zoomMap, mapControl);
|
306 |
zoomMap.setExtensionRequest(zoomMapRequestManager); |
307 |
zoomMapSelectPointTool = new SelectPointTool(zoomMap.getCanvas(), this); |
308 |
|
309 |
//A?adimos las ventanas a gvSIG
|
310 |
PluginServices.getMDIManager().addWindow(viewRaster); |
311 |
PluginServices.getMDIManager().addWindow(viewMap); |
312 |
PluginServices.getMDIManager().addWindow(table); |
313 |
PluginServices.getMDIManager().addWindow(zoomMap); |
314 |
PluginServices.getMDIManager().addWindow(zoomRaster); |
315 |
|
316 |
layersPointManager.setViews(viewRaster, viewMap, zoomRaster, zoomMap); |
317 |
layersPointManager.setTools(viewRasterSelectPointTool, viewMapSelectPointTool, zoomRasterSelectPointTool, zoomMapSelectPointTool); |
318 |
layersPointManager.registerPointToolListener(); |
319 |
|
320 |
viewsManager.setViews(viewRaster, viewMap, zoomRaster, zoomMap); |
321 |
viewsManager.setRequestsManager(viewRasterRequestManager, viewMapRequestManager, zoomRasterRequestManager, zoomMapRequestManager); |
322 |
viewsManager.setTablePanel(table); |
323 |
|
324 |
try {
|
325 |
viewMap.setCursorSize(zoomMap.getCanvasWidth() / ZOOM_RATIO, zoomMap.getCanvasHeight() / ZOOM_RATIO); |
326 |
viewRaster.setCursorSize(zoomRaster.getCanvasWidth() / ZOOM_RATIO, zoomRaster.getCanvasHeight() / ZOOM_RATIO); |
327 |
viewMap.setCursorPosition(viewMap.getCanvasWidth() / 2, viewMap.getCanvasHeight() / 2); |
328 |
viewRaster.setCursorPosition(viewRaster.getCanvasWidth() / 2, viewRaster.getCanvasHeight() / 2); |
329 |
|
330 |
if(mapControl.getMapContext().getLayers().getFullEnvelope() == null) |
331 |
RasterToolsUtil.messageBoxError("error_setview_preview", this); |
332 |
|
333 |
//Inicializamos la vista de mapa
|
334 |
viewMapRequestManager.initRequest(mapControl.getMapContext().getLayers().getFullEnvelope()); |
335 |
|
336 |
//Inicializamos la vista de raster
|
337 |
viewRasterRequestManager.initRequest(lyrToGeoref.getFullEnvelope()); |
338 |
|
339 |
//Inicializamos el zoom de mapa
|
340 |
Rectangle2D ext = viewMap.getCursorAdjustedWorldCoordinates(zoomMap.getCanvasWidth(), zoomMap.getCanvasHeight());
|
341 |
zoomMapRequestManager.initRequest(ext); |
342 |
|
343 |
//Inicializamos el zoom de raster
|
344 |
ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight()); |
345 |
zoomRasterRequestManager.initRequest(lyrToGeoref.getFullEnvelope()); |
346 |
zoomRasterRequestManager.request(ext); |
347 |
|
348 |
layersPointManager.createGCPPIxelLayer(viewRaster, viewRasterRequestManager, zoomRasterRequestManager); |
349 |
layersPointManager.createGCPMapLayer(viewMap, viewMapRequestManager, zoomMapRequestManager); |
350 |
|
351 |
} catch (InvalidRequestException e1) {
|
352 |
RasterToolsUtil.messageBoxError("error_setview_preview", this, e1); |
353 |
closeAllWindows(); |
354 |
}catch (Exception e1) { |
355 |
RasterToolsUtil.messageBoxError("error_setview_preview", this, e1); |
356 |
closeAllWindows(); |
357 |
} |
358 |
} |
359 |
|
360 |
/**
|
361 |
* Cierra todas las ventanas de georreferenciaci?n
|
362 |
*/
|
363 |
public void closeAllWindows() { |
364 |
if(zoomMap != null) |
365 |
PluginServices.getMDIManager().closeWindow(zoomMap); |
366 |
if(zoomRaster != null) |
367 |
PluginServices.getMDIManager().closeWindow(zoomRaster); |
368 |
if(viewRaster != null) |
369 |
PluginServices.getMDIManager().closeWindow(viewRaster); |
370 |
if(viewMap != null) |
371 |
PluginServices.getMDIManager().closeWindow(viewMap); |
372 |
if(table != null) |
373 |
PluginServices.getMDIManager().closeWindow(table); |
374 |
} |
375 |
|
376 |
/**
|
377 |
* A?ade una capa en la vista del mapa para previsualizar el resultado
|
378 |
* @param lyr
|
379 |
*/
|
380 |
public void addTestRasterLayer(FLyrRasterSE lyr) { |
381 |
viewsManager.addTestRasterLayer(lyr, |
382 |
getOptions().getAlgorithm(), |
383 |
getOptions().getInterpolationMethod(), |
384 |
getOptions().getDegree(), |
385 |
getOptions().getOutFile()); |
386 |
} |
387 |
|
388 |
/**
|
389 |
* Elimina la capa de test de la vista de mapa
|
390 |
* @throws InvalidRequestException
|
391 |
*/
|
392 |
public void removeTestRasterLayer() { |
393 |
viewsManager.removeTestRasterLayer(); |
394 |
} |
395 |
|
396 |
/**
|
397 |
* Obtiene la ?ltima capa procesada con los puntos de control
|
398 |
* @return FLyrRaterSE
|
399 |
*/
|
400 |
public FLyrRasterSE getLastTestLayer() {
|
401 |
return viewsManager.getLastTestLayer();
|
402 |
} |
403 |
|
404 |
/**
|
405 |
* Lanzador del cuadro de inicializaci?n de propiedades de georreferenciaci?n.
|
406 |
*/
|
407 |
private void launcher() { |
408 |
// Project p = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
|
409 |
Project p = ProjectManager.getInstance().getCurrentProject(); |
410 |
|
411 |
List<Document> docs = p.getDocuments(ViewManager.TYPENAME); |
412 |
String[] viewList = new String[docs.size()]; |
413 |
for (int i = 0; i < docs.size(); i++) |
414 |
viewList[i] = (((DefaultViewDocument)docs.get(i)).getName()); |
415 |
initDialog = new GeorefLauncherDialog(viewList, DEFAULT_DEGREE, this); |
416 |
PluginServices.getMDIManager().addWindow(initDialog); |
417 |
} |
418 |
|
419 |
/**
|
420 |
* Captura de eventos de los botones Aceptar y Cancelar del cuadro
|
421 |
* inicial con las propiedades de georreferenciaci?n.
|
422 |
*/
|
423 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
424 |
|
425 |
//-----------------
|
426 |
// Bot?n de Aceptar
|
427 |
if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
|
428 |
if(initDialog != null) { |
429 |
selectedView = initDialog.getSelectedView(); |
430 |
|
431 |
if(initDialog.getType() == Georeferencing.WITH_MAP) {
|
432 |
boolean findView = false; |
433 |
IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
|
434 |
for (int i = 0; i < windowList.length; i++) |
435 |
if(windowList[i] instanceof IView && windowList[i].getWindowInfo().getTitle().endsWith(": " + selectedView)) |
436 |
findView = true;
|
437 |
|
438 |
if(!findView) {
|
439 |
RasterToolsUtil.messageBoxError("no_view_found", this); |
440 |
return;
|
441 |
} |
442 |
} |
443 |
|
444 |
lyrToGeoref = initDialog.getLayer(); |
445 |
getOptions().setAlgorithm(initDialog.getAlgorithm()); |
446 |
getOptions().setDegree(initDialog.getDegree()); |
447 |
getOptions().setOutFile(initDialog.getOutFile()); |
448 |
getOptions().setInterpolationMethod(initDialog.getInterpolationMethod()); |
449 |
getOptions().setXCellSize(initDialog.getXCellSizeValue()); |
450 |
getOptions().setYCellSize(initDialog.getYCellSizeValue()); |
451 |
//Inicializamos la matriz de transformaci?n en la imagen que vamos a georreferenciar para
|
452 |
//que nos de coordenadas pixel
|
453 |
if(lyrToGeoref == null) |
454 |
RasterToolsUtil.messageBoxError("layer_not_loaded", this); |
455 |
else {
|
456 |
lyrToGeoref.setAffineTransform(new AffineTransform(1, 0, 0, 1, 0, 0)); |
457 |
PluginServices.getMDIManager().closeWindow(initDialog); |
458 |
if(initDialog.getType() == Georeferencing.WITH_MAP)
|
459 |
initWindowsWithMap(); |
460 |
if(initDialog.getType() == Georeferencing.WITHOUT_MAP)
|
461 |
initWindowsWithoutMap(); |
462 |
} |
463 |
} |
464 |
} |
465 |
|
466 |
//----------------
|
467 |
// Bot?n de Cerrar
|
468 |
if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
|
469 |
if(initDialog != null) |
470 |
PluginServices.getMDIManager().closeWindow(initDialog); |
471 |
} |
472 |
} |
473 |
|
474 |
/**
|
475 |
* Controla los eventos de finalizaci?n de la capa con el
|
476 |
* cursor gr?fico que controla el ?rea de la miniimagen asociada y
|
477 |
* la terminaci?n de la operaci?n de mover punto
|
478 |
*/
|
479 |
public void endAction(ToolEvent ev) { |
480 |
|
481 |
//-----------------
|
482 |
//Operaci?n de zoom
|
483 |
if(ev.getSource() instanceof ZoomCursorGraphicLayer) { |
484 |
try {
|
485 |
Rectangle2D ext = null; |
486 |
if(viewRaster != null) { |
487 |
ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight()); |
488 |
viewsManager.getZoomRasterRequestManager().request(ext); |
489 |
} |
490 |
if(viewMap != null) { |
491 |
ext = viewMap.getCursorAdjustedWorldCoordinates(zoomMap.getCanvasWidth(), zoomMap.getCanvasHeight()); |
492 |
viewsManager.getZoomMapRequestManager().request(ext); |
493 |
} |
494 |
} catch (InvalidRequestException e1) {
|
495 |
RasterToolsUtil.messageBoxError("error_setview_preview", this); |
496 |
} |
497 |
} |
498 |
|
499 |
//-----------
|
500 |
//Mover punto
|
501 |
if(ev.getSource() instanceof GCPsGraphicLayer) { |
502 |
buttonsListener.setEnableTableEvent(false);
|
503 |
//Se redibujan, se obtienen las coordenadas del punto y se actualiza la tabla
|
504 |
if(layersPointManager != null) |
505 |
layersPointManager.redrawPoints(); |
506 |
GPGraphic gPoint = ((GCPsGraphicLayer)ev.getSource()).getLastPoint(); |
507 |
Point2D pRaster = gPoint.getGeoPoint().pixelPoint;
|
508 |
Point2D pMap = gPoint.getGeoPoint().mapPoint;
|
509 |
try {
|
510 |
table.updatePoint( new Double(pMap.getX()), |
511 |
new Double(pMap.getY()), |
512 |
new Double(pRaster.getX()), |
513 |
new Double(pRaster.getY()), |
514 |
gPoint.getGeoPoint().number); |
515 |
table.getTable().getTable().getJTable().setRowSelectionInterval(gPoint.getGeoPoint().number, gPoint.getGeoPoint().number); |
516 |
} catch (NotInitializeException e) {
|
517 |
RasterToolsUtil.messageBoxError("no_rows_selected", table, e);
|
518 |
} catch (ArrayIndexOutOfBoundsException e) { |
519 |
RasterToolsUtil.messageBoxError("no_rows_selected", table, e);
|
520 |
} |
521 |
if(getOptions().isCenterView())
|
522 |
viewsManager.centerToPoint(gPoint.getGeoPoint().number); |
523 |
buttonsListener.setEnableTableEvent(true);
|
524 |
} |
525 |
|
526 |
//------------------
|
527 |
//Selecci?n de punto
|
528 |
if(ev.getSource() instanceof SelectPointTool) { |
529 |
try {
|
530 |
//Se obtiene el punto seleccionado, se actualiza la tabla y se redibujan
|
531 |
int nPoint = table.getTable().getSelectedRow();
|
532 |
GeoPoint gp = layersPointManager.getPointByNumber(nPoint); |
533 |
|
534 |
if(ev.getSource() == viewRasterSelectPointTool || ev.getSource() == zoomRasterSelectPointTool) {
|
535 |
Point2D[] p = (Point2D[])((SelectPointTool)ev.getSource()).getResult(); |
536 |
table.updateRasterPoint(new Double(p[1].getX()), new Double(p[1].getY()), nPoint); |
537 |
if(gp != null) { |
538 |
gp.pixelPoint = p[1];
|
539 |
layersPointManager.redrawPoints(); |
540 |
} |
541 |
} |
542 |
if(ev.getSource() == viewMapSelectPointTool || ev.getSource() == zoomMapSelectPointTool) {
|
543 |
Point2D[] p = (Point2D[])((SelectPointTool)ev.getSource()).getResult(); |
544 |
table.updateMapPoint(new Double(p[1].getX()), new Double(p[1].getY()), nPoint); |
545 |
if(gp != null) { |
546 |
gp.mapPoint = p[1];
|
547 |
layersPointManager.redrawPoints(); |
548 |
} |
549 |
} |
550 |
if(getOptions().isCenterView())
|
551 |
viewsManager.centerToPoint(nPoint); |
552 |
} catch (NotInitializeException e) {
|
553 |
RasterToolsUtil.messageBoxError("no_rows_selected", table, e);
|
554 |
} catch (ArrayIndexOutOfBoundsException e) { |
555 |
RasterToolsUtil.messageBoxError("no_rows_selected", table, e);
|
556 |
} |
557 |
} |
558 |
} |
559 |
|
560 |
/**
|
561 |
* <P>
|
562 |
* Controla las prioridades de eventos sobre la vista en las herramientas y capas de selecci?n.
|
563 |
* Esto es necesario para que no se mezclen eventos entre capas.
|
564 |
* <P></P>
|
565 |
* Prioridades:
|
566 |
* </P>
|
567 |
* <UL>
|
568 |
* <LI>Capa de ZoomCursorGraphicLayer</LI>
|
569 |
* <LI>Capa de GCPsGraphicLayer</LI>
|
570 |
* <LI>Tool de selecci?n de zoom rectangulo</LI>
|
571 |
* <LI>Tool de selecci?n de puntos</LI>
|
572 |
* </UL>
|
573 |
*/
|
574 |
public void onTool(ToolEvent ev) { |
575 |
|
576 |
//---------------------------
|
577 |
//Operaci?n de cursor de zoom
|
578 |
if(ev.getSource() instanceof ZoomCursorGraphicLayer) { |
579 |
layersPointManager.setActiveLayerPoints(false);
|
580 |
viewsManager.sleepActiveTools(); |
581 |
return;
|
582 |
} |
583 |
|
584 |
//-----------
|
585 |
//Mover punto
|
586 |
if(ev.getSource() instanceof GCPsGraphicLayer) { |
587 |
layersPointManager.setActiveLayerZoomCursor(false);
|
588 |
viewsManager.sleepActiveTools(); |
589 |
return;
|
590 |
} |
591 |
|
592 |
//------------------
|
593 |
//Selecci?n de punto
|
594 |
if(ev.getSource() instanceof SelectPointTool) { |
595 |
if(viewMap != null) { |
596 |
viewMap.getControl().selectTool(ZoomRectangleTool.class, false);
|
597 |
viewMap.getControl().selectTool(PanTool.class, false);
|
598 |
viewMap.getControl().getBSelectZoomArea().setSelected(false);
|
599 |
viewMap.getControl().getBMove().setSelected(false);
|
600 |
} |
601 |
if(viewRaster != null) { |
602 |
viewRaster.getControl().selectTool(ZoomRectangleTool.class, false);
|
603 |
viewRaster.getControl().selectTool(PanTool.class, false);
|
604 |
viewRaster.getControl().getBSelectZoomArea().setSelected(false);
|
605 |
viewRaster.getControl().getBMove().setSelected(false);
|
606 |
} |
607 |
} |
608 |
|
609 |
//-------------------------
|
610 |
//Selecci?n de zoom ventana
|
611 |
if(ev.getSource() instanceof ZoomRectangleTool) { |
612 |
if(viewMap != null) { |
613 |
viewMap.getControl().selectTool(SelectPointTool.class, false);
|
614 |
viewMap.getControl().selectTool(PanTool.class, false);
|
615 |
viewMap.getControl().getBMove().setSelected(false);
|
616 |
} |
617 |
if(viewRaster != null) { |
618 |
viewRaster.getControl().selectTool(SelectPointTool.class, false);
|
619 |
viewRaster.getControl().selectTool(PanTool.class, false);
|
620 |
viewRaster.getControl().getBMove().setSelected(false);
|
621 |
} |
622 |
table.getToolSelectPointButton().setSelected(false);
|
623 |
} |
624 |
|
625 |
//---------------------------
|
626 |
//Selecci?n de desplazamiento
|
627 |
if(ev.getSource() instanceof PanTool) { |
628 |
if(viewMap != null) { |
629 |
viewMap.getControl().selectTool(SelectPointTool.class, false);
|
630 |
viewMap.getControl().selectTool(ZoomRectangleTool.class, false);
|
631 |
viewMap.getControl().getBSelectZoomArea().setSelected(false);
|
632 |
} |
633 |
if(viewRaster != null) { |
634 |
viewRaster.getControl().selectTool(SelectPointTool.class, false);
|
635 |
viewRaster.getControl().selectTool(ZoomRectangleTool.class, false);
|
636 |
viewRaster.getControl().getBSelectZoomArea().setSelected(false);
|
637 |
} |
638 |
table.getToolSelectPointButton().setSelected(false);
|
639 |
} |
640 |
} |
641 |
|
642 |
/**
|
643 |
*
|
644 |
*/
|
645 |
public void offTool(ToolEvent ev) { |
646 |
|
647 |
//-----------------
|
648 |
//Operaci?n de zoom
|
649 |
if(ev.getSource() instanceof ZoomCursorGraphicLayer) { |
650 |
layersPointManager.setActiveLayerPoints(true);
|
651 |
viewsManager.awakeActiveTools(); |
652 |
return;
|
653 |
} |
654 |
|
655 |
//-----------
|
656 |
//Mover punto
|
657 |
if(ev.getSource() instanceof GCPsGraphicLayer) { |
658 |
layersPointManager.setActiveLayerZoomCursor(true);
|
659 |
viewsManager.awakeActiveTools(); |
660 |
return;
|
661 |
} |
662 |
|
663 |
//Selecci?n de punto
|
664 |
/*if(ev.getSource() instanceof SelectPointTool) {
|
665 |
}
|
666 |
//Selecci?n de zoom ventana
|
667 |
if(ev.getSource() instanceof ZoomRectangleTool) {
|
668 |
}*/
|
669 |
} |
670 |
|
671 |
//*******************************************************
|
672 |
//Eventos sobre las vistas
|
673 |
|
674 |
|
675 |
public void addingTool(ViewEvent ev) { |
676 |
} |
677 |
|
678 |
public void endDraw(ViewEvent ev) { |
679 |
} |
680 |
|
681 |
public void startDraw(ViewEvent ev) { |
682 |
} |
683 |
|
684 |
/**
|
685 |
* Cuando cambia el zoom de alguna vista hay que recalcular la posici?n
|
686 |
* del cursor de zoom
|
687 |
*/
|
688 |
public void zoomViewChanged(ViewEvent ev) { |
689 |
Rectangle2D ext = null; |
690 |
try {
|
691 |
if(viewRaster != null && zoomRaster != null && viewsManager.getZoomRasterRequestManager() != null) { |
692 |
ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight()); |
693 |
viewsManager.getZoomRasterRequestManager().request(ext); |
694 |
} |
695 |
if(viewMap != null && zoomMap != null && viewsManager.getZoomMapRequestManager() != null) { |
696 |
ext = viewMap.getCursorAdjustedWorldCoordinates(zoomMap.getCanvasWidth(), zoomMap.getCanvasHeight()); |
697 |
viewsManager.getZoomMapRequestManager().request(ext); |
698 |
} |
699 |
}catch(InvalidRequestException ex) {
|
700 |
RasterToolsUtil.messageBoxError("error_set_view", table, ex);
|
701 |
} |
702 |
} |
703 |
|
704 |
/**
|
705 |
* Obtiene la capa a georreferenciar
|
706 |
* @return FLyrRasterSE
|
707 |
*/
|
708 |
public FLyrRasterSE getLayer() {
|
709 |
return lyrToGeoref;
|
710 |
} |
711 |
|
712 |
} |