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