Changeset 619:7763179ff6b0 for src


Ignore:
Timestamp:
03/29/15 12:10:53 (10 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Reworked the representation and handling of gate data (re #113)

Location:
src/mlx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/acft.py

    r612 r619  
    11
    22import const
     3import gates
    34import checks
    45import fs
     
    620621            gateList = ""
    621622            occupiedGateNumbers = fleet.getOccupiedGateNumbers()
    622             for gateNumber in const.lhbpGateNumbers:
    623                 if gateNumber not in occupiedGateNumbers:
     623            for gate in gates.lhbpGates.gates:
     624                if gate.isAvailable(gates.lhbpGates, occupiedGateNumbers):
    624625                    if gateList: gateList += ", "
    625                     gateList += gateNumber
     626                    gateList += gate.number
    626627            fs.sendMessage(const.MESSAGETYPE_GATE_SYSTEM,
    627628                           "Free gates: " + gateList, 20)
  • src/mlx/const.py

    r618 r619  
    471471#-------------------------------------------------------------------------------
    472472
    473 ## The available gates at LHBP
    474 lhbpGateNumbers = []
    475 
    476 for i in range(1, 7):
    477     lhbpGateNumbers.append(str(i))
    478 
    479 for i in range(10, 19):
    480     lhbpGateNumbers.append(str(i))
    481 
    482 for i in range(24, 28):
    483     lhbpGateNumbers.append(str(i))
    484 
    485 for i in range(31, 39):
    486     lhbpGateNumbers.append(str(i))
    487 
    488 for i in range(42, 47):
    489     lhbpGateNumbers.append(str(i))
    490 
    491 for i in range(60, 84):
    492     if i!=70 and i!=80:
    493         lhbpGateNumbers.append(str(i))
    494 
    495 #-------------------------------------------------------------------------------
    496 
    497473languages = ["$system", "en_GB", "hu_HU"]
    498474
  • src/mlx/gates.py

    r618 r619  
     1#--------------------------------------------------------------------------------------
     2
     3## @package mlx.gates
     4#
     5# The module to handle the LHBP gate information.
     6#
     7
     8#--------------------------------------------------------------------------------------
     9
     10class Gate(object):
     11    """Information about a gate."""
     12    def __init__(self, number, terminal, type,
     13                 availableFn = None):
     14        """Construct the gate with the given information.
     15
     16        number is the gate's number as a string (as it can contain letters).
     17        terminal is the terminal the gate belongs to (not used currently).
     18        type is the gate's type: G for gate, S for stand.
     19        availableFn is a function that can determine if the gate is available based on
     20        the statuses of other gates. Its arguments are:
     21        - a collection of the gates, and
     22        - a set of occupied gate numbers."""
     23        self._number = number
     24        self._terminal = terminal
     25        self._type = type
     26        self._availableFn = availableFn
     27
     28    @property
     29    def number(self):
     30        """Get the number of the gate."""
     31        return self._number
     32
     33    def isAvailable(self, gates, occupiedGateNumbers):
     34        """Determine if this gate is available given the set of gates and
     35        occupied gate numbers."""
     36        if self._number in occupiedGateNumbers:
     37            return False
     38        return True if self._availableFn is None else \
     39               self._availableFn(gates, occupiedGateNumbers)
     40
     41#--------------------------------------------------------------------------------------
     42
     43class Gates(object):
     44    """A collection of gates."""
     45    # Display info type: a gate (number)
     46    DISPLAY_GATE=1
     47
     48    # Display info type: a space
     49    DISPLAY_SPACE=2
     50
     51    # Display info type: a new column
     52    DISPLAY_NEW_COLUMN=3
     53
     54    def __init__(self):
     55        """Construct the gate collection."""
     56        self._gates = []
     57        self._displayInfos = []
     58        self._numColumns = 1
     59        self._numRows = 0
     60        self._numRowsInColumn = 0
     61
     62    @property
     63    def gates(self):
     64        """Get an iterator over the gates."""
     65        return iter(self._gates)
     66
     67    @property
     68    def displayInfos(self):
     69        """Get an iterator over the display info tuples.
     70
     71        Each tuple consists of
     72        - a type (one of the DISPLAY_XXX constants), and
     73        - an additional data (the gate for DISPLAY_GATE, None for others)."""
     74        return iter(self._displayInfos)
     75
     76    @property
     77    def numRows(self):
     78        """Get the number of rows."""
     79        return self._numRows
     80
     81    @property
     82    def numColumns(self):
     83        """Get the number of columns."""
     84        return self._numColumns
     85
     86    def add(self, gate):
     87        """Add a gate to the collection."""
     88        self._gates.append(gate)
     89        self._displayInfos.append((Gates.DISPLAY_GATE, gate))
     90        self._addRow()
     91
     92    def addSpace(self):
     93        """Add a space between subsequent gates."""
     94        self._displayInfos.append((Gates.DISPLAY_SPACE, None))
     95        self._addRow()
     96
     97    def addNewColumn(self):
     98        """Start a new column of gates."""
     99        self._displayInfos.append((Gates.DISPLAY_NEW_COLUMN, None))
     100        self._numRowsInColumn = 0
     101        self._numColumns += 1
     102
     103    def _addRow(self):
     104        """Add a new row."""
     105        self._numRowsInColumn += 1
     106        if self._numRowsInColumn > self._numRows:
     107            self._numRows = self._numRowsInColumn
     108
     109#--------------------------------------------------------------------------------------
     110
     111def availableIf(occupiedGateNumbers, othersAvailable = []):
     112    """Determine if a gate is available.
     113
     114    othersAvailable is a list of numbers of gates, that must be available so
     115    that the one we are considering is available."""
     116    for otherNumber in othersAvailable:
     117        if otherNumber in occupiedGateNumbers:
     118            return False
     119    return True
     120
     121#--------------------------------------------------------------------------------------
     122
     123def getAvilableIf(othersAvailable = []):
     124    """Get a function that determines if a gate is available based on the
     125    statuses of other gates."""
     126    return lambda gates, occupiedGateNumbers: availableIf(occupiedGateNumbers,
     127                                                          othersAvailable =
     128                                                          othersAvailable)
     129
     130#--------------------------------------------------------------------------------------
     131
     132# The gates at LHBP
     133lhbpGates = Gates()
     134
     135lhbpGates.add(Gate("1", "1", "S"))
     136lhbpGates.add(Gate("2", "1", "S"))
     137lhbpGates.add(Gate("3", "1", "S"))
     138lhbpGates.add(Gate("4", "1", "S"))
     139lhbpGates.add(Gate("5", "1", "S"))
     140lhbpGates.add(Gate("6", "1", "S"))
     141lhbpGates.add(Gate("25", "1", "S"))
     142lhbpGates.add(Gate("26", "1", "S"))
     143lhbpGates.add(Gate("27", "1", "S"))
     144lhbpGates.addSpace()
     145
     146lhbpGates.add(Gate("31", "2B", "G"))
     147lhbpGates.add(Gate("32", "2B", "G"))
     148lhbpGates.add(Gate("33", "2B", "G"))
     149lhbpGates.addNewColumn()
     150
     151lhbpGates.add(Gate("34", "2B", "G"))
     152lhbpGates.add(Gate("35", "2B", "G"))
     153lhbpGates.add(Gate("36", "2B", "G"))
     154lhbpGates.add(Gate("37", "2B", "G"))
     155lhbpGates.add(Gate("38", "2B", "G"))
     156lhbpGates.add(Gate("39", "2B", "G"))
     157lhbpGates.addSpace()
     158
     159lhbpGates.add(Gate("42", "2A", "G"))
     160lhbpGates.add(Gate("43", "2A", "G"))
     161lhbpGates.add(Gate("44", "2A", "G"))
     162lhbpGates.add(Gate("45", "2A", "G"))
     163lhbpGates.addNewColumn()
     164
     165lhbpGates.add(Gate("107", "1", "S"))
     166lhbpGates.add(Gate("108", "1", "S"))
     167lhbpGates.add(Gate("109", "1", "S"))
     168lhbpGates.add(Gate("R110", "1", "S",
     169                   availableFn = getAvilableIf(othersAvailable = ["R111"])))
     170lhbpGates.add(Gate("R111", "1", "S",
     171                   availableFn = getAvilableIf(othersAvailable = ["R110", "R112"])))
     172lhbpGates.add(Gate("R112", "1", "S",
     173                   availableFn = getAvilableIf(othersAvailable = ["R111"])))
     174lhbpGates.add(Gate("R113", "1", "S",
     175                   availableFn = getAvilableIf(othersAvailable = ["R114"])))
     176lhbpGates.add(Gate("R114", "1", "S",
     177                   availableFn = getAvilableIf(othersAvailable = ["R113"])))
     178lhbpGates.add(Gate("R115", "1", "S"))
     179lhbpGates.add(Gate("R116", "1", "S"))
     180lhbpGates.add(Gate("R117", "1", "S"))
     181lhbpGates.addNewColumn()
     182
     183lhbpGates.add(Gate("R210", "2A", "S",
     184                   availableFn = getAvilableIf(othersAvailable = ["R212A"])))
     185lhbpGates.add(Gate("R211", "2A", "S",
     186                   availableFn = getAvilableIf(othersAvailable = ["R212A"])))
     187lhbpGates.add(Gate("R212", "2A", "S",
     188                   availableFn = getAvilableIf(othersAvailable = ["R212A"])))
     189lhbpGates.add(Gate("R212A", "2A", "S",
     190                   availableFn = getAvilableIf(othersAvailable = ["R210", "R211", "R212"])))
     191lhbpGates.addSpace()
     192
     193lhbpGates.add(Gate("R220", "2B", "S"))
     194lhbpGates.add(Gate("R221", "2B", "S"))
     195lhbpGates.add(Gate("R222", "2B", "S"))
     196lhbpGates.add(Gate("R223", "2B", "S"))
     197lhbpGates.addSpace()
     198
     199lhbpGates.add(Gate("R224", "2A", "R"))
     200lhbpGates.add(Gate("R225", "2A", "S"))
     201lhbpGates.add(Gate("R226", "2A", "S"))
     202lhbpGates.add(Gate("R227", "2A", "S"))
     203lhbpGates.addNewColumn()
     204
     205lhbpGates.add(Gate("R270", "2A", "S"))
     206lhbpGates.add(Gate("R271", "2A", "S"))
     207lhbpGates.add(Gate("R272", "2A", "S"))
     208lhbpGates.add(Gate("R274", "2A", "S"))
     209lhbpGates.add(Gate("R275", "2A", "S"))
     210lhbpGates.add(Gate("R276", "2A", "S"))
     211lhbpGates.add(Gate("R277", "2A", "S"))
     212lhbpGates.add(Gate("R278", "2A", "S",
     213                   availableFn = getAvilableIf(othersAvailable = ["R278A"])))
     214lhbpGates.add(Gate("R278A", "2A", "S",
     215                   availableFn = getAvilableIf(othersAvailable = ["R278", "R279"])))
     216lhbpGates.add(Gate("R279", "2A", "S",
     217                   availableFn = getAvilableIf(othersAvailable = ["R278A"])))
  • src/mlx/gui/flight.py

    r607 r619  
    77from mlx.flight import Flight
    88from mlx.checks import PayloadChecker
     9from mlx.gates import lhbpGates
    910import mlx.util as util
    1011from mlx.pirep import PIREP
     
    818819        self._gateList.set_sensitive(True)
    819820        occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers()
    820         for gateNumber in const.lhbpGateNumbers:
    821             if gateNumber not in occupiedGateNumbers:
    822                 self._listStore.append([gateNumber])
     821        for gate in lhbpGates:
     822            if gate.isAvailable(lhbpGates, occupiedGateNumbers):
     823                self._listStore.append([gate.number])
    823824
    824825    def finalize(self):
     
    32533254           self._wizard.bookedFlight.arrivalICAO=="LHBP" and \
    32543255           not self._wizard.entranceExam:
    3255             occupiedGates = self._wizard._fleet.getOccupiedGateNumbers()
    3256             for gateNumber in const.lhbpGateNumbers:
    3257                 if gateNumber not in occupiedGates:
    3258                     self._gatesModel.append([gateNumber])
     3256            occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers()
     3257            for gate in lhbpGates.gates:
     3258                if gate.isAvailable(lhbpGates, occupiedGateNumbers):
     3259                    self._gatesModel.append([gate.number])
    32593260            self._gateLabel.set_sensitive(True)
    32603261            self._gate.set_sensitive(True)
  • src/mlx/gui/gates.py

    r300 r619  
    44from mlx.i18n import xstr
    55import mlx.const as const
     6from mlx.gates import Gates, lhbpGates
    67
    78#-------------------------------------------------------------------------------
     
    8283        statusBox.pack_start(gatesFrame, True, True, 4)       
    8384
    84         self._gatesTable = table = gtk.Table(14, 4)
     85        self._gatesTable = table = gtk.Table(lhbpGates.numRows,
     86                                             lhbpGates.numColumns)
    8587        table.set_tooltip_markup(xstr("gates_gates_tooltip"))
    8688        alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
     
    9496        column = 0
    9597        row = 0
    96         for gateNumber in const.lhbpGateNumbers:
    97             label = gtk.Label()
    98             label.set_markup("<b>" + gateNumber + "</b>")
    99             table.attach(label, column, column + 1, row, row + 1)
     98        for (type, data) in lhbpGates.displayInfos:
     99            if type==Gates.DISPLAY_GATE:
     100                gate = data
    100101
    101             self._gateLabels[gateNumber] = label
    102            
    103             if column==1 and row==12:
    104                 column = 2
    105                 row = 1
    106             elif row==13:
     102                label = gtk.Label()
     103                label.set_markup("<b>" + gate.number + "</b>")
     104                table.attach(label, column, column + 1, row, row + 1)
     105
     106                self._gateLabels[gate.number] = label
     107                row += 1
     108            elif type==Gates.DISPLAY_SPACE:
     109                row += 1
     110            elif type==Gates.DISPLAY_NEW_COLUMN:
     111                row = 0
    107112                column += 1
    108                 row = 0
    109             else:
    110                 row += 1
    111                
     113
    112114        button = gtk.Button(xstr("gates_refresh"))
    113115        button.set_use_underline(True)
     
    168170
    169171            occupiedGateNumbers = fleet.getOccupiedGateNumbers()
    170             for gateNumber in const.lhbpGateNumbers:
     172            for gate in lhbpGates.gates:
     173                gateNumber = gate.number
    171174                markup = gateNumber
    172175                if gateNumber in occupiedGateNumbers:
Note: See TracChangeset for help on using the changeset viewer.