|
@@ -0,0 +1,247 @@
|
|
|
+#include "mainwindow.h"
|
|
|
+#include "ui_mainwindow.h"
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+#include <QMessageBox>
|
|
|
+#include <math.h>
|
|
|
+
|
|
|
+#include "google/protobuf/io/zero_copy_stream_impl.h"
|
|
|
+#include "google/protobuf/text_format.h"
|
|
|
+
|
|
|
+#define VIEW_WIDTH 6000
|
|
|
+#define VIEW_HEIGHT 6000
|
|
|
+
|
|
|
+MainWindow::MainWindow(QWidget *parent) :
|
|
|
+ QMainWindow(parent),
|
|
|
+ ui(new Ui::MainWindow)
|
|
|
+{
|
|
|
+ ui->setupUi(this);
|
|
|
+
|
|
|
+ setWindowTitle(tr("SIASUN Remote Control"));
|
|
|
+
|
|
|
+ mmyview = new MyView(ui->Map);
|
|
|
+ mmyview->setObjectName(QStringLiteral("graphicsView"));
|
|
|
+ mmyview->setGeometry(QRect(0, 0, 800, 530));
|
|
|
+ mmyview->setCacheMode(mmyview->CacheBackground);
|
|
|
+
|
|
|
+ mpscene = new QGraphicsScene;
|
|
|
+
|
|
|
+ mpscene = new QGraphicsScene(0,0,VIEW_WIDTH,VIEW_HEIGHT);
|
|
|
+ mpscene->setBackgroundBrush(Qt::white);
|
|
|
+ mmyview->setScene(mpscene);
|
|
|
+
|
|
|
+ mmyview->centerOn(VIEW_WIDTH/2,VIEW_HEIGHT/2);
|
|
|
+
|
|
|
+ ui->tabWidget->setCurrentIndex(0);
|
|
|
+
|
|
|
+ mpdkp = new DialogKickPoint(&msissunmap, this);
|
|
|
+
|
|
|
+ connect(mmyview,SIGNAL(dbclickxy(double,double)),this,SLOT(ondbclick(double,double)));
|
|
|
+}
|
|
|
+
|
|
|
+MainWindow::~MainWindow()
|
|
|
+{
|
|
|
+ delete ui;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::paintEvent(QPaintEvent * event)
|
|
|
+{
|
|
|
+ (void)event;
|
|
|
+ static double foldratio = 1.0;
|
|
|
+
|
|
|
+
|
|
|
+ double ratio = mmyview->getbeishu();
|
|
|
+ if(fabs(ratio - foldratio)>0.000001)
|
|
|
+ {
|
|
|
+ foldratio = ratio;
|
|
|
+ double fscale = 1.0/ratio;
|
|
|
+ unsigned int i;
|
|
|
+ for(i=0;i<mvectorPickPointItem.size();i++)
|
|
|
+ {
|
|
|
+ mvectorPickPointItem[i]->setScale(fscale);
|
|
|
+ }
|
|
|
+ for(i=0;i<mvectorMapPointItem.size();i++)
|
|
|
+ {
|
|
|
+ mvectorMapPointItem[i]->setScale(fscale);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ mmyview->setScene(mpscene);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void MainWindow::resizeEvent(QResizeEvent *event)
|
|
|
+{
|
|
|
+ (void)event;
|
|
|
+ QSize sizemain = ui->centralWidget->size();
|
|
|
+ ui->tabWidget->setGeometry(0,0,sizemain.width(),sizemain.height());
|
|
|
+
|
|
|
+ QSize sizemap = ui->Map->size();
|
|
|
+ mmyview->setGeometry(0,0,sizemap.width(),sizemap.height());
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_actionInsert_Kick_Point_triggered()
|
|
|
+{
|
|
|
+ mpdkp->setModal(false);
|
|
|
+ mpdkp->show();
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_actionSave_triggered()
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ QString strfilepath = "/home/yuchuli/testsia.txt";
|
|
|
+ using google::protobuf::TextFormat;
|
|
|
+ using google::protobuf::io::FileOutputStream;
|
|
|
+ using google::protobuf::io::ZeroCopyOutputStream;
|
|
|
+ std::string strout;
|
|
|
+ ZeroCopyOutputStream *output = new google::protobuf::io::StringOutputStream(&strout);//new FileOutputStream(file_descriptor);
|
|
|
+
|
|
|
+ bool success = TextFormat::Print(msissunmap, output);
|
|
|
+ if(success)
|
|
|
+ {
|
|
|
+ QFile xFile;
|
|
|
+ xFile.setFileName(strfilepath);
|
|
|
+ if(xFile.open(QIODevice::ReadWrite))
|
|
|
+ {
|
|
|
+ xFile.write(strout.data(),strout.size());
|
|
|
+ xFile.close();
|
|
|
+ }
|
|
|
+ // std::cout<<strout<<std::endl;
|
|
|
+ // qDebug(strout.data());
|
|
|
+ }
|
|
|
+ delete output;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_actionLoad_triggered()
|
|
|
+{
|
|
|
+ QString strfilepath = "/home/yuchuli/testsia.txt";
|
|
|
+
|
|
|
+ QFile xFile;
|
|
|
+ xFile.setFileName(strfilepath);
|
|
|
+ QByteArray ba;
|
|
|
+ if(xFile.open(QIODevice::ReadOnly))
|
|
|
+ {
|
|
|
+ ba = xFile.readAll();
|
|
|
+ xFile.close();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,tr("Warning"),tr("Open File Fail."),QMessageBox::YesAll);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ using google::protobuf::TextFormat;
|
|
|
+ using google::protobuf::io::FileInputStream;
|
|
|
+ using google::protobuf::io::ZeroCopyInputStream;
|
|
|
+ std::string strout;
|
|
|
+ ZeroCopyInputStream *input = new google::protobuf::io::ArrayInputStream(ba.data(),ba.size());//new FileOutputStream(file_descriptor);
|
|
|
+
|
|
|
+ iv::siasun::map xsiasun;
|
|
|
+ bool success = TextFormat::Parse(input,&xsiasun);
|
|
|
+ if(success)
|
|
|
+ {
|
|
|
+ msissunmap.CopyFrom(xsiasun);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,tr("Warning"),tr("Load map fail."),QMessageBox::YesAll);
|
|
|
+ delete input;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ delete input;
|
|
|
+
|
|
|
+ if(msissunmap.mutable_mkickarray()->mkick_size() == 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ iv::siasun::kickpointarray * pkickarray = msissunmap.mutable_mkickarray();
|
|
|
+
|
|
|
+ int i;
|
|
|
+ mlon0 = pkickarray->mutable_mkick(0)->mflon();
|
|
|
+ mlat0 = pkickarray->mutable_mkick(0)->mflat();
|
|
|
+
|
|
|
+ for(i=0;i<pkickarray->mkick_size();i++)
|
|
|
+ {
|
|
|
+ iv::siasun::kickpoint * ppoint = pkickarray->mutable_mkick(i);
|
|
|
+ double x0,y0;
|
|
|
+ double x,y;
|
|
|
+ GaussProjCal(ppoint->mflon(),ppoint->mflat(),&x,&y);
|
|
|
+ GaussProjCal(mlon0,mlat0,&x0,&y0);
|
|
|
+ x = x - x0;
|
|
|
+ y = y - y0;
|
|
|
+
|
|
|
+ double ratio = mmyview->getbeishu();
|
|
|
+ double fscale = 1.0/ratio;
|
|
|
+ QGraphicsEllipseItem * pmainitem;
|
|
|
+ pmainitem = new QGraphicsEllipseItem(0-mfPointSize/2.0,0*(-1)-mfPointSize/2.0,mfPointSize,mfPointSize);
|
|
|
+ pmainitem->setBrush(Qt::blue);
|
|
|
+ pmainitem->setPen(Qt::NoPen);
|
|
|
+ pmainitem->setPos(VIEW_WIDTH/2 + x,VIEW_HEIGHT/2 -y);
|
|
|
+ pmainitem->setScale(fscale);
|
|
|
+ mpscene->addItem(pmainitem);
|
|
|
+ mvectorPickPointItem.push_back(pmainitem);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_actionInsert_Map_Point_triggered()
|
|
|
+{
|
|
|
+ if(mbInsertMapPoint == false)
|
|
|
+ {
|
|
|
+ ui->actionInsert_Map_Point->setText(tr("Stop Insert Map Point"));
|
|
|
+ mbInsertMapPoint = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ui->actionInsert_Map_Point->setText(tr("Start Insert Map Point"));
|
|
|
+ mbInsertMapPoint = false;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::ondbclick(double x,double y)
|
|
|
+{
|
|
|
+ if(mbInsertMapPoint)
|
|
|
+ {
|
|
|
+
|
|
|
+ double fx,fy;
|
|
|
+ fx = x - VIEW_WIDTH/2;
|
|
|
+ fy = VIEW_HEIGHT/2 - y;
|
|
|
+ double x0,y0;
|
|
|
+ GaussProjCal(mlon0,mlat0,&x0,&y0);
|
|
|
+ double flonx,flaty;
|
|
|
+ flonx = fx + x0;
|
|
|
+ flaty = fy + y0;
|
|
|
+ double flon,flat;
|
|
|
+ GaussProjInvCal(flonx,flaty,&flon,&flat);
|
|
|
+ iv::siasun::waypointarray * pwayarray = msissunmap.mutable_mwayarray();
|
|
|
+ if(pwayarray == NULL)
|
|
|
+ {
|
|
|
+ std::cout<<"way array is NULL."<<std::endl;
|
|
|
+ iv::siasun::waypointarray * pnew = new iv::siasun::waypointarray;
|
|
|
+ msissunmap.set_allocated_mwayarray(pnew);
|
|
|
+ pwayarray = msissunmap.mutable_mwayarray();
|
|
|
+ }
|
|
|
+ iv::siasun::waypoint * pwaypoint = pwayarray->add_mwaypoint();
|
|
|
+ pwaypoint->set_mflat(flat);
|
|
|
+ pwaypoint->set_mflon(flon);
|
|
|
+
|
|
|
+
|
|
|
+ double ratio = mmyview->getbeishu();
|
|
|
+ double fscale = 1.0/ratio;
|
|
|
+ QGraphicsEllipseItem * pmainitem;
|
|
|
+ pmainitem = new QGraphicsEllipseItem(0-mfPointSize/2.0,0*(-1)-mfPointSize/2.0,mfPointSize,mfPointSize);
|
|
|
+ pmainitem->setBrush(Qt::green);
|
|
|
+ pmainitem->setPen(Qt::NoPen);
|
|
|
+ pmainitem->setPos(x,y);
|
|
|
+ pmainitem->setScale(fscale);
|
|
|
+ mpscene->addItem(pmainitem);
|
|
|
+ mvectorPickPointItem.push_back(pmainitem);
|
|
|
+ }
|
|
|
+}
|