Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# lat,lon type ?
if name.count(",")>0: #lat,lon or apt,rwy type
txt1,txt2 = name.split(",")
if islat(txt1):
self.lat = txt2lat(txt1)
self.lon = txt2lon(txt2)
self.name = ""
self.type ="latlon"
# runway type ? "EHAM/RW06","EHGG/RWY27"
elif name.count("/RW")>0:
try:
aptname,rwytxt = name.split("/RW")
rwyname = rwytxt.lstrip("Y").upper() # remove Y and spaces
self.lat,self.lon = bs.navdb.rwythresholds[aptname][rwyname][:2] # raises error if not found
except:
self.error = True
self.type = "rwy"
# airport?
elif bs.navdb.aptid.count(name)>0:
idx = bs.navdb.aptid.index(name.upper())
self.lat = bs.navdb.aptlat[idx]
self.lon = bs.navdb.aptlon[idx]
self.type ="apt"
# fix or navaid?
elif bs.navdb.wpid.count(name)>0:
idx = bs.navdb.getwpidx(name,reflat,reflon)
self.lat = bs.navdb.wplat[idx]
self.rwyline = []
self.rwytotime = []
for runwayname in cmdargs:
if runwayname[0] == "R":
success, rwyposobj = txt2pos(self.name + "/" + runwayname, self.lat, self.lon)
else:
success,rwyposobj = txt2pos(self.name+"/RW"+runwayname,self.lat,self.lon)
if success:
self.runways.append(runwayname)
self.rwylat.append(rwyposobj.lat)
self.rwylon.append(rwyposobj.lon)
rwyname = runwayname.upper().lstrip('RWY')
#try:
if True:
self.rwyhdg.append(navdb.rwythresholds[self.name][rwyname][2])
#if self.name=="EHAM":
#S print("runway added with hdg:",self.rwyhdg[-1])
#except:
# success = False
self.rwyline.append(0)
self.rwytotime.append(-999.)
else:
self.runways.append(runwayname)
self.rwylat.append(self.lat)
self.rwylon.append(self.lon)
rwydigits = runwayname.lstrip("RWY").rstrip("LCR")
self.rwyhdg.append(10. * int(rwydigits.rstrip("LCR").lstrip("0")))
self.rwyline.append(0)
self.rwytotime.append(-999.)
( 0.0, 0.8 * wpt_size),
(-0.2 * wpt_size, 0.2 * wpt_size),
(-0.8 * wpt_size, 0.0)], dtype=np.float32)
self.rwaypoints = RenderObject(gl.GL_LINE_LOOP, vertex=rwptvertices, color=palette.route)
self.rwaypoints.bind_attrib(ATTRIB_LAT, 1, self.routewplatbuf, instance_divisor=1)
self.rwaypoints.bind_attrib(ATTRIB_LON, 1, self.routewplonbuf, instance_divisor=1)
# --------Aircraft Trails------------------------------------------------
self.traillines = RenderObject(gl.GL_LINES, vertex=self.trailbuf, color=palette.trails)
# ------- Waypoints ------------------------------
wptvertices = np.array([(0.0, 0.5 * wpt_size), (-0.5 * wpt_size, -0.5 * wpt_size), (0.5 * wpt_size, -0.5 * wpt_size)], dtype=np.float32) # a triangle
self.nwaypoints = len(bs.navdb.wplat)
self.waypoints = RenderObject(gl.GL_LINE_LOOP, vertex=wptvertices, color=palette.wptsymbol, n_instances=self.nwaypoints)
# Sort based on id string length
llid = sorted(zip(bs.navdb.wpid, bs.navdb.wplat, bs.navdb.wplon), key=lambda i: len(i[0]) > 3)
wpidlst, wplat, wplon = zip(*llid)
self.wptlatbuf = self.waypoints.bind_attrib(ATTRIB_LAT, 1, np.array(wplat, dtype=np.float32), instance_divisor=1)
self.wptlonbuf = self.waypoints.bind_attrib(ATTRIB_LON, 1, np.array(wplon, dtype=np.float32), instance_divisor=1)
wptids = ''
self.nnavaids = 0
for wptid in wpidlst:
if len(wptid) <= 3:
self.nnavaids += 1
wptids += wptid[:5].ljust(5)
npwpids = np.array(wptids, dtype=np.string_)
self.wptlabels = self.font.prepare_text_instanced(npwpids, (5, 1), self.wptlatbuf, self.wptlonbuf, char_size=text_size, vertex_offset=(wpt_size, 0.5 * wpt_size))
self.wptlabels.bind_color(palette.wptlabel)
del wptids
self.customwp = RenderObject(gl.GL_LINE_LOOP, vertex=wptvertices, color=palette.wptsymbol)
self.customwp.bind_attrib(ATTRIB_LAT, 1, self.custwplatbuf, instance_divisor=1)
self.customwp.bind_attrib(ATTRIB_LON, 1, self.custwplonbuf, instance_divisor=1)
# Lat/lon: wpname is then call sign of aircraft: add number
if wptype == Route.wplatlon:
newname = Route.get_available_name(
self.wpname, name, 3)
# Else make data complete with nav database and closest to given lat,lon
else: # so wptypewpnav
newname = wprtename
if not wptype == Route.runway:
i = bs.navdb.getwpidx(name, lat, lon)
wpok = (i >= 0)
if wpok:
wplat = bs.navdb.wplat[i]
wplon = bs.navdb.wplon[i]
else:
i = bs.navdb.getaptidx(name)
wpok = (i >= 0)
if wpok:
wplat = bs.navdb.aptlat[i]
wplon = bs.navdb.aptlon[i]
# Check if afterwp or beforewp is specified and found:
aftwp = afterwp.upper().strip() # Remove space, upper case
bfwp = beforewp.upper().strip()
if wpok:
if (afterwp and self.wpname.count(aftwp) > 0) or \
(beforewp and self.wpname.count(bfwp) > 0):
# print len(self.cstsel[0])," coastlines"
self.cx0, self.cy0 = self.ll2xy(self.coastlat0, self.coastlon0)
self.cx1, self.cy1 = self.ll2xy(self.coastlat1, self.coastlon1)
for i in list(self.cstsel[0]):
pg.draw.line(self.radbmp, grey, (self.cx0[i], self.cy0[i]), \
(self.cx1[i], self.cy1[i]))
#------ Draw FIRs ------
if self.swfir:
self.firx0, self.firy0 = self.ll2xy(bs.navdb.firlat0, \
bs.navdb.firlon0)
self.firx1, self.firy1 = self.ll2xy(bs.navdb.firlat1, \
bs.navdb.firlon1)
for i in range(len(self.firx0)):
pg.draw.line(self.radbmp, lightcyan,
(self.firx0[i], self.firy0[i]),
(self.firx1[i], self.firy1[i]))
# -----------------Waypoint & airport symbols-----------------
# Check whether we need to reselect waypoint set to be drawn
navsel = (self.lat0, self.lat1, \
self.lon0, self.lon1)
if self.navsel != navsel:
self.navsel = navsel
# Make list of indices of waypoints & airports on screen
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"
# Show country name
try:
ico = bs.navdb.cocode2.index(bs.navdb.aptco[iap].upper())
lines = lines + "in "+bs.navdb.coname[ico]+" ("+ \
bs.navdb.aptco[iap]+")"
except:
ico = -1
lines = lines + "Country code: "+bs.navdb.aptco[iap]
try:
runways = bs.navdb.rwythresholds[bs.navdb.aptid[iap]].keys()
if runways:
lines = lines + "\nRunways: " + ", ".join(runways)
for wptid in wpidlst:
if len(wptid) <= 3:
self.nnavaids += 1
wptids += wptid[:5].ljust(5)
npwpids = np.array(wptids, dtype=np.string_)
self.wptlabels = self.font.prepare_text_instanced(npwpids, (5, 1), self.wptlatbuf, self.wptlonbuf, char_size=text_size, vertex_offset=(wpt_size, 0.5 * wpt_size))
self.wptlabels.bind_color(palette.wptlabel)
del wptids
self.customwp = RenderObject(gl.GL_LINE_LOOP, vertex=wptvertices, color=palette.wptsymbol)
self.customwp.bind_attrib(ATTRIB_LAT, 1, self.custwplatbuf, instance_divisor=1)
self.customwp.bind_attrib(ATTRIB_LON, 1, self.custwplonbuf, instance_divisor=1)
self.customwplbl = self.font.prepare_text_instanced(self.custwplblbuf, (10, 1), self.custwplatbuf, self.custwplonbuf, char_size=text_size, vertex_offset=(wpt_size, 0.5 * wpt_size))
self.customwplbl.bind_color(palette.wptlabel)
# ------- Airports -------------------------------
aptvertices = np.array([(-0.5 * apt_size, -0.5 * apt_size), (0.5 * apt_size, -0.5 * apt_size), (0.5 * apt_size, 0.5 * apt_size), (-0.5 * apt_size, 0.5 * apt_size)], dtype=np.float32) # a square
self.nairports = len(bs.navdb.aptlat)
self.airports = RenderObject(gl.GL_LINE_LOOP, vertex=aptvertices, color=palette.aptsymbol, n_instances=self.nairports)
indices = bs.navdb.aptype.argsort()
aplat = np.array(bs.navdb.aptlat[indices], dtype=np.float32)
aplon = np.array(bs.navdb.aptlon[indices], dtype=np.float32)
aptypes = bs.navdb.aptype[indices]
apnames = np.array(bs.navdb.aptid)
apnames = apnames[indices]
# The number of large, large+med, and large+med+small airports
self.nairports = [aptypes.searchsorted(2), aptypes.searchsorted(3), self.nairports]
self.aptlatbuf = self.airports.bind_attrib(ATTRIB_LAT, 1, aplat, instance_divisor=1)
self.aptlonbuf = self.airports.bind_attrib(ATTRIB_LON, 1, aplon, instance_divisor=1)
aptids = ''
for aptid in apnames:
aptids += aptid.ljust(4)
self.aptlabels = self.font.prepare_text_instanced(np.array(aptids, dtype=np.string_), (4, 1), self.aptlatbuf, self.aptlonbuf, char_size=text_size, vertex_offset=(apt_size, 0.5 * apt_size))
idx = 0 if orig else self.nwp - 1
# NORMAL: Wptype is normal waypoint? (lat/lon or nav)
else:
# Lat/lon: wpname is then call sign of aircraft: add number
if wptype == Route.wplatlon:
newname = Route.get_available_name(
self.wpname, name, 3)
# Else make data complete with nav database and closest to given lat,lon
else: # so wptypewpnav
newname = wprtename
if not wptype == Route.runway:
i = bs.navdb.getwpidx(name, lat, lon)
wpok = (i >= 0)
if wpok:
wplat = bs.navdb.wplat[i]
wplon = bs.navdb.wplon[i]
else:
i = bs.navdb.getaptidx(name)
wpok = (i >= 0)
if wpok:
wplat = bs.navdb.aptlat[i]
wplon = bs.navdb.aptlon[i]
# Check if afterwp or beforewp is specified and found:
aftwp = afterwp.upper().strip() # Remove space, upper case
bfwp = beforewp.upper().strip()
def setdestorig(self, cmd, idx, *args):
if len(args) == 0:
if cmd == 'DEST':
return True, 'DEST ' + bs.traf.id[idx] + ': ' + self.dest[idx]
else:
return True, 'ORIG ' + bs.traf.id[idx] + ': ' + self.orig[idx]
if idx<0 or idx>=bs.traf.ntraf:
return False, cmd + ": Aircraft does not exist."
route = self.route[idx]
name = args[0]
apidx = bs.navdb.getaptidx(name)
if apidx < 0:
if cmd =="DEST" and bs.traf.ap.route[idx].nwp>0:
reflat = bs.traf.ap.route[idx].wplat[-1]
reflon = bs.traf.ap.route[idx].wplon[-1]
else:
reflat = bs.traf.lat[idx]
reflon = bs.traf.lon[idx]
success, posobj = txt2pos(name, reflat, reflon)
if success:
lat = posobj.lat
lon = posobj.lon
else:
return False, (cmd + ": Position " + name + " not found.")
# Check whether we need to reselect waypoint set to be drawn
navsel = (self.lat0, self.lat1, \
self.lon0, self.lon1)
if self.navsel != navsel:
self.navsel = navsel
# Make list of indices of waypoints & airports on screen
self.wpinside = list(np.where(self.onradar(bs.navdb.wplat, \
bs.navdb.wplon))[0])
self.wptsel = []
for i in self.wpinside:
if self.wpsw == 3 or \
(self.wpsw == 1 and len(bs.navdb.wpid[i]) == 3) or \
(self.wpsw == 2 and bs.navdb.wpid[i].isalpha()):
self.wptsel.append(i)
self.wptx, self.wpty = self.ll2xy(bs.navdb.wplat, bs.navdb.wplon)
self.apinside = list(np.where(self.onradar(bs.navdb.aptlat, \
bs.navdb.aptlon))[0])
self.aptsel = []
for i in self.apinside:
if self.apsw == 2 or (self.apsw == 1 and \
bs.navdb.aptmaxrwy[i] > 1000.):
self.aptsel.append(i)
self.aptx, self.apty = self.ll2xy(bs.navdb.aptlat, bs.navdb.aptlon)
#------- Draw waypoints -------