123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "math/gnss_coordinate_convert.h"
- #include <QFileDialog>
- MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
- , ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- setWindowTitle(tr("GPS Calculate Tool"));
- #ifndef Q_OS_WASM
- ui->pushButton_SaveXY->setVisible(false);
- ui->pushButton_SaveLonLat->setVisible(false);
- #endif
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::on_pushButton_LonLatConvertXY_clicked()
- {
- double x,y;
- double lon = ui->lineEdit_1_Lon->text().toDouble();
- double lat = ui->lineEdit_1_Lat->text().toDouble();
- GaussProjCal(lon,lat,&x,&y);
- ui->lineEdit_1_x->setText(QString::number(x,'f',3));
- ui->lineEdit_1_y->setText(QString::number(y,'f',3));
- }
- void MainWindow::on_pushButton_LonLatConvertRel_clicked()
- {
- double lon_base,lat_base,heading_base;
- double lon_test,lat_test,heading_test;
- double x_base,y_base,hdg_base;
- double x_test,y_test,hdg_test;
- double x_rel,y_rel,hdg_rel;
- double x_rel_raw,y_rel_raw;
- double fDis;
- lon_base = ui->lineEdit_2_Lon->text().toDouble();
- lat_base = ui->lineEdit_2_Lat->text().toDouble();
- heading_base = ui->lineEdit_2_Heading->text().toDouble();
- lon_test = ui->lineEdit_2_Lon2->text().toDouble();
- lat_test = ui->lineEdit_2_Lat2->text().toDouble();
- heading_test = ui->lineEdit_2_Heading2->text().toDouble();
- GaussProjCal(lon_base,lat_base,&x_base,&y_base);
- GaussProjCal(lon_test,lat_test,&x_test,&y_test);
- fDis = sqrt(pow(x_test - x_base,2) + pow(y_test - y_base,2));
- x_rel_raw = x_test - x_base;
- y_rel_raw = y_test - y_base;
- hdg_base = (90-heading_base)*M_PI/180.0;
- normalhdg(hdg_base);
- hdg_test = (90-heading_test)*M_PI/180.0;
- normalhdg(hdg_test);
- hdg_rel = hdg_test - hdg_base;
- normalhdg(hdg_rel);
- x_rel = x_rel_raw * cos(-hdg_base) - y_rel_raw * sin(-hdg_base);
- y_rel = x_rel_raw * sin(-hdg_base) - y_rel_raw * cos(-hdg_base);
- char strout[1000];
- char strtem[100];
- snprintf(strout,1000," Rel Value:\n");
- snprintf(strtem,100,"x:%6.3f\n",x_rel);strncat(strout,strtem,1000);
- snprintf(strtem,100,"y:%6.3f\n",y_rel);strncat(strout,strtem,1000);
- snprintf(strtem,100,"hdg:%11.9f\n",hdg_rel);strncat(strout,strtem,1000);
- snprintf(strtem,100,"\n Raw rel Value:\n");strncat(strout,strtem,1000);
- snprintf(strtem,100,"x_raw:%6.3f\n",x_rel_raw);strncat(strout,strtem,1000);
- snprintf(strtem,100,"y_raw:%6.3f\n",y_rel_raw);strncat(strout,strtem,1000);
- snprintf(strtem,100,"\n Point Distance:\n");strncat(strout,strtem,1000);
- snprintf(strtem,100,"Distance:%6.3f\n",fDis);strncat(strout,strtem,1000);
- double R;
- double theta = hdg_rel;
- if(theta >M_PI) theta = 2.0*M_PI - theta;
- theta = theta/2.0;
- if(sin(theta)>0)
- {
- R = fDis/(2.0*sin(theta));
- snprintf(strtem,100,"\n R:\n");strncat(strout,strtem,1000);
- snprintf(strtem,100,"R:%6.3f\n",R);strncat(strout,strtem,1000);
- }
- ui->plainTextEdit_Rel->setPlainText(strout);
- }
- void MainWindow::on_pushButton_RelConvertLonLat_clicked()
- {
- double lon_base,lat_base,heading_base;
- double lon_test,lat_test,heading_test;
- double x_base,y_base,hdg_base;
- double x_test,y_test,hdg_test;
- double x_rel,y_rel,hdg_rel;
- double x_rel_raw,y_rel_raw;
- lon_base = ui->lineEdit_3_Lon->text().toDouble();
- lat_base = ui->lineEdit_3_Lat->text().toDouble();
- heading_base = ui->lineEdit_3_Heading->text().toDouble();
- x_rel = ui->lineEdit_3_x->text().toDouble();
- y_rel = ui->lineEdit_3_y->text().toDouble();
- hdg_rel = ui->lineEdit_3_hdg->text().toDouble();
- GaussProjCal(lon_base,lat_base,&x_base,&y_base);
- hdg_base = (90-heading_base)*M_PI/180.0;
- normalhdg(hdg_base);
- x_rel_raw = x_rel * cos(hdg_base) - y_rel * sin(hdg_base);
- y_rel_raw = x_rel * sin(hdg_base) - y_rel * cos(hdg_base);
- hdg_test = hdg_base + hdg_rel;
- heading_test = (M_PI/2.0 - hdg_test) * 180.0/M_PI;
- normalheading(heading_test);
- x_test = x_base + x_rel_raw;
- y_test = y_base + y_rel_raw;
- GaussProjInvCal(x_test,y_test,&lon_test,&lat_test);
- char strout[1000];
- char strtem[100];
- snprintf(strout,1000,"Lon Lat:\n");
- snprintf(strtem,100,"Lon:%11.8f\n",lon_test);strncat(strout,strtem,1000);
- snprintf(strtem,100,"Lat:%11.8f\n",lat_test);strncat(strout,strtem,1000);
- snprintf(strtem,100,"heading:%6.3f\n",heading_test);strncat(strout,strtem,1000);
- ui->plainTextEdit_LonLat->setPlainText(strout);
- }
- void MainWindow::normalheading(double & heading)
- {
- while(heading>=360.0)heading = heading - 360.0;
- while(heading<0)heading = heading + 360.0;
- }
- void MainWindow::normalhdg(double & hdg)
- {
- while(hdg >= (2.0*M_PI))hdg = hdg - M_PI * 2.0;
- while(hdg < 0)hdg = hdg + M_PI * 2.0;
- }
- void MainWindow::on_pushButton_SaveXY_clicked()
- {
- double lon_base,lat_base,heading_base;
- double lon_test,lat_test,heading_test;
- lon_base = ui->lineEdit_2_Lon->text().toDouble();
- lat_base = ui->lineEdit_2_Lat->text().toDouble();
- heading_base = ui->lineEdit_2_Heading->text().toDouble();
- lon_test = ui->lineEdit_2_Lon2->text().toDouble();
- lat_test = ui->lineEdit_2_Lat2->text().toDouble();
- heading_test = ui->lineEdit_2_Heading2->text().toDouble();
- char strbase[1000];
- snprintf(strbase,1000,"From Value:\n Base:%11.7f %11.7f %11.7f\n Test:%11.7f %11.7f %11.7f\n\n",
- lon_base,lat_base,heading_base,lon_test,lat_test,heading_test);
- QByteArray ba1;
- ba1 = QByteArray::fromRawData(strbase,strnlen(strbase,1000));
- QString str = ui->plainTextEdit_Rel->toPlainText();
- QByteArray ba;
- ba = QByteArray::fromStdString(str.toStdString());
- #ifdef Q_OS_WASM
- ba1.append(ba);
- QFileDialog::saveFileContent(ba1,"xy.txt");
- #endif
- }
- //Qt使用Emscripten的文件系统,还提供其他API:
- // QFile可以照常使用。默认情况下,存储的文件进入MEMFS。
- // QSettings具有一个基于IndexedDB的后端;请注意,QSettings在WebAssembly上是异步的。请参阅[2]上的用法示例
- // QFileDialog :: getOpenFileContent()打开一个本机文件对话框,用户可以在其中选择文件
- // QFileDialog :: saveFileContent()通过文件下载将文件保存到本地文件系统
- void MainWindow::on_pushButton_SaveLonLat_clicked()
- {
- double lon_base,lat_base,heading_base;
- double x_rel,y_rel,hdg_rel;
- lon_base = ui->lineEdit_3_Lon->text().toDouble();
- lat_base = ui->lineEdit_3_Lat->text().toDouble();
- heading_base = ui->lineEdit_3_Heading->text().toDouble();
- x_rel = ui->lineEdit_3_x->text().toDouble();
- y_rel = ui->lineEdit_3_y->text().toDouble();
- hdg_rel = ui->lineEdit_3_hdg->text().toDouble();
- char strbase[1000];
- snprintf(strbase,1000,"From Value:\n Base:%11.7f %11.7f %11.7f\n Test:%11.7f %11.7f %11.7f\n\n",
- lon_base,lat_base,heading_base,x_rel,y_rel,hdg_rel);
- QByteArray ba1;
- ba1 = QByteArray::fromRawData(strbase,strnlen(strbase,1000));
- QString str = ui->plainTextEdit_LonLat->toPlainText();
- QByteArray ba;
- ba = QByteArray::fromStdString(str.toStdString());
- #ifdef Q_OS_WASM
- ba1.append(ba);
- QFileDialog::saveFileContent(ba1,"lonlat.txt");
- #endif
- }
|