StelUtils.cpp   StelUtils.cpp 
skipping to change at line 29 skipping to change at line 29
#include <config.h> #include <config.h>
#include <cmath> // std::fmod #include <cmath> // std::fmod
#ifdef CYGWIN #ifdef CYGWIN
#include <malloc.h> #include <malloc.h>
#endif #endif
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "vecmath.h" #include "VecMath.hpp"
#include "GLee.h" #include "GLee.h"
#include "fixx11h.h" #include "fixx11h.h"
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QTextStream> #include <QTextStream>
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
#include <QLocale> #include <QLocale>
#include <QRegExp>
namespace StelUtils namespace StelUtils
{ {
double hmsToRad(unsigned int h, unsigned int m, double s ) double hmsToRad(unsigned int h, unsigned int m, double s )
{ {
return (double)M_PI/24.*h*2.+(double)M_PI/12.*m/60.+s*M_PI/43200.; return (double)M_PI/24.*h*2.+(double)M_PI/12.*m/60.+s*M_PI/43200.;
} }
double dmsToRad(int d, unsigned int m, double s) double dmsToRad(int d, unsigned int m, double s)
skipping to change at line 261 skipping to change at line 262
// Converts a Vec3f to HTML color notation. // Converts a Vec3f to HTML color notation.
QString vec3fToHtmlColor(const Vec3f& v) QString vec3fToHtmlColor(const Vec3f& v)
{ {
return QString("#%1%2%3") return QString("#%1%2%3")
.arg(qMin(255, int(v[0] * 255)), 2, 16, QChar('0')) .arg(qMin(255, int(v[0] * 255)), 2, 16, QChar('0'))
.arg(qMin(255, int(v[1] * 255)), 2, 16, QChar('0')) .arg(qMin(255, int(v[1] * 255)), 2, 16, QChar('0'))
.arg(qMin(255, int(v[2] * 255)), 2, 16, QChar('0')); .arg(qMin(255, int(v[2] * 255)), 2, 16, QChar('0'));
} }
Vec3f htmlColorToVec3f(const QString& c)
{
Vec3f v;
QRegExp re("^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$");
if (re.exactMatch(c))
{
bool ok;
int i = re.capturedTexts().at(1).toInt(&ok, 16);
v[0] = (float)i / 255.;
i = re.capturedTexts().at(2).toInt(&ok, 16);
v[1] = (float)i / 255.;
i = re.capturedTexts().at(3).toInt(&ok, 16);
v[2] = (float)i / 255.;
}
else
{
v[0] = 0.;
v[1] = 0.;
v[2] = 0.;
}
return v;
}
void spheToRect(double lng, double lat, Vec3d& v) void spheToRect(double lng, double lat, Vec3d& v)
{ {
const double cosLat = cos(lat); const double cosLat = cos(lat);
v.set(cos(lng) * cosLat, sin(lng) * cosLat, sin(lat)); v.set(cos(lng) * cosLat, sin(lng) * cosLat, sin(lat));
} }
void spheToRect(float lng, float lat, Vec3f& v) void spheToRect(float lng, float lat, Vec3f& v)
{ {
const double cosLat = cos(lat); const double cosLat = cos(lat);
v.set(cos(lng) * cosLat, sin(lng) * cosLat, sin(lat)); v.set(cos(lng) * cosLat, sin(lng) * cosLat, sin(lat));
skipping to change at line 303 skipping to change at line 327
void rectToSphe(double *lng, double *lat, const Vec3f& v) void rectToSphe(double *lng, double *lat, const Vec3f& v)
{ {
double r = v.length(); double r = v.length();
*lat = asin(v[2]/r); *lat = asin(v[2]/r);
*lng = atan2(v[1],v[0]); *lng = atan2(v[1],v[0]);
} }
double getDecAngle(const QString& str) double getDecAngle(const QString& str)
{ {
QRegExp re1("^\\s*([\\+\\-])?\\s*(\\d+)\\s*[Dd\xBA]\\s*(\\d+)\\s*['M QRegExp re1("^\\s*([\\+\\-])?\\s*(\\d+)\\s*([hHDd\xBA])\\s*(\\d+)\\s
m]\\s*(\\d+(\\.\\d+)?)\\s*[\"Ss]\\s*([NSEWnsew])?\\s*$"); *['Mm]\\s*(\\d+(\\.\\d+)?)\\s*[\"Ss]\\s*([NSEWnsew])?\\s*$"); // DMS/HMS
QRegExp re2("^\\s*([\\+\\-])?\\s*(\\d+(\\.\\d+)?).?([NSEWnsew])\\s*$ QRegExp re2("^\\s*([\\+\\-])?\\s*(\\d+(\\.\\d+)?).?([NSEWnsew])?\\s*
"); $"); // Decimal
if (re1.exactMatch(str)) if (re1.exactMatch(str))
{ {
bool neg = (re1.capturedTexts().at(1) == "-"); bool neg = (re1.capturedTexts().at(1) == "-");
double d = re1.capturedTexts().at(2).toDouble(); double d = re1.capturedTexts().at(2).toDouble();
double m = re1.capturedTexts().at(3).toDouble(); double m = re1.capturedTexts().at(4).toDouble();
double s = re1.capturedTexts().at(4).toDouble(); double s = re1.capturedTexts().at(5).toDouble();
QString cardinal = re1.capturedTexts().at(6); if (re1.capturedTexts().at(3).toUpper() == "H")
{
d *= 15;
m *= 15;
s *= 15;
}
QString cardinal = re1.capturedTexts().at(7);
double deg = d + (m/60) + (s/3600); double deg = d + (m/60) + (s/3600);
if (cardinal.toLower() == "s" || cardinal.toLower() == "w" | | neg) if (cardinal.toLower() == "s" || cardinal.toLower() == "w" | | neg)
deg *= -1.; deg *= -1.;
return (deg * 2 * M_PI / 360.); return (deg * 2 * M_PI / 360.);
} }
else if (re2.exactMatch(str)) else if (re2.exactMatch(str))
{ {
bool neg = (re2.capturedTexts().at(1) == "-"); bool neg = (re2.capturedTexts().at(1) == "-");
double deg = re2.capturedTexts().at(2).toDouble(); double deg = re2.capturedTexts().at(2).toDouble();
QString cardinal = re2.capturedTexts().at(4); QString cardinal = re2.capturedTexts().at(4);
if (cardinal.toLower() == "s" || cardinal.toLower() == "w" | | neg) if (cardinal.toLower() == "s" || cardinal.toLower() == "w" | | neg)
deg *= -1.; deg *= -1.;
return (deg * 2 * M_PI / 360.); return (deg * 2 * M_PI / 360.);
} }
qDebug() << "getDecAngle failed to parse angle string:" << str; qDebug() << "getDecAngle failed to parse angle string:" << str;
return -0.0; return -0.0;
} }
// Check if a number is a power of 2 // Check if a number is a power of 2
bool isPowerOfTwo(int value) bool isPowerOfTwo(int value)
{ {
return (value & -value) == value; return (value & -value) == value;
} }
// Return the first power of two bigger than the given value // Return the first power of two bigger than the given value
int getBiggerPowerOfTwo(int value) int getBiggerPowerOfTwo(int value)
skipping to change at line 578 skipping to change at line 607
} }
//! try to get a reasonable locale date string from the system, trying to w ork around //! try to get a reasonable locale date string from the system, trying to w ork around
//! limitations of qdatetime for large dates in the past. see QDateTime::t oString(). //! limitations of qdatetime for large dates in the past. see QDateTime::t oString().
QString localeDateString(int year, int month, int day, int dayOfWeek) QString localeDateString(int year, int month, int day, int dayOfWeek)
{ {
// try the QDateTime first // try the QDateTime first
QDate test(year, month, day); QDate test(year, month, day);
if (test.isValid() && !test.toString(Qt::LocaleDate).isEmpty()) // try to avoid QDate's non-astronomical time here, don't do BCE or
year 0.
if (year > 0 && test.isValid() && !test.toString(Qt::LocaleDate).isE
mpty())
{ {
return test.toString(Qt::LocaleDate); return test.toString(Qt::LocaleDate);
} }
else else
{ {
return localeDateString(year,month,day,dayOfWeek,QLocale().d ateFormat(QLocale::ShortFormat)); return localeDateString(year,month,day,dayOfWeek,QLocale().d ateFormat(QLocale::ShortFormat));
} }
} }
//! use QDateTime to get a Julian Date from the system's current time. //! use QDateTime to get a Julian Date from the system's current time.
skipping to change at line 615 skipping to change at line 645
int mins = (int)((decHours-(hours*0.041666666666666666666))/0.000694 44444444444444444); int mins = (int)((decHours-(hours*0.041666666666666666666))/0.000694 44444444444444444);
return QTime::fromString(QString("%1.%2").arg(hours).arg(mins), "h.m "); return QTime::fromString(QString("%1.%2").arg(hours).arg(mins), "h.m ");
} }
// Use Qt's own sense of time and offset instead of platform specific code. // Use Qt's own sense of time and offset instead of platform specific code.
float getGMTShiftFromQT(double JD) float getGMTShiftFromQT(double JD)
{ {
int year, month, day, hour, minute, second; int year, month, day, hour, minute, second;
getDateFromJulianDay(JD, &year, &month, &day); getDateFromJulianDay(JD, &year, &month, &day);
getTimeFromJulianDay(JD, &hour, &minute, &second); getTimeFromJulianDay(JD, &hour, &minute, &second);
// as analogous to second statement in getJDFromDate, nkerr
if ( year <= 0 ) {
year = year - 1;
}
QDateTime current(QDate(year, month, day), QTime(hour, minute, secon d)); QDateTime current(QDate(year, month, day), QTime(hour, minute, secon d));
if (! current.isValid()) if (! current.isValid())
{ {
qWarning() << "JD " << QString("%1").arg(JD) << " out of bou //qWarning() << "JD " << QString("%1").arg(JD) << " out of b
nds of QT help with GMT shift, using current datetime"; ounds of QT help with GMT shift, using current datetime";
current = QDateTime::currentDateTime(); // Assumes the GMT shift was always the same before year -47
10
current = QDateTime(QDate(-4710, month, day), QTime(hour, mi
nute, second));
} }
QDateTime c1 = QDateTime::fromString(current.toString(Qt::ISODate),Q t::ISODate); QDateTime c1 = QDateTime::fromString(current.toString(Qt::ISODate),Q t::ISODate);
QDateTime u1 = QDateTime::fromString(current.toUTC().toString(Qt::IS ODate),Qt::ISODate); QDateTime u1 = QDateTime::fromString(current.toUTC().toString(Qt::IS ODate),Qt::ISODate);
int secsto = u1.secsTo(c1); int secsto = u1.secsTo(c1);
float hrsto = secsto / 3600.0f; float hrsto = secsto / 3600.0f;
return hrsto; return hrsto;
} }
// UTC ! // UTC !
skipping to change at line 825 skipping to change at line 860
*ry = oy; *ry = oy;
*rm = om; *rm = om;
*rd = od; *rd = od;
*rh = oh; *rh = oh;
*rmin = omin; *rmin = omin;
*rs = os; *rs = os;
} }
return change; return change;
} }
void debugQVariantMap(const QVariant& m, const QString& indent, const QStri
ng& key)
{
QVariant::Type t = m.type();
if (t == QVariant::Map)
{
qDebug() << indent + key + "(map):";
QList<QString> keys = m.toMap().keys();
qSort(keys);
foreach(QString k, keys)
{
debugQVariantMap(m.toMap()[k], indent + " ", k);
}
}
else if (t == QVariant::List)
{
qDebug() << indent + key + "(list):";
foreach(QVariant item, m.toList())
{
debugQVariantMap(item, indent + " ");
}
}
else
qDebug() << indent + key + " => " + m.toString();
}
QList<int> getIntsFromISO8601String(const QString & dt)
{
// Represents a valid, complete date string.
static QRegExp finalRe("(-0*[1-9][0-9]{0,5}|0+|0*[1-9][0-9]{0,5})-(0
[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[10])[T ]([01][0-9]|2[0123]):([012345][0-9
]):([012345][0-9])");
QList<int> retval;
if (finalRe.exactMatch(dt))
{
QStringList number_strings = finalRe.capturedTexts();
bool ok;
int v;
for (int i = 1; i < number_strings.size(); i++)
{
qWarning() << ":: at capture " << i << " got a " <<
number_strings[i];
ok = true;
v = number_strings[i].toInt(&ok, 10);
qWarning() << " :: and it was a " << v << " " << ok
;
if (ok)
{
retval.push_back(v);
}
else
{
retval.clear();
qWarning() << "StelUtils::getIntsFromISO8601
String: input string failed to be an exact date at capture " << i << ", ret
urning nothing: " << dt;
break;
}
}
}
else
{
qWarning() << "StelUtils::getIntsFromISO8601String: input st
ring failed to be an exact date, returning nothing: " << dt;
}
return retval;
}
} // end of the StelUtils namespace } // end of the StelUtils namespace
 End of changes. 10 change blocks. 
13 lines changed or deleted 121 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/