示例#1
0
def init():
    # Both sim and gui need a navdatabase in all versions of BlueSky
    from bluesky.navdatabase import Navdatabase
    global navdb
    navdb = Navdatabase()

    # The remaining objects are only instantiated in the sim nodes
    if settings.is_sim:
        from bluesky.traffic import Traffic

        if settings.gui == 'pygame':
            from bluesky.ui.pygame import Screen
            from bluesky.simulation.pygame import Simulation
        else:
            from bluesky.simulation.qtgl import Simulation, ScreenIO as Screen

        from bluesky import stack
        from bluesky.tools import plugin, plotter

        # Initialize singletons
        global traf, sim, scr
        traf = Traffic()
        sim = Simulation()
        scr = Screen()

        # Initialize remaining modules
        plugin.init()
        plotter.init()
        stack.init()
示例#2
0
def init(mode='sim', pygame=False, discovery=False, cfgfile='', scnfile=''):
    """ Initialize bluesky modules.

        Arguments:
        - mode: can be 'sim', 'sim-detached', 'server-gui', 'server-headless',
          or 'client'
        - pygame: indicate if BlueSky is started with BlueSky_pygame.py
        - discovery: Enable network discovery
    """
    # Initialize global settings first, possibly loading a custom config file
    settings.init(cfgfile)

    # Is this a server running headless?
    headless = (mode[-8:] == 'headless')

    # Keep track of the gui type.
    global gui_type
    gui_type = 'pygame' if pygame else \
               'none' if headless or mode[:3] == 'sim' else 'qtgl'

    # Load navdatabase in all versions of BlueSky
    # Only the headless server doesn't need this
    if not headless:
        from bluesky.navdatabase import Navdatabase
        global navdb
        navdb = Navdatabase()

    # If mode is server-gui or server-headless start the networking server
    if mode[:6] == 'server':
        global server
        from bluesky.network import Server
        server = Server(headless)

    # The remaining objects are only instantiated in the sim nodes
    if mode[:3] == 'sim':
        # Check whether simulation node should run detached
        detached = (mode[-8:] == 'detached')
        from bluesky.traffic import Traffic

        if pygame:
            from bluesky.ui.pygame import Screen
            from bluesky.simulation.pygame import Simulation
        else:
            from bluesky.simulation.qtgl import Simulation, ScreenIO as Screen

        from bluesky import stack
        from bluesky.tools import plugin, plotter

        # Initialize singletons
        global traf, sim, scr
        traf = Traffic()
        sim = Simulation(detached)
        scr = Screen()

        # Initialize remaining modules
        plugin.init(mode)
        plotter.init()
        stack.init(scnfile)
示例#3
0
def init(mode='sim', pygame=False, discovery=False, cfgfile='', scnfile=''):
    ''' Initialize bluesky modules.

        Arguments:
        - mode: can be 'sim', 'sim-detached', 'server-gui', 'server-headless',
          or 'client'
        - pygame: indicate if BlueSky is started with BlueSky_pygame.py
        - discovery: Enable network discovery
    '''
    # Is this a server running headless?
    headless = (mode[-8:] == 'headless')

    # Keep track of the gui type.
    global gui_type
    gui_type = 'pygame' if pygame else \
               'none' if headless or mode[:3] == 'sim' else 'qtgl'

    # Initialize global settings first, possibly loading a custom config file
    settings.init(cfgfile)

    # Initialise tools
    tools.init()

    # Load navdatabase in all versions of BlueSky
    # Only the headless server doesn't need this
    if not headless:
        from bluesky.navdatabase import Navdatabase
        global navdb
        navdb = Navdatabase()

    # If mode is server-gui or server-headless start the networking server
    if mode[:6] == 'server':
        global server
        from bluesky.network.server import Server
        server = Server(discovery)

    # The remaining objects are only instantiated in the sim nodes
    if mode[:3] == 'sim':
        # Check whether simulation node should run detached
        detached = (mode[-8:] == 'detached')
        from bluesky.traffic import Traffic
        from bluesky.simulation import Simulation
        if pygame:
            from bluesky.ui.pygame import Screen
            from bluesky.network.detached import Node
        else:
            from bluesky.simulation import ScreenIO as Screen
            if detached:
                from bluesky.network.detached import Node
            else:
                from bluesky.network.node import Node

        from bluesky.core import varexplorer

        # Initialize singletons
        global traf, sim, scr, net
        traf = Traffic()
        sim = Simulation()
        scr = Screen()
        net = Node(settings.simevent_port,
                   settings.simstream_port)

        # Initialize remaining modules
        varexplorer.init()
        if scnfile:
            stack.stack(f'IC {scnfile}')

    from bluesky.core import plugin
    plugin.init(mode)
    stack.init(mode)
