Browse Source

change tool_siasun.

yuchuli 2 years ago
parent
commit
2fea9cde46

+ 135 - 0
src/tool/tool_siasun/mainwindow.cpp

@@ -8,6 +8,8 @@
 #include "google/protobuf/io/zero_copy_stream_impl.h"
 #include "google/protobuf/text_format.h"
 
+
+
 #define VIEW_WIDTH 6000
 #define VIEW_HEIGHT 6000
 
@@ -65,8 +67,18 @@ void MainWindow::paintEvent(QPaintEvent * event)
             mvectorMapPointItem[i]->setScale(fscale);
         }
 
+        for(i=0;i<(int)mvectorwidthline.size();i++)
+        {
+            mvectorwidthline[i]->ChangeWidth(mfLineWidth*fscale);
+        }
+
+        if(mpSelectPointItem != NULL)
+        {
+            mpSelectPointItem->setScale(fscale);
+        }
     }
 
+
     mmyview->setScene(mpscene);
 
 }
@@ -241,7 +253,130 @@ void MainWindow::ondbclick(double x,double y)
         pmainitem->setPen(Qt::NoPen);
         pmainitem->setPos(x,y);
         pmainitem->setScale(fscale);
+
         mpscene->addItem(pmainitem);
         mvectorPickPointItem.push_back(pmainitem);
     }
+    else
+    {
+        if(mnSelectMode == 1)
+        {
+            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 fdismin = 1000000.0;
+            int index = -1;
+            int i;
+            double xv,yv;
+            iv::siasun::kickpointarray * parray = msissunmap.mutable_mkickarray();
+            for(i=0;i<parray->mkick_size();i++)
+            {
+                iv::siasun::kickpoint * p = parray->mutable_mkick(i);
+                double p1x,p1y;
+                GaussProjCal(p->mflon(),p->mflat(),&p1x,&p1y);
+                double fdis = sqrt(pow(p1x-flonx,2)+pow(p1y-flaty,2));
+                if(fdis<fdismin)
+                {
+                    fdismin = fdis;
+                    index = i;
+                    xv = p1x;
+                    yv = p1y;
+
+                }
+                std::cout<<" fdis: "<<fdismin<<std::endl;
+            }
+            if(fdismin < mfNearDisLimit)
+            {
+                double ratio = mmyview->getbeishu();
+                double fscale = 1.0/ratio;
+                if(mpSelectPointItem == NULL)
+                {
+
+                    QGraphicsEllipseItem * pmainitem;
+                    pmainitem = new QGraphicsEllipseItem(0-mfPointSize*2.0/2.0,0*(-1)-mfPointSize*2.0/2.0,mfPointSize*2.0,mfPointSize*2.0);
+                    pmainitem->setBrush(Qt::red);
+                    pmainitem->setPen(Qt::NoPen);
+                    pmainitem->setPos(VIEW_WIDTH/2 + xv-x0,VIEW_HEIGHT/2 -(yv-y0));
+                    pmainitem->setScale(fscale);
+                    mpscene->addItem(pmainitem);
+                    mpSelectPointItem = pmainitem;
+                }
+                else
+                {
+                    mpSelectPointItem->setPos(VIEW_WIDTH/2 + xv-x0,VIEW_HEIGHT/2 -(yv-y0));
+                    mpSelectPointItem->setScale(fscale);
+                }
+            }
+        }
+    }
+}
+
+void MainWindow::on_actionCreate_Map_triggered()
+{
+    iv::siasun::waypointarray  * pwayarray  = msissunmap.mutable_mwayarray();
+    if(pwayarray == NULL)
+    {
+        QMessageBox::warning(this,tr("Warning"),tr("No Way Point."),QMessageBox::YesAll);
+        return;
+    }
+    if(pwayarray->mwaypoint_size()<2)
+    {
+        QMessageBox::warning(this,tr("Warning"),tr("At Least 2 point."),QMessageBox::YesAll);
+        return;
+    }
+
+    mvectorlinemap.clear();
+    int i;
+    for(i=0;i<(int)mvectorwidthline.size();i++)
+    {
+        mpscene->removeItem(mvectorwidthline[i]->GetWidthLine());
+        delete mvectorwidthline[i];
+    }
+    mvectorwidthline.clear();
+
+    sissunmap xsissunmap;
+    mvectorlinemap = xsissunmap.GetMapLine(&msissunmap);
+
+
+    double x0,y0;
+    GaussProjCal(mlon0,mlat0,&x0,&y0);
+    for(i=0;i<(int)mvectorlinemap.size();i++)
+    {
+        widthline *pline = new widthline(mvectorlinemap[i].mfx1-x0,mvectorlinemap[i].mfy1-y0,
+                                         mvectorlinemap[i].mfx2-x0,mvectorlinemap[i].mfy2-y0,mfLineWidth,mColorBrush_mapline,VIEW_WIDTH/2,VIEW_HEIGHT/2);
+        mpscene->addItem(pline->GetWidthLine());
+        double ratio = mmyview->getbeishu();
+        double fscale = 1.0/ratio;
+        pline->ChangeWidth(fscale*mfLineWidth);
+        mvectorwidthline.push_back(pline);
+
+    }
+
+
+
+}
+
+void MainWindow::on_actionSelect_None_triggered()
+{
+    mnSelectMode = 0;
+    if(mpSelectPointItem != NULL)
+    {
+        mpscene->removeItem(mpSelectPointItem);
+        mpSelectPointItem = NULL;
+    }
+}
+
+void MainWindow::on_actionSelect_Kick_triggered()
+{
+   mnSelectMode = 1;
+}
+
+void MainWindow::on_actionSelect_Point_triggered()
+{
+    mnSelectMode = 2;
 }

