-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgps_bar_plot.py
151 lines (124 loc) · 5.24 KB
/
gps_bar_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# This file is part of Camino.
# Copyright (C) 2017 Manuel Luitz <[email protected]>
#
# Camino 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 of the License, or
# (at your option) any later version.
#
# Camino 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 Camino. If not, see <http://www.gnu.org/licenses/>.
#
from PyQt4 import QtCore, QtGui
import gpgsv
class GPSBarPlot(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
# Bars
self.barWidth = 15
self.barLineWidth = 2
self.barDistance = 10
self.barTextDistance = 3
self.xBarOffset = 5
# Margins
self.bottomMargin = 40
self.topMargin = 10
self.leftMargin = 40
self.rightMargin = 10
# Axes
self.axesColor = QtGui.QColor(50,50,50,255)
self.axesLineWidth = 2
self.range = [0,60]
self.yticsFreq = 10
self.yticsDist = 25
self.xticsDist = 18
# grid
self.grid = True
self.gridLineWidth = 1
self.gridColor = QtGui.QColor(200,200,200,255)
# Bar Colors
self.labelColor = QtCore.Qt.black
self.barBorderColor = QtGui.QColor(60, 60, 60, 255)
self.barColor1 = QtGui.QColor(0, 153, 0, 255)
self.barColor2 = QtGui.QColor(0, 76, 153, 255)
# Background color
self.setAutoFillBackground(True)
palette = self.palette()
palette.setColor(self.backgroundRole(), QtCore.Qt.white)
self.setPalette(palette)
self.data = []
def updateData(self, gpgsvMessage):
self.data = gpgsvMessage
self.update()
def resetData(self):
self.data = []
self.update()
def drawAxes(self, painter):
# set color and width of line drawing pen
painter.setPen(QtGui.QPen(self.axesColor, self.axesLineWidth))
# axis: drawLine(x1, y1, x2, y2) from point (x1,y1) to (x2,y2)
# x-axis
painter.drawLine(self.leftMargin, self.h-self.bottomMargin, self.w-self.rightMargin, self.h-self.bottomMargin)
# y-axis
painter.drawLine(self.leftMargin, self.topMargin, self.leftMargin, self.h - self.bottomMargin)
# draw y-ticks
for i in range(0, self.range[1], self.yticsFreq):
y = self.h - self.bottomMargin - self.yscale * i
painter.drawLine(self.leftMargin, y, self.leftMargin-4, y)
s = "{: >3d}".format(i)
painter.drawText(self.leftMargin - self.yticsDist, y+4, s)
# draw x-ticks
for x in range(self.leftMargin + self.barDistance + self.xBarOffset + self.barWidth/2, self.w-self.rightMargin, self.barWidth + self.barDistance):
painter.drawLine(x, self.h - self.bottomMargin, x, self.h-self.bottomMargin + 4)
painter.rotate(-90)
painter.drawText(-(self.h+self.bottomMargin)/2.-20, 13, "SNR (dB-Hz)")
painter.rotate(90)
painter.drawText((self.leftMargin + self.w)/2. - 25, self.h-3, "Satellite ID")
def drawGrid(self, painter):
painter.setPen(QtGui.QPen(self.gridColor, self.gridLineWidth))
# draw y grid
for i in range(0, self.range[1], self.yticsFreq):
y = self.h - self.bottomMargin - self.yscale * i
painter.drawLine(self.leftMargin, y, self.w-self.rightMargin, y)
def paintEvent(self, event):
# Get dimensions
self.w = self.frameGeometry().width()
self.h = self.frameGeometry().height()
self.yspace = self.h - self.bottomMargin - self.topMargin
self.yscale = float(self.yspace)/self.range[1]
painter = QtGui.QPainter()
painter.begin(self)
# Grid
if self.grid: self.drawGrid(painter)
# Axes
self.drawAxes(painter)
# set up color and width of the bars
delta = self.barWidth + self.barDistance
x = self.barDistance + self.xBarOffset + self.leftMargin
for satellite in self.data:
if satellite.isTracking():
painter.setBrush(self.barColor1)
else:
painter.setBrush(self.barColor2)
# correct for width
y = self.h - self.bottomMargin - ( satellite.getSnr() * self.yscale ) - (self.axesLineWidth )/2.
barHeight = satellite.getSnr() * self.yscale
# draw each bar
painter.setPen(QtGui.QPen(self.barBorderColor, self.barLineWidth))
painter.drawRect(x, y, self.barWidth, barHeight)
# Draw labels
painter.setPen(QtGui.QPen(self.labelColor, self.barLineWidth))
s = "{: >2d}".format(satellite.getSnr())
painter.drawText(x, y-self.barTextDistance, s)
s = "{: >2d}".format(satellite.getPrnId())
painter.drawText(x, self.h - self.bottomMargin + self.xticsDist, s)
x += delta
painter.end()