Merge branch 'az_map'

This commit is contained in:
Nick Foster 2012-10-29 09:28:30 -07:00
commit 90c8ba5a10
5 changed files with 1239 additions and 938 deletions

View File

@ -85,6 +85,9 @@ class mainwindow(QtGui.QMainWindow):
self.ui.list_aircraft.setModel(self.datamodel) self.ui.list_aircraft.setModel(self.datamodel)
self.ui.list_aircraft.setModelColumn(0) self.ui.list_aircraft.setModelColumn(0)
self.az_model = air_modes.az_map_model(None)
self.ui.azimuth_map.setModel(self.az_model)
#set up dashboard views #set up dashboard views
self.icaodelegate = ICAOViewDelegate() self.icaodelegate = ICAOViewDelegate()
self.ui.list_aircraft.setItemDelegate(self.icaodelegate) self.ui.list_aircraft.setItemDelegate(self.icaodelegate)
@ -276,9 +279,13 @@ class mainwindow(QtGui.QMainWindow):
self.outputs.append(rawport.output) self.outputs.append(rawport.output)
self.updates.append(rawport.add_pending_conns) self.updates.append(rawport.add_pending_conns)
#add azimuth map output and hook it up
if my_position is not None:
self.az_map_output = air_modes.az_map_output(my_position, self.az_model)
self.outputs.append(self.az_map_output.output)
self.livedata = air_modes.output_print(my_position) self.livedata = air_modes.output_print(my_position)
#add output for live data box #add output for live data box
#TODO: this doesn't handle large volumes of data well; i get segfaults.
self.outputs.append(self.output_live_data) self.outputs.append(self.output_live_data)
#create SQL database for KML and dashboard displays #create SQL database for KML and dashboard displays
@ -317,6 +324,13 @@ class mainwindow(QtGui.QMainWindow):
#slot to catch signal emitted by output_live_data (necessary for #slot to catch signal emitted by output_live_data (necessary for
#thread safety since output_live_data is called by another thread) #thread safety since output_live_data is called by another thread)
def on_append_live_data(self, msgstr): def on_append_live_data(self, msgstr):
#limit scrollback buffer size -- is there a faster way?
if(self.ui.text_livedata.document().lineCount() > 500):
cursor = self.ui.text_livedata.textCursor()
cursor.movePosition(QtGui.QTextCursor.Start)
cursor.select(QtGui.QTextCursor.LineUnderCursor)
cursor.removeSelectedText()
self.ui.text_livedata.append(msgstr) self.ui.text_livedata.append(msgstr)
self.ui.text_livedata.verticalScrollBar().setSliderPosition(self.ui.text_livedata.verticalScrollBar().maximum()) self.ui.text_livedata.verticalScrollBar().setSliderPosition(self.ui.text_livedata.verticalScrollBar().maximum())

View File

