2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
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>
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.
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.
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
34 #include <glib/gi18n.h>
39 #include "viktrwlayer.h"
40 #include "viktrwlayer_propwin.h"
43 #include "vikviewport.h" /* ugh */
44 #include <gdk-pixbuf/gdk-pixdata.h>
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;
56 /* (Hopefully!) Human friendly altitude grid sizes - note no fixed 'ratio' just numbers that look nice...*/
57 static 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};
62 /* (Hopefully!) Human friendly gradient grid sizes - note no fixed 'ratio' just numbers that look nice...*/
63 static 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, 100000.0};
67 // Normally gradients should range up to couple hundred precent at most,
68 // however there are possibilities of having points with no altitude after a point with a big altitude
69 // (such as places with invalid DEM values in otherwise mountainous regions) - thus giving huge negative gradients.
71 /* (Hopefully!) Human friendly grid sizes - note no fixed 'ratio' just numbers that look nice...*/
72 /* As need to cover walking speeds - have many low numbers (but also may go up to airplane speeds!) */
73 static const gdouble chunkss[] = {1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
74 15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
75 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
76 750.0, 1000.0, 10000.0};
78 /* (Hopefully!) Human friendly distance grid sizes - note no fixed 'ratio' just numbers that look nice...*/
79 static const gdouble chunksd[] = {0.1, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
80 15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
81 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
82 750.0, 1000.0, 10000.0};
84 typedef struct _propsaved {
89 typedef struct _propwidgets {
90 gboolean configure_dialog;
98 gint profile_width_old;
99 gint profile_height_old;
100 gint profile_width_offset;
101 gint profile_height_offset;
103 GtkWidget *w_comment;
104 GtkWidget *w_description;
105 GtkWidget *w_track_length;
106 GtkWidget *w_tp_count;
107 GtkWidget *w_segment_count;
108 GtkWidget *w_duptp_count;
109 GtkWidget *w_max_speed;
110 GtkWidget *w_avg_speed;
111 GtkWidget *w_mvg_speed;
112 GtkWidget *w_avg_dist;
113 GtkWidget *w_elev_range;
114 GtkWidget *w_elev_gain;
115 GtkWidget *w_time_start;
116 GtkWidget *w_time_end;
117 GtkWidget *w_time_dur;
119 GtkWidget *w_namelabel;
120 GtkWidget *w_number_distlabels;
121 GtkWidget *w_cur_dist; /*< Current distance */
122 GtkWidget *w_cur_elevation;
123 GtkWidget *w_cur_gradient_dist; /*< Current distance on gradient graph */
124 GtkWidget *w_cur_gradient_gradient; /*< Current gradient on gradient graph */
125 GtkWidget *w_cur_time; /*< Current time */
126 GtkWidget *w_cur_speed;
127 GtkWidget *w_cur_dist_dist; /*< Current distance on distance graph */
128 GtkWidget *w_cur_dist_time; /*< Current time on distance graph */
129 GtkWidget *w_cur_elev_elev;
130 GtkWidget *w_cur_elev_time;
131 GtkWidget *w_cur_speed_dist;
132 GtkWidget *w_cur_speed_speed;
133 GtkWidget *w_show_dem;
134 GtkWidget *w_show_alt_gps_speed;
135 GtkWidget *w_show_gps_speed;
136 GtkWidget *w_show_gradient_gps_speed;
137 GtkWidget *w_show_dist_speed;
138 GtkWidget *w_show_elev_speed;
139 GtkWidget *w_show_sd_gps_speed;
140 gdouble track_length;
141 gdouble track_length_inc_gaps;
142 PropSaved elev_graph_saved_img;
143 PropSaved gradient_graph_saved_img;
144 PropSaved speed_graph_saved_img;
145 PropSaved dist_graph_saved_img;
146 PropSaved elev_time_graph_saved_img;
147 PropSaved speed_dist_graph_saved_img;
149 GtkWidget *gradient_box;
150 GtkWidget *speed_box;
152 GtkWidget *elev_time_box;
153 GtkWidget *speed_dist_box;
155 gdouble *ats; // altitudes in time
156 gdouble min_altitude;
157 gdouble max_altitude;
158 gdouble draw_min_altitude;
159 gdouble draw_min_altitude_time;
160 gint cia; // Chunk size Index into Altitudes
161 gint ciat; // Chunk size Index into Altitudes / Time
162 // NB cia & ciat are normally same value but sometimes not due to differing methods of altitude array creation
163 // thus also have draw_min_altitude for each altitude graph type
165 gdouble min_gradient;
166 gdouble max_gradient;
167 gdouble draw_min_gradient;
168 gint cig; // Chunk size Index into Gradients
170 gdouble *speeds_dist;
173 gdouble draw_min_speed;
174 gdouble max_speed_dist;
175 gint cis; // Chunk size Index into Speeds
176 gint cisd; // Chunk size Index into Speed/Distance
178 gint cid; // Chunk size Index into Distance
179 VikTrackpoint *marker_tp;
180 gboolean is_marker_drawn;
181 VikTrackpoint *blob_tp;
182 gboolean is_blob_drawn;
185 static PropWidgets *prop_widgets_new()
187 PropWidgets *widgets = g_malloc0(sizeof(PropWidgets));
192 static void prop_widgets_free(PropWidgets *widgets)
194 if (widgets->elev_graph_saved_img.img)
195 g_object_unref(widgets->elev_graph_saved_img.img);
196 if (widgets->gradient_graph_saved_img.img)
197 g_object_unref(widgets->gradient_graph_saved_img.img);
198 if (widgets->speed_graph_saved_img.img)
199 g_object_unref(widgets->speed_graph_saved_img.img);
200 if (widgets->dist_graph_saved_img.img)
201 g_object_unref(widgets->dist_graph_saved_img.img);
202 if (widgets->elev_time_graph_saved_img.img)
203 g_object_unref(widgets->elev_time_graph_saved_img.img);
204 if (widgets->speed_dist_graph_saved_img.img)
205 g_object_unref(widgets->speed_dist_graph_saved_img.img);
206 if (widgets->altitudes)
207 g_free(widgets->altitudes);
208 if (widgets->gradients)
209 g_free(widgets->gradients);
211 g_free(widgets->speeds);
212 if (widgets->distances)
213 g_free(widgets->distances);
215 g_free(widgets->ats);
216 if (widgets->speeds_dist)
217 g_free(widgets->speeds_dist);
221 static void minmax_array(const gdouble *array, gdouble *min, gdouble *max, gboolean NO_ALT_TEST, gint PROFILE_WIDTH)
226 for ( i=0; i < PROFILE_WIDTH; i++ ) {
227 if ( NO_ALT_TEST || (array[i] != VIK_DEFAULT_ALTITUDE) ) {
228 if ( array[i] > *max )
230 if ( array[i] < *min )
239 * get_new_min_and_chunk_index:
240 * Returns via pointers:
241 * the new minimum value to be used for the graph
242 * the index in to the chunk sizes array (ci = Chunk Index)
244 static void get_new_min_and_chunk_index (gdouble mina, gdouble maxa, const gdouble *chunks, size_t chunky, gdouble *new_min, gint *ci)
246 /* Get unitized chunk */
247 /* Find suitable chunk index */
249 gdouble diff_chunk = (maxa - mina)/LINES;
251 /* Loop through to find best match */
252 while (diff_chunk > chunks[*ci]) {
254 /* Last Resort Check */
255 if ( *ci == chunky ) {
256 // Use previous value and exit loop
262 /* Ensure adjusted minimum .. maximum covers mina->maxa */
264 // Now work out adjusted minimum point to the nearest lowest chunk divisor value
265 // When negative ensure logic uses lowest value
267 *new_min = (gdouble) ( (gint)((mina - chunks[*ci]) / chunks[*ci]) * chunks[*ci] );
269 *new_min = (gdouble) ( (gint)(mina / chunks[*ci]) * chunks[*ci] );
271 // Range not big enough - as new minimum has lowered
272 if ((*new_min + (chunks[*ci] * LINES) < maxa)) {
273 // Next chunk should cover it
274 if ( *ci < chunky-1 ) {
276 // Remember to adjust the minimum too...
278 *new_min = (gdouble) ( (gint)((mina - chunks[*ci]) / chunks[*ci]) * chunks[*ci] );
280 *new_min = (gdouble) ( (gint)(mina / chunks[*ci]) * chunks[*ci] );
285 static VikTrackpoint *set_center_at_graph_position(gdouble event_x,
294 VikTrackpoint *trackpoint;
295 gdouble x = event_x - img_width / 2 + PROFILE_WIDTH / 2 - MARGIN / 2;
298 if (x > PROFILE_WIDTH)
302 trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / PROFILE_WIDTH, NULL );
304 trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / PROFILE_WIDTH, NULL );
307 VikCoord coord = trackpoint->coord;
309 vik_viewport_set_center_coord ( vik_layers_panel_get_viewport(vlp), &coord );
310 vik_layers_panel_emit_update ( vlp );
313 /* since vlp not set, vvp should be valid instead! */
315 vik_viewport_set_center_coord ( vvp, &coord );
316 vik_layer_emit_update ( VIK_LAYER(vtl) );
323 * Returns whether the marker was drawn or not and whether the blob was drawn or not
325 static void save_image_and_draw_graph_marks (GtkWidget *image,
330 PropSaved *saved_img,
333 gboolean *marker_drawn,
334 gboolean *blob_drawn)
336 GdkPixmap *pix = NULL;
337 /* the pixmap = margin + graph area */
338 gtk_image_get_pixmap(GTK_IMAGE(image), &pix, NULL);
340 /* Restore previously saved image */
341 if (saved_img->saved) {
342 gdk_draw_image(GDK_DRAWABLE(pix), gc, saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
343 saved_img->saved = FALSE;
346 // ATM always save whole image - as anywhere could have changed
348 gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
350 saved_img->img = gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
351 saved_img->saved = TRUE;
353 if ((marker_x >= MARGIN) && (marker_x < (PROFILE_WIDTH + MARGIN))) {
354 gdk_draw_line (GDK_DRAWABLE(pix), gc, marker_x, 0, marker_x, image->allocation.height);
355 *marker_drawn = TRUE;
358 *marker_drawn = FALSE;
360 // Draw a square blob to indicate where we are on track for this graph
361 if ( (blob_x >= MARGIN) && (blob_x < (PROFILE_WIDTH + MARGIN)) && (blob_y < PROFILE_HEIGHT) ) {
362 gdk_draw_rectangle (GDK_DRAWABLE(pix), gc, TRUE, blob_x-3, blob_y-3, 6, 6);
368 // Anywhere on image could have changed
369 if (*marker_drawn || *blob_drawn)
370 gtk_widget_queue_draw(image);
374 * Return the percentage of how far a trackpoint is a long a track via the time method
376 static gdouble tp_percentage_by_time ( VikTrack *tr, VikTrackpoint *trackpoint )
379 if (trackpoint == NULL)
381 time_t t_start, t_end, t_total;
382 t_start = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
383 t_end = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp;
384 t_total = t_end - t_start;
385 pc = (gdouble)(trackpoint->timestamp - t_start)/t_total;
390 * Return the percentage of how far a trackpoint is a long a track via the distance method
392 static gdouble tp_percentage_by_distance ( VikTrack *tr, VikTrackpoint *trackpoint, gdouble track_length )
395 if (trackpoint == NULL)
399 for (iter = tr->trackpoints->next; iter != NULL; iter = iter->next) {
400 dist += vik_coord_diff(&(VIK_TRACKPOINT(iter->data)->coord),
401 &(VIK_TRACKPOINT(iter->prev->data)->coord));
402 /* Assuming trackpoint is not a copy */
403 if (trackpoint == VIK_TRACKPOINT(iter->data))
407 pc = dist/track_length;
411 static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, PropWidgets *widgets, VikPropWinGraphType_t graph_type )
413 gboolean is_time_graph =
414 ( graph_type == PROPWIN_GRAPH_TYPE_SPEED_TIME ||
415 graph_type == PROPWIN_GRAPH_TYPE_DISTANCE_TIME ||
416 graph_type == PROPWIN_GRAPH_TYPE_ELEVATION_TIME );
418 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);
419 // Unable to get the point so give up
420 if ( trackpoint == NULL ) {
421 gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
425 widgets->marker_tp = trackpoint;
429 GtkWidget *window = gtk_widget_get_toplevel(GTK_WIDGET(event_box));
430 GtkWidget *graph_box;
431 PropSaved *graph_saved_img;
434 // Attempt to redraw marker on all graph types
436 for ( graphite = PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE;
437 graphite < PROPWIN_GRAPH_TYPE_END;
440 // Switch commonal variables to particular graph type
443 case PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE:
444 graph_box = widgets->elev_box;
445 graph_saved_img = &widgets->elev_graph_saved_img;
446 is_time_graph = FALSE;
448 case PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE:
449 graph_box = widgets->gradient_box;
450 graph_saved_img = &widgets->gradient_graph_saved_img;
451 is_time_graph = FALSE;
453 case PROPWIN_GRAPH_TYPE_SPEED_TIME:
454 graph_box = widgets->speed_box;
455 graph_saved_img = &widgets->speed_graph_saved_img;
456 is_time_graph = TRUE;
458 case PROPWIN_GRAPH_TYPE_DISTANCE_TIME:
459 graph_box = widgets->dist_box;
460 graph_saved_img = &widgets->dist_graph_saved_img;
461 is_time_graph = TRUE;
463 case PROPWIN_GRAPH_TYPE_ELEVATION_TIME:
464 graph_box = widgets->elev_time_box;
465 graph_saved_img = &widgets->elev_time_graph_saved_img;
466 is_time_graph = TRUE;
468 case PROPWIN_GRAPH_TYPE_SPEED_DISTANCE:
469 graph_box = widgets->speed_dist_box;
470 graph_saved_img = &widgets->speed_dist_graph_saved_img;
471 is_time_graph = FALSE;
475 // Commonal method of redrawing marker
478 child = gtk_container_get_children(GTK_CONTAINER(graph_box));
479 image = GTK_WIDGET(child->data);
482 pc = tp_percentage_by_time ( widgets->tr, trackpoint );
484 pc = tp_percentage_by_distance ( widgets->tr, trackpoint, widgets->track_length_inc_gaps );
487 gdouble marker_x = (pc * widgets->profile_width) + MARGIN;
488 save_image_and_draw_graph_marks(image,
490 gtk_widget_get_style(window)->black_gc,
491 -1, // Don't draw blob on clicks
494 widgets->profile_width,
495 widgets->profile_height,
496 &widgets->is_marker_drawn,
497 &widgets->is_blob_drawn);
503 gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, widgets->is_marker_drawn);
506 static gboolean track_profile_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
508 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE);
509 return TRUE; /* don't call other (further) callbacks */
512 static gboolean track_gradient_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
514 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE);
515 return TRUE; /* don't call other (further) callbacks */
518 static gboolean track_vt_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
520 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_SPEED_TIME);
521 return TRUE; /* don't call other (further) callbacks */
524 static gboolean track_dt_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
526 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_DISTANCE_TIME);
527 return TRUE; /* don't call other (further) callbacks */
530 static gboolean track_et_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
532 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_ELEVATION_TIME);
533 return TRUE; /* don't call other (further) callbacks */
536 static gboolean track_sd_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
538 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_SPEED_DISTANCE);
539 return TRUE; /* don't call other (further) callbacks */
543 * Calculate y position for blob on elevation graph
545 static gint blobby_altitude ( gdouble x_blob, PropWidgets *widgets )
547 gint ix = (gint)x_blob;
548 // Ensure ix is inbounds
549 if (ix == widgets->profile_width)
552 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->altitudes[ix]-widgets->draw_min_altitude)/(chunksa[widgets->cia]*LINES);
558 * Calculate y position for blob on gradient graph
560 static gint blobby_gradient ( gdouble x_blob, PropWidgets *widgets )
562 gint ix = (gint)x_blob;
563 // Ensure ix is inbounds
564 if (ix == widgets->profile_width)
567 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->gradients[ix]-widgets->draw_min_gradient)/(chunksg[widgets->cig]*LINES);
573 * Calculate y position for blob on speed graph
575 static gint blobby_speed ( gdouble x_blob, PropWidgets *widgets )
577 gint ix = (gint)x_blob;
578 // Ensure ix is inbounds
579 if (ix == widgets->profile_width)
582 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->speeds[ix]-widgets->draw_min_speed)/(chunkss[widgets->cis]*LINES);
588 * Calculate y position for blob on distance graph
590 static gint blobby_distance ( gdouble x_blob, PropWidgets *widgets )
592 gint ix = (gint)x_blob;
593 // Ensure ix is inbounds
594 if (ix == widgets->profile_width)
597 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->distances[ix])/(chunksd[widgets->cid]*LINES);
598 //NB min distance is always 0, so no need to subtract that from this ______/
604 * Calculate y position for blob on elevation/time graph
606 static gint blobby_altitude_time ( gdouble x_blob, PropWidgets *widgets )
608 gint ix = (gint)x_blob;
609 // Ensure ix is inbounds
610 if (ix == widgets->profile_width)
613 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->ats[ix]-widgets->draw_min_altitude_time)/(chunksa[widgets->ciat]*LINES);
618 * Calculate y position for blob on speed/dist graph
620 static gint blobby_speed_dist ( gdouble x_blob, PropWidgets *widgets )
622 gint ix = (gint)x_blob;
623 // Ensure ix is inbounds
624 if (ix == widgets->profile_width)
627 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->speeds_dist[ix]-widgets->draw_min_speed)/(chunkss[widgets->cisd]*LINES);
633 void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
635 int mouse_x, mouse_y;
636 GdkModifierType state;
639 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
643 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
646 if (x > widgets->profile_width)
647 x = widgets->profile_width;
649 gdouble meters_from_start;
650 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
651 if (trackpoint && widgets->w_cur_dist) {
652 static gchar tmp_buf[20];
653 vik_units_distance_t dist_units = a_vik_get_units_distance ();
654 switch (dist_units) {
655 case VIK_UNITS_DISTANCE_KILOMETRES:
656 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
658 case VIK_UNITS_DISTANCE_MILES:
659 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
662 g_critical("Houston, we've had a problem. distance=%d", dist_units);
664 gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist), tmp_buf);
667 // Show track elevation for this position - to the nearest whole number
668 if (trackpoint && widgets->w_cur_elevation) {
669 static gchar tmp_buf[20];
670 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
671 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d ft", (int)VIK_METERS_TO_FEET(trackpoint->altitude));
673 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d m", (int)trackpoint->altitude);
674 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elevation), tmp_buf);
677 widgets->blob_tp = trackpoint;
679 if ( widgets->altitudes == NULL )
682 GtkWidget *window = gtk_widget_get_toplevel (event_box);
683 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
684 GtkWidget *image = GTK_WIDGET(child->data);
686 gint y_blob = blobby_altitude (x, widgets);
688 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
689 if (widgets->is_marker_drawn) {
690 gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
692 marker_x = (pc * widgets->profile_width) + MARGIN;
696 save_image_and_draw_graph_marks (image,
698 gtk_widget_get_style(window)->black_gc,
701 &widgets->elev_graph_saved_img,
702 widgets->profile_width,
703 widgets->profile_height,
704 &widgets->is_marker_drawn,
705 &widgets->is_blob_drawn);
710 void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
712 int mouse_x, mouse_y;
713 GdkModifierType state;
716 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
720 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
723 if (x > widgets->profile_width)
724 x = widgets->profile_width;
726 gdouble meters_from_start;
727 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
728 if (trackpoint && widgets->w_cur_gradient_dist) {
729 static gchar tmp_buf[20];
730 vik_units_distance_t dist_units = a_vik_get_units_distance ();
731 switch (dist_units) {
732 case VIK_UNITS_DISTANCE_KILOMETRES:
733 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
735 case VIK_UNITS_DISTANCE_MILES:
736 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
739 g_critical("Houston, we've had a problem. distance=%d", dist_units);
741 gtk_label_set_text(GTK_LABEL(widgets->w_cur_gradient_dist), tmp_buf);
744 // Show track gradient for this position - to the nearest whole number
745 if (trackpoint && widgets->w_cur_gradient_gradient) {
746 static gchar tmp_buf[20];
748 double gradient = widgets->gradients[(int) x];
750 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d%%", (int)gradient);
751 gtk_label_set_text(GTK_LABEL(widgets->w_cur_gradient_gradient), tmp_buf);
754 widgets->blob_tp = trackpoint;
756 if ( widgets->gradients == NULL )
759 GtkWidget *window = gtk_widget_get_toplevel (event_box);
760 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
761 GtkWidget *image = GTK_WIDGET(child->data);
763 gint y_blob = blobby_gradient (x, widgets);
765 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
766 if (widgets->is_marker_drawn) {
767 gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
769 marker_x = (pc * widgets->profile_width) + MARGIN;
773 save_image_and_draw_graph_marks (image,
775 gtk_widget_get_style(window)->black_gc,
778 &widgets->gradient_graph_saved_img,
779 widgets->profile_width,
780 widgets->profile_height,
781 &widgets->is_marker_drawn,
782 &widgets->is_blob_drawn);
787 void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
789 int mouse_x, mouse_y;
790 GdkModifierType state;
793 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
797 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
800 if (x > widgets->profile_width)
801 x = widgets->profile_width;
803 time_t seconds_from_start;
804 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
805 if (trackpoint && widgets->w_cur_time) {
806 static gchar tmp_buf[20];
808 h = seconds_from_start/3600;
809 m = (seconds_from_start - h*3600)/60;
810 s = seconds_from_start - (3600*h) - (60*m);
811 g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
813 gtk_label_set_text(GTK_LABEL(widgets->w_cur_time), tmp_buf);
817 // Ensure ix is inbounds
818 if (ix == widgets->profile_width)
821 // Show track speed for this position
822 if (trackpoint && widgets->w_cur_speed) {
823 static gchar tmp_buf[20];
824 // Even if GPS speed available (trackpoint->speed), the text will correspond to the speed map shown
825 // No conversions needed as already in appropriate units
826 vik_units_speed_t speed_units = a_vik_get_units_speed ();
827 switch (speed_units) {
828 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
829 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f kph"), widgets->speeds[ix]);
831 case VIK_UNITS_SPEED_MILES_PER_HOUR:
832 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f mph"), widgets->speeds[ix]);
834 case VIK_UNITS_SPEED_KNOTS:
835 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f knots"), widgets->speeds[ix]);
838 // VIK_UNITS_SPEED_METRES_PER_SECOND:
839 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f m/s"), widgets->speeds[ix]);
842 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed), tmp_buf);
845 widgets->blob_tp = trackpoint;
847 if ( widgets->speeds == NULL )
850 GtkWidget *window = gtk_widget_get_toplevel (event_box);
851 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
852 GtkWidget *image = GTK_WIDGET(child->data);
854 gint y_blob = blobby_speed (x, widgets);
856 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
857 if (widgets->is_marker_drawn) {
858 gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
860 marker_x = (pc * widgets->profile_width) + MARGIN;
864 save_image_and_draw_graph_marks (image,
866 gtk_widget_get_style(window)->black_gc,
869 &widgets->speed_graph_saved_img,
870 widgets->profile_width,
871 widgets->profile_height,
872 &widgets->is_marker_drawn,
873 &widgets->is_blob_drawn);
879 * Update labels and blob marker on mouse moves in the distance/time graph
881 void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
883 int mouse_x, mouse_y;
884 GdkModifierType state;
887 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
891 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
894 if (x > widgets->profile_width)
895 x = widgets->profile_width;
897 time_t seconds_from_start;
898 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
899 if (trackpoint && widgets->w_cur_dist_time) {
900 static gchar tmp_buf[20];
902 h = seconds_from_start/3600;
903 m = (seconds_from_start - h*3600)/60;
904 s = seconds_from_start - (3600*h) - (60*m);
905 g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
907 gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_time), tmp_buf);
911 // Ensure ix is inbounds
912 if (ix == widgets->profile_width)
915 if (trackpoint && widgets->w_cur_dist_dist) {
916 static gchar tmp_buf[20];
917 if ( a_vik_get_units_distance () == VIK_UNITS_DISTANCE_MILES )
918 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", widgets->distances[ix]);
920 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", widgets->distances[ix]);
921 gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_dist), tmp_buf);
924 widgets->blob_tp = trackpoint;
926 if ( widgets->distances == NULL )
929 GtkWidget *window = gtk_widget_get_toplevel (event_box);
930 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
931 GtkWidget *image = GTK_WIDGET(child->data);
933 gint y_blob = blobby_distance (x, widgets);
935 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
936 if (widgets->is_marker_drawn) {
937 gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
939 marker_x = (pc * widgets->profile_width) + MARGIN;
943 save_image_and_draw_graph_marks (image,
945 gtk_widget_get_style(window)->black_gc,
948 &widgets->dist_graph_saved_img,
949 widgets->profile_width,
950 widgets->profile_height,
951 &widgets->is_marker_drawn,
952 &widgets->is_blob_drawn);
958 * Update labels and blob marker on mouse moves in the elevation/time graph
960 void track_et_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
962 int mouse_x, mouse_y;
963 GdkModifierType state;
966 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
970 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
973 if (x > widgets->profile_width)
974 x = widgets->profile_width;
976 time_t seconds_from_start;
977 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
978 if (trackpoint && widgets->w_cur_elev_time) {
979 static gchar tmp_buf[20];
981 h = seconds_from_start/3600;
982 m = (seconds_from_start - h*3600)/60;
983 s = seconds_from_start - (3600*h) - (60*m);
984 g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
986 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elev_time), tmp_buf);
990 // Ensure ix is inbounds
991 if (ix == widgets->profile_width)
994 if (trackpoint && widgets->w_cur_elev_elev) {
995 static gchar tmp_buf[20];
996 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
997 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d ft", (int)VIK_METERS_TO_FEET(trackpoint->altitude));
999 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d m", (int)trackpoint->altitude);
1000 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elev_elev), tmp_buf);
1003 widgets->blob_tp = trackpoint;
1005 if ( widgets->ats == NULL )
1008 GtkWidget *window = gtk_widget_get_toplevel (event_box);
1009 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
1010 GtkWidget *image = GTK_WIDGET(child->data);
1012 gint y_blob = blobby_altitude_time (x, widgets);
1014 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
1015 if (widgets->is_marker_drawn) {
1016 gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
1018 marker_x = (pc * widgets->profile_width) + MARGIN;
1022 save_image_and_draw_graph_marks (image,
1024 gtk_widget_get_style(window)->black_gc,
1027 &widgets->elev_time_graph_saved_img,
1028 widgets->profile_width,
1029 widgets->profile_height,
1030 &widgets->is_marker_drawn,
1031 &widgets->is_blob_drawn);
1036 void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
1038 int mouse_x, mouse_y;
1039 GdkModifierType state;
1042 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
1046 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
1049 if (x > widgets->profile_width)
1050 x = widgets->profile_width;
1052 gdouble meters_from_start;
1053 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
1054 if (trackpoint && widgets->w_cur_speed_dist) {
1055 static gchar tmp_buf[20];
1056 vik_units_distance_t dist_units = a_vik_get_units_distance ();
1057 switch (dist_units) {
1058 case VIK_UNITS_DISTANCE_KILOMETRES:
1059 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
1061 case VIK_UNITS_DISTANCE_MILES:
1062 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
1065 g_critical("Houston, we've had a problem. distance=%d", dist_units);
1067 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed_dist), tmp_buf);
1071 // Ensure ix is inbounds
1072 if (ix == widgets->profile_width)
1075 if ( widgets->speeds_dist == NULL )
1078 // Show track speed for this position
1079 if (widgets->w_cur_speed_speed) {
1080 static gchar tmp_buf[20];
1081 // Even if GPS speed available (trackpoint->speed), the text will correspond to the speed map shown
1082 // No conversions needed as already in appropriate units
1083 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1084 switch (speed_units) {
1085 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1086 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f kph"), widgets->speeds_dist[ix]);
1088 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1089 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f mph"), widgets->speeds_dist[ix]);
1091 case VIK_UNITS_SPEED_KNOTS:
1092 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f knots"), widgets->speeds_dist[ix]);
1095 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1096 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f m/s"), widgets->speeds_dist[ix]);
1099 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed_speed), tmp_buf);
1102 widgets->blob_tp = trackpoint;
1104 GtkWidget *window = gtk_widget_get_toplevel (event_box);
1105 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
1106 GtkWidget *image = GTK_WIDGET(child->data);
1108 gint y_blob = blobby_speed_dist (x, widgets);
1110 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
1111 if (widgets->is_marker_drawn) {
1112 gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
1114 marker_x = (pc * widgets->profile_width) + MARGIN;
1118 save_image_and_draw_graph_marks (image,
1120 gtk_widget_get_style(window)->black_gc,
1123 &widgets->speed_dist_graph_saved_img,
1124 widgets->profile_width,
1125 widgets->profile_height,
1126 &widgets->is_marker_drawn,
1127 &widgets->is_blob_drawn);
1133 * Draws DEM points and a respresentative speed on the supplied pixmap
1134 * (which is the elevations graph)
1136 static void draw_dem_alt_speed_dist(VikTrack *tr,
1142 gdouble max_speed_in,
1151 gdouble max_speed = 0;
1152 gdouble total_length = vik_track_get_length_including_gaps(tr);
1154 // Calculate the max speed factor
1156 max_speed = max_speed_in * 110 / 100;
1159 for (iter = tr->trackpoints->next; iter; iter = iter->next) {
1161 dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
1162 &(VIK_TRACKPOINT(iter->prev->data)->coord) );
1163 x = (width * dist)/total_length + margin;
1165 gint16 elev = a_dems_get_elev_by_coord(&(VIK_TRACKPOINT(iter->data)->coord), VIK_DEM_INTERPOL_BEST);
1167 if ( elev != VIK_DEM_INVALID_ELEVATION ) {
1168 // Convert into height units
1169 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
1170 elev = VIK_METERS_TO_FEET(elev);
1171 // No conversion needed if already in metres
1173 // consider chunk size
1174 int y_alt = height - ((height * elev)/(chunksa[cia]*LINES) );
1175 gdk_draw_rectangle(GDK_DRAWABLE(pix), alt_gc, TRUE, x-2, y_alt-2, 4, 4);
1179 // This is just a speed indicator - no actual values can be inferred by user
1180 if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
1181 int y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
1182 gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
1191 * A common way to draw the grid with y axis labels
1194 static void draw_grid ( GtkWidget *window, GtkWidget *image, PropWidgets *widgets, GdkPixmap *pix, gchar *ss, gint i )
1196 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1198 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1199 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1201 gchar *label_markup = g_strdup_printf ( "<span size=\"small\">%s</span>", ss );
1202 pango_layout_set_markup ( pl, label_markup, -1 );
1203 g_free ( label_markup );
1206 pango_layout_get_pixel_size ( pl, &w, &h );
1208 gdk_draw_layout ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1209 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl );
1211 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1212 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i );
1213 g_object_unref ( G_OBJECT ( pl ) );
1218 * Draw just the height profile image
1220 static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1230 // Free previous allocation
1231 if ( widgets->altitudes )
1232 g_free ( widgets->altitudes );
1234 widgets->altitudes = vik_track_make_elevation_map ( tr, widgets->profile_width );
1236 if ( widgets->altitudes == NULL )
1239 // Convert into appropriate units
1240 vik_units_height_t height_units = a_vik_get_units_height ();
1241 if ( height_units == VIK_UNITS_HEIGHT_FEET ) {
1242 // Convert altitudes into feet units
1243 for ( i = 0; i < widgets->profile_width; i++ ) {
1244 widgets->altitudes[i] = VIK_METERS_TO_FEET(widgets->altitudes[i]);
1247 // Otherwise leave in metres
1249 minmax_array(widgets->altitudes, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
1251 get_new_min_and_chunk_index (widgets->min_altitude, widgets->max_altitude, chunksa, G_N_ELEMENTS(chunksa), &widgets->draw_min_altitude, &widgets->cia);
1254 mina = widgets->draw_min_altitude;
1255 maxa = widgets->max_altitude;
1257 window = gtk_widget_get_toplevel (widgets->elev_box);
1259 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1261 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1263 no_alt_info = gdk_gc_new ( gtk_widget_get_window(window) );
1264 gdk_color_parse ( "yellow", &color );
1265 gdk_gc_set_rgb_fg_color ( no_alt_info, &color);
1267 /* clear the image */
1268 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1269 TRUE, 0, 0, MARGIN, widgets->profile_height);
1270 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1271 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1274 for (i=0; i<=LINES; i++) {
1277 switch (height_units) {
1278 case VIK_UNITS_HEIGHT_METRES:
1279 sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
1281 case VIK_UNITS_HEIGHT_FEET:
1282 // NB values already converted into feet
1283 sprintf(s, "%8dft", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
1287 g_critical("Houston, we've had a problem. height=%d", height_units);
1290 draw_grid ( window, image, widgets, pix, s, i );
1293 /* draw elevations */
1294 for ( i = 0; i < widgets->profile_width; i++ )
1295 if ( widgets->altitudes[i] == VIK_DEFAULT_ALTITUDE )
1296 gdk_draw_line ( GDK_DRAWABLE(pix), no_alt_info,
1297 i + MARGIN, 0, i + MARGIN, widgets->profile_height );
1299 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1300 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->altitudes[i]-mina)/(chunksa[widgets->cia]*LINES) );
1302 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)) ||
1303 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)) ) {
1305 GdkGC *dem_alt_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1306 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1308 gdk_color_parse ( "green", &color );
1309 gdk_gc_set_rgb_fg_color ( dem_alt_gc, &color);
1311 gdk_color_parse ( "red", &color );
1312 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1314 // Ensure somekind of max speed when not set
1315 if ( widgets->max_speed < 0.01 )
1316 widgets->max_speed = vik_track_get_max_speed(tr);
1318 draw_dem_alt_speed_dist(tr,
1326 widgets->profile_width,
1327 widgets->profile_height,
1329 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)),
1330 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
1332 g_object_unref ( G_OBJECT(dem_alt_gc) );
1333 g_object_unref ( G_OBJECT(gps_speed_gc) );
1337 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1339 g_object_unref ( G_OBJECT(pix) );
1340 g_object_unref ( G_OBJECT(no_alt_info) );
1344 * Draws representative speed on the supplied pixmap
1345 * (which is the gradients graph)
1347 static void draw_speed_dist(VikTrack *tr,
1350 gdouble max_speed_in,
1357 gdouble max_speed = 0;
1358 gdouble total_length = vik_track_get_length_including_gaps(tr);
1360 // Calculate the max speed factor
1362 max_speed = max_speed_in * 110 / 100;
1365 for (iter = tr->trackpoints->next; iter; iter = iter->next) {
1367 dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
1368 &(VIK_TRACKPOINT(iter->prev->data)->coord) );
1369 x = (width * dist)/total_length + margin;
1371 // This is just a speed indicator - no actual values can be inferred by user
1372 if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
1373 int y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
1374 gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
1381 * Draw just the gradient image
1383 static void draw_gradients (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1392 // Free previous allocation
1393 if ( widgets->gradients )
1394 g_free ( widgets->gradients );
1396 widgets->gradients = vik_track_make_gradient_map ( tr, widgets->profile_width );
1398 if ( widgets->gradients == NULL )
1401 minmax_array(widgets->gradients, &widgets->min_gradient, &widgets->max_gradient, TRUE, widgets->profile_width);
1403 get_new_min_and_chunk_index (widgets->min_gradient, widgets->max_gradient, chunksg, G_N_ELEMENTS(chunksg), &widgets->draw_min_gradient, &widgets->cig);
1406 mina = widgets->draw_min_gradient;
1408 window = gtk_widget_get_toplevel (widgets->gradient_box);
1410 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1412 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1414 /* clear the image */
1415 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1416 TRUE, 0, 0, MARGIN, widgets->profile_height);
1417 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1418 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1421 for (i=0; i<=LINES; i++) {
1424 sprintf(s, "%8d%%", (int)(mina + (LINES-i)*chunksg[widgets->cig]));
1426 draw_grid ( window, image, widgets, pix, s, i );
1429 /* draw gradients */
1430 for ( i = 0; i < widgets->profile_width; i++ )
1431 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1432 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->gradients[i]-mina)/(chunksg[widgets->cig]*LINES) );
1434 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_gradient_gps_speed)) ) {
1435 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1437 gdk_color_parse ( "red", &color );
1438 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1440 // Ensure somekind of max speed when not set
1441 if ( widgets->max_speed < 0.01 )
1442 widgets->max_speed = vik_track_get_max_speed(tr);
1448 widgets->profile_width,
1449 widgets->profile_height,
1451 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
1453 g_object_unref ( G_OBJECT(gps_speed_gc) );
1457 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1459 g_object_unref ( G_OBJECT(pix) );
1463 * Draw just the speed (velocity)/time image
1465 static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
1472 // Free previous allocation
1473 if ( widgets->speeds )
1474 g_free ( widgets->speeds );
1476 widgets->speeds = vik_track_make_speed_map ( tr, widgets->profile_width );
1477 if ( widgets->speeds == NULL )
1480 // Convert into appropriate units
1481 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1482 switch (speed_units) {
1483 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1484 for ( i = 0; i < widgets->profile_width; i++ ) {
1485 widgets->speeds[i] = VIK_MPS_TO_KPH(widgets->speeds[i]);
1488 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1489 for ( i = 0; i < widgets->profile_width; i++ ) {
1490 widgets->speeds[i] = VIK_MPS_TO_MPH(widgets->speeds[i]);
1493 case VIK_UNITS_SPEED_KNOTS:
1494 for ( i = 0; i < widgets->profile_width; i++ ) {
1495 widgets->speeds[i] = VIK_MPS_TO_KNOTS(widgets->speeds[i]);
1499 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1500 // No need to convert as already in m/s
1504 window = gtk_widget_get_toplevel (widgets->speed_box);
1506 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1508 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1510 minmax_array(widgets->speeds, &widgets->min_speed, &widgets->max_speed, FALSE, widgets->profile_width);
1511 if (widgets->min_speed < 0.0)
1512 widgets->min_speed = 0; /* splines sometimes give negative speeds */
1514 /* Find suitable chunk index */
1515 get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed, chunkss, G_N_ELEMENTS(chunkss), &widgets->draw_min_speed, &widgets->cis);
1518 mins = widgets->draw_min_speed;
1520 /* clear the image */
1521 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1522 TRUE, 0, 0, MARGIN, widgets->profile_height);
1523 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1524 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1527 for (i=0; i<=LINES; i++) {
1530 // NB: No need to convert here anymore as numbers are in the appropriate units
1531 switch (speed_units) {
1532 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1533 sprintf(s, "%8dkm/h", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1535 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1536 sprintf(s, "%8dmph", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1538 case VIK_UNITS_SPEED_METRES_PER_SECOND:
1539 sprintf(s, "%8dm/s", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1541 case VIK_UNITS_SPEED_KNOTS:
1542 sprintf(s, "%8dknots", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1546 g_critical("Houston, we've had a problem. speed=%d", speed_units);
1549 draw_grid ( window, image, widgets, pix, s, i );
1554 for ( i = 0; i < widgets->profile_width; i++ )
1555 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1556 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds[i]-mins)/(chunkss[widgets->cis]*LINES) );
1559 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_gps_speed)) ) {
1561 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1563 gdk_color_parse ( "red", &color );
1564 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1566 time_t beg_time = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
1567 time_t dur = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp - beg_time;
1570 for (iter = tr->trackpoints; iter; iter = iter->next) {
1571 gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed;
1572 if (isnan(gps_speed))
1574 switch (speed_units) {
1575 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1576 gps_speed = VIK_MPS_TO_KPH(gps_speed);
1578 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1579 gps_speed = VIK_MPS_TO_MPH(gps_speed);
1581 case VIK_UNITS_SPEED_KNOTS:
1582 gps_speed = VIK_MPS_TO_KNOTS(gps_speed);
1585 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1586 // No need to convert as already in m/s
1589 int x = MARGIN + widgets->profile_width * (VIK_TRACKPOINT(iter->data)->timestamp - beg_time) / dur;
1590 int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cis]*LINES);
1591 gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
1593 g_object_unref ( G_OBJECT(gps_speed_gc) );
1597 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1599 g_object_unref ( G_OBJECT(pix) );
1603 * Draw just the distance/time image
1605 static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1612 // Free previous allocation
1613 if ( widgets->distances )
1614 g_free ( widgets->distances );
1616 widgets->distances = vik_track_make_distance_map ( tr, widgets->profile_width );
1617 if ( widgets->distances == NULL )
1620 // Convert into appropriate units
1621 vik_units_distance_t dist_units = a_vik_get_units_distance ();
1622 if ( dist_units == VIK_UNITS_DISTANCE_MILES ) {
1623 for ( i = 0; i < widgets->profile_width; i++ ) {
1624 widgets->distances[i] = VIK_METERS_TO_MILES(widgets->distances[i]);
1628 // Metres - but want in kms
1629 for ( i = 0; i < widgets->profile_width; i++ ) {
1630 widgets->distances[i] = widgets->distances[i]/1000.0;
1634 window = gtk_widget_get_toplevel (widgets->dist_box);
1636 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1638 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1640 // easy to work out min / max of distance!
1642 // mind = 0.0; - Thus not used
1643 if ( dist_units == VIK_UNITS_DISTANCE_MILES )
1644 maxd = VIK_METERS_TO_MILES(vik_track_get_length_including_gaps (tr));
1646 maxd = vik_track_get_length_including_gaps (tr) / 1000.0;
1648 /* Find suitable chunk index */
1649 gdouble dummy = 0.0; // expect this to remain the same! (not that it's used)
1650 get_new_min_and_chunk_index (0, maxd, chunksd, G_N_ELEMENTS(chunksd), &dummy, &widgets->cid);
1652 /* clear the image */
1653 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1654 TRUE, 0, 0, MARGIN, widgets->profile_height);
1655 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1656 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1659 for (i=0; i<=LINES; i++) {
1662 if ( dist_units == VIK_UNITS_DISTANCE_MILES )
1663 sprintf(s, _("%.1f miles"), ((LINES-i)*chunksd[widgets->cid]));
1665 sprintf(s, _("%.1f km"), ((LINES-i)*chunksd[widgets->cid]));
1667 draw_grid ( window, image, widgets, pix, s, i );
1671 for ( i = 0; i < widgets->profile_width; i++ )
1672 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1673 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->distances[i])/(chunksd[widgets->cid]*LINES) );
1675 // Show speed indicator
1676 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_dist_speed)) ) {
1677 GdkGC *dist_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1679 gdk_color_parse ( "red", &color );
1680 gdk_gc_set_rgb_fg_color ( dist_speed_gc, &color);
1682 gdouble max_speed = 0;
1683 max_speed = widgets->max_speed * 110 / 100;
1685 // This is just an indicator - no actual values can be inferred by user
1687 for ( i = 0; i < widgets->profile_width; i++ ) {
1688 int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
1689 gdk_draw_rectangle(GDK_DRAWABLE(pix), dist_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
1691 g_object_unref ( G_OBJECT(dist_speed_gc) );
1695 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1697 g_object_unref ( G_OBJECT(pix) );
1702 * Draw just the elevation/time image
1704 static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1711 // Free previous allocation
1713 g_free ( widgets->ats );
1715 widgets->ats = vik_track_make_elevation_time_map ( tr, widgets->profile_width );
1717 if ( widgets->ats == NULL )
1720 // Convert into appropriate units
1721 vik_units_height_t height_units = a_vik_get_units_height ();
1722 if ( height_units == VIK_UNITS_HEIGHT_FEET ) {
1723 // Convert altitudes into feet units
1724 for ( i = 0; i < widgets->profile_width; i++ ) {
1725 widgets->ats[i] = VIK_METERS_TO_FEET(widgets->ats[i]);
1728 // Otherwise leave in metres
1730 minmax_array(widgets->ats, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
1732 get_new_min_and_chunk_index (widgets->min_altitude, widgets->max_altitude, chunksa, G_N_ELEMENTS(chunksa), &widgets->draw_min_altitude_time, &widgets->ciat);
1735 mina = widgets->draw_min_altitude_time;
1737 window = gtk_widget_get_toplevel (widgets->elev_time_box);
1739 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1741 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1743 /* clear the image */
1744 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1745 TRUE, 0, 0, MARGIN, widgets->profile_height);
1746 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1747 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1750 for (i=0; i<=LINES; i++) {
1753 switch (height_units) {
1754 case VIK_UNITS_HEIGHT_METRES:
1755 sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->ciat]));
1757 case VIK_UNITS_HEIGHT_FEET:
1758 // NB values already converted into feet
1759 sprintf(s, "%8dft", (int)(mina + (LINES-i)*chunksa[widgets->ciat]));
1763 g_critical("Houston, we've had a problem. height=%d", height_units);
1766 draw_grid ( window, image, widgets, pix, s, i );
1769 /* draw elevations */
1770 for ( i = 0; i < widgets->profile_width; i++ )
1771 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1772 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->ats[i]-mina)/(chunksa[widgets->ciat]*LINES) );
1774 // Show speed indicator
1775 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_elev_speed)) ) {
1776 GdkGC *elev_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1778 gdk_color_parse ( "red", &color );
1779 gdk_gc_set_rgb_fg_color ( elev_speed_gc, &color);
1781 gdouble max_speed = 0;
1782 max_speed = widgets->max_speed * 110 / 100;
1784 // This is just an indicator - no actual values can be inferred by user
1786 for ( i = 0; i < widgets->profile_width; i++ ) {
1787 int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
1788 gdk_draw_rectangle(GDK_DRAWABLE(pix), elev_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
1790 g_object_unref ( G_OBJECT(elev_speed_gc) );
1794 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1796 g_object_unref ( G_OBJECT(pix) );
1801 * Draw just the speed/distance image
1803 static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
1810 // Free previous allocation
1811 if ( widgets->speeds_dist )
1812 g_free ( widgets->speeds_dist );
1814 widgets->speeds_dist = vik_track_make_speed_dist_map ( tr, widgets->profile_width );
1815 if ( widgets->speeds_dist == NULL )
1818 // Convert into appropriate units
1819 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1820 switch (speed_units) {
1821 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1822 for ( i = 0; i < widgets->profile_width; i++ ) {
1823 widgets->speeds_dist[i] = VIK_MPS_TO_KPH(widgets->speeds_dist[i]);
1826 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1827 for ( i = 0; i < widgets->profile_width; i++ ) {
1828 widgets->speeds_dist[i] = VIK_MPS_TO_MPH(widgets->speeds_dist[i]);
1831 case VIK_UNITS_SPEED_KNOTS:
1832 for ( i = 0; i < widgets->profile_width; i++ ) {
1833 widgets->speeds_dist[i] = VIK_MPS_TO_KNOTS(widgets->speeds_dist[i]);
1837 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1838 // No need to convert as already in m/s
1842 window = gtk_widget_get_toplevel (widgets->speed_dist_box);
1844 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1846 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1848 // OK to resuse min_speed here
1849 minmax_array(widgets->speeds_dist, &widgets->min_speed, &widgets->max_speed_dist, FALSE, widgets->profile_width);
1850 if (widgets->min_speed < 0.0)
1851 widgets->min_speed = 0; /* splines sometimes give negative speeds */
1853 /* Find suitable chunk index */
1854 get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed_dist, chunkss, G_N_ELEMENTS(chunkss), &widgets->draw_min_speed, &widgets->cisd);
1857 mins = widgets->draw_min_speed;
1859 /* clear the image */
1860 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1861 TRUE, 0, 0, MARGIN, widgets->profile_height);
1862 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1863 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1866 for (i=0; i<=LINES; i++) {
1869 // NB: No need to convert here anymore as numbers are in the appropriate units
1870 switch (speed_units) {
1871 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1872 sprintf(s, "%8dkm/h", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1874 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1875 sprintf(s, "%8dmph", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1877 case VIK_UNITS_SPEED_METRES_PER_SECOND:
1878 sprintf(s, "%8dm/s", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1880 case VIK_UNITS_SPEED_KNOTS:
1881 sprintf(s, "%8dknots", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1885 g_critical("Houston, we've had a problem. speed=%d", speed_units);
1888 draw_grid ( window, image, widgets, pix, s, i );
1892 for ( i = 0; i < widgets->profile_width; i++ )
1893 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1894 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds_dist[i]-mins)/(chunkss[widgets->cisd]*LINES) );
1897 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_sd_gps_speed)) ) {
1899 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1901 gdk_color_parse ( "red", &color );
1902 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1904 gdouble dist = vik_track_get_length_including_gaps(tr);
1905 gdouble dist_tp = 0.0;
1907 GList *iter = tr->trackpoints;
1908 for (iter = iter->next; iter; iter = iter->next) {
1909 gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed;
1910 if (isnan(gps_speed))
1912 switch (speed_units) {
1913 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1914 gps_speed = VIK_MPS_TO_KPH(gps_speed);
1916 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1917 gps_speed = VIK_MPS_TO_MPH(gps_speed);
1919 case VIK_UNITS_SPEED_KNOTS:
1920 gps_speed = VIK_MPS_TO_KNOTS(gps_speed);
1923 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1924 // No need to convert as already in m/s
1927 dist_tp += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord), &(VIK_TRACKPOINT(iter->prev->data)->coord) );
1928 int x = MARGIN + (widgets->profile_width * dist_tp / dist);
1929 int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cisd]*LINES);
1930 gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
1932 g_object_unref ( G_OBJECT(gps_speed_gc) );
1936 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1938 g_object_unref ( G_OBJECT(pix) );
1945 static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean resized )
1947 // Draw graphs even if they are not visible
1949 GList *child = NULL;
1950 GtkWidget *image = NULL;
1951 GtkWidget *window = gtk_widget_get_toplevel(widget);
1953 gdouble pc_blob = NAN;
1956 if (widgets->elev_box != NULL) {
1958 // Saved image no longer any good as we've resized, so we remove it here
1959 if (resized && widgets->elev_graph_saved_img.img) {
1960 g_object_unref(widgets->elev_graph_saved_img.img);
1961 widgets->elev_graph_saved_img.img = NULL;
1962 widgets->elev_graph_saved_img.saved = FALSE;
1965 child = gtk_container_get_children(GTK_CONTAINER(widgets->elev_box));
1966 draw_elevations (GTK_WIDGET(child->data), widgets->tr, widgets );
1968 image = GTK_WIDGET(child->data);
1971 // Ensure marker or blob are redrawn if necessary
1972 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
1974 pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
1975 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
1977 if (widgets->is_blob_drawn) {
1978 pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
1979 if (!isnan(pc_blob)) {
1980 x_blob = (pc_blob * widgets->profile_width);
1982 y_blob = blobby_altitude (x_blob, widgets);
1985 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
1987 marker_x = (pc * widgets->profile_width) + MARGIN;
1990 save_image_and_draw_graph_marks (image,
1992 gtk_widget_get_style(window)->black_gc,
1995 &widgets->elev_graph_saved_img,
1996 widgets->profile_width,
1997 widgets->profile_height,
1998 &widgets->is_marker_drawn,
1999 &widgets->is_blob_drawn);
2004 if (widgets->gradient_box != NULL) {
2006 // Saved image no longer any good as we've resized, so we remove it here
2007 if (resized && widgets->gradient_graph_saved_img.img) {
2008 g_object_unref(widgets->gradient_graph_saved_img.img);
2009 widgets->gradient_graph_saved_img.img = NULL;
2010 widgets->gradient_graph_saved_img.saved = FALSE;
2013 child = gtk_container_get_children(GTK_CONTAINER(widgets->gradient_box));
2014 draw_gradients (GTK_WIDGET(child->data), widgets->tr, widgets );
2016 image = GTK_WIDGET(child->data);
2019 // Ensure marker or blob are redrawn if necessary
2020 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2022 pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
2023 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2025 if (widgets->is_blob_drawn) {
2026 pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
2027 if (!isnan(pc_blob)) {
2028 x_blob = (pc_blob * widgets->profile_width);
2030 y_blob = blobby_gradient (x_blob, widgets);
2033 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2035 marker_x = (pc * widgets->profile_width) + MARGIN;
2038 save_image_and_draw_graph_marks (image,
2040 gtk_widget_get_style(window)->black_gc,
2043 &widgets->gradient_graph_saved_img,
2044 widgets->profile_width,
2045 widgets->profile_height,
2046 &widgets->is_marker_drawn,
2047 &widgets->is_blob_drawn);
2052 if (widgets->speed_box != NULL) {
2054 // Saved image no longer any good as we've resized
2055 if (resized && widgets->speed_graph_saved_img.img) {
2056 g_object_unref(widgets->speed_graph_saved_img.img);
2057 widgets->speed_graph_saved_img.img = NULL;
2058 widgets->speed_graph_saved_img.saved = FALSE;
2061 child = gtk_container_get_children(GTK_CONTAINER(widgets->speed_box));
2062 draw_vt (GTK_WIDGET(child->data), widgets->tr, widgets );
2064 image = GTK_WIDGET(child->data);
2067 // Ensure marker or blob are redrawn if necessary
2068 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2070 pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
2072 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2074 if (widgets->is_blob_drawn) {
2075 pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
2076 if (!isnan(pc_blob)) {
2077 x_blob = (pc_blob * widgets->profile_width);
2080 y_blob = blobby_speed (x_blob, widgets);
2083 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2085 marker_x = (pc * widgets->profile_width) + MARGIN;
2088 save_image_and_draw_graph_marks (image,
2090 gtk_widget_get_style(window)->black_gc,
2093 &widgets->speed_graph_saved_img,
2094 widgets->profile_width,
2095 widgets->profile_height,
2096 &widgets->is_marker_drawn,
2097 &widgets->is_blob_drawn);
2102 if (widgets->dist_box != NULL) {
2104 // Saved image no longer any good as we've resized
2105 if (resized && widgets->dist_graph_saved_img.img) {
2106 g_object_unref(widgets->dist_graph_saved_img.img);
2107 widgets->dist_graph_saved_img.img = NULL;
2108 widgets->dist_graph_saved_img.saved = FALSE;
2111 child = gtk_container_get_children(GTK_CONTAINER(widgets->dist_box));
2112 draw_dt (GTK_WIDGET(child->data), widgets->tr, widgets );
2114 image = GTK_WIDGET(child->data);
2117 // Ensure marker or blob are redrawn if necessary
2118 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2120 pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
2122 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2124 if (widgets->is_blob_drawn) {
2125 pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
2126 if (!isnan(pc_blob)) {
2127 x_blob = (pc_blob * widgets->profile_width);
2130 y_blob = blobby_distance (x_blob, widgets);
2133 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2135 marker_x = (pc * widgets->profile_width) + MARGIN;
2138 save_image_and_draw_graph_marks (image,
2140 gtk_widget_get_style(window)->black_gc,
2143 &widgets->dist_graph_saved_img,
2144 widgets->profile_width,
2145 widgets->profile_height,
2146 &widgets->is_marker_drawn,
2147 &widgets->is_blob_drawn);
2151 // Draw Elevations in timely manner
2152 if (widgets->elev_time_box != NULL) {
2154 // Saved image no longer any good as we've resized
2155 if (resized && widgets->elev_time_graph_saved_img.img) {
2156 g_object_unref(widgets->elev_time_graph_saved_img.img);
2157 widgets->elev_time_graph_saved_img.img = NULL;
2158 widgets->elev_time_graph_saved_img.saved = FALSE;
2161 child = gtk_container_get_children(GTK_CONTAINER(widgets->elev_time_box));
2162 draw_et (GTK_WIDGET(child->data), widgets->tr, widgets );
2164 image = GTK_WIDGET(child->data);
2167 // Ensure marker or blob are redrawn if necessary
2168 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2170 pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
2172 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2174 if (widgets->is_blob_drawn) {
2175 pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
2176 if (!isnan(pc_blob)) {
2177 x_blob = (pc_blob * widgets->profile_width);
2179 y_blob = blobby_altitude_time (x_blob, widgets);
2182 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2184 marker_x = (pc * widgets->profile_width) + MARGIN;
2187 save_image_and_draw_graph_marks (image,
2189 gtk_widget_get_style(window)->black_gc,
2192 &widgets->elev_time_graph_saved_img,
2193 widgets->profile_width,
2194 widgets->profile_height,
2195 &widgets->is_marker_drawn,
2196 &widgets->is_blob_drawn);
2200 // Draw speed distances
2201 if (widgets->speed_dist_box != NULL) {
2203 // Saved image no longer any good as we've resized, so we remove it here
2204 if (resized && widgets->speed_dist_graph_saved_img.img) {
2205 g_object_unref(widgets->speed_dist_graph_saved_img.img);
2206 widgets->speed_dist_graph_saved_img.img = NULL;
2207 widgets->speed_dist_graph_saved_img.saved = FALSE;
2210 child = gtk_container_get_children(GTK_CONTAINER(widgets->speed_dist_box));
2211 draw_sd (GTK_WIDGET(child->data), widgets->tr, widgets );
2213 image = GTK_WIDGET(child->data);
2216 // Ensure marker or blob are redrawn if necessary
2217 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2219 pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
2220 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2222 if (widgets->is_blob_drawn) {
2223 pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
2224 if (!isnan(pc_blob)) {
2225 x_blob = (pc_blob * widgets->profile_width);
2227 y_blob = blobby_speed_dist (x_blob, widgets);
2230 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2232 marker_x = (pc * widgets->profile_width) + MARGIN;
2235 save_image_and_draw_graph_marks (image,
2237 gtk_widget_get_style(window)->black_gc,
2240 &widgets->speed_dist_graph_saved_img,
2241 widgets->profile_width,
2242 widgets->profile_height,
2243 &widgets->is_marker_drawn,
2244 &widgets->is_blob_drawn);
2251 * Configure/Resize the profile & speed/time images
2253 static gboolean configure_event ( GtkWidget *widget, GdkEventConfigure *event, PropWidgets *widgets )
2255 if (widgets->configure_dialog) {
2256 // Determine size offsets between dialog size and size for images
2257 // Only on the initialisation of the dialog
2258 widgets->profile_width_offset = event->width - widgets->profile_width;
2259 widgets->profile_height_offset = event->height - widgets->profile_height;
2260 widgets->configure_dialog = FALSE;
2262 // Without this the settting, the dialog will only grow in vertical size - one can not then make it smaller!
2263 gtk_widget_set_size_request ( widget, widgets->profile_width+widgets->profile_width_offset, widgets->profile_height+widgets->profile_height_offset );
2265 // Allow resizing back down to a minimal size (especially useful if the initial size has been made bigger after restoring from the saved settings)
2266 GdkGeometry geom = { 600+widgets->profile_width_offset, 300+widgets->profile_height_offset, 0, 0, 0, 0, 0, 0, 0, 0, GDK_GRAVITY_STATIC };
2267 gdk_window_set_geometry_hints ( gtk_widget_get_window(widget), &geom, GDK_HINT_MIN_SIZE );
2270 widgets->profile_width_old = widgets->profile_width;
2271 widgets->profile_height_old = widgets->profile_height;
2274 // Now adjust From Dialog size to get image size
2275 widgets->profile_width = event->width - widgets->profile_width_offset;
2276 widgets->profile_height = event->height - widgets->profile_height_offset;
2278 // ATM we receive configure_events when the dialog is moved and so no further action is necessary
2279 if ( !widgets->configure_dialog &&
2280 (widgets->profile_width_old == widgets->profile_width) && (widgets->profile_height_old == widgets->profile_height) )
2284 draw_all_graphs ( widget, widgets, TRUE );
2290 * Create height profile widgets including the image and callbacks
2292 GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, PropWidgets *widgets, gdouble *min_alt, gdouble *max_alt)
2296 GtkWidget *eventbox;
2299 widgets->altitudes = vik_track_make_elevation_map ( widgets->tr, widgets->profile_width );
2301 if ( widgets->altitudes == NULL ) {
2302 *min_alt = *max_alt = VIK_DEFAULT_ALTITUDE;
2306 minmax_array(widgets->altitudes, min_alt, max_alt, TRUE, widgets->profile_width);
2308 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2309 image = gtk_image_new_from_pixmap ( pix, NULL );
2311 g_object_unref ( G_OBJECT(pix) );
2313 eventbox = gtk_event_box_new ();
2314 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_profile_click), widgets );
2315 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_profile_move), widgets );
2316 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2317 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_STRUCTURE_MASK);
2323 * Create height profile widgets including the image and callbacks
2325 GtkWidget *vik_trw_layer_create_gradient ( GtkWidget *window, PropWidgets *widgets)
2329 GtkWidget *eventbox;
2332 widgets->gradients = vik_track_make_gradient_map ( widgets->tr, widgets->profile_width );
2334 if ( widgets->gradients == NULL ) {
2338 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2339 image = gtk_image_new_from_pixmap ( pix, NULL );
2341 g_object_unref ( G_OBJECT(pix) );
2343 eventbox = gtk_event_box_new ();
2344 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_gradient_click), widgets );
2345 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_gradient_move), widgets );
2346 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2347 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_STRUCTURE_MASK);
2353 * Create speed/time widgets including the image and callbacks
2355 GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, PropWidgets *widgets)
2359 GtkWidget *eventbox;
2362 widgets->speeds = vik_track_make_speed_map ( widgets->tr, widgets->profile_width );
2363 if ( widgets->speeds == NULL )
2366 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2367 image = gtk_image_new_from_pixmap ( pix, NULL );
2370 /* XXX this can go out, it's just a helpful dev tool */
2373 GdkGC **colors[8] = { gtk_widget_get_style(window)->bg_gc,
2374 gtk_widget_get_style(window)->fg_gc,
2375 gtk_widget_get_style(window)->light_gc,
2376 gtk_widget_get_style(window)->dark_gc,
2377 gtk_widget_get_style(window)->mid_gc,
2378 gtk_widget_get_style(window)->text_gc,
2379 gtk_widget_get_style(window)->base_gc,
2380 gtk_widget_get_style(window)->text_aa_gc };
2381 for (i=0; i<5; i++) {
2382 for (j=0; j<8; j++) {
2383 gdk_draw_rectangle(GDK_DRAWABLE(pix), colors[j][i],
2384 TRUE, i*20, j*20, 20, 20);
2385 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc,
2386 FALSE, i*20, j*20, 20, 20);
2392 g_object_unref ( G_OBJECT(pix) );
2394 eventbox = gtk_event_box_new ();
2395 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_vt_click), widgets );
2396 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_vt_move), widgets );
2397 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2398 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2404 * Create distance / time widgets including the image and callbacks
2406 GtkWidget *vik_trw_layer_create_dtdiag ( GtkWidget *window, PropWidgets *widgets)
2410 GtkWidget *eventbox;
2413 widgets->distances = vik_track_make_distance_map ( widgets->tr, widgets->profile_width );
2414 if ( widgets->distances == NULL )
2417 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2418 image = gtk_image_new_from_pixmap ( pix, NULL );
2420 g_object_unref ( G_OBJECT(pix) );
2422 eventbox = gtk_event_box_new ();
2423 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_dt_click), widgets );
2424 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_dt_move), widgets );
2425 //g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), widgets );
2426 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2427 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2433 * Create elevation / time widgets including the image and callbacks
2435 GtkWidget *vik_trw_layer_create_etdiag ( GtkWidget *window, PropWidgets *widgets)
2439 GtkWidget *eventbox;
2442 widgets->ats = vik_track_make_elevation_time_map ( widgets->tr, widgets->profile_width );
2443 if ( widgets->ats == NULL )
2446 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2447 image = gtk_image_new_from_pixmap ( pix, NULL );
2449 g_object_unref ( G_OBJECT(pix) );
2451 eventbox = gtk_event_box_new ();
2452 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_et_click), widgets );
2453 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_et_move), widgets );
2454 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2455 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2461 * Create speed/distance widgets including the image and callbacks
2463 GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, PropWidgets *widgets)
2467 GtkWidget *eventbox;
2470 widgets->speeds_dist = vik_track_make_speed_dist_map ( widgets->tr, widgets->profile_width );
2471 if ( widgets->speeds_dist == NULL )
2474 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2475 image = gtk_image_new_from_pixmap ( pix, NULL );
2477 g_object_unref ( G_OBJECT(pix) );
2479 eventbox = gtk_event_box_new ();
2480 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_sd_click), widgets );
2481 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_sd_move), widgets );
2482 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2483 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2489 #define VIK_SETTINGS_TRACK_PROFILE_WIDTH "track_profile_display_width"
2490 #define VIK_SETTINGS_TRACK_PROFILE_HEIGHT "track_profile_display_height"
2492 static void save_values ( PropWidgets *widgets )
2494 a_settings_set_integer ( VIK_SETTINGS_TRACK_PROFILE_WIDTH, widgets->profile_width );
2495 a_settings_set_integer ( VIK_SETTINGS_TRACK_PROFILE_HEIGHT, widgets->profile_height );
2498 static void destroy_cb ( GtkDialog *dialog, PropWidgets *widgets )
2500 save_values(widgets);
2501 prop_widgets_free(widgets);
2504 static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widgets )
2506 VikTrack *tr = widgets->tr;
2507 VikTrwLayer *vtl = widgets->vtl;
2508 gboolean keep_dialog = FALSE;
2510 /* FIXME: check and make sure the track still exists before doing anything to it */
2511 /* Note: destroying diaglog (eg, parent window exit) won't give "response" */
2513 case GTK_RESPONSE_DELETE_EVENT: /* received delete event (not from buttons) */
2514 case GTK_RESPONSE_REJECT:
2516 case GTK_RESPONSE_ACCEPT:
2517 vik_track_set_comment(tr, gtk_entry_get_text(GTK_ENTRY(widgets->w_comment)));
2518 vik_track_set_description(tr, gtk_entry_get_text(GTK_ENTRY(widgets->w_description)));
2519 gtk_color_button_get_color ( GTK_COLOR_BUTTON(widgets->w_color), &(tr->color) );
2520 tr->draw_name_mode = gtk_combo_box_get_active ( GTK_COMBO_BOX(widgets->w_namelabel) );
2521 tr->max_number_dist_labels = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widgets->w_number_distlabels) );
2522 trw_layer_update_treeview ( widgets->vtl, widgets->tr, widgets->trk_id );
2523 vik_layer_emit_update ( VIK_LAYER(vtl) );
2525 case VIK_TRW_LAYER_PROPWIN_REVERSE:
2526 vik_track_reverse(tr);
2527 vik_layer_emit_update ( VIK_LAYER(vtl) );
2529 case VIK_TRW_LAYER_PROPWIN_DEL_DUP:
2530 vik_track_remove_dup_points(tr); // NB ignore the returned answer
2531 // As we could have seen the nuber of dulplicates that would be deleted in the properties statistics tab,
2532 // choose not to inform the user unnecessarily
2534 /* above operation could have deleted current_tp or last_tp */
2535 trw_layer_cancel_tps_of_track ( vtl, tr );
2536 vik_layer_emit_update ( VIK_LAYER(vtl) );
2538 case VIK_TRW_LAYER_PROPWIN_SPLIT:
2540 /* get new tracks, add them and then the delete old one. old can still exist on clipboard. */
2543 VikTrack **tracks = vik_track_split_into_segments(tr, &ntracks);
2546 for ( i = 0; i < ntracks; i++ )
2549 new_tr_name = trw_layer_new_unique_sublayer_name ( vtl,
2550 widgets->tr->is_route ? VIK_TRW_LAYER_SUBLAYER_ROUTE : VIK_TRW_LAYER_SUBLAYER_TRACK,
2552 if ( widgets->tr->is_route )
2553 vik_trw_layer_add_route ( vtl, new_tr_name, tracks[i] );
2555 vik_trw_layer_add_track ( vtl, new_tr_name, tracks[i] );
2556 vik_track_calculate_bounds ( tracks[i] );
2558 g_free ( new_tr_name );
2564 /* Don't let track destroy this dialog */
2565 vik_track_clear_property_dialog(tr);
2566 if ( widgets->tr->is_route )
2567 vik_trw_layer_delete_route ( vtl, tr );
2569 vik_trw_layer_delete_track ( vtl, tr );
2570 vik_layer_emit_update ( VIK_LAYER(vtl) ); /* chase thru the hoops */
2574 case VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER:
2576 GList *iter = tr->trackpoints;
2577 while ((iter = iter->next)) {
2578 if (widgets->marker_tp == VIK_TRACKPOINT(iter->data))
2582 a_dialog_msg(VIK_GTK_WINDOW_FROM_LAYER(vtl), GTK_MESSAGE_ERROR,
2583 _("Failed spliting track. Track unchanged"), NULL);
2588 gchar *r_name = trw_layer_new_unique_sublayer_name(vtl,
2589 widgets->tr->is_route ? VIK_TRW_LAYER_SUBLAYER_ROUTE : VIK_TRW_LAYER_SUBLAYER_TRACK,
2591 iter->prev->next = NULL;
2593 VikTrack *tr_right = vik_track_new();
2595 vik_track_set_comment ( tr_right, tr->comment );
2596 tr_right->visible = tr->visible;
2597 tr_right->is_route = tr->is_route;
2598 tr_right->trackpoints = iter;
2600 if ( widgets->tr->is_route )
2601 vik_trw_layer_add_route(vtl, r_name, tr_right);
2603 vik_trw_layer_add_track(vtl, r_name, tr_right);
2604 vik_track_calculate_bounds ( tr_right );
2608 vik_layer_emit_update ( VIK_LAYER(vtl) );
2612 fprintf(stderr, "DEBUG: unknown response\n");
2616 /* Keep same behaviour for now: destroy dialog if click on any button */
2618 vik_track_clear_property_dialog(tr);
2619 gtk_widget_destroy ( GTK_WIDGET(dialog) );
2624 * Force a redraw when checkbutton has been toggled to show/hide that information
2626 static void checkbutton_toggle_cb ( GtkToggleButton *togglebutton, PropWidgets *widgets, gpointer dummy )
2628 // Even though not resized, we'll pretend it is -
2629 // as this invalidates the saved images (since the image may have changed)
2630 draw_all_graphs ( widgets->dialog, widgets, TRUE );
2634 * Create the widgets for the given graph tab
2636 static GtkWidget *create_graph_page ( GtkWidget *graph,
2637 const gchar *markup,
2639 const gchar *markup2,
2641 GtkWidget *checkbutton1,
2642 gboolean checkbutton1_default,
2643 GtkWidget *checkbutton2,
2644 gboolean checkbutton2_default )
2646 GtkWidget *hbox = gtk_hbox_new ( FALSE, 10 );
2647 GtkWidget *vbox = gtk_vbox_new ( FALSE, 10 );
2648 GtkWidget *label = gtk_label_new (NULL);
2649 GtkWidget *label2 = gtk_label_new (NULL);
2650 gtk_box_pack_start (GTK_BOX(vbox), graph, FALSE, FALSE, 0);
2651 gtk_label_set_markup ( GTK_LABEL(label), markup );
2652 gtk_label_set_markup ( GTK_LABEL(label2), markup2 );
2653 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
2654 gtk_box_pack_start (GTK_BOX(hbox), value, FALSE, FALSE, 0);
2655 gtk_box_pack_start (GTK_BOX(hbox), label2, FALSE, FALSE, 0);
2656 gtk_box_pack_start (GTK_BOX(hbox), value2, FALSE, FALSE, 0);
2658 gtk_box_pack_end (GTK_BOX(hbox), checkbutton2, FALSE, FALSE, 0);
2659 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton2), checkbutton2_default);
2662 gtk_box_pack_end (GTK_BOX(hbox), checkbutton1, FALSE, FALSE, 0);
2663 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton1), checkbutton1_default);
2665 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
2670 static GtkWidget *create_table (int cnt, char *labels[], GtkWidget *contents[])
2675 table = GTK_TABLE(gtk_table_new (cnt, 2, FALSE));
2676 gtk_table_set_col_spacing (table, 0, 10);
2677 for (i=0; i<cnt; i++) {
2680 // Settings so the text positioning only moves around vertically when the dialog is resized
2681 // This also gives more room to see the track comment
2682 label = gtk_label_new(NULL);
2683 gtk_misc_set_alignment ( GTK_MISC(label), 1, 0.5 ); // Position text centrally in vertical plane
2684 gtk_label_set_markup ( GTK_LABEL(label), _(labels[i]) );
2685 gtk_table_attach ( table, label, 0, 1, i, i+1, GTK_FILL, GTK_SHRINK, 0, 0 );
2686 if (GTK_IS_MISC(contents[i])) {
2687 gtk_misc_set_alignment ( GTK_MISC(contents[i]), 0, 0.5 );
2689 if ( GTK_IS_COLOR_BUTTON(contents[i]) || GTK_IS_COMBO_BOX(contents[i]) )
2690 // Buttons compressed - otherwise look weird (to me) if vertically massive
2691 gtk_table_attach ( table, contents[i], 1, 2, i, i+1, GTK_FILL, GTK_SHRINK, 0, 5 );
2693 // Expand for comments + descriptions / labels
2694 gtk_table_attach_defaults ( table, contents[i], 1, 2, i, i+1 );
2697 return GTK_WIDGET (table);
2700 void vik_trw_layer_propwin_run ( GtkWindow *parent,
2706 gboolean start_on_stats )
2708 PropWidgets *widgets = prop_widgets_new();
2713 widgets->trk_id = trk_id;
2715 gint profile_size_value;
2716 // Ensure minimum values
2717 widgets->profile_width = 600;
2718 if ( a_settings_get_integer ( VIK_SETTINGS_TRACK_PROFILE_WIDTH, &profile_size_value ) )
2719 if ( profile_size_value > widgets->profile_width )
2720 widgets->profile_width = profile_size_value;
2722 widgets->profile_height = 300;
2723 if ( a_settings_get_integer ( VIK_SETTINGS_TRACK_PROFILE_HEIGHT, &profile_size_value ) )
2724 if ( profile_size_value > widgets->profile_height )
2725 widgets->profile_height = profile_size_value;
2727 gchar *title = g_strdup_printf(_("%s - Track Properties"), tr->name);
2728 GtkWidget *dialog = gtk_dialog_new_with_buttons (title,
2730 GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
2731 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
2732 _("Split at _Marker"), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER,
2733 _("Split _Segments"), VIK_TRW_LAYER_PROPWIN_SPLIT,
2734 _("_Reverse"), VIK_TRW_LAYER_PROPWIN_REVERSE,
2735 _("_Delete Dupl."), VIK_TRW_LAYER_PROPWIN_DEL_DUP,
2736 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2738 widgets->dialog = dialog;
2739 g_signal_connect( G_OBJECT(dialog), "response", G_CALLBACK(propwin_response_cb), widgets);
2747 gdouble min_alt, max_alt;
2748 widgets->elev_box = vik_trw_layer_create_profile(GTK_WIDGET(parent), widgets, &min_alt, &max_alt);
2749 widgets->gradient_box = vik_trw_layer_create_gradient(GTK_WIDGET(parent), widgets);
2750 widgets->speed_box = vik_trw_layer_create_vtdiag(GTK_WIDGET(parent), widgets);
2751 widgets->dist_box = vik_trw_layer_create_dtdiag(GTK_WIDGET(parent), widgets);
2752 widgets->elev_time_box = vik_trw_layer_create_etdiag(GTK_WIDGET(parent), widgets);
2753 widgets->speed_dist_box = vik_trw_layer_create_sddiag(GTK_WIDGET(parent), widgets);
2754 GtkWidget *graphs = gtk_notebook_new();
2756 GtkWidget *content_prop[20];
2759 static gchar *label_texts[] = {
2760 N_("<b>Comment:</b>"),
2761 N_("<b>Description:</b>"),
2762 N_("<b>Color:</b>"),
2763 N_("<b>Draw Name:</b>"),
2764 N_("<b>Distance Labels:</b>"),
2766 static gchar *stats_texts[] = {
2767 N_("<b>Track Length:</b>"),
2768 N_("<b>Trackpoints:</b>"),
2769 N_("<b>Segments:</b>"),
2770 N_("<b>Duplicate Points:</b>"),
2771 N_("<b>Max Speed:</b>"),
2772 N_("<b>Avg. Speed:</b>"),
2773 N_("<b>Moving Avg. Speed:</b>"),
2774 N_("<b>Avg. Dist. Between TPs:</b>"),
2775 N_("<b>Elevation Range:</b>"),
2776 N_("<b>Total Elevation Gain/Loss:</b>"),
2777 N_("<b>Start:</b>"),
2779 N_("<b>Duration:</b>"),
2781 static gchar tmp_buf[50];
2785 widgets->w_comment = gtk_entry_new ();
2787 gtk_entry_set_text ( GTK_ENTRY(widgets->w_comment), tr->comment );
2788 g_signal_connect_swapped ( widgets->w_comment, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
2789 content_prop[cnt_prop++] = widgets->w_comment;
2791 widgets->w_description = gtk_entry_new ();
2792 if ( tr->description )
2793 gtk_entry_set_text ( GTK_ENTRY(widgets->w_description), tr->description );
2794 g_signal_connect_swapped ( widgets->w_description, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
2795 content_prop[cnt_prop++] = widgets->w_description;
2797 widgets->w_color = content_prop[cnt_prop++] = gtk_color_button_new_with_color ( &(tr->color) );
2799 static gchar *draw_name_labels[] = {
2804 N_("Start and End"),
2805 N_("Centre, Start and End"),
2809 widgets->w_namelabel = content_prop[cnt_prop++] = vik_combo_box_text_new ();
2810 gchar **pstr = draw_name_labels;
2812 vik_combo_box_text_append ( widgets->w_namelabel, *(pstr++) );
2813 gtk_combo_box_set_active ( GTK_COMBO_BOX(widgets->w_namelabel), tr->draw_name_mode );
2815 widgets->w_number_distlabels = content_prop[cnt_prop++] =
2816 gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new(tr->max_number_dist_labels, 0, 100, 1, 1, 0)), 1, 0 );
2817 gtk_widget_set_tooltip_text ( GTK_WIDGET(widgets->w_number_distlabels), _("Maximum number of distance labels to be shown") );
2819 table = create_table (cnt_prop, label_texts, content_prop);
2821 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), GTK_WIDGET(table), gtk_label_new(_("Properties")));
2824 GtkWidget *content[20];
2827 vik_units_distance_t dist_units = a_vik_get_units_distance ();
2829 // NB This value not shown yet - but is used by internal calculations
2830 widgets->track_length_inc_gaps = vik_track_get_length_including_gaps(tr);
2832 tr_len = widgets->track_length = vik_track_get_length(tr);
2833 switch (dist_units) {
2834 case VIK_UNITS_DISTANCE_KILOMETRES:
2835 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", tr_len/1000.0 );
2837 case VIK_UNITS_DISTANCE_MILES:
2838 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(tr_len) );
2841 g_critical("Houston, we've had a problem. distance=%d", dist_units);
2843 widgets->w_track_length = content[cnt++] = gtk_label_new ( tmp_buf );
2845 tp_count = vik_track_get_tp_count(tr);
2846 g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", tp_count );
2847 widgets->w_tp_count = content[cnt++] = gtk_label_new ( tmp_buf );
2849 seg_count = vik_track_get_segment_count(tr) ;
2850 g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", seg_count );
2851 widgets->w_segment_count = content[cnt++] = gtk_label_new ( tmp_buf );
2853 g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", vik_track_get_dup_point_count(tr) );
2854 widgets->w_duptp_count = content[cnt++] = gtk_label_new ( tmp_buf );
2856 vik_units_speed_t speed_units = a_vik_get_units_speed ();
2857 tmp_speed = vik_track_get_max_speed(tr);
2858 if ( tmp_speed == 0 )
2859 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2861 switch (speed_units) {
2862 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2863 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2865 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2866 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2868 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2869 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2871 case VIK_UNITS_SPEED_KNOTS:
2872 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2875 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2876 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2879 widgets->w_max_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2881 tmp_speed = vik_track_get_average_speed(tr);
2882 if ( tmp_speed == 0 )
2883 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2885 switch (speed_units) {
2886 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2887 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2889 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2890 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2892 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2893 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2895 case VIK_UNITS_SPEED_KNOTS:
2896 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2899 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2900 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2903 widgets->w_avg_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2905 // Use 60sec as the default period to be considered stopped
2906 // this is the TrackWaypoint draw stops default value 'vtl->stop_length'
2907 // however this variable is not directly accessible - and I don't expect it's often changed from the default
2908 // so ATM just put in the number
2909 tmp_speed = vik_track_get_average_speed_moving(tr, 60);
2910 if ( tmp_speed == 0 )
2911 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2913 switch (speed_units) {
2914 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2915 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2917 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2918 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2920 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2921 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2923 case VIK_UNITS_SPEED_KNOTS:
2924 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2927 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2928 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2931 widgets->w_mvg_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2933 switch (dist_units) {
2934 case VIK_UNITS_DISTANCE_KILOMETRES:
2935 // Even though kilometres, the average distance between points is going to be quite small so keep in metres
2936 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m", (tp_count - seg_count) == 0 ? 0 : tr_len / ( tp_count - seg_count ) );
2938 case VIK_UNITS_DISTANCE_MILES:
2939 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 )) );
2942 g_critical("Houston, we've had a problem. distance=%d", dist_units);
2944 widgets->w_avg_dist = content[cnt++] = gtk_label_new ( tmp_buf );
2946 vik_units_height_t height_units = a_vik_get_units_height ();
2947 if ( min_alt == VIK_DEFAULT_ALTITUDE )
2948 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2950 switch (height_units) {
2951 case VIK_UNITS_HEIGHT_METRES:
2952 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m - %.0f m", min_alt, max_alt );
2954 case VIK_UNITS_HEIGHT_FEET:
2955 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f feet - %.0f feet", VIK_METERS_TO_FEET(min_alt), VIK_METERS_TO_FEET(max_alt) );
2958 g_snprintf(tmp_buf, sizeof(tmp_buf), "--" );
2959 g_critical("Houston, we've had a problem. height=%d", height_units);
2962 widgets->w_elev_range = content[cnt++] = gtk_label_new ( tmp_buf );
2964 vik_track_get_total_elevation_gain(tr, &max_alt, &min_alt );
2965 if ( min_alt == VIK_DEFAULT_ALTITUDE )
2966 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2968 switch (height_units) {
2969 case VIK_UNITS_HEIGHT_METRES:
2970 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m / %.0f m", max_alt, min_alt );
2972 case VIK_UNITS_HEIGHT_FEET:
2973 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f feet / %.0f feet", VIK_METERS_TO_FEET(max_alt), VIK_METERS_TO_FEET(min_alt) );
2976 g_snprintf(tmp_buf, sizeof(tmp_buf), "--" );
2977 g_critical("Houston, we've had a problem. height=%d", height_units);
2980 widgets->w_elev_gain = content[cnt++] = gtk_label_new ( tmp_buf );
2983 #define PACK(w) gtk_box_pack_start (GTK_BOX(right_vbox), w, FALSE, FALSE, 0);
2984 gtk_box_pack_start (GTK_BOX(right_vbox), e_cmt, FALSE, FALSE, 0);
2997 if ( tr->trackpoints && VIK_TRACKPOINT(tr->trackpoints->data)->timestamp )
3000 t1 = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
3001 t2 = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp;
3003 strftime (tmp_buf, sizeof(tmp_buf), "%c", localtime(&(t1)));
3004 widgets->w_time_start = content[cnt++] = gtk_label_new(tmp_buf);
3006 strftime (tmp_buf, sizeof(tmp_buf), "%c", localtime(&(t2)));
3007 widgets->w_time_end = content[cnt++] = gtk_label_new(tmp_buf);
3009 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%d minutes"), (int)(t2-t1)/60);
3010 widgets->w_time_dur = content[cnt++] = gtk_label_new(tmp_buf);
3012 widgets->w_time_start = content[cnt++] = gtk_label_new(_("No Data"));
3013 widgets->w_time_end = content[cnt++] = gtk_label_new(_("No Data"));
3014 widgets->w_time_dur = content[cnt++] = gtk_label_new(_("No Data"));
3017 table = create_table (cnt, stats_texts, content);
3019 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), GTK_WIDGET(table), gtk_label_new(_("Statistics")));
3021 if ( widgets->elev_box ) {
3022 GtkWidget *page = NULL;
3023 widgets->w_cur_dist = gtk_label_new(_("No Data"));
3024 widgets->w_cur_elevation = gtk_label_new(_("No Data"));
3025 widgets->w_show_dem = gtk_check_button_new_with_mnemonic(_("Show D_EM"));
3026 widgets->w_show_alt_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3027 page = create_graph_page (widgets->elev_box,
3028 _("<b>Track Distance:</b>"), widgets->w_cur_dist,
3029 _("<b>Track Height:</b>"), widgets->w_cur_elevation,
3030 widgets->w_show_dem, TRUE,
3031 widgets->w_show_alt_gps_speed, TRUE);
3032 g_signal_connect (widgets->w_show_dem, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3033 g_signal_connect (widgets->w_show_alt_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3034 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-distance")));
3037 if ( widgets->gradient_box ) {
3038 GtkWidget *page = NULL;
3039 widgets->w_cur_gradient_dist = gtk_label_new(_("No Data"));
3040 widgets->w_cur_gradient_gradient = gtk_label_new(_("No Data"));
3041 widgets->w_show_gradient_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3042 page = create_graph_page (widgets->gradient_box,
3043 _("<b>Track Distance:</b>"), widgets->w_cur_gradient_dist,
3044 _("<b>Track Gradient:</b>"), widgets->w_cur_gradient_gradient,
3045 widgets->w_show_gradient_gps_speed, TRUE,
3047 g_signal_connect (widgets->w_show_gradient_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3048 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Gradient-distance")));
3051 if ( widgets->speed_box ) {
3052 GtkWidget *page = NULL;
3053 widgets->w_cur_time = gtk_label_new(_("No Data"));
3054 widgets->w_cur_speed = gtk_label_new(_("No Data"));
3055 widgets->w_show_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3056 page = create_graph_page (widgets->speed_box,
3057 _("<b>Track Time:</b>"), widgets->w_cur_time,
3058 _("<b>Track Speed:</b>"), widgets->w_cur_speed,
3059 widgets->w_show_gps_speed, TRUE,
3061 g_signal_connect (widgets->w_show_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3062 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-time")));
3065 if ( widgets->dist_box ) {
3066 GtkWidget *page = NULL;
3067 widgets->w_cur_dist_time = gtk_label_new(_("No Data"));
3068 widgets->w_cur_dist_dist = gtk_label_new(_("No Data"));
3069 widgets->w_show_dist_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
3070 page = create_graph_page (widgets->dist_box,
3071 _("<b>Track Distance:</b>"), widgets->w_cur_dist_dist,
3072 _("<b>Track Time:</b>"), widgets->w_cur_dist_time,
3073 widgets->w_show_dist_speed, FALSE,
3075 g_signal_connect (widgets->w_show_dist_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3076 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Distance-time")));
3079 if ( widgets->elev_time_box ) {
3080 GtkWidget *page = NULL;
3081 widgets->w_cur_elev_time = gtk_label_new(_("No Data"));
3082 widgets->w_cur_elev_elev = gtk_label_new(_("No Data"));
3083 widgets->w_show_elev_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
3084 page = create_graph_page (widgets->elev_time_box,
3085 _("<b>Track Time:</b>"), widgets->w_cur_elev_time,
3086 _("<b>Track Height:</b>"), widgets->w_cur_elev_elev,
3087 widgets->w_show_elev_speed, FALSE,
3089 g_signal_connect (widgets->w_show_elev_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3090 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-time")));
3093 if ( widgets->speed_dist_box ) {
3094 GtkWidget *page = NULL;
3095 widgets->w_cur_speed_dist = gtk_label_new(_("No Data"));
3096 widgets->w_cur_speed_speed = gtk_label_new(_("No Data"));
3097 widgets->w_show_sd_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3098 page = create_graph_page (widgets->speed_dist_box,
3099 _("<b>Track Distance:</b>"), widgets->w_cur_speed_dist,
3100 _("<b>Track Speed:</b>"), widgets->w_cur_speed_speed,
3101 widgets->w_show_sd_gps_speed, TRUE,
3103 g_signal_connect (widgets->w_show_sd_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3104 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-distance")));
3107 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), graphs, FALSE, FALSE, 0);
3109 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
3111 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT, FALSE);
3112 if (vik_track_get_dup_point_count(tr) <= 0)
3113 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_DEL_DUP, FALSE);
3115 // On dialog realization configure_event causes the graphs to be initially drawn
3116 widgets->configure_dialog = TRUE;
3117 g_signal_connect ( G_OBJECT(dialog), "configure-event", G_CALLBACK (configure_event), widgets );
3119 g_signal_connect ( G_OBJECT(dialog), "destroy", G_CALLBACK (destroy_cb), widgets );
3121 vik_track_set_property_dialog(tr, dialog);
3122 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
3123 gtk_widget_show_all ( dialog );
3125 // Gtk note: due to historical reasons, this must be done after widgets are shown
3126 if ( start_on_stats )
3127 gtk_notebook_set_current_page ( GTK_NOTEBOOK(graphs), 1 );
3132 * Update this property dialog
3133 * e.g. if the track has been renamed
3135 void vik_trw_layer_propwin_update ( VikTrack *trk )
3137 // If not displayed do nothing
3138 if ( !trk->property_dialog )
3141 // Update title with current name
3143 gchar *title = g_strdup_printf ( _("%s - Track Properties"), trk->name );
3144 gtk_window_set_title ( GTK_WINDOW(trk->property_dialog), title );