Merge branch 'az_map' into next

This commit is contained in:
Nick Foster 2013-07-22 18:23:35 -07:00
commit 3540114c94

View File

@ -27,7 +27,7 @@ import threading
import math import math
import air_modes import air_modes
from air_modes.exceptions import * from air_modes.exceptions import *
import numpy as np
# model has max range vs. azimuth in n-degree increments # model has max range vs. azimuth in n-degree increments
# contains separate max range for a variety of altitudes so # contains separate max range for a variety of altitudes so
@ -85,18 +85,15 @@ class az_map_model(QtCore.QObject):
# the azimuth map widget # the azimuth map widget
class az_map(QtGui.QWidget): class az_map(QtGui.QWidget):
maxrange = 450 maxrange = 200
ringsize = 100
bgcolor = QtCore.Qt.black bgcolor = QtCore.Qt.black
ringpen = QtGui.QPen(QtGui.QColor(0, 96, 127, 255), 1.3) ringpen = QtGui.QPen(QtGui.QColor(0, 96, 127, 255), 1.3)
#rangepen = QtGui.QPen(QtGui.QColor(255, 255, 0, 255), 1.0)
def __init__(self, parent=None): def __init__(self, parent=None):
super(az_map, self).__init__(parent) super(az_map, self).__init__(parent)
self._model = None self._model = None
self._paths = [] self._paths = []
self.maxrange = az_map.maxrange self.maxrange = az_map.maxrange
self.ringsize = az_map.ringsize
def minimumSizeHint(self): def minimumSizeHint(self):
return QtCore.QSize(50, 50) return QtCore.QSize(50, 50)
@ -136,7 +133,7 @@ class az_map(QtGui.QWidget):
bearing = (i+0.5) * 360./az_map_model.npoints bearing = (i+0.5) * 360./az_map_model.npoints
distance = self._model._data[i][alt] distance = self._model._data[i][alt]
radius = min(self.width(), self.height()) / 2.0 radius = min(self.width(), self.height()) / 2.0
scale = radius * distance / self.maxrange scale = radius * distance / self.get_range()
#convert bearing,distance to x,y #convert bearing,distance to x,y
xpts = scale * math.sin(bearing * math.pi / 180) xpts = scale * math.sin(bearing * math.pi / 180)
ypts = scale * math.cos(bearing * math.pi / 180) ypts = scale * math.cos(bearing * math.pi / 180)
@ -153,21 +150,34 @@ class az_map(QtGui.QWidget):
self._paths.append(path) self._paths.append(path)
#this is just to add a little buffer space for showing the ring & range
def get_range(self):
return int(self.maxrange * 1.1)
def drawRangeRings(self, painter): def drawRangeRings(self, painter):
painter.translate(self.width()/2, self.height()/2) painter.translate(self.width()/2, self.height()/2)
#choose intelligent range step -- keep it between 3-5 rings
rangestep = 100
while self.get_range() / rangestep < 3:
rangestep /= 2.0
for i in np.arange(rangestep, self.get_range(), rangestep):
diameter = (float(i) / self.get_range()) * min(self.width(), self.height())
painter.setPen(az_map.ringpen) painter.setPen(az_map.ringpen)
for i in range(0, self.maxrange, self.ringsize):
diameter = (float(i) / az_map.maxrange) * min(self.width(), self.height())
painter.drawEllipse(QtCore.QRectF(-diameter / 2.0, painter.drawEllipse(QtCore.QRectF(-diameter / 2.0,
-diameter / 2.0, diameter, diameter)) -diameter / 2.0, diameter, diameter))
painter.setPen(QtGui.QColor(255,127,0,255))
painter.drawText(0-70/2.0, diameter/2.0, 70, 30, QtCore.Qt.AlignHCenter,
"%.1fnm" % i)
def setMaxRange(self, maxrange): def setMaxRange(self, maxrange):
maxrange = max(3.25, maxrange)
maxrange = min(500., maxrange)
self.maxrange = maxrange self.maxrange = maxrange
self.drawPath() self.repaint()
def setRingSize(self, ringsize): def wheelEvent(self, event):
self.ringsize = ringsize self.setMaxRange(self.maxrange + (event.delta()/120.)*self.maxrange/4.)
self.drawPath()
class az_map_output: class az_map_output:
def __init__(self, cprdec, model, pub): def __init__(self, cprdec, model, pub):
@ -177,10 +187,8 @@ class az_map_output:
def output(self, msg): def output(self, msg):
try: try:
msgtype = msg.data["df"]
now = time.time() now = time.time()
if msgtype == 17:
icao = msg.data["aa"] icao = msg.data["aa"]
subtype = msg.data["ftc"] subtype = msg.data["ftc"]
distance, altitude, bearing = [0,0,0] distance, altitude, bearing = [0,0,0]