source: src/mlx/gui/weighthelp.py@ 917:803dc6bacfa5

Last change on this file since 917:803dc6bacfa5 was 899:ec5238c77005, checked in by István Váradi <ivaradi@…>, 7 years ago

Cockpit and cabin crew weight is included in DOW, extra people are calulcated with specific weights, and passenger weight is set to 84 kgs (re #332)

File size: 20.2 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(17, 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._cockpitCrewLabel = \
94 gtk.Label(xstr("weighthelp_cockpit_crew") % ("99",))
95 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
96 xscale = 0.0, yscale = 0.0)
97 alignment.add(self._cockpitCrewLabel)
98 table.attach(alignment, 0, 1, 1, 2)
99
100 self._cockpitCrewWeight = gtk.Label("0")
101 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
102 xscale = 0.0, yscale = 0.0)
103 alignment.add(self._cockpitCrewWeight)
104 table.attach(alignment, 1, 2, 1, 2)
105
106 table.attach(gtk.Label("kg"), 2, 3, 1, 2)
107
108 self._cabinCrewLabel = \
109 gtk.Label(xstr("weighthelp_cabin_crew") % ("99",))
110 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
111 xscale = 0.0, yscale = 0.0)
112 alignment.add(self._cabinCrewLabel)
113 table.attach(alignment, 0, 1, 2, 3)
114
115 self._cabinCrewWeight = gtk.Label("0")
116 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
117 xscale = 0.0, yscale = 0.0)
118 alignment.add(self._cabinCrewWeight)
119 table.attach(alignment, 1, 2, 2, 3)
120
121 table.attach(gtk.Label("kg"), 2, 3, 2, 3)
122
123 text = xstr("weighthelp_pax") % ("999",)
124 self._paxLabel = gtk.Label(text)
125 self._paxLabel.set_width_chars(len(text))
126 self._paxLabel.set_alignment(0.0, 0.5)
127 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
128 xscale = 0.0, yscale = 0.0)
129 alignment.add(self._paxLabel)
130 table.attach(alignment, 0, 1, 3, 4)
131
132 self._paxWeight = gtk.Label("20000")
133 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
134 xscale = 0.0, yscale = 0.0)
135 alignment.add(self._paxWeight)
136 table.attach(alignment, 1, 2, 3, 4)
137
138 table.attach(gtk.Label("kg"), 2, 3, 3, 4)
139
140 label = gtk.Label(xstr("weighthelp_baggage"))
141 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
142 xscale = 0.0, yscale = 0.0)
143 alignment.add(label)
144 table.attach(alignment, 0, 1, 4, 5)
145
146 self._bagWeight = gtk.Label("2000")
147 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
148 xscale = 0.0, yscale = 0.0)
149 alignment.add(self._bagWeight)
150 table.attach(alignment, 1, 2, 4, 5)
151
152 table.attach(gtk.Label("kg"), 2, 3, 4, 5)
153
154 label = gtk.Label(xstr("weighthelp_cargo"))
155 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
156 xscale = 0.0, yscale = 0.0)
157 alignment.add(label)
158 table.attach(alignment, 0, 1, 5, 6)
159
160 self._cargoWeight = gtk.Label("2000")
161 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
162 xscale = 0.0, yscale = 0.0)
163 alignment.add(self._cargoWeight)
164 table.attach(alignment, 1, 2, 5, 6)
165
166 table.attach(gtk.Label("kg"), 2, 3, 5, 6)
167
168 label = gtk.Label(xstr("weighthelp_mail"))
169 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
170 xscale = 0.0, yscale = 0.0)
171 alignment.add(label)
172 table.attach(alignment, 0, 1, 6, 7)
173
174 self._mailWeight = gtk.Label("2000")
175 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
176 xscale = 0.0, yscale = 0.0)
177 alignment.add(self._mailWeight)
178 table.attach(alignment, 1, 2, 6, 7)
179
180 table.attach(gtk.Label("kg"), 2, 3, 6, 7)
181
182 table.attach(gtk.HSeparator(), 1, 2, 7, 8)
183
184 label = gtk.Label("<b>" + xstr("weighthelp_payload") + "</b>")
185 label.set_use_markup(True)
186 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
187 xscale = 0.0, yscale = 0.0)
188 alignment.add(label)
189 table.attach(alignment, 0, 1, 8, 9)
190
191 self._payload = gtk.Label("<b>32000</b>")
192 self._payload.set_use_markup(True)
193 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
194 xscale = 0.0, yscale = 0.0)
195 alignment.add(self._payload)
196 table.attach(alignment, 1, 2, 8, 9)
197
198 table.attach(gtk.Label("kg"), 2, 3, 8, 9)
199
200 self._fsPayload = gtk.Label("<b>32001</b>")
201 self._fsPayload.set_use_markup(True)
202 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
203 xscale = 0.0, yscale = 0.0)
204 alignment.add(self._fsPayload)
205 table.attach(alignment, 3, 4, 8, 9)
206
207 table.attach(gtk.Label("kg"), 4, 5, 8, 9)
208
209 label = gtk.Label(xstr("weighthelp_dow"))
210 label.set_use_markup(True)
211 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
212 xscale = 0.0, yscale = 0.0)
213 alignment.add(label)
214 table.attach(alignment, 0, 1, 9, 10)
215
216 self._dow = gtk.Label("35000")
217 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
218 xscale = 0.0, yscale = 0.0)
219 alignment.add(self._dow)
220 table.attach(alignment, 1, 2, 9, 10)
221
222 table.attach(gtk.Label("kg"), 2, 3, 9, 10)
223
224 self._fsDOW = gtk.Label("33012")
225 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
226 xscale = 0.0, yscale = 0.0)
227 alignment.add(self._fsDOW)
228 table.attach(alignment, 3, 4, 9, 10)
229
230 table.attach(gtk.Label("kg"), 4, 5, 9, 10)
231
232 table.attach(gtk.HSeparator(), 1, 2, 10, 11)
233
234 table.attach(gtk.HSeparator(), 3, 4, 10, 11)
235
236 label = gtk.Label("<b>" + xstr("weighthelp_zfw") + "</b>")
237 label.set_use_markup(True)
238 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
239 xscale = 0.0, yscale = 0.0)
240 alignment.add(label)
241 table.attach(alignment, 0, 1, 11, 12)
242
243 self._zfw = gtk.Label("<b>122000</b>")
244 self._zfw.set_use_markup(True)
245 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
246 xscale = 0.0, yscale = 0.0)
247 alignment.add(self._zfw)
248 table.attach(alignment, 1, 2, 11, 12)
249
250 table.attach(gtk.Label("kg"), 2, 3, 11, 12)
251
252 self._fsZFW = gtk.Label("<b>124000</b>")
253 self._fsZFW.set_use_markup(True)
254 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
255 xscale = 0.0, yscale = 0.0)
256 alignment.add(self._fsZFW)
257 table.attach(alignment, 3, 4, 11, 12)
258
259 table.attach(gtk.Label("kg"), 4, 5, 11, 12)
260
261 table.attach(gtk.HSeparator(), 0, 5, 12, 13)
262
263 label = gtk.Label(xstr("weighthelp_gross"))
264 label.set_use_markup(True)
265 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
266 xscale = 0.0, yscale = 0.0)
267 alignment.add(label)
268 table.attach(alignment, 0, 1, 13, 14)
269
270 self._fsGross = gtk.Label("124000")
271 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
272 xscale = 0.0, yscale = 0.0)
273 alignment.add(self._fsGross)
274 table.attach(alignment, 3, 4, 13, 14)
275
276 table.attach(gtk.Label("kg"), 4, 5, 13, 14)
277
278 label = gtk.Label(xstr("weighthelp_mzfw"))
279 label.set_use_markup(True)
280 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
281 xscale = 0.0, yscale = 0.0)
282 alignment.add(label)
283 table.attach(alignment, 0, 1, 14, 15)
284
285 self._mzfw = gtk.Label("35000")
286 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
287 xscale = 0.0, yscale = 0.0)
288 alignment.add(self._mzfw)
289 table.attach(alignment, 1, 2, 14, 15)
290
291 table.attach(gtk.Label("kg"), 2, 3, 14, 15)
292
293 label = gtk.Label(xstr("weighthelp_mtow"))
294 label.set_use_markup(True)
295 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
296 xscale = 0.0, yscale = 0.0)
297 alignment.add(label)
298 table.attach(alignment, 0, 1, 15, 16)
299
300 self._mtow = gtk.Label("35000")
301 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
302 xscale = 0.0, yscale = 0.0)
303 alignment.add(self._mtow)
304 table.attach(alignment, 1, 2, 15, 16)
305
306 table.attach(gtk.Label("kg"), 2, 3, 15, 16)
307
308 label = gtk.Label(xstr("weighthelp_mlw"))
309 label.set_use_markup(True)
310 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.5,
311 xscale = 0.0, yscale = 0.0)
312 alignment.add(label)
313 table.attach(alignment, 0, 1, 16, 17)
314
315 self._mlw = gtk.Label("35000")
316 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5,
317 xscale = 0.0, yscale = 0.0)
318 alignment.add(self._mlw)
319 table.attach(alignment, 1, 2, 16, 17)
320
321 table.attach(gtk.Label("kg"), 2, 3, 16, 17)
322
323 self.show_all()
324
325 def disable(self):
326 """Disable the widget."""
327 self._mainBox.set_sensitive(False)
328
329 def enable(self):
330 """Enable the widget."""
331 self._mainBox.set_sensitive(True)
332
333 def reset(self):
334 """Reset all calculated and FS data."""
335
336 self._usingHelp.set_active(False)
337 self._usingHelp.set_sensitive(True)
338 self._weightsTable.set_sensitive(False)
339
340 self._cockpitCrew = -1
341 self._cabinCrew = -1
342 self._pax = -1
343 self._dowCockpit = 2
344 self._cockpitCrewMemberWeight = 85.0
345 self._dowCabin = 2
346 self._cabinCrewMemberWeight = 75.0
347 self._humanWeight = 84.0
348 self._bag = -1
349 self._cargo = -1
350 self._mail = -1
351 self._dowValue = -1
352 self._mzfwValue = -1
353 self._mtowValue = -1
354 self._mlwValue = -1
355
356 self._fsPayloadValue = -1
357 self._fsDOWValue = -1
358 self._fsZFWValue = -1
359 self._fsGrossValue = -1
360
361 self._setupCalculated()
362 self._setupFS()
363
364 def _setupCalculated(self):
365 """Setup the labels for the calculated values."""
366 if self._cockpitCrew<0:
367 self._cockpitCrewLabel.set_text(xstr("weighthelp_cockpit_crew") % ("-",))
368 self._cockpitCrewWeight.set_text("-")
369 else:
370 self._cockpitCrewLabel.set_text(xstr("weighthelp_cockpit_crew") %
371 (str(self._cockpitCrew),))
372 crewWeight = (self._cockpitCrew - self._dowCockpit) * self._cockpitCrewMemberWeight
373 self._cockpitCrewWeight.set_text("%.0f" % (crewWeight,))
374
375 if self._cabinCrew<0:
376 self._cabinCrewLabel.set_text(xstr("weighthelp_cabin_crew") % ("-",))
377 self._cabinCrewWeight.set_text("-")
378 else:
379 self._cabinCrewLabel.set_text(xstr("weighthelp_cabin_crew") %
380 (str(self._cabinCrew),))
381 crewWeight = (self._cabinCrew - self._dowCabin) * self._cabinCrewMemberWeight
382 self._cabinCrewWeight.set_text("%.0f" % (crewWeight,))
383
384 if self._pax<0:
385 self._paxLabel.set_text(xstr("weighthelp_pax") % ("-",))
386 self._paxWeight.set_text("-")
387 else:
388 self._paxLabel.set_text(xstr("weighthelp_pax") % (str(self._pax),))
389 paxWeight = self._pax * self._humanWeight
390 self._paxWeight.set_text("%.0f" % (paxWeight,))
391
392 self._setWeightLabel(self._bagWeight, self._bag)
393
394 self._setWeightLabel(self._cargoWeight, self._cargo)
395
396 self._setWeightLabel(self._mailWeight, self._mail)
397
398 (payload, zfw) = self._calculateWeights()
399
400 self._setWeightLabel(self._payload, payload, bold = True)
401
402 self._setWeightLabel(self._dow, self._dowValue)
403
404 if zfw<0:
405 self._zfw.set_text("-")
406 else:
407 markup = "%.0f" % (zfw,)
408 if self._mzfwValue>0 and zfw>self._mzfwValue:
409 markup = '<span foreground="red">' + markup + '</span>'
410 markup = '<b>' + markup + '</b>'
411 self._zfw.set_markup(markup)
412
413 self._setWeightLabel(self._mzfw, self._mzfwValue)
414
415 self._setWeightLabel(self._mtow, self._mtowValue)
416
417 self._setWeightLabel(self._mlw, self._mlwValue)
418
419 def _setupFS(self):
420 if self._dowValue<0:
421 self._dow.set_text("-")
422 else:
423 self._dow.set_text("%.0f" % (self._dowValue,))
424
425 """Setup the labels for the FS values."""
426 (payload, zfw) = self._calculateWeights()
427
428 if self._fsPayloadValue<0:
429 self._fsPayload.set_text("-")
430 else:
431 markup = WeightHelp._getMarkup(self._fsPayloadValue, payload,
432 PayloadChecker.TOLERANCE)
433 self._fsPayload.set_markup("<b>" + markup + "</b>")
434
435 if self._fsDOWValue<0:
436 self._fsDOW.set_text("-")
437 else:
438 markup = WeightHelp._getMarkup(self._fsDOWValue, self._dowValue,
439 PayloadChecker.TOLERANCE)
440 self._fsDOW.set_markup(markup)
441
442 if self._fsZFWValue<0:
443 self._fsZFW.set_text("-")
444 else:
445 markup = WeightHelp._getMarkup(self._fsZFWValue, zfw,
446 PayloadChecker.TOLERANCE)
447 self._fsZFW.set_markup("<b>" + markup + "</b>")
448
449 self._setWeightLabel(self._fsGross, self._fsGrossValue)
450
451 def _calculateWeights(self):
452 """Calculate the payload and the zero-fuel weight.
453
454 It returns a tuple with these two items. If any of the items cannot be
455 calculated, that is -1."""
456 if self._cockpitCrew<0 or self._cabinCrew<0 or self._pax<0 or \
457 self._bag<0 or self._cargo<0 or self._mail<0:
458 payload = -1
459 else:
460 payload = \
461 (self._cockpitCrew - self._dowCockpit) * \
462 self._cockpitCrewMemberWeight + \
463 (self._cabinCrew - self._dowCabin) * \
464 self._cabinCrewMemberWeight + \
465 self._pax * self._humanWeight + \
466 self._bag + self._cargo + self._mail
467
468 if payload<0 or self._dowValue<0:
469 zfw = -1
470 else:
471 zfw = payload + self._dowValue
472
473 return (payload, zfw)
474
475 def _usingHelpToggled(self, button):
476 """Called when the Using help button is toggled."""
477 assert self._usingHelp.get_active()
478 self._usingHelp.set_sensitive(False)
479
480 self._gui.logger.untimedMessage("The weight calculation help function was used by the pilot")
481
482 self._cockpitCrew = self._gui.numCockpitCrew
483 self._cabinCrew = self._gui.numCabinCrew
484 self._pax = self._gui.numPassengers
485 self._bag = self._gui.bagWeight
486 self._cargo = self._gui.cargoWeight
487 self._mail = self._gui.mailWeight
488
489 aircraft = self._gui.flight.aircraft
490 self._dowCockpit = aircraft.dowCockpit
491 self._cockpitCrewMemberWeight = aircraft.cockpitCrewWeight
492 self._dowCabin = aircraft.dowCabin
493 self._cabinCrewMemberWeight = aircraft.cabinCrewWeight
494 self._humanWeight = aircraft.humanWeight
495 self._dowValue = aircraft.dow
496 self._mzfwValue = aircraft.mzfw
497 self._mtowValue = aircraft.mtow
498 self._mlwValue = aircraft.mlw
499
500 self._setupCalculated()
501 self._weightsTable.set_sensitive(True)
502
503 def _fsButtonClicked(self, button):
504 """Callback for the FS button being clicked."""
505 gui = self._gui
506 gui.beginBusy(xstr("weighthelp_busy"))
507 gui.simulator.requestWeights(self._handleWeights)
508
509 def _handleWeights(self, dow, payload, zfw, grossWeight):
510 """Handle the given weights."""
511 gobject.idle_add(self._processWeights, dow, payload, zfw, grossWeight)
512
513 def _processWeights(self, dow, payload, zfw, grossWeight):
514 """Process the given weights."""
515 self._gui.endBusy()
516 if self._usingHelp.get_active():
517 self._fsPayloadValue = payload
518 self._fsDOWValue = dow
519 self._fsZFWValue = zfw
520 self._fsGrossValue = grossWeight
521 self._setupFS()
522
523 def _setWeightLabel(self, label, weight, bold = False):
524 """Set the given weight label to the given weight."""
525 if weight<0:
526 label.set_text("-")
527 else:
528 markup = "%.0f" % (weight,)
529 if bold: markup = "<b>" + markup + "</b>"
530 label.set_markup(markup)
531
532
Note: See TracBrowser for help on using the repository browser.