summaryrefslogtreecommitdiff
path: root/xgpsspeed
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-01-17 09:57:47 -0500
committerEric S. Raymond <esr@thyrsus.com>2013-01-17 09:57:47 -0500
commit8d8e44c1a1b164d7c041671117e23f05ac85cabc (patch)
tree37dfecf0b27b7fb764b26e534b021550e2bd76d0 /xgpsspeed
parent3ee9482af36577554f3311bea78a99d2d1298fce (diff)
downloadgpsd-8d8e44c1a1b164d7c041671117e23f05ac85cabc.tar.gz
Information hiding.
Diffstat (limited to 'xgpsspeed')
-rwxr-xr-xxgpsspeed88
1 files changed, 43 insertions, 45 deletions
diff --git a/xgpsspeed b/xgpsspeed
index 1cbf3881..fcaca783 100755
--- a/xgpsspeed
+++ b/xgpsspeed
@@ -245,23 +245,10 @@ class Speedometer(gtk.DrawingArea):
def get_radius(self, width, height):
return min(width / 2.0, height / 2.0) - 20
-HEADING_SAT_GAP = 0.8
-GPS_PRNMAX = 32 # Above this number are SBAS satellites
-SAT_SIZE = 10 # radius of the satellite circle in skyview
-
-
-def polar2xy(radius, angle, polex, poley):
- '''convert Polar coordinate to Cartesian coordinate system
- the y axis in pygtk points downward
- Args:
- radius:
- angle: azimuth from from Polar coordinate system, in radian
- polex and poley are the Cartesian coordinate of the pole
- return a tuple contains (x, y)'''
- return (polex + cos(angle) * radius, poley - sin(angle) * radius)
-
-
class SpeedAndTrack(gtk.DrawingArea):
+ HEADING_SAT_GAP = 0.8
+ GPS_PRNMAX = 32 # Above this number are SBAS satellites
+ SAT_SIZE = 10 # radius of the satellite circle in skyview
def __init__(self, speed_unit=None, maxspeed=100):
gtk.DrawingArea.__init__(self)
self.connect('expose_event', self.expose_event)
@@ -288,6 +275,17 @@ class SpeedAndTrack(gtk.DrawingArea):
'%s is not a valid speed unit'
% (repr(speed_unit)))
+ @staticmethod
+ def polar2xy(radius, angle, polex, poley):
+ '''convert Polar coordinate to Cartesian coordinate system
+ the y axis in pygtk points downward
+ Args:
+ radius:
+ angle: azimuth from from Polar coordinate system, in radian
+ polex and poley are the Cartesian coordinate of the pole
+ return a tuple contains (x, y)'''
+ return (polex + cos(angle) * radius, poley - sin(angle) * radius)
+
def expose_event(self, unused, event, empty=None):
self.cr = self.window.cairo_create()
self.cr.rectangle(
@@ -304,7 +302,7 @@ class SpeedAndTrack(gtk.DrawingArea):
self.draw_arc_and_ticks(width, height, radius, x, y)
self.draw_heading(20, self.last_heading, radius, x, y)
for sat in self.satellites:
- self.draw_sat(sat, radius * HEADING_SAT_GAP, x, y)
+ self.draw_sat(sat, radius * SpeedAndTrack.HEADING_SAT_GAP, x, y)
self.draw_speed(radius, x, y)
def draw_text(self, x, y, text, fontsize=10):
@@ -343,12 +341,12 @@ class SpeedAndTrack(gtk.DrawingArea):
for i in xrange(11):
#draw the large ticks
alpha = (8 - i) * pi / 6
- self.cr.move_to(*polar2xy(rspeed, alpha, x, y))
+ self.cr.move_to(*SpeedAndTrack.polar2xy(rspeed, alpha, x, y))
self.cr.set_line_width(radius / 100)
- self.cr.line_to(*polar2xy(rspeed - s_long, alpha, x, y))
+ self.cr.line_to(*SpeedAndTrack.polar2xy(rspeed - s_long, alpha, x, y))
self.cr.stroke()
self.cr.set_line_width(radius / 200)
- xf, yf = polar2xy(rspeed + 10, alpha, x, y)
+ xf, yf = SpeedAndTrack.polar2xy(rspeed + 10, alpha, x, y)
stxt = (self.maxspeed / 10) * i
self.draw_text(xf, yf, stxt, fontsize=radius / 15)
@@ -356,14 +354,14 @@ class SpeedAndTrack(gtk.DrawingArea):
# middle tick
alpha = (8 - i) * pi / 6
beta = (17 - 2 * i) * pi / 12
- self.cr.move_to(*polar2xy(rspeed, beta, x, y))
- self.cr.line_to(*polar2xy(rspeed - s_middle, beta, x, y))
+ self.cr.move_to(*SpeedAndTrack.polar2xy(rspeed, beta, x, y))
+ self.cr.line_to(*SpeedAndTrack.polar2xy(rspeed - s_middle, beta, x, y))
# short tick
for n in xrange(10):
gamma = alpha + n * pi / 60
- self.cr.move_to(*polar2xy(rspeed, gamma, x, y))
- self.cr.line_to(*polar2xy(rspeed - s_short, gamma, x, y))
+ self.cr.move_to(*SpeedAndTrack.polar2xy(rspeed, gamma, x, y))
+ self.cr.line_to(*SpeedAndTrack.polar2xy(rspeed - s_short, gamma, x, y))
#draw the heading arc
self.cr.new_sub_path()
@@ -378,15 +376,15 @@ class SpeedAndTrack(gtk.DrawingArea):
for n in xrange(0, 4):
label = str(n * 90)
#self.cr.set_source_rgba(0, 1, 0)
- #radius * (1 + HEADING_SAT_GAP),
- tbox_x, tbox_y = polar2xy(radius * 0.88,
+ #radius * (1 + SpeedAndTrack.HEADING_SAT_GAP),
+ tbox_x, tbox_y = SpeedAndTrack.polar2xy(radius * 0.88,
(1 - n) * pi / 2,
x, y)
self.draw_text(tbox_x, tbox_y,
label, fontsize=radius / 20)
# draw the satellite arcs
- skyradius = radius * HEADING_SAT_GAP
+ skyradius = radius * SpeedAndTrack.HEADING_SAT_GAP
self.cr.set_line_width(radius / 200)
self.cr.set_source_rgba(0, 0, 0)
self.cr.arc(x, y, skyradius, 0, 2 * pi)
@@ -412,22 +410,22 @@ class SpeedAndTrack(gtk.DrawingArea):
#draw the large ticks
for i in xrange(12):
agllong = i * pi / 6
- self.cr.move_to(*polar2xy(radius - long_inset, agllong, x, y))
- self.cr.line_to(*polar2xy(radius, agllong, x, y))
+ self.cr.move_to(*SpeedAndTrack.polar2xy(radius - long_inset, agllong, x, y))
+ self.cr.line_to(*SpeedAndTrack.polar2xy(radius, agllong, x, y))
self.cr.set_line_width(radius / 100)
self.cr.stroke()
self.cr.set_line_width(radius / 200)
# middle tick
aglmid = (i + 0.5) * pi / 6
- self.cr.move_to(*polar2xy(radius - mid_inset, aglmid, x, y))
- self.cr.line_to(*polar2xy(radius, aglmid, x, y))
+ self.cr.move_to(*SpeedAndTrack.polar2xy(radius - mid_inset, aglmid, x, y))
+ self.cr.line_to(*SpeedAndTrack.polar2xy(radius, aglmid, x, y))
# short tick
for n in xrange(1, 10):
aglshrt = agllong + n * pi / 60
- self.cr.move_to(*polar2xy(radius - short_inset, aglshrt, x, y))
- self.cr.line_to(*polar2xy(radius, aglshrt, x, y))
+ self.cr.move_to(*SpeedAndTrack.polar2xy(radius - short_inset, aglshrt, x, y))
+ self.cr.line_to(*SpeedAndTrack.polar2xy(radius, aglshrt, x, y))
self.cr.stroke()
def draw_heading(self, trig_height, heading, radius, x, y):
@@ -455,16 +453,16 @@ class SpeedAndTrack(gtk.DrawingArea):
self.cr.stroke()
# heading text
- (tbox_x, tbox_y) = polar2xy(radius * 1.1, h, x, y)
+ (tbox_x, tbox_y) = SpeedAndTrack.polar2xy(radius * 1.1, h, x, y)
self.draw_text(tbox_x, tbox_y, int(heading), fontsize=radius / 15)
# the ship shape, based on test and try
- shiplen = radius * HEADING_SAT_GAP / 4
- xh, yh = polar2xy(shiplen * 2.3, h, x, y)
- xa, ya = polar2xy(shiplen * 2.2, h + pi - 0.3, x, y)
- xb, yb = polar2xy(shiplen * 2.2, h + pi + 0.3, x, y)
- xc, yc = polar2xy(shiplen * 1.4, h - pi / 5, x, y)
- xd, yd = polar2xy(shiplen * 1.4, h + pi / 5, x, y)
+ shiplen = radius * SpeedAndTrack.HEADING_SAT_GAP / 4
+ xh, yh = SpeedAndTrack.polar2xy(shiplen * 2.3, h, x, y)
+ xa, ya = SpeedAndTrack.polar2xy(shiplen * 2.2, h + pi - 0.3, x, y)
+ xb, yb = SpeedAndTrack.polar2xy(shiplen * 2.2, h + pi + 0.3, x, y)
+ xc, yc = SpeedAndTrack.polar2xy(shiplen * 1.4, h - pi / 5, x, y)
+ xd, yd = SpeedAndTrack.polar2xy(shiplen * 1.4, h + pi / 5, x, y)
self.cr.set_source_rgba(0, 0.3, 0.2, 0.5)
self.cr.move_to(xa, ya)
@@ -493,14 +491,14 @@ class SpeedAndTrack(gtk.DrawingArea):
self.cr.set_line_width(2)
self.cr.set_source_rgb(0, 0, 0)
- x0, y0 = polar2xy(radius * (90 - satsoup['el']) / 90, h, x, y)
+ x0, y0 = SpeedAndTrack.polar2xy(radius * (90 - satsoup['el']) / 90, h, x, y)
self.cr.new_sub_path()
- if satsoup['PRN'] > GPS_PRNMAX:
- self.cr.rectangle(x0 - SAT_SIZE, y0 - SAT_SIZE,
- SAT_SIZE * 2, SAT_SIZE * 2)
+ if satsoup['PRN'] > SpeedAndTrack.GPS_PRNMAX:
+ self.cr.rectangle(x0 - SpeedAndTrack.SAT_SIZE, y0 - SpeedAndTrack.SAT_SIZE,
+ SpeedAndTrack.SAT_SIZE * 2, SpeedAndTrack.SAT_SIZE * 2)
else:
- self.cr.arc(x0, y0, SAT_SIZE, 0, pi * 2.0)
+ self.cr.arc(x0, y0, SpeedAndTrack.SAT_SIZE, 0, pi * 2.0)
if satsoup['ss'] < 10:
self.set_color('Gray')