Mercurial > hg > aimc
comparison src/Modules/Output/Graphics/GraphAxisSpec.cc @ 117:c5ac2f0c7fc5
- All \t to two spaces (style guide compliance)
author | tomwalters |
---|---|
date | Fri, 15 Oct 2010 05:46:53 +0000 |
parents | 47b009f2c936 |
children | 18237d55e346 |
comparison
equal
deleted
inserted
replaced
116:47b009f2c936 | 117:c5ac2f0c7fc5 |
---|---|
20 #include <stdio.h> | 20 #include <stdio.h> |
21 | 21 |
22 #include "Modules/Output/Graphics/GraphAxisSpec.h" | 22 #include "Modules/Output/Graphics/GraphAxisSpec.h" |
23 | 23 |
24 GraphAxisSpec::GraphAxisSpec(float fMin, float fMax, Scale::ScaleType iScale) { | 24 GraphAxisSpec::GraphAxisSpec(float fMin, float fMax, Scale::ScaleType iScale) { |
25 m_pScale = NULL; | 25 m_pScale = NULL; |
26 m_sLabel = NULL; | 26 m_sLabel = NULL; |
27 SetDisplayRange(fMin, fMax); | 27 SetDisplayRange(fMin, fMax); |
28 SetDisplayScale(iScale); | 28 SetDisplayScale(iScale); |
29 } | 29 } |
30 | 30 |
31 GraphAxisSpec::GraphAxisSpec() { | 31 GraphAxisSpec::GraphAxisSpec() { |
32 m_pScale = NULL; | 32 m_pScale = NULL; |
33 m_sLabel = NULL; | 33 m_sLabel = NULL; |
34 m_fMin = 0; | 34 m_fMin = 0; |
35 m_fMax = 0; | 35 m_fMax = 0; |
36 } | 36 } |
37 | 37 |
38 GraphAxisSpec::~GraphAxisSpec() { | 38 GraphAxisSpec::~GraphAxisSpec() { |
39 DELETE_IF_NONNULL(m_pScale); | 39 DELETE_IF_NONNULL(m_pScale); |
40 } | 40 } |
41 | 41 |
42 void GraphAxisSpec::SetDisplayRange(float fMin, float fMax) { | 42 void GraphAxisSpec::SetDisplayRange(float fMin, float fMax) { |
43 AIM_ASSERT(fMin <= fMax); | 43 AIM_ASSERT(fMin <= fMax); |
44 m_fMin = fMin; | 44 m_fMin = fMin; |
45 m_fMax = fMax; | 45 m_fMax = fMax; |
46 if (m_pScale) | 46 if (m_pScale) |
47 m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax); | 47 m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax); |
48 } | 48 } |
49 | 49 |
50 void GraphAxisSpec::SetDisplayScale(Scale::ScaleType iScale) { | 50 void GraphAxisSpec::SetDisplayScale(Scale::ScaleType iScale) { |
51 DELETE_IF_NONNULL(m_pScale); | 51 DELETE_IF_NONNULL(m_pScale); |
52 m_pScale = Scale::Create(iScale); | 52 m_pScale = Scale::Create(iScale); |
53 aimASSERT(m_pScale); | 53 aimASSERT(m_pScale); |
54 m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax); | 54 m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax); |
55 } | 55 } |
56 | 56 |
57 bool GraphAxisSpec::Initialize(Parameters *parameters, | 57 bool GraphAxisSpec::Initialize(Parameters *parameters, |
58 const char *sPrefix, | 58 const char *sPrefix, |
59 float fMin, | 59 float fMin, |
60 float fMax, | 60 float fMax, |
61 Scale::ScaleType iScale) { | 61 Scale::ScaleType iScale) { |
62 AIM_ASSERT(pParam); | 62 AIM_ASSERT(pParam); |
63 AIM_ASSERT(sPrefix && sPrefix[0]!='\0'); | 63 AIM_ASSERT(sPrefix && sPrefix[0]!='\0'); |
64 char sParamName[Parameters::MaxParamNameLength]; | 64 char sParamName[Parameters::MaxParamNameLength]; |
65 | 65 |
66 //! The following parameters are recognized for each axis: | 66 //! The following parameters are recognized for each axis: |
67 //! - \c "<prefix>.min", the minimum value; a float or \c 'auto' | 67 //! - \c "<prefix>.min", the minimum value; a float or \c 'auto' |
68 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), | 68 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), |
69 "%s.min", | 69 "%s.min", |
70 sPrefix); | 70 sPrefix); |
71 if (pParam->IsSet(sParamName)) { | 71 if (pParam->IsSet(sParamName)) { |
72 if (strcmp(parameters->GetString(sParamName), "auto") == 0) | 72 if (strcmp(parameters->GetString(sParamName), "auto") == 0) |
73 m_fMin = fMin; | 73 m_fMin = fMin; |
74 else | 74 else |
75 m_fMin = parameters->GetFloat(sParamName); | 75 m_fMin = parameters->GetFloat(sParamName); |
76 } | 76 } |
77 | 77 |
78 //! - \c "<prefix>.max", the maximum value; a float or \c 'auto' | 78 //! - \c "<prefix>.max", the maximum value; a float or \c 'auto' |
79 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), | 79 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), |
80 "%s.max", | 80 "%s.max", |
81 sPrefix); | 81 sPrefix); |
82 if (pParam->IsSet(sParamName)) { | 82 if (pParam->IsSet(sParamName)) { |
83 if (strcmp(parameters->GetString(sParamName), "auto")==0) | 83 if (strcmp(parameters->GetString(sParamName), "auto")==0) |
84 m_fMax = fMax; | 84 m_fMax = fMax; |
85 else | 85 else |
86 m_fMax = parameters->GetFloat(sParamName); | 86 m_fMax = parameters->GetFloat(sParamName); |
87 } | 87 } |
88 | 88 |
89 // Make sure ranges are updated properly | 89 // Make sure ranges are updated properly |
90 SetDisplayRange(m_fMin, m_fMax); | 90 SetDisplayRange(m_fMin, m_fMax); |
91 | 91 |
92 //! - \c "<prefix>.scale", the scale; one of \c 'auto', | 92 //! - \c "<prefix>.scale", the scale; one of \c 'auto', |
93 //! \c 'linear', \c 'erb' or \c 'log' | 93 //! \c 'linear', \c 'erb' or \c 'log' |
94 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), | 94 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), |
95 "%s.scale", | 95 "%s.scale", |
96 sPrefix); | 96 sPrefix); |
97 if (pParam->IsSet(sParamName)) { | 97 if (pParam->IsSet(sParamName)) { |
98 // Scale change, we updated min/max values already so no need to | 98 // Scale change, we updated min/max values already so no need to |
99 Scale::ScaleType iThisScale; | 99 Scale::ScaleType iThisScale; |
100 const char *sVal = parameters->GetString(sParamName); | 100 const char *sVal = parameters->GetString(sParamName); |
101 if (strcmp(sVal, "auto")==0) | 101 if (strcmp(sVal, "auto")==0) |
102 iThisScale = iScale; | 102 iThisScale = iScale; |
103 else if (strcmp(sVal, "linear")==0) | 103 else if (strcmp(sVal, "linear")==0) |
104 iThisScale = Scale::SCALE_LINEAR; | 104 iThisScale = Scale::SCALE_LINEAR; |
105 else if (strcmp(sVal, "erb")==0) | 105 else if (strcmp(sVal, "erb")==0) |
106 iThisScale = Scale::SCALE_ERB; | 106 iThisScale = Scale::SCALE_ERB; |
107 else if (strcmp(sVal, "log")==0) | 107 else if (strcmp(sVal, "log")==0) |
108 iThisScale = Scale::SCALE_LOG; | 108 iThisScale = Scale::SCALE_LOG; |
109 else { | 109 else { |
110 AIM_ERROR(_T("Unrecognized scale type in parameter '%s': '%s'"), | 110 AIM_ERROR(_T("Unrecognized scale type in parameter '%s': '%s'"), |
111 sParamName, | 111 sParamName, |
112 sVal); | 112 sVal); |
113 return false; | 113 return false; |
114 } | 114 } |
115 SetDisplayScale(iThisScale); | 115 SetDisplayScale(iThisScale); |
116 } | 116 } |
117 | 117 |
118 //! - \c "<prefix>.label", the label; a string | 118 //! - \c "<prefix>.label", the label; a string |
119 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), | 119 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), |
120 "%s.label", | 120 "%s.label", |
121 sPrefix); | 121 sPrefix); |
122 if (parameters->IsSet(sParamName)) | 122 if (parameters->IsSet(sParamName)) |
123 m_sLabel = parameters->GetString(sParamName); // Assumes strings remains valid | 123 m_sLabel = parameters->GetString(sParamName); // Assumes strings remains valid |
124 | 124 |
125 return true; | 125 return true; |
126 } | 126 } |