Merge branch 'fixing/resultDialog'
[speedfreak] / Client / routedialog.cpp
1 /*
2  * RouteDialog class
3  *
4  * @author     Olavi Pulkkinen <olavi.pulkkinen@fudeco.com>
5  * @copyright  (c) 2010 Speed Freak team
6  * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
7  */
8
9 #include "routedialog.h"
10 #include "ui_routedialog.h"
11 #include "usersettings.h"
12 #include <cmath>
13 #include <QPainter>
14 #include <QList>
15 #include <QMessageBox>
16 #include <QFile>
17 #include <QFileDialog>
18 #include <QPolygon>
19
20 /*
21   * Vector class.
22   * In starting Qt 4.6 there is QVector3D.
23   * Later (updating Qt version) this class can be removed.
24   */
25 class Vector
26 {
27     qreal x, y, z;      // Location
28     qreal v;            // Velocity
29 public:
30     Vector() { x=0.; y=0. ; z=0.; };
31     Vector( qreal initX, qreal initY, qreal initZ) { x = initX, y = initY; z = initZ; };
32     void setX( qreal newX) { x = newX; };
33     void setY( qreal newY) { y = newY; };
34     void setZ( qreal newZ) { z = newZ; };
35     void setV( qreal newV) { v = newV; };
36     qreal getX() { return x; };
37     qreal getY() { return y; };
38     qreal getZ() { return z; };
39     qreal getV() { return v; };
40     qreal length() { return sqrt(x*x+y*y+z*z); };
41     Vector operator+(Vector v)
42     {
43         x = x + v.x; y = y + v.y; z = z + v.z;
44         return *this;
45     };
46     Vector operator-(Vector v)
47     {
48         x = x - v.x; y = y - v.y; z = z - v.z;
49         return *this;
50     };
51     Vector operator/(qreal c)
52     {
53         x = x/c; y = y/c; z = z/c;
54         return *this;
55     };
56     Vector crossProduct( Vector a, Vector b)
57     {
58         x = a.y*b.z - a.z*b.y;
59         y = a.z*b.x - a.x*b.z;
60         z = a.x*b.y - a.y*b.x;
61         return *this;
62     };
63 };
64
65
66 class Viewing
67 {
68     Vector atPoint, fromPoint, up, a1, a2, a3;
69     qreal offsx, offsy, offsz;
70     qreal dval;
71     qreal angle;
72 public:
73     qreal getOffsx() { return offsx; };
74     qreal getOffsy() { return offsy; };
75     qreal getOffsz() { return offsz; };
76     qreal getDval() { return dval; };
77     void setAngle( qreal newA) { angle = newA; };
78     void setUp( qreal newUpX, qreal newUpY, qreal newUpZ)
79     {
80         up.setX(newUpX); up.setY(newUpY); up.setZ(newUpZ);
81     };
82     void setAtPoint( qreal newX, qreal newY, qreal newZ)
83     {
84         atPoint.setX(newX); atPoint.setY(newY); atPoint.setZ(newZ);
85     };
86     void setFromPoint(qreal newX, qreal newY, qreal newZ)
87     {
88         fromPoint.setX(newX); fromPoint.setY(newY); fromPoint.setZ(newZ);
89     }
90     void setEye()
91     {
92         double amarkmag, tempmag;
93         Vector temp, dist;
94
95         dval = cos(angle/2.0)/sin(angle/2.0);
96         dist = atPoint-fromPoint;
97         amarkmag = dist.length();
98         a3 = dist/amarkmag;
99
100         temp.crossProduct( dist, up);
101         tempmag = temp.length();
102         a1 = temp/tempmag;
103
104         temp.crossProduct( a1, a3);
105         tempmag = temp.length();
106         a2 = temp/tempmag;
107
108         offsx = -a1.getX()*fromPoint.getX() - a1.getY()*fromPoint.getY() - a1.getZ()*fromPoint.getZ();
109         offsy = -a2.getX()*fromPoint.getX() - a2.getY()*fromPoint.getY() - a2.getZ()*fromPoint.getZ();
110         offsz = -a3.getX()*fromPoint.getX() - a3.getY()*fromPoint.getY() - a3.getZ()*fromPoint.getZ();
111         //QString jono2 = QString("offsx %1 offsy %2 offsz %3").arg(offsx).arg(offsy).arg(offsz);
112         //QMessageBox::about(0,"offs x y z", jono2);
113     } ;
114     Vector getAtPoint() { return atPoint; };
115     Vector getFromPoint() { return fromPoint; };
116     Vector getA1() { return a1; };
117     Vector getA2() { return a2; };
118     Vector getA3() { return a3; };
119     Viewing () {};
120 };
121
122 qreal xmax, xmin, ymin, ymax;       // Limits in world coordinates
123
124 QList<Vector> vertexList;           // Vertecies of route
125
126 qreal objxmin, objxmax, objymin, objymax, objzmin, objzmax; // data ranges
127
128 #define maxof(val1,val2)  ((val1>val2)?val1:val2)
129 #define toradians( degrees) (degrees*0.017453293)
130
131 #define WIDTH 1.8   // For 3d viewing only
132 qreal a, b,c,d; // Used for 3d viewing to calculate screen coordinates
133
134 Viewing view3d;   // Viewing settings for 3d
135
136 // Function prototypes
137 void dataMinMax( void);
138 void setAtPoint( Viewing *v);
139 void setFromPoint( Viewing *v);
140 void transformseg( Viewing *v, Vector *v1, Vector *v2, int *xscreen1, int *yscreen1, int *xscreen2, int *yscreen2 );
141
142 #define R 6378.140 // The radius of the earth by kilometers
143 /*
144   * count distance of two points (defined by longitude & latitude)
145   * on the surface of the earth.
146   */
147 qreal countDistance(Vector *p1, Vector *p2)
148 {
149     qreal dLon, dLat;   // delta of longitude & latitude
150     qreal a, c;
151
152     dLon = p2->getX() - p1->getX();     // longitude difference
153     dLat = p2->getY() - p1->getY();     // latitude difference
154     if (dLon <0) dLon = -dLon;
155     if (dLat <0) dLat = -dLat;
156
157     dLon = dLon*3.14/180;
158     dLat = dLat*3.14/180;
159     a = (sin(dLat/2.))*(sin(dLat/2.)) +
160         (cos(p1->getY())*3.14/180)*(cos(p2->getY())*3.14/180)*(sin(dLon/2.))*(sin(dLon/2.));
161     c = 2.*atan(sqrt(a)/sqrt(1-a));     // c is angle between points p1 & p2 with circel by radius 1.
162
163     return R*c;   // Return distance in kilometers
164 }
165
166 RouteDialog::RouteDialog(QWidget *parent) :
167     QDialog(parent),
168     ui(new Ui::RouteDialog)
169 {
170     ui->setupUi(this);
171     this->setWindowTitle("Route");
172     left = 5; top = 5; right = 495; bottom = 295; // Limits in screen coordinates
173
174     //Button settings
175     ui->sendPushButton->setAutoFillBackground(true);
176     ui->sendPushButton->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
177     ui->newPushButton->setAutoFillBackground(true);
178     ui->newPushButton->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
179
180     // Send rout to server button disable/enable.
181     ui->sendPushButton->setEnabled(false);
182     if (loginSaved())
183     {
184         ui->sendPushButton->setEnabled(true);
185     }
186 }
187
188 RouteDialog::~RouteDialog()
189 {
190     delete ui;
191 }
192
193 void RouteDialog::changeEvent(QEvent *e)
194 {
195     QDialog::changeEvent(e);
196     switch (e->type()) {
197     case QEvent::LanguageChange:
198         ui->retranslateUi(this);
199         break;
200     default:
201         break;
202     }
203 }
204 int RouteDialog::getLeft()
205 {
206     return left;
207 }
208 int RouteDialog::getRight()
209 {
210     return right;
211 }
212 int RouteDialog::getTop()
213 {
214     return top;
215 }
216 int RouteDialog::getBottom()
217 {
218     return bottom;
219 }
220
221 void drawFlag( RouteDialog *rD, QPainter *p, int x, int y)
222 {
223     /*QPolygon pg;
224
225     pg.setPoint(0,x, y-25);
226     pg.setPoint(1,x+10,y-20);
227     pg.setPoint(2,x, y-15);
228     pg.setPoint(3,x,y-20);*/
229     if (y> (rD->getTop() + 25))
230     {
231         // Upside
232         p->drawLine(x,y,x,y-15);
233         if (x <= (rD->getRight()-20))
234         {
235             // flag right
236             p->drawLine( x,    y-25, x+10, y-20);
237             p->drawLine( x+10, y-20, x,    y-15);
238             p->drawLine( x,    y-15, x,    y-25);
239         }
240         else
241         {
242             // Flag left
243             p->drawLine( x,    y-25, x-10, y-20);
244             p->drawLine( x-10, y-20, x,    y-15);
245             p->drawLine( x,    y-15, x,    y-25);
246         }
247
248     }
249     else if (y <= (rD->getTop() + 25))
250     {
251         // downside
252         p->drawLine(x,y,x,y+15);
253         if (x <= (rD->getRight()-20))
254         {
255             // flag right
256             p->drawLine( x,    y+25, x+10, y+20);
257             p->drawLine( x+10, y+20, x,    y+15);
258             p->drawLine( x,    y+15, x,    y+25);
259         }
260         else
261         {
262             // Flag left
263             p->drawLine( x,    y+25, x-10, y+20);
264             p->drawLine( x-10, y+20, x,    y+15);
265             p->drawLine( x,    y+15, x,    y+25);
266         }
267     }
268     //p->drawPolygon();
269    // p->drawPolygon( pg,Qt::OddEvenFill);
270     //p->drawPolyline( &pg);
271     //p->drawPoints( pg);
272 }
273
274 /**
275   * Draws route to the route dialog.
276   * Type 0 is 2d viewing and type 1 is for 3d viewing
277   * @param QPaintEvent
278  */
279 /* */
280 void RouteDialog::paintEvent(QPaintEvent *)
281 {
282     int type = 0; //  0 for 2d, 1 for 3d
283     int startx, starty; // Starting point of the route
284     int i, maxi;
285     qreal x1, y1, x2, y2;
286     int x1Screen, y1Screen, x2Screen, y2Screen;
287     Vector v1, v2;
288     QPainter painter(this);
289
290     painter.setRenderHint(QPainter::Antialiasing, true);
291     painter.setPen(QPen((Qt::white),2));
292     painter.setBrush(QBrush((Qt::yellow), Qt::SolidPattern));
293
294     // Draw route window frame
295     /*painter.drawLine(left,top,right,top);
296     painter.drawLine(right,top,right,bottom);
297     painter.drawLine(left,top,left,bottom);
298     painter.drawLine(left,bottom,right,bottom);*/
299
300     maxi = vertexList.size();
301
302     for (i=0; i<maxi-1; i++)
303     {
304        v1 = vertexList.at(i);
305        v2 = vertexList.at(i+1);
306
307        if (type == 0)
308        {    // 2d
309             x1 = v1.getX(); y1 = v1.getY();
310             x2 = v2.getX(); y2 = v2.getY();
311             //QString jono = QString("x: %1 y: %2").arg(x1).arg(y1);
312             //QMessageBox::about(0,"Tark",jono);
313
314             x1Screen = left + (x1-xmin)/(xmax-xmin)*(right-left);
315             y1Screen = top + (ymax-y1)/(ymax-ymin)*(bottom-top);
316             x2Screen = left + (x2-xmin)/(xmax-xmin)*(right-left);
317             y2Screen = top + (ymax-y2)/(ymax-ymin)*(bottom-top);
318         }
319         else if (type == 1)
320         {   // 3d
321             transformseg( &view3d, &v1,&v2, &x1Screen, &y1Screen, &x2Screen, &y2Screen);
322         }
323
324         // Show with circle if starting point
325         if (i==0)
326         {
327             // Starting point
328             startx = x1Screen; starty = y1Screen;
329            // painter.drawEllipse( x1Screen-5, y1Screen-5, 10, 10);
330            drawFlag( this, &painter,  x1Screen ,  y1Screen);
331         }
332         painter.drawLine( x1Screen, y1Screen, x2Screen, y2Screen);
333     }
334     // Show the endig point if different than the starting point
335     if (x2Screen != startx || y2Screen != starty)
336     {
337         //painter.drawEllipse( x2Screen-5, y2Screen-5, 10, 10);
338         drawFlag( this, &painter,x2Screen, y2Screen );
339     }
340
341     {
342         qreal maxvx, maxvy; // max speed point coordinates
343         qreal maxv;         // max speed
344         Vector v;
345
346         maxv = 0.0;
347         for (i=0; i<maxi-1; i++)
348         {
349             v = vertexList.at(i);
350             if (v.getV() > maxv)
351             {
352                 maxv = v.getV();
353                 maxvx = v.getX();
354                 maxvy = v.getY();
355             }
356         }
357         // Translate world coordinates to screen coordinates
358         x1Screen = left + (maxvx-xmin)/(xmax-xmin)*(right-left);
359         y1Screen = top + (ymax-maxvy)/(ymax-ymin)*(bottom-top);
360
361         // Show max velocity point by yellow circle
362         painter.drawEllipse( x1Screen-5, y1Screen-5, 10, 10);
363
364         QString jono;
365         jono = QString("%1 km/h").arg(maxv);
366         ui->speedValueLabel->setText(jono);
367     }
368 }
369
370 bool RouteDialog::readRouteFromFile( QString &routeFile)
371  {
372     Vector temp;
373     QString rivi;
374     QFile file;
375
376     //QString fileName = QFileDialog::getOpenFileName(this,
377     //     tr("Read Route"), "./", tr("Route Files (*.txt)"));
378
379     //file.setFileName( fileName);
380     file.setFileName( "routetemp.xml");
381     if (!file.open(QIODevice::ReadOnly))
382     {
383         QMessageBox::about(0, "Error", "File not found");
384         return false;
385     }
386
387     vertexList.clear();
388
389     while(!file.atEnd())
390     {
391         int count;
392         bool allRead;
393         QString astr1, astr2, astr3, astr4;
394         QString str1, str2, str3, str4;
395         rivi = file.readLine();
396
397         allRead = false;
398         count = 0;
399         while( !allRead)
400         {
401             astr1 = rivi.section(" ", count*4+1, count*4+1); // latitude=""
402             astr2 = rivi.section(" ", count*4+2, count*4+2); // longitude=""
403             astr3 = rivi.section(" ", count*4+3, count*4+3); // altitude=""
404             astr4 = rivi.section(" ", count*4+4, count*4+4); // speed=""
405
406             {
407                 double x, y, z, v;
408                 str1 = astr1.section('"',1,1);
409                 str2 = astr2.section('"',1,1);
410                 str3 = astr3.section('"',1,1);
411                 str4 = astr4.section('"',1,1);
412             //QString str = QString("%1 %2 %3 %4").arg(str1).arg(str2).arg(str3).arg(str4);
413             //QMessageBox::about(0, "LUKEE", str);
414                 /* */
415
416                 if (str1.length() > 0)
417                 {
418                     x = str2.toDouble();// latitude y-value
419                     y = str1.toDouble();// longitude x-value
420                     z = str3.toDouble();// altitude z-value
421                     v = str4.toDouble();// speed km/h
422                // QString str = QString("%1 %2 %3 %4").arg(x).arg(y).arg(z).arg(v);
423                // QMessageBox::about(0, "LUKEE", str);
424                     temp.setX( x); // Longitude
425                     temp.setY( y); // Latitude
426                     temp.setZ( z); // altitude
427                     temp.setV( v);
428
429                     vertexList.append(temp);
430                     count++;
431                 }
432                 else
433                 {
434                     allRead = true;
435                 }
436             }
437         }
438         // Older version
439         /*
440         str1 = rivi.section(" ", 0, 0);
441         if (str1.compare("Start:") != 0 && str1.compare("Stop:") != 0)
442         {
443             str1 = rivi.section(" ", 2, 2); // latitude y-value
444             str2 = rivi.section(" ", 4, 4); // longitude x-value
445             str3 = rivi.section(" ", 6, 6); // altitude z-value
446             str4 = rivi.section(" ", 8, 8); // speed km/h
447             //QString str = QString("la: %1 lo: %2 al: %3").arg(str1).arg(str2).arg(str3);
448             //QMessageBox::about(0, "LUKEE", str);
449
450             if (str1.length() > 0)
451             {
452                 double x, y, z, v;
453                 x = str2.toDouble();
454                 y = str1.toDouble();
455                 z = str3.toDouble();
456                 v = str4.toDouble();
457                 temp.setX( x); // Longitude
458                 temp.setY( y); // Latitude
459                 temp.setZ( z); // altitude
460                 temp.setV( v);
461
462                 vertexList.append(temp);
463             }
464         }
465         */
466     }
467
468     file.close();
469
470      /********  in 3d use only */
471      a = 400/2.;
472      b = 1 - a*(-1);
473      c = -300/2.;
474      d = 300 - c*(-1);
475      //angle = toradians(60);
476
477      view3d.setUp( 1.0, 0.0, 0.0);
478      view3d.setAngle(toradians(60));
479      setAtPoint( &view3d);
480      xmin = objxmin; xmax = objxmax; ymin = objymin; ymax = objymax; // 2d viewing needs this !!!!
481      setFromPoint( &view3d);
482      view3d.setEye();
483      /****** end of 3d *****/
484
485      /*
486      //Testing distance counting
487      Vector a1, a2;
488      qreal dist;
489      //a1.setX( xmin); a1.setY( ymin);
490      //a2.setX( xmax); a2.setY( ymax);
491      a1.setX( 25.483); a1.setY( 65.017); // Oulu
492      a2.setX( 27.767); a2.setY( 64.283); // Kajaani
493      dist = countDistance( &a1, &a2);
494      QString str = QString("Min & Max datan välimatka %1").arg(dist);
495      QMessageBox::about( 0, "Testi", str);
496      */
497
498      return true;
499  }
500
501 /*
502   * Find out data range for x-, y- and z-coordinates
503   */
504 void dataMinMax( void)
505 {
506     int i, maxi;
507     qreal x,y,z;
508     Vector temp;
509
510     temp = vertexList.at(0);
511     objxmax = objxmin = temp.getX();
512     objymax = objymin = temp.getY();
513     objzmax = objzmin = temp.getZ();
514
515     maxi = vertexList.size();
516     for (i=1; i<maxi; i++)
517     {
518         temp = vertexList.at(i);
519         x = temp.getX();
520         y = temp.getY();
521         z = temp.getZ();
522
523         if (x < objxmin)
524         {
525                 objxmin = x;
526         }
527         else if (x > objxmax)
528         {
529                objxmax = x;
530         }
531
532         if (y < objymin)
533         {
534                 objymin = y;
535         }
536         else if (y > objymax)
537         {
538                objymax = y;
539         }
540
541         if (z < objzmin)
542         {
543                 objzmin = z;
544         }
545         else if (z > objzmax)
546         {
547                objzmax = z;
548         }
549     }
550     //QString jono = QString("ojxmin %1 objxmax %2").arg(objxmin).arg(objxmax);
551     //QString jono = QString("ojymin %1 objymax %2").arg(objymin).arg(objymax);
552     //QString jono = QString("ojzmin %1 objzmax %2").arg(objzmin).arg(objzmax);
553     //QMessageBox::about(0,"Tark", jono);
554 }
555
556 /*
557   * Setting the point where the viewed object is. In the middle of datapoints.
558   */
559 void setAtPoint( Viewing *v)
560 {
561     qreal x, y, z;
562     dataMinMax();
563     //Vector test;
564
565     x = (objxmax+objxmin)/2.0;
566     y= (objymax+objymin)/2.0;
567     z= (objzmax+objzmin)/2.0;
568
569     v->setAtPoint( x, y, z);
570     //QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(atPoint.x()).arg(atPoint.y()).arg(atPoint.z());
571     //QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(atPoint.x).arg(atPoint.y).arg(atPoint.z);
572
573     /* *
574     test = v->getAtPoint();
575     QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(test.getX()).arg(test.getY()).arg(test.getZ());
576     QMessageBox::about(0,"At point", jono);
577     * */
578 }
579
580 /*
581   * Setting the point where the object is viewed by eye.
582   */
583 void setFromPoint( Viewing *v)
584 {
585     qreal x, y, z;
586     Vector point;
587     point = v->getAtPoint();
588     //Vector test;
589     //fromPoint.setX( atPoint.getX() + (objxmax-objxmin)/2.0 + WIDTH*maxof((objzmax-objzmin)/2.0,(objymax-objymin)/2.0));
590     //x = 3.0;
591     //x = point.getX() + (objxmax-objxmin)/2.0 + WIDTH*maxof((objzmax-objzmin)/2.0,(objymax-objymin)/2.0);
592     x = point.getX();
593     //y = point.getY();
594     y = point.getY() + 40; // + (objymax-objymin)/2.0 + WIDTH*maxof((objzmax-objzmin)/2.0,(objxmax-objxmin)/2.0);
595     z = point.getZ();
596
597     v->setFromPoint(x,y,z);
598     //QString jono = QString("FromX %1 FromY %2 FromZ %3").arg(fromPoint.x()).arg(fromPoint.y()).arg(fromPoint.z());
599     //QString jono = QString("FromX %1 FromY %2 FromZ %3").arg(fromPoint.x).arg(fromPoint.y).arg(fromPoint.z);
600     /* *
601     test = v->getFromPoint();
602     QString jono = QString("FromX %1 FromY %2 FromZ %3").arg(test.getX()).arg(test.getY()).arg(test.getZ());
603     QMessageBox::about(0,"From point", jono); // (1.9, 0.5, 0.5)
604     * */
605 }
606
607
608 #define NOEDGE     0x00
609 #define LEFTEDGE   0x01
610 #define RIGHTEDGE  0x02
611 #define BOTTOMEDGE 0x04
612 #define TOPEDGE    0x08
613 /*
614   * Returns a code specifying which edge in the viewing pyramid was crossed.
615   * There may be more than one.
616   */
617 int code( qreal x, qreal y, qreal z)
618 {
619     int c;
620
621     c = NOEDGE;
622     if (x<-z) c |= LEFTEDGE;
623     if (x>z) c |= RIGHTEDGE;
624     if (y<-z) c |= BOTTOMEDGE;
625     if (y>z) c |= TOPEDGE;
626
627     return c;
628 }
629
630 /*
631   * Converts clipped world coordinates to screen coordinates.
632   */
633 void WORLDtoSCREEN( qreal xWorld, qreal yWorld, int *xScreen, int *yScreen)
634 {
635    *xScreen = (int) (a*xWorld+b);
636    *yScreen = (int) (c*yWorld+d);
637 }
638
639 /*
640   * Clips the line segment in three-dimensional coordinates to the
641   * viewing pyramid.
642   */
643 void clip3d( qreal x1, qreal y1, qreal z1, qreal x2, qreal y2, qreal z2, int *xscreen1, int *yscreen1, int *xscreen2, int *yscreen2)
644 {
645     int c,c1,c2;
646     qreal x,y,z,t;
647
648     c1 = code(x1,y1,z1);
649     c2 = code(x2,y2,z2);
650
651     while (c1!= NOEDGE || c2 != NOEDGE)
652     {
653         if ((c1 & c2 ) != NOEDGE) return;
654         c = c1;
655         if (c == NOEDGE) c = c2;
656         if ((c&LEFTEDGE) == LEFTEDGE)
657         {
658                 // Crosses left edge
659                 t = (z1+x1)/((x1-x2)-(z2-z1));
660                 z = t*(z2-z1)+z1;
661                 x = -z;
662                 y = t*(y2-y1)+y1;
663         }
664         else if ((c&RIGHTEDGE) == RIGHTEDGE)
665         {
666                 // Crosses right edge
667                 t = (z1-x1)/((x2-x1)-(z2-z1));
668                 z = t*(z2-z1)+z1;
669                 x = z;
670                 y = t*(y2-y1)+y1;
671         }
672         else if ((c&BOTTOMEDGE) == BOTTOMEDGE)
673         {
674                 // Crosses bottom edge
675                 t = (z1+y1)/((y1-y2)-(z2-z1));
676                 z = t*(z2-z1)+z1;
677                 x = t*(x2-x1)+x1;
678                 y = -z;
679         }
680         else if ((c&TOPEDGE) == TOPEDGE)
681         {
682                 // Crosses top edge
683                 t = (z1-y1)/((y2-y1)-(z2-z1));
684                 z = t*(z2-z1)+z1;
685                 x = t*(x2-x1)+x1;
686                 y = z;
687         }
688
689         if (c == c1)
690         {
691             x1=x; y1=y; z1=z;
692             c1 = code(x,y,z);
693         }
694         else
695         {
696             x2=x; y2=y; z2=z;
697             c2 = code(x,y,z);
698         }
699     }
700
701     if (z1 != 0)
702     {
703         WORLDtoSCREEN(x1/z1,y1/z1,xscreen1, yscreen1);
704         WORLDtoSCREEN(x2/z2,y2/z2,xscreen2, yscreen2);
705     }
706     else
707     {
708         WORLDtoSCREEN(x1,y1,xscreen1, yscreen1);
709         WORLDtoSCREEN(x2,y2,xscreen2, yscreen2);
710     }
711     //Now ready to draw line( xscreen1, yscreen1, xscreen2, yscreen2);
712 }
713
714 /*
715   * Transform the segment connecting the two vectors into the viewing plane.
716   * clip3d() clips the line if needed.
717   */
718 void transformseg( Viewing *v, Vector *v1, Vector *v2, int *xscreen1, int *yscreen1, int *xscreen2, int *yscreen2)
719
720 {
721     qreal x1, y1, z1, x2, y2, z2;
722     Vector a1, a2, a3;
723
724     a1 = v->getA1();
725     a2 = v->getA2();
726     a3 = v->getA3();
727
728     x1 = (a1.getX()*v1->getX() + a1.getY()*v1->getY() + a1.getZ()*v1->getZ() + v->getOffsx())*v->getDval();
729     y1 = (a2.getX()*v1->getX() + a2.getY()*v1->getY() + a2.getZ()*v1->getZ() + v->getOffsy())*v->getDval();
730     z1 = a3.getX()*v1->getX() + a3.getY()*v1->getY() + a3.getZ()*v1->getZ() + v->getOffsz();
731
732     x2 = (a1.getX()*v2->getX() + a1.getY()*v2->getY() + a1.getZ()*v2->getZ() + v->getOffsx())*v->getDval();
733     y2 = (a2.getX()*v2->getX() + a2.getY()*v2->getY() + a2.getZ()*v2->getZ() + v->getOffsy())*v->getDval();
734     z2 = a3.getX()*v2->getX() + a3.getY()*v2->getY() + a3.getZ()*v2->getZ() + v->getOffsz();
735
736     clip3d(x1,y1,z1,x2,y2,z2, xscreen1, yscreen1, xscreen2, yscreen2 );
737 }
738
739 void RouteDialog::on_newPushButton_clicked()
740 {
741     close();    // go back to previous dialog
742 }
743
744 void RouteDialog::on_sendPushButton_clicked()
745 {
746     emit sendroute();
747 }
748
749 void RouteDialog::setLabelInfoToUser(QString infoText)
750 {
751     this->ui->labelInfoToUser->setText(infoText);
752 }