Просмотр исходного кода

change map_collectfromveh,not complete.

yuchuli 3 лет назад
Родитель
Сommit
a84799d303

+ 48 - 0
src/tool/map_collectfromveh/commif.cpp

@@ -0,0 +1,48 @@
+
+#include "modulecomm.h"
+#include "commif.h"
+
+#include <memory>
+
+
+static mcommCall  gpgpscall;
+void UpdateGPS(const char *strdata, const unsigned int nSize, const unsigned int index, const QDateTime *dt, const char *strmemname)
+{
+    (void)index;
+    (void)dt;
+    (void)strmemname;
+
+    (*gpgpscall)(strdata,nSize);
+
+//    std::shared_ptr<iv::gps::gpsimu> xgpsimu_ptr = std::shared_ptr<iv::gps::gpsimu>(new iv::gps::gpsimu);
+
+//    if(!xgpsimu_ptr->ParseFromArray(strdata,nSize))
+//    {
+//        qDebug("MainWindow::UpdateGPS Parse Error. nSize is ",nSize);
+//        return;
+//    }
+
+//    mMutex.lock();
+//    mgpsimu_ptr = xgpsimu_ptr;
+//    mbUpdate = true;
+//    mMutex.unlock();
+}
+
+void * RegisterSend(char * strmemname,const unsigned int nmemsize,const unsigned int nbufpacket)
+{
+    void * pa = iv::modulecomm::RegisterSend(strmemname,nmemsize,nbufpacket);
+    return pa;
+}
+
+void SendMsg(void * pa,char * strdata,unsigned int nsize)
+{
+    iv::modulecomm::ModuleSendMsg(pa,strdata,nsize);
+}
+
+
+void * RegisterRecvGPS(char * strmemname,mcommCall pcall)
+{
+    gpgpscall = pcall;
+    void * pa = iv::modulecomm::RegisterRecv(strmemname,UpdateGPS);
+    return pa;
+}

+ 14 - 0
src/tool/map_collectfromveh/commif.h

@@ -0,0 +1,14 @@
+#ifndef COMMIF_H
+#define COMMIF_H
+
+
+
+typedef void (* mcommCall)(const char * strdata,const unsigned int nSize);
+
+void * RegisterSend(char * strmemname,const unsigned int nmemsize,const unsigned int nbufpacket);
+void SendMsg(void * pa,char * strdata,unsigned int nsize);
+
+void * RegisterRecvGPS(char * strmemname,mcommCall pcall);
+
+
+#endif // COMMIF_H

+ 105 - 0
src/tool/map_collectfromveh/lineitem.cpp

@@ -0,0 +1,105 @@
+#include "lineitem.h"
+
+#include <math.h>
+#include <iostream>
+
+/**
+  * @brief CalcHdg
+  * 计算点0到点1的航向
+  * @param p0        Point 0
+  * @param p1        Point 1
+**/
+static double CalcHdg(QPointF p0, QPointF p1)
+{
+    double x0,y0,x1,y1;
+    x0 = p0.x();
+    y0 = p0.y();
+    x1 = p1.x();
+    y1 = p1.y();
+    if(x0 == x1)
+    {
+        if(y0 < y1)
+        {
+            return M_PI/2.0;
+        }
+        else
+            return M_PI*3.0/2.0;
+    }
+
+    double ratio = (y1-y0)/(x1-x0);
+
+    double hdg = atan(ratio);
+
+    if(ratio > 0)
+    {
+        if(y1 > y0)
+        {
+
+        }
+        else
+        {
+            hdg = hdg + M_PI;
+        }
+    }
+    else
+    {
+        if(y1 > y0)
+        {
+            hdg = hdg + M_PI;
+        }
+        else
+        {
+            hdg = hdg + 2.0*M_PI;
+        }
+    }
+
+    return hdg;
+}
+
+
+
+LineItem::LineItem(QPointF startpoint,QPointF endpoint,double fwidth)
+{
+    mstartpoint = startpoint;
+    mendpoint = endpoint;
+    mfWdith = fwidth;
+}
+
+QRectF LineItem::boundingRect() const
+{
+    return QRectF( - 10000,-10000 ,20000,
+                  20000);
+}
+void LineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+
+    Q_UNUSED(option);
+    Q_UNUSED(widget);
+
+    CalcPoint();
+    painter->setPen(Qt::NoPen);
+    painter->setBrush(Qt::black);
+    painter->drawPolygon(mPoints,4);
+
+
+}
+
+void LineItem::setratio(float ratio)
+{
+    mfratio = 1.0/ratio;
+}
+
+void LineItem::CalcPoint()
+{
+    std::cout<<"ratio; "<<mfratio<<std::endl;
+    double fwidth = mfWdith * mfratio;
+    double fhdg = CalcHdg(mstartpoint,mendpoint);
+    mPoints[0].setX(mstartpoint.x() + (fwidth/2.0)*cos(fhdg + M_PI/2.0));
+    mPoints[0].setY(mstartpoint.y()*(-1.0) + (fwidth/2.0)*sin(fhdg + M_PI/2.0));
+    mPoints[1].setX(mendpoint.x() + (fwidth/2.0)*cos(fhdg + M_PI/2.0));
+    mPoints[1].setY(mendpoint.y()*(-1.0) + (fwidth/2.0)*sin(fhdg + M_PI/2.0));
+    mPoints[2].setX(mendpoint.x() + (fwidth/2.0)*cos(fhdg - M_PI/2.0));
+    mPoints[2].setY(mendpoint.y()*(-1.0) + (fwidth/2.0)*sin(fhdg - M_PI/2.0));
+    mPoints[3].setX(mstartpoint.x() + (fwidth/2.0)*cos(fhdg - M_PI/2.0));
+    mPoints[3].setY(mstartpoint.y()*(-1.0) + (fwidth/2.0)*sin(fhdg - M_PI/2.0));
+}

