コード例 #1
0
    def reset(self):
        self.samplecount = 0
        self.prevcount = 0
        self.prevtime = 0.0

        # Communicate reset to gui
        manager.sendEvent(DisplayFlagEvent('RESET', 'ALL'))
コード例 #2
0
    def objappend(self, objtype, objname, data_in):
        """Add a drawing object to the radar screen using the following inpouts:
           objtype: "LINE"/"POLY" /"BOX"/"CIRCLE" = string with type of object
           objname: string with a name as key for reference
           objdata: lat,lon data, depending on type:
                    POLY/LINE: lat0,lon0,lat1,lon1,lat2,lon2,....
                    BOX : lat0,lon0,lat1,lon1   (bounding box coordinates)
                    CIRCLE: latctr,lonctr,radiusnm  (circle parameters)
        """
        if data_in is None:
            # This is an object delete event
            data = None

        elif objtype == 'LINE' or objtype[:4] == 'POLY':
            # Input data is laist or array: [lat0,lon0,lat1,lon1,lat2,lon2,lat3,lon3,..]
            data = np.array(data_in, dtype=np.float32)

        elif objtype == 'BOX':
            # Convert box coordinates into polyline list
            # BOX: 0 = lat0, 1 = lon0, 2 = lat1, 3 = lon1 , use bounding box
            data = np.array([
                data_in[0], data_in[1], data_in[0], data_in[3], data_in[2],
                data_in[3], data_in[2], data_in[1]
            ],
                            dtype=np.float32)

        elif objtype == 'CIRCLE':
            # Input data is latctr,lonctr,radius[nm]
            # Convert circle into polyline list

            # Circle parameters
            Rearth = 6371000.0  # radius of the Earth [m]
            numPoints = 72  # number of straight line segments that make up the circrle

            # Inputs
            lat0 = data_in[0]  # latitude of the center of the circle [deg]
            lon0 = data_in[1]  # longitude of the center of the circle [deg]
            Rcircle = data_in[2] * 1852.0  # radius of circle [NM]

            # Compute flat Earth correction at the center of the experiment circle
            coslatinv = 1.0 / np.cos(np.deg2rad(lat0))

            # compute the x and y coordinates of the circle
            angles = np.linspace(0.0, 2.0 * np.pi,
                                 numPoints)  # ,endpoint=True) # [rad]

            # Calculate the circle coordinates in lat/lon degrees.
            # Use flat-earth approximation to convert from cartesian to lat/lon.
            latCircle = lat0 + np.rad2deg(
                Rcircle * np.sin(angles) / Rearth)  # [deg]
            lonCircle = lon0 + np.rad2deg(
                Rcircle * np.cos(angles) * coslatinv / Rearth)  # [deg]

            # make the data array in the format needed to plot circle
            data = np.empty(2 * numPoints,
                            dtype=np.float32)  # Create empty array
            data[0::2] = latCircle  # Fill array lat0,lon0,lat1,lon1....
            data[1::2] = lonCircle

        manager.sendEvent(DisplayShapeEvent(objname, data))
コード例 #3
0
    def send_route_data(self):
        if manager.isActive() and self.route_acid is not None:
            data = RouteDataEvent()
            data.acid = self.route_acid
            idx = bs.traf.id2idx(self.route_acid)
            if idx >= 0:
                route = bs.traf.ap.route[idx]
                data.iactwp = route.iactwp

                # We also need the corresponding aircraft position
                data.aclat = bs.traf.lat[idx]
                data.aclon = bs.traf.lon[idx]

                data.wplat = route.wplat
                data.wplon = route.wplon

                data.wpalt = route.wpalt
                data.wpspd = route.wpspd

                data.wpname = route.wpname

            manager.sendEvent(data)  # Send route data to GUI
            # Empty route acid string means no longer send route data
            if len(self.route_acid) == 0:
                self.route_acid = None
コード例 #4
0
 def zoom(self, zoom, absolute=True):
     if manager.isActive():
         if absolute:
             self.scrzoom = zoom
         else:
             self.scrzoom *= zoom
         manager.sendEvent(PanZoomEvent(zoom=zoom, absolute=absolute))
コード例 #5
0
 def batch(self, filename):
     # The contents of the scenario file are meant as a batch list: send to manager and clear stack
     result = stack.openfile(filename)
     scentime, scencmd = stack.get_scendata()
     if result is True:
         manager.sendEvent(BatchEvent(scentime, scencmd))
     self.reset()
     return result
コード例 #6
0
 def send_siminfo(self):
     t = time.time()
     dt = np.maximum(t - self.prevtime, 0.00001)  # avoid divide by 0
     speed = (self.samplecount - self.prevcount) / dt * bs.sim.simdt
     manager.sendEvent(
         SimInfoEvent(speed, bs.sim.simdt, bs.sim.simt, bs.sim.simtclock,
                      bs.traf.ntraf, bs.sim.state, stack.get_scenname()))
     self.prevtime = t
     self.prevcount = self.samplecount
コード例 #7
0
    def pan(self, *args):
        ''' Move center of display, relative of to absolute position lat,lon '''
        if manager.isActive():
            if args[0] == "LEFT":
                self.ctrlon -= 0.5
            elif args[0] == "RIGHT":
                self.ctrlon += 0.5
            elif args[0] == "UP" or args[0] == "ABOVE":
                self.ctrlat += 0.5
            elif args[0] == "DOWN":
                self.ctrlat -= 0.5
            else:
                self.ctrlat, self.ctrlon = args

            manager.sendEvent(
                PanZoomEvent(pan=(self.ctrlat, self.ctrlon), absolute=True))
