Engauge Digitizer  2
FormatDegreesMinutesSecondsPolarTheta.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "CoordSymbol.h"
8 #include "EngaugeAssert.h"
9 #include "FormatDegreesMinutesSecondsPolarTheta.h"
10 #include "Logger.h"
11 #include <qmath.h>
12 #include <QRegExp>
13 #include <QStringList>
14 
15 const int DECIMAL_TO_MINUTES = 60.0;
16 
18 {
19 }
20 
21 QString FormatDegreesMinutesSecondsPolarTheta::formatOutput (CoordUnitsPolarTheta coordUnits,
22  double value,
23  bool isNsHemisphere) const
24 {
25  LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutput";
26 
27  // See if similar method with hemisphere argument should have been called
28  ENGAUGE_ASSERT (coordUnits != COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW);
29 
30  switch (coordUnits) {
31  case COORD_UNITS_POLAR_THETA_DEGREES:
32  return formatOutputDegrees (value);
33 
34  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
35  return formatOutputDegreesMinutes (value);
36 
37  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
38  return formatOutputDegreesMinutesSeconds (value);
39 
40  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
42  isNsHemisphere);
43 
44  default:
45  break;
46  }
47 
48  LOG4CPP_ERROR_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutput";
49  ENGAUGE_ASSERT (false);
50 
51  return "";
52 }
53 
54 QString FormatDegreesMinutesSecondsPolarTheta::formatOutputDegrees (double value) const
55 {
56  LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutputDegrees";
57 
58  // Since version 6 there has been no number-only option (=without degrees symbol) for theta in CoordUnitsPolarTheta.
59  // The degrees symbol causes more problems than it is worth for COORD_UNITS_POLAR_THETA_DEGREES, so we output only
60  // the number and skip the degrees symbol here
61  return QString ("%1")
62  .arg (value);
63 }
64 
65 QString FormatDegreesMinutesSecondsPolarTheta::formatOutputDegreesMinutes (double value) const
66 {
67  LOG4CPP_INFO_S ((*mainCat)) << "FormatDegreesMinutesSecondsPolarTheta::formatOutputDegreesMinutes";
68 
69  // Only smallest resolution value is floating point
70  bool negative = (value < 0);
71  value = qAbs (value);
72  int degrees = qFloor (value);
73  value -= degrees;
74  double minutes = value * DECIMAL_TO_MINUTES;
75  degrees *= (negative ? -1.0 : 1.0);
76 
77  return QString ("%1%2 %3%4")
78  .arg (degrees)
79  .arg (QChar (COORD_SYMBOL_DEGREES))
80  .arg (minutes)
81  .arg (QChar (COORD_SYMBOL_MINUTES_PRIME));
82 }
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/...
QString formatOutputDegreesMinutesSecondsNsew(double value, bool isNsHemisphere) const
Format as degrees, minutes and seconds with hemisphere.
QString formatOutputDegreesMinutesSeconds(double value) const
Format as degrees, minutes and seconds without hemisphere.