/* * * mappix-fileio * * Copyright (C) 2006 Nils Faerber * * * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ #include #include #include #include #include "mappix.h" #include "geo-tools.h" static void write_trackpoint(gpointer data, gpointer user_data) { trackdata *tdata = (trackdata *)data; FILE *mfile = (FILE *)user_data; gfloat llat, llong; gchar dstr[G_ASCII_DTOSTR_BUF_SIZE]; if (tdata != NULL) { g_fprintf(mfile, "unitx, tdata->unity, llat, llong); g_ascii_dtostr(dstr, G_ASCII_DTOSTR_BUF_SIZE, llat); g_fprintf(mfile, "lat=\"%s\" ", dstr); g_ascii_dtostr(dstr, G_ASCII_DTOSTR_BUF_SIZE, llong); g_fprintf(mfile, "long=\"%s\">\n", dstr); g_fprintf(mfile, "%.6f\n", tdata->elevation); #if 0 // if (tdata->datetime != NULL) // g_fprintf(mfile, "\n", tdata->datetime); g_fprintf(mfile, "%d\n", tdata->nrsat); g_fprintf(mfile, "%f\n", tdata->hdop); g_fprintf(mfile, "%f\n", tdata->vdop); g_fprintf(mfile, "%f\n", tdata->pdop); #endif g_fprintf(mfile, "\n"); } } static void write_track(gpointer data, gpointer user_data) { track_head *thead = (track_head *)data; FILE *mfile = (FILE *)user_data; gfloat minlat, minlon, maxlat, maxlon; if (thead != NULL) { g_fprintf(mfile, "\n"); g_fprintf(mfile, "%s\n", thead->name); g_fprintf(mfile, "%d\n", thead->type); /* NOT GPX CONFORMANT */ g_fprintf(mfile, "%s\n", thead->show ? "true" : "false"); /* NOT GPX CONFORMANT */ unit2latlon(thead->xmin, thead->ymin, minlat, minlon); unit2latlon(thead->xmax, thead->ymax, maxlat, maxlon); g_fprintf(mfile, "\n", minlat, minlon, maxlat, maxlon); g_fprintf(mfile, "\n"); if (thead->track != NULL) g_list_foreach(thead->track, write_trackpoint, mfile); g_fprintf(mfile, "\n"); g_fprintf(mfile, "\n"); } } static void write_waypoint(gpointer data, gpointer user_data) { waypoint *tdata = (waypoint *)data; FILE *mfile = (FILE *)user_data; gfloat llat, llong; gchar dstr[G_ASCII_DTOSTR_BUF_SIZE]; if (tdata != NULL) { g_fprintf(mfile, "unitx, tdata->unity, llat, llong); g_ascii_dtostr(dstr, G_ASCII_DTOSTR_BUF_SIZE, llat); g_fprintf(mfile, "lat=\"%s\" ", dstr); g_ascii_dtostr(dstr, G_ASCII_DTOSTR_BUF_SIZE, llong); g_fprintf(mfile, "long=\"%s\">\n", dstr); g_fprintf(mfile, "%s\n", tdata->name); g_fprintf(mfile, "%.6f\n", tdata->elevation); #if 0 // not yet used if (tdata->datetime != NULL) g_fprintf(mfile, "\n", tdata->datetime); g_fprintf(mfile, "%d\n", tdata->nrsat); g_fprintf(mfile, "%f\n", tdata->hdop); g_fprintf(mfile, "%f\n", tdata->vdop); g_fprintf(mfile, "%f\n", tdata->pdop); #endif g_fprintf(mfile, "\n"); } } gint save_project_to_file(gchar *filename, mapwin *Mapper) { FILE *mfile; mfile = g_fopen(filename, "w"); g_fprintf(mfile, "\n\n"); if (Mapper->tracklist) g_list_foreach(Mapper->tracklist, write_track, mfile); if (Mapper->waypoints) g_list_foreach(Mapper->waypoints, write_waypoint, mfile); g_fprintf(mfile, "\n"); fclose(mfile); return 0; }