Blame view

build2/epsilon-master/apps/solver/interval_controller.cpp 4.29 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
129
130
131
132
  #include "interval_controller.h"
  #include "app.h"
  #include "../i18n.h"
  #include <assert.h>
  #include <string.h>
  
  namespace Solver {
  
  IntervalController::ContentView::ContentView(SelectableTableView * selectableTableView) :
    m_instructions0(KDText::FontSize::Small, I18n::Message::ApproximateSolutionIntervalInstruction0, 0.5f, 0.5f, KDColorBlack, Palette::WallScreen),
    m_instructions1(KDText::FontSize::Small, I18n::Message::ApproximateSolutionIntervalInstruction1, 0.5f, 0.5f, KDColorBlack, Palette::WallScreen),
    m_selectableTableView(selectableTableView)
  {
  }
  
  void IntervalController::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
    ctx->fillRect(KDRect(0, 0, bounds().width(), k_topMargin), Palette::WallScreen);
  }
  
  int IntervalController::ContentView::numberOfSubviews() const {
    return 3;
  }
  
  View * IntervalController::ContentView::subviewAtIndex(int index) {
    assert(index >= 0 && index < 5);
    if (index == 0) {
      return &m_instructions0;
    }
    if (index == 1) {
      return &m_instructions1;
    }
    return m_selectableTableView;
  }
  
  void IntervalController::ContentView::layoutSubviews() {
    KDCoordinate textHeight = KDText::charSize(KDText::FontSize::Small).height();
    m_instructions0.setFrame(KDRect(0, k_topMargin/2-textHeight, bounds().width(), textHeight));
    m_instructions1.setFrame(KDRect(0, k_topMargin/2, bounds().width(), textHeight));
    m_selectableTableView->setFrame(KDRect(0, k_topMargin, bounds().width(),  bounds().height()-k_topMargin));
  }
  
  /* IntervalController Controller */
  
  IntervalController::IntervalController(Responder * parentResponder, EquationStore * equationStore) :
    FloatParameterController(parentResponder),
    m_selectableTableView(nullptr),
    m_intervalCell{},
    m_equationStore(equationStore)
  {
  }
  
  const char * IntervalController::title() {
    return I18n::translate(I18n::Message::SearchInverval);
  }
  
  int IntervalController::numberOfRows() {
    return k_maxNumberOfCells+1;
  }
  
  void IntervalController::willDisplayCellForIndex(HighlightCell * cell, int index) {
    if (index == numberOfRows()-1) {
      return;
    }
    I18n::Message labels[k_maxNumberOfCells] = {I18n::Message::XMin, I18n::Message::XMax};
    MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *) cell;
    myCell->setMessage(labels[index]);
    FloatParameterController::willDisplayCellForIndex(cell, index);
  }
  
  HighlightCell * IntervalController::reusableParameterCell(int index, int type) {
    assert(index >= 0);
    assert(index < 2);
    return m_intervalCell[index];
  }
  
  int IntervalController::reusableParameterCellCount(int type) {
    return k_maxNumberOfCells;
  }
  
  double IntervalController::parameterAtIndex(int index) {
    return m_equationStore->intervalBound(index);
  }
  
  bool IntervalController::setParameterAtIndex(int parameterIndex, double f) {
    m_equationStore->setIntervalBound(parameterIndex, f);
    return true;
  }
  
  bool IntervalController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
    if (FloatParameterController::textFieldDidFinishEditing(textField, text, event)) {
      m_selectableTableView->reloadData();
      return true;
    }
    return false;
  }
  
  void IntervalController::buttonAction() {
    StackViewController * stack = stackController();
    App * solverApp = static_cast<App *>(app());
    m_equationStore->approximateSolve(solverApp->localContext());
    stack->push(solverApp->solutionsControllerStack(), KDColorWhite, Palette::SubTab, Palette::SubTab);
  }
  
  I18n::Message IntervalController::okButtonText() {
    return I18n::Message::ResolveEquation;
  }
  
  View * IntervalController::loadView() {
    m_selectableTableView = (SelectableTableView *)FloatParameterController::loadView();
    m_selectableTableView->setTopMargin(0);
    for (int i = 0; i < k_maxNumberOfCells; i++) {
      m_intervalCell[i] = new MessageTableCellWithEditableText(m_selectableTableView, this, m_draftTextBuffer);
    }
    ContentView * contentView = (ContentView *)new ContentView(m_selectableTableView);
    return contentView;
  }
  
  void IntervalController::unloadView(View * view) {
    delete m_selectableTableView;
    m_selectableTableView = nullptr;
    for (int i = 0; i < k_maxNumberOfCells; i++) {
      delete m_intervalCell[i];
      m_intervalCell[i] = nullptr;
    }
    FloatParameterController::unloadView(view);
  }
  
  SelectableTableView * IntervalController::selectableTableView() {
    return m_selectableTableView;
  }
  
  }