Blame view

build4/epsilon-master/apps/regression/graph_options_controller.cpp 4.06 KB
6663b6c9   adorian   projet complet av...
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
  #include "graph_options_controller.h"
  #include "app.h"
  #include "graph_controller.h"
  #include "regression_controller.h"
  #include <apps/apps_container.h>
  #include <assert.h>
  
  using namespace Shared;
  
  namespace Regression {
  
  GraphOptionsController::GraphOptionsController(Responder * parentResponder, Store * store, CurveViewCursor * cursor, GraphController * graphController) :
    ViewController(parentResponder),
    m_changeRegressionCell(I18n::Message::Regression),
    m_selectableTableView(this),
    m_goToParameterController(this, store, cursor, graphController),
    m_store(store),
    m_graphController(graphController)
  {
    static_cast<ExpressionView *>(m_changeRegressionCell.subAccessoryView())->setHorizontalMargin(Metric::ExpressionViewHorizontalMargin);
  }
  
  const char * GraphOptionsController::title() {
    return I18n::translate(I18n::Message::RegressionCurve);
  }
  
  View * GraphOptionsController::view() {
    return &m_selectableTableView;
  }
  
  void GraphOptionsController::didBecomeFirstResponder() {
    if (selectedRow() < 0) {
      selectCellAtLocation(0, 0);
    }
    app()->setFirstResponder(&m_selectableTableView);
  }
  
  void GraphOptionsController::viewWillAppear() {
    m_selectableTableView.reloadData();
  }
  
  bool GraphOptionsController::handleEvent(Ion::Events::Event event) {
    if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) {
      if (selectedRow() == numberOfRows() -1) {
        RegressionController * regressionController = static_cast<Regression::App *>(app())->regressionController();
        regressionController->setSeries(m_graphController->selectedSeriesIndex());
        StackViewController * stack = static_cast<StackViewController *>(parentResponder());
        stack->push(regressionController);
      } else {
        m_goToParameterController.setXPrediction(selectedRow() == 0);
        StackViewController * stack = (StackViewController *)parentResponder();
        stack->push(&m_goToParameterController);
      }
      return true;
    }
    return false;
  }
  
  int GraphOptionsController::numberOfRows() {
    return k_numberOfParameterCells + 1;
  }
  
  KDCoordinate GraphOptionsController::rowHeight(int j) {
    if ((j == numberOfRows() - 1) &&
        (static_cast<Store *>(m_store)->seriesRegressionType(m_graphController->selectedSeriesIndex()) == Model::Type::Logistic))
    {
      return RegressionController::k_logisticCellHeight;
    }
    return Metric::ParameterCellHeight;
  }
  
  KDCoordinate GraphOptionsController::cumulatedHeightFromIndex(int j) {
    assert (j >= 0 && j <= numberOfRows());
    KDCoordinate result = 0;
    for (int i = 0; i < j; i++) {
      result+= rowHeight(i);
    }
    return result;
  }
  
  int GraphOptionsController::indexFromCumulatedHeight(KDCoordinate offsetY) {
    int result = 0;
    int j = 0;
    int numberRows = numberOfRows();
    while (result < offsetY && j < numberRows) {
      result += rowHeight(j++);
    }
    return (result < offsetY || offsetY == 0) ? j : j - 1;
  }
  
  HighlightCell * GraphOptionsController::reusableCell(int index, int type) {
    assert(index >= 0);
    assert(index < reusableCellCount(type));
    if (type == k_regressionCellType) {
      return &m_changeRegressionCell;
    }
    assert(type == k_parameterCelltype);
    return &m_parameterCells[index];
  }
  
  int GraphOptionsController::reusableCellCount(int type) {
    if (type == k_regressionCellType) {
      return 1;
    }
    assert(type == k_parameterCelltype);
    return k_numberOfParameterCells;
  }
  
  int GraphOptionsController::typeAtLocation(int i, int j) {
    assert(i == 0);
    if (j == numberOfRows() -1) {
      return k_regressionCellType;
    }
    return k_parameterCelltype;
  }
  
  void GraphOptionsController::willDisplayCellForIndex(HighlightCell * cell, int index) {
    if (index == numberOfRows() - 1) {
      m_changeRegressionCell.setExpressionLayout(static_cast<Store *>(m_store)->modelForSeries(m_graphController->selectedSeriesIndex())->layout());
      return;
    }
    assert(index >=0 && index < k_numberOfParameterCells);
    MessageTableCellWithChevron * myCell = (MessageTableCellWithChevron *)cell;
    I18n::Message titles[k_numberOfParameterCells] = {I18n::Message::XPrediction, I18n::Message::YPrediction};
    myCell->setMessage(titles[index]);
  }
  
  }