GUI Traffic Variables - ilabs-kdc/bluesky GitHub Wiki

Just like the traffic variables on the server side, there are also traffic variables on the GUI side of the program. The data stored in the traffic variables on the server side are the same for every GUI (i.e. every screen when doing a distributed simulation), while the data stored in the traffic variables on the GUI side may vary for every GUI. More information about the different sides of the program can be found here. In the python file ui/qtgl/trafficgui.py the variables are stored and processed. The variables are set up in such a way that the data of an aircraft can be accessed with the same index as for the server traffic variables.

Adding variables

In the ui/qtgl/trafficgui.py file a variable can be added. When adding a variable, also a default value needs to be set. This is the value a newly created aircraft gets. The name of the default variable should always end with _default.

def __init__(self):
    
    ...
    
    # Variables
    self.variable_name = []  # Can be a list or numpy array
    
    ...
    
    # Defaults
    self.variable_name_default = ...  # Can be a single value or a numpy array

Accessing GUI traffic variables

The GUI traffic variables can be accessed in the ui/qtgl/gltraffic.py file. This can be done by using self.trafdata, which is shown below. More information about graphics handling can be found here.

self.trafdata.variable_name

Set GUI traffic data with commands

To set the data of a GUI traffic variable for an aircraft, first a new command should be added to the stack/basecmds.py file.

"COMMANDNAME": [
    "COMMANDNAME CALLSIGN ARGS",
    "acid, ...",
    bs.scr.commandname,
    "Command description"
],

As can be seen above, it is needed to add a function in bs.scr. This should be done in simulation/screenio.py. In the ScreenIO class the function can be added (under the # Functions part). The number of inputs of this function should match the number of inputs set in the stack/basecmds.py file. The function should then send a b'DISPLAYFLAG' event, containing a dictionary with the flag set to 'GUITRAFDATA'. The command name and the input data should be stored in a dictionary, where 'cmd' is set to the command name and the 'data' is set to the input data. The args of the event dictionary is then set to this dictionary.

def commandname(idx, ...)
    """
    Function: Command function description
    Args:
        idx: Index for traffic variables [int]
        ...
    Returns: -
    
    Created by: ...
    Date: ....
    """
    
    bs.net.send_event(b'DISPLAYFLAG', dict(flag='GUITRAFDATA', args={'cmd': "COMMANDNAME", 'data': [idx, ...]}))  # The data can be put in a list, dictionary, ... etc.

The command data should then be processed in the ui/qtgl/trafficui.py file. This should be done in the set_trafficdata function. To process the data of the new command, a new if statement should be added where it is checked if the incomming data is from the new command. Next the GUI traffic data can be set.

def set_trafficdata(self, data):
    
    ...
    
    if data.guitrafdata['cmd'] == 'COMMANDNAME':
        idx = data.guitrafdata['data'][0]
        self.variable_name[idx] = ...