Engauge Digitizer  2
FormatDegreesMinutesSecondsPolarTheta.cpp
1 #include "CoordSymbol.h"
2 #include "EngaugeAssert.h"
3 #include "FormatDegreesMinutesSecondsPolarTheta.h"
4 #include "Logger.h"
5 #include <qmath.h>
6 #include <QRegExp>
7 #include <QStringList>
8 
9 const int DECIMAL_TO_MINUTES = 60.0;
10 const int DECIMAL_TO_SECONDS = 60.0;
11 
13 {
14 }
15 
16 QString FormatDegreesMinutesSecondsPolarTheta::formatOutput (CoordUnitsPolarTheta coordUnits,
17  double value,
18  bool isNsHemisphere) const
19 {
20  LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutput";
21 
22  // See if similar method with hemisphere argument should have been called
23  ENGAUGE_ASSERT (coordUnits != COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW);
24 
25  switch (coordUnits) {
26  case COORD_UNITS_POLAR_THETA_DEGREES:
27  return formatOutputDegrees (value);
28 
29  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
30  return formatOutputDegreesMinutes (value);
31 
32  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
33  return formatOutputDegreesMinutesSeconds (value);
34 
35  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
37  isNsHemisphere);
38 
39  default:
40  break;
41  }
42 
43  LOG4CPP_ERROR_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutput";
44  ENGAUGE_ASSERT (false);
45 
46  return "";
47 }
48 
49 QString FormatDegreesMinutesSecondsPolarTheta::formatOutputDegrees (double value) const
50 {
51  LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutputDegrees";
52 
53  // Even for just degrees we include the degrees symbol since user would have picked regular numbers if that symbol was unwanted
54  return QString ("%1%2")
55  .arg (value)
56  .arg (QChar (COORD_SYMBOL_DEGREES));
57 }
58 
59 QString FormatDegreesMinutesSecondsPolarTheta::formatOutputDegreesMinutes (double value) const
60 {
61  LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutputDegreesMinutes";
62 
63  // Only smallest resolution value is floating point
64  bool negative = (value < 0);
65  value = qAbs (value);
66  int degrees = qFloor (value);
67  value -= degrees;
68  double minutes = value * DECIMAL_TO_MINUTES;
69  degrees *= (negative ? -1.0 : 1.0);
70 
71  return QString ("%1%2 %3%4")
72  .arg (degrees)
73  .arg (QChar (COORD_SYMBOL_DEGREES))
74  .arg (minutes)
75  .arg (QChar (COORD_SYMBOL_MINUTES_PRIME));
76 }
QString formatOutputDegreesMinutesSeconds(double value) const
Format as degrees, minutes and seconds without hemisphere.
QString formatOutputDegreesMinutesSecondsNsew(double value, bool isNsHemisphere) const
Format as degrees, minutes and seconds with hemisphere.
QString formatOutput(CoordUnitsPolarTheta coordUnits, double value, bool isXTheta) const
Format the degrees/minutes/seconds value. Distinguishing x/theta versus y/radius is required for N/S/...