]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
4 | * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | * | |
20 | */ | |
21 | ||
22 | #ifdef HAVE_CONFIG_H | |
23 | #include "config.h" | |
24 | #endif | |
25 | ||
26 | #include <math.h> | |
27 | ||
28 | #include <gtk/gtk.h> | |
29 | #include <glib/gi18n.h> | |
30 | #include <time.h> | |
31 | #include <string.h> | |
32 | #include "coords.h" | |
33 | #include "vikcoord.h" | |
34 | #include "viktrack.h" | |
35 | #include "viktrwlayer.h" | |
36 | #include "viktrwlayer_propwin.h" | |
37 | #include "vikwaypoint.h" | |
38 | #include "dialog.h" | |
39 | #include "globals.h" | |
40 | #include "dems.h" | |
41 | ||
42 | #include "vikviewport.h" /* ugh */ | |
43 | #include "viktreeview.h" /* ugh */ | |
44 | #include <gdk-pixbuf/gdk-pixdata.h> | |
45 | #include "viklayer.h" /* ugh */ | |
46 | #include "vikaggregatelayer.h" | |
47 | #include "viklayerspanel.h" /* ugh */ | |
48 | ||
49 | #define PROFILE_WIDTH 600 | |
50 | #define PROFILE_HEIGHT 300 | |
51 | #define MIN_ALT_DIFF 100.0 | |
52 | #define MIN_SPEED_DIFF 20.0 | |
53 | ||
54 | typedef struct _propsaved { | |
55 | gboolean saved; | |
56 | gint pos; | |
57 | GdkImage *img; | |
58 | } PropSaved; | |
59 | ||
60 | typedef struct _propwidgets { | |
61 | VikTrwLayer *vtl; | |
62 | VikTrack *tr; | |
63 | VikLayersPanel *vlp; | |
64 | gchar *track_name; | |
65 | GtkWidget *dialog; | |
66 | GtkWidget *w_comment; | |
67 | GtkWidget *w_track_length; | |
68 | GtkWidget *w_tp_count; | |
69 | GtkWidget *w_segment_count; | |
70 | GtkWidget *w_duptp_count; | |
71 | GtkWidget *w_max_speed; | |
72 | GtkWidget *w_avg_speed; | |
73 | GtkWidget *w_avg_dist; | |
74 | GtkWidget *w_elev_range; | |
75 | GtkWidget *w_elev_gain; | |
76 | GtkWidget *w_time_start; | |
77 | GtkWidget *w_time_end; | |
78 | GtkWidget *w_time_dur; | |
79 | GtkWidget *w_cur_dist; /*< Current distance */ | |
80 | GtkWidget *w_cur_time; /*< Current time */ | |
81 | gdouble track_length; | |
82 | PropSaved elev_graph_saved_img; | |
83 | PropSaved speed_graph_saved_img; | |
84 | GtkWidget *elev_box; | |
85 | GtkWidget *speed_box; | |
86 | VikTrackpoint *marker_tp; | |
87 | } PropWidgets; | |
88 | ||
89 | static PropWidgets *prop_widgets_new() | |
90 | { | |
91 | PropWidgets *widgets = g_malloc0(sizeof(PropWidgets)); | |
92 | ||
93 | return widgets; | |
94 | } | |
95 | ||
96 | static void prop_widgets_free(PropWidgets *widgets) | |
97 | { | |
98 | ||
99 | if (widgets->elev_graph_saved_img.img) | |
100 | g_object_unref(widgets->elev_graph_saved_img.img); | |
101 | if (widgets->speed_graph_saved_img.img) | |
102 | g_object_unref(widgets->speed_graph_saved_img.img); | |
103 | g_free(widgets); | |
104 | } | |
105 | ||
106 | static void minmax_alt(const gdouble *altitudes, gdouble *min, gdouble *max) | |
107 | { | |
108 | *max = -1000; | |
109 | *min = 20000; | |
110 | guint i; | |
111 | for ( i=0; i < PROFILE_WIDTH; i++ ) { | |
112 | if ( altitudes[i] != VIK_DEFAULT_ALTITUDE ) { | |
113 | if ( altitudes[i] > *max ) | |
114 | *max = altitudes[i]; | |
115 | if ( altitudes[i] < *min ) | |
116 | *min = altitudes[i]; | |
117 | } | |
118 | } | |
119 | } | |
120 | ||
121 | #define MARGIN 70 | |
122 | #define LINES 5 | |
123 | static VikTrackpoint *set_center_at_graph_position(gdouble event_x, gint img_width, VikLayersPanel *vlp, VikTrack *tr, gboolean time_base) | |
124 | { | |
125 | VikTrackpoint *trackpoint; | |
126 | gdouble x = event_x - img_width / 2 + PROFILE_WIDTH / 2 - MARGIN / 2; | |
127 | if (x < 0) | |
128 | x = 0; | |
129 | if (x > PROFILE_WIDTH) | |
130 | x = PROFILE_WIDTH; | |
131 | ||
132 | if (time_base) | |
133 | trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / PROFILE_WIDTH, NULL ); | |
134 | else | |
135 | trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / PROFILE_WIDTH, NULL ); | |
136 | ||
137 | if ( trackpoint ) { | |
138 | VikCoord coord = trackpoint->coord; | |
139 | vik_viewport_set_center_coord ( vik_layers_panel_get_viewport(vlp), &coord ); | |
140 | vik_layers_panel_emit_update ( vlp ); | |
141 | } | |
142 | return trackpoint; | |
143 | } | |
144 | ||
145 | static void draw_graph_mark(GtkWidget *image, gdouble event_x, gint img_width, GdkGC *gc, PropSaved *saved_img) | |
146 | { | |
147 | GdkPixmap *pix; | |
148 | const int saved_width = 5; | |
149 | /* the pixmap = margin + graph area */ | |
150 | gdouble x = event_x - img_width/2 + PROFILE_WIDTH/2 + MARGIN/2; | |
151 | ||
152 | // fprintf(stderr, "event_x=%f img_width=%d x=%f\n", event_x, img_width, x); | |
153 | ||
154 | gtk_image_get_pixmap(GTK_IMAGE(image), &pix, NULL); | |
155 | if (saved_img->saved) { | |
156 | gdk_draw_image(GDK_DRAWABLE(pix), gc, saved_img->img, 0, 0, | |
157 | saved_img->pos, 0, -1, -1); | |
158 | saved_img->saved = FALSE; | |
159 | gtk_widget_queue_draw_area(image, | |
160 | saved_img->pos + img_width/2 - PROFILE_WIDTH/2 - MARGIN/2, 0, | |
161 | saved_img->img->width, saved_img->img->height); | |
162 | } | |
163 | if ((x >= MARGIN) && (x < (PROFILE_WIDTH + MARGIN))) { | |
164 | if (saved_img->img) | |
165 | gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, | |
166 | x - (saved_width/2), 0, 0, 0, saved_img->img->width, saved_img->img->height); | |
167 | else | |
168 | saved_img->img = gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), | |
169 | saved_img->img, x - (saved_width/2), 0, 0, 0, saved_width, PROFILE_HEIGHT); | |
170 | saved_img->pos = x - (saved_width/2); | |
171 | saved_img->saved = TRUE; | |
172 | gdk_draw_line (GDK_DRAWABLE(pix), gc, x, 0, x, image->allocation.height); | |
173 | /* redraw the area which contains the line, saved_width is just convenient */ | |
174 | gtk_widget_queue_draw_area(image, event_x - saved_width/2, 0, saved_width, PROFILE_HEIGHT); | |
175 | } | |
176 | } | |
177 | ||
178 | static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along, gboolean is_vt_graph ) | |
179 | { | |
180 | VikTrack *tr = pass_along[0]; | |
181 | VikLayersPanel *vlp = pass_along[1]; | |
182 | PropWidgets *widgets = pass_along[2]; | |
183 | GList *child = gtk_container_get_children(GTK_CONTAINER(event_box)); | |
184 | GtkWidget *image = GTK_WIDGET(child->data); | |
185 | GtkWidget *window = gtk_widget_get_toplevel(GTK_WIDGET(event_box)); | |
186 | ||
187 | ||
188 | VikTrackpoint *trackpoint = set_center_at_graph_position(event->x, event_box->allocation.width, vlp, tr, is_vt_graph); | |
189 | draw_graph_mark(image, event->x, event_box->allocation.width, window->style->black_gc, | |
190 | is_vt_graph ? &widgets->speed_graph_saved_img : &widgets->elev_graph_saved_img); | |
191 | g_list_free(child); | |
192 | widgets->marker_tp = trackpoint; | |
193 | gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, TRUE); | |
194 | ||
195 | /* draw on the other graph */ | |
196 | if (trackpoint == NULL || widgets->elev_box == NULL || widgets->speed_box == NULL) | |
197 | /* This test assumes we have only 2 graphs */ | |
198 | return; | |
199 | ||
200 | gdouble pc = NAN; | |
201 | gdouble x2; | |
202 | GList *other_child = gtk_container_get_children(GTK_CONTAINER( | |
203 | is_vt_graph ? widgets->elev_box : widgets->speed_box)); | |
204 | GtkWidget *other_image = GTK_WIDGET(other_child->data); | |
205 | if (is_vt_graph) { | |
206 | gdouble dist = 0.0; | |
207 | GList *iter; | |
208 | for (iter = tr->trackpoints->next; iter != NULL; iter = iter->next) { | |
209 | dist += vik_coord_diff(&(VIK_TRACKPOINT(iter->data)->coord), | |
210 | &(VIK_TRACKPOINT(iter->prev->data)->coord)); | |
211 | /* Assuming trackpoint is not a copy */ | |
212 | if (trackpoint == VIK_TRACKPOINT(iter->data)) | |
213 | break; | |
214 | } | |
215 | if (iter != NULL) | |
216 | pc = dist/widgets->track_length; | |
217 | } else { | |
218 | time_t t_start, t_end, t_total; | |
219 | t_start = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp; | |
220 | t_end = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp; | |
221 | t_total = t_end - t_start; | |
222 | pc = (gdouble)(trackpoint->timestamp - t_start)/t_total; | |
223 | } | |
224 | if (!isnan(pc)) { | |
225 | x2 = pc * PROFILE_WIDTH + MARGIN + (event_box->allocation.width/2 - PROFILE_WIDTH/2 - MARGIN/2); | |
226 | draw_graph_mark(other_image, x2, event_box->allocation.width, window->style->black_gc, | |
227 | is_vt_graph ? &widgets->elev_graph_saved_img : &widgets->speed_graph_saved_img); | |
228 | } | |
229 | ||
230 | g_list_free(other_child); | |
231 | ||
232 | } | |
233 | ||
234 | static gboolean track_profile_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along ) | |
235 | { | |
236 | track_graph_click(event_box, event, pass_along, FALSE); | |
237 | return TRUE; /* don't call other (further) callbacks */ | |
238 | } | |
239 | ||
240 | static gboolean track_vt_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along ) | |
241 | { | |
242 | track_graph_click(event_box, event, pass_along, TRUE); | |
243 | return TRUE; /* don't call other (further) callbacks */ | |
244 | } | |
245 | ||
246 | void track_profile_move( GtkWidget *image, GdkEventMotion *event, gpointer *pass_along ) | |
247 | { | |
248 | VikTrack *tr = pass_along[0]; | |
249 | PropWidgets *widgets = pass_along[2]; | |
250 | int mouse_x, mouse_y; | |
251 | GdkModifierType state; | |
252 | ||
253 | if (event->is_hint) | |
254 | gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state); | |
255 | else | |
256 | mouse_x = event->x; | |
257 | ||
258 | gdouble x = mouse_x - image->allocation.width / 2 + PROFILE_WIDTH / 2 - MARGIN / 2; | |
259 | if (x < 0) | |
260 | x = 0; | |
261 | if (x > PROFILE_WIDTH) | |
262 | x = PROFILE_WIDTH; | |
263 | ||
264 | gdouble meters_from_start; | |
265 | VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / PROFILE_WIDTH, &meters_from_start ); | |
266 | if (trackpoint && widgets->w_cur_dist) { | |
267 | static gchar tmp_buf[20]; | |
268 | g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m", meters_from_start); | |
269 | gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist), tmp_buf); | |
270 | } | |
271 | } | |
272 | ||
273 | void track_vt_move( GtkWidget *image, GdkEventMotion *event, gpointer *pass_along ) | |
274 | { | |
275 | VikTrack *tr = pass_along[0]; | |
276 | PropWidgets *widgets = pass_along[2]; | |
277 | int mouse_x, mouse_y; | |
278 | GdkModifierType state; | |
279 | ||
280 | if (event->is_hint) | |
281 | gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state); | |
282 | else | |
283 | mouse_x = event->x; | |
284 | ||
285 | gdouble x = mouse_x - image->allocation.width / 2 + PROFILE_WIDTH / 2 - MARGIN / 2; | |
286 | if (x < 0) | |
287 | x = 0; | |
288 | if (x > PROFILE_WIDTH) | |
289 | x = PROFILE_WIDTH; | |
290 | ||
291 | time_t seconds_from_start; | |
292 | VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / PROFILE_WIDTH, &seconds_from_start ); | |
293 | if (trackpoint && widgets->w_cur_time) { | |
294 | static gchar tmp_buf[20]; | |
295 | guint h, m, s; | |
296 | h = seconds_from_start/3600; | |
297 | m = (seconds_from_start - h*3600)/60; | |
298 | s = seconds_from_start - (3600*h) - (60*m); | |
299 | g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s); | |
300 | ||
301 | gtk_label_set_text(GTK_LABEL(widgets->w_cur_time), tmp_buf); | |
302 | } | |
303 | } | |
304 | ||
305 | static void draw_dem_alt_speed_dist(VikTrack *tr, GdkDrawable *pix, GdkGC *alt_gc, GdkGC *speed_gc, gdouble alt_offset, gdouble alt_diff, gint width, gint height, gint margin) | |
306 | { | |
307 | GList *iter; | |
308 | gdouble dist = 0; | |
309 | gdouble max_speed = 0; | |
310 | gdouble total_length = vik_track_get_length_including_gaps(tr); | |
311 | ||
312 | for (iter = tr->trackpoints->next; iter; iter = iter->next) { | |
313 | if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) | |
314 | max_speed = MAX(max_speed, VIK_TRACKPOINT(iter->data)->speed); | |
315 | } | |
316 | max_speed = max_speed * 110 / 100; | |
317 | ||
318 | for (iter = tr->trackpoints->next; iter; iter = iter->next) { | |
319 | int x, y_alt, y_speed; | |
320 | gint16 elev = a_dems_get_elev_by_coord(&(VIK_TRACKPOINT(iter->data)->coord), VIK_DEM_INTERPOL_BEST); | |
321 | elev -= alt_offset; | |
322 | dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord), | |
323 | &(VIK_TRACKPOINT(iter->prev->data)->coord) ); | |
324 | x = (width * dist)/total_length + margin; | |
325 | if ( elev != VIK_DEM_INVALID_ELEVATION ) { | |
326 | y_alt = height - ((height * elev)/alt_diff); | |
327 | gdk_draw_rectangle(GDK_DRAWABLE(pix), alt_gc, TRUE, x-2, y_alt-2, 4, 4); | |
328 | } | |
329 | if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) { | |
330 | y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed; | |
331 | gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4); | |
332 | } | |
333 | } | |
334 | } | |
335 | ||
336 | GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, VikTrack *tr, gpointer vlp, PropWidgets *widgets, gdouble *min_alt, gdouble *max_alt) | |
337 | { | |
338 | GdkPixmap *pix; | |
339 | GtkWidget *image; | |
340 | gdouble *altitudes = vik_track_make_elevation_map ( tr, PROFILE_WIDTH ); | |
341 | gdouble mina, maxa; | |
342 | GtkWidget *eventbox; | |
343 | gpointer *pass_along; | |
344 | guint i; | |
345 | ||
346 | if ( altitudes == NULL ) { | |
347 | *min_alt = *max_alt = VIK_DEFAULT_ALTITUDE; | |
348 | return NULL; | |
349 | } | |
350 | ||
351 | pix = gdk_pixmap_new( window->window, PROFILE_WIDTH + MARGIN, PROFILE_HEIGHT, -1 ); | |
352 | image = gtk_image_new_from_pixmap ( pix, NULL ); | |
353 | ||
354 | GdkGC *no_alt_info = gdk_gc_new ( window->window ); | |
355 | GdkGC *dem_alt_gc = gdk_gc_new ( window->window ); | |
356 | GdkGC *gps_speed_gc = gdk_gc_new ( window->window ); | |
357 | GdkColor color; | |
358 | ||
359 | gdk_color_parse ( "yellow", &color ); | |
360 | gdk_gc_set_rgb_fg_color ( no_alt_info, &color); | |
361 | gdk_color_parse ( "green", &color ); | |
362 | gdk_gc_set_rgb_fg_color ( dem_alt_gc, &color); | |
363 | gdk_color_parse ( "red", &color ); | |
364 | gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color); | |
365 | ||
366 | ||
367 | minmax_alt(altitudes, min_alt, max_alt); | |
368 | mina = *min_alt; | |
369 | maxa = *max_alt + ((*max_alt - *min_alt) * 0.25); | |
370 | ||
371 | /* clear the image */ | |
372 | gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0], | |
373 | TRUE, 0, 0, MARGIN, PROFILE_HEIGHT); | |
374 | gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0], | |
375 | TRUE, MARGIN, 0, PROFILE_WIDTH, PROFILE_HEIGHT); | |
376 | ||
377 | /* draw grid */ | |
378 | #define LABEL_FONT "Sans 7" | |
379 | for (i=0; i<=LINES; i++) { | |
380 | PangoFontDescription *pfd; | |
381 | PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL); | |
382 | gchar s[32]; | |
383 | int w, h; | |
384 | ||
385 | pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT); | |
386 | pfd = pango_font_description_from_string (LABEL_FONT); | |
387 | pango_layout_set_font_description (pl, pfd); | |
388 | pango_font_description_free (pfd); | |
389 | sprintf(s, "%8dm", (int)(mina + (LINES-i)*(maxa-mina)/LINES)); | |
390 | pango_layout_set_text(pl, s, -1); | |
391 | pango_layout_get_pixel_size (pl, &w, &h); | |
392 | gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3, | |
393 | CLAMP((int)i*PROFILE_HEIGHT/LINES - h/2, 0, PROFILE_HEIGHT-h), pl); | |
394 | ||
395 | gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0], | |
396 | MARGIN, PROFILE_HEIGHT/LINES * i, MARGIN + PROFILE_WIDTH, PROFILE_HEIGHT/LINES * i); | |
397 | } | |
398 | ||
399 | /* draw elevations */ | |
400 | for ( i = 0; i < PROFILE_WIDTH; i++ ) | |
401 | if ( altitudes[i] == VIK_DEFAULT_ALTITUDE ) | |
402 | gdk_draw_line ( GDK_DRAWABLE(pix), no_alt_info, | |
403 | i + MARGIN, 0, i + MARGIN, PROFILE_HEIGHT ); | |
404 | else | |
405 | gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3], | |
406 | i + MARGIN, PROFILE_HEIGHT, i + MARGIN, PROFILE_HEIGHT-PROFILE_HEIGHT*(altitudes[i]-mina)/(maxa-mina) ); | |
407 | ||
408 | draw_dem_alt_speed_dist(tr, GDK_DRAWABLE(pix), dem_alt_gc, gps_speed_gc, mina, maxa - mina, PROFILE_WIDTH, PROFILE_HEIGHT, MARGIN); | |
409 | ||
410 | /* draw border */ | |
411 | gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, PROFILE_WIDTH-1, PROFILE_HEIGHT-1); | |
412 | ||
413 | ||
414 | ||
415 | g_object_unref ( G_OBJECT(pix) ); | |
416 | g_free ( altitudes ); | |
417 | g_object_unref ( G_OBJECT(no_alt_info) ); | |
418 | g_object_unref ( G_OBJECT(dem_alt_gc) ); | |
419 | g_object_unref ( G_OBJECT(gps_speed_gc) ); | |
420 | ||
421 | pass_along = g_malloc ( sizeof(gpointer) * 3 ); /* FIXME: mem leak -- never be freed */ | |
422 | pass_along[0] = tr; | |
423 | pass_along[1] = vlp; | |
424 | pass_along[2] = widgets; | |
425 | ||
426 | eventbox = gtk_event_box_new (); | |
427 | g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_profile_click), pass_along ); | |
428 | g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_profile_move), pass_along ); | |
429 | g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along ); | |
430 | gtk_container_add ( GTK_CONTAINER(eventbox), image ); | |
431 | gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | |
432 | | GDK_POINTER_MOTION_MASK | |
433 | | GDK_POINTER_MOTION_HINT_MASK); | |
434 | ||
435 | return eventbox; | |
436 | } | |
437 | ||
438 | #define METRIC 1 | |
439 | #ifdef METRIC | |
440 | #define MTOK(v) ( (v)*3.6) /* m/s to km/h */ | |
441 | #else | |
442 | #define MTOK(v) ( (v)*3600.0/1000.0 * 0.6214) /* m/s to mph - we'll handle this globally eventually but for now ...*/ | |
443 | #endif | |
444 | ||
445 | GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, PropWidgets *widgets) | |
446 | { | |
447 | GdkPixmap *pix; | |
448 | GtkWidget *image; | |
449 | gdouble mins, maxs; | |
450 | guint i; | |
451 | GtkWidget *eventbox; | |
452 | gpointer *pass_along; | |
453 | ||
454 | pass_along = g_malloc ( sizeof(gpointer) * 3 ); /* FIXME: mem leak -- never be freed */ | |
455 | pass_along[0] = tr; | |
456 | pass_along[1] = vlp; | |
457 | pass_along[2] = widgets; | |
458 | ||
459 | gdouble *speeds = vik_track_make_speed_map ( tr, PROFILE_WIDTH ); | |
460 | if ( speeds == NULL ) | |
461 | return NULL; | |
462 | ||
463 | pix = gdk_pixmap_new( window->window, PROFILE_WIDTH + MARGIN, PROFILE_HEIGHT, -1 ); | |
464 | image = gtk_image_new_from_pixmap ( pix, NULL ); | |
465 | ||
466 | for (i=0; i<PROFILE_WIDTH; i++) { | |
467 | speeds[i] = MTOK(speeds[i]); | |
468 | } | |
469 | ||
470 | minmax_alt(speeds, &mins, &maxs); | |
471 | if (mins < 0.0) | |
472 | mins = 0; /* splines sometimes give negative speeds */ | |
473 | maxs = maxs + ((maxs - mins) * 0.1); | |
474 | if (maxs-mins < MIN_SPEED_DIFF) { | |
475 | maxs = mins + MIN_SPEED_DIFF; | |
476 | } | |
477 | ||
478 | /* clear the image */ | |
479 | gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0], | |
480 | TRUE, 0, 0, MARGIN, PROFILE_HEIGHT); | |
481 | gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0], | |
482 | TRUE, MARGIN, 0, PROFILE_WIDTH, PROFILE_HEIGHT); | |
483 | ||
484 | #if 0 | |
485 | /* XXX this can go out, it's just a helpful dev tool */ | |
486 | { | |
487 | int j; | |
488 | GdkGC **colors[8] = { window->style->bg_gc, window->style->fg_gc, | |
489 | window->style->light_gc, | |
490 | window->style->dark_gc, window->style->mid_gc, | |
491 | window->style->text_gc, window->style->base_gc, | |
492 | window->style->text_aa_gc }; | |
493 | for (i=0; i<5; i++) { | |
494 | for (j=0; j<8; j++) { | |
495 | gdk_draw_rectangle(GDK_DRAWABLE(pix), colors[j][i], | |
496 | TRUE, i*20, j*20, 20, 20); | |
497 | gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, | |
498 | FALSE, i*20, j*20, 20, 20); | |
499 | } | |
500 | } | |
501 | } | |
502 | #else | |
503 | ||
504 | /* draw grid */ | |
505 | #define LABEL_FONT "Sans 7" | |
506 | for (i=0; i<=LINES; i++) { | |
507 | PangoFontDescription *pfd; | |
508 | PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL); | |
509 | gchar s[32]; | |
510 | int w, h; | |
511 | ||
512 | pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT); | |
513 | pfd = pango_font_description_from_string (LABEL_FONT); | |
514 | pango_layout_set_font_description (pl, pfd); | |
515 | pango_font_description_free (pfd); | |
516 | #ifdef METRIC | |
517 | sprintf(s, "%5dkm/h", (int)(mins + (LINES-i)*(maxs-mins)/LINES)); | |
518 | #else | |
519 | sprintf(s, "%8dmph", (int)(mins + (LINES-i)*(maxs-mins)/LINES)); | |
520 | #endif | |
521 | pango_layout_set_text(pl, s, -1); | |
522 | pango_layout_get_pixel_size (pl, &w, &h); | |
523 | gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3, | |
524 | CLAMP((int)i*PROFILE_HEIGHT/LINES - h/2, 0, PROFILE_HEIGHT-h), pl); | |
525 | ||
526 | gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0], | |
527 | MARGIN, PROFILE_HEIGHT/LINES * i, MARGIN + PROFILE_WIDTH, PROFILE_HEIGHT/LINES * i); | |
528 | } | |
529 | ||
530 | ||
531 | /* draw speeds */ | |
532 | for ( i = 0; i < PROFILE_WIDTH; i++ ) | |
533 | gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3], | |
534 | i + MARGIN, PROFILE_HEIGHT, i + MARGIN, PROFILE_HEIGHT-PROFILE_HEIGHT*(speeds[i]-mins)/(maxs-mins) ); | |
535 | #endif | |
536 | ||
537 | ||
538 | GdkGC *gps_speed_gc = gdk_gc_new ( window->window ); | |
539 | GdkColor color; | |
540 | ||
541 | gdk_color_parse ( "red", &color ); | |
542 | gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color); | |
543 | ||
544 | time_t beg_time = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp; | |
545 | time_t dur = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp - beg_time; | |
546 | GList *iter; | |
547 | for (iter = tr->trackpoints; iter; iter = iter->next) { | |
548 | gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed; | |
549 | if (isnan(gps_speed)) | |
550 | continue; | |
551 | int x = MARGIN + PROFILE_WIDTH * (VIK_TRACKPOINT(iter->data)->timestamp - beg_time) / dur; | |
552 | int y = PROFILE_HEIGHT - PROFILE_HEIGHT*(MTOK(gps_speed) - mins)/(maxs - mins); | |
553 | gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4); | |
554 | } | |
555 | ||
556 | /* draw border */ | |
557 | gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, PROFILE_WIDTH-1, PROFILE_HEIGHT-1); | |
558 | ||
559 | g_object_unref ( G_OBJECT(pix) ); | |
560 | g_object_unref ( G_OBJECT(gps_speed_gc) ); | |
561 | g_free ( speeds ); | |
562 | ||
563 | eventbox = gtk_event_box_new (); | |
564 | g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_vt_click), pass_along ); | |
565 | g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_vt_move), pass_along ); | |
566 | g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along ); | |
567 | gtk_container_add ( GTK_CONTAINER(eventbox), image ); | |
568 | gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | |
569 | | GDK_POINTER_MOTION_MASK | |
570 | | GDK_POINTER_MOTION_HINT_MASK); | |
571 | ||
572 | return eventbox; | |
573 | } | |
574 | #undef MARGIN | |
575 | #undef LINES | |
576 | ||
577 | static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widgets) | |
578 | { | |
579 | VikTrack *tr = widgets->tr; | |
580 | VikTrwLayer *vtl = widgets->vtl; | |
581 | gboolean keep_dialog = FALSE; | |
582 | ||
583 | /* FIXME: check and make sure the track still exists before doing anything to it */ | |
584 | /* Note: destroying diaglog (eg, parent window exit) won't give "response" */ | |
585 | switch (resp) { | |
586 | case GTK_RESPONSE_DELETE_EVENT: /* received delete event (not from buttons) */ | |
587 | case GTK_RESPONSE_REJECT: | |
588 | break; | |
589 | case GTK_RESPONSE_ACCEPT: | |
590 | vik_track_set_comment(tr, gtk_entry_get_text(GTK_ENTRY(widgets->w_comment))); | |
591 | break; | |
592 | case VIK_TRW_LAYER_PROPWIN_REVERSE: | |
593 | vik_track_reverse(tr); | |
594 | vik_layer_emit_update ( VIK_LAYER(vtl) ); | |
595 | break; | |
596 | case VIK_TRW_LAYER_PROPWIN_DEL_DUP: | |
597 | vik_track_remove_dup_points(tr); | |
598 | /* above operation could have deleted current_tp or last_tp */ | |
599 | trw_layer_cancel_tps_of_track ( vtl, widgets->track_name ); | |
600 | vik_layer_emit_update ( VIK_LAYER(vtl) ); | |
601 | break; | |
602 | case VIK_TRW_LAYER_PROPWIN_SPLIT: | |
603 | { | |
604 | /* get new tracks, add them, resolve naming conflicts (free if cancel), and delete old. old can still exist on clipboard. */ | |
605 | guint ntracks; | |
606 | VikTrack **tracks = vik_track_split_into_segments(tr, &ntracks); | |
607 | gchar *new_tr_name; | |
608 | guint i; | |
609 | for ( i = 0; i < ntracks; i++ ) | |
610 | { | |
611 | g_assert ( tracks[i] ); | |
612 | new_tr_name = g_strdup_printf("%s #%d", widgets->track_name, i+1); | |
613 | /* if ( (wp_exists) && (! overwrite) ) */ | |
614 | /* don't need to upper case new_tr_name because old tr name was uppercase */ | |
615 | if ( vik_trw_layer_get_track(vtl, new_tr_name ) && | |
616 | ( ! a_dialog_overwrite ( VIK_GTK_WINDOW_FROM_LAYER(vtl), "The track \"%s\" exists, do you wish to overwrite it?", new_tr_name ) ) ) | |
617 | { | |
618 | gchar *new_new_tr_name = a_dialog_new_track ( VIK_GTK_WINDOW_FROM_LAYER(vtl), vik_trw_layer_get_tracks(vtl) ); | |
619 | g_free ( new_tr_name ); | |
620 | if (new_new_tr_name) | |
621 | new_tr_name = new_new_tr_name; | |
622 | else | |
623 | { | |
624 | new_tr_name = NULL; | |
625 | vik_track_free ( tracks[i] ); | |
626 | } | |
627 | } | |
628 | if ( new_tr_name ) | |
629 | vik_trw_layer_add_track ( vtl, new_tr_name, tracks[i] ); | |
630 | } | |
631 | if ( tracks ) | |
632 | { | |
633 | g_free ( tracks ); | |
634 | /* Don't let track destroy this dialog */ | |
635 | vik_track_clear_property_dialog(tr); | |
636 | vik_trw_layer_delete_track ( vtl, widgets->track_name ); | |
637 | vik_layer_emit_update ( VIK_LAYER(vtl) ); /* chase thru the hoops */ | |
638 | } | |
639 | } | |
640 | break; | |
641 | case VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER: | |
642 | { | |
643 | GList *iter = tr->trackpoints; | |
644 | while ((iter = iter->next)) { | |
645 | if (widgets->marker_tp == VIK_TRACKPOINT(iter->data)) | |
646 | break; | |
647 | } | |
648 | if (iter == NULL) { | |
649 | a_dialog_msg(VIK_GTK_WINDOW_FROM_LAYER(vtl), GTK_MESSAGE_ERROR, | |
650 | _("Failed spliting track. Track unchanged"), NULL); | |
651 | keep_dialog = TRUE; | |
652 | break; | |
653 | } | |
654 | ||
655 | gchar *r_name = g_strdup_printf("%s #R", widgets->track_name); | |
656 | if (vik_trw_layer_get_track(vtl, r_name ) && | |
657 | ( ! a_dialog_overwrite( VIK_GTK_WINDOW_FROM_LAYER(vtl), | |
658 | "The track \"%s\" exists, do you wish to overwrite it?", r_name))) | |
659 | { | |
660 | gchar *new_r_name = a_dialog_new_track( VIK_GTK_WINDOW_FROM_LAYER(vtl), vik_trw_layer_get_tracks(vtl) ); | |
661 | if (new_r_name) { | |
662 | g_free( r_name ); | |
663 | r_name = new_r_name; | |
664 | } | |
665 | else { | |
666 | a_dialog_msg(VIK_GTK_WINDOW_FROM_LAYER(vtl), GTK_MESSAGE_WARNING, | |
667 | _("Operation Aborted. Track unchanged"), NULL); | |
668 | keep_dialog = TRUE; | |
669 | break; | |
670 | } | |
671 | } | |
672 | iter->prev->next = NULL; | |
673 | iter->prev = NULL; | |
674 | VikTrack *tr_right = vik_track_new(); | |
675 | if ( tr->comment ) | |
676 | vik_track_set_comment ( tr_right, tr->comment ); | |
677 | tr_right->visible = tr->visible; | |
678 | tr_right->trackpoints = iter; | |
679 | ||
680 | vik_trw_layer_add_track(vtl, r_name, tr_right); | |
681 | vik_layer_emit_update ( VIK_LAYER(vtl) ); | |
682 | } | |
683 | break; | |
684 | default: | |
685 | fprintf(stderr, "DEBUG: unknown response\n"); | |
686 | return; | |
687 | } | |
688 | ||
689 | /* Keep same behaviour for now: destroy dialog if click on any button */ | |
690 | if (!keep_dialog) { | |
691 | prop_widgets_free(widgets); | |
692 | vik_track_clear_property_dialog(tr); | |
693 | gtk_widget_destroy ( GTK_WIDGET(dialog) ); | |
694 | } | |
695 | } | |
696 | ||
697 | static GtkWidget *create_graph_page ( GtkWidget *graph, | |
698 | const gchar *markup, | |
699 | GtkWidget *value) | |
700 | { | |
701 | GtkWidget *hbox = gtk_hbox_new ( FALSE, 10 ); | |
702 | GtkWidget *vbox = gtk_vbox_new ( FALSE, 10 ); | |
703 | GtkWidget *label = gtk_label_new (NULL); | |
704 | gtk_box_pack_start (GTK_BOX(vbox), graph, FALSE, FALSE, 0); | |
705 | gtk_label_set_markup ( GTK_LABEL(label), markup ); | |
706 | gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
707 | gtk_box_pack_start (GTK_BOX(hbox), value, FALSE, FALSE, 0); | |
708 | gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
709 | ||
710 | return vbox; | |
711 | } | |
712 | ||
713 | void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *tr, gpointer vlp, gchar *track_name ) | |
714 | { | |
715 | /* FIXME: free widgets when destroy signal received */ | |
716 | PropWidgets *widgets = prop_widgets_new(); | |
717 | widgets->vtl = vtl; | |
718 | widgets->tr = tr; | |
719 | widgets->vlp = vlp; | |
720 | widgets->track_name = track_name; | |
721 | gchar *title = g_strdup_printf(_("%s - Track Properties"), track_name); | |
722 | GtkWidget *dialog = gtk_dialog_new_with_buttons (title, | |
723 | parent, | |
724 | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, | |
725 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, | |
726 | _("Split at Marker"), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, | |
727 | _("Split Segments"), VIK_TRW_LAYER_PROPWIN_SPLIT, | |
728 | _("Reverse"), VIK_TRW_LAYER_PROPWIN_REVERSE, | |
729 | _("Delete Dupl."), VIK_TRW_LAYER_PROPWIN_DEL_DUP, | |
730 | GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, | |
731 | NULL); | |
732 | widgets->dialog = dialog; | |
733 | g_free(title); | |
734 | g_signal_connect(dialog, "response", G_CALLBACK(propwin_response_cb), widgets); | |
735 | //fprintf(stderr, "DEBUG: dialog=0x%p\n", dialog); | |
736 | GtkTable *table; | |
737 | gdouble tr_len; | |
738 | guint32 tp_count, seg_count; | |
739 | ||
740 | gdouble min_alt, max_alt; | |
741 | GtkWidget *profile = vik_trw_layer_create_profile(GTK_WIDGET(parent),tr, vlp, widgets, &min_alt,&max_alt); | |
742 | GtkWidget *vtdiag = vik_trw_layer_create_vtdiag(GTK_WIDGET(parent), tr, vlp, widgets); | |
743 | GtkWidget *graphs = gtk_notebook_new(); | |
744 | ||
745 | widgets->elev_box = profile; | |
746 | widgets->speed_box = vtdiag; | |
747 | ||
748 | GtkWidget *content[20]; | |
749 | int cnt; | |
750 | int i; | |
751 | ||
752 | static gchar *label_texts[] = { N_("<b>Comment:</b>"), N_("<b>Track Length:</b>"), N_("<b>Trackpoints:</b>"), N_("<b>Segments:</b>"), N_("<b>Duplicate Points:</b>"), N_("<b>Max Speed:</b>"), N_("<b>Avg. Speed:</b>"), N_("<b>Avg. Dist. Between TPs:</b>"), N_("<b>Elevation Range:</b>"), N_("<b>Total Elevation Gain/Loss:</b>"), N_("<b>Start:</b>"), N_("<b>End:</b>"), N_("<b>Duration:</b>") }; | |
753 | static gchar tmp_buf[50]; | |
754 | gdouble tmp_speed; | |
755 | ||
756 | cnt = 0; | |
757 | widgets->w_comment = gtk_entry_new (); | |
758 | if ( tr->comment ) | |
759 | gtk_entry_set_text ( GTK_ENTRY(widgets->w_comment), tr->comment ); | |
760 | g_signal_connect_swapped ( widgets->w_comment, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) ); | |
761 | content[cnt++] = widgets->w_comment; | |
762 | ||
763 | tr_len = widgets->track_length = vik_track_get_length(tr); | |
764 | g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m", tr_len ); | |
765 | widgets->w_track_length = content[cnt++] = gtk_label_new ( tmp_buf ); | |
766 | ||
767 | tp_count = vik_track_get_tp_count(tr); | |
768 | g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", tp_count ); | |
769 | widgets->w_tp_count = content[cnt++] = gtk_label_new ( tmp_buf ); | |
770 | ||
771 | seg_count = vik_track_get_segment_count(tr) ; | |
772 | g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", seg_count ); | |
773 | widgets->w_segment_count = content[cnt++] = gtk_label_new ( tmp_buf ); | |
774 | ||
775 | g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", vik_track_get_dup_point_count(tr) ); | |
776 | widgets->w_duptp_count = content[cnt++] = gtk_label_new ( tmp_buf ); | |
777 | ||
778 | tmp_speed = vik_track_get_max_speed(tr); | |
779 | if ( tmp_speed == 0 ) | |
780 | g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data")); | |
781 | else | |
782 | g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s (%.0f km/h)", tmp_speed, MTOK(tmp_speed) ); | |
783 | widgets->w_max_speed = content[cnt++] = gtk_label_new ( tmp_buf ); | |
784 | ||
785 | tmp_speed = vik_track_get_average_speed(tr); | |
786 | if ( tmp_speed == 0 ) | |
787 | g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data")); | |
788 | else | |
789 | g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s (%.0f km/h)", tmp_speed, MTOK(tmp_speed) ); | |
790 | widgets->w_avg_speed = content[cnt++] = gtk_label_new ( tmp_buf ); | |
791 | ||
792 | g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m", (tp_count - seg_count) == 0 ? 0 : tr_len / ( tp_count - seg_count ) ); | |
793 | widgets->w_avg_dist = content[cnt++] = gtk_label_new ( tmp_buf ); | |
794 | ||
795 | if ( min_alt == VIK_DEFAULT_ALTITUDE ) | |
796 | g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data")); | |
797 | else | |
798 | g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m - %.0f m", min_alt, max_alt ); | |
799 | widgets->w_elev_range = content[cnt++] = gtk_label_new ( tmp_buf ); | |
800 | ||
801 | vik_track_get_total_elevation_gain(tr, &max_alt, &min_alt ); | |
802 | if ( min_alt == VIK_DEFAULT_ALTITUDE ) | |
803 | g_snprintf(tmp_buf, sizeof(tmp_buf), _("No Data")); | |
804 | else | |
805 | g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m / %.0f m", max_alt, min_alt ); | |
806 | widgets->w_elev_gain = content[cnt++] = gtk_label_new ( tmp_buf ); | |
807 | ||
808 | #if 0 | |
809 | #define PACK(w) gtk_box_pack_start (GTK_BOX(right_vbox), w, FALSE, FALSE, 0); | |
810 | gtk_box_pack_start (GTK_BOX(right_vbox), e_cmt, FALSE, FALSE, 0); | |
811 | PACK(l_len); | |
812 | PACK(l_tps); | |
813 | PACK(l_segs); | |
814 | PACK(l_dups); | |
815 | PACK(l_maxs); | |
816 | PACK(l_avgs); | |
817 | PACK(l_avgd); | |
818 | PACK(l_elev); | |
819 | PACK(l_galo); | |
820 | #undef PACK; | |
821 | #endif | |
822 | ||
823 | if ( tr->trackpoints && VIK_TRACKPOINT(tr->trackpoints->data)->timestamp ) | |
824 | { | |
825 | time_t t1, t2; | |
826 | t1 = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp; | |
827 | t2 = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp; | |
828 | ||
829 | strncpy(tmp_buf, ctime(&t1), sizeof(tmp_buf)); | |
830 | tmp_buf[sizeof(tmp_buf)-1] = 0; | |
831 | g_strchomp(tmp_buf); | |
832 | widgets->w_time_start = content[cnt++] = gtk_label_new(tmp_buf); | |
833 | ||
834 | strncpy(tmp_buf, ctime(&t2), sizeof(tmp_buf)); | |
835 | tmp_buf[sizeof(tmp_buf)-1] = 0; | |
836 | g_strchomp(tmp_buf); | |
837 | widgets->w_time_end = content[cnt++] = gtk_label_new(tmp_buf); | |
838 | ||
839 | g_snprintf(tmp_buf, sizeof(tmp_buf), _("%d minutes"), (int)(t2-t1)/60); | |
840 | widgets->w_time_dur = content[cnt++] = gtk_label_new(tmp_buf); | |
841 | } else { | |
842 | widgets->w_time_start = content[cnt++] = gtk_label_new(_("No Data")); | |
843 | widgets->w_time_end = content[cnt++] = gtk_label_new(_("No Data")); | |
844 | widgets->w_time_dur = content[cnt++] = gtk_label_new(_("No Data")); | |
845 | } | |
846 | ||
847 | table = GTK_TABLE(gtk_table_new (cnt, 2, FALSE)); | |
848 | gtk_table_set_col_spacing (table, 0, 10); | |
849 | for (i=0; i<cnt; i++) { | |
850 | GtkWidget *label; | |
851 | ||
852 | label = gtk_label_new(NULL); | |
853 | gtk_misc_set_alignment ( GTK_MISC(label), 1, 0 ); | |
854 | gtk_label_set_markup ( GTK_LABEL(label), _(label_texts[i]) ); | |
855 | gtk_table_attach_defaults ( table, label, 0, 1, i, i+1 ); | |
856 | if (GTK_IS_MISC(content[i])) { | |
857 | gtk_misc_set_alignment ( GTK_MISC(content[i]), 0, 0 ); | |
858 | } | |
859 | gtk_table_attach_defaults ( table, content[i], 1, 2, i, i+1 ); | |
860 | } | |
861 | ||
862 | gtk_notebook_append_page(GTK_NOTEBOOK(graphs), GTK_WIDGET(table), gtk_label_new(_("Statistics"))); | |
863 | ||
864 | if ( profile ) { | |
865 | GtkWidget *page = NULL; | |
866 | widgets->w_cur_dist = gtk_label_new(_("No Data")); | |
867 | page = create_graph_page (profile, _("<b>Track Distance:</b>"), widgets->w_cur_dist ); | |
868 | gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-distance"))); | |
869 | } | |
870 | ||
871 | if ( vtdiag ) { | |
872 | GtkWidget *page = NULL; | |
873 | widgets->w_cur_time = gtk_label_new(_("No Data")); | |
874 | page = create_graph_page (vtdiag, _("<b>Track Time:</b>"), widgets->w_cur_time ); | |
875 | gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-time"))); | |
876 | } | |
877 | ||
878 | gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), graphs, FALSE, FALSE, 0); | |
879 | ||
880 | gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE); | |
881 | if (seg_count <= 1) | |
882 | gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT, FALSE); | |
883 | if (vik_track_get_dup_point_count(tr) <= 0) | |
884 | gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_DEL_DUP, FALSE); | |
885 | ||
886 | vik_track_set_property_dialog(tr, dialog); | |
887 | gtk_widget_show_all ( dialog ); | |
888 | } |