Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
""" Start the mainloop (and possible other threads) """
splash.show()
bs.init(pygame=True)
bs.sim.operate()
bs.scr.init()
# Main loop for BlueSky
while not bs.sim.mode == bs.sim.end:
bs.sim.update() # Update sim
bs.scr.update() # GUI update
# Restart traffic simulation:
if bs.sim.mode == bs.sim.init:
bs.sim.reset()
bs.scr.objdel() # Delete user defined objects
bs.sim.stop()
pg.quit()
print('BlueSky normal end.')
def defwpt(self,name=None,lat=None,lon=None,wptype=None):
# Prevent polluting the database: check arguments
if name==None or name=="":
return False,"Insufficient arguments"
elif name.isdigit():
return False,"Name needs to start with an alphabetical character"
# No data: give info on waypoint
elif lat==None or lon==None:
reflat, reflon = bs.scr.getviewctr()
if self.wpid.count(name.upper()) > 0:
i = self.getwpidx(name.upper(),reflat,reflon)
txt = self.wpid[i]+" : "+str(self.wplat[i])+","+str(self.wplon[i])
if len(self.wptype[i]+self.wpco[i])>0:
txt = txt+" "+self.wptype[i]+" in "+self.wpco[i]
return True,txt
# Waypoint name is free
else:
return True,"Waypoint "+name.upper()+" does not yet exist."
# Still here? So there is data, then we add this waypoint
self.wpid.append(name.upper())
self.wplat = np.append(self.wplat,lat)
self.wplon = np.append(self.wplon,lon)
nextarg, args = getnextarg(args)
name = curargu + "/" + nextarg.upper()
# Return something different for the two argtypes:
# wpt argument type: simply return positiontext, no need it look up nw
if argtype == "wpt":
result = [name]
# lat/lon argument type we also need to it up:
elif argtype == "latlon":
# Set default reference lat,lon for duplicate name in navdb to screen
if (
Argparser.reflat < -180.0
): # No reference avaiable yet: use screen center
Argparser.reflat, Argparser.reflon = bs.scr.getviewctr()
success, posobj = txt2pos(name, Argparser.reflat, Argparser.reflon)
if success:
# for runway type, get heading as default optional argument for command line
if posobj.type == "rwy":
aptname, rwyname = name.split("/RW")
rwyname = rwyname.lstrip("Y")
try:
self.additional["hdg"] = bs.navdb.rwythresholds[aptname][
rwyname
][2]
except:
pass
# Update reference lat/lon
lines = lines + " from " + self.ap.orig[idx]
if self.ap.dest[idx] != "":
lines = lines + " to " + self.ap.dest[idx]
# Show a/c info and highlight route of aircraft in radar window
# and pan to a/c (to show route)
bs.scr.showroute(acid)
return True, lines
# Waypoint: airport, navaid or fix
else:
wp = idxorwp.upper()
# Reference position for finding nearest
reflat, reflon = bs.scr.getviewctr()
lines = "Info on "+wp+":\n"
# First try airports (most used and shorter, hence faster list)
iap = bs.navdb.getaptidx(wp)
if iap>=0:
aptypes = ["large","medium","small"]
lines = lines + bs.navdb.aptname[iap]+"\n" \
+ "is a "+ aptypes[max(-1,bs.navdb.aptype[iap]-1)] \
+" airport at:\n" \
+ latlon2txt(bs.navdb.aptlat[iap], \
bs.navdb.aptlon[iap]) + "\n" \
+ "Elevation: " \
+ str(int(round(bs.navdb.aptelev[iap]/ft))) \
+ " ft \n"
def show_performance(self, acid):
bs.scr.echo("Flight phase: %s" % ph.readable_phase(self.phase[acid]))
bs.scr.echo("Thrust: %d kN" % (self.thrust[acid] / 1000))
bs.scr.echo("Drag: %d kN" % (self.drag[acid] / 1000))
bs.scr.echo("Fuel flow: %.2f kg/s" % self.fuelflow[acid])
bs.scr.echo("Speed envelope: [%d, %d] m/s" % (self.vmin[acid], self.vmax[acid]))
bs.scr.echo(
"Vertical speed envelope: [%d, %d] m/s"
% (self.vsmin[acid], self.vsmax[acid])
)
bs.scr.echo("Ceiling: %d km" % (self.hmax[acid] / 1000))
# self.drag.astype(int)
def show_performance(self, acid):
bs.scr.echo("Flight phase: %s" % ph.readable_phase(self.phase[acid]))
bs.scr.echo("Thrust: %d kN" % (self.thrust[acid] / 1000))
bs.scr.echo("Drag: %d kN" % (self.drag[acid] / 1000))
bs.scr.echo("Fuel flow: %.2f kg/s" % self.fuelflow[acid])
bs.scr.echo("Speed envelope: [%d, %d] m/s" % (self.vmin[acid], self.vmax[acid]))
bs.scr.echo(
"Vertical speed envelope: [%d, %d] m/s"
% (self.vsmin[acid], self.vsmax[acid])
)
bs.scr.echo("Ceiling: %d km" % (self.hmax[acid] / 1000))
# self.drag.astype(int)
self.wpid.append(name.upper())
self.wplat = np.append(self.wplat,lat)
self.wplon = np.append(self.wplon,lon)
if wptype == None:
self.wptype.append("")
else:
self.wptype.append(wptype)
self.wpelev.append(0.0) # elevation [m]
self.wpvar.append(0.0) # magn variation [deg]
self.wpfreq.append(0.0) # frequency [kHz/MHz]
self.wpdesc.append("Custom waypoint") # description
# Update screen info
bs.scr.addnavwpt(name.upper(),lat,lon)
return True,name.upper()+" added to navdb."
lines += "LNAV to " + route.wpname[route.iactwp] + "\n"
# Flight info: Destination and origin
if self.ap.orig[idx] != "" or self.ap.dest[idx] != "":
lines = lines + "Flying"
if self.ap.orig[idx] != "":
lines = lines + " from " + self.ap.orig[idx]
if self.ap.dest[idx] != "":
lines = lines + " to " + self.ap.dest[idx]
# Show a/c info and highlight route of aircraft in radar window
# and pan to a/c (to show route)
bs.scr.showroute(acid)
return True, lines
# Waypoint: airport, navaid or fix
else:
wp = idxorwp.upper()
# Reference position for finding nearest
reflat, reflon = bs.scr.getviewctr()
lines = "Info on "+wp+":\n"
# First try airports (most used and shorter, hence faster list)
iap = bs.navdb.getaptidx(wp)
if iap>=0:
aptypes = ["large","medium","small"]
lines = lines + bs.navdb.aptname[iap]+"\n" \
"DTNOLOOK": [
"DTNOLOOK [time]",
"[float]",
bs.traf.asas.SetDtNoLook,
"Set interval for conflict detection",
],
"DUMPRTE": [
"DUMPRTE acid",
"acid",
lambda idx: bs.traf.ap.route[idx].dumpRoute(idx),
"Write route to output/routelog.txt",
],
"ECHO": [
"ECHO txt",
"string",
bs.scr.echo,
"Show a text in command window for user to read",
],
"ENG": [
"ENG acid,[engine_id]",
"acid,[txt]",
bs.traf.perf.engchange,
"Specify a different engine type",
],
"FF": [
"FF [timeinsec]",
"[time]",
bs.sim.fastforward,
"Fast forward the simulation",
],
"FILTERALT": [
"FILTERALT ON/OFF,[bottom,top]",
bs.scr.zoom(sqrt(2.0))
elif event.button==5:
bs.scr.zoom(0.5*sqrt(2.0))
# Mouse motion: drag edit/menu window with mouse, if necessary
# Check also for mouse button 1
elif event.type==pg.MOUSEMOTION and \
(self.dragedit or self.dragpotmenu or self.dragmenu):
if self.dragedit:
pressed = pg.mouse.get_pressed()[0]
if not pressed:
self.dragedit = False
else:
bs.scr.editwin.winx = event.pos[0]-self.dragdx
bs.scr.editwin.winy = event.pos[1]-self.dragdy
bs.scr.editwin.rect = pg.Rect(bs.scr.editwin.winx,bs.scr.editwin.winy, \
bs.scr.editwin.bmpdx,bs.scr.editwin.bmpdy)
bs.scr.redrawedit = True
elif self.dragpotmenu:
pressed = pg.mouse.get_pressed()[0]
if not pressed:
self.dragpotmenu = False
self.dragmenu = False
else:
mx,my = pg.mouse.get_pos()
outside = not bs.scr.menu.rect.collidepoint((mx,my))
if outside and pressed:
self.dragmenu = True
self.dragpotmenu = False
elif self.dragmenu: