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>
42 #include "viktrwlayer.h"
43 #include "viktrwlayer_propwin.h"
44 #include "vikwaypoint.h"
49 #include "vikviewport.h" /* ugh */
50 #include "viktreeview.h" /* ugh */
51 #include <gdk-pixbuf/gdk-pixdata.h>
52 #include "viklayer.h" /* ugh */
53 #include "vikaggregatelayer.h"
54 #include "viklayerspanel.h" /* ugh */
56 #define PROPWIN_PROFILE_WIDTH 600
57 #define PROPWIN_PROFILE_HEIGHT 300
59 #define PROPWIN_LABEL_FONT "Sans 7"
62 PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE,
63 PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE,
64 PROPWIN_GRAPH_TYPE_SPEED_TIME,
65 PROPWIN_GRAPH_TYPE_DISTANCE_TIME,
66 PROPWIN_GRAPH_TYPE_ELEVATION_TIME,
67 PROPWIN_GRAPH_TYPE_SPEED_DISTANCE,
68 PROPWIN_GRAPH_TYPE_END,
69 } VikPropWinGraphType_t;
71 /* (Hopefully!) Human friendly altitude grid sizes - note no fixed 'ratio' just numbers that look nice...*/
72 static const gdouble chunksa[] = {2.0, 5.0, 10.0, 15.0, 20.0,
73 25.0, 40.0, 50.0, 75.0, 100.0,
74 150.0, 200.0, 250.0, 375.0, 500.0,
75 750.0, 1000.0, 2000.0, 5000.0, 10000.0, 100000.0};
77 /* (Hopefully!) Human friendly gradient grid sizes - note no fixed 'ratio' just numbers that look nice...*/
78 static const gdouble chunksg[] = {1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
79 12.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 75.0,
80 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
81 750.0, 1000.0, 10000.0};
83 /* (Hopefully!) Human friendly grid sizes - note no fixed 'ratio' just numbers that look nice...*/
84 /* As need to cover walking speeds - have many low numbers (but also may go up to airplane speeds!) */
85 static const gdouble chunkss[] = {1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
86 15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
87 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
88 750.0, 1000.0, 10000.0};
90 /* (Hopefully!) Human friendly distance grid sizes - note no fixed 'ratio' just numbers that look nice...*/
91 static const gdouble chunksd[] = {0.1, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
92 15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
93 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
94 750.0, 1000.0, 10000.0};
96 typedef struct _propsaved {
101 typedef struct _propwidgets {
102 gboolean configure_dialog;
107 gint profile_width_old;
108 gint profile_height_old;
109 gint profile_width_offset;
110 gint profile_height_offset;
112 GtkWidget *w_comment;
113 GtkWidget *w_track_length;
114 GtkWidget *w_tp_count;
115 GtkWidget *w_segment_count;
116 GtkWidget *w_duptp_count;
117 GtkWidget *w_max_speed;
118 GtkWidget *w_avg_speed;
119 GtkWidget *w_mvg_speed;
120 GtkWidget *w_avg_dist;
121 GtkWidget *w_elev_range;
122 GtkWidget *w_elev_gain;
123 GtkWidget *w_time_start;
124 GtkWidget *w_time_end;
125 GtkWidget *w_time_dur;
126 GtkWidget *w_cur_dist; /*< Current distance */
127 GtkWidget *w_cur_elevation;
128 GtkWidget *w_cur_gradient_dist; /*< Current distance on gradient graph */
129 GtkWidget *w_cur_gradient_gradient; /*< Current gradient on gradient graph */
130 GtkWidget *w_cur_time; /*< Current time */
131 GtkWidget *w_cur_speed;
132 GtkWidget *w_cur_dist_dist; /*< Current distance on distance graph */
133 GtkWidget *w_cur_dist_time; /*< Current time on distance graph */
134 GtkWidget *w_cur_elev_elev;
135 GtkWidget *w_cur_elev_time;
136 GtkWidget *w_cur_speed_dist;
137 GtkWidget *w_cur_speed_speed;
138 GtkWidget *w_show_dem;
139 GtkWidget *w_show_alt_gps_speed;
140 GtkWidget *w_show_gps_speed;
141 GtkWidget *w_show_gradient_gps_speed;
142 GtkWidget *w_show_dist_speed;
143 GtkWidget *w_show_elev_speed;
144 GtkWidget *w_show_sd_gps_speed;
145 gdouble track_length;
146 gdouble track_length_inc_gaps;
147 PropSaved elev_graph_saved_img;
148 PropSaved gradient_graph_saved_img;
149 PropSaved speed_graph_saved_img;
150 PropSaved dist_graph_saved_img;
151 PropSaved elev_time_graph_saved_img;
152 PropSaved speed_dist_graph_saved_img;
154 GtkWidget *gradient_box;
155 GtkWidget *speed_box;
157 GtkWidget *elev_time_box;
158 GtkWidget *speed_dist_box;
160 gdouble *ats; // altitudes in time
161 gdouble min_altitude;
162 gdouble max_altitude;
163 gdouble draw_min_altitude;
164 gdouble draw_min_altitude_time;
165 gint cia; // Chunk size Index into Altitudes
166 gint ciat; // Chunk size Index into Altitudes / Time
167 // NB cia & ciat are normally same value but sometimes not due to differing methods of altitude array creation
168 // thus also have draw_min_altitude for each altitude graph type
170 gdouble min_gradient;
171 gdouble max_gradient;
172 gdouble draw_min_gradient;
173 gint cig; // Chunk size Index into Gradients
175 gdouble *speeds_dist;
178 gdouble draw_min_speed;
179 gdouble max_speed_dist;
180 gint cis; // Chunk size Index into Speeds
181 gint cisd; // Chunk size Index into Speed/Distance
183 gint cid; // Chunk size Index into Distance
184 VikTrackpoint *marker_tp;
185 gboolean is_marker_drawn;
186 VikTrackpoint *blob_tp;
187 gboolean is_blob_drawn;
190 static PropWidgets *prop_widgets_new()
192 PropWidgets *widgets = g_malloc0(sizeof(PropWidgets));
197 static void prop_widgets_free(PropWidgets *widgets)
199 if (widgets->elev_graph_saved_img.img)
200 g_object_unref(widgets->elev_graph_saved_img.img);
201 if (widgets->gradient_graph_saved_img.img)
202 g_object_unref(widgets->gradient_graph_saved_img.img);
203 if (widgets->speed_graph_saved_img.img)
204 g_object_unref(widgets->speed_graph_saved_img.img);
205 if (widgets->dist_graph_saved_img.img)
206 g_object_unref(widgets->dist_graph_saved_img.img);
207 if (widgets->elev_time_graph_saved_img.img)
208 g_object_unref(widgets->elev_time_graph_saved_img.img);
209 if (widgets->speed_dist_graph_saved_img.img)
210 g_object_unref(widgets->speed_dist_graph_saved_img.img);
211 if (widgets->altitudes)
212 g_free(widgets->altitudes);
213 if (widgets->gradients)
214 g_free(widgets->gradients);
216 g_free(widgets->speeds);
217 if (widgets->distances)
218 g_free(widgets->distances);
220 g_free(widgets->ats);
221 if (widgets->speeds_dist)
222 g_free(widgets->speeds_dist);
226 static void minmax_array(const gdouble *array, gdouble *min, gdouble *max, gboolean NO_ALT_TEST, gint PROFILE_WIDTH)
231 for ( i=0; i < PROFILE_WIDTH; i++ ) {
232 if ( NO_ALT_TEST || (array[i] != VIK_DEFAULT_ALTITUDE) ) {
233 if ( array[i] > *max )
235 if ( array[i] < *min )
244 * Returns via pointers:
245 * the new minimum value to be used for the altitude graph
246 * the index in to the altitudes chunk sizes array (ci = Chunk Index)
248 static void get_new_min_and_chunk_index_altitude (gdouble mina, gdouble maxa, gdouble *new_min, gint *ci)
250 /* Get unitized chunk */
251 /* Find suitable chunk index */
253 gdouble diffa_chunk = (maxa - mina)/LINES;
255 /* Loop through to find best match */
256 while (diffa_chunk > chunksa[*ci]) {
258 /* Last Resort Check */
259 if ( *ci == sizeof(chunksa)/sizeof(chunksa[0]) )
263 /* Ensure adjusted minimum .. maximum covers mina->maxa */
265 // Now work out adjusted minimum point to the nearest lowest chunk divisor value
266 // When negative ensure logic uses lowest value
268 *new_min = (gdouble) ( ( (gint)(mina - chunksa[*ci]) / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
270 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
272 // Range not big enough - as new minimum has lowered
273 if ((*new_min + (chunksa[*ci] * LINES) < maxa)) {
274 // Next chunk should cover it
275 if ( *ci < sizeof(chunksa)/sizeof(chunksa[0]) ) {
277 // Remember to adjust the minimum too...
279 *new_min = (gdouble) ( ( (gint)(mina - chunksa[*ci]) / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
281 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
287 * Returns via pointers:
288 * the new minimum value to be used for the altitude graph
289 * the index in to the altitudes chunk sizes array (ci = Chunk Index)
291 static void get_new_min_and_chunk_index_gradient (gdouble mina, gdouble maxa, gdouble *new_min, gint *ci)
293 /* Get unitized chunk */
294 /* Find suitable chunk index */
296 gdouble diffa_chunk = (maxa - mina)/LINES;
298 /* Loop through to find best match */
299 while (diffa_chunk > chunksg[*ci]) {
301 /* Last Resort Check */
302 if ( *ci == sizeof(chunksg)/sizeof(chunksg[0]) )
306 /* Ensure adjusted minimum .. maximum covers mina->maxa */
308 // Now work out adjusted minimum point to the nearest lowest chunk divisor value
309 // When negative ensure logic uses lowest value
311 *new_min = (gdouble) ( ( (gint)(mina - chunksg[*ci]) / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
313 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
315 // Range not big enough - as new minimum has lowered
316 if ((*new_min + (chunksg[*ci] * LINES) < maxa)) {
317 // Next chunk should cover it
318 if ( *ci < sizeof(chunksg)/sizeof(chunksg[0]) ) {
320 // Remember to adjust the minimum too...
322 *new_min = (gdouble) ( ( (gint)(mina - chunksg[*ci]) / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
324 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
330 * Returns via pointers:
331 * the new minimum value to be used for the appropriate graph
332 * the index in to that array (ci = Chunk Index)
334 static void get_new_min_and_chunk_index (gdouble mins, gdouble maxs, const gdouble *chunks, size_t chunky, gdouble *new_min, gint *ci)
337 gdouble diff_chunk = (maxs - mins)/LINES;
339 /* Loop through to find best match */
340 while (diff_chunk > chunks[*ci]) {
342 /* Last Resort Check */
346 *new_min = (gdouble) ( (gint)((mins / chunks[*ci] ) * chunks[*ci]) );
348 // Speeds are never negative so don't need to worry about a negative new minimum
351 static VikTrackpoint *set_center_at_graph_position(gdouble event_x,
360 VikTrackpoint *trackpoint;
361 gdouble x = event_x - img_width / 2 + PROFILE_WIDTH / 2 - MARGIN / 2;
364 if (x > PROFILE_WIDTH)
368 trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / PROFILE_WIDTH, NULL );
370 trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / PROFILE_WIDTH, NULL );
373 VikCoord coord = trackpoint->coord;
375 vik_viewport_set_center_coord ( vik_layers_panel_get_viewport(vlp), &coord );
376 vik_layers_panel_emit_update ( vlp );
379 /* since vlp not set, vvp should be valid instead! */
381 vik_viewport_set_center_coord ( vvp, &coord );
382 vik_layer_emit_update ( VIK_LAYER(vtl), FALSE );
389 * Returns whether the marker was drawn or not and whether the blob was drawn or not
391 static void save_image_and_draw_graph_marks (GtkWidget *image,
396 PropSaved *saved_img,
399 gboolean *marker_drawn,
400 gboolean *blob_drawn)
402 GdkPixmap *pix = NULL;
403 /* the pixmap = margin + graph area */
404 gtk_image_get_pixmap(GTK_IMAGE(image), &pix, NULL);
406 /* Restore previously saved image */
407 if (saved_img->saved) {
408 gdk_draw_image(GDK_DRAWABLE(pix), gc, saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
409 saved_img->saved = FALSE;
412 // ATM always save whole image - as anywhere could have changed
414 gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
416 saved_img->img = gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
417 saved_img->saved = TRUE;
419 if ((marker_x >= MARGIN) && (marker_x < (PROFILE_WIDTH + MARGIN))) {
420 gdk_draw_line (GDK_DRAWABLE(pix), gc, marker_x, 0, marker_x, image->allocation.height);
421 *marker_drawn = TRUE;
424 *marker_drawn = FALSE;
426 // Draw a square blob to indicate where we are on track for this graph
427 if ( (blob_x >= MARGIN) && (blob_x < (PROFILE_WIDTH + MARGIN)) && (blob_y < PROFILE_HEIGHT) ) {
428 gdk_draw_rectangle (GDK_DRAWABLE(pix), gc, TRUE, blob_x-3, blob_y-3, 6, 6);
434 // Anywhere on image could have changed
435 if (*marker_drawn || *blob_drawn)
436 gtk_widget_queue_draw(image);
440 * Return the percentage of how far a trackpoint is a long a track via the time method
442 static gdouble tp_percentage_by_time ( VikTrack *tr, VikTrackpoint *trackpoint )
445 if (trackpoint == NULL)
447 time_t t_start, t_end, t_total;
448 t_start = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
449 t_end = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp;
450 t_total = t_end - t_start;
451 pc = (gdouble)(trackpoint->timestamp - t_start)/t_total;
456 * Return the percentage of how far a trackpoint is a long a track via the distance method
458 static gdouble tp_percentage_by_distance ( VikTrack *tr, VikTrackpoint *trackpoint, gdouble track_length )
461 if (trackpoint == NULL)
465 for (iter = tr->trackpoints->next; iter != NULL; iter = iter->next) {
466 dist += vik_coord_diff(&(VIK_TRACKPOINT(iter->data)->coord),
467 &(VIK_TRACKPOINT(iter->prev->data)->coord));
468 /* Assuming trackpoint is not a copy */
469 if (trackpoint == VIK_TRACKPOINT(iter->data))
473 pc = dist/track_length;
477 static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along, VikPropWinGraphType_t graph_type )
479 VikTrack *tr = pass_along[0];
480 VikLayersPanel *vlp = pass_along[1];
481 VikViewport *vvp = pass_along[2];
482 PropWidgets *widgets = pass_along[3];
484 gboolean is_time_graph =
485 ( graph_type == PROPWIN_GRAPH_TYPE_SPEED_TIME ||
486 graph_type == PROPWIN_GRAPH_TYPE_DISTANCE_TIME ||
487 graph_type == PROPWIN_GRAPH_TYPE_ELEVATION_TIME );
489 VikTrackpoint *trackpoint = set_center_at_graph_position(event->x, event_box->allocation.width, widgets->vtl, vlp, vvp, tr, is_time_graph, widgets->profile_width);
490 // Unable to get the point so give up
491 if ( trackpoint == NULL ) {
492 gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
496 widgets->marker_tp = trackpoint;
500 GtkWidget *window = gtk_widget_get_toplevel(GTK_WIDGET(event_box));
501 GtkWidget *graph_box;
502 PropSaved *graph_saved_img;
505 // Attempt to redraw marker on all graph types
507 for ( graphite = PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE;
508 graphite < PROPWIN_GRAPH_TYPE_END;
511 // Switch commonal variables to particular graph type
514 case PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE:
515 graph_box = widgets->elev_box;
516 graph_saved_img = &widgets->elev_graph_saved_img;
517 is_time_graph = FALSE;
519 case PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE:
520 graph_box = widgets->gradient_box;
521 graph_saved_img = &widgets->gradient_graph_saved_img;
522 is_time_graph = FALSE;
524 case PROPWIN_GRAPH_TYPE_SPEED_TIME:
525 graph_box = widgets->speed_box;
526 graph_saved_img = &widgets->speed_graph_saved_img;
527 is_time_graph = TRUE;
529 case PROPWIN_GRAPH_TYPE_DISTANCE_TIME:
530 graph_box = widgets->dist_box;
531 graph_saved_img = &widgets->dist_graph_saved_img;
532 is_time_graph = TRUE;
534 case PROPWIN_GRAPH_TYPE_ELEVATION_TIME:
535 graph_box = widgets->elev_time_box;
536 graph_saved_img = &widgets->elev_time_graph_saved_img;
537 is_time_graph = TRUE;
539 case PROPWIN_GRAPH_TYPE_SPEED_DISTANCE:
540 graph_box = widgets->speed_dist_box;
541 graph_saved_img = &widgets->speed_dist_graph_saved_img;
542 is_time_graph = FALSE;
546 // Commonal method of redrawing marker
549 child = gtk_container_get_children(GTK_CONTAINER(graph_box));
550 image = GTK_WIDGET(child->data);
553 pc = tp_percentage_by_time ( tr, trackpoint );
555 pc = tp_percentage_by_distance ( tr, trackpoint, widgets->track_length_inc_gaps );
558 gdouble marker_x = (pc * widgets->profile_width) + MARGIN;
559 save_image_and_draw_graph_marks(image,
561 window->style->black_gc,
562 -1, // Don't draw blob on clicks
565 widgets->profile_width,
566 widgets->profile_height,
567 &widgets->is_marker_drawn,
568 &widgets->is_blob_drawn);
574 gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, widgets->is_marker_drawn);
577 static gboolean track_profile_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
579 track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE);
580 return TRUE; /* don't call other (further) callbacks */
583 static gboolean track_gradient_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
585 track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE);
586 return TRUE; /* don't call other (further) callbacks */
589 static gboolean track_vt_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
591 track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_SPEED_TIME);
592 return TRUE; /* don't call other (further) callbacks */
595 static gboolean track_dt_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
597 track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_DISTANCE_TIME);
598 return TRUE; /* don't call other (further) callbacks */
601 static gboolean track_et_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
603 track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_ELEVATION_TIME);
604 return TRUE; /* don't call other (further) callbacks */
607 static gboolean track_sd_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
609 track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_SPEED_DISTANCE);
610 return TRUE; /* don't call other (further) callbacks */
614 * Calculate y position for blob on elevation graph
616 static gint blobby_altitude ( gdouble x_blob, PropWidgets *widgets )
618 gint ix = (gint)x_blob;
619 // Ensure ix is inbounds
620 if (ix == widgets->profile_width)
623 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->altitudes[ix]-widgets->draw_min_altitude)/(chunksa[widgets->cia]*LINES);
629 * Calculate y position for blob on gradient graph
631 static gint blobby_gradient ( gdouble x_blob, PropWidgets *widgets )
633 gint ix = (gint)x_blob;
634 // Ensure ix is inbounds
635 if (ix == widgets->profile_width)
638 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->gradients[ix]-widgets->draw_min_gradient)/(chunksg[widgets->cig]*LINES);
644 * Calculate y position for blob on speed graph
646 static gint blobby_speed ( gdouble x_blob, PropWidgets *widgets )
648 gint ix = (gint)x_blob;
649 // Ensure ix is inbounds
650 if (ix == widgets->profile_width)
653 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->speeds[ix]-widgets->draw_min_speed)/(chunkss[widgets->cis]*LINES);
659 * Calculate y position for blob on distance graph
661 static gint blobby_distance ( gdouble x_blob, PropWidgets *widgets )
663 gint ix = (gint)x_blob;
664 // Ensure ix is inbounds
665 if (ix == widgets->profile_width)
668 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->distances[ix])/(chunksd[widgets->cid]*LINES);
669 //NB min distance is always 0, so no need to subtract that from this ______/
675 * Calculate y position for blob on elevation/time graph
677 static gint blobby_altitude_time ( gdouble x_blob, PropWidgets *widgets )
679 gint ix = (gint)x_blob;
680 // Ensure ix is inbounds
681 if (ix == widgets->profile_width)
684 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->ats[ix]-widgets->draw_min_altitude_time)/(chunksa[widgets->ciat]*LINES);
689 * Calculate y position for blob on speed/dist graph
691 static gint blobby_speed_dist ( gdouble x_blob, PropWidgets *widgets )
693 gint ix = (gint)x_blob;
694 // Ensure ix is inbounds
695 if (ix == widgets->profile_width)
698 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->speeds_dist[ix]-widgets->draw_min_speed)/(chunkss[widgets->cisd]*LINES);
704 void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
706 VikTrack *tr = pass_along[0];
707 PropWidgets *widgets = pass_along[3];
708 int mouse_x, mouse_y;
709 GdkModifierType state;
712 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
716 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
719 if (x > widgets->profile_width)
720 x = widgets->profile_width;
722 gdouble meters_from_start;
723 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / widgets->profile_width, &meters_from_start );
724 if (trackpoint && widgets->w_cur_dist) {
725 static gchar tmp_buf[20];
726 vik_units_distance_t dist_units = a_vik_get_units_distance ();
727 switch (dist_units) {
728 case VIK_UNITS_DISTANCE_KILOMETRES:
729 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
731 case VIK_UNITS_DISTANCE_MILES:
732 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
735 g_critical("Houston, we've had a problem. distance=%d", dist_units);
737 gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist), tmp_buf);
740 // Show track elevation for this position - to the nearest whole number
741 if (trackpoint && widgets->w_cur_elevation) {
742 static gchar tmp_buf[20];
743 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
744 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d ft", (int)VIK_METERS_TO_FEET(trackpoint->altitude));
746 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d m", (int)trackpoint->altitude);
747 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elevation), tmp_buf);
750 widgets->blob_tp = trackpoint;
752 if ( widgets->altitudes == NULL )
755 GtkWidget *window = gtk_widget_get_toplevel (event_box);
756 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
757 GtkWidget *image = GTK_WIDGET(child->data);
759 gint y_blob = blobby_altitude (x, widgets);
761 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
762 if (widgets->is_marker_drawn) {
763 gdouble pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
765 marker_x = (pc * widgets->profile_width) + MARGIN;
769 save_image_and_draw_graph_marks (image,
771 window->style->black_gc,
774 &widgets->elev_graph_saved_img,
775 widgets->profile_width,
776 widgets->profile_height,
777 &widgets->is_marker_drawn,
778 &widgets->is_blob_drawn);
783 void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
785 VikTrack *tr = pass_along[0];
786 PropWidgets *widgets = pass_along[3];
787 int mouse_x, mouse_y;
788 GdkModifierType state;
791 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
795 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
798 if (x > widgets->profile_width)
799 x = widgets->profile_width;
801 gdouble meters_from_start;
802 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / widgets->profile_width, &meters_from_start );
803 if (trackpoint && widgets->w_cur_gradient_dist) {
804 static gchar tmp_buf[20];
805 vik_units_distance_t dist_units = a_vik_get_units_distance ();
806 switch (dist_units) {
807 case VIK_UNITS_DISTANCE_KILOMETRES:
808 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
810 case VIK_UNITS_DISTANCE_MILES:
811 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
814 g_critical("Houston, we've had a problem. distance=%d", dist_units);
816 gtk_label_set_text(GTK_LABEL(widgets->w_cur_gradient_dist), tmp_buf);
819 // Show track gradient for this position - to the nearest whole number
820 if (trackpoint && widgets->w_cur_gradient_gradient) {
821 static gchar tmp_buf[20];
823 double gradient = widgets->gradients[(int) x];
825 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d%%", (int)gradient);
826 gtk_label_set_text(GTK_LABEL(widgets->w_cur_gradient_gradient), tmp_buf);
829 widgets->blob_tp = trackpoint;
831 if ( widgets->gradients == NULL )
834 GtkWidget *window = gtk_widget_get_toplevel (event_box);
835 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
836 GtkWidget *image = GTK_WIDGET(child->data);
838 gint y_blob = blobby_gradient (x, widgets);
840 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
841 if (widgets->is_marker_drawn) {
842 gdouble pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
844 marker_x = (pc * widgets->profile_width) + MARGIN;
848 save_image_and_draw_graph_marks (image,
850 window->style->black_gc,
853 &widgets->gradient_graph_saved_img,
854 widgets->profile_width,
855 widgets->profile_height,
856 &widgets->is_marker_drawn,
857 &widgets->is_blob_drawn);
862 void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
864 VikTrack *tr = pass_along[0];
865 PropWidgets *widgets = pass_along[3];
866 int mouse_x, mouse_y;
867 GdkModifierType state;
870 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
874 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
877 if (x > widgets->profile_width)
878 x = widgets->profile_width;
880 time_t seconds_from_start;
881 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
882 if (trackpoint && widgets->w_cur_time) {
883 static gchar tmp_buf[20];
885 h = seconds_from_start/3600;
886 m = (seconds_from_start - h*3600)/60;
887 s = seconds_from_start - (3600*h) - (60*m);
888 g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
890 gtk_label_set_text(GTK_LABEL(widgets->w_cur_time), tmp_buf);
894 // Ensure ix is inbounds
895 if (ix == widgets->profile_width)
898 // Show track speed for this position
899 if (trackpoint && widgets->w_cur_speed) {
900 static gchar tmp_buf[20];
901 // Even if GPS speed available (trackpoint->speed), the text will correspond to the speed map shown
902 // No conversions needed as already in appropriate units
903 vik_units_speed_t speed_units = a_vik_get_units_speed ();
904 switch (speed_units) {
905 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
906 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f kph"), widgets->speeds[ix]);
908 case VIK_UNITS_SPEED_MILES_PER_HOUR:
909 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f mph"), widgets->speeds[ix]);
911 case VIK_UNITS_SPEED_KNOTS:
912 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f knots"), widgets->speeds[ix]);
915 // VIK_UNITS_SPEED_METRES_PER_SECOND:
916 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f m/s"), widgets->speeds[ix]);
919 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed), tmp_buf);
922 widgets->blob_tp = trackpoint;
924 if ( widgets->speeds == NULL )
927 GtkWidget *window = gtk_widget_get_toplevel (event_box);
928 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
929 GtkWidget *image = GTK_WIDGET(child->data);
931 gint y_blob = blobby_speed (x, widgets);
933 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
934 if (widgets->is_marker_drawn) {
935 gdouble pc = tp_percentage_by_time ( tr, widgets->marker_tp );
937 marker_x = (pc * widgets->profile_width) + MARGIN;
941 save_image_and_draw_graph_marks (image,
943 window->style->black_gc,
946 &widgets->speed_graph_saved_img,
947 widgets->profile_width,
948 widgets->profile_height,
949 &widgets->is_marker_drawn,
950 &widgets->is_blob_drawn);
956 * Update labels and blob marker on mouse moves in the distance/time graph
958 void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
960 VikTrack *tr = pass_along[0];
961 PropWidgets *widgets = pass_along[3];
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 ( tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
978 if (trackpoint && widgets->w_cur_dist_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_dist_time), tmp_buf);
990 // Ensure ix is inbounds
991 if (ix == widgets->profile_width)
994 if (trackpoint && widgets->w_cur_dist_dist) {
995 static gchar tmp_buf[20];
996 if ( a_vik_get_units_distance () == VIK_UNITS_DISTANCE_MILES )
997 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", widgets->distances[ix]);
999 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", widgets->distances[ix]);
1000 gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_dist), tmp_buf);
1003 widgets->blob_tp = trackpoint;
1005 if ( widgets->distances == 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_distance (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 ( tr, widgets->marker_tp );
1018 marker_x = (pc * widgets->profile_width) + MARGIN;
1022 save_image_and_draw_graph_marks (image,
1024 window->style->black_gc,
1027 &widgets->dist_graph_saved_img,
1028 widgets->profile_width,
1029 widgets->profile_height,
1030 &widgets->is_marker_drawn,
1031 &widgets->is_blob_drawn);
1037 * Update labels and blob marker on mouse moves in the elevation/time graph
1039 void track_et_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
1041 VikTrack *tr = pass_along[0];
1042 PropWidgets *widgets = pass_along[3];
1043 int mouse_x, mouse_y;
1044 GdkModifierType state;
1047 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
1051 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
1054 if (x > widgets->profile_width)
1055 x = widgets->profile_width;
1057 time_t seconds_from_start;
1058 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
1059 if (trackpoint && widgets->w_cur_elev_time) {
1060 static gchar tmp_buf[20];
1062 h = seconds_from_start/3600;
1063 m = (seconds_from_start - h*3600)/60;
1064 s = seconds_from_start - (3600*h) - (60*m);
1065 g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
1067 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elev_time), tmp_buf);
1071 // Ensure ix is inbounds
1072 if (ix == widgets->profile_width)
1075 if (trackpoint && widgets->w_cur_elev_elev) {
1076 static gchar tmp_buf[20];
1077 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
1078 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d ft", (int)VIK_METERS_TO_FEET(trackpoint->altitude));
1080 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d m", (int)trackpoint->altitude);
1081 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elev_elev), tmp_buf);
1084 widgets->blob_tp = trackpoint;
1086 if ( widgets->ats == NULL )
1089 GtkWidget *window = gtk_widget_get_toplevel (event_box);
1090 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
1091 GtkWidget *image = GTK_WIDGET(child->data);
1093 gint y_blob = blobby_altitude_time (x, widgets);
1095 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
1096 if (widgets->is_marker_drawn) {
1097 gdouble pc = tp_percentage_by_time ( tr, widgets->marker_tp );
1099 marker_x = (pc * widgets->profile_width) + MARGIN;
1103 save_image_and_draw_graph_marks (image,
1105 window->style->black_gc,
1108 &widgets->elev_time_graph_saved_img,
1109 widgets->profile_width,
1110 widgets->profile_height,
1111 &widgets->is_marker_drawn,
1112 &widgets->is_blob_drawn);
1117 void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
1119 VikTrack *tr = pass_along[0];
1120 PropWidgets *widgets = pass_along[3];
1121 int mouse_x, mouse_y;
1122 GdkModifierType state;
1125 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
1129 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
1132 if (x > widgets->profile_width)
1133 x = widgets->profile_width;
1135 gdouble meters_from_start;
1136 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / widgets->profile_width, &meters_from_start );
1137 if (trackpoint && widgets->w_cur_speed_dist) {
1138 static gchar tmp_buf[20];
1139 vik_units_distance_t dist_units = a_vik_get_units_distance ();
1140 switch (dist_units) {
1141 case VIK_UNITS_DISTANCE_KILOMETRES:
1142 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
1144 case VIK_UNITS_DISTANCE_MILES:
1145 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
1148 g_critical("Houston, we've had a problem. distance=%d", dist_units);
1150 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed_dist), tmp_buf);
1154 // Ensure ix is inbounds
1155 if (ix == widgets->profile_width)
1158 if ( widgets->speeds_dist == NULL )
1161 // Show track speed for this position
1162 if (widgets->w_cur_speed_speed) {
1163 static gchar tmp_buf[20];
1164 // Even if GPS speed available (trackpoint->speed), the text will correspond to the speed map shown
1165 // No conversions needed as already in appropriate units
1166 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1167 switch (speed_units) {
1168 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1169 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f kph"), widgets->speeds_dist[ix]);
1171 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1172 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f mph"), widgets->speeds_dist[ix]);
1174 case VIK_UNITS_SPEED_KNOTS:
1175 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f knots"), widgets->speeds_dist[ix]);
1178 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1179 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f m/s"), widgets->speeds_dist[ix]);
1182 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed_speed), tmp_buf);
1185 widgets->blob_tp = trackpoint;
1187 GtkWidget *window = gtk_widget_get_toplevel (event_box);
1188 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
1189 GtkWidget *image = GTK_WIDGET(child->data);
1191 gint y_blob = blobby_speed_dist (x, widgets);
1193 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
1194 if (widgets->is_marker_drawn) {
1195 gdouble pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
1197 marker_x = (pc * widgets->profile_width) + MARGIN;
1201 save_image_and_draw_graph_marks (image,
1203 window->style->black_gc,
1206 &widgets->speed_dist_graph_saved_img,
1207 widgets->profile_width,
1208 widgets->profile_height,
1209 &widgets->is_marker_drawn,
1210 &widgets->is_blob_drawn);
1216 * Draws DEM points and a respresentative speed on the supplied pixmap
1217 * (which is the elevations graph)
1219 static void draw_dem_alt_speed_dist(VikTrack *tr,
1225 gdouble max_speed_in,
1234 gdouble max_speed = 0;
1235 gdouble total_length = vik_track_get_length_including_gaps(tr);
1237 // Calculate the max speed factor
1239 max_speed = max_speed_in * 110 / 100;
1242 for (iter = tr->trackpoints->next; iter; iter = iter->next) {
1244 dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
1245 &(VIK_TRACKPOINT(iter->prev->data)->coord) );
1246 x = (width * dist)/total_length + margin;
1248 gint16 elev = a_dems_get_elev_by_coord(&(VIK_TRACKPOINT(iter->data)->coord), VIK_DEM_INTERPOL_BEST);
1250 if ( elev != VIK_DEM_INVALID_ELEVATION ) {
1251 // Convert into height units
1252 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
1253 elev = VIK_METERS_TO_FEET(elev);
1254 // No conversion needed if already in metres
1256 // consider chunk size
1257 int y_alt = height - ((height * elev)/(chunksa[cia]*LINES) );
1258 gdk_draw_rectangle(GDK_DRAWABLE(pix), alt_gc, TRUE, x-2, y_alt-2, 4, 4);
1262 // This is just a speed indicator - no actual values can be inferred by user
1263 if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
1264 int y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
1265 gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
1272 * Draw just the height profile image
1274 static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1284 // Free previous allocation
1285 if ( widgets->altitudes )
1286 g_free ( widgets->altitudes );
1288 widgets->altitudes = vik_track_make_elevation_map ( tr, widgets->profile_width );
1290 if ( widgets->altitudes == NULL )
1293 // Convert into appropriate units
1294 vik_units_height_t height_units = a_vik_get_units_height ();
1295 if ( height_units == VIK_UNITS_HEIGHT_FEET ) {
1296 // Convert altitudes into feet units
1297 for ( i = 0; i < widgets->profile_width; i++ ) {
1298 widgets->altitudes[i] = VIK_METERS_TO_FEET(widgets->altitudes[i]);
1301 // Otherwise leave in metres
1303 minmax_array(widgets->altitudes, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
1305 get_new_min_and_chunk_index_altitude (widgets->min_altitude, widgets->max_altitude, &widgets->draw_min_altitude, &widgets->cia);
1308 mina = widgets->draw_min_altitude;
1309 maxa = widgets->max_altitude;
1311 window = gtk_widget_get_toplevel (widgets->elev_box);
1313 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1315 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1317 no_alt_info = gdk_gc_new ( window->window );
1318 gdk_color_parse ( "yellow", &color );
1319 gdk_gc_set_rgb_fg_color ( no_alt_info, &color);
1321 /* clear the image */
1322 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
1323 TRUE, 0, 0, MARGIN, widgets->profile_height);
1324 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
1325 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1328 for (i=0; i<=LINES; i++) {
1329 PangoFontDescription *pfd;
1330 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1334 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1335 pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
1336 pango_layout_set_font_description (pl, pfd);
1337 pango_font_description_free (pfd);
1338 switch (height_units) {
1339 case VIK_UNITS_HEIGHT_METRES:
1340 sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
1342 case VIK_UNITS_HEIGHT_FEET:
1343 // NB values already converted into feet
1344 sprintf(s, "%8dft", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
1348 g_critical("Houston, we've had a problem. height=%d", height_units);
1350 pango_layout_set_text(pl, s, -1);
1351 pango_layout_get_pixel_size (pl, &w, &h);
1352 gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3,
1353 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1355 gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
1356 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1357 g_object_unref ( G_OBJECT ( pl ) );
1361 /* draw elevations */
1362 for ( i = 0; i < widgets->profile_width; i++ )
1363 if ( widgets->altitudes[i] == VIK_DEFAULT_ALTITUDE )
1364 gdk_draw_line ( GDK_DRAWABLE(pix), no_alt_info,
1365 i + MARGIN, 0, i + MARGIN, widgets->profile_height );
1367 gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3],
1368 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->altitudes[i]-mina)/(chunksa[widgets->cia]*LINES) );
1370 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)) ||
1371 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)) ) {
1373 GdkGC *dem_alt_gc = gdk_gc_new ( window->window );
1374 GdkGC *gps_speed_gc = gdk_gc_new ( window->window );
1376 gdk_color_parse ( "green", &color );
1377 gdk_gc_set_rgb_fg_color ( dem_alt_gc, &color);
1379 gdk_color_parse ( "red", &color );
1380 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1382 // Ensure somekind of max speed when not set
1383 if ( widgets->max_speed < 0.01 )
1384 widgets->max_speed = vik_track_get_max_speed(tr);
1386 draw_dem_alt_speed_dist(tr,
1394 widgets->profile_width,
1395 widgets->profile_height,
1397 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)),
1398 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
1400 g_object_unref ( G_OBJECT(dem_alt_gc) );
1401 g_object_unref ( G_OBJECT(gps_speed_gc) );
1405 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1407 g_object_unref ( G_OBJECT(pix) );
1408 g_object_unref ( G_OBJECT(no_alt_info) );
1412 * Draws representative speed on the supplied pixmap
1413 * (which is the gradients graph)
1415 static void draw_speed_dist(VikTrack *tr,
1418 gdouble max_speed_in,
1425 gdouble max_speed = 0;
1426 gdouble total_length = vik_track_get_length_including_gaps(tr);
1428 // Calculate the max speed factor
1430 max_speed = max_speed_in * 110 / 100;
1433 for (iter = tr->trackpoints->next; iter; iter = iter->next) {
1435 dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
1436 &(VIK_TRACKPOINT(iter->prev->data)->coord) );
1437 x = (width * dist)/total_length + margin;
1439 // This is just a speed indicator - no actual values can be inferred by user
1440 if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
1441 int y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
1442 gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
1449 * Draw just the gradient image
1451 static void draw_gradients (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1460 // Free previous allocation
1461 if ( widgets->gradients )
1462 g_free ( widgets->gradients );
1464 widgets->gradients = vik_track_make_gradient_map ( tr, widgets->profile_width );
1466 if ( widgets->gradients == NULL )
1469 minmax_array(widgets->gradients, &widgets->min_gradient, &widgets->max_gradient, TRUE, widgets->profile_width);
1471 get_new_min_and_chunk_index_gradient (widgets->min_gradient, widgets->max_gradient, &widgets->draw_min_gradient, &widgets->cig);
1474 mina = widgets->draw_min_gradient;
1476 window = gtk_widget_get_toplevel (widgets->gradient_box);
1478 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1480 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1482 /* clear the image */
1483 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
1484 TRUE, 0, 0, MARGIN, widgets->profile_height);
1485 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
1486 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1489 for (i=0; i<=LINES; i++) {
1490 PangoFontDescription *pfd;
1491 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1495 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1496 pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
1497 pango_layout_set_font_description (pl, pfd);
1498 pango_font_description_free (pfd);
1499 sprintf(s, "%8d%%", (int)(mina + (LINES-i)*chunksg[widgets->cig]));
1500 pango_layout_set_text(pl, s, -1);
1501 pango_layout_get_pixel_size (pl, &w, &h);
1502 gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3,
1503 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1505 gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
1506 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1507 g_object_unref ( G_OBJECT ( pl ) );
1511 /* draw gradients */
1512 for ( i = 0; i < widgets->profile_width; i++ )
1513 gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3],
1514 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->gradients[i]-mina)/(chunksg[widgets->cig]*LINES) );
1516 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_gradient_gps_speed)) ) {
1517 GdkGC *gps_speed_gc = gdk_gc_new ( window->window );
1519 gdk_color_parse ( "red", &color );
1520 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1522 // Ensure somekind of max speed when not set
1523 if ( widgets->max_speed < 0.01 )
1524 widgets->max_speed = vik_track_get_max_speed(tr);
1530 widgets->profile_width,
1531 widgets->profile_height,
1533 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
1535 g_object_unref ( G_OBJECT(gps_speed_gc) );
1539 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1541 g_object_unref ( G_OBJECT(pix) );
1545 * Draw just the speed (velocity)/time image
1547 static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
1554 // Free previous allocation
1555 if ( widgets->speeds )
1556 g_free ( widgets->speeds );
1558 widgets->speeds = vik_track_make_speed_map ( tr, widgets->profile_width );
1559 if ( widgets->speeds == NULL )
1562 // Convert into appropriate units
1563 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1564 switch (speed_units) {
1565 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1566 for ( i = 0; i < widgets->profile_width; i++ ) {
1567 widgets->speeds[i] = VIK_MPS_TO_KPH(widgets->speeds[i]);
1570 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1571 for ( i = 0; i < widgets->profile_width; i++ ) {
1572 widgets->speeds[i] = VIK_MPS_TO_MPH(widgets->speeds[i]);
1575 case VIK_UNITS_SPEED_KNOTS:
1576 for ( i = 0; i < widgets->profile_width; i++ ) {
1577 widgets->speeds[i] = VIK_MPS_TO_KNOTS(widgets->speeds[i]);
1581 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1582 // No need to convert as already in m/s
1586 window = gtk_widget_get_toplevel (widgets->speed_box);
1588 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1590 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1592 minmax_array(widgets->speeds, &widgets->min_speed, &widgets->max_speed, FALSE, widgets->profile_width);
1593 if (widgets->min_speed < 0.0)
1594 widgets->min_speed = 0; /* splines sometimes give negative speeds */
1596 /* Find suitable chunk index */
1597 get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed, chunkss, sizeof(chunkss)/sizeof(chunkss[0]), &widgets->draw_min_speed, &widgets->cis);
1600 mins = widgets->draw_min_speed;
1602 /* clear the image */
1603 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
1604 TRUE, 0, 0, MARGIN, widgets->profile_height);
1605 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
1606 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1609 for (i=0; i<=LINES; i++) {
1610 PangoFontDescription *pfd;
1611 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1615 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1616 pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
1617 pango_layout_set_font_description (pl, pfd);
1618 pango_font_description_free (pfd);
1619 // NB: No need to convert here anymore as numbers are in the appropriate units
1620 switch (speed_units) {
1621 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1622 sprintf(s, "%8dkm/h", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1624 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1625 sprintf(s, "%8dmph", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1627 case VIK_UNITS_SPEED_METRES_PER_SECOND:
1628 sprintf(s, "%8dm/s", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1630 case VIK_UNITS_SPEED_KNOTS:
1631 sprintf(s, "%8dknots", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1635 g_critical("Houston, we've had a problem. speed=%d", speed_units);
1638 pango_layout_set_text(pl, s, -1);
1639 pango_layout_get_pixel_size (pl, &w, &h);
1640 gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3,
1641 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1643 gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
1644 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1645 g_object_unref ( G_OBJECT ( pl ) );
1651 for ( i = 0; i < widgets->profile_width; i++ )
1652 gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3],
1653 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds[i]-mins)/(chunkss[widgets->cis]*LINES) );
1656 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_gps_speed)) ) {
1658 GdkGC *gps_speed_gc = gdk_gc_new ( window->window );
1660 gdk_color_parse ( "red", &color );
1661 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1663 time_t beg_time = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
1664 time_t dur = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp - beg_time;
1667 for (iter = tr->trackpoints; iter; iter = iter->next) {
1668 gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed;
1669 if (isnan(gps_speed))
1671 switch (speed_units) {
1672 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1673 gps_speed = VIK_MPS_TO_KPH(gps_speed);
1675 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1676 gps_speed = VIK_MPS_TO_MPH(gps_speed);
1678 case VIK_UNITS_SPEED_KNOTS:
1679 gps_speed = VIK_MPS_TO_KNOTS(gps_speed);
1682 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1683 // No need to convert as already in m/s
1686 int x = MARGIN + widgets->profile_width * (VIK_TRACKPOINT(iter->data)->timestamp - beg_time) / dur;
1687 int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cis]*LINES);
1688 gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
1690 g_object_unref ( G_OBJECT(gps_speed_gc) );
1694 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1696 g_object_unref ( G_OBJECT(pix) );
1700 * Draw just the distance/time image
1702 static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1709 // Free previous allocation
1710 if ( widgets->distances )
1711 g_free ( widgets->distances );
1713 widgets->distances = vik_track_make_distance_map ( tr, widgets->profile_width );
1714 if ( widgets->distances == NULL )
1717 // Convert into appropriate units
1718 vik_units_distance_t dist_units = a_vik_get_units_distance ();
1719 if ( dist_units == VIK_UNITS_DISTANCE_MILES ) {
1720 for ( i = 0; i < widgets->profile_width; i++ ) {
1721 widgets->distances[i] = VIK_METERS_TO_MILES(widgets->distances[i]);
1725 // Metres - but want in kms
1726 for ( i = 0; i < widgets->profile_width; i++ ) {
1727 widgets->distances[i] = widgets->distances[i]/1000.0;
1731 window = gtk_widget_get_toplevel (widgets->dist_box);
1733 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1735 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1737 // easy to work out min / max of distance!
1739 // mind = 0.0; - Thus not used
1740 if ( dist_units == VIK_UNITS_DISTANCE_MILES )
1741 maxd = VIK_METERS_TO_MILES(vik_track_get_length_including_gaps (tr));
1743 maxd = vik_track_get_length_including_gaps (tr) / 1000.0;
1745 /* Find suitable chunk index */
1746 gdouble dummy = 0.0; // expect this to remain the same! (not that it's used)
1747 get_new_min_and_chunk_index (0, maxd, chunksd, sizeof(chunksd)/sizeof(chunksd[0]), &dummy, &widgets->cid);
1749 /* clear the image */
1750 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
1751 TRUE, 0, 0, MARGIN, widgets->profile_height);
1752 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
1753 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1756 for (i=0; i<=LINES; i++) {
1757 PangoFontDescription *pfd;
1758 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1762 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1763 pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
1764 pango_layout_set_font_description (pl, pfd);
1765 pango_font_description_free (pfd);
1766 if ( dist_units == VIK_UNITS_DISTANCE_MILES )
1767 sprintf(s, _("%.1f miles"), ((LINES-i)*chunksd[widgets->cid]));
1769 sprintf(s, _("%.1f km"), ((LINES-i)*chunksd[widgets->cid]));
1771 pango_layout_set_text(pl, s, -1);
1772 pango_layout_get_pixel_size (pl, &w, &h);
1773 gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3,
1774 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1776 gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
1777 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1778 g_object_unref ( G_OBJECT ( pl ) );
1783 for ( i = 0; i < widgets->profile_width; i++ )
1784 gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3],
1785 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->distances[i])/(chunksd[widgets->cid]*LINES) );
1787 // Show speed indicator
1788 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_dist_speed)) ) {
1789 GdkGC *dist_speed_gc = gdk_gc_new ( window->window );
1791 gdk_color_parse ( "red", &color );
1792 gdk_gc_set_rgb_fg_color ( dist_speed_gc, &color);
1794 gdouble max_speed = 0;
1795 max_speed = widgets->max_speed * 110 / 100;
1797 // This is just an indicator - no actual values can be inferred by user
1799 for ( i = 0; i < widgets->profile_width; i++ ) {
1800 int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
1801 gdk_draw_rectangle(GDK_DRAWABLE(pix), dist_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
1803 g_object_unref ( G_OBJECT(dist_speed_gc) );
1807 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1809 g_object_unref ( G_OBJECT(pix) );
1814 * Draw just the elevation/time image
1816 static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1823 // Free previous allocation
1825 g_free ( widgets->ats );
1827 widgets->ats = vik_track_make_elevation_time_map ( tr, widgets->profile_width );
1829 if ( widgets->ats == NULL )
1832 // Convert into appropriate units
1833 vik_units_height_t height_units = a_vik_get_units_height ();
1834 if ( height_units == VIK_UNITS_HEIGHT_FEET ) {
1835 // Convert altitudes into feet units
1836 for ( i = 0; i < widgets->profile_width; i++ ) {
1837 widgets->ats[i] = VIK_METERS_TO_FEET(widgets->ats[i]);
1840 // Otherwise leave in metres
1842 minmax_array(widgets->ats, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
1844 get_new_min_and_chunk_index_altitude (widgets->min_altitude, widgets->max_altitude, &widgets->draw_min_altitude_time, &widgets->ciat);
1847 mina = widgets->draw_min_altitude_time;
1849 window = gtk_widget_get_toplevel (widgets->elev_time_box);
1851 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1853 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1855 /* clear the image */
1856 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
1857 TRUE, 0, 0, MARGIN, widgets->profile_height);
1858 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
1859 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1862 for (i=0; i<=LINES; i++) {
1863 PangoFontDescription *pfd;
1864 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1868 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1869 pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
1870 pango_layout_set_font_description (pl, pfd);
1871 pango_font_description_free (pfd);
1872 switch (height_units) {
1873 case VIK_UNITS_HEIGHT_METRES:
1874 sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->ciat]));
1876 case VIK_UNITS_HEIGHT_FEET:
1877 // NB values already converted into feet
1878 sprintf(s, "%8dft", (int)(mina + (LINES-i)*chunksa[widgets->ciat]));
1882 g_critical("Houston, we've had a problem. height=%d", height_units);
1884 pango_layout_set_text(pl, s, -1);
1885 pango_layout_get_pixel_size (pl, &w, &h);
1886 gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3,
1887 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1889 gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
1890 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1891 g_object_unref ( G_OBJECT ( pl ) );
1895 /* draw elevations */
1896 for ( i = 0; i < widgets->profile_width; i++ )
1897 gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3],
1898 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->ats[i]-mina)/(chunksa[widgets->ciat]*LINES) );
1900 // Show speed indicator
1901 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_elev_speed)) ) {
1902 GdkGC *elev_speed_gc = gdk_gc_new ( window->window );
1904 gdk_color_parse ( "red", &color );
1905 gdk_gc_set_rgb_fg_color ( elev_speed_gc, &color);
1907 gdouble max_speed = 0;
1908 max_speed = widgets->max_speed * 110 / 100;
1910 // This is just an indicator - no actual values can be inferred by user
1912 for ( i = 0; i < widgets->profile_width; i++ ) {
1913 int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
1914 gdk_draw_rectangle(GDK_DRAWABLE(pix), elev_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
1916 g_object_unref ( G_OBJECT(elev_speed_gc) );
1920 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1922 g_object_unref ( G_OBJECT(pix) );
1927 * Draw just the speed/distance image
1929 static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
1936 // Free previous allocation
1937 if ( widgets->speeds_dist )
1938 g_free ( widgets->speeds_dist );
1940 widgets->speeds_dist = vik_track_make_speed_dist_map ( tr, widgets->profile_width );
1941 if ( widgets->speeds_dist == NULL )
1944 // Convert into appropriate units
1945 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1946 switch (speed_units) {
1947 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1948 for ( i = 0; i < widgets->profile_width; i++ ) {
1949 widgets->speeds_dist[i] = VIK_MPS_TO_KPH(widgets->speeds_dist[i]);
1952 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1953 for ( i = 0; i < widgets->profile_width; i++ ) {
1954 widgets->speeds_dist[i] = VIK_MPS_TO_MPH(widgets->speeds_dist[i]);
1957 case VIK_UNITS_SPEED_KNOTS:
1958 for ( i = 0; i < widgets->profile_width; i++ ) {
1959 widgets->speeds_dist[i] = VIK_MPS_TO_KNOTS(widgets->speeds_dist[i]);
1963 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1964 // No need to convert as already in m/s
1968 window = gtk_widget_get_toplevel (widgets->speed_dist_box);
1970 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1972 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1974 // OK to resuse min_speed here
1975 minmax_array(widgets->speeds_dist, &widgets->min_speed, &widgets->max_speed_dist, FALSE, widgets->profile_width);
1976 if (widgets->min_speed < 0.0)
1977 widgets->min_speed = 0; /* splines sometimes give negative speeds */
1979 /* Find suitable chunk index */
1980 get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed_dist, chunkss, sizeof(chunkss)/sizeof(chunkss[0]), &widgets->draw_min_speed, &widgets->cisd);
1983 mins = widgets->draw_min_speed;
1985 /* clear the image */
1986 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
1987 TRUE, 0, 0, MARGIN, widgets->profile_height);
1988 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
1989 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1992 for (i=0; i<=LINES; i++) {
1993 PangoFontDescription *pfd;
1994 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1998 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1999 pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
2000 pango_layout_set_font_description (pl, pfd);
2001 pango_font_description_free (pfd);
2002 // NB: No need to convert here anymore as numbers are in the appropriate units
2003 switch (speed_units) {
2004 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2005 sprintf(s, "%8dkm/h", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
2007 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2008 sprintf(s, "%8dmph", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
2010 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2011 sprintf(s, "%8dm/s", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
2013 case VIK_UNITS_SPEED_KNOTS:
2014 sprintf(s, "%8dknots", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
2018 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2021 pango_layout_set_text(pl, s, -1);
2022 pango_layout_get_pixel_size (pl, &w, &h);
2023 gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3,
2024 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
2026 gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
2027 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
2028 g_object_unref ( G_OBJECT ( pl ) );
2034 for ( i = 0; i < widgets->profile_width; i++ )
2035 gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3],
2036 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds_dist[i]-mins)/(chunkss[widgets->cisd]*LINES) );
2039 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_sd_gps_speed)) ) {
2041 GdkGC *gps_speed_gc = gdk_gc_new ( window->window );
2043 gdk_color_parse ( "red", &color );
2044 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
2046 gdouble dist = vik_track_get_length_including_gaps(tr);
2047 gdouble dist_tp = 0.0;
2049 GList *iter = tr->trackpoints;
2050 for (iter = iter->next; iter; iter = iter->next) {
2051 gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed;
2052 if (isnan(gps_speed))
2054 switch (speed_units) {
2055 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2056 gps_speed = VIK_MPS_TO_KPH(gps_speed);
2058 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2059 gps_speed = VIK_MPS_TO_MPH(gps_speed);
2061 case VIK_UNITS_SPEED_KNOTS:
2062 gps_speed = VIK_MPS_TO_KNOTS(gps_speed);
2065 // VIK_UNITS_SPEED_METRES_PER_SECOND:
2066 // No need to convert as already in m/s
2069 dist_tp += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord), &(VIK_TRACKPOINT(iter->prev->data)->coord) );
2070 int x = MARGIN + (widgets->profile_width * dist_tp / dist);
2071 int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cisd]*LINES);
2072 gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
2074 g_object_unref ( G_OBJECT(gps_speed_gc) );
2078 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
2080 g_object_unref ( G_OBJECT(pix) );
2087 static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean resized )
2089 VikTrack *tr = pass_along[0];
2090 PropWidgets *widgets = pass_along[3];
2092 // Draw graphs even if they are not visible
2094 GList *child = NULL;
2095 GtkWidget *image = NULL;
2096 GtkWidget *window = gtk_widget_get_toplevel(widget);
2098 gdouble pc_blob = NAN;
2101 if (widgets->elev_box != NULL) {
2103 // Saved image no longer any good as we've resized, so we remove it here
2104 if (resized && widgets->elev_graph_saved_img.img) {
2105 g_object_unref(widgets->elev_graph_saved_img.img);
2106 widgets->elev_graph_saved_img.img = NULL;
2107 widgets->elev_graph_saved_img.saved = FALSE;
2110 child = gtk_container_get_children(GTK_CONTAINER(widgets->elev_box));
2111 draw_elevations (GTK_WIDGET(child->data), tr, widgets );
2113 image = GTK_WIDGET(child->data);
2116 // Ensure marker or blob are redrawn if necessary
2117 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2119 pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
2120 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2122 if (widgets->is_blob_drawn) {
2123 pc_blob = tp_percentage_by_distance ( tr, widgets->blob_tp, widgets->track_length_inc_gaps );
2124 if (!isnan(pc_blob)) {
2125 x_blob = (pc_blob * widgets->profile_width);
2127 y_blob = blobby_altitude (x_blob, widgets);
2130 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2132 marker_x = (pc * widgets->profile_width) + MARGIN;
2135 save_image_and_draw_graph_marks (image,
2137 window->style->black_gc,
2140 &widgets->elev_graph_saved_img,
2141 widgets->profile_width,
2142 widgets->profile_height,
2143 &widgets->is_marker_drawn,
2144 &widgets->is_blob_drawn);
2149 if (widgets->gradient_box != NULL) {
2151 // Saved image no longer any good as we've resized, so we remove it here
2152 if (resized && widgets->gradient_graph_saved_img.img) {
2153 g_object_unref(widgets->gradient_graph_saved_img.img);
2154 widgets->gradient_graph_saved_img.img = NULL;
2155 widgets->gradient_graph_saved_img.saved = FALSE;
2158 child = gtk_container_get_children(GTK_CONTAINER(widgets->gradient_box));
2159 draw_gradients (GTK_WIDGET(child->data), tr, widgets );
2161 image = GTK_WIDGET(child->data);
2164 // Ensure marker or blob are redrawn if necessary
2165 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2167 pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
2168 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2170 if (widgets->is_blob_drawn) {
2171 pc_blob = tp_percentage_by_distance ( tr, widgets->blob_tp, widgets->track_length_inc_gaps );
2172 if (!isnan(pc_blob)) {
2173 x_blob = (pc_blob * widgets->profile_width);
2175 y_blob = blobby_gradient (x_blob, widgets);
2178 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2180 marker_x = (pc * widgets->profile_width) + MARGIN;
2183 save_image_and_draw_graph_marks (image,
2185 window->style->black_gc,
2188 &widgets->gradient_graph_saved_img,
2189 widgets->profile_width,
2190 widgets->profile_height,
2191 &widgets->is_marker_drawn,
2192 &widgets->is_blob_drawn);
2197 if (widgets->speed_box != NULL) {
2199 // Saved image no longer any good as we've resized
2200 if (resized && widgets->speed_graph_saved_img.img) {
2201 g_object_unref(widgets->speed_graph_saved_img.img);
2202 widgets->speed_graph_saved_img.img = NULL;
2203 widgets->speed_graph_saved_img.saved = FALSE;
2206 child = gtk_container_get_children(GTK_CONTAINER(widgets->speed_box));
2207 draw_vt (GTK_WIDGET(child->data), tr, widgets );
2209 image = GTK_WIDGET(child->data);
2212 // Ensure marker or blob are redrawn if necessary
2213 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2215 pc = tp_percentage_by_time ( tr, widgets->marker_tp );
2217 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2219 if (widgets->is_blob_drawn) {
2220 pc_blob = tp_percentage_by_time ( tr, widgets->blob_tp );
2221 if (!isnan(pc_blob)) {
2222 x_blob = (pc_blob * widgets->profile_width);
2225 y_blob = blobby_speed (x_blob, widgets);
2228 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2230 marker_x = (pc * widgets->profile_width) + MARGIN;
2233 save_image_and_draw_graph_marks (image,
2235 window->style->black_gc,
2238 &widgets->speed_graph_saved_img,
2239 widgets->profile_width,
2240 widgets->profile_height,
2241 &widgets->is_marker_drawn,
2242 &widgets->is_blob_drawn);
2247 if (widgets->dist_box != NULL) {
2249 // Saved image no longer any good as we've resized
2250 if (resized && widgets->dist_graph_saved_img.img) {
2251 g_object_unref(widgets->dist_graph_saved_img.img);
2252 widgets->dist_graph_saved_img.img = NULL;
2253 widgets->dist_graph_saved_img.saved = FALSE;
2256 child = gtk_container_get_children(GTK_CONTAINER(widgets->dist_box));
2257 draw_dt (GTK_WIDGET(child->data), tr, widgets );
2259 image = GTK_WIDGET(child->data);
2262 // Ensure marker or blob are redrawn if necessary
2263 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2265 pc = tp_percentage_by_time ( tr, widgets->marker_tp );
2267 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2269 if (widgets->is_blob_drawn) {
2270 pc_blob = tp_percentage_by_time ( tr, widgets->blob_tp );
2271 if (!isnan(pc_blob)) {
2272 x_blob = (pc_blob * widgets->profile_width);
2275 y_blob = blobby_distance (x_blob, widgets);
2278 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2280 marker_x = (pc * widgets->profile_width) + MARGIN;
2283 save_image_and_draw_graph_marks (image,
2285 window->style->black_gc,
2288 &widgets->dist_graph_saved_img,
2289 widgets->profile_width,
2290 widgets->profile_height,
2291 &widgets->is_marker_drawn,
2292 &widgets->is_blob_drawn);
2296 // Draw Elevations in timely manner
2297 if (widgets->elev_time_box != NULL) {
2299 // Saved image no longer any good as we've resized
2300 if (resized && widgets->elev_time_graph_saved_img.img) {
2301 g_object_unref(widgets->elev_time_graph_saved_img.img);
2302 widgets->elev_time_graph_saved_img.img = NULL;
2303 widgets->elev_time_graph_saved_img.saved = FALSE;
2306 child = gtk_container_get_children(GTK_CONTAINER(widgets->elev_time_box));
2307 draw_et (GTK_WIDGET(child->data), tr, widgets );
2309 image = GTK_WIDGET(child->data);
2312 // Ensure marker or blob are redrawn if necessary
2313 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2315 pc = tp_percentage_by_time ( tr, widgets->marker_tp );
2317 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2319 if (widgets->is_blob_drawn) {
2320 pc_blob = tp_percentage_by_time ( tr, widgets->blob_tp );
2321 if (!isnan(pc_blob)) {
2322 x_blob = (pc_blob * widgets->profile_width);
2324 y_blob = blobby_altitude_time (x_blob, widgets);
2327 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2329 marker_x = (pc * widgets->profile_width) + MARGIN;
2332 save_image_and_draw_graph_marks (image,
2334 window->style->black_gc,
2337 &widgets->elev_time_graph_saved_img,
2338 widgets->profile_width,
2339 widgets->profile_height,
2340 &widgets->is_marker_drawn,
2341 &widgets->is_blob_drawn);
2345 // Draw speed distances
2346 if (widgets->speed_dist_box != NULL) {
2348 // Saved image no longer any good as we've resized, so we remove it here
2349 if (resized && widgets->speed_dist_graph_saved_img.img) {
2350 g_object_unref(widgets->speed_dist_graph_saved_img.img);
2351 widgets->speed_dist_graph_saved_img.img = NULL;
2352 widgets->speed_dist_graph_saved_img.saved = FALSE;
2355 child = gtk_container_get_children(GTK_CONTAINER(widgets->speed_dist_box));
2356 draw_sd (GTK_WIDGET(child->data), tr, widgets );
2358 image = GTK_WIDGET(child->data);
2361 // Ensure marker or blob are redrawn if necessary
2362 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2364 pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
2365 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2367 if (widgets->is_blob_drawn) {
2368 pc_blob = tp_percentage_by_distance ( tr, widgets->blob_tp, widgets->track_length_inc_gaps );
2369 if (!isnan(pc_blob)) {
2370 x_blob = (pc_blob * widgets->profile_width);
2372 y_blob = blobby_speed_dist (x_blob, widgets);
2375 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2377 marker_x = (pc * widgets->profile_width) + MARGIN;
2380 save_image_and_draw_graph_marks (image,
2382 window->style->black_gc,
2385 &widgets->speed_dist_graph_saved_img,
2386 widgets->profile_width,
2387 widgets->profile_height,
2388 &widgets->is_marker_drawn,
2389 &widgets->is_blob_drawn);
2396 * Configure/Resize the profile & speed/time images
2398 static gboolean configure_event ( GtkWidget *widget, GdkEventConfigure *event, gpointer *pass_along )
2400 PropWidgets *widgets = pass_along[3];
2402 if (widgets->configure_dialog) {
2403 // Determine size offsets between dialog size and size for images
2404 // Only on the initialisation of the dialog
2405 widgets->profile_width_offset = event->width - widgets->profile_width;
2406 widgets->profile_height_offset = event->height - widgets->profile_height;
2407 widgets->configure_dialog = FALSE;
2409 // Without this the settting, the dialog will only grow in vertical size - one can not then make it smaller!
2410 gtk_widget_set_size_request ( widget, widgets->profile_width+widgets->profile_width_offset, widgets->profile_height );
2411 // In fact this allows one to compress it a bit more vertically as I don't add on the height offset
2414 widgets->profile_width_old = widgets->profile_width;
2415 widgets->profile_height_old = widgets->profile_height;
2418 // Now adjust From Dialog size to get image size
2419 widgets->profile_width = event->width - widgets->profile_width_offset;
2420 widgets->profile_height = event->height - widgets->profile_height_offset;
2422 // ATM we receive configure_events when the dialog is moved and so no further action is necessary
2423 if ( !widgets->configure_dialog &&
2424 (widgets->profile_width_old == widgets->profile_width) && (widgets->profile_height_old == widgets->profile_height) )
2428 draw_all_graphs ( widget, pass_along, TRUE );
2434 * Create height profile widgets including the image and callbacks
2436 GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets, gdouble *min_alt, gdouble *max_alt)
2440 GtkWidget *eventbox;
2441 gpointer *pass_along;
2444 widgets->altitudes = vik_track_make_elevation_map ( tr, widgets->profile_width );
2446 if ( widgets->altitudes == NULL ) {
2447 *min_alt = *max_alt = VIK_DEFAULT_ALTITUDE;
2451 minmax_array(widgets->altitudes, min_alt, max_alt, TRUE, widgets->profile_width);
2453 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2454 image = gtk_image_new_from_pixmap ( pix, NULL );
2456 g_object_unref ( G_OBJECT(pix) );
2458 pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
2460 pass_along[1] = vlp;
2461 pass_along[2] = vvp;
2462 pass_along[3] = widgets;
2464 eventbox = gtk_event_box_new ();
2465 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_profile_click), pass_along );
2466 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_profile_move), pass_along );
2467 g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
2468 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2469 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_STRUCTURE_MASK);
2475 * Create height profile widgets including the image and callbacks
2477 GtkWidget *vik_trw_layer_create_gradient ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
2481 GtkWidget *eventbox;
2482 gpointer *pass_along;
2485 widgets->gradients = vik_track_make_gradient_map ( tr, widgets->profile_width );
2487 if ( widgets->gradients == NULL ) {
2491 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2492 image = gtk_image_new_from_pixmap ( pix, NULL );
2494 g_object_unref ( G_OBJECT(pix) );
2496 pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
2498 pass_along[1] = vlp;
2499 pass_along[2] = vvp;
2500 pass_along[3] = widgets;
2502 eventbox = gtk_event_box_new ();
2503 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_gradient_click), pass_along );
2504 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_gradient_move), pass_along );
2505 g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
2506 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2507 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_STRUCTURE_MASK);
2513 * Create speed/time widgets including the image and callbacks
2515 GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
2519 GtkWidget *eventbox;
2520 gpointer *pass_along;
2523 widgets->speeds = vik_track_make_speed_map ( tr, widgets->profile_width );
2524 if ( widgets->speeds == NULL )
2527 pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
2529 pass_along[1] = vlp;
2530 pass_along[2] = vvp;
2531 pass_along[3] = widgets;
2533 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2534 image = gtk_image_new_from_pixmap ( pix, NULL );
2537 /* XXX this can go out, it's just a helpful dev tool */
2540 GdkGC **colors[8] = { window->style->bg_gc,
2541 window->style->fg_gc,
2542 window->style->light_gc,
2543 window->style->dark_gc,
2544 window->style->mid_gc,
2545 window->style->text_gc,
2546 window->style->base_gc,
2547 window->style->text_aa_gc };
2548 for (i=0; i<5; i++) {
2549 for (j=0; j<8; j++) {
2550 gdk_draw_rectangle(GDK_DRAWABLE(pix), colors[j][i],
2551 TRUE, i*20, j*20, 20, 20);
2552 gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc,
2553 FALSE, i*20, j*20, 20, 20);
2559 g_object_unref ( G_OBJECT(pix) );
2561 eventbox = gtk_event_box_new ();
2562 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_vt_click), pass_along );
2563 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_vt_move), pass_along );
2564 g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
2565 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2566 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2572 * Create distance / time widgets including the image and callbacks
2574 GtkWidget *vik_trw_layer_create_dtdiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
2578 GtkWidget *eventbox;
2579 gpointer *pass_along;
2582 widgets->distances = vik_track_make_distance_map ( tr, widgets->profile_width );
2583 if ( widgets->distances == NULL )
2586 pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
2588 pass_along[1] = vlp;
2589 pass_along[2] = vvp;
2590 pass_along[3] = widgets;
2592 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2593 image = gtk_image_new_from_pixmap ( pix, NULL );
2595 g_object_unref ( G_OBJECT(pix) );
2597 eventbox = gtk_event_box_new ();
2598 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_dt_click), pass_along );
2599 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_dt_move), pass_along );
2600 g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
2601 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2602 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2608 * Create elevation / time widgets including the image and callbacks
2610 GtkWidget *vik_trw_layer_create_etdiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
2614 GtkWidget *eventbox;
2615 gpointer *pass_along;
2618 widgets->ats = vik_track_make_elevation_time_map ( tr, widgets->profile_width );
2619 if ( widgets->ats == NULL )
2622 pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
2624 pass_along[1] = vlp;
2625 pass_along[2] = vvp;
2626 pass_along[3] = widgets;
2628 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2629 image = gtk_image_new_from_pixmap ( pix, NULL );
2631 g_object_unref ( G_OBJECT(pix) );
2633 eventbox = gtk_event_box_new ();
2634 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_et_click), pass_along );
2635 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_et_move), pass_along );
2636 g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
2637 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2638 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2644 * Create speed/distance widgets including the image and callbacks
2646 GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
2650 GtkWidget *eventbox;
2651 gpointer *pass_along;
2654 widgets->speeds_dist = vik_track_make_speed_dist_map ( tr, widgets->profile_width );
2655 if ( widgets->speeds_dist == NULL )
2658 pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
2660 pass_along[1] = vlp;
2661 pass_along[2] = vvp;
2662 pass_along[3] = widgets;
2664 pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2665 image = gtk_image_new_from_pixmap ( pix, NULL );
2667 g_object_unref ( G_OBJECT(pix) );
2669 eventbox = gtk_event_box_new ();
2670 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_sd_click), pass_along );
2671 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_sd_move), pass_along );
2672 g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
2673 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2674 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2680 static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widgets)
2682 VikTrack *tr = widgets->tr;
2683 VikTrwLayer *vtl = widgets->vtl;
2684 gboolean keep_dialog = FALSE;
2686 /* FIXME: check and make sure the track still exists before doing anything to it */
2687 /* Note: destroying diaglog (eg, parent window exit) won't give "response" */
2689 case GTK_RESPONSE_DELETE_EVENT: /* received delete event (not from buttons) */
2690 case GTK_RESPONSE_REJECT:
2692 case GTK_RESPONSE_ACCEPT:
2693 vik_track_set_comment(tr, gtk_entry_get_text(GTK_ENTRY(widgets->w_comment)));
2695 case VIK_TRW_LAYER_PROPWIN_REVERSE:
2696 vik_track_reverse(tr);
2697 vik_layer_emit_update ( VIK_LAYER(vtl), FALSE );
2699 case VIK_TRW_LAYER_PROPWIN_DEL_DUP:
2700 vik_track_remove_dup_points(tr);
2701 /* above operation could have deleted current_tp or last_tp */
2702 trw_layer_cancel_tps_of_track ( vtl, tr );
2703 vik_layer_emit_update ( VIK_LAYER(vtl), FALSE );
2705 case VIK_TRW_LAYER_PROPWIN_SPLIT:
2707 /* get new tracks, add them and then the delete old one. old can still exist on clipboard. */
2710 VikTrack **tracks = vik_track_split_into_segments(tr, &ntracks);
2713 for ( i = 0; i < ntracks; i++ )
2716 new_tr_name = g_strdup_printf("%s #%d", widgets->tr->name, i+1);
2717 vik_trw_layer_add_track ( vtl, new_tr_name, tracks[i] );
2723 /* Don't let track destroy this dialog */
2724 vik_track_clear_property_dialog(tr);
2725 vik_trw_layer_delete_track ( vtl, tr );
2726 vik_layer_emit_update ( VIK_LAYER(vtl), FALSE ); /* chase thru the hoops */
2730 case VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER:
2732 GList *iter = tr->trackpoints;
2733 while ((iter = iter->next)) {
2734 if (widgets->marker_tp == VIK_TRACKPOINT(iter->data))
2738 a_dialog_msg(VIK_GTK_WINDOW_FROM_LAYER(vtl), GTK_MESSAGE_ERROR,
2739 _("Failed spliting track. Track unchanged"), NULL);
2744 gchar *r_name = g_strdup_printf("%s #2", widgets->tr->name);
2745 iter->prev->next = NULL;
2747 VikTrack *tr_right = vik_track_new();
2749 vik_track_set_comment ( tr_right, tr->comment );
2750 tr_right->visible = tr->visible;
2751 tr_right->trackpoints = iter;
2753 vik_trw_layer_add_track(vtl, r_name, tr_right);
2754 vik_layer_emit_update ( VIK_LAYER(vtl), FALSE );
2758 fprintf(stderr, "DEBUG: unknown response\n");
2762 /* Keep same behaviour for now: destroy dialog if click on any button */
2764 prop_widgets_free(widgets);
2765 vik_track_clear_property_dialog(tr);
2766 gtk_widget_destroy ( GTK_WIDGET(dialog) );
2771 * Force a redraw when checkbutton has been toggled to show/hide that information
2773 static void checkbutton_toggle_cb ( GtkToggleButton *togglebutton, gpointer *pass_along, gpointer dummy)
2775 PropWidgets *widgets = pass_along[3];
2776 // Even though not resized, we'll pretend it is -
2777 // as this invalidates the saved images (since the image may have changed)
2778 draw_all_graphs ( widgets->dialog, pass_along, TRUE);
2782 * Create the widgets for the given graph tab
2784 static GtkWidget *create_graph_page ( GtkWidget *graph,
2785 const gchar *markup,
2787 const gchar *markup2,
2789 GtkWidget *checkbutton1,
2790 gboolean checkbutton1_default,
2791 GtkWidget *checkbutton2,
2792 gboolean checkbutton2_default )
2794 GtkWidget *hbox = gtk_hbox_new ( FALSE, 10 );
2795 GtkWidget *vbox = gtk_vbox_new ( FALSE, 10 );
2796 GtkWidget *label = gtk_label_new (NULL);
2797 GtkWidget *label2 = gtk_label_new (NULL);
2798 gtk_box_pack_start (GTK_BOX(vbox), graph, FALSE, FALSE, 0);
2799 gtk_label_set_markup ( GTK_LABEL(label), markup );
2800 gtk_label_set_markup ( GTK_LABEL(label2), markup2 );
2801 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
2802 gtk_box_pack_start (GTK_BOX(hbox), value, FALSE, FALSE, 0);
2803 gtk_box_pack_start (GTK_BOX(hbox), label2, FALSE, FALSE, 0);
2804 gtk_box_pack_start (GTK_BOX(hbox), value2, FALSE, FALSE, 0);
2806 gtk_box_pack_end (GTK_BOX(hbox), checkbutton2, FALSE, FALSE, 0);
2807 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton2), checkbutton2_default);
2810 gtk_box_pack_end (GTK_BOX(hbox), checkbutton1, FALSE, FALSE, 0);
2811 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton1), checkbutton1_default);
2813 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
2818 void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *tr, gpointer vlp, VikViewport *vvp )
2820 /* FIXME: free widgets when destroy signal received */
2821 PropWidgets *widgets = prop_widgets_new();
2824 widgets->profile_width = PROPWIN_PROFILE_WIDTH;
2825 widgets->profile_height = PROPWIN_PROFILE_HEIGHT;
2826 gchar *title = g_strdup_printf(_("%s - Track Properties"), tr->name);
2827 GtkWidget *dialog = gtk_dialog_new_with_buttons (title,
2829 GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
2830 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
2831 _("Split at _Marker"), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER,
2832 _("Split _Segments"), VIK_TRW_LAYER_PROPWIN_SPLIT,
2833 _("_Reverse"), VIK_TRW_LAYER_PROPWIN_REVERSE,
2834 _("_Delete Dupl."), VIK_TRW_LAYER_PROPWIN_DEL_DUP,
2835 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2837 widgets->dialog = dialog;
2839 g_signal_connect(dialog, "response", G_CALLBACK(propwin_response_cb), widgets);
2842 guint32 tp_count, seg_count;
2844 gdouble min_alt, max_alt;
2845 widgets->elev_box = vik_trw_layer_create_profile(GTK_WIDGET(parent), tr, vlp, vvp, widgets, &min_alt, &max_alt);
2846 widgets->gradient_box = vik_trw_layer_create_gradient(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
2847 widgets->speed_box = vik_trw_layer_create_vtdiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
2848 widgets->dist_box = vik_trw_layer_create_dtdiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
2849 widgets->elev_time_box = vik_trw_layer_create_etdiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
2850 widgets->speed_dist_box = vik_trw_layer_create_sddiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
2851 GtkWidget *graphs = gtk_notebook_new();
2853 GtkWidget *content[20];
2857 static gchar *label_texts[] = { N_("<b>Comment:</b>"), N_("<b>Track Length:</b>"), N_("<b>Trackpoints:</b>"), N_("<b>Segments:</b>"), N_("<b>Duplicate Points:</b>"), N_("<b>Max Speed:</b>"), N_("<b>Avg. Speed:</b>"), N_("<b>Moving Avg. Speed:</b>"), N_("<b>Avg. Dist. Between TPs:</b>"), N_("<b>Elevation Range:</b>"), N_("<b>Total Elevation Gain/Loss:</b>"), N_("<b>Start:</b>"), N_("<b>End:</b>"), N_("<b>Duration:</b>") };
2858 static gchar tmp_buf[50];
2862 widgets->w_comment = gtk_entry_new ();
2864 gtk_entry_set_text ( GTK_ENTRY(widgets->w_comment), tr->comment );
2865 g_signal_connect_swapped ( widgets->w_comment, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
2866 content[cnt++] = widgets->w_comment;
2868 vik_units_distance_t dist_units = a_vik_get_units_distance ();
2870 // NB This value not shown yet - but is used by internal calculations
2871 widgets->track_length_inc_gaps = vik_track_get_length_including_gaps(tr);
2873 tr_len = widgets->track_length = vik_track_get_length(tr);
2874 switch (dist_units) {
2875 case VIK_UNITS_DISTANCE_KILOMETRES:
2876 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", tr_len/1000.0 );
2878 case VIK_UNITS_DISTANCE_MILES:
2879 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(tr_len) );
2882 g_critical("Houston, we've had a problem. distance=%d", dist_units);
2884 widgets->w_track_length = content[cnt++] = gtk_label_new ( tmp_buf );
2886 tp_count = vik_track_get_tp_count(tr);
2887 g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", tp_count );
2888 widgets->w_tp_count = content[cnt++] = gtk_label_new ( tmp_buf );
2890 seg_count = vik_track_get_segment_count(tr) ;
2891 g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", seg_count );
2892 widgets->w_segment_count = content[cnt++] = gtk_label_new ( tmp_buf );
2894 g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", vik_track_get_dup_point_count(tr) );
2895 widgets->w_duptp_count = content[cnt++] = gtk_label_new ( tmp_buf );
2897 vik_units_speed_t speed_units = a_vik_get_units_speed ();
2898 tmp_speed = vik_track_get_max_speed(tr);
2899 if ( tmp_speed == 0 )
2900 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2902 switch (speed_units) {
2903 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2904 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2906 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2907 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2909 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2910 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2912 case VIK_UNITS_SPEED_KNOTS:
2913 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2916 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2917 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2920 widgets->w_max_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2922 tmp_speed = vik_track_get_average_speed(tr);
2923 if ( tmp_speed == 0 )
2924 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2926 switch (speed_units) {
2927 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2928 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2930 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2931 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2933 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2934 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2936 case VIK_UNITS_SPEED_KNOTS:
2937 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2940 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2941 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2944 widgets->w_avg_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2946 // Use 60sec as the default period to be considered stopped
2947 // this is the TrackWaypoint draw stops default value 'vtl->stop_length'
2948 // however this variable is not directly accessible - and I don't expect it's often changed from the default
2949 // so ATM just put in the number
2950 tmp_speed = vik_track_get_average_speed_moving(tr, 60);
2951 if ( tmp_speed == 0 )
2952 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2954 switch (speed_units) {
2955 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2956 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2958 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2959 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2961 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2962 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2964 case VIK_UNITS_SPEED_KNOTS:
2965 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2968 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2969 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2972 widgets->w_mvg_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2974 switch (dist_units) {
2975 case VIK_UNITS_DISTANCE_KILOMETRES:
2976 // Even though kilometres, the average distance between points is going to be quite small so keep in metres
2977 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m", (tp_count - seg_count) == 0 ? 0 : tr_len / ( tp_count - seg_count ) );
2979 case VIK_UNITS_DISTANCE_MILES:
2980 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 )) );
2983 g_critical("Houston, we've had a problem. distance=%d", dist_units);
2985 widgets->w_avg_dist = content[cnt++] = gtk_label_new ( tmp_buf );
2987 vik_units_height_t height_units = a_vik_get_units_height ();
2988 if ( min_alt == VIK_DEFAULT_ALTITUDE )
2989 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2991 switch (height_units) {
2992 case VIK_UNITS_HEIGHT_METRES:
2993 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m - %.0f m", min_alt, max_alt );
2995 case VIK_UNITS_HEIGHT_FEET:
2996 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f feet - %.0f feet", VIK_METERS_TO_FEET(min_alt), VIK_METERS_TO_FEET(max_alt) );
2999 g_snprintf(tmp_buf, sizeof(tmp_buf), "--" );
3000 g_critical("Houston, we've had a problem. height=%d", height_units);
3003 widgets->w_elev_range = content[cnt++] = gtk_label_new ( tmp_buf );
3005 vik_track_get_total_elevation_gain(tr, &max_alt, &min_alt );
3006 if ( min_alt == VIK_DEFAULT_ALTITUDE )
3007 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
3009 switch (height_units) {
3010 case VIK_UNITS_HEIGHT_METRES:
3011 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m / %.0f m", max_alt, min_alt );
3013 case VIK_UNITS_HEIGHT_FEET:
3014 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f feet / %.0f feet", VIK_METERS_TO_FEET(max_alt), VIK_METERS_TO_FEET(min_alt) );
3017 g_snprintf(tmp_buf, sizeof(tmp_buf), "--" );
3018 g_critical("Houston, we've had a problem. height=%d", height_units);
3021 widgets->w_elev_gain = content[cnt++] = gtk_label_new ( tmp_buf );
3024 #define PACK(w) gtk_box_pack_start (GTK_BOX(right_vbox), w, FALSE, FALSE, 0);
3025 gtk_box_pack_start (GTK_BOX(right_vbox), e_cmt, FALSE, FALSE, 0);
3038 if ( tr->trackpoints && VIK_TRACKPOINT(tr->trackpoints->data)->timestamp )
3041 t1 = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
3042 t2 = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp;
3044 strncpy(tmp_buf, ctime(&t1), sizeof(tmp_buf));
3045 tmp_buf[sizeof(tmp_buf)-1] = 0;
3046 g_strchomp(tmp_buf);
3047 widgets->w_time_start = content[cnt++] = gtk_label_new(tmp_buf);
3049 strncpy(tmp_buf, ctime(&t2), sizeof(tmp_buf));
3050 tmp_buf[sizeof(tmp_buf)-1] = 0;
3051 g_strchomp(tmp_buf);
3052 widgets->w_time_end = content[cnt++] = gtk_label_new(tmp_buf);
3054 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%d minutes"), (int)(t2-t1)/60);
3055 widgets->w_time_dur = content[cnt++] = gtk_label_new(tmp_buf);
3057 widgets->w_time_start = content[cnt++] = gtk_label_new(_("No Data"));
3058 widgets->w_time_end = content[cnt++] = gtk_label_new(_("No Data"));
3059 widgets->w_time_dur = content[cnt++] = gtk_label_new(_("No Data"));
3062 table = GTK_TABLE(gtk_table_new (cnt, 2, FALSE));
3063 gtk_table_set_col_spacing (table, 0, 10);
3064 for (i=0; i<cnt; i++) {
3067 // Settings so the text positioning only moves around vertically when the dialog is resized
3068 // This also gives more room to see the track comment
3069 label = gtk_label_new(NULL);
3070 gtk_misc_set_alignment ( GTK_MISC(label), 1, 0.5 ); // Position text centrally in vertical plane
3071 gtk_label_set_markup ( GTK_LABEL(label), _(label_texts[i]) );
3072 gtk_table_attach ( table, label, 0, 1, i, i+1, GTK_FILL, GTK_SHRINK, 0, 0 );
3073 if (GTK_IS_MISC(content[i])) {
3074 gtk_misc_set_alignment ( GTK_MISC(content[i]), 0, 0.5 );
3076 gtk_table_attach_defaults ( table, content[i], 1, 2, i, i+1 );
3079 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), GTK_WIDGET(table), gtk_label_new(_("Statistics")));
3081 gpointer *pass_along;
3082 pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
3084 pass_along[1] = vlp;
3085 pass_along[2] = vvp;
3086 pass_along[3] = widgets;
3088 if ( widgets->elev_box ) {
3089 GtkWidget *page = NULL;
3090 widgets->w_cur_dist = gtk_label_new(_("No Data"));
3091 widgets->w_cur_elevation = gtk_label_new(_("No Data"));
3092 widgets->w_show_dem = gtk_check_button_new_with_mnemonic(_("Show D_EM"));
3093 widgets->w_show_alt_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3094 page = create_graph_page (widgets->elev_box,
3095 _("<b>Track Distance:</b>"), widgets->w_cur_dist,
3096 _("<b>Track Height:</b>"), widgets->w_cur_elevation,
3097 widgets->w_show_dem, TRUE,
3098 widgets->w_show_alt_gps_speed, TRUE);
3099 g_signal_connect (widgets->w_show_dem, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
3100 g_signal_connect (widgets->w_show_alt_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
3101 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-distance")));
3104 if ( widgets->gradient_box ) {
3105 GtkWidget *page = NULL;
3106 widgets->w_cur_gradient_dist = gtk_label_new(_("No Data"));
3107 widgets->w_cur_gradient_gradient = gtk_label_new(_("No Data"));
3108 widgets->w_show_gradient_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3109 page = create_graph_page (widgets->gradient_box,
3110 _("<b>Track Distance:</b>"), widgets->w_cur_gradient_dist,
3111 _("<b>Track Gradient:</b>"), widgets->w_cur_gradient_gradient,
3112 widgets->w_show_gradient_gps_speed, TRUE,
3114 g_signal_connect (widgets->w_show_gradient_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
3115 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Gradient-distance")));
3118 if ( widgets->speed_box ) {
3119 GtkWidget *page = NULL;
3120 widgets->w_cur_time = gtk_label_new(_("No Data"));
3121 widgets->w_cur_speed = gtk_label_new(_("No Data"));
3122 widgets->w_show_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3123 page = create_graph_page (widgets->speed_box,
3124 _("<b>Track Time:</b>"), widgets->w_cur_time,
3125 _("<b>Track Speed:</b>"), widgets->w_cur_speed,
3126 widgets->w_show_gps_speed, TRUE,
3128 g_signal_connect (widgets->w_show_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
3129 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-time")));
3132 if ( widgets->dist_box ) {
3133 GtkWidget *page = NULL;
3134 widgets->w_cur_dist_time = gtk_label_new(_("No Data"));
3135 widgets->w_cur_dist_dist = gtk_label_new(_("No Data"));
3136 widgets->w_show_dist_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
3137 page = create_graph_page (widgets->dist_box,
3138 _("<b>Track Distance:</b>"), widgets->w_cur_dist_dist,
3139 _("<b>Track Time:</b>"), widgets->w_cur_dist_time,
3140 widgets->w_show_dist_speed, FALSE,
3142 g_signal_connect (widgets->w_show_dist_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
3143 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Distance-time")));
3146 if ( widgets->elev_time_box ) {
3147 GtkWidget *page = NULL;
3148 widgets->w_cur_elev_time = gtk_label_new(_("No Data"));
3149 widgets->w_cur_elev_elev = gtk_label_new(_("No Data"));
3150 widgets->w_show_elev_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
3151 page = create_graph_page (widgets->elev_time_box,
3152 _("<b>Track Time:</b>"), widgets->w_cur_elev_time,
3153 _("<b>Track Height:</b>"), widgets->w_cur_elev_elev,
3154 widgets->w_show_elev_speed, FALSE,
3156 g_signal_connect (widgets->w_show_elev_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
3157 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-time")));
3160 if ( widgets->speed_dist_box ) {
3161 GtkWidget *page = NULL;
3162 widgets->w_cur_speed_dist = gtk_label_new(_("No Data"));
3163 widgets->w_cur_speed_speed = gtk_label_new(_("No Data"));
3164 widgets->w_show_sd_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3165 page = create_graph_page (widgets->speed_dist_box,
3166 _("<b>Track Distance:</b>"), widgets->w_cur_speed_dist,
3167 _("<b>Track Speed:</b>"), widgets->w_cur_speed_speed,
3168 widgets->w_show_sd_gps_speed, TRUE,
3170 g_signal_connect (widgets->w_show_sd_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
3171 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-distance")));
3174 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), graphs, FALSE, FALSE, 0);
3176 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
3178 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT, FALSE);
3179 if (vik_track_get_dup_point_count(tr) <= 0)
3180 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_DEL_DUP, FALSE);
3182 // On dialog realization configure_event casues the graphs to be initially drawn
3183 widgets->configure_dialog = TRUE;
3184 g_signal_connect ( G_OBJECT(dialog), "configure-event", G_CALLBACK (configure_event), pass_along);
3186 vik_track_set_property_dialog(tr, dialog);
3187 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
3188 gtk_widget_show_all ( dialog );
3193 * Update this property dialog
3194 * e.g. if the track has been renamed
3196 void vik_trw_layer_propwin_update ( VikTrack *trk )
3198 // If not displayed do nothing
3199 if ( !trk->property_dialog )
3202 // Update title with current name
3204 gchar *title = g_strdup_printf ( _("%s - Track Properties"), trk->name );
3205 gtk_window_set_title ( GTK_WINDOW(trk->property_dialog), title );