Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
FormatCoordsUnitsStrategyPolarTheta.cpp
1 #include "EngaugeAssert.h"
2 #include "FormatCoordsUnitsStrategyPolarTheta.h"
3 #include "FormatDegreesMinutesSecondsPolarTheta.h"
4 #include "Logger.h"
5 
7 {
8 }
9 
11  CoordUnitsPolarTheta coordUnits) const
12 {
13  LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::formattedToUnformatted";
14 
15  double value;
16 
17  switch (coordUnits) {
18  case COORD_UNITS_POLAR_THETA_DEGREES:
19  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
20  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
21  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
22  {
24  ENGAUGE_ASSERT (format.parseInput (string,
25  value) == QValidator::Acceptable);
26  }
27  break;
28 
29  case COORD_UNITS_POLAR_THETA_GRADIANS:
30  case COORD_UNITS_POLAR_THETA_RADIANS:
31  case COORD_UNITS_POLAR_THETA_TURNS:
32  value = string.toDouble();
33  break;
34 
35  default:
36  LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormattedStrategyPolarTheta";
37  ENGAUGE_ASSERT (false);
38  break;
39  }
40 
41  return value;
42 }
43 
45  CoordUnitsPolarTheta coordUnits,
46  const Transformation &transformation,
47  double valueUnformattedOther) const
48 {
49  LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormatted";
50 
51  const char FORMAT ('g');
52  const bool IS_X_THETA = true;
53 
54  QString valueFormatted;
55 
56  switch (coordUnits) {
57  case COORD_UNITS_POLAR_THETA_DEGREES:
58  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
59  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
60  case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
61  {
63  valueFormatted = format.formatOutput (coordUnits,
64  valueUnformatted,
65  IS_X_THETA);
66  }
67  break;
68 
69  case COORD_UNITS_POLAR_THETA_GRADIANS:
70  case COORD_UNITS_POLAR_THETA_RADIANS:
71  case COORD_UNITS_POLAR_THETA_TURNS:
72  valueFormatted = QString::number (valueUnformatted,
73  FORMAT,
74  precisionDigitsForRawNumber (valueUnformatted,
75  valueUnformattedOther,
76  IS_X_THETA,
77  transformation));
78  break;
79 
80  default:
81  LOG4CPP_ERROR_S ((*mainCat)) << "FormatCoordsUnitsStrategyPolarTheta::unformattedToFormattedStrategyPolarTheta";
82  ENGAUGE_ASSERT (false);
83  break;
84  }
85 
86  return valueFormatted;
87 }
double formattedToUnformatted(const QString &string, CoordUnitsPolarTheta coordUnits) const
Convert formatted string to simple unformatted number.
Angular units according to CoordUnitsPolarTheta.
QValidator::State parseInput(const QString &stringUntrimmed, double &value) const
Parse the input string into a number value.
Affine transformation between screen and graph coordinates, based on digitized axis points...
int precisionDigitsForRawNumber(double valueUnformatted, double valueUnformattedOther, bool isXTheta, const Transformation &transformation) const
Compute precision for outputting an unformatted value, consistent with the resolution at the point wh...
QString unformattedToFormatted(double valueUnformatted, CoordUnitsPolarTheta coordUnits, const Transformation &transformation, double valueUnformattedOther) const
Convert simple unformatted number to formatted string.
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/...