+ 27 - 0
src/tool/map_collectfromveh/lineitem.h

@@ -0,0 +1,27 @@
+#ifndef LINEITEM_H
+#define LINEITEM_H
+
+#include <QGraphicsItem>
+#include <QPainter>
+
+class LineItem : public QGraphicsItem
+{
+public:
+    LineItem(QPointF startpoint,QPointF endpoint,double fviewwidth);
+    QRectF boundingRect() const override;
+    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
+    void setratio(float ratio);
+
+
+private:
+    void CalcPoint();
+private:
+    QPointF mstartpoint,mendpoint;
+    double mfWdith;
+    double mfratio = 1.0;
+    float mfoldcalratio = 1.0;
+    bool mbNeedCalc;
+    QPointF mPoints[4];
+};
+
+#endif // LINEITEM_H

+ 84 - 5
src/tool/map_collectfromveh/mainwindow.cpp

@@ -1,6 +1,9 @@
 #include "mainwindow.h"
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 #include "ui_mainwindow.h"
 
 
+#include "gnss_coordinate_convert.h"
+
+MainWindow * gw;
 
 
 #define VIEW_WIDTH 6000
 #define VIEW_WIDTH 6000
 #define VIEW_HEIGHT 6000
 #define VIEW_HEIGHT 6000
@@ -8,12 +11,29 @@
 std::string strtypevalue[]={"None","Solid","Dash","Solid Solid","Dash Dash","Solid Dash","Dash Solid"};
 std::string strtypevalue[]={"None","Solid","Dash","Solid Solid","Dash Dash","Solid Dash","Dash Solid"};
 std::string strcolorvalue[]={"White","Yellow"};
 std::string strcolorvalue[]={"White","Yellow"};
 
 
