gpsdata.cpp

来自「给予QT的qps开源最新源码」· C++ 代码 · 共 314 行

CPP
314
字号
/*
   qpegps is a program for displaying a map centered at the current longitude/
   latitude as read from a gps receiver.

   Copyright (C) 2002 Ralf Haselmeier <Ralf.Haselmeier@gmx.de>

   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., 675 Mass Ave, Cambridge, MA 02139, USA.

 */

#include "gpsdata.h"

#include "convert.h"
// initialization of static elements:
Altitude::Unit Altitude::unit = Altitude::Feet;
Speed::Unit Speed::unit = Speed::Knots;
Distance::Unit Distance::unit = Distance::Naut;
Position::Unit Position::unit = Position::DegMin;

QString Altitude::toString(bool bUnit)
{
   switch ( Altitude::unit ) {
      case None:
         return QObject::tr("");
         break;
      case Meter:
         if (bUnit)
            QObject::tr("%1 m").arg(val, 0, 'f', 0);
         else
            QObject::tr("%1").arg(val, 0, 'f', 0);
         break;
      case Feet:
         if (bUnit)
            return QObject::tr("%1 ft").arg(val * 3.2808399, 0, 'f', 0);
         else
            return QObject::tr("%1").arg(val * 3.2808399, 0, 'f', 0);
         break;
      case FL:
         if (bUnit)
            return QObject::tr("%1 FL").arg(val * 0.032808399,0, 'f', 1);
         else
            return QObject::tr("%1").arg(val * 0.032808399,0, 'f', 1);
         break;
   }
   return 0;
}

QString Speed::toString()
{
   switch ( Speed::unit ) {
      case None:
         return QObject::tr("");
         break;
      case Kmh:
         return QObject::tr("%1 kmh").arg(val * MPS_TO_KPH, 0, 'f', 1);
         break;
      case Knots:
         return QObject::tr("%1 kn").arg(val * MPS_TO_KNOTS, 0, 'f', 1);
         break;
      case Mph:
         return QObject::tr("%1 mph").arg(val * MPS_TO_MPH, 0, 'f', 1);
         break;
   }
   return 0;
}

QString Distance::toString()
{
   switch ( Distance::unit ) {
      case None:
         return QObject::tr("");
         break;
      case Km:
         return QObject::tr("%1 km").arg(val * 1.852, 0, 'f', 3);
         break;
      case Naut:
         return QObject::tr("%1 nmi").arg(val, 0, 'f', 3);
         break;
      case Statute:
         return QObject::tr("%1 mi").arg(val * 1.1507794, 0, 'f', 3);
         break;
   }
   return 0;
}

QString Position::string(double l, Axis a)
{
   QString sign;
   if ( a == Lat ) {
      sign = ( l > 0 ) ? QObject::tr("N") : QObject::tr("S");
   } else {
      sign = ( l > 0 ) ? QObject::tr("E") : QObject::tr("W");
   }
   double dec = fabs(l);
   switch ( Position::unit ) {
      case Degree:
         return QObject::tr("%1\260%2").arg(dec, 0, 'f', 5).arg(sign);
         break;
      case DegMin:
         {
         double deg = floor(dec);
         double min = (dec - deg) * 60.0;
         return QObject::tr("%1\260%2'%3").arg(deg, 0, 'f', 0)
            .arg(min, 0, 'f', 3).arg(sign);
         }
         break;
      case DegMinSec:
         {
         double deg = floor(dec);
         double min = floor((dec - deg) * 60.0);
         double sec = (dec - (deg + min / 60.0)) * 3600.0;
         return QObject::tr("%1\260%2'%3\"%4").arg(deg, 0, 'f', 0)
            .arg(min, 0, 'f', 0)
            .arg(sec, 0, 'f', 2).arg(sign);
         }
         break;
   }
   return 0;
}

double Position::number(const QString & l, Axis a)
{
   double sign = +1.0;
   QRegExp re("[\\s'\"]");

   QString str = l.simplifyWhiteSpace();

   int p;
   if ( a == Lat ) {
      p = str.find(QObject::tr("s"), 0, false);
   } else {
      p = str.find(QObject::tr("w"), 0, false);
   }
   if ( p >= 0 ) {
      sign = -1.0;
      str.remove(p, 1);
      str = str.simplifyWhiteSpace();
   }
   if ( a == Lat ) {
      p = str.find(QObject::tr("n"), 0, false);
   } else {
      p = str.find(QObject::tr("e"), 0, false);
   }
   if ( p >= 0 ) {
      str.remove(p, 1);
      str = str.simplifyWhiteSpace();
   }

   float deg = str.toFloat();
   float min = 0.0, sec = 0.0;
   p = str.find(re);
   if ( p > 0 ) {
      str = str.mid(p + 1);
      min = str.toFloat();
      p = str.find(re);
      if ( p > 0 ) {
         str = str.mid(p + 1);
         sec = str.toFloat();
      }
   }
   return sign * dms2deg(deg, min, sec);
}

