]>
Commit | Line | Data |
---|---|---|
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 | ||
4c77d5e0 GB |
22 | #ifdef HAVE_CONFIG_H |
23 | #include "config.h" | |
24 | #endif | |
25 | ||
50a14534 | 26 | #include <gtk/gtk.h> |
4c77d5e0 | 27 | #include <glib/gi18n.h> |
50a14534 | 28 | #include <time.h> |
86f7d733 | 29 | #include <math.h> |
50a14534 EB |
30 | |
31 | #include "coords.h" | |
32 | #include "vikcoord.h" | |
33 | #include "viktrack.h" | |
34 | #include "viktrwlayer_tpwin.h" | |
35 | #include "vikwaypoint.h" | |
36 | #include "dialog.h" | |
6f9336aa | 37 | #include "globals.h" |
93cfbc21 | 38 | #include "vikdatetime_edit_dialog.h" |
50a14534 | 39 | |
50a14534 EB |
40 | struct _VikTrwLayerTpwin { |
41 | GtkDialog parent; | |
0243b089 | 42 | GtkSpinButton *lat, *lon, *alt, *ts; |
b45865b4 | 43 | GtkWidget *trkpt_name; |
93cfbc21 RN |
44 | GtkWidget *localtime; |
45 | GtkLabel *course, *diff_dist, *diff_time, *diff_speed, *speed, *hdop, *vdop, *pdop, *sat; | |
2cada010 RN |
46 | // Previously these buttons were in a glist, however I think the ordering behaviour is implicit |
47 | // thus control manually to ensure operating on the correct button | |
48 | GtkWidget *button_close; | |
49 | GtkWidget *button_delete; | |
50 | GtkWidget *button_insert; | |
51 | GtkWidget *button_split; | |
52 | GtkWidget *button_back; | |
53 | GtkWidget *button_forward; | |
50a14534 | 54 | VikTrackpoint *cur_tp; |
50a14534 EB |
55 | gboolean sync_to_tp_block; |
56 | }; | |
57 | ||
58 | GType vik_trw_layer_tpwin_get_type (void) | |
59 | { | |
60 | static GType tpwin_type = 0; | |
61 | ||
62 | if (!tpwin_type) | |
63 | { | |
64 | static const GTypeInfo tpwin_info = | |
65 | { | |
66 | sizeof (VikTrwLayerTpwinClass), | |
67 | NULL, /* base_init */ | |
68 | NULL, /* base_finalize */ | |
69 | NULL, /* class init */ | |
70 | NULL, /* class_finalize */ | |
71 | NULL, /* class_data */ | |
72 | sizeof (VikTrwLayerTpwin), | |
73 | 0, | |
74 | NULL /* instance init */ | |
75 | }; | |
76 | tpwin_type = g_type_register_static ( GTK_TYPE_DIALOG, "VikTrwLayerTpwin", &tpwin_info, 0 ); | |
77 | } | |
78 | ||
79 | return tpwin_type; | |
80 | } | |
81 | ||
0243b089 RN |
82 | /** |
83 | * Just update the display for the time fields | |
84 | */ | |
85 | static void tpwin_update_times ( VikTrwLayerTpwin *tpwin, VikTrackpoint *tp ) | |
86 | { | |
87 | char tmp_str[64]; | |
88 | ||
89 | if ( tp->has_timestamp ) { | |
90 | gtk_spin_button_set_value ( tpwin->ts, tp->timestamp ); | |
91 | strftime ( tmp_str, sizeof(tmp_str), "%c", localtime(&(tp->timestamp)) ); | |
93cfbc21 | 92 | gtk_button_set_label ( GTK_BUTTON(tpwin->localtime), tmp_str ); |
0243b089 RN |
93 | } |
94 | else { | |
95 | gtk_spin_button_set_value ( tpwin->ts, 0 ); | |
93cfbc21 | 96 | gtk_button_set_label ( GTK_BUTTON(tpwin->localtime), "" ); |
0243b089 RN |
97 | } |
98 | } | |
99 | ||
50a14534 EB |
100 | static void tpwin_sync_ll_to_tp ( VikTrwLayerTpwin *tpwin ) |
101 | { | |
102 | if ( tpwin->cur_tp && (!tpwin->sync_to_tp_block) ) | |
103 | { | |
104 | struct LatLon ll; | |
105 | VikCoord coord; | |
106 | ll.lat = gtk_spin_button_get_value ( tpwin->lat ); | |
107 | ll.lon = gtk_spin_button_get_value ( tpwin->lon ); | |
108 | vik_coord_load_from_latlon ( &coord, tpwin->cur_tp->coord.mode, &ll ); | |
109 | ||
110 | /* don't redraw unless we really have to */ | |
111 | if ( vik_coord_diff(&(tpwin->cur_tp->coord), &coord) > 0.05 ) /* may not be exact due to rounding */ | |
112 | { | |
113 | tpwin->cur_tp->coord = coord; | |
114 | gtk_dialog_response ( GTK_DIALOG(tpwin), VIK_TRW_LAYER_TPWIN_DATA_CHANGED ); | |
115 | } | |
116 | } | |
117 | } | |
118 | ||
119 | static void tpwin_sync_alt_to_tp ( VikTrwLayerTpwin *tpwin ) | |
120 | { | |
6027a9c5 RN |
121 | if ( tpwin->cur_tp && (!tpwin->sync_to_tp_block) ) { |
122 | // Always store internally in metres | |
123 | vik_units_height_t height_units = a_vik_get_units_height (); | |
124 | switch (height_units) { | |
125 | case VIK_UNITS_HEIGHT_METRES: | |
126 | tpwin->cur_tp->altitude = gtk_spin_button_get_value ( tpwin->alt ); | |
127 | break; | |
128 | case VIK_UNITS_HEIGHT_FEET: | |
ab1e0693 | 129 | tpwin->cur_tp->altitude = VIK_FEET_TO_METERS(gtk_spin_button_get_value ( tpwin->alt )); |
6027a9c5 RN |
130 | break; |
131 | default: | |
132 | tpwin->cur_tp->altitude = gtk_spin_button_get_value ( tpwin->alt ); | |
133 | g_critical("Houston, we've had a problem. height=%d", height_units); | |
134 | } | |
135 | } | |
50a14534 EB |
136 | } |
137 | ||
0243b089 RN |
138 | /** |
139 | * | |
140 | */ | |
141 | static void tpwin_sync_ts_to_tp ( VikTrwLayerTpwin *tpwin ) | |
142 | { | |
143 | if ( tpwin->cur_tp && (!tpwin->sync_to_tp_block) ) { | |
144 | tpwin->cur_tp->timestamp = gtk_spin_button_get_value_as_int ( tpwin->ts ); | |
145 | ||
146 | tpwin_update_times ( tpwin, tpwin->cur_tp ); | |
147 | } | |
148 | } | |
149 | ||
2d4b00e1 RN |
150 | static time_t last_edit_time = 0; |
151 | ||
93cfbc21 RN |
152 | /** |
153 | * tpwin_sync_time_to_tp: | |
154 | * | |
155 | */ | |
156 | static void tpwin_sync_time_to_tp ( VikTrwLayerTpwin *tpwin ) | |
157 | { | |
158 | if ( !tpwin->cur_tp || tpwin->sync_to_tp_block ) | |
159 | return; | |
2d4b00e1 RN |
160 | |
161 | if ( tpwin->cur_tp->has_timestamp ) | |
162 | last_edit_time = tpwin->cur_tp->timestamp; | |
163 | else if ( last_edit_time == 0 ) | |
164 | time ( &last_edit_time ); | |
93cfbc21 RN |
165 | |
166 | GTimeZone *gtz = g_time_zone_new_local (); | |
2d4b00e1 RN |
167 | time_t mytime = vik_datetime_edit_dialog ( GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(&tpwin->parent))), |
168 | _("Date/Time Edit"), | |
169 | last_edit_time, | |
170 | gtz ); | |
93cfbc21 RN |
171 | g_time_zone_unref ( gtz ); |
172 | ||
173 | // Was the dialog cancelled? | |
174 | if ( mytime == 0 ) | |
175 | return; | |
176 | ||
177 | // Otherwise use the new value | |
178 | tpwin->cur_tp->timestamp = mytime; | |
2d4b00e1 | 179 | tpwin->cur_tp->has_timestamp = TRUE; |
93cfbc21 RN |
180 | // TODO: consider warning about unsorted times? |
181 | ||
2d4b00e1 RN |
182 | // Clear the previous 'Add' image as now a time is set |
183 | if ( gtk_button_get_image ( GTK_BUTTON(tpwin->localtime) ) ) | |
184 | gtk_button_set_image ( GTK_BUTTON(tpwin->localtime), NULL ); | |
185 | ||
93cfbc21 RN |
186 | tpwin_update_times ( tpwin, tpwin->cur_tp ); |
187 | } | |
188 | ||
f629b00b | 189 | static gboolean tpwin_set_name ( VikTrwLayerTpwin *tpwin ) |
b45865b4 RN |
190 | { |
191 | if ( tpwin->cur_tp && (!tpwin->sync_to_tp_block) ) { | |
192 | vik_trackpoint_set_name ( tpwin->cur_tp, gtk_entry_get_text(GTK_ENTRY(tpwin->trkpt_name)) ); | |
193 | } | |
f629b00b | 194 | return FALSE; |
b45865b4 RN |
195 | } |
196 | ||
50a14534 EB |
197 | VikTrwLayerTpwin *vik_trw_layer_tpwin_new ( GtkWindow *parent ) |
198 | { | |
b45865b4 | 199 | static gchar *left_label_texts[] = { N_("<b>Name:</b>"), |
86f7d733 | 200 | N_("<b>Latitude:</b>"), |
4c77d5e0 | 201 | N_("<b>Longitude:</b>"), |
86f7d733 RN |
202 | N_("<b>Altitude:</b>"), |
203 | N_("<b>Course:</b>"), | |
204 | N_("<b>Timestamp:</b>"), | |
205 | N_("<b>Time:</b>") }; | |
4c77d5e0 GB |
206 | static gchar *right_label_texts[] = { N_("<b>Distance Difference:</b>"), |
207 | N_("<b>Time Difference:</b>"), | |
86f7d733 RN |
208 | N_("<b>\"Speed\" Between:</b>"), |
209 | N_("<b>Speed:</b>"), | |
210 | N_("<b>VDOP:</b>"), | |
211 | N_("<b>HDOP:</b>"), | |
212 | N_("<b>PDOP:</b>"), | |
213 | N_("<b>SAT/FIX:</b>") }; | |
50a14534 EB |
214 | |
215 | VikTrwLayerTpwin *tpwin = VIK_TRW_LAYER_TPWIN ( g_object_new ( VIK_TRW_LAYER_TPWIN_TYPE, NULL ) ); | |
216 | GtkWidget *main_hbox, *left_vbox, *right_vbox; | |
217 | GtkWidget *diff_left_vbox, *diff_right_vbox; | |
50a14534 EB |
218 | |
219 | gtk_window_set_transient_for ( GTK_WINDOW(tpwin), parent ); | |
4c77d5e0 | 220 | gtk_window_set_title ( GTK_WINDOW(tpwin), _("Trackpoint") ); |
50a14534 | 221 | |
2cada010 RN |
222 | tpwin->button_close = gtk_dialog_add_button ( GTK_DIALOG(tpwin), GTK_STOCK_CLOSE, VIK_TRW_LAYER_TPWIN_CLOSE); |
223 | tpwin->button_insert = gtk_dialog_add_button ( GTK_DIALOG(tpwin), _("_Insert After"), VIK_TRW_LAYER_TPWIN_INSERT); | |
224 | tpwin->button_delete = gtk_dialog_add_button ( GTK_DIALOG(tpwin), GTK_STOCK_DELETE, VIK_TRW_LAYER_TPWIN_DELETE); | |
225 | tpwin->button_split = gtk_dialog_add_button ( GTK_DIALOG(tpwin), _("Split Here"), VIK_TRW_LAYER_TPWIN_SPLIT); | |
226 | tpwin->button_back = gtk_dialog_add_button ( GTK_DIALOG(tpwin), GTK_STOCK_GO_BACK, VIK_TRW_LAYER_TPWIN_BACK); | |
227 | tpwin->button_forward = gtk_dialog_add_button ( GTK_DIALOG(tpwin), GTK_STOCK_GO_FORWARD, VIK_TRW_LAYER_TPWIN_FORWARD); | |
228 | ||
229 | /* | |
50a14534 EB |
230 | gtk_dialog_add_buttons ( GTK_DIALOG(tpwin), |
231 | GTK_STOCK_CLOSE, VIK_TRW_LAYER_TPWIN_CLOSE, | |
2880a1de | 232 | _("_Insert After"), VIK_TRW_LAYER_TPWIN_INSERT, |
50a14534 | 233 | GTK_STOCK_DELETE, VIK_TRW_LAYER_TPWIN_DELETE, |
4c77d5e0 | 234 | _("Split Here"), VIK_TRW_LAYER_TPWIN_SPLIT, |
50a14534 EB |
235 | GTK_STOCK_GO_BACK, VIK_TRW_LAYER_TPWIN_BACK, |
236 | GTK_STOCK_GO_FORWARD, VIK_TRW_LAYER_TPWIN_FORWARD, | |
237 | NULL ); | |
238 | tpwin->buttons = gtk_container_get_children(GTK_CONTAINER(GTK_DIALOG(tpwin)->action_area)); | |
2cada010 | 239 | */ |
50a14534 EB |
240 | |
241 | /* main track info */ | |
86f7d733 | 242 | left_vbox = a_dialog_create_label_vbox ( left_label_texts, G_N_ELEMENTS(left_label_texts), 1, 3 ); |
50a14534 | 243 | |
b45865b4 RN |
244 | tpwin->trkpt_name = gtk_entry_new(); |
245 | g_signal_connect_swapped ( G_OBJECT(tpwin->trkpt_name), "focus-out-event", G_CALLBACK(tpwin_set_name), tpwin ); | |
246 | ||
86f7d733 | 247 | tpwin->course = GTK_LABEL(gtk_label_new(NULL)); |
93cfbc21 RN |
248 | tpwin->localtime = gtk_button_new(); |
249 | gtk_button_set_relief ( GTK_BUTTON(tpwin->localtime), GTK_RELIEF_NONE ); | |
250 | g_signal_connect_swapped ( G_OBJECT(tpwin->localtime), "clicked", G_CALLBACK(tpwin_sync_time_to_tp), tpwin ); | |
50a14534 EB |
251 | |
252 | tpwin->lat = GTK_SPIN_BUTTON(gtk_spin_button_new( GTK_ADJUSTMENT(gtk_adjustment_new ( | |
253 | 0, -90, 90, 0.00005, 0.01, 0 )), 0.00005, 6)); | |
254 | tpwin->lon = GTK_SPIN_BUTTON(gtk_spin_button_new( GTK_ADJUSTMENT(gtk_adjustment_new ( | |
255 | 0, -180, 180, 0.00005, 0.01, 0 )), 0.00005, 6)); | |
256 | ||
257 | g_signal_connect_swapped ( G_OBJECT(tpwin->lat), "value-changed", G_CALLBACK(tpwin_sync_ll_to_tp), tpwin ); | |
258 | g_signal_connect_swapped ( G_OBJECT(tpwin->lon), "value-changed", G_CALLBACK(tpwin_sync_ll_to_tp), tpwin ); | |
259 | ||
260 | tpwin->alt = GTK_SPIN_BUTTON(gtk_spin_button_new( GTK_ADJUSTMENT(gtk_adjustment_new ( | |
261 | 0, -1000, 25000, 10, 100, 0 )), 10, 2)); | |
262 | ||
263 | g_signal_connect_swapped ( G_OBJECT(tpwin->alt), "value-changed", G_CALLBACK(tpwin_sync_alt_to_tp), tpwin ); | |
264 | ||
0243b089 RN |
265 | tpwin->ts = GTK_SPIN_BUTTON(gtk_spin_button_new_with_range(0,2147483647,1)); //pow(2,31)-1 limit input to ~2038 for now |
266 | g_signal_connect_swapped ( G_OBJECT(tpwin->ts), "value-changed", G_CALLBACK(tpwin_sync_ts_to_tp), tpwin ); | |
267 | gtk_spin_button_set_digits ( tpwin->ts, 0 ); | |
268 | ||
86f7d733 | 269 | right_vbox = gtk_vbox_new ( TRUE, 1 ); |
b45865b4 | 270 | gtk_box_pack_start ( GTK_BOX(right_vbox), GTK_WIDGET(tpwin->trkpt_name), FALSE, FALSE, 3 ); |
86f7d733 RN |
271 | gtk_box_pack_start ( GTK_BOX(right_vbox), GTK_WIDGET(tpwin->lat), FALSE, FALSE, 3 ); |
272 | gtk_box_pack_start ( GTK_BOX(right_vbox), GTK_WIDGET(tpwin->lon), FALSE, FALSE, 3 ); | |
273 | gtk_box_pack_start ( GTK_BOX(right_vbox), GTK_WIDGET(tpwin->alt), FALSE, FALSE, 3 ); | |
274 | gtk_box_pack_start ( GTK_BOX(right_vbox), GTK_WIDGET(tpwin->course), FALSE, FALSE, 3 ); | |
275 | gtk_box_pack_start ( GTK_BOX(right_vbox), GTK_WIDGET(tpwin->ts), FALSE, FALSE, 3 ); | |
276 | gtk_box_pack_start ( GTK_BOX(right_vbox), GTK_WIDGET(tpwin->localtime), FALSE, FALSE, 3 ); | |
50a14534 EB |
277 | |
278 | /* diff info */ | |
86f7d733 | 279 | diff_left_vbox = a_dialog_create_label_vbox ( right_label_texts, G_N_ELEMENTS(right_label_texts), 1, 3 ); |
50a14534 EB |
280 | |
281 | tpwin->diff_dist = GTK_LABEL(gtk_label_new(NULL)); | |
282 | tpwin->diff_time = GTK_LABEL(gtk_label_new(NULL)); | |
283 | tpwin->diff_speed = GTK_LABEL(gtk_label_new(NULL)); | |
86f7d733 | 284 | tpwin->speed = GTK_LABEL(gtk_label_new(NULL)); |
50a14534 | 285 | |
4a42b254 T |
286 | tpwin->vdop = GTK_LABEL(gtk_label_new(NULL)); |
287 | tpwin->hdop = GTK_LABEL(gtk_label_new(NULL)); | |
288 | tpwin->pdop = GTK_LABEL(gtk_label_new(NULL)); | |
289 | tpwin->sat = GTK_LABEL(gtk_label_new(NULL)); | |
290 | ||
86f7d733 RN |
291 | diff_right_vbox = gtk_vbox_new ( TRUE, 1 ); |
292 | gtk_box_pack_start ( GTK_BOX(diff_right_vbox), GTK_WIDGET(tpwin->diff_dist), FALSE, FALSE, 3 ); | |
293 | gtk_box_pack_start ( GTK_BOX(diff_right_vbox), GTK_WIDGET(tpwin->diff_time), FALSE, FALSE, 3 ); | |
294 | gtk_box_pack_start ( GTK_BOX(diff_right_vbox), GTK_WIDGET(tpwin->diff_speed), FALSE, FALSE, 3 ); | |
295 | gtk_box_pack_start ( GTK_BOX(diff_right_vbox), GTK_WIDGET(tpwin->speed), FALSE, FALSE, 3 ); | |
50a14534 | 296 | |
86f7d733 RN |
297 | gtk_box_pack_start ( GTK_BOX(diff_right_vbox), GTK_WIDGET(tpwin->vdop), FALSE, FALSE, 3 ); |
298 | gtk_box_pack_start ( GTK_BOX(diff_right_vbox), GTK_WIDGET(tpwin->hdop), FALSE, FALSE, 3 ); | |
299 | gtk_box_pack_start ( GTK_BOX(diff_right_vbox), GTK_WIDGET(tpwin->pdop), FALSE, FALSE, 3 ); | |
300 | gtk_box_pack_start ( GTK_BOX(diff_right_vbox), GTK_WIDGET(tpwin->sat), FALSE, FALSE, 3 ); | |
4a42b254 | 301 | |
bc748ef1 | 302 | main_hbox = gtk_hbox_new( FALSE, 0 ); |
50a14534 EB |
303 | gtk_box_pack_start ( GTK_BOX(main_hbox), left_vbox, TRUE, TRUE, 0 ); |
304 | gtk_box_pack_start ( GTK_BOX(main_hbox), right_vbox, TRUE, TRUE, 0 ); | |
305 | gtk_box_pack_start ( GTK_BOX(main_hbox), diff_left_vbox, TRUE, TRUE, 0 ); | |
306 | gtk_box_pack_start ( GTK_BOX(main_hbox), diff_right_vbox, TRUE, TRUE, 0 ); | |
307 | ||
9b082b39 | 308 | gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(tpwin))), main_hbox, FALSE, FALSE, 0 ); |
50a14534 EB |
309 | |
310 | tpwin->cur_tp = NULL; | |
311 | ||
b45865b4 RN |
312 | GtkWidget *response_w = NULL; |
313 | #if GTK_CHECK_VERSION (2, 20, 0) | |
314 | response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(tpwin), VIK_TRW_LAYER_TPWIN_CLOSE ); | |
315 | #endif | |
316 | if ( response_w ) | |
317 | gtk_widget_grab_focus ( response_w ); | |
318 | ||
50a14534 EB |
319 | return tpwin; |
320 | } | |
321 | ||
322 | void vik_trw_layer_tpwin_set_empty ( VikTrwLayerTpwin *tpwin ) | |
323 | { | |
b45865b4 RN |
324 | gtk_editable_delete_text ( GTK_EDITABLE(tpwin->trkpt_name), 0, -1 ); |
325 | gtk_widget_set_sensitive ( tpwin->trkpt_name, FALSE ); | |
326 | ||
93cfbc21 | 327 | gtk_button_set_label ( GTK_BUTTON(tpwin->localtime), "" ); |
86f7d733 | 328 | gtk_label_set_text ( tpwin->course, NULL ); |
50a14534 EB |
329 | |
330 | gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->lat), FALSE ); | |
331 | gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->lon), FALSE ); | |
332 | gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->alt), FALSE ); | |
0243b089 | 333 | gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->ts), FALSE ); |
93cfbc21 | 334 | gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->localtime), FALSE ); |
50a14534 | 335 | |
2cada010 RN |
336 | // Only keep close button enabled |
337 | gtk_widget_set_sensitive ( tpwin->button_insert, FALSE ); | |
338 | gtk_widget_set_sensitive ( tpwin->button_split, FALSE ); | |
339 | gtk_widget_set_sensitive ( tpwin->button_delete, FALSE ); | |
340 | gtk_widget_set_sensitive ( tpwin->button_back, FALSE ); | |
341 | gtk_widget_set_sensitive ( tpwin->button_forward, FALSE ); | |
342 | ||
50a14534 EB |
343 | gtk_label_set_text ( tpwin->diff_dist, NULL ); |
344 | gtk_label_set_text ( tpwin->diff_time, NULL ); | |
345 | gtk_label_set_text ( tpwin->diff_speed, NULL ); | |
86f7d733 | 346 | gtk_label_set_text ( tpwin->speed, NULL ); |
4a42b254 T |
347 | gtk_label_set_text ( tpwin->vdop, NULL ); |
348 | gtk_label_set_text ( tpwin->hdop, NULL ); | |
349 | gtk_label_set_text ( tpwin->pdop, NULL ); | |
350 | gtk_label_set_text ( tpwin->sat, NULL ); | |
b45865b4 RN |
351 | |
352 | gtk_window_set_title ( GTK_WINDOW(tpwin), _("Trackpoint") ); | |
50a14534 EB |
353 | } |
354 | ||
2d4b00e1 RN |
355 | /** |
356 | * vik_trw_layer_tpwin_set_tp: | |
357 | * @tpwin: The Trackpoint Edit Window | |
358 | * @tpl: The #Glist of trackpoints pointing at the current trackpoint | |
359 | * @track_name: The name of the track in which the trackpoint belongs | |
360 | * @is_route: Is the track of the trackpoint actually a route? | |
361 | * | |
362 | * Sets the Trackpoint Edit Window to the values of the current trackpoint given in @tpl. | |
363 | * | |
364 | */ | |
365 | void vik_trw_layer_tpwin_set_tp ( VikTrwLayerTpwin *tpwin, GList *tpl, const gchar *track_name, gboolean is_route ) | |
50a14534 | 366 | { |
fff4e5e3 | 367 | static char tmp_str[64]; |
50a14534 EB |
368 | static struct LatLon ll; |
369 | VikTrackpoint *tp = VIK_TRACKPOINT(tpl->data); | |
370 | ||
b45865b4 RN |
371 | if ( tp->name ) |
372 | gtk_entry_set_text ( GTK_ENTRY(tpwin->trkpt_name), tp->name ); | |
373 | else | |
374 | gtk_editable_delete_text ( GTK_EDITABLE(tpwin->trkpt_name), 0, -1 ); | |
375 | gtk_widget_set_sensitive ( tpwin->trkpt_name, TRUE ); | |
376 | ||
2880a1de | 377 | /* Only can insert if not at the end (otherwise use extend track) */ |
2cada010 RN |
378 | gtk_widget_set_sensitive ( tpwin->button_insert, (gboolean) GPOINTER_TO_INT (tpl->next) ); |
379 | gtk_widget_set_sensitive ( tpwin->button_delete, TRUE ); | |
50a14534 EB |
380 | |
381 | /* We can only split up a track if it's not an endpoint. Makes sense to me. */ | |
2cada010 | 382 | gtk_widget_set_sensitive ( tpwin->button_split, tpl->next && tpl->prev ); |
50a14534 | 383 | |
2cada010 RN |
384 | gtk_widget_set_sensitive ( tpwin->button_forward, (gboolean) GPOINTER_TO_INT (tpl->next) ); |
385 | gtk_widget_set_sensitive ( tpwin->button_back, (gboolean) GPOINTER_TO_INT (tpl->prev) ); | |
50a14534 | 386 | |
50a14534 EB |
387 | gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->lat), TRUE ); |
388 | gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->lon), TRUE ); | |
21a4eb5f | 389 | gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->alt), TRUE ); |
0243b089 | 390 | gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->ts), tp->has_timestamp ); |
93cfbc21 | 391 | gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->localtime), tp->has_timestamp ); |
2d4b00e1 RN |
392 | // Enable adding timestamps - but not on routepoints |
393 | if ( !tp->has_timestamp && !is_route ) { | |
394 | gtk_widget_set_sensitive ( GTK_WIDGET(tpwin->localtime), TRUE ); | |
395 | GtkWidget *img = gtk_image_new_from_stock ( GTK_STOCK_ADD, GTK_ICON_SIZE_MENU ); | |
396 | gtk_button_set_image ( GTK_BUTTON(tpwin->localtime), img ); | |
397 | } | |
398 | else | |
50a14534 | 399 | |
b45865b4 | 400 | vik_trw_layer_tpwin_set_track_name ( tpwin, track_name ); |
50a14534 EB |
401 | |
402 | tpwin->sync_to_tp_block = TRUE; /* don't update while setting data. */ | |
403 | ||
404 | vik_coord_to_latlon ( &(tp->coord), &ll ); | |
405 | gtk_spin_button_set_value ( tpwin->lat, ll.lat ); | |
406 | gtk_spin_button_set_value ( tpwin->lon, ll.lon ); | |
6027a9c5 RN |
407 | vik_units_height_t height_units = a_vik_get_units_height (); |
408 | switch (height_units) { | |
409 | case VIK_UNITS_HEIGHT_METRES: | |
410 | gtk_spin_button_set_value ( tpwin->alt, tp->altitude ); | |
411 | break; | |
412 | case VIK_UNITS_HEIGHT_FEET: | |
6c20e59a | 413 | gtk_spin_button_set_value ( tpwin->alt, VIK_METERS_TO_FEET(tp->altitude) ); |
6027a9c5 RN |
414 | break; |
415 | default: | |
416 | gtk_spin_button_set_value ( tpwin->alt, tp->altitude ); | |
417 | g_critical("Houston, we've had a problem. height=%d", height_units); | |
418 | } | |
419 | ||
0243b089 | 420 | tpwin_update_times ( tpwin, tp ); |
50a14534 | 421 | |
0243b089 | 422 | tpwin->sync_to_tp_block = FALSE; // don't update while setting data. |
50a14534 | 423 | |
86f7d733 | 424 | vik_units_speed_t speed_units = a_vik_get_units_speed (); |
6f9336aa | 425 | vik_units_distance_t dist_units = a_vik_get_units_distance (); |
50a14534 EB |
426 | if ( tpwin->cur_tp ) |
427 | { | |
6f9336aa RN |
428 | switch (dist_units) { |
429 | case VIK_UNITS_DISTANCE_KILOMETRES: | |
430 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f m", vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord))); | |
431 | break; | |
432 | case VIK_UNITS_DISTANCE_MILES: | |
433 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f yards", vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord))*1.0936133); | |
434 | break; | |
435 | default: | |
436 | g_critical("Houston, we've had a problem. distance=%d", dist_units); | |
437 | } | |
438 | ||
50a14534 EB |
439 | gtk_label_set_text ( tpwin->diff_dist, tmp_str ); |
440 | if ( tp->has_timestamp && tpwin->cur_tp->has_timestamp ) | |
441 | { | |
442 | g_snprintf ( tmp_str, sizeof(tmp_str), "%ld s", tp->timestamp - tpwin->cur_tp->timestamp); | |
443 | gtk_label_set_text ( tpwin->diff_time, tmp_str ); | |
444 | if ( tp->timestamp == tpwin->cur_tp->timestamp ) | |
445 | gtk_label_set_text ( tpwin->diff_speed, "--" ); | |
446 | else | |
447 | { | |
13bdea80 RN |
448 | switch (speed_units) { |
449 | case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR: | |
ab1e0693 | 450 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f km/h", VIK_MPS_TO_KPH(vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / (ABS(tp->timestamp - tpwin->cur_tp->timestamp))) ); |
13bdea80 RN |
451 | break; |
452 | case VIK_UNITS_SPEED_MILES_PER_HOUR: | |
ab1e0693 | 453 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f mph", VIK_MPS_TO_MPH(vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / (ABS(tp->timestamp - tpwin->cur_tp->timestamp))) ); |
13bdea80 RN |
454 | break; |
455 | case VIK_UNITS_SPEED_METRES_PER_SECOND: | |
456 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f m/s", vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / ABS(tp->timestamp - tpwin->cur_tp->timestamp) ); | |
457 | break; | |
a4c92313 | 458 | case VIK_UNITS_SPEED_KNOTS: |
ab1e0693 | 459 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f knots", VIK_MPS_TO_KNOTS(vik_coord_diff(&(tp->coord), &(tpwin->cur_tp->coord)) / (ABS(tp->timestamp - tpwin->cur_tp->timestamp))) ); |
a4c92313 | 460 | break; |
13bdea80 RN |
461 | default: |
462 | g_snprintf ( tmp_str, sizeof(tmp_str), "--" ); | |
463 | g_critical("Houston, we've had a problem. speed=%d", speed_units); | |
464 | } | |
50a14534 EB |
465 | gtk_label_set_text ( tpwin->diff_speed, tmp_str ); |
466 | } | |
467 | } | |
468 | else | |
469 | { | |
470 | gtk_label_set_text ( tpwin->diff_time, NULL ); | |
471 | gtk_label_set_text ( tpwin->diff_speed, NULL ); | |
472 | } | |
473 | } | |
474 | ||
86f7d733 RN |
475 | if ( isnan(tp->course) ) |
476 | g_snprintf ( tmp_str, sizeof(tmp_str), "--" ); | |
477 | else | |
478 | g_snprintf ( tmp_str, sizeof(tmp_str), "%05.1f\302\260", tp->course ); | |
479 | gtk_label_set_text ( tpwin->course, tmp_str ); | |
480 | ||
481 | if ( isnan(tp->speed) ) | |
482 | g_snprintf ( tmp_str, sizeof(tmp_str), "--" ); | |
483 | else { | |
484 | switch (speed_units) { | |
485 | case VIK_UNITS_SPEED_MILES_PER_HOUR: | |
486 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f mph", VIK_MPS_TO_MPH(tp->speed) ); | |
487 | break; | |
488 | case VIK_UNITS_SPEED_METRES_PER_SECOND: | |
489 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f m/s", tp->speed ); | |
490 | break; | |
491 | case VIK_UNITS_SPEED_KNOTS: | |
492 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f knots", VIK_MPS_TO_KNOTS(tp->speed) ); | |
493 | break; | |
494 | default: | |
495 | // VIK_UNITS_SPEED_KILOMETRES_PER_HOUR: | |
496 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.2f km/h", VIK_MPS_TO_KPH(tp->speed) ); | |
497 | break; | |
498 | } | |
499 | } | |
500 | gtk_label_set_text ( tpwin->speed, tmp_str ); | |
501 | ||
6f9336aa RN |
502 | switch (dist_units) { |
503 | case VIK_UNITS_DISTANCE_KILOMETRES: | |
504 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f m", tp->hdop ); | |
505 | gtk_label_set_text ( tpwin->hdop, tmp_str ); | |
506 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f m", tp->pdop ); | |
507 | gtk_label_set_text ( tpwin->pdop, tmp_str ); | |
508 | break; | |
509 | case VIK_UNITS_DISTANCE_MILES: | |
510 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f yards", tp->hdop*1.0936133 ); | |
511 | gtk_label_set_text ( tpwin->hdop, tmp_str ); | |
512 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f yards", tp->pdop*1.0936133 ); | |
513 | gtk_label_set_text ( tpwin->pdop, tmp_str ); | |
514 | break; | |
515 | default: | |
516 | g_critical("Houston, we've had a problem. distance=%d", dist_units); | |
517 | } | |
6027a9c5 RN |
518 | |
519 | switch (height_units) { | |
520 | case VIK_UNITS_HEIGHT_METRES: | |
521 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f m", tp->vdop ); | |
522 | break; | |
523 | case VIK_UNITS_HEIGHT_FEET: | |
6c20e59a | 524 | g_snprintf ( tmp_str, sizeof(tmp_str), "%.5f feet", VIK_METERS_TO_FEET(tp->vdop) ); |
6027a9c5 RN |
525 | break; |
526 | default: | |
527 | g_snprintf ( tmp_str, sizeof(tmp_str), "--" ); | |
528 | g_critical("Houston, we've had a problem. height=%d", height_units); | |
529 | } | |
b24a25f4 | 530 | gtk_label_set_text ( tpwin->vdop, tmp_str ); |
6027a9c5 | 531 | |
b24a25f4 T |
532 | g_snprintf ( tmp_str, sizeof(tmp_str), "%d / %d", tp->nsats, tp->fix_mode ); |
533 | gtk_label_set_text ( tpwin->sat, tmp_str ); | |
eb790888 RN |
534 | |
535 | tpwin->cur_tp = tp; | |
50a14534 EB |
536 | } |
537 | ||
538 | void vik_trw_layer_tpwin_set_track_name ( VikTrwLayerTpwin *tpwin, const gchar *track_name ) | |
539 | { | |
b45865b4 RN |
540 | gchar *tmp_name = g_strdup_printf ( "%s: %s", track_name, _("Trackpoint") ); |
541 | gtk_window_set_title ( GTK_WINDOW(tpwin), tmp_name ); | |
542 | g_free ( tmp_name ); | |
543 | //gtk_label_set_text ( tpwin->track_name, track_name ); | |
50a14534 | 544 | } |