示例#4
0
def init(mode='sim', configfile=None, scenfile=None, discoverable=False,
         gui=None, detached=False, **kwargs):
    ''' Initialize bluesky modules.

        Arguments:

    '''

    # Keep track of mode and gui type.
    globals()['mode'] = mode
    globals()['gui'] = gui

    # Initialize global settings first, possibly loading a custom config file
    settings.init(configfile)

    # Initialise tools
    tools.init()

    # Load navdatabase in all versions of BlueSky
    # Only the headless server doesn't need this
    if mode == "sim" or gui is not None:
        from bluesky.navdatabase import Navdatabase
        global navdb
        navdb = Navdatabase()

    # If mode is server-gui or server-headless start the networking server
    if mode == 'server':
        global server
        from bluesky.network.server import Server
        server = Server(discoverable, configfile, scenfile)

    # The remaining objects are only instantiated in the sim nodes
    if mode == 'sim':
        from bluesky.traffic import Traffic
        from bluesky.simulation import Simulation
        if gui == 'pygame':
            from bluesky.ui.pygame import Screen
            from bluesky.network.detached import Node
        else:
            from bluesky.simulation import ScreenIO as Screen
            if detached:
                from bluesky.network.detached import Node
            else:
                from bluesky.network.node import Node

        from bluesky.core import varexplorer

        # Initialize singletons
        global traf, sim, scr, net
        traf = Traffic()
        sim = Simulation()
        scr = Screen()
        net = Node(settings.simevent_port,
                   settings.simstream_port)

        # Initialize remaining modules
        varexplorer.init()
        if scenfile:
            stack.stack(f'IC {scenfile}')

    from bluesky.core import plugin
    plugin.init(mode)
    stack.init(mode)
示例#5
0
def main():
    """
        Start BlueSky: This is the main entrypoint for BlueSky.
        Depending on settings and arguments passed it can start in different
        modes. The central part of BlueSky consists of a server managing all
        simulations, normally together with a gui. The different modes for this
        are:
        - server-gui: Start gui and simulation server
        - server-headless: start server without gui
        - client: start gui only, which can connect to an already running server

        A BlueSky server can start one or more simulation processes, which run
        the actual simulations. These simulations can also be started completely
        separate from all other BlueSky functionality, in the detached mode.
        This is useful when calling bluesky from within another python
        script/program. The corresponding modes are:
        - sim: The normal simulation process started by a BlueSky server
        - sim-detached: An isolated simulation node, without networking
    """
    # When importerror gives different name than (pip) install needs,
    # also advise latest version
    missingmodules = {
        "OpenGL": "pyopengl and pyopengl-accelerate",
        "PyQt4": "pyqt5"
    }

    if "--build-caches" in sys.argv:
        settings.init("")
        from bluesky.navdatabase import Navdatabase
        Navdatabase()
        return

    ### Parse command-line arguments ###
    # BlueSky.py modes:
    # server-gui: Start gui and simulation server
    # client: start gui only, which can connect to an already running server
    # server-headless: start server only
    # detached: start only one simulation node, without networking
    #   ==> useful for calling bluesky from within another python script/program
    if '--detached' in sys.argv:
        mode = 'sim-detached'
    elif '--sim' in sys.argv:
        mode = 'sim'
    elif '--client' in sys.argv:
        mode = 'client'
    elif '--headless' in sys.argv:
        mode = 'server-headless'
    else:
        mode = 'server-gui'

    discovery = ('--discoverable' in sys.argv or mode[-8:] == 'headless')

    # Check if alternate config file is passed or a default scenfile
    cfgfile = ''
    scnfile = ''
    for i in range(len(sys.argv)):
        if len(sys.argv) > i + 1:
            if sys.argv[i] == '--config-file':
                cfgfile = sys.argv[i + 1]
            elif sys.argv[i] == '--scenfile':
                scnfile = sys.argv[i + 1]

    # Catch import errors
    try:
        # Initialize bluesky modules
        bs.init(mode, discovery=discovery, cfgfile=cfgfile, scnfile=scnfile)

        # Only start a simulation node if called with --sim or --detached
        if mode[:3] == 'sim':
            bs.sim.start()
        else:
            # Only print start message in the non-sim cases to avoid printing
            # this for every started node
            print("   *****   BlueSky Open ATM simulator *****")
            print("Distributed under GNU General Public License v3")

        # Start server if server/gui or server-headless is started here
        if mode[:6] == 'server':
            if mode[-8:] == 'headless':
                bs.server.run()
            else:
                bs.server.start()

        # Start gui if client or main server/gui combination is started here
        if mode in ('client', 'server-gui'):
            from bluesky.ui import qtgl
            qtgl.start(mode)

    # Give info on missing module
    except ImportError as error:
        modulename = missingmodules.get(error.name) or error.name
        if modulename is None:
            raise error
        print("Bluesky needs", modulename)
        print("Install using e.g. pip install", modulename)