]> git.street.me.uk Git - andy/viking.git/blame_incremental - src/viktrwlayer_propwin.c
Add a startup option to load a default map (as defined by layer default for the map...
[andy/viking.git] / src / viktrwlayer_propwin.c
... / ...
CommitLineData
1/*
2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3 *
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
5 * Copyright (C) 2005-2007, Alex Foobarian <foobarian@gmail.com>
6 * Copyright (C) 2007-2008, Quy Tonthat <qtonthat@gmail.com>
7 * Copyright (C) 2012, Rob Norris <rw_norris@hotmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#ifdef HAVE_MATH_H
30#include <math.h>
31#endif
32
33#include <gtk/gtk.h>
34#include <glib/gi18n.h>
35#include <time.h>
36#ifdef HAVE_STRING_H
37#include <string.h>
38#endif
39#include "viktrwlayer.h"
40#include "viktrwlayer_propwin.h"
41#include "dems.h"
42#include "viking.h"
43#include "vikviewport.h" /* ugh */
44#include <gdk-pixbuf/gdk-pixdata.h>
45
46typedef enum {
47 PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE,
48 PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE,
49 PROPWIN_GRAPH_TYPE_SPEED_TIME,
50 PROPWIN_GRAPH_TYPE_DISTANCE_TIME,
51 PROPWIN_GRAPH_TYPE_ELEVATION_TIME,
52 PROPWIN_GRAPH_TYPE_SPEED_DISTANCE,
53 PROPWIN_GRAPH_TYPE_END,
54} VikPropWinGraphType_t;
55
56/* (Hopefully!) Human friendly altitude grid sizes - note no fixed 'ratio' just numbers that look nice...*/
57static const gdouble chunksa[] = {2.0, 5.0, 10.0, 15.0, 20.0,
58 25.0, 40.0, 50.0, 75.0, 100.0,
59 150.0, 200.0, 250.0, 375.0, 500.0,
60 750.0, 1000.0, 2000.0, 5000.0, 10000.0, 100000.0};
61
62/* (Hopefully!) Human friendly gradient grid sizes - note no fixed 'ratio' just numbers that look nice...*/
63static const gdouble chunksg[] = {1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
64 12.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 75.0,
65 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
66 750.0, 1000.0, 10000.0};
67
68/* (Hopefully!) Human friendly grid sizes - note no fixed 'ratio' just numbers that look nice...*/
69/* As need to cover walking speeds - have many low numbers (but also may go up to airplane speeds!) */
70static const gdouble chunkss[] = {1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
71 15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
72 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
73 750.0, 1000.0, 10000.0};
74
75/* (Hopefully!) Human friendly distance grid sizes - note no fixed 'ratio' just numbers that look nice...*/
76static const gdouble chunksd[] = {0.1, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
77 15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
78 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
79 750.0, 1000.0, 10000.0};
80
81typedef struct _propsaved {
82 gboolean saved;
83 GdkImage *img;
84} PropSaved;
85
86typedef struct _propwidgets {
87 gboolean configure_dialog;
88 VikTrwLayer *vtl;
89 VikTrack *tr;
90 gpointer trk_id;
91 VikViewport *vvp;
92 VikLayersPanel *vlp;
93 gint profile_width;
94 gint profile_height;
95 gint profile_width_old;
96 gint profile_height_old;
97 gint profile_width_offset;
98 gint profile_height_offset;
99 GtkWidget *dialog;
100 GtkWidget *w_comment;
101 GtkWidget *w_description;
102 GtkWidget *w_track_length;
103 GtkWidget *w_tp_count;
104 GtkWidget *w_segment_count;
105 GtkWidget *w_duptp_count;
106 GtkWidget *w_max_speed;
107 GtkWidget *w_avg_speed;
108 GtkWidget *w_mvg_speed;
109 GtkWidget *w_avg_dist;
110 GtkWidget *w_elev_range;
111 GtkWidget *w_elev_gain;
112 GtkWidget *w_time_start;
113 GtkWidget *w_time_end;
114 GtkWidget *w_time_dur;
115 GtkWidget *w_color;
116 GtkWidget *w_cur_dist; /*< Current distance */
117 GtkWidget *w_cur_elevation;
118 GtkWidget *w_cur_gradient_dist; /*< Current distance on gradient graph */
119 GtkWidget *w_cur_gradient_gradient; /*< Current gradient on gradient graph */
120 GtkWidget *w_cur_time; /*< Current time */
121 GtkWidget *w_cur_speed;
122 GtkWidget *w_cur_dist_dist; /*< Current distance on distance graph */
123 GtkWidget *w_cur_dist_time; /*< Current time on distance graph */
124 GtkWidget *w_cur_elev_elev;
125 GtkWidget *w_cur_elev_time;
126 GtkWidget *w_cur_speed_dist;
127 GtkWidget *w_cur_speed_speed;
128 GtkWidget *w_show_dem;
129 GtkWidget *w_show_alt_gps_speed;
130 GtkWidget *w_show_gps_speed;
131 GtkWidget *w_show_gradient_gps_speed;
132 GtkWidget *w_show_dist_speed;
133 GtkWidget *w_show_elev_speed;
134 GtkWidget *w_show_sd_gps_speed;
135 gdouble track_length;
136 gdouble track_length_inc_gaps;
137 PropSaved elev_graph_saved_img;
138 PropSaved gradient_graph_saved_img;
139 PropSaved speed_graph_saved_img;
140 PropSaved dist_graph_saved_img;
141 PropSaved elev_time_graph_saved_img;
142 PropSaved speed_dist_graph_saved_img;
143 GtkWidget *elev_box;
144 GtkWidget *gradient_box;
145 GtkWidget *speed_box;
146 GtkWidget *dist_box;
147 GtkWidget *elev_time_box;
148 GtkWidget *speed_dist_box;
149 gdouble *altitudes;
150 gdouble *ats; // altitudes in time
151 gdouble min_altitude;
152 gdouble max_altitude;
153 gdouble draw_min_altitude;
154 gdouble draw_min_altitude_time;
155 gint cia; // Chunk size Index into Altitudes
156 gint ciat; // Chunk size Index into Altitudes / Time
157 // NB cia & ciat are normally same value but sometimes not due to differing methods of altitude array creation
158 // thus also have draw_min_altitude for each altitude graph type
159 gdouble *gradients;
160 gdouble min_gradient;
161 gdouble max_gradient;
162 gdouble draw_min_gradient;
163 gint cig; // Chunk size Index into Gradients
164 gdouble *speeds;
165 gdouble *speeds_dist;
166 gdouble min_speed;
167 gdouble max_speed;
168 gdouble draw_min_speed;
169 gdouble max_speed_dist;
170 gint cis; // Chunk size Index into Speeds
171 gint cisd; // Chunk size Index into Speed/Distance
172 gdouble *distances;
173 gint cid; // Chunk size Index into Distance
174 VikTrackpoint *marker_tp;
175 gboolean is_marker_drawn;
176 VikTrackpoint *blob_tp;
177 gboolean is_blob_drawn;
178} PropWidgets;
179
180static PropWidgets *prop_widgets_new()
181{
182 PropWidgets *widgets = g_malloc0(sizeof(PropWidgets));
183
184 return widgets;
185}
186
187static void prop_widgets_free(PropWidgets *widgets)
188{
189 if (widgets->elev_graph_saved_img.img)
190 g_object_unref(widgets->elev_graph_saved_img.img);
191 if (widgets->gradient_graph_saved_img.img)
192 g_object_unref(widgets->gradient_graph_saved_img.img);
193 if (widgets->speed_graph_saved_img.img)
194 g_object_unref(widgets->speed_graph_saved_img.img);
195 if (widgets->dist_graph_saved_img.img)
196 g_object_unref(widgets->dist_graph_saved_img.img);
197 if (widgets->elev_time_graph_saved_img.img)
198 g_object_unref(widgets->elev_time_graph_saved_img.img);
199 if (widgets->speed_dist_graph_saved_img.img)
200 g_object_unref(widgets->speed_dist_graph_saved_img.img);
201 if (widgets->altitudes)
202 g_free(widgets->altitudes);
203 if (widgets->gradients)
204 g_free(widgets->gradients);
205 if (widgets->speeds)
206 g_free(widgets->speeds);
207 if (widgets->distances)
208 g_free(widgets->distances);
209 if (widgets->ats)
210 g_free(widgets->ats);
211 if (widgets->speeds_dist)
212 g_free(widgets->speeds_dist);
213 g_free(widgets);
214}
215
216static void minmax_array(const gdouble *array, gdouble *min, gdouble *max, gboolean NO_ALT_TEST, gint PROFILE_WIDTH)
217{
218 *max = -1000;
219 *min = 20000;
220 guint i;
221 for ( i=0; i < PROFILE_WIDTH; i++ ) {
222 if ( NO_ALT_TEST || (array[i] != VIK_DEFAULT_ALTITUDE) ) {
223 if ( array[i] > *max )
224 *max = array[i];
225 if ( array[i] < *min )
226 *min = array[i];
227 }
228 }
229}
230
231#define MARGIN 70
232#define LINES 5
233/**
234 * Returns via pointers:
235 * the new minimum value to be used for the altitude graph
236 * the index in to the altitudes chunk sizes array (ci = Chunk Index)
237 */
238static void get_new_min_and_chunk_index_altitude (gdouble mina, gdouble maxa, gdouble *new_min, gint *ci)
239{
240 /* Get unitized chunk */
241 /* Find suitable chunk index */
242 *ci = 0;
243 gdouble diffa_chunk = (maxa - mina)/LINES;
244
245 /* Loop through to find best match */
246 while (diffa_chunk > chunksa[*ci]) {
247 (*ci)++;
248 /* Last Resort Check */
249 if ( *ci == sizeof(chunksa)/sizeof(chunksa[0]) )
250 break;
251 }
252
253 /* Ensure adjusted minimum .. maximum covers mina->maxa */
254
255 // Now work out adjusted minimum point to the nearest lowest chunk divisor value
256 // When negative ensure logic uses lowest value
257 if ( mina < 0 )
258 *new_min = (gdouble) ( ( (gint)(mina - chunksa[*ci]) / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
259 else
260 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
261
262 // Range not big enough - as new minimum has lowered
263 if ((*new_min + (chunksa[*ci] * LINES) < maxa)) {
264 // Next chunk should cover it
265 if ( *ci < sizeof(chunksa)/sizeof(chunksa[0]) ) {
266 (*ci)++;
267 // Remember to adjust the minimum too...
268 if ( mina < 0 )
269 *new_min = (gdouble) ( ( (gint)(mina - chunksa[*ci]) / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
270 else
271 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
272 }
273 }
274}
275
276/**
277 * Returns via pointers:
278 * the new minimum value to be used for the altitude graph
279 * the index in to the altitudes chunk sizes array (ci = Chunk Index)
280 */
281static void get_new_min_and_chunk_index_gradient (gdouble mina, gdouble maxa, gdouble *new_min, gint *ci)
282{
283 /* Get unitized chunk */
284 /* Find suitable chunk index */
285 *ci = 0;
286 gdouble diffa_chunk = (maxa - mina)/LINES;
287
288 /* Loop through to find best match */
289 while (diffa_chunk > chunksg[*ci]) {
290 (*ci)++;
291 /* Last Resort Check */
292 if ( *ci == sizeof(chunksg)/sizeof(chunksg[0]) )
293 break;
294 }
295
296 /* Ensure adjusted minimum .. maximum covers mina->maxa */
297
298 // Now work out adjusted minimum point to the nearest lowest chunk divisor value
299 // When negative ensure logic uses lowest value
300 if ( mina < 0 )
301 *new_min = (gdouble) ( ( (gint)(mina - chunksg[*ci]) / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
302 else
303 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
304
305 // Range not big enough - as new minimum has lowered
306 if ((*new_min + (chunksg[*ci] * LINES) < maxa)) {
307 // Next chunk should cover it
308 if ( *ci < sizeof(chunksg)/sizeof(chunksg[0]) ) {
309 (*ci)++;
310 // Remember to adjust the minimum too...
311 if ( mina < 0 )
312 *new_min = (gdouble) ( ( (gint)(mina - chunksg[*ci]) / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
313 else
314 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
315 }
316 }
317}
318
319/**
320 * Returns via pointers:
321 * the new minimum value to be used for the appropriate graph
322 * the index in to that array (ci = Chunk Index)
323 */
324static void get_new_min_and_chunk_index (gdouble mins, gdouble maxs, const gdouble *chunks, size_t chunky, gdouble *new_min, gint *ci)
325{
326 *ci = 0;
327 gdouble diff_chunk = (maxs - mins)/LINES;
328
329 /* Loop through to find best match */
330 while (diff_chunk > chunks[*ci]) {
331 (*ci)++;
332 /* Last Resort Check */
333 if ( *ci == chunky )
334 break;
335 }
336 *new_min = (gdouble) ( (gint)((mins / chunks[*ci] ) * chunks[*ci]) );
337
338 // Speeds are never negative so don't need to worry about a negative new minimum
339}
340
341static VikTrackpoint *set_center_at_graph_position(gdouble event_x,
342 gint img_width,
343 VikTrwLayer *vtl,
344 VikLayersPanel *vlp,
345 VikViewport *vvp,
346 VikTrack *tr,
347 gboolean time_base,
348 gint PROFILE_WIDTH)
349{
350 VikTrackpoint *trackpoint;
351 gdouble x = event_x - img_width / 2 + PROFILE_WIDTH / 2 - MARGIN / 2;
352 if (x < 0)
353 x = 0;
354 if (x > PROFILE_WIDTH)
355 x = PROFILE_WIDTH;
356
357 if (time_base)
358 trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / PROFILE_WIDTH, NULL );
359 else
360 trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / PROFILE_WIDTH, NULL );
361
362 if ( trackpoint ) {
363 VikCoord coord = trackpoint->coord;
364 if ( vlp ) {
365 vik_viewport_set_center_coord ( vik_layers_panel_get_viewport(vlp), &coord );
366 vik_layers_panel_emit_update ( vlp );
367 }
368 else {
369 /* since vlp not set, vvp should be valid instead! */
370 if ( vvp )
371 vik_viewport_set_center_coord ( vvp, &coord );
372 vik_layer_emit_update ( VIK_LAYER(vtl) );
373 }
374 }
375 return trackpoint;
376}
377
378/**
379 * Returns whether the marker was drawn or not and whether the blob was drawn or not
380 */
381static void save_image_and_draw_graph_marks (GtkWidget *image,
382 gdouble marker_x,
383 GdkGC *gc,
384 gint blob_x,
385 gint blob_y,
386 PropSaved *saved_img,
387 gint PROFILE_WIDTH,
388 gint PROFILE_HEIGHT,
389 gboolean *marker_drawn,
390 gboolean *blob_drawn)
391{
392 GdkPixmap *pix = NULL;
393 /* the pixmap = margin + graph area */
394 gtk_image_get_pixmap(GTK_IMAGE(image), &pix, NULL);
395
396 /* Restore previously saved image */
397 if (saved_img->saved) {
398 gdk_draw_image(GDK_DRAWABLE(pix), gc, saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
399 saved_img->saved = FALSE;
400 }
401
402 // ATM always save whole image - as anywhere could have changed
403 if (saved_img->img)
404 gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
405 else
406 saved_img->img = gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
407 saved_img->saved = TRUE;
408
409 if ((marker_x >= MARGIN) && (marker_x < (PROFILE_WIDTH + MARGIN))) {
410 gdk_draw_line (GDK_DRAWABLE(pix), gc, marker_x, 0, marker_x, image->allocation.height);
411 *marker_drawn = TRUE;
412 }
413 else
414 *marker_drawn = FALSE;
415
416 // Draw a square blob to indicate where we are on track for this graph
417 if ( (blob_x >= MARGIN) && (blob_x < (PROFILE_WIDTH + MARGIN)) && (blob_y < PROFILE_HEIGHT) ) {
418 gdk_draw_rectangle (GDK_DRAWABLE(pix), gc, TRUE, blob_x-3, blob_y-3, 6, 6);
419 *blob_drawn = TRUE;
420 }
421 else
422 *blob_drawn = FALSE;
423
424 // Anywhere on image could have changed
425 if (*marker_drawn || *blob_drawn)
426 gtk_widget_queue_draw(image);
427}
428
429/**
430 * Return the percentage of how far a trackpoint is a long a track via the time method
431 */
432static gdouble tp_percentage_by_time ( VikTrack *tr, VikTrackpoint *trackpoint )
433{
434 gdouble pc = NAN;
435 if (trackpoint == NULL)
436 return pc;
437 time_t t_start, t_end, t_total;
438 t_start = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
439 t_end = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp;
440 t_total = t_end - t_start;
441 pc = (gdouble)(trackpoint->timestamp - t_start)/t_total;
442 return pc;
443}
444
445/**
446 * Return the percentage of how far a trackpoint is a long a track via the distance method
447 */
448static gdouble tp_percentage_by_distance ( VikTrack *tr, VikTrackpoint *trackpoint, gdouble track_length )
449{
450 gdouble pc = NAN;
451 if (trackpoint == NULL)
452 return pc;
453 gdouble dist = 0.0;
454 GList *iter;
455 for (iter = tr->trackpoints->next; iter != NULL; iter = iter->next) {
456 dist += vik_coord_diff(&(VIK_TRACKPOINT(iter->data)->coord),
457 &(VIK_TRACKPOINT(iter->prev->data)->coord));
458 /* Assuming trackpoint is not a copy */
459 if (trackpoint == VIK_TRACKPOINT(iter->data))
460 break;
461 }
462 if (iter != NULL)
463 pc = dist/track_length;
464 return pc;
465}
466
467static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, PropWidgets *widgets, VikPropWinGraphType_t graph_type )
468{
469 gboolean is_time_graph =
470 ( graph_type == PROPWIN_GRAPH_TYPE_SPEED_TIME ||
471 graph_type == PROPWIN_GRAPH_TYPE_DISTANCE_TIME ||
472 graph_type == PROPWIN_GRAPH_TYPE_ELEVATION_TIME );
473
474 VikTrackpoint *trackpoint = set_center_at_graph_position(event->x, event_box->allocation.width, widgets->vtl, widgets->vlp, widgets->vvp, widgets->tr, is_time_graph, widgets->profile_width);
475 // Unable to get the point so give up
476 if ( trackpoint == NULL ) {
477 gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
478 return;
479 }
480
481 widgets->marker_tp = trackpoint;
482
483 GList *child;
484 GtkWidget *image;
485 GtkWidget *window = gtk_widget_get_toplevel(GTK_WIDGET(event_box));
486 GtkWidget *graph_box;
487 PropSaved *graph_saved_img;
488 gdouble pc = NAN;
489
490 // Attempt to redraw marker on all graph types
491 gint graphite;
492 for ( graphite = PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE;
493 graphite < PROPWIN_GRAPH_TYPE_END;
494 graphite++ ) {
495
496 // Switch commonal variables to particular graph type
497 switch (graphite) {
498 default:
499 case PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE:
500 graph_box = widgets->elev_box;
501 graph_saved_img = &widgets->elev_graph_saved_img;
502 is_time_graph = FALSE;
503 break;
504 case PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE:
505 graph_box = widgets->gradient_box;
506 graph_saved_img = &widgets->gradient_graph_saved_img;
507 is_time_graph = FALSE;
508 break;
509 case PROPWIN_GRAPH_TYPE_SPEED_TIME:
510 graph_box = widgets->speed_box;
511 graph_saved_img = &widgets->speed_graph_saved_img;
512 is_time_graph = TRUE;
513 break;
514 case PROPWIN_GRAPH_TYPE_DISTANCE_TIME:
515 graph_box = widgets->dist_box;
516 graph_saved_img = &widgets->dist_graph_saved_img;
517 is_time_graph = TRUE;
518 break;
519 case PROPWIN_GRAPH_TYPE_ELEVATION_TIME:
520 graph_box = widgets->elev_time_box;
521 graph_saved_img = &widgets->elev_time_graph_saved_img;
522 is_time_graph = TRUE;
523 break;
524 case PROPWIN_GRAPH_TYPE_SPEED_DISTANCE:
525 graph_box = widgets->speed_dist_box;
526 graph_saved_img = &widgets->speed_dist_graph_saved_img;
527 is_time_graph = FALSE;
528 break;
529 }
530
531 // Commonal method of redrawing marker
532 if ( graph_box ) {
533
534 child = gtk_container_get_children(GTK_CONTAINER(graph_box));
535 image = GTK_WIDGET(child->data);
536
537 if (is_time_graph)
538 pc = tp_percentage_by_time ( widgets->tr, trackpoint );
539 else
540 pc = tp_percentage_by_distance ( widgets->tr, trackpoint, widgets->track_length_inc_gaps );
541
542 if (!isnan(pc)) {
543 gdouble marker_x = (pc * widgets->profile_width) + MARGIN;
544 save_image_and_draw_graph_marks(image,
545 marker_x,
546 gtk_widget_get_style(window)->black_gc,
547 -1, // Don't draw blob on clicks
548 0,
549 graph_saved_img,
550 widgets->profile_width,
551 widgets->profile_height,
552 &widgets->is_marker_drawn,
553 &widgets->is_blob_drawn);
554 }
555 g_list_free(child);
556 }
557 }
558
559 gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, widgets->is_marker_drawn);
560}
561
562static gboolean track_profile_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
563{
564 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE);
565 return TRUE; /* don't call other (further) callbacks */
566}
567
568static gboolean track_gradient_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
569{
570 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE);
571 return TRUE; /* don't call other (further) callbacks */
572}
573
574static gboolean track_vt_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
575{
576 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_SPEED_TIME);
577 return TRUE; /* don't call other (further) callbacks */
578}
579
580static gboolean track_dt_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
581{
582 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_DISTANCE_TIME);
583 return TRUE; /* don't call other (further) callbacks */
584}
585
586static gboolean track_et_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
587{
588 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_ELEVATION_TIME);
589 return TRUE; /* don't call other (further) callbacks */
590}
591
592static gboolean track_sd_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
593{
594 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_SPEED_DISTANCE);
595 return TRUE; /* don't call other (further) callbacks */
596}
597
598/**
599 * Calculate y position for blob on elevation graph
600 */
601static gint blobby_altitude ( gdouble x_blob, PropWidgets *widgets )
602{
603 gint ix = (gint)x_blob;
604 // Ensure ix is inbounds
605 if (ix == widgets->profile_width)
606 ix--;
607
608 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->altitudes[ix]-widgets->draw_min_altitude)/(chunksa[widgets->cia]*LINES);
609
610 return y_blob;
611}
612
613/**
614 * Calculate y position for blob on gradient graph
615 */
616static gint blobby_gradient ( gdouble x_blob, PropWidgets *widgets )
617{
618 gint ix = (gint)x_blob;
619 // Ensure ix is inbounds
620 if (ix == widgets->profile_width)
621 ix--;
622
623 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->gradients[ix]-widgets->draw_min_gradient)/(chunksg[widgets->cig]*LINES);
624
625 return y_blob;
626}
627
628/**
629 * Calculate y position for blob on speed graph
630 */
631static gint blobby_speed ( gdouble x_blob, PropWidgets *widgets )
632{
633 gint ix = (gint)x_blob;
634 // Ensure ix is inbounds
635 if (ix == widgets->profile_width)
636 ix--;
637
638 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->speeds[ix]-widgets->draw_min_speed)/(chunkss[widgets->cis]*LINES);
639
640 return y_blob;
641}
642
643/**
644 * Calculate y position for blob on distance graph
645 */
646static gint blobby_distance ( gdouble x_blob, PropWidgets *widgets )
647{
648 gint ix = (gint)x_blob;
649 // Ensure ix is inbounds
650 if (ix == widgets->profile_width)
651 ix--;
652
653 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->distances[ix])/(chunksd[widgets->cid]*LINES);
654 //NB min distance is always 0, so no need to subtract that from this ______/
655
656 return y_blob;
657}
658
659/**
660 * Calculate y position for blob on elevation/time graph
661 */
662static gint blobby_altitude_time ( gdouble x_blob, PropWidgets *widgets )
663{
664 gint ix = (gint)x_blob;
665 // Ensure ix is inbounds
666 if (ix == widgets->profile_width)
667 ix--;
668
669 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->ats[ix]-widgets->draw_min_altitude_time)/(chunksa[widgets->ciat]*LINES);
670 return y_blob;
671}
672
673/**
674 * Calculate y position for blob on speed/dist graph
675 */
676static gint blobby_speed_dist ( gdouble x_blob, PropWidgets *widgets )
677{
678 gint ix = (gint)x_blob;
679 // Ensure ix is inbounds
680 if (ix == widgets->profile_width)
681 ix--;
682
683 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->speeds_dist[ix]-widgets->draw_min_speed)/(chunkss[widgets->cisd]*LINES);
684
685 return y_blob;
686}
687
688
689void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
690{
691 int mouse_x, mouse_y;
692 GdkModifierType state;
693
694 if (event->is_hint)
695 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
696 else
697 mouse_x = event->x;
698
699 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
700 if (x < 0)
701 x = 0;
702 if (x > widgets->profile_width)
703 x = widgets->profile_width;
704
705 gdouble meters_from_start;
706 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
707 if (trackpoint && widgets->w_cur_dist) {
708 static gchar tmp_buf[20];
709 vik_units_distance_t dist_units = a_vik_get_units_distance ();
710 switch (dist_units) {
711 case VIK_UNITS_DISTANCE_KILOMETRES:
712 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
713 break;
714 case VIK_UNITS_DISTANCE_MILES:
715 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
716 break;
717 default:
718 g_critical("Houston, we've had a problem. distance=%d", dist_units);
719 }
720 gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist), tmp_buf);
721 }
722
723 // Show track elevation for this position - to the nearest whole number
724 if (trackpoint && widgets->w_cur_elevation) {
725 static gchar tmp_buf[20];
726 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
727 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d ft", (int)VIK_METERS_TO_FEET(trackpoint->altitude));
728 else
729 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d m", (int)trackpoint->altitude);
730 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elevation), tmp_buf);
731 }
732
733 widgets->blob_tp = trackpoint;
734
735 if ( widgets->altitudes == NULL )
736 return;
737
738 GtkWidget *window = gtk_widget_get_toplevel (event_box);
739 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
740 GtkWidget *image = GTK_WIDGET(child->data);
741
742 gint y_blob = blobby_altitude (x, widgets);
743
744 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
745 if (widgets->is_marker_drawn) {
746 gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
747 if (!isnan(pc)) {
748 marker_x = (pc * widgets->profile_width) + MARGIN;
749 }
750 }
751
752 save_image_and_draw_graph_marks (image,
753 marker_x,
754 gtk_widget_get_style(window)->black_gc,
755 MARGIN+x,
756 y_blob,
757 &widgets->elev_graph_saved_img,
758 widgets->profile_width,
759 widgets->profile_height,
760 &widgets->is_marker_drawn,
761 &widgets->is_blob_drawn);
762
763 g_list_free(child);
764}
765
766void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
767{
768 int mouse_x, mouse_y;
769 GdkModifierType state;
770
771 if (event->is_hint)
772 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
773 else
774 mouse_x = event->x;
775
776 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
777 if (x < 0)
778 x = 0;
779 if (x > widgets->profile_width)
780 x = widgets->profile_width;
781
782 gdouble meters_from_start;
783 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
784 if (trackpoint && widgets->w_cur_gradient_dist) {
785 static gchar tmp_buf[20];
786 vik_units_distance_t dist_units = a_vik_get_units_distance ();
787 switch (dist_units) {
788 case VIK_UNITS_DISTANCE_KILOMETRES:
789 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
790 break;
791 case VIK_UNITS_DISTANCE_MILES:
792 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
793 break;
794 default:
795 g_critical("Houston, we've had a problem. distance=%d", dist_units);
796 }
797 gtk_label_set_text(GTK_LABEL(widgets->w_cur_gradient_dist), tmp_buf);
798 }
799
800 // Show track gradient for this position - to the nearest whole number
801 if (trackpoint && widgets->w_cur_gradient_gradient) {
802 static gchar tmp_buf[20];
803
804 double gradient = widgets->gradients[(int) x];
805
806 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d%%", (int)gradient);
807 gtk_label_set_text(GTK_LABEL(widgets->w_cur_gradient_gradient), tmp_buf);
808 }
809
810 widgets->blob_tp = trackpoint;
811
812 if ( widgets->gradients == NULL )
813 return;
814
815 GtkWidget *window = gtk_widget_get_toplevel (event_box);
816 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
817 GtkWidget *image = GTK_WIDGET(child->data);
818
819 gint y_blob = blobby_gradient (x, widgets);
820
821 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
822 if (widgets->is_marker_drawn) {
823 gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
824 if (!isnan(pc)) {
825 marker_x = (pc * widgets->profile_width) + MARGIN;
826 }
827 }
828
829 save_image_and_draw_graph_marks (image,
830 marker_x,
831 gtk_widget_get_style(window)->black_gc,
832 MARGIN+x,
833 y_blob,
834 &widgets->gradient_graph_saved_img,
835 widgets->profile_width,
836 widgets->profile_height,
837 &widgets->is_marker_drawn,
838 &widgets->is_blob_drawn);
839
840 g_list_free(child);
841}
842
843void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
844{
845 int mouse_x, mouse_y;
846 GdkModifierType state;
847
848 if (event->is_hint)
849 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
850 else
851 mouse_x = event->x;
852
853 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
854 if (x < 0)
855 x = 0;
856 if (x > widgets->profile_width)
857 x = widgets->profile_width;
858
859 time_t seconds_from_start;
860 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
861 if (trackpoint && widgets->w_cur_time) {
862 static gchar tmp_buf[20];
863 guint h, m, s;
864 h = seconds_from_start/3600;
865 m = (seconds_from_start - h*3600)/60;
866 s = seconds_from_start - (3600*h) - (60*m);
867 g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
868
869 gtk_label_set_text(GTK_LABEL(widgets->w_cur_time), tmp_buf);
870 }
871
872 gint ix = (gint)x;
873 // Ensure ix is inbounds
874 if (ix == widgets->profile_width)
875 ix--;
876
877 // Show track speed for this position
878 if (trackpoint && widgets->w_cur_speed) {
879 static gchar tmp_buf[20];
880 // Even if GPS speed available (trackpoint->speed), the text will correspond to the speed map shown
881 // No conversions needed as already in appropriate units
882 vik_units_speed_t speed_units = a_vik_get_units_speed ();
883 switch (speed_units) {
884 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
885 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f kph"), widgets->speeds[ix]);
886 break;
887 case VIK_UNITS_SPEED_MILES_PER_HOUR:
888 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f mph"), widgets->speeds[ix]);
889 break;
890 case VIK_UNITS_SPEED_KNOTS:
891 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f knots"), widgets->speeds[ix]);
892 break;
893 default:
894 // VIK_UNITS_SPEED_METRES_PER_SECOND:
895 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f m/s"), widgets->speeds[ix]);
896 break;
897 }
898 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed), tmp_buf);
899 }
900
901 widgets->blob_tp = trackpoint;
902
903 if ( widgets->speeds == NULL )
904 return;
905
906 GtkWidget *window = gtk_widget_get_toplevel (event_box);
907 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
908 GtkWidget *image = GTK_WIDGET(child->data);
909
910 gint y_blob = blobby_speed (x, widgets);
911
912 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
913 if (widgets->is_marker_drawn) {
914 gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
915 if (!isnan(pc)) {
916 marker_x = (pc * widgets->profile_width) + MARGIN;
917 }
918 }
919
920 save_image_and_draw_graph_marks (image,
921 marker_x,
922 gtk_widget_get_style(window)->black_gc,
923 MARGIN+x,
924 y_blob,
925 &widgets->speed_graph_saved_img,
926 widgets->profile_width,
927 widgets->profile_height,
928 &widgets->is_marker_drawn,
929 &widgets->is_blob_drawn);
930
931 g_list_free(child);
932}
933
934/**
935 * Update labels and blob marker on mouse moves in the distance/time graph
936 */
937void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
938{
939 int mouse_x, mouse_y;
940 GdkModifierType state;
941
942 if (event->is_hint)
943 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
944 else
945 mouse_x = event->x;
946
947 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
948 if (x < 0)
949 x = 0;
950 if (x > widgets->profile_width)
951 x = widgets->profile_width;
952
953 time_t seconds_from_start;
954 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
955 if (trackpoint && widgets->w_cur_dist_time) {
956 static gchar tmp_buf[20];
957 guint h, m, s;
958 h = seconds_from_start/3600;
959 m = (seconds_from_start - h*3600)/60;
960 s = seconds_from_start - (3600*h) - (60*m);
961 g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
962
963 gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_time), tmp_buf);
964 }
965
966 gint ix = (gint)x;
967 // Ensure ix is inbounds
968 if (ix == widgets->profile_width)
969 ix--;
970
971 if (trackpoint && widgets->w_cur_dist_dist) {
972 static gchar tmp_buf[20];
973 if ( a_vik_get_units_distance () == VIK_UNITS_DISTANCE_MILES )
974 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", widgets->distances[ix]);
975 else
976 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", widgets->distances[ix]);
977 gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_dist), tmp_buf);
978 }
979
980 widgets->blob_tp = trackpoint;
981
982 if ( widgets->distances == NULL )
983 return;
984
985 GtkWidget *window = gtk_widget_get_toplevel (event_box);
986 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
987 GtkWidget *image = GTK_WIDGET(child->data);
988
989 gint y_blob = blobby_distance (x, widgets);
990
991 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
992 if (widgets->is_marker_drawn) {
993 gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
994 if (!isnan(pc)) {
995 marker_x = (pc * widgets->profile_width) + MARGIN;
996 }
997 }
998
999 save_image_and_draw_graph_marks (image,
1000 marker_x,
1001 gtk_widget_get_style(window)->black_gc,
1002 MARGIN+x,
1003 y_blob,
1004 &widgets->dist_graph_saved_img,
1005 widgets->profile_width,
1006 widgets->profile_height,
1007 &widgets->is_marker_drawn,
1008 &widgets->is_blob_drawn);
1009
1010 g_list_free(child);
1011}
1012
1013/**
1014 * Update labels and blob marker on mouse moves in the elevation/time graph
1015 */
1016void track_et_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
1017{
1018 int mouse_x, mouse_y;
1019 GdkModifierType state;
1020
1021 if (event->is_hint)
1022 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
1023 else
1024 mouse_x = event->x;
1025
1026 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
1027 if (x < 0)
1028 x = 0;
1029 if (x > widgets->profile_width)
1030 x = widgets->profile_width;
1031
1032 time_t seconds_from_start;
1033 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
1034 if (trackpoint && widgets->w_cur_elev_time) {
1035 static gchar tmp_buf[20];
1036 guint h, m, s;
1037 h = seconds_from_start/3600;
1038 m = (seconds_from_start - h*3600)/60;
1039 s = seconds_from_start - (3600*h) - (60*m);
1040 g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
1041
1042 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elev_time), tmp_buf);
1043 }
1044
1045 gint ix = (gint)x;
1046 // Ensure ix is inbounds
1047 if (ix == widgets->profile_width)
1048 ix--;
1049
1050 if (trackpoint && widgets->w_cur_elev_elev) {
1051 static gchar tmp_buf[20];
1052 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
1053 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d ft", (int)VIK_METERS_TO_FEET(trackpoint->altitude));
1054 else
1055 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d m", (int)trackpoint->altitude);
1056 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elev_elev), tmp_buf);
1057 }
1058
1059 widgets->blob_tp = trackpoint;
1060
1061 if ( widgets->ats == NULL )
1062 return;
1063
1064 GtkWidget *window = gtk_widget_get_toplevel (event_box);
1065 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
1066 GtkWidget *image = GTK_WIDGET(child->data);
1067
1068 gint y_blob = blobby_altitude_time (x, widgets);
1069
1070 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
1071 if (widgets->is_marker_drawn) {
1072 gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
1073 if (!isnan(pc)) {
1074 marker_x = (pc * widgets->profile_width) + MARGIN;
1075 }
1076 }
1077
1078 save_image_and_draw_graph_marks (image,
1079 marker_x,
1080 gtk_widget_get_style(window)->black_gc,
1081 MARGIN+x,
1082 y_blob,
1083 &widgets->elev_time_graph_saved_img,
1084 widgets->profile_width,
1085 widgets->profile_height,
1086 &widgets->is_marker_drawn,
1087 &widgets->is_blob_drawn);
1088
1089 g_list_free(child);
1090}
1091
1092void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
1093{
1094 int mouse_x, mouse_y;
1095 GdkModifierType state;
1096
1097 if (event->is_hint)
1098 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
1099 else
1100 mouse_x = event->x;
1101
1102 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
1103 if (x < 0)
1104 x = 0;
1105 if (x > widgets->profile_width)
1106 x = widgets->profile_width;
1107
1108 gdouble meters_from_start;
1109 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
1110 if (trackpoint && widgets->w_cur_speed_dist) {
1111 static gchar tmp_buf[20];
1112 vik_units_distance_t dist_units = a_vik_get_units_distance ();
1113 switch (dist_units) {
1114 case VIK_UNITS_DISTANCE_KILOMETRES:
1115 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
1116 break;
1117 case VIK_UNITS_DISTANCE_MILES:
1118 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
1119 break;
1120 default:
1121 g_critical("Houston, we've had a problem. distance=%d", dist_units);
1122 }
1123 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed_dist), tmp_buf);
1124 }
1125
1126 gint ix = (gint)x;
1127 // Ensure ix is inbounds
1128 if (ix == widgets->profile_width)
1129 ix--;
1130
1131 if ( widgets->speeds_dist == NULL )
1132 return;
1133
1134 // Show track speed for this position
1135 if (widgets->w_cur_speed_speed) {
1136 static gchar tmp_buf[20];
1137 // Even if GPS speed available (trackpoint->speed), the text will correspond to the speed map shown
1138 // No conversions needed as already in appropriate units
1139 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1140 switch (speed_units) {
1141 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1142 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f kph"), widgets->speeds_dist[ix]);
1143 break;
1144 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1145 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f mph"), widgets->speeds_dist[ix]);
1146 break;
1147 case VIK_UNITS_SPEED_KNOTS:
1148 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f knots"), widgets->speeds_dist[ix]);
1149 break;
1150 default:
1151 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1152 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f m/s"), widgets->speeds_dist[ix]);
1153 break;
1154 }
1155 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed_speed), tmp_buf);
1156 }
1157
1158 widgets->blob_tp = trackpoint;
1159
1160 GtkWidget *window = gtk_widget_get_toplevel (event_box);
1161 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
1162 GtkWidget *image = GTK_WIDGET(child->data);
1163
1164 gint y_blob = blobby_speed_dist (x, widgets);
1165
1166 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
1167 if (widgets->is_marker_drawn) {
1168 gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
1169 if (!isnan(pc)) {
1170 marker_x = (pc * widgets->profile_width) + MARGIN;
1171 }
1172 }
1173
1174 save_image_and_draw_graph_marks (image,
1175 marker_x,
1176 gtk_widget_get_style(window)->black_gc,
1177 MARGIN+x,
1178 y_blob,
1179 &widgets->speed_dist_graph_saved_img,
1180 widgets->profile_width,
1181 widgets->profile_height,
1182 &widgets->is_marker_drawn,
1183 &widgets->is_blob_drawn);
1184
1185 g_list_free(child);
1186}
1187
1188/**
1189 * Draws DEM points and a respresentative speed on the supplied pixmap
1190 * (which is the elevations graph)
1191 */
1192static void draw_dem_alt_speed_dist(VikTrack *tr,
1193 GdkDrawable *pix,
1194 GdkGC *alt_gc,
1195 GdkGC *speed_gc,
1196 gdouble alt_offset,
1197 gdouble alt_diff,
1198 gdouble max_speed_in,
1199 gint cia,
1200 gint width,
1201 gint height,
1202 gint margin,
1203 gboolean do_dem,
1204 gboolean do_speed)
1205{
1206 GList *iter;
1207 gdouble max_speed = 0;
1208 gdouble total_length = vik_track_get_length_including_gaps(tr);
1209
1210 // Calculate the max speed factor
1211 if (do_speed)
1212 max_speed = max_speed_in * 110 / 100;
1213
1214 gdouble dist = 0;
1215 for (iter = tr->trackpoints->next; iter; iter = iter->next) {
1216 int x;
1217 dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
1218 &(VIK_TRACKPOINT(iter->prev->data)->coord) );
1219 x = (width * dist)/total_length + margin;
1220 if (do_dem) {
1221 gint16 elev = a_dems_get_elev_by_coord(&(VIK_TRACKPOINT(iter->data)->coord), VIK_DEM_INTERPOL_BEST);
1222 elev -= alt_offset;
1223 if ( elev != VIK_DEM_INVALID_ELEVATION ) {
1224 // Convert into height units
1225 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
1226 elev = VIK_METERS_TO_FEET(elev);
1227 // No conversion needed if already in metres
1228
1229 // consider chunk size
1230 int y_alt = height - ((height * elev)/(chunksa[cia]*LINES) );
1231 gdk_draw_rectangle(GDK_DRAWABLE(pix), alt_gc, TRUE, x-2, y_alt-2, 4, 4);
1232 }
1233 }
1234 if (do_speed) {
1235 // This is just a speed indicator - no actual values can be inferred by user
1236 if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
1237 int y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
1238 gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
1239 }
1240 }
1241 }
1242}
1243
1244/**
1245 * Draw just the height profile image
1246 */
1247static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1248{
1249 GtkWidget *window;
1250 GdkPixmap *pix;
1251 gdouble mina, maxa;
1252 guint i;
1253
1254 GdkGC *no_alt_info;
1255 GdkColor color;
1256
1257 // Free previous allocation
1258 if ( widgets->altitudes )
1259 g_free ( widgets->altitudes );
1260
1261 widgets->altitudes = vik_track_make_elevation_map ( tr, widgets->profile_width );
1262
1263 if ( widgets->altitudes == NULL )
1264 return;
1265
1266 // Convert into appropriate units
1267 vik_units_height_t height_units = a_vik_get_units_height ();
1268 if ( height_units == VIK_UNITS_HEIGHT_FEET ) {
1269 // Convert altitudes into feet units
1270 for ( i = 0; i < widgets->profile_width; i++ ) {
1271 widgets->altitudes[i] = VIK_METERS_TO_FEET(widgets->altitudes[i]);
1272 }
1273 }
1274 // Otherwise leave in metres
1275
1276 minmax_array(widgets->altitudes, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
1277
1278 get_new_min_and_chunk_index_altitude (widgets->min_altitude, widgets->max_altitude, &widgets->draw_min_altitude, &widgets->cia);
1279
1280 // Assign locally
1281 mina = widgets->draw_min_altitude;
1282 maxa = widgets->max_altitude;
1283
1284 window = gtk_widget_get_toplevel (widgets->elev_box);
1285
1286 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1287
1288 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1289
1290 no_alt_info = gdk_gc_new ( gtk_widget_get_window(window) );
1291 gdk_color_parse ( "yellow", &color );
1292 gdk_gc_set_rgb_fg_color ( no_alt_info, &color);
1293
1294 /* clear the image */
1295 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1296 TRUE, 0, 0, MARGIN, widgets->profile_height);
1297 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1298 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1299
1300 /* draw grid */
1301 for (i=0; i<=LINES; i++) {
1302 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1303 gchar s[32];
1304 int w, h;
1305
1306 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1307 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1308
1309 switch (height_units) {
1310 case VIK_UNITS_HEIGHT_METRES:
1311 sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
1312 break;
1313 case VIK_UNITS_HEIGHT_FEET:
1314 // NB values already converted into feet
1315 sprintf(s, "%8dft", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
1316 break;
1317 default:
1318 sprintf(s, "--");
1319 g_critical("Houston, we've had a problem. height=%d", height_units);
1320 }
1321 pango_layout_set_text(pl, s, -1);
1322 pango_layout_get_pixel_size (pl, &w, &h);
1323 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1324 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1325
1326 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1327 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1328 g_object_unref ( G_OBJECT ( pl ) );
1329 pl = NULL;
1330 }
1331
1332 /* draw elevations */
1333 for ( i = 0; i < widgets->profile_width; i++ )
1334 if ( widgets->altitudes[i] == VIK_DEFAULT_ALTITUDE )
1335 gdk_draw_line ( GDK_DRAWABLE(pix), no_alt_info,
1336 i + MARGIN, 0, i + MARGIN, widgets->profile_height );
1337 else
1338 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1339 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->altitudes[i]-mina)/(chunksa[widgets->cia]*LINES) );
1340
1341 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)) ||
1342 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)) ) {
1343
1344 GdkGC *dem_alt_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1345 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1346
1347 gdk_color_parse ( "green", &color );
1348 gdk_gc_set_rgb_fg_color ( dem_alt_gc, &color);
1349
1350 gdk_color_parse ( "red", &color );
1351 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1352
1353 // Ensure somekind of max speed when not set
1354 if ( widgets->max_speed < 0.01 )
1355 widgets->max_speed = vik_track_get_max_speed(tr);
1356
1357 draw_dem_alt_speed_dist(tr,
1358 GDK_DRAWABLE(pix),
1359 dem_alt_gc,
1360 gps_speed_gc,
1361 mina,
1362 maxa - mina,
1363 widgets->max_speed,
1364 widgets->cia,
1365 widgets->profile_width,
1366 widgets->profile_height,
1367 MARGIN,
1368 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)),
1369 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
1370
1371 g_object_unref ( G_OBJECT(dem_alt_gc) );
1372 g_object_unref ( G_OBJECT(gps_speed_gc) );
1373 }
1374
1375 /* draw border */
1376 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1377
1378 g_object_unref ( G_OBJECT(pix) );
1379 g_object_unref ( G_OBJECT(no_alt_info) );
1380}
1381
1382/**
1383 * Draws representative speed on the supplied pixmap
1384 * (which is the gradients graph)
1385 */
1386static void draw_speed_dist(VikTrack *tr,
1387 GdkDrawable *pix,
1388 GdkGC *speed_gc,
1389 gdouble max_speed_in,
1390 gint width,
1391 gint height,
1392 gint margin,
1393 gboolean do_speed)
1394{
1395 GList *iter;
1396 gdouble max_speed = 0;
1397 gdouble total_length = vik_track_get_length_including_gaps(tr);
1398
1399 // Calculate the max speed factor
1400 if (do_speed)
1401 max_speed = max_speed_in * 110 / 100;
1402
1403 gdouble dist = 0;
1404 for (iter = tr->trackpoints->next; iter; iter = iter->next) {
1405 int x;
1406 dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
1407 &(VIK_TRACKPOINT(iter->prev->data)->coord) );
1408 x = (width * dist)/total_length + margin;
1409 if (do_speed) {
1410 // This is just a speed indicator - no actual values can be inferred by user
1411 if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
1412 int y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
1413 gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
1414 }
1415 }
1416 }
1417}
1418
1419/**
1420 * Draw just the gradient image
1421 */
1422static void draw_gradients (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1423{
1424 GtkWidget *window;
1425 GdkPixmap *pix;
1426 gdouble mina;
1427 guint i;
1428
1429 GdkColor color;
1430
1431 // Free previous allocation
1432 if ( widgets->gradients )
1433 g_free ( widgets->gradients );
1434
1435 widgets->gradients = vik_track_make_gradient_map ( tr, widgets->profile_width );
1436
1437 if ( widgets->gradients == NULL )
1438 return;
1439
1440 minmax_array(widgets->gradients, &widgets->min_gradient, &widgets->max_gradient, TRUE, widgets->profile_width);
1441
1442 get_new_min_and_chunk_index_gradient (widgets->min_gradient, widgets->max_gradient, &widgets->draw_min_gradient, &widgets->cig);
1443
1444 // Assign locally
1445 mina = widgets->draw_min_gradient;
1446
1447 window = gtk_widget_get_toplevel (widgets->gradient_box);
1448
1449 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1450
1451 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1452
1453 /* clear the image */
1454 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1455 TRUE, 0, 0, MARGIN, widgets->profile_height);
1456 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1457 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1458
1459 /* draw grid */
1460 for (i=0; i<=LINES; i++) {
1461 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1462 gchar s[32];
1463 int w, h;
1464
1465 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1466 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1467
1468 sprintf(s, "%8d%%", (int)(mina + (LINES-i)*chunksg[widgets->cig]));
1469 pango_layout_set_text(pl, s, -1);
1470 pango_layout_get_pixel_size (pl, &w, &h);
1471 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1472 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1473
1474 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1475 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1476 g_object_unref ( G_OBJECT ( pl ) );
1477 pl = NULL;
1478 }
1479
1480 /* draw gradients */
1481 for ( i = 0; i < widgets->profile_width; i++ )
1482 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1483 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->gradients[i]-mina)/(chunksg[widgets->cig]*LINES) );
1484
1485 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_gradient_gps_speed)) ) {
1486 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1487
1488 gdk_color_parse ( "red", &color );
1489 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1490
1491 // Ensure somekind of max speed when not set
1492 if ( widgets->max_speed < 0.01 )
1493 widgets->max_speed = vik_track_get_max_speed(tr);
1494
1495 draw_speed_dist(tr,
1496 GDK_DRAWABLE(pix),
1497 gps_speed_gc,
1498 widgets->max_speed,
1499 widgets->profile_width,
1500 widgets->profile_height,
1501 MARGIN,
1502 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
1503
1504 g_object_unref ( G_OBJECT(gps_speed_gc) );
1505 }
1506
1507 /* draw border */
1508 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1509
1510 g_object_unref ( G_OBJECT(pix) );
1511}
1512
1513/**
1514 * Draw just the speed (velocity)/time image
1515 */
1516static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
1517{
1518 GtkWidget *window;
1519 GdkPixmap *pix;
1520 gdouble mins;
1521 guint i;
1522
1523 // Free previous allocation
1524 if ( widgets->speeds )
1525 g_free ( widgets->speeds );
1526
1527 widgets->speeds = vik_track_make_speed_map ( tr, widgets->profile_width );
1528 if ( widgets->speeds == NULL )
1529 return;
1530
1531 // Convert into appropriate units
1532 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1533 switch (speed_units) {
1534 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1535 for ( i = 0; i < widgets->profile_width; i++ ) {
1536 widgets->speeds[i] = VIK_MPS_TO_KPH(widgets->speeds[i]);
1537 }
1538 break;
1539 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1540 for ( i = 0; i < widgets->profile_width; i++ ) {
1541 widgets->speeds[i] = VIK_MPS_TO_MPH(widgets->speeds[i]);
1542 }
1543 break;
1544 case VIK_UNITS_SPEED_KNOTS:
1545 for ( i = 0; i < widgets->profile_width; i++ ) {
1546 widgets->speeds[i] = VIK_MPS_TO_KNOTS(widgets->speeds[i]);
1547 }
1548 break;
1549 default:
1550 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1551 // No need to convert as already in m/s
1552 break;
1553 }
1554
1555 window = gtk_widget_get_toplevel (widgets->speed_box);
1556
1557 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1558
1559 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1560
1561 minmax_array(widgets->speeds, &widgets->min_speed, &widgets->max_speed, FALSE, widgets->profile_width);
1562 if (widgets->min_speed < 0.0)
1563 widgets->min_speed = 0; /* splines sometimes give negative speeds */
1564
1565 /* Find suitable chunk index */
1566 get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed, chunkss, sizeof(chunkss)/sizeof(chunkss[0]), &widgets->draw_min_speed, &widgets->cis);
1567
1568 // Assign locally
1569 mins = widgets->draw_min_speed;
1570
1571 /* clear the image */
1572 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1573 TRUE, 0, 0, MARGIN, widgets->profile_height);
1574 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1575 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1576
1577 /* draw grid */
1578 for (i=0; i<=LINES; i++) {
1579 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1580 gchar s[32];
1581 int w, h;
1582
1583 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1584 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1585
1586 // NB: No need to convert here anymore as numbers are in the appropriate units
1587 switch (speed_units) {
1588 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1589 sprintf(s, "%8dkm/h", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1590 break;
1591 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1592 sprintf(s, "%8dmph", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1593 break;
1594 case VIK_UNITS_SPEED_METRES_PER_SECOND:
1595 sprintf(s, "%8dm/s", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1596 break;
1597 case VIK_UNITS_SPEED_KNOTS:
1598 sprintf(s, "%8dknots", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1599 break;
1600 default:
1601 sprintf(s, "--");
1602 g_critical("Houston, we've had a problem. speed=%d", speed_units);
1603 }
1604
1605 pango_layout_set_text(pl, s, -1);
1606 pango_layout_get_pixel_size (pl, &w, &h);
1607 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1608 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1609
1610 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1611 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1612 g_object_unref ( G_OBJECT ( pl ) );
1613 pl = NULL;
1614 }
1615
1616
1617 /* draw speeds */
1618 for ( i = 0; i < widgets->profile_width; i++ )
1619 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1620 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds[i]-mins)/(chunkss[widgets->cis]*LINES) );
1621
1622
1623 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_gps_speed)) ) {
1624
1625 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1626 GdkColor color;
1627 gdk_color_parse ( "red", &color );
1628 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1629
1630 time_t beg_time = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
1631 time_t dur = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp - beg_time;
1632
1633 GList *iter;
1634 for (iter = tr->trackpoints; iter; iter = iter->next) {
1635 gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed;
1636 if (isnan(gps_speed))
1637 continue;
1638 switch (speed_units) {
1639 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1640 gps_speed = VIK_MPS_TO_KPH(gps_speed);
1641 break;
1642 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1643 gps_speed = VIK_MPS_TO_MPH(gps_speed);
1644 break;
1645 case VIK_UNITS_SPEED_KNOTS:
1646 gps_speed = VIK_MPS_TO_KNOTS(gps_speed);
1647 break;
1648 default:
1649 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1650 // No need to convert as already in m/s
1651 break;
1652 }
1653 int x = MARGIN + widgets->profile_width * (VIK_TRACKPOINT(iter->data)->timestamp - beg_time) / dur;
1654 int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cis]*LINES);
1655 gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
1656 }
1657 g_object_unref ( G_OBJECT(gps_speed_gc) );
1658 }
1659
1660 /* draw border */
1661 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1662
1663 g_object_unref ( G_OBJECT(pix) );
1664}
1665
1666/**
1667 * Draw just the distance/time image
1668 */
1669static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1670{
1671 GtkWidget *window;
1672 GdkPixmap *pix;
1673 gdouble maxd;
1674 guint i;
1675
1676 // Free previous allocation
1677 if ( widgets->distances )
1678 g_free ( widgets->distances );
1679
1680 widgets->distances = vik_track_make_distance_map ( tr, widgets->profile_width );
1681 if ( widgets->distances == NULL )
1682 return;
1683
1684 // Convert into appropriate units
1685 vik_units_distance_t dist_units = a_vik_get_units_distance ();
1686 if ( dist_units == VIK_UNITS_DISTANCE_MILES ) {
1687 for ( i = 0; i < widgets->profile_width; i++ ) {
1688 widgets->distances[i] = VIK_METERS_TO_MILES(widgets->distances[i]);
1689 }
1690 }
1691 else {
1692 // Metres - but want in kms
1693 for ( i = 0; i < widgets->profile_width; i++ ) {
1694 widgets->distances[i] = widgets->distances[i]/1000.0;
1695 }
1696 }
1697
1698 window = gtk_widget_get_toplevel (widgets->dist_box);
1699
1700 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1701
1702 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1703
1704 // easy to work out min / max of distance!
1705 // Assign locally
1706 // mind = 0.0; - Thus not used
1707 if ( dist_units == VIK_UNITS_DISTANCE_MILES )
1708 maxd = VIK_METERS_TO_MILES(vik_track_get_length_including_gaps (tr));
1709 else
1710 maxd = vik_track_get_length_including_gaps (tr) / 1000.0;
1711
1712 /* Find suitable chunk index */
1713 gdouble dummy = 0.0; // expect this to remain the same! (not that it's used)
1714 get_new_min_and_chunk_index (0, maxd, chunksd, sizeof(chunksd)/sizeof(chunksd[0]), &dummy, &widgets->cid);
1715
1716 /* clear the image */
1717 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1718 TRUE, 0, 0, MARGIN, widgets->profile_height);
1719 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1720 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1721
1722 /* draw grid */
1723 for (i=0; i<=LINES; i++) {
1724 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1725 gchar s[32];
1726 int w, h;
1727
1728 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1729 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1730
1731 if ( dist_units == VIK_UNITS_DISTANCE_MILES )
1732 sprintf(s, _("%.1f miles"), ((LINES-i)*chunksd[widgets->cid]));
1733 else
1734 sprintf(s, _("%.1f km"), ((LINES-i)*chunksd[widgets->cid]));
1735
1736 pango_layout_set_text(pl, s, -1);
1737 pango_layout_get_pixel_size (pl, &w, &h);
1738 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1739 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1740
1741 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1742 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1743 g_object_unref ( G_OBJECT ( pl ) );
1744 pl = NULL;
1745 }
1746
1747 /* draw distance */
1748 for ( i = 0; i < widgets->profile_width; i++ )
1749 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1750 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->distances[i])/(chunksd[widgets->cid]*LINES) );
1751
1752 // Show speed indicator
1753 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_dist_speed)) ) {
1754 GdkGC *dist_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1755 GdkColor color;
1756 gdk_color_parse ( "red", &color );
1757 gdk_gc_set_rgb_fg_color ( dist_speed_gc, &color);
1758
1759 gdouble max_speed = 0;
1760 max_speed = widgets->max_speed * 110 / 100;
1761
1762 // This is just an indicator - no actual values can be inferred by user
1763 gint i;
1764 for ( i = 0; i < widgets->profile_width; i++ ) {
1765 int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
1766 gdk_draw_rectangle(GDK_DRAWABLE(pix), dist_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
1767 }
1768 g_object_unref ( G_OBJECT(dist_speed_gc) );
1769 }
1770
1771 /* draw border */
1772 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1773
1774 g_object_unref ( G_OBJECT(pix) );
1775
1776}
1777
1778/**
1779 * Draw just the elevation/time image
1780 */
1781static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1782{
1783 GtkWidget *window;
1784 GdkPixmap *pix;
1785 gdouble mina;
1786 guint i;
1787
1788 // Free previous allocation
1789 if ( widgets->ats )
1790 g_free ( widgets->ats );
1791
1792 widgets->ats = vik_track_make_elevation_time_map ( tr, widgets->profile_width );
1793
1794 if ( widgets->ats == NULL )
1795 return;
1796
1797 // Convert into appropriate units
1798 vik_units_height_t height_units = a_vik_get_units_height ();
1799 if ( height_units == VIK_UNITS_HEIGHT_FEET ) {
1800 // Convert altitudes into feet units
1801 for ( i = 0; i < widgets->profile_width; i++ ) {
1802 widgets->ats[i] = VIK_METERS_TO_FEET(widgets->ats[i]);
1803 }
1804 }
1805 // Otherwise leave in metres
1806
1807 minmax_array(widgets->ats, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
1808
1809 get_new_min_and_chunk_index_altitude (widgets->min_altitude, widgets->max_altitude, &widgets->draw_min_altitude_time, &widgets->ciat);
1810
1811 // Assign locally
1812 mina = widgets->draw_min_altitude_time;
1813
1814 window = gtk_widget_get_toplevel (widgets->elev_time_box);
1815
1816 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1817
1818 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1819
1820 /* clear the image */
1821 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1822 TRUE, 0, 0, MARGIN, widgets->profile_height);
1823 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1824 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1825
1826 /* draw grid */
1827 for (i=0; i<=LINES; i++) {
1828 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1829 gchar s[32];
1830 int w, h;
1831
1832 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1833 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1834
1835 switch (height_units) {
1836 case VIK_UNITS_HEIGHT_METRES:
1837 sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->ciat]));
1838 break;
1839 case VIK_UNITS_HEIGHT_FEET:
1840 // NB values already converted into feet
1841 sprintf(s, "%8dft", (int)(mina + (LINES-i)*chunksa[widgets->ciat]));
1842 break;
1843 default:
1844 sprintf(s, "--");
1845 g_critical("Houston, we've had a problem. height=%d", height_units);
1846 }
1847 pango_layout_set_text(pl, s, -1);
1848 pango_layout_get_pixel_size (pl, &w, &h);
1849 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1850 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1851
1852 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1853 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1854 g_object_unref ( G_OBJECT ( pl ) );
1855 pl = NULL;
1856 }
1857
1858 /* draw elevations */
1859 for ( i = 0; i < widgets->profile_width; i++ )
1860 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1861 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->ats[i]-mina)/(chunksa[widgets->ciat]*LINES) );
1862
1863 // Show speed indicator
1864 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_elev_speed)) ) {
1865 GdkGC *elev_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1866 GdkColor color;
1867 gdk_color_parse ( "red", &color );
1868 gdk_gc_set_rgb_fg_color ( elev_speed_gc, &color);
1869
1870 gdouble max_speed = 0;
1871 max_speed = widgets->max_speed * 110 / 100;
1872
1873 // This is just an indicator - no actual values can be inferred by user
1874 gint i;
1875 for ( i = 0; i < widgets->profile_width; i++ ) {
1876 int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
1877 gdk_draw_rectangle(GDK_DRAWABLE(pix), elev_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
1878 }
1879 g_object_unref ( G_OBJECT(elev_speed_gc) );
1880 }
1881
1882 /* draw border */
1883 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1884
1885 g_object_unref ( G_OBJECT(pix) );
1886
1887}
1888
1889/**
1890 * Draw just the speed/distance image
1891 */
1892static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
1893{
1894 GtkWidget *window;
1895 GdkPixmap *pix;
1896 gdouble mins;
1897 guint i;
1898
1899 // Free previous allocation
1900 if ( widgets->speeds_dist )
1901 g_free ( widgets->speeds_dist );
1902
1903 widgets->speeds_dist = vik_track_make_speed_dist_map ( tr, widgets->profile_width );
1904 if ( widgets->speeds_dist == NULL )
1905 return;
1906
1907 // Convert into appropriate units
1908 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1909 switch (speed_units) {
1910 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1911 for ( i = 0; i < widgets->profile_width; i++ ) {
1912 widgets->speeds_dist[i] = VIK_MPS_TO_KPH(widgets->speeds_dist[i]);
1913 }
1914 break;
1915 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1916 for ( i = 0; i < widgets->profile_width; i++ ) {
1917 widgets->speeds_dist[i] = VIK_MPS_TO_MPH(widgets->speeds_dist[i]);
1918 }
1919 break;
1920 case VIK_UNITS_SPEED_KNOTS:
1921 for ( i = 0; i < widgets->profile_width; i++ ) {
1922 widgets->speeds_dist[i] = VIK_MPS_TO_KNOTS(widgets->speeds_dist[i]);
1923 }
1924 break;
1925 default:
1926 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1927 // No need to convert as already in m/s
1928 break;
1929 }
1930
1931 window = gtk_widget_get_toplevel (widgets->speed_dist_box);
1932
1933 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1934
1935 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1936
1937 // OK to resuse min_speed here
1938 minmax_array(widgets->speeds_dist, &widgets->min_speed, &widgets->max_speed_dist, FALSE, widgets->profile_width);
1939 if (widgets->min_speed < 0.0)
1940 widgets->min_speed = 0; /* splines sometimes give negative speeds */
1941
1942 /* Find suitable chunk index */
1943 get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed_dist, chunkss, sizeof(chunkss)/sizeof(chunkss[0]), &widgets->draw_min_speed, &widgets->cisd);
1944
1945 // Assign locally
1946 mins = widgets->draw_min_speed;
1947
1948 /* clear the image */
1949 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1950 TRUE, 0, 0, MARGIN, widgets->profile_height);
1951 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1952 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1953
1954 /* draw grid */
1955 for (i=0; i<=LINES; i++) {
1956 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1957 gchar s[32];
1958 int w, h;
1959
1960 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1961 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1962
1963 // NB: No need to convert here anymore as numbers are in the appropriate units
1964 switch (speed_units) {
1965 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1966 sprintf(s, "%8dkm/h", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1967 break;
1968 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1969 sprintf(s, "%8dmph", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1970 break;
1971 case VIK_UNITS_SPEED_METRES_PER_SECOND:
1972 sprintf(s, "%8dm/s", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1973 break;
1974 case VIK_UNITS_SPEED_KNOTS:
1975 sprintf(s, "%8dknots", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1976 break;
1977 default:
1978 sprintf(s, "--");
1979 g_critical("Houston, we've had a problem. speed=%d", speed_units);
1980 }
1981
1982 pango_layout_set_text(pl, s, -1);
1983 pango_layout_get_pixel_size (pl, &w, &h);
1984 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1985 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1986
1987 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1988 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1989 g_object_unref ( G_OBJECT ( pl ) );
1990 pl = NULL;
1991 }
1992
1993
1994 /* draw speeds */
1995 for ( i = 0; i < widgets->profile_width; i++ )
1996 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1997 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds_dist[i]-mins)/(chunkss[widgets->cisd]*LINES) );
1998
1999
2000 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_sd_gps_speed)) ) {
2001
2002 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
2003 GdkColor color;
2004 gdk_color_parse ( "red", &color );
2005 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
2006
2007 gdouble dist = vik_track_get_length_including_gaps(tr);
2008 gdouble dist_tp = 0.0;
2009
2010 GList *iter = tr->trackpoints;
2011 for (iter = iter->next; iter; iter = iter->next) {
2012 gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed;
2013 if (isnan(gps_speed))
2014 continue;
2015 switch (speed_units) {
2016 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2017 gps_speed = VIK_MPS_TO_KPH(gps_speed);
2018 break;
2019 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2020 gps_speed = VIK_MPS_TO_MPH(gps_speed);
2021 break;
2022 case VIK_UNITS_SPEED_KNOTS:
2023 gps_speed = VIK_MPS_TO_KNOTS(gps_speed);
2024 break;
2025 default:
2026 // VIK_UNITS_SPEED_METRES_PER_SECOND:
2027 // No need to convert as already in m/s
2028 break;
2029 }
2030 dist_tp += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord), &(VIK_TRACKPOINT(iter->prev->data)->coord) );
2031 int x = MARGIN + (widgets->profile_width * dist_tp / dist);
2032 int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cisd]*LINES);
2033 gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
2034 }
2035 g_object_unref ( G_OBJECT(gps_speed_gc) );
2036 }
2037
2038 /* draw border */
2039 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
2040
2041 g_object_unref ( G_OBJECT(pix) );
2042}
2043#undef LINES
2044
2045/**
2046 * Draw all graphs
2047 */
2048static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean resized )
2049{
2050 // Draw graphs even if they are not visible
2051
2052 GList *child = NULL;
2053 GtkWidget *image = NULL;
2054 GtkWidget *window = gtk_widget_get_toplevel(widget);
2055 gdouble pc = NAN;
2056 gdouble pc_blob = NAN;
2057
2058 // Draw elevations
2059 if (widgets->elev_box != NULL) {
2060
2061 // Saved image no longer any good as we've resized, so we remove it here
2062 if (resized && widgets->elev_graph_saved_img.img) {
2063 g_object_unref(widgets->elev_graph_saved_img.img);
2064 widgets->elev_graph_saved_img.img = NULL;
2065 widgets->elev_graph_saved_img.saved = FALSE;
2066 }
2067
2068 child = gtk_container_get_children(GTK_CONTAINER(widgets->elev_box));
2069 draw_elevations (GTK_WIDGET(child->data), widgets->tr, widgets );
2070
2071 image = GTK_WIDGET(child->data);
2072 g_list_free(child);
2073
2074 // Ensure marker or blob are redrawn if necessary
2075 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2076
2077 pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
2078 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2079 gint y_blob = 0;
2080 if (widgets->is_blob_drawn) {
2081 pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
2082 if (!isnan(pc_blob)) {
2083 x_blob = (pc_blob * widgets->profile_width);
2084 }
2085 y_blob = blobby_altitude (x_blob, widgets);
2086 }
2087
2088 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2089 if (!isnan(pc)) {
2090 marker_x = (pc * widgets->profile_width) + MARGIN;
2091 }
2092
2093 save_image_and_draw_graph_marks (image,
2094 marker_x,
2095 gtk_widget_get_style(window)->black_gc,
2096 x_blob+MARGIN,
2097 y_blob,
2098 &widgets->elev_graph_saved_img,
2099 widgets->profile_width,
2100 widgets->profile_height,
2101 &widgets->is_marker_drawn,
2102 &widgets->is_blob_drawn);
2103 }
2104 }
2105
2106 // Draw gradients
2107 if (widgets->gradient_box != NULL) {
2108
2109 // Saved image no longer any good as we've resized, so we remove it here
2110 if (resized && widgets->gradient_graph_saved_img.img) {
2111 g_object_unref(widgets->gradient_graph_saved_img.img);
2112 widgets->gradient_graph_saved_img.img = NULL;
2113 widgets->gradient_graph_saved_img.saved = FALSE;
2114 }
2115
2116 child = gtk_container_get_children(GTK_CONTAINER(widgets->gradient_box));
2117 draw_gradients (GTK_WIDGET(child->data), widgets->tr, widgets );
2118
2119 image = GTK_WIDGET(child->data);
2120 g_list_free(child);
2121
2122 // Ensure marker or blob are redrawn if necessary
2123 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2124
2125 pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
2126 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2127 gint y_blob = 0;
2128 if (widgets->is_blob_drawn) {
2129 pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
2130 if (!isnan(pc_blob)) {
2131 x_blob = (pc_blob * widgets->profile_width);
2132 }
2133 y_blob = blobby_gradient (x_blob, widgets);
2134 }
2135
2136 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2137 if (!isnan(pc)) {
2138 marker_x = (pc * widgets->profile_width) + MARGIN;
2139 }
2140
2141 save_image_and_draw_graph_marks (image,
2142 marker_x,
2143 gtk_widget_get_style(window)->black_gc,
2144 x_blob+MARGIN,
2145 y_blob,
2146 &widgets->gradient_graph_saved_img,
2147 widgets->profile_width,
2148 widgets->profile_height,
2149 &widgets->is_marker_drawn,
2150 &widgets->is_blob_drawn);
2151 }
2152 }
2153
2154 // Draw speeds
2155 if (widgets->speed_box != NULL) {
2156
2157 // Saved image no longer any good as we've resized
2158 if (resized && widgets->speed_graph_saved_img.img) {
2159 g_object_unref(widgets->speed_graph_saved_img.img);
2160 widgets->speed_graph_saved_img.img = NULL;
2161 widgets->speed_graph_saved_img.saved = FALSE;
2162 }
2163
2164 child = gtk_container_get_children(GTK_CONTAINER(widgets->speed_box));
2165 draw_vt (GTK_WIDGET(child->data), widgets->tr, widgets );
2166
2167 image = GTK_WIDGET(child->data);
2168 g_list_free(child);
2169
2170 // Ensure marker or blob are redrawn if necessary
2171 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2172
2173 pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
2174
2175 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2176 gint y_blob = 0;
2177 if (widgets->is_blob_drawn) {
2178 pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
2179 if (!isnan(pc_blob)) {
2180 x_blob = (pc_blob * widgets->profile_width);
2181 }
2182
2183 y_blob = blobby_speed (x_blob, widgets);
2184 }
2185
2186 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2187 if (!isnan(pc)) {
2188 marker_x = (pc * widgets->profile_width) + MARGIN;
2189 }
2190
2191 save_image_and_draw_graph_marks (image,
2192 marker_x,
2193 gtk_widget_get_style(window)->black_gc,
2194 x_blob+MARGIN,
2195 y_blob,
2196 &widgets->speed_graph_saved_img,
2197 widgets->profile_width,
2198 widgets->profile_height,
2199 &widgets->is_marker_drawn,
2200 &widgets->is_blob_drawn);
2201 }
2202 }
2203
2204 // Draw Distances
2205 if (widgets->dist_box != NULL) {
2206
2207 // Saved image no longer any good as we've resized
2208 if (resized && widgets->dist_graph_saved_img.img) {
2209 g_object_unref(widgets->dist_graph_saved_img.img);
2210 widgets->dist_graph_saved_img.img = NULL;
2211 widgets->dist_graph_saved_img.saved = FALSE;
2212 }
2213
2214 child = gtk_container_get_children(GTK_CONTAINER(widgets->dist_box));
2215 draw_dt (GTK_WIDGET(child->data), widgets->tr, widgets );
2216
2217 image = GTK_WIDGET(child->data);
2218 g_list_free(child);
2219
2220 // Ensure marker or blob are redrawn if necessary
2221 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2222
2223 pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
2224
2225 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2226 gint y_blob = 0;
2227 if (widgets->is_blob_drawn) {
2228 pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
2229 if (!isnan(pc_blob)) {
2230 x_blob = (pc_blob * widgets->profile_width);
2231 }
2232
2233 y_blob = blobby_distance (x_blob, widgets);
2234 }
2235
2236 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2237 if (!isnan(pc)) {
2238 marker_x = (pc * widgets->profile_width) + MARGIN;
2239 }
2240
2241 save_image_and_draw_graph_marks (image,
2242 marker_x,
2243 gtk_widget_get_style(window)->black_gc,
2244 x_blob+MARGIN,
2245 y_blob,
2246 &widgets->dist_graph_saved_img,
2247 widgets->profile_width,
2248 widgets->profile_height,
2249 &widgets->is_marker_drawn,
2250 &widgets->is_blob_drawn);
2251 }
2252 }
2253
2254 // Draw Elevations in timely manner
2255 if (widgets->elev_time_box != NULL) {
2256
2257 // Saved image no longer any good as we've resized
2258 if (resized && widgets->elev_time_graph_saved_img.img) {
2259 g_object_unref(widgets->elev_time_graph_saved_img.img);
2260 widgets->elev_time_graph_saved_img.img = NULL;
2261 widgets->elev_time_graph_saved_img.saved = FALSE;
2262 }
2263
2264 child = gtk_container_get_children(GTK_CONTAINER(widgets->elev_time_box));
2265 draw_et (GTK_WIDGET(child->data), widgets->tr, widgets );
2266
2267 image = GTK_WIDGET(child->data);
2268 g_list_free(child);
2269
2270 // Ensure marker or blob are redrawn if necessary
2271 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2272
2273 pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
2274
2275 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2276 gint y_blob = 0;
2277 if (widgets->is_blob_drawn) {
2278 pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
2279 if (!isnan(pc_blob)) {
2280 x_blob = (pc_blob * widgets->profile_width);
2281 }
2282 y_blob = blobby_altitude_time (x_blob, widgets);
2283 }
2284
2285 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2286 if (!isnan(pc)) {
2287 marker_x = (pc * widgets->profile_width) + MARGIN;
2288 }
2289
2290 save_image_and_draw_graph_marks (image,
2291 marker_x,
2292 gtk_widget_get_style(window)->black_gc,
2293 x_blob+MARGIN,
2294 y_blob,
2295 &widgets->elev_time_graph_saved_img,
2296 widgets->profile_width,
2297 widgets->profile_height,
2298 &widgets->is_marker_drawn,
2299 &widgets->is_blob_drawn);
2300 }
2301 }
2302
2303 // Draw speed distances
2304 if (widgets->speed_dist_box != NULL) {
2305
2306 // Saved image no longer any good as we've resized, so we remove it here
2307 if (resized && widgets->speed_dist_graph_saved_img.img) {
2308 g_object_unref(widgets->speed_dist_graph_saved_img.img);
2309 widgets->speed_dist_graph_saved_img.img = NULL;
2310 widgets->speed_dist_graph_saved_img.saved = FALSE;
2311 }
2312
2313 child = gtk_container_get_children(GTK_CONTAINER(widgets->speed_dist_box));
2314 draw_sd (GTK_WIDGET(child->data), widgets->tr, widgets );
2315
2316 image = GTK_WIDGET(child->data);
2317 g_list_free(child);
2318
2319 // Ensure marker or blob are redrawn if necessary
2320 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2321
2322 pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
2323 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2324 gint y_blob = 0;
2325 if (widgets->is_blob_drawn) {
2326 pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
2327 if (!isnan(pc_blob)) {
2328 x_blob = (pc_blob * widgets->profile_width);
2329 }
2330 y_blob = blobby_speed_dist (x_blob, widgets);
2331 }
2332
2333 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2334 if (!isnan(pc)) {
2335 marker_x = (pc * widgets->profile_width) + MARGIN;
2336 }
2337
2338 save_image_and_draw_graph_marks (image,
2339 marker_x,
2340 gtk_widget_get_style(window)->black_gc,
2341 x_blob+MARGIN,
2342 y_blob,
2343 &widgets->speed_dist_graph_saved_img,
2344 widgets->profile_width,
2345 widgets->profile_height,
2346 &widgets->is_marker_drawn,
2347 &widgets->is_blob_drawn);
2348 }
2349 }
2350
2351}
2352
2353/**
2354 * Configure/Resize the profile & speed/time images
2355 */
2356static gboolean configure_event ( GtkWidget *widget, GdkEventConfigure *event, PropWidgets *widgets )
2357{
2358 if (widgets->configure_dialog) {
2359 // Determine size offsets between dialog size and size for images
2360 // Only on the initialisation of the dialog
2361 widgets->profile_width_offset = event->width - widgets->profile_width;
2362 widgets->profile_height_offset = event->height - widgets->profile_height;
2363 widgets->configure_dialog = FALSE;
2364
2365 // Without this the settting, the dialog will only grow in vertical size - one can not then make it smaller!
2366 gtk_widget_set_size_request ( widget, widgets->profile_width+widgets->profile_width_offset, widgets->profile_height+widgets->profile_height_offset );
2367
2368 // Allow resizing back down to a minimal size (especially useful if the initial size has been made bigger after restoring from the saved settings)
2369 GdkGeometry geom = { 600+widgets->profile_width_offset, 300+widgets->profile_height_offset, 0, 0, 0, 0, 0, 0, 0, 0, GDK_GRAVITY_STATIC };
2370 gdk_window_set_geometry_hints ( gtk_widget_get_window(widget), &geom, GDK_HINT_MIN_SIZE );
2371 }
2372 else {
2373 widgets->profile_width_old = widgets->profile_width;
2374 widgets->profile_height_old = widgets->profile_height;
2375 }
2376
2377 // Now adjust From Dialog size to get image size
2378 widgets->profile_width = event->width - widgets->profile_width_offset;
2379 widgets->profile_height = event->height - widgets->profile_height_offset;
2380
2381 // ATM we receive configure_events when the dialog is moved and so no further action is necessary
2382 if ( !widgets->configure_dialog &&
2383 (widgets->profile_width_old == widgets->profile_width) && (widgets->profile_height_old == widgets->profile_height) )
2384 return FALSE;
2385
2386 // Draw stuff
2387 draw_all_graphs ( widget, widgets, TRUE );
2388
2389 return FALSE;
2390}
2391
2392/**
2393 * Create height profile widgets including the image and callbacks
2394 */
2395GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, PropWidgets *widgets, gdouble *min_alt, gdouble *max_alt)
2396{
2397 GdkPixmap *pix;
2398 GtkWidget *image;
2399 GtkWidget *eventbox;
2400
2401 // First allocation
2402 widgets->altitudes = vik_track_make_elevation_map ( widgets->tr, widgets->profile_width );
2403
2404 if ( widgets->altitudes == NULL ) {
2405 *min_alt = *max_alt = VIK_DEFAULT_ALTITUDE;
2406 return NULL;
2407 }
2408
2409 minmax_array(widgets->altitudes, min_alt, max_alt, TRUE, widgets->profile_width);
2410
2411 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2412 image = gtk_image_new_from_pixmap ( pix, NULL );
2413
2414 g_object_unref ( G_OBJECT(pix) );
2415
2416 eventbox = gtk_event_box_new ();
2417 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_profile_click), widgets );
2418 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_profile_move), widgets );
2419 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2420 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_STRUCTURE_MASK);
2421
2422 return eventbox;
2423}
2424
2425/**
2426 * Create height profile widgets including the image and callbacks
2427 */
2428GtkWidget *vik_trw_layer_create_gradient ( GtkWidget *window, PropWidgets *widgets)
2429{
2430 GdkPixmap *pix;
2431 GtkWidget *image;
2432 GtkWidget *eventbox;
2433
2434 // First allocation
2435 widgets->gradients = vik_track_make_gradient_map ( widgets->tr, widgets->profile_width );
2436
2437 if ( widgets->gradients == NULL ) {
2438 return NULL;
2439 }
2440
2441 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2442 image = gtk_image_new_from_pixmap ( pix, NULL );
2443
2444 g_object_unref ( G_OBJECT(pix) );
2445
2446 eventbox = gtk_event_box_new ();
2447 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_gradient_click), widgets );
2448 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_gradient_move), widgets );
2449 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2450 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_STRUCTURE_MASK);
2451
2452 return eventbox;
2453}
2454
2455/**
2456 * Create speed/time widgets including the image and callbacks
2457 */
2458GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, PropWidgets *widgets)
2459{
2460 GdkPixmap *pix;
2461 GtkWidget *image;
2462 GtkWidget *eventbox;
2463
2464 // First allocation
2465 widgets->speeds = vik_track_make_speed_map ( widgets->tr, widgets->profile_width );
2466 if ( widgets->speeds == NULL )
2467 return NULL;
2468
2469 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2470 image = gtk_image_new_from_pixmap ( pix, NULL );
2471
2472#if 0
2473 /* XXX this can go out, it's just a helpful dev tool */
2474 {
2475 int j;
2476 GdkGC **colors[8] = { gtk_widget_get_style(window)->bg_gc,
2477 gtk_widget_get_style(window)->fg_gc,
2478 gtk_widget_get_style(window)->light_gc,
2479 gtk_widget_get_style(window)->dark_gc,
2480 gtk_widget_get_style(window)->mid_gc,
2481 gtk_widget_get_style(window)->text_gc,
2482 gtk_widget_get_style(window)->base_gc,
2483 gtk_widget_get_style(window)->text_aa_gc };
2484 for (i=0; i<5; i++) {
2485 for (j=0; j<8; j++) {
2486 gdk_draw_rectangle(GDK_DRAWABLE(pix), colors[j][i],
2487 TRUE, i*20, j*20, 20, 20);
2488 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc,
2489 FALSE, i*20, j*20, 20, 20);
2490 }
2491 }
2492 }
2493#endif
2494
2495 g_object_unref ( G_OBJECT(pix) );
2496
2497 eventbox = gtk_event_box_new ();
2498 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_vt_click), widgets );
2499 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_vt_move), widgets );
2500 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2501 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2502
2503 return eventbox;
2504}
2505
2506/**
2507 * Create distance / time widgets including the image and callbacks
2508 */
2509GtkWidget *vik_trw_layer_create_dtdiag ( GtkWidget *window, PropWidgets *widgets)
2510{
2511 GdkPixmap *pix;
2512 GtkWidget *image;
2513 GtkWidget *eventbox;
2514
2515 // First allocation
2516 widgets->distances = vik_track_make_distance_map ( widgets->tr, widgets->profile_width );
2517 if ( widgets->distances == NULL )
2518 return NULL;
2519
2520 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2521 image = gtk_image_new_from_pixmap ( pix, NULL );
2522
2523 g_object_unref ( G_OBJECT(pix) );
2524
2525 eventbox = gtk_event_box_new ();
2526 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_dt_click), widgets );
2527 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_dt_move), widgets );
2528 //g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), widgets );
2529 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2530 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2531
2532 return eventbox;
2533}
2534
2535/**
2536 * Create elevation / time widgets including the image and callbacks
2537 */
2538GtkWidget *vik_trw_layer_create_etdiag ( GtkWidget *window, PropWidgets *widgets)
2539{
2540 GdkPixmap *pix;
2541 GtkWidget *image;
2542 GtkWidget *eventbox;
2543
2544 // First allocation
2545 widgets->ats = vik_track_make_elevation_time_map ( widgets->tr, widgets->profile_width );
2546 if ( widgets->ats == NULL )
2547 return NULL;
2548
2549 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2550 image = gtk_image_new_from_pixmap ( pix, NULL );
2551
2552 g_object_unref ( G_OBJECT(pix) );
2553
2554 eventbox = gtk_event_box_new ();
2555 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_et_click), widgets );
2556 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_et_move), widgets );
2557 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2558 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2559
2560 return eventbox;
2561}
2562
2563/**
2564 * Create speed/distance widgets including the image and callbacks
2565 */
2566GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, PropWidgets *widgets)
2567{
2568 GdkPixmap *pix;
2569 GtkWidget *image;
2570 GtkWidget *eventbox;
2571
2572 // First allocation
2573 widgets->speeds_dist = vik_track_make_speed_dist_map ( widgets->tr, widgets->profile_width );
2574 if ( widgets->speeds_dist == NULL )
2575 return NULL;
2576
2577 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2578 image = gtk_image_new_from_pixmap ( pix, NULL );
2579
2580 g_object_unref ( G_OBJECT(pix) );
2581
2582 eventbox = gtk_event_box_new ();
2583 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_sd_click), widgets );
2584 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_sd_move), widgets );
2585 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2586 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2587
2588 return eventbox;
2589}
2590#undef MARGIN
2591
2592#define VIK_SETTINGS_TRACK_PROFILE_WIDTH "track_profile_display_width"
2593#define VIK_SETTINGS_TRACK_PROFILE_HEIGHT "track_profile_display_height"
2594
2595static void save_values ( PropWidgets *widgets )
2596{
2597 a_settings_set_integer ( VIK_SETTINGS_TRACK_PROFILE_WIDTH, widgets->profile_width );
2598 a_settings_set_integer ( VIK_SETTINGS_TRACK_PROFILE_HEIGHT, widgets->profile_height );
2599}
2600
2601static void destroy_cb ( GtkDialog *dialog, PropWidgets *widgets )
2602{
2603 save_values(widgets);
2604 prop_widgets_free(widgets);
2605}
2606
2607static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widgets )
2608{
2609 VikTrack *tr = widgets->tr;
2610 VikTrwLayer *vtl = widgets->vtl;
2611 gboolean keep_dialog = FALSE;
2612
2613 /* FIXME: check and make sure the track still exists before doing anything to it */
2614 /* Note: destroying diaglog (eg, parent window exit) won't give "response" */
2615 switch (resp) {
2616 case GTK_RESPONSE_DELETE_EVENT: /* received delete event (not from buttons) */
2617 case GTK_RESPONSE_REJECT:
2618 break;
2619 case GTK_RESPONSE_ACCEPT:
2620 vik_track_set_comment(tr, gtk_entry_get_text(GTK_ENTRY(widgets->w_comment)));
2621 vik_track_set_description(tr, gtk_entry_get_text(GTK_ENTRY(widgets->w_description)));
2622 gtk_color_button_get_color ( GTK_COLOR_BUTTON(widgets->w_color), &(tr->color) );
2623 trw_layer_update_treeview ( widgets->vtl, widgets->tr, widgets->trk_id );
2624 vik_layer_emit_update ( VIK_LAYER(vtl) );
2625 break;
2626 case VIK_TRW_LAYER_PROPWIN_REVERSE:
2627 vik_track_reverse(tr);
2628 vik_layer_emit_update ( VIK_LAYER(vtl) );
2629 break;
2630 case VIK_TRW_LAYER_PROPWIN_DEL_DUP:
2631 vik_track_remove_dup_points(tr); // NB ignore the returned answer
2632 // As we could have seen the nuber of dulplicates that would be deleted in the properties statistics tab,
2633 // choose not to inform the user unnecessarily
2634
2635 /* above operation could have deleted current_tp or last_tp */
2636 trw_layer_cancel_tps_of_track ( vtl, tr );
2637 vik_layer_emit_update ( VIK_LAYER(vtl) );
2638 break;
2639 case VIK_TRW_LAYER_PROPWIN_SPLIT:
2640 {
2641 /* get new tracks, add them and then the delete old one. old can still exist on clipboard. */
2642 guint ntracks;
2643
2644 VikTrack **tracks = vik_track_split_into_segments(tr, &ntracks);
2645 gchar *new_tr_name;
2646 guint i;
2647 for ( i = 0; i < ntracks; i++ )
2648 {
2649 if ( tracks[i] ) {
2650 new_tr_name = trw_layer_new_unique_sublayer_name ( vtl,
2651 widgets->tr->is_route ? VIK_TRW_LAYER_SUBLAYER_ROUTE : VIK_TRW_LAYER_SUBLAYER_TRACK,
2652 widgets->tr->name);
2653 if ( widgets->tr->is_route )
2654 vik_trw_layer_add_route ( vtl, new_tr_name, tracks[i] );
2655 else
2656 vik_trw_layer_add_track ( vtl, new_tr_name, tracks[i] );
2657 }
2658 }
2659 if ( tracks )
2660 {
2661 g_free ( tracks );
2662 /* Don't let track destroy this dialog */
2663 vik_track_clear_property_dialog(tr);
2664 if ( widgets->tr->is_route )
2665 vik_trw_layer_delete_route ( vtl, tr );
2666 else
2667 vik_trw_layer_delete_track ( vtl, tr );
2668 vik_layer_emit_update ( VIK_LAYER(vtl) ); /* chase thru the hoops */
2669 }
2670 }
2671 break;
2672 case VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER:
2673 {
2674 GList *iter = tr->trackpoints;
2675 while ((iter = iter->next)) {
2676 if (widgets->marker_tp == VIK_TRACKPOINT(iter->data))
2677 break;
2678 }
2679 if (iter == NULL) {
2680 a_dialog_msg(VIK_GTK_WINDOW_FROM_LAYER(vtl), GTK_MESSAGE_ERROR,
2681 _("Failed spliting track. Track unchanged"), NULL);
2682 keep_dialog = TRUE;
2683 break;
2684 }
2685
2686 gchar *r_name = trw_layer_new_unique_sublayer_name(vtl,
2687 widgets->tr->is_route ? VIK_TRW_LAYER_SUBLAYER_ROUTE : VIK_TRW_LAYER_SUBLAYER_TRACK,
2688 widgets->tr->name);
2689 iter->prev->next = NULL;
2690 iter->prev = NULL;
2691 VikTrack *tr_right = vik_track_new();
2692 if ( tr->comment )
2693 vik_track_set_comment ( tr_right, tr->comment );
2694 tr_right->visible = tr->visible;
2695 tr_right->is_route = tr->is_route;
2696 tr_right->trackpoints = iter;
2697
2698 if ( widgets->tr->is_route )
2699 vik_trw_layer_add_route(vtl, r_name, tr_right);
2700 else
2701 vik_trw_layer_add_track(vtl, r_name, tr_right);
2702 vik_layer_emit_update ( VIK_LAYER(vtl) );
2703 }
2704 break;
2705 default:
2706 fprintf(stderr, "DEBUG: unknown response\n");
2707 return;
2708 }
2709
2710 /* Keep same behaviour for now: destroy dialog if click on any button */
2711 if (!keep_dialog) {
2712 vik_track_clear_property_dialog(tr);
2713 gtk_widget_destroy ( GTK_WIDGET(dialog) );
2714 }
2715}
2716
2717/**
2718 * Force a redraw when checkbutton has been toggled to show/hide that information
2719 */
2720static void checkbutton_toggle_cb ( GtkToggleButton *togglebutton, PropWidgets *widgets, gpointer dummy )
2721{
2722 // Even though not resized, we'll pretend it is -
2723 // as this invalidates the saved images (since the image may have changed)
2724 draw_all_graphs ( widgets->dialog, widgets, TRUE );
2725}
2726
2727/**
2728 * Create the widgets for the given graph tab
2729 */
2730static GtkWidget *create_graph_page ( GtkWidget *graph,
2731 const gchar *markup,
2732 GtkWidget *value,
2733 const gchar *markup2,
2734 GtkWidget *value2,
2735 GtkWidget *checkbutton1,
2736 gboolean checkbutton1_default,
2737 GtkWidget *checkbutton2,
2738 gboolean checkbutton2_default )
2739{
2740 GtkWidget *hbox = gtk_hbox_new ( FALSE, 10 );
2741 GtkWidget *vbox = gtk_vbox_new ( FALSE, 10 );
2742 GtkWidget *label = gtk_label_new (NULL);
2743 GtkWidget *label2 = gtk_label_new (NULL);
2744 gtk_box_pack_start (GTK_BOX(vbox), graph, FALSE, FALSE, 0);
2745 gtk_label_set_markup ( GTK_LABEL(label), markup );
2746 gtk_label_set_markup ( GTK_LABEL(label2), markup2 );
2747 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
2748 gtk_box_pack_start (GTK_BOX(hbox), value, FALSE, FALSE, 0);
2749 gtk_box_pack_start (GTK_BOX(hbox), label2, FALSE, FALSE, 0);
2750 gtk_box_pack_start (GTK_BOX(hbox), value2, FALSE, FALSE, 0);
2751 if (checkbutton2) {
2752 gtk_box_pack_end (GTK_BOX(hbox), checkbutton2, FALSE, FALSE, 0);
2753 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton2), checkbutton2_default);
2754 }
2755 if (checkbutton1) {
2756 gtk_box_pack_end (GTK_BOX(hbox), checkbutton1, FALSE, FALSE, 0);
2757 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton1), checkbutton1_default);
2758 }
2759 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
2760
2761 return vbox;
2762}
2763
2764void vik_trw_layer_propwin_run ( GtkWindow *parent,
2765 VikTrwLayer *vtl,
2766 VikTrack *tr,
2767 gpointer vlp,
2768 VikViewport *vvp,
2769 gpointer *trk_id )
2770{
2771 PropWidgets *widgets = prop_widgets_new();
2772 widgets->vtl = vtl;
2773 widgets->vvp = vvp;
2774 widgets->vlp = vlp;
2775 widgets->tr = tr;
2776 widgets->trk_id = trk_id;
2777
2778 gint profile_size_value;
2779 // Ensure minimum values
2780 widgets->profile_width = 600;
2781 if ( a_settings_get_integer ( VIK_SETTINGS_TRACK_PROFILE_WIDTH, &profile_size_value ) )
2782 if ( profile_size_value > widgets->profile_width )
2783 widgets->profile_width = profile_size_value;
2784
2785 widgets->profile_height = 300;
2786 if ( a_settings_get_integer ( VIK_SETTINGS_TRACK_PROFILE_HEIGHT, &profile_size_value ) )
2787 if ( profile_size_value > widgets->profile_height )
2788 widgets->profile_height = profile_size_value;
2789
2790 gchar *title = g_strdup_printf(_("%s - Track Properties"), tr->name);
2791 GtkWidget *dialog = gtk_dialog_new_with_buttons (title,
2792 parent,
2793 GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
2794 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
2795 _("Split at _Marker"), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER,
2796 _("Split _Segments"), VIK_TRW_LAYER_PROPWIN_SPLIT,
2797 _("_Reverse"), VIK_TRW_LAYER_PROPWIN_REVERSE,
2798 _("_Delete Dupl."), VIK_TRW_LAYER_PROPWIN_DEL_DUP,
2799 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2800 NULL);
2801 widgets->dialog = dialog;
2802 g_signal_connect( G_OBJECT(dialog), "response", G_CALLBACK(propwin_response_cb), widgets);
2803
2804 g_free(title);
2805 GtkTable *table;
2806 gdouble tr_len;
2807 gulong tp_count;
2808 guint seg_count;
2809
2810 gdouble min_alt, max_alt;
2811 widgets->elev_box = vik_trw_layer_create_profile(GTK_WIDGET(parent), widgets, &min_alt, &max_alt);
2812 widgets->gradient_box = vik_trw_layer_create_gradient(GTK_WIDGET(parent), widgets);
2813 widgets->speed_box = vik_trw_layer_create_vtdiag(GTK_WIDGET(parent), widgets);
2814 widgets->dist_box = vik_trw_layer_create_dtdiag(GTK_WIDGET(parent), widgets);
2815 widgets->elev_time_box = vik_trw_layer_create_etdiag(GTK_WIDGET(parent), widgets);
2816 widgets->speed_dist_box = vik_trw_layer_create_sddiag(GTK_WIDGET(parent), widgets);
2817 GtkWidget *graphs = gtk_notebook_new();
2818
2819 GtkWidget *content[20];
2820 int cnt;
2821 int i;
2822
2823 static gchar *label_texts[] = {
2824 N_("<b>Comment:</b>"),
2825 N_("<b>Description:</b>"),
2826 N_("<b>Track Length:</b>"),
2827 N_("<b>Trackpoints:</b>"),
2828 N_("<b>Segments:</b>"),
2829 N_("<b>Duplicate Points:</b>"),
2830 N_("<b>Max Speed:</b>"),
2831 N_("<b>Avg. Speed:</b>"),
2832 N_("<b>Moving Avg. Speed:</b>"),
2833 N_("<b>Avg. Dist. Between TPs:</b>"),
2834 N_("<b>Elevation Range:</b>"),
2835 N_("<b>Total Elevation Gain/Loss:</b>"),
2836 N_("<b>Start:</b>"),
2837 N_("<b>End:</b>"),
2838 N_("<b>Duration:</b>"),
2839 N_("<b>Color:</b>") };
2840 static gchar tmp_buf[50];
2841 gdouble tmp_speed;
2842
2843 cnt = 0;
2844 widgets->w_comment = gtk_entry_new ();
2845 if ( tr->comment )
2846 gtk_entry_set_text ( GTK_ENTRY(widgets->w_comment), tr->comment );
2847 g_signal_connect_swapped ( widgets->w_comment, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
2848 content[cnt++] = widgets->w_comment;
2849
2850 widgets->w_description = gtk_entry_new ();
2851 if ( tr->description )
2852 gtk_entry_set_text ( GTK_ENTRY(widgets->w_description), tr->description );
2853 g_signal_connect_swapped ( widgets->w_description, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
2854 content[cnt++] = widgets->w_description;
2855
2856 vik_units_distance_t dist_units = a_vik_get_units_distance ();
2857
2858 // NB This value not shown yet - but is used by internal calculations
2859 widgets->track_length_inc_gaps = vik_track_get_length_including_gaps(tr);
2860
2861 tr_len = widgets->track_length = vik_track_get_length(tr);
2862 switch (dist_units) {
2863 case VIK_UNITS_DISTANCE_KILOMETRES:
2864 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", tr_len/1000.0 );
2865 break;
2866 case VIK_UNITS_DISTANCE_MILES:
2867 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(tr_len) );
2868 break;
2869 default:
2870 g_critical("Houston, we've had a problem. distance=%d", dist_units);
2871 }
2872 widgets->w_track_length = content[cnt++] = gtk_label_new ( tmp_buf );
2873
2874 tp_count = vik_track_get_tp_count(tr);
2875 g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", tp_count );
2876 widgets->w_tp_count = content[cnt++] = gtk_label_new ( tmp_buf );
2877
2878 seg_count = vik_track_get_segment_count(tr) ;
2879 g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", seg_count );
2880 widgets->w_segment_count = content[cnt++] = gtk_label_new ( tmp_buf );
2881
2882 g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", vik_track_get_dup_point_count(tr) );
2883 widgets->w_duptp_count = content[cnt++] = gtk_label_new ( tmp_buf );
2884
2885 vik_units_speed_t speed_units = a_vik_get_units_speed ();
2886 tmp_speed = vik_track_get_max_speed(tr);
2887 if ( tmp_speed == 0 )
2888 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2889 else {
2890 switch (speed_units) {
2891 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2892 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2893 break;
2894 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2895 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2896 break;
2897 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2898 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2899 break;
2900 case VIK_UNITS_SPEED_KNOTS:
2901 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2902 break;
2903 default:
2904 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2905 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2906 }
2907 }
2908 widgets->w_max_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2909
2910 tmp_speed = vik_track_get_average_speed(tr);
2911 if ( tmp_speed == 0 )
2912 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2913 else {
2914 switch (speed_units) {
2915 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2916 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2917 break;
2918 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2919 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2920 break;
2921 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2922 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2923 break;
2924 case VIK_UNITS_SPEED_KNOTS:
2925 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2926 break;
2927 default:
2928 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2929 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2930 }
2931 }
2932 widgets->w_avg_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2933
2934 // Use 60sec as the default period to be considered stopped
2935 // this is the TrackWaypoint draw stops default value 'vtl->stop_length'
2936 // however this variable is not directly accessible - and I don't expect it's often changed from the default
2937 // so ATM just put in the number
2938 tmp_speed = vik_track_get_average_speed_moving(tr, 60);
2939 if ( tmp_speed == 0 )
2940 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2941 else {
2942 switch (speed_units) {
2943 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2944 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2945 break;
2946 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2947 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2948 break;
2949 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2950 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2951 break;
2952 case VIK_UNITS_SPEED_KNOTS:
2953 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2954 break;
2955 default:
2956 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2957 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2958 }
2959 }
2960 widgets->w_mvg_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2961
2962 switch (dist_units) {
2963 case VIK_UNITS_DISTANCE_KILOMETRES:
2964 // Even though kilometres, the average distance between points is going to be quite small so keep in metres
2965 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m", (tp_count - seg_count) == 0 ? 0 : tr_len / ( tp_count - seg_count ) );
2966 break;
2967 case VIK_UNITS_DISTANCE_MILES:
2968 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.3f miles", (tp_count - seg_count) == 0 ? 0 : VIK_METERS_TO_MILES(tr_len / ( tp_count - seg_count )) );
2969 break;
2970 default:
2971 g_critical("Houston, we've had a problem. distance=%d", dist_units);
2972 }
2973 widgets->w_avg_dist = content[cnt++] = gtk_label_new ( tmp_buf );
2974
2975 vik_units_height_t height_units = a_vik_get_units_height ();
2976 if ( min_alt == VIK_DEFAULT_ALTITUDE )
2977 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2978 else {
2979 switch (height_units) {
2980 case VIK_UNITS_HEIGHT_METRES:
2981 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m - %.0f m", min_alt, max_alt );
2982 break;
2983 case VIK_UNITS_HEIGHT_FEET:
2984 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f feet - %.0f feet", VIK_METERS_TO_FEET(min_alt), VIK_METERS_TO_FEET(max_alt) );
2985 break;
2986 default:
2987 g_snprintf(tmp_buf, sizeof(tmp_buf), "--" );
2988 g_critical("Houston, we've had a problem. height=%d", height_units);
2989 }
2990 }
2991 widgets->w_elev_range = content[cnt++] = gtk_label_new ( tmp_buf );
2992
2993 vik_track_get_total_elevation_gain(tr, &max_alt, &min_alt );
2994 if ( min_alt == VIK_DEFAULT_ALTITUDE )
2995 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2996 else {
2997 switch (height_units) {
2998 case VIK_UNITS_HEIGHT_METRES:
2999 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m / %.0f m", max_alt, min_alt );
3000 break;
3001 case VIK_UNITS_HEIGHT_FEET:
3002 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f feet / %.0f feet", VIK_METERS_TO_FEET(max_alt), VIK_METERS_TO_FEET(min_alt) );
3003 break;
3004 default:
3005 g_snprintf(tmp_buf, sizeof(tmp_buf), "--" );
3006 g_critical("Houston, we've had a problem. height=%d", height_units);
3007 }
3008 }
3009 widgets->w_elev_gain = content[cnt++] = gtk_label_new ( tmp_buf );
3010
3011#if 0
3012#define PACK(w) gtk_box_pack_start (GTK_BOX(right_vbox), w, FALSE, FALSE, 0);
3013 gtk_box_pack_start (GTK_BOX(right_vbox), e_cmt, FALSE, FALSE, 0);
3014 PACK(l_len);
3015 PACK(l_tps);
3016 PACK(l_segs);
3017 PACK(l_dups);
3018 PACK(l_maxs);
3019 PACK(l_avgs);
3020 PACK(l_avgd);
3021 PACK(l_elev);
3022 PACK(l_galo);
3023#undef PACK;
3024#endif
3025
3026 if ( tr->trackpoints && VIK_TRACKPOINT(tr->trackpoints->data)->timestamp )
3027 {
3028 time_t t1, t2;
3029 t1 = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
3030 t2 = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp;
3031
3032 strftime (tmp_buf, sizeof(tmp_buf), "%c", localtime(&(t1)));
3033 widgets->w_time_start = content[cnt++] = gtk_label_new(tmp_buf);
3034
3035 strftime (tmp_buf, sizeof(tmp_buf), "%c", localtime(&(t2)));
3036 widgets->w_time_end = content[cnt++] = gtk_label_new(tmp_buf);
3037
3038 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%d minutes"), (int)(t2-t1)/60);
3039 widgets->w_time_dur = content[cnt++] = gtk_label_new(tmp_buf);
3040 } else {
3041 widgets->w_time_start = content[cnt++] = gtk_label_new(_("No Data"));
3042 widgets->w_time_end = content[cnt++] = gtk_label_new(_("No Data"));
3043 widgets->w_time_dur = content[cnt++] = gtk_label_new(_("No Data"));
3044 }
3045
3046 widgets->w_color = content[cnt++] = gtk_color_button_new_with_color ( &(tr->color) );
3047
3048 table = GTK_TABLE(gtk_table_new (cnt, 2, FALSE));
3049 gtk_table_set_col_spacing (table, 0, 10);
3050 for (i=0; i<cnt; i++) {
3051 GtkWidget *label;
3052
3053 // Settings so the text positioning only moves around vertically when the dialog is resized
3054 // This also gives more room to see the track comment
3055 label = gtk_label_new(NULL);
3056 gtk_misc_set_alignment ( GTK_MISC(label), 1, 0.5 ); // Position text centrally in vertical plane
3057 gtk_label_set_markup ( GTK_LABEL(label), _(label_texts[i]) );
3058 gtk_table_attach ( table, label, 0, 1, i, i+1, GTK_FILL, GTK_SHRINK, 0, 0 );
3059 if (GTK_IS_MISC(content[i])) {
3060 gtk_misc_set_alignment ( GTK_MISC(content[i]), 0, 0.5 );
3061 }
3062 gtk_table_attach_defaults ( table, content[i], 1, 2, i, i+1 );
3063 }
3064
3065 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), GTK_WIDGET(table), gtk_label_new(_("Statistics")));
3066
3067 if ( widgets->elev_box ) {
3068 GtkWidget *page = NULL;
3069 widgets->w_cur_dist = gtk_label_new(_("No Data"));
3070 widgets->w_cur_elevation = gtk_label_new(_("No Data"));
3071 widgets->w_show_dem = gtk_check_button_new_with_mnemonic(_("Show D_EM"));
3072 widgets->w_show_alt_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3073 page = create_graph_page (widgets->elev_box,
3074 _("<b>Track Distance:</b>"), widgets->w_cur_dist,
3075 _("<b>Track Height:</b>"), widgets->w_cur_elevation,
3076 widgets->w_show_dem, TRUE,
3077 widgets->w_show_alt_gps_speed, TRUE);
3078 g_signal_connect (widgets->w_show_dem, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3079 g_signal_connect (widgets->w_show_alt_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3080 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-distance")));
3081 }
3082
3083 if ( widgets->gradient_box ) {
3084 GtkWidget *page = NULL;
3085 widgets->w_cur_gradient_dist = gtk_label_new(_("No Data"));
3086 widgets->w_cur_gradient_gradient = gtk_label_new(_("No Data"));
3087 widgets->w_show_gradient_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3088 page = create_graph_page (widgets->gradient_box,
3089 _("<b>Track Distance:</b>"), widgets->w_cur_gradient_dist,
3090 _("<b>Track Gradient:</b>"), widgets->w_cur_gradient_gradient,
3091 widgets->w_show_gradient_gps_speed, TRUE,
3092 NULL, FALSE);
3093 g_signal_connect (widgets->w_show_gradient_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3094 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Gradient-distance")));
3095 }
3096
3097 if ( widgets->speed_box ) {
3098 GtkWidget *page = NULL;
3099 widgets->w_cur_time = gtk_label_new(_("No Data"));
3100 widgets->w_cur_speed = gtk_label_new(_("No Data"));
3101 widgets->w_show_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3102 page = create_graph_page (widgets->speed_box,
3103 _("<b>Track Time:</b>"), widgets->w_cur_time,
3104 _("<b>Track Speed:</b>"), widgets->w_cur_speed,
3105 widgets->w_show_gps_speed, TRUE,
3106 NULL, FALSE);
3107 g_signal_connect (widgets->w_show_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3108 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-time")));
3109 }
3110
3111 if ( widgets->dist_box ) {
3112 GtkWidget *page = NULL;
3113 widgets->w_cur_dist_time = gtk_label_new(_("No Data"));
3114 widgets->w_cur_dist_dist = gtk_label_new(_("No Data"));
3115 widgets->w_show_dist_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
3116 page = create_graph_page (widgets->dist_box,
3117 _("<b>Track Distance:</b>"), widgets->w_cur_dist_dist,
3118 _("<b>Track Time:</b>"), widgets->w_cur_dist_time,
3119 widgets->w_show_dist_speed, FALSE,
3120 NULL, FALSE);
3121 g_signal_connect (widgets->w_show_dist_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3122 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Distance-time")));
3123 }
3124
3125 if ( widgets->elev_time_box ) {
3126 GtkWidget *page = NULL;
3127 widgets->w_cur_elev_time = gtk_label_new(_("No Data"));
3128 widgets->w_cur_elev_elev = gtk_label_new(_("No Data"));
3129 widgets->w_show_elev_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
3130 page = create_graph_page (widgets->elev_time_box,
3131 _("<b>Track Time:</b>"), widgets->w_cur_elev_time,
3132 _("<b>Track Height:</b>"), widgets->w_cur_elev_elev,
3133 widgets->w_show_elev_speed, FALSE,
3134 NULL, FALSE);
3135 g_signal_connect (widgets->w_show_elev_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3136 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-time")));
3137 }
3138
3139 if ( widgets->speed_dist_box ) {
3140 GtkWidget *page = NULL;
3141 widgets->w_cur_speed_dist = gtk_label_new(_("No Data"));
3142 widgets->w_cur_speed_speed = gtk_label_new(_("No Data"));
3143 widgets->w_show_sd_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3144 page = create_graph_page (widgets->speed_dist_box,
3145 _("<b>Track Distance:</b>"), widgets->w_cur_speed_dist,
3146 _("<b>Track Speed:</b>"), widgets->w_cur_speed_speed,
3147 widgets->w_show_sd_gps_speed, TRUE,
3148 NULL, FALSE);
3149 g_signal_connect (widgets->w_show_sd_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3150 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-distance")));
3151 }
3152
3153 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), graphs, FALSE, FALSE, 0);
3154
3155 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
3156 if (seg_count <= 1)
3157 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT, FALSE);
3158 if (vik_track_get_dup_point_count(tr) <= 0)
3159 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_DEL_DUP, FALSE);
3160
3161 // On dialog realization configure_event causes the graphs to be initially drawn
3162 widgets->configure_dialog = TRUE;
3163 g_signal_connect ( G_OBJECT(dialog), "configure-event", G_CALLBACK (configure_event), widgets );
3164
3165 g_signal_connect ( G_OBJECT(dialog), "destroy", G_CALLBACK (destroy_cb), widgets );
3166
3167 vik_track_set_property_dialog(tr, dialog);
3168 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
3169 gtk_widget_show_all ( dialog );
3170}
3171
3172
3173/**
3174 * Update this property dialog
3175 * e.g. if the track has been renamed
3176 */
3177void vik_trw_layer_propwin_update ( VikTrack *trk )
3178{
3179 // If not displayed do nothing
3180 if ( !trk->property_dialog )
3181 return;
3182
3183 // Update title with current name
3184 if ( trk->name ) {
3185 gchar *title = g_strdup_printf ( _("%s - Track Properties"), trk->name );
3186 gtk_window_set_title ( GTK_WINDOW(trk->property_dialog), title );
3187 g_free(title);
3188 }
3189
3190}