1 #include "Models.h"
2
3 #include "Wt/WColor.h"
4 #include <cmath>
5
SombreroData(int nbXPts,int nbYPts,double xStart,double xEnd,double yStart,double yEnd)6 SombreroData::SombreroData(int nbXPts, int nbYPts,
7 double xStart, double xEnd,
8 double yStart, double yEnd)
9 : WAbstractTableModel(),
10 nbXPts_(nbXPts), nbYPts_(nbYPts),
11 xStart_(xStart), xEnd_(xEnd), yStart_(yStart), yEnd_(yEnd)
12 {}
13
rowCount(const Wt::WModelIndex &)14 int SombreroData::rowCount(const Wt::WModelIndex&) const
15 {
16 return nbXPts_+1;
17 }
18
columnCount(const Wt::WModelIndex &)19 int SombreroData::columnCount(const Wt::WModelIndex&) const
20 {
21 return nbYPts_+1;
22 }
23
data(int row,int column,Wt::ItemDataRole role,const Wt::WModelIndex & parent)24 Wt::cpp17::any SombreroData::data(int row, int column, Wt::ItemDataRole role,
25 const Wt::WModelIndex &parent) const
26 {
27 return data(createIndex(row, column, (void*)0), role);
28 }
29
data(const Wt::WModelIndex & index,Wt::ItemDataRole role)30 Wt::cpp17::any SombreroData::data(const Wt::WModelIndex& index,
31 Wt::ItemDataRole role) const
32 {
33 double delta_y = (yEnd_ - yStart_)/(nbYPts_-1);
34 if (index.row() == 0) { // give back y-abscis
35 if (index.column() == 0)
36 return 0.0;
37 return yStart_ + (index.column()-1)*delta_y;
38 }
39
40 double delta_x = (xEnd_ - xStart_)/(nbXPts_-1);
41 if (index.column() == 0) { // give back x-abscis
42 if (index.row() == 0)
43 return 0.0;
44 return xStart_ + (index.row()-1)*delta_x;
45 }
46
47 double x, y;
48 y = yStart_ + (index.column()-1)*delta_y;
49 x = xStart_ + (index.row()-1)*delta_x;
50
51 if (role == Wt::ItemDataRole::MarkerBrushColor) {
52 return Wt::cpp17::any();
53 } else if (role == Wt::ItemDataRole::Display) {
54 return 4*sin(sqrt(pow(x,2) + pow(y,2))) / (sqrt (pow(x,2) + pow(y,2)));
55 } else {
56 return Wt::cpp17::any();
57 }
58 }
59
headerData(int section,Wt::Orientation orientation,Wt::ItemDataRole role)60 Wt::cpp17::any SombreroData::headerData(int section,
61 Wt::Orientation orientation,
62 Wt::ItemDataRole role) const
63 {
64 return 0.0; // unimplemented
65 }
66
PlaneData(int nbXPts,int nbYPts,double xStart,double xDelta,double yStart,double yDelta,bool Yvariation,double colorRoleBound,double sizeRoleBound)67 PlaneData::PlaneData(int nbXPts, int nbYPts,
68 double xStart, double xDelta,
69 double yStart, double yDelta,
70 bool Yvariation,
71 double colorRoleBound, double sizeRoleBound)
72 : WAbstractTableModel(),
73 nbXPts_(nbXPts), nbYPts_(nbYPts),
74 xStart_(xStart), xDelta_(xDelta), yStart_(yStart), yDelta_(yDelta),
75 yVar_(Yvariation),
76 colorRoleBound_(colorRoleBound), sizeRoleBound_(sizeRoleBound)
77 {}
78
rowCount(const Wt::WModelIndex & parent)79 int PlaneData::rowCount(const Wt::WModelIndex& parent) const
80 {
81 return nbXPts_;
82 }
83
columnCount(const Wt::WModelIndex & parent)84 int PlaneData::columnCount(const Wt::WModelIndex& parent) const
85 {
86 return nbYPts_;
87 }
88
data(int row,int column,Wt::ItemDataRole role,const Wt::WModelIndex & parent)89 Wt::cpp17::any PlaneData::data(int row, int column, Wt::ItemDataRole role,
90 const Wt::WModelIndex &parent) const
91 {
92 return data(createIndex(row, column, (void*)0), role);
93 }
94
data(const Wt::WModelIndex & index,Wt::ItemDataRole role)95 Wt::cpp17::any PlaneData::data(const Wt::WModelIndex& index,
96 Wt::ItemDataRole role) const
97 {
98
99
100 double x, y, value;
101 y = yStart_ + index.column() * yDelta_;
102 x = xStart_ + index.row() * xDelta_;
103 if (yVar_)
104 value = 0.5*y;
105 else
106 value = 0.5*x;
107
108 if (role == Wt::ItemDataRole::Display) {
109 return value;
110 } else if (role == Wt::ItemDataRole::MarkerBrushColor) {
111 if (value > colorRoleBound_)
112 return Wt::WColor(Wt::StandardColor::Blue);
113 else
114 return Wt::cpp17::any();
115 } else if (role == Wt::ItemDataRole::MarkerScaleFactor) {
116 if (value > sizeRoleBound_)
117 return 5;
118 else
119 return Wt::cpp17::any();
120 } else {
121 return Wt::cpp17::any();
122 }
123 }
124
headerData(int section,Wt::Orientation orientation,Wt::ItemDataRole role)125 Wt::cpp17::any PlaneData::headerData(int section,
126 Wt::Orientation orientation,
127 Wt::ItemDataRole role) const
128 {
129 return 0.0; // unimplemented
130 }
131
PointsData(int nbPts)132 PointsData::PointsData(int nbPts)
133 : nbPts_(nbPts)
134 {}
135
rowCount(const Wt::WModelIndex & parent)136 int PointsData::rowCount(const Wt::WModelIndex& parent) const
137 {
138 return nbPts_;
139 }
140
columnCount(const Wt::WModelIndex & parent)141 int PointsData::columnCount(const Wt::WModelIndex& parent) const
142 {
143 return 3;
144 }
145
data(int row,int column,Wt::ItemDataRole role,const Wt::WModelIndex & parent)146 Wt::cpp17::any PointsData::data(int row, int column, Wt::ItemDataRole role,
147 const Wt::WModelIndex &parent) const
148 {
149 return data(createIndex(row, column, (void*)0), role);
150 }
151
data(const Wt::WModelIndex & index,Wt::ItemDataRole role)152 Wt::cpp17::any PointsData::data(const Wt::WModelIndex& index,
153 Wt::ItemDataRole role) const
154 {
155 if (role != Wt::ItemDataRole::Display) {
156 return Wt::cpp17::any();
157 }
158
159
160 const double pi = 3.141592;
161 double XYangle = index.row() * (8*pi/nbPts_);
162 if (index.column() == 0) {
163 return cos(XYangle);
164 }
165 if (index.column() == 1) {
166 return sin(XYangle);
167 }
168 if (index.column() == 2) {
169 return -5.0 + index.row() * (10.0/nbPts_);
170 }
171 return Wt::cpp17::any();
172 }
173
headerData(int section,Wt::Orientation orientation,Wt::ItemDataRole role)174 Wt::cpp17::any PointsData::headerData(int section,
175 Wt::Orientation orientation,
176 Wt::ItemDataRole role) const
177 {
178 return 0.0; // unimplemented
179 }
180
181
Parabola(double xMin,double deltaX,double yMin,double deltaY,double factor,double minimum,bool withColorRoles,double colorRoleBoundary)182 Parabola::Parabola(double xMin, double deltaX, double yMin, double deltaY,
183 double factor, double minimum, bool withColorRoles,
184 double colorRoleBoundary)
185 : xMin_(xMin), deltaX_(deltaX), yMin_(yMin), deltaY_(deltaY),
186 factor_(factor), minimum_(minimum), colorRoles_(withColorRoles),
187 colorRoleBoundary_(colorRoleBoundary)
188 {
189 }
190
rowCount(const Wt::WModelIndex & parent)191 int Parabola::rowCount(const Wt::WModelIndex& parent) const
192 {
193 return 41;
194 }
195
columnCount(const Wt::WModelIndex & parent)196 int Parabola::columnCount(const Wt::WModelIndex& parent) const
197 {
198 return 41;
199 }
200
data(int row,int column,Wt::ItemDataRole role,const Wt::WModelIndex & parent)201 Wt::cpp17::any Parabola::data(int row, int column, Wt::ItemDataRole role,
202 const Wt::WModelIndex &parent) const
203 {
204 return data(createIndex(row, column, (void*)0), role);
205 }
206
data(const Wt::WModelIndex & index,Wt::ItemDataRole role)207 Wt::cpp17::any Parabola::data(const Wt::WModelIndex& index,
208 Wt::ItemDataRole role) const
209 {
210 // double value = factor_ * (xMin_+index.row()*deltaX_)*(yMin_+index.column()*deltaY_);
211 double value = factor_ * ( (xMin_+index.row()*deltaX_)*(xMin_+index.row()*deltaX_) + (yMin_+index.column()*deltaY_)*(yMin_+index.column()*deltaY_) ) + minimum_;
212
213 if (role == Wt::ItemDataRole::MarkerBrushColor) {
214 if (!colorRoles_)
215 return Wt::cpp17::any();
216 else
217 return value > colorRoleBoundary_ ? Wt::cpp17::any() : Wt::WColor(Wt::StandardColor::Blue);
218 } else if (role != Wt::ItemDataRole::Display) {
219 return Wt::cpp17::any();
220 } else {
221 return value;
222 }
223 }
224
headerData(int section,Wt::Orientation orientation,Wt::ItemDataRole role)225 Wt::cpp17::any Parabola::headerData(int section,
226 Wt::Orientation orientation,
227 Wt::ItemDataRole role) const
228 {
229 return 0.0; // unimplemented
230 }
231