-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
892 lines (747 loc) · 27.2 KB
/
MainWindow.cpp
File metadata and controls
892 lines (747 loc) · 27.2 KB
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
#ifdef _MSC_VER
#define _USE_MATH_DEFINES
#include <cfloat>
inline bool isnan(double v) {return _isnan(v)!=0;}
inline bool isinf(double v) {return !_finite(v);}
#endif
#include <QtGui>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#endif
#include <sstream>
#include <iostream>
#include "MainWindow.h"
#include "Settings.hpp"
#include "getReportDialog.h"
#include "reportToggleDialog.h"
#include "settingsDialog.h"
#include "qDFProjReport.hpp"
#include "aprsDisplay.hpp"
#include "rawTextDisplay.hpp"
#include "kmlDisplay.hpp"
#include "qDFDisplayManager.hpp"
#include <Util_Misc.hpp>
#define RAD_TO_DEG 57.295779513082321
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
dirtyCollection(false),
currentFileName("")
{
setupUi(this);
menuHelp->addAction(QWhatsThis::createAction());
readSettings();
theAPRS.setPort(theSettings_.getAPRSPort());
theAPRS.setServer(theSettings_.getAPRSServer());
theAPRS.setCallsign(theSettings_.getAPRSCallsign());
theAPRS.setCallpass(theSettings_.getAPRSCallpass());
theAPRSDisplay_ = new aprsDisplay(&theAPRS,aprsPacketsTextEdit);
theRTDisplay_ = new rawTextDisplay();
theKMLDisplay_ = new kmlDisplay("qDF_GE.kml");
theDisplayManager.addDisplay("MainWindow",this,true);
theDisplayManager.addDisplay("APRS",theAPRSDisplay_,theSettings_.publishAPRS());
theDisplayManager.addDisplay("RawText",theRTDisplay_,false);
theDisplayManager.addDisplay("KML",theKMLDisplay_,true);
}
MainWindow::~MainWindow()
{
theReportCollection.deleteReports();
}
void MainWindow::setupConnections()
{
// File menu
connect(actionSave_As, SIGNAL(triggered()), this, SLOT(saveAs()));
connect(actionSave, SIGNAL(triggered()), this, SLOT(save()));
connect(actionOpen, SIGNAL(triggered()), this, SLOT(open()));
connect(actionClose, SIGNAL(triggered()), this, SLOT(closeFile()));
// Edit menu:
connect(actionSettings, SIGNAL(triggered()), this, SLOT(editSettings()));
// Report menu
connect(actionNew_Report, SIGNAL(triggered()), this, SLOT(newReportClicked()));
connect(actionToggle_Validity, SIGNAL(triggered()), this, SLOT(toggleValidityClicked()));
connect(this, SIGNAL(newReportCreated(qDFProjReport *)),
&theReportCollection, SLOT(newReport(qDFProjReport *)));
connect(&theReportCollection,SIGNAL(collectionChanged()),
this,SLOT(reportCollectionChanged()));
connect(&theReportCollection,SIGNAL(collectionCleared()),
this,SLOT(reportCollectionChanged()));
connect(&theReportCollection,SIGNAL(collectionCleared()),
this,SLOT(clearCollectionDisplay()));
connect(&theReportCollection,SIGNAL(collectionChanged(int)),
this,SLOT(updateCollectionDisplay(int)));
connect(reportListWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)),
this,SLOT(listItemDoubleClicked(QListWidgetItem *)));
// Help menu
connect(actionAbout,SIGNAL(triggered()),this,SLOT(about()));
connect(actionAbout_Qt,SIGNAL(triggered()),this,SLOT(aboutQt()));
}
void MainWindow::toggleValidityClicked()
{
reportToggleDialog theToggleDialog;
if (theToggleDialog.exec())
{
std::string reportName = theToggleDialog.lineEdit_ReportName->text().toStdString();
int reportIndex = theReportCollection.getReportIndex(reportName);
if (reportIndex != -1)
{
theReportCollection.toggleValidity(reportIndex);
// std::cout << "Toggling validity of report number " << reportIndex << " named " << reportName << std::endl;
}
}
}
void MainWindow::newReportClicked()
{
QList<QString> existingNames=theReportCollection.getReportNames();
getReportDialog theRD(theSettings_,existingNames);
if (theRD.exec())
{
std::string reportName= theRD.lineEdit_ReportName->text().toStdString();
QString coordSysName=theRD.comboBox_CoordSys->currentText();
QString equipType=theRD.comboBox_EquipmentType->currentText();
QString quality=theRD.comboBox_Quality->currentText();
double bearing=theRD.lineEdit_bearing->text().toDouble()+
theSettings_.getDefaultDeclination();
double sd=
theSettings_.getStandardDeviation(equipType, quality);
bool isValid=theRD.checkBox_validity->isChecked();
// This is not right yet..., need to check for zone. Don't worry now.
// CoordSysBuilder myCSB;
CoordSys myCS=theSettings_.getCoordSys(coordSysName);
QVector<double> llCoords(2);
theRD.latLon->getCoords(llCoords);
std::vector<double> coords(2,0.0);
coords[0]=llCoords[1]; // llCoords[1] is latitude
coords[1]=llCoords[0]; // llcoords[0] is longitude. Rearrange for DFLib,
// which expects longitude (X) and latitude (Y) in
// that order.
qDFProjReport *theNewReport = new qDFProjReport(coords,bearing,sd,
reportName,myCS,
equipType, quality);
if (isValid)
theNewReport->setValid();
else
theNewReport->setInvalid();
// At this point, if the collection is completely empty, intialize the displays. WE'll add our
// new report after this, and the displays will get updated.
if (theReportCollection.size() == 0)
{
theDisplayManager.initializeDisplays();
}
emit newReportCreated(theNewReport);
}
else
{
// std::cout << "You clicked Cancel" << std::endl;
}
}
void MainWindow::newReportReceived(qDFProjReport *report)
{
// std::cout << " received a new report, its pointer is " << report << std::endl;
// delete report;
}
void MainWindow::reportCollectionChanged()
{
int nreports= theReportCollection.numValidReports() ;
if (nreports>0)
dirtyCollection=true; // otherwise we might have cleared it!
// std::cout << " in slot reportCollectionChanged." << std::endl;
// std::cout << " collection now has " << nreports
// << " valid reports out of a total of " << theReportCollection.size()
// << " reports. " <<std::endl;
lcdNumberNReports->setSegmentStyle(QLCDNumber::Filled);
lcdNumberNReports->display(nreports);
if (nreports>=2)
{
CoordSys myCS=theSettings_.getDefaultCS();
std::vector<double> foo(2,0.0);
std::vector<double> FCA_stddev(2);
std::vector<std::string> formattedCoords;
DFLib::Proj::Point FCA(foo,myCS.getProj4Params());
bool FCA_computed=false;
DFLib::Proj::Point LSFix=FCA;
bool LSFix_computed=false;
DFLib::Proj::Point MLFix=LSFix;
bool MLFix_computed=false;
DFLib::Proj::Point StansfieldFix=LSFix;
bool StansfieldFix_computed=false;
FCA_computed=theReportCollection.computeFixCutAverage(FCA,FCA_stddev,
theSettings_.getDefaultFCAMinAngle());
if (nreports>2)
{
theReportCollection.computeLeastSquaresFix(LSFix);
LSFix_computed=true;
}
if (nreports >= 2)
{
try
{
theReportCollection.computeMLFix(MLFix);
MLFix_computed=checkValidMLFix(MLFix);
if (!MLFix_computed)
{
MLFix=LSFix; // reset
theReportCollection.aggressiveComputeMLFix(MLFix);
MLFix_computed=checkValidMLFix(MLFix);
}
}
catch (...)
{
// If computeMLFix throws an exception, such as for
// convergence failures, ignore it
MLFix_computed=false;
}
double am2ML=0;
double bm2ML=0;
double phiML;
if (MLFix_computed)
{
theReportCollection.computeCramerRaoBounds(MLFix,am2ML,bm2ML,phiML);
}
// Compute the Stansfield fix and its error ellipse parameters:
double am2,bm2,phi;
try
{
StansfieldFix=LSFix;
theReportCollection.computeStansfieldFix(StansfieldFix,am2,bm2,phi);
StansfieldFix_computed=true;
}
catch (DFLib::Util::Exception x)
{
std::cerr << "Ooops got exception " << x.getEmsg() << std::endl;
StansfieldFix_computed=false;
}
if (LSFix_computed)
{
theDisplayManager.displayLSFix(LSFix);
}
if (MLFix_computed)
{
theDisplayManager.displayMLFix(MLFix,am2ML,bm2ML,phiML);
}
else
{
theDisplayManager.undisplayMLFix();
}
if (StansfieldFix_computed)
{
theDisplayManager.displayBPEFix(StansfieldFix,am2,bm2,phi);
}
else
{
theDisplayManager.undisplayBPEFix();
}
}
else
{
theDisplayManager.undisplayMLFix();
theDisplayManager.undisplayLSFix();
}
if (FCA_computed)
{
theDisplayManager.displayFCAFix(FCA,FCA_stddev);
}
else
{
theDisplayManager.undisplayFCAFix();
}
}
else
{
// we don't have enough reports do do any analysis, make sure we don't
// show data for the fixes.
theDisplayManager.undisplayFCAFix();
theDisplayManager.undisplayMLFix();
theDisplayManager.undisplayLSFix();
theDisplayManager.undisplayBPEFix();
}
}
void MainWindow::printCoords(const std::vector<double> &latlon,const std::string &text)
{
std::vector<std::string>formattedCoords;
formatCoords(latlon,formattedCoords);
std::cout << " Longitude of " << text << ": " << formattedCoords[0]
<< std::endl;
std::cout << " Latitude of " << text << ": " << formattedCoords[1]
<< std::endl;
}
void MainWindow::formatCoords(const std::vector<double> &latlon,
std::vector<std::string> &formattedCoords)
{
int latfac=1; int lonfac=1;
char EW,NS;
formattedCoords.resize(2);
EW='E';
NS='N';
if (latlon[0] < 0)
{
lonfac=-1;
EW='W';
}
if (latlon[1] < 0)
{
latfac=-1;
NS='S';
}
std::ostringstream os;
os << static_cast<int>(latlon[0]*lonfac)
<< "d"
<< (latlon[0]*lonfac-static_cast<int>(latlon[0]*lonfac))*60
<< "'" << EW ;
formattedCoords[0]=os.str();
os.str("");
os << static_cast<int>(latlon[1]*latfac)
<< "d"
<< (latlon[1]*latfac-static_cast<int>(latlon[1]*latfac))*60
<< "'" << NS ;
formattedCoords[1]=os.str();
}
void MainWindow::clearCollectionDisplay()
{
dirtyCollection=false;
theDisplayManager.closeDisplays();
}
void MainWindow::updateCollectionDisplay(int reportIndex)
{
theDisplayManager.displayDFReport(dynamic_cast<const qDFProjReport *>(theReportCollection.getReport(reportIndex)));
}
void MainWindow::listItemDoubleClicked(QListWidgetItem *item)
{
// int theReportIndex=theReportCollection.getReportIndex(item->data(Qt::UserRole).toString().toStdString());
// theReportCollection.toggleValidity(theReportIndex);
QString reportName=item->data(Qt::UserRole).toString();
editReport(reportName);
}
void MainWindow::editReport(QString & rN)
{
qDFProjReport * theReportPtr = theReportCollection.getReportPointer(rN);
if (theReportPtr)
{
getReportDialog theRD(theSettings_,theReportPtr);
if (theRD.exec())
{
QString coordSysName=theRD.comboBox_CoordSys->currentText();
QString equipType=theRD.comboBox_EquipmentType->currentText();
QString quality=theRD.comboBox_Quality->currentText();
double bearing=theRD.lineEdit_bearing->text().toDouble()+
theSettings_.getDefaultDeclination();
double sd=
theSettings_.getStandardDeviation(equipType, quality);
bool isValid=theRD.checkBox_validity->isChecked();
// This is not right yet..., need to check for zone. Don't worry now.
// CoordSysBuilder myCSB;
CoordSys myCS=theSettings_.getCoordSys(coordSysName);
QVector<double> llCoords(2);
theRD.latLon->getCoords(llCoords);
std::vector<double> coords(2,0.0);
coords[0]=llCoords[1]; // llCoords[1] is latitude
coords[1]=llCoords[0]; // llcoords[0] is longitude. Rearrange for DFLib,
// which expects longitude (X) and latitude (Y) in
// that order.
if (isValid)
theReportPtr->setValid();
else
theReportPtr->setInvalid();
// The next line takes care of the "emit" of a reportChanged"
theReportPtr->setAll(coords,bearing,sd,myCS,equipType,quality);
}
}
}
void MainWindow::aboutQt()
{
QMessageBox::aboutQt(this,tr("About Qt"));
}
void MainWindow::about()
{
QMessageBox::about(this,tr("About qDF"),
tr("<h2>qDF 0.2</h2>"
"<p>Copyright © 2010 Tom Russo, KM5VY."
"<p>qDF is an application for computing "
"fixes of transmitter location from bearings-only "
"measurements by receivers."
"<p>It computes the Fix Cut Average, Least Squares, "
"Maximum Likelihood, and Stansfield fixes."
"<p>The Fix Cut Average is the average position of "
"pairwise intersections of report lines."
"<p>The Least Squares fix is the point that minimizes "
"the sum of squares of perpendicular distances to "
"bearing lines."
"<p>The Maximum Likelihood fix is the point that "
"maximizes the probability distribution assuming "
"Gaussian distributions of error from each receiver."
"<p>The Stansfield fix is a version of the Maximum "
"Likelihood fix that incorporates the assumption that "
"angular error is small and distance between receiver "
"and transmitter is large. It is based on the seminal "
"1947 paper by R.G. Stansfield."));
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if (okToContinue()) {
writeSettings();
event->accept();
} else {
event->ignore();
}
if (theReportCollection.size())
{
theDisplayManager.closeDisplays();
theReportCollection.deleteReports();
// Now we have an issue. If we just exit now, the (possibly lengthy)
// process of deleting APRS objects has only just begun. So what we'll do
// is ignore this event and set it up so that when APRS emits a signal
// that the queue is cleared, we get called again. At that point,
// theReportCollection will have been emptied, so this will work.
if (theSettings_.publishAPRS())
{
connect(&theAPRS,SIGNAL(queueCleared()),this,SLOT(close()));
event->ignore();
}
}
}
bool MainWindow::okToContinue()
{
if (theReportCollection.size()!=0 && dirtyCollection)
{
int r = QMessageBox::warning(this, tr("qDF"),
tr("There are reports in the collection"
" that have not been saved\n"
"Do you want to save them?"),
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No,
QMessageBox::Cancel | QMessageBox::Escape);
if (r == QMessageBox::Yes)
{
return save();
}
else if (r == QMessageBox::Cancel)
{
return false;
}
}
return true;
}
void MainWindow::readSettings()
{
QSettings qsettings("Tom Russo","qDF");
restoreGeometry(qsettings.value("geometry",QRect(0,0,800,600)).toByteArray());
QString csName=qsettings.value("defaultCoordSysName",
theSettings_.getDefaultCSName()).toString();
theSettings_.setDefaultCS(csName);
double defDec=qsettings.value("defaultDeclination",
theSettings_.getDefaultDeclination()).toDouble();
theSettings_.setDefaultDeclination(defDec);
double defFCAMA=qsettings.value("defaultFCAMinAngle",
theSettings_.getDefaultFCAMinAngle()).toDouble();
theSettings_.setDefaultFCAMinAngle(defFCAMA);
int defZone=qsettings.value("defaultUTMZone",
theSettings_.getDefaultUTMZone()).toInt();
theSettings_.setDefaultUTMZone(defZone);
int defNS=qsettings.value("defaultNS",
theSettings_.getDefaultNSHemisphere()).toInt();
theSettings_.setDefaultNSHemisphere(defNS);
int defEW=qsettings.value("defaultEW",
theSettings_.getDefaultEWHemisphere()).toInt();
theSettings_.setDefaultEWHemisphere(defEW);
quint16 defPort=qsettings.value("aprsPort",
theSettings_.getAPRSPort()).toInt();
theSettings_.setAPRSPort(defPort);
QString aprsServer=qsettings.value("aprsServer",
theSettings_.getAPRSServer()).toString();
theSettings_.setAPRSServer(aprsServer);
QString aprsCallsign=qsettings.value("aprsCallsign",
theSettings_.getAPRSCallsign()).toString();
theSettings_.setAPRSCallsign(aprsCallsign);
QString aprsCallpass=qsettings.value("aprsCallpass",
theSettings_.getAPRSCallpass()).toString();
theSettings_.setAPRSCallpass(aprsCallpass);
bool publishAPRS=qsettings.value("publishAPRS",
theSettings_.publishAPRS()).toBool();
theSettings_.setPublishAPRS(publishAPRS);
// can't do the equipment map exactly. Work it out...
}
void MainWindow::writeSettings()
{
QSettings settings("Tom Russo","qDF");
settings.setValue("geometry",geometry());
settings.setValue("defaultCoordSysName",theSettings_.getDefaultCSName());
settings.setValue("defaultDeclination",theSettings_.getDefaultDeclination());
settings.setValue("defaultFCAMinAngle",theSettings_.getDefaultFCAMinAngle());
settings.setValue("defaultUTMZone",theSettings_.getDefaultUTMZone());
settings.setValue("defaultNS",theSettings_.getDefaultNSHemisphere());
settings.setValue("defaultEW",theSettings_.getDefaultEWHemisphere());
settings.setValue("aprsPort",theSettings_.getAPRSPort());
settings.setValue("aprsCallsign",theSettings_.getAPRSCallsign());
settings.setValue("aprsCallpass",theSettings_.getAPRSCallpass());
settings.setValue("aprsServer",theSettings_.getAPRSServer());
settings.setValue("publishAPRS",theSettings_.publishAPRS());
}
bool MainWindow::writeFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly))
{
QMessageBox::warning(this, tr("qDF"),
tr("Cannot write file %1:\n%2.")
.arg(file.fileName())
.arg(file.errorString()));
return false;
}
QDataStream out(&file);
out.setVersion(QDataStream::Qt_4_4);
out << quint32(MagicNumber);
QApplication::setOverrideCursor(Qt::WaitCursor);
out << theReportCollection;
QApplication::restoreOverrideCursor();
return true;
}
bool MainWindow::loadFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
{
QMessageBox::warning(this, tr("qDF"),
tr("Cannot read file %1:\n%2.")
.arg(file.fileName())
.arg(file.errorString()));
return false;
}
QDataStream in(&file);
in.setVersion(QDataStream::Qt_4_4);
quint32 magic;
in >> magic;
if (magic != MagicNumber)
{
QMessageBox::warning(this,tr("qDF"),
tr("The file is not a qDF file for this version of qDF."));
return false;
}
theReportCollection.deleteReports();
theDisplayManager.initializeDisplays();
QApplication::setOverrideCursor(Qt::WaitCursor);
in >> theReportCollection;
dirtyCollection=false;
QApplication::restoreOverrideCursor();
return true;
}
bool MainWindow::save()
{
if (currentFileName.isEmpty())
{
return saveAs();
}
else
{
return saveFile(currentFileName);
}
}
bool MainWindow::saveAs()
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save Reports"),".",
tr("qDF Files (*.qdf)"));
if (fileName.isEmpty())
return false;
return saveFile(fileName);
}
void MainWindow::open()
{
if (okToContinue())
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open DF Reports"), ".",
tr("qDF files (*.qdf)"));
if (!fileName.isEmpty())
{
loadFile(fileName);
currentFileName=fileName;
}
}
}
void MainWindow::closeFile()
{
if (okToContinue())
{
theDisplayManager.closeDisplays();
theReportCollection.deleteReports();
currentFileName="";
}
}
bool MainWindow::saveFile(const QString &fileName)
{
bool retcode=writeFile(fileName);
if (retcode)
{
dirtyCollection=false;
currentFileName=fileName;
}
return(retcode);
}
void MainWindow::editSettings()
{
settingsDialog theSD(theSettings_);
if (theSD.exec())
{
theSD.retrieveSettings(theSettings_);
theAPRS.setPort(theSettings_.getAPRSPort());
theAPRS.setServer(theSettings_.getAPRSServer());
theAPRS.setCallsign(theSettings_.getAPRSCallsign());
theAPRS.setCallpass(theSettings_.getAPRSCallpass());
if (theSettings_.publishAPRS())
theDisplayManager.enableDisplay("APRS");
else
theDisplayManager.disableDisplay("APRS");
}
}
// ML sometimes returns complete garbage for the ML fix. When it does,
// the point is off at infinity. Sanity check:
bool MainWindow::checkValidMLFix(DFLib::Proj::Point &thePoint)
{
DFLib::Proj::Point tempPoint=thePoint;
for (int i=0; i<theReportCollection.size();i++)
{
if (theReportCollection.isValid(i))
{
tempPoint=dynamic_cast<const DFLib::Proj::Report *>(theReportCollection.getReport(i))->getReceiverPoint();
break;
}
}
tempPoint.setUserProj(theSettings_.getDefaultCS().getProj4Params());
std::vector<double>latlon=thePoint.getUserCoords();
std::vector<double>merc=thePoint.getXY();
std::vector<double>r0_coords=tempPoint.getUserCoords();
if (!(std::isinf(latlon[0])||std::isinf(latlon[1])||std::isnan(latlon[0])||std::isnan(latlon[1])
||
std::isinf(merc[0])||std::isinf(merc[1])||std::isnan(merc[0])||std::isnan(merc[1])))
{
// Use the Haversine formula to compute the distance between the fix and
// the first valid report location we have.
// compute very rough distance on sphere with haversine formula:
double dlon=(latlon[0]-r0_coords[0])/RAD_TO_DEG;
double dlat=(latlon[1]-r0_coords[1])/RAD_TO_DEG;
double haversin_a=sin(dlat/2.0)*sin(dlat/2.0)+cos(latlon[1]/RAD_TO_DEG)*cos(r0_coords[1]/RAD_TO_DEG)*sin(dlon/2)*sin(dlon/2);
double haversin_c=2*atan2(sqrt(haversin_a),sqrt(1-haversin_a));
double haversin_d=3596*haversin_c; // miles, give or take
return (haversin_d<100);
}
return(false);
}
// qDFDisplayInterface methods
void MainWindow::initializeDisplay()
{
// Takes no initialization steps
}
void MainWindow::clearDisplay()
{
label_FCA_Longitude->setText("Not Available");
label_FCA_Latitude->setText("Not Available");
label_FCA_Longitude_SD->setText("Not Available");
label_FCA_Latitude_SD->setText("Not Available");
label_ML_Longitude->setText("Not Available");
label_ML_Latitude->setText("Not Available");
label_LS_Longitude->setText("Not Available");
label_LS_Latitude->setText("Not Available");
label_Stansfield_Longitude->setText("Not Available");
label_Stansfield_Latitude->setText("Not Available");
reportListWidget->clear();
}
void MainWindow::closeDisplay()
{
clearDisplay();
}
void MainWindow::displayDFReport(const qDFProjReport *theReport)
{
std::vector<std::string> theProj4Params = theSettings_.getDefaultCS().getProj4Params();
QString theReportName=theReport->getReportNameQS();
QString theReportSummary=theReport->getReportSummary(theProj4Params);
// Don't like this, but we need the index to get at the item in the list widget
int reportIndex = theReportCollection.getReportIndex(theReport);
// First job is to update the display in the clickable list
// add (or replace) the report summary to the list
QListWidgetItem *theWidgetItem=reportListWidget->item(reportIndex);
if(theWidgetItem)
{
theWidgetItem->setText(theReportSummary);
}
else
{
reportListWidget->insertItem(reportIndex,theReportSummary);
theWidgetItem=reportListWidget->item(reportIndex);
}
// set the data for the listitem to be our name.
theWidgetItem->setData(Qt::UserRole,theReportName);
// set the validity indicator
QFont theItemFont=theWidgetItem->font();
if (theReportCollection.isValid(reportIndex))
{
theItemFont.setItalic(false);
}
else
{
theItemFont.setItalic(true);
}
theWidgetItem->setFont(theItemFont);
}
void MainWindow::displayLSFix(DFLib::Proj::Point & LSFix)
{
std::vector<std::string> formattedCoords;
std::vector<double> LS_point=LSFix.getUserCoords();
// printCoords(LS_point,std::string("Least Squares Fix"));
formatCoords(LS_point,formattedCoords);
label_LS_Longitude->setText(QString::fromStdString(formattedCoords[0]));
label_LS_Latitude->setText(QString::fromStdString(formattedCoords[1]));
}
void MainWindow::undisplayLSFix()
{
label_LS_Longitude->setText("Not Available");
label_LS_Latitude->setText("Not Available");
}
void MainWindow::displayFCAFix(DFLib::Proj::Point & FCAFix, std::vector<double> FCA_stddev)
{
std::vector<std::string> formattedCoords;
std::vector<double> FCA_point=FCAFix.getUserCoords();
// printCoords(FCA_point,std::string("Fix Cut Average"));
formatCoords(FCA_point,formattedCoords);
label_FCA_Longitude->setText(QString::fromStdString(formattedCoords[0]));
label_FCA_Latitude->setText(QString::fromStdString(formattedCoords[1]));
std::ostringstream os;
os << FCA_stddev[0];
label_FCA_Longitude_SD->setText(QString::fromStdString(os.str()));
os.str("");
os << FCA_stddev[1];
label_FCA_Latitude_SD->setText(QString::fromStdString(os.str()));
}
void MainWindow::undisplayFCAFix()
{
label_FCA_Longitude->setText("Not Available");
label_FCA_Latitude->setText("Not Available");
label_FCA_Longitude_SD->setText("Not Available");
label_FCA_Latitude_SD->setText("Not Available");
}
void MainWindow::displayBPEFix(DFLib::Proj::Point & StansfieldFix, double am2, double bm2, double phi)
{
std::vector<std::string> formattedCoords;
std::vector<double> Stansfield_point=StansfieldFix.getUserCoords();
// printCoords(ML_point,std::string("Maximum Likelihood Fix"));
formatCoords(Stansfield_point,formattedCoords);
label_Stansfield_Longitude->setText(QString::fromStdString(formattedCoords[0]));
label_Stansfield_Latitude->setText(QString::fromStdString(formattedCoords[1]));
// we ignore the error stuff for the main window display
}
void MainWindow::undisplayBPEFix()
{
label_Stansfield_Longitude->setText("Not Available");
label_Stansfield_Latitude->setText("Not Available");
}
void MainWindow::displayMLFix(DFLib::Proj::Point & MLFix, double am2, double bm2, double phi)
{
std::vector<std::string> formattedCoords;
std::vector<double> ML_point=MLFix.getUserCoords();
// printCoords(ML_point,std::string("Maximum Likelihood Fix"));
formatCoords(ML_point,formattedCoords);
label_ML_Longitude->setText(QString::fromStdString(formattedCoords[0]));
label_ML_Latitude->setText(QString::fromStdString(formattedCoords[1]));
}
void MainWindow::undisplayMLFix()
{
label_ML_Longitude->setText("Not Available");
label_ML_Latitude->setText("Not Available");
}