+ 25 - 0
src/tool/tool_siasun/mainwindow.h

@@ -11,12 +11,18 @@
 
 #include "siasun.pb.h"
 
+#include "sissunmap.h"
+
 #include "gnss_coordinate_convert.h"
+#include "widthline.h"
 
 namespace Ui {
 class MainWindow;
 }
 
+
+
+
 class MainWindow : public QMainWindow
 {
     Q_OBJECT
@@ -40,6 +46,14 @@ private slots:
 
      void ondbclick(double x,double y);
 
+     void on_actionCreate_Map_triggered();
+
+     void on_actionSelect_None_triggered();
+
+     void on_actionSelect_Kick_triggered();
+
+     void on_actionSelect_Point_triggered();
+
 private:
     Ui::MainWindow *ui;
 
@@ -57,12 +71,23 @@ private:
     std::vector<QGraphicsEllipseItem * > mvectorPickPointItem;
     std::vector<QGraphicsEllipseItem * > mvectorMapPointItem;
 
+    QGraphicsEllipseItem * mpSelectPointItem = NULL;
+
 
 //    QGraphicsEllipseItem * mpNowPosItem;
     const double mfPointSize = 9.0;
+    const double mfNearDisLimit = 10.0;
 
     bool mbInsertMapPoint = false;
 
+    std::vector<iv::mapline> mvectorlinemap;
+    std::vector<widthline *> mvectorwidthline;
+
+    double mfLineWidth = 3;
+    QColor mColorBrush_mapline = Qt::darkGreen;
+
+    int mnSelectMode = 0;
+
 };
 
 #endif // MAINWINDOW_H

+ 36 - 0
src/tool/tool_siasun/mainwindow.ui

@@ -61,8 +61,24 @@
     <addaction name="separator"/>
     <addaction name="actionInsert_Kick_Point"/>
     <addaction name="actionInsert_Map_Point"/>
+    <addaction name="actionCreate_Map"/>
+   </widget>
+   <widget class="QMenu" name="menuView">
+    <property name="title">
+     <string>View</string>
+    </property>
+    <widget class="QMenu" name="menuSelect">
+     <property name="title">
+      <string>Select</string>
+     </property>
+     <addaction name="actionSelect_None"/>
+     <addaction name="actionSelect_Kick"/>
+     <addaction name="actionSelect_Point"/>
+    </widget>
+    <addaction name="menuSelect"/>
    </widget>
    <addaction name="menuFile"/>
+   <addaction name="menuView"/>
    <addaction name="menuMap"/>
   </widget>
   <widget class="QToolBar" name="mainToolBar">
@@ -94,6 +110,26 @@
     <string>Start Insert Map Point</string>
    </property>
   </action>