QString Angle::toString()
{
   return QObject::tr("%1").arg(val, 0, 'f', 0);
}

QString TimeStamp::toString()
{
   if ( date.isEmpty() || time.isEmpty() ) {
      return QObject::tr("* No GMT Signal rcvd *");
   }
   return date + " " + time;
}

GeoDatum::GeoDatum(QObject * parent, const char * name)
   : QObject(parent,name)
{
   errorCode = Initialize_Ellipsoids();
   if ( errorCode ) {
      qWarning(tr("Ellipsoid table couldn't be initialized (check existance and path of ellipse.dat)"));
   }
   errorCode = Initialize_Datums();
   if ( errorCode ) {
      qWarning(tr("Datum table couldn't be initialized (check existance and path of 3_param.dat and 7_param.dat"));
      datumCount = 0;
      datumList = 0;
   } else {
      char datumName[64];
      QString datName;
      Datum_Count(&datumCount);
      for ( long i = 1; i < datumCount; ++i ) {
         Datum_Name(i, datumName);
         datName = datumName;
         datName = datName.simplifyWhiteSpace();
         //datName = datName.lower();
         //datName.truncate(26);
         datumList.append(datName);
      }
   }
}

void GeoDatum::convertDatum(long fromIdx, long toIdx,
      double * lat, double * lon, double * altitude)
{
   long error;
   error = Geodetic_Datum_Shift(
         fromIdx, *lat, *lon, *altitude,
         toIdx, lat, lon, altitude);

   if ( error ) {
      QString msg = "Error in datum conversion of the current position:\n ";
      if ( error & DATUM_NOT_INITIALIZED_ERROR ) {
         msg.append("Datum module has not been initialized\n ");
      }
      if ( error & DATUM_7PARAM_FILE_OPEN_ERROR ) {
         msg.append("7 parameter file opening error\n ");
      }
      if ( error & DATUM_7PARAM_FILE_PARSING_ERROR ) {
         msg.append("7 parameter file structure error\n ");
      }
      if ( error & DATUM_7PARAM_OVERFLOW_ERROR ) {
         msg.append("7 parameter table overflow\n ");
      }
      if ( error & DATUM_3PARAM_FILE_OPEN_ERROR ) {
         msg.append("3 parameter file opening error\n ");
      }
      if ( error & DATUM_3PARAM_FILE_PARSING_ERROR ) {
         msg.append("3 parameter file structure error\n ");
      }
      if ( error & DATUM_3PARAM_OVERFLOW_ERROR ) {
         msg.append("3 parameter table overflow\n ");
      }
      if ( error & DATUM_INVALID_INDEX_ERROR ) {
         msg.append("Index out of valid range (less than one or more than Datum_Count)\n ");
      }
      if ( error & DATUM_INVALID_SRC_INDEX_ERROR ) {
         msg.append("Source datum index invalid\n ");
      }
      if ( error & DATUM_INVALID_DEST_INDEX_ERROR ) {
         msg.append("Destination datum index invalid\n ");
      }
      if ( error & DATUM_INVALID_CODE_ERROR ) {
         msg.append("Datum code not found in table\n ");
      }
      if ( error & DATUM_LAT_ERROR ) {
         msg.append("Latitude out of valid range (-90 to 90 in rad)\n ");
      }
      if ( error & DATUM_LON_ERROR ) {
         msg.append("Longitude out of valid range (-180 to 360 in rad)\n ");
      }
      if ( error & DATUM_SIGMA_ERROR ) {
         msg.append("Standard error values must be positive (or -1 if unknown)\n ");
      }
      if ( error & DATUM_DOMAIN_ERROR ) {
         msg.append("Domain of validity not well defined\n ");
      }
      if ( error & DATUM_ELLIPSE_ERROR ) {
         msg.append("Error in ellipsoid module (check existance and path of ellipse.dat)\n ");
      }
      if ( error & DATUM_NOT_USERDEF_ERROR ) {
         msg.append("Datum code is not user defined - cannot be deleted\n ");
      }
      qDebug(msg);
   }
}

bool Satellite::operator==(const Satellite & other) const
{
   return ((name == other.name)
         && (elevation == other.elevation)
         && (azimut == other.azimut)
         && (snr == other.snr) 
         && (used == other.used))
         ;
}

bool Satellite::operator!=(const Satellite & other) const
{
   return ((name != other.name)
         || (elevation != other.elevation)
         || (azimut != other.azimut)
         || (snr != other.snr)
         || (used != other.used));
}

Satellite & Satellite::operator=(const class Satellite & other)
{
   // memberwise copy (needed here because QObject operator = is private)
   name = other.name;
   elevation = other.elevation;
   azimut = other.azimut;
   snr = other.snr;
   used = other.used;
   updated = other.updated;

   return *this;
}

// end of file

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?