gvsig-raster / org.gvsig.raster.georeferencing / trunk / org.gvsig.raster.georeferencing / org.gvsig.raster.georeferencing.app / org.gvsig.raster.georeferencing.app.georeferencingclient / src / main / java / org / gvsig / raster / georeferencing / app / georeferencingclient / Georeferencing.java @ 1717
History | View | Annotate | Download (17.2 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.georeferencing.app.georeferencingclient; |
23 |
|
24 |
import java.awt.geom.Rectangle2D; |
25 |
import java.util.ArrayList; |
26 |
import java.util.List; |
27 |
|
28 |
import javax.swing.JPanel; |
29 |
import javax.swing.table.DefaultTableModel; |
30 |
|
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
33 |
import org.gvsig.app.ApplicationLocator; |
34 |
import org.gvsig.app.ApplicationManager; |
35 |
import org.gvsig.app.project.documents.Document; |
36 |
import org.gvsig.app.project.documents.view.ViewDocument; |
37 |
import org.gvsig.app.project.documents.view.gui.IView; |
38 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPoint; |
39 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPointList; |
40 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
41 |
import org.gvsig.fmap.geom.primitive.Envelope; |
42 |
import org.gvsig.fmap.mapcontrol.MapControl; |
43 |
import org.gvsig.i18n.Messages; |
44 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ApplicationControlsListener; |
45 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.LauncherDialogListener; |
46 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ViewDialogListener; |
47 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ViewMapRequestManager; |
48 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ViewRasterRequestManager; |
49 |
import org.gvsig.raster.georeferencing.framework.GeoreferencingFrameworkLocator; |
50 |
import org.gvsig.raster.georeferencing.framework.GeoreferencingFrameworkManager; |
51 |
import org.gvsig.raster.georeferencing.framework.LayoutEnvironment; |
52 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingLauncher; |
53 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingOptionsDataModel; |
54 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingLibrary; |
55 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingLocator; |
56 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingManager; |
57 |
import org.gvsig.raster.georeferencing.swing.control.GeorefControlPanel; |
58 |
import org.gvsig.raster.georeferencing.swing.exception.InvalidRequestException; |
59 |
import org.gvsig.raster.georeferencing.swing.impl.GeoreferencingSwingImplLibrary; |
60 |
import org.gvsig.raster.georeferencing.swing.view.GeoreferencingView; |
61 |
import org.gvsig.raster.georeferencing.swing.view.IViewRequestManager; |
62 |
import org.gvsig.raster.georeferencing.swing.view.SynchronizedViews; |
63 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
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 { |
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 = 3; |
88 |
public static int ZOOM_RATIO = 5; |
89 |
|
90 |
private GeoreferencingFrameworkManager
|
91 |
fManager = null;
|
92 |
private GeoreferencingSwingManager sManager = null; |
93 |
|
94 |
//Dialogos
|
95 |
private GeoreferencingLauncher launcher = null; |
96 |
private GeoreferencingView viewRaster = null; |
97 |
private GeoreferencingView viewMap = null; |
98 |
private GeoreferencingView zoomMap = null; |
99 |
private GeoreferencingView zoomRaster = null; |
100 |
|
101 |
private ViewRasterRequestManager zoomRasterRequestManager = null; |
102 |
private ViewMapRequestManager zoomMapRequestManager = null; |
103 |
|
104 |
private GeorefControlPanel georefControlPanel = null; |
105 |
|
106 |
private TableWrapper table = null; |
107 |
|
108 |
private MapControl mapCtrl = null; |
109 |
private GeoreferencingOptionsDataModel
|
110 |
dataModel = null;
|
111 |
private GeoPointList geoPointList = null; |
112 |
private SynchronizedViews syncViews = null; |
113 |
private ViewDialogListener listener = null; |
114 |
private GeoreferencingProcessActions processActions = null; |
115 |
private ApplicationControlsListener appControlsListener = null; |
116 |
|
117 |
class GeoPointListImpl extends ArrayList<GeoPoint> implements GeoPointList { |
118 |
private static final long serialVersionUID = 1L; |
119 |
} |
120 |
|
121 |
public void initialize() { |
122 |
fManager = GeoreferencingFrameworkLocator.getManager(); |
123 |
sManager = GeoreferencingSwingLocator.getSwingManager(); |
124 |
listener = new ViewDialogListener(this); |
125 |
processActions = new GeoreferencingProcessActions();
|
126 |
launcher(); |
127 |
} |
128 |
|
129 |
/**
|
130 |
* Launcher of the initial dialog
|
131 |
*/
|
132 |
private void launcher() { |
133 |
ApplicationManager application = ApplicationLocator.getManager(); |
134 |
List<Document> docs = application.getProjectManager().getCurrentProject().getDocuments(); |
135 |
List<String> viewList = new ArrayList<String>(); |
136 |
for (int i = 0; i < docs.size(); i++) { |
137 |
Document doc = docs.get(i);
|
138 |
if(doc instanceof ViewDocument) { |
139 |
viewList.add(doc.getName()); |
140 |
} |
141 |
} |
142 |
|
143 |
|
144 |
launcher = sManager.createWindowLauncher(viewList, DEFAULT_DEGREE); |
145 |
LauncherDialogListener listener = new LauncherDialogListener(this, launcher); |
146 |
launcher.setButtonsListener(listener); |
147 |
fManager.showWindow(launcher.getComponent(), 400, 420, Messages.getText("georeferencing")); |
148 |
} |
149 |
|
150 |
public MapControl getMapCtrl() {
|
151 |
if(mapCtrl == null) { |
152 |
IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
|
153 |
for (int i = 0; i < windowList.length; i++) { |
154 |
if(windowList[i] instanceof IView) { |
155 |
String name = ((IView)windowList[i]).getViewDocument().getName();
|
156 |
if(name.equals(dataModel.getSelectedView())) {
|
157 |
mapCtrl = ((IView)windowList[i]).getMapControl(); |
158 |
} |
159 |
} |
160 |
} |
161 |
} |
162 |
return mapCtrl;
|
163 |
} |
164 |
|
165 |
public void endLauncherDialog(GeoreferencingOptionsDataModel dataModel) { |
166 |
this.dataModel = dataModel;
|
167 |
if(dataModel.getType() == Georeferencing.WITH_MAP)
|
168 |
initWindowsWithMap(dataModel); |
169 |
if(dataModel.getType() == Georeferencing.WITHOUT_MAP)
|
170 |
initWindowsWithoutMap(dataModel); |
171 |
createAppControlsListener(); |
172 |
} |
173 |
|
174 |
/**
|
175 |
* Colocaci?n inicial de las ventanas del espacio de trabajo. Carga la configuraci?n
|
176 |
* de ventanas con cartograf?a de referencia.
|
177 |
*/
|
178 |
private void initWindowsWithoutMap(GeoreferencingOptionsDataModel dataModel) { |
179 |
RasterDataStore store = dataModel.getDataStore(); |
180 |
|
181 |
getDataModel().setType(WITHOUT_MAP); |
182 |
|
183 |
//Inicializaci?n de la ventana con la vista raster
|
184 |
viewRaster = sManager.createView(true, false, true, listener); |
185 |
ViewRasterRequestManager viewRasterRequestManager = new ViewRasterRequestManager(viewRaster, store);
|
186 |
viewRaster.setMinxMaxyUL(false);
|
187 |
viewRaster.setViewListener(listener); |
188 |
viewRaster.setRequestListener(viewRasterRequestManager); |
189 |
viewRaster.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
190 |
|
191 |
//Inicializaci?n de la ventana del zoom de la vista raster
|
192 |
zoomRaster = sManager.createZoom(true, false); |
193 |
zoomRasterRequestManager = new ViewRasterRequestManager(zoomRaster, store);
|
194 |
zoomRaster.setMinxMaxyUL(false);
|
195 |
zoomRaster.setRequestListener(zoomRasterRequestManager); |
196 |
zoomRaster.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
197 |
|
198 |
PagedTable pt = getTableWrapper().getTable(); |
199 |
|
200 |
//Creamos el layout
|
201 |
|
202 |
LayoutEnvironment layoutEnv = fManager.createLayoutEnvironment(); |
203 |
layoutEnv.setTable((JPanel)pt.getComponent());
|
204 |
layoutEnv.setViewRasterToGeoref(viewRaster.getComponent()); |
205 |
layoutEnv.setViewZoomRasterToGeoref(zoomRaster.getComponent()); |
206 |
layoutEnv.setControlBar(getGeorefControlPanel().getComponent()); |
207 |
|
208 |
fManager.createLayout(layoutEnv); |
209 |
GeoreferencingView[] v = new GeoreferencingView[]{null, viewRaster, null, zoomRaster}; |
210 |
IViewRequestManager[] rm = new IViewRequestManager[]{null, viewRasterRequestManager, null, zoomRasterRequestManager}; |
211 |
syncViews = sManager.createSyncViews(v, rm, getGeoPointList(), pt, listener); |
212 |
|
213 |
//
|
214 |
// viewsManager.setViews(viewRaster, null, zoomRaster, null);
|
215 |
// viewsManager.setRequestsManager(viewRasterRequestManager, null, zoomRasterRequestManager, null);
|
216 |
// viewsManager.setTablePanel(table);
|
217 |
//
|
218 |
try {
|
219 |
viewRaster.setCursorSize(zoomRaster.getCanvasWidth() / ZOOM_RATIO, zoomRaster.getCanvasHeight() / ZOOM_RATIO); |
220 |
viewRaster.setCursorPosition(viewRaster.getCanvasWidth() / 2, viewRaster.getCanvasHeight() / 2); |
221 |
|
222 |
//Inicializamos la vista de raster
|
223 |
viewRasterRequestManager.initRequest(dataModel.getDataStore().getExtent().toRectangle2D()); |
224 |
|
225 |
//Inicializamos el zoom de raster
|
226 |
Rectangle2D ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight());
|
227 |
zoomRasterRequestManager.initRequest(dataModel.getDataStore().getExtent().toRectangle2D()); |
228 |
zoomRasterRequestManager.request(ext); |
229 |
|
230 |
} catch (InvalidRequestException e1) {
|
231 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null, e1); |
232 |
fManager.closeAllWindows(); |
233 |
}catch (Exception e1) { |
234 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null, e1); |
235 |
fManager.closeAllWindows(); |
236 |
} |
237 |
} |
238 |
|
239 |
public TableWrapper getTableWrapper() {
|
240 |
if(table == null) { |
241 |
table = new TableWrapper(getGeoPointList(), getDataModel(), getGeorefControlPanel());
|
242 |
} |
243 |
return table;
|
244 |
} |
245 |
|
246 |
public void createAppControlsListener() { |
247 |
if(appControlsListener == null) { |
248 |
appControlsListener = new ApplicationControlsListener(getTableWrapper(), this); |
249 |
((DefaultTableModel)getTableWrapper().getTable().getTableModel()).addTableModelListener(appControlsListener);
|
250 |
getGeorefControlPanel().setListener(appControlsListener); |
251 |
} |
252 |
} |
253 |
|
254 |
/**
|
255 |
* Colocaci?n inicial de las ventanas del espacio de trabajo. Carga la configuraci?n
|
256 |
* de ventanas con cartograf?a de referencia.
|
257 |
*/
|
258 |
private void initWindowsWithMap(GeoreferencingOptionsDataModel dataModel) { |
259 |
RasterDataStore store = dataModel.getDataStore(); |
260 |
|
261 |
getDataModel().setType(WITH_MAP); |
262 |
|
263 |
//Inicializaci?n de la ventana con la vista raster
|
264 |
viewRaster = sManager.createView(true, false, true, listener); |
265 |
ViewRasterRequestManager viewRasterRequestManager = new ViewRasterRequestManager(viewRaster, store);
|
266 |
viewRaster.setMinxMaxyUL(false);
|
267 |
viewRaster.setViewListener(listener); |
268 |
viewRaster.setRequestListener(viewRasterRequestManager); |
269 |
viewRaster.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
270 |
|
271 |
//Inicializaci?n de la ventana del zoom de la vista raster
|
272 |
zoomRaster = sManager.createZoom(true, false); |
273 |
zoomRaster.setMinxMaxyUL(false);
|
274 |
zoomRasterRequestManager = new ViewRasterRequestManager(zoomRaster, store);
|
275 |
zoomRaster.setRequestListener(zoomRasterRequestManager); |
276 |
zoomRaster.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
277 |
|
278 |
//Inicializaci?n de la ventana con la vista del terreno
|
279 |
viewMap = sManager.createView(true, false, false, listener); |
280 |
viewMap.setMinxMaxyUL(true);
|
281 |
ViewMapRequestManager viewMapRequestManager = new ViewMapRequestManager(viewMap, getMapCtrl());
|
282 |
viewMap.setViewListener(listener); |
283 |
viewMap.setRequestListener(viewMapRequestManager); |
284 |
viewMap.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
285 |
|
286 |
//Inicializaci?n de la ventana del zoom de la vista del terreno
|
287 |
zoomMap = sManager.createZoom(true, false); |
288 |
zoomMap.setMinxMaxyUL(true);
|
289 |
zoomMapRequestManager = new ViewMapRequestManager(zoomMap, getMapCtrl());
|
290 |
zoomMap.setRequestListener(zoomMapRequestManager); |
291 |
zoomMap.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
292 |
|
293 |
PagedTable pt = getTableWrapper().getTable(); |
294 |
|
295 |
//Creamos el layout
|
296 |
LayoutEnvironment layoutEnv = fManager.createLayoutEnvironment(); |
297 |
layoutEnv.setTable((JPanel)pt.getComponent());
|
298 |
layoutEnv.setViewRasterToGeoref(viewRaster.getComponent()); |
299 |
layoutEnv.setViewZoomRasterToGeoref(zoomRaster.getComponent()); |
300 |
layoutEnv.setViewBaseCartography(viewMap.getComponent()); |
301 |
layoutEnv.setViewZoomBaseCartography(zoomMap.getComponent()); |
302 |
layoutEnv.setControlBar(getGeorefControlPanel().getComponent()); |
303 |
|
304 |
fManager.createLayout(layoutEnv); |
305 |
GeoreferencingView[] v = new GeoreferencingView[]{viewMap, viewRaster, zoomMap, zoomRaster}; |
306 |
IViewRequestManager[] rm = new IViewRequestManager[]{viewMapRequestManager, viewRasterRequestManager, zoomMapRequestManager, zoomRasterRequestManager}; |
307 |
syncViews = sManager.createSyncViews(v, rm, getGeoPointList(), pt, listener); |
308 |
|
309 |
getDataModel().setType(WITH_MAP); |
310 |
//
|
311 |
// viewsManager.setViews(viewRaster, viewMap, zoomRaster, zoomMap);
|
312 |
// viewsManager.setRequestsManager(viewRasterRequestManager, viewMapRequestManager, zoomRasterRequestManager, zoomMapRequestManager);
|
313 |
// viewsManager.setTablePanel(table);
|
314 |
//
|
315 |
try {
|
316 |
viewMap.setCursorSize(zoomMap.getCanvasWidth() / ZOOM_RATIO, zoomMap.getCanvasHeight() / ZOOM_RATIO); |
317 |
viewRaster.setCursorSize(zoomRaster.getCanvasWidth() / ZOOM_RATIO, zoomRaster.getCanvasHeight() / ZOOM_RATIO); |
318 |
viewMap.setCursorPosition(viewMap.getCanvasWidth() / 2, viewMap.getCanvasHeight() / 2); |
319 |
viewRaster.setCursorPosition(viewRaster.getCanvasWidth() / 2, viewRaster.getCanvasHeight() / 2); |
320 |
|
321 |
if(getMapCtrl().getMapContext().getLayers().getFullEnvelope() == null) |
322 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null); |
323 |
|
324 |
//Inicializamos la vista de mapa
|
325 |
Envelope e = getMapCtrl().getMapContext().getLayers().getFullEnvelope(); |
326 |
Rectangle2D r = new Rectangle2D.Double(e.getMinimum(0), e.getMinimum(1), e.getLength(0), e.getLength(1)); |
327 |
viewMapRequestManager.initRequest(r); |
328 |
|
329 |
//Inicializamos la vista de raster
|
330 |
viewRasterRequestManager.initRequest(store.getExtent().toRectangle2D()); |
331 |
|
332 |
//Inicializamos el zoom de mapa
|
333 |
Rectangle2D ext = viewMap.getCursorAdjustedWorldCoordinates(zoomMap.getCanvasWidth(), zoomMap.getCanvasHeight());
|
334 |
zoomMapRequestManager.initRequest(ext); |
335 |
|
336 |
//Inicializamos el zoom de raster
|
337 |
ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight()); |
338 |
zoomRasterRequestManager.initRequest(store.getExtent().toRectangle2D()); |
339 |
zoomRasterRequestManager.request(ext); |
340 |
|
341 |
// layersPointManager.createGCPPIxelLayer(viewRaster, viewRasterRequestManager, zoomRasterRequestManager);
|
342 |
// layersPointManager.createGCPMapLayer(viewMap, viewMapRequestManager, zoomMapRequestManager);
|
343 |
//
|
344 |
processActions.setViewMapRequest(viewMapRequestManager); |
345 |
} catch (InvalidRequestException e1) {
|
346 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", this, e1); |
347 |
fManager.closeAllWindows(); |
348 |
}catch (Exception e1) { |
349 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", this, e1); |
350 |
fManager.closeAllWindows(); |
351 |
} |
352 |
} |
353 |
|
354 |
public GeoreferencingView getViewRaster() {
|
355 |
return viewRaster;
|
356 |
} |
357 |
|
358 |
public GeoreferencingView getViewMap() {
|
359 |
return viewMap;
|
360 |
} |
361 |
|
362 |
public GeoreferencingView getZoomMap() {
|
363 |
return zoomMap;
|
364 |
} |
365 |
|
366 |
public GeoreferencingView getZoomRaster() {
|
367 |
return zoomRaster;
|
368 |
} |
369 |
|
370 |
public ViewRasterRequestManager getZoomRasterRequestManager() {
|
371 |
return zoomRasterRequestManager;
|
372 |
} |
373 |
|
374 |
public ViewMapRequestManager getZoomMapRequestManager() {
|
375 |
return zoomMapRequestManager;
|
376 |
} |
377 |
|
378 |
public GeorefControlPanel getGeorefControlPanel() {
|
379 |
if(georefControlPanel == null) { |
380 |
georefControlPanel = sManager.createGeorefControlPanel(); |
381 |
} |
382 |
return georefControlPanel;
|
383 |
} |
384 |
|
385 |
public SynchronizedViews getSyncViews() {
|
386 |
return syncViews;
|
387 |
} |
388 |
|
389 |
public GeoPointList getGeoPointList() {
|
390 |
if(geoPointList == null) |
391 |
geoPointList = new GeoPointListImpl();
|
392 |
return geoPointList;
|
393 |
} |
394 |
|
395 |
/**
|
396 |
* Obtiene la capa a georreferenciar
|
397 |
* @return FLyrRaster
|
398 |
*/
|
399 |
public RasterDataStore getLayer() {
|
400 |
return launcher.getDataModel().getDataStore();
|
401 |
} |
402 |
|
403 |
public GeoreferencingProcessActions getProcessActions() {
|
404 |
return processActions;
|
405 |
} |
406 |
|
407 |
public GeoreferencingOptionsDataModel getDataModel() {
|
408 |
return launcher.getDataModel();
|
409 |
} |
410 |
|
411 |
} |