1
/***************************************************************************
2
* Copyright (C) 2005 by Robin Gingras *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
25
#define M_PI 3.14159265358979323846
32
#include "qgpssatellitetracker.h"
34
QGPSSatelliteTracker::QGPSSatelliteTracker(QWidget *parent)
35
: QWidget(parent), Heading(0)
39
void QGPSSatelliteTracker::setSatellites(const std::vector<Satellite>& aList)
45
void QGPSSatelliteTracker::setHeading(int x)
52
* private void QGPSSatelliteTracker::paintEvent()
54
* Does the actual drawing of the widget. Reads the satArray array to
55
* get satellite positions and PRNs. Reads the satActive array to get
56
* which satellites are being used.
58
* @param QPaintEvent * Ignored by this function
61
void QGPSSatelliteTracker::paintEvent(QPaintEvent *)
63
QPainter painter(this);
64
painter.setRenderHint(QPainter::Antialiasing);
65
painter.translate(width()/2,height()/2);
73
painter.setPen(QPen(palette().mid(), 1, Qt::SolidLine));
74
painter.setBrush(QBrush(Qt::black, Qt::NoBrush));
76
// first paint the two reference circles, one at 0 degrees, and
77
// the other at 45 degrees
78
painter.drawEllipse(-rad,-rad, rad*2,rad*2);
79
painter.drawEllipse(-rad/2,-rad/2,rad,rad);
81
// now the reference lines, one vertical and the other horizontal
82
painter.drawLine(-rad,0,rad,0);
83
painter.drawLine(0,-rad,0,rad);
88
painter.setPen(QPen(QColor(240,32,32),3,Qt::SolidLine,Qt::RoundCap));
89
float Alfa = Heading-90;
90
Alfa = Alfa*3.141592/180;
91
float fx = cos(Alfa)*rad*3/4;
92
float fy = sin(Alfa)*rad*3/4;
93
painter.drawLine(0,0,int(fx),int(fy));
94
painter.drawLine(int(fx),int(fy),
95
int(fx+cos(Alfa+3.1415*5/6)*8),int(fy+sin(Alfa+3.1415*5/6)*8));
96
painter.drawLine(int(fx),int(fy),
97
int(fx+cos(Alfa-3.1415*5/6)*8),int(fy+sin(Alfa-3.1415*5/6)*8));
101
// now plot the satellites
102
painter.setPen(QPen(palette().foreground(), 2, Qt::SolidLine));
103
painter.setBrush(QBrush(palette().foreground()));
106
for (unsigned int i=0; i<List.size(); ++i)
108
if(List[i].SignalStrength > 0)
110
getCoordsFromPos(rad,List[i].Elevation,List[i].Azimuth, x, y);
112
painter.drawEllipse(x - 2, y - 2, 4, 4);
113
painter.drawText(x + 5, y - 1, QString("%1").arg(List[i].Id));
119
* private void QGPSSatelliteTracker::getCoordsFromPos()
121
* Inputs and elevation and azimuth, and translates them to coordinates
122
* that QPainter can use. This one took some thought, but I think it's
123
* correct. Satellites jump around, maybe a problem?
125
* @param int elevation Elevation of the satellite in degrees, 0 - 90
126
* @param int azimuth Azimuth of the satellite in degrees, 0 - 360
127
* @param int &x Pointer to x-coordinate
128
* @param int &y Pointer to y-coordinate
131
void QGPSSatelliteTracker::getCoordsFromPos(int rad, int elevation, int azimuth, int &x, int &y)
133
int theta = azimuth-90;
135
// since the "origin" of the sky is 90 (directly overhead), reverse
136
// elevation to make the origin 0 (an elevation of 90 becomes 0, etc)
137
elevation = 90 - elevation;
139
// you should know this (slept too much in trig)
140
x = int(cos(theta*M_PI/180) * elevation * rad / 90);
141
y = int(sin(theta*M_PI/180) * elevation * rad / 90);