COPASI API  4.16.103
qwt3dScale.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/barChart/qwt3dScale.cpp,v $
3 // $Revision: 1.5 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:24:50 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 #include "qwt3dScale.h"
24 //#include <iostream>
25 using namespace Qwt3D;
26 
27 int LinearAutoScaler2::execute2(double& a, double& b, double start, double stop, int ivals)
28 {
29 
30  return execute(a, b, start, stop, ivals);
31 }
32 
33 //! Applies LinearAutoScaler::execute()
34 int ValueScale::autoscale(double& a, double& b, double start, double stop, int ivals)
35 {
36  return autoscaler_p2.execute2(a, b, start, stop, ivals);
37 }
38 
39 //! Creates the major and minor vector for the scale
41 {
42  int i;
43  int j;
44  majors_p.clear();
45  minors_p.clear();
46 
47  double interval = mstop_p - mstart_p;
48 
49  double runningval;
50 
51  // majors
52 
53  // first tic
54  if (mstart_p < start_p || mstop_p > stop_p)
55  return;
56 
57  majors_p.push_back(mstart_p);
58 
59  // remaining tics
60  for (i = 1; i <= majorintervals_p; ++i)
61  {
62  double t = double(i) / majorintervals_p;
63  runningval = mstart_p + t * interval;
64 
65  if (runningval > stop_p)
66  break;
67 
68  if (isPracticallyZero(mstart_p, -t*interval)) // prevent rounding errors near 0
69  runningval = 0.0;
70 
71  majors_p.push_back(runningval);
72  }
73 
74  majorintervals_p = (int) majors_p.size();
75 
76  if (majorintervals_p)
77  --majorintervals_p;
78 
79  // minors
80  if (!majorintervals_p || !minorintervals_p) // no valid interval
81  {
82  minorintervals_p = 0;
83  return;
84  }
85 
86  // start_p mstart_p
87  // |_____________|_____ _ _ _
88 
89  double step = (majors_p[1] - majors_p[0]) / minorintervals_p;
90 
91  if (isPracticallyZero(step))
92  return;
93 
94  runningval = mstart_p - step;
95 
96  while (runningval > start_p)
97  {
98  minors_p.push_back(runningval);
99  runningval -= step;
100  }
101 
102  // mstart_p mstop_p
103  // ________|_____ _ _ _ _ _ ___|__________
104 
105  for (i = 0; i != majorintervals_p; ++i)
106  {
107  runningval = majors_p[i] + step;
108 
109  for (j = 0; j != minorintervals_p; ++j)
110  {
111  minors_p.push_back(runningval);
112  runningval += step;
113  }
114  }
115 
116  // mstop_p stop_p
117  // _ _ _|_____________|
118 
119  runningval = mstop_p + step;
120 
121  while (runningval < stop_p)
122  {
123  minors_p.push_back(runningval);
124  runningval += step;
125  }
126 }
127 
128 QString ValueScale::ticLabel(unsigned int idx) const
129 {
130  if (idx < majors_p.size())
131  {
132  return QString::number(majors_p[idx]);
133  }
134 
135  return QString("");
136 }
137 
138 RowScale::RowScale(const std::vector<std::string> * vos, int showRow)
139  : ValueScale(),
140  mpRowsDes(vos),
141  showRow(showRow)
142 {}
143 
144 QString RowScale::ticLabel(unsigned int idx) const
145 {
146  if (!mpRowsDes) return QString("");
147 
148  if ((mpRowsDes->size() - 1) < idx) return QString("");
149 
150  if (showRow == (unsigned int) - 1)
151  {
152  std::string a;
153  a = (*mpRowsDes)[idx];
154  return (QString(a.c_str()));
155  }
156  else
157  {
158  if (showRow == idx)
159  {
160  std::string a;
161  a = (*mpRowsDes)[idx];
162  return (QString(a.c_str()));
163  }
164  else
165  {
166  return QString("");
167  }
168  }
169 }
170 
171 ColumnScale::ColumnScale(const std::vector<std::string> * vos, int showColumn)
172  : ValueScale(),
173  mpColumnsDes(vos),
174  showColumn(showColumn)
175 {}
176 
177 QString ColumnScale::ticLabel(unsigned int idx) const
178 {
179  if (!mpColumnsDes) return QString("");
180 
181  if ((mpColumnsDes->size() - 1) < idx) return QString("");
182 
183  if (showColumn == (unsigned int) - 1)
184  {
185  std::string a;
186  a = (*mpColumnsDes)[idx];
187  return (QString(a.c_str()));
188  }
189  else
190  {
191  if (showColumn == idx)
192  {
193  std::string a;
194  a = (*mpColumnsDes)[idx];
195  return (QString(a.c_str()));
196  }
197  else
198  {
199  return QString("");
200  }
201  }
202 }
ColumnScale(const std::vector< std::string > *vos, int showColumn=-1)
Definition: qwt3dScale.cpp:171
int execute2(double &a, double &b, double start, double stop, int ivals)
Definition: qwt3dScale.cpp:27
unsigned int showColumn
Definition: qwt3dScale.h:57
void calculate()
Creates the major and minor vector for the scale.
Definition: qwt3dScale.cpp:40
virtual QString ticLabel(unsigned int idx) const
Definition: qwt3dScale.cpp:177
The standard (1:1) mapping class for axis numbering.
Definition: qwt3dScale.h:33
QString ticLabel(unsigned int idx) const
Definition: qwt3dScale.cpp:144
int autoscale(double &a, double &b, double start, double stop, int ivals)
Applies LinearAutoScaler::execute()
Definition: qwt3dScale.cpp:34
RowScale(const std::vector< std::string > *vos, int showRow=-1)
Definition: qwt3dScale.cpp:138
const std::vector< std::string > * mpRowsDes
Definition: qwt3dScale.h:69
const std::vector< std::string > * mpColumnsDes
Definition: qwt3dScale.h:56
unsigned int showRow
Definition: qwt3dScale.h:70
QString ticLabel(unsigned int idx) const
Definition: qwt3dScale.cpp:128