// -*- mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; coding: utf-8-unix -*- /*************************************************************************** * Copyright (C) 2010-2012 by Oleg Khudyakov * * prcoder@gmail.com * * * * 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. * ***************************************************************************/ // ***** BEGIN LICENSE BLOCK ***** ////////////////////////////////////////////////////////////////////////// // Copyright (c) 2011-2014 RALOVICH, Kristóf // // // // 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 3 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. // // // ////////////////////////////////////////////////////////////////////////// // ***** END LICENSE BLOCK ***** #include "GPX.hpp" #include #include #include "common.hpp" using namespace std; namespace antpm{ WayPoint::WayPoint(): time(0), latitude(INT32_MAX), longitude(INT32_MAX), altitude(UINT16_MAX) { } WayPoint::~WayPoint() { } void WayPoint::putToFile(ofstream &file) { if ((latitude != INT32_MAX) && (longitude != INT32_MAX)) { file << " " << endl; file << " " << name << "" << endl; if (altitude != UINT16_MAX) { file << " " << setprecision(1) << GarminConvert::altitude(altitude) << "" << endl; } file << " " << endl; file << " city (small)" << endl; file << " " << endl; } } TrackPoint::TrackPoint() { time = 0; latitude = INT32_MAX; longitude = INT32_MAX; altitude = UINT16_MAX; heartRate = UINT8_MAX; cadence = UINT8_MAX; } TrackPoint::~TrackPoint() { } void TrackPoint::putToFile(ofstream &file) { if ((latitude != INT32_MAX) && (longitude != INT32_MAX)) { file << " " << endl; if (altitude != UINT16_MAX) { file << " " << setprecision(1) << GarminConvert::altitude(altitude) << "" << endl; } file << " " << endl; if ((heartRate != UINT8_MAX) || (cadence != UINT8_MAX)) { file << " " << endl; file << " " << endl; if (heartRate != UINT8_MAX) { file << " " << dec << (unsigned)heartRate << "" << endl; } if (cadence != UINT8_MAX) { file << " " << dec << (unsigned)cadence << "" << endl; } file << " " << endl; file << " " << endl; } file << " " << endl; } } TrackSeg::TrackSeg() { } TrackSeg::~TrackSeg() { } void TrackSeg::putToFile(ofstream &file) { if (trackPoints.size()) { file << " " << endl; map::iterator it; for (it = trackPoints.begin(); it != trackPoints.end(); it++) { TrackPoint &trackPoint = it->second; trackPoint.putToFile(file); } file << " " << endl; } } Track::Track(string &p_name) : name(p_name) { } Track::~Track() { } void Track::newTrackSeg() { TrackSeg trackSeg; trackSegs.push_back(trackSeg); } void Track::putToFile(ofstream &file) { file << "" << endl; file << " " << name << "" << endl; for (size_t i=0; i" << endl; } GPX::GPX() { } GPX::~GPX() { } void GPX::newTrack(string name) { Track track(name); tracks.push_back(track); newTrackSeg(); } void GPX::newTrackSeg() { tracks.back().newTrackSeg(); } void GPX::newWayPoint() { WayPoint wayPoint; wayPoints.push_back(wayPoint); } bool GPX::writeToFile(string fileName) { ofstream file(fileName.c_str()); if (!file.is_open()) { cerr << "Error writing to file '" << fileName << "'" << endl; return false; } file.setf(ios::fixed,ios::floatfield); file << "" << endl; file << "" << endl; for (size_t i=0; i" << endl; file.close(); return true; } }