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 */
28 #include "vikmapslayer.h"
29 #include "viktrwlayer_pixmap.h"
30 #include "viktrwlayer_tpwin.h"
31 #include "viktrwlayer_propwin.h"
32 #include "garminsymbols.h"
33 #include "thumbnails.h"
34 #include "background.h"
46 #define GOOGLE_DIRECTIONS_STRING "(wget -O - \"http://maps.google.com/maps?q=%f,%f to %f,%f&output=js\" 2>/dev/null)"
47 #define VIK_TRW_LAYER_TRACK_GC 13
48 #define VIK_TRW_LAYER_TRACK_GC_RATES 10
49 #define VIK_TRW_LAYER_TRACK_GC_MIN 0
50 #define VIK_TRW_LAYER_TRACK_GC_MAX 11
51 #define VIK_TRW_LAYER_TRACK_GC_BLACK 12
53 #define DRAWMODE_BY_TRACK 0
54 #define DRAWMODE_BY_VELOCITY 1
55 #define DRAWMODE_ALL_BLACK 2
60 /* this is how it knows when you click if you are clicking close to a trackpoint. */
61 #define TRACKPOINT_SIZE_APPROX 5
62 #define WAYPOINT_SIZE_APPROX 5
64 #define MIN_STOP_LENGTH 15
65 #define MAX_STOP_LENGTH 86400
66 #define DRAW_ELEVATION_FACTOR 30 /* height of elevation plotting, sort of relative to zoom level ("mpp" that isn't mpp necessarily) */
67 /* this is multiplied by user-inputted value from 1-100. */
69 VIK_TRW_LAYER_SUBLAYER_TRACKS
,
70 VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
,
71 VIK_TRW_LAYER_SUBLAYER_TRACK
,
72 VIK_TRW_LAYER_SUBLAYER_WAYPOINT
75 enum { WP_SYMBOL_FILLED_SQUARE
, WP_SYMBOL_SQUARE
, WP_SYMBOL_CIRCLE
, WP_SYMBOL_X
, WP_NUM_SYMBOLS
};
80 GHashTable
*tracks_iters
;
81 GHashTable
*waypoints_iters
;
82 GHashTable
*waypoints
;
83 GtkTreeIter waypoints_iter
, tracks_iter
;
84 gboolean tracks_visible
, waypoints_visible
;
88 guint8 elevation_factor
;
92 guint8 line_thickness
;
93 guint8 bg_line_thickness
;
97 gboolean wp_draw_symbols
;
99 gdouble velocity_min
, velocity_max
;
101 guint16 track_gc_iter
;
104 GdkGC
*waypoint_text_gc
;
105 GdkGC
*waypoint_bg_gc
;
106 GdkFont
*waypoint_font
;
107 VikTrack
*current_track
;
108 guint16 ct_x1
, ct_y1
, ct_x2
, ct_y2
;
110 VikCoordMode coord_mode
;
112 /* wp editing tool */
113 VikWaypoint
*current_wp
;
114 gchar
*current_wp_name
;
116 gboolean waypoint_rightclick
;
118 /* track editing tool */
120 gchar
*current_tp_track_name
;
121 VikTrwLayerTpwin
*tpwin
;
123 /* weird hack for joining tracks */
125 gchar
*last_tp_track_name
;
127 /* track editing tool -- more specifically, moving tps */
130 /* magic scissors tool */
131 gboolean magic_scissors_started
;
132 VikCoord magic_scissors_coord
;
139 guint16 image_cache_size
;
141 /* for waypoint text */
142 PangoLayout
*wplabellayout
;
144 gboolean has_verified_thumbnails
;
146 GtkMenu
*wp_right_click_menu
;
149 VikStdLayerMenuItem menu_selection
;
153 /* A caached waypoint image. */
156 gchar
*image
; /* filename */
159 struct DrawingParams
{
163 guint16 width
, height
;
164 const VikCoord
*center
;
166 gboolean one_zone
, lat_lon
;
167 gdouble ce1
, ce2
, cn1
, cn2
;
170 static void vik_trw_layer_set_menu_selection(VikTrwLayer
*vtl
, guint16
);
171 static guint16
vik_trw_layer_get_menu_selection(VikTrwLayer
*vtl
);
173 static void trw_layer_delete_item ( gpointer
*pass_along
);
174 static void trw_layer_copy_item_cb( gpointer
*pass_along
);
175 static void trw_layer_cut_item_cb( gpointer
*pass_along
);
177 static void trw_layer_find_maxmin_waypoints ( const gchar
*name
, const VikWaypoint
*w
, struct LatLon maxmin
[2] );
178 static void trw_layer_find_maxmin_tracks ( const gchar
*name
, GList
**t
, struct LatLon maxmin
[2] );
180 static void trw_layer_new_track_gcs ( VikTrwLayer
*vtl
, VikViewport
*vp
);
181 static void trw_layer_free_track_gcs ( VikTrwLayer
*vtl
);
183 static gint
calculate_velocity ( VikTrwLayer
*vtl
, VikTrackpoint
*tp1
, VikTrackpoint
*tp2
);
184 static void trw_layer_draw_track_cb ( const gchar
*name
, VikTrack
*track
, struct DrawingParams
*dp
);
185 static void trw_layer_draw_waypoint ( const gchar
*name
, VikWaypoint
*wp
, struct DrawingParams
*dp
);
187 static void goto_coord ( VikLayersPanel
*vlp
, const VikCoord
*coord
);
188 static void trw_layer_goto_track_startpoint ( gpointer pass_along
[5] );
189 static void trw_layer_goto_track_endpoint ( gpointer pass_along
[6] );
190 static void trw_layer_merge_by_timestamp ( gpointer pass_along
[6] );
191 static void trw_layer_split_by_timestamp ( gpointer pass_along
[6] );
192 static void trw_layer_download_map_along_track_cb(gpointer pass_along
[6]);
193 static void trw_layer_centerize ( gpointer layer_and_vlp
[2] );
194 static void trw_layer_export ( gpointer layer_and_vlp
[2], guint file_type
);
195 static void trw_layer_goto_wp ( gpointer layer_and_vlp
[2] );
196 static void trw_layer_new_wp ( gpointer lav
[2] );
199 static void trw_layer_properties_item ( gpointer pass_along
[5] );
200 static void trw_layer_goto_waypoint ( gpointer pass_along
[5] );
201 static void trw_layer_waypoint_gc_webpage ( gpointer pass_along
[5] );
203 static void trw_layer_realize_waypoint ( gchar
*name
, VikWaypoint
*wp
, gpointer pass_along
[4] );
204 static void trw_layer_realize_track ( gchar
*name
, VikTrack
*track
, gpointer pass_along
[4] );
205 static void init_drawing_params ( struct DrawingParams
*dp
, VikViewport
*vp
);
208 static VikTrwLayer
*trw_layer_copy ( VikTrwLayer
*vtl
, gpointer vp
);
209 static void trw_layer_marshall( VikTrwLayer
*vtl
, guint8
**data
, gint
*len
);
210 static VikTrwLayer
*trw_layer_unmarshall( gpointer data
, gint len
, VikViewport
*vvp
);
212 static gboolean
trw_layer_set_param ( VikTrwLayer
*vtl
, guint16 id
, VikLayerParamData data
, VikViewport
*vp
);
213 static VikLayerParamData
trw_layer_get_param ( VikTrwLayer
*vtl
, guint16 id
);
215 static void trw_layer_del_item ( VikTrwLayer
*vtl
, gint subtype
, gpointer sublayer
);
216 static void trw_layer_copy_item ( VikTrwLayer
*vtl
, gint subtype
, gpointer sublayer
, guint8
**item
, guint
*len
);
217 static gboolean
trw_layer_paste_item ( VikTrwLayer
*vtl
, gint subtype
, guint8
*item
, guint len
);
218 static void trw_layer_free_copied_item ( gint subtype
, gpointer item
);
219 static void trw_layer_drag_drop_request ( VikTrwLayer
*vtl_src
, VikTrwLayer
*vtl_dest
, GtkTreeIter
*src_item_iter
, GtkTreePath
*dest_path
);
221 static void trw_layer_cancel_tps_of_track ( VikTrwLayer
*vtl
, const gchar
*trk_name
);
222 static void trw_layer_cancel_last_tp ( VikTrwLayer
*vtl
);
223 static void trw_layer_cancel_current_tp ( VikTrwLayer
*vtl
, gboolean destroy
);
224 static void trw_layer_tpwin_response ( VikTrwLayer
*vtl
, gint response
);
225 static void trw_layer_tpwin_init ( VikTrwLayer
*vtl
);
227 static gpointer
tool_edit_trackpoint_create ( VikWindow
*vw
, VikViewport
*vvp
);
228 static gboolean
tool_edit_trackpoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
229 static gboolean
tool_edit_trackpoint_move ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
230 static gboolean
tool_edit_trackpoint_release ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
231 static gpointer
tool_show_picture_create ( VikWindow
*vw
, VikViewport
*vvp
);
232 static gboolean
tool_show_picture_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
);
233 static gpointer
tool_edit_waypoint_create ( VikWindow
*vw
, VikViewport
*vvp
);
234 static gboolean
tool_edit_waypoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
235 static gboolean
tool_edit_waypoint_move ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
236 static gboolean
tool_edit_waypoint_release ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
);
237 static gpointer
tool_new_track_create ( VikWindow
*vw
, VikViewport
*vvp
);
238 static gboolean
tool_new_track_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
);
239 static gpointer
tool_new_waypoint_create ( VikWindow
*vw
, VikViewport
*vvp
);
240 static gboolean
tool_new_waypoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
);
241 static gpointer
tool_magic_scissors_create ( VikWindow
*vw
, VikViewport
*vvp
);
242 static gboolean
tool_magic_scissors_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
);
245 static gboolean
uppercase_exists_in_hash ( GHashTable
*hash
, const gchar
*str
);
247 static void cached_pixbuf_free ( CachedPixbuf
*cp
);
248 static gint
cached_pixbuf_cmp ( CachedPixbuf
*cp
, const gchar
*name
);
249 static void trw_layer_verify_thumbnails ( VikTrwLayer
*vtl
, GtkWidget
*vp
);
251 static VikTrackpoint
*closest_tp_in_five_pixel_interval ( VikTrwLayer
*vtl
, VikViewport
*vvp
, gint x
, gint y
);
252 static VikWaypoint
*closest_wp_in_five_pixel_interval ( VikTrwLayer
*vtl
, VikViewport
*vvp
, gint x
, gint y
);
254 static void trw_layer_change_coord_mode ( VikTrwLayer
*vtl
, VikCoordMode dest_mode
);
256 static gchar
*get_new_unique_sublayer_name (VikTrwLayer
*vtl
, gint sublayer_type
, const gchar
*name
);
257 static void waypoint_convert ( const gchar
*name
, VikWaypoint
*wp
, VikCoordMode
*dest_mode
);
258 static void track_convert ( const gchar
*name
, VikTrack
*tr
, VikCoordMode
*dest_mode
);
260 static VikToolInterface trw_layer_tools
[] = {
261 { "Create Waypoint", (VikToolConstructorFunc
) tool_new_waypoint_create
, NULL
, NULL
, NULL
,
262 (VikToolMouseFunc
) tool_new_waypoint_click
, NULL
, NULL
},
264 { "Create Track", (VikToolConstructorFunc
) tool_new_track_create
, NULL
, NULL
, NULL
,
265 (VikToolMouseFunc
) tool_new_track_click
, NULL
, NULL
},
267 { "Edit Waypoint", (VikToolConstructorFunc
) tool_edit_waypoint_create
, NULL
, NULL
, NULL
,
268 (VikToolMouseFunc
) tool_edit_waypoint_click
,
269 (VikToolMouseFunc
) tool_edit_waypoint_move
,
270 (VikToolMouseFunc
) tool_edit_waypoint_release
},
272 { "Edit Trackpoint", (VikToolConstructorFunc
) tool_edit_trackpoint_create
, NULL
, NULL
, NULL
,
273 (VikToolMouseFunc
) tool_edit_trackpoint_click
,
274 (VikToolMouseFunc
) tool_edit_trackpoint_move
,
275 (VikToolMouseFunc
) tool_edit_trackpoint_release
},
277 { "Show Picture", (VikToolConstructorFunc
) tool_show_picture_create
, NULL
, NULL
, NULL
,
278 (VikToolMouseFunc
) tool_show_picture_click
, NULL
, NULL
},
280 { "Magic Scissors", (VikToolConstructorFunc
) tool_magic_scissors_create
, NULL
, NULL
, NULL
,
281 (VikToolMouseFunc
) tool_magic_scissors_click
, NULL
, NULL
},
284 /****** PARAMETERS ******/
286 static gchar
*params_groups
[] = { "Waypoints", "Tracks", "Waypoint Images" };
287 enum { GROUP_WAYPOINTS
, GROUP_TRACKS
, GROUP_IMAGES
};
289 static gchar
*params_drawmodes
[] = { "Draw by Track", "Draw by Velocity", "All Tracks Black", 0 };
290 static gchar
*params_wpsymbols
[] = { "Filled Square", "Square", "Circle", "X", 0 };
293 static VikLayerParamScale params_scales
[] = {
294 /* min max step digits */
295 { 1, 10, 1, 0 }, /* line_thickness */
296 { 0.0, 99.0, 1, 2 }, /* velocity_min */
297 { 1.0, 100.0, 1.0, 2 }, /* velocity_max */
298 /* 5 * step == how much to turn */
299 { 16, 128, 3.2, 0 }, /* image_size */
300 { 0, 255, 5, 0 }, /* image alpha */
301 { 5, 500, 5, 0 }, /* image cache_size */
302 { 0, 8, 1, 0 }, /* image cache_size */
303 { 1, 64, 1, 0 }, /* wpsize */
304 { MIN_STOP_LENGTH
, MAX_STOP_LENGTH
, 1, 0 }, /* stop_length */
305 { 1, 100, 1, 0 }, /* stop_length */
308 VikLayerParam trw_layer_params
[] = {
309 { "tracks_visible", VIK_LAYER_PARAM_BOOLEAN
, VIK_LAYER_NOT_IN_PROPERTIES
},
310 { "waypoints_visible", VIK_LAYER_PARAM_BOOLEAN
, VIK_LAYER_NOT_IN_PROPERTIES
},
312 { "drawmode", VIK_LAYER_PARAM_UINT
, GROUP_TRACKS
, "Track Drawing Mode:", VIK_LAYER_WIDGET_RADIOGROUP
, NULL
},
313 { "drawlines", VIK_LAYER_PARAM_BOOLEAN
, GROUP_TRACKS
, "Draw Track Lines", VIK_LAYER_WIDGET_CHECKBUTTON
},
314 { "drawpoints", VIK_LAYER_PARAM_BOOLEAN
, GROUP_TRACKS
, "Draw Trackpoints", VIK_LAYER_WIDGET_CHECKBUTTON
},
315 { "drawelevation", VIK_LAYER_PARAM_BOOLEAN
, GROUP_TRACKS
, "Draw Elevation", VIK_LAYER_WIDGET_CHECKBUTTON
},
316 { "elevation_factor", VIK_LAYER_PARAM_UINT
, GROUP_TRACKS
, "Draw Elevation Height %:", VIK_LAYER_WIDGET_HSCALE
, params_scales
+ 9 },
318 { "drawstops", VIK_LAYER_PARAM_BOOLEAN
, GROUP_TRACKS
, "Draw Stops", VIK_LAYER_WIDGET_CHECKBUTTON
},
319 { "stop_length", VIK_LAYER_PARAM_UINT
, GROUP_TRACKS
, "Min Stop Length (seconds):", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 8 },
321 { "line_thickness", VIK_LAYER_PARAM_UINT
, GROUP_TRACKS
, "Track Thickness:", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 0 },
322 { "bg_line_thickness", VIK_LAYER_PARAM_UINT
, GROUP_TRACKS
, "Track BG Thickness:", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 6 },
323 { "trackbgcolor", VIK_LAYER_PARAM_COLOR
, GROUP_TRACKS
, "Track Background Color", VIK_LAYER_WIDGET_COLOR
, 0 },
324 { "velocity_min", VIK_LAYER_PARAM_DOUBLE
, GROUP_TRACKS
, "Min Track Velocity:", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 1 },
325 { "velocity_max", VIK_LAYER_PARAM_DOUBLE
, GROUP_TRACKS
, "Max Track Velocity:", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 2 },
327 { "drawlabels", VIK_LAYER_PARAM_BOOLEAN
, GROUP_WAYPOINTS
, "Draw Labels", VIK_LAYER_WIDGET_CHECKBUTTON
},
328 { "wpcolor", VIK_LAYER_PARAM_COLOR
, GROUP_WAYPOINTS
, "Waypoint Color:", VIK_LAYER_WIDGET_COLOR
, 0 },
329 { "wptextcolor", VIK_LAYER_PARAM_COLOR
, GROUP_WAYPOINTS
, "Waypoint Text:", VIK_LAYER_WIDGET_COLOR
, 0 },
330 { "wpbgcolor", VIK_LAYER_PARAM_COLOR
, GROUP_WAYPOINTS
, "Background:", VIK_LAYER_WIDGET_COLOR
, 0 },
331 { "wpbgand", VIK_LAYER_PARAM_BOOLEAN
, GROUP_WAYPOINTS
, "Fake BG Color Translucency:", VIK_LAYER_WIDGET_CHECKBUTTON
, 0 },
332 { "wpsymbol", VIK_LAYER_PARAM_UINT
, GROUP_WAYPOINTS
, "Waypoint marker:", VIK_LAYER_WIDGET_RADIOGROUP
, NULL
},
333 { "wpsize", VIK_LAYER_PARAM_UINT
, GROUP_WAYPOINTS
, "Waypoint size:", VIK_LAYER_WIDGET_SPINBUTTON
, params_scales
+ 7 },
334 { "wpsyms", VIK_LAYER_PARAM_BOOLEAN
, GROUP_WAYPOINTS
, "Draw Waypoint Symbols:", VIK_LAYER_WIDGET_CHECKBUTTON
},
336 { "drawimages", VIK_LAYER_PARAM_BOOLEAN
, GROUP_IMAGES
, "Draw Waypoint Images", VIK_LAYER_WIDGET_CHECKBUTTON
},
337 { "image_size", VIK_LAYER_PARAM_UINT
, GROUP_IMAGES
, "Image Size (pixels):", VIK_LAYER_WIDGET_HSCALE
, params_scales
+ 3 },
338 { "image_alpha", VIK_LAYER_PARAM_UINT
, GROUP_IMAGES
, "Image Alpha:", VIK_LAYER_WIDGET_HSCALE
, params_scales
+ 4 },
339 { "image_cache_size", VIK_LAYER_PARAM_UINT
, GROUP_IMAGES
, "Image Memory Cache Size:", VIK_LAYER_WIDGET_HSCALE
, params_scales
+ 5 },
342 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
};
345 *** 1) Add to trw_layer_params and enumeration
346 *** 2) Handle in get_param & set_param (presumably adding on to VikTrwLayer struct)
349 /****** END PARAMETERS ******/
351 VikLayerInterface vik_trw_layer_interface
= {
356 sizeof(trw_layer_tools
) / sizeof(VikToolInterface
),
360 params_groups
, /* params_groups */
361 sizeof(params_groups
)/sizeof(params_groups
[0]), /* number of groups */
365 (VikLayerFuncCreate
) vik_trw_layer_create
,
366 (VikLayerFuncRealize
) vik_trw_layer_realize
,
367 (VikLayerFuncPostRead
) trw_layer_verify_thumbnails
,
368 (VikLayerFuncFree
) vik_trw_layer_free
,
370 (VikLayerFuncProperties
) NULL
,
371 (VikLayerFuncDraw
) vik_trw_layer_draw
,
372 (VikLayerFuncChangeCoordMode
) trw_layer_change_coord_mode
,
374 (VikLayerFuncSetMenuItemsSelection
) vik_trw_layer_set_menu_selection
,
375 (VikLayerFuncGetMenuItemsSelection
) vik_trw_layer_get_menu_selection
,
377 (VikLayerFuncAddMenuItems
) vik_trw_layer_add_menu_items
,
378 (VikLayerFuncSublayerAddMenuItems
) vik_trw_layer_sublayer_add_menu_items
,
380 (VikLayerFuncSublayerRenameRequest
) vik_trw_layer_sublayer_rename_request
,
381 (VikLayerFuncSublayerToggleVisible
) vik_trw_layer_sublayer_toggle_visible
,
383 (VikLayerFuncCopy
) trw_layer_copy
,
384 (VikLayerFuncMarshall
) trw_layer_marshall
,
385 (VikLayerFuncUnmarshall
) trw_layer_unmarshall
,
387 (VikLayerFuncSetParam
) trw_layer_set_param
,
388 (VikLayerFuncGetParam
) trw_layer_get_param
,
390 (VikLayerFuncReadFileData
) a_gpspoint_read_file
,
391 (VikLayerFuncWriteFileData
) a_gpspoint_write_file
,
393 (VikLayerFuncDeleteItem
) trw_layer_del_item
,
394 (VikLayerFuncCopyItem
) trw_layer_copy_item
,
395 (VikLayerFuncPasteItem
) trw_layer_paste_item
,
396 (VikLayerFuncFreeCopiedItem
) trw_layer_free_copied_item
,
398 (VikLayerFuncDragDropRequest
) trw_layer_drag_drop_request
,
401 /* for copy & paste (I think?) */
409 GType
vik_trw_layer_get_type ()
411 static GType vtl_type
= 0;
415 static const GTypeInfo vtl_info
=
417 sizeof (VikTrwLayerClass
),
418 NULL
, /* base_init */
419 NULL
, /* base_finalize */
420 NULL
, /* class init */
421 NULL
, /* class_finalize */
422 NULL
, /* class_data */
423 sizeof (VikTrwLayer
),
425 NULL
/* instance init */
427 vtl_type
= g_type_register_static ( VIK_LAYER_TYPE
, "VikTrwLayer", &vtl_info
, 0 );
433 static void trw_layer_del_item ( VikTrwLayer
*vtl
, gint subtype
, gpointer sublayer
)
435 static gpointer pass_along
[5];
441 pass_along
[1] = NULL
;
442 pass_along
[2] = (gpointer
) subtype
;
443 pass_along
[3] = sublayer
;
444 pass_along
[4] = NULL
;
446 trw_layer_delete_item ( pass_along
);
449 static void trw_layer_copy_item_cb( gpointer pass_along
[5])
451 VikTrwLayer
*vtl
= VIK_TRW_LAYER(pass_along
[0]);
452 gint subtype
= (gint
)pass_along
[2];
453 gpointer
* sublayer
= pass_along
[3];
457 trw_layer_copy_item( vtl
, subtype
, sublayer
, &data
, &len
);
460 a_clipboard_copy( VIK_CLIPBOARD_DATA_SUBLAYER
, VIK_LAYER_TRW
,
465 static void trw_layer_cut_item_cb( gpointer pass_along
[5])
467 trw_layer_copy_item_cb(pass_along
);
468 trw_layer_delete_item(pass_along
);
471 static void trw_layer_copy_item ( VikTrwLayer
*vtl
, gint subtype
, gpointer sublayer
, guint8
**item
, guint
*len
)
482 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
)
484 vik_waypoint_marshall ( g_hash_table_lookup ( vtl
->waypoints
, sublayer
), &id
, &il
);
486 vik_track_marshall ( g_hash_table_lookup ( vtl
->tracks
, sublayer
), &id
, &il
);
489 *len
= sizeof(FlatItem
) + strlen(sublayer
) + 1 + il
;
490 fi
= g_malloc ( *len
);
491 fi
->len
= strlen(sublayer
) + 1;
492 memcpy(fi
->data
, sublayer
, fi
->len
);
493 memcpy(fi
->data
+ fi
->len
, id
, il
);
495 *item
= (guint8
*)fi
;
498 static gboolean
trw_layer_paste_item ( VikTrwLayer
*vtl
, gint subtype
, guint8
*item
, guint len
)
500 FlatItem
*fi
= (FlatItem
*) item
;
502 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
&& fi
)
507 name
= get_new_unique_sublayer_name(vtl
, VIK_TRW_LAYER_SUBLAYER_WAYPOINT
, (gchar
*)fi
->data
);
508 w
= vik_waypoint_unmarshall(fi
->data
+ fi
->len
, len
- sizeof(*fi
) - fi
->len
);
509 vik_trw_layer_add_waypoint ( vtl
, name
, w
);
510 waypoint_convert(name
, w
, &vtl
->coord_mode
);
513 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_TRACK
&& fi
)
517 name
= get_new_unique_sublayer_name(vtl
, VIK_TRW_LAYER_SUBLAYER_TRACK
, (gchar
*)fi
->data
);
518 t
= vik_track_unmarshall(fi
->data
+ fi
->len
, len
- sizeof(*fi
) - fi
->len
);
519 vik_trw_layer_add_track ( vtl
, name
, t
);
520 track_convert(name
, t
, &vtl
->coord_mode
);
526 static void trw_layer_free_copied_item ( gint subtype
, gpointer item
)
533 static void waypoint_copy ( const gchar
*name
, VikWaypoint
*wp
, GHashTable
*dest
)
535 g_hash_table_insert ( dest
, g_strdup(name
), vik_waypoint_copy(wp
) );
538 static gboolean
trw_layer_set_param ( VikTrwLayer
*vtl
, guint16 id
, VikLayerParamData data
, VikViewport
*vp
)
542 case PARAM_TV
: vtl
->tracks_visible
= data
.b
; break;
543 case PARAM_WV
: vtl
->waypoints_visible
= data
.b
; break;
544 case PARAM_DM
: vtl
->drawmode
= data
.u
; break;
545 case PARAM_DP
: vtl
->drawpoints
= data
.b
; break;
546 case PARAM_DE
: vtl
->drawelevation
= data
.b
; break;
547 case PARAM_DS
: vtl
->drawstops
= data
.b
; break;
548 case PARAM_DL
: vtl
->drawlines
= data
.b
; break;
549 case PARAM_SL
: if ( data
.u
>= MIN_STOP_LENGTH
&& data
.u
<= MAX_STOP_LENGTH
)
550 vtl
->stop_length
= data
.u
;
552 case PARAM_EF
: if ( data
.u
>= 1 && data
.u
<= 100 )
553 vtl
->elevation_factor
= data
.u
;
555 case PARAM_LT
: if ( data
.u
> 0 && data
.u
< 15 && data
.u
!= vtl
->line_thickness
)
557 vtl
->line_thickness
= data
.u
;
558 trw_layer_new_track_gcs ( vtl
, vp
);
561 case PARAM_BLT
: if ( data
.u
> 0 && data
.u
<= 8 && data
.u
!= vtl
->bg_line_thickness
)
563 vtl
->bg_line_thickness
= data
.u
;
564 trw_layer_new_track_gcs ( vtl
, vp
);
567 case PARAM_VMIN
: vtl
->velocity_min
= data
.d
; break;
568 case PARAM_VMAX
: vtl
->velocity_max
= data
.d
; break;
569 case PARAM_TBGC
: gdk_gc_set_rgb_fg_color(vtl
->track_bg_gc
, &(data
.c
)); break;
570 case PARAM_DLA
: vtl
->drawlabels
= data
.b
; break;
571 case PARAM_DI
: vtl
->drawimages
= data
.b
; break;
572 case PARAM_IS
: if ( data
.u
!= vtl
->image_size
)
574 vtl
->image_size
= data
.u
;
575 g_list_foreach ( vtl
->image_cache
->head
, (GFunc
) cached_pixbuf_free
, NULL
);
576 g_queue_free ( vtl
->image_cache
);
577 vtl
->image_cache
= g_queue_new ();
580 case PARAM_IA
: vtl
->image_alpha
= data
.u
; break;
581 case PARAM_ICS
: vtl
->image_cache_size
= data
.u
;
582 while ( vtl
->image_cache
->length
> vtl
->image_cache_size
) /* if shrinking cache_size, free pixbuf ASAP */
583 cached_pixbuf_free ( g_queue_pop_tail ( vtl
->image_cache
) );
585 case PARAM_WPC
: gdk_gc_set_rgb_fg_color(vtl
->waypoint_gc
, &(data
.c
)); break;
586 case PARAM_WPTC
: gdk_gc_set_rgb_fg_color(vtl
->waypoint_text_gc
, &(data
.c
)); break;
587 case PARAM_WPBC
: gdk_gc_set_rgb_fg_color(vtl
->waypoint_bg_gc
, &(data
.c
)); break;
588 case PARAM_WPBA
: gdk_gc_set_function(vtl
->waypoint_bg_gc
, data
.b
? GDK_AND
: GDK_COPY
); break;
589 case PARAM_WPSYM
: if ( data
.u
< WP_NUM_SYMBOLS
) vtl
->wp_symbol
= data
.u
; break;
590 case PARAM_WPSIZE
: if ( data
.u
> 0 && data
.u
<= 64 ) vtl
->wp_size
= data
.u
; break;
591 case PARAM_WPSYMS
: vtl
->wp_draw_symbols
= data
.b
; break;
596 static VikLayerParamData
trw_layer_get_param ( VikTrwLayer
*vtl
, guint16 id
)
598 VikLayerParamData rv
;
601 case PARAM_TV
: rv
.b
= vtl
->tracks_visible
; break;
602 case PARAM_WV
: rv
.b
= vtl
->waypoints_visible
; break;
603 case PARAM_DM
: rv
.u
= vtl
->drawmode
; break;
604 case PARAM_DP
: rv
.b
= vtl
->drawpoints
; break;
605 case PARAM_DE
: rv
.b
= vtl
->drawelevation
; break;
606 case PARAM_EF
: rv
.u
= vtl
->elevation_factor
; break;
607 case PARAM_DS
: rv
.b
= vtl
->drawstops
; break;
608 case PARAM_SL
: rv
.u
= vtl
->stop_length
; break;
609 case PARAM_DL
: rv
.b
= vtl
->drawlines
; break;
610 case PARAM_LT
: rv
.u
= vtl
->line_thickness
; break;
611 case PARAM_BLT
: rv
.u
= vtl
->bg_line_thickness
; break;
612 case PARAM_VMIN
: rv
.d
= vtl
->velocity_min
; break;
613 case PARAM_VMAX
: rv
.d
= vtl
->velocity_max
; break;
614 case PARAM_DLA
: rv
.b
= vtl
->drawlabels
; break;
615 case PARAM_DI
: rv
.b
= vtl
->drawimages
; break;
616 case PARAM_TBGC
: vik_gc_get_fg_color(vtl
->track_bg_gc
, &(rv
.c
)); break;
617 case PARAM_IS
: rv
.u
= vtl
->image_size
; break;
618 case PARAM_IA
: rv
.u
= vtl
->image_alpha
; break;
619 case PARAM_ICS
: rv
.u
= vtl
->image_cache_size
; break;
620 case PARAM_WPC
: vik_gc_get_fg_color(vtl
->waypoint_gc
, &(rv
.c
)); break;
621 case PARAM_WPTC
: vik_gc_get_fg_color(vtl
->waypoint_text_gc
, &(rv
.c
)); break;
622 case PARAM_WPBC
: vik_gc_get_fg_color(vtl
->waypoint_bg_gc
, &(rv
.c
)); break;
623 case PARAM_WPBA
: rv
.b
= (vik_gc_get_function(vtl
->waypoint_bg_gc
)==GDK_AND
); break;
624 case PARAM_WPSYM
: rv
.u
= vtl
->wp_symbol
; break;
625 case PARAM_WPSIZE
: rv
.u
= vtl
->wp_size
; break;
626 case PARAM_WPSYMS
: rv
.b
= vtl
->wp_draw_symbols
; break;
631 static void track_copy ( const gchar
*name
, VikTrack
*tr
, GHashTable
*dest
)
633 g_hash_table_insert ( dest
, g_strdup ( name
), vik_track_copy(tr
) );
636 static void trw_layer_marshall( VikTrwLayer
*vtl
, guint8
**data
, gint
*len
)
645 if ((f
= fdopen(g_file_open_tmp (NULL
, &tmpname
, NULL
), "r+"))) {
646 a_gpx_write_file(vtl
, f
);
647 vik_layer_marshall_params(VIK_LAYER(vtl
), &pd
, &pl
);
649 g_file_get_contents(tmpname
, (void *)&dd
, (void *)&dl
, NULL
);
650 *len
= sizeof(pl
) + pl
+ dl
;
651 *data
= g_malloc(*len
);
652 memcpy(*data
, &pl
, sizeof(pl
));
653 memcpy(*data
+ sizeof(pl
), pd
, pl
);
654 memcpy(*data
+ sizeof(pl
) + pl
, dd
, dl
);
663 static VikTrwLayer
*trw_layer_unmarshall( gpointer data
, gint len
, VikViewport
*vvp
)
665 VikTrwLayer
*rv
= VIK_TRW_LAYER(vik_layer_create ( VIK_LAYER_TRW
, vvp
, NULL
, FALSE
));
671 memcpy(&pl
, data
, sizeof(pl
));
673 vik_layer_unmarshall_params ( VIK_LAYER(rv
), data
, pl
, vvp
);
676 if (!(f
= fdopen(g_file_open_tmp (NULL
, &tmpname
, NULL
), "r+"))) {
677 g_critical("couldn't open temp file\n");
680 fwrite(data
, len
- pl
- sizeof(pl
), 1, f
);
682 a_gpx_read_file(rv
, f
);
689 static VikTrwLayer
*trw_layer_copy ( VikTrwLayer
*vtl
, gpointer vp
)
691 VikTrwLayer
*rv
= vik_trw_layer_new ( vtl
->drawmode
);
692 PangoFontDescription
*pfd
;
693 rv
->wplabellayout
= gtk_widget_create_pango_layout (GTK_WIDGET(vp
), NULL
);
694 pfd
= pango_font_description_from_string (WAYPOINT_FONT
);
695 pango_layout_set_font_description (rv
->wplabellayout
, pfd
);
696 /* freeing PangoFontDescription, cause it has been copied by prev. call */
697 pango_font_description_free (pfd
);
699 rv
->tracks_visible
= vtl
->tracks_visible
;
700 rv
->waypoints_visible
= vtl
->waypoints_visible
;
701 rv
->drawpoints
= vtl
->drawpoints
;
702 rv
->drawstops
= vtl
->drawstops
;
703 rv
->drawelevation
= vtl
->drawelevation
;
704 rv
->elevation_factor
= vtl
->elevation_factor
;
705 rv
->drawlines
= vtl
->drawlines
;
706 rv
->stop_length
= vtl
->stop_length
;
707 rv
->line_thickness
= vtl
->line_thickness
;
708 rv
->bg_line_thickness
= vtl
->bg_line_thickness
;
709 rv
->velocity_min
= vtl
->velocity_min
;
710 rv
->velocity_max
= vtl
->velocity_max
;
711 rv
->drawlabels
= vtl
->drawlabels
;
712 rv
->drawimages
= vtl
->drawimages
;
713 rv
->image_size
= vtl
->image_size
;
714 rv
->image_alpha
= vtl
->image_alpha
;
715 rv
->image_cache_size
= vtl
->image_cache_size
;
716 rv
->has_verified_thumbnails
= TRUE
;
717 rv
->coord_mode
= vtl
->coord_mode
;
718 rv
->wp_symbol
= vtl
->wp_symbol
;
719 rv
->wp_size
= vtl
->wp_size
;
720 rv
->wp_draw_symbols
= vtl
->wp_draw_symbols
;
722 trw_layer_new_track_gcs ( rv
, VIK_VIEWPORT(vp
) );
724 rv
->waypoint_gc
= gdk_gc_new ( GTK_WIDGET(vp
)->window
);
725 gdk_gc_set_line_attributes ( rv
->waypoint_gc
, 2, GDK_LINE_SOLID
, GDK_CAP_ROUND
, GDK_JOIN_ROUND
);
727 rv
->waypoint_text_gc
= gdk_gc_new ( GTK_WIDGET(vp
)->window
);
728 rv
->waypoint_bg_gc
= gdk_gc_new ( GTK_WIDGET(vp
)->window
);
729 gdk_gc_copy ( rv
->waypoint_gc
, vtl
->waypoint_gc
);
730 gdk_gc_copy ( rv
->waypoint_text_gc
, vtl
->waypoint_text_gc
);
731 gdk_gc_copy ( rv
->waypoint_bg_gc
, vtl
->waypoint_bg_gc
);
733 rv
->waypoint_font
= gdk_font_load ( "-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1" );
735 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) waypoint_copy
, rv
->waypoints
);
736 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) track_copy
, rv
->tracks
);
741 static GList
* a_array_to_glist(gpointer data
[])
745 for (p
= data
; *p
; p
++)
746 gl
= g_list_prepend(gl
, *p
);
747 return(g_list_reverse(gl
));
750 VikTrwLayer
*vik_trw_layer_new ( gint drawmode
)
752 if (trw_layer_params
[PARAM_DM
].widget_data
== NULL
)
753 trw_layer_params
[PARAM_DM
].widget_data
= a_array_to_glist(params_drawmodes
);
754 if (trw_layer_params
[PARAM_WPSYM
].widget_data
== NULL
)
755 trw_layer_params
[PARAM_WPSYM
].widget_data
= a_array_to_glist(params_wpsymbols
);
757 VikTrwLayer
*rv
= VIK_TRW_LAYER ( g_object_new ( VIK_TRW_LAYER_TYPE
, NULL
) );
758 vik_layer_init ( VIK_LAYER(rv
), VIK_LAYER_TRW
);
760 rv
->waypoints
= g_hash_table_new_full ( g_str_hash
, g_str_equal
, g_free
, (GDestroyNotify
) vik_waypoint_free
);
761 rv
->tracks
= g_hash_table_new_full ( g_str_hash
, g_str_equal
, g_free
, (GDestroyNotify
) vik_track_free
);
762 rv
->tracks_iters
= g_hash_table_new_full ( g_str_hash
, g_str_equal
, NULL
, g_free
);
763 rv
->waypoints_iters
= g_hash_table_new_full ( g_str_hash
, g_str_equal
, NULL
, g_free
);
765 /* TODO: constants at top */
766 rv
->waypoints_visible
= rv
->tracks_visible
= TRUE
;
767 rv
->drawmode
= drawmode
;
768 rv
->drawpoints
= TRUE
;
769 rv
->drawstops
= FALSE
;
770 rv
->drawelevation
= FALSE
;
771 rv
->elevation_factor
= 30;
772 rv
->stop_length
= 60;
773 rv
->drawlines
= TRUE
;
774 rv
->wplabellayout
= NULL
;
775 rv
->wp_right_click_menu
= NULL
;
776 rv
->waypoint_gc
= NULL
;
777 rv
->waypoint_text_gc
= NULL
;
778 rv
->waypoint_bg_gc
= NULL
;
780 rv
->velocity_max
= 5.0;
781 rv
->velocity_min
= 0.0;
782 rv
->line_thickness
= 1;
783 rv
->bg_line_thickness
= 0;
784 rv
->current_wp
= NULL
;
785 rv
->current_wp_name
= NULL
;
786 rv
->current_track
= NULL
;
787 rv
->current_tpl
= NULL
;
788 rv
->current_tp_track_name
= NULL
;
789 rv
->moving_tp
= FALSE
;
790 rv
->moving_wp
= FALSE
;
792 rv
->magic_scissors_started
= FALSE
;
794 rv
->waypoint_rightclick
= FALSE
;
796 rv
->last_tp_track_name
= NULL
;
798 rv
->image_cache
= g_queue_new();
800 rv
->image_alpha
= 255;
801 rv
->image_cache_size
= 300;
802 rv
->drawimages
= TRUE
;
803 rv
->drawlabels
= TRUE
;
808 void vik_trw_layer_free ( VikTrwLayer
*trwlayer
)
810 g_hash_table_destroy(trwlayer
->waypoints
);
811 g_hash_table_destroy(trwlayer
->tracks
);
813 /* ODC: replace with GArray */
814 trw_layer_free_track_gcs ( trwlayer
);
816 if ( trwlayer
->wp_right_click_menu
)
817 gtk_object_sink ( GTK_OBJECT(trwlayer
->wp_right_click_menu
) );
819 if ( trwlayer
->wplabellayout
!= NULL
)
820 g_object_unref ( G_OBJECT ( trwlayer
->wplabellayout
) );
822 if ( trwlayer
->waypoint_gc
!= NULL
)
823 g_object_unref ( G_OBJECT ( trwlayer
->waypoint_gc
) );
825 if ( trwlayer
->waypoint_text_gc
!= NULL
)
826 g_object_unref ( G_OBJECT ( trwlayer
->waypoint_text_gc
) );
828 if ( trwlayer
->waypoint_bg_gc
!= NULL
)
829 g_object_unref ( G_OBJECT ( trwlayer
->waypoint_bg_gc
) );
831 if ( trwlayer
->waypoint_font
!= NULL
)
832 gdk_font_unref ( trwlayer
->waypoint_font
);
834 if ( trwlayer
->tpwin
!= NULL
)
835 gtk_widget_destroy ( GTK_WIDGET(trwlayer
->tpwin
) );
837 g_list_foreach ( trwlayer
->image_cache
->head
, (GFunc
) cached_pixbuf_free
, NULL
);
838 g_queue_free ( trwlayer
->image_cache
);
841 static void init_drawing_params ( struct DrawingParams
*dp
, VikViewport
*vp
)
844 dp
->xmpp
= vik_viewport_get_xmpp ( vp
);
845 dp
->ympp
= vik_viewport_get_ympp ( vp
);
846 dp
->width
= vik_viewport_get_width ( vp
);
847 dp
->height
= vik_viewport_get_height ( vp
);
848 dp
->center
= vik_viewport_get_center ( vp
);
849 dp
->one_zone
= vik_viewport_is_one_zone ( vp
); /* false if some other projection besides UTM */
850 dp
->lat_lon
= vik_viewport_get_coord_mode ( vp
) == VIK_COORD_LATLON
;
855 w2
= dp
->xmpp
* (dp
->width
/ 2) + 1600 / dp
->xmpp
;
856 h2
= dp
->ympp
* (dp
->height
/ 2) + 1600 / dp
->ympp
;
857 /* leniency -- for tracks. Obviously for waypoints this SHOULD be a lot smaller */
859 dp
->ce1
= dp
->center
->east_west
-w2
;
860 dp
->ce2
= dp
->center
->east_west
+w2
;
861 dp
->cn1
= dp
->center
->north_south
-h2
;
862 dp
->cn2
= dp
->center
->north_south
+h2
;
863 } else if ( dp
->lat_lon
) {
864 VikCoord upperleft
, bottomright
;
865 /* quick & dirty calculation; really want to check all corners due to lat/lon smaller at top in northern hemisphere */
866 /* this also DOESN'T WORK if you are crossing 180/-180 lon. I don't plan to in the near future... */
867 vik_viewport_screen_to_coord ( vp
, -500, -500, &upperleft
);
868 vik_viewport_screen_to_coord ( vp
, dp
->width
+500, dp
->height
+500, &bottomright
);
869 dp
->ce1
= upperleft
.east_west
;
870 dp
->ce2
= bottomright
.east_west
;
871 dp
->cn1
= bottomright
.north_south
;
872 dp
->cn2
= upperleft
.north_south
;
875 dp
->track_gc_iter
= 0;
878 static gint
calculate_velocity ( VikTrwLayer
*vtl
, VikTrackpoint
*tp1
, VikTrackpoint
*tp2
)
880 static gdouble rv
= 0;
881 if ( tp1
->has_timestamp
&& tp2
->has_timestamp
)
883 rv
= ( vik_coord_diff ( &(tp1
->coord
), &(tp2
->coord
) )
884 / (tp1
->timestamp
- tp2
->timestamp
) ) - vtl
->velocity_min
;
887 return VIK_TRW_LAYER_TRACK_GC_MIN
;
888 else if ( vtl
->velocity_min
>= vtl
->velocity_max
)
889 return VIK_TRW_LAYER_TRACK_GC_MAX
;
891 rv
*= (VIK_TRW_LAYER_TRACK_GC_RATES
/ (vtl
->velocity_max
- vtl
->velocity_min
));
893 if ( rv
>= VIK_TRW_LAYER_TRACK_GC_MAX
)
894 return VIK_TRW_LAYER_TRACK_GC_MAX
;
898 return VIK_TRW_LAYER_TRACK_GC_BLACK
;
901 void draw_utm_skip_insignia ( VikViewport
*vvp
, GdkGC
*gc
, gint x
, gint y
)
903 vik_viewport_draw_line ( vvp
, gc
, x
+5, y
, x
-5, y
);
904 vik_viewport_draw_line ( vvp
, gc
, x
, y
+5, x
, y
-5 );
905 vik_viewport_draw_line ( vvp
, gc
, x
+5, y
+5, x
-5, y
-5 );
906 vik_viewport_draw_line ( vvp
, gc
, x
+5, y
-5, x
-5, y
+5 );
909 static void trw_layer_draw_track ( const gchar
*name
, VikTrack
*track
, struct DrawingParams
*dp
, gboolean drawing_white_background
)
911 /* TODO: this function is a mess, get rid of any redundancy */
912 GList
*list
= track
->trackpoints
;
913 gboolean useoldvals
= TRUE
;
917 gboolean drawelevation
;
918 gdouble min_alt
, max_alt
, alt_diff
= 0;
920 const guint8 tp_size_reg
= 2;
921 const guint8 tp_size_cur
= 4;
924 if ( dp
->vtl
->drawelevation
)
926 /* assume if it has elevation at the beginning, it has it throughout. not ness a true good assumption */
927 if ( ( drawelevation
= vik_track_get_minmax_alt ( track
, &min_alt
, &max_alt
) ) )
928 alt_diff
= max_alt
- min_alt
;
931 if ( ! track
->visible
)
934 /* admittedly this is not an efficient way to do it because we go through the whole GC thing all over... */
935 if ( dp
->vtl
->bg_line_thickness
&& !drawing_white_background
)
936 trw_layer_draw_track ( name
, track
, dp
, TRUE
);
938 if ( drawing_white_background
)
939 drawpoints
= drawstops
= FALSE
;
941 drawpoints
= dp
->vtl
->drawpoints
;
942 drawstops
= dp
->vtl
->drawstops
;
946 int x
, y
, oldx
, oldy
;
947 VikTrackpoint
*tp
= VIK_TRACKPOINT(list
->data
);
949 tp_size
= (list
== dp
->vtl
->current_tpl
) ? tp_size_cur
: tp_size_reg
;
951 vik_viewport_coord_to_screen ( dp
->vp
, &(tp
->coord
), &x
, &y
);
953 if ( (drawpoints
) && dp
->track_gc_iter
< VIK_TRW_LAYER_TRACK_GC
)
955 GdkPoint trian
[3] = { { x
, y
-(3*tp_size
) }, { x
-(2*tp_size
), y
+(2*tp_size
) }, {x
+(2*tp_size
), y
+(2*tp_size
)} };
956 vik_viewport_draw_polygon ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), TRUE
, trian
, 3 );
962 if ( dp
->vtl
->drawmode
== DRAWMODE_ALL_BLACK
)
963 dp
->track_gc_iter
= VIK_TRW_LAYER_TRACK_GC_MAX
+ 1;
965 while ((list
= g_list_next(list
)))
967 tp
= VIK_TRACKPOINT(list
->data
);
968 tp_size
= (list
== dp
->vtl
->current_tpl
) ? tp_size_cur
: tp_size_reg
;
970 /* check some stuff -- but only if we're in UTM and there's only ONE ZONE; or lat lon */
971 if ( (!dp
->one_zone
&& !dp
->lat_lon
) || /* UTM & zones; do everything */
972 ( ((!dp
->one_zone
) || tp
->coord
.utm_zone
== dp
->center
->utm_zone
) && /* only check zones if UTM & one_zone */
973 tp
->coord
.east_west
< dp
->ce2
&& tp
->coord
.east_west
> dp
->ce1
&& /* both UTM and lat lon */
974 tp
->coord
.north_south
> dp
->cn1
&& tp
->coord
.north_south
< dp
->cn2
) )
976 vik_viewport_coord_to_screen ( dp
->vp
, &(tp
->coord
), &x
, &y
);
978 if ( drawpoints
&& ! drawing_white_background
)
981 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
);
983 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
);
986 if ( drawstops
&& VIK_TRACKPOINT(list
->next
->data
)->timestamp
- VIK_TRACKPOINT(list
->data
)->timestamp
> dp
->vtl
->stop_length
)
987 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 );
990 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 );
993 if ((!tp
->newsegment
) && (dp
->vtl
->drawlines
))
995 VikTrackpoint
*tp2
= VIK_TRACKPOINT(list
->prev
->data
);
997 /* UTM only: zone check */
998 if ( drawpoints
&& dp
->vtl
->coord_mode
== VIK_COORD_UTM
&& tp
->coord
.utm_zone
!= dp
->center
->utm_zone
)
999 draw_utm_skip_insignia ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), x
, y
);
1001 if ( dp
->vtl
->drawmode
== DRAWMODE_BY_VELOCITY
)
1002 dp
->track_gc_iter
= calculate_velocity ( dp
->vtl
, tp
, tp2
);
1005 vik_viewport_coord_to_screen ( dp
->vp
, &(tp2
->coord
), &oldx
, &oldy
);
1007 if ( drawing_white_background
) {
1008 vik_viewport_draw_line ( dp
->vp
, dp
->vtl
->track_bg_gc
, oldx
, oldy
, x
, y
);
1012 vik_viewport_draw_line ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), oldx
, oldy
, x
, y
);
1013 if ( dp
->vtl
->drawelevation
&& list
&& list
->next
&& VIK_TRACKPOINT(list
->next
->data
)->altitude
!= VIK_DEFAULT_ALTITUDE
) {
1015 #define FIXALTITUDE(what) ((VIK_TRACKPOINT((what))->altitude-min_alt)/alt_diff*DRAW_ELEVATION_FACTOR*dp->vtl->elevation_factor/dp->xmpp)
1016 if ( list
&& list
->next
&& VIK_TRACKPOINT(list
->next
->data
)->altitude
!= VIK_DEFAULT_ALTITUDE
) {
1020 tmp
[1].y
= oldy
-FIXALTITUDE(list
->data
);
1022 tmp
[2].y
= y
-FIXALTITUDE(list
->next
->data
);
1027 if ( ((oldx
- x
) > 0 && (oldy
- y
) > 0) || ((oldx
- x
) < 0 && (oldy
- y
) < 0))
1028 tmp_gc
= GTK_WIDGET(dp
->vp
)->style
->light_gc
[3];
1030 tmp_gc
= GTK_WIDGET(dp
->vp
)->style
->dark_gc
[0];
1031 vik_viewport_draw_polygon ( dp
->vp
, tmp_gc
, TRUE
, tmp
, 4);
1033 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
));
1043 if (useoldvals
&& dp
->vtl
->drawlines
&& (!tp
->newsegment
))
1045 VikTrackpoint
*tp2
= VIK_TRACKPOINT(list
->prev
->data
);
1046 if ( dp
->vtl
->coord_mode
!= VIK_COORD_UTM
|| tp
->coord
.utm_zone
== dp
->center
->utm_zone
)
1048 vik_viewport_coord_to_screen ( dp
->vp
, &(tp
->coord
), &x
, &y
);
1049 if ( dp
->vtl
->drawmode
== DRAWMODE_BY_VELOCITY
)
1050 dp
->track_gc_iter
= calculate_velocity ( dp
->vtl
, tp
, tp2
);
1052 if ( drawing_white_background
)
1053 vik_viewport_draw_line ( dp
->vp
, dp
->vtl
->track_bg_gc
, oldx
, oldy
, x
, y
);
1055 vik_viewport_draw_line ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), oldx
, oldy
, x
, y
);
1059 vik_viewport_coord_to_screen ( dp
->vp
, &(tp2
->coord
), &x
, &y
);
1060 draw_utm_skip_insignia ( dp
->vp
, g_array_index(dp
->vtl
->track_gc
, GdkGC
*, dp
->track_gc_iter
), x
, y
);
1067 if ( dp
->vtl
->drawmode
== DRAWMODE_BY_TRACK
)
1068 if ( ++(dp
->track_gc_iter
) >= VIK_TRW_LAYER_TRACK_GC
)
1069 dp
->track_gc_iter
= 0;
1072 /* the only reason this exists is so that trw_layer_draw_track can first call itself to draw the white track background */
1073 static void trw_layer_draw_track_cb ( const gchar
*name
, VikTrack
*track
, struct DrawingParams
*dp
)
1075 trw_layer_draw_track ( name
, track
, dp
, FALSE
);
1078 static void cached_pixbuf_free ( CachedPixbuf
*cp
)
1080 g_object_unref ( G_OBJECT(cp
->pixbuf
) );
1081 g_free ( cp
->image
);
1084 static gint
cached_pixbuf_cmp ( CachedPixbuf
*cp
, const gchar
*name
)
1086 return strcmp ( cp
->image
, name
);
1089 static void trw_layer_draw_waypoint ( const gchar
*name
, VikWaypoint
*wp
, struct DrawingParams
*dp
)
1092 if ( (!dp
->one_zone
) || ( wp
->coord
.utm_zone
== dp
->center
->utm_zone
&&
1093 wp
->coord
.east_west
< dp
->ce2
&& wp
->coord
.east_west
> dp
->ce1
&&
1094 wp
->coord
.north_south
> dp
->cn1
&& wp
->coord
.north_south
< dp
->cn2
) )
1098 vik_viewport_coord_to_screen ( dp
->vp
, &(wp
->coord
), &x
, &y
);
1100 /* if in shrunken_cache, get that. If not, get and add to shrunken_cache */
1102 if ( wp
->image
&& dp
->vtl
->drawimages
)
1104 GdkPixbuf
*pixbuf
= NULL
;
1107 if ( dp
->vtl
->image_alpha
== 0)
1110 l
= g_list_find_custom ( dp
->vtl
->image_cache
->head
, wp
->image
, (GCompareFunc
) cached_pixbuf_cmp
);
1112 pixbuf
= ((CachedPixbuf
*) l
->data
)->pixbuf
;
1115 gchar
*image
= wp
->image
;
1116 GdkPixbuf
*regularthumb
= a_thumbnails_get ( wp
->image
);
1117 if ( ! regularthumb
)
1119 regularthumb
= a_thumbnails_get_default (); /* cache one 'not yet loaded' for all thumbs not loaded */
1120 image
= "\x12\x00"; /* this shouldn't occur naturally. */
1124 CachedPixbuf
*cp
= NULL
;
1125 cp
= g_malloc ( sizeof ( CachedPixbuf
) );
1126 if ( dp
->vtl
->image_size
== 128 )
1127 cp
->pixbuf
= regularthumb
;
1130 cp
->pixbuf
= a_thumbnails_scale_pixbuf(regularthumb
, dp
->vtl
->image_size
, dp
->vtl
->image_size
);
1131 g_assert ( cp
->pixbuf
);
1132 g_object_unref ( G_OBJECT(regularthumb
) );
1134 cp
->image
= g_strdup ( image
);
1136 /* needed so 'click picture' tool knows how big the pic is; we don't
1137 * store it in cp because they may have been freed already. */
1138 wp
->image_width
= gdk_pixbuf_get_width ( cp
->pixbuf
);
1139 wp
->image_height
= gdk_pixbuf_get_height ( cp
->pixbuf
);
1141 g_queue_push_head ( dp
->vtl
->image_cache
, cp
);
1142 if ( dp
->vtl
->image_cache
->length
> dp
->vtl
->image_cache_size
)
1143 cached_pixbuf_free ( g_queue_pop_tail ( dp
->vtl
->image_cache
) );
1145 pixbuf
= cp
->pixbuf
;
1149 pixbuf
= a_thumbnails_get_default (); /* thumbnail not yet loaded */
1155 w
= gdk_pixbuf_get_width ( pixbuf
);
1156 h
= gdk_pixbuf_get_height ( pixbuf
);
1158 if ( x
+(w
/2) > 0 && y
+(h
/2) > 0 && x
-(w
/2) < dp
->width
&& y
-(h
/2) < dp
->height
) /* always draw within boundaries */
1160 if ( dp
->vtl
->image_alpha
== 255 )
1161 vik_viewport_draw_pixbuf ( dp
->vp
, pixbuf
, 0, 0, x
- (w
/2), y
- (h
/2), w
, h
);
1163 vik_viewport_draw_pixbuf_with_alpha ( dp
->vp
, pixbuf
, dp
->vtl
->image_alpha
, 0, 0, x
- (w
/2), y
- (h
/2), w
, h
);
1165 return; /* if failed to draw picture, default to drawing regular waypoint (below) */
1169 /* DRAW ACTUAL DOT */
1170 if ( dp
->vtl
->wp_draw_symbols
&& wp
->symbol
&& (sym
= a_get_wp_sym(wp
->symbol
)) ) {
1171 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 );
1173 else if ( wp
== dp
->vtl
->current_wp
) {
1174 switch ( dp
->vtl
->wp_symbol
) {
1175 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;
1176 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;
1177 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;
1178 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 );
1179 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 );
1183 switch ( dp
->vtl
->wp_symbol
) {
1184 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;
1185 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;
1186 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;
1187 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
);
1188 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;
1192 if ( dp
->vtl
->drawlabels
)
1194 /* thanks to the GPSDrive people (Fritz Ganter et al.) for hints on this part ... yah, I'm too lazy to study documentation */
1196 pango_layout_set_text ( dp
->vtl
->wplabellayout
, name
, -1 );
1197 pango_layout_get_pixel_size ( dp
->vtl
->wplabellayout
, &width
, &height
);
1198 vik_viewport_draw_rectangle ( dp
->vp
, dp
->vtl
->waypoint_bg_gc
, TRUE
, x
+ dp
->vtl
->wp_size
- 1, y
-1,width
+1,height
-1);
1199 vik_viewport_draw_layout ( dp
->vp
, dp
->vtl
->waypoint_text_gc
, x
+ dp
->vtl
->wp_size
, y
, dp
->vtl
->wplabellayout
);
1204 void vik_trw_layer_draw ( VikTrwLayer
*l
, gpointer data
)
1206 static struct DrawingParams dp
;
1207 g_assert ( l
!= NULL
);
1209 init_drawing_params ( &dp
, VIK_VIEWPORT(data
) );
1212 if ( l
->tracks_visible
)
1213 g_hash_table_foreach ( l
->tracks
, (GHFunc
) trw_layer_draw_track_cb
, &dp
);
1215 if (l
->waypoints_visible
)
1216 g_hash_table_foreach ( l
->waypoints
, (GHFunc
) trw_layer_draw_waypoint
, &dp
);
1219 static void trw_layer_free_track_gcs ( VikTrwLayer
*vtl
)
1222 if ( vtl
->track_bg_gc
)
1224 g_object_unref ( vtl
->track_bg_gc
);
1225 vtl
->track_bg_gc
= NULL
;
1228 if ( ! vtl
->track_gc
)
1230 for ( i
= vtl
->track_gc
->len
- 1; i
>= 0; i
-- )
1231 g_object_unref ( g_array_index ( vtl
->track_gc
, GObject
*, i
) );
1232 g_array_free ( vtl
->track_gc
, TRUE
);
1233 vtl
->track_gc
= NULL
;
1236 static void trw_layer_new_track_gcs ( VikTrwLayer
*vtl
, VikViewport
*vp
)
1238 GdkGC
*gc
[ VIK_TRW_LAYER_TRACK_GC
];
1239 gint width
= vtl
->line_thickness
;
1241 if ( vtl
->track_gc
)
1242 trw_layer_free_track_gcs ( vtl
);
1244 if ( vtl
->track_bg_gc
)
1245 g_object_unref ( vtl
->track_bg_gc
);
1246 vtl
->track_bg_gc
= vik_viewport_new_gc ( vp
, "#FFFFFF", width
+ vtl
->bg_line_thickness
);
1248 vtl
->track_gc
= g_array_sized_new ( FALSE
, FALSE
, sizeof ( GdkGC
* ), VIK_TRW_LAYER_TRACK_GC
);
1250 gc
[0] = vik_viewport_new_gc ( vp
, "#2d870a", width
); /* below range */
1252 gc
[1] = vik_viewport_new_gc ( vp
, "#0a8742", width
);
1253 gc
[2] = vik_viewport_new_gc ( vp
, "#0a8783", width
);
1254 gc
[3] = vik_viewport_new_gc ( vp
, "#0a4d87", width
);
1255 gc
[4] = vik_viewport_new_gc ( vp
, "#05469f", width
);
1256 gc
[5] = vik_viewport_new_gc ( vp
, "#1b059f", width
);
1257 gc
[6] = vik_viewport_new_gc ( vp
, "#2d059f", width
);
1258 gc
[7] = vik_viewport_new_gc ( vp
, "#4a059f", width
);
1259 gc
[8] = vik_viewport_new_gc ( vp
, "#84059f", width
);
1260 gc
[9] = vik_viewport_new_gc ( vp
, "#96059f", width
);
1261 gc
[10] = vik_viewport_new_gc ( vp
, "#f22ef2", width
);
1263 gc
[11] = vik_viewport_new_gc ( vp
, "#ff0000", width
); /* above range */
1265 gc
[12] = vik_viewport_new_gc ( vp
, "#000000", width
); /* black / no speed data */
1267 g_array_append_vals ( vtl
->track_gc
, gc
, VIK_TRW_LAYER_TRACK_GC
);
1270 VikTrwLayer
*vik_trw_layer_create ( VikViewport
*vp
)
1272 VikTrwLayer
*rv
= vik_trw_layer_new ( 0 );
1273 PangoFontDescription
*pfd
;
1274 rv
->wplabellayout
= gtk_widget_create_pango_layout (GTK_WIDGET(vp
), NULL
);
1275 pfd
= pango_font_description_from_string (WAYPOINT_FONT
);
1276 pango_layout_set_font_description (rv
->wplabellayout
, pfd
);
1277 /* freeing PangoFontDescription, cause it has been copied by prev. call */
1278 pango_font_description_free (pfd
);
1280 vik_layer_rename ( VIK_LAYER(rv
), vik_trw_layer_interface
.name
);
1282 trw_layer_new_track_gcs ( rv
, vp
);
1284 rv
->waypoint_gc
= vik_viewport_new_gc ( vp
, "#000000", 2 );
1285 rv
->waypoint_text_gc
= vik_viewport_new_gc ( vp
, "#FFFFFF", 1 );
1286 rv
->waypoint_bg_gc
= vik_viewport_new_gc ( vp
, "#8383C4", 1 );
1287 gdk_gc_set_function ( rv
->waypoint_bg_gc
, GDK_AND
);
1289 rv
->waypoint_font
= gdk_font_load ( "-*-helvetica-bold-r-normal-*-*-100-*-*-p-*-iso8859-1" );
1291 rv
->has_verified_thumbnails
= FALSE
;
1292 rv
->wp_symbol
= WP_SYMBOL_FILLED_SQUARE
;
1294 rv
->wp_draw_symbols
= TRUE
;
1296 rv
->coord_mode
= vik_viewport_get_coord_mode ( vp
);
1298 rv
->menu_selection
= vik_layer_get_interface(VIK_LAYER(rv
)->type
)->menu_items_selection
;
1303 static void trw_layer_realize_track ( gchar
*name
, VikTrack
*track
, gpointer pass_along
[4] )
1305 GtkTreeIter
*new_iter
= g_malloc(sizeof(GtkTreeIter
));
1307 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1308 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
);
1310 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
);
1313 *new_iter
= *((GtkTreeIter
*) pass_along
[1]);
1314 g_hash_table_insert ( VIK_TRW_LAYER(pass_along
[2])->tracks_iters
, name
, new_iter
);
1316 if ( ! track
->visible
)
1317 vik_treeview_item_set_visible ( (VikTreeview
*) pass_along
[3], (GtkTreeIter
*) pass_along
[1], FALSE
);
1320 static void trw_layer_realize_waypoint ( gchar
*name
, VikWaypoint
*wp
, gpointer pass_along
[4] )
1322 GtkTreeIter
*new_iter
= g_malloc(sizeof(GtkTreeIter
));
1323 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1324 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
);
1326 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
);
1329 *new_iter
= *((GtkTreeIter
*) pass_along
[1]);
1330 g_hash_table_insert ( VIK_TRW_LAYER(pass_along
[2])->waypoints_iters
, name
, new_iter
);
1332 if ( ! wp
->visible
)
1333 vik_treeview_item_set_visible ( (VikTreeview
*) pass_along
[3], (GtkTreeIter
*) pass_along
[1], FALSE
);
1337 void vik_trw_layer_realize ( VikTrwLayer
*vtl
, VikTreeview
*vt
, GtkTreeIter
*layer_iter
)
1340 gpointer pass_along
[5] = { &(vtl
->tracks_iter
), &iter2
, vtl
, vt
, (gpointer
) VIK_TRW_LAYER_SUBLAYER_TRACK
};
1342 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1343 vik_treeview_add_sublayer_alphabetized ( (VikTreeview
*) vt
, layer_iter
, &(vtl
->tracks_iter
), "Tracks", vtl
, NULL
, VIK_TRW_LAYER_SUBLAYER_TRACKS
, NULL
, TRUE
, FALSE
);
1345 vik_treeview_add_sublayer ( (VikTreeview
*) vt
, layer_iter
, &(vtl
->tracks_iter
), "Tracks", vtl
, NULL
, VIK_TRW_LAYER_SUBLAYER_TRACKS
, NULL
, TRUE
, FALSE
);
1347 if ( ! vtl
->tracks_visible
)
1348 vik_treeview_item_set_visible ( (VikTreeview
*) vt
, &(vtl
->tracks_iter
), FALSE
);
1350 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) trw_layer_realize_track
, pass_along
);
1352 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1353 vik_treeview_add_sublayer_alphabetized ( (VikTreeview
*) vt
, layer_iter
, &(vtl
->waypoints_iter
), "Waypoints", vtl
, NULL
, VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
, NULL
, TRUE
, FALSE
);
1355 vik_treeview_add_sublayer ( (VikTreeview
*) vt
, layer_iter
, &(vtl
->waypoints_iter
), "Waypoints", vtl
, NULL
, VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
, NULL
, TRUE
, FALSE
);
1358 if ( ! vtl
->waypoints_visible
)
1359 vik_treeview_item_set_visible ( (VikTreeview
*) vt
, &(vtl
->waypoints_iter
), FALSE
);
1361 pass_along
[0] = &(vtl
->waypoints_iter
);
1362 pass_along
[4] = (gpointer
) VIK_TRW_LAYER_SUBLAYER_WAYPOINT
;
1364 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) trw_layer_realize_waypoint
, pass_along
);
1368 gboolean
vik_trw_layer_sublayer_toggle_visible ( VikTrwLayer
*l
, gint subtype
, gpointer sublayer
)
1372 case VIK_TRW_LAYER_SUBLAYER_TRACKS
: return (l
->tracks_visible
^= 1);
1373 case VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
: return (l
->waypoints_visible
^= 1);
1374 case VIK_TRW_LAYER_SUBLAYER_TRACK
:
1376 VikTrack
*t
= g_hash_table_lookup ( l
->tracks
, sublayer
);
1378 return (t
->visible
^= 1);
1382 case VIK_TRW_LAYER_SUBLAYER_WAYPOINT
:
1384 VikWaypoint
*t
= g_hash_table_lookup ( l
->waypoints
, sublayer
);
1386 return (t
->visible
^= 1);
1394 GHashTable
*vik_trw_layer_get_tracks ( VikTrwLayer
*l
)
1399 GHashTable
*vik_trw_layer_get_waypoints ( VikTrwLayer
*l
)
1401 return l
->waypoints
;
1404 static void trw_layer_find_maxmin_waypoints ( const gchar
*name
, const VikWaypoint
*w
, struct LatLon maxmin
[2] )
1406 static VikCoord fixme
;
1407 vik_coord_copy_convert ( &(w
->coord
), VIK_COORD_LATLON
, &fixme
);
1408 if ( VIK_LATLON(&fixme
)->lat
> maxmin
[0].lat
|| maxmin
[0].lat
== 0.0 )
1409 maxmin
[0].lat
= VIK_LATLON(&fixme
)->lat
;
1410 if ( VIK_LATLON(&fixme
)->lat
< maxmin
[1].lat
|| maxmin
[1].lat
== 0.0 )
1411 maxmin
[1].lat
= VIK_LATLON(&fixme
)->lat
;
1412 if ( VIK_LATLON(&fixme
)->lon
> maxmin
[0].lon
|| maxmin
[0].lon
== 0.0 )
1413 maxmin
[0].lon
= VIK_LATLON(&fixme
)->lon
;
1414 if ( VIK_LATLON(&fixme
)->lon
< maxmin
[1].lon
|| maxmin
[1].lon
== 0.0 )
1415 maxmin
[1].lon
= VIK_LATLON(&fixme
)->lon
;
1418 static void trw_layer_find_maxmin_tracks ( const gchar
*name
, GList
**t
, struct LatLon maxmin
[2] )
1421 static VikCoord fixme
;
1425 vik_coord_copy_convert ( &(VIK_TRACKPOINT(tr
->data
)->coord
), VIK_COORD_LATLON
, &fixme
);
1426 if ( VIK_LATLON(&fixme
)->lat
> maxmin
[0].lat
|| maxmin
[0].lat
== 0.0 )
1427 maxmin
[0].lat
= VIK_LATLON(&fixme
)->lat
;
1428 if ( VIK_LATLON(&fixme
)->lat
< maxmin
[1].lat
|| maxmin
[1].lat
== 0.0 )
1429 maxmin
[1].lat
= VIK_LATLON(&fixme
)->lat
;
1430 if ( VIK_LATLON(&fixme
)->lon
> maxmin
[0].lon
|| maxmin
[0].lon
== 0.0 )
1431 maxmin
[0].lon
= VIK_LATLON(&fixme
)->lon
;
1432 if ( VIK_LATLON(&fixme
)->lon
< maxmin
[1].lon
|| maxmin
[1].lon
== 0.0 )
1433 maxmin
[1].lon
= VIK_LATLON(&fixme
)->lon
;
1439 gboolean
vik_trw_layer_find_center ( VikTrwLayer
*vtl
, VikCoord
*dest
)
1441 /* 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... */
1442 struct LatLon maxmin
[2] = { {0.0,0.0}, {0.0,0.0} };
1443 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) trw_layer_find_maxmin_waypoints
, maxmin
);
1444 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) trw_layer_find_maxmin_tracks
, maxmin
);
1445 if (maxmin
[0].lat
== 0.0 && maxmin
[0].lon
== 0.0 && maxmin
[1].lat
== 0.0 && maxmin
[1].lon
== 0.0)
1449 struct LatLon average
= { (maxmin
[0].lat
+maxmin
[1].lat
)/2, (maxmin
[0].lon
+maxmin
[1].lon
)/2 };
1450 vik_coord_load_from_latlon ( dest
, vtl
->coord_mode
, &average
);
1455 static void trw_layer_centerize ( gpointer layer_and_vlp
[2] )
1458 if ( vik_trw_layer_find_center ( VIK_TRW_LAYER(layer_and_vlp
[0]), &coord
) )
1459 goto_coord ( VIK_LAYERS_PANEL(layer_and_vlp
[1]), &coord
);
1461 a_dialog_info_msg ( VIK_GTK_WINDOW_FROM_LAYER(layer_and_vlp
[0]), "This layer has no waypoints or trackpoints." );
1464 static void trw_layer_export ( gpointer layer_and_vlp
[2], guint file_type
)
1466 GtkWidget
*file_selector
;
1468 gboolean failed
= FALSE
;
1469 file_selector
= gtk_file_selection_new ("Export Layer");
1471 while ( gtk_dialog_run ( GTK_DIALOG(file_selector
) ) == GTK_RESPONSE_OK
)
1473 fn
= gtk_file_selection_get_filename (GTK_FILE_SELECTION(file_selector
) );
1474 if ( access ( fn
, F_OK
) != 0 )
1476 gtk_widget_hide ( file_selector
);
1477 failed
= ! a_file_export ( VIK_TRW_LAYER(layer_and_vlp
[0]), fn
, file_type
);
1482 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
) ) )
1484 gtk_widget_hide ( file_selector
);
1485 failed
= ! a_file_export ( VIK_TRW_LAYER(layer_and_vlp
[0]), fn
, file_type
);
1490 gtk_widget_destroy ( file_selector
);
1492 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(layer_and_vlp
[0]), "The filename you requested could not be opened for writing." );
1495 static void trw_layer_export_gpspoint ( gpointer layer_and_vlp
[2] )
1497 trw_layer_export ( layer_and_vlp
, FILE_TYPE_GPSPOINT
);
1500 static void trw_layer_export_gpsmapper ( gpointer layer_and_vlp
[2] )
1502 trw_layer_export ( layer_and_vlp
, FILE_TYPE_GPSMAPPER
);
1505 static void trw_layer_export_gpx ( gpointer layer_and_vlp
[2] )
1507 trw_layer_export ( layer_and_vlp
, FILE_TYPE_GPX
);
1510 static void trw_layer_goto_wp ( gpointer layer_and_vlp
[2] )
1512 GHashTable
*wps
= vik_trw_layer_get_waypoints ( VIK_TRW_LAYER(layer_and_vlp
[0]) );
1513 GtkWidget
*dia
= gtk_dialog_new_with_buttons ("Create",
1514 VIK_GTK_WINDOW_FROM_LAYER(layer_and_vlp
[0]),
1515 GTK_DIALOG_MODAL
| GTK_DIALOG_DESTROY_WITH_PARENT
,
1517 GTK_RESPONSE_REJECT
,
1519 GTK_RESPONSE_ACCEPT
,
1522 GtkWidget
*label
, *entry
;
1523 label
= gtk_label_new("Waypoint Name:");
1524 entry
= gtk_entry_new();
1526 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia
)->vbox
), label
, FALSE
, FALSE
, 0);
1527 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia
)->vbox
), entry
, FALSE
, FALSE
, 0);
1528 gtk_widget_show_all ( label
);
1529 gtk_widget_show_all ( entry
);
1531 while ( gtk_dialog_run ( GTK_DIALOG(dia
) ) == GTK_RESPONSE_ACCEPT
)
1534 gchar
*upname
= g_strdup(gtk_entry_get_text(GTK_ENTRY(entry
)));
1537 for ( i
= strlen(upname
)-1; i
>= 0; i
-- )
1538 upname
[i
] = toupper(upname
[i
]);
1540 wp
= g_hash_table_lookup ( wps
, upname
);
1543 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(layer_and_vlp
[0]), "Waypoint not found in this layer." );
1546 vik_viewport_set_center_coord ( vik_layers_panel_get_viewport(VIK_LAYERS_PANEL(layer_and_vlp
[1])), &(wp
->coord
) );
1547 vik_layers_panel_emit_update ( VIK_LAYERS_PANEL(layer_and_vlp
[1]) );
1548 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
) );
1555 gtk_widget_destroy ( dia
);
1558 gboolean
vik_trw_layer_new_waypoint ( VikTrwLayer
*vtl
, GtkWindow
*w
, const VikCoord
*def_coord
)
1561 VikWaypoint
*wp
= vik_waypoint_new();
1562 wp
->coord
= *def_coord
;
1563 wp
->altitude
= VIK_DEFAULT_ALTITUDE
;
1565 if ( a_dialog_new_waypoint ( w
, &name
, wp
, vik_trw_layer_get_waypoints ( vtl
), vtl
->coord_mode
) )
1568 vik_trw_layer_add_waypoint ( vtl
, name
, wp
);
1571 vik_waypoint_free(wp
);
1575 static void trw_layer_new_wp ( gpointer lav
[2] )
1577 VikTrwLayer
*vtl
= VIK_TRW_LAYER(lav
[0]);
1578 VikLayersPanel
*vlp
= VIK_LAYERS_PANEL(lav
[1]);
1579 /* TODO longone: okay, if layer above (aggregate) is invisible but vtl->visible is true, this redraws for no reason.
1580 instead return true if you want to update. */
1581 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
)
1582 vik_layers_panel_emit_update ( vlp
);
1585 void vik_trw_layer_add_menu_items ( VikTrwLayer
*vtl
, GtkMenu
*menu
, gpointer vlp
)
1587 static gpointer pass_along
[2];
1589 GtkMenu
*export_submenu
;
1590 pass_along
[0] = vtl
;
1591 pass_along
[1] = vlp
;
1593 item
= gtk_menu_item_new();
1594 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
1595 gtk_widget_show ( item
);
1597 item
= gtk_menu_item_new_with_label ( "Goto Center of Layer" );
1598 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_centerize
), pass_along
);
1599 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
1600 gtk_widget_show ( item
);
1602 item
= gtk_menu_item_new_with_label ( "Goto Waypoint" );
1603 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_goto_wp
), pass_along
);
1604 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
1605 gtk_widget_show ( item
);
1607 export_submenu
= gtk_menu_new ();
1608 item
= gtk_menu_item_new_with_label ( "Export layer" );
1609 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
1610 gtk_widget_show ( item
);
1611 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item
), export_submenu
);
1613 item
= gtk_menu_item_new_with_label ( "Export as GPSPoint" );
1614 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_export_gpspoint
), pass_along
);
1615 gtk_menu_shell_append (GTK_MENU_SHELL (export_submenu
), item
);
1616 gtk_widget_show ( item
);
1618 item
= gtk_menu_item_new_with_label ( "Export as GPSMapper" );
1619 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_export_gpsmapper
), pass_along
);
1620 gtk_menu_shell_append (GTK_MENU_SHELL (export_submenu
), item
);
1621 gtk_widget_show ( item
);
1623 item
= gtk_menu_item_new_with_label ( "Export as GPX" );
1624 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_export_gpx
), pass_along
);
1625 gtk_menu_shell_append (GTK_MENU_SHELL (export_submenu
), item
);
1626 gtk_widget_show ( item
);
1628 item
= gtk_menu_item_new_with_label ( "New Waypoint" );
1629 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_new_wp
), pass_along
);
1630 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
1631 gtk_widget_show ( item
);
1634 void vik_trw_layer_add_waypoint ( VikTrwLayer
*vtl
, gchar
*name
, VikWaypoint
*wp
)
1636 if ( VIK_LAYER(vtl
)->realized
)
1638 VikWaypoint
*oldwp
= VIK_WAYPOINT ( g_hash_table_lookup ( vtl
->waypoints
, name
) );
1640 wp
->visible
= oldwp
->visible
; /* same visibility so we don't have to update viktreeview */
1643 GtkTreeIter
*iter
= g_malloc(sizeof(GtkTreeIter
));
1644 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1645 vik_treeview_add_sublayer_alphabetized ( VIK_LAYER(vtl
)->vt
, &(vtl
->waypoints_iter
), iter
, name
, vtl
, name
, VIK_TRW_LAYER_SUBLAYER_WAYPOINT
, NULL
, TRUE
, TRUE
);
1647 vik_treeview_add_sublayer ( VIK_LAYER(vtl
)->vt
, &(vtl
->waypoints_iter
), iter
, name
, vtl
, name
, VIK_TRW_LAYER_SUBLAYER_WAYPOINT
, NULL
, TRUE
, TRUE
);
1649 vik_treeview_select_iter ( VIK_LAYER(vtl
)->vt
, iter
);
1650 g_hash_table_insert ( vtl
->waypoints_iters
, name
, iter
);
1657 g_hash_table_insert ( vtl
->waypoints
, name
, wp
);
1661 void vik_trw_layer_add_track ( VikTrwLayer
*vtl
, gchar
*name
, VikTrack
*t
)
1663 if ( VIK_LAYER(vtl
)->realized
)
1665 VikTrack
*oldt
= VIK_TRACK ( g_hash_table_lookup ( vtl
->tracks
, name
) );
1667 t
->visible
= oldt
->visible
; /* same visibility so we don't have to update viktreeview */
1670 GtkTreeIter
*iter
= g_malloc(sizeof(GtkTreeIter
));
1671 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
1672 vik_treeview_add_sublayer_alphabetized ( VIK_LAYER(vtl
)->vt
, &(vtl
->tracks_iter
), iter
, name
, vtl
, name
, VIK_TRW_LAYER_SUBLAYER_TRACK
, NULL
, TRUE
, TRUE
);
1674 vik_treeview_add_sublayer ( VIK_LAYER(vtl
)->vt
, &(vtl
->tracks_iter
), iter
, name
, vtl
, name
, VIK_TRW_LAYER_SUBLAYER_TRACK
, NULL
, TRUE
, TRUE
);
1676 vik_treeview_select_iter ( VIK_LAYER(vtl
)->vt
, iter
);
1677 g_hash_table_insert ( vtl
->tracks_iters
, name
, iter
);
1678 /* t->visible = TRUE; */
1682 ; /* t->visible = TRUE; // this is now used by file input functions */
1684 g_hash_table_insert ( vtl
->tracks
, name
, t
);
1688 static gboolean
uppercase_exists_in_hash ( GHashTable
*hash
, const gchar
*str
)
1690 gchar
*upp
= g_strdup ( str
);
1695 *tmp
= toupper(*tmp
);
1698 rv
= g_hash_table_lookup ( hash
, upp
) ? TRUE
: FALSE
;
1703 /* to be called whenever a track has been deleted or may have been changed. */
1704 static void trw_layer_cancel_tps_of_track ( VikTrwLayer
*vtl
, const gchar
*trk_name
)
1706 if (vtl
->current_tp_track_name
&& g_strcasecmp(trk_name
, vtl
->current_tp_track_name
) == 0)
1707 trw_layer_cancel_current_tp ( vtl
, FALSE
);
1708 else if (vtl
->last_tp_track_name
&& g_strcasecmp(trk_name
, vtl
->last_tp_track_name
) == 0)
1709 trw_layer_cancel_last_tp ( vtl
);
1712 static gchar
*get_new_unique_sublayer_name (VikTrwLayer
*vtl
, gint sublayer_type
, const gchar
*name
)
1715 gchar
*newname
= g_strdup(name
);
1716 while ((sublayer_type
== VIK_TRW_LAYER_SUBLAYER_TRACK
) ?
1717 (void *)vik_trw_layer_get_track(vtl
, newname
) : (void *)vik_trw_layer_get_waypoint(vtl
, newname
)) {
1718 gchar
*new_newname
= g_strdup_printf("%s#%d", name
, i
);
1720 newname
= new_newname
;
1726 void vik_trw_layer_filein_add_waypoint ( VikTrwLayer
*vtl
, gchar
*name
, VikWaypoint
*wp
)
1728 vik_trw_layer_add_waypoint ( vtl
,
1729 get_new_unique_sublayer_name(vtl
, VIK_TRW_LAYER_SUBLAYER_WAYPOINT
, name
),
1732 void vik_trw_layer_filein_add_track ( VikTrwLayer
*vtl
, gchar
*name
, VikTrack
*tr
)
1734 vik_trw_layer_add_track ( vtl
,
1735 get_new_unique_sublayer_name(vtl
, VIK_TRW_LAYER_SUBLAYER_TRACK
, name
),
1739 static void trw_layer_enum_item ( const gchar
*name
, GList
**tr
, GList
**l
)
1741 *l
= g_list_append(*l
, (gpointer
)name
);
1744 static void trw_layer_move_item ( VikTrwLayer
*vtl_src
, VikTrwLayer
*vtl_dest
, gchar
*name
, gint type
)
1746 gchar
*newname
= get_new_unique_sublayer_name(vtl_dest
, type
, name
);
1747 if (type
== VIK_TRW_LAYER_SUBLAYER_TRACK
) {
1749 t
= vik_track_copy(vik_trw_layer_get_track(vtl_src
, name
));
1750 vik_trw_layer_delete_track(vtl_src
, name
);
1751 vik_trw_layer_add_track(vtl_dest
, newname
, t
);
1753 if (type
==VIK_TRW_LAYER_SUBLAYER_WAYPOINT
) {
1755 w
= vik_waypoint_copy(vik_trw_layer_get_waypoint(vtl_src
, name
));
1756 vik_trw_layer_delete_waypoint(vtl_src
, name
);
1757 vik_trw_layer_add_waypoint(vtl_dest
, newname
, w
);
1761 static void trw_layer_drag_drop_request ( VikTrwLayer
*vtl_src
, VikTrwLayer
*vtl_dest
, GtkTreeIter
*src_item_iter
, GtkTreePath
*dest_path
)
1763 VikTreeview
*vt
= VIK_LAYER(vtl_src
)->vt
;
1764 gint type
= vik_treeview_item_get_data(vt
, src_item_iter
);
1766 if (!vik_treeview_item_get_pointer(vt
, src_item_iter
)) {
1767 GList
*items
= NULL
;
1770 if (type
==VIK_TRW_LAYER_SUBLAYER_TRACKS
) {
1771 g_hash_table_foreach ( vtl_src
->tracks
, (GHFunc
)trw_layer_enum_item
, &items
);
1773 if (type
==VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
) {
1774 g_hash_table_foreach ( vtl_src
->waypoints
, (GHFunc
)trw_layer_enum_item
, &items
);
1779 if (type
==VIK_TRW_LAYER_SUBLAYER_TRACKS
) {
1780 trw_layer_move_item ( vtl_src
, vtl_dest
, iter
->data
, VIK_TRW_LAYER_SUBLAYER_TRACK
);
1782 trw_layer_move_item ( vtl_src
, vtl_dest
, iter
->data
, VIK_TRW_LAYER_SUBLAYER_WAYPOINT
);
1789 gchar
*name
= vik_treeview_item_get_pointer(vt
, src_item_iter
);
1790 trw_layer_move_item(vtl_src
, vtl_dest
, name
, type
);
1795 gboolean
vik_trw_layer_delete_track ( VikTrwLayer
*vtl
, const gchar
*trk_name
)
1797 VikTrack
*t
= g_hash_table_lookup ( vtl
->tracks
, trk_name
);
1798 gboolean was_visible
= FALSE
;
1802 was_visible
= t
->visible
;
1803 if ( t
== vtl
->current_track
)
1804 vtl
->current_track
= NULL
;
1806 /* could be current_tp, so we have to check */
1807 trw_layer_cancel_tps_of_track ( vtl
, trk_name
);
1809 g_assert ( ( it
= g_hash_table_lookup ( vtl
->tracks_iters
, trk_name
) ) );
1810 vik_treeview_item_delete ( VIK_LAYER(vtl
)->vt
, it
);
1811 g_hash_table_remove ( vtl
->tracks_iters
, trk_name
);
1813 /* do this last because trk_name may be pointing to actual orig key */
1814 g_hash_table_remove ( vtl
->tracks
, trk_name
);
1819 gboolean
vik_trw_layer_delete_waypoint ( VikTrwLayer
*vtl
, const gchar
*wp_name
)
1821 gboolean was_visible
= FALSE
;
1824 wp
= g_hash_table_lookup ( vtl
->waypoints
, wp_name
);
1828 if ( wp
== vtl
->current_wp
) {
1829 vtl
->current_wp
= NULL
;
1830 vtl
->current_wp_name
= NULL
;
1831 vtl
->moving_wp
= FALSE
;
1834 was_visible
= wp
->visible
;
1835 g_assert ( ( it
= g_hash_table_lookup ( vtl
->waypoints_iters
, (gchar
*) wp_name
) ) );
1836 vik_treeview_item_delete ( VIK_LAYER(vtl
)->vt
, it
);
1837 g_hash_table_remove ( vtl
->waypoints_iters
, (gchar
*) wp_name
);
1838 g_hash_table_remove ( vtl
->waypoints
, wp_name
); /* last because this frees name */
1844 static void remove_item_from_treeview(const gchar
*name
, GtkTreeIter
*it
, VikTreeview
* vt
)
1846 vik_treeview_item_delete (vt
, it
);
1849 void vik_trw_layer_delete_all_tracks ( VikTrwLayer
*vtl
)
1852 vtl
->current_track
= NULL
;
1853 if (vtl
->current_tp_track_name
)
1854 trw_layer_cancel_current_tp(vtl
, FALSE
);
1855 if (vtl
->last_tp_track_name
)
1856 trw_layer_cancel_last_tp ( vtl
);
1858 g_hash_table_foreach(vtl
->tracks_iters
, (GHFunc
) remove_item_from_treeview
, VIK_LAYER(vtl
)->vt
);
1859 g_hash_table_remove_all(vtl
->tracks_iters
);
1860 g_hash_table_remove_all(vtl
->tracks
);
1862 /* TODO: only update if the layer is visible (ticked) */
1863 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1866 void vik_trw_layer_delete_all_waypoints ( VikTrwLayer
*vtl
)
1868 vtl
->current_wp
= NULL
;
1869 vtl
->current_wp_name
= NULL
;
1870 vtl
->moving_wp
= FALSE
;
1872 g_hash_table_foreach(vtl
->waypoints_iters
, (GHFunc
) remove_item_from_treeview
, VIK_LAYER(vtl
)->vt
);
1873 g_hash_table_remove_all(vtl
->waypoints_iters
);
1874 g_hash_table_remove_all(vtl
->waypoints
);
1876 /* TODO: only update if the layer is visible (ticked) */
1877 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1880 static void trw_layer_delete_item ( gpointer pass_along
[5] )
1882 VikTrwLayer
*vtl
= VIK_TRW_LAYER(pass_along
[0]);
1883 gboolean was_visible
= FALSE
;
1884 if ( (gint
) pass_along
[2] == VIK_TRW_LAYER_SUBLAYER_WAYPOINT
)
1886 was_visible
= vik_trw_layer_delete_waypoint ( vtl
, (gchar
*) pass_along
[3] );
1890 was_visible
= vik_trw_layer_delete_track ( vtl
, (gchar
*) pass_along
[3] );
1893 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1897 static void trw_layer_properties_item ( gpointer pass_along
[5] )
1899 VikTrwLayer
*vtl
= VIK_TRW_LAYER(pass_along
[0]);
1900 if ( (gint
) pass_along
[2] == VIK_TRW_LAYER_SUBLAYER_WAYPOINT
)
1902 VikWaypoint
*wp
= g_hash_table_lookup ( vtl
->waypoints
, pass_along
[3] );
1905 if ( a_dialog_new_waypoint ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), NULL
, wp
, NULL
, vtl
->coord_mode
) )
1907 if ( VIK_LAYER(vtl
)->visible
)
1908 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1913 VikTrack
*tr
= g_hash_table_lookup ( vtl
->tracks
, pass_along
[3] );
1916 gint resp
= vik_trw_layer_propwin_run ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), tr
, pass_along
[1] /* vlp */ );
1917 if ( resp
== VIK_TRW_LAYER_PROPWIN_DEL_DUP
)
1919 vik_track_remove_dup_points(tr
);
1920 /* above operation could have deleted current_tp or last_tp */
1921 trw_layer_cancel_tps_of_track ( vtl
, (gchar
*) pass_along
[3] );
1922 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1924 if ( resp
== VIK_TRW_LAYER_PROPWIN_REVERSE
)
1926 vik_track_reverse(tr
);
1927 vik_layer_emit_update ( VIK_LAYER(vtl
) );
1929 else if ( resp
== VIK_TRW_LAYER_PROPWIN_SPLIT
)
1931 /* get new tracks, add them, resolve naming conflicts (free if cancel), and delete old. old can still exist on clipboard. */
1933 VikTrack
**tracks
= vik_track_split_into_segments(tr
, &ntracks
);
1936 for ( i
= 0; i
< ntracks
; i
++ )
1938 g_assert ( tracks
[i
] );
1939 new_tr_name
= g_strdup_printf("%s #%d", (gchar
*) pass_along
[3], i
+1);
1940 /* if ( (wp_exists) && (! overwrite) ) */
1941 /* don't need to upper case new_tr_name because old tr name was uppercase */
1942 if ( g_hash_table_lookup ( vtl
->tracks
, new_tr_name
) &&
1943 ( ! a_dialog_overwrite ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), "The track \"%s\" exists, do you wish to overwrite it?", new_tr_name
) ) )
1945 gchar
*new_new_tr_name
= a_dialog_new_track ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), vtl
->tracks
);
1946 g_free ( new_tr_name
);
1947 if (new_new_tr_name
)
1948 new_tr_name
= new_new_tr_name
;
1952 vik_track_free ( tracks
[i
] );
1956 vik_trw_layer_add_track ( vtl
, new_tr_name
, tracks
[i
] );
1961 vik_trw_layer_delete_track ( vtl
, (gchar
*) pass_along
[3] );
1962 vik_layer_emit_update ( VIK_LAYER(vtl
) ); /* chase thru the hoops */
1969 static void goto_coord ( VikLayersPanel
*vlp
, const VikCoord
*coord
)
1971 vik_viewport_set_center_coord ( vik_layers_panel_get_viewport(vlp
), coord
);
1972 vik_layers_panel_emit_update ( vlp
);
1975 static void trw_layer_goto_track_startpoint ( gpointer pass_along
[5] )
1977 GList
*trps
= ((VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] ))->trackpoints
;
1978 if ( trps
&& trps
->data
)
1979 goto_coord ( VIK_LAYERS_PANEL(pass_along
[1]), &(((VikTrackpoint
*) trps
->data
)->coord
));
1982 static void trw_layer_goto_track_center ( gpointer pass_along
[5] )
1984 GList
**trps
= g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] );
1985 if ( trps
&& *trps
)
1987 struct LatLon average
, maxmin
[2] = { {0,0}, {0,0} };
1989 trw_layer_find_maxmin_tracks ( NULL
, trps
, maxmin
);
1990 average
.lat
= (maxmin
[0].lat
+maxmin
[1].lat
)/2;
1991 average
.lon
= (maxmin
[0].lon
+maxmin
[1].lon
)/2;
1992 vik_coord_load_from_latlon ( &coord
, VIK_TRW_LAYER(pass_along
[0])->coord_mode
, &average
);
1993 goto_coord ( VIK_LAYERS_PANEL(pass_along
[1]), &coord
);
1997 static void trw_layer_apply_dem_data ( gpointer pass_along
[6] )
1999 /* TODO: check & warn if no DEM data, or no applicable DEM data. */
2000 /* Also warn if overwrite old elevation data */
2001 VikTrack
*track
= (VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] );
2003 vik_track_apply_dem_data ( track
);
2007 static void trw_layer_goto_track_endpoint ( gpointer pass_along
[6] )
2009 GList
*trps
= ((VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] ))->trackpoints
;
2012 trps
= g_list_last(trps
);
2013 goto_coord ( VIK_LAYERS_PANEL(pass_along
[1]), &(((VikTrackpoint
*) trps
->data
)->coord
));
2017 /*************************************
2018 * merge/split by time routines
2019 *************************************/
2021 /* called for each key in track hash table. if original track user_data[1] is close enough
2022 * to the passed one, add it to list in user_data[0]
2024 static void find_nearby_track(gpointer key
, gpointer value
, gpointer user_data
)
2027 VikTrackpoint
*p1
, *p2
;
2029 GList
**nearby_tracks
= ((gpointer
*)user_data
)[0];
2030 GList
*orig_track
= ((gpointer
*)user_data
)[1];
2031 guint thr
= (guint
)((gpointer
*)user_data
)[2];
2033 t1
= VIK_TRACKPOINT(orig_track
->data
)->timestamp
;
2034 t2
= VIK_TRACKPOINT(g_list_last(orig_track
)->data
)->timestamp
;
2036 if (VIK_TRACK(value
)->trackpoints
== orig_track
) {
2040 p1
= VIK_TRACKPOINT(VIK_TRACK(value
)->trackpoints
->data
);
2041 p2
= VIK_TRACKPOINT(g_list_last(VIK_TRACK(value
)->trackpoints
)->data
);
2043 if (!p1
->has_timestamp
|| !p2
->has_timestamp
) {
2044 g_print("no timestamp\n");
2048 /* g_print("Got track named %s, times %d, %d\n", (gchar *)key, p1->timestamp, p2->timestamp); */
2049 if (abs(t1
- p2
->timestamp
) < thr
*60 ||
2051 abs(p1
->timestamp
- t2
) < thr
*60
2054 *nearby_tracks
= g_list_prepend(*nearby_tracks
, key
);
2058 /* comparison function used to sort tracks; a and b are hash table keys */
2059 static gint
track_compare(gconstpointer a
, gconstpointer b
, gpointer user_data
)
2061 GHashTable
*tracks
= user_data
;
2064 t1
= VIK_TRACKPOINT(VIK_TRACK(g_hash_table_lookup(tracks
, a
))->trackpoints
->data
)->timestamp
;
2065 t2
= VIK_TRACKPOINT(VIK_TRACK(g_hash_table_lookup(tracks
, b
))->trackpoints
->data
)->timestamp
;
2067 if (t1
< t2
) return -1;
2068 if (t1
> t2
) return 1;
2072 /* comparison function used to sort trackpoints */
2073 static gint
trackpoint_compare(gconstpointer a
, gconstpointer b
)
2075 time_t t1
= VIK_TRACKPOINT(a
)->timestamp
, t2
= VIK_TRACKPOINT(b
)->timestamp
;
2077 if (t1
< t2
) return -1;
2078 if (t1
> t2
) return 1;
2082 /* merge by time routine */
2083 static void trw_layer_merge_by_timestamp ( gpointer pass_along
[6] )
2086 GList
*nearby_tracks
= NULL
;
2089 static guint thr
= 1;
2090 guint track_count
= 0;
2091 gchar
*orig_track_name
= strdup(pass_along
[3]);
2093 if (!a_dialog_time_threshold(VIK_GTK_WINDOW_FROM_LAYER(pass_along
[0]),
2094 "Merge Threshold...",
2095 "Merge when time between trackpoints less than:",
2100 /* merge tracks until we can't */
2104 track
= (VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, orig_track_name
);
2105 trps
= track
->trackpoints
;
2110 if (nearby_tracks
) {
2111 g_list_free(nearby_tracks
);
2112 nearby_tracks
= NULL
;
2115 t1
= ((VikTrackpoint
*)trps
->data
)->timestamp
;
2116 t2
= ((VikTrackpoint
*)g_list_last(trps
)->data
)->timestamp
;
2118 /* g_print("Original track times: %d and %d\n", t1, t2); */
2119 params
[0] = &nearby_tracks
;
2121 params
[2] = (gpointer
)thr
;
2123 /* get a list of adjacent-in-time tracks */
2124 g_hash_table_foreach(VIK_TRW_LAYER(pass_along
[0])->tracks
, find_nearby_track
, (gpointer
)params
);
2126 /* add original track */
2127 nearby_tracks
= g_list_prepend(nearby_tracks
, orig_track_name
);
2129 /* sort by first trackpoint; assumes they don't overlap */
2130 nearby_tracks
= g_list_sort_with_data(nearby_tracks
, track_compare
, VIK_TRW_LAYER(pass_along
[0])->tracks
);
2134 #define get_track(x) VIK_TRACK(g_hash_table_lookup(VIK_TRW_LAYER(pass_along[0])->tracks, (gchar *)((x)->data)))
2135 #define get_first_trackpoint(x) VIK_TRACKPOINT(get_track(x)->trackpoints->data)
2136 #define get_last_trackpoint(x) VIK_TRACKPOINT(g_list_last(get_track(x)->trackpoints)->data)
2137 GList
*l
= nearby_tracks
;
2138 VikTrack
*tr
= vik_track_new();
2139 tr
->visible
= track
->visible
;
2144 t1 = get_first_trackpoint(l)->timestamp;
2145 t2 = get_last_trackpoint(l)->timestamp;
2146 g_print(" %20s: track %d - %d\n", (char *)l->data, (int)t1, (int)t2);
2150 /* remove trackpoints from merged track, delete track */
2151 tr
->trackpoints
= g_list_concat(tr
->trackpoints
, get_track(l
)->trackpoints
);
2152 get_track(l
)->trackpoints
= NULL
;
2153 vik_trw_layer_delete_track(VIK_TRW_LAYER(pass_along
[0]), l
->data
);
2158 tr
->trackpoints
= g_list_sort(tr
->trackpoints
, trackpoint_compare
);
2159 vik_trw_layer_add_track(VIK_TRW_LAYER(pass_along
[0]), strdup(orig_track_name
), tr
);
2161 #undef get_first_trackpoint
2162 #undef get_last_trackpoint
2165 } while (track_count
> 1);
2166 g_list_free(nearby_tracks
);
2167 free(orig_track_name
);
2168 vik_layer_emit_update(VIK_LAYER(pass_along
[0]));
2171 /* split by time routine */
2172 static void trw_layer_split_by_timestamp ( gpointer pass_along
[6] )
2174 VikTrack
*track
= (VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] );
2175 GList
*trps
= track
->trackpoints
;
2177 GList
*newlists
= NULL
;
2178 GList
*newtps
= NULL
;
2180 static guint thr
= 1;
2187 if (!a_dialog_time_threshold(VIK_GTK_WINDOW_FROM_LAYER(pass_along
[0]),
2188 "Split Threshold...",
2189 "Split when time between trackpoints exceeds:",
2194 /* iterate through trackpoints, and copy them into new lists without touching original list */
2195 prev_ts
= VIK_TRACKPOINT(trps
->data
)->timestamp
;
2199 ts
= VIK_TRACKPOINT(iter
->data
)->timestamp
;
2201 g_print("panic: ts < prev_ts: this should never happen!\n");
2204 if (ts
- prev_ts
> thr
*60) {
2205 /* flush accumulated trackpoints into new list */
2206 newlists
= g_list_prepend(newlists
, g_list_reverse(newtps
));
2210 /* accumulate trackpoint copies in newtps, in reverse order */
2211 newtps
= g_list_prepend(newtps
, vik_trackpoint_copy(VIK_TRACKPOINT(iter
->data
)));
2213 iter
= g_list_next(iter
);
2216 newlists
= g_list_prepend(newlists
, g_list_reverse(newtps
));
2219 /* put lists of trackpoints into tracks */
2226 tr
= vik_track_new();
2227 tr
->visible
= track
->visible
;
2228 tr
->trackpoints
= (GList
*)(iter
->data
);
2230 new_tr_name
= g_strdup_printf("%s #%d", (gchar
*) pass_along
[3], i
++);
2231 vik_trw_layer_add_track(VIK_TRW_LAYER(pass_along
[0]), new_tr_name
, tr
);
2232 /* g_print("adding track %s, times %d - %d\n", new_tr_name, VIK_TRACKPOINT(tr->trackpoints->data)->timestamp,
2233 VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp);*/
2235 iter
= g_list_next(iter
);
2237 g_list_free(newlists
);
2238 vik_trw_layer_delete_track(VIK_TRW_LAYER(pass_along
[0]), (gchar
*)pass_along
[3]);
2239 vik_layer_emit_update(VIK_LAYER(pass_along
[0]));
2242 /* end of split/merge routines */
2245 static void trw_layer_goto_waypoint ( gpointer pass_along
[5] )
2247 VikWaypoint
*wp
= g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->waypoints
, pass_along
[3] );
2249 goto_coord ( VIK_LAYERS_PANEL(pass_along
[1]), &(wp
->coord
) );
2252 static void trw_layer_waypoint_gc_webpage ( gpointer pass_along
[5] )
2254 gchar
*webpage
= g_strdup_printf("http://www.geocaching.com/seek/cache_details.aspx?wp=%s", (gchar
*) pass_along
[3] );
2256 ShellExecute(NULL
, NULL
, (char *) webpage
, NULL
, ".\\", 0);
2259 gchar
*cmd
= g_strdup_printf ( "%s %s", UNIX_WEB_BROWSER
, webpage
);
2260 if ( ! g_spawn_command_line_async ( cmd
, &err
) )
2262 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(VIK_LAYER(pass_along
[0])), "Could not launch web browser." );
2263 g_error_free ( err
);
2266 #endif /* WINDOWS */
2270 const gchar
*vik_trw_layer_sublayer_rename_request ( VikTrwLayer
*l
, const gchar
*newname
, gpointer vlp
, gint subtype
, gpointer sublayer
, GtkTreeIter
*iter
)
2272 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
)
2278 if ( strcasecmp ( newname
, sublayer
) == 0 )
2281 if ( uppercase_exists_in_hash ( l
->waypoints
, newname
) )
2283 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(l
), "Waypoint Already Exists" );
2287 iter
= g_hash_table_lookup ( l
->waypoints_iters
, sublayer
);
2288 g_hash_table_steal ( l
->waypoints_iters
, sublayer
);
2290 wp
= vik_waypoint_copy ( VIK_WAYPOINT(g_hash_table_lookup ( l
->waypoints
, sublayer
)) );
2291 g_hash_table_remove ( l
->waypoints
, sublayer
);
2293 rv
= g_strdup(newname
);
2294 for ( i
= strlen(rv
) - 1; i
>= 0; i
-- )
2295 rv
[i
] = toupper(rv
[i
]);
2297 vik_treeview_item_set_pointer ( VIK_LAYER(l
)->vt
, iter
, rv
);
2299 g_hash_table_insert ( l
->waypoints
, rv
, wp
);
2300 g_hash_table_insert ( l
->waypoints_iters
, rv
, iter
);
2302 /* it hasn't been updated yet so we pass new name */
2303 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
2304 vik_treeview_sublayer_realphabetize ( VIK_LAYER(l
)->vt
, iter
, rv
);
2307 vik_layers_panel_emit_update ( VIK_LAYERS_PANEL(vlp
) );
2310 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_TRACK
)
2318 if ( strcasecmp ( newname
, sublayer
) == 0 )
2321 if ( uppercase_exists_in_hash ( l
->tracks
, newname
) )
2323 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(l
), "Track Already Exists" );
2327 g_hash_table_lookup_extended ( l
->tracks
, sublayer
, (void *)&orig_key
, (void *)&tr
);
2328 g_hash_table_steal ( l
->tracks
, sublayer
);
2330 iter
= g_hash_table_lookup ( l
->tracks_iters
, sublayer
);
2331 g_hash_table_steal ( l
->tracks_iters
, sublayer
);
2333 rv
= g_strdup(newname
);
2334 for ( i
= strlen(rv
) - 1; i
>= 0; i
-- )
2335 rv
[i
] = toupper(rv
[i
]);
2337 vik_treeview_item_set_pointer ( VIK_LAYER(l
)->vt
, iter
, rv
);
2339 g_hash_table_insert ( l
->tracks
, rv
, tr
);
2340 g_hash_table_insert ( l
->tracks_iters
, rv
, iter
);
2342 /* don't forget about current_tp_track_name, update that too */
2343 if ( l
->current_tp_track_name
&& g_strcasecmp(orig_key
,l
->current_tp_track_name
) == 0 )
2345 l
->current_tp_track_name
= rv
;
2347 vik_trw_layer_tpwin_set_track_name ( l
->tpwin
, rv
);
2349 else if ( l
->last_tp_track_name
&& g_strcasecmp(orig_key
,l
->last_tp_track_name
) == 0 )
2350 l
->last_tp_track_name
= rv
;
2352 g_free ( orig_key
);
2354 #ifdef VIK_CONFIG_ALPHABETIZED_TRW
2355 vik_treeview_sublayer_realphabetize ( VIK_LAYER(l
)->vt
, iter
, rv
);
2358 vik_layers_panel_emit_update ( VIK_LAYERS_PANEL(vlp
) );
2364 static gboolean
is_valid_geocache_name ( gchar
*str
)
2366 gint len
= strlen ( str
);
2367 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]));
2370 /* vlp can be NULL if necessary - i.e. right-click from a tool -- but be careful, some functions may try to use it */
2371 gboolean
vik_trw_layer_sublayer_add_menu_items ( VikTrwLayer
*l
, GtkMenu
*menu
, gpointer vlp
, gint subtype
, gpointer sublayer
, GtkTreeIter
*iter
)
2373 static GtkTreeIter staticiter
;
2374 static gpointer pass_along
[5];
2376 gboolean rv
= FALSE
;
2379 pass_along
[1] = vlp
;
2380 pass_along
[2] = (gpointer
) subtype
;
2381 pass_along
[3] = sublayer
;
2382 staticiter
= *iter
; /* will exist after function has ended */
2383 pass_along
[4] = &staticiter
;
2385 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
|| subtype
== VIK_TRW_LAYER_SUBLAYER_TRACK
)
2389 item
= gtk_image_menu_item_new_from_stock ( GTK_STOCK_PROPERTIES
, NULL
);
2390 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_properties_item
), pass_along
);
2391 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2392 gtk_widget_show ( item
);
2394 item
= gtk_image_menu_item_new_from_stock ( GTK_STOCK_CUT
, NULL
);
2395 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_cut_item_cb
), pass_along
);
2396 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2397 gtk_widget_show ( item
);
2399 item
= gtk_image_menu_item_new_from_stock ( GTK_STOCK_COPY
, NULL
);
2400 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_copy_item_cb
), pass_along
);
2401 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2402 gtk_widget_show ( item
);
2404 item
= gtk_image_menu_item_new_from_stock ( GTK_STOCK_DELETE
, NULL
);
2405 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_delete_item
), pass_along
);
2406 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2407 gtk_widget_show ( item
);
2409 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
)
2411 /* could be a right-click using the tool */
2412 if ( vlp
!= NULL
) {
2413 item
= gtk_menu_item_new_with_label ( "Goto" );
2414 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_goto_waypoint
), pass_along
);
2415 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2416 gtk_widget_show ( item
);
2419 if ( is_valid_geocache_name ( (gchar
*) sublayer
) )
2421 item
= gtk_menu_item_new_with_label ( "Visit Geocache Webpage" );
2422 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_waypoint_gc_webpage
), pass_along
);
2423 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2424 gtk_widget_show ( item
);
2430 if ( subtype
== VIK_TRW_LAYER_SUBLAYER_TRACK
)
2432 item
= gtk_menu_item_new ();
2433 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2434 gtk_widget_show ( item
);
2436 item
= gtk_menu_item_new_with_label ( "Goto Startpoint" );
2437 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_goto_track_startpoint
), pass_along
);
2438 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2439 gtk_widget_show ( item
);
2441 item
= gtk_menu_item_new_with_label ( "Goto \"Center\"" );
2442 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_goto_track_center
), pass_along
);
2443 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2444 gtk_widget_show ( item
);
2446 item
= gtk_menu_item_new_with_label ( "Goto Endpoint" );
2447 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_goto_track_endpoint
), pass_along
);
2448 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2449 gtk_widget_show ( item
);
2451 item
= gtk_menu_item_new_with_label ( "Merge By Time" );
2452 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_merge_by_timestamp
), pass_along
);
2453 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2454 gtk_widget_show ( item
);
2456 item
= gtk_menu_item_new_with_label ( "Split By Time" );
2457 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_split_by_timestamp
), pass_along
);
2458 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2459 gtk_widget_show ( item
);
2461 item
= gtk_menu_item_new_with_label ( "Download maps along track..." );
2462 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_download_map_along_track_cb
), pass_along
);
2463 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2464 gtk_widget_show ( item
);
2466 item
= gtk_menu_item_new_with_label ( "Apply DEM Data" );
2467 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_apply_dem_data
), pass_along
);
2468 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2469 gtk_widget_show ( item
);
2472 if ( vlp
&& (subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINTS
|| subtype
== VIK_TRW_LAYER_SUBLAYER_WAYPOINT
) )
2474 item
= gtk_menu_item_new ();
2475 gtk_menu_shell_append ( GTK_MENU_SHELL(menu
), item
);
2476 gtk_widget_show ( item
);
2478 item
= gtk_menu_item_new_with_label ( "New Waypoint" );
2479 g_signal_connect_swapped ( G_OBJECT(item
), "activate", G_CALLBACK(trw_layer_new_wp
), pass_along
);
2480 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);
2481 gtk_widget_show ( item
);
2488 /* to be called when last_tpl no long exists. */
2489 static void trw_layer_cancel_last_tp ( VikTrwLayer
*vtl
)
2491 if ( vtl
->tpwin
) /* can't join with a non-existant TP. */
2492 vik_trw_layer_tpwin_disable_join ( vtl
->tpwin
);
2493 vtl
->last_tpl
= NULL
;
2494 vtl
->last_tp_track_name
= NULL
;
2497 static void trw_layer_cancel_current_tp ( VikTrwLayer
*vtl
, gboolean destroy
)
2503 gtk_widget_destroy ( GTK_WIDGET(vtl
->tpwin
) );
2507 vik_trw_layer_tpwin_set_empty ( vtl
->tpwin
);
2509 if ( vtl
->current_tpl
)
2511 vtl
->current_tpl
= NULL
;
2512 vtl
->current_tp_track_name
= NULL
;
2513 vik_layer_emit_update(VIK_LAYER(vtl
));
2517 static void trw_layer_tpwin_response ( VikTrwLayer
*vtl
, gint response
)
2519 g_assert ( vtl
->tpwin
!= NULL
);
2520 if ( response
== VIK_TRW_LAYER_TPWIN_CLOSE
)
2521 trw_layer_cancel_current_tp ( vtl
, TRUE
);
2522 else if ( response
== VIK_TRW_LAYER_TPWIN_SPLIT
&& vtl
->current_tpl
->next
&& vtl
->current_tpl
->prev
)
2525 if ( ( name
= a_dialog_new_track ( GTK_WINDOW(vtl
->tpwin
), vtl
->tracks
) ) )
2527 VikTrack
*tr
= vik_track_new ();
2528 GList
*newglist
= g_list_alloc ();
2529 newglist
->prev
= NULL
;
2530 newglist
->next
= vtl
->current_tpl
->next
;
2531 newglist
->data
= vik_trackpoint_copy(VIK_TRACKPOINT(vtl
->current_tpl
->data
));
2532 tr
->trackpoints
= newglist
;
2534 vtl
->current_tpl
->next
->prev
= newglist
; /* end old track here */
2535 vtl
->current_tpl
->next
= NULL
;
2537 vtl
->current_tpl
= newglist
; /* change tp to first of new track. */
2538 vtl
->current_tp_track_name
= name
;
2540 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
, vtl
->current_tp_track_name
);
2542 vik_trw_layer_add_track ( vtl
, name
, tr
);
2543 vik_layer_emit_update(VIK_LAYER(vtl
));
2546 else if ( response
== VIK_TRW_LAYER_TPWIN_DELETE
)
2548 VikTrack
*tr
= g_hash_table_lookup ( vtl
->tracks
, vtl
->current_tp_track_name
);
2550 g_assert(tr
!= NULL
);
2552 /* can't join with a non-existent trackpoint */
2553 vtl
->last_tpl
= NULL
;
2554 vtl
->last_tp_track_name
= NULL
;
2556 if ( (new_tpl
= vtl
->current_tpl
->next
) || (new_tpl
= vtl
->current_tpl
->prev
) )
2558 if ( VIK_TRACKPOINT(vtl
->current_tpl
->data
)->newsegment
&& vtl
->current_tpl
->next
)
2559 VIK_TRACKPOINT(vtl
->current_tpl
->next
->data
)->newsegment
= TRUE
; /* don't concat segments on del */
2561 tr
->trackpoints
= g_list_remove_link ( tr
->trackpoints
, vtl
->current_tpl
); /* this nulls current_tpl->prev and next */
2563 /* at this point the old trackpoint exists, but the list links are correct (new), so it is safe to do this. */
2564 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, new_tpl
, vtl
->current_tp_track_name
);
2566 trw_layer_cancel_last_tp ( vtl
);
2568 g_free ( vtl
->current_tpl
->data
); /* TODO: vik_trackpoint_free() */
2569 g_list_free_1 ( vtl
->current_tpl
);
2570 vtl
->current_tpl
= new_tpl
;
2571 vik_layer_emit_update(VIK_LAYER(vtl
));
2575 tr
->trackpoints
= g_list_remove_link ( tr
->trackpoints
, vtl
->current_tpl
);
2576 g_free ( vtl
->current_tpl
->data
); /* TODO longone: vik_trackpoint_new() and vik_trackpoint_free() */
2577 g_list_free_1 ( vtl
->current_tpl
);
2578 trw_layer_cancel_current_tp ( vtl
, FALSE
);
2581 else if ( response
== VIK_TRW_LAYER_TPWIN_FORWARD
&& vtl
->current_tpl
->next
)
2583 vtl
->last_tpl
= vtl
->current_tpl
;
2584 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
= vtl
->current_tpl
->next
, vtl
->current_tp_track_name
);
2585 vik_layer_emit_update(VIK_LAYER(vtl
)); /* TODO longone: either move or only update if tp is inside drawing window */
2587 else if ( response
== VIK_TRW_LAYER_TPWIN_BACK
&& vtl
->current_tpl
->prev
)
2589 vtl
->last_tpl
= vtl
->current_tpl
;
2590 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
= vtl
->current_tpl
->prev
, vtl
->current_tp_track_name
);
2591 vik_layer_emit_update(VIK_LAYER(vtl
));
2593 else if ( response
== VIK_TRW_LAYER_TPWIN_JOIN
)
2595 VikTrack
*tr1
= g_hash_table_lookup ( vtl
->tracks
, vtl
->last_tp_track_name
);
2596 VikTrack
*tr2
= g_hash_table_lookup ( vtl
->tracks
, vtl
->current_tp_track_name
);
2598 VikTrack
*tr_first
= tr1
, *tr_last
= tr2
;
2602 if ( (!vtl
->last_tpl
->next
) && (!vtl
->current_tpl
->next
) ) /* both endpoints */
2603 vik_track_reverse ( tr2
); /* reverse the second, that way second track clicked will be later. */
2604 else if ( (!vtl
->last_tpl
->prev
) && (!vtl
->current_tpl
->prev
) )
2605 vik_track_reverse ( tr1
);
2606 else if ( (!vtl
->last_tpl
->prev
) && (!vtl
->current_tpl
->next
) ) /* clicked startpoint, then endpoint -- concat end to start */
2611 /* default -- clicked endpoint then startpoint -- connect endpoint to startpoint */
2613 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. */
2614 VIK_TRACKPOINT(tr_last
->trackpoints
->data
)->newsegment
= FALSE
;
2615 tr1
->trackpoints
= g_list_concat ( tr_first
->trackpoints
, tr_last
->trackpoints
);
2616 tr2
->trackpoints
= NULL
;
2618 tmp
= vtl
->current_tp_track_name
;
2620 vtl
->current_tp_track_name
= vtl
->last_tp_track_name
; /* current_tp stays the same (believe it or not!) */
2621 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
, vtl
->current_tp_track_name
);
2623 /* if we did this before, trw_layer_delete_track would have canceled the current tp because
2624 * it was the current track. canceling the current tp would have set vtl->current_tpl to NULL */
2625 vik_trw_layer_delete_track ( vtl
, tmp
);
2627 trw_layer_cancel_last_tp ( vtl
); /* same TP, can't join. */
2628 vik_layer_emit_update(VIK_LAYER(vtl
));
2630 else if ( response
== VIK_TRW_LAYER_TPWIN_DATA_CHANGED
)
2631 vik_layer_emit_update (VIK_LAYER(vtl
));
2634 static void trw_layer_tpwin_init ( VikTrwLayer
*vtl
)
2638 vtl
->tpwin
= vik_trw_layer_tpwin_new ( VIK_GTK_WINDOW_FROM_LAYER(vtl
) );
2639 g_signal_connect_swapped ( GTK_DIALOG(vtl
->tpwin
), "response", G_CALLBACK(trw_layer_tpwin_response
), vtl
);
2640 /* connect signals -- DELETE SIGNAL VERY IMPORTANT TO SET TO NULL */
2641 g_signal_connect_swapped ( vtl
->tpwin
, "delete-event", G_CALLBACK(trw_layer_cancel_current_tp
), vtl
);
2642 gtk_widget_show_all ( GTK_WIDGET(vtl
->tpwin
) );
2644 if ( vtl
->current_tpl
)
2645 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
, vtl
->current_tp_track_name
);
2646 /* set layer name and TP data */
2649 /***************************************************************************
2651 ***************************************************************************/
2653 /*** Utility data structures and functions ****/
2657 gint closest_x
, closest_y
;
2658 gchar
*closest_wp_name
;
2659 VikWaypoint
*closest_wp
;
2665 gint closest_x
, closest_y
;
2666 gchar
*closest_track_name
;
2667 VikTrackpoint
*closest_tp
;
2672 static void waypoint_search_closest_tp ( gchar
*name
, VikWaypoint
*wp
, WPSearchParams
*params
)
2678 vik_viewport_coord_to_screen ( params
->vvp
, &(wp
->coord
), &x
, &y
);
2680 if ( abs (x
- params
->x
) <= WAYPOINT_SIZE_APPROX
&& abs (y
- params
->y
) <= WAYPOINT_SIZE_APPROX
&&
2681 ((!params
->closest_wp
) || /* was the old waypoint we already found closer than this one? */
2682 abs(x
- params
->x
)+abs(y
- params
->y
) < abs(x
- params
->closest_x
)+abs(y
- params
->closest_y
)))
2684 params
->closest_wp_name
= name
;
2685 params
->closest_wp
= wp
;
2686 params
->closest_x
= x
;
2687 params
->closest_y
= y
;
2691 static void track_search_closest_tp ( gchar
*name
, VikTrack
*t
, TPSearchParams
*params
)
2693 GList
*tpl
= t
->trackpoints
;
2702 tp
= VIK_TRACKPOINT(tpl
->data
);
2704 vik_viewport_coord_to_screen ( params
->vvp
, &(tp
->coord
), &x
, &y
);
2706 if ( abs (x
- params
->x
) <= TRACKPOINT_SIZE_APPROX
&& abs (y
- params
->y
) <= TRACKPOINT_SIZE_APPROX
&&
2707 ((!params
->closest_tp
) || /* was the old trackpoint we already found closer than this one? */
2708 abs(x
- params
->x
)+abs(y
- params
->y
) < abs(x
- params
->closest_x
)+abs(y
- params
->closest_y
)))
2710 params
->closest_track_name
= name
;
2711 params
->closest_tp
= tp
;
2712 params
->closest_tpl
= tpl
;
2713 params
->closest_x
= x
;
2714 params
->closest_y
= y
;
2720 static VikTrackpoint
*closest_tp_in_five_pixel_interval ( VikTrwLayer
*vtl
, VikViewport
*vvp
, gint x
, gint y
)
2722 TPSearchParams params
;
2726 params
.closest_track_name
= NULL
;
2727 params
.closest_tp
= NULL
;
2728 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) track_search_closest_tp
, ¶ms
);
2729 return params
.closest_tp
;
2732 static VikWaypoint
*closest_wp_in_five_pixel_interval ( VikTrwLayer
*vtl
, VikViewport
*vvp
, gint x
, gint y
)
2734 WPSearchParams params
;
2738 params
.closest_wp
= NULL
;
2739 params
.closest_wp_name
= NULL
;
2740 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) waypoint_search_closest_tp
, ¶ms
);
2741 return params
.closest_wp
;
2744 /* background drawing hook, to be passed the viewport */
2745 static gboolean tool_sync_done
= TRUE
;
2747 static gboolean
tool_sync(gpointer data
)
2749 VikViewport
*vvp
= data
;
2750 gdk_threads_enter();
2751 vik_viewport_sync(vvp
);
2752 tool_sync_done
= TRUE
;
2753 gdk_threads_leave();
2764 static void marker_begin_move ( tool_ed_t
*t
, gint x
, gint y
)
2767 t
->gc
= vik_viewport_new_gc (t
->vvp
, "black", 2);
2768 gdk_gc_set_function ( t
->gc
, GDK_INVERT
);
2769 vik_viewport_draw_rectangle ( t
->vvp
, t
->gc
, FALSE
, x
-3, y
-3, 6, 6 );
2770 vik_viewport_sync(t
->vvp
);
2775 static void marker_moveto ( tool_ed_t
*t
, gint x
, gint y
)
2777 VikViewport
*vvp
= t
->vvp
;
2778 vik_viewport_draw_rectangle ( vvp
, t
->gc
, FALSE
, t
->oldx
-3, t
->oldy
-3, 6, 6 );
2779 vik_viewport_draw_rectangle ( vvp
, t
->gc
, FALSE
, x
-3, y
-3, 6, 6 );
2782 if (tool_sync_done
) {
2783 g_idle_add_full (G_PRIORITY_HIGH_IDLE
+ 10, tool_sync
, vvp
, NULL
);
2784 tool_sync_done
= FALSE
;
2788 static void marker_end_move ( tool_ed_t
*t
)
2790 vik_viewport_draw_rectangle ( t
->vvp
, t
->gc
, FALSE
, t
->oldx
-3, t
->oldy
-3, 6, 6 );
2791 g_object_unref ( t
->gc
);
2795 /*** Edit waypoint ****/
2797 static gpointer
tool_edit_waypoint_create ( VikWindow
*vw
, VikViewport
*vvp
)
2799 tool_ed_t
*t
= g_new(tool_ed_t
, 1);
2805 static gboolean
tool_edit_waypoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
2807 WPSearchParams params
;
2808 tool_ed_t
*t
= data
;
2809 VikViewport
*vvp
= t
->vvp
;
2811 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
2818 if ( vtl
->current_wp
&& vtl
->current_wp
->visible
)
2820 /* first check if current WP is within area (other may be 'closer', but we want to move the current) */
2822 vik_viewport_coord_to_screen ( vvp
, &(vtl
->current_wp
->coord
), &x
, &y
);
2824 if ( abs(x
- event
->x
) <= WAYPOINT_SIZE_APPROX
&&
2825 abs(y
- event
->y
) <= WAYPOINT_SIZE_APPROX
)
2827 if ( event
->button
== 3 )
2828 vtl
->waypoint_rightclick
= TRUE
; /* remember that we're clicking; other layers will ignore release signal */
2830 marker_begin_move(t
, event
->x
, event
->y
);
2837 params
.x
= event
->x
;
2838 params
.y
= event
->y
;
2839 params
.closest_wp_name
= NULL
;
2840 /* TODO: should get track listitem so we can break it up, make a new track, mess it up, all that. */
2841 params
.closest_wp
= NULL
;
2842 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) waypoint_search_closest_tp
, ¶ms
);
2843 if ( vtl
->current_wp
== params
.closest_wp
&& vtl
->current_wp
!= NULL
)
2845 /* how do we get here? I'm putting in the abort until we can figure it out. -alex */
2846 marker_begin_move(t
, event
->x
, event
->y
);
2847 g_critical("shouldn't be here");
2850 else if ( params
.closest_wp
)
2852 if ( event
->button
== 3 )
2853 vtl
->waypoint_rightclick
= TRUE
; /* remember that we're clicking; other layers will ignore release signal */
2855 vtl
->waypoint_rightclick
= FALSE
;
2857 vtl
->current_wp
= params
.closest_wp
;
2858 vtl
->current_wp_name
= params
.closest_wp_name
;
2860 if ( params
.closest_wp
)
2861 vik_treeview_select_iter ( VIK_LAYER(vtl
)->vt
, g_hash_table_lookup ( vtl
->waypoints_iters
, vtl
->current_wp_name
) );
2863 /* could make it so don't update if old WP is off screen and new is null but oh well */
2864 vik_layer_emit_update ( VIK_LAYER(vtl
) );
2868 vtl
->current_wp
= NULL
;
2869 vtl
->current_wp_name
= NULL
;
2870 vtl
->waypoint_rightclick
= FALSE
;
2871 vik_layer_emit_update ( VIK_LAYER(vtl
) );
2875 static gboolean
tool_edit_waypoint_move ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
2877 tool_ed_t
*t
= data
;
2878 VikViewport
*vvp
= t
->vvp
;
2880 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
2885 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &new_coord
);
2888 if ( event
->state
& GDK_CONTROL_MASK
)
2890 VikTrackpoint
*tp
= closest_tp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
2892 new_coord
= tp
->coord
;
2896 if ( event
->state
& GDK_SHIFT_MASK
)
2898 VikWaypoint
*wp
= closest_wp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
2899 if ( wp
&& wp
!= vtl
->current_wp
)
2900 new_coord
= wp
->coord
;
2905 vik_viewport_coord_to_screen ( vvp
, &new_coord
, &x
, &y
);
2906 marker_moveto ( t
, x
, y
);
2913 static gboolean
tool_edit_waypoint_release ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
2915 tool_ed_t
*t
= data
;
2916 VikViewport
*vvp
= t
->vvp
;
2918 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
2921 if ( t
->holding
&& event
->button
== 1 )
2924 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &new_coord
);
2927 if ( event
->state
& GDK_CONTROL_MASK
)
2929 VikTrackpoint
*tp
= closest_tp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
2931 new_coord
= tp
->coord
;
2935 if ( event
->state
& GDK_SHIFT_MASK
)
2937 VikWaypoint
*wp
= closest_wp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
2938 if ( wp
&& wp
!= vtl
->current_wp
)
2939 new_coord
= wp
->coord
;
2942 marker_end_move ( t
);
2944 vtl
->current_wp
->coord
= new_coord
;
2945 vik_layer_emit_update ( VIK_LAYER(vtl
) );
2948 /* PUT IN RIGHT PLACE!!! */
2949 if ( event
->button
== 3 && vtl
->waypoint_rightclick
)
2951 if ( vtl
->wp_right_click_menu
)
2952 gtk_object_sink ( GTK_OBJECT(vtl
->wp_right_click_menu
) );
2953 vtl
->wp_right_click_menu
= GTK_MENU ( gtk_menu_new () );
2954 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
) );
2955 gtk_menu_popup ( vtl
->wp_right_click_menu
, NULL
, NULL
, NULL
, NULL
, event
->button
, gtk_get_current_event_time() );
2956 vtl
->waypoint_rightclick
= FALSE
;
2961 /*** New track ****/
2963 static gpointer
tool_new_track_create ( VikWindow
*vw
, VikViewport
*vvp
)
2968 static gboolean
tool_new_track_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
)
2972 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
2975 if ( event
->button
== 3 && vtl
->current_track
)
2978 if ( vtl
->current_track
->trackpoints
)
2980 GList
*last
= g_list_last(vtl
->current_track
->trackpoints
);
2981 g_free ( last
->data
);
2982 vtl
->current_track
->trackpoints
= g_list_remove_link ( vtl
->current_track
->trackpoints
, last
);
2984 vik_layer_emit_update ( VIK_LAYER(vtl
) );
2988 if ( event
->type
== GDK_2BUTTON_PRESS
)
2990 /* subtract last (duplicate from double click) tp then end */
2991 if ( vtl
->current_track
&& vtl
->current_track
->trackpoints
&& vtl
->ct_x1
== vtl
->ct_x2
&& vtl
->ct_y1
== vtl
->ct_y2
)
2993 GList
*last
= g_list_last(vtl
->current_track
->trackpoints
);
2994 g_free ( last
->data
);
2995 vtl
->current_track
->trackpoints
= g_list_remove_link ( vtl
->current_track
->trackpoints
, last
);
2996 /* undo last, then end */
2997 vtl
->current_track
= NULL
;
3002 if ( ! vtl
->current_track
)
3005 if ( ( name
= a_dialog_new_track ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), vtl
->tracks
) ) )
3007 vtl
->current_track
= vik_track_new();
3008 vtl
->current_track
->visible
= TRUE
;
3009 vik_trw_layer_add_track ( vtl
, name
, vtl
->current_track
);
3014 tp
= vik_trackpoint_new();
3015 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &(tp
->coord
) );
3017 /* snap to other TP */
3018 if ( event
->state
& GDK_CONTROL_MASK
)
3020 VikTrackpoint
*other_tp
= closest_tp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
3022 tp
->coord
= other_tp
->coord
;
3025 tp
->newsegment
= FALSE
;
3026 tp
->has_timestamp
= FALSE
;
3028 tp
->altitude
= VIK_DEFAULT_ALTITUDE
;
3029 vtl
->current_track
->trackpoints
= g_list_append ( vtl
->current_track
->trackpoints
, tp
);
3031 vtl
->ct_x1
= vtl
->ct_x2
;
3032 vtl
->ct_y1
= vtl
->ct_y2
;
3033 vtl
->ct_x2
= event
->x
;
3034 vtl
->ct_y2
= event
->y
;
3036 vik_layer_emit_update ( VIK_LAYER(vtl
) );
3041 /*** New waypoint ****/
3043 static gpointer
tool_new_waypoint_create ( VikWindow
*vw
, VikViewport
*vvp
)
3048 static gboolean
tool_new_waypoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
)
3051 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
3053 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &coord
);
3054 if (vik_trw_layer_new_waypoint ( vtl
, VIK_GTK_WINDOW_FROM_LAYER(vtl
), &coord
) && VIK_LAYER(vtl
)->visible
)
3055 vik_layer_emit_update ( VIK_LAYER(vtl
) );
3060 /*** Edit trackpoint ****/
3062 static gpointer
tool_edit_trackpoint_create ( VikWindow
*vw
, VikViewport
*vvp
)
3064 tool_ed_t
*t
= g_new(tool_ed_t
, 1);
3070 static gboolean
tool_edit_trackpoint_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
3072 tool_ed_t
*t
= data
;
3073 VikViewport
*vvp
= t
->vvp
;
3074 TPSearchParams params
;
3075 /* OUTDATED DOCUMENTATION:
3076 find 5 pixel range on each side. then put these UTM, and a pointer
3077 to the winning track name (and maybe the winning track itself), and a
3078 pointer to the winning trackpoint, inside an array or struct. pass
3079 this along, do a foreach on the tracks which will do a foreach on the
3082 params
.x
= event
->x
;
3083 params
.y
= event
->y
;
3084 params
.closest_track_name
= NULL
;
3085 /* TODO: should get track listitem so we can break it up, make a new track, mess it up, all that. */
3086 params
.closest_tp
= NULL
;
3088 if ( event
->button
!= 1 )
3091 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
3094 if ( vtl
->current_tpl
)
3096 /* 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.) */
3097 VikTrackpoint
*tp
= VIK_TRACKPOINT(vtl
->current_tpl
->data
);
3098 VikTrack
*current_tr
= VIK_TRACK(g_hash_table_lookup(vtl
->tracks
, vtl
->current_tp_track_name
));
3100 g_assert ( current_tr
);
3102 vik_viewport_coord_to_screen ( vvp
, &(tp
->coord
), &x
, &y
);
3104 if ( current_tr
->visible
&&
3105 abs(x
- event
->x
) < TRACKPOINT_SIZE_APPROX
&&
3106 abs(y
- event
->y
) < TRACKPOINT_SIZE_APPROX
) {
3107 marker_begin_move ( t
, event
->x
, event
->y
);
3111 vtl
->last_tpl
= vtl
->current_tpl
;
3112 vtl
->last_tp_track_name
= vtl
->current_tp_track_name
;
3115 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) track_search_closest_tp
, ¶ms
);
3117 if ( params
.closest_tp
)
3119 vtl
->current_tpl
= params
.closest_tpl
;
3120 vtl
->current_tp_track_name
= params
.closest_track_name
;
3121 vik_treeview_select_iter ( VIK_LAYER(vtl
)->vt
, g_hash_table_lookup ( vtl
->tracks_iters
, vtl
->current_tp_track_name
) );
3122 trw_layer_tpwin_init ( vtl
);
3123 vik_layer_emit_update ( VIK_LAYER(vtl
) );
3127 /* these aren't the droids you're looking for */
3131 static gboolean
tool_edit_trackpoint_move ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
3133 tool_ed_t
*t
= data
;
3134 VikViewport
*vvp
= t
->vvp
;
3136 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
3142 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &new_coord
);
3145 if ( event
->state
& GDK_CONTROL_MASK
)
3147 VikTrackpoint
*tp
= closest_tp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
3148 if ( tp
&& tp
!= vtl
->current_tpl
->data
)
3149 new_coord
= tp
->coord
;
3151 // VIK_TRACKPOINT(vtl->current_tpl->data)->coord = new_coord;
3154 vik_viewport_coord_to_screen ( vvp
, &new_coord
, &x
, &y
);
3155 marker_moveto ( t
, x
, y
);
3163 static gboolean
tool_edit_trackpoint_release ( VikTrwLayer
*vtl
, GdkEventButton
*event
, gpointer data
)
3165 tool_ed_t
*t
= data
;
3166 VikViewport
*vvp
= t
->vvp
;
3168 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
3170 if ( event
->button
!= 1)
3175 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &new_coord
);
3178 if ( event
->state
& GDK_CONTROL_MASK
)
3180 VikTrackpoint
*tp
= closest_tp_in_five_pixel_interval ( vtl
, vvp
, event
->x
, event
->y
);
3181 if ( tp
&& tp
!= vtl
->current_tpl
->data
)
3182 new_coord
= tp
->coord
;
3185 VIK_TRACKPOINT(vtl
->current_tpl
->data
)->coord
= new_coord
;
3187 marker_end_move ( t
);
3189 /* diff dist is diff from orig */
3190 vik_trw_layer_tpwin_set_tp ( vtl
->tpwin
, vtl
->current_tpl
, vtl
->current_tp_track_name
);
3191 /* can't join with itself! */
3192 trw_layer_cancel_last_tp ( vtl
);
3194 vik_layer_emit_update ( VIK_LAYER(vtl
) );
3201 /*** Magic Scissors ***/
3202 static gpointer
tool_magic_scissors_create ( VikWindow
*vw
, VikViewport
*vvp
)
3207 static gboolean
tool_magic_scissors_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
)
3210 vik_viewport_screen_to_coord ( vvp
, event
->x
, event
->y
, &tmp
);
3211 if ( vtl
->magic_scissors_started
) {
3212 struct LatLon start
, end
;
3214 vik_coord_to_latlon ( &(vtl
->magic_scissors_coord
), &start
);
3215 vik_coord_to_latlon ( &(tmp
), &end
);
3216 cmd
= g_strdup_printf(GOOGLE_DIRECTIONS_STRING
, start
.lat
, start
.lon
, end
.lat
, end
.lon
);
3217 a_babel_convert_from_shellcommand ( vtl
, cmd
, "google", NULL
, NULL
);
3219 vik_layer_emit_update ( VIK_LAYER(vtl
) );
3221 vtl
->magic_scissors_coord
= tmp
;
3223 vtl
->magic_scissors_started
= !vtl
->magic_scissors_started
;
3227 /*** Show picture ****/
3229 static gpointer
tool_show_picture_create ( VikWindow
*vw
, VikViewport
*vvp
)
3234 /* Params are: vvp, event, last match found or NULL */
3235 static void tool_show_picture_wp ( char *name
, VikWaypoint
*wp
, gpointer params
[2] )
3237 if ( wp
->image
&& wp
->visible
)
3239 gint x
, y
, slackx
, slacky
;
3240 GdkEventButton
*event
= (GdkEventButton
*) params
[1];
3242 vik_viewport_coord_to_screen ( VIK_VIEWPORT(params
[0]), &(wp
->coord
), &x
, &y
);
3243 slackx
= wp
->image_width
/ 2;
3244 slacky
= wp
->image_height
/ 2;
3245 if ( x
<= event
->x
+ slackx
&& x
>= event
->x
- slackx
3246 && y
<= event
->y
+ slacky
&& y
>= event
->y
- slacky
)
3248 params
[2] = wp
->image
; /* we've found a match. however continue searching
3249 * since we want to find the last match -- that
3250 * is, the match that was drawn last. */
3255 static gboolean
tool_show_picture_click ( VikTrwLayer
*vtl
, GdkEventButton
*event
, VikViewport
*vvp
)
3257 gpointer params
[3] = { vvp
, event
, NULL
};
3258 if (!vtl
|| vtl
->vl
.type
!= VIK_LAYER_TRW
)
3260 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) tool_show_picture_wp
, params
);
3263 /* thanks to the Gaim people for showing me ShellExecute and g_spawn_command_line_async */
3265 ShellExecute(NULL
, NULL
, (char *) params
[2], NULL
, ".\\", 0);
3268 gchar
*quoted_file
= g_shell_quote ( (gchar
*) params
[2] );
3269 gchar
*cmd
= g_strdup_printf ( "eog %s", quoted_file
);
3270 g_free ( quoted_file
);
3271 if ( ! g_spawn_command_line_async ( cmd
, &err
) )
3273 a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(vtl
), "Could not launch eog to open file." );
3274 g_error_free ( err
);
3277 #endif /* WINDOWS */
3278 return TRUE
; /* found a match */
3281 return FALSE
; /* go through other layers, searching for a match */
3284 /***************************************************************************
3286 ***************************************************************************/
3292 static void image_wp_make_list ( char *name
, VikWaypoint
*wp
, GSList
**pics
)
3294 if ( wp
->image
&& ( ! a_thumbnails_exists ( wp
->image
) ) )
3295 *pics
= g_slist_append ( *pics
, (gpointer
) g_strdup ( wp
->image
) );
3298 static void create_thumbnails_thread ( GSList
*pics
, gpointer threaddata
)
3300 guint total
= g_slist_length(pics
), done
= 0;
3303 a_thumbnails_create ( (gchar
*) pics
->data
);
3304 a_background_thread_progress ( threaddata
, ((gdouble
) ++done
) / total
);
3309 static void free_pics_slist ( GSList
*pics
)
3313 g_free ( pics
->data
);
3314 pics
= g_slist_delete_link ( pics
, pics
);
3318 static void trw_layer_verify_thumbnails ( VikTrwLayer
*vtl
, GtkWidget
*vp
)
3320 if ( ! vtl
->has_verified_thumbnails
)
3322 GSList
*pics
= NULL
;
3323 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) image_wp_make_list
, &pics
);
3326 gint len
= g_slist_length ( pics
);
3327 gchar
*tmp
= g_strdup_printf ( "Creating %d Image Thumbnails...", len
);
3328 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
);
3334 VikCoordMode
vik_trw_layer_get_coord_mode ( VikTrwLayer
*vtl
)
3336 return vtl
->coord_mode
;
3341 static void waypoint_convert ( const gchar
*name
, VikWaypoint
*wp
, VikCoordMode
*dest_mode
)
3343 vik_coord_convert ( &(wp
->coord
), *dest_mode
);
3346 static void track_convert ( const gchar
*name
, VikTrack
*tr
, VikCoordMode
*dest_mode
)
3348 vik_track_convert ( tr
, *dest_mode
);
3351 static void trw_layer_change_coord_mode ( VikTrwLayer
*vtl
, VikCoordMode dest_mode
)
3353 if ( vtl
->coord_mode
!= dest_mode
)
3355 vtl
->coord_mode
= dest_mode
;
3356 g_hash_table_foreach ( vtl
->waypoints
, (GHFunc
) waypoint_convert
, &dest_mode
);
3357 g_hash_table_foreach ( vtl
->tracks
, (GHFunc
) track_convert
, &dest_mode
);
3361 VikWaypoint
*vik_trw_layer_get_waypoint ( VikTrwLayer
*vtl
, gchar
*name
)
3363 return g_hash_table_lookup ( vtl
->waypoints
, name
);
3366 VikTrack
*vik_trw_layer_get_track ( VikTrwLayer
*vtl
, gchar
*name
)
3368 return g_hash_table_lookup ( vtl
->tracks
, name
);
3371 static void vik_trw_layer_set_menu_selection(VikTrwLayer
*vtl
, guint16 selection
)
3373 vtl
->menu_selection
= selection
;
3376 static guint16
vik_trw_layer_get_menu_selection(VikTrwLayer
*vtl
)
3378 return(vtl
->menu_selection
);
3381 /* ----------- Downloading maps along tracks --------------- */
3383 static int get_download_area_width(VikViewport
*vvp
, gdouble zoom_level
, struct LatLon
*wh
)
3385 /* TODO: calculating based on current size of viewport */
3386 const gdouble w_at_zoom_0_125
= 0.0013;
3387 const gdouble h_at_zoom_0_125
= 0.0011;
3388 gdouble zoom_factor
= zoom_level
/0.125;
3390 wh
->lat
= h_at_zoom_0_125
* zoom_factor
;
3391 wh
->lon
= w_at_zoom_0_125
* zoom_factor
;
3393 return 0; /* all OK */
3396 static VikCoord
*get_next_coord(VikCoord
*from
, VikCoord
*to
, struct LatLon
*dist
, gdouble gradient
)
3398 if ((dist
->lon
>= ABS(to
->east_west
- from
->east_west
)) &&
3399 (dist
->lat
>= ABS(to
->north_south
- from
->north_south
)))
3402 VikCoord
*coord
= g_malloc(sizeof(VikCoord
));
3403 coord
->mode
= VIK_COORD_LATLON
;
3405 if (ABS(gradient
) < 1) {
3406 if (from
->east_west
> to
->east_west
)
3407 coord
->east_west
= from
->east_west
- dist
->lon
;
3409 coord
->east_west
= from
->east_west
+ dist
->lon
;
3410 coord
->north_south
= gradient
* (coord
->east_west
- from
->east_west
) + from
->north_south
;
3412 if (from
->north_south
> to
->north_south
)
3413 coord
->north_south
= from
->north_south
- dist
->lat
;
3415 coord
->north_south
= from
->north_south
+ dist
->lat
;
3416 coord
->east_west
= (1/gradient
) * (coord
->north_south
- from
->north_south
) + from
->north_south
;
3422 static GList
*add_fillins(GList
*list
, VikCoord
*from
, VikCoord
*to
, struct LatLon
*dist
)
3424 /* TODO: handle virtical track (to->east_west - from->east_west == 0) */
3425 gdouble gradient
= (to
->north_south
- from
->north_south
)/(to
->east_west
- from
->east_west
);
3427 VikCoord
*next
= from
;
3429 if ((next
= get_next_coord(next
, to
, dist
, gradient
)) == NULL
)
3431 list
= g_list_prepend(list
, next
);
3437 void vik_track_download_map(VikTrack
*tr
, VikMapsLayer
*vml
, VikViewport
*vvp
, gdouble zoom_level
)
3439 typedef struct _Rect
{
3444 #define GLRECT(iter) ((Rect *)((iter)->data))
3447 GList
*rects_to_download
= NULL
;
3450 if (get_download_area_width(vvp
, zoom_level
, &wh
))
3453 GList
*iter
= tr
->trackpoints
;
3457 gboolean new_map
= TRUE
;
3458 VikCoord
*cur_coord
, tl
, br
;
3461 cur_coord
= &(VIK_TRACKPOINT(iter
->data
))->coord
;
3463 vik_coord_set_area(cur_coord
, &wh
, &tl
, &br
);
3464 rect
= g_malloc(sizeof(Rect
));
3467 rect
->center
= *cur_coord
;
3468 rects_to_download
= g_list_prepend(rects_to_download
, rect
);
3473 gboolean found
= FALSE
;
3474 for (rect_iter
= rects_to_download
; rect_iter
; rect_iter
= rect_iter
->next
) {
3475 if (vik_coord_inside(cur_coord
, &GLRECT(rect_iter
)->tl
, &GLRECT(rect_iter
)->br
)) {
3486 /* fill-ins for far apart points */
3487 GList
*cur_rect
, *next_rect
;
3488 GList
*fillins
= NULL
;
3489 for (cur_rect
= rects_to_download
;
3490 (next_rect
= cur_rect
->next
) != NULL
;
3491 cur_rect
= cur_rect
->next
) {
3492 if ((wh
.lon
< ABS(GLRECT(cur_rect
)->center
.east_west
- GLRECT(next_rect
)->center
.east_west
)) ||
3493 (wh
.lat
< ABS(GLRECT(cur_rect
)->center
.north_south
- GLRECT(next_rect
)->center
.north_south
))) {
3494 fillins
= add_fillins(fillins
, &GLRECT(cur_rect
)->center
, &GLRECT(next_rect
)->center
, &wh
);
3499 GList
*iter
= fillins
;
3501 cur_coord
= (VikCoord
*)(iter
->data
);
3502 vik_coord_set_area(cur_coord
, &wh
, &tl
, &br
);
3503 rect
= g_malloc(sizeof(Rect
));
3506 rect
->center
= *cur_coord
;
3507 rects_to_download
= g_list_prepend(rects_to_download
, rect
);
3512 for (rect_iter
= rects_to_download
; rect_iter
; rect_iter
= rect_iter
->next
) {
3513 maps_layer_download_section_without_redraw(vml
, vvp
, &(((Rect
*)(rect_iter
->data
))->tl
), &(((Rect
*)(rect_iter
->data
))->br
), zoom_level
);
3517 for (iter
= fillins
; iter
; iter
= iter
->next
)
3519 g_list_free(fillins
);
3521 if (rects_to_download
) {
3522 for (rect_iter
= rects_to_download
; rect_iter
; rect_iter
= rect_iter
->next
)
3523 g_free(rect_iter
->data
);
3524 g_list_free(rects_to_download
);
3528 static void trw_layer_download_map_along_track_cb(gpointer pass_along
[6])
3531 gint selected_map
, default_map
;
3532 gchar
*zoomlist
[] = {"0.125", "0.25", "0.5", "1", "2", "4", "8", "16", "32", "64", "128", "256", "512", "1024", NULL
};
3533 gdouble zoom_vals
[] = {0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
3534 gint selected_zoom
, default_zoom
;
3538 VikTrwLayer
*vtl
= pass_along
[0];
3539 VikLayersPanel
*vlp
= pass_along
[1];
3540 VikTrack
*tr
= (VikTrack
*) g_hash_table_lookup ( VIK_TRW_LAYER(pass_along
[0])->tracks
, pass_along
[3] );
3541 VikViewport
*vvp
= vik_window_viewport((VikWindow
*)(VIK_GTK_WINDOW_FROM_LAYER(vtl
)));
3543 GList
*vmls
= vik_layers_panel_get_all_layers_of_type(vlp
, VIK_LAYER_MAPS
);
3544 int num_maps
= g_list_length(vmls
);
3547 a_dialog_msg(VIK_GTK_WINDOW_FROM_LAYER(vtl
), GTK_MESSAGE_ERROR
,"No map layer in use. Create one first", NULL
);
3551 gchar
**map_names
= g_malloc(1 + num_maps
* sizeof(gpointer
));
3552 VikMapsLayer
**map_layers
= g_malloc(1 + num_maps
* sizeof(gpointer
));
3554 gchar
**np
= map_names
;
3555 VikMapsLayer
**lp
= map_layers
;
3556 for (i
= 0; i
< num_maps
; i
++) {
3557 gboolean dup
= FALSE
;
3558 vml
= (VikMapsLayer
*)(vmls
->data
);
3559 for (j
= 0; j
< i
; j
++) { /* no duplicate allowed */
3560 if (vik_maps_layer_get_map_type(vml
) == vik_maps_layer_get_map_type(map_layers
[j
])) {
3567 *np
++ = vik_maps_layer_get_map_label(vml
);
3573 num_maps
= lp
- map_layers
;
3575 for (default_map
= 0; default_map
< num_maps
; default_map
++) {
3576 /* TODO: check for parent layer's visibility */
3577 if (VIK_LAYER(map_layers
[default_map
])->visible
)
3580 default_map
= (default_map
== num_maps
) ? 0 : default_map
;
3582 gdouble cur_zoom
= vik_viewport_get_zoom(vvp
);
3583 for (default_zoom
= 0; default_zoom
< sizeof(zoom_vals
)/sizeof(gdouble
); default_zoom
++) {
3584 if (cur_zoom
== zoom_vals
[default_zoom
])
3587 default_zoom
= (default_zoom
== sizeof(zoom_vals
)/sizeof(gdouble
)) ? sizeof(zoom_vals
)/sizeof(gdouble
) - 1 : default_zoom
;
3589 if (!a_dialog_map_n_zoom(VIK_GTK_WINDOW_FROM_LAYER(vtl
), map_names
, default_map
, zoomlist
, default_zoom
, &selected_map
, &selected_zoom
))
3592 vik_track_download_map(tr
, map_layers
[selected_map
], vvp
, zoom_vals
[selected_zoom
]);
3595 for (i
= 0; i
< num_maps
; i
++)
3596 g_free(map_names
[i
]);