2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "vikgeoreflayer_pixmap.h"
27 VikLayerParam georef_layer_params
[] = {
28 { "image", VIK_LAYER_PARAM_STRING
, VIK_LAYER_NOT_IN_PROPERTIES
},
29 { "corner_easting", VIK_LAYER_PARAM_DOUBLE
, VIK_LAYER_NOT_IN_PROPERTIES
},
30 { "corner_northing", VIK_LAYER_PARAM_DOUBLE
, VIK_LAYER_NOT_IN_PROPERTIES
},
31 { "mpp_easting", VIK_LAYER_PARAM_DOUBLE
, VIK_LAYER_NOT_IN_PROPERTIES
},
32 { "mpp_northing", VIK_LAYER_PARAM_DOUBLE
, VIK_LAYER_NOT_IN_PROPERTIES
},
35 enum { PARAM_IMAGE
= 0, PARAM_CE
, PARAM_CN
, PARAM_ME
, PARAM_MN
, NUM_PARAMS
};
37 static void georef_layer_marshall( VikGeorefLayer
*vgl
, guint8
**data
, gint
*len
);
38 static VikGeorefLayer
*georef_layer_unmarshall( guint8
*data
, gint len
, VikViewport
*vvp
);
39 static VikGeorefLayer
*georef_layer_copy ( VikGeorefLayer
*vgl
, gpointer vp
);
40 static gboolean
georef_layer_set_param ( VikGeorefLayer
*vgl
, guint16 id
, VikLayerParamData data
, VikViewport
*vp
);
41 static VikLayerParamData
georef_layer_get_param ( VikGeorefLayer
*vgl
, guint16 id
);
42 VikGeorefLayer
*georef_layer_new ( );
43 VikGeorefLayer
*georef_layer_create ( VikViewport
*vp
);
44 static void georef_layer_free ( VikGeorefLayer
*vgl
);
45 gboolean
georef_layer_properties ( VikGeorefLayer
*vgl
, gpointer vp
);
46 static void georef_layer_draw ( VikGeorefLayer
*vgl
, gpointer data
);
47 static void georef_layer_add_menu_items ( VikGeorefLayer
*vgl
, GtkMenu
*menu
, gpointer vlp
);
48 static void georef_layer_set_image ( VikGeorefLayer
*vgl
, const gchar
*image
);
49 static gboolean
georef_layer_dialog ( VikGeorefLayer
**vgl
, gpointer vp
, GtkWindow
*w
);
50 static void georef_layer_load_image ( VikGeorefLayer
*vgl
);
53 static gpointer
georef_layer_move_create ( VikWindow
*vw
, VikViewport
*vvp
);
54 static gboolean
georef_layer_move_release ( VikGeorefLayer
*vgl
, GdkEventButton
*event
, VikViewport
*vvp
);
55 static gboolean
georef_layer_move_press ( VikGeorefLayer
*vgl
, GdkEventButton
*event
, VikViewport
*vvp
);
56 static gpointer
georef_layer_zoom_create ( VikWindow
*vw
, VikViewport
*vvp
);
57 static gboolean
georef_layer_zoom_press ( VikGeorefLayer
*vgl
, GdkEventButton
*event
, VikViewport
*vvp
);
59 static VikToolInterface georef_tools
[] = {
60 { "Georef Move Map", (VikToolConstructorFunc
) georef_layer_move_create
, NULL
, NULL
, NULL
,
61 (VikToolMouseFunc
) georef_layer_move_press
, NULL
, (VikToolMouseFunc
) georef_layer_move_release
},
63 { "Georef Zoom Tool", (VikToolConstructorFunc
) georef_layer_zoom_create
, NULL
, NULL
, NULL
,
64 (VikToolMouseFunc
) georef_layer_zoom_press
, NULL
, NULL
},
67 VikLayerInterface vik_georef_layer_interface
= {
69 &georeflayer_pixbuf
, /*icon */
72 sizeof(georef_tools
) / sizeof(VikToolInterface
),
81 (VikLayerFuncCreate
) georef_layer_create
,
82 (VikLayerFuncRealize
) NULL
,
83 (VikLayerFuncPostRead
) georef_layer_load_image
,
84 (VikLayerFuncFree
) georef_layer_free
,
86 (VikLayerFuncProperties
) georef_layer_properties
,
87 (VikLayerFuncDraw
) georef_layer_draw
,
88 (VikLayerFuncChangeCoordMode
) NULL
,
90 (VikLayerFuncSetMenuItemsSelection
) NULL
,
91 (VikLayerFuncGetMenuItemsSelection
) NULL
,
93 (VikLayerFuncAddMenuItems
) georef_layer_add_menu_items
,
94 (VikLayerFuncSublayerAddMenuItems
) NULL
,
96 (VikLayerFuncSublayerRenameRequest
) NULL
,
97 (VikLayerFuncSublayerToggleVisible
) NULL
,
99 (VikLayerFuncCopy
) georef_layer_copy
,
100 (VikLayerFuncMarshall
) georef_layer_marshall
,
101 (VikLayerFuncUnmarshall
) georef_layer_unmarshall
,
103 (VikLayerFuncSetParam
) georef_layer_set_param
,
104 (VikLayerFuncGetParam
) georef_layer_get_param
,
106 (VikLayerFuncReadFileData
) NULL
,
107 (VikLayerFuncWriteFileData
) NULL
,
109 (VikLayerFuncDeleteItem
) NULL
,
110 (VikLayerFuncCopyItem
) NULL
,
111 (VikLayerFuncPasteItem
) NULL
,
112 (VikLayerFuncFreeCopiedItem
) NULL
,
113 (VikLayerFuncDragDropRequest
) NULL
,
116 struct _VikGeorefLayer
{
121 gdouble mpp_easting
, mpp_northing
;
124 gint click_x
, click_y
;
129 GType
vik_georef_layer_get_type ()
131 static GType vgl_type
= 0;
135 static const GTypeInfo vgl_info
=
137 sizeof (VikGeorefLayerClass
),
138 NULL
, /* base_init */
139 NULL
, /* base_finalize */
140 NULL
, /* class init */
141 NULL
, /* class_finalize */
142 NULL
, /* class_data */
143 sizeof (VikGeorefLayer
),
145 NULL
/* instance init */
147 vgl_type
= g_type_register_static ( VIK_LAYER_TYPE
, "VikGeorefLayer", &vgl_info
, 0 );
153 static VikGeorefLayer
*georef_layer_copy ( VikGeorefLayer
*vgl
, gpointer vp
)
155 VikGeorefLayer
*rv
= georef_layer_new ();
156 rv
->corner
= vgl
->corner
;
157 rv
->mpp_easting
= vgl
->mpp_easting
;
158 rv
->mpp_northing
= vgl
->mpp_northing
;
159 rv
->width
= vgl
->width
;
160 rv
->height
= vgl
->height
;
164 rv
->image
= g_strdup ( vgl
->image
);
165 georef_layer_load_image ( rv
);
170 static void georef_layer_marshall( VikGeorefLayer
*vgl
, guint8
**data
, gint
*len
)
172 vik_layer_marshall_params ( VIK_LAYER(vgl
), data
, len
);
175 static VikGeorefLayer
*georef_layer_unmarshall( guint8
*data
, gint len
, VikViewport
*vvp
)
177 VikGeorefLayer
*rv
= georef_layer_new ( vvp
);
178 vik_layer_unmarshall_params ( VIK_LAYER(rv
), data
, len
, vvp
);
180 georef_layer_load_image ( rv
);
185 static gboolean
georef_layer_set_param ( VikGeorefLayer
*vgl
, guint16 id
, VikLayerParamData data
, VikViewport
*vp
)
189 case PARAM_IMAGE
: georef_layer_set_image ( vgl
, data
.s
); break;
190 case PARAM_CN
: vgl
->corner
.northing
= data
.d
; break;
191 case PARAM_CE
: vgl
->corner
.easting
= data
.d
; break;
192 case PARAM_MN
: vgl
->mpp_northing
= data
.d
; break;
193 case PARAM_ME
: vgl
->mpp_easting
= data
.d
; break;
198 static VikLayerParamData
georef_layer_get_param ( VikGeorefLayer
*vgl
, guint16 id
)
200 VikLayerParamData rv
;
203 case PARAM_IMAGE
: rv
.s
= vgl
->image
? vgl
->image
: ""; break;
204 case PARAM_CN
: rv
.d
= vgl
->corner
.northing
; break;
205 case PARAM_CE
: rv
.d
= vgl
->corner
.easting
; break;
206 case PARAM_MN
: rv
.d
= vgl
->mpp_northing
; break;
207 case PARAM_ME
: rv
.d
= vgl
->mpp_easting
; break;
212 VikGeorefLayer
*georef_layer_new ( )
214 VikGeorefLayer
*vgl
= VIK_GEOREF_LAYER ( g_object_new ( VIK_GEOREF_LAYER_TYPE
, NULL
) );
215 vik_layer_init ( VIK_LAYER(vgl
), VIK_LAYER_GEOREF
);
224 static void georef_layer_draw ( VikGeorefLayer
*vgl
, gpointer data
)
229 VikViewport
*vp
= VIK_VIEWPORT(data
);
230 struct UTM utm_middle
;
231 gdouble xmpp
= vik_viewport_get_xmpp(vp
), ympp
= vik_viewport_get_ympp(vp
);
232 vik_coord_to_utm ( vik_viewport_get_center ( vp
), &utm_middle
);
234 if ( xmpp
== vgl
->mpp_easting
&& ympp
== vgl
->mpp_northing
)
236 guint width
= vik_viewport_get_width(vp
), height
= vik_viewport_get_height(vp
);
238 vgl
->corner
.zone
= utm_middle
.zone
;
239 vgl
->corner
.letter
= utm_middle
.letter
;
240 VikCoord corner_coord
;
241 vik_coord_load_from_utm ( &corner_coord
, vik_viewport_get_coord_mode(vp
), &(vgl
->corner
) );
242 vik_viewport_coord_to_screen ( vp
, &corner_coord
, &x
, &y
);
243 if ( (x
< 0 || x
< width
) && (y
< 0 || y
< height
) && x
+vgl
->width
> 0 && y
+vgl
->height
> 0 )
244 vik_viewport_draw_pixbuf ( vp
, vgl
->pixbuf
, 0, 0, x
, y
, vgl
->width
, vgl
->height
); /* todo: draw only what we need to. */
249 static void georef_layer_free ( VikGeorefLayer
*vgl
)
251 if ( vgl
->image
!= NULL
)
252 g_free ( vgl
->image
);
255 VikGeorefLayer
*georef_layer_create ( VikViewport
*vp
)
257 return georef_layer_new ();
260 gboolean
georef_layer_properties ( VikGeorefLayer
*vgl
, gpointer vp
)
262 return georef_layer_dialog ( &vgl
, vp
, VIK_GTK_WINDOW_FROM_WIDGET(vp
) );
265 static void georef_layer_load_image ( VikGeorefLayer
*vgl
)
268 if ( vgl
->image
== NULL
)
272 g_object_unref ( G_OBJECT(vgl
->pixbuf
) );
274 vgl
->pixbuf
= gdk_pixbuf_new_from_file ( vgl
->image
, &gx
);
278 g_warning ( "Couldn't open image file: %s", gx
->message
);
283 vgl
->width
= gdk_pixbuf_get_width ( vgl
->pixbuf
);
284 vgl
->height
= gdk_pixbuf_get_height ( vgl
->pixbuf
);
287 /* should find length and width here too */
290 static void georef_layer_set_image ( VikGeorefLayer
*vgl
, const gchar
*image
)
293 g_free ( vgl
->image
);
296 vgl
->image
= g_strdup ( image
);
299 static gboolean
world_file_read_line ( gchar
*buffer
, gint size
, FILE *f
, GtkWidget
*widget
, gboolean use_value
)
301 if (!fgets ( buffer
, 1024, f
))
303 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(widget
), "Unexpected end of file reading World file." );
310 gdouble val
= strtod ( buffer
, NULL
);
311 gtk_spin_button_set_value ( GTK_SPIN_BUTTON(widget
), val
> 0 ? val
: -val
);
316 static void georef_layer_dialog_load ( GtkWidget
*pass_along
[4] )
318 GtkWidget
*file_selector
= gtk_file_selection_new ("Choose World file");
320 if ( gtk_dialog_run ( GTK_DIALOG ( file_selector
) ) == GTK_RESPONSE_OK
)
322 FILE *f
= fopen ( gtk_file_selection_get_filename ( GTK_FILE_SELECTION(file_selector
) ), "r" );
323 gtk_widget_destroy ( file_selector
);
326 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(pass_along
[0]), "The World file you requested could not be opened for reading." );
331 gchar
*buffer
= g_malloc ( 1024 * sizeof(gchar
) );
332 if ( world_file_read_line ( buffer
, 1024, f
, pass_along
[0], TRUE
) && world_file_read_line ( buffer
, 1024, f
, pass_along
[1], TRUE
)
333 && world_file_read_line ( buffer
, 1024, f
, pass_along
[0], FALSE
) && world_file_read_line ( buffer
, 1024, f
, pass_along
[0], FALSE
)
334 && world_file_read_line ( buffer
, 1024, f
, pass_along
[2], TRUE
) && world_file_read_line ( buffer
, 1024, f
, pass_along
[3], TRUE
) )
342 gtk_widget_destroy ( file_selector
);
345 file selection dialog
346 file opener for reading, if NULL, send error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(pass_along[0]) )
347 does that catch directories too?
348 read lines -- if not enough lines, give error.
349 if anything outside, give error. define range with #define CONSTANTS
350 put 'em in thar widgets, and that's it.
354 static void georef_layer_export_params ( gpointer
*pass_along
[2] )
356 VikGeorefLayer
*vgl
= VIK_GEOREF_LAYER(pass_along
[0]);
357 GtkWidget
*file_selector
= gtk_file_selection_new ("Choose World file");
359 if ( gtk_dialog_run ( GTK_DIALOG ( file_selector
) ) == GTK_RESPONSE_OK
)
361 FILE *f
= fopen ( gtk_file_selection_get_filename ( GTK_FILE_SELECTION(file_selector
) ), "w" );
362 gtk_widget_destroy ( file_selector
);
365 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_WIDGET(pass_along
[0]), "The file you requested could not be opened for writing." );
370 fprintf ( f
, "%f\n%f\n%f\n%f\n%f\n%f\n", vgl
->mpp_easting
, vgl
->mpp_northing
, 0.0, 0.0, vgl
->corner
.easting
, vgl
->corner
.northing
);
375 gtk_widget_destroy ( file_selector
);
378 /* returns TRUE if OK was pressed. */
379 static gboolean
georef_layer_dialog ( VikGeorefLayer
**vgl
, gpointer vp
, GtkWindow
*w
)
381 GtkWidget
*dialog
= gtk_dialog_new_with_buttons ("Layer Properties",
383 GTK_DIALOG_MODAL
| GTK_DIALOG_DESTROY_WITH_PARENT
,
389 GtkWidget
*table
, *wfp_hbox
, *wfp_label
, *wfp_button
, *ce_label
, *ce_spin
, *cn_label
, *cn_spin
, *xlabel
, *xspin
, *ylabel
, *yspin
, *imagelabel
, *imageentry
;
391 GtkWidget
*pass_along
[4];
393 table
= gtk_table_new ( 6, 2, FALSE
);
394 gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog
)->vbox
), table
, TRUE
, TRUE
, 0 );
396 wfp_hbox
= gtk_hbox_new ( FALSE
, 0 );
397 wfp_label
= gtk_label_new ( "World File Parameters:" );
398 wfp_button
= gtk_button_new_with_label ( "Load From File..." );
400 gtk_box_pack_start ( GTK_BOX(wfp_hbox
), wfp_label
, TRUE
, TRUE
, 0 );
401 gtk_box_pack_start ( GTK_BOX(wfp_hbox
), wfp_button
, FALSE
, FALSE
, 3 );
403 ce_label
= gtk_label_new ( "Corner pixel easting:" );
404 ce_spin
= gtk_spin_button_new ( (GtkAdjustment
*) gtk_adjustment_new ( 4, 0.0, 1500000.0, 1, 5, 5 ), 1, 4 );
406 cn_label
= gtk_label_new ( "Corner pixel northing:" );
407 cn_spin
= gtk_spin_button_new ( (GtkAdjustment
*) gtk_adjustment_new ( 4, 0.0, 9000000.0, 1, 5, 5 ), 1, 4 );
409 xlabel
= gtk_label_new ( "X (easting) scale (mpp): ");
410 ylabel
= gtk_label_new ( "Y (northing) scale (mpp): ");
412 xspin
= gtk_spin_button_new ( (GtkAdjustment
*) gtk_adjustment_new ( 4, VIK_VIEWPORT_MIN_ZOOM
, VIK_VIEWPORT_MAX_ZOOM
, 1, 5, 5 ), 1, 8 );
413 yspin
= gtk_spin_button_new ( (GtkAdjustment
*) gtk_adjustment_new ( 4, VIK_VIEWPORT_MIN_ZOOM
, VIK_VIEWPORT_MAX_ZOOM
, 1, 5, 5 ), 1, 8 );
415 imagelabel
= gtk_label_new ( "Map Image:" );
416 imageentry
= vik_file_entry_new ();
420 gtk_spin_button_set_value ( GTK_SPIN_BUTTON(ce_spin
), (*vgl
)->corner
.easting
);
421 gtk_spin_button_set_value ( GTK_SPIN_BUTTON(cn_spin
), (*vgl
)->corner
.northing
);
422 gtk_spin_button_set_value ( GTK_SPIN_BUTTON(xspin
), (*vgl
)->mpp_easting
);
423 gtk_spin_button_set_value ( GTK_SPIN_BUTTON(yspin
), (*vgl
)->mpp_northing
);
425 vik_file_entry_set_filename ( VIK_FILE_ENTRY(imageentry
), (*vgl
)->image
);
429 VikCoord corner_coord
;
431 vik_viewport_screen_to_coord ( VIK_VIEWPORT(vp
), 0, 0, &corner_coord
);
432 vik_coord_to_utm ( &corner_coord
, &utm
);
433 gtk_spin_button_set_value ( GTK_SPIN_BUTTON(ce_spin
), utm
.easting
);
434 gtk_spin_button_set_value ( GTK_SPIN_BUTTON(cn_spin
), utm
.northing
);
435 gtk_spin_button_set_value ( GTK_SPIN_BUTTON(xspin
), vik_viewport_get_xmpp ( VIK_VIEWPORT(vp
) ) );
436 gtk_spin_button_set_value ( GTK_SPIN_BUTTON(yspin
), vik_viewport_get_ympp ( VIK_VIEWPORT(vp
) ) );
439 gtk_table_attach_defaults ( GTK_TABLE(table
), imagelabel
, 0, 1, 0, 1 );
440 gtk_table_attach_defaults ( GTK_TABLE(table
), imageentry
, 1, 2, 0, 1 );
441 gtk_table_attach_defaults ( GTK_TABLE(table
), wfp_hbox
, 0, 2, 1, 2 );
442 gtk_table_attach_defaults ( GTK_TABLE(table
), xlabel
, 0, 1, 2, 3 );
443 gtk_table_attach_defaults ( GTK_TABLE(table
), xspin
, 1, 2, 2, 3 );
444 gtk_table_attach_defaults ( GTK_TABLE(table
), ylabel
, 0, 1, 3, 4 );
445 gtk_table_attach_defaults ( GTK_TABLE(table
), yspin
, 1, 2, 3, 4 );
446 gtk_table_attach_defaults ( GTK_TABLE(table
), ce_label
, 0, 1, 4, 5 );
447 gtk_table_attach_defaults ( GTK_TABLE(table
), ce_spin
, 1, 2, 4, 5 );
448 gtk_table_attach_defaults ( GTK_TABLE(table
), cn_label
, 0, 1, 5, 6 );
449 gtk_table_attach_defaults ( GTK_TABLE(table
), cn_spin
, 1, 2, 5, 6 );
451 pass_along
[0] = xspin
;
452 pass_along
[1] = yspin
;
453 pass_along
[2] = ce_spin
;
454 pass_along
[3] = cn_spin
;
455 g_signal_connect_swapped ( G_OBJECT(wfp_button
), "clicked", G_CALLBACK(georef_layer_dialog_load
), pass_along
);
457 gtk_widget_show_all ( table
);
459 if ( gtk_dialog_run ( GTK_DIALOG(dialog
) ) == GTK_RESPONSE_ACCEPT
)
463 *vgl
= georef_layer_new ();
464 vik_layer_rename ( VIK_LAYER(*vgl
), vik_georef_layer_interface
.name
);
466 (*vgl
)->corner
.easting
= gtk_spin_button_get_value ( GTK_SPIN_BUTTON(ce_spin
) );
467 (*vgl
)->corner
.northing
= gtk_spin_button_get_value ( GTK_SPIN_BUTTON(cn_spin
) );
468 (*vgl
)->mpp_easting
= gtk_spin_button_get_value ( GTK_SPIN_BUTTON(xspin
) );
469 (*vgl
)->mpp_northing
= gtk_spin_button_get_value ( GTK_SPIN_BUTTON(yspin
) );
470 if ( (!(*vgl
)->image
) || strcmp( (*vgl
)->image
, vik_file_entry_get_filename(VIK_FILE_ENTRY(imageentry
)) ) != 0 )
472 georef_layer_set_image ( *vgl
, vik_file_entry_get_filename(VIK_FILE_ENTRY(imageentry
)) );
473 georef_layer_load_image ( *vgl
);
476 gtk_widget_destroy ( GTK_WIDGET(dialog
) );
479 gtk_widget_destroy ( GTK_WIDGET(dialog
) );
483 static void georef_layer_zoom_to_fit ( gpointer vgl_vlp
[2] )
485 vik_viewport_set_xmpp ( vik_layers_panel_get_viewport(VIK_LAYERS_PANEL(vgl_vlp
[1])), VIK_GEOREF_LAYER(vgl_vlp
[0])->mpp_easting
);
486 vik_viewport_set_ympp ( vik_layers_panel_get_viewport(VIK_LAYERS_PANEL(vgl_vlp
[1])), VIK_GEOREF_LAYER(vgl_vlp
[0])->mpp_northing
);
487 vik_layers_panel_emit_update ( VIK_LAYERS_PANEL(vgl_vlp
[1]) );
490 static void georef_layer_goto_center ( gpointer vgl_vlp
[2] )
492 VikGeorefLayer
*vgl
= VIK_GEOREF_LAYER ( vgl_vlp
[0] );
493 VikViewport
*vp
= vik_layers_panel_get_viewport(VIK_LAYERS_PANEL(vgl_vlp
[1]));
497 vik_coord_to_utm ( vik_viewport_get_center ( vp
), &utm
);
499 utm
.easting
= vgl
->corner
.easting
+ (vgl
->width
* vgl
->mpp_easting
/ 2); /* only an approximation */
500 utm
.northing
= vgl
->corner
.northing
- (vgl
->height
* vgl
->mpp_northing
/ 2);
502 vik_coord_load_from_utm ( &coord
, vik_viewport_get_coord_mode ( vp
), &utm
);
503 vik_viewport_set_center_coord ( vp
, &coord
);
505 vik_layers_panel_emit_update ( VIK_LAYERS_PANEL(vgl_vlp
[1]) );
508 static void georef_layer_add_menu_items ( VikGeorefLayer
*vgl
, GtkMenu
*menu
, gpointer vlp
)
510 static gpointer pass_along
[2];
515 item
= gtk_menu_item_new();
516 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
517 gtk_widget_show ( item
);
519 item
= gtk_menu_item_new_with_label ( "Zoom to Fit Map" );
520 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(georef_layer_zoom_to_fit
), pass_along
);
521 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
522 gtk_widget_show ( item
);
524 item
= gtk_menu_item_new_with_label ( "Goto Map Center" );
525 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(georef_layer_goto_center
), pass_along
);
526 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
527 gtk_widget_show ( item
);
529 item
= gtk_menu_item_new_with_label ( "Export to World File" );
530 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(georef_layer_export_params
), pass_along
);
531 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
532 gtk_widget_show ( item
);
536 static gpointer
georef_layer_move_create ( VikWindow
*vw
, VikViewport
*vvp
)
541 static gboolean
georef_layer_move_release ( VikGeorefLayer
*vgl
, GdkEventButton
*event
, VikViewport
*vvp
)
543 if (!vgl
|| vgl
->vl
.type
!= VIK_LAYER_GEOREF
)
546 if ( vgl
->click_x
!= -1 )
548 vgl
->corner
.easting
+= (event
->x
- vgl
->click_x
) * vik_viewport_get_xmpp (vvp
);
549 vgl
->corner
.northing
-= (event
->y
- vgl
->click_y
) * vik_viewport_get_ympp (vvp
);
550 vik_layer_emit_update ( VIK_LAYER(vgl
) );
553 return FALSE
; /* I didn't move anything on this layer! */
556 static gpointer
georef_layer_zoom_create ( VikWindow
*vw
, VikViewport
*vvp
)
561 static gboolean
georef_layer_zoom_press ( VikGeorefLayer
*vgl
, GdkEventButton
*event
, VikViewport
*vvp
)
563 if (!vgl
|| vgl
->vl
.type
!= VIK_LAYER_GEOREF
)
565 if ( event
->button
== 1 )
567 if ( vgl
->mpp_easting
< (VIK_VIEWPORT_MAX_ZOOM
/ 1.05) && vgl
->mpp_northing
< (VIK_VIEWPORT_MAX_ZOOM
/ 1.05) )
569 vgl
->mpp_easting
*= 1.01;
570 vgl
->mpp_northing
*= 1.01;
575 if ( vgl
->mpp_easting
> (VIK_VIEWPORT_MIN_ZOOM
* 1.05) && vgl
->mpp_northing
> (VIK_VIEWPORT_MIN_ZOOM
* 1.05) )
577 vgl
->mpp_easting
/= 1.01;
578 vgl
->mpp_northing
/= 1.01;
581 vik_viewport_set_xmpp ( vvp
, vgl
->mpp_easting
);
582 vik_viewport_set_ympp ( vvp
, vgl
->mpp_northing
);
583 vik_layer_emit_update ( VIK_LAYER(vgl
) );
587 static gboolean
georef_layer_move_press ( VikGeorefLayer
*vgl
, GdkEventButton
*event
, VikViewport
*vvp
)
589 if (!vgl
|| vgl
->vl
.type
!= VIK_LAYER_GEOREF
)
591 vgl
->click_x
= event
->x
;
592 vgl
->click_y
= event
->y
;