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
|
#include "Models.h"
#include "Wt/WColor"
SombreroData::SombreroData(int nbXPts, int nbYPts,
double xStart, double xEnd,
double yStart, double yEnd,
WObject *parent)
: WAbstractTableModel(parent),
nbXPts_(nbXPts), nbYPts_(nbYPts),
xStart_(xStart), xEnd_(xEnd), yStart_(yStart), yEnd_(yEnd)
{}
int SombreroData::rowCount(const Wt::WModelIndex& parent) const
{
return nbXPts_+1;
}
int SombreroData::columnCount(const Wt::WModelIndex& parent) const
{
return nbYPts_+1;
}
boost::any SombreroData::data(int row, int column, int role,
const WModelIndex &parent) const
{
return data(createIndex(row, column, (void*)0), role);
}
boost::any SombreroData::data(const Wt::WModelIndex& index,
int role) const
{
double delta_y = (yEnd_ - yStart_)/(nbYPts_-1);
if (index.row() == 0) { // give back y-abscis
if (index.column() == 0)
return 0.0;
return yStart_ + (index.column()-1)*delta_y;
}
double delta_x = (xEnd_ - xStart_)/(nbXPts_-1);
if (index.column() == 0) { // give back x-abscis
if (index.row() == 0)
return 0.0;
return xStart_ + (index.row()-1)*delta_x;
}
double x, y;
y = yStart_ + (index.column()-1)*delta_y;
x = xStart_ + (index.row()-1)*delta_x;
if (role == MarkerBrushColorRole) {
return boost::any();
} else if (role == DisplayRole) {
return 4*sin(sqrt(pow(x,2) + pow(y,2))) / (sqrt (pow(x,2) + pow(y,2)));
} else {
return boost::any();
}
}
boost::any SombreroData::headerData(int section,
Wt::Orientation orientation,
int role) const
{
return 0.0; // unimplemented
}
PlaneData::PlaneData(int nbXPts, int nbYPts,
double xStart, double xDelta,
double yStart, double yDelta,
bool Yvariation,
double colorRoleBound, double sizeRoleBound,
WObject *parent)
: WAbstractTableModel(parent),
nbXPts_(nbXPts), nbYPts_(nbYPts),
xStart_(xStart), xDelta_(xDelta), yStart_(yStart), yDelta_(yDelta),
yVar_(Yvariation),
colorRoleBound_(colorRoleBound), sizeRoleBound_(sizeRoleBound)
{}
int PlaneData::rowCount(const Wt::WModelIndex& parent) const
{
return nbXPts_;
}
int PlaneData::columnCount(const Wt::WModelIndex& parent) const
{
return nbYPts_;
}
boost::any PlaneData::data(int row, int column, int role,
const WModelIndex &parent) const
{
return data(createIndex(row, column, (void*)0), role);
}
boost::any PlaneData::data(const Wt::WModelIndex& index,
int role) const
{
double x, y, value;
y = yStart_ + index.column() * yDelta_;
x = xStart_ + index.row() * xDelta_;
if (yVar_)
value = 0.5*y;
else
value = 0.5*x;
if (role == DisplayRole) {
return value;
} else if (role == MarkerBrushColorRole) {
if (value > colorRoleBound_)
return WColor(blue);
else
return boost::any();
} else if (role == MarkerScaleFactorRole) {
if (value > sizeRoleBound_)
return 5;
else
return boost::any();
} else {
return boost::any();
}
}
boost::any PlaneData::headerData(int section,
Wt::Orientation orientation,
int role) const
{
return 0.0; // unimplemented
}
PointsData::PointsData(int nbPts, WObject *parent)
: nbPts_(nbPts)
{}
int PointsData::rowCount(const Wt::WModelIndex& parent) const
{
return nbPts_;
}
int PointsData::columnCount(const Wt::WModelIndex& parent) const
{
return 3;
}
boost::any PointsData::data(int row, int column, int role,
const WModelIndex &parent) const
{
return data(createIndex(row, column, (void*)0), role);
}
boost::any PointsData::data(const Wt::WModelIndex& index,
int role) const
{
if (role != DisplayRole) {
return boost::any();
}
const double pi = 3.141592;
double XYangle = index.row() * (8*pi/nbPts_);
if (index.column() == 0) {
return cos(XYangle);
}
if (index.column() == 1) {
return sin(XYangle);
}
if (index.column() == 2) {
return -5.0 + index.row() * (10.0/nbPts_);
}
return boost::any();
}
boost::any PointsData::headerData(int section,
Wt::Orientation orientation,
int role) const
{
return 0.0; // unimplemented
}
Parabola::Parabola(double xMin, double deltaX, double yMin, double deltaY,
double factor, double minimum, bool withColorRoles,
double colorRoleBoundary, WObject *parent)
: xMin_(xMin), deltaX_(deltaX), yMin_(yMin), deltaY_(deltaY),
factor_(factor), minimum_(minimum), colorRoles_(withColorRoles),
colorRoleBoundary_(colorRoleBoundary)
{
}
int Parabola::rowCount(const Wt::WModelIndex& parent) const
{
return 41;
}
int Parabola::columnCount(const Wt::WModelIndex& parent) const
{
return 41;
}
boost::any Parabola::data(int row, int column, int role,
const WModelIndex &parent) const
{
return data(createIndex(row, column, (void*)0), role);
}
boost::any Parabola::data(const Wt::WModelIndex& index,
int role) const
{
// double value = factor_ * (xMin_+index.row()*deltaX_)*(yMin_+index.column()*deltaY_);
double value = factor_ * ( (xMin_+index.row()*deltaX_)*(xMin_+index.row()*deltaX_) + (yMin_+index.column()*deltaY_)*(yMin_+index.column()*deltaY_) ) + minimum_;
if (role == MarkerBrushColorRole) {
if (!colorRoles_)
return boost::any();
else
return value > colorRoleBoundary_ ? boost::any() : WColor(blue);
} else if (role != DisplayRole) {
return boost::any();
} else {
return value;
}
}
boost::any Parabola::headerData(int section,
Wt::Orientation orientation,
int role) const
{
return 0.0; // unimplemented
}
|