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