@ -32,6 +32,7 @@ GR_PYTHON_INSTALL(
FILES FILES
__init__.py __init__.py
altitude.py altitude.py
az_map.py
cpr.py cpr.py
mlat.py mlat.py
exceptions.py exceptions.py

View File

@ -59,6 +59,7 @@ from sbs1 import output_sbs1
from kml import output_kml from kml import output_kml
from raw_server import raw_server from raw_server import raw_server
from exceptions import * from exceptions import *
from az_map import *
#this is try/excepted in case the user doesn't have numpy installed #this is try/excepted in case the user doesn't have numpy installed
try: try:
from flightgear import output_flightgear from flightgear import output_flightgear

237
python/az_map.py Executable file
View File

@ -0,0 +1,237 @@
#!/usr/bin/env python
#
# Copyright 2012 Nick Foster
#
# This file is part of gr-air-modes
#
# gr-air-modes is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# gr-air-modes is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with gr-air-modes; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
# azimuthal projection widget to plot reception range vs. azimuth
from PyQt4 import QtCore, QtGui
import threading
import math
import air_modes
# model has max range vs. azimuth in n-degree increments
# contains separate max range for a variety of altitudes so
# you can determine your altitude dropouts by bearing
# assumes that if you can hear ac at 1000', you can hear at 5000'+.
class az_map_model(QtCore.QObject):
dataChanged = QtCore.pyqtSignal(name='dataChanged')
npoints = 360/5
def __init__(self, parent=None):
super(az_map_model, self).__init__(parent)
self._data = []
self.lock = threading.Lock()
self._altitudes = [0, 1000, 2000, 5000, 10000, 15000, 20000, 25000, 30000]
#initialize everything to 0
for i in range(0,az_map_model.npoints):
self._data.append([0] * len(self._altitudes))
def rowCount(self):
return len(self._data)
def columnCount(self):
return len(self._altitudes)
def data(self, row, col):
return self._data[row][col]
def addRecord(self, bearing, altitude, distance):
with self.lock:
#round up to nearest altitude in altitudes list
#there's probably another way to do it
if altitude >= max(self._altitudes):
col = self.columnCount()-1
else:
col = self._altitudes.index(min([alt for alt in self._altitudes if alt >= altitude]))
#find which bearing row we sit in
row = int(int(bearing+(180./az_map_model.npoints)) / (360./az_map_model.npoints)) % az_map_model.npoints
#set max range for all alts >= the ac alt
#this expresses the assumption that higher ac can be heard further
update = False
for i in range(col, len(self._altitudes)):
if distance > self._data[row][i]:
self._data[row][i] = distance
update = True
if update:
self.dataChanged.emit()
def reset(self):
with self.lock:
self._data = []
for i in range(0,az_map_model.npoints):
self._data.append([0] * len(self._altitudes))
self.dataChanged.emit()
# the azimuth map widget
class az_map(QtGui.QWidget):
maxrange = 450
ringsize = 100
bgcolor = QtCore.Qt.black
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):
super(az_map, self).__init__(parent)
self._model = None
self._paths = []
self.maxrange = az_map.maxrange
self.ringsize = az_map.ringsize
def minimumSizeHint(self):
return QtCore.QSize(50, 50)
def sizeHint(self):
return QtCore.QSize(300, 300)
def setModel(self, model):
self._model = model
self._model.dataChanged.connect(self.repaint)
def paintEvent(self, event):
painter = QtGui.QPainter(self)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
#TODO: make it not have to redraw paths EVERY repaint
#drawing paths is VERY SLOW
#maybe use a QTimer to limit repaints
self.drawPaths()
#set background
painter.fillRect(event.rect(), QtGui.QBrush(az_map.bgcolor))
#draw the range rings
self.drawRangeRings(painter)
for i in range(len(self._paths)):
alpha = 230 * (i+1) / (len(self._paths)) + 25
painter.setPen(QtGui.QPen(QtGui.QColor(alpha,alpha,0,255), 1.0))
painter.drawPath(self._paths[i])
def drawPaths(self):
self._paths = []
if(self._model):
for alt in range(0, self._model.columnCount()):
path = QtGui.QPainterPath()
for i in range(az_map_model.npoints-1,-1,-1):
#bearing is to start point of arc (clockwise)
bearing = (i+0.5) * 360./az_map_model.npoints
distance = self._model._data[i][alt]
radius = min(self.width(), self.height()) / 2.0
scale = radius * distance / self.maxrange
#convert bearing,distance to x,y
xpts = scale * math.sin(bearing * math.pi / 180)
ypts = scale * math.cos(bearing * math.pi / 180)
#get the bounding rectangle of the arc
arcrect = QtCore.QRectF(QtCore.QPointF(0-scale, 0-scale),
QtCore.QPointF(scale, scale))
if path.isEmpty():
path.moveTo(xpts, 0-ypts) #so we don't get a line from 0,0 to the first point
else:
path.lineTo(xpts, 0-ypts)
path.arcTo(arcrect, 90-bearing, 360./az_map_model.npoints)
self._paths.append(path)
def drawRangeRings(self, painter):
painter.translate(self.width()/2, self.height()/2)
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,
-diameter / 2.0, diameter, diameter))
def setMaxRange(self, maxrange):
self.maxrange = maxrange
self.drawPath()
def setRingSize(self, ringsize):
self.ringsize = ringsize
self.drawPath()
class az_map_output(air_modes.parse):
def __init__(self, mypos, model):
air_modes.parse.__init__(self, mypos)
self.model = model
def output(self, msg):
[data, ecc, reference, timestamp] = msg.split()
data = air_modes.modes_reply(long(data, 16))
ecc = long(ecc, 16)
rssi = 10.*math.log10(float(reference))
msgtype = data["df"]
now = time.time()
if msgtype == 17:
icao = data["aa"]
subtype = data["ftc"]
distance, altitude, bearing = [0,0,0]
if 5 <= subtype <= 8:
(ground_track, decoded_lat, decoded_lon, distance, bearing) = self.parseBDS06(data)
altitude = 0
elif 9 <= subtype <= 18:
(altitude, decoded_lat, decoded_lon, distance, bearing) = self.parseBDS05(data)
self.model.addRecord(bearing, altitude, distance)
##############################
# Test stuff
##############################
import random, time
class model_updater(threading.Thread):
def __init__(self, model):
super(model_updater, self).__init__()
self.model = model
self.setDaemon(1)
self.done = False
self.start()
def run(self):
for i in range(az_map_model.npoints):
time.sleep(0.005)
if(self.model):
for alt in self.model._altitudes:
self.model.addRecord(i*360./az_map_model.npoints, alt, random.randint(0,az_map.maxrange)*alt / max(self.model._altitudes))
self.done = True
class Window(QtGui.QWidget):
def __init__(self):
super(Window, self).__init__()
layout = QtGui.QGridLayout()
self.model = az_map_model()
mymap = az_map(None)
mymap.setModel(self.model)
self.updater = model_updater(self.model)
layout.addWidget(mymap, 0, 1)
self.setLayout(layout)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
window.update()
sys.exit(app.exec_())