+
+void UpdateGPS(const char * strdata,const unsigned int nSize)
+{
+    std::shared_ptr<iv::gps::gpsimu> xgpsimu_ptr = std::shared_ptr<iv::gps::gpsimu>(new iv::gps::gpsimu);
+
+    if(!xgpsimu_ptr->ParseFromArray(strdata,nSize))
+    {
+        qDebug("MainWindow::UpdateGPS Parse Error. nSize is ",nSize);
+        return;
+    }
+
+    gw->UpdateGPSIMU(xgpsimu_ptr);
+}
+
+LineItem * gt;
+QGraphicsEllipseItem * gpe;
 MainWindow::MainWindow(QWidget *parent)
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
     : QMainWindow(parent)
     , ui(new Ui::MainWindow)
     , ui(new Ui::MainWindow)
 {
 {
     ui->setupUi(this);
     ui->setupUi(this);
 
 
+
     ui->horizontalSlider_width->setRange(0,1000);
     ui->horizontalSlider_width->setRange(0,1000);
     ui->horizontalSlider_width->setValue(360);
     ui->horizontalSlider_width->setValue(360);
     ui->lineEdit->setText("3.6");
     ui->lineEdit->setText("3.6");
@@ -37,6 +57,7 @@ MainWindow::MainWindow(QWidget *parent)
 
 
     ui->lineEdit_DisLeft->setText("1.8");
     ui->lineEdit_DisLeft->setText("1.8");
     ui->lineEdit_DisRight->setText("1.8");
     ui->lineEdit_DisRight->setText("1.8");
+    ui->lineEdit_DisRight->setEnabled(false);
 
 
     ui->radioButton_Auto->setChecked(true);
     ui->radioButton_Auto->setChecked(true);
     ui->pushButton_ManualCollect->setEnabled(false);
     ui->pushButton_ManualCollect->setEnabled(false);
@@ -45,11 +66,6 @@ MainWindow::MainWindow(QWidget *parent)
     myview->setObjectName(QStringLiteral("graphicsView"));
     myview->setObjectName(QStringLiteral("graphicsView"));
     myview->setGeometry(QRect(820, 10,500, 585));
     myview->setGeometry(QRect(820, 10,500, 585));
 
 
-//    image = new QImage(2000, 2000, QImage::Format_RGB32);//画布的初始化大小设为300*300,使用32位颜色
-//    myview->setCacheMode(myview->CacheBackground);
-//    painter=new QPainter(this);
-//    painter->end();
-//    scene = new QGraphicsScene;
 
 
     mpscene = new  QGraphicsScene(0,0,VIEW_WIDTH,VIEW_HEIGHT);
     mpscene = new  QGraphicsScene(0,0,VIEW_WIDTH,VIEW_HEIGHT);
     mpscene->setBackgroundBrush(Qt::white);
     mpscene->setBackgroundBrush(Qt::white);
@@ -66,8 +82,26 @@ MainWindow::MainWindow(QWidget *parent)
     mpscene->addItem(ptext);
     mpscene->addItem(ptext);
     ptext->setPos(1000,1000);
     ptext->setPos(1000,1000);
 
 
+    LineItem * ptest = new LineItem(QPointF(100,100),QPointF(2000,100),1.0);
+    mpscene->addItem(ptest);
+    ptest->setPos(3000,3000);
+    gt = ptest;
+
+    QGraphicsEllipseItem * pe = new QGraphicsEllipseItem(-10.0,-10.0,20.0,20.0);
+    pe->setPos(3000,3000);
+    QBrush xBrush;
+    xBrush.setColor(Qt::blue);
+    pe->setBrush(Qt::green);
+    pe->setPen(Qt::NoPen);
+    mpscene->addItem(pe);
+    gpe = pe;
+
+    connect(this,SIGNAL(updategps()),this,SLOT(ongpsupdate()));
+
     setWindowTitle("Collect Data From Vehicle");
     setWindowTitle("Collect Data From Vehicle");
 
 
+    gw = this;
+
 }
 }
 
 
 MainWindow::~MainWindow()
 MainWindow::~MainWindow()
@@ -84,6 +118,7 @@ void MainWindow::on_lineEdit_textChanged(const QString &arg1)
     if(value>10)return;
     if(value>10)return;
     int nvalue = value *100.0;
     int nvalue = value *100.0;
     ui->horizontalSlider_width->setValue(nvalue);
     ui->horizontalSlider_width->setValue(nvalue);
+    ChangeRightValue();
 }
 }
 
 
 void MainWindow::on_horizontalSlider_width_sliderMoved(int position)
 void MainWindow::on_horizontalSlider_width_sliderMoved(int position)
@@ -92,6 +127,7 @@ void MainWindow::on_horizontalSlider_width_sliderMoved(int position)
     double fvalue = nvalue;
     double fvalue = nvalue;
     fvalue = fvalue * 0.01;
     fvalue = fvalue * 0.01;
     ui->lineEdit->setText(QString::number(fvalue));
     ui->lineEdit->setText(QString::number(fvalue));
+    ChangeRightValue();
 }
 }
 
 
 void MainWindow::resizeEvent(QResizeEvent *event)
 void MainWindow::resizeEvent(QResizeEvent *event)
@@ -111,6 +147,49 @@ void MainWindow::on_pushButton_NewRoad_clicked()
 void MainWindow::paintEvent(QPaintEvent * event)
 void MainWindow::paintEvent(QPaintEvent * event)
 {
 {
     (void)event;
     (void)event;
+
+    double ratio = myview->getbeishu();
+    gt->setratio(ratio);
+    gpe->setScale(1.0/ratio);
     myview->setScene(mpscene);
     myview->setScene(mpscene);
 
 
 }
 }
+
+void MainWindow::ChangeRightValue()
+{
+    double flanewidth = ui->lineEdit->text().toDouble();
+    double fleftvalue = ui->lineEdit_DisLeft->text().toDouble();
+    double fdisright = flanewidth - fleftvalue;
+    ui->lineEdit_DisRight->setText(QString::number(fdisright));
+}
+
+void MainWindow::on_lineEdit_DisLeft_textChanged(const QString &arg1)
+{
+    if(arg1.length() == 0)return;
+    ChangeRightValue();
+}
+
+void MainWindow::UpdateGPSIMU(std::shared_ptr<iv::gps::gpsimu> xgpsimu_ptr)
+{
+    mMutex.lock();
+    mgpsimu_ptr = xgpsimu_ptr;
+    mMutex.lock();
+
+    if(mbSetZero == false)
+    {
+        mlon0 = mgpsimu_ptr->lon();
+        mlat0 = mgpsimu_ptr->lat();
+        mbSetZero = true;
+    }
+
+    emit updategps();
+}
+
+void MainWindow::ongpsupdate()
+{
+    double xrelx,xrely,x0,y0,x1,y1;
+    GaussProjCal(mlon0,mlat0,&x0,&y0);
+    GaussProjCal(mgpsimu_ptr->lon(),mgpsimu_ptr->lat(),&x1,&y1);
+    xrelx = x1-x0;
+    xrely = y1-y0;
+}

