]> git.street.me.uk Git - andy/viking.git/blame - src/viktrwlayer_propwin.c
Initial revision
[andy/viking.git] / src / viktrwlayer_propwin.c
CommitLineData
50a14534
EB
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#include <gtk/gtk.h>
23#include <time.h>
24#include "coords.h"
25#include "vikcoord.h"
26#include "viktrack.h"
27#include "viktrwlayer_propwin.h"
28#include "vikwaypoint.h"
29#include "dialog.h"
30#include "globals.h"
31
32#define PROFILE_WIDTH 600
33#define PROFILE_HEIGHT 300
34
35static void minmax_alt(const gdouble *altitudes, gdouble *min, gdouble *max)
36{
37 *max = -1000;
38 *min = 20000;
39 guint i;
40 for ( i=0; i < PROFILE_WIDTH; i++ ) {
41 if ( altitudes[i] != VIK_DEFAULT_ALTITUDE ) {
42 if ( altitudes[i] > *max )
43 *max = altitudes[i];
44 if ( altitudes[i] < *min )
45 *min = altitudes[i];
46 }
47 }
48
49}
50
51GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, VikTrack *tr, gdouble *min_alt, gdouble *max_alt )
52{
53 GdkPixmap *pix = gdk_pixmap_new( window->window, PROFILE_WIDTH, PROFILE_HEIGHT, -1 );
54 GtkWidget *image = gtk_image_new_from_pixmap ( pix, NULL );
55 gdouble *altitudes = vik_track_make_elevation_map ( tr, PROFILE_WIDTH );
56
57 guint i;
58
59 GdkGC *no_alt_info = gdk_gc_new ( window->window );
60 GdkColor color;
61
62 gdk_color_parse ( "red", &color );
63 gdk_gc_set_rgb_fg_color ( no_alt_info, &color);
64
65 minmax_alt(altitudes, min_alt, max_alt);
66
67 for ( i = 0; i < PROFILE_WIDTH; i++ )
68 if ( altitudes[i] == VIK_DEFAULT_ALTITUDE )
69 gdk_draw_line ( GDK_DRAWABLE(pix), no_alt_info, i, 0, i, PROFILE_HEIGHT );
70 else
71 gdk_draw_line ( GDK_DRAWABLE(pix), window->style->white_gc, i, 0, i, PROFILE_HEIGHT-PROFILE_HEIGHT*(altitudes[i]-*min_alt)/(*max_alt-*min_alt) );
72
73 g_object_unref ( G_OBJECT(pix) );
74 g_free ( altitudes );
75 g_object_unref ( G_OBJECT(no_alt_info) );
76 return image;
77}
78
79gint vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrack *tr )
80{
81 GtkWidget *dialog = gtk_dialog_new_with_buttons ("Track Properties",
82 parent,
83 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
84 GTK_STOCK_CANCEL,
85 GTK_RESPONSE_REJECT,
86 "Split Segments",
87 VIK_TRW_LAYER_PROPWIN_SPLIT,
88 "Reverse",
89 VIK_TRW_LAYER_PROPWIN_REVERSE,
90 "Delete Dupl.",
91 VIK_TRW_LAYER_PROPWIN_DEL_DUP,
92 GTK_STOCK_OK,
93 GTK_RESPONSE_ACCEPT,
94 NULL);
95 GtkWidget *left_vbox, *right_vbox, *hbox;
96 GtkWidget *e_cmt;
97 GtkWidget *l_len, *l_tps, *l_segs, *l_dups, *l_maxs, *l_avgs, *l_avgd, *l_elev, *l_galo;
98 gdouble tr_len;
99 guint32 tp_count, seg_count;
100 gint resp;
101
102 gdouble min_alt, max_alt;
103 GtkWidget *profile = vik_trw_layer_create_profile(GTK_WIDGET(parent),tr,&min_alt,&max_alt);
104
105 static gchar *label_texts[] = { "<b>Comment:</b>", "<b>Track Length:</b>", "<b>Trackpoints:</b>", "<b>Segments:</b>", "<b>Duplicate Points</b>", "<b>Max Speed</b>", "<b>Avg. Speed</b>", "<b>Avg. Dist. Between TPs</b>", "<b>Elevation Range</b>", "<b>Total Elevation Gain/Loss:</b>" };
106 static gchar tmp_buf[20];
107
108 left_vbox = a_dialog_create_label_vbox ( label_texts, sizeof(label_texts) / sizeof(label_texts[0]) );
109 right_vbox = gtk_vbox_new ( TRUE, 3 );
110
111 e_cmt = gtk_entry_new ();
112 if ( tr->comment )
113 gtk_entry_set_text ( GTK_ENTRY(e_cmt), tr->comment );
114 g_signal_connect_swapped ( e_cmt, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
115
116 tr_len = vik_track_get_length(tr);
117 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m", tr_len );
118 l_len = gtk_label_new ( tmp_buf );
119
120 tp_count = vik_track_get_tp_count(tr);
121 g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", tp_count );
122 l_tps = gtk_label_new ( tmp_buf );
123
124 seg_count = vik_track_get_segment_count(tr) ;
125 g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", seg_count );
126 l_segs = gtk_label_new ( tmp_buf );
127
128 g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", vik_track_get_dup_point_count(tr) );
129 l_dups = gtk_label_new ( tmp_buf );
130
131 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", vik_track_get_max_speed(tr) );
132 l_maxs = gtk_label_new ( tmp_buf );
133
134 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", vik_track_get_average_speed(tr) );
135 l_avgs = gtk_label_new ( tmp_buf );
136
137 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m", (tp_count - seg_count) == 0 ? 0 : tr_len / ( tp_count - seg_count ) );
138 l_avgd = gtk_label_new ( tmp_buf );
139
140 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m - %.0f m", min_alt, max_alt );
141 l_elev = gtk_label_new ( tmp_buf );
142
143 vik_track_get_total_elevation_gain(tr, &max_alt, &min_alt );
144 g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m / %.0f m", max_alt, min_alt );
145 l_galo = gtk_label_new ( tmp_buf );
146
147 gtk_box_pack_start (GTK_BOX(right_vbox), e_cmt, FALSE, FALSE, 0);
148 gtk_box_pack_start (GTK_BOX(right_vbox), l_len, FALSE, FALSE, 0);
149 gtk_box_pack_start (GTK_BOX(right_vbox), l_tps, FALSE, FALSE, 0);
150 gtk_box_pack_start (GTK_BOX(right_vbox), l_segs, FALSE, FALSE, 0);
151 gtk_box_pack_start (GTK_BOX(right_vbox), l_dups, FALSE, FALSE, 0);
152 gtk_box_pack_start (GTK_BOX(right_vbox), l_maxs, FALSE, FALSE, 0);
153 gtk_box_pack_start (GTK_BOX(right_vbox), l_avgs, FALSE, FALSE, 0);
154 gtk_box_pack_start (GTK_BOX(right_vbox), l_avgd, FALSE, FALSE, 0);
155 gtk_box_pack_start (GTK_BOX(right_vbox), l_elev, FALSE, FALSE, 0);
156 gtk_box_pack_start (GTK_BOX(right_vbox), l_galo, FALSE, FALSE, 0);
157
158 hbox = gtk_hbox_new ( TRUE, 0 );
159 gtk_box_pack_start (GTK_BOX(hbox), left_vbox, FALSE, FALSE, 0);
160 gtk_box_pack_start (GTK_BOX(hbox), right_vbox, FALSE, FALSE, 0);
161 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0);
162 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), profile, FALSE, FALSE, 0);
163
164
165 gtk_widget_show_all ( dialog );
166 resp = gtk_dialog_run (GTK_DIALOG (dialog));
167 if ( resp == GTK_RESPONSE_ACCEPT )
168 vik_track_set_comment ( tr, gtk_entry_get_text ( GTK_ENTRY(e_cmt) ) );
169
170 gtk_widget_destroy ( dialog );
171 return resp;
172}