00001
00002
00003
00004
00005
00006
00007 #include "CoordSymbol.h"
00008 #include "EngaugeAssert.h"
00009 #include "FormatDegreesMinutesSecondsPolarTheta.h"
00010 #include "Logger.h"
00011 #include <qmath.h>
00012 #include <QRegExp>
00013 #include <QStringList>
00014
00015 const int DECIMAL_TO_MINUTES = 60.0;
00016
00017 FormatDegreesMinutesSecondsPolarTheta::FormatDegreesMinutesSecondsPolarTheta()
00018 {
00019 }
00020
00021 QString FormatDegreesMinutesSecondsPolarTheta::formatOutput (CoordUnitsPolarTheta coordUnits,
00022 double value,
00023 bool isNsHemisphere) const
00024 {
00025 LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutput";
00026
00027
00028 ENGAUGE_ASSERT (coordUnits != COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW);
00029
00030 switch (coordUnits) {
00031 case COORD_UNITS_POLAR_THETA_DEGREES:
00032 return formatOutputDegrees (value);
00033
00034 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
00035 return formatOutputDegreesMinutes (value);
00036
00037 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
00038 return formatOutputDegreesMinutesSeconds (value);
00039
00040 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
00041 return formatOutputDegreesMinutesSecondsNsew (value,
00042 isNsHemisphere);
00043
00044 default:
00045 break;
00046 }
00047
00048 LOG4CPP_ERROR_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutput";
00049 ENGAUGE_ASSERT (false);
00050
00051 return "";
00052 }
00053
00054 QString FormatDegreesMinutesSecondsPolarTheta::formatOutputDegrees (double value) const
00055 {
00056 LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutputDegrees";
00057
00058
00059
00060
00061 return QString ("%1")
00062 .arg (value);
00063 }
00064
00065 QString FormatDegreesMinutesSecondsPolarTheta::formatOutputDegreesMinutes (double value) const
00066 {
00067 LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutputDegreesMinutes";
00068
00069
00070 bool negative = (value < 0);
00071 value = qAbs (value);
00072 int degrees = qFloor (value);
00073 value -= degrees;
00074 double minutes = value * DECIMAL_TO_MINUTES;
00075 degrees *= (negative ? -1.0 : 1.0);
00076
00077 return QString ("%1%2 %3%4")
00078 .arg (degrees)
00079 .arg (QChar (COORD_SYMBOL_DEGREES))
00080 .arg (minutes)
00081 .arg (QChar (COORD_SYMBOL_MINUTES_PRIME));
00082 }