-
Notifications
You must be signed in to change notification settings - Fork 1
/
aprsDisplay.cpp
235 lines (207 loc) · 7.02 KB
/
aprsDisplay.cpp
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include <QtGui>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#endif
#include "aprsDisplay.hpp"
#include "APRS.hpp"
#include "qDFProjReport.hpp"
#include "CoordSysBuilder.hpp"
// Display class for APRS
// Constructor
aprsDisplay::aprsDisplay(APRS * theAPRS, QPlainTextEdit *theTextEdit)
:theAPRS_(theAPRS),
aprsPacketsTextEdit_(theTextEdit)
{
CoordSysBuilder myCSB;
QString myCSName="WGS84 Lat/Lon";
// APRS always uses WGS84 no matter what our other settings may be
myCS_ = myCSB.getCoordSys(myCSName);
}
// public implementations of qDFDisplayInterface methods
void aprsDisplay::initializeDisplay()
{
// no need to initialize anything
}
void aprsDisplay::clearDisplay()
{
QStringList foo=theAPRS_->deleteAllObjects();
foreach(QString str,foo)
{
displayAPRSText_(str);
}
}
void aprsDisplay::closeDisplay()
{
clearDisplay();
}
void aprsDisplay::displayDFReport(const qDFProjReport *theReport)
{
if (theReport->isValid())
{
DFLib::Proj::Point tempPoint=theReport->getReceiverPoint();
tempPoint.setUserProj(myCS_.getProj4Params());
std::vector<double> coords(2);
coords=tempPoint.getUserCoords();
QString oName=theReport->getReportNameQS();
QString aprsPosit=theAPRS_->createDFObject(oName,coords,
theReport->getBearing(),
theReport->getSigma(),
" via qDF");
displayAPRSText_(aprsPosit);
}
else
{
undisplayDFReport(theReport);
}
}
void aprsDisplay::undisplayDFReport(const qDFProjReport *theReport)
{
QString oName=theReport->getReportNameQS();
QString aprsPosit=theAPRS_->deleteObject(oName);
if (!aprsPosit.isEmpty()) displayAPRSText_(aprsPosit);
}
void aprsDisplay::displayLSFix(DFLib::Proj::Point & LSFixPoint)
{
DFLib::Proj::Point tempPoint = LSFixPoint;
tempPoint.setUserProj(myCS_.getProj4Params());
std::vector<double> LS_point=tempPoint.getUserCoords();
aprsPointObject_("LS-Fix",LS_point,"Ln"," Least Squares Solution");
}
void aprsDisplay::undisplayLSFix()
{
deleteAPRSObject_("LS-Fix");
}
void aprsDisplay::displayFCAFix(DFLib::Proj::Point & FCAFixPoint, std::vector<double> stddevs)
{
DFLib::Proj::Point tempPoint = FCAFixPoint;
tempPoint.setUserProj(myCS_.getProj4Params());
std::vector<double> FCA_point=tempPoint.getUserCoords();
aprsPointObject_("FCA-Fix",FCA_point,"An"," Fix Cut Average Solution");
if (stddevs[0] != 0 && stddevs[1]!=0)
{
aprsDFErrorObject_("FCA-err", FCA_point,stddevs);
}
}
void aprsDisplay::undisplayFCAFix()
{
deleteAPRSObject_("FCA-Fix");
deleteAPRSObject_("FCA-err");
}
void aprsDisplay::displayMLFix(DFLib::Proj::Point & MLFixPoint,
double am2, double bm2, double phi)
{
DFLib::Proj::Point tempPoint = MLFixPoint;
tempPoint.setUserProj(myCS_.getProj4Params());
std::vector<double> ML_point=tempPoint.getUserCoords();
aprsPointObject_("ML-Fix",ML_point,"Mn"," Maximum Likelihood Solution");
aprsRotatedEllipse_("MLErr50",MLFixPoint,am2,bm2,phi,50);
aprsRotatedEllipse_("MLErr75",MLFixPoint,am2,bm2,phi,75);
aprsRotatedEllipse_("MLErr95",MLFixPoint,am2,bm2,phi,95);
}
void aprsDisplay::undisplayMLFix()
{
deleteAPRSObject_("ML-Fix");
deleteAPRSObject_("MLErr50");
deleteAPRSObject_("MLErr75");
deleteAPRSObject_("MLErr95");
}
void aprsDisplay::displayBPEFix(DFLib::Proj::Point & BPEFixPoint,
double am2, double bm2, double phi)
{
DFLib::Proj::Point tempPoint = BPEFixPoint;
tempPoint.setUserProj(myCS_.getProj4Params());
std::vector<double> BPE_point=tempPoint.getUserCoords();
aprsPointObject_("BPE-Fix",BPE_point,"Sn"," Stansfield BPE");
aprsRotatedEllipse_("SErr50",BPEFixPoint,am2,bm2,phi,50);
aprsRotatedEllipse_("SErr75",BPEFixPoint,am2,bm2,phi,75);
aprsRotatedEllipse_("SErr95",BPEFixPoint,am2,bm2,phi,95);
}
void aprsDisplay::undisplayBPEFix()
{
deleteAPRSObject_("BPE-Fix");
deleteAPRSObject_("SErr50");
deleteAPRSObject_("SErr75");
deleteAPRSObject_("SErr95");
}
// Private methods
void aprsDisplay::displayAPRSText_(const QString & str)
{
aprsPacketsTextEdit_->insertPlainText(str);
aprsPacketsTextEdit_->insertPlainText("\n");
}
void aprsDisplay::aprsPointObject_(const QString &oName,
const std::vector<double>& oPoint,
const QString &oSym,
const QString & oComment)
{
QString aprsPosit=theAPRS_->createObject(oName,oPoint,oSym,oComment);
displayAPRSText_(aprsPosit);
}
void aprsDisplay::aprsDFErrorObject_(const QString &oName,
const std::vector<double>&oPoint,
const std::vector<double>&oSDs)
{
QString aprsPosit=theAPRS_->createDFErrorObject(oName,oPoint,oSDs[0],oSDs[1]);
displayAPRSText_(aprsPosit);
}
void aprsDisplay::deleteAPRSObject_(const QString &oName)
{
QString aprsPosit=theAPRS_->deleteObject(oName);
if (!aprsPosit.isEmpty())
displayAPRSText_(aprsPosit);
}
void aprsDisplay::aprsRotatedEllipse_(const QString &oName, DFLib::Proj::Point &thePoint,
double am2, double bm2, double phi,
int percent)
{
if (am2>0 && bm2>0)
{
// this is tricky. We need to calculate the Stansfield ellipses in
// XY coordinates, then convert their points to lat/lon before generating
// the APRS object.
double P=((double)percent)/100.0;
double rho=sqrt(-2*log(1-P));
DFLib::Proj::Point tempPoint(thePoint);
tempPoint.setUserProj(myCS_.getProj4Params());
std::vector<double> lats;
std::vector<double> lons;
std::vector<double> centerCoords=thePoint.getXY();
std::vector<double> tempCoords(2);
double a=sqrt(1.0/am2);
double b=sqrt(1.0/bm2);
double cosphi=cos(phi);
double sinphi=sin(phi);
const double pi=4*atan(1.0);
// this is the equation of an ellipse of axis a*rho and b*rho, rotated
// by an angle phi.
for (int i=0;i<16;i++)
{
tempCoords[0]=centerCoords[0]
+a*rho*cosphi*cos(2.0*pi/15.0*i)-b*rho*sinphi*sin(2.0*pi/15.0*i);
tempCoords[1]=centerCoords[1]
+a*rho*sinphi*cos(2.0*pi/15.0*i)+b*rho*cosphi*sin(2.0*pi/15.0*i);
// those are the coordinates in XY. Now get 'em in lat/lon
tempPoint.setXY(tempCoords);
tempCoords=tempPoint.getUserCoords();
lons.push_back(tempCoords[0]);
lats.push_back(tempCoords[1]);
}
// we now have our rotated ellipse transformed to lat/lon. Make the
// APRS object
char colorStyle;
if (percent>=50)
colorStyle='g';
if (percent>=75)
colorStyle='e';
if (percent>90)
colorStyle='a';
tempPoint.setXY(centerCoords);
centerCoords=tempPoint.getUserCoords();
QString aprsPosit=
theAPRS_->createMultilineObject(oName,
lats,lons,centerCoords,
colorStyle,0,
"\\l");
displayAPRSText_(aprsPosit);
}
}