Blame view

build4/epsilon-master/apps/sequence/values/values_controller.cpp 3.14 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
  #include "values_controller.h"
  #include <assert.h>
  #include <cmath>
  
  using namespace Shared;
  
  namespace Sequence {
  
  ValuesController::ValuesController(Responder * parentResponder, SequenceStore * sequenceStore, Interval * interval, ButtonRowController * header) :
    Shared::ValuesController(parentResponder, header, I18n::Message::NColumn, &m_intervalParameterController, interval),
    m_sequenceTitleCells{},
    m_floatCells{},
    m_sequenceStore(sequenceStore),
  #if COPY_COLUMN
    m_sequenceParameterController('n'),
  #endif
    m_intervalParameterController(this, m_interval)
  {
  }
  
  void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
    Shared::ValuesController::willDisplayCellAtLocation(cell, i, j);
    // The cell is the abscissa title cell:
    if (j == 0 && i == 0) {
      EvenOddMessageTextCell * mytitleCell = (EvenOddMessageTextCell *)cell;
      mytitleCell->setMessage(I18n::Message::N);
      return;
    }
    // The cell is a function title cell:
    if (j == 0 && i > 0) {
      SequenceTitleCell * myCell = (SequenceTitleCell *)cell;
      Sequence * sequence = m_sequenceStore->activeFunctionAtIndex(i-1);
      myCell->setExpressionLayout(sequence->nameLayout());
      myCell->setColor(sequence->color());
    }
  }
  
  I18n::Message ValuesController::emptyMessage() {
    if (m_sequenceStore->numberOfDefinedModels() == 0) {
      return I18n::Message::NoSequence;
    }
    return I18n::Message::NoActivatedSequence;
  }
  
  IntervalParameterController * ValuesController::intervalParameterController() {
    return &m_intervalParameterController;
  }
  
  bool ValuesController::setDataAtLocation(double floatBody, int columnIndex, int rowIndex) {
    if (floatBody < 0) {
        return false;
    }
    return Shared::ValuesController::setDataAtLocation(std::round(floatBody), columnIndex, rowIndex);
  }
  
  int ValuesController::maxNumberOfCells() {
    return k_maxNumberOfCells;
  }
  
  int ValuesController::maxNumberOfFunctions() {
    return k_maxNumberOfSequences;
  }
  
  SequenceTitleCell * ValuesController::functionTitleCells(int j) {
    assert(j >= 0 && j < k_maxNumberOfSequences);
    return m_sequenceTitleCells[j];
  }
  
  EvenOddBufferTextCell * ValuesController::floatCells(int j) {
    assert(j >= 0 && j < k_maxNumberOfCells);
    return m_floatCells[j];
  }
  
  SequenceStore * ValuesController::functionStore() const {
    return m_sequenceStore;
  }
  
  Shared::ValuesFunctionParameterController * ValuesController::functionParameterController() {
  #if COPY_COLUMN
    return &m_sequenceParameterController;
  #else
    return nullptr;
  #endif
  }
  
  View * ValuesController::loadView() {
    for (int i = 0; i < k_maxNumberOfSequences; i++) {
      m_sequenceTitleCells[i] = new SequenceTitleCell(FunctionTitleCell::Orientation::HorizontalIndicator);
    }
    for (int i = 0; i < k_maxNumberOfCells; i++) {
      m_floatCells[i] = new EvenOddBufferTextCell();
    }
    return Shared::ValuesController::loadView();
  }
  
  void ValuesController::unloadView(View * view) {
    for (int i = 0; i < k_maxNumberOfCells; i++) {
      delete m_floatCells[i];
      m_floatCells[i] = nullptr;
    }
    for (int i = 0; i < k_maxNumberOfSequences; i++) {
      delete m_sequenceTitleCells[i];
      m_sequenceTitleCells[i] = nullptr;
    }
    Shared::ValuesController::unloadView(view);
  }
  
  }