Blame view

app/gui/oven_control/multicookcontainer.cpp 2.93 KB
2f6b55128   김태훈   다중 요리 구현
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
  #include "multicookcontainer.h"
  
  MultiCookContainer::MultiCookContainer(QObject *parent) : QObject(parent)
  {
      for (int i = 0; i < 10; i++)
          list.append(Q_NULLPTR);
  
      isEmpty_ = true;
      state = Idle;
  }
  
  void MultiCookContainer::add(int slot, MultiCook *cook)
  {
      list.replace(slot, cook);
      if (isEmpty_)
      {
          mode_ = cook->mode();
          isEmpty_ = false;
      }
  
      switch (state)
      {
      case Idle:
          // Do nothing
          break;
      case Running:
          cook->start();
          break;
      case Paused:
          cook->start();
          cook->pause();
          break;
      }
  }
  
  void MultiCookContainer::remove(int slot)
  {
      MultiCook *cook = list.at(slot);
      if (cook == Q_NULLPTR)
          return;
  
      cook->stop();
  
      list.replace(slot, Q_NULLPTR);
  
      isEmpty_ = true;
      foreach (MultiCook *c, list)
          if (c != Q_NULLPTR)
          {
              isEmpty_ = false;
              break;
          }
  
      if (isEmpty_)
      {
          mode_ = Define::InvalidMode;
          state = Idle;
      }
  }
  
  MultiCook *MultiCookContainer::at(int slot)
  {
      return list.at(slot);
  }
  
  bool MultiCookContainer::isEmpty()
  {
      return isEmpty_;
  }
  
  bool MultiCookContainer::isFinished()
  {
      foreach (MultiCook *c, list)
          if (c != Q_NULLPTR && c->remainingTime() > 0)
              return false;
  
      return true;
  }
  
  Define::Mode MultiCookContainer::mode()
  {
      return mode_;
  }
  
  int MultiCookContainer::temperature()
  {
      int count = 0;
      int temp = 0;
      foreach (MultiCook *c, list)
          if (c != Q_NULLPTR && c->remainingTime() > 0)
          {
              temp += c->temperature();
              count++;
          }
  
      if (count == 0)
          return -1;
  
      return temp / count;
  }
  
  int MultiCookContainer::humidity()
  {
      int count = 0;
      int hum = 0;
      foreach (MultiCook *c, list)
          if (c != Q_NULLPTR && c->remainingTime() > 0)
          {
              hum += c->humidity();
              count++;
          }
  
      if (count == 0)
          return -1;
  
      return hum / count;
  }
  
  int MultiCookContainer::remainingTime()
  {
      int max = 0;
      foreach (MultiCook *c, list)
          if (c != Q_NULLPTR)
              max = qMax(max, c->remainingTime());
  
      return max;
  }
  
  void MultiCookContainer::start()
  {
      if (isEmpty_ || state != Idle)
          return;
  
      state = Running;
  
      foreach (MultiCook *c, list)
          if (c != Q_NULLPTR)
              c->start();
  }
  
  void MultiCookContainer::stop()
  {
      if (isEmpty_ || state != Running)
          return;
  
      state = Idle;
  
      foreach (MultiCook *c, list)
          if (c != Q_NULLPTR)
              c->stop();
  }
  
  void MultiCookContainer::pause()
  {
      if (isEmpty_ || state != Running)
          return;
  
      state = Paused;
  
      foreach (MultiCook *c, list)
          if (c != Q_NULLPTR)
              c->pause();
  }
  
  void MultiCookContainer::resume()
  {
      if (isEmpty_ || state != Paused)
          return;
  
      state = Running;
  
      foreach (MultiCook *c, list)
          if (c != Q_NULLPTR)
              c->resume();
  }