mainwindow.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "math/gnss_coordinate_convert.h"
  4. #include <QFileDialog>
  5. MainWindow::MainWindow(QWidget *parent)
  6. : QMainWindow(parent)
  7. , ui(new Ui::MainWindow)
  8. {
  9. ui->setupUi(this);
  10. setWindowTitle(tr("GPS Calculate Tool"));
  11. #ifndef Q_OS_WASM
  12. ui->pushButton_SaveXY->setVisible(false);
  13. ui->pushButton_SaveLonLat->setVisible(false);
  14. #endif
  15. }
  16. MainWindow::~MainWindow()
  17. {
  18. delete ui;
  19. }
  20. void MainWindow::on_pushButton_LonLatConvertXY_clicked()
  21. {
  22. double x,y;
  23. double lon = ui->lineEdit_1_Lon->text().toDouble();
  24. double lat = ui->lineEdit_1_Lat->text().toDouble();
  25. GaussProjCal(lon,lat,&x,&y);
  26. ui->lineEdit_1_x->setText(QString::number(x,'f',3));
  27. ui->lineEdit_1_y->setText(QString::number(y,'f',3));
  28. }
  29. void MainWindow::on_pushButton_LonLatConvertRel_clicked()
  30. {
  31. double lon_base,lat_base,heading_base;
  32. double lon_test,lat_test,heading_test;
  33. double x_base,y_base,hdg_base;
  34. double x_test,y_test,hdg_test;
  35. double x_rel,y_rel,hdg_rel;
  36. double x_rel_raw,y_rel_raw;
  37. double fDis;
  38. lon_base = ui->lineEdit_2_Lon->text().toDouble();
  39. lat_base = ui->lineEdit_2_Lat->text().toDouble();
  40. heading_base = ui->lineEdit_2_Heading->text().toDouble();
  41. lon_test = ui->lineEdit_2_Lon2->text().toDouble();
  42. lat_test = ui->lineEdit_2_Lat2->text().toDouble();
  43. heading_test = ui->lineEdit_2_Heading2->text().toDouble();
  44. GaussProjCal(lon_base,lat_base,&x_base,&y_base);
  45. GaussProjCal(lon_test,lat_test,&x_test,&y_test);
  46. fDis = sqrt(pow(x_test - x_base,2) + pow(y_test - y_base,2));
  47. x_rel_raw = x_test - x_base;
  48. y_rel_raw = y_test - y_base;
  49. hdg_base = (90-heading_base)*M_PI/180.0;
  50. normalhdg(hdg_base);
  51. hdg_test = (90-heading_test)*M_PI/180.0;
  52. normalhdg(hdg_test);
  53. hdg_rel = hdg_test - hdg_base;
  54. normalhdg(hdg_rel);
  55. x_rel = x_rel_raw * cos(-hdg_base) - y_rel_raw * sin(-hdg_base);
  56. y_rel = x_rel_raw * sin(-hdg_base) - y_rel_raw * cos(-hdg_base);
  57. char strout[1000];
  58. char strtem[100];
  59. snprintf(strout,1000," Rel Value:\n");
  60. snprintf(strtem,100,"x:%6.3f\n",x_rel);strncat(strout,strtem,1000);
  61. snprintf(strtem,100,"y:%6.3f\n",y_rel);strncat(strout,strtem,1000);
  62. snprintf(strtem,100,"hdg:%11.9f\n",hdg_rel);strncat(strout,strtem,1000);
  63. snprintf(strtem,100,"\n Raw rel Value:\n");strncat(strout,strtem,1000);
  64. snprintf(strtem,100,"x_raw:%6.3f\n",x_rel_raw);strncat(strout,strtem,1000);
  65. snprintf(strtem,100,"y_raw:%6.3f\n",y_rel_raw);strncat(strout,strtem,1000);
  66. snprintf(strtem,100,"\n Point Distance:\n");strncat(strout,strtem,1000);
  67. snprintf(strtem,100,"Distance:%6.3f\n",fDis);strncat(strout,strtem,1000);
  68. double R;
  69. double theta = hdg_rel;
  70. if(theta >M_PI) theta = 2.0*M_PI - theta;
  71. theta = theta/2.0;
  72. if(sin(theta)>0)
  73. {
  74. R = fDis/(2.0*sin(theta));
  75. snprintf(strtem,100,"\n R:\n");strncat(strout,strtem,1000);
  76. snprintf(strtem,100,"R:%6.3f\n",R);strncat(strout,strtem,1000);
  77. }
  78. ui->plainTextEdit_Rel->setPlainText(strout);
  79. }
  80. void MainWindow::on_pushButton_RelConvertLonLat_clicked()
  81. {
  82. double lon_base,lat_base,heading_base;
  83. double lon_test,lat_test,heading_test;
  84. double x_base,y_base,hdg_base;
  85. double x_test,y_test,hdg_test;
  86. double x_rel,y_rel,hdg_rel;
  87. double x_rel_raw,y_rel_raw;
  88. lon_base = ui->lineEdit_3_Lon->text().toDouble();
  89. lat_base = ui->lineEdit_3_Lat->text().toDouble();
  90. heading_base = ui->lineEdit_3_Heading->text().toDouble();
  91. x_rel = ui->lineEdit_3_x->text().toDouble();
  92. y_rel = ui->lineEdit_3_y->text().toDouble();
  93. hdg_rel = ui->lineEdit_3_hdg->text().toDouble();
  94. GaussProjCal(lon_base,lat_base,&x_base,&y_base);
  95. hdg_base = (90-heading_base)*M_PI/180.0;
  96. normalhdg(hdg_base);
  97. x_rel_raw = x_rel * cos(hdg_base) - y_rel * sin(hdg_base);
  98. y_rel_raw = x_rel * sin(hdg_base) - y_rel * cos(hdg_base);
  99. hdg_test = hdg_base + hdg_rel;
  100. heading_test = (M_PI/2.0 - hdg_test) * 180.0/M_PI;
  101. normalheading(heading_test);
  102. x_test = x_base + x_rel_raw;
  103. y_test = y_base + y_rel_raw;
  104. GaussProjInvCal(x_test,y_test,&lon_test,&lat_test);
  105. char strout[1000];
  106. char strtem[100];
  107. snprintf(strout,1000,"Lon Lat:\n");
  108. snprintf(strtem,100,"Lon:%11.8f\n",lon_test);strncat(strout,strtem,1000);
  109. snprintf(strtem,100,"Lat:%11.8f\n",lat_test);strncat(strout,strtem,1000);
  110. snprintf(strtem,100,"heading:%6.3f\n",heading_test);strncat(strout,strtem,1000);
  111. ui->plainTextEdit_LonLat->setPlainText(strout);
  112. }
  113. void MainWindow::normalheading(double & heading)
  114. {
  115. while(heading>=360.0)heading = heading - 360.0;
  116. while(heading<0)heading = heading + 360.0;
  117. }
  118. void MainWindow::normalhdg(double & hdg)
  119. {
  120. while(hdg >= (2.0*M_PI))hdg = hdg - M_PI * 2.0;
  121. while(hdg < 0)hdg = hdg + M_PI * 2.0;
  122. }
  123. void MainWindow::on_pushButton_SaveXY_clicked()
  124. {
  125. double lon_base,lat_base,heading_base;
  126. double lon_test,lat_test,heading_test;
  127. lon_base = ui->lineEdit_2_Lon->text().toDouble();
  128. lat_base = ui->lineEdit_2_Lat->text().toDouble();
  129. heading_base = ui->lineEdit_2_Heading->text().toDouble();
  130. lon_test = ui->lineEdit_2_Lon2->text().toDouble();
  131. lat_test = ui->lineEdit_2_Lat2->text().toDouble();
  132. heading_test = ui->lineEdit_2_Heading2->text().toDouble();
  133. char strbase[1000];
  134. snprintf(strbase,1000,"From Value:\n Base:%11.7f %11.7f %11.7f\n Test:%11.7f %11.7f %11.7f\n\n",
  135. lon_base,lat_base,heading_base,lon_test,lat_test,heading_test);
  136. QByteArray ba1;
  137. ba1 = QByteArray::fromRawData(strbase,strnlen(strbase,1000));
  138. QString str = ui->plainTextEdit_Rel->toPlainText();
  139. QByteArray ba;
  140. ba = QByteArray::fromStdString(str.toStdString());
  141. #ifdef Q_OS_WASM
  142. ba1.append(ba);
  143. QFileDialog::saveFileContent(ba1,"xy.txt");
  144. #endif
  145. }
  146. //Qt使用Emscripten的文件系统,还提供其他API:
  147. // QFile可以照常使用。默认情况下,存储的文件进入MEMFS。
  148. // QSettings具有一个基于IndexedDB的后端;请注意,QSettings在WebAssembly上是异步的。请参阅[2]上的用法示例
  149. // QFileDialog :: getOpenFileContent()打开一个本机文件对话框,用户可以在其中选择文件
  150. // QFileDialog :: saveFileContent()通过文件下载将文件保存到本地文件系统
  151. void MainWindow::on_pushButton_SaveLonLat_clicked()
  152. {
  153. double lon_base,lat_base,heading_base;
  154. double x_rel,y_rel,hdg_rel;
  155. lon_base = ui->lineEdit_3_Lon->text().toDouble();
  156. lat_base = ui->lineEdit_3_Lat->text().toDouble();
  157. heading_base = ui->lineEdit_3_Heading->text().toDouble();
  158. x_rel = ui->lineEdit_3_x->text().toDouble();
  159. y_rel = ui->lineEdit_3_y->text().toDouble();
  160. hdg_rel = ui->lineEdit_3_hdg->text().toDouble();
  161. char strbase[1000];
  162. snprintf(strbase,1000,"From Value:\n Base:%11.7f %11.7f %11.7f\n Test:%11.7f %11.7f %11.7f\n\n",
  163. lon_base,lat_base,heading_base,x_rel,y_rel,hdg_rel);
  164. QByteArray ba1;
  165. ba1 = QByteArray::fromRawData(strbase,strnlen(strbase,1000));
  166. QString str = ui->plainTextEdit_LonLat->toPlainText();
  167. QByteArray ba;
  168. ba = QByteArray::fromStdString(str.toStdString());
  169. #ifdef Q_OS_WASM
  170. ba1.append(ba);
  171. QFileDialog::saveFileContent(ba1,"lonlat.txt");
  172. #endif
  173. }