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
60 PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE,
61 PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE,
62 PROPWIN_GRAPH_TYPE_SPEED_TIME,
63 PROPWIN_GRAPH_TYPE_DISTANCE_TIME,
64 PROPWIN_GRAPH_TYPE_ELEVATION_TIME,
65 PROPWIN_GRAPH_TYPE_SPEED_DISTANCE,
66 PROPWIN_GRAPH_TYPE_END,
67 } VikPropWinGraphType_t;
69 /* (Hopefully!) Human friendly altitude grid sizes - note no fixed 'ratio' just numbers that look nice...*/
70 static const gdouble chunksa[] = {2.0, 5.0, 10.0, 15.0, 20.0,
71 25.0, 40.0, 50.0, 75.0, 100.0,
72 150.0, 200.0, 250.0, 375.0, 500.0,
73 750.0, 1000.0, 2000.0, 5000.0, 10000.0, 100000.0};
75 /* (Hopefully!) Human friendly gradient grid sizes - note no fixed 'ratio' just numbers that look nice...*/
76 static const gdouble chunksg[] = {1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
77 12.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 75.0,
78 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
79 750.0, 1000.0, 10000.0};
81 /* (Hopefully!) Human friendly grid sizes - note no fixed 'ratio' just numbers that look nice...*/
82 /* As need to cover walking speeds - have many low numbers (but also may go up to airplane speeds!) */
83 static const gdouble chunkss[] = {1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
84 15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
85 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
86 750.0, 1000.0, 10000.0};
88 /* (Hopefully!) Human friendly distance grid sizes - note no fixed 'ratio' just numbers that look nice...*/
89 static const gdouble chunksd[] = {0.1, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
90 15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
91 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
92 750.0, 1000.0, 10000.0};
94 typedef struct _propsaved {
99 typedef struct _propwidgets {
100 gboolean configure_dialog;
108 gint profile_width_old;
109 gint profile_height_old;
110 gint profile_width_offset;
111 gint profile_height_offset;
113 GtkWidget *w_comment;
114 GtkWidget *w_description;
115 GtkWidget *w_track_length;
116 GtkWidget *w_tp_count;
117 GtkWidget *w_segment_count;
118 GtkWidget *w_duptp_count;
119 GtkWidget *w_max_speed;
120 GtkWidget *w_avg_speed;
121 GtkWidget *w_mvg_speed;
122 GtkWidget *w_avg_dist;
123 GtkWidget *w_elev_range;
124 GtkWidget *w_elev_gain;
125 GtkWidget *w_time_start;
126 GtkWidget *w_time_end;
127 GtkWidget *w_time_dur;
129 GtkWidget *w_cur_dist; /*< Current distance */
130 GtkWidget *w_cur_elevation;
131 GtkWidget *w_cur_gradient_dist; /*< Current distance on gradient graph */
132 GtkWidget *w_cur_gradient_gradient; /*< Current gradient on gradient graph */
133 GtkWidget *w_cur_time; /*< Current time */
134 GtkWidget *w_cur_speed;
135 GtkWidget *w_cur_dist_dist; /*< Current distance on distance graph */
136 GtkWidget *w_cur_dist_time; /*< Current time on distance graph */
137 GtkWidget *w_cur_elev_elev;
138 GtkWidget *w_cur_elev_time;
139 GtkWidget *w_cur_speed_dist;
140 GtkWidget *w_cur_speed_speed;
141 GtkWidget *w_show_dem;
142 GtkWidget *w_show_alt_gps_speed;
143 GtkWidget *w_show_gps_speed;
144 GtkWidget *w_show_gradient_gps_speed;
145 GtkWidget *w_show_dist_speed;
146 GtkWidget *w_show_elev_speed;
147 GtkWidget *w_show_sd_gps_speed;
148 gdouble track_length;
149 gdouble track_length_inc_gaps;
150 PropSaved elev_graph_saved_img;
151 PropSaved gradient_graph_saved_img;
152 PropSaved speed_graph_saved_img;
153 PropSaved dist_graph_saved_img;
154 PropSaved elev_time_graph_saved_img;
155 PropSaved speed_dist_graph_saved_img;
157 GtkWidget *gradient_box;
158 GtkWidget *speed_box;
160 GtkWidget *elev_time_box;
161 GtkWidget *speed_dist_box;
163 gdouble *ats; // altitudes in time
164 gdouble min_altitude;
165 gdouble max_altitude;
166 gdouble draw_min_altitude;
167 gdouble draw_min_altitude_time;
168 gint cia; // Chunk size Index into Altitudes
169 gint ciat; // Chunk size Index into Altitudes / Time
170 // NB cia & ciat are normally same value but sometimes not due to differing methods of altitude array creation
171 // thus also have draw_min_altitude for each altitude graph type
173 gdouble min_gradient;
174 gdouble max_gradient;
175 gdouble draw_min_gradient;
176 gint cig; // Chunk size Index into Gradients
178 gdouble *speeds_dist;
181 gdouble draw_min_speed;
182 gdouble max_speed_dist;
183 gint cis; // Chunk size Index into Speeds
184 gint cisd; // Chunk size Index into Speed/Distance
186 gint cid; // Chunk size Index into Distance
187 VikTrackpoint *marker_tp;
188 gboolean is_marker_drawn;
189 VikTrackpoint *blob_tp;
190 gboolean is_blob_drawn;
193 static PropWidgets *prop_widgets_new()
195 PropWidgets *widgets = g_malloc0(sizeof(PropWidgets));
200 static void prop_widgets_free(PropWidgets *widgets)
202 if (widgets->elev_graph_saved_img.img)
203 g_object_unref(widgets->elev_graph_saved_img.img);
204 if (widgets->gradient_graph_saved_img.img)
205 g_object_unref(widgets->gradient_graph_saved_img.img);
206 if (widgets->speed_graph_saved_img.img)
207 g_object_unref(widgets->speed_graph_saved_img.img);
208 if (widgets->dist_graph_saved_img.img)
209 g_object_unref(widgets->dist_graph_saved_img.img);
210 if (widgets->elev_time_graph_saved_img.img)
211 g_object_unref(widgets->elev_time_graph_saved_img.img);
212 if (widgets->speed_dist_graph_saved_img.img)
213 g_object_unref(widgets->speed_dist_graph_saved_img.img);
214 if (widgets->altitudes)
215 g_free(widgets->altitudes);
216 if (widgets->gradients)
217 g_free(widgets->gradients);
219 g_free(widgets->speeds);
220 if (widgets->distances)
221 g_free(widgets->distances);
223 g_free(widgets->ats);
224 if (widgets->speeds_dist)
225 g_free(widgets->speeds_dist);
229 static void minmax_array(const gdouble *array, gdouble *min, gdouble *max, gboolean NO_ALT_TEST, gint PROFILE_WIDTH)
234 for ( i=0; i < PROFILE_WIDTH; i++ ) {
235 if ( NO_ALT_TEST || (array[i] != VIK_DEFAULT_ALTITUDE) ) {
236 if ( array[i] > *max )
238 if ( array[i] < *min )
247 * Returns via pointers:
248 * the new minimum value to be used for the altitude graph
249 * the index in to the altitudes chunk sizes array (ci = Chunk Index)
251 static void get_new_min_and_chunk_index_altitude (gdouble mina, gdouble maxa, gdouble *new_min, gint *ci)
253 /* Get unitized chunk */
254 /* Find suitable chunk index */
256 gdouble diffa_chunk = (maxa - mina)/LINES;
258 /* Loop through to find best match */
259 while (diffa_chunk > chunksa[*ci]) {
261 /* Last Resort Check */
262 if ( *ci == sizeof(chunksa)/sizeof(chunksa[0]) )
266 /* Ensure adjusted minimum .. maximum covers mina->maxa */
268 // Now work out adjusted minimum point to the nearest lowest chunk divisor value
269 // When negative ensure logic uses lowest value
271 *new_min = (gdouble) ( ( (gint)(mina - chunksa[*ci]) / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
273 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
275 // Range not big enough - as new minimum has lowered
276 if ((*new_min + (chunksa[*ci] * LINES) < maxa)) {
277 // Next chunk should cover it
278 if ( *ci < sizeof(chunksa)/sizeof(chunksa[0]) ) {
280 // Remember to adjust the minimum too...
282 *new_min = (gdouble) ( ( (gint)(mina - chunksa[*ci]) / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
284 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
290 * Returns via pointers:
291 * the new minimum value to be used for the altitude graph
292 * the index in to the altitudes chunk sizes array (ci = Chunk Index)
294 static void get_new_min_and_chunk_index_gradient (gdouble mina, gdouble maxa, gdouble *new_min, gint *ci)
296 /* Get unitized chunk */
297 /* Find suitable chunk index */
299 gdouble diffa_chunk = (maxa - mina)/LINES;
301 /* Loop through to find best match */
302 while (diffa_chunk > chunksg[*ci]) {
304 /* Last Resort Check */
305 if ( *ci == sizeof(chunksg)/sizeof(chunksg[0]) )
309 /* Ensure adjusted minimum .. maximum covers mina->maxa */
311 // Now work out adjusted minimum point to the nearest lowest chunk divisor value
312 // When negative ensure logic uses lowest value
314 *new_min = (gdouble) ( ( (gint)(mina - chunksg[*ci]) / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
316 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
318 // Range not big enough - as new minimum has lowered
319 if ((*new_min + (chunksg[*ci] * LINES) < maxa)) {
320 // Next chunk should cover it
321 if ( *ci < sizeof(chunksg)/sizeof(chunksg[0]) ) {
323 // Remember to adjust the minimum too...
325 *new_min = (gdouble) ( ( (gint)(mina - chunksg[*ci]) / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
327 *new_min = (gdouble) ( ( (gint)mina / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
333 * Returns via pointers:
334 * the new minimum value to be used for the appropriate graph
335 * the index in to that array (ci = Chunk Index)
337 static void get_new_min_and_chunk_index (gdouble mins, gdouble maxs, const gdouble *chunks, size_t chunky, gdouble *new_min, gint *ci)
340 gdouble diff_chunk = (maxs - mins)/LINES;
342 /* Loop through to find best match */
343 while (diff_chunk > chunks[*ci]) {
345 /* Last Resort Check */
349 *new_min = (gdouble) ( (gint)((mins / chunks[*ci] ) * chunks[*ci]) );
351 // Speeds are never negative so don't need to worry about a negative new minimum
354 static VikTrackpoint *set_center_at_graph_position(gdouble event_x,
363 VikTrackpoint *trackpoint;
364 gdouble x = event_x - img_width / 2 + PROFILE_WIDTH / 2 - MARGIN / 2;
367 if (x > PROFILE_WIDTH)
371 trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / PROFILE_WIDTH, NULL );
373 trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / PROFILE_WIDTH, NULL );
376 VikCoord coord = trackpoint->coord;
378 vik_viewport_set_center_coord ( vik_layers_panel_get_viewport(vlp), &coord );
379 vik_layers_panel_emit_update ( vlp );
382 /* since vlp not set, vvp should be valid instead! */
384 vik_viewport_set_center_coord ( vvp, &coord );
385 vik_layer_emit_update ( VIK_LAYER(vtl) );
392 * Returns whether the marker was drawn or not and whether the blob was drawn or not
394 static void save_image_and_draw_graph_marks (GtkWidget *image,
399 PropSaved *saved_img,
402 gboolean *marker_drawn,
403 gboolean *blob_drawn)
405 GdkPixmap *pix = NULL;
406 /* the pixmap = margin + graph area */
407 gtk_image_get_pixmap(GTK_IMAGE(image), &pix, NULL);
409 /* Restore previously saved image */
410 if (saved_img->saved) {
411 gdk_draw_image(GDK_DRAWABLE(pix), gc, saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
412 saved_img->saved = FALSE;
415 // ATM always save whole image - as anywhere could have changed
417 gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
419 saved_img->img = gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
420 saved_img->saved = TRUE;
422 if ((marker_x >= MARGIN) && (marker_x < (PROFILE_WIDTH + MARGIN))) {
423 gdk_draw_line (GDK_DRAWABLE(pix), gc, marker_x, 0, marker_x, image->allocation.height);
424 *marker_drawn = TRUE;
427 *marker_drawn = FALSE;
429 // Draw a square blob to indicate where we are on track for this graph
430 if ( (blob_x >= MARGIN) && (blob_x < (PROFILE_WIDTH + MARGIN)) && (blob_y < PROFILE_HEIGHT) ) {
431 gdk_draw_rectangle (GDK_DRAWABLE(pix), gc, TRUE, blob_x-3, blob_y-3, 6, 6);
437 // Anywhere on image could have changed
438 if (*marker_drawn || *blob_drawn)
439 gtk_widget_queue_draw(image);
443 * Return the percentage of how far a trackpoint is a long a track via the time method
445 static gdouble tp_percentage_by_time ( VikTrack *tr, VikTrackpoint *trackpoint )
448 if (trackpoint == NULL)
450 time_t t_start, t_end, t_total;
451 t_start = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
452 t_end = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp;
453 t_total = t_end - t_start;
454 pc = (gdouble)(trackpoint->timestamp - t_start)/t_total;
459 * Return the percentage of how far a trackpoint is a long a track via the distance method
461 static gdouble tp_percentage_by_distance ( VikTrack *tr, VikTrackpoint *trackpoint, gdouble track_length )
464 if (trackpoint == NULL)
468 for (iter = tr->trackpoints->next; iter != NULL; iter = iter->next) {
469 dist += vik_coord_diff(&(VIK_TRACKPOINT(iter->data)->coord),
470 &(VIK_TRACKPOINT(iter->prev->data)->coord));
471 /* Assuming trackpoint is not a copy */
472 if (trackpoint == VIK_TRACKPOINT(iter->data))
476 pc = dist/track_length;
480 static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, PropWidgets *widgets, VikPropWinGraphType_t graph_type )
482 gboolean is_time_graph =
483 ( graph_type == PROPWIN_GRAPH_TYPE_SPEED_TIME ||
484 graph_type == PROPWIN_GRAPH_TYPE_DISTANCE_TIME ||
485 graph_type == PROPWIN_GRAPH_TYPE_ELEVATION_TIME );
487 VikTrackpoint *trackpoint = set_center_at_graph_position(event->x, event_box->allocation.width, widgets->vtl, widgets->vlp, widgets->vvp, widgets->tr, is_time_graph, widgets->profile_width);
488 // Unable to get the point so give up
489 if ( trackpoint == NULL ) {
490 gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
494 widgets->marker_tp = trackpoint;
498 GtkWidget *window = gtk_widget_get_toplevel(GTK_WIDGET(event_box));
499 GtkWidget *graph_box;
500 PropSaved *graph_saved_img;
503 // Attempt to redraw marker on all graph types
505 for ( graphite = PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE;
506 graphite < PROPWIN_GRAPH_TYPE_END;
509 // Switch commonal variables to particular graph type
512 case PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE:
513 graph_box = widgets->elev_box;
514 graph_saved_img = &widgets->elev_graph_saved_img;
515 is_time_graph = FALSE;
517 case PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE:
518 graph_box = widgets->gradient_box;
519 graph_saved_img = &widgets->gradient_graph_saved_img;
520 is_time_graph = FALSE;
522 case PROPWIN_GRAPH_TYPE_SPEED_TIME:
523 graph_box = widgets->speed_box;
524 graph_saved_img = &widgets->speed_graph_saved_img;
525 is_time_graph = TRUE;
527 case PROPWIN_GRAPH_TYPE_DISTANCE_TIME:
528 graph_box = widgets->dist_box;
529 graph_saved_img = &widgets->dist_graph_saved_img;
530 is_time_graph = TRUE;
532 case PROPWIN_GRAPH_TYPE_ELEVATION_TIME:
533 graph_box = widgets->elev_time_box;
534 graph_saved_img = &widgets->elev_time_graph_saved_img;
535 is_time_graph = TRUE;
537 case PROPWIN_GRAPH_TYPE_SPEED_DISTANCE:
538 graph_box = widgets->speed_dist_box;
539 graph_saved_img = &widgets->speed_dist_graph_saved_img;
540 is_time_graph = FALSE;
544 // Commonal method of redrawing marker
547 child = gtk_container_get_children(GTK_CONTAINER(graph_box));
548 image = GTK_WIDGET(child->data);
551 pc = tp_percentage_by_time ( widgets->tr, trackpoint );
553 pc = tp_percentage_by_distance ( widgets->tr, trackpoint, widgets->track_length_inc_gaps );
556 gdouble marker_x = (pc * widgets->profile_width) + MARGIN;
557 save_image_and_draw_graph_marks(image,
559 gtk_widget_get_style(window)->black_gc,
560 -1, // Don't draw blob on clicks
563 widgets->profile_width,
564 widgets->profile_height,
565 &widgets->is_marker_drawn,
566 &widgets->is_blob_drawn);
572 gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, widgets->is_marker_drawn);
575 static gboolean track_profile_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
577 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE);
578 return TRUE; /* don't call other (further) callbacks */
581 static gboolean track_gradient_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
583 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE);
584 return TRUE; /* don't call other (further) callbacks */
587 static gboolean track_vt_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
589 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_SPEED_TIME);
590 return TRUE; /* don't call other (further) callbacks */
593 static gboolean track_dt_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
595 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_DISTANCE_TIME);
596 return TRUE; /* don't call other (further) callbacks */
599 static gboolean track_et_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
601 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_ELEVATION_TIME);
602 return TRUE; /* don't call other (further) callbacks */
605 static gboolean track_sd_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
607 track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_SPEED_DISTANCE);
608 return TRUE; /* don't call other (further) callbacks */
612 * Calculate y position for blob on elevation graph
614 static gint blobby_altitude ( gdouble x_blob, PropWidgets *widgets )
616 gint ix = (gint)x_blob;
617 // Ensure ix is inbounds
618 if (ix == widgets->profile_width)
621 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->altitudes[ix]-widgets->draw_min_altitude)/(chunksa[widgets->cia]*LINES);
627 * Calculate y position for blob on gradient graph
629 static gint blobby_gradient ( gdouble x_blob, PropWidgets *widgets )
631 gint ix = (gint)x_blob;
632 // Ensure ix is inbounds
633 if (ix == widgets->profile_width)
636 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->gradients[ix]-widgets->draw_min_gradient)/(chunksg[widgets->cig]*LINES);
642 * Calculate y position for blob on speed graph
644 static gint blobby_speed ( gdouble x_blob, PropWidgets *widgets )
646 gint ix = (gint)x_blob;
647 // Ensure ix is inbounds
648 if (ix == widgets->profile_width)
651 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->speeds[ix]-widgets->draw_min_speed)/(chunkss[widgets->cis]*LINES);
657 * Calculate y position for blob on distance graph
659 static gint blobby_distance ( gdouble x_blob, PropWidgets *widgets )
661 gint ix = (gint)x_blob;
662 // Ensure ix is inbounds
663 if (ix == widgets->profile_width)
666 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->distances[ix])/(chunksd[widgets->cid]*LINES);
667 //NB min distance is always 0, so no need to subtract that from this ______/
673 * Calculate y position for blob on elevation/time graph
675 static gint blobby_altitude_time ( gdouble x_blob, PropWidgets *widgets )
677 gint ix = (gint)x_blob;
678 // Ensure ix is inbounds
679 if (ix == widgets->profile_width)
682 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->ats[ix]-widgets->draw_min_altitude_time)/(chunksa[widgets->ciat]*LINES);
687 * Calculate y position for blob on speed/dist graph
689 static gint blobby_speed_dist ( gdouble x_blob, PropWidgets *widgets )
691 gint ix = (gint)x_blob;
692 // Ensure ix is inbounds
693 if (ix == widgets->profile_width)
696 gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->speeds_dist[ix]-widgets->draw_min_speed)/(chunkss[widgets->cisd]*LINES);
702 void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
704 int mouse_x, mouse_y;
705 GdkModifierType state;
708 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
712 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
715 if (x > widgets->profile_width)
716 x = widgets->profile_width;
718 gdouble meters_from_start;
719 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
720 if (trackpoint && widgets->w_cur_dist) {
721 static gchar tmp_buf[20];
722 vik_units_distance_t dist_units = a_vik_get_units_distance ();
723 switch (dist_units) {
724 case VIK_UNITS_DISTANCE_KILOMETRES:
725 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
727 case VIK_UNITS_DISTANCE_MILES:
728 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
731 g_critical("Houston, we've had a problem. distance=%d", dist_units);
733 gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist), tmp_buf);
736 // Show track elevation for this position - to the nearest whole number
737 if (trackpoint && widgets->w_cur_elevation) {
738 static gchar tmp_buf[20];
739 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
740 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d ft", (int)VIK_METERS_TO_FEET(trackpoint->altitude));
742 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d m", (int)trackpoint->altitude);
743 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elevation), tmp_buf);
746 widgets->blob_tp = trackpoint;
748 if ( widgets->altitudes == NULL )
751 GtkWidget *window = gtk_widget_get_toplevel (event_box);
752 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
753 GtkWidget *image = GTK_WIDGET(child->data);
755 gint y_blob = blobby_altitude (x, widgets);
757 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
758 if (widgets->is_marker_drawn) {
759 gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
761 marker_x = (pc * widgets->profile_width) + MARGIN;
765 save_image_and_draw_graph_marks (image,
767 gtk_widget_get_style(window)->black_gc,
770 &widgets->elev_graph_saved_img,
771 widgets->profile_width,
772 widgets->profile_height,
773 &widgets->is_marker_drawn,
774 &widgets->is_blob_drawn);
779 void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
781 int mouse_x, mouse_y;
782 GdkModifierType state;
785 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
789 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
792 if (x > widgets->profile_width)
793 x = widgets->profile_width;
795 gdouble meters_from_start;
796 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
797 if (trackpoint && widgets->w_cur_gradient_dist) {
798 static gchar tmp_buf[20];
799 vik_units_distance_t dist_units = a_vik_get_units_distance ();
800 switch (dist_units) {
801 case VIK_UNITS_DISTANCE_KILOMETRES:
802 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
804 case VIK_UNITS_DISTANCE_MILES:
805 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
808 g_critical("Houston, we've had a problem. distance=%d", dist_units);
810 gtk_label_set_text(GTK_LABEL(widgets->w_cur_gradient_dist), tmp_buf);
813 // Show track gradient for this position - to the nearest whole number
814 if (trackpoint && widgets->w_cur_gradient_gradient) {
815 static gchar tmp_buf[20];
817 double gradient = widgets->gradients[(int) x];
819 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d%%", (int)gradient);
820 gtk_label_set_text(GTK_LABEL(widgets->w_cur_gradient_gradient), tmp_buf);
823 widgets->blob_tp = trackpoint;
825 if ( widgets->gradients == NULL )
828 GtkWidget *window = gtk_widget_get_toplevel (event_box);
829 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
830 GtkWidget *image = GTK_WIDGET(child->data);
832 gint y_blob = blobby_gradient (x, widgets);
834 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
835 if (widgets->is_marker_drawn) {
836 gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
838 marker_x = (pc * widgets->profile_width) + MARGIN;
842 save_image_and_draw_graph_marks (image,
844 gtk_widget_get_style(window)->black_gc,
847 &widgets->gradient_graph_saved_img,
848 widgets->profile_width,
849 widgets->profile_height,
850 &widgets->is_marker_drawn,
851 &widgets->is_blob_drawn);
856 void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
858 int mouse_x, mouse_y;
859 GdkModifierType state;
862 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
866 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
869 if (x > widgets->profile_width)
870 x = widgets->profile_width;
872 time_t seconds_from_start;
873 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
874 if (trackpoint && widgets->w_cur_time) {
875 static gchar tmp_buf[20];
877 h = seconds_from_start/3600;
878 m = (seconds_from_start - h*3600)/60;
879 s = seconds_from_start - (3600*h) - (60*m);
880 g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
882 gtk_label_set_text(GTK_LABEL(widgets->w_cur_time), tmp_buf);
886 // Ensure ix is inbounds
887 if (ix == widgets->profile_width)
890 // Show track speed for this position
891 if (trackpoint && widgets->w_cur_speed) {
892 static gchar tmp_buf[20];
893 // Even if GPS speed available (trackpoint->speed), the text will correspond to the speed map shown
894 // No conversions needed as already in appropriate units
895 vik_units_speed_t speed_units = a_vik_get_units_speed ();
896 switch (speed_units) {
897 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
898 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f kph"), widgets->speeds[ix]);
900 case VIK_UNITS_SPEED_MILES_PER_HOUR:
901 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f mph"), widgets->speeds[ix]);
903 case VIK_UNITS_SPEED_KNOTS:
904 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f knots"), widgets->speeds[ix]);
907 // VIK_UNITS_SPEED_METRES_PER_SECOND:
908 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f m/s"), widgets->speeds[ix]);
911 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed), tmp_buf);
914 widgets->blob_tp = trackpoint;
916 if ( widgets->speeds == NULL )
919 GtkWidget *window = gtk_widget_get_toplevel (event_box);
920 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
921 GtkWidget *image = GTK_WIDGET(child->data);
923 gint y_blob = blobby_speed (x, widgets);
925 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
926 if (widgets->is_marker_drawn) {
927 gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
929 marker_x = (pc * widgets->profile_width) + MARGIN;
933 save_image_and_draw_graph_marks (image,
935 gtk_widget_get_style(window)->black_gc,
938 &widgets->speed_graph_saved_img,
939 widgets->profile_width,
940 widgets->profile_height,
941 &widgets->is_marker_drawn,
942 &widgets->is_blob_drawn);
948 * Update labels and blob marker on mouse moves in the distance/time graph
950 void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
952 int mouse_x, mouse_y;
953 GdkModifierType state;
956 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
960 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
963 if (x > widgets->profile_width)
964 x = widgets->profile_width;
966 time_t seconds_from_start;
967 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
968 if (trackpoint && widgets->w_cur_dist_time) {
969 static gchar tmp_buf[20];
971 h = seconds_from_start/3600;
972 m = (seconds_from_start - h*3600)/60;
973 s = seconds_from_start - (3600*h) - (60*m);
974 g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
976 gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_time), tmp_buf);
980 // Ensure ix is inbounds
981 if (ix == widgets->profile_width)
984 if (trackpoint && widgets->w_cur_dist_dist) {
985 static gchar tmp_buf[20];
986 if ( a_vik_get_units_distance () == VIK_UNITS_DISTANCE_MILES )
987 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", widgets->distances[ix]);
989 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", widgets->distances[ix]);
990 gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_dist), tmp_buf);
993 widgets->blob_tp = trackpoint;
995 if ( widgets->distances == NULL )
998 GtkWidget *window = gtk_widget_get_toplevel (event_box);
999 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
1000 GtkWidget *image = GTK_WIDGET(child->data);
1002 gint y_blob = blobby_distance (x, widgets);
1004 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
1005 if (widgets->is_marker_drawn) {
1006 gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
1008 marker_x = (pc * widgets->profile_width) + MARGIN;
1012 save_image_and_draw_graph_marks (image,
1014 gtk_widget_get_style(window)->black_gc,
1017 &widgets->dist_graph_saved_img,
1018 widgets->profile_width,
1019 widgets->profile_height,
1020 &widgets->is_marker_drawn,
1021 &widgets->is_blob_drawn);
1027 * Update labels and blob marker on mouse moves in the elevation/time graph
1029 void track_et_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
1031 int mouse_x, mouse_y;
1032 GdkModifierType state;
1035 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
1039 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
1042 if (x > widgets->profile_width)
1043 x = widgets->profile_width;
1045 time_t seconds_from_start;
1046 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
1047 if (trackpoint && widgets->w_cur_elev_time) {
1048 static gchar tmp_buf[20];
1050 h = seconds_from_start/3600;
1051 m = (seconds_from_start - h*3600)/60;
1052 s = seconds_from_start - (3600*h) - (60*m);
1053 g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
1055 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elev_time), tmp_buf);
1059 // Ensure ix is inbounds
1060 if (ix == widgets->profile_width)
1063 if (trackpoint && widgets->w_cur_elev_elev) {
1064 static gchar tmp_buf[20];
1065 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
1066 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d ft", (int)VIK_METERS_TO_FEET(trackpoint->altitude));
1068 g_snprintf(tmp_buf, sizeof(tmp_buf), "%d m", (int)trackpoint->altitude);
1069 gtk_label_set_text(GTK_LABEL(widgets->w_cur_elev_elev), tmp_buf);
1072 widgets->blob_tp = trackpoint;
1074 if ( widgets->ats == NULL )
1077 GtkWidget *window = gtk_widget_get_toplevel (event_box);
1078 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
1079 GtkWidget *image = GTK_WIDGET(child->data);
1081 gint y_blob = blobby_altitude_time (x, widgets);
1083 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
1084 if (widgets->is_marker_drawn) {
1085 gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
1087 marker_x = (pc * widgets->profile_width) + MARGIN;
1091 save_image_and_draw_graph_marks (image,
1093 gtk_widget_get_style(window)->black_gc,
1096 &widgets->elev_time_graph_saved_img,
1097 widgets->profile_width,
1098 widgets->profile_height,
1099 &widgets->is_marker_drawn,
1100 &widgets->is_blob_drawn);
1105 void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
1107 int mouse_x, mouse_y;
1108 GdkModifierType state;
1111 gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
1115 gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
1118 if (x > widgets->profile_width)
1119 x = widgets->profile_width;
1121 gdouble meters_from_start;
1122 VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
1123 if (trackpoint && widgets->w_cur_speed_dist) {
1124 static gchar tmp_buf[20];
1125 vik_units_distance_t dist_units = a_vik_get_units_distance ();
1126 switch (dist_units) {
1127 case VIK_UNITS_DISTANCE_KILOMETRES:
1128 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
1130 case VIK_UNITS_DISTANCE_MILES:
1131 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
1134 g_critical("Houston, we've had a problem. distance=%d", dist_units);
1136 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed_dist), tmp_buf);
1140 // Ensure ix is inbounds
1141 if (ix == widgets->profile_width)
1144 if ( widgets->speeds_dist == NULL )
1147 // Show track speed for this position
1148 if (widgets->w_cur_speed_speed) {
1149 static gchar tmp_buf[20];
1150 // Even if GPS speed available (trackpoint->speed), the text will correspond to the speed map shown
1151 // No conversions needed as already in appropriate units
1152 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1153 switch (speed_units) {
1154 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1155 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f kph"), widgets->speeds_dist[ix]);
1157 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1158 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f mph"), widgets->speeds_dist[ix]);
1160 case VIK_UNITS_SPEED_KNOTS:
1161 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f knots"), widgets->speeds_dist[ix]);
1164 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1165 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f m/s"), widgets->speeds_dist[ix]);
1168 gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed_speed), tmp_buf);
1171 widgets->blob_tp = trackpoint;
1173 GtkWidget *window = gtk_widget_get_toplevel (event_box);
1174 GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
1175 GtkWidget *image = GTK_WIDGET(child->data);
1177 gint y_blob = blobby_speed_dist (x, widgets);
1179 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
1180 if (widgets->is_marker_drawn) {
1181 gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
1183 marker_x = (pc * widgets->profile_width) + MARGIN;
1187 save_image_and_draw_graph_marks (image,
1189 gtk_widget_get_style(window)->black_gc,
1192 &widgets->speed_dist_graph_saved_img,
1193 widgets->profile_width,
1194 widgets->profile_height,
1195 &widgets->is_marker_drawn,
1196 &widgets->is_blob_drawn);
1202 * Draws DEM points and a respresentative speed on the supplied pixmap
1203 * (which is the elevations graph)
1205 static void draw_dem_alt_speed_dist(VikTrack *tr,
1211 gdouble max_speed_in,
1220 gdouble max_speed = 0;
1221 gdouble total_length = vik_track_get_length_including_gaps(tr);
1223 // Calculate the max speed factor
1225 max_speed = max_speed_in * 110 / 100;
1228 for (iter = tr->trackpoints->next; iter; iter = iter->next) {
1230 dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
1231 &(VIK_TRACKPOINT(iter->prev->data)->coord) );
1232 x = (width * dist)/total_length + margin;
1234 gint16 elev = a_dems_get_elev_by_coord(&(VIK_TRACKPOINT(iter->data)->coord), VIK_DEM_INTERPOL_BEST);
1236 if ( elev != VIK_DEM_INVALID_ELEVATION ) {
1237 // Convert into height units
1238 if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
1239 elev = VIK_METERS_TO_FEET(elev);
1240 // No conversion needed if already in metres
1242 // consider chunk size
1243 int y_alt = height - ((height * elev)/(chunksa[cia]*LINES) );
1244 gdk_draw_rectangle(GDK_DRAWABLE(pix), alt_gc, TRUE, x-2, y_alt-2, 4, 4);
1248 // This is just a speed indicator - no actual values can be inferred by user
1249 if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
1250 int y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
1251 gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
1258 * Draw just the height profile image
1260 static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1270 // Free previous allocation
1271 if ( widgets->altitudes )
1272 g_free ( widgets->altitudes );
1274 widgets->altitudes = vik_track_make_elevation_map ( tr, widgets->profile_width );
1276 if ( widgets->altitudes == NULL )
1279 // Convert into appropriate units
1280 vik_units_height_t height_units = a_vik_get_units_height ();
1281 if ( height_units == VIK_UNITS_HEIGHT_FEET ) {
1282 // Convert altitudes into feet units
1283 for ( i = 0; i < widgets->profile_width; i++ ) {
1284 widgets->altitudes[i] = VIK_METERS_TO_FEET(widgets->altitudes[i]);
1287 // Otherwise leave in metres
1289 minmax_array(widgets->altitudes, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
1291 get_new_min_and_chunk_index_altitude (widgets->min_altitude, widgets->max_altitude, &widgets->draw_min_altitude, &widgets->cia);
1294 mina = widgets->draw_min_altitude;
1295 maxa = widgets->max_altitude;
1297 window = gtk_widget_get_toplevel (widgets->elev_box);
1299 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1301 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1303 no_alt_info = gdk_gc_new ( gtk_widget_get_window(window) );
1304 gdk_color_parse ( "yellow", &color );
1305 gdk_gc_set_rgb_fg_color ( no_alt_info, &color);
1307 /* clear the image */
1308 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1309 TRUE, 0, 0, MARGIN, widgets->profile_height);
1310 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1311 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1314 for (i=0; i<=LINES; i++) {
1315 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1319 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1320 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1322 switch (height_units) {
1323 case VIK_UNITS_HEIGHT_METRES:
1324 sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
1326 case VIK_UNITS_HEIGHT_FEET:
1327 // NB values already converted into feet
1328 sprintf(s, "%8dft", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
1332 g_critical("Houston, we've had a problem. height=%d", height_units);
1334 pango_layout_set_text(pl, s, -1);
1335 pango_layout_get_pixel_size (pl, &w, &h);
1336 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1337 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1339 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1340 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1341 g_object_unref ( G_OBJECT ( pl ) );
1345 /* draw elevations */
1346 for ( i = 0; i < widgets->profile_width; i++ )
1347 if ( widgets->altitudes[i] == VIK_DEFAULT_ALTITUDE )
1348 gdk_draw_line ( GDK_DRAWABLE(pix), no_alt_info,
1349 i + MARGIN, 0, i + MARGIN, widgets->profile_height );
1351 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1352 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->altitudes[i]-mina)/(chunksa[widgets->cia]*LINES) );
1354 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)) ||
1355 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)) ) {
1357 GdkGC *dem_alt_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1358 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1360 gdk_color_parse ( "green", &color );
1361 gdk_gc_set_rgb_fg_color ( dem_alt_gc, &color);
1363 gdk_color_parse ( "red", &color );
1364 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1366 // Ensure somekind of max speed when not set
1367 if ( widgets->max_speed < 0.01 )
1368 widgets->max_speed = vik_track_get_max_speed(tr);
1370 draw_dem_alt_speed_dist(tr,
1378 widgets->profile_width,
1379 widgets->profile_height,
1381 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)),
1382 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
1384 g_object_unref ( G_OBJECT(dem_alt_gc) );
1385 g_object_unref ( G_OBJECT(gps_speed_gc) );
1389 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1391 g_object_unref ( G_OBJECT(pix) );
1392 g_object_unref ( G_OBJECT(no_alt_info) );
1396 * Draws representative speed on the supplied pixmap
1397 * (which is the gradients graph)
1399 static void draw_speed_dist(VikTrack *tr,
1402 gdouble max_speed_in,
1409 gdouble max_speed = 0;
1410 gdouble total_length = vik_track_get_length_including_gaps(tr);
1412 // Calculate the max speed factor
1414 max_speed = max_speed_in * 110 / 100;
1417 for (iter = tr->trackpoints->next; iter; iter = iter->next) {
1419 dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
1420 &(VIK_TRACKPOINT(iter->prev->data)->coord) );
1421 x = (width * dist)/total_length + margin;
1423 // This is just a speed indicator - no actual values can be inferred by user
1424 if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
1425 int y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
1426 gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
1433 * Draw just the gradient image
1435 static void draw_gradients (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1444 // Free previous allocation
1445 if ( widgets->gradients )
1446 g_free ( widgets->gradients );
1448 widgets->gradients = vik_track_make_gradient_map ( tr, widgets->profile_width );
1450 if ( widgets->gradients == NULL )
1453 minmax_array(widgets->gradients, &widgets->min_gradient, &widgets->max_gradient, TRUE, widgets->profile_width);
1455 get_new_min_and_chunk_index_gradient (widgets->min_gradient, widgets->max_gradient, &widgets->draw_min_gradient, &widgets->cig);
1458 mina = widgets->draw_min_gradient;
1460 window = gtk_widget_get_toplevel (widgets->gradient_box);
1462 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1464 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1466 /* clear the image */
1467 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1468 TRUE, 0, 0, MARGIN, widgets->profile_height);
1469 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1470 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1473 for (i=0; i<=LINES; i++) {
1474 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1478 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1479 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1481 sprintf(s, "%8d%%", (int)(mina + (LINES-i)*chunksg[widgets->cig]));
1482 pango_layout_set_text(pl, s, -1);
1483 pango_layout_get_pixel_size (pl, &w, &h);
1484 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1485 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1487 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1488 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1489 g_object_unref ( G_OBJECT ( pl ) );
1493 /* draw gradients */
1494 for ( i = 0; i < widgets->profile_width; i++ )
1495 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1496 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->gradients[i]-mina)/(chunksg[widgets->cig]*LINES) );
1498 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_gradient_gps_speed)) ) {
1499 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1501 gdk_color_parse ( "red", &color );
1502 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1504 // Ensure somekind of max speed when not set
1505 if ( widgets->max_speed < 0.01 )
1506 widgets->max_speed = vik_track_get_max_speed(tr);
1512 widgets->profile_width,
1513 widgets->profile_height,
1515 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
1517 g_object_unref ( G_OBJECT(gps_speed_gc) );
1521 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1523 g_object_unref ( G_OBJECT(pix) );
1527 * Draw just the speed (velocity)/time image
1529 static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
1536 // Free previous allocation
1537 if ( widgets->speeds )
1538 g_free ( widgets->speeds );
1540 widgets->speeds = vik_track_make_speed_map ( tr, widgets->profile_width );
1541 if ( widgets->speeds == NULL )
1544 // Convert into appropriate units
1545 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1546 switch (speed_units) {
1547 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1548 for ( i = 0; i < widgets->profile_width; i++ ) {
1549 widgets->speeds[i] = VIK_MPS_TO_KPH(widgets->speeds[i]);
1552 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1553 for ( i = 0; i < widgets->profile_width; i++ ) {
1554 widgets->speeds[i] = VIK_MPS_TO_MPH(widgets->speeds[i]);
1557 case VIK_UNITS_SPEED_KNOTS:
1558 for ( i = 0; i < widgets->profile_width; i++ ) {
1559 widgets->speeds[i] = VIK_MPS_TO_KNOTS(widgets->speeds[i]);
1563 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1564 // No need to convert as already in m/s
1568 window = gtk_widget_get_toplevel (widgets->speed_box);
1570 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1572 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1574 minmax_array(widgets->speeds, &widgets->min_speed, &widgets->max_speed, FALSE, widgets->profile_width);
1575 if (widgets->min_speed < 0.0)
1576 widgets->min_speed = 0; /* splines sometimes give negative speeds */
1578 /* Find suitable chunk index */
1579 get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed, chunkss, sizeof(chunkss)/sizeof(chunkss[0]), &widgets->draw_min_speed, &widgets->cis);
1582 mins = widgets->draw_min_speed;
1584 /* clear the image */
1585 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1586 TRUE, 0, 0, MARGIN, widgets->profile_height);
1587 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1588 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1591 for (i=0; i<=LINES; i++) {
1592 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1596 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1597 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1599 // NB: No need to convert here anymore as numbers are in the appropriate units
1600 switch (speed_units) {
1601 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1602 sprintf(s, "%8dkm/h", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1604 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1605 sprintf(s, "%8dmph", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1607 case VIK_UNITS_SPEED_METRES_PER_SECOND:
1608 sprintf(s, "%8dm/s", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1610 case VIK_UNITS_SPEED_KNOTS:
1611 sprintf(s, "%8dknots", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
1615 g_critical("Houston, we've had a problem. speed=%d", speed_units);
1618 pango_layout_set_text(pl, s, -1);
1619 pango_layout_get_pixel_size (pl, &w, &h);
1620 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1621 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1623 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1624 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1625 g_object_unref ( G_OBJECT ( pl ) );
1631 for ( i = 0; i < widgets->profile_width; i++ )
1632 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1633 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds[i]-mins)/(chunkss[widgets->cis]*LINES) );
1636 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_gps_speed)) ) {
1638 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1640 gdk_color_parse ( "red", &color );
1641 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
1643 time_t beg_time = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
1644 time_t dur = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp - beg_time;
1647 for (iter = tr->trackpoints; iter; iter = iter->next) {
1648 gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed;
1649 if (isnan(gps_speed))
1651 switch (speed_units) {
1652 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1653 gps_speed = VIK_MPS_TO_KPH(gps_speed);
1655 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1656 gps_speed = VIK_MPS_TO_MPH(gps_speed);
1658 case VIK_UNITS_SPEED_KNOTS:
1659 gps_speed = VIK_MPS_TO_KNOTS(gps_speed);
1662 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1663 // No need to convert as already in m/s
1666 int x = MARGIN + widgets->profile_width * (VIK_TRACKPOINT(iter->data)->timestamp - beg_time) / dur;
1667 int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cis]*LINES);
1668 gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
1670 g_object_unref ( G_OBJECT(gps_speed_gc) );
1674 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1676 g_object_unref ( G_OBJECT(pix) );
1680 * Draw just the distance/time image
1682 static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1689 // Free previous allocation
1690 if ( widgets->distances )
1691 g_free ( widgets->distances );
1693 widgets->distances = vik_track_make_distance_map ( tr, widgets->profile_width );
1694 if ( widgets->distances == NULL )
1697 // Convert into appropriate units
1698 vik_units_distance_t dist_units = a_vik_get_units_distance ();
1699 if ( dist_units == VIK_UNITS_DISTANCE_MILES ) {
1700 for ( i = 0; i < widgets->profile_width; i++ ) {
1701 widgets->distances[i] = VIK_METERS_TO_MILES(widgets->distances[i]);
1705 // Metres - but want in kms
1706 for ( i = 0; i < widgets->profile_width; i++ ) {
1707 widgets->distances[i] = widgets->distances[i]/1000.0;
1711 window = gtk_widget_get_toplevel (widgets->dist_box);
1713 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1715 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1717 // easy to work out min / max of distance!
1719 // mind = 0.0; - Thus not used
1720 if ( dist_units == VIK_UNITS_DISTANCE_MILES )
1721 maxd = VIK_METERS_TO_MILES(vik_track_get_length_including_gaps (tr));
1723 maxd = vik_track_get_length_including_gaps (tr) / 1000.0;
1725 /* Find suitable chunk index */
1726 gdouble dummy = 0.0; // expect this to remain the same! (not that it's used)
1727 get_new_min_and_chunk_index (0, maxd, chunksd, sizeof(chunksd)/sizeof(chunksd[0]), &dummy, &widgets->cid);
1729 /* clear the image */
1730 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1731 TRUE, 0, 0, MARGIN, widgets->profile_height);
1732 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1733 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1736 for (i=0; i<=LINES; i++) {
1737 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1741 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1742 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1744 if ( dist_units == VIK_UNITS_DISTANCE_MILES )
1745 sprintf(s, _("%.1f miles"), ((LINES-i)*chunksd[widgets->cid]));
1747 sprintf(s, _("%.1f km"), ((LINES-i)*chunksd[widgets->cid]));
1749 pango_layout_set_text(pl, s, -1);
1750 pango_layout_get_pixel_size (pl, &w, &h);
1751 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1752 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1754 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1755 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1756 g_object_unref ( G_OBJECT ( pl ) );
1761 for ( i = 0; i < widgets->profile_width; i++ )
1762 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1763 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->distances[i])/(chunksd[widgets->cid]*LINES) );
1765 // Show speed indicator
1766 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_dist_speed)) ) {
1767 GdkGC *dist_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1769 gdk_color_parse ( "red", &color );
1770 gdk_gc_set_rgb_fg_color ( dist_speed_gc, &color);
1772 gdouble max_speed = 0;
1773 max_speed = widgets->max_speed * 110 / 100;
1775 // This is just an indicator - no actual values can be inferred by user
1777 for ( i = 0; i < widgets->profile_width; i++ ) {
1778 int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
1779 gdk_draw_rectangle(GDK_DRAWABLE(pix), dist_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
1781 g_object_unref ( G_OBJECT(dist_speed_gc) );
1785 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1787 g_object_unref ( G_OBJECT(pix) );
1792 * Draw just the elevation/time image
1794 static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
1801 // Free previous allocation
1803 g_free ( widgets->ats );
1805 widgets->ats = vik_track_make_elevation_time_map ( tr, widgets->profile_width );
1807 if ( widgets->ats == NULL )
1810 // Convert into appropriate units
1811 vik_units_height_t height_units = a_vik_get_units_height ();
1812 if ( height_units == VIK_UNITS_HEIGHT_FEET ) {
1813 // Convert altitudes into feet units
1814 for ( i = 0; i < widgets->profile_width; i++ ) {
1815 widgets->ats[i] = VIK_METERS_TO_FEET(widgets->ats[i]);
1818 // Otherwise leave in metres
1820 minmax_array(widgets->ats, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
1822 get_new_min_and_chunk_index_altitude (widgets->min_altitude, widgets->max_altitude, &widgets->draw_min_altitude_time, &widgets->ciat);
1825 mina = widgets->draw_min_altitude_time;
1827 window = gtk_widget_get_toplevel (widgets->elev_time_box);
1829 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1831 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1833 /* clear the image */
1834 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1835 TRUE, 0, 0, MARGIN, widgets->profile_height);
1836 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1837 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1840 for (i=0; i<=LINES; i++) {
1841 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1845 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1846 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1848 switch (height_units) {
1849 case VIK_UNITS_HEIGHT_METRES:
1850 sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->ciat]));
1852 case VIK_UNITS_HEIGHT_FEET:
1853 // NB values already converted into feet
1854 sprintf(s, "%8dft", (int)(mina + (LINES-i)*chunksa[widgets->ciat]));
1858 g_critical("Houston, we've had a problem. height=%d", height_units);
1860 pango_layout_set_text(pl, s, -1);
1861 pango_layout_get_pixel_size (pl, &w, &h);
1862 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1863 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
1865 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
1866 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
1867 g_object_unref ( G_OBJECT ( pl ) );
1871 /* draw elevations */
1872 for ( i = 0; i < widgets->profile_width; i++ )
1873 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
1874 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->ats[i]-mina)/(chunksa[widgets->ciat]*LINES) );
1876 // Show speed indicator
1877 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_elev_speed)) ) {
1878 GdkGC *elev_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
1880 gdk_color_parse ( "red", &color );
1881 gdk_gc_set_rgb_fg_color ( elev_speed_gc, &color);
1883 gdouble max_speed = 0;
1884 max_speed = widgets->max_speed * 110 / 100;
1886 // This is just an indicator - no actual values can be inferred by user
1888 for ( i = 0; i < widgets->profile_width; i++ ) {
1889 int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
1890 gdk_draw_rectangle(GDK_DRAWABLE(pix), elev_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
1892 g_object_unref ( G_OBJECT(elev_speed_gc) );
1896 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
1898 g_object_unref ( G_OBJECT(pix) );
1903 * Draw just the speed/distance image
1905 static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
1912 // Free previous allocation
1913 if ( widgets->speeds_dist )
1914 g_free ( widgets->speeds_dist );
1916 widgets->speeds_dist = vik_track_make_speed_dist_map ( tr, widgets->profile_width );
1917 if ( widgets->speeds_dist == NULL )
1920 // Convert into appropriate units
1921 vik_units_speed_t speed_units = a_vik_get_units_speed ();
1922 switch (speed_units) {
1923 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1924 for ( i = 0; i < widgets->profile_width; i++ ) {
1925 widgets->speeds_dist[i] = VIK_MPS_TO_KPH(widgets->speeds_dist[i]);
1928 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1929 for ( i = 0; i < widgets->profile_width; i++ ) {
1930 widgets->speeds_dist[i] = VIK_MPS_TO_MPH(widgets->speeds_dist[i]);
1933 case VIK_UNITS_SPEED_KNOTS:
1934 for ( i = 0; i < widgets->profile_width; i++ ) {
1935 widgets->speeds_dist[i] = VIK_MPS_TO_KNOTS(widgets->speeds_dist[i]);
1939 // VIK_UNITS_SPEED_METRES_PER_SECOND:
1940 // No need to convert as already in m/s
1944 window = gtk_widget_get_toplevel (widgets->speed_dist_box);
1946 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
1948 gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
1950 // OK to resuse min_speed here
1951 minmax_array(widgets->speeds_dist, &widgets->min_speed, &widgets->max_speed_dist, FALSE, widgets->profile_width);
1952 if (widgets->min_speed < 0.0)
1953 widgets->min_speed = 0; /* splines sometimes give negative speeds */
1955 /* Find suitable chunk index */
1956 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);
1959 mins = widgets->draw_min_speed;
1961 /* clear the image */
1962 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
1963 TRUE, 0, 0, MARGIN, widgets->profile_height);
1964 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
1965 TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
1968 for (i=0; i<=LINES; i++) {
1969 PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
1973 pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
1974 pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
1976 // NB: No need to convert here anymore as numbers are in the appropriate units
1977 switch (speed_units) {
1978 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
1979 sprintf(s, "%8dkm/h", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1981 case VIK_UNITS_SPEED_MILES_PER_HOUR:
1982 sprintf(s, "%8dmph", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1984 case VIK_UNITS_SPEED_METRES_PER_SECOND:
1985 sprintf(s, "%8dm/s", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1987 case VIK_UNITS_SPEED_KNOTS:
1988 sprintf(s, "%8dknots", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
1992 g_critical("Houston, we've had a problem. speed=%d", speed_units);
1995 pango_layout_set_text(pl, s, -1);
1996 pango_layout_get_pixel_size (pl, &w, &h);
1997 gdk_draw_layout(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
1998 CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
2000 gdk_draw_line (GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
2001 MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
2002 g_object_unref ( G_OBJECT ( pl ) );
2008 for ( i = 0; i < widgets->profile_width; i++ )
2009 gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
2010 i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds_dist[i]-mins)/(chunkss[widgets->cisd]*LINES) );
2013 if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_sd_gps_speed)) ) {
2015 GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
2017 gdk_color_parse ( "red", &color );
2018 gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
2020 gdouble dist = vik_track_get_length_including_gaps(tr);
2021 gdouble dist_tp = 0.0;
2023 GList *iter = tr->trackpoints;
2024 for (iter = iter->next; iter; iter = iter->next) {
2025 gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed;
2026 if (isnan(gps_speed))
2028 switch (speed_units) {
2029 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2030 gps_speed = VIK_MPS_TO_KPH(gps_speed);
2032 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2033 gps_speed = VIK_MPS_TO_MPH(gps_speed);
2035 case VIK_UNITS_SPEED_KNOTS:
2036 gps_speed = VIK_MPS_TO_KNOTS(gps_speed);
2039 // VIK_UNITS_SPEED_METRES_PER_SECOND:
2040 // No need to convert as already in m/s
2043 dist_tp += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord), &(VIK_TRACKPOINT(iter->prev->data)->coord) );
2044 int x = MARGIN + (widgets->profile_width * dist_tp / dist);
2045 int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cisd]*LINES);
2046 gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
2048 g_object_unref ( G_OBJECT(gps_speed_gc) );
2052 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
2054 g_object_unref ( G_OBJECT(pix) );
2061 static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean resized )
2063 // Draw graphs even if they are not visible
2065 GList *child = NULL;
2066 GtkWidget *image = NULL;
2067 GtkWidget *window = gtk_widget_get_toplevel(widget);
2069 gdouble pc_blob = NAN;
2072 if (widgets->elev_box != NULL) {
2074 // Saved image no longer any good as we've resized, so we remove it here
2075 if (resized && widgets->elev_graph_saved_img.img) {
2076 g_object_unref(widgets->elev_graph_saved_img.img);
2077 widgets->elev_graph_saved_img.img = NULL;
2078 widgets->elev_graph_saved_img.saved = FALSE;
2081 child = gtk_container_get_children(GTK_CONTAINER(widgets->elev_box));
2082 draw_elevations (GTK_WIDGET(child->data), widgets->tr, widgets );
2084 image = GTK_WIDGET(child->data);
2087 // Ensure marker or blob are redrawn if necessary
2088 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2090 pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
2091 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2093 if (widgets->is_blob_drawn) {
2094 pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
2095 if (!isnan(pc_blob)) {
2096 x_blob = (pc_blob * widgets->profile_width);
2098 y_blob = blobby_altitude (x_blob, widgets);
2101 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2103 marker_x = (pc * widgets->profile_width) + MARGIN;
2106 save_image_and_draw_graph_marks (image,
2108 gtk_widget_get_style(window)->black_gc,
2111 &widgets->elev_graph_saved_img,
2112 widgets->profile_width,
2113 widgets->profile_height,
2114 &widgets->is_marker_drawn,
2115 &widgets->is_blob_drawn);
2120 if (widgets->gradient_box != NULL) {
2122 // Saved image no longer any good as we've resized, so we remove it here
2123 if (resized && widgets->gradient_graph_saved_img.img) {
2124 g_object_unref(widgets->gradient_graph_saved_img.img);
2125 widgets->gradient_graph_saved_img.img = NULL;
2126 widgets->gradient_graph_saved_img.saved = FALSE;
2129 child = gtk_container_get_children(GTK_CONTAINER(widgets->gradient_box));
2130 draw_gradients (GTK_WIDGET(child->data), widgets->tr, widgets );
2132 image = GTK_WIDGET(child->data);
2135 // Ensure marker or blob are redrawn if necessary
2136 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2138 pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
2139 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2141 if (widgets->is_blob_drawn) {
2142 pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
2143 if (!isnan(pc_blob)) {
2144 x_blob = (pc_blob * widgets->profile_width);
2146 y_blob = blobby_gradient (x_blob, widgets);
2149 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2151 marker_x = (pc * widgets->profile_width) + MARGIN;
2154 save_image_and_draw_graph_marks (image,
2156 gtk_widget_get_style(window)->black_gc,
2159 &widgets->gradient_graph_saved_img,
2160 widgets->profile_width,
2161 widgets->profile_height,
2162 &widgets->is_marker_drawn,
2163 &widgets->is_blob_drawn);
2168 if (widgets->speed_box != NULL) {
2170 // Saved image no longer any good as we've resized
2171 if (resized && widgets->speed_graph_saved_img.img) {
2172 g_object_unref(widgets->speed_graph_saved_img.img);
2173 widgets->speed_graph_saved_img.img = NULL;
2174 widgets->speed_graph_saved_img.saved = FALSE;
2177 child = gtk_container_get_children(GTK_CONTAINER(widgets->speed_box));
2178 draw_vt (GTK_WIDGET(child->data), widgets->tr, widgets );
2180 image = GTK_WIDGET(child->data);
2183 // Ensure marker or blob are redrawn if necessary
2184 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2186 pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
2188 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2190 if (widgets->is_blob_drawn) {
2191 pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
2192 if (!isnan(pc_blob)) {
2193 x_blob = (pc_blob * widgets->profile_width);
2196 y_blob = blobby_speed (x_blob, widgets);
2199 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2201 marker_x = (pc * widgets->profile_width) + MARGIN;
2204 save_image_and_draw_graph_marks (image,
2206 gtk_widget_get_style(window)->black_gc,
2209 &widgets->speed_graph_saved_img,
2210 widgets->profile_width,
2211 widgets->profile_height,
2212 &widgets->is_marker_drawn,
2213 &widgets->is_blob_drawn);
2218 if (widgets->dist_box != NULL) {
2220 // Saved image no longer any good as we've resized
2221 if (resized && widgets->dist_graph_saved_img.img) {
2222 g_object_unref(widgets->dist_graph_saved_img.img);
2223 widgets->dist_graph_saved_img.img = NULL;
2224 widgets->dist_graph_saved_img.saved = FALSE;
2227 child = gtk_container_get_children(GTK_CONTAINER(widgets->dist_box));
2228 draw_dt (GTK_WIDGET(child->data), widgets->tr, widgets );
2230 image = GTK_WIDGET(child->data);
2233 // Ensure marker or blob are redrawn if necessary
2234 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2236 pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
2238 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2240 if (widgets->is_blob_drawn) {
2241 pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
2242 if (!isnan(pc_blob)) {
2243 x_blob = (pc_blob * widgets->profile_width);
2246 y_blob = blobby_distance (x_blob, widgets);
2249 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2251 marker_x = (pc * widgets->profile_width) + MARGIN;
2254 save_image_and_draw_graph_marks (image,
2256 gtk_widget_get_style(window)->black_gc,
2259 &widgets->dist_graph_saved_img,
2260 widgets->profile_width,
2261 widgets->profile_height,
2262 &widgets->is_marker_drawn,
2263 &widgets->is_blob_drawn);
2267 // Draw Elevations in timely manner
2268 if (widgets->elev_time_box != NULL) {
2270 // Saved image no longer any good as we've resized
2271 if (resized && widgets->elev_time_graph_saved_img.img) {
2272 g_object_unref(widgets->elev_time_graph_saved_img.img);
2273 widgets->elev_time_graph_saved_img.img = NULL;
2274 widgets->elev_time_graph_saved_img.saved = FALSE;
2277 child = gtk_container_get_children(GTK_CONTAINER(widgets->elev_time_box));
2278 draw_et (GTK_WIDGET(child->data), widgets->tr, widgets );
2280 image = GTK_WIDGET(child->data);
2283 // Ensure marker or blob are redrawn if necessary
2284 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2286 pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
2288 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2290 if (widgets->is_blob_drawn) {
2291 pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
2292 if (!isnan(pc_blob)) {
2293 x_blob = (pc_blob * widgets->profile_width);
2295 y_blob = blobby_altitude_time (x_blob, widgets);
2298 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2300 marker_x = (pc * widgets->profile_width) + MARGIN;
2303 save_image_and_draw_graph_marks (image,
2305 gtk_widget_get_style(window)->black_gc,
2308 &widgets->elev_time_graph_saved_img,
2309 widgets->profile_width,
2310 widgets->profile_height,
2311 &widgets->is_marker_drawn,
2312 &widgets->is_blob_drawn);
2316 // Draw speed distances
2317 if (widgets->speed_dist_box != NULL) {
2319 // Saved image no longer any good as we've resized, so we remove it here
2320 if (resized && widgets->speed_dist_graph_saved_img.img) {
2321 g_object_unref(widgets->speed_dist_graph_saved_img.img);
2322 widgets->speed_dist_graph_saved_img.img = NULL;
2323 widgets->speed_dist_graph_saved_img.saved = FALSE;
2326 child = gtk_container_get_children(GTK_CONTAINER(widgets->speed_dist_box));
2327 draw_sd (GTK_WIDGET(child->data), widgets->tr, widgets );
2329 image = GTK_WIDGET(child->data);
2332 // Ensure marker or blob are redrawn if necessary
2333 if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
2335 pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
2336 gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
2338 if (widgets->is_blob_drawn) {
2339 pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
2340 if (!isnan(pc_blob)) {
2341 x_blob = (pc_blob * widgets->profile_width);
2343 y_blob = blobby_speed_dist (x_blob, widgets);
2346 gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
2348 marker_x = (pc * widgets->profile_width) + MARGIN;
2351 save_image_and_draw_graph_marks (image,
2353 gtk_widget_get_style(window)->black_gc,
2356 &widgets->speed_dist_graph_saved_img,
2357 widgets->profile_width,
2358 widgets->profile_height,
2359 &widgets->is_marker_drawn,
2360 &widgets->is_blob_drawn);
2367 * Configure/Resize the profile & speed/time images
2369 static gboolean configure_event ( GtkWidget *widget, GdkEventConfigure *event, PropWidgets *widgets )
2371 if (widgets->configure_dialog) {
2372 // Determine size offsets between dialog size and size for images
2373 // Only on the initialisation of the dialog
2374 widgets->profile_width_offset = event->width - widgets->profile_width;
2375 widgets->profile_height_offset = event->height - widgets->profile_height;
2376 widgets->configure_dialog = FALSE;
2378 // Without this the settting, the dialog will only grow in vertical size - one can not then make it smaller!
2379 gtk_widget_set_size_request ( widget, widgets->profile_width+widgets->profile_width_offset, widgets->profile_height );
2380 // In fact this allows one to compress it a bit more vertically as I don't add on the height offset
2383 widgets->profile_width_old = widgets->profile_width;
2384 widgets->profile_height_old = widgets->profile_height;
2387 // Now adjust From Dialog size to get image size
2388 widgets->profile_width = event->width - widgets->profile_width_offset;
2389 widgets->profile_height = event->height - widgets->profile_height_offset;
2391 // ATM we receive configure_events when the dialog is moved and so no further action is necessary
2392 if ( !widgets->configure_dialog &&
2393 (widgets->profile_width_old == widgets->profile_width) && (widgets->profile_height_old == widgets->profile_height) )
2397 draw_all_graphs ( widget, widgets, TRUE );
2403 * Create height profile widgets including the image and callbacks
2405 GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, PropWidgets *widgets, gdouble *min_alt, gdouble *max_alt)
2409 GtkWidget *eventbox;
2412 widgets->altitudes = vik_track_make_elevation_map ( widgets->tr, widgets->profile_width );
2414 if ( widgets->altitudes == NULL ) {
2415 *min_alt = *max_alt = VIK_DEFAULT_ALTITUDE;
2419 minmax_array(widgets->altitudes, min_alt, max_alt, TRUE, widgets->profile_width);
2421 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2422 image = gtk_image_new_from_pixmap ( pix, NULL );
2424 g_object_unref ( G_OBJECT(pix) );
2426 eventbox = gtk_event_box_new ();
2427 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_profile_click), widgets );
2428 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_profile_move), widgets );
2429 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2430 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_STRUCTURE_MASK);
2436 * Create height profile widgets including the image and callbacks
2438 GtkWidget *vik_trw_layer_create_gradient ( GtkWidget *window, PropWidgets *widgets)
2442 GtkWidget *eventbox;
2445 widgets->gradients = vik_track_make_gradient_map ( widgets->tr, widgets->profile_width );
2447 if ( widgets->gradients == NULL ) {
2451 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2452 image = gtk_image_new_from_pixmap ( pix, NULL );
2454 g_object_unref ( G_OBJECT(pix) );
2456 eventbox = gtk_event_box_new ();
2457 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_gradient_click), widgets );
2458 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_gradient_move), widgets );
2459 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2460 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_STRUCTURE_MASK);
2466 * Create speed/time widgets including the image and callbacks
2468 GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, PropWidgets *widgets)
2472 GtkWidget *eventbox;
2475 widgets->speeds = vik_track_make_speed_map ( widgets->tr, widgets->profile_width );
2476 if ( widgets->speeds == NULL )
2479 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2480 image = gtk_image_new_from_pixmap ( pix, NULL );
2483 /* XXX this can go out, it's just a helpful dev tool */
2486 GdkGC **colors[8] = { gtk_widget_get_style(window)->bg_gc,
2487 gtk_widget_get_style(window)->fg_gc,
2488 gtk_widget_get_style(window)->light_gc,
2489 gtk_widget_get_style(window)->dark_gc,
2490 gtk_widget_get_style(window)->mid_gc,
2491 gtk_widget_get_style(window)->text_gc,
2492 gtk_widget_get_style(window)->base_gc,
2493 gtk_widget_get_style(window)->text_aa_gc };
2494 for (i=0; i<5; i++) {
2495 for (j=0; j<8; j++) {
2496 gdk_draw_rectangle(GDK_DRAWABLE(pix), colors[j][i],
2497 TRUE, i*20, j*20, 20, 20);
2498 gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc,
2499 FALSE, i*20, j*20, 20, 20);
2505 g_object_unref ( G_OBJECT(pix) );
2507 eventbox = gtk_event_box_new ();
2508 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_vt_click), widgets );
2509 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_vt_move), widgets );
2510 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2511 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2517 * Create distance / time widgets including the image and callbacks
2519 GtkWidget *vik_trw_layer_create_dtdiag ( GtkWidget *window, PropWidgets *widgets)
2523 GtkWidget *eventbox;
2526 widgets->distances = vik_track_make_distance_map ( widgets->tr, widgets->profile_width );
2527 if ( widgets->distances == NULL )
2530 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2531 image = gtk_image_new_from_pixmap ( pix, NULL );
2533 g_object_unref ( G_OBJECT(pix) );
2535 eventbox = gtk_event_box_new ();
2536 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_dt_click), widgets );
2537 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_dt_move), widgets );
2538 //g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), widgets );
2539 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2540 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2546 * Create elevation / time widgets including the image and callbacks
2548 GtkWidget *vik_trw_layer_create_etdiag ( GtkWidget *window, PropWidgets *widgets)
2552 GtkWidget *eventbox;
2555 widgets->ats = vik_track_make_elevation_time_map ( widgets->tr, widgets->profile_width );
2556 if ( widgets->ats == NULL )
2559 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2560 image = gtk_image_new_from_pixmap ( pix, NULL );
2562 g_object_unref ( G_OBJECT(pix) );
2564 eventbox = gtk_event_box_new ();
2565 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_et_click), widgets );
2566 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_et_move), widgets );
2567 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2568 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2574 * Create speed/distance widgets including the image and callbacks
2576 GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, PropWidgets *widgets)
2580 GtkWidget *eventbox;
2583 widgets->speeds_dist = vik_track_make_speed_dist_map ( widgets->tr, widgets->profile_width );
2584 if ( widgets->speeds_dist == NULL )
2587 pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
2588 image = gtk_image_new_from_pixmap ( pix, NULL );
2590 g_object_unref ( G_OBJECT(pix) );
2592 eventbox = gtk_event_box_new ();
2593 g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_sd_click), widgets );
2594 g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_sd_move), widgets );
2595 gtk_container_add ( GTK_CONTAINER(eventbox), image );
2596 gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
2602 static void destroy_cb ( GtkDialog *dialog, PropWidgets *widgets )
2604 prop_widgets_free(widgets);
2607 static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widgets )
2609 VikTrack *tr = widgets->tr;
2610 VikTrwLayer *vtl = widgets->vtl;
2611 gboolean keep_dialog = FALSE;
2613 /* FIXME: check and make sure the track still exists before doing anything to it */
2614 /* Note: destroying diaglog (eg, parent window exit) won't give "response" */
2616 case GTK_RESPONSE_DELETE_EVENT: /* received delete event (not from buttons) */
2617 case GTK_RESPONSE_REJECT:
2619 case GTK_RESPONSE_ACCEPT:
2620 vik_track_set_comment(tr, gtk_entry_get_text(GTK_ENTRY(widgets->w_comment)));
2621 vik_track_set_description(tr, gtk_entry_get_text(GTK_ENTRY(widgets->w_description)));
2622 gtk_color_button_get_color ( GTK_COLOR_BUTTON(widgets->w_color), &(tr->color) );
2623 trw_layer_update_treeview ( widgets->vtl, widgets->tr, widgets->trk_id );
2624 vik_layer_emit_update ( VIK_LAYER(vtl) );
2626 case VIK_TRW_LAYER_PROPWIN_REVERSE:
2627 vik_track_reverse(tr);
2628 vik_layer_emit_update ( VIK_LAYER(vtl) );
2630 case VIK_TRW_LAYER_PROPWIN_DEL_DUP:
2631 vik_track_remove_dup_points(tr); // NB ignore the returned answer
2632 // As we could have seen the nuber of dulplicates that would be deleted in the properties statistics tab,
2633 // choose not to inform the user unnecessarily
2635 /* above operation could have deleted current_tp or last_tp */
2636 trw_layer_cancel_tps_of_track ( vtl, tr );
2637 vik_layer_emit_update ( VIK_LAYER(vtl) );
2639 case VIK_TRW_LAYER_PROPWIN_SPLIT:
2641 /* get new tracks, add them and then the delete old one. old can still exist on clipboard. */
2644 VikTrack **tracks = vik_track_split_into_segments(tr, &ntracks);
2647 for ( i = 0; i < ntracks; i++ )
2650 new_tr_name = trw_layer_new_unique_sublayer_name ( vtl,
2651 widgets->tr->is_route ? VIK_TRW_LAYER_SUBLAYER_ROUTE : VIK_TRW_LAYER_SUBLAYER_TRACK,
2653 if ( widgets->tr->is_route )
2654 vik_trw_layer_add_route ( vtl, new_tr_name, tracks[i] );
2656 vik_trw_layer_add_track ( vtl, new_tr_name, tracks[i] );
2662 /* Don't let track destroy this dialog */
2663 vik_track_clear_property_dialog(tr);
2664 if ( widgets->tr->is_route )
2665 vik_trw_layer_delete_route ( vtl, tr );
2667 vik_trw_layer_delete_track ( vtl, tr );
2668 vik_layer_emit_update ( VIK_LAYER(vtl) ); /* chase thru the hoops */
2672 case VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER:
2674 GList *iter = tr->trackpoints;
2675 while ((iter = iter->next)) {
2676 if (widgets->marker_tp == VIK_TRACKPOINT(iter->data))
2680 a_dialog_msg(VIK_GTK_WINDOW_FROM_LAYER(vtl), GTK_MESSAGE_ERROR,
2681 _("Failed spliting track. Track unchanged"), NULL);
2686 gchar *r_name = trw_layer_new_unique_sublayer_name(vtl,
2687 widgets->tr->is_route ? VIK_TRW_LAYER_SUBLAYER_ROUTE : VIK_TRW_LAYER_SUBLAYER_TRACK,
2689 iter->prev->next = NULL;
2691 VikTrack *tr_right = vik_track_new();
2693 vik_track_set_comment ( tr_right, tr->comment );
2694 tr_right->visible = tr->visible;
2695 tr_right->is_route = tr->is_route;
2696 tr_right->trackpoints = iter;
2698 if ( widgets->tr->is_route )
2699 vik_trw_layer_add_route(vtl, r_name, tr_right);
2701 vik_trw_layer_add_track(vtl, r_name, tr_right);
2702 vik_layer_emit_update ( VIK_LAYER(vtl) );
2706 fprintf(stderr, "DEBUG: unknown response\n");
2710 /* Keep same behaviour for now: destroy dialog if click on any button */
2712 vik_track_clear_property_dialog(tr);
2713 gtk_widget_destroy ( GTK_WIDGET(dialog) );
2718 * Force a redraw when checkbutton has been toggled to show/hide that information
2720 static void checkbutton_toggle_cb ( GtkToggleButton *togglebutton, PropWidgets *widgets, gpointer dummy )
2722 // Even though not resized, we'll pretend it is -
2723 // as this invalidates the saved images (since the image may have changed)
2724 draw_all_graphs ( widgets->dialog, widgets, TRUE );
2728 * Create the widgets for the given graph tab
2730 static GtkWidget *create_graph_page ( GtkWidget *graph,
2731 const gchar *markup,
2733 const gchar *markup2,
2735 GtkWidget *checkbutton1,
2736 gboolean checkbutton1_default,
2737 GtkWidget *checkbutton2,
2738 gboolean checkbutton2_default )
2740 GtkWidget *hbox = gtk_hbox_new ( FALSE, 10 );
2741 GtkWidget *vbox = gtk_vbox_new ( FALSE, 10 );
2742 GtkWidget *label = gtk_label_new (NULL);
2743 GtkWidget *label2 = gtk_label_new (NULL);
2744 gtk_box_pack_start (GTK_BOX(vbox), graph, FALSE, FALSE, 0);
2745 gtk_label_set_markup ( GTK_LABEL(label), markup );
2746 gtk_label_set_markup ( GTK_LABEL(label2), markup2 );
2747 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
2748 gtk_box_pack_start (GTK_BOX(hbox), value, FALSE, FALSE, 0);
2749 gtk_box_pack_start (GTK_BOX(hbox), label2, FALSE, FALSE, 0);
2750 gtk_box_pack_start (GTK_BOX(hbox), value2, FALSE, FALSE, 0);
2752 gtk_box_pack_end (GTK_BOX(hbox), checkbutton2, FALSE, FALSE, 0);
2753 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton2), checkbutton2_default);
2756 gtk_box_pack_end (GTK_BOX(hbox), checkbutton1, FALSE, FALSE, 0);
2757 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton1), checkbutton1_default);
2759 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
2764 void vik_trw_layer_propwin_run ( GtkWindow *parent,
2771 PropWidgets *widgets = prop_widgets_new();
2776 widgets->trk_id = trk_id;
2777 widgets->profile_width = PROPWIN_PROFILE_WIDTH;
2778 widgets->profile_height = PROPWIN_PROFILE_HEIGHT;
2779 gchar *title = g_strdup_printf(_("%s - Track Properties"), tr->name);
2780 GtkWidget *dialog = gtk_dialog_new_with_buttons (title,
2782 GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
2783 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
2784 _("Split at _Marker"), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER,
2785 _("Split _Segments"), VIK_TRW_LAYER_PROPWIN_SPLIT,
2786 _("_Reverse"), VIK_TRW_LAYER_PROPWIN_REVERSE,
2787 _("_Delete Dupl."), VIK_TRW_LAYER_PROPWIN_DEL_DUP,
2788 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2790 widgets->dialog = dialog;
2791 g_signal_connect( G_OBJECT(dialog), "response", G_CALLBACK(propwin_response_cb), widgets);
2799 gdouble min_alt, max_alt;
2800 widgets->elev_box = vik_trw_layer_create_profile(GTK_WIDGET(parent), widgets, &min_alt, &max_alt);
2801 widgets->gradient_box = vik_trw_layer_create_gradient(GTK_WIDGET(parent), widgets);
2802 widgets->speed_box = vik_trw_layer_create_vtdiag(GTK_WIDGET(parent), widgets);
2803 widgets->dist_box = vik_trw_layer_create_dtdiag(GTK_WIDGET(parent), widgets);
2804 widgets->elev_time_box = vik_trw_layer_create_etdiag(GTK_WIDGET(parent), widgets);
2805 widgets->speed_dist_box = vik_trw_layer_create_sddiag(GTK_WIDGET(parent), widgets);
2806 GtkWidget *graphs = gtk_notebook_new();
2808 GtkWidget *content[20];
2812 static gchar *label_texts[] = {
2813 N_("<b>Comment:</b>"),
2814 N_("<b>Description:</b>"),
2815 N_("<b>Track Length:</b>"),
2816 N_("<b>Trackpoints:</b>"),
2817 N_("<b>Segments:</b>"),
2818 N_("<b>Duplicate Points:</b>"),
2819 N_("<b>Max Speed:</b>"),
2820 N_("<b>Avg. Speed:</b>"),
2821 N_("<b>Moving Avg. Speed:</b>"),
2822 N_("<b>Avg. Dist. Between TPs:</b>"),
2823 N_("<b>Elevation Range:</b>"),
2824 N_("<b>Total Elevation Gain/Loss:</b>"),
2825 N_("<b>Start:</b>"),
2827 N_("<b>Duration:</b>"),
2828 N_("<b>Color:</b>") };
2829 static gchar tmp_buf[50];
2833 widgets->w_comment = gtk_entry_new ();
2835 gtk_entry_set_text ( GTK_ENTRY(widgets->w_comment), tr->comment );
2836 g_signal_connect_swapped ( widgets->w_comment, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
2837 content[cnt++] = widgets->w_comment;
2839 widgets->w_description = gtk_entry_new ();
2840 if ( tr->description )
2841 gtk_entry_set_text ( GTK_ENTRY(widgets->w_description), tr->description );
2842 g_signal_connect_swapped ( widgets->w_description, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
2843 content[cnt++] = widgets->w_description;
2845 vik_units_distance_t dist_units = a_vik_get_units_distance ();
2847 // NB This value not shown yet - but is used by internal calculations
2848 widgets->track_length_inc_gaps = vik_track_get_length_including_gaps(tr);
2850 tr_len = widgets->track_length = vik_track_get_length(tr);
2851 switch (dist_units) {
2852 case VIK_UNITS_DISTANCE_KILOMETRES:
2853 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", tr_len/1000.0 );
2855 case VIK_UNITS_DISTANCE_MILES:
2856 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(tr_len) );
2859 g_critical("Houston, we've had a problem. distance=%d", dist_units);
2861 widgets->w_track_length = content[cnt++] = gtk_label_new ( tmp_buf );
2863 tp_count = vik_track_get_tp_count(tr);
2864 g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", tp_count );
2865 widgets->w_tp_count = content[cnt++] = gtk_label_new ( tmp_buf );
2867 seg_count = vik_track_get_segment_count(tr) ;
2868 g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", seg_count );
2869 widgets->w_segment_count = content[cnt++] = gtk_label_new ( tmp_buf );
2871 g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", vik_track_get_dup_point_count(tr) );
2872 widgets->w_duptp_count = content[cnt++] = gtk_label_new ( tmp_buf );
2874 vik_units_speed_t speed_units = a_vik_get_units_speed ();
2875 tmp_speed = vik_track_get_max_speed(tr);
2876 if ( tmp_speed == 0 )
2877 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2879 switch (speed_units) {
2880 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2881 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2883 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2884 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2886 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2887 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2889 case VIK_UNITS_SPEED_KNOTS:
2890 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2893 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2894 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2897 widgets->w_max_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2899 tmp_speed = vik_track_get_average_speed(tr);
2900 if ( tmp_speed == 0 )
2901 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2903 switch (speed_units) {
2904 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2905 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2907 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2908 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2910 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2911 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2913 case VIK_UNITS_SPEED_KNOTS:
2914 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2917 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2918 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2921 widgets->w_avg_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2923 // Use 60sec as the default period to be considered stopped
2924 // this is the TrackWaypoint draw stops default value 'vtl->stop_length'
2925 // however this variable is not directly accessible - and I don't expect it's often changed from the default
2926 // so ATM just put in the number
2927 tmp_speed = vik_track_get_average_speed_moving(tr, 60);
2928 if ( tmp_speed == 0 )
2929 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2931 switch (speed_units) {
2932 case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
2933 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km/h", VIK_MPS_TO_KPH(tmp_speed));
2935 case VIK_UNITS_SPEED_MILES_PER_HOUR:
2936 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f mph", VIK_MPS_TO_MPH(tmp_speed));
2938 case VIK_UNITS_SPEED_METRES_PER_SECOND:
2939 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
2941 case VIK_UNITS_SPEED_KNOTS:
2942 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f knots", VIK_MPS_TO_KNOTS(tmp_speed));
2945 g_snprintf (tmp_buf, sizeof(tmp_buf), "--" );
2946 g_critical("Houston, we've had a problem. speed=%d", speed_units);
2949 widgets->w_mvg_speed = content[cnt++] = gtk_label_new ( tmp_buf );
2951 switch (dist_units) {
2952 case VIK_UNITS_DISTANCE_KILOMETRES:
2953 // Even though kilometres, the average distance between points is going to be quite small so keep in metres
2954 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m", (tp_count - seg_count) == 0 ? 0 : tr_len / ( tp_count - seg_count ) );
2956 case VIK_UNITS_DISTANCE_MILES:
2957 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 )) );
2960 g_critical("Houston, we've had a problem. distance=%d", dist_units);
2962 widgets->w_avg_dist = content[cnt++] = gtk_label_new ( tmp_buf );
2964 vik_units_height_t height_units = a_vik_get_units_height ();
2965 if ( min_alt == VIK_DEFAULT_ALTITUDE )
2966 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2968 switch (height_units) {
2969 case VIK_UNITS_HEIGHT_METRES:
2970 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m - %.0f m", min_alt, max_alt );
2972 case VIK_UNITS_HEIGHT_FEET:
2973 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f feet - %.0f feet", VIK_METERS_TO_FEET(min_alt), VIK_METERS_TO_FEET(max_alt) );
2976 g_snprintf(tmp_buf, sizeof(tmp_buf), "--" );
2977 g_critical("Houston, we've had a problem. height=%d", height_units);
2980 widgets->w_elev_range = content[cnt++] = gtk_label_new ( tmp_buf );
2982 vik_track_get_total_elevation_gain(tr, &max_alt, &min_alt );
2983 if ( min_alt == VIK_DEFAULT_ALTITUDE )
2984 g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data"));
2986 switch (height_units) {
2987 case VIK_UNITS_HEIGHT_METRES:
2988 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m / %.0f m", max_alt, min_alt );
2990 case VIK_UNITS_HEIGHT_FEET:
2991 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f feet / %.0f feet", VIK_METERS_TO_FEET(max_alt), VIK_METERS_TO_FEET(min_alt) );
2994 g_snprintf(tmp_buf, sizeof(tmp_buf), "--" );
2995 g_critical("Houston, we've had a problem. height=%d", height_units);
2998 widgets->w_elev_gain = content[cnt++] = gtk_label_new ( tmp_buf );
3001 #define PACK(w) gtk_box_pack_start (GTK_BOX(right_vbox), w, FALSE, FALSE, 0);
3002 gtk_box_pack_start (GTK_BOX(right_vbox), e_cmt, FALSE, FALSE, 0);
3015 if ( tr->trackpoints && VIK_TRACKPOINT(tr->trackpoints->data)->timestamp )
3018 t1 = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
3019 t2 = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp;
3021 strftime (tmp_buf, sizeof(tmp_buf), "%c", localtime(&(t1)));
3022 widgets->w_time_start = content[cnt++] = gtk_label_new(tmp_buf);
3024 strftime (tmp_buf, sizeof(tmp_buf), "%c", localtime(&(t2)));
3025 widgets->w_time_end = content[cnt++] = gtk_label_new(tmp_buf);
3027 g_snprintf(tmp_buf, sizeof(tmp_buf), _("%d minutes"), (int)(t2-t1)/60);
3028 widgets->w_time_dur = content[cnt++] = gtk_label_new(tmp_buf);
3030 widgets->w_time_start = content[cnt++] = gtk_label_new(_("No Data"));
3031 widgets->w_time_end = content[cnt++] = gtk_label_new(_("No Data"));
3032 widgets->w_time_dur = content[cnt++] = gtk_label_new(_("No Data"));
3035 widgets->w_color = content[cnt++] = gtk_color_button_new_with_color ( &(tr->color) );
3037 table = GTK_TABLE(gtk_table_new (cnt, 2, FALSE));
3038 gtk_table_set_col_spacing (table, 0, 10);
3039 for (i=0; i<cnt; i++) {
3042 // Settings so the text positioning only moves around vertically when the dialog is resized
3043 // This also gives more room to see the track comment
3044 label = gtk_label_new(NULL);
3045 gtk_misc_set_alignment ( GTK_MISC(label), 1, 0.5 ); // Position text centrally in vertical plane
3046 gtk_label_set_markup ( GTK_LABEL(label), _(label_texts[i]) );
3047 gtk_table_attach ( table, label, 0, 1, i, i+1, GTK_FILL, GTK_SHRINK, 0, 0 );
3048 if (GTK_IS_MISC(content[i])) {
3049 gtk_misc_set_alignment ( GTK_MISC(content[i]), 0, 0.5 );
3051 gtk_table_attach_defaults ( table, content[i], 1, 2, i, i+1 );
3054 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), GTK_WIDGET(table), gtk_label_new(_("Statistics")));
3056 if ( widgets->elev_box ) {
3057 GtkWidget *page = NULL;
3058 widgets->w_cur_dist = gtk_label_new(_("No Data"));
3059 widgets->w_cur_elevation = gtk_label_new(_("No Data"));
3060 widgets->w_show_dem = gtk_check_button_new_with_mnemonic(_("Show D_EM"));
3061 widgets->w_show_alt_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3062 page = create_graph_page (widgets->elev_box,
3063 _("<b>Track Distance:</b>"), widgets->w_cur_dist,
3064 _("<b>Track Height:</b>"), widgets->w_cur_elevation,
3065 widgets->w_show_dem, TRUE,
3066 widgets->w_show_alt_gps_speed, TRUE);
3067 g_signal_connect (widgets->w_show_dem, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3068 g_signal_connect (widgets->w_show_alt_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3069 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-distance")));
3072 if ( widgets->gradient_box ) {
3073 GtkWidget *page = NULL;
3074 widgets->w_cur_gradient_dist = gtk_label_new(_("No Data"));
3075 widgets->w_cur_gradient_gradient = gtk_label_new(_("No Data"));
3076 widgets->w_show_gradient_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3077 page = create_graph_page (widgets->gradient_box,
3078 _("<b>Track Distance:</b>"), widgets->w_cur_gradient_dist,
3079 _("<b>Track Gradient:</b>"), widgets->w_cur_gradient_gradient,
3080 widgets->w_show_gradient_gps_speed, TRUE,
3082 g_signal_connect (widgets->w_show_gradient_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3083 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Gradient-distance")));
3086 if ( widgets->speed_box ) {
3087 GtkWidget *page = NULL;
3088 widgets->w_cur_time = gtk_label_new(_("No Data"));
3089 widgets->w_cur_speed = gtk_label_new(_("No Data"));
3090 widgets->w_show_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3091 page = create_graph_page (widgets->speed_box,
3092 _("<b>Track Time:</b>"), widgets->w_cur_time,
3093 _("<b>Track Speed:</b>"), widgets->w_cur_speed,
3094 widgets->w_show_gps_speed, TRUE,
3096 g_signal_connect (widgets->w_show_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3097 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-time")));
3100 if ( widgets->dist_box ) {
3101 GtkWidget *page = NULL;
3102 widgets->w_cur_dist_time = gtk_label_new(_("No Data"));
3103 widgets->w_cur_dist_dist = gtk_label_new(_("No Data"));
3104 widgets->w_show_dist_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
3105 page = create_graph_page (widgets->dist_box,
3106 _("<b>Track Distance:</b>"), widgets->w_cur_dist_dist,
3107 _("<b>Track Time:</b>"), widgets->w_cur_dist_time,
3108 widgets->w_show_dist_speed, FALSE,
3110 g_signal_connect (widgets->w_show_dist_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3111 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Distance-time")));
3114 if ( widgets->elev_time_box ) {
3115 GtkWidget *page = NULL;
3116 widgets->w_cur_elev_time = gtk_label_new(_("No Data"));
3117 widgets->w_cur_elev_elev = gtk_label_new(_("No Data"));
3118 widgets->w_show_elev_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
3119 page = create_graph_page (widgets->elev_time_box,
3120 _("<b>Track Time:</b>"), widgets->w_cur_elev_time,
3121 _("<b>Track Height:</b>"), widgets->w_cur_elev_elev,
3122 widgets->w_show_elev_speed, FALSE,
3124 g_signal_connect (widgets->w_show_elev_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3125 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-time")));
3128 if ( widgets->speed_dist_box ) {
3129 GtkWidget *page = NULL;
3130 widgets->w_cur_speed_dist = gtk_label_new(_("No Data"));
3131 widgets->w_cur_speed_speed = gtk_label_new(_("No Data"));
3132 widgets->w_show_sd_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
3133 page = create_graph_page (widgets->speed_dist_box,
3134 _("<b>Track Distance:</b>"), widgets->w_cur_speed_dist,
3135 _("<b>Track Speed:</b>"), widgets->w_cur_speed_speed,
3136 widgets->w_show_sd_gps_speed, TRUE,
3138 g_signal_connect (widgets->w_show_sd_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
3139 gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-distance")));
3142 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), graphs, FALSE, FALSE, 0);
3144 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
3146 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT, FALSE);
3147 if (vik_track_get_dup_point_count(tr) <= 0)
3148 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_DEL_DUP, FALSE);
3150 // On dialog realization configure_event casues the graphs to be initially drawn
3151 widgets->configure_dialog = TRUE;
3152 g_signal_connect ( G_OBJECT(dialog), "configure-event", G_CALLBACK (configure_event), widgets );
3154 g_signal_connect ( G_OBJECT(dialog), "destroy", G_CALLBACK (destroy_cb), widgets );
3156 vik_track_set_property_dialog(tr, dialog);
3157 gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
3158 gtk_widget_show_all ( dialog );
3163 * Update this property dialog
3164 * e.g. if the track has been renamed
3166 void vik_trw_layer_propwin_update ( VikTrack *trk )
3168 // If not displayed do nothing
3169 if ( !trk->property_dialog )
3172 // Update title with current name
3174 gchar *title = g_strdup_printf ( _("%s - Track Properties"), trk->name );
3175 gtk_window_set_title ( GTK_WINDOW(trk->property_dialog), title );