Engauge Digitizer  2
FormatDegreesMinutesSecondsPolarTheta.cpp
Go to the documentation of this file.
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"
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 
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
29 
30  switch (coordUnits) {
32  return formatOutputDegrees (value);
33 
35  return formatOutputDegreesMinutes (value);
36 
38  return formatOutputDegreesMinutesSeconds (value);
39 
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 }
const int COORD_SYMBOL_DEGREES
Mathematical symbols for degrees, minutes, seconds input/outputs from/to users.
Definition: CoordSymbol.cpp:9
const int COORD_SYMBOL_MINUTES_PRIME
Definition: CoordSymbol.cpp:10
CoordUnitsPolarTheta
@ COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW
@ COORD_UNITS_POLAR_THETA_DEGREES_MINUTES
@ COORD_UNITS_POLAR_THETA_DEGREES
@ COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20
log4cpp::Category * mainCat
Definition: Logger.cpp:14
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/...
#define LOG4CPP_ERROR_S(logger)
Definition: convenience.h:12