+  <action name="actionCreate_Map">
+   <property name="text">
+    <string>Create Map</string>
+   </property>
+  </action>
+  <action name="actionSelect_None">
+   <property name="text">
+    <string>Select None</string>
+   </property>
+  </action>
+  <action name="actionSelect_Kick">
+   <property name="text">
+    <string>Select Kick</string>
+   </property>
+  </action>
+  <action name="actionSelect_Point">
+   <property name="text">
+    <string>Select Point</string>
+   </property>
+  </action>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
  <resources/>

+ 323 - 0
src/tool/tool_siasun/sissunmap.cpp

@@ -0,0 +1,323 @@
+#include "sissunmap.h"
+
+#include "math.h"
+
+sissunmap::sissunmap()
+{
+
+}
+
+
+double sissunmap::GetPointDis(iv::siasun::waypoint * p1,iv::siasun::waypoint * p2)
+{
+    double x1,y1,x2,y2;
+    GaussProjCal(p1->mflon(),p1->mflat(),&x1,&y1);
+    GaussProjCal(p2->mflon(),p2->mflat(),&x2,&y2);
+    return  sqrt(pow(x2-x1,2)+pow(y2-y1,2));
+}
+
+double sissunmap::GetHdg(iv::siasun::waypoint * p1,iv::siasun::waypoint * p2)
+{
+    double x0,y0,x1,y1;
+    GaussProjCal(p1->mflon(),p1->mflat(),&x0,&y0);
+    GaussProjCal(p2->mflon(),p2->mflat(),&x1,&y1);
+
+    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;
+}
+
+bool sissunmap::CheckPointNear(std::vector<int> & xvectorpointindex,iv::siasun::waypointarray * ppointarray,iv::siasun::waypoint * p)
+{
+    int i;
+    for(i=0;i<(int)xvectorpointindex.size();i++)
+    {
+        iv::siasun::waypoint * p2 = ppointarray->mutable_mwaypoint(xvectorpointindex[i]);
+        double fdis = GetPointDis(p,p2);
+        if(fdis<mfDisMin)
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
+double sissunmap::GetPoint2LineCrossDis(QPointF xpoint, QPointF linepoint1, QPointF linepoint2,double & spos,int & nnear,bool & bright)
+{
+
+    double spp =  (linepoint1.x()-xpoint.x())*(linepoint2.y()-xpoint.y())-(linepoint1.y()-xpoint.y())*(linepoint2.x()-xpoint.x()) ;
+    if(spp>0)
+    {
+        bright = false;
+    }
+    else
+    {
+        bright = true;
+    }
+    double xc,yc,fdis;
+    if(linepoint1.x() == linepoint2.x())
+    {
+        xc = linepoint1.x();
+        yc = xpoint.y();
+    }
+    else
+    {
+        double k, b;/*y=kx+b*/
+        k = (linepoint2.y() - linepoint1.y()) / (linepoint2.x() - linepoint1.x());
+        b = linepoint2.y()  - linepoint2.x() * k;
+
+        double A,B,C;
+        A= k;
+        B = -1;
+        C = b;
+
+        xc = (B*B*xpoint.x() - A*B*xpoint.y() - A*C)/(A*A + B*B);
+        yc = (A*A*xpoint.y() - A*B*xpoint.x() - B*C)/(A*A + B*B);  //https://blog.csdn.net/hbuxiaoshe/article/details/5889366
+    }
+
+    fdis = sqrt(pow(xc - xpoint.x(),2) + pow(yc - xpoint.y(),2));
+    if((xc - linepoint1.x())*(xc-linepoint2.x())<=0)
+    {
+
+        spos = sqrt(pow(xc - linepoint1.x(),2)+pow(yc-linepoint1.y(),2));
+        nnear = 0;
+    }
+    else
+    {
+        double fdis1 = sqrt(pow(linepoint1.x() - xpoint.x(),2)+pow(linepoint1.y() - xpoint.y(),2));
+        double fdis2 = sqrt(pow(linepoint2.x()-xpoint.x(),2)+pow(linepoint2.y()-xpoint.y(),2));
+        if(fdis1<fdis2)
+        {
+            nnear = 1;
+            spos = -sqrt(pow(xc - linepoint1.x(),2)+pow(yc-linepoint1.y(),2));
+        }
+        else
+        {
+            nnear = 2;
+            spos = -sqrt(pow(xc - linepoint2.x(),2)+pow(yc-linepoint2.y(),2));
+        }
+    }
+    if(spp<0)fdis = fdis * (-1.0);  //right, dis < 0;
+    return fdis;
+}
+
+
+int sissunmap::JustPointPos(std::vector<int> & xvectorpointindex,iv::siasun::waypointarray * ppointarray,iv::siasun::waypoint * p)
+{
+    if(xvectorpointindex.size() <= 1)return 1;
+    int index1min = -1;
+    int index2min = -1;
+    double fdis1min = 1000000000.0;
+    double fdis2min = 1000000000.0;
+    int i;
+    for(i=0;i<(int)xvectorpointindex.size();i++)
+    {
+        double fdis = GetPointDis(ppointarray->mutable_mwaypoint(xvectorpointindex[i]),p);
+        if(index1min == -1)
+        {
+            index1min = i;
+            fdis1min = fdis;
+        }
+        else
+        {
+            if(index2min == -1)
+            {
+                if(fdis<fdis1min)
+                {
+                    index2min = index1min;
+                    fdis2min = fdis1min;
+                    index1min = i;
+                    fdis1min = fdis;
+                }
+                else
+                {
+                    index2min = i;
+                    fdis2min = fdis;
+                }
+            }
+            else
+            {
+                if(fdis<fdis1min)
+                {
+                    index2min = index1min;
+                    fdis2min = fdis1min;
+                    index1min = i;
+                    fdis1min = fdis;
+                }
+                else
+                {
+                    if(fdis<fdis2min)
+                    {
+                        index2min = i;
+                        fdis2min = fdis;
+                    }
+                }
+            }
+        }
+    }
+
+    if(index1min>index2min)
+    {
+        int temindex;
+        double fdistem;
+        temindex = index1min;
+        fdistem = fdis1min;
+        fdis1min = fdis2min;
+        index1min = index2min;
+        fdis2min = fdistem;
+        index2min = temindex;
+    }
+
+    double x,y;
+    double x1,y1;
+    double x2,y2;
+    iv::siasun::waypoint * p1 = ppointarray->mutable_mwaypoint(xvectorpointindex[index1min]);
+    iv::siasun::waypoint * p2 = ppointarray->mutable_mwaypoint(xvectorpointindex[index2min]);
+    GaussProjCal(p->mflon(),p->mflat(),&x,&y);
+    GaussProjCal(p1->mflon(),p1->mflat(),&x1,&y1);
+    GaussProjCal(p2->mflon(),p2->mflat(),&x2,&y2);
+
+    double spos;
+    int near;
+    bool bright;
+    GetPoint2LineCrossDis(QPointF(x,y),QPointF(x1,y1),QPointF(x2,y2),spos,near,bright);
+
+    if(near == 0)return index2min;
+    if(near == 1)return  index1min;
+    return  index2min+1;
+}
+
+std::vector<iv::mapline> sissunmap::GetMapLine(iv::siasun::map *psiamap)
+{
+    std::vector<iv::mapline> xvectormapline;
+    iv::mapline xmapline;
+    iv::siasun::waypointarray * pwayarray = psiamap->mutable_mwayarray();
+
+    if(pwayarray == NULL)return xvectormapline;
+
+    std::vector<int> xvectorpointindex;
+    int index = 0;
+
+    xvectorpointindex.push_back(0);
+    iv::siasun::waypoint * ppoint;
+
+    for(index =1;index<pwayarray->mwaypoint_size();index++)
+    {
+        ppoint = pwayarray->mutable_mwaypoint(index);
+        if(ppoint == NULL)return xvectormapline;
+
+        bool bPointNear = CheckPointNear(xvectorpointindex,pwayarray,ppoint);
+        if(bPointNear == false)
+        {
+            xvectorpointindex.push_back(index);
+            index++;
+            break;
+        }
+
+    }
+
+    int i;
+    for(i=index;i<pwayarray->mwaypoint_size();i++)
+    {
+        ppoint = pwayarray->mutable_mwaypoint(i);
+        if(ppoint == NULL)return xvectormapline;
+
+        bool bPointNear = CheckPointNear(xvectorpointindex,pwayarray,ppoint);
+        if(bPointNear == true)
+        {
+            std::cout<<" point at "<<i<<" is near exist point. "<<std::endl;
+            continue;
+        }
+
+        int npos = JustPointPos(xvectorpointindex,pwayarray,ppoint);
+        if(npos>= xvectorpointindex.size())xvectorpointindex.push_back(i);
+        else
+        {
+             xvectorpointindex.insert(xvectorpointindex.begin()+npos,i);
+        }
+    }
+
+
+//    for(i=0;i<(int)xvectorpointindex.size();i++)
+//    {
+//        std::cout<<" i: "<<i<<" index: "<<xvectorpointindex[i]<<std::endl;
+//    }
+
+    for(i=1;i<(int)xvectorpointindex.size();i++)
+    {
+        iv::mapline xmapline;
+        iv::siasun::waypoint * p1 = pwayarray->mutable_mwaypoint(xvectorpointindex[i-1]);
+        iv::siasun::waypoint * p2 = pwayarray->mutable_mwaypoint(xvectorpointindex[i]);
+        double x1,y1,x2,y2;
+        GaussProjCal(p1->mflon(),p1->mflat(),&x1,&y1);
+        GaussProjCal(p2->mflon(),p2->mflat(),&x2,&y2);
+        xmapline.mfLat1 = p1->mflat();
+        xmapline.mfLon1 = p1->mflon();
+        xmapline.mfLat2 = p2->mflat();
+        xmapline.mfLon2 = p2->mflon();
+        xmapline.mfx1 = x1;
+        xmapline.mfy1 = y1;
+        xmapline.mfx2 = x2;
+        xmapline.mfy2 = y2;
+        xvectormapline.push_back(xmapline);
+    }
+
+    return xvectormapline;
+
+//    iv::siasun::waypoint * ppoint = pwayarray->mutable_mwaypoint(index);
+//    if(ppoint == NULL)return xvectormapline;
+
+//    double fLat = ppoint->mflat();
+//    double fLon = ppoint->mflon();
+//    double x,y;
+//    GaussProjCal(fLon,fLat,&x,&y);
+//    xmapline.mfLat1 = fLat;
+//    xmapline.mfLon1 = fLon;
+//    xmapline.mfx1 = x;
+//    xmapline.mfy1 = y;
+
+
+
+//    for(index =1;index<pwayarray->mwaypoint_size();index++)
+//    {
+//    ppoint = pwayarray->mutable_mwaypoint(index);
+//    if(ppoint == NULL)return xvectormapline;
+//    }
+
+
+}

+ 48 - 0
src/tool/tool_siasun/sissunmap.h

@@ -0,0 +1,48 @@
+#ifndef SISSUNMAP_H
+#define SISSUNMAP_H
+
+#include "siasun.pb.h"
+#include "gnss_coordinate_convert.h"
+
+#include <QtCore>
+
+namespace  iv {
+
+struct mapline
+{
+    double mfLon1;
+    double mfLat1;
+    double mfLon2;
+    double mfLat2;
+    double mfViewx1;
+    double mfViewy1;
+    double mfViewx2;
+    double mfViewy2;
+    double mfx1;
+    double mfy1;
+    double mfx2;
+    double mfy2;
+    double mfLen;
+};
+
+}
+
+
+class sissunmap
+{
+public:
+    sissunmap();
+
+    std::vector<iv::mapline> GetMapLine(iv::siasun::map * psiamap);
+
+    const double mfDisMin = 0.1; //2 point distance must bigger than 0.1m
+
+private:
+    double GetPointDis(iv::siasun::waypoint * p1,iv::siasun::waypoint * p2);
+    double GetHdg(iv::siasun::waypoint * p1,iv::siasun::waypoint * p2);
+    bool CheckPointNear(std::vector<int> & xvectorpointindex,iv::siasun::waypointarray * ppointarray,iv::siasun::waypoint * p);
+    int JustPointPos(std::vector<int> & xvectorpointindex,iv::siasun::waypointarray * ppointarray,iv::siasun::waypoint * p);
+    double GetPoint2LineCrossDis(QPointF xpoint, QPointF linepoint1, QPointF linepoint2,double & spos,int & nnear,bool & bright);
+};
+
+#endif // SISSUNMAP_H

+ 6 - 2
src/tool/tool_siasun/tool_siasun.pro

@@ -28,14 +28,18 @@ SOURCES += \
         mainwindow.cpp \
     myview.cpp \
     dialogkickpoint.cpp \
-    ../../common/common/math/gnss_coordinate_convert.cpp
+    ../../common/common/math/gnss_coordinate_convert.cpp \
+    sissunmap.cpp \
+    widthline.cpp
 
 HEADERS += \
         mainwindow.h \
     myview.h \
     dialogkickpoint.h \
     ../../include/msgtype/siasun.pb.h \
-    ../../common/common/math/gnss_coordinate_convert.h
+    ../../common/common/math/gnss_coordinate_convert.h \
+    sissunmap.h \
+    widthline.h
 
 FORMS += \
         mainwindow.ui \

+ 221 - 0
src/tool/tool_siasun/widthline.cpp

@@ -0,0 +1,221 @@
+#include "widthline.h"
+
+#include <math.h>
+
+/**
+  * @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;
+}
+
+widthline::widthline(double startx,double starty,double endx,double endy,double linewidth,QColor xLineColor,int CenterX,int CenterY)
+{
+    mfHdg = CalcHdg(QPointF(startx,starty),QPointF(endx,endy));
+    mstartx = startx;
+    mstarty = starty;
+    mendx = endx;
+    mendy = endy;
+    mflinewidth = linewidth;
+    mfhalflw = mflinewidth/2.0;
+    mBrushColor = xLineColor;
+    mCenterX = CenterX;
+    mCenterY = CenterY;
+
+    CreateLine();
+
+}
+
+widthline::~widthline()
+{
+//    delete mpwidthline;
+}
+
+/**
+ * Copy constructor
+ */
+widthline::widthline (const widthline& xwl)
+{
+    mfHdg = xwl.mfHdg;
+    mstartx = xwl.mstartx;
+    mstarty = xwl.mstarty;
+    mendx = xwl.mendx;
+    mendy = xwl.mendy;
+    mflinewidth = xwl.mflinewidth;
+    mfhalflw = xwl.mfhalflw;
+    mBrushColor = xwl.mBrushColor;
+    mCenterX = xwl.mCenterX;
+    mCenterY = xwl.mCenterY;
+    mpwidthline = NULL;
+    mpwidthline = xwl.mpwidthline;
+
+//    CreateLine();
+}
+
+/**
+ * Assignment operator overload
+ */
+const widthline& widthline::operator=(const widthline& xwl)
+{
+    if (this!= &xwl)
+    {
+        mfHdg = xwl.mfHdg;
+        mstartx = xwl.mstartx;
+        mstarty = xwl.mstarty;
+        mendx = xwl.mendx;
+        mendy = xwl.mendy;
+        mflinewidth = xwl.mflinewidth;
+        mfhalflw = xwl.mfhalflw;
+        mBrushColor = xwl.mBrushColor;
+        mpwidthline = xwl.mpwidthline;
+        mCenterX = xwl.mCenterX;
+        mCenterY = xwl.mCenterY;
+//        CreateLine();
+    }
+    return *this;
+}
+
+#include <thread>
+
+void widthline::CreateLine()
+{
+    QPainterPath xpath;
+    double fx1,fx2,fx3,fx4,fy1,fy2,fy3,fy4;
+    fx1 = mstartx + mfhalflw * cos(mfHdg - M_PI/2.0);
+    fy1 = (mstarty + mfhalflw * sin(mfHdg - M_PI/2.0))*(-1);
+    fx2 = mendx + mfhalflw * cos(mfHdg - M_PI/2.0);
+    fy2 = (mendy + mfhalflw * sin(mfHdg - M_PI/2.0))*(-1);
+    fx3 = mendx + mfhalflw * cos(mfHdg + M_PI/2.0);
+    fy3 = (mendy + mfhalflw * sin(mfHdg + M_PI/2.0))*(-1);
+    fx4 = mstartx + mfhalflw * cos(mfHdg + M_PI/2.0);
+    fy4 = (mstarty + mfhalflw * sin(mfHdg + M_PI/2.0))*(-1);
+    xpath.moveTo(fx1 ,fy1);
+    xpath.lineTo(fx2 ,fy2);
+    xpath.lineTo(fx3 ,fy3);
+    xpath.lineTo(fx4 ,fy4);
+    xpath.closeSubpath();
+
+    QGraphicsPathItem * pitem = new QGraphicsPathItem;
+    pitem->setPath(xpath);
+    QColor brushcolor = mBrushColor;
+    pitem->setBrush(brushcolor);
+    pitem->setPen(QPen(brushcolor,0.001));
+
+    pitem->setPos(3000,3000);
+
+    mpwidthline = pitem;
+
+    std::this_thread::sleep_for(std::chrono::nanoseconds(1));
+}
+
+QGraphicsPathItem * widthline::GetWidthLine()
+{
+    return mpwidthline;
+}
+
+void widthline::ChangeWidth(double flinewidth)
+{
+    mflinewidth = flinewidth;
+    mfhalflw = mflinewidth/2.0;
+    QPainterPath xpath;
+
+    xpath.moveTo(mstartx + mfhalflw * cos(mfHdg + M_PI/2.0) ,(mstarty + mfhalflw * sin(mfHdg + M_PI/2.0))*(-1));
+    xpath.lineTo(mendx + mfhalflw * cos(mfHdg + M_PI/2.0) ,(mendy + mfhalflw * sin(mfHdg + M_PI/2.0))*(-1));
+    xpath.lineTo(mendx + mfhalflw * cos(mfHdg - M_PI/2.0) ,(mendy + mfhalflw * sin(mfHdg - M_PI/2.0))*(-1));
+    xpath.lineTo(mstartx + mfhalflw * cos(mfHdg - M_PI/2.0) ,(mstarty + mfhalflw * sin(mfHdg - M_PI/2.0))*(-1));
+
+    xpath.closeSubpath();
+    QGraphicsPathItem * pitem = mpwidthline;
+    pitem->setPath(xpath);
+    if(mbSelect == false) pitem->setBrush(mBrushColor);
+    else pitem->setBrush(mBrushSelectColor);
+
+    pitem->setPen(QPen(mBrushColor,0.001));
+}
+
+bool widthline::IsNearLine(double startx, double starty, double endx, double endy)
+{
+    if((startx == mstartx)&&(starty == mstarty)&&(endx == mendx)&&(endy == mendy))
+    {
+        return true;
+    }
+    return false;
+}
+
+bool widthline::ChangeSelect()
+{
+    mbSelect = !mbSelect;
+    if(mbSelect)
+    {
+        mpwidthline->setBrush(mBrushSelectColor);
+    }
+    else
+    {
+        mpwidthline->setBrush(mBrushColor);
+    }
+    return mbSelect;
+}
+
+bool widthline::IsSelect()
+{
+    return mbSelect;
+}
+
+void widthline::SetSelect(bool bSelect)
+{
+    mbSelect = bSelect;
+    if(mbSelect)
+    {
+        mpwidthline->setBrush(mBrushSelectColor);
+    }
+    else
+    {
+        mpwidthline->setBrush(mBrushColor);
+    }
+}

+ 53 - 0
src/tool/tool_siasun/widthline.h

@@ -0,0 +1,53 @@
+#ifndef WIDTHLINE_H
+#define WIDTHLINE_H
+
+#include <QGraphicsScene>
+#include <QGraphicsPathItem>
+
+class widthline
+{
+public:
+    widthline(double startx,double starty,double endx,double endy,double linewidth,QColor xLineColor,int CenterX,int CenterY);
+    ~widthline();
+
+    /**
+     * Copy constructor
+     */
+    widthline (const widthline& xwl);
+
+    /**
+     * Assignment operator overload
+     */
+    const widthline& operator=(const widthline& rhs);
+
+    bool IsNearLine(double startx,double starty,double endx,double endy);
+
+private:
+    double mfHdg;
+    QGraphicsPathItem * mpwidthline;
+
+    double mstartx,mstarty;
+    double mendx,mendy;
+    double mflinewidth;
+    double mfhalflw;
+    QColor mBrushColor;
+    QColor mBrushSelectColor = Qt::red;
+    int mCenterX;
+    int mCenterY;
+    bool mbSelect = false;
+
+private:
+    void CreateLine();
+
+public:
+    QGraphicsPathItem * GetWidthLine();
+    void ChangeWidth(double flinewidth);
+    bool ChangeSelect();
+    bool IsSelect();
+    void SetSelect(bool bSelect);
+
+
+
+};
+
+#endif // WIDTHLINE_H