Changeset 1172:6cb71d6b4572


Ignore:
Timestamp:
10/20/24 12:57:19 (5 weeks ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Message:

The gate data can be read from a JSON file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gates.py

    r1158 r1172  
    1010class Gate(object):
    1111    """Information about a gate."""
     12    @staticmethod
     13    def fromJSON(data):
     14        """Create the gate from the given JSON data."""
     15        return Gate(data["number"], data["terminal"],
     16                    data["type"],
     17                    maxSpan = data["maxSpan"],
     18                    maxLength = data["maxLength"])
     19
    1220    def __init__(self, number, terminal, type,
    1321                 availableFn = None, taxiThrough = False,
     
    4452            return False
    4553
     54    def toJSON(self):
     55        """Create a JSON representation of the gate."""
     56        data = {}
     57        for attributeName in ["number", "terminal", "type",
     58                              "maxSpan", "maxLength"]:
     59            data[attributeName] = getattr(self, attributeName)
     60        return data
     61
    4662#--------------------------------------------------------------------------------------
    4763
     
    5672    # Display info type: a new column
    5773    DISPLAY_NEW_COLUMN=3
     74
     75    @staticmethod
     76    def fromJSON(data):
     77        """Create a gates object from the given JSON data."""
     78        gates = Gates()
     79        for gateData in data:
     80            gates.add(Gate.fromJSON(gateData))
     81        return gates
    5882
    5983    def __init__(self):
     
    137161                    print("Gate %s has no maximal dimensions from the database" %
    138162                          (gate.number,))
     163
     164    def toJSON(self):
     165        """Convert the list of gates into a JSON data."""
     166        return [gate.toJSON() for gate in self._gates]
    139167
    140168    def _addRow(self):
Note: See TracChangeset for help on using the changeset viewer.