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
22 #define WAYPOINT_FONT "Sans 8"
24 /* WARNING: If you go beyond this point, we are NOT responsible for any ill effects on your sanity */
25 /* viktrwlayer.c -- 2200 lines can make a difference in the state of things */
32 #include "vikmapslayer.h"
33 #include "viktrwlayer_pixmap.h"
34 #include "viktrwlayer_tpwin.h"
35 #include "viktrwlayer_propwin.h"
36 #include "garminsymbols.h"
37 #include "thumbnails.h"
38 #include "background.h"
43 #ifdef VIK_CONFIG_OPENSTREETMAP
44 #include "osm-traces.h"
52 #define GOOGLE_DIRECTIONS_STRING "(wget -O - \"http://maps.google.com/maps?q=%f,%f to %f,%f&output=js\" 2>/dev/null)"
53 #define VIK_TRW_LAYER_TRACK_GC 13
54 #define VIK_TRW_LAYER_TRACK_GC_RATES 10
55 #define VIK_TRW_LAYER_TRACK_GC_MIN 0
56 #define VIK_TRW_LAYER_TRACK_GC_MAX 11
57 #define VIK_TRW_LAYER_TRACK_GC_BLACK 12
59 #define DRAWMODE_BY_TRACK 0
60 #define DRAWMODE_BY_VELOCITY 1
61 #define DRAWMODE_ALL_BLACK 2
66 /* this is how it knows when you click if you are clicking close to a trackpoint. */
67 #define TRACKPOINT_SIZE_APPROX 5
68 #define WAYPOINT_SIZE_APPROX 5
70 #define MIN_STOP_LENGTH 15
71 #define MAX_STOP_LENGTH 86400
72 #define DRAW_ELEVATION_FACTOR 30 /* height of elevation plotting, sort of relative to zoom level ("mpp" that isn't mpp necessarily) */
73 /* this is multiplied by user-inputted value from 1-100. */
75 VIK_TRW_LAYER_SUBLAYER_TRACKS
,
76 VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
,
77 VIK_TRW_LAYER_SUBLAYER_TRACK
,
78 VIK_TRW_LAYER_SUBLAYER_WAYPOINT
81 enum { WP_SYMBOL_FILLED_SQUARE
, WP_SYMBOL_SQUARE
, WP_SYMBOL_CIRCLE
, WP_SYMBOL_X
, WP_NUM_SYMBOLS
};
86 GHashTable
*tracks_iters
;
87 GHashTable
*waypoints_iters
;
88 GHashTable
*waypoints
;
89 GtkTreeIter waypoints_iter
, tracks_iter
;
90 gboolean tracks_visible
, waypoints_visible
;
94 guint8 elevation_factor
;
98 guint8 line_thickness
;
99 guint8 bg_line_thickness
;
103 gboolean wp_draw_symbols
;
105 gdouble velocity_min
, velocity_max
;
107 guint16 track_gc_iter
;
110 GdkGC
*waypoint_text_gc
;
111 GdkGC
*waypoint_bg_gc
;
112 GdkFont
*waypoint_font
;
113 VikTrack
*current_track
;
114 guint16 ct_x1
, ct_y1
, ct_x2
, ct_y2
;
116 VikCoordMode coord_mode
;
118 /* wp editing tool */
119 VikWaypoint
*current_wp
;
120 gchar
*current_wp_name
;
122 gboolean waypoint_rightclick
;
124 /* track editing tool */
126 gchar
*current_tp_track_name
;
127 VikTrwLayerTpwin
*tpwin
;
129 /* weird hack for joining tracks */
131 gchar
*last_tp_track_name
;
133 /* track editing tool -- more specifically, moving tps */
136 /* magic scissors tool */
137 gboolean magic_scissors_started
;
138 VikCoord magic_scissors_coord
;
145 guint16 image_cache_size
;
147 /* for waypoint text */
148 PangoLayout
*wplabellayout
;
150 gboolean has_verified_thumbnails
;
152 GtkMenu
*wp_right_click_menu
;
155 VikStdLayerMenuItem menu_selection
;
159 /* A caached waypoint image. */
162 gchar
*image
; /* filename */
165 struct DrawingParams
{
169 guint16 width
, height
;
170 const VikCoord
*center
;
172 gboolean one_zone
, lat_lon
;
173 gdouble ce1
, ce2
, cn1
, cn2
;
176 static void vik_trw_layer_set_menu_selection(VikTrwLayer
*vtl
, guint16
);
177 static guint16
vik_trw_layer_get_menu_selection(VikTrwLayer
*vtl
);
179 static void trw_layer_delete_item ( gpointer
*pass_along
);
180 static void trw_layer_copy_item_cb( gpointer
*pass_along
);
181 static void trw_layer_cut_item_cb( gpointer
*pass_along
);
183 static void trw_layer_find_maxmin_waypoints ( const gchar
*name
, const VikWaypoint
*w
, struct LatLon maxmin
[2] );
184 static void trw_layer_find_maxmin_tracks ( const gchar
*name
, GList
**t
, struct LatLon maxmin
[2] );
186 static void trw_layer_new_track_gcs ( VikTrwLayer
*vtl
, VikViewport
*vp
);
187 static void trw_layer_free_track_gcs ( VikTrwLayer
*vtl
);
189 static gint
calculate_velocity ( VikTrwLayer
*vtl
, VikTrackpoint
*tp1
, VikTrackpoint
*tp2
);
190 static void trw_layer_draw_track_cb ( const gchar
*name
, VikTrack
*track
, struct DrawingParams
*dp
);
191 static void trw_layer_draw_waypoint ( const gchar
*name
, VikWaypoint
*wp
, struct DrawingParams
*dp
);
193 static void goto_coord ( VikLayersPanel
*vlp
, const VikCoord
*coord
);
194 static void trw_layer_goto_track_startpoint ( gpointer pass_along
[5] );
195 static void trw_layer_goto_track_endpoint ( gpointer pass_along
[6] );
196 static void trw_layer_merge_by_timestamp ( gpointer pass_along
[6] );
197 static void trw_layer_split_by_timestamp ( gpointer pass_along
[6] );
198 static void trw_layer_download_map_along_track_cb(gpointer pass_along
[6]);
199 static void trw_layer_centerize ( gpointer layer_and_vlp
[2] );
200 static void trw_layer_export ( gpointer layer_and_vlp
[2], guint file_type
);
201 static void trw_layer_goto_wp ( gpointer layer_and_vlp
[2] );
202 static void trw_layer_new_wp ( gpointer lav
[2] );
205 static void trw_layer_properties_item ( gpointer pass_along
[5] );
206 static void trw_layer_goto_waypoint ( gpointer pass_along
[5] );
207 static void trw_layer_waypoint_gc_webpage ( gpointer pass_along
[5] );
209 static void trw_layer_realize_waypoint ( gchar
*name
, VikWaypoint
*wp
, gpointer pass_along
[4] );
210 static void trw_layer_realize_track ( gchar
*name
, VikTrack
*track
, gpointer pass_along
[4] );
211 static void init_drawing_params ( struct DrawingParams
*dp
, VikViewport
*vp
);
214 static VikTrwLayer
*trw_layer_copy ( VikTrwLayer
*vtl
, gpointer vp
);
215 static void trw_layer_marshall( VikTrwLayer
*vtl
, guint8
**data
, gint
*len
);
216 static VikTrwLayer
*trw_layer_unmarshall( gpointer data
, gint len
, VikViewport
*vvp
);
218 static gboolean
trw_layer_set_param ( VikTrwLayer
*vtl
, guint16 id
, VikLayerParamData data
, VikViewport
*vp
);
219 static VikLayerParamData
trw_layer_get_param ( VikTrwLayer
*vtl
, guint16 id
);
221 static void trw_layer_del_item ( VikTrwLayer
*vtl
, gint subtype
, gpointer sublayer
);
222 static void trw_layer_copy_item ( VikTrwLayer
*vtl
, gint subtype
, gpointer sublayer
, guint8
**item
, guint
*len
);
223 static gboolean
trw_layer_paste_item ( VikTrwLayer
*vtl
, gint subtype
, guint8
*item
, guint len
);
224 static void trw_layer_free_copied_item ( gint subtype
, gpointer item
);
225 static void trw_layer_drag_drop_request ( VikTrwLayer
*vtl_src
, VikTrwLayer
*vtl_dest
, GtkTreeIter
*src_item_iter
, GtkTreePath
*dest_path
);
227 static void trw_layer_cancel_tps_of_track ( VikTrwLayer
*vtl
, const gchar
*trk_name
);
228 static void trw_layer_cancel_last_tp ( VikTrwLayer
*vtl
);
229 static void trw_layer_cancel_current_tp ( VikTrwLayer
*vtl
, gboolean destroy
);
230 static void trw_layer_tpwin_response ( VikTrwLayer
*vtl
, gint response
);
231 static void trw_layer_tpwin_init ( VikTrwLayer
*vtl
);
233 static gpointer
tool_edit_trackpoint_create ( VikWindow
*vw
, VikViewport
*vvp
);
234 static gboolean
tool_edit_trackpoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
235 static gboolean
tool_edit_trackpoint_move ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
236 static gboolean
tool_edit_trackpoint_release ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
237 static gpointer
tool_show_picture_create ( VikWindow
*vw
, VikViewport
*vvp
);
238 static gboolean
tool_show_picture_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
);
239 static gpointer
tool_edit_waypoint_create ( VikWindow
*vw
, VikViewport
*vvp
);
240 static gboolean
tool_edit_waypoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
241 static gboolean
tool_edit_waypoint_move ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
242 static gboolean
tool_edit_waypoint_release ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
243 static gpointer
tool_new_track_create ( VikWindow
*vw
, VikViewport
*vvp
);
244 static gboolean
tool_new_track_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
);
245 static gpointer
tool_new_waypoint_create ( VikWindow
*vw
, VikViewport
*vvp
);
246 static gboolean
tool_new_waypoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
);
247 static gpointer
tool_magic_scissors_create ( VikWindow
*vw
, VikViewport
*vvp
);
248 static gboolean
tool_magic_scissors_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
);
251 static gboolean
uppercase_exists_in_hash ( GHashTable
*hash
, const gchar
*str
);
253 static void cached_pixbuf_free ( CachedPixbuf
*cp
);
254 static gint
cached_pixbuf_cmp ( CachedPixbuf
*cp
, const gchar
*name
);
255 static void trw_layer_verify_thumbnails ( VikTrwLayer
*vtl
, GtkWidget
*vp
);
257 static VikTrackpoint
*closest_tp_in_five_pixel_interval ( VikTrwLayer
*vtl
, VikViewport
*vvp
, gint x
, gint y
);
258 static VikWaypoint
*closest_wp_in_five_pixel_interval ( VikTrwLayer
*vtl
, VikViewport
*vvp
, gint x
, gint y
);
260 static void trw_layer_change_coord_mode ( VikTrwLayer
*vtl
, VikCoordMode dest_mode
);
262 static gchar
*get_new_unique_sublayer_name (VikTrwLayer
*vtl
, gint sublayer_type
, const gchar
*name
);
263 static void waypoint_convert ( const gchar
*name
, VikWaypoint
*wp
, VikCoordMode
*dest_mode
);
264 static void track_convert ( const gchar
*name
, VikTrack
*tr
, VikCoordMode
*dest_mode
);
266 static VikToolInterface trw_layer_tools
[] = {
267 { "Create Waypoint", (VikToolConstructorFunc
) tool_new_waypoint_create
, NULL
, NULL
, NULL
,
268 (VikToolMouseFunc
) tool_new_waypoint_click
, NULL
, NULL
},
270 { "Create Track", (VikToolConstructorFunc
) tool_new_track_create
, NULL
, NULL
, NULL
,
271 (VikToolMouseFunc
) tool_new_track_click
, NULL
, NULL
},
273 { "Edit Waypoint", (VikToolConstructorFunc
) tool_edit_waypoint_create
, NULL
, NULL
, NULL
,
274 (VikToolMouseFunc
) tool_edit_waypoint_click
,
275 (VikToolMouseFunc
) tool_edit_waypoint_move
,
276 (VikToolMouseFunc
) tool_edit_waypoint_release
},
278 { "Edit Trackpoint", (VikToolConstructorFunc
) tool_edit_trackpoint_create
, NULL
, NULL
, NULL
,
279 (VikToolMouseFunc
) tool_edit_trackpoint_click
,
280 (VikToolMouseFunc
) tool_edit_trackpoint_move
,
281 (VikToolMouseFunc
) tool_edit_trackpoint_release
},
283 { "Show Picture", (VikToolConstructorFunc
) tool_show_picture_create
, NULL
, NULL
, NULL
,
284 (VikToolMouseFunc
) tool_show_picture_click
, NULL
, NULL
},
286 { "Magic Scissors", (VikToolConstructorFunc
) tool_magic_scissors_create
, NULL
, NULL
, NULL
,
287 (VikToolMouseFunc
) tool_magic_scissors_click
, NULL
, NULL
},
290 /****** PARAMETERS ******/
292 static gchar
*params_groups
[] = { "Waypoints", "Tracks", "Waypoint Images" };
293 enum { GROUP_WAYPOINTS
, GROUP_TRACKS
, GROUP_IMAGES
};
295 static gchar
*params_drawmodes
[] = { "Draw by Track", "Draw by Velocity", "All Tracks Black", 0 };
296 static gchar
*params_wpsymbols
[] = { "Filled Square", "Square", "Circle", "X", 0 };
299 static VikLayerParamScale params_scales
[] = {
300 /* min max step digits */
301 { 1, 10, 1, 0 }, /* line_thickness */
302 { 0.0, 99.0, 1, 2 }, /* velocity_min */
303 { 1.0, 100.0, 1.0, 2 }, /* velocity_max */
304 /* 5 * step == how much to turn */
305 { 16, 128, 3.2, 0 }, /* image_size */
306 { 0, 255, 5, 0 }, /* image alpha */
307 { 5, 500, 5, 0 }, /* image cache_size */
308 { 0, 8, 1, 0 }, /* image cache_size */
309 { 1, 64, 1, 0 }, /* wpsize */
310 { MIN_STOP_LENGTH
, MAX_STOP_LENGTH
, 1, 0 }, /* stop_length */
311 { 1, 100, 1, 0 }, /* stop_length */
314 VikLayerParam trw_layer_params
[] = {
315 { "tracks_visible", VIK_LAYER_PARAM_BOOLEAN
, VIK_LAYER_NOT_IN_PROPERTIES
},
316 { "waypoints_visible", VIK_LAYER_PARAM_BOOLEAN
, VIK_LAYER_NOT_IN_PROPERTIES
},
318 { "drawmode", VIK_LAYER_PARAM_UINT
, GROUP_TRACKS
, "Track Drawing Mode:", VIK_LAYER_WIDGET_RADIOGROUP
, NULL
},
319 { "drawlines", VIK_LAYER_PARAM_BOOLEAN
, GROUP_TRACKS
, "Draw Track Lines", VIK_LAYER_WIDGET_CHECKBUTTON
},
320 { "drawpoints", VIK_LAYER_PARAM_BOOLEAN
, GROUP_TRACKS
, "Draw Trackpoints", VIK_LAYER_WIDGET_CHECKBUTTON
},
321 { "drawelevation", VIK_LAYER_PARAM_BOOLEAN
, GROUP_TRACKS
, "Draw Elevation", VIK_LAYER_WIDGET_CHECKBUTTON
},
322 { "elevation_factor", VIK_LAYER_PARAM_UINT
, GROUP_TRACKS
, "Draw Elevation Height %:", VIK_LAYER_WIDGET_HSCALE
, params_scales
+ 9 },
324 { "drawstops", VIK_LAYER_PARAM_BOOLEAN
, GROUP_TRACKS
, "Draw Stops", VIK_LAYER_WIDGET_CHECKBUTTON
},
325 { "stop_length", VIK_LAYER_PARAM_UINT
, GROUP_TRACKS
, "Min Stop Length (seconds):", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 8 },
327 { "line_thickness", VIK_LAYER_PARAM_UINT
, GROUP_TRACKS
, "Track Thickness:", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 0 },
328 { "bg_line_thickness", VIK_LAYER_PARAM_UINT
, GROUP_TRACKS
, "Track BG Thickness:", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 6 },
329 { "trackbgcolor", VIK_LAYER_PARAM_COLOR
, GROUP_TRACKS
, "Track Background Color", VIK_LAYER_WIDGET_COLOR
, 0 },
330 { "velocity_min", VIK_LAYER_PARAM_DOUBLE
, GROUP_TRACKS
, "Min Track Velocity:", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 1 },
331 { "velocity_max", VIK_LAYER_PARAM_DOUBLE
, GROUP_TRACKS
, "Max Track Velocity:", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 2 },
333 { "drawlabels", VIK_LAYER_PARAM_BOOLEAN
, GROUP_WAYPOINTS
, "Draw Labels", VIK_LAYER_WIDGET_CHECKBUTTON
},
334 { "wpcolor", VIK_LAYER_PARAM_COLOR
, GROUP_WAYPOINTS
, "Waypoint Color:", VIK_LAYER_WIDGET_COLOR
, 0 },
335 { "wptextcolor", VIK_LAYER_PARAM_COLOR
, GROUP_WAYPOINTS
, "Waypoint Text:", VIK_LAYER_WIDGET_COLOR
, 0 },
336 { "wpbgcolor", VIK_LAYER_PARAM_COLOR
, GROUP_WAYPOINTS
, "Background:", VIK_LAYER_WIDGET_COLOR
, 0 },
337 { "wpbgand", VIK_LAYER_PARAM_BOOLEAN
, GROUP_WAYPOINTS
, "Fake BG Color Translucency:", VIK_LAYER_WIDGET_CHECKBUTTON
, 0 },
338 { "wpsymbol", VIK_LAYER_PARAM_UINT
, GROUP_WAYPOINTS
, "Waypoint marker:", VIK_LAYER_WIDGET_RADIOGROUP
, NULL
},
339 { "wpsize", VIK_LAYER_PARAM_UINT
, GROUP_WAYPOINTS
, "Waypoint size:", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 7 },
340 { "wpsyms", VIK_LAYER_PARAM_BOOLEAN
, GROUP_WAYPOINTS
, "Draw Waypoint Symbols:", VIK_LAYER_WIDGET_CHECKBUTTON
},
342 { "drawimages", VIK_LAYER_PARAM_BOOLEAN
, GROUP_IMAGES
, "Draw Waypoint Images", VIK_LAYER_WIDGET_CHECKBUTTON
},
343 { "image_size", VIK_LAYER_PARAM_UINT
, GROUP_IMAGES
, "Image Size (pixels):", VIK_LAYER_WIDGET_HSCALE
, params_scales
+ 3 },
344 { "image_alpha", VIK_LAYER_PARAM_UINT
, GROUP_IMAGES
, "Image Alpha:", VIK_LAYER_WIDGET_HSCALE
, params_scales
+ 4 },
345 { "image_cache_size", VIK_LAYER_PARAM_UINT
, GROUP_IMAGES
, "Image Memory Cache Size:", VIK_LAYER_WIDGET_HSCALE
, params_scales
+ 5 },
348 enum { PARAM_TV
, PARAM_WV
, PARAM_DM
, PARAM_DL
, PARAM_DP
, PARAM_DE
, PARAM_EF
, PARAM_DS
, PARAM_SL
, PARAM_LT
, PARAM_BLT
, PARAM_TBGC
, PARAM_VMIN
, PARAM_VMAX
, PARAM_DLA
, PARAM_WPC
, PARAM_WPTC
, PARAM_WPBC
, PARAM_WPBA
, PARAM_WPSYM
, PARAM_WPSIZE
, PARAM_WPSYMS
, PARAM_DI
, PARAM_IS
, PARAM_IA
, PARAM_ICS
, NUM_PARAMS
};
351 *** 1) Add to trw_layer_params and enumeration
352 *** 2) Handle in get_param & set_param (presumably adding on to VikTrwLayer struct)
355 /****** END PARAMETERS ******/
357 VikLayerInterface vik_trw_layer_interface
= {
362 sizeof(trw_layer_tools
) / sizeof(VikToolInterface
),
366 params_groups
, /* params_groups */
367 sizeof(params_groups
)/sizeof(params_groups
[0]), /* number of groups */
371 (VikLayerFuncCreate
) vik_trw_layer_create
,
372 (VikLayerFuncRealize
) vik_trw_layer_realize
,
373 (VikLayerFuncPostRead
) trw_layer_verify_thumbnails
,
374 (VikLayerFuncFree
) vik_trw_layer_free
,
376 (VikLayerFuncProperties
) NULL
,
377 (VikLayerFuncDraw
) vik_trw_layer_draw
,
378 (VikLayerFuncChangeCoordMode
) trw_layer_change_coord_mode
,
380 (VikLayerFuncSetMenuItemsSelection
) vik_trw_layer_set_menu_selection
,
381 (VikLayerFuncGetMenuItemsSelection
) vik_trw_layer_get_menu_selection
,
383 (VikLayerFuncAddMenuItems
) vik_trw_layer_add_menu_items
,
384 (VikLayerFuncSublayerAddMenuItems
) vik_trw_layer_sublayer_add_menu_items
,
386 (VikLayerFuncSublayerRenameRequest
) vik_trw_layer_sublayer_rename_request
,
387 (VikLayerFuncSublayerToggleVisible
) vik_trw_layer_sublayer_toggle_visible
,
389 (VikLayerFuncCopy
) trw_layer_copy
,
390 (VikLayerFuncMarshall
) trw_layer_marshall
,
391 (VikLayerFuncUnmarshall
) trw_layer_unmarshall
,
393 (VikLayerFuncSetParam
) trw_layer_set_param
,
394 (VikLayerFuncGetParam
) trw_layer_get_param
,
396 (VikLayerFuncReadFileData
) a_gpspoint_read_file
,
397 (VikLayerFuncWriteFileData
) a_gpspoint_write_file
,
399 (VikLayerFuncDeleteItem
) trw_layer_del_item
,
400 (VikLayerFuncCopyItem
) trw_layer_copy_item
,
401 (VikLayerFuncPasteItem
) trw_layer_paste_item
,
402 (VikLayerFuncFreeCopiedItem
) trw_layer_free_copied_item
,
404 (VikLayerFuncDragDropRequest
) trw_layer_drag_drop_request
,
407 /* for copy & paste (I think?) */
415 GType
vik_trw_layer_get_type ()
417 static GType vtl_type
= 0;
421 static const GTypeInfo vtl_info
=
423 sizeof (VikTrwLayerClass
),
424 NULL
, /* base_init */
425 NULL
, /* base_finalize */
426 NULL
, /* class init */
427 NULL
, /* class_finalize */
428 NULL
, /* class_data */
429 sizeof (VikTrwLayer
),
431 NULL
/* instance init */
433 vtl_type
= g_type_register_static ( VIK_LAYER_TYPE
, "VikTrwLayer", &vtl_info
, 0 );
439 static void trw_layer_del_item ( VikTrwLayer
*vtl
, gint subtype
, gpointer sublayer
)
441 static gpointer pass_along
[5];
447 pass_along
[1] = NULL
;
448 pass_along
[2] = (gpointer
) subtype
;
449 pass_along
[3] = sublayer
;
450 pass_along
[4] = NULL
;
452 trw_layer_delete_item ( pass_along
);
455 static void trw_layer_copy_item_cb( gpointer pass_along
[5])
457 VikTrwLayer
*vtl
= VIK_TRW_LAYER(pass_along
[0]);
458 gint subtype
= (gint
)pass_along
[2];
459 gpointer
* sublayer
= pass_along
[3];
463 trw_layer_copy_item( vtl
, subtype
, sublayer
, &data
, &len
);
466 a_clipboard_copy( VIK_CLIPBOARD_DATA_SUBLAYER
, VIK_LAYER_TRW
,
471 static void trw_layer_cut_item_cb( gpointer pass_along
[5])
473 trw_layer_copy_item_cb(pass_along
);
474 trw_layer_delete_item(pass_along
);
477 static void trw_layer_copy_item ( VikTrwLayer
*vtl
, gint subtype
, gpointer sublayer
, guint8
**item
, guint
*len
)
488 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
)
490 vik_waypoint_marshall ( g_hash_table_lookup ( vtl
->waypoints
, sublayer
), &id
, &il
);
492 vik_track_marshall ( g_hash_table_lookup ( vtl
->tracks
, sublayer
), &id
, &il
);
495 *len
= sizeof(FlatItem
) + strlen(sublayer
) + 1 + il
;
496 fi
= g_malloc ( *len
);
497 fi
->len
= strlen(sublayer
) + 1;
498 memcpy(fi
->data
, sublayer
, fi
->len
);
499 memcpy(fi
->data
+ fi
->len
, id
, il
);
501 *item
= (guint8
*)fi
;
504 static gboolean
trw_layer_paste_item ( VikTrwLayer
*vtl
, gint subtype
, guint8
*item
, guint len
)
506 FlatItem
*fi
= (FlatItem
*) item
;
508 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
&& fi
)
513 name
= get_new_unique_sublayer_name(vtl
, VIK_TRW_LAYER_SUBLAYER_WAYPOINT
, (gchar
*)fi
->data
);
514 w
= vik_waypoint_unmarshall(fi
->data
+ fi
->len
, len
- sizeof(*fi
) - fi
->len
);
515 vik_trw_layer_add_waypoint ( vtl
, name
, w
);
516 waypoint_convert(name
, w
, &vtl
->coord_mode
);
519 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_TRACK
&& fi
)
523 name
= get_new_unique_sublayer_name(vtl
, VIK_TRW_LAYER_SUBLAYER_TRACK
, (gchar
*)fi
->data
);
524 t
= vik_track_unmarshall(fi
->data
+ fi
->len
, len
- sizeof(*fi
) - fi
->len
);
525 vik_trw_layer_add_track ( vtl
, name
, t
);
526 track_convert(name
, t
, &vtl
->coord_mode
);
532 static void trw_layer_free_copied_item ( gint subtype
, gpointer item
)
539 static void waypoint_copy ( const gchar
*name
, VikWaypoint
*wp
, GHashTable
*dest
)
541 g_hash_table_insert ( dest
, g_strdup(name
), vik_waypoint_copy(wp
) );
544 static gboolean
trw_layer_set_param ( VikTrwLayer
*vtl
, guint16 id
, VikLayerParamData data
, VikViewport
*vp
)
548 case PARAM_TV
: vtl
->tracks_visible
= data
.b
; break;
549 case PARAM_WV
: vtl
->waypoints_visible
= data
.b
; break;
550 case PARAM_DM
: vtl
->drawmode
= data
.u
; break;
551 case PARAM_DP
: vtl
->drawpoints
= data
.b
; break;
552 case PARAM_DE
: vtl
->drawelevation
= data
.b
; break;
553 case PARAM_DS
: vtl
->drawstops
= data
.b
; break;
554 case PARAM_DL
: vtl
->drawlines
= data
.b
; break;
555 case PARAM_SL
: if ( data
.u
>= MIN_STOP_LENGTH
&& data
.u
<= MAX_STOP_LENGTH
)
556 vtl
->stop_length
= data
.u
;
558 case PARAM_EF
: if ( data
.u
>= 1 && data
.u
<= 100 )
559 vtl
->elevation_factor
= data
.u
;
561 case PARAM_LT
: if ( data
.u
> 0 && data
.u
< 15 && data
.u
!= vtl
->line_thickness
)
563 vtl
->line_thickness
= data
.u
;
564 trw_layer_new_track_gcs ( vtl
, vp
);
567 case PARAM_BLT
: if ( data
.u
> 0 && data
.u
<= 8 && data
.u
!= vtl
->bg_line_thickness
)
569 vtl
->bg_line_thickness
= data
.u
;
570 trw_layer_new_track_gcs ( vtl
, vp
);
573 case PARAM_VMIN
: vtl
->velocity_min
= data
.d
; break;
574 case PARAM_VMAX
: vtl
->velocity_max
= data
.d
; break;
575 case PARAM_TBGC
: gdk_gc_set_rgb_fg_color(vtl
->track_bg_gc
, &(data
.c
)); break;
576 case PARAM_DLA
: vtl
->drawlabels
= data
.b
; break;
577 case PARAM_DI
: vtl
->drawimages
= data
.b
; break;
578 case PARAM_IS
: if ( data
.u
!= vtl
->image_size
)
580 vtl
->image_size
= data
.u
;
581 g_list_foreach ( vtl
->image_cache
->head
, (GFunc
) cached_pixbuf_free
, NULL
);
582 g_queue_free ( vtl
->image_cache
);
583 vtl
->image_cache
= g_queue_new ();
586 case PARAM_IA
: vtl
->image_alpha
= data
.u
; break;
587 case PARAM_ICS
: vtl
->image_cache_size
= data
.u
;
588 while ( vtl
->image_cache
->length
> vtl
->image_cache_size
) /* if shrinking cache_size, free pixbuf ASAP */
589 cached_pixbuf_free ( g_queue_pop_tail ( vtl
->image_cache
) );
591 case PARAM_WPC
: gdk_gc_set_rgb_fg_color(vtl
->waypoint_gc
, &(data
.c
)); break;
592 case PARAM_WPTC
: gdk_gc_set_rgb_fg_color(vtl
->waypoint_text_gc
, &(data
.c
)); break;
593 case PARAM_WPBC
: gdk_gc_set_rgb_fg_color(vtl
->waypoint_bg_gc
, &(data
.c
)); break;
594 case PARAM_WPBA
: gdk_gc_set_function(vtl
->waypoint_bg_gc
, data
.b
? GDK_AND
: GDK_COPY
); break;
595 case PARAM_WPSYM
: if ( data
.u
< WP_NUM_SYMBOLS
) vtl
->wp_symbol
= data
.u
; break;
596 case PARAM_WPSIZE
: if ( data
.u
> 0 && data
.u
<= 64 ) vtl
->wp_size
= data
.u
; break;
597 case PARAM_WPSYMS
: vtl
->wp_draw_symbols
= data
.b
; break;
602 static VikLayerParamData
trw_layer_get_param ( VikTrwLayer
*vtl
, guint16 id
)
604 VikLayerParamData rv
;
607 case PARAM_TV
: rv
.b
= vtl
->tracks_visible
; break;
608 case PARAM_WV
: rv
.b
= vtl
->waypoints_visible
; break;
609 case PARAM_DM
: rv
.u
= vtl
->drawmode
; break;
610 case PARAM_DP
: rv
.b
= vtl
->drawpoints
; break;
611 case PARAM_DE
: rv
.b
= vtl
->drawelevation
; break;
612 case PARAM_EF
: rv
.u
= vtl
->elevation_factor
; break;
613 case PARAM_DS
: rv
.b
= vtl
->drawstops
; break;
614 case PARAM_SL
: rv
.u
= vtl
->stop_length
; break;
615 case PARAM_DL
: rv
.b
= vtl
->drawlines
; break;
616 case PARAM_LT
: rv
.u
= vtl
->line_thickness
; break;
617 case PARAM_BLT
: rv
.u
= vtl
->bg_line_thickness
; break;
618 case PARAM_VMIN
: rv
.d
= vtl
->velocity_min
; break;
619 case PARAM_VMAX
: rv
.d
= vtl
->velocity_max
; break;
620 case PARAM_DLA
: rv
.b
= vtl
->drawlabels
; break;
621 case PARAM_DI
: rv
.b
= vtl
->drawimages
; break;
622 case PARAM_TBGC
: vik_gc_get_fg_color(vtl
->track_bg_gc
, &(rv
.c
)); break;
623 case PARAM_IS
: rv
.u
= vtl
->image_size
; break;
624 case PARAM_IA
: rv
.u
= vtl
->image_alpha
; break;
625 case PARAM_ICS
: rv
.u
= vtl
->image_cache_size
; break;
626 case PARAM_WPC
: vik_gc_get_fg_color(vtl
->waypoint_gc
, &(rv
.c
)); break;
627 case PARAM_WPTC
: vik_gc_get_fg_color(vtl
->waypoint_text_gc
, &(rv
.c
)); break;
628 case PARAM_WPBC
: vik_gc_get_fg_color(vtl
->waypoint_bg_gc
, &(rv
.c
)); break;
629 case PARAM_WPBA
: rv
.b
= (vik_gc_get_function(vtl
->waypoint_bg_gc
)==GDK_AND
); break;
630 case PARAM_WPSYM
: rv
.u
= vtl
->wp_symbol
; break;
631 case PARAM_WPSIZE
: rv
.u
= vtl
->wp_size
; break;
632 case PARAM_WPSYMS
: rv
.b
= vtl
->wp_draw_symbols
; break;
637 static void track_copy ( const gchar
*name
, VikTrack
*tr
, GHashTable
*dest
)
639 g_hash_table_insert ( dest
, g_strdup ( name
), vik_track_copy(tr
) );
642 static void trw_layer_marshall( VikTrwLayer
*vtl
, guint8
**data
, gint
*len
)
651 if ((f
= fdopen(g_file_open_tmp (NULL
, &tmpname
, NULL
), "r+"))) {
652 a_gpx_write_file(vtl
, f
);
653 vik_layer_marshall_params(VIK_LAYER(vtl
), &pd
, &pl
);
655 g_file_get_contents(tmpname
, (void *)&dd
, (void *)&dl
, NULL
);
656 *len
= sizeof(pl
) + pl
+ dl
;
657 *data
= g_malloc(*len
);
658 memcpy(*data
, &pl
, sizeof(pl
));
659 memcpy(*data
+ sizeof(pl
), pd
, pl
);
660 memcpy(*data
+ sizeof(pl
) + pl
, dd
, dl
);
669 static VikTrwLayer
*trw_layer_unmarshall( gpointer data
, gint len
, VikViewport
*vvp
)
671 VikTrwLayer
*rv
= VIK_TRW_LAYER(vik_layer_create ( VIK_LAYER_TRW
, vvp
, NULL
, FALSE
));
677 memcpy(&pl
, data
, sizeof(pl
));
679 vik_layer_unmarshall_params ( VIK_LAYER(rv
), data
, pl
, vvp
);
682 if (!(f
= fdopen(g_file_open_tmp (NULL
, &tmpname
, NULL
), "r+"))) {
683 g_critical("couldn't open temp file\n");
686 fwrite(data
, len
- pl
- sizeof(pl
), 1, f
);
688 a_gpx_read_file(rv
, f
);
695 static VikTrwLayer
*trw_layer_copy ( VikTrwLayer
*vtl
, gpointer vp
)
697 VikTrwLayer
*rv
= vik_trw_layer_new ( vtl
->drawmode
);
698 PangoFontDescription
*pfd
;
699 rv
->wplabellayout
= gtk_widget_create_pango_layout (GTK_WIDGET(vp
), NULL
);
700 pfd
= pango_font_description_from_string (WAYPOINT_FONT
);
701 pango_layout_set_font_description (rv
->wplabellayout
, pfd
);
702 /* freeing PangoFontDescription, cause it has been copied by prev. call */
703 pango_font_description_free (pfd
);
705 rv
->tracks_visible
= vtl
->tracks_visible
;
706 rv
->waypoints_visible
= vtl
->waypoints_visible
;
707 rv
->drawpoints
= vtl
->drawpoints
;
708 rv
->drawstops
= vtl
->drawstops
;
709 rv
->drawelevation
= vtl
->drawelevation
;
710 rv
->elevation_factor
= vtl
->elevation_factor
;
711 rv
->drawlines
= vtl
->drawlines
;
712 rv
->stop_length
= vtl
->stop_length
;
713 rv
->line_thickness
= vtl
->line_thickness
;
714 rv
->bg_line_thickness
= vtl
->bg_line_thickness
;
715 rv
->velocity_min
= vtl
->velocity_min
;
716 rv
->velocity_max
= vtl
->velocity_max
;
717 rv
->drawlabels
= vtl
->drawlabels
;
718 rv
->drawimages
= vtl
->drawimages
;
719 rv
->image_size
= vtl
->image_size
;
720 rv
->image_alpha
= vtl
->image_alpha
;
721 rv
->image_cache_size
= vtl
->image_cache_size
;
722 rv
->has_verified_thumbnails
= TRUE
;
723 rv
->coord_mode
= vtl
->coord_mode
;
724 rv
->wp_symbol
= vtl
->wp_symbol
;
725 rv
->wp_size
= vtl
->wp_size
;
726 rv
->wp_draw_symbols
= vtl
->wp_draw_symbols
;
728 trw_layer_new_track_gcs ( rv
, VIK_VIEWPORT(vp
) );
730 rv
->waypoint_gc
= gdk_gc_new ( GTK_WIDGET(vp
)->window
);
731 gdk_gc_set_line_attributes ( rv
->waypoint_gc
, 2, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
733 rv
->waypoint_text_gc
= gdk_gc_new ( GTK_WIDGET(vp
)->window
);
734 rv
->waypoint_bg_gc
= gdk_gc_new ( GTK_WIDGET(vp
)->window
);
735 gdk_gc_copy ( rv
->waypoint_gc
, vtl
->waypoint_gc
);
736 gdk_gc_copy ( rv
->waypoint_text_gc
, vtl
->waypoint_text_gc
);
737 gdk_gc_copy ( rv
->waypoint_bg_gc
, vtl
->waypoint_bg_gc
);
739 rv
->waypoint_font
= gdk_font_load ( "-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1" );
741 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) waypoint_copy
, rv
->waypoints
);
742 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) track_copy
, rv
->tracks
);
747 static GList
* a_array_to_glist(gpointer data
[])
751 for (p
= data
; *p
; p
++)
752 gl
= g_list_prepend(gl
, *p
);
753 return(g_list_reverse(gl
));
756 VikTrwLayer
*vik_trw_layer_new ( gint drawmode
)
758 if (trw_layer_params
[PARAM_DM
].widget_data
== NULL
)
759 trw_layer_params
[PARAM_DM
].widget_data
= a_array_to_glist(params_drawmodes
);
760 if (trw_layer_params
[PARAM_WPSYM
].widget_data
== NULL
)
761 trw_layer_params
[PARAM_WPSYM
].widget_data
= a_array_to_glist(params_wpsymbols
);
763 VikTrwLayer
*rv
= VIK_TRW_LAYER ( g_object_new ( VIK_TRW_LAYER_TYPE
, NULL
) );
764 vik_layer_init ( VIK_LAYER(rv
), VIK_LAYER_TRW
);
766 rv
->waypoints
= g_hash_table_new_full ( g_str_hash
, g_str_equal
, g_free
, (GDestroyNotify
) vik_waypoint_free
);
767 rv
->tracks
= g_hash_table_new_full ( g_str_hash
, g_str_equal
, g_free
, (GDestroyNotify
) vik_track_free
);
768 rv
->tracks_iters
= g_hash_table_new_full ( g_str_hash
, g_str_equal
, NULL
, g_free
);
769 rv
->waypoints_iters
= g_hash_table_new_full ( g_str_hash
, g_str_equal
, NULL
, g_free
);
771 /* TODO: constants at top */
772 rv
->waypoints_visible
= rv
->tracks_visible
= TRUE
;
773 rv
->drawmode
= drawmode
;
774 rv
->drawpoints
= TRUE
;
775 rv
->drawstops
= FALSE
;
776 rv
->drawelevation
= FALSE
;
777 rv
->elevation_factor
= 30;
778 rv
->stop_length
= 60;
779 rv
->drawlines
= TRUE
;
780 rv
->wplabellayout
= NULL
;
781 rv
->wp_right_click_menu
= NULL
;
782 rv
->waypoint_gc
= NULL
;
783 rv
->waypoint_text_gc
= NULL
;
784 rv
->waypoint_bg_gc
= NULL
;
786 rv
->velocity_max
= 5.0;
787 rv
->velocity_min
= 0.0;
788 rv
->line_thickness
= 1;
789 rv
->bg_line_thickness
= 0;
790 rv
->current_wp
= NULL
;
791 rv
->current_wp_name
= NULL
;
792 rv
->current_track
= NULL
;
793 rv
->current_tpl
= NULL
;
794 rv
->current_tp_track_name
= NULL
;
795 rv
->moving_tp
= FALSE
;
796 rv
->moving_wp
= FALSE
;
798 rv
->magic_scissors_started
= FALSE
;
800 rv
->waypoint_rightclick
= FALSE
;
802 rv
->last_tp_track_name
= NULL
;
804 rv
->image_cache
= g_queue_new();
806 rv
->image_alpha
= 255;
807 rv
->image_cache_size
= 300;
808 rv
->drawimages
= TRUE
;
809 rv
->drawlabels
= TRUE
;
814 void vik_trw_layer_free ( VikTrwLayer
*trwlayer
)
816 g_hash_table_destroy(trwlayer
->waypoints
);
817 g_hash_table_destroy(trwlayer
->tracks
);
819 /* ODC: replace with GArray */
820 trw_layer_free_track_gcs ( trwlayer
);
822 if ( trwlayer
->wp_right_click_menu
)
823 gtk_object_sink ( GTK_OBJECT(trwlayer
->wp_right_click_menu
) );
825 if ( trwlayer
->wplabellayout
!= NULL
)
826 g_object_unref ( G_OBJECT ( trwlayer
->wplabellayout
) );
828 if ( trwlayer
->waypoint_gc
!= NULL
)
829 g_object_unref ( G_OBJECT ( trwlayer
->waypoint_gc
) );
831 if ( trwlayer
->waypoint_text_gc
!= NULL
)
832 g_object_unref ( G_OBJECT ( trwlayer
->waypoint_text_gc
) );
834 if ( trwlayer
->waypoint_bg_gc
!= NULL
)
835 g_object_unref ( G_OBJECT ( trwlayer
->waypoint_bg_gc
) );
837 if ( trwlayer
->waypoint_font
!= NULL
)
838 gdk_font_unref ( trwlayer
->waypoint_font
);
840 if ( trwlayer
->tpwin
!= NULL
)
841 gtk_widget_destroy ( GTK_WIDGET(trwlayer
->tpwin
) );
843 g_list_foreach ( trwlayer
->image_cache
->head
, (GFunc
) cached_pixbuf_free
, NULL
);
844 g_queue_free ( trwlayer
->image_cache
);
847 static void init_drawing_params ( struct DrawingParams
*dp
, VikViewport
*vp
)
850 dp
->xmpp
= vik_viewport_get_xmpp ( vp
);
851 dp
->ympp
= vik_viewport_get_ympp ( vp
);
852 dp
->width
= vik_viewport_get_width ( vp
);
853 dp
->height
= vik_viewport_get_height ( vp
);
854 dp
->center
= vik_viewport_get_center ( vp
);
855 dp
->one_zone
= vik_viewport_is_one_zone ( vp
); /* false if some other projection besides UTM */
856 dp
->lat_lon
= vik_viewport_get_coord_mode ( vp
) == VIK_COORD_LATLON
;
861 w2
= dp
->xmpp
* (dp
->width
/ 2) + 1600 / dp
->xmpp
;
862 h2
= dp
->ympp
* (dp
->height
/ 2) + 1600 / dp
->ympp
;
863 /* leniency -- for tracks. Obviously for waypoints this SHOULD be a lot smaller */
865 dp
->ce1
= dp
->center
->east_west
-w2
;
866 dp
->ce2
= dp
->center
->east_west
+w2
;
867 dp
->cn1
= dp
->center
->north_south
-h2
;
868 dp
->cn2
= dp
->center
->north_south
+h2
;
869 } else if ( dp
->lat_lon
) {
870 VikCoord upperleft
, bottomright
;
871 /* quick & dirty calculation; really want to check all corners due to lat/lon smaller at top in northern hemisphere */
872 /* this also DOESN'T WORK if you are crossing 180/-180 lon. I don't plan to in the near future... */
873 vik_viewport_screen_to_coord ( vp
, -500, -500, &upperleft
);
874 vik_viewport_screen_to_coord ( vp
, dp
->width
+500, dp
->height
+500, &bottomright
);
875 dp
->ce1
= upperleft
.east_west
;
876 dp
->ce2
= bottomright
.east_west
;
877 dp
->cn1
= bottomright
.north_south
;
878 dp
->cn2
= upperleft
.north_south
;
881 dp
->track_gc_iter
= 0;
884 static gint
calculate_velocity ( VikTrwLayer
*vtl
, VikTrackpoint
*tp1
, VikTrackpoint
*tp2
)
886 static gdouble rv
= 0;
887 if ( tp1
->has_timestamp
&& tp2
->has_timestamp
)
889 rv
= ( vik_coord_diff ( &(tp1
->coord
), &(tp2
->coord
) )
890 / (tp1
->timestamp
- tp2
->timestamp
) ) - vtl
->velocity_min
;
893 return VIK_TRW_LAYER_TRACK_GC_MIN
;
894 else if ( vtl
->velocity_min
>= vtl
->velocity_max
)
895 return VIK_TRW_LAYER_TRACK_GC_MAX
;
897 rv
*= (VIK_TRW_LAYER_TRACK_GC_RATES
/ (vtl
->velocity_max
- vtl
->velocity_min
));
899 if ( rv
>= VIK_TRW_LAYER_TRACK_GC_MAX
)
900 return VIK_TRW_LAYER_TRACK_GC_MAX
;
904 return VIK_TRW_LAYER_TRACK_GC_BLACK
;
907 void draw_utm_skip_insignia ( VikViewport
*vvp
, GdkGC
*gc
, gint x
, gint y
)
909 vik_viewport_draw_line ( vvp
, gc
, x
+5, y
, x
-5, y
);
910 vik_viewport_draw_line ( vvp
, gc
, x
, y
+5, x
, y
-5 );
911 vik_viewport_draw_line ( vvp
, gc
, x
+5, y
+5, x
-5, y
-5 );
912 vik_viewport_draw_line ( vvp
, gc
, x
+5, y
-5, x
-5, y
+5 );
915 static void trw_layer_draw_track ( const gchar
*name
, VikTrack
*track
, struct DrawingParams
*dp
, gboolean drawing_white_background
)
917 /* TODO: this function is a mess, get rid of any redundancy */
918 GList
*list
= track
->trackpoints
;
919 gboolean useoldvals
= TRUE
;
923 gboolean drawelevation
;
924 gdouble min_alt
, max_alt
, alt_diff
= 0;
926 const guint8 tp_size_reg
= 2;
927 const guint8 tp_size_cur
= 4;
930 if ( dp
->vtl
->drawelevation
)
932 /* assume if it has elevation at the beginning, it has it throughout. not ness a true good assumption */
933 if ( ( drawelevation
= vik_track_get_minmax_alt ( track
, &min_alt
, &max_alt
) ) )
934 alt_diff
= max_alt
- min_alt
;
937 if ( ! track
->visible
)
940 /* admittedly this is not an efficient way to do it because we go through the whole GC thing all over... */
941 if ( dp
->vtl
->bg_line_thickness
&& !drawing_white_background
)
942 trw_layer_draw_track ( name
, track
, dp
, TRUE
);
944 if ( drawing_white_background
)
945 drawpoints
= drawstops
= FALSE
;
947 drawpoints
= dp
->vtl
->drawpoints
;
948 drawstops
= dp
->vtl
->drawstops
;
952 int x
, y
, oldx
, oldy
;
953 VikTrackpoint
*tp
= VIK_TRACKPOINT(list
->data
);
955 tp_size
= (list
== dp
->vtl
->current_tpl
) ? tp_size_cur
: tp_size_reg
;
957 vik_viewport_coord_to_screen ( dp
->vp
, &(tp
->coord
), &x
, &y
);
959 if ( (drawpoints
) && dp
->track_gc_iter
< VIK_TRW_LAYER_TRACK_GC
)
961 GdkPoint trian
[3] = { { x
, y
-(3*tp_size
) }, { x
-(2*tp_size
), y
+(2*tp_size
) }, {x
+(2*tp_size
), y
+(2*tp_size
)} };
962 vik_viewport_draw_polygon ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), TRUE
, trian
, 3 );
968 if ( dp
->vtl
->drawmode
== DRAWMODE_ALL_BLACK
)
969 dp
->track_gc_iter
= VIK_TRW_LAYER_TRACK_GC_MAX
+ 1;
971 while ((list
= g_list_next(list
)))
973 tp
= VIK_TRACKPOINT(list
->data
);
974 tp_size
= (list
== dp
->vtl
->current_tpl
) ? tp_size_cur
: tp_size_reg
;
976 /* check some stuff -- but only if we're in UTM and there's only ONE ZONE; or lat lon */
977 if ( (!dp
->one_zone
&& !dp
->lat_lon
) || /* UTM & zones; do everything */
978 ( ((!dp
->one_zone
) || tp
->coord
.utm_zone
== dp
->center
->utm_zone
) && /* only check zones if UTM & one_zone */
979 tp
->coord
.east_west
< dp
->ce2
&& tp
->coord
.east_west
> dp
->ce1
&& /* both UTM and lat lon */
980 tp
->coord
.north_south
> dp
->cn1
&& tp
->coord
.north_south
< dp
->cn2
) )
982 vik_viewport_coord_to_screen ( dp
->vp
, &(tp
->coord
), &x
, &y
);
984 if ( drawpoints
&& ! drawing_white_background
)
987 vik_viewport_draw_rectangle ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), TRUE
, x
-tp_size
, y
-tp_size
, 2*tp_size
, 2*tp_size
);
989 vik_viewport_draw_rectangle ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), TRUE
, x
-tp_size
, y
-tp_size
, 2*tp_size
, 2*tp_size
);
992 if ( drawstops
&& VIK_TRACKPOINT(list
->next
->data
)->timestamp
- VIK_TRACKPOINT(list
->data
)->timestamp
> dp
->vtl
->stop_length
)
993 vik_viewport_draw_arc ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, 11), TRUE
, x
-(3*tp_size
), y
-(3*tp_size
), 6*tp_size
, 6*tp_size
, 0, 360*64 );
996 vik_viewport_draw_arc ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), TRUE
, x
-(2*tp_size
), y
-(2*tp_size
), 4*tp_size
, 4*tp_size
, 0, 360*64 );
999 if ((!tp
->newsegment
) && (dp
->vtl
->drawlines
))
1001 VikTrackpoint
*tp2
= VIK_TRACKPOINT(list
->prev
->data
);
1003 /* UTM only: zone check */
1004 if ( drawpoints
&& dp
->vtl
->coord_mode
== VIK_COORD_UTM
&& tp
->coord
.utm_zone
!= dp
->center
->utm_zone
)
1005 draw_utm_skip_insignia ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), x
, y
);
1007 if ( dp
->vtl
->drawmode
== DRAWMODE_BY_VELOCITY
)
1008 dp
->track_gc_iter
= calculate_velocity ( dp
->vtl
, tp
, tp2
);
1011 vik_viewport_coord_to_screen ( dp
->vp
, &(tp2
->coord
), &oldx
, &oldy
);
1013 if ( drawing_white_background
) {
1014 vik_viewport_draw_line ( dp
->vp
, dp
->vtl
->track_bg_gc
, oldx
, oldy
, x
, y
);
1018 vik_viewport_draw_line ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), oldx
, oldy
, x
, y
);
1019 if ( dp
->vtl
->drawelevation
&& list
&& list
->next
&& VIK_TRACKPOINT(list
->next
->data
)->altitude
!= VIK_DEFAULT_ALTITUDE
) {
1021 #define FIXALTITUDE(what) ((VIK_TRACKPOINT((what))->altitude-min_alt)/alt_diff*DRAW_ELEVATION_FACTOR*dp->vtl->elevation_factor/dp->xmpp)
1022 if ( list
&& list
->next
&& VIK_TRACKPOINT(list
->next
->data
)->altitude
!= VIK_DEFAULT_ALTITUDE
) {
1026 tmp
[1].y
= oldy
-FIXALTITUDE(list
->data
);
1028 tmp
[2].y
= y
-FIXALTITUDE(list
->next
->data
);
1033 if ( ((oldx
- x
) > 0 && (oldy
- y
) > 0) || ((oldx
- x
) < 0 && (oldy
- y
) < 0))
1034 tmp_gc
= GTK_WIDGET(dp
->vp
)->style
->light_gc
[3];
1036 tmp_gc
= GTK_WIDGET(dp
->vp
)->style
->dark_gc
[0];
1037 vik_viewport_draw_polygon ( dp
->vp
, tmp_gc
, TRUE
, tmp
, 4);
1039 vik_viewport_draw_line ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), oldx
, oldy
-FIXALTITUDE(list
->data
), x
, y
-FIXALTITUDE(list
->next
->data
));
1049 if (useoldvals
&& dp
->vtl
->drawlines
&& (!tp
->newsegment
))
1051 VikTrackpoint
*tp2
= VIK_TRACKPOINT(list
->prev
->data
);
1052 if ( dp
->vtl
->coord_mode
!= VIK_COORD_UTM
|| tp
->coord
.utm_zone
== dp
->center
->utm_zone
)
1054 vik_viewport_coord_to_screen ( dp
->vp
, &(tp
->coord
), &x
, &y
);
1055 if ( dp
->vtl
->drawmode
== DRAWMODE_BY_VELOCITY
)
1056 dp
->track_gc_iter
= calculate_velocity ( dp
->vtl
, tp
, tp2
);
1058 if ( drawing_white_background
)
1059 vik_viewport_draw_line ( dp
->vp
, dp
->vtl
->track_bg_gc
, oldx
, oldy
, x
, y
);
1061 vik_viewport_draw_line ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), oldx
, oldy
, x
, y
);
1065 vik_viewport_coord_to_screen ( dp
->vp
, &(tp2
->coord
), &x
, &y
);
1066 draw_utm_skip_insignia ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), x
, y
);
1073 if ( dp
->vtl
->drawmode
== DRAWMODE_BY_TRACK
)
1074 if ( ++(dp
->track_gc_iter
) >= VIK_TRW_LAYER_TRACK_GC
)
1075 dp
->track_gc_iter
= 0;
1078 /* the only reason this exists is so that trw_layer_draw_track can first call itself to draw the white track background */
1079 static void trw_layer_draw_track_cb ( const gchar
*name
, VikTrack
*track
, struct DrawingParams
*dp
)
1081 trw_layer_draw_track ( name
, track
, dp
, FALSE
);
1084 static void cached_pixbuf_free ( CachedPixbuf
*cp
)
1086 g_object_unref ( G_OBJECT(cp
->pixbuf
) );
1087 g_free ( cp
->image
);
1090 static gint
cached_pixbuf_cmp ( CachedPixbuf
*cp
, const gchar
*name
)
1092 return strcmp ( cp
->image
, name
);
1095 static void trw_layer_draw_waypoint ( const gchar
*name
, VikWaypoint
*wp
, struct DrawingParams
*dp
)
1098 if ( (!dp
->one_zone
) || ( wp
->coord
.utm_zone
== dp
->center
->utm_zone
&&
1099 wp
->coord
.east_west
< dp
->ce2
&& wp
->coord
.east_west
> dp
->ce1
&&
1100 wp
->coord
.north_south
> dp
->cn1
&& wp
->coord
.north_south
< dp
->cn2
) )
1104 vik_viewport_coord_to_screen ( dp
->vp
, &(wp
->coord
), &x
, &y
);
1106 /* if in shrunken_cache, get that. If not, get and add to shrunken_cache */
1108 if ( wp
->image
&& dp
->vtl
->drawimages
)
1110 GdkPixbuf
*pixbuf
= NULL
;
1113 if ( dp
->vtl
->image_alpha
== 0)
1116 l
= g_list_find_custom ( dp
->vtl
->image_cache
->head
, wp
->image
, (GCompareFunc
) cached_pixbuf_cmp
);
1118 pixbuf
= ((CachedPixbuf
*) l
->data
)->pixbuf
;
1121 gchar
*image
= wp
->image
;
1122 GdkPixbuf
*regularthumb
= a_thumbnails_get ( wp
->image
);
1123 if ( ! regularthumb
)
1125 regularthumb
= a_thumbnails_get_default (); /* cache one 'not yet loaded' for all thumbs not loaded */
1126 image
= "\x12\x00"; /* this shouldn't occur naturally. */
1130 CachedPixbuf
*cp
= NULL
;
1131 cp
= g_malloc ( sizeof ( CachedPixbuf
) );
1132 if ( dp
->vtl
->image_size
== 128 )
1133 cp
->pixbuf
= regularthumb
;
1136 cp
->pixbuf
= a_thumbnails_scale_pixbuf(regularthumb
, dp
->vtl
->image_size
, dp
->vtl
->image_size
);
1137 g_assert ( cp
->pixbuf
);
1138 g_object_unref ( G_OBJECT(regularthumb
) );
1140 cp
->image
= g_strdup ( image
);
1142 /* needed so 'click picture' tool knows how big the pic is; we don't
1143 * store it in cp because they may have been freed already. */
1144 wp
->image_width
= gdk_pixbuf_get_width ( cp
->pixbuf
);
1145 wp
->image_height
= gdk_pixbuf_get_height ( cp
->pixbuf
);
1147 g_queue_push_head ( dp
->vtl
->image_cache
, cp
);
1148 if ( dp
->vtl
->image_cache
->length
> dp
->vtl
->image_cache_size
)
1149 cached_pixbuf_free ( g_queue_pop_tail ( dp
->vtl
->image_cache
) );
1151 pixbuf
= cp
->pixbuf
;
1155 pixbuf
= a_thumbnails_get_default (); /* thumbnail not yet loaded */
1161 w
= gdk_pixbuf_get_width ( pixbuf
);
1162 h
= gdk_pixbuf_get_height ( pixbuf
);
1164 if ( x
+(w
/2) > 0 && y
+(h
/2) > 0 && x
-(w
/2) < dp
->width
&& y
-(h
/2) < dp
->height
) /* always draw within boundaries */
1166 if ( dp
->vtl
->image_alpha
== 255 )
1167 vik_viewport_draw_pixbuf ( dp
->vp
, pixbuf
, 0, 0, x
- (w
/2), y
- (h
/2), w
, h
);
1169 vik_viewport_draw_pixbuf_with_alpha ( dp
->vp
, pixbuf
, dp
->vtl
->image_alpha
, 0, 0, x
- (w
/2), y
- (h
/2), w
, h
);
1171 return; /* if failed to draw picture, default to drawing regular waypoint (below) */
1175 /* DRAW ACTUAL DOT */
1176 if ( dp
->vtl
->wp_draw_symbols
&& wp
->symbol
&& (sym
= a_get_wp_sym(wp
->symbol
)) ) {
1177 vik_viewport_draw_pixbuf ( dp
->vp
, sym
, 0, 0, x
- gdk_pixbuf_get_width(sym
)/2, y
- gdk_pixbuf_get_height(sym
)/2, -1, -1 );
1179 else if ( wp
== dp
->vtl
->current_wp
) {
1180 switch ( dp
->vtl
->wp_symbol
) {
1181 case WP_SYMBOL_FILLED_SQUARE
: vik_viewport_draw_rectangle ( dp
->vp
, dp
->vtl
->waypoint_gc
, TRUE
, x
- (dp
->vtl
->wp_size
), y
- (dp
->vtl
->wp_size
), dp
->vtl
->wp_size
*2, dp
->vtl
->wp_size
*2 ); break;
1182 case WP_SYMBOL_SQUARE
: vik_viewport_draw_rectangle ( dp
->vp
, dp
->vtl
->waypoint_gc
, FALSE
, x
- (dp
->vtl
->wp_size
), y
- (dp
->vtl
->wp_size
), dp
->vtl
->wp_size
*2, dp
->vtl
->wp_size
*2 ); break;
1183 case WP_SYMBOL_CIRCLE
: vik_viewport_draw_arc ( dp
->vp
, dp
->vtl
->waypoint_gc
, TRUE
, x
- dp
->vtl
->wp_size
, y
- dp
->vtl
->wp_size
, dp
->vtl
->wp_size
, dp
->vtl
->wp_size
, 0, 360*64 ); break;
1184 case WP_SYMBOL_X
: vik_viewport_draw_line ( dp
->vp
, dp
->vtl
->waypoint_gc
, x
- dp
->vtl
->wp_size
*2, y
- dp
->vtl
->wp_size
*2, x
+ dp
->vtl
->wp_size
*2, y
+ dp
->vtl
->wp_size
*2 );
1185 vik_viewport_draw_line ( dp
->vp
, dp
->vtl
->waypoint_gc
, x
- dp
->vtl
->wp_size
*2, y
+ dp
->vtl
->wp_size
*2, x
+ dp
->vtl
->wp_size
*2, y
- dp
->vtl
->wp_size
*2 );
1189 switch ( dp
->vtl
->wp_symbol
) {
1190 case WP_SYMBOL_FILLED_SQUARE
: vik_viewport_draw_rectangle ( dp
->vp
, dp
->vtl
->waypoint_gc
, TRUE
, x
- dp
->vtl
->wp_size
/2, y
- dp
->vtl
->wp_size
/2, dp
->vtl
->wp_size
, dp
->vtl
->wp_size
); break;
1191 case WP_SYMBOL_SQUARE
: vik_viewport_draw_rectangle ( dp
->vp
, dp
->vtl
->waypoint_gc
, FALSE
, x
- dp
->vtl
->wp_size
/2, y
- dp
->vtl
->wp_size
/2, dp
->vtl
->wp_size
, dp
->vtl
->wp_size
); break;
1192 case WP_SYMBOL_CIRCLE
: vik_viewport_draw_arc ( dp
->vp
, dp
->vtl
->waypoint_gc
, TRUE
, x
-dp
->vtl
->wp_size
/2, y
-dp
->vtl
->wp_size
/2, dp
->vtl
->wp_size
, dp
->vtl
->wp_size
, 0, 360*64 ); break;
1193 case WP_SYMBOL_X
: vik_viewport_draw_line ( dp
->vp
, dp
->vtl
->waypoint_gc
, x
-dp
->vtl
->wp_size
, y
-dp
->vtl
->wp_size
, x
+dp
->vtl
->wp_size
, y
+dp
->vtl
->wp_size
);
1194 vik_viewport_draw_line ( dp
->vp
, dp
->vtl
->waypoint_gc
, x
-dp
->vtl
->wp_size
, y
+dp
->vtl
->wp_size
, x
+dp
->vtl
->wp_size
, y
-dp
->vtl
->wp_size
); break;
1198 if ( dp
->vtl
->drawlabels
)
1200 /* thanks to the GPSDrive people (Fritz Ganter et al.) for hints on this part ... yah, I'm too lazy to study documentation */
1202 pango_layout_set_text ( dp
->vtl
->wplabellayout
, name
, -1 );
1203 pango_layout_get_pixel_size ( dp
->vtl
->wplabellayout
, &width
, &height
);
1204 vik_viewport_draw_rectangle ( dp
->vp
, dp
->vtl
->waypoint_bg_gc
, TRUE
, x
+ dp
->vtl
->wp_size
- 1, y
-1,width
+1,height
-1);
1205 vik_viewport_draw_layout ( dp
->vp
, dp
->vtl
->waypoint_text_gc
, x
+ dp
->vtl
->wp_size
, y
, dp
->vtl
->wplabellayout
);
1210 void vik_trw_layer_draw ( VikTrwLayer
*l
, gpointer data
)
1212 static struct DrawingParams dp
;
1213 g_assert ( l
!= NULL
);
1215 init_drawing_params ( &dp
, VIK_VIEWPORT(data
) );
1218 if ( l
->tracks_visible
)
1219 g_hash_table_foreach ( l
->tracks
, (GHFunc
) trw_layer_draw_track_cb
, &dp
);
1221 if (l
->waypoints_visible
)
1222 g_hash_table_foreach ( l
->waypoints
, (GHFunc
) trw_layer_draw_waypoint
, &dp
);
1225 static void trw_layer_free_track_gcs ( VikTrwLayer
*vtl
)
1228 if ( vtl
->track_bg_gc
)
1230 g_object_unref ( vtl
->track_bg_gc
);
1231 vtl
->track_bg_gc
= NULL
;
1234 if ( ! vtl
->track_gc
)
1236 for ( i
= vtl
->track_gc
->len
- 1; i
>= 0; i
-- )
1237 g_object_unref ( g_array_index ( vtl
->track_gc
, GObject
*, i
) );
1238 g_array_free ( vtl
->track_gc
, TRUE
);
1239 vtl
->track_gc
= NULL
;
1242 static void trw_layer_new_track_gcs ( VikTrwLayer
*vtl
, VikViewport
*vp
)
1244 GdkGC
*gc
[ VIK_TRW_LAYER_TRACK_GC
];
1245 gint width
= vtl
->line_thickness
;
1247 if ( vtl
->track_gc
)
1248 trw_layer_free_track_gcs ( vtl
);
1250 if ( vtl
->track_bg_gc
)
1251 g_object_unref ( vtl
->track_bg_gc
);
1252 vtl
->track_bg_gc
= vik_viewport_new_gc ( vp
, "#FFFFFF", width
+ vtl
->bg_line_thickness
);
1254 vtl
->track_gc
= g_array_sized_new ( FALSE
, FALSE
, sizeof ( GdkGC
* ), VIK_TRW_LAYER_TRACK_GC
);
1256 gc
[0] = vik_viewport_new_gc ( vp
, "#2d870a", width
); /* below range */
1258 gc
[1] = vik_viewport_new_gc ( vp
, "#0a8742", width
);
1259 gc
[2] = vik_viewport_new_gc ( vp
, "#0a8783", width
);
1260 gc
[3] = vik_viewport_new_gc ( vp
, "#0a4d87", width
);
1261 gc
[4] = vik_viewport_new_gc ( vp
, "#05469f", width
);
1262 gc
[5] = vik_viewport_new_gc ( vp
, "#1b059f", width
);
1263 gc
[6] = vik_viewport_new_gc ( vp
, "#2d059f", width
);
1264 gc
[7] = vik_viewport_new_gc ( vp
, "#4a059f", width
);
1265 gc
[8] = vik_viewport_new_gc ( vp
, "#84059f", width
);
1266 gc
[9] = vik_viewport_new_gc ( vp
, "#96059f", width
);
1267 gc
[10] = vik_viewport_new_gc ( vp
, "#f22ef2", width
);
1269 gc
[11] = vik_viewport_new_gc ( vp
, "#ff0000", width
); /* above range */
1271 gc
[12] = vik_viewport_new_gc ( vp
, "#000000", width
); /* black / no speed data */
1273 g_array_append_vals ( vtl
->track_gc
, gc
, VIK_TRW_LAYER_TRACK_GC
);
1276 VikTrwLayer
*vik_trw_layer_create ( VikViewport
*vp
)
1278 VikTrwLayer
*rv
= vik_trw_layer_new ( 0 );
1279 PangoFontDescription
*pfd
;
1280 rv
->wplabellayout
= gtk_widget_create_pango_layout (GTK_WIDGET(vp
), NULL
);
1281 pfd
= pango_font_description_from_string (WAYPOINT_FONT
);
1282 pango_layout_set_font_description (rv
->wplabellayout
, pfd
);
1283 /* freeing PangoFontDescription, cause it has been copied by prev. call */
1284 pango_font_description_free (pfd
);
1286 vik_layer_rename ( VIK_LAYER(rv
), vik_trw_layer_interface
.name
);
1288 trw_layer_new_track_gcs ( rv
, vp
);
1290 rv
->waypoint_gc
= vik_viewport_new_gc ( vp
, "#000000", 2 );
1291 rv
->waypoint_text_gc
= vik_viewport_new_gc ( vp
, "#FFFFFF", 1 );
1292 rv
->waypoint_bg_gc
= vik_viewport_new_gc ( vp
, "#8383C4", 1 );
1293 gdk_gc_set_function ( rv
->waypoint_bg_gc
, GDK_AND
);
1295 rv
->waypoint_font
= gdk_font_load ( "-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1" );
1297 rv
->has_verified_thumbnails
= FALSE
;
1298 rv
->wp_symbol
= WP_SYMBOL_FILLED_SQUARE
;
1300 rv
->wp_draw_symbols
= TRUE
;
1302 rv
->coord_mode
= vik_viewport_get_coord_mode ( vp
);
1304 rv
->menu_selection
= vik_layer_get_interface(VIK_LAYER(rv
)->type
)->menu_items_selection
;
1309 static void trw_layer_realize_track ( gchar
*name
, VikTrack
*track
, gpointer pass_along
[4] )
1311 GtkTreeIter
*new_iter
= g_malloc(sizeof(GtkTreeIter
));
1313 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1314 vik_treeview_add_sublayer_alphabetized ( (VikTreeview
*) pass_along
[3], (GtkTreeIter
*) pass_along
[0], (GtkTreeIter
*) pass_along
[1], name
, pass_along
[2], name
, (gint
) pass_along
[4], NULL
, TRUE
, TRUE
);
1316 vik_treeview_add_sublayer ( (VikTreeview
*) pass_along
[3], (GtkTreeIter
*) pass_along
[0], (GtkTreeIter
*) pass_along
[1], name
, pass_along
[2], name
, (gint
) pass_along
[4], NULL
, TRUE
, TRUE
);
1319 *new_iter
= *((GtkTreeIter
*) pass_along
[1]);
1320 g_hash_table_insert ( VIK_TRW_LAYER(pass_along
[2])->tracks_iters
, name
, new_iter
);
1322 if ( ! track
->visible
)
1323 vik_treeview_item_set_visible ( (VikTreeview
*) pass_along
[3], (GtkTreeIter
*) pass_along
[1], FALSE
);
1326 static void trw_layer_realize_waypoint ( gchar
*name
, VikWaypoint
*wp
, gpointer pass_along
[4] )
1328 GtkTreeIter
*new_iter
= g_malloc(sizeof(GtkTreeIter
));
1329 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1330 vik_treeview_add_sublayer_alphabetized ( (VikTreeview
*) pass_along
[3], (GtkTreeIter
*) pass_along
[0], (GtkTreeIter
*) pass_along
[1], name
, pass_along
[2], name
, (gint
) pass_along
[4], NULL
, TRUE
, TRUE
);
1332 vik_treeview_add_sublayer ( (VikTreeview
*) pass_along
[3], (GtkTreeIter
*) pass_along
[0], (GtkTreeIter
*) pass_along
[1], name
, pass_along
[2], name
, (gint
) pass_along
[4], NULL
, TRUE
, TRUE
);
1335 *new_iter
= *((GtkTreeIter
*) pass_along
[1]);
1336 g_hash_table_insert ( VIK_TRW_LAYER(pass_along
[2])->waypoints_iters
, name
, new_iter
);
1338 if ( ! wp
->visible
)
1339 vik_treeview_item_set_visible ( (VikTreeview
*) pass_along
[3], (GtkTreeIter
*) pass_along
[1], FALSE
);
1343 void vik_trw_layer_realize ( VikTrwLayer
*vtl
, VikTreeview
*vt
, GtkTreeIter
*layer_iter
)
1346 gpointer pass_along
[5] = { &(vtl
->tracks_iter
), &iter2
, vtl
, vt
, (gpointer
) VIK_TRW_LAYER_SUBLAYER_TRACK
};
1348 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1349 vik_treeview_add_sublayer_alphabetized ( (VikTreeview
*) vt
, layer_iter
, &(vtl
->tracks_iter
), "Tracks", vtl
, NULL
, VIK_TRW_LAYER_SUBLAYER_TRACKS
, NULL
, TRUE
, FALSE
);
1351 vik_treeview_add_sublayer ( (VikTreeview
*) vt
, layer_iter
, &(vtl
->tracks_iter
), "Tracks", vtl
, NULL
, VIK_TRW_LAYER_SUBLAYER_TRACKS
, NULL
, TRUE
, FALSE
);
1353 if ( ! vtl
->tracks_visible
)
1354 vik_treeview_item_set_visible ( (VikTreeview
*) vt
, &(vtl
->tracks_iter
), FALSE
);
1356 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) trw_layer_realize_track
, pass_along
);
1358 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1359 vik_treeview_add_sublayer_alphabetized ( (VikTreeview
*) vt
, layer_iter
, &(vtl
->waypoints_iter
), "Waypoints", vtl
, NULL
, VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
, NULL
, TRUE
, FALSE
);
1361 vik_treeview_add_sublayer ( (VikTreeview
*) vt
, layer_iter
, &(vtl
->waypoints_iter
), "Waypoints", vtl
, NULL
, VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
, NULL
, TRUE
, FALSE
);
1364 if ( ! vtl
->waypoints_visible
)
1365 vik_treeview_item_set_visible ( (VikTreeview
*) vt
, &(vtl
->waypoints_iter
), FALSE
);
1367 pass_along
[0] = &(vtl
->waypoints_iter
);
1368 pass_along
[4] = (gpointer
) VIK_TRW_LAYER_SUBLAYER_WAYPOINT
;
1370 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) trw_layer_realize_waypoint
, pass_along
);
1374 gboolean
vik_trw_layer_sublayer_toggle_visible ( VikTrwLayer
*l
, gint subtype
, gpointer sublayer
)
1378 case VIK_TRW_LAYER_SUBLAYER_TRACKS
: return (l
->tracks_visible
^= 1);
1379 case VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
: return (l
->waypoints_visible
^= 1);
1380 case VIK_TRW_LAYER_SUBLAYER_TRACK
:
1382 VikTrack
*t
= g_hash_table_lookup ( l
->tracks
, sublayer
);
1384 return (t
->visible
^= 1);
1388 case VIK_TRW_LAYER_SUBLAYER_WAYPOINT
:
1390 VikWaypoint
*t
= g_hash_table_lookup ( l
->waypoints
, sublayer
);
1392 return (t
->visible
^= 1);
1400 GHashTable
*vik_trw_layer_get_tracks ( VikTrwLayer
*l
)
1405 GHashTable
*vik_trw_layer_get_waypoints ( VikTrwLayer
*l
)
1407 return l
->waypoints
;
1410 static void trw_layer_find_maxmin_waypoints ( const gchar
*name
, const VikWaypoint
*w
, struct LatLon maxmin
[2] )
1412 static VikCoord fixme
;
1413 vik_coord_copy_convert ( &(w
->coord
), VIK_COORD_LATLON
, &fixme
);
1414 if ( VIK_LATLON(&fixme
)->lat
> maxmin
[0].lat
|| maxmin
[0].lat
== 0.0 )
1415 maxmin
[0].lat
= VIK_LATLON(&fixme
)->lat
;
1416 if ( VIK_LATLON(&fixme
)->lat
< maxmin
[1].lat
|| maxmin
[1].lat
== 0.0 )
1417 maxmin
[1].lat
= VIK_LATLON(&fixme
)->lat
;
1418 if ( VIK_LATLON(&fixme
)->lon
> maxmin
[0].lon
|| maxmin
[0].lon
== 0.0 )
1419 maxmin
[0].lon
= VIK_LATLON(&fixme
)->lon
;
1420 if ( VIK_LATLON(&fixme
)->lon
< maxmin
[1].lon
|| maxmin
[1].lon
== 0.0 )
1421 maxmin
[1].lon
= VIK_LATLON(&fixme
)->lon
;
1424 static void trw_layer_find_maxmin_tracks ( const gchar
*name
, GList
**t
, struct LatLon maxmin
[2] )
1427 static VikCoord fixme
;
1431 vik_coord_copy_convert ( &(VIK_TRACKPOINT(tr
->data
)->coord
), VIK_COORD_LATLON
, &fixme
);
1432 if ( VIK_LATLON(&fixme
)->lat
> maxmin
[0].lat
|| maxmin
[0].lat
== 0.0 )
1433 maxmin
[0].lat
= VIK_LATLON(&fixme
)->lat
;
1434 if ( VIK_LATLON(&fixme
)->lat
< maxmin
[1].lat
|| maxmin
[1].lat
== 0.0 )
1435 maxmin
[1].lat
= VIK_LATLON(&fixme
)->lat
;
1436 if ( VIK_LATLON(&fixme
)->lon
> maxmin
[0].lon
|| maxmin
[0].lon
== 0.0 )
1437 maxmin
[0].lon
= VIK_LATLON(&fixme
)->lon
;
1438 if ( VIK_LATLON(&fixme
)->lon
< maxmin
[1].lon
|| maxmin
[1].lon
== 0.0 )
1439 maxmin
[1].lon
= VIK_LATLON(&fixme
)->lon
;
1445 gboolean
vik_trw_layer_find_center ( VikTrwLayer
*vtl
, VikCoord
*dest
)
1447 /* TODO: what if there's only one waypoint @ 0,0, it will think nothing found. like I don't have more important things to worry about... */
1448 struct LatLon maxmin
[2] = { {0.0,0.0}, {0.0,0.0} };
1449 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) trw_layer_find_maxmin_waypoints
, maxmin
);
1450 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) trw_layer_find_maxmin_tracks
, maxmin
);
1451 if (maxmin
[0].lat
== 0.0 && maxmin
[0].lon
== 0.0 && maxmin
[1].lat
== 0.0 && maxmin
[1].lon
== 0.0)
1455 struct LatLon average
= { (maxmin
[0].lat
+maxmin
[1].lat
)/2, (maxmin
[0].lon
+maxmin
[1].lon
)/2 };
1456 vik_coord_load_from_latlon ( dest
, vtl
->coord_mode
, &average
);
1461 static void trw_layer_centerize ( gpointer layer_and_vlp
[2] )
1464 if ( vik_trw_layer_find_center ( VIK_TRW_LAYER(layer_and_vlp
[0]), &coord
) )
1465 goto_coord ( VIK_LAYERS_PANEL(layer_and_vlp
[1]), &coord
);
1467 a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_LAYER(layer_and_vlp
[0]), "This layer has no waypoints or trackpoints." );
1470 static void trw_layer_export ( gpointer layer_and_vlp
[2], guint file_type
)
1472 GtkWidget
*file_selector
;
1474 gboolean failed
= FALSE
;
1475 file_selector
= gtk_file_selection_new ("Export Layer");
1477 while ( gtk_dialog_run ( GTK_DIALOG(file_selector
) ) == GTK_RESPONSE_OK
)
1479 fn
= gtk_file_selection_get_filename (GTK_FILE_SELECTION(file_selector
) );
1480 if ( access ( fn
, F_OK
) != 0 )
1482 gtk_widget_hide ( file_selector
);
1483 failed
= ! a_file_export ( VIK_TRW_LAYER(layer_and_vlp
[0]), fn
, file_type
);
1488 if ( a_dialog_overwrite ( VIK_GTK_WINDOW_FROM_LAYER(layer_and_vlp
[0]), "The file \"%s\" exists, do you wish to overwrite it?", a_file_basename ( fn
) ) )
1490 gtk_widget_hide ( file_selector
);
1491 failed
= ! a_file_export ( VIK_TRW_LAYER(layer_and_vlp
[0]), fn
, file_type
);
1496 gtk_widget_destroy ( file_selector
);
1498 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(layer_and_vlp
[0]), "The filename you requested could not be opened for writing." );
1501 static void trw_layer_export_gpspoint ( gpointer layer_and_vlp
[2] )
1503 trw_layer_export ( layer_and_vlp
, FILE_TYPE_GPSPOINT
);
1506 static void trw_layer_export_gpsmapper ( gpointer layer_and_vlp
[2] )
1508 trw_layer_export ( layer_and_vlp
, FILE_TYPE_GPSMAPPER
);
1511 static void trw_layer_export_gpx ( gpointer layer_and_vlp
[2] )
1513 trw_layer_export ( layer_and_vlp
, FILE_TYPE_GPX
);
1516 static void trw_layer_goto_wp ( gpointer layer_and_vlp
[2] )
1518 GHashTable
*wps
= vik_trw_layer_get_waypoints ( VIK_TRW_LAYER(layer_and_vlp
[0]) );
1519 GtkWidget
*dia
= gtk_dialog_new_with_buttons ("Create",
1520 VIK_GTK_WINDOW_FROM_LAYER(layer_and_vlp
[0]),
1521 GTK_DIALOG_MODAL
| GTK_DIALOG_DESTROY_WITH_PARENT
,
1523 GTK_RESPONSE_REJECT
,
1525 GTK_RESPONSE_ACCEPT
,
1528 GtkWidget
*label
, *entry
;
1529 label
= gtk_label_new("Waypoint Name:");
1530 entry
= gtk_entry_new();
1532 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia
)->vbox
), label
, FALSE
, FALSE
, 0);
1533 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia
)->vbox
), entry
, FALSE
, FALSE
, 0);
1534 gtk_widget_show_all ( label
);
1535 gtk_widget_show_all ( entry
);
1537 while ( gtk_dialog_run ( GTK_DIALOG(dia
) ) == GTK_RESPONSE_ACCEPT
)
1540 gchar
*upname
= g_strdup(gtk_entry_get_text(GTK_ENTRY(entry
)));
1543 for ( i
= strlen(upname
)-1; i
>= 0; i
-- )
1544 upname
[i
] = toupper(upname
[i
]);
1546 wp
= g_hash_table_lookup ( wps
, upname
);
1549 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(layer_and_vlp
[0]), "Waypoint not found in this layer." );
1552 vik_viewport_set_center_coord ( vik_layers_panel_get_viewport(VIK_LAYERS_PANEL(layer_and_vlp
[1])), &(wp
->coord
) );
1553 vik_layers_panel_emit_update ( VIK_LAYERS_PANEL(layer_and_vlp
[1]) );
1554 vik_treeview_select_iter ( VIK_LAYER(layer_and_vlp
[0])->vt
, g_hash_table_lookup ( VIK_TRW_LAYER(layer_and_vlp
[0])->waypoints_iters
, upname
) );
1561 gtk_widget_destroy ( dia
);
1564 gboolean
vik_trw_layer_new_waypoint ( VikTrwLayer
*vtl
, GtkWindow
*w
, const VikCoord
*def_coord
)
1567 VikWaypoint
*wp
= vik_waypoint_new();
1568 wp
->coord
= *def_coord
;
1569 wp
->altitude
= VIK_DEFAULT_ALTITUDE
;
1571 if ( a_dialog_new_waypoint ( w
, &name
, wp
, vik_trw_layer_get_waypoints ( vtl
), vtl
->coord_mode
) )
1574 vik_trw_layer_add_waypoint ( vtl
, name
, wp
);
1577 vik_waypoint_free(wp
);
1581 static void trw_layer_new_wp ( gpointer lav
[2] )
1583 VikTrwLayer
*vtl
= VIK_TRW_LAYER(lav
[0]);
1584 VikLayersPanel
*vlp
= VIK_LAYERS_PANEL(lav
[1]);
1585 /* TODO longone: okay, if layer above (aggregate) is invisible but vtl->visible is true, this redraws for no reason.
1586 instead return true if you want to update. */
1587 if ( vik_trw_layer_new_waypoint ( vtl
, VIK_GTK_WINDOW_FROM_LAYER(vtl
), vik_viewport_get_center(vik_layers_panel_get_viewport(vlp
))) && VIK_LAYER(vtl
)->visible
)
1588 vik_layers_panel_emit_update ( vlp
);
1591 void vik_trw_layer_add_menu_items ( VikTrwLayer
*vtl
, GtkMenu
*menu
, gpointer vlp
)
1593 static gpointer pass_along
[2];
1595 GtkWidget
*export_submenu
;
1596 pass_along
[0] = vtl
;
1597 pass_along
[1] = vlp
;
1599 item
= gtk_menu_item_new();
1600 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
1601 gtk_widget_show ( item
);
1603 item
= gtk_menu_item_new_with_label ( "Goto Center of Layer" );
1604 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_centerize
), pass_along
);
1605 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
1606 gtk_widget_show ( item
);
1608 item
= gtk_menu_item_new_with_label ( "Goto Waypoint" );
1609 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_goto_wp
), pass_along
);
1610 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
1611 gtk_widget_show ( item
);
1613 export_submenu
= gtk_menu_new ();
1614 item
= gtk_menu_item_new_with_label ( "Export layer" );
1615 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
1616 gtk_widget_show ( item
);
1617 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item
), export_submenu
);
1619 item
= gtk_menu_item_new_with_label ( "Export as GPSPoint" );
1620 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_export_gpspoint
), pass_along
);
1621 gtk_menu_shell_append (GTK_MENU_SHELL (export_submenu
), item
);
1622 gtk_widget_show ( item
);
1624 item
= gtk_menu_item_new_with_label ( "Export as GPSMapper" );
1625 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_export_gpsmapper
), pass_along
);
1626 gtk_menu_shell_append (GTK_MENU_SHELL (export_submenu
), item
);
1627 gtk_widget_show ( item
);
1629 item
= gtk_menu_item_new_with_label ( "Export as GPX" );
1630 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_export_gpx
), pass_along
);
1631 gtk_menu_shell_append (GTK_MENU_SHELL (export_submenu
), item
);
1632 gtk_widget_show ( item
);
1634 item
= gtk_menu_item_new_with_label ( "New Waypoint" );
1635 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_new_wp
), pass_along
);
1636 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
1637 gtk_widget_show ( item
);
1639 #ifdef VIK_CONFIG_OPENSTREETMAP
1640 item
= gtk_menu_item_new_with_label ( "Upload to OSM" );
1641 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(osm_traces_upload_cb
), pass_along
);
1642 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
1643 gtk_widget_show ( item
);
1647 void vik_trw_layer_add_waypoint ( VikTrwLayer
*vtl
, gchar
*name
, VikWaypoint
*wp
)
1649 if ( VIK_LAYER(vtl
)->realized
)
1651 VikWaypoint
*oldwp
= VIK_WAYPOINT ( g_hash_table_lookup ( vtl
->waypoints
, name
) );
1653 wp
->visible
= oldwp
->visible
; /* same visibility so we don't have to update viktreeview */
1656 GtkTreeIter
*iter
= g_malloc(sizeof(GtkTreeIter
));
1657 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1658 vik_treeview_add_sublayer_alphabetized ( VIK_LAYER(vtl
)->vt
, &(vtl
->waypoints_iter
), iter
, name
, vtl
, name
, VIK_TRW_LAYER_SUBLAYER_WAYPOINT
, NULL
, TRUE
, TRUE
);
1660 vik_treeview_add_sublayer ( VIK_LAYER(vtl
)->vt
, &(vtl
->waypoints_iter
), iter
, name
, vtl
, name
, VIK_TRW_LAYER_SUBLAYER_WAYPOINT
, NULL
, TRUE
, TRUE
);
1662 vik_treeview_select_iter ( VIK_LAYER(vtl
)->vt
, iter
);
1663 g_hash_table_insert ( vtl
->waypoints_iters
, name
, iter
);
1670 g_hash_table_insert ( vtl
->waypoints
, name
, wp
);
1674 void vik_trw_layer_add_track ( VikTrwLayer
*vtl
, gchar
*name
, VikTrack
*t
)
1676 if ( VIK_LAYER(vtl
)->realized
)
1678 VikTrack
*oldt
= VIK_TRACK ( g_hash_table_lookup ( vtl
->tracks
, name
) );
1680 t
->visible
= oldt
->visible
; /* same visibility so we don't have to update viktreeview */
1683 GtkTreeIter
*iter
= g_malloc(sizeof(GtkTreeIter
));
1684 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1685 vik_treeview_add_sublayer_alphabetized ( VIK_LAYER(vtl
)->vt
, &(vtl
->tracks_iter
), iter
, name
, vtl
, name
, VIK_TRW_LAYER_SUBLAYER_TRACK
, NULL
, TRUE
, TRUE
);
1687 vik_treeview_add_sublayer ( VIK_LAYER(vtl
)->vt
, &(vtl
->tracks_iter
), iter
, name
, vtl
, name
, VIK_TRW_LAYER_SUBLAYER_TRACK
, NULL
, TRUE
, TRUE
);
1689 vik_treeview_select_iter ( VIK_LAYER(vtl
)->vt
, iter
);
1690 g_hash_table_insert ( vtl
->tracks_iters
, name
, iter
);
1691 /* t->visible = TRUE; */
1695 ; /* t->visible = TRUE; // this is now used by file input functions */
1697 g_hash_table_insert ( vtl
->tracks
, name
, t
);
1701 static gboolean
uppercase_exists_in_hash ( GHashTable
*hash
, const gchar
*str
)
1703 gchar
*upp
= g_strdup ( str
);
1708 *tmp
= toupper(*tmp
);
1711 rv
= g_hash_table_lookup ( hash
, upp
) ? TRUE
: FALSE
;
1716 /* to be called whenever a track has been deleted or may have been changed. */
1717 static void trw_layer_cancel_tps_of_track ( VikTrwLayer
*vtl
, const gchar
*trk_name
)
1719 if (vtl
->current_tp_track_name
&& g_strcasecmp(trk_name
, vtl
->current_tp_track_name
) == 0)
1720 trw_layer_cancel_current_tp ( vtl
, FALSE
);
1721 else if (vtl
->last_tp_track_name
&& g_strcasecmp(trk_name
, vtl
->last_tp_track_name
) == 0)
1722 trw_layer_cancel_last_tp ( vtl
);
1725 static gchar
*get_new_unique_sublayer_name (VikTrwLayer
*vtl
, gint sublayer_type
, const gchar
*name
)
1728 gchar
*newname
= g_strdup(name
);
1729 while ((sublayer_type
== VIK_TRW_LAYER_SUBLAYER_TRACK
) ?
1730 (void *)vik_trw_layer_get_track(vtl
, newname
) : (void *)vik_trw_layer_get_waypoint(vtl
, newname
)) {
1731 gchar
*new_newname
= g_strdup_printf("%s#%d", name
, i
);
1733 newname
= new_newname
;
1739 void vik_trw_layer_filein_add_waypoint ( VikTrwLayer
*vtl
, gchar
*name
, VikWaypoint
*wp
)
1741 vik_trw_layer_add_waypoint ( vtl
,
1742 get_new_unique_sublayer_name(vtl
, VIK_TRW_LAYER_SUBLAYER_WAYPOINT
, name
),
1745 void vik_trw_layer_filein_add_track ( VikTrwLayer
*vtl
, gchar
*name
, VikTrack
*tr
)
1747 vik_trw_layer_add_track ( vtl
,
1748 get_new_unique_sublayer_name(vtl
, VIK_TRW_LAYER_SUBLAYER_TRACK
, name
),
1752 static void trw_layer_enum_item ( const gchar
*name
, GList
**tr
, GList
**l
)
1754 *l
= g_list_append(*l
, (gpointer
)name
);
1757 static void trw_layer_move_item ( VikTrwLayer
*vtl_src
, VikTrwLayer
*vtl_dest
, gchar
*name
, gint type
)
1759 gchar
*newname
= get_new_unique_sublayer_name(vtl_dest
, type
, name
);
1760 if (type
== VIK_TRW_LAYER_SUBLAYER_TRACK
) {
1762 t
= vik_track_copy(vik_trw_layer_get_track(vtl_src
, name
));
1763 vik_trw_layer_delete_track(vtl_src
, name
);
1764 vik_trw_layer_add_track(vtl_dest
, newname
, t
);
1766 if (type
==VIK_TRW_LAYER_SUBLAYER_WAYPOINT
) {
1768 w
= vik_waypoint_copy(vik_trw_layer_get_waypoint(vtl_src
, name
));
1769 vik_trw_layer_delete_waypoint(vtl_src
, name
);
1770 vik_trw_layer_add_waypoint(vtl_dest
, newname
, w
);
1774 static void trw_layer_drag_drop_request ( VikTrwLayer
*vtl_src
, VikTrwLayer
*vtl_dest
, GtkTreeIter
*src_item_iter
, GtkTreePath
*dest_path
)
1776 VikTreeview
*vt
= VIK_LAYER(vtl_src
)->vt
;
1777 gint type
= vik_treeview_item_get_data(vt
, src_item_iter
);
1779 if (!vik_treeview_item_get_pointer(vt
, src_item_iter
)) {
1780 GList
*items
= NULL
;
1783 if (type
==VIK_TRW_LAYER_SUBLAYER_TRACKS
) {
1784 g_hash_table_foreach ( vtl_src
->tracks
, (GHFunc
)trw_layer_enum_item
, &items
);
1786 if (type
==VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
) {
1787 g_hash_table_foreach ( vtl_src
->waypoints
, (GHFunc
)trw_layer_enum_item
, &items
);
1792 if (type
==VIK_TRW_LAYER_SUBLAYER_TRACKS
) {
1793 trw_layer_move_item ( vtl_src
, vtl_dest
, iter
->data
, VIK_TRW_LAYER_SUBLAYER_TRACK
);
1795 trw_layer_move_item ( vtl_src
, vtl_dest
, iter
->data
, VIK_TRW_LAYER_SUBLAYER_WAYPOINT
);
1802 gchar
*name
= vik_treeview_item_get_pointer(vt
, src_item_iter
);
1803 trw_layer_move_item(vtl_src
, vtl_dest
, name
, type
);
1808 gboolean
vik_trw_layer_delete_track ( VikTrwLayer
*vtl
, const gchar
*trk_name
)
1810 VikTrack
*t
= g_hash_table_lookup ( vtl
->tracks
, trk_name
);
1811 gboolean was_visible
= FALSE
;
1815 was_visible
= t
->visible
;
1816 if ( t
== vtl
->current_track
)
1817 vtl
->current_track
= NULL
;
1819 /* could be current_tp, so we have to check */
1820 trw_layer_cancel_tps_of_track ( vtl
, trk_name
);
1822 g_assert ( ( it
= g_hash_table_lookup ( vtl
->tracks_iters
, trk_name
) ) );
1823 vik_treeview_item_delete ( VIK_LAYER(vtl
)->vt
, it
);
1824 g_hash_table_remove ( vtl
->tracks_iters
, trk_name
);
1826 /* do this last because trk_name may be pointing to actual orig key */
1827 g_hash_table_remove ( vtl
->tracks
, trk_name
);
1832 gboolean
vik_trw_layer_delete_waypoint ( VikTrwLayer
*vtl
, const gchar
*wp_name
)
1834 gboolean was_visible
= FALSE
;
1837 wp
= g_hash_table_lookup ( vtl
->waypoints
, wp_name
);
1841 if ( wp
== vtl
->current_wp
) {
1842 vtl
->current_wp
= NULL
;
1843 vtl
->current_wp_name
= NULL
;
1844 vtl
->moving_wp
= FALSE
;
1847 was_visible
= wp
->visible
;
1848 g_assert ( ( it
= g_hash_table_lookup ( vtl
->waypoints_iters
, (gchar
*) wp_name
) ) );
1849 vik_treeview_item_delete ( VIK_LAYER(vtl
)->vt
, it
);
1850 g_hash_table_remove ( vtl
->waypoints_iters
, (gchar
*) wp_name
);
1851 g_hash_table_remove ( vtl
->waypoints
, wp_name
); /* last because this frees name */
1857 static void remove_item_from_treeview(const gchar
*name
, GtkTreeIter
*it
, VikTreeview
* vt
)
1859 vik_treeview_item_delete (vt
, it
);
1862 void vik_trw_layer_delete_all_tracks ( VikTrwLayer
*vtl
)
1865 vtl
->current_track
= NULL
;
1866 if (vtl
->current_tp_track_name
)
1867 trw_layer_cancel_current_tp(vtl
, FALSE
);
1868 if (vtl
->last_tp_track_name
)
1869 trw_layer_cancel_last_tp ( vtl
);
1871 g_hash_table_foreach(vtl
->tracks_iters
, (GHFunc
) remove_item_from_treeview
, VIK_LAYER(vtl
)->vt
);
1872 g_hash_table_remove_all(vtl
->tracks_iters
);
1873 g_hash_table_remove_all(vtl
->tracks
);
1875 /* TODO: only update if the layer is visible (ticked) */
1876 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1879 void vik_trw_layer_delete_all_waypoints ( VikTrwLayer
*vtl
)
1881 vtl
->current_wp
= NULL
;
1882 vtl
->current_wp_name
= NULL
;
1883 vtl
->moving_wp
= FALSE
;
1885 g_hash_table_foreach(vtl
->waypoints_iters
, (GHFunc
) remove_item_from_treeview
, VIK_LAYER(vtl
)->vt
);
1886 g_hash_table_remove_all(vtl
->waypoints_iters
);
1887 g_hash_table_remove_all(vtl
->waypoints
);
1889 /* TODO: only update if the layer is visible (ticked) */
1890 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1893 static void trw_layer_delete_item ( gpointer pass_along
[5] )
1895 VikTrwLayer
*vtl
= VIK_TRW_LAYER(pass_along
[0]);
1896 gboolean was_visible
= FALSE
;
1897 if ( (gint
) pass_along
[2] == VIK_TRW_LAYER_SUBLAYER_WAYPOINT
)
1899 was_visible
= vik_trw_layer_delete_waypoint ( vtl
, (gchar
*) pass_along
[3] );
1903 was_visible
= vik_trw_layer_delete_track ( vtl
, (gchar
*) pass_along
[3] );
1906 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1910 static void trw_layer_properties_item ( gpointer pass_along
[5] )
1912 VikTrwLayer
*vtl
= VIK_TRW_LAYER(pass_along
[0]);
1913 if ( (gint
) pass_along
[2] == VIK_TRW_LAYER_SUBLAYER_WAYPOINT
)
1915 VikWaypoint
*wp
= g_hash_table_lookup ( vtl
->waypoints
, pass_along
[3] );
1918 if ( a_dialog_new_waypoint ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), NULL
, wp
, NULL
, vtl
->coord_mode
) )
1920 if ( VIK_LAYER(vtl
)->visible
)
1921 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1926 VikTrack
*tr
= g_hash_table_lookup ( vtl
->tracks
, pass_along
[3] );
1929 gint resp
= vik_trw_layer_propwin_run ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), tr
, pass_along
[1] /* vlp */ );
1930 if ( resp
== VIK_TRW_LAYER_PROPWIN_DEL_DUP
)
1932 vik_track_remove_dup_points(tr
);
1933 /* above operation could have deleted current_tp or last_tp */
1934 trw_layer_cancel_tps_of_track ( vtl
, (gchar
*) pass_along
[3] );
1935 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1937 if ( resp
== VIK_TRW_LAYER_PROPWIN_REVERSE
)
1939 vik_track_reverse(tr
);
1940 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1942 else if ( resp
== VIK_TRW_LAYER_PROPWIN_SPLIT
)
1944 /* get new tracks, add them, resolve naming conflicts (free if cancel), and delete old. old can still exist on clipboard. */
1946 VikTrack
**tracks
= vik_track_split_into_segments(tr
, &ntracks
);
1949 for ( i
= 0; i
< ntracks
; i
++ )
1951 g_assert ( tracks
[i
] );
1952 new_tr_name
= g_strdup_printf("%s #%d", (gchar
*) pass_along
[3], i
+1);
1953 /* if ( (wp_exists) && (! overwrite) ) */
1954 /* don't need to upper case new_tr_name because old tr name was uppercase */
1955 if ( g_hash_table_lookup ( vtl
->tracks
, new_tr_name
) &&
1956 ( ! a_dialog_overwrite ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), "The track \"%s\" exists, do you wish to overwrite it?", new_tr_name
) ) )
1958 gchar
*new_new_tr_name
= a_dialog_new_track ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), vtl
->tracks
);
1959 g_free ( new_tr_name
);
1960 if (new_new_tr_name
)
1961 new_tr_name
= new_new_tr_name
;
1965 vik_track_free ( tracks
[i
] );
1969 vik_trw_layer_add_track ( vtl
, new_tr_name
, tracks
[i
] );
1974 vik_trw_layer_delete_track ( vtl
, (gchar
*) pass_along
[3] );
1975 vik_layer_emit_update ( VIK_LAYER(vtl
) ); /* chase thru the hoops */
1982 static void goto_coord ( VikLayersPanel
*vlp
, const VikCoord
*coord
)
1984 vik_viewport_set_center_coord ( vik_layers_panel_get_viewport(vlp
), coord
);
1985 vik_layers_panel_emit_update ( vlp
);
1988 static void trw_layer_goto_track_startpoint ( gpointer pass_along
[5] )
1990 GList
*trps
= ((VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] ))->trackpoints
;
1991 if ( trps
&& trps
->data
)
1992 goto_coord ( VIK_LAYERS_PANEL(pass_along
[1]), &(((VikTrackpoint
*) trps
->data
)->coord
));
1995 static void trw_layer_goto_track_center ( gpointer pass_along
[5] )
1997 GList
**trps
= g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] );
1998 if ( trps
&& *trps
)
2000 struct LatLon average
, maxmin
[2] = { {0,0}, {0,0} };
2002 trw_layer_find_maxmin_tracks ( NULL
, trps
, maxmin
);
2003 average
.lat
= (maxmin
[0].lat
+maxmin
[1].lat
)/2;
2004 average
.lon
= (maxmin
[0].lon
+maxmin
[1].lon
)/2;
2005 vik_coord_load_from_latlon ( &coord
, VIK_TRW_LAYER(pass_along
[0])->coord_mode
, &average
);
2006 goto_coord ( VIK_LAYERS_PANEL(pass_along
[1]), &coord
);
2010 static void trw_layer_apply_dem_data ( gpointer pass_along
[6] )
2012 /* TODO: check & warn if no DEM data, or no applicable DEM data. */
2013 /* Also warn if overwrite old elevation data */
2014 VikTrack
*track
= (VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] );
2016 vik_track_apply_dem_data ( track
);
2020 static void trw_layer_goto_track_endpoint ( gpointer pass_along
[6] )
2022 GList
*trps
= ((VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] ))->trackpoints
;
2025 trps
= g_list_last(trps
);
2026 goto_coord ( VIK_LAYERS_PANEL(pass_along
[1]), &(((VikTrackpoint
*) trps
->data
)->coord
));
2030 /*************************************
2031 * merge/split by time routines
2032 *************************************/
2034 /* called for each key in track hash table. if original track user_data[1] is close enough
2035 * to the passed one, add it to list in user_data[0]
2037 static void find_nearby_track(gpointer key
, gpointer value
, gpointer user_data
)
2040 VikTrackpoint
*p1
, *p2
;
2042 GList
**nearby_tracks
= ((gpointer
*)user_data
)[0];
2043 GList
*orig_track
= ((gpointer
*)user_data
)[1];
2044 guint thr
= (guint
)((gpointer
*)user_data
)[2];
2046 t1
= VIK_TRACKPOINT(orig_track
->data
)->timestamp
;
2047 t2
= VIK_TRACKPOINT(g_list_last(orig_track
)->data
)->timestamp
;
2049 if (VIK_TRACK(value
)->trackpoints
== orig_track
) {
2053 p1
= VIK_TRACKPOINT(VIK_TRACK(value
)->trackpoints
->data
);
2054 p2
= VIK_TRACKPOINT(g_list_last(VIK_TRACK(value
)->trackpoints
)->data
);
2056 if (!p1
->has_timestamp
|| !p2
->has_timestamp
) {
2057 g_print("no timestamp\n");
2061 /* g_print("Got track named %s, times %d, %d\n", (gchar *)key, p1->timestamp, p2->timestamp); */
2062 if (abs(t1
- p2
->timestamp
) < thr
*60 ||
2064 abs(p1
->timestamp
- t2
) < thr
*60
2067 *nearby_tracks
= g_list_prepend(*nearby_tracks
, key
);
2071 /* comparison function used to sort tracks; a and b are hash table keys */
2072 static gint
track_compare(gconstpointer a
, gconstpointer b
, gpointer user_data
)
2074 GHashTable
*tracks
= user_data
;
2077 t1
= VIK_TRACKPOINT(VIK_TRACK(g_hash_table_lookup(tracks
, a
))->trackpoints
->data
)->timestamp
;
2078 t2
= VIK_TRACKPOINT(VIK_TRACK(g_hash_table_lookup(tracks
, b
))->trackpoints
->data
)->timestamp
;
2080 if (t1
< t2
) return -1;
2081 if (t1
> t2
) return 1;
2085 /* comparison function used to sort trackpoints */
2086 static gint
trackpoint_compare(gconstpointer a
, gconstpointer b
)
2088 time_t t1
= VIK_TRACKPOINT(a
)->timestamp
, t2
= VIK_TRACKPOINT(b
)->timestamp
;
2090 if (t1
< t2
) return -1;
2091 if (t1
> t2
) return 1;
2095 /* merge by time routine */
2096 static void trw_layer_merge_by_timestamp ( gpointer pass_along
[6] )
2099 GList
*nearby_tracks
= NULL
;
2102 static guint thr
= 1;
2103 guint track_count
= 0;
2104 gchar
*orig_track_name
= strdup(pass_along
[3]);
2106 if (!a_dialog_time_threshold(VIK_GTK_WINDOW_FROM_LAYER(pass_along
[0]),
2107 "Merge Threshold...",
2108 "Merge when time between trackpoints less than:",
2113 /* merge tracks until we can't */
2117 track
= (VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, orig_track_name
);
2118 trps
= track
->trackpoints
;
2123 if (nearby_tracks
) {
2124 g_list_free(nearby_tracks
);
2125 nearby_tracks
= NULL
;
2128 t1
= ((VikTrackpoint
*)trps
->data
)->timestamp
;
2129 t2
= ((VikTrackpoint
*)g_list_last(trps
)->data
)->timestamp
;
2131 /* g_print("Original track times: %d and %d\n", t1, t2); */
2132 params
[0] = &nearby_tracks
;
2134 params
[2] = (gpointer
)thr
;
2136 /* get a list of adjacent-in-time tracks */
2137 g_hash_table_foreach(VIK_TRW_LAYER(pass_along
[0])->tracks
, find_nearby_track
, (gpointer
)params
);
2139 /* add original track */
2140 nearby_tracks
= g_list_prepend(nearby_tracks
, orig_track_name
);
2142 /* sort by first trackpoint; assumes they don't overlap */
2143 nearby_tracks
= g_list_sort_with_data(nearby_tracks
, track_compare
, VIK_TRW_LAYER(pass_along
[0])->tracks
);
2147 #define get_track(x) VIK_TRACK(g_hash_table_lookup(VIK_TRW_LAYER(pass_along[0])->tracks, (gchar *)((x)->data)))
2148 #define get_first_trackpoint(x) VIK_TRACKPOINT(get_track(x)->trackpoints->data)
2149 #define get_last_trackpoint(x) VIK_TRACKPOINT(g_list_last(get_track(x)->trackpoints)->data)
2150 GList
*l
= nearby_tracks
;
2151 VikTrack
*tr
= vik_track_new();
2152 tr
->visible
= track
->visible
;
2157 t1 = get_first_trackpoint(l)->timestamp;
2158 t2 = get_last_trackpoint(l)->timestamp;
2159 g_print(" %20s: track %d - %d\n", (char *)l->data, (int)t1, (int)t2);
2163 /* remove trackpoints from merged track, delete track */
2164 tr
->trackpoints
= g_list_concat(tr
->trackpoints
, get_track(l
)->trackpoints
);
2165 get_track(l
)->trackpoints
= NULL
;
2166 vik_trw_layer_delete_track(VIK_TRW_LAYER(pass_along
[0]), l
->data
);
2171 tr
->trackpoints
= g_list_sort(tr
->trackpoints
, trackpoint_compare
);
2172 vik_trw_layer_add_track(VIK_TRW_LAYER(pass_along
[0]), strdup(orig_track_name
), tr
);
2174 #undef get_first_trackpoint
2175 #undef get_last_trackpoint
2178 } while (track_count
> 1);
2179 g_list_free(nearby_tracks
);
2180 free(orig_track_name
);
2181 vik_layer_emit_update(VIK_LAYER(pass_along
[0]));
2184 /* split by time routine */
2185 static void trw_layer_split_by_timestamp ( gpointer pass_along
[6] )
2187 VikTrack
*track
= (VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] );
2188 GList
*trps
= track
->trackpoints
;
2190 GList
*newlists
= NULL
;
2191 GList
*newtps
= NULL
;
2193 static guint thr
= 1;
2200 if (!a_dialog_time_threshold(VIK_GTK_WINDOW_FROM_LAYER(pass_along
[0]),
2201 "Split Threshold...",
2202 "Split when time between trackpoints exceeds:",
2207 /* iterate through trackpoints, and copy them into new lists without touching original list */
2208 prev_ts
= VIK_TRACKPOINT(trps
->data
)->timestamp
;
2212 ts
= VIK_TRACKPOINT(iter
->data
)->timestamp
;
2214 g_print("panic: ts < prev_ts: this should never happen!\n");
2217 if (ts
- prev_ts
> thr
*60) {
2218 /* flush accumulated trackpoints into new list */
2219 newlists
= g_list_prepend(newlists
, g_list_reverse(newtps
));
2223 /* accumulate trackpoint copies in newtps, in reverse order */
2224 newtps
= g_list_prepend(newtps
, vik_trackpoint_copy(VIK_TRACKPOINT(iter
->data
)));
2226 iter
= g_list_next(iter
);
2229 newlists
= g_list_prepend(newlists
, g_list_reverse(newtps
));
2232 /* put lists of trackpoints into tracks */
2239 tr
= vik_track_new();
2240 tr
->visible
= track
->visible
;
2241 tr
->trackpoints
= (GList
*)(iter
->data
);
2243 new_tr_name
= g_strdup_printf("%s #%d", (gchar
*) pass_along
[3], i
++);
2244 vik_trw_layer_add_track(VIK_TRW_LAYER(pass_along
[0]), new_tr_name
, tr
);
2245 /* g_print("adding track %s, times %d - %d\n", new_tr_name, VIK_TRACKPOINT(tr->trackpoints->data)->timestamp,
2246 VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp);*/
2248 iter
= g_list_next(iter
);
2250 g_list_free(newlists
);
2251 vik_trw_layer_delete_track(VIK_TRW_LAYER(pass_along
[0]), (gchar
*)pass_along
[3]);
2252 vik_layer_emit_update(VIK_LAYER(pass_along
[0]));
2255 /* end of split/merge routines */
2258 static void trw_layer_goto_waypoint ( gpointer pass_along
[5] )
2260 VikWaypoint
*wp
= g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->waypoints
, pass_along
[3] );
2262 goto_coord ( VIK_LAYERS_PANEL(pass_along
[1]), &(wp
->coord
) );
2265 static void trw_layer_waypoint_gc_webpage ( gpointer pass_along
[5] )
2267 gchar
*webpage
= g_strdup_printf("http://www.geocaching.com/seek/cache_details.aspx?wp=%s", (gchar
*) pass_along
[3] );
2269 ShellExecute(NULL
, NULL
, (char *) webpage
, NULL
, ".\\", 0);
2272 gchar
*cmd
= g_strdup_printf ( "%s %s", UNIX_WEB_BROWSER
, webpage
);
2273 if ( ! g_spawn_command_line_async ( cmd
, &err
) )
2275 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(VIK_LAYER(pass_along
[0])), "Could not launch web browser." );
2276 g_error_free ( err
);
2279 #endif /* WINDOWS */
2283 const gchar
*vik_trw_layer_sublayer_rename_request ( VikTrwLayer
*l
, const gchar
*newname
, gpointer vlp
, gint subtype
, gpointer sublayer
, GtkTreeIter
*iter
)
2285 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
)
2291 if ( strcasecmp ( newname
, sublayer
) == 0 )
2294 if ( uppercase_exists_in_hash ( l
->waypoints
, newname
) )
2296 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(l
), "Waypoint Already Exists" );
2300 iter
= g_hash_table_lookup ( l
->waypoints_iters
, sublayer
);
2301 g_hash_table_steal ( l
->waypoints_iters
, sublayer
);
2303 wp
= vik_waypoint_copy ( VIK_WAYPOINT(g_hash_table_lookup ( l
->waypoints
, sublayer
)) );
2304 g_hash_table_remove ( l
->waypoints
, sublayer
);
2306 rv
= g_strdup(newname
);
2307 for ( i
= strlen(rv
) - 1; i
>= 0; i
-- )
2308 rv
[i
] = toupper(rv
[i
]);
2310 vik_treeview_item_set_pointer ( VIK_LAYER(l
)->vt
, iter
, rv
);
2312 g_hash_table_insert ( l
->waypoints
, rv
, wp
);
2313 g_hash_table_insert ( l
->waypoints_iters
, rv
, iter
);
2315 /* it hasn't been updated yet so we pass new name */
2316 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
2317 vik_treeview_sublayer_realphabetize ( VIK_LAYER(l
)->vt
, iter
, rv
);
2320 vik_layers_panel_emit_update ( VIK_LAYERS_PANEL(vlp
) );
2323 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_TRACK
)
2331 if ( strcasecmp ( newname
, sublayer
) == 0 )
2334 if ( uppercase_exists_in_hash ( l
->tracks
, newname
) )
2336 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(l
), "Track Already Exists" );
2340 g_hash_table_lookup_extended ( l
->tracks
, sublayer
, (void *)&orig_key
, (void *)&tr
);
2341 g_hash_table_steal ( l
->tracks
, sublayer
);
2343 iter
= g_hash_table_lookup ( l
->tracks_iters
, sublayer
);
2344 g_hash_table_steal ( l
->tracks_iters
, sublayer
);
2346 rv
= g_strdup(newname
);
2347 for ( i
= strlen(rv
) - 1; i
>= 0; i
-- )
2348 rv
[i
] = toupper(rv
[i
]);
2350 vik_treeview_item_set_pointer ( VIK_LAYER(l
)->vt
, iter
, rv
);
2352 g_hash_table_insert ( l
->tracks
, rv
, tr
);
2353 g_hash_table_insert ( l
->tracks_iters
, rv
, iter
);
2355 /* don't forget about current_tp_track_name, update that too */
2356 if ( l
->current_tp_track_name
&& g_strcasecmp(orig_key
,l
->current_tp_track_name
) == 0 )
2358 l
->current_tp_track_name
= rv
;
2360 vik_trw_layer_tpwin_set_track_name ( l
->tpwin
, rv
);
2362 else if ( l
->last_tp_track_name
&& g_strcasecmp(orig_key
,l
->last_tp_track_name
) == 0 )
2363 l
->last_tp_track_name
= rv
;
2365 g_free ( orig_key
);
2367 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
2368 vik_treeview_sublayer_realphabetize ( VIK_LAYER(l
)->vt
, iter
, rv
);
2371 vik_layers_panel_emit_update ( VIK_LAYERS_PANEL(vlp
) );
2377 static gboolean
is_valid_geocache_name ( gchar
*str
)
2379 gint len
= strlen ( str
);
2380 return len
>= 3 && len
<= 6 && str
[0] == 'G' && str
[1] == 'C' && isalnum(str
[2]) && (len
< 4 || isalnum(str
[3])) && (len
< 5 || isalnum(str
[4])) && (len
< 6 || isalnum(str
[5]));
2383 /* vlp can be NULL if necessary - i.e. right-click from a tool -- but be careful, some functions may try to use it */
2384 gboolean
vik_trw_layer_sublayer_add_menu_items ( VikTrwLayer
*l
, GtkMenu
*menu
, gpointer vlp
, gint subtype
, gpointer sublayer
, GtkTreeIter
*iter
)
2386 static GtkTreeIter staticiter
;
2387 static gpointer pass_along
[5];
2389 gboolean rv
= FALSE
;
2392 pass_along
[1] = vlp
;
2393 pass_along
[2] = (gpointer
) subtype
;
2394 pass_along
[3] = sublayer
;
2395 staticiter
= *iter
; /* will exist after function has ended */
2396 pass_along
[4] = &staticiter
;
2398 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
|| subtype
== VIK_TRW_LAYER_SUBLAYER_TRACK
)
2402 item
= gtk_image_menu_item_new_from_stock ( GTK_STOCK_PROPERTIES
, NULL
);
2403 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_properties_item
), pass_along
);
2404 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2405 gtk_widget_show ( item
);
2407 item
= gtk_image_menu_item_new_from_stock ( GTK_STOCK_CUT
, NULL
);
2408 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_cut_item_cb
), pass_along
);
2409 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2410 gtk_widget_show ( item
);
2412 item
= gtk_image_menu_item_new_from_stock ( GTK_STOCK_COPY
, NULL
);
2413 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_copy_item_cb
), pass_along
);
2414 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2415 gtk_widget_show ( item
);
2417 item
= gtk_image_menu_item_new_from_stock ( GTK_STOCK_DELETE
, NULL
);
2418 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_delete_item
), pass_along
);
2419 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2420 gtk_widget_show ( item
);
2422 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
)
2424 /* could be a right-click using the tool */
2425 if ( vlp
!= NULL
) {
2426 item
= gtk_menu_item_new_with_label ( "Goto" );
2427 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_goto_waypoint
), pass_along
);
2428 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2429 gtk_widget_show ( item
);
2432 if ( is_valid_geocache_name ( (gchar
*) sublayer
) )
2434 item
= gtk_menu_item_new_with_label ( "Visit Geocache Webpage" );
2435 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_waypoint_gc_webpage
), pass_along
);
2436 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2437 gtk_widget_show ( item
);
2443 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_TRACK
)
2445 item
= gtk_menu_item_new ();
2446 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2447 gtk_widget_show ( item
);
2449 item
= gtk_menu_item_new_with_label ( "Goto Startpoint" );
2450 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_goto_track_startpoint
), pass_along
);
2451 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2452 gtk_widget_show ( item
);
2454 item
= gtk_menu_item_new_with_label ( "Goto \"Center\"" );
2455 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_goto_track_center
), pass_along
);
2456 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2457 gtk_widget_show ( item
);
2459 item
= gtk_menu_item_new_with_label ( "Goto Endpoint" );
2460 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_goto_track_endpoint
), pass_along
);
2461 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2462 gtk_widget_show ( item
);
2464 item
= gtk_menu_item_new_with_label ( "Merge By Time" );
2465 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_merge_by_timestamp
), pass_along
);
2466 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2467 gtk_widget_show ( item
);
2469 item
= gtk_menu_item_new_with_label ( "Split By Time" );
2470 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_split_by_timestamp
), pass_along
);
2471 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2472 gtk_widget_show ( item
);
2474 item
= gtk_menu_item_new_with_label ( "Download maps along track..." );
2475 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_download_map_along_track_cb
), pass_along
);
2476 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2477 gtk_widget_show ( item
);
2479 item
= gtk_menu_item_new_with_label ( "Apply DEM Data" );
2480 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_apply_dem_data
), pass_along
);
2481 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2482 gtk_widget_show ( item
);
2484 #ifdef VIK_CONFIG_OPENSTREETMAP
2485 item
= gtk_menu_item_new_with_label ( "Upload to OSM" );
2486 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(osm_traces_upload_track_cb
), pass_along
);
2487 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2488 gtk_widget_show ( item
);
2492 if ( vlp
&& (subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
|| subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
) )
2494 item
= gtk_menu_item_new ();
2495 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2496 gtk_widget_show ( item
);
2498 item
= gtk_menu_item_new_with_label ( "New Waypoint" );
2499 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_new_wp
), pass_along
);
2500 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
2501 gtk_widget_show ( item
);
2508 /* to be called when last_tpl no long exists. */
2509 static void trw_layer_cancel_last_tp ( VikTrwLayer
*vtl
)
2511 if ( vtl
->tpwin
) /* can't join with a non-existant TP. */
2512 vik_trw_layer_tpwin_disable_join ( vtl
->tpwin
);
2513 vtl
->last_tpl
= NULL
;
2514 vtl
->last_tp_track_name
= NULL
;
2517 static void trw_layer_cancel_current_tp ( VikTrwLayer
*vtl
, gboolean destroy
)
2523 gtk_widget_destroy ( GTK_WIDGET(vtl
->tpwin
) );
2527 vik_trw_layer_tpwin_set_empty ( vtl
->tpwin
);
2529 if ( vtl
->current_tpl
)
2531 vtl
->current_tpl
= NULL
;
2532 vtl
->current_tp_track_name
= NULL
;
2533 vik_layer_emit_update(VIK_LAYER(vtl
));
2537 static void trw_layer_tpwin_response ( VikTrwLayer
*vtl
, gint response
)
2539 g_assert ( vtl
->tpwin
!= NULL
);
2540 if ( response
== VIK_TRW_LAYER_TPWIN_CLOSE
)
2541 trw_layer_cancel_current_tp ( vtl
, TRUE
);
2542 else if ( response
== VIK_TRW_LAYER_TPWIN_SPLIT
&& vtl
->current_tpl
->next
&& vtl
->current_tpl
->prev
)
2545 if ( ( name
= a_dialog_new_track ( GTK_WINDOW(vtl
->tpwin
), vtl
->tracks
) ) )
2547 VikTrack
*tr
= vik_track_new ();
2548 GList
*newglist
= g_list_alloc ();
2549 newglist
->prev
= NULL
;
2550 newglist
->next
= vtl
->current_tpl
->next
;
2551 newglist
->data
= vik_trackpoint_copy(VIK_TRACKPOINT(vtl
->current_tpl
->data
));
2552 tr
->trackpoints
= newglist
;
2554 vtl
->current_tpl
->next
->prev
= newglist
; /* end old track here */
2555 vtl
->current_tpl
->next
= NULL
;
2557 vtl
->current_tpl
= newglist
; /* change tp to first of new track. */
2558 vtl
->current_tp_track_name
= name
;
2560 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
, vtl
->current_tp_track_name
);
2562 vik_trw_layer_add_track ( vtl
, name
, tr
);
2563 vik_layer_emit_update(VIK_LAYER(vtl
));
2566 else if ( response
== VIK_TRW_LAYER_TPWIN_DELETE
)
2568 VikTrack
*tr
= g_hash_table_lookup ( vtl
->tracks
, vtl
->current_tp_track_name
);
2570 g_assert(tr
!= NULL
);
2572 /* can't join with a non-existent trackpoint */
2573 vtl
->last_tpl
= NULL
;
2574 vtl
->last_tp_track_name
= NULL
;
2576 if ( (new_tpl
= vtl
->current_tpl
->next
) || (new_tpl
= vtl
->current_tpl
->prev
) )
2578 if ( VIK_TRACKPOINT(vtl
->current_tpl
->data
)->newsegment
&& vtl
->current_tpl
->next
)
2579 VIK_TRACKPOINT(vtl
->current_tpl
->next
->data
)->newsegment
= TRUE
; /* don't concat segments on del */
2581 tr
->trackpoints
= g_list_remove_link ( tr
->trackpoints
, vtl
->current_tpl
); /* this nulls current_tpl->prev and next */
2583 /* at this point the old trackpoint exists, but the list links are correct (new), so it is safe to do this. */
2584 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, new_tpl
, vtl
->current_tp_track_name
);
2586 trw_layer_cancel_last_tp ( vtl
);
2588 g_free ( vtl
->current_tpl
->data
); /* TODO: vik_trackpoint_free() */
2589 g_list_free_1 ( vtl
->current_tpl
);
2590 vtl
->current_tpl
= new_tpl
;
2591 vik_layer_emit_update(VIK_LAYER(vtl
));
2595 tr
->trackpoints
= g_list_remove_link ( tr
->trackpoints
, vtl
->current_tpl
);
2596 g_free ( vtl
->current_tpl
->data
); /* TODO longone: vik_trackpoint_new() and vik_trackpoint_free() */
2597 g_list_free_1 ( vtl
->current_tpl
);
2598 trw_layer_cancel_current_tp ( vtl
, FALSE
);
2601 else if ( response
== VIK_TRW_LAYER_TPWIN_FORWARD
&& vtl
->current_tpl
->next
)
2603 vtl
->last_tpl
= vtl
->current_tpl
;
2604 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
= vtl
->current_tpl
->next
, vtl
->current_tp_track_name
);
2605 vik_layer_emit_update(VIK_LAYER(vtl
)); /* TODO longone: either move or only update if tp is inside drawing window */
2607 else if ( response
== VIK_TRW_LAYER_TPWIN_BACK
&& vtl
->current_tpl
->prev
)
2609 vtl
->last_tpl
= vtl
->current_tpl
;
2610 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
= vtl
->current_tpl
->prev
, vtl
->current_tp_track_name
);
2611 vik_layer_emit_update(VIK_LAYER(vtl
));
2613 else if ( response
== VIK_TRW_LAYER_TPWIN_JOIN
)
2615 VikTrack
*tr1
= g_hash_table_lookup ( vtl
->tracks
, vtl
->last_tp_track_name
);
2616 VikTrack
*tr2
= g_hash_table_lookup ( vtl
->tracks
, vtl
->current_tp_track_name
);
2618 VikTrack
*tr_first
= tr1
, *tr_last
= tr2
;
2622 if ( (!vtl
->last_tpl
->next
) && (!vtl
->current_tpl
->next
) ) /* both endpoints */
2623 vik_track_reverse ( tr2
); /* reverse the second, that way second track clicked will be later. */
2624 else if ( (!vtl
->last_tpl
->prev
) && (!vtl
->current_tpl
->prev
) )
2625 vik_track_reverse ( tr1
);
2626 else if ( (!vtl
->last_tpl
->prev
) && (!vtl
->current_tpl
->next
) ) /* clicked startpoint, then endpoint -- concat end to start */
2631 /* default -- clicked endpoint then startpoint -- connect endpoint to startpoint */
2633 if ( tr_last
->trackpoints
) /* deleting this part here joins them into 1 segmented track. useful but there's no place in the UI for this feature. segments should be deprecated anyway. */
2634 VIK_TRACKPOINT(tr_last
->trackpoints
->data
)->newsegment
= FALSE
;
2635 tr1
->trackpoints
= g_list_concat ( tr_first
->trackpoints
, tr_last
->trackpoints
);
2636 tr2
->trackpoints
= NULL
;
2638 tmp
= vtl
->current_tp_track_name
;
2640 vtl
->current_tp_track_name
= vtl
->last_tp_track_name
; /* current_tp stays the same (believe it or not!) */
2641 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
, vtl
->current_tp_track_name
);
2643 /* if we did this before, trw_layer_delete_track would have canceled the current tp because
2644 * it was the current track. canceling the current tp would have set vtl->current_tpl to NULL */
2645 vik_trw_layer_delete_track ( vtl
, tmp
);
2647 trw_layer_cancel_last_tp ( vtl
); /* same TP, can't join. */
2648 vik_layer_emit_update(VIK_LAYER(vtl
));
2650 else if ( response
== VIK_TRW_LAYER_TPWIN_DATA_CHANGED
)
2651 vik_layer_emit_update (VIK_LAYER(vtl
));
2654 static void trw_layer_tpwin_init ( VikTrwLayer
*vtl
)
2658 vtl
->tpwin
= vik_trw_layer_tpwin_new ( VIK_GTK_WINDOW_FROM_LAYER(vtl
) );
2659 g_signal_connect_swapped ( GTK_DIALOG(vtl
->tpwin
), "response", G_CALLBACK(trw_layer_tpwin_response
), vtl
);
2660 /* connect signals -- DELETE SIGNAL VERY IMPORTANT TO SET TO NULL */
2661 g_signal_connect_swapped ( vtl
->tpwin
, "delete-event", G_CALLBACK(trw_layer_cancel_current_tp
), vtl
);
2662 gtk_widget_show_all ( GTK_WIDGET(vtl
->tpwin
) );
2664 if ( vtl
->current_tpl
)
2665 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
, vtl
->current_tp_track_name
);
2666 /* set layer name and TP data */
2669 /***************************************************************************
2671 ***************************************************************************/
2673 /*** Utility data structures and functions ****/
2677 gint closest_x
, closest_y
;
2678 gchar
*closest_wp_name
;
2679 VikWaypoint
*closest_wp
;
2685 gint closest_x
, closest_y
;
2686 gchar
*closest_track_name
;
2687 VikTrackpoint
*closest_tp
;
2692 static void waypoint_search_closest_tp ( gchar
*name
, VikWaypoint
*wp
, WPSearchParams
*params
)
2698 vik_viewport_coord_to_screen ( params
->vvp
, &(wp
->coord
), &x
, &y
);
2700 if ( abs (x
- params
->x
) <= WAYPOINT_SIZE_APPROX
&& abs (y
- params
->y
) <= WAYPOINT_SIZE_APPROX
&&
2701 ((!params
->closest_wp
) || /* was the old waypoint we already found closer than this one? */
2702 abs(x
- params
->x
)+abs(y
- params
->y
) < abs(x
- params
->closest_x
)+abs(y
- params
->closest_y
)))
2704 params
->closest_wp_name
= name
;
2705 params
->closest_wp
= wp
;
2706 params
->closest_x
= x
;
2707 params
->closest_y
= y
;
2711 static void track_search_closest_tp ( gchar
*name
, VikTrack
*t
, TPSearchParams
*params
)
2713 GList
*tpl
= t
->trackpoints
;
2722 tp
= VIK_TRACKPOINT(tpl
->data
);
2724 vik_viewport_coord_to_screen ( params
->vvp
, &(tp
->coord
), &x
, &y
);
2726 if ( abs (x
- params
->x
) <= TRACKPOINT_SIZE_APPROX
&& abs (y
- params
->y
) <= TRACKPOINT_SIZE_APPROX
&&
2727 ((!params
->closest_tp
) || /* was the old trackpoint we already found closer than this one? */
2728 abs(x
- params
->x
)+abs(y
- params
->y
) < abs(x
- params
->closest_x
)+abs(y
- params
->closest_y
)))
2730 params
->closest_track_name
= name
;
2731 params
->closest_tp
= tp
;
2732 params
->closest_tpl
= tpl
;
2733 params
->closest_x
= x
;
2734 params
->closest_y
= y
;
2740 static VikTrackpoint
*closest_tp_in_five_pixel_interval ( VikTrwLayer
*vtl
, VikViewport
*vvp
, gint x
, gint y
)
2742 TPSearchParams params
;
2746 params
.closest_track_name
= NULL
;
2747 params
.closest_tp
= NULL
;
2748 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) track_search_closest_tp
, ¶ms
);
2749 return params
.closest_tp
;
2752 static VikWaypoint
*closest_wp_in_five_pixel_interval ( VikTrwLayer
*vtl
, VikViewport
*vvp
, gint x
, gint y
)
2754 WPSearchParams params
;
2758 params
.closest_wp
= NULL
;
2759 params
.closest_wp_name
= NULL
;
2760 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) waypoint_search_closest_tp
, ¶ms
);
2761 return params
.closest_wp
;
2764 /* background drawing hook, to be passed the viewport */
2765 static gboolean tool_sync_done
= TRUE
;
2767 static gboolean
tool_sync(gpointer data
)
2769 VikViewport
*vvp
= data
;
2770 gdk_threads_enter();
2771 vik_viewport_sync(vvp
);
2772 tool_sync_done
= TRUE
;
2773 gdk_threads_leave();
2784 static void marker_begin_move ( tool_ed_t
*t
, gint x
, gint y
)
2787 t
->gc
= vik_viewport_new_gc (t
->vvp
, "black", 2);
2788 gdk_gc_set_function ( t
->gc
, GDK_INVERT
);
2789 vik_viewport_draw_rectangle ( t
->vvp
, t
->gc
, FALSE
, x
-3, y
-3, 6, 6 );
2790 vik_viewport_sync(t
->vvp
);
2795 static void marker_moveto ( tool_ed_t
*t
, gint x
, gint y
)
2797 VikViewport
*vvp
= t
->vvp
;
2798 vik_viewport_draw_rectangle ( vvp
, t
->gc
, FALSE
, t
->oldx
-3, t
->oldy
-3, 6, 6 );
2799 vik_viewport_draw_rectangle ( vvp
, t
->gc
, FALSE
, x
-3, y
-3, 6, 6 );
2802 if (tool_sync_done
) {
2803 g_idle_add_full (G_PRIORITY_HIGH_IDLE
+ 10, tool_sync
, vvp
, NULL
);
2804 tool_sync_done
= FALSE
;
2808 static void marker_end_move ( tool_ed_t
*t
)
2810 vik_viewport_draw_rectangle ( t
->vvp
, t
->gc
, FALSE
, t
->oldx
-3, t
->oldy
-3, 6, 6 );
2811 g_object_unref ( t
->gc
);
2815 /*** Edit waypoint ****/
2817 static gpointer
tool_edit_waypoint_create ( VikWindow
*vw
, VikViewport
*vvp
)
2819 tool_ed_t
*t
= g_new(tool_ed_t
, 1);
2825 static gboolean
tool_edit_waypoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
2827 WPSearchParams params
;
2828 tool_ed_t
*t
= data
;
2829 VikViewport
*vvp
= t
->vvp
;
2831 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
2838 if ( vtl
->current_wp
&& vtl
->current_wp
->visible
)
2840 /* first check if current WP is within area (other may be 'closer', but we want to move the current) */
2842 vik_viewport_coord_to_screen ( vvp
, &(vtl
->current_wp
->coord
), &x
, &y
);
2844 if ( abs(x
- event
->x
) <= WAYPOINT_SIZE_APPROX
&&
2845 abs(y
- event
->y
) <= WAYPOINT_SIZE_APPROX
)
2847 if ( event
->button
== 3 )
2848 vtl
->waypoint_rightclick
= TRUE
; /* remember that we're clicking; other layers will ignore release signal */
2850 marker_begin_move(t
, event
->x
, event
->y
);
2857 params
.x
= event
->x
;
2858 params
.y
= event
->y
;
2859 params
.closest_wp_name
= NULL
;
2860 /* TODO: should get track listitem so we can break it up, make a new track, mess it up, all that. */
2861 params
.closest_wp
= NULL
;
2862 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) waypoint_search_closest_tp
, ¶ms
);
2863 if ( vtl
->current_wp
== params
.closest_wp
&& vtl
->current_wp
!= NULL
)
2865 /* how do we get here? I'm putting in the abort until we can figure it out. -alex */
2866 marker_begin_move(t
, event
->x
, event
->y
);
2867 g_critical("shouldn't be here");
2870 else if ( params
.closest_wp
)
2872 if ( event
->button
== 3 )
2873 vtl
->waypoint_rightclick
= TRUE
; /* remember that we're clicking; other layers will ignore release signal */
2875 vtl
->waypoint_rightclick
= FALSE
;
2877 vtl
->current_wp
= params
.closest_wp
;
2878 vtl
->current_wp_name
= params
.closest_wp_name
;
2880 if ( params
.closest_wp
)
2881 vik_treeview_select_iter ( VIK_LAYER(vtl
)->vt
, g_hash_table_lookup ( vtl
->waypoints_iters
, vtl
->current_wp_name
) );
2883 /* could make it so don't update if old WP is off screen and new is null but oh well */
2884 vik_layer_emit_update ( VIK_LAYER(vtl
) );
2888 vtl
->current_wp
= NULL
;
2889 vtl
->current_wp_name
= NULL
;
2890 vtl
->waypoint_rightclick
= FALSE
;
2891 vik_layer_emit_update ( VIK_LAYER(vtl
) );
2895 static gboolean
tool_edit_waypoint_move ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
2897 tool_ed_t
*t
= data
;
2898 VikViewport
*vvp
= t
->vvp
;
2900 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
2905 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &new_coord
);
2908 if ( event
->state
& GDK_CONTROL_MASK
)
2910 VikTrackpoint
*tp
= closest_tp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
2912 new_coord
= tp
->coord
;
2916 if ( event
->state
& GDK_SHIFT_MASK
)
2918 VikWaypoint
*wp
= closest_wp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
2919 if ( wp
&& wp
!= vtl
->current_wp
)
2920 new_coord
= wp
->coord
;
2925 vik_viewport_coord_to_screen ( vvp
, &new_coord
, &x
, &y
);
2926 marker_moveto ( t
, x
, y
);
2933 static gboolean
tool_edit_waypoint_release ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
2935 tool_ed_t
*t
= data
;
2936 VikViewport
*vvp
= t
->vvp
;
2938 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
2941 if ( t
->holding
&& event
->button
== 1 )
2944 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &new_coord
);
2947 if ( event
->state
& GDK_CONTROL_MASK
)
2949 VikTrackpoint
*tp
= closest_tp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
2951 new_coord
= tp
->coord
;
2955 if ( event
->state
& GDK_SHIFT_MASK
)
2957 VikWaypoint
*wp
= closest_wp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
2958 if ( wp
&& wp
!= vtl
->current_wp
)
2959 new_coord
= wp
->coord
;
2962 marker_end_move ( t
);
2964 vtl
->current_wp
->coord
= new_coord
;
2965 vik_layer_emit_update ( VIK_LAYER(vtl
) );
2968 /* PUT IN RIGHT PLACE!!! */
2969 if ( event
->button
== 3 && vtl
->waypoint_rightclick
)
2971 if ( vtl
->wp_right_click_menu
)
2972 gtk_object_sink ( GTK_OBJECT(vtl
->wp_right_click_menu
) );
2973 vtl
->wp_right_click_menu
= GTK_MENU ( gtk_menu_new () );
2974 vik_trw_layer_sublayer_add_menu_items ( vtl
, vtl
->wp_right_click_menu
, NULL
, VIK_TRW_LAYER_SUBLAYER_WAYPOINT
, vtl
->current_wp_name
, g_hash_table_lookup ( vtl
->waypoints_iters
, vtl
->current_wp_name
) );
2975 gtk_menu_popup ( vtl
->wp_right_click_menu
, NULL
, NULL
, NULL
, NULL
, event
->button
, gtk_get_current_event_time() );
2976 vtl
->waypoint_rightclick
= FALSE
;
2981 /*** New track ****/
2983 static gpointer
tool_new_track_create ( VikWindow
*vw
, VikViewport
*vvp
)
2988 static gboolean
tool_new_track_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
)
2992 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
2995 if ( event
->button
== 3 && vtl
->current_track
)
2998 if ( vtl
->current_track
->trackpoints
)
3000 GList
*last
= g_list_last(vtl
->current_track
->trackpoints
);
3001 g_free ( last
->data
);
3002 vtl
->current_track
->trackpoints
= g_list_remove_link ( vtl
->current_track
->trackpoints
, last
);
3004 vik_layer_emit_update ( VIK_LAYER(vtl
) );
3008 if ( event
->type
== GDK_2BUTTON_PRESS
)
3010 /* subtract last (duplicate from double click) tp then end */
3011 if ( vtl
->current_track
&& vtl
->current_track
->trackpoints
&& vtl
->ct_x1
== vtl
->ct_x2
&& vtl
->ct_y1
== vtl
->ct_y2
)
3013 GList
*last
= g_list_last(vtl
->current_track
->trackpoints
);
3014 g_free ( last
->data
);
3015 vtl
->current_track
->trackpoints
= g_list_remove_link ( vtl
->current_track
->trackpoints
, last
);
3016 /* undo last, then end */
3017 vtl
->current_track
= NULL
;
3022 if ( ! vtl
->current_track
)
3025 if ( ( name
= a_dialog_new_track ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), vtl
->tracks
) ) )
3027 vtl
->current_track
= vik_track_new();
3028 vtl
->current_track
->visible
= TRUE
;
3029 vik_trw_layer_add_track ( vtl
, name
, vtl
->current_track
);
3034 tp
= vik_trackpoint_new();
3035 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &(tp
->coord
) );
3037 /* snap to other TP */
3038 if ( event
->state
& GDK_CONTROL_MASK
)
3040 VikTrackpoint
*other_tp
= closest_tp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
3042 tp
->coord
= other_tp
->coord
;
3045 tp
->newsegment
= FALSE
;
3046 tp
->has_timestamp
= FALSE
;
3048 tp
->altitude
= VIK_DEFAULT_ALTITUDE
;
3049 vtl
->current_track
->trackpoints
= g_list_append ( vtl
->current_track
->trackpoints
, tp
);
3051 vtl
->ct_x1
= vtl
->ct_x2
;
3052 vtl
->ct_y1
= vtl
->ct_y2
;
3053 vtl
->ct_x2
= event
->x
;
3054 vtl
->ct_y2
= event
->y
;
3056 vik_layer_emit_update ( VIK_LAYER(vtl
) );
3061 /*** New waypoint ****/
3063 static gpointer
tool_new_waypoint_create ( VikWindow
*vw
, VikViewport
*vvp
)
3068 static gboolean
tool_new_waypoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
)
3071 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
3073 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &coord
);
3074 if (vik_trw_layer_new_waypoint ( vtl
, VIK_GTK_WINDOW_FROM_LAYER(vtl
), &coord
) && VIK_LAYER(vtl
)->visible
)
3075 vik_layer_emit_update ( VIK_LAYER(vtl
) );
3080 /*** Edit trackpoint ****/
3082 static gpointer
tool_edit_trackpoint_create ( VikWindow
*vw
, VikViewport
*vvp
)
3084 tool_ed_t
*t
= g_new(tool_ed_t
, 1);
3090 static gboolean
tool_edit_trackpoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
3092 tool_ed_t
*t
= data
;
3093 VikViewport
*vvp
= t
->vvp
;
3094 TPSearchParams params
;
3095 /* OUTDATED DOCUMENTATION:
3096 find 5 pixel range on each side. then put these UTM, and a pointer
3097 to the winning track name (and maybe the winning track itself), and a
3098 pointer to the winning trackpoint, inside an array or struct. pass
3099 this along, do a foreach on the tracks which will do a foreach on the
3102 params
.x
= event
->x
;
3103 params
.y
= event
->y
;
3104 params
.closest_track_name
= NULL
;
3105 /* TODO: should get track listitem so we can break it up, make a new track, mess it up, all that. */
3106 params
.closest_tp
= NULL
;
3108 if ( event
->button
!= 1 )
3111 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
3114 if ( vtl
->current_tpl
)
3116 /* first check if it is within range of prev. tp. and if current_tp track is shown. (if it is, we are moving that trackpoint.) */
3117 VikTrackpoint
*tp
= VIK_TRACKPOINT(vtl
->current_tpl
->data
);
3118 VikTrack
*current_tr
= VIK_TRACK(g_hash_table_lookup(vtl
->tracks
, vtl
->current_tp_track_name
));
3120 g_assert ( current_tr
);
3122 vik_viewport_coord_to_screen ( vvp
, &(tp
->coord
), &x
, &y
);
3124 if ( current_tr
->visible
&&
3125 abs(x
- event
->x
) < TRACKPOINT_SIZE_APPROX
&&
3126 abs(y
- event
->y
) < TRACKPOINT_SIZE_APPROX
) {
3127 marker_begin_move ( t
, event
->x
, event
->y
);
3131 vtl
->last_tpl
= vtl
->current_tpl
;
3132 vtl
->last_tp_track_name
= vtl
->current_tp_track_name
;
3135 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) track_search_closest_tp
, ¶ms
);
3137 if ( params
.closest_tp
)
3139 vtl
->current_tpl
= params
.closest_tpl
;
3140 vtl
->current_tp_track_name
= params
.closest_track_name
;
3141 vik_treeview_select_iter ( VIK_LAYER(vtl
)->vt
, g_hash_table_lookup ( vtl
->tracks_iters
, vtl
->current_tp_track_name
) );
3142 trw_layer_tpwin_init ( vtl
);
3143 vik_layer_emit_update ( VIK_LAYER(vtl
) );
3147 /* these aren't the droids you're looking for */
3151 static gboolean
tool_edit_trackpoint_move ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
3153 tool_ed_t
*t
= data
;
3154 VikViewport
*vvp
= t
->vvp
;
3156 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
3162 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &new_coord
);
3165 if ( event
->state
& GDK_CONTROL_MASK
)
3167 VikTrackpoint
*tp
= closest_tp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
3168 if ( tp
&& tp
!= vtl
->current_tpl
->data
)
3169 new_coord
= tp
->coord
;
3171 // VIK_TRACKPOINT(vtl->current_tpl->data)->coord = new_coord;
3174 vik_viewport_coord_to_screen ( vvp
, &new_coord
, &x
, &y
);
3175 marker_moveto ( t
, x
, y
);
3183 static gboolean
tool_edit_trackpoint_release ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
3185 tool_ed_t
*t
= data
;
3186 VikViewport
*vvp
= t
->vvp
;
3188 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
3190 if ( event
->button
!= 1)
3195 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &new_coord
);
3198 if ( event
->state
& GDK_CONTROL_MASK
)
3200 VikTrackpoint
*tp
= closest_tp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
3201 if ( tp
&& tp
!= vtl
->current_tpl
->data
)
3202 new_coord
= tp
->coord
;
3205 VIK_TRACKPOINT(vtl
->current_tpl
->data
)->coord
= new_coord
;
3207 marker_end_move ( t
);
3209 /* diff dist is diff from orig */
3210 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
, vtl
->current_tp_track_name
);
3211 /* can't join with itself! */
3212 trw_layer_cancel_last_tp ( vtl
);
3214 vik_layer_emit_update ( VIK_LAYER(vtl
) );
3221 /*** Magic Scissors ***/
3222 static gpointer
tool_magic_scissors_create ( VikWindow
*vw
, VikViewport
*vvp
)
3227 static gboolean
tool_magic_scissors_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
)
3230 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &tmp
);
3231 if ( vtl
->magic_scissors_started
) {
3232 struct LatLon start
, end
;
3234 vik_coord_to_latlon ( &(vtl
->magic_scissors_coord
), &start
);
3235 vik_coord_to_latlon ( &(tmp
), &end
);
3236 cmd
= g_strdup_printf(GOOGLE_DIRECTIONS_STRING
, start
.lat
, start
.lon
, end
.lat
, end
.lon
);
3237 a_babel_convert_from_shellcommand ( vtl
, cmd
, "google", NULL
, NULL
);
3239 vik_layer_emit_update ( VIK_LAYER(vtl
) );
3241 vtl
->magic_scissors_coord
= tmp
;
3243 vtl
->magic_scissors_started
= !vtl
->magic_scissors_started
;
3247 /*** Show picture ****/
3249 static gpointer
tool_show_picture_create ( VikWindow
*vw
, VikViewport
*vvp
)
3254 /* Params are: vvp, event, last match found or NULL */
3255 static void tool_show_picture_wp ( char *name
, VikWaypoint
*wp
, gpointer params
[2] )
3257 if ( wp
->image
&& wp
->visible
)
3259 gint x
, y
, slackx
, slacky
;
3260 GdkEventButton
*event
= (GdkEventButton
*) params
[1];
3262 vik_viewport_coord_to_screen ( VIK_VIEWPORT(params
[0]), &(wp
->coord
), &x
, &y
);
3263 slackx
= wp
->image_width
/ 2;
3264 slacky
= wp
->image_height
/ 2;
3265 if ( x
<= event
->x
+ slackx
&& x
>= event
->x
- slackx
3266 && y
<= event
->y
+ slacky
&& y
>= event
->y
- slacky
)
3268 params
[2] = wp
->image
; /* we've found a match. however continue searching
3269 * since we want to find the last match -- that
3270 * is, the match that was drawn last. */
3275 static gboolean
tool_show_picture_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
)
3277 gpointer params
[3] = { vvp
, event
, NULL
};
3278 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
3280 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) tool_show_picture_wp
, params
);
3283 /* thanks to the Gaim people for showing me ShellExecute and g_spawn_command_line_async */
3285 ShellExecute(NULL
, NULL
, (char *) params
[2], NULL
, ".\\", 0);
3288 gchar
*quoted_file
= g_shell_quote ( (gchar
*) params
[2] );
3289 gchar
*cmd
= g_strdup_printf ( "eog %s", quoted_file
);
3290 g_free ( quoted_file
);
3291 if ( ! g_spawn_command_line_async ( cmd
, &err
) )
3293 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), "Could not launch eog to open file." );
3294 g_error_free ( err
);
3297 #endif /* WINDOWS */
3298 return TRUE
; /* found a match */
3301 return FALSE
; /* go through other layers, searching for a match */
3304 /***************************************************************************
3306 ***************************************************************************/
3312 static void image_wp_make_list ( char *name
, VikWaypoint
*wp
, GSList
**pics
)
3314 if ( wp
->image
&& ( ! a_thumbnails_exists ( wp
->image
) ) )
3315 *pics
= g_slist_append ( *pics
, (gpointer
) g_strdup ( wp
->image
) );
3318 static void create_thumbnails_thread ( GSList
*pics
, gpointer threaddata
)
3320 guint total
= g_slist_length(pics
), done
= 0;
3323 a_thumbnails_create ( (gchar
*) pics
->data
);
3324 a_background_thread_progress ( threaddata
, ((gdouble
) ++done
) / total
);
3329 static void free_pics_slist ( GSList
*pics
)
3333 g_free ( pics
->data
);
3334 pics
= g_slist_delete_link ( pics
, pics
);
3338 static void trw_layer_verify_thumbnails ( VikTrwLayer
*vtl
, GtkWidget
*vp
)
3340 if ( ! vtl
->has_verified_thumbnails
)
3342 GSList
*pics
= NULL
;
3343 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) image_wp_make_list
, &pics
);
3346 gint len
= g_slist_length ( pics
);
3347 gchar
*tmp
= g_strdup_printf ( "Creating %d Image Thumbnails...", len
);
3348 a_background_thread ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), tmp
, (vik_thr_func
) create_thumbnails_thread
, pics
, (vik_thr_free_func
) free_pics_slist
, NULL
, len
);
3354 VikCoordMode
vik_trw_layer_get_coord_mode ( VikTrwLayer
*vtl
)
3356 return vtl
->coord_mode
;
3361 static void waypoint_convert ( const gchar
*name
, VikWaypoint
*wp
, VikCoordMode
*dest_mode
)
3363 vik_coord_convert ( &(wp
->coord
), *dest_mode
);
3366 static void track_convert ( const gchar
*name
, VikTrack
*tr
, VikCoordMode
*dest_mode
)
3368 vik_track_convert ( tr
, *dest_mode
);
3371 static void trw_layer_change_coord_mode ( VikTrwLayer
*vtl
, VikCoordMode dest_mode
)
3373 if ( vtl
->coord_mode
!= dest_mode
)
3375 vtl
->coord_mode
= dest_mode
;
3376 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) waypoint_convert
, &dest_mode
);
3377 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) track_convert
, &dest_mode
);
3381 VikWaypoint
*vik_trw_layer_get_waypoint ( VikTrwLayer
*vtl
, gchar
*name
)
3383 return g_hash_table_lookup ( vtl
->waypoints
, name
);
3386 VikTrack
*vik_trw_layer_get_track ( VikTrwLayer
*vtl
, gchar
*name
)
3388 return g_hash_table_lookup ( vtl
->tracks
, name
);
3391 static void vik_trw_layer_set_menu_selection(VikTrwLayer
*vtl
, guint16 selection
)
3393 vtl
->menu_selection
= selection
;
3396 static guint16
vik_trw_layer_get_menu_selection(VikTrwLayer
*vtl
)
3398 return(vtl
->menu_selection
);
3401 /* ----------- Downloading maps along tracks --------------- */
3403 static int get_download_area_width(VikViewport
*vvp
, gdouble zoom_level
, struct LatLon
*wh
)
3405 /* TODO: calculating based on current size of viewport */
3406 const gdouble w_at_zoom_0_125
= 0.0013;
3407 const gdouble h_at_zoom_0_125
= 0.0011;
3408 gdouble zoom_factor
= zoom_level
/0.125;
3410 wh
->lat
= h_at_zoom_0_125
* zoom_factor
;
3411 wh
->lon
= w_at_zoom_0_125
* zoom_factor
;
3413 return 0; /* all OK */
3416 static VikCoord
*get_next_coord(VikCoord
*from
, VikCoord
*to
, struct LatLon
*dist
, gdouble gradient
)
3418 if ((dist
->lon
>= ABS(to
->east_west
- from
->east_west
)) &&
3419 (dist
->lat
>= ABS(to
->north_south
- from
->north_south
)))
3422 VikCoord
*coord
= g_malloc(sizeof(VikCoord
));
3423 coord
->mode
= VIK_COORD_LATLON
;
3425 if (ABS(gradient
) < 1) {
3426 if (from
->east_west
> to
->east_west
)
3427 coord
->east_west
= from
->east_west
- dist
->lon
;
3429 coord
->east_west
= from
->east_west
+ dist
->lon
;
3430 coord
->north_south
= gradient
* (coord
->east_west
- from
->east_west
) + from
->north_south
;
3432 if (from
->north_south
> to
->north_south
)
3433 coord
->north_south
= from
->north_south
- dist
->lat
;
3435 coord
->north_south
= from
->north_south
+ dist
->lat
;
3436 coord
->east_west
= (1/gradient
) * (coord
->north_south
- from
->north_south
) + from
->north_south
;
3442 static GList
*add_fillins(GList
*list
, VikCoord
*from
, VikCoord
*to
, struct LatLon
*dist
)
3444 /* TODO: handle virtical track (to->east_west - from->east_west == 0) */
3445 gdouble gradient
= (to
->north_south
- from
->north_south
)/(to
->east_west
- from
->east_west
);
3447 VikCoord
*next
= from
;
3449 if ((next
= get_next_coord(next
, to
, dist
, gradient
)) == NULL
)
3451 list
= g_list_prepend(list
, next
);
3457 void vik_track_download_map(VikTrack
*tr
, VikMapsLayer
*vml
, VikViewport
*vvp
, gdouble zoom_level
)
3459 typedef struct _Rect
{
3464 #define GLRECT(iter) ((Rect *)((iter)->data))
3467 GList
*rects_to_download
= NULL
;
3470 if (get_download_area_width(vvp
, zoom_level
, &wh
))
3473 GList
*iter
= tr
->trackpoints
;
3477 gboolean new_map
= TRUE
;
3478 VikCoord
*cur_coord
, tl
, br
;
3481 cur_coord
= &(VIK_TRACKPOINT(iter
->data
))->coord
;
3483 vik_coord_set_area(cur_coord
, &wh
, &tl
, &br
);
3484 rect
= g_malloc(sizeof(Rect
));
3487 rect
->center
= *cur_coord
;
3488 rects_to_download
= g_list_prepend(rects_to_download
, rect
);
3493 gboolean found
= FALSE
;
3494 for (rect_iter
= rects_to_download
; rect_iter
; rect_iter
= rect_iter
->next
) {
3495 if (vik_coord_inside(cur_coord
, &GLRECT(rect_iter
)->tl
, &GLRECT(rect_iter
)->br
)) {
3506 /* fill-ins for far apart points */
3507 GList
*cur_rect
, *next_rect
;
3508 GList
*fillins
= NULL
;
3509 for (cur_rect
= rects_to_download
;
3510 (next_rect
= cur_rect
->next
) != NULL
;
3511 cur_rect
= cur_rect
->next
) {
3512 if ((wh
.lon
< ABS(GLRECT(cur_rect
)->center
.east_west
- GLRECT(next_rect
)->center
.east_west
)) ||
3513 (wh
.lat
< ABS(GLRECT(cur_rect
)->center
.north_south
- GLRECT(next_rect
)->center
.north_south
))) {
3514 fillins
= add_fillins(fillins
, &GLRECT(cur_rect
)->center
, &GLRECT(next_rect
)->center
, &wh
);
3519 GList
*iter
= fillins
;
3521 cur_coord
= (VikCoord
*)(iter
->data
);
3522 vik_coord_set_area(cur_coord
, &wh
, &tl
, &br
);
3523 rect
= g_malloc(sizeof(Rect
));
3526 rect
->center
= *cur_coord
;
3527 rects_to_download
= g_list_prepend(rects_to_download
, rect
);
3532 for (rect_iter
= rects_to_download
; rect_iter
; rect_iter
= rect_iter
->next
) {
3533 maps_layer_download_section_without_redraw(vml
, vvp
, &(((Rect
*)(rect_iter
->data
))->tl
), &(((Rect
*)(rect_iter
->data
))->br
), zoom_level
);
3537 for (iter
= fillins
; iter
; iter
= iter
->next
)
3539 g_list_free(fillins
);
3541 if (rects_to_download
) {
3542 for (rect_iter
= rects_to_download
; rect_iter
; rect_iter
= rect_iter
->next
)
3543 g_free(rect_iter
->data
);
3544 g_list_free(rects_to_download
);
3548 static void trw_layer_download_map_along_track_cb(gpointer pass_along
[6])
3551 gint selected_map
, default_map
;
3552 gchar
*zoomlist
[] = {"0.125", "0.25", "0.5", "1", "2", "4", "8", "16", "32", "64", "128", "256", "512", "1024", NULL
};
3553 gdouble zoom_vals
[] = {0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
3554 gint selected_zoom
, default_zoom
;
3558 VikTrwLayer
*vtl
= pass_along
[0];
3559 VikLayersPanel
*vlp
= pass_along
[1];
3560 VikTrack
*tr
= (VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] );
3561 VikViewport
*vvp
= vik_window_viewport((VikWindow
*)(VIK_GTK_WINDOW_FROM_LAYER(vtl
)));
3563 GList
*vmls
= vik_layers_panel_get_all_layers_of_type(vlp
, VIK_LAYER_MAPS
);
3564 int num_maps
= g_list_length(vmls
);
3567 a_dialog_msg(VIK_GTK_WINDOW_FROM_LAYER(vtl
), GTK_MESSAGE_ERROR
,"No map layer in use. Create one first", NULL
);
3571 gchar
**map_names
= g_malloc(1 + num_maps
* sizeof(gpointer
));
3572 VikMapsLayer
**map_layers
= g_malloc(1 + num_maps
* sizeof(gpointer
));
3574 gchar
**np
= map_names
;
3575 VikMapsLayer
**lp
= map_layers
;
3576 for (i
= 0; i
< num_maps
; i
++) {
3577 gboolean dup
= FALSE
;
3578 vml
= (VikMapsLayer
*)(vmls
->data
);
3579 for (j
= 0; j
< i
; j
++) { /* no duplicate allowed */
3580 if (vik_maps_layer_get_map_type(vml
) == vik_maps_layer_get_map_type(map_layers
[j
])) {
3587 *np
++ = vik_maps_layer_get_map_label(vml
);
3593 num_maps
= lp
- map_layers
;
3595 for (default_map
= 0; default_map
< num_maps
; default_map
++) {
3596 /* TODO: check for parent layer's visibility */
3597 if (VIK_LAYER(map_layers
[default_map
])->visible
)
3600 default_map
= (default_map
== num_maps
) ? 0 : default_map
;
3602 gdouble cur_zoom
= vik_viewport_get_zoom(vvp
);
3603 for (default_zoom
= 0; default_zoom
< sizeof(zoom_vals
)/sizeof(gdouble
); default_zoom
++) {
3604 if (cur_zoom
== zoom_vals
[default_zoom
])
3607 default_zoom
= (default_zoom
== sizeof(zoom_vals
)/sizeof(gdouble
)) ? sizeof(zoom_vals
)/sizeof(gdouble
) - 1 : default_zoom
;
3609 if (!a_dialog_map_n_zoom(VIK_GTK_WINDOW_FROM_LAYER(vtl
), map_names
, default_map
, zoomlist
, default_zoom
, &selected_map
, &selected_zoom
))
3612 vik_track_download_map(tr
, map_layers
[selected_map
], vvp
, zoom_vals
[selected_zoom
]);
3615 for (i
= 0; i
< num_maps
; i
++)
3616 g_free(map_names
[i
]);