コード例 #8
0
    def send_aircraft_data(self):
        if manager.isActive():
            data = ACDataEvent()
            data.simt = bs.sim.simt
            data.id = bs.traf.id
            data.lat = bs.traf.lat
            data.lon = bs.traf.lon
            data.alt = bs.traf.alt
            data.tas = bs.traf.tas
            data.cas = bs.traf.cas
            data.iconf = bs.traf.asas.iconf
            data.confcpalat = bs.traf.asas.latowncpa
            data.confcpalon = bs.traf.asas.lonowncpa
            data.trk = bs.traf.hdg

            # Trails, send only new line segments to be added
            data.swtrails = bs.traf.trails.active
            data.traillat0 = bs.traf.trails.newlat0
            data.traillon0 = bs.traf.trails.newlon0
            data.traillat1 = bs.traf.trails.newlat1
            data.traillon1 = bs.traf.trails.newlon1
            bs.traf.trails.clearnew()

            # Last segment which is being built per aircraft
            data.traillastlat = list(bs.traf.trails.lastlat)
            data.traillastlon = list(bs.traf.trails.lastlon)

            # Conflict statistics
            data.nconf_tot = len(bs.traf.asas.conflist_all)
            data.nlos_tot = len(bs.traf.asas.LOSlist_all)
            data.nconf_exp = len(bs.traf.asas.conflist_exp)
            data.nlos_exp = len(bs.traf.asas.LOSlist_exp)
            data.nconf_cur = len(bs.traf.asas.conflist_now)
            data.nlos_cur = len(bs.traf.asas.LOSlist_now)

            manager.sendEvent(data)
コード例 #9
0
 def show_cmd_doc(self, cmd=''):
     if manager.isActive():
         manager.sendEvent(ShowDialogEvent(1, cmd=cmd))
コード例 #10
0
 def show_file_dialog(self):
     if manager.isActive():
         manager.sendEvent(ShowDialogEvent())
     return ''
コード例 #11
0
 def showssd(self, *param):
     ''' Conflict prevention display
         Show solution space diagram, indicating potential conflicts'''
     if manager.isActive():
         manager.sendEvent(DisplayFlagEvent('SSD', param))
コード例 #12
0
 def addnavwpt(self, name, lat, lon):
     ''' Add custom waypoint to visualization '''
     manager.sendEvent(DisplayFlagEvent('DEFWPT', (name, lat, lon)))
     return True
コード例 #13
0
 def trails(self, sw):
     if manager.isActive():
         manager.sendEvent(DisplayFlagEvent('TRAIL', sw))
コード例 #14
0
    def doWork(self):
        self.syst = int(time.time() * 1000.0)
        self.fixdt = self.simdt

        # Send list of stack functions available in this sim to gui at start
        stackdict = {
            cmd: val[0][len(cmd) + 1:]
            for cmd, val in stack.cmddict.iteritems()
        }
        manager.sendEvent(StackInitEvent(stackdict))

        while self.running:
            if self.state == Simulation.op:
                # Plugins pre-update
                plugin.preupdate(self.simt)
                # Datalog pre-update (communicate current sim time to loggers)
                datalog.preupdate(self.simt)

            # Update screen logic
            bs.scr.update()

            # Simulation starts as soon as there is traffic, or pending commands
            if self.state == Simulation.init:
                if bs.traf.ntraf > 0 or len(stack.get_scendata()[0]) > 0:
                    self.start()
                    if self.benchdt > 0.0:
                        self.fastforward(self.benchdt)
                        self.bencht = time.time()

            if self.state == Simulation.op:
                stack.checkfile(self.simt)

            # Always update stack
            stack.process()

            if self.state == Simulation.op:

                bs.traf.update(self.simt, self.simdt)

                # Update metrics
                self.metric.update()

                # Update plugins
                plugin.update(self.simt)

                # Update loggers
                datalog.postupdate()

                # Update time for the next timestep
                self.simt += self.simdt

            # Update clock
            self.simtclock = (self.deltclock + self.simt) % onedayinsec

            # Process Qt events
            manager.processEvents()

            # When running at a fixed rate, or when in hold/init, increment system time with sysdt and calculate remainder to sleep
            if not self.ffmode or not self.state == Simulation.op:
                self.syst += self.sysdt
                remainder = self.syst - int(1000.0 * time.time())

                if remainder > 0:
                    QThread.msleep(remainder)

            elif self.ffstop is not None and self.simt >= self.ffstop:
                if self.benchdt > 0.0:
                    bs.scr.echo(
                        'Benchmark complete: %d samples in %.3f seconds.' %
                        (self.screenio.samplecount, time.time() - self.bencht))
                    self.benchdt = -1.0
                    self.pause()
                else:
                    self.start()

            # Inform main of our state change
            if not self.state == self.prevstate:
                self.sendState()
                self.prevstate = self.state
コード例 #15
0
 def echo(self, text):
     if manager.isActive():
         manager.sendEvent(StackTextEvent(disptext=text))
コード例 #16
0
 def feature(self, switch, argument=''):
     if manager.isActive():
         manager.sendEvent(DisplayFlagEvent(switch, argument))
コード例 #17
0
 def cmdline(self, text):
     if manager.isActive():
         manager.sendEvent(StackTextEvent(cmdtext=text))
コード例 #18
0
 def filteralt(self, *args):
     manager.sendEvent(DisplayFlagEvent('FILTERALT', args))
コード例 #19
0
 def symbol(self):
     if manager.isActive():
         manager.sendEvent(DisplayFlagEvent('SYM'))
コード例 #20
0
 def sendState(self):
     manager.sendEvent(SimStateEvent(self.state))