File: qwt__drange_8cpp-source.html

package info (click to toggle)
libqwt 4.2.0-4.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,832 kB
  • ctags: 5,512
  • sloc: cpp: 22,973; ansic: 244; makefile: 66
file content (265 lines) | stat: -rw-r--r-- 15,344 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Qwt User&apos;s Guide: qwt_drange.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.8 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<h1>qwt_drange.cpp</h1><pre class="fragment"><div>00001 <span class="comment">/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************</span>
00002 <span class="comment"> * Qwt Widget Library</span>
00003 <span class="comment"> * Copyright (C) 1997   Josef Wilgen</span>
00004 <span class="comment"> * Copyright (C) 2002   Uwe Rathmann</span>
00005 <span class="comment"> * </span>
00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
00007 <span class="comment"> * modify it under the terms of the Qwt License, Version 1.0</span>
00008 <span class="comment"> *****************************************************************************/</span>
00009 
00010 <span class="preprocessor">#include "qwt_drange.h"</span>
00011 <span class="preprocessor">#include "<a class="code" href="qwt__math_8h.html">qwt_math.h</a>"</span>
00012 
00013 <span class="keyword">static</span> <span class="keywordtype">double</span> MinRelStep = 1.0e-10;
00014 <span class="keyword">static</span> <span class="keywordtype">double</span> DefaultRelStep = 1.0e-2;
00015 <span class="keyword">static</span> <span class="keywordtype">double</span> MinEps = 1.0e-10;
00016 
<a name="l00021"></a><a class="code" href="class_qwt_dbl_range.html#a0">00021</a> <a class="code" href="class_qwt_dbl_range.html#a0">QwtDblRange::QwtDblRange</a>():
00022     d_minValue(0.0),
00023     d_maxValue(100.0),
00024     d_step(1.0),
00025     d_pageSize(1),
00026     d_isValid(FALSE),
00027     d_value(0.0),
00028     d_exactValue(0.0),
00029     d_exactPrevValue(0.0),
00030     d_prevValue(0.0),
00031     d_periodic(FALSE)
00032 {
00033 }
00034 
<a name="l00036"></a><a class="code" href="class_qwt_dbl_range.html#a1">00036</a> <a class="code" href="class_qwt_dbl_range.html#a1">QwtDblRange::~QwtDblRange</a>()
00037 {
00038 }
00039 
<a name="l00041"></a><a class="code" href="class_qwt_dbl_range.html#a3">00041</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_dbl_range.html#a3">QwtDblRange::setValid</a>(<span class="keywordtype">bool</span> isValid)
00042 {
00043     <span class="keywordflow">if</span> ( isValid != d_isValid )
00044     {
00045         d_isValid = isValid;
00046         <a class="code" href="class_qwt_dbl_range.html#b3">valueChange</a>();
00047     }
00048 }
00049 
<a name="l00051"></a><a class="code" href="class_qwt_dbl_range.html#a4">00051</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_dbl_range.html#a4">QwtDblRange::isValid</a>()<span class="keyword"> const</span>
00052 <span class="keyword"></span>{
00053     <span class="keywordflow">return</span> d_isValid;
00054 }
00055 
00064 <span class="keywordtype">void</span> QwtDblRange::setNewValue(<span class="keywordtype">double</span> x, <span class="keywordtype">int</span> align)
00065 {
00066     <span class="keywordtype">double</span> vmin,vmax;
00067     
00068     d_prevValue = d_value;
00069 
00070     vmin = qwtMin(d_minValue, d_maxValue);
00071     vmax = qwtMax(d_minValue, d_maxValue);
00072 
00073     <span class="comment">// </span>
00074     <span class="comment">// Range check</span>
00075     <span class="comment">//</span>
00076     <span class="keywordflow">if</span> (x &lt; vmin)
00077     {
00078         <span class="keywordflow">if</span> ((d_periodic) &amp;&amp; (vmin != vmax))
00079            d_value = x + ceil( (vmin - x) / (vmax - vmin ) ) 
00080               * (vmax - vmin);
00081         <span class="keywordflow">else</span>
00082            d_value = vmin;
00083     }
00084     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (x &gt; vmax)
00085     {
00086         <span class="keywordflow">if</span> ((d_periodic) &amp;&amp; (vmin != vmax))
00087            d_value = x - ceil( ( x - vmax) / (vmax - vmin )) 
00088               * (vmax - vmin);
00089         <span class="keywordflow">else</span>
00090            d_value = vmax;
00091     }
00092     <span class="keywordflow">else</span>
00093        d_value = x;
00094 
00095     d_exactPrevValue = d_exactValue;
00096     d_exactValue = d_value;
00097     
00098     <span class="comment">// align to grid</span>
00099     <span class="keywordflow">if</span> (align)
00100     {
00101         <span class="keywordflow">if</span> (d_step != 0.0)
00102            d_value = d_minValue +
00103              floor ((d_value - d_minValue) / d_step + 0.5) * d_step;
00104         <span class="keywordflow">else</span>
00105            d_value = d_minValue;
00106         
00107         <span class="comment">// correct rounding error at the border</span>
00108         <span class="keywordflow">if</span> (fabs(d_value - d_maxValue) &lt; MinEps * qwtAbs(d_step))
00109            d_value = d_maxValue;
00110 
00111         <span class="comment">// correct rounding error if value = 0</span>
00112         <span class="keywordflow">if</span> (fabs(d_value) &lt; MinEps * qwtAbs(d_step))
00113            d_value = 0.0;
00114     }
00115 
00116     <span class="keywordflow">if</span> (!d_isValid || d_prevValue != d_value)
00117     {
00118         d_isValid = TRUE;
00119         <a class="code" href="class_qwt_dbl_range.html#b3">valueChange</a>();
00120     }
00121 }
00122 
<a name="l00132"></a><a class="code" href="class_qwt_dbl_range.html#a16">00132</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_dbl_range.html#a16">QwtDblRange::fitValue</a>(<span class="keywordtype">double</span> x)
00133 {
00134     setNewValue(x,1);
00135 }
00136 
00137 
<a name="l00147"></a><a class="code" href="class_qwt_dbl_range.html#a5">00147</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_dbl_range.html#a5">QwtDblRange::setValue</a>(<span class="keywordtype">double</span> x)
00148 {
00149     setNewValue(x,0);
00150 }
00151 
<a name="l00169"></a><a class="code" href="class_qwt_dbl_range.html#a2">00169</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_dbl_range.html#a2">QwtDblRange::setRange</a>(<span class="keywordtype">double</span> vmin, <span class="keywordtype">double</span> vmax, <span class="keywordtype">double</span> vstep, <span class="keywordtype">int</span> pageSize)
00170 {
00171     <span class="keywordtype">int</span> rchg = ((d_maxValue != vmax) || (d_minValue != vmin));
00172     
00173     <span class="keywordflow">if</span> (rchg) 
00174     {
00175         d_minValue = vmin;
00176         d_maxValue = vmax;
00177     }
00178     
00179     <span class="comment">//</span>
00180     <span class="comment">// look if the step width has an acceptable </span>
00181     <span class="comment">// value or otherwise change it.</span>
00182     <span class="comment">//</span>
00183     <a class="code" href="class_qwt_dbl_range.html#a9">setStep</a>(vstep);
00184 
00185     <span class="comment">//</span>
00186     <span class="comment">// limit page size</span>
00187     <span class="comment">//</span>
00188     d_pageSize = <a class="code" href="qwt__math_8h.html#a37">qwtLim</a>(pageSize,0, 
00189         <span class="keywordtype">int</span>(qwtAbs((d_maxValue - d_minValue) / d_step))); 
00190     
00191     <span class="comment">// </span>
00192     <span class="comment">// If the value lies out of the range, it </span>
00193     <span class="comment">// will be changed. Note that it will not be adjusted to </span>
00194     <span class="comment">// the new step width.</span>
00195     setNewValue(d_value,0);
00196     
00197     <span class="comment">// call notifier after the step width has been </span>
00198     <span class="comment">// adjusted.</span>
00199     <span class="keywordflow">if</span> (rchg)
00200        <a class="code" href="class_qwt_dbl_range.html#b5">rangeChange</a>();
00201 }
00202 
<a name="l00208"></a><a class="code" href="class_qwt_dbl_range.html#a9">00208</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_dbl_range.html#a9">QwtDblRange::setStep</a>(<span class="keywordtype">double</span> vstep)
00209 {
00210     <span class="keywordtype">double</span> intv = d_maxValue - d_minValue;
00211     
00212     <span class="keywordtype">double</span> newStep;
00213     <span class="keywordflow">if</span> (vstep == 0.0)
00214        newStep = intv * DefaultRelStep;
00215     <span class="keywordflow">else</span>
00216     {
00217         <span class="keywordflow">if</span> ((intv &gt; 0) &amp;&amp; (vstep &lt; 0) || (intv &lt; 0) &amp;&amp; (vstep &gt; 0))
00218            newStep = -vstep;
00219         <span class="keywordflow">else</span>
00220            newStep = vstep;
00221         
00222         <span class="keywordflow">if</span> ( fabs(newStep) &lt; fabs(MinRelStep * intv) )
00223            newStep = MinRelStep * intv;
00224     }
00225     
00226     <span class="keywordflow">if</span> (newStep != d_step)
00227     {
00228         d_step = newStep;
00229         <a class="code" href="class_qwt_dbl_range.html#b4">stepChange</a>();
00230     }
00231 }
00232 
00233 
<a name="l00248"></a><a class="code" href="class_qwt_dbl_range.html#a7">00248</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_dbl_range.html#a7">QwtDblRange::setPeriodic</a>(<span class="keywordtype">bool</span> tf)
00249 {
00250     d_periodic = tf;
00251 }
00252 
<a name="l00259"></a><a class="code" href="class_qwt_dbl_range.html#a14">00259</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_dbl_range.html#a14">QwtDblRange::incValue</a>(<span class="keywordtype">int</span> nSteps)
00260 {
00261     <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_dbl_range.html#a4">isValid</a>() )
00262         setNewValue(d_value + <span class="keywordtype">double</span>(nSteps) * d_step,1);
00263 }
00264 
<a name="l00271"></a><a class="code" href="class_qwt_dbl_range.html#a15">00271</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_dbl_range.html#a15">QwtDblRange::incPages</a>(<span class="keywordtype">int</span> nPages)
00272 {
00273     <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_dbl_range.html#a4">isValid</a>() )
00274         setNewValue(d_value + <span class="keywordtype">double</span>(nPages) * <span class="keywordtype">double</span>(d_pageSize) * d_step,1);
00275 }
00276 
<a name="l00283"></a><a class="code" href="class_qwt_dbl_range.html#b3">00283</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_dbl_range.html#b3">QwtDblRange::valueChange</a>()
00284 {
00285 }
00286 
00287 
<a name="l00294"></a><a class="code" href="class_qwt_dbl_range.html#b5">00294</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_dbl_range.html#b5">QwtDblRange::rangeChange</a>()
00295 {
00296 }
00297 
00298 
<a name="l00305"></a><a class="code" href="class_qwt_dbl_range.html#b4">00305</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_dbl_range.html#b4">QwtDblRange::stepChange</a>()
00306 {
00307 }
00308 
<a name="l00313"></a><a class="code" href="class_qwt_dbl_range.html#a10">00313</a> <span class="keywordtype">double</span> <a class="code" href="class_qwt_dbl_range.html#a10">QwtDblRange::step</a>()<span class="keyword"> const</span>
00314 <span class="keyword"></span>{
00315     <span class="keywordflow">return</span> qwtAbs(d_step);
00316 }
00317 
<a name="l00326"></a><a class="code" href="class_qwt_dbl_range.html#a11">00326</a> <span class="keywordtype">double</span> <a class="code" href="class_qwt_dbl_range.html#a11">QwtDblRange::maxValue</a>()<span class="keyword"> const</span>
00327 <span class="keyword"></span>{   
00328     <span class="keywordflow">return</span> d_maxValue;
00329 } 
00330     
<a name="l00339"></a><a class="code" href="class_qwt_dbl_range.html#a12">00339</a> <span class="keywordtype">double</span> <a class="code" href="class_qwt_dbl_range.html#a12">QwtDblRange::minValue</a>()<span class="keyword"> const </span>
00340 <span class="keyword"></span>{
00341     <span class="keywordflow">return</span> d_minValue; 
00342 }   
00343 
<a name="l00348"></a><a class="code" href="class_qwt_dbl_range.html#a8">00348</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_dbl_range.html#a8">QwtDblRange::periodic</a>()<span class="keyword"> const </span>
00349 <span class="keyword"></span>{ 
00350     <span class="keywordflow">return</span> d_periodic; 
00351 }
00352 
<a name="l00354"></a><a class="code" href="class_qwt_dbl_range.html#a13">00354</a> <span class="keywordtype">int</span> <a class="code" href="class_qwt_dbl_range.html#a13">QwtDblRange::pageSize</a>()<span class="keyword"> const </span>
00355 <span class="keyword"></span>{ 
00356     <span class="keywordflow">return</span> d_pageSize; 
00357 }
00358 
<a name="l00360"></a><a class="code" href="class_qwt_dbl_range.html#a6">00360</a> <span class="keywordtype">double</span> <a class="code" href="class_qwt_dbl_range.html#a6">QwtDblRange::value</a>()<span class="keyword"> const </span>
00361 <span class="keyword"></span>{ 
00362     <span class="keywordflow">return</span> d_value; 
00363 }
00364 
<a name="l00374"></a><a class="code" href="class_qwt_dbl_range.html#b0">00374</a> <span class="keywordtype">double</span> <a class="code" href="class_qwt_dbl_range.html#b0">QwtDblRange::exactValue</a>()<span class="keyword"> const </span>
00375 <span class="keyword"></span>{ 
00376     <span class="keywordflow">return</span> d_exactValue; 
00377 }
00378 
<a name="l00380"></a><a class="code" href="class_qwt_dbl_range.html#b1">00380</a> <span class="keywordtype">double</span> <a class="code" href="class_qwt_dbl_range.html#b1">QwtDblRange::exactPrevValue</a>()<span class="keyword"> const </span>
00381 <span class="keyword"></span>{ 
00382     <span class="keywordflow">return</span> d_exactPrevValue; 
00383 }
00384 
<a name="l00386"></a><a class="code" href="class_qwt_dbl_range.html#b2">00386</a> <span class="keywordtype">double</span> <a class="code" href="class_qwt_dbl_range.html#b2">QwtDblRange::prevValue</a>()<span class="keyword"> const </span>
00387 <span class="keyword"></span>{ 
00388     <span class="keywordflow">return</span> d_prevValue; 
00389 }
</div></pre><hr size="1"><address style="align: right;"><small>Generated on Tue Nov 16 21:12:20 2004 for Qwt User's Guide by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.8 </small></address>
</body>
</html>