googlemaps.c googlemaps.h \
gtkcellrendererprogress.c gtkcellrendererprogress.h \
khmaps.c khmaps.h \
- usgs.c usgs.h
+ usgs.c usgs.h \
+ gpx.c gpx.h
INCLUDES = @GTK_CFLAGS@
LDADD = @GTK_LIBS@
+CFLAGS = -Wall -g
endif
TARGET=viking$(EXE)
-OBJECTS=gtkcolorbutton.o viktrack.o vikwaypoint.o clipboard.o coords.o gpsmapper.o gpspoint.o file.o main.o dialog.o http.o viktreeview.o viktrwlayer.o viklayer.o viklayerspanel.o vikcoordlayer.o vikstatus.o vikwindow.o vikviewport.o vikaggregatelayer.o vikgeoreflayer.o vikfileentry.o viktrwlayer_tpwin.o viktrwlayer_propwin.o thumbnails.o background.o vikradiogroup.o vikcoord.o expedia.o mapcache.o vikmapslayer.o terraserver.o googlemaps.o gtkcellrendererprogress.o
+OBJECTS=gtkcolorbutton.o viktrack.o vikwaypoint.o clipboard.o coords.o gpsmapper.o gpspoint.o file.o main.o dialog.o http.o viktreeview.o viktrwlayer.o viklayer.o viklayerspanel.o vikcoordlayer.o vikstatus.o vikwindow.o vikviewport.o vikaggregatelayer.o vikgeoreflayer.o vikfileentry.o viktrwlayer_tpwin.o viktrwlayer_propwin.o thumbnails.o background.o vikradiogroup.o vikcoord.o expedia.o mapcache.o vikmapslayer.o terraserver.o googlemaps.o gtkcellrendererprogress.o gpx.o
CCFLAGS = -DGTK_2_2 -Wall -g
LINKFLAGS =
VikCoord new_center;
VikLayer *vtl = vik_layer_create ( VIK_LAYER_TRW, vp, NULL, FALSE );
vik_layer_rename ( vtl, a_file_basename ( filename ) );
- a_gpspoint_read_file ( VIK_TRW_LAYER(vtl), f );
+ // a_gpspoint_read_file ( VIK_TRW_LAYER(vtl), f );
+ a_gpx_read_file ( VIK_TRW_LAYER(vtl), f );
vik_layer_post_read ( vtl, vp );
--- /dev/null
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+
+#define _XOPEN_SOURCE /* glibc2 needs this */
+
+#include "viking.h"
+#include <expat.h>
+#include <string.h>
+
+// see ~/evan/programs/gpsbabel-1.2.7/gpx.c
+
+typedef enum {
+ tt_unknown = 0,
+
+ tt_gpx,
+
+ tt_wpt,
+ tt_wpt_desc,
+ tt_wpt_name,
+ tt_wpt_ele,
+ tt_wpt_link, /* New in GPX 1.1 */
+
+ tt_trk,
+ tt_trk_desc,
+ tt_trk_name,
+
+ tt_trk_trkseg,
+ tt_trk_trkseg_trkpt,
+ tt_trk_trkseg_trkpt_ele,
+ tt_trk_trkseg_trkpt_time,
+} tag_type;
+
+typedef struct tag_mapping {
+ tag_type tag_type; /* enum from above for this tag */
+ const char *tag_name; /* xpath-ish tag name */
+} tag_mapping;
+
+/*
+ * xpath(ish) mappings between full tag paths and internal identifers.
+ * These appear in the order they appear in the GPX specification.
+ * If it's not a tag we explictly handle, it doesn't go here.
+ */
+
+tag_mapping tag_path_map[] = {
+ { tt_gpx, "/gpx" },
+
+ { tt_wpt, "/gpx/wpt" },
+ { tt_wpt_ele, "/gpx/wpt/ele" },
+ { tt_wpt_name, "/gpx/wpt/name" },
+ { tt_wpt_desc, "/gpx/wpt/desc" },
+ { tt_wpt_link, "/gpx/wpt/link" }, /* GPX 1.1 */
+
+ { tt_trk, "/gpx/trk" },
+ { tt_trk_name, "/gpx/trk/name" },
+ { tt_trk_desc, "/gpx/trk/desc" },
+ { tt_trk_trkseg, "/gpx/trk/trkseg" },
+
+ { tt_trk_trkseg_trkpt, "/gpx/trk/trkseg/trkpt" },
+ { tt_trk_trkseg_trkpt_ele, "/gpx/trk/trkseg/trkpt/ele" },
+ { tt_trk_trkseg_trkpt_time, "/gpx/trk/trkseg/trkpt/time" },
+
+ {0}
+};
+
+static tag_type get_tag(const char *t)
+{
+ tag_mapping *tm;
+ for (tm = tag_path_map; tm->tag_type != 0; tm++)
+ if (0 == strcmp(tm->tag_name, t))
+ return tm->tag_type;
+ return tt_unknown;
+}
+
+/******************************************/
+
+tag_type current_tag = tt_unknown;
+GString *xpath = NULL;
+GString *c_cdata = NULL;
+
+/* current ("c_") objects */
+VikTrackpoint *c_tp = NULL;
+VikWaypoint *c_wp = NULL;
+VikTrack *c_tr = NULL;
+
+gchar *c_wp_name = NULL;
+gchar *c_tr_name = NULL;
+
+/* temporary things so we don't have to create them lots of times */
+const gchar *c_slat, *c_slon;
+struct LatLon c_ll;
+
+/* specialty flags / etc */
+gboolean f_tr_newseg;
+guint unnamed_waypoints = 0;
+guint unnamed_tracks = 0;
+
+
+static const char *get_attr ( const char **attr, const char *key )
+{
+ while ( *attr ) {
+ if ( strcmp(*attr,key) == 0 )
+ return *(attr + 1);
+ attr += 2;
+ }
+ return NULL;
+}
+
+static gboolean set_c_ll ( const char **attr )
+{
+ if ( (c_slat = get_attr ( attr, "lat" )) && (c_slon = get_attr ( attr, "lon" )) ) {
+ c_ll.lat = strtod(c_slat, NULL);
+ c_ll.lon = strtod(c_slon, NULL);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static void gpx_start(VikTrwLayer *vtl, const char *el, const char **attr)
+{
+ g_string_append_c ( xpath, '/' );
+ g_string_append ( xpath, el );
+ current_tag = get_tag ( xpath->str );
+
+ switch ( current_tag ) {
+
+ case tt_wpt:
+ if ( set_c_ll( attr ) ) {
+ c_wp = vik_waypoint_new ();
+ c_wp->altitude = VIK_DEFAULT_ALTITUDE;
+ if ( ! get_attr ( attr, "hidden" ) )
+ c_wp->visible = TRUE;
+
+ vik_coord_load_from_latlon ( &(c_wp->coord), vik_trw_layer_get_coord_mode ( vtl ), &c_ll );
+ }
+ break;
+
+ case tt_trk:
+ c_tr = vik_track_new ();
+ if ( ! get_attr ( attr, "hidden" ) )
+ c_tr->visible = TRUE;
+ break;
+
+ case tt_trk_trkseg:
+ f_tr_newseg = TRUE;
+ break;
+
+ case tt_trk_trkseg_trkpt:
+ if ( set_c_ll( attr ) ) {
+ c_tp = vik_trackpoint_new ();
+ c_tp->altitude = VIK_DEFAULT_ALTITUDE;
+ vik_coord_load_from_latlon ( &(c_tp->coord), vik_trw_layer_get_coord_mode ( vtl ), &c_ll );
+ if ( f_tr_newseg ) {
+ c_tp->newsegment = TRUE;
+ f_tr_newseg = FALSE;
+ }
+ c_tr->trackpoints = g_list_append ( c_tr->trackpoints, c_tp );
+ }
+ break;
+
+ case tt_trk_trkseg_trkpt_ele:
+ case tt_trk_trkseg_trkpt_time:
+ case tt_wpt_desc:
+ case tt_wpt_name:
+ case tt_wpt_ele:
+ case tt_wpt_link:
+ case tt_trk_desc:
+ case tt_trk_name:
+ g_string_erase ( c_cdata, 0, -1 ); /* clear the cdata buffer */
+
+ default: break;
+ }
+}
+
+static void gpx_end(VikTrwLayer *vtl, const char *el)
+{
+ static struct tm tm;
+ g_string_truncate ( xpath, xpath->len - strlen(el) - 1 );
+
+ switch ( current_tag ) {
+
+ case tt_wpt:
+ if ( ! c_wp_name )
+ c_wp_name = g_strdup_printf("VIKING_WP%d", unnamed_waypoints++);
+ g_hash_table_insert ( vik_trw_layer_get_waypoints ( vtl ), c_wp_name, c_wp );
+ c_wp = NULL;
+ c_wp_name = NULL;
+ break;
+
+ case tt_trk:
+ if ( ! c_tr_name )
+ c_tr_name = g_strdup_printf("VIKING_TR%d", unnamed_waypoints++);
+ g_hash_table_insert ( vik_trw_layer_get_tracks ( vtl ), c_tr_name, c_tr );
+ c_tr = NULL;
+ c_tr_name = NULL;
+ break;
+
+ case tt_wpt_name:
+ if ( c_wp_name )
+ g_free ( c_wp_name );
+ c_wp_name = g_strdup ( c_cdata->str );
+ g_string_erase ( c_cdata, 0, -1 );
+ break;
+
+ case tt_trk_name:
+ if ( c_tr_name )
+ g_free ( c_tr_name );
+ c_tr_name = g_strdup ( c_cdata->str );
+ g_string_erase ( c_cdata, 0, -1 );
+ break;
+
+ case tt_wpt_ele:
+ c_wp->altitude = strtod ( c_cdata->str, NULL );
+ g_string_erase ( c_cdata, 0, -1 );
+ break;
+
+ case tt_trk_trkseg_trkpt_ele:
+ c_tp->altitude = strtod ( c_cdata->str, NULL );
+ g_string_erase ( c_cdata, 0, -1 );
+ break;
+
+ case tt_wpt_desc:
+ vik_waypoint_set_comment ( c_wp, c_cdata->str );
+ g_string_erase ( c_cdata, 0, -1 );
+ break;
+
+ case tt_wpt_link:
+ vik_waypoint_set_image ( c_wp, c_cdata->str );
+ g_string_erase ( c_cdata, 0, -1 );
+ break;
+
+ case tt_trk_desc:
+ vik_track_set_comment ( c_tr, c_cdata->str );
+ g_string_erase ( c_cdata, 0, -1 );
+ break;
+
+ case tt_trk_trkseg_trkpt_time:
+ if ( strptime(c_cdata->str, "%Y-%m-%dT%H:%M:%SZ", &tm) != c_cdata->str ) { /* it read at least one char */
+ c_tp->timestamp = mktime(&tm);
+ c_tp->has_timestamp = TRUE;
+ }
+ g_string_erase ( c_cdata, 0, -1 );
+
+ default: break;
+ }
+
+ current_tag = get_tag ( xpath->str );
+}
+
+static void gpx_cdata(void *dta, const XML_Char *s, int len)
+{
+ switch ( current_tag ) {
+ case tt_wpt_name:
+ case tt_trk_name:
+ case tt_wpt_ele:
+ case tt_trk_trkseg_trkpt_ele:
+ case tt_wpt_desc:
+ case tt_wpt_link:
+ case tt_trk_desc:
+ case tt_trk_trkseg_trkpt_time:
+ g_string_append_len ( c_cdata, s, len );
+ break;
+
+ default: break; /* ignore cdata from other things */
+ }
+}
+
+// make like a "stack" of tag names
+// like gpspoint's separated like /gpx/wpt/whatever
+
+void a_gpx_read_file( VikTrwLayer *vtl, FILE *f ) {
+ XML_Parser parser = XML_ParserCreate(NULL);
+ int done=0, len;
+
+ XML_SetElementHandler(parser, (XML_StartElementHandler) gpx_start, (XML_EndElementHandler) gpx_end);
+ XML_SetUserData(parser, vtl); /* in the future we could remove all global variables */
+ XML_SetCharacterDataHandler(parser, (XML_CharacterDataHandler) gpx_cdata);
+
+ gchar buf[4096];
+
+ //g_assert ( f != NULL && vtl != NULL );
+
+ xpath = g_string_new ( "" );
+ c_cdata = g_string_new ( "" );
+
+ unnamed_waypoints = 0;
+ unnamed_tracks = 0;
+
+ while (!done) {
+ len = fread(buf, 1, sizeof(buf)-7, f);
+ done = feof(f) || !len;
+ XML_Parse(parser, buf, len, done);
+ }
+
+ g_string_free ( xpath, TRUE );
+ g_string_free ( c_cdata, TRUE );
+}
--- /dev/null
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _VIKING_GPX_H
+#define _VIKING_GPX_H
+
+void a_gpx_read_file ( VikTrwLayer *trw, FILE *f );
+void a_gpx_write_file ( VikTrwLayer *trw, FILE *f );
+
+#endif
VikTrack *vik_track_new()
{
- VikTrack *tr = g_malloc ( sizeof ( VikTrack ) );
- tr->trackpoints = NULL;
- tr->comment = NULL;
+ VikTrack *tr = g_malloc0 ( sizeof ( VikTrack ) );
tr->ref_count = 1;
return tr;
}
{
gdouble diff;
*up = *down = 0;
- if ( tr->trackpoints )
+ if ( tr->trackpoints && VIK_TRACKPOINT(tr->trackpoints->data)->altitude != VIK_DEFAULT_ALTITUDE )
{
GList *iter = tr->trackpoints->next;
while (iter)
iter = iter->next;
}
}
+ *up = *down = VIK_DEFAULT_ALTITUDE;
}
gdouble *vik_track_make_speed_map ( const VikTrack *tr, guint16 num_chunks )
if (!useoldvals)
vik_viewport_coord_to_screen ( dp->vp, &(tp2->coord), &oldx, &oldy );
- if ( drawing_white_background )
+ if ( drawing_white_background ) {
vik_viewport_draw_line ( dp->vp, dp->vtl->track_bg_gc, oldx, oldy, x, y);
- else
+ }
+ else {
+ GdkPoint tmp[4];
+#define FIXALTITUDE(what) (pow((VIK_TRACKPOINT((what))->altitude-330),2)/1500/dp->xmpp)
+ if ( list && list->next && VIK_TRACKPOINT(list->next->data)->altitude != VIK_DEFAULT_ALTITUDE ) {
+ tmp[0].x = oldx;
+ tmp[0].y = oldy;
+ tmp[1].x = oldx;
+ tmp[1].y = oldy-FIXALTITUDE(list->data);
+ tmp[2].x = x;
+ tmp[2].y = y-FIXALTITUDE(list->next->data);
+ tmp[3].x = x;
+ tmp[3].y = y;
+
+ GdkGC *tmp_gc;
+ if ( ((oldx - x) > 0 && (oldy - y) > 0) || ((oldx - x) < 0 && (oldy - y) < 0))
+ tmp_gc = GTK_WIDGET(dp->vp)->style->light_gc[3];
+ else
+ tmp_gc = GTK_WIDGET(dp->vp)->style->dark_gc[0];
+ vik_viewport_draw_polygon ( dp->vp, tmp_gc, TRUE, tmp, 4);
+ }
+
vik_viewport_draw_line ( dp->vp, g_array_index(dp->vtl->track_gc, GdkGC *, dp->track_gc_iter), oldx, oldy, x, y);
+ if ( list && list->next && VIK_TRACKPOINT(list->next->data)->altitude != VIK_DEFAULT_ALTITUDE ) {
+ vik_viewport_draw_line ( dp->vp, g_array_index(dp->vtl->track_gc, GdkGC *, dp->track_gc_iter), oldx, oldy-FIXALTITUDE(list->data), x, y-FIXALTITUDE(list->next->data));
+ }
+ }
}
oldx = x;
*min = altitudes[i];
}
}
-
}
#define MARGIN 50
gpointer *pass_along;
guint i;
- if ( altitudes == NULL )
+ if ( altitudes == NULL ) {
+ *min_alt = *max_alt = VIK_DEFAULT_ALTITUDE;
return NULL;
+ }
pix = gdk_pixmap_new( window->window, PROFILE_WIDTH + MARGIN, PROFILE_HEIGHT, -1 );
image = gtk_image_new_from_pixmap ( pix, NULL );
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>", "<b>Start:</b>", "<b>End:</b>", "<b>Duration:</b>" };
static gchar tmp_buf[25];
+ gdouble tmp_speed;
left_vbox = a_dialog_create_label_vbox ( label_texts, sizeof(label_texts) / sizeof(label_texts[0]) );
right_vbox = gtk_vbox_new ( TRUE, 3 );
g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", vik_track_get_dup_point_count(tr) );
l_dups = gtk_label_new ( tmp_buf );
- g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", vik_track_get_max_speed(tr) );
+ tmp_speed = vik_track_get_max_speed(tr);
+ if ( tmp_speed == 0 )
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "No Data");
+ else
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
l_maxs = gtk_label_new ( tmp_buf );
- g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", vik_track_get_average_speed(tr) );
+ tmp_speed = vik_track_get_average_speed(tr);
+ if ( tmp_speed == 0 )
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "No Data");
+ else
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m/s", tmp_speed );
l_avgs = gtk_label_new ( tmp_buf );
g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f m", (tp_count - seg_count) == 0 ? 0 : tr_len / ( tp_count - seg_count ) );
l_avgd = gtk_label_new ( tmp_buf );
- g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m - %.0f m", min_alt, max_alt );
+ if ( min_alt == VIK_DEFAULT_ALTITUDE )
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "No Data");
+ else
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m - %.0f m", min_alt, max_alt );
l_elev = gtk_label_new ( tmp_buf );
vik_track_get_total_elevation_gain(tr, &max_alt, &min_alt );
- g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m / %.0f m", max_alt, min_alt );
+ if ( max_alt == VIK_DEFAULT_ALTITUDE )
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "No Data");
+ else
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.0f m / %.0f m", max_alt, min_alt );
l_galo = gtk_label_new ( tmp_buf );
gtk_box_pack_start (GTK_BOX(right_vbox), l_elev, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX(right_vbox), l_galo, FALSE, FALSE, 0);
- if ( tr->trackpoints )
+ if ( tr->trackpoints && VIK_TRACKPOINT(tr->trackpoints->data)->timestamp )
{
time_t t1, t2;
t1 = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
g_snprintf(tmp_buf, sizeof(tmp_buf), "%d minutes", (int)(t2-t1)/60);
l_dur = gtk_label_new(tmp_buf);
-
- gtk_box_pack_start (GTK_BOX(right_vbox), l_begin, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX(right_vbox), l_end, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX(right_vbox), l_dur, FALSE, FALSE, 0);
+ } else {
+ l_begin = gtk_label_new("No Data");
+ l_end = gtk_label_new("No Data");
+ l_dur = gtk_label_new("No Data");
}
+ gtk_box_pack_start (GTK_BOX(right_vbox), l_begin, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(right_vbox), l_end, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(right_vbox), l_dur, FALSE, FALSE, 0);
hbox = gtk_hbox_new ( TRUE, 0 );
gtk_box_pack_start (GTK_BOX(hbox), left_vbox, FALSE, FALSE, 0);
GObjectClass *object_class;
window_signals[VW_NEWWINDOW_SIGNAL] = g_signal_new ( "newwindow", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (VikWindowClass, newwindow), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
- window_signals[VW_OPENWINDOW_SIGNAL] = g_signal_new ( "openwindow", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (VikWindowClass, openwindow), NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_POINTER);
+ window_signals[VW_OPENWINDOW_SIGNAL] = g_signal_new ( "openwindow", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (VikWindowClass, openwindow), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
object_class = G_OBJECT_CLASS (klass);