Models.C 5.4 KB

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