Changeset 1154:516ca7c94d1d


Ignore:
Timestamp:
04/24/24 18:31:17 (8 months ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Message:

Gate dimensions are retrieved from the server and are used to restrict the set of gates available for a plane (re #386).

Location:
src/mlx
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/acft.py

    r1137 r1154  
    673673        if fleet is not None:
    674674            gateList = ""
    675             occupiedGateNumbers = fleet.getOccupiedGateNumbers()
    676             for gate in gates.lhbpGates.gates:
    677                 if gate.isAvailable(gates.lhbpGates, occupiedGateNumbers):
    678                     if gateList: gateList += ", "
    679                     gateList += gate.number
     675            for gate in fleet.iterAvailableLHBPGates(self.flight.bookedFlight.tailNumber):
     676                if gateList: gateList += ", "
     677                gateList += gate.number
    680678            fs.sendMessage(const.MESSAGETYPE_GATE_SYSTEM,
    681679                           "Free gates: " + gateList, 20)
  • src/mlx/gates.py

    r1151 r1154  
    1111    """Information about a gate."""
    1212    def __init__(self, number, terminal, type,
    13                  availableFn = None, taxiThrough = False):
     13                 availableFn = None, taxiThrough = False,
     14                 maxSpan = 0.0, maxLength = 0.0):
    1415        """Construct the gate with the given information.
    1516
     
    2122        - a collection of the gates, and
    2223        - a set of occupied gate numbers."""
    23         self._number = number
    24         self._terminal = terminal
    25         self._type = type
     24        self.number = number
     25        self.terminal = terminal
     26        self.type = type
    2627        self._availableFn = availableFn
    27         self._taxiThrough = taxiThrough
    28 
    29     @property
    30     def number(self):
    31         """Get the number of the gate."""
    32         return self._number
    33 
    34     @property
    35     def taxiThrough(self):
    36         """Get if the gate is a taxi through one."""
    37         return self._taxiThrough
    38 
    39     def isAvailable(self, gates, occupiedGateNumbers):
    40         """Determine if this gate is available given the set of gates and
    41         occupied gate numbers."""
    42         if self._number in occupiedGateNumbers:
     28        self.taxiThrough = taxiThrough
     29        self.maxSpan = maxSpan
     30        self.maxLength = maxLength
     31
     32    def isAvailable(self, plane, gates, occupiedGateNumbers):
     33        """Determine if this gate is available for the given plane and the
     34        given the set of gates and occupied gate numbers."""
     35        if self.number in occupiedGateNumbers:
    4336            return False
    44         return True if self._availableFn is None else \
    45                self._availableFn(gates, occupiedGateNumbers)
     37        if self._availableFn is None or \
     38           self._availableFn(gates, occupiedGateNumbers):
     39            return plane is None or \
     40                (plane.wingSpan <= self.maxSpan and \
     41                 plane.fuselageLength <= self.maxLength)
     42        else:
     43            return False
    4644
    4745#--------------------------------------------------------------------------------------
     
    112110        self._numRowsInColumn = 0
    113111        self._numColumns += 1
     112
     113    def merge(self, otherGates):
     114        """Merge the information from the given gate list (retrieved from the
     115        MAVA server) into this gate list."""
     116        for otherGate in otherGates.gates:
     117            gate = self.find(otherGate.number)
     118            if gate is None:
     119                print("Received data for gate %s, but it does not exist locally!" %
     120                      (otherGate.number,))
     121            else:
     122                if gate.terminal != otherGate.terminal:
     123                    print("The terminal for gate %s is received as: %s" %
     124                          (gate.number, otherGate.terminal))
     125                    gate.terminal = otherGate.terminal
     126                if gate.type != otherGate.type:
     127                    print("The type for gate %s is received as: %s" %
     128                          (gate.number, otherGate.type))
     129                    gate.type = otherGate.type
     130
     131                gate.maxSpan = otherGate.maxSpan
     132                gate.maxLength = otherGate.maxLength
     133
     134        for gate in self.gates:
     135            if gate.maxSpan==0.0 or gate.maxLength==0.0:
     136                    print("Gate %s has no maximal dimensions from the database" %
     137                          (gate.number,))
    114138
    115139    def _addRow(self):
  • src/mlx/gui/flight.py

    r1152 r1154  
    15001500        self._listStore.clear()
    15011501        self._gateList.set_sensitive(True)
    1502         occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers()
    1503         for gate in lhbpGates.gates:
    1504             if gate.isAvailable(lhbpGates, occupiedGateNumbers):
    1505                 self._listStore.append([gate.number])
     1502        for gate in self._wizard.iterAvailableLHBPGates():
     1503            self._listStore.append([gate.number])
    15061504
    15071505    def finalize(self):
     
    60236021           self._wizard.bookedFlight.arrivalICAO=="LHBP" and \
    60246022           not self._wizard.entranceExam:
    6025             occupiedGateNumbers = self._wizard._fleet.getOccupiedGateNumbers()
    6026             for gate in lhbpGates.gates:
    6027                 if gate.isAvailable(lhbpGates, occupiedGateNumbers):
    6028                     self._gatesModel.append([gate.number])
     6023            for gate in self._wizard.iterAvailableLHBPGates():
     6024                self._gatesModel.append([gate.number])
    60296025            self._gateLabel.set_sensitive(True)
    60306026            self._gate.set_sensitive(True)
     
    68716867            if result.loggedIn:
    68726868                self._loginResult = result
     6869                self._mergeGates()
    68736870                self.gui.loginSuccessful()
    68746871            else:
     
    69606957        self._simBriefingPage.finalizeCEF()
    69616958
     6959    def iterAvailableLHBPGates(self):
     6960        """Iterate over the available gates at LHBP for the current flight's plane."""
     6961        for gate in self._fleet.iterAvailableLHBPGates(self._bookedFlight.tailNumber):
     6962            yield gate
     6963
    69626964    def _connectSimulator(self, simulatorType):
    69636965        """Connect to the simulator."""
     
    69866988        assert False
    69876989
     6990    def _mergeGates(self):
     6991        """Merge the gate information retrieved during login into the
     6992        existing gate information for LHBP."""
     6993        lhbpGates.merge(self._loginResult.gates)
     6994
    69886995#-----------------------------------------------------------------------------
  • src/mlx/rpc.py

    r1153 r1154  
    11from . import const
    22from . import rpccommon
     3from . import gates
    34
    45from .common import MAVA_BASE_URL, fixUnpickled
     
    630631#---------------------------------------------------------------------------------------
    631632
     633class Gate(gates.Gate, RPCObject):
     634    """A gate."""
     635    _instructions = {
     636        "number": str,
     637        "terminal": str,
     638        "type": str,
     639        "maxSpan": float,
     640        "maxLength": float
     641    }
     642
     643    def __init__(self, value):
     644        """Construct the gate."""
     645        RPCObject.__init__(self, value, instructions = Gate._instructions)
     646
     647#---------------------------------------------------------------------------------------
     648
     649class Gates(gates.Gates):
     650    """The gates."""
     651    def __init__(self, value):
     652        """Construct the gates."""
     653        super(Gates, self).__init__()
     654        for gateValue in value:
     655            self.add(Gate(gateValue))
     656
     657#---------------------------------------------------------------------------------------
     658
    632659class Registration(object):
    633660    """Data for registration."""
     
    808835        return Fleet(value)
    809836
     837    def getGates(self):
     838        """Query and return the gate information."""
     839        value = self._performCall(lambda sessionID:
     840                                  self._server.getGates(sessionID))
     841
     842        return Gates(value)
     843
    810844    def updatePlane(self, tailNumber, status, gateNumber):
    811845        """Update the state and position of the plane with the given tail
  • src/mlx/rpccommon.py

    r919 r1154  
    44
    55from . import const
     6from .gates import lhbpGates
    67
    78#------------------------------------------------------------------------------
     
    5152        """Check if the gate of the given plane conflicts with another plane's
    5253        position."""
     54        gate = lhbpGates.find(plane.gateNumber)
    5355        for p in self._planes.values():
    5456            if p.tailNumber!=plane.tailNumber and \
    55                p.status==const.PLANE_HOME and \
    56                p.gateNumber==plane.gateNumber:
    57                 return True
     57               p.status==const.PLANE_HOME:
     58                if p.gateNumber==plane.gateNumber:
     59                    return True
     60                if gate is not None and not gate.isAvailable(plane,
     61                                                             lhbpGates,
     62                                                             [p.gateNumber]):
     63                    return True
    5864
    5965        return False
     
    6672                gateNumbers.add(p.gateNumber)
    6773        return gateNumbers
     74
     75    def iterAvailableLHBPGates(self, tailNumber):
     76        """Iterate over the available gates at LHBP."""
     77        occupiedGateNumbers = self.getOccupiedGateNumbers()
     78        plane = self.__getitem__(tailNumber)
     79        for gate in lhbpGates.gates:
     80            if gate.isAvailable(plane, lhbpGates, occupiedGateNumbers):
     81                yield gate
    6882
    6983    def updatePlane(self, tailNumber, status, gateNumber = None):
  • src/mlx/web.py

    r1114 r1154  
    476476            result.password = password
    477477            result.fleet = client.getFleet()
     478            result.gates = client.getGates()
    478479            flights = client.getFlights()
    479480            result.flights = flights[0]
Note: See TracChangeset for help on using the changeset viewer.