+ 29 - 6
src/tool/map_collectfromveh/mainwindow.h

@@ -2,9 +2,15 @@
 #define MAINWINDOW_H
 #define MAINWINDOW_H
 
 
 #include <QMainWindow>
 #include <QMainWindow>
+#include <QMutex>
+
+#include <memory>
 
 
 #include "myview.h"
 #include "myview.h"
 
 
+#include "lineitem.h"
+#include "gpsimu.pb.h"
+
 QT_BEGIN_NAMESPACE
 QT_BEGIN_NAMESPACE
 namespace Ui { class MainWindow; }
 namespace Ui { class MainWindow; }
 QT_END_NAMESPACE
 QT_END_NAMESPACE
@@ -26,23 +32,40 @@ private slots:
 
 
     virtual void paintEvent(QPaintEvent *);
     virtual void paintEvent(QPaintEvent *);
 
 
+    void on_lineEdit_DisLeft_textChanged(const QString &arg1);
+
+    void ongpsupdate();
+
 public:
 public:
      void resizeEvent(QResizeEvent *event);
      void resizeEvent(QResizeEvent *event);
 
 
+public:
+     void UpdateGPSIMU(std::shared_ptr<iv::gps::gpsimu> xgpsimu_ptr);
+
+signals:
+     void updategps();
+
 
 
+
+
+private:
+    void ChangeRightValue();
 private:
 private:
     Ui::MainWindow *ui;
     Ui::MainWindow *ui;
 
 
     MyView *myview;
     MyView *myview;
 
 
+    QGraphicsScene * mpscene;
 
 
-//    QGraphicsView *view;
-//    QImage *image;
-//    QPainter *painter;
-//    QTimer *timer;
-//    QGraphicsScene *scene;
+    std::vector<QGraphicsEllipseItem * > mvectorLeftPointItem;
+    std::vector<QGraphicsEllipseItem * > mvectorRightPointItem;
+    std::vector<QGraphicsEllipseItem * > mvectorMainPointItem;
 
 
-    QGraphicsScene * mpscene;
+    std::shared_ptr<iv::gps::gpsimu> mgpsimu_ptr;
+    QMutex mMutex;
+
+    double mlon0,mlat0;
+    bool mbSetZero = false;
 
 
 };
 };
 #endif // MAINWINDOW_H
 #endif // MAINWINDOW_H

+ 19 - 0
src/tool/map_collectfromveh/map_collectfromveh.pro

@@ -9,11 +9,19 @@ CONFIG += c++11
 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 
 
 SOURCES += \
 SOURCES += \
+    ../../common/common/math/gnss_coordinate_convert.cpp \
+    ../../include/msgtype/gpsimu.pb.cc \
+    commif.cpp \
+    lineitem.cpp \
     main.cpp \
     main.cpp \
     mainwindow.cpp \
     mainwindow.cpp \
     myview.cpp
     myview.cpp
 
 
 HEADERS += \
 HEADERS += \
+    ../../common/common/math/gnss_coordinate_convert.h \
+    ../../include/msgtype/gpsimu.pb.h \
+    commif.h \
+    lineitem.h \
     mainwindow.h \
     mainwindow.h \
     myview.h
     myview.h
 
 
@@ -24,3 +32,14 @@ FORMS += \
 qnx: target.path = /tmp/$${TARGET}/bin
 qnx: target.path = /tmp/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
 !isEmpty(target.path): INSTALLS += target
 !isEmpty(target.path): INSTALLS += target
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivprotobuf.pri ) {
+    error( "Couldn't find the ivprotobuf.pri file!" )
+}
+
+INCLUDEPATH += ../../common/common/math
+

+ 5 - 0
src/tool/map_collectfromveh/myview.cpp

@@ -216,3 +216,8 @@ void MyView::pinchTriggered(QPinchGesture *gesture)
 
 
 }
 }
 
 
+double MyView::getbeishu()
+{
+    return beishu;
+}
+

+ 2 - 0
src/tool/map_collectfromveh/myview.h

@@ -25,6 +25,8 @@ public:
     qreal x, y, beishu;
     qreal x, y, beishu;
 
 
     void zoomone();
     void zoomone();
+
+    double getbeishu();
 protected:
 protected:
     void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
     void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
     void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
     void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;