View File

@ -6,27 +6,94 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>686</width> <width>687</width>
<height>418</height> <height>422</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>MainWindow</string> <string>MainWindow</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>Visible aircraft</string>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="list_aircraft">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="layoutMode">
<enum>QListView::SinglePass</enum>
</property>
<property name="selectionRectVisible">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTabWidget" name="tab_dataview"> <widget class="QTabWidget" name="tab_dataview">
<property name="geometry"> <property name="sizePolicy">
<rect> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<x>130</x> <horstretch>1</horstretch>
<y>30</y> <verstretch>1</verstretch>
<width>551</width> </sizepolicy>
<height>301</height>
</rect>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>3</number>
</property>
<widget class="QWidget" name="setup">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
<string>Setup</string> <string>Setup</string>
</attribute> </attribute>
@ -234,10 +301,6 @@
<string>Filename</string> <string>Filename</string>
</property> </property>
</widget> </widget>
<zorder>line_inputfile</zorder>
<zorder>label_13</zorder>
<zorder>combo_rate</zorder>
<zorder>label_27</zorder>
</widget> </widget>
</widget> </widget>
</widget> </widget>
@ -842,118 +905,97 @@
</property> </property>
</widget> </widget>
</widget> </widget>
<widget class="QWidget" name="browsertab"> <widget class="QWidget" name="azimuth_tab">
<attribute name="title"> <attribute name="title">
<string>Data browser</string> <string>Azimuth map</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="az_map" name="azimuth_map" native="true"/>
</item>
</layout>
</widget> </widget>
<widget class="QWidget" name="livedatatab"> <widget class="QWidget" name="livedatatab">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="title"> <attribute name="title">
<string>Live data</string> <string>Live data</string>
</attribute> </attribute>
<widget class="QTextEdit" name="text_livedata"> <layout class="QGridLayout" name="gridLayout_4">
<property name="geometry"> <item row="0" column="0">
<rect> <widget class="QTextEdit" name="text_livedata"/>
<x>5</x> </item>
<y>11</y> </layout>
<width>531</width>
<height>251</height>
</rect>
</property>
</widget> </widget>
</widget> </widget>
</widget> </item>
<widget class="QLabel" name="label_14"> </layout>
<property name="geometry"> </item>
<rect> <item row="1" column="0">
<x>19</x> <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1,0,0,0">
<y>36</y> <item>
<width>101</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Visible aircraft</string>
</property>
</widget>
<widget class="QPushButton" name="button_start">
<property name="geometry">
<rect>
<x>580</x>
<y>340</y>
<width>98</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
<widget class="QCheckBox" name="check_adsbonly"> <widget class="QCheckBox" name="check_adsbonly">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="geometry">
<rect>
<x>4</x>
<y>344</y>
<width>271</width>
<height>22</height>
</rect>
</property>
<property name="text"> <property name="text">
<string>Show ADS-B-equipped aircraft only</string> <string>Show ADS-B-equipped aircraft only</string>
</property> </property>
</widget> </widget>
<widget class="QListView" name="list_aircraft"> </item>
<property name="geometry"> <item>
<rect> <spacer name="horizontalSpacer">
<x>18</x> <property name="orientation">
<y>59</y> <enum>Qt::Horizontal</enum>
<width>101</width>
<height>272</height>
</rect>
</property> </property>
<property name="editTriggers"> <property name="sizeHint" stdset="0">
<set>QAbstractItemView::NoEditTriggers</set> <size>
</property> <width>40</width>
<property name="layoutMode">
<enum>QListView::SinglePass</enum>
</property>
<property name="selectionRectVisible">
<bool>true</bool>
</property>
</widget>
<widget class="QLineEdit" name="line_reports">
<property name="geometry">
<rect>
<x>520</x>
<y>341</y>
<width>41</width>
<height>27</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_33">
<property name="geometry">
<rect>
<x>407</x>
<y>345</y>
<width>111</width>
<height>20</height> <height>20</height>
</rect> </size>
</property> </property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_33">
<property name="text"> <property name="text">
<string>Reports/second</string> <string>Reports/second</string>
</property> </property>
</widget> </widget>
</item>
<item>
<widget class="QLineEdit" name="line_reports">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_start">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget> </widget>
<widget class="QMenuBar" name="menubar"> <widget class="QMenuBar" name="menubar">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>686</width> <width>687</width>
<height>25</height> <height>25</height>
</rect> </rect>
</property> </property>
@ -971,6 +1013,12 @@
<extends>QWidget</extends> <extends>QWidget</extends>
<header>qwt_dial.h</header> <header>qwt_dial.h</header>
</customwidget> </customwidget>
<customwidget>
<class>az_map</class>
<extends>QWidget</extends>
<header location="global">air_modes/az_map</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>