source: src/mlx/gui/weighthelp.py@ 895:929448cde3f5

Last change on this file since 895:929448cde3f5 was 303:8d5607e36aed, checked in by István Váradi <ivaradi@…>, 12 years ago

The number of the crew and the passengers as well as all payload weights can be edited

File size: 18.3 KB
Line 
1
2from mlx.gui.common import *
3
4from mlx.i18n import xstr
5from mlx.checks import PayloadChecker
6
7#-------------------------------------------------------------------------------
8
9## @package mlx.gui.weighthelp
10#
11# The weight calculation help tab.
12#
13# This module implements the tab containing the weight calculation help.
14
15#-------------------------------------------------------------------------------
16
17class WeightHelp(gtk.VBox):
18 """The weight calculation help tab."""
19 @staticmethod
20 def _getMarkup(value, expectedValue = None, tolerance = None):
21 """Get the markup for the given value.
22
23 If it is too much different from the expected value, it will be
24 colored yellow (if within the tolerance), or red (if out of the tolerance)."""
25 markup = "%.0f" % (value,)
26 if expectedValue is not None and tolerance is not None:
27 colour = None
28 diff = abs(value - expectedValue)
29 if diff>tolerance: colour = "red"
30 elif (diff*10)>=tolerance: colour = "orange"
31 else: colour = "darkgreen"
32 if colour is not None:
33 markup = '<span foreground="' + colour + '">' + markup + '</span>'
34 return markup
35
36 def __init__(self, gui):
37 """Construct the tab."""
38 super(WeightHelp, self).__init__()
39
40 self._gui = gui
41
42 mainAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
43 xscale = 1.0, yscale = 1.0)
44 mainAlignment.set_padding(padding_top = 4, padding_bottom = 4,
45 padding_left = 12, padding_right = 12)
46 self.add(mainAlignment)
47
48 self._mainBox = mainBox = gtk.VBox()
49 mainAlignment.add(mainBox)
50
51 self._usingHelp = gtk.CheckButton(xstr("weighthelp_usinghelp"))
52 self._usingHelp.set_use_underline(True)
53 self._usingHelp.set_tooltip_text(xstr("weighthelp_usinghelp_tooltip"))
54 self._usingHelp.connect("toggled", self._usingHelpToggled)
55 mainBox.pack_start(self._usingHelp, False, False, 4)
56
57
58 self._weightsTable = table = gtk.Table(16, 5)
59 table.set_homogeneous(False)
60 table.set_row_spacings(4)
61 table.set_col_spacings(16)
62 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
63 xscale = 0.0, yscale = 0.0)
64 alignment.add(table)
65 mainBox.pack_start(alignment, True, True, 4)
66
67 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.0,
68 xscale = 0.0, yscale = 0.0)
69 alignment.set_padding(padding_bottom = 16, padding_top = 0,
70 padding_left = 0, padding_right = 0)
71 label = gtk.Label(xstr("weighthelp_header_calculated"))
72 label.set_use_markup(True)
73 # FIXME: should be a constant in common
74 label.set_justify(gtk.Justification.CENTER if pygobject
75 else gtk.JUSTIFY_CENTER)
76 alignment.add(label)
77 table.attach(alignment, 1, 2, 0, 1)
78
79 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.0,
80 xscale = 0.0, yscale = 0.0)
81 alignment.set_padding(padding_bottom = 16, padding_top = 0,
82 padding_left = 0, padding_right = 0)
83 button = gtk.Button(xstr("weighthelp_header_simulator"))
84 button.set_tooltip_markup(xstr("weighthelp_header_simulator_tooltip"))
85 button.connect("clicked", self._fsButtonClicked)
86 label = button.get_child()
87 label.set_justify(gtk.Justification.CENTER if pygobject
88 else gtk.JUSTIFY_CENTER)
89 alignment.add(button)
90 table.attach(alignment, 3, 4, 0, 1)
91
92
93 self._crewLabel = gtk.Label(xstr("weighthelp_crew") % ("99",))
94 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
95 xscale = 0.0, yscale = 0.0)
96 alignment.add(self._crewLabel)
97 table.attach(alignment, 0, 1, 1, 2)
98
99 self._crewWeight = gtk.Label("0")
100 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
101 xscale = 0.0, yscale = 0.0)
102 alignment.add(self._crewWeight)
103 table.attach(alignment, 1, 2, 1, 2)
104
105 table.attach(gtk.Label("kg"), 2, 3, 1, 2)
106
107 text = xstr("weighthelp_pax") % ("999",)
108 self._paxLabel = gtk.Label(text)
109 self._paxLabel.set_width_chars(len(text))
110 self._paxLabel.set_alignment(0.0, 0.5)
111 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
112 xscale = 0.0, yscale = 0.0)
113 alignment.add(self._paxLabel)
114 table.attach(alignment, 0, 1, 2, 3)
115
116 self._paxWeight = gtk.Label("20000")
117 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
118 xscale = 0.0, yscale = 0.0)
119 alignment.add(self._paxWeight)
120 table.attach(alignment, 1, 2, 2, 3)
121
122 table.attach(gtk.Label("kg"), 2, 3, 2, 3)
123
124 label = gtk.Label(xstr("weighthelp_baggage"))
125 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
126 xscale = 0.0, yscale = 0.0)
127 alignment.add(label)
128 table.attach(alignment, 0, 1, 3, 4)
129
130 self._bagWeight = gtk.Label("2000")
131 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
132 xscale = 0.0, yscale = 0.0)
133 alignment.add(self._bagWeight)
134 table.attach(alignment, 1, 2, 3, 4)
135
136 table.attach(gtk.Label("kg"), 2, 3, 3, 4)
137
138 label = gtk.Label(xstr("weighthelp_cargo"))
139 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
140 xscale = 0.0, yscale = 0.0)
141 alignment.add(label)
142 table.attach(alignment, 0, 1, 4, 5)
143
144 self._cargoWeight = gtk.Label("2000")
145 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
146 xscale = 0.0, yscale = 0.0)
147 alignment.add(self._cargoWeight)
148 table.attach(alignment, 1, 2, 4, 5)
149
150 table.attach(gtk.Label("kg"), 2, 3, 4, 5)
151
152 label = gtk.Label(xstr("weighthelp_mail"))
153 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
154 xscale = 0.0, yscale = 0.0)
155 alignment.add(label)
156 table.attach(alignment, 0, 1, 5, 6)
157
158 self._mailWeight = gtk.Label("2000")
159 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
160 xscale = 0.0, yscale = 0.0)
161 alignment.add(self._mailWeight)
162 table.attach(alignment, 1, 2, 5, 6)
163
164 table.attach(gtk.Label("kg"), 2, 3, 5, 6)
165
166 table.attach(gtk.HSeparator(), 1, 2, 6, 7)
167
168 label = gtk.Label("<b>" + xstr("weighthelp_payload") + "</b>")
169 label.set_use_markup(True)
170 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
171 xscale = 0.0, yscale = 0.0)
172 alignment.add(label)
173 table.attach(alignment, 0, 1, 7, 8)
174
175 self._payload = gtk.Label("<b>32000</b>")
176 self._payload.set_use_markup(True)
177 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
178 xscale = 0.0, yscale = 0.0)
179 alignment.add(self._payload)
180 table.attach(alignment, 1, 2, 7, 8)
181
182 table.attach(gtk.Label("kg"), 2, 3, 7, 8)
183
184 self._fsPayload = gtk.Label("<b>32001</b>")
185 self._fsPayload.set_use_markup(True)
186 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
187 xscale = 0.0, yscale = 0.0)
188 alignment.add(self._fsPayload)
189 table.attach(alignment, 3, 4, 7, 8)
190
191 table.attach(gtk.Label("kg"), 4, 5, 7, 8)
192
193 label = gtk.Label(xstr("weighthelp_dow"))
194 label.set_use_markup(True)
195 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
196 xscale = 0.0, yscale = 0.0)
197 alignment.add(label)
198 table.attach(alignment, 0, 1, 8, 9)
199
200 self._dow = gtk.Label("35000")
201 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
202 xscale = 0.0, yscale = 0.0)
203 alignment.add(self._dow)
204 table.attach(alignment, 1, 2, 8, 9)
205
206 table.attach(gtk.Label("kg"), 2, 3, 8, 9)
207
208 self._fsDOW = gtk.Label("33012")
209 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
210 xscale = 0.0, yscale = 0.0)
211 alignment.add(self._fsDOW)
212 table.attach(alignment, 3, 4, 8, 9)
213
214 table.attach(gtk.Label("kg"), 4, 5, 8, 9)
215
216 table.attach(gtk.HSeparator(), 1, 2, 9, 10)
217
218 table.attach(gtk.HSeparator(), 3, 4, 9, 10)
219
220 label = gtk.Label("<b>" + xstr("weighthelp_zfw") + "</b>")
221 label.set_use_markup(True)
222 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
223 xscale = 0.0, yscale = 0.0)
224 alignment.add(label)
225 table.attach(alignment, 0, 1, 10, 11)
226
227 self._zfw = gtk.Label("<b>122000</b>")
228 self._zfw.set_use_markup(True)
229 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
230 xscale = 0.0, yscale = 0.0)
231 alignment.add(self._zfw)
232 table.attach(alignment, 1, 2, 10, 11)
233
234 table.attach(gtk.Label("kg"), 2, 3, 10, 11)
235
236 self._fsZFW = gtk.Label("<b>124000</b>")
237 self._fsZFW.set_use_markup(True)
238 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
239 xscale = 0.0, yscale = 0.0)
240 alignment.add(self._fsZFW)
241 table.attach(alignment, 3, 4, 10, 11)
242
243 table.attach(gtk.Label("kg"), 4, 5, 10, 11)
244
245 table.attach(gtk.HSeparator(), 0, 5, 11, 12)
246
247 label = gtk.Label(xstr("weighthelp_gross"))
248 label.set_use_markup(True)
249 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
250 xscale = 0.0, yscale = 0.0)
251 alignment.add(label)
252 table.attach(alignment, 0, 1, 12, 13)
253
254 self._fsGross = gtk.Label("124000")
255 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
256 xscale = 0.0, yscale = 0.0)
257 alignment.add(self._fsGross)
258 table.attach(alignment, 3, 4, 12, 13)
259
260 table.attach(gtk.Label("kg"), 4, 5, 12, 13)
261
262 label = gtk.Label(xstr("weighthelp_mzfw"))
263 label.set_use_markup(True)
264 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
265 xscale = 0.0, yscale = 0.0)
266 alignment.add(label)
267 table.attach(alignment, 0, 1, 13, 14)
268
269 self._mzfw = gtk.Label("35000")
270 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
271 xscale = 0.0, yscale = 0.0)
272 alignment.add(self._mzfw)
273 table.attach(alignment, 1, 2, 13, 14)
274
275 table.attach(gtk.Label("kg"), 2, 3, 13, 14)
276
277 label = gtk.Label(xstr("weighthelp_mtow"))
278 label.set_use_markup(True)
279 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
280 xscale = 0.0, yscale = 0.0)
281 alignment.add(label)
282 table.attach(alignment, 0, 1, 14, 15)
283
284 self._mtow = gtk.Label("35000")
285 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
286 xscale = 0.0, yscale = 0.0)
287 alignment.add(self._mtow)
288 table.attach(alignment, 1, 2, 14, 15)
289
290 table.attach(gtk.Label("kg"), 2, 3, 14, 15)
291
292 label = gtk.Label(xstr("weighthelp_mlw"))
293 label.set_use_markup(True)
294 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
295 xscale = 0.0, yscale = 0.0)
296 alignment.add(label)
297 table.attach(alignment, 0, 1, 15, 16)
298
299 self._mlw = gtk.Label("35000")
300 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
301 xscale = 0.0, yscale = 0.0)
302 alignment.add(self._mlw)
303 table.attach(alignment, 1, 2, 15, 16)
304
305 table.attach(gtk.Label("kg"), 2, 3, 15, 16)
306
307 self.show_all()
308
309 def disable(self):
310 """Disable the widget."""
311 self._mainBox.set_sensitive(False)
312
313 def enable(self):
314 """Enable the widget."""
315 self._mainBox.set_sensitive(True)
316
317 def reset(self):
318 """Reset all calculated and FS data."""
319
320 self._usingHelp.set_active(False)
321 self._usingHelp.set_sensitive(True)
322 self._weightsTable.set_sensitive(False)
323
324 self._crew = -1
325 self._pax = -1
326 self._humanWeight = 82.0
327 self._bag = -1
328 self._cargo = -1
329 self._mail = -1
330 self._dowValue = -1
331 self._mzfwValue = -1
332 self._mtowValue = -1
333 self._mlwValue = -1
334
335 self._fsPayloadValue = -1
336 self._fsDOWValue = -1
337 self._fsZFWValue = -1
338 self._fsGrossValue = -1
339
340 self._setupCalculated()
341 self._setupFS()
342
343 def _setupCalculated(self):
344 """Setup the labels for the calculated values."""
345 if self._crew<0:
346 self._crewLabel.set_text(xstr("weighthelp_crew") % ("-",))
347 self._crewWeight.set_text("-")
348 else:
349 self._crewLabel.set_text(xstr("weighthelp_crew") % (str(self._crew),))
350 crewWeight = self._crew * self._humanWeight
351 self._crewWeight.set_text("%.0f" % (crewWeight,))
352
353 if self._pax<0:
354 self._paxLabel.set_text(xstr("weighthelp_pax") % ("-",))
355 self._paxWeight.set_text("-")
356 else:
357 self._paxLabel.set_text(xstr("weighthelp_pax") % (str(self._pax),))
358 paxWeight = self._pax * self._humanWeight
359 self._paxWeight.set_text("%.0f" % (paxWeight,))
360
361 self._setWeightLabel(self._bagWeight, self._bag)
362
363 self._setWeightLabel(self._cargoWeight, self._cargo)
364
365 self._setWeightLabel(self._mailWeight, self._mail)
366
367 (payload, zfw) = self._calculateWeights()
368
369 self._setWeightLabel(self._payload, payload, bold = True)
370
371 self._setWeightLabel(self._dow, self._dowValue)
372
373 if zfw<0:
374 self._zfw.set_text("-")
375 else:
376 markup = "%.0f" % (zfw,)
377 if self._mzfwValue>0 and zfw>self._mzfwValue:
378 markup = '<span foreground="red">' + markup + '</span>'
379 markup = '<b>' + markup + '</b>'
380 self._zfw.set_markup(markup)
381
382 self._setWeightLabel(self._mzfw, self._mzfwValue)
383
384 self._setWeightLabel(self._mtow, self._mtowValue)
385
386 self._setWeightLabel(self._mlw, self._mlwValue)
387
388 def _setupFS(self):
389 if self._dowValue<0:
390 self._dow.set_text("-")
391 else:
392 self._dow.set_text("%.0f" % (self._dowValue,))
393
394 """Setup the labels for the FS values."""
395 (payload, zfw) = self._calculateWeights()
396
397 if self._fsPayloadValue<0:
398 self._fsPayload.set_text("-")
399 else:
400 markup = WeightHelp._getMarkup(self._fsPayloadValue, payload,
401 PayloadChecker.TOLERANCE)
402 self._fsPayload.set_markup("<b>" + markup + "</b>")
403
404 if self._fsDOWValue<0:
405 self._fsDOW.set_text("-")
406 else:
407 markup = WeightHelp._getMarkup(self._fsDOWValue, self._dowValue,
408 PayloadChecker.TOLERANCE)
409 self._fsDOW.set_markup(markup)
410
411 if self._fsZFWValue<0:
412 self._fsZFW.set_text("-")
413 else:
414 markup = WeightHelp._getMarkup(self._fsZFWValue, zfw,
415 PayloadChecker.TOLERANCE)
416 self._fsZFW.set_markup("<b>" + markup + "</b>")
417
418 self._setWeightLabel(self._fsGross, self._fsGrossValue)
419
420 def _calculateWeights(self):
421 """Calculate the payload and the zero-fuel weight.
422
423 It returns a tuple with these two items. If any of the items cannot be
424 calculated, that is -1."""
425 if self._crew<0 or self._pax<0 or \
426 self._bag<0 or self._cargo<0 or self._mail<0:
427 payload = -1
428 else:
429 payload = (self._crew + self._pax) * self._humanWeight + \
430 self._bag + self._cargo + self._mail
431
432 if payload<0 or self._dowValue<0:
433 zfw = -1
434 else:
435 zfw = payload + self._dowValue
436
437 return (payload, zfw)
438
439 def _usingHelpToggled(self, button):
440 """Called when the Using help button is toggled."""
441 assert self._usingHelp.get_active()
442 self._usingHelp.set_sensitive(False)
443
444 self._gui.logger.untimedMessage("The weight calculation help function was used by the pilot")
445
446 self._crew = self._gui.numCrew
447 self._pax = self._gui.numPassengers
448 self._bag = self._gui.bagWeight
449 self._cargo = self._gui.cargoWeight
450 self._mail = self._gui.mailWeight
451
452 aircraft = self._gui.flight.aircraft
453 self._humanWeight = aircraft.humanWeight
454 self._dowValue = aircraft.dow
455 self._mzfwValue = aircraft.mzfw
456 self._mtowValue = aircraft.mtow
457 self._mlwValue = aircraft.mlw
458
459 self._setupCalculated()
460 self._weightsTable.set_sensitive(True)
461
462 def _fsButtonClicked(self, button):
463 """Callback for the FS button being clicked."""
464 gui = self._gui
465 gui.beginBusy(xstr("weighthelp_busy"))
466 gui.simulator.requestWeights(self._handleWeights)
467
468 def _handleWeights(self, dow, payload, zfw, grossWeight):
469 """Handle the given weights."""
470 gobject.idle_add(self._processWeights, dow, payload, zfw, grossWeight)
471
472 def _processWeights(self, dow, payload, zfw, grossWeight):
473 """Process the given weights."""
474 self._gui.endBusy()
475 if self._usingHelp.get_active():
476 self._fsPayloadValue = payload
477 self._fsDOWValue = dow
478 self._fsZFWValue = zfw
479 self._fsGrossValue = grossWeight
480 self._setupFS()
481
482 def _setWeightLabel(self, label, weight, bold = False):
483 """Set the given weight label to the given weight."""
484 if weight<0:
485 label.set_text("-")
486 else:
487 markup = "%.0f" % (weight,)
488 if bold: markup = "<b>" + markup + "</b>"
489 label.set_markup(markup)
490
491
Note: See TracBrowser for help on using the repository browser.