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 @ 1724
History | View | Annotate | Download (15.7 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 |
|
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
32 |
import org.gvsig.app.ApplicationLocator; |
33 |
import org.gvsig.app.ApplicationManager; |
34 |
import org.gvsig.app.project.documents.Document; |
35 |
import org.gvsig.app.project.documents.view.ViewDocument; |
36 |
import org.gvsig.app.project.documents.view.gui.IView; |
37 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
38 |
import org.gvsig.fmap.geom.primitive.Envelope; |
39 |
import org.gvsig.fmap.mapcontrol.MapControl; |
40 |
import org.gvsig.i18n.Messages; |
41 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ApplicationControlsListener; |
42 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.LauncherDialogListener; |
43 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ViewDialogListener; |
44 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ViewMapRequestManager; |
45 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.listener.ViewRasterRequestManager; |
46 |
import org.gvsig.raster.georeferencing.framework.GeoreferencingFrameworkLocator; |
47 |
import org.gvsig.raster.georeferencing.framework.GeoreferencingFrameworkManager; |
48 |
import org.gvsig.raster.georeferencing.framework.LayoutEnvironment; |
49 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingLauncher; |
50 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingOptionsDataModel; |
51 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingLibrary; |
52 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingLocator; |
53 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingManager; |
54 |
import org.gvsig.raster.georeferencing.swing.control.GeorefControlPanel; |
55 |
import org.gvsig.raster.georeferencing.swing.exception.InvalidRequestException; |
56 |
import org.gvsig.raster.georeferencing.swing.impl.GeoreferencingSwingImplLibrary; |
57 |
import org.gvsig.raster.georeferencing.swing.view.GeoreferencingView; |
58 |
import org.gvsig.raster.georeferencing.swing.view.IViewRequestManager; |
59 |
import org.gvsig.raster.georeferencing.swing.view.SynchronizedViews; |
60 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
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 { |
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 = 3; |
85 |
public static int ZOOM_RATIO = 5; |
86 |
|
87 |
private GeoreferencingFrameworkManager
|
88 |
fManager = null;
|
89 |
private GeoreferencingSwingManager sManager = null; |
90 |
|
91 |
//Dialogos
|
92 |
private GeoreferencingLauncher launcher = null; |
93 |
private GeoreferencingView viewRaster = null; |
94 |
private GeoreferencingView viewMap = null; |
95 |
private GeoreferencingView zoomMap = null; |
96 |
private GeoreferencingView zoomRaster = null; |
97 |
|
98 |
private ViewRasterRequestManager zoomRasterRequestManager = null; |
99 |
private ViewMapRequestManager zoomMapRequestManager = null; |
100 |
private ViewRasterRequestManager viewRasterRequestManager = null; |
101 |
private ViewMapRequestManager viewMapRequestManager = null; |
102 |
|
103 |
private GeorefControlPanel georefControlPanel = null; |
104 |
|
105 |
private TableWrapper table = null; |
106 |
|
107 |
private MapControl mapCtrl = null; |
108 |
private GeoreferencingOptionsDataModel
|
109 |
dataModel = null;
|
110 |
private SynchronizedViews syncViews = null; |
111 |
private ViewDialogListener listener = null; |
112 |
private GeoreferencingProcessActions processActions = null; |
113 |
private ApplicationControlsListener appControlsListener = null; |
114 |
public static boolean enableTableEvent = true; |
115 |
|
116 |
public void initialize() { |
117 |
fManager = GeoreferencingFrameworkLocator.getManager(); |
118 |
sManager = GeoreferencingSwingLocator.getSwingManager(); |
119 |
listener = new ViewDialogListener(this); |
120 |
processActions = new GeoreferencingProcessActions();
|
121 |
launcher(); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Launcher of the initial dialog
|
126 |
*/
|
127 |
private void launcher() { |
128 |
ApplicationManager application = ApplicationLocator.getManager(); |
129 |
List<Document> docs = application.getProjectManager().getCurrentProject().getDocuments(); |
130 |
List<String> viewList = new ArrayList<String>(); |
131 |
for (int i = 0; i < docs.size(); i++) { |
132 |
Document doc = docs.get(i);
|
133 |
if(doc instanceof ViewDocument) { |
134 |
viewList.add(doc.getName()); |
135 |
} |
136 |
} |
137 |
|
138 |
|
139 |
launcher = sManager.createWindowLauncher(viewList, DEFAULT_DEGREE); |
140 |
LauncherDialogListener listener = new LauncherDialogListener(this, launcher); |
141 |
launcher.setButtonsListener(listener); |
142 |
fManager.showWindow(launcher.getComponent(), 400, 420, Messages.getText("georeferencing")); |
143 |
} |
144 |
|
145 |
public MapControl getMapCtrl() {
|
146 |
if(mapCtrl == null) { |
147 |
IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
|
148 |
for (int i = 0; i < windowList.length; i++) { |
149 |
if(windowList[i] instanceof IView) { |
150 |
String name = ((IView)windowList[i]).getViewDocument().getName();
|
151 |
if(name.equals(dataModel.getSelectedView())) {
|
152 |
mapCtrl = ((IView)windowList[i]).getMapControl(); |
153 |
} |
154 |
} |
155 |
} |
156 |
} |
157 |
return mapCtrl;
|
158 |
} |
159 |
|
160 |
public void endLauncherDialog(GeoreferencingOptionsDataModel dataModel) { |
161 |
this.dataModel = dataModel;
|
162 |
if(dataModel.getType() == Georeferencing.WITH_MAP)
|
163 |
initWindowsWithMap(dataModel); |
164 |
if(dataModel.getType() == Georeferencing.WITHOUT_MAP)
|
165 |
initWindowsWithoutMap(dataModel); |
166 |
createAppControlsListener(); |
167 |
} |
168 |
|
169 |
/**
|
170 |
* Builds the raster view
|
171 |
* @return
|
172 |
*/
|
173 |
public GeoreferencingView getViewRaster() {
|
174 |
if(viewRaster == null) { |
175 |
viewRaster = sManager.createView(true, false, true, listener); |
176 |
viewRasterRequestManager = new ViewRasterRequestManager(viewRaster, dataModel.getDataStore());
|
177 |
viewRaster.setMinxMaxyUL(true);
|
178 |
viewRaster.setViewListener(listener); |
179 |
viewRaster.setRequestListener(viewRasterRequestManager); |
180 |
viewRaster.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
181 |
} |
182 |
return viewRaster;
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* Builds the map view
|
187 |
* @return
|
188 |
*/
|
189 |
public GeoreferencingView getViewMap() {
|
190 |
if(viewMap == null) { |
191 |
viewMap = sManager.createView(true, false, false, listener); |
192 |
viewMap.setMinxMaxyUL(true);
|
193 |
viewMapRequestManager = new ViewMapRequestManager(viewMap, getMapCtrl());
|
194 |
viewMap.setViewListener(listener); |
195 |
viewMap.setRequestListener(viewMapRequestManager); |
196 |
viewMap.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
197 |
} |
198 |
return viewMap;
|
199 |
} |
200 |
|
201 |
/**
|
202 |
* Builds the zoom for the map view
|
203 |
* @return
|
204 |
*/
|
205 |
public GeoreferencingView getZoomMap() {
|
206 |
if(zoomMap == null) { |
207 |
zoomMap = sManager.createZoom(true, false); |
208 |
zoomMap.setMinxMaxyUL(true);
|
209 |
zoomMapRequestManager = new ViewMapRequestManager(zoomMap, getMapCtrl());
|
210 |
zoomMap.setRequestListener(zoomMapRequestManager); |
211 |
zoomMap.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
212 |
} |
213 |
return zoomMap;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* Builds the zoom for the raster view
|
218 |
* @return
|
219 |
*/
|
220 |
public GeoreferencingView getZoomRaster() {
|
221 |
if(zoomRaster == null) { |
222 |
zoomRaster = sManager.createZoom(true, false); |
223 |
zoomRasterRequestManager = new ViewRasterRequestManager(zoomRaster, dataModel.getDataStore());
|
224 |
zoomRaster.setMinxMaxyUL(false);
|
225 |
zoomRaster.setRequestListener(zoomRasterRequestManager); |
226 |
zoomRaster.setTool(GeoreferencingSwingLibrary.SELECT_POINT_TOOL, listener); |
227 |
} |
228 |
return zoomRaster;
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* Colocaci?n inicial de las ventanas del espacio de trabajo. Carga la configuraci?n
|
233 |
* de ventanas con cartograf?a de referencia.
|
234 |
*/
|
235 |
private void initWindowsWithoutMap(GeoreferencingOptionsDataModel dataModel) { |
236 |
//RasterDataStore store = dataModel.getDataStore();
|
237 |
|
238 |
getDataModel().setType(WITHOUT_MAP); |
239 |
|
240 |
viewRaster = getViewRaster(); |
241 |
zoomRaster = getZoomRaster(); |
242 |
|
243 |
PagedTable pt = getTableWrapper().getTable(); |
244 |
|
245 |
getDataModel().getGCPList().buildNewList(getDataModel().getDataStore().getGeoPointList()); |
246 |
|
247 |
//Creamos el layout
|
248 |
LayoutEnvironment layoutEnv = fManager.createLayoutEnvironment(); |
249 |
layoutEnv.setTable((JPanel)pt.getComponent());
|
250 |
layoutEnv.setViewRasterToGeoref(viewRaster.getComponent()); |
251 |
layoutEnv.setViewZoomRasterToGeoref(zoomRaster.getComponent()); |
252 |
layoutEnv.setControlBar(getGeorefControlPanel().getComponent()); |
253 |
|
254 |
fManager.createLayout(layoutEnv); |
255 |
GeoreferencingView[] v = new GeoreferencingView[]{null, viewRaster, null, zoomRaster}; |
256 |
IViewRequestManager[] rm = new IViewRequestManager[]{null, viewRasterRequestManager, null, zoomRasterRequestManager}; |
257 |
syncViews = sManager.createSyncViews(v, rm, pt, listener); |
258 |
|
259 |
try {
|
260 |
viewRaster.setCursorSize(zoomRaster.getCanvasWidth() / ZOOM_RATIO, zoomRaster.getCanvasHeight() / ZOOM_RATIO); |
261 |
viewRaster.setCursorPosition(viewRaster.getCanvasWidth() / 2, viewRaster.getCanvasHeight() / 2); |
262 |
|
263 |
//Inicializamos la vista de raster
|
264 |
viewRasterRequestManager.initRequest(dataModel.getDataStore().getExtent().toRectangle2D()); |
265 |
|
266 |
//Inicializamos el zoom de raster
|
267 |
Rectangle2D ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight());
|
268 |
zoomRasterRequestManager.initRequest(dataModel.getDataStore().getExtent().toRectangle2D()); |
269 |
zoomRasterRequestManager.request(ext); |
270 |
|
271 |
} catch (InvalidRequestException e1) {
|
272 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null, e1); |
273 |
fManager.closeAllWindows(); |
274 |
}catch (Exception e1) { |
275 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null, e1); |
276 |
fManager.closeAllWindows(); |
277 |
} |
278 |
} |
279 |
|
280 |
public TableWrapper getTableWrapper() {
|
281 |
if(table == null) { |
282 |
table = new TableWrapper(
|
283 |
getDataModel(), |
284 |
getGeorefControlPanel()); |
285 |
} |
286 |
return table;
|
287 |
} |
288 |
|
289 |
public void createAppControlsListener() { |
290 |
if(appControlsListener == null) { |
291 |
appControlsListener = new ApplicationControlsListener(getTableWrapper(), this); |
292 |
getTableWrapper().getTable().addListener(appControlsListener); |
293 |
} |
294 |
} |
295 |
|
296 |
/**
|
297 |
* Colocaci?n inicial de las ventanas del espacio de trabajo. Carga la configuraci?n
|
298 |
* de ventanas con cartograf?a de referencia.
|
299 |
*/
|
300 |
private void initWindowsWithMap(GeoreferencingOptionsDataModel dataModel) { |
301 |
RasterDataStore store = dataModel.getDataStore(); |
302 |
|
303 |
getDataModel().setType(WITH_MAP); |
304 |
|
305 |
viewRaster = getViewRaster(); |
306 |
zoomRaster = getZoomRaster(); |
307 |
viewMap = getViewMap(); |
308 |
zoomMap = getZoomMap(); |
309 |
|
310 |
PagedTable pt = getTableWrapper().getTable(); |
311 |
|
312 |
getDataModel().getGCPList().buildNewList(getDataModel().getDataStore().getGeoPointList()); |
313 |
|
314 |
//Creamos el layout
|
315 |
LayoutEnvironment layoutEnv = fManager.createLayoutEnvironment(); |
316 |
layoutEnv.setTable((JPanel)pt.getComponent());
|
317 |
layoutEnv.setViewRasterToGeoref(viewRaster.getComponent()); |
318 |
layoutEnv.setViewZoomRasterToGeoref(zoomRaster.getComponent()); |
319 |
layoutEnv.setViewBaseCartography(viewMap.getComponent()); |
320 |
layoutEnv.setViewZoomBaseCartography(zoomMap.getComponent()); |
321 |
layoutEnv.setControlBar(getGeorefControlPanel().getComponent()); |
322 |
|
323 |
fManager.createLayout(layoutEnv); |
324 |
GeoreferencingView[] v = new GeoreferencingView[]{viewMap, viewRaster, zoomMap, zoomRaster}; |
325 |
IViewRequestManager[] rm = new IViewRequestManager[]{viewMapRequestManager, viewRasterRequestManager, zoomMapRequestManager, zoomRasterRequestManager}; |
326 |
syncViews = sManager.createSyncViews(v, rm, pt, listener); |
327 |
|
328 |
getDataModel().setType(WITH_MAP); |
329 |
|
330 |
try {
|
331 |
viewMap.setCursorSize(zoomMap.getCanvasWidth() / ZOOM_RATIO, zoomMap.getCanvasHeight() / ZOOM_RATIO); |
332 |
viewRaster.setCursorSize(zoomRaster.getCanvasWidth() / ZOOM_RATIO, zoomRaster.getCanvasHeight() / ZOOM_RATIO); |
333 |
viewMap.setCursorPosition(viewMap.getCanvasWidth() / 2, viewMap.getCanvasHeight() / 2); |
334 |
viewRaster.setCursorPosition(viewRaster.getCanvasWidth() / 2, viewRaster.getCanvasHeight() / 2); |
335 |
|
336 |
if(getMapCtrl().getMapContext().getLayers().getFullEnvelope() == null) |
337 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null); |
338 |
|
339 |
//Inicializamos la vista de mapa
|
340 |
Envelope e = getMapCtrl().getMapContext().getLayers().getFullEnvelope(); |
341 |
Rectangle2D r = new Rectangle2D.Double(e.getMinimum(0), e.getMinimum(1), e.getLength(0), e.getLength(1)); |
342 |
viewMapRequestManager.initRequest(r); |
343 |
|
344 |
//Inicializamos la vista de raster
|
345 |
viewRasterRequestManager.initRequest(store.getExtent().toRectangle2D()); |
346 |
|
347 |
//Inicializamos el zoom de mapa
|
348 |
Rectangle2D ext = viewMap.getCursorAdjustedWorldCoordinates(zoomMap.getCanvasWidth(), zoomMap.getCanvasHeight());
|
349 |
zoomMapRequestManager.initRequest(ext); |
350 |
|
351 |
//Inicializamos el zoom de raster
|
352 |
ext = viewRaster.getCursorAdjustedWorldCoordinates(zoomRaster.getCanvasWidth(), zoomRaster.getCanvasHeight()); |
353 |
zoomRasterRequestManager.initRequest(store.getExtent().toRectangle2D()); |
354 |
zoomRasterRequestManager.request(ext); |
355 |
|
356 |
processActions.setViewMapRequest(viewMapRequestManager); |
357 |
} catch (InvalidRequestException e1) {
|
358 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", this, e1); |
359 |
fManager.closeAllWindows(); |
360 |
}catch (Exception e1) { |
361 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", this, e1); |
362 |
fManager.closeAllWindows(); |
363 |
} |
364 |
} |
365 |
|
366 |
public ViewRasterRequestManager getZoomRasterRequestManager() {
|
367 |
return zoomRasterRequestManager;
|
368 |
} |
369 |
|
370 |
public ViewMapRequestManager getZoomMapRequestManager() {
|
371 |
return zoomMapRequestManager;
|
372 |
} |
373 |
|
374 |
public GeorefControlPanel getGeorefControlPanel() {
|
375 |
if(georefControlPanel == null) { |
376 |
georefControlPanel = sManager.createGeorefControlPanel(); |
377 |
} |
378 |
return georefControlPanel;
|
379 |
} |
380 |
|
381 |
public SynchronizedViews getSyncViews() {
|
382 |
return syncViews;
|
383 |
} |
384 |
|
385 |
public GeoreferencingProcessActions getProcessActions() {
|
386 |
return processActions;
|
387 |
} |
388 |
|
389 |
public GeoreferencingOptionsDataModel getDataModel() {
|
390 |
return GeoreferencingSwingLocator.getSwingManager().getDataModel();
|
391 |
} |
392 |
|
393 |
} |