+/**
+ *
+ */
+int RouteDialog::getLeft()
+{
+ return left;
+}
+
+/**
+ *
+ */
+int RouteDialog::getRight()
+{
+ return right;
+}
+
+/**
+ *
+ */
+int RouteDialog::getTop()
+{
+ return top;
+}
+
+/**
+ *
+ */
+int RouteDialog::getBottom()
+{
+ return bottom;
+}
+
+/**
+ *
+ */
+void drawFlag( RouteDialog *rD, QPainter *p, int x, int y, QString startFinish)
+{
+ /*QPolygon pg;
+
+ pg.setPoint(0,x, y-25);
+ pg.setPoint(1,x+10,y-20);
+ pg.setPoint(2,x, y-15);
+ pg.setPoint(3,x,y-20);*/
+ if (y> (rD->getTop() + 25))
+ {
+ // Upside
+ p->drawLine(x,y,x,y-15);
+ if (x <= (rD->getRight()-20))
+ {
+ // flag right
+ p->drawLine( x, y-25, x+10, y-20);
+ p->drawLine( x+10, y-20, x, y-15);
+ p->drawLine( x, y-15, x, y-25);
+
+ // Draw start or finish
+ p->drawText(x+10, y, startFinish);
+ }
+ else
+ {
+ // Flag left
+ p->drawLine( x, y-25, x-10, y-20);
+ p->drawLine( x-10, y-20, x, y-15);
+ p->drawLine( x, y-15, x, y-25);
+
+ // Draw start or finish
+ p->drawText(x+10, y, startFinish);
+ }
+ }
+ else if (y <= (rD->getTop() + 25))
+ {
+ // downside
+ p->drawLine(x,y,x,y+15);
+ if (x <= (rD->getRight()-20))
+ {
+ // flag right
+ p->drawLine( x, y+25, x+10, y+20);
+ p->drawLine( x+10, y+20, x, y+15);
+ p->drawLine( x, y+15, x, y+25);
+
+ // Draw start or finish
+ p->drawText(x+10, y+15, startFinish);
+ }
+ else
+ {
+ // Flag left
+ p->drawLine( x, y+25, x-10, y+20);
+ p->drawLine( x-10, y+20, x, y+15);
+ p->drawLine( x, y+15, x, y+25);
+
+ // Draw start or finish
+ p->drawText(x+10, y+15, startFinish);
+ }
+ }
+ //p->drawPolygon();
+ // p->drawPolygon( pg,Qt::OddEvenFill);
+ //p->drawPolyline( &pg);
+ //p->drawPoints( pg);
+}
+
+/**
+ * Draws route to the route dialog.
+ * Type 0 is 2d viewing and type 1 is for 3d viewing
+ * @param QPaintEvent
+ */
+/* */
+void RouteDialog::paintEvent(QPaintEvent *)
+{
+ // Check login
+ checkLogin();
+
+ int type = 0; // 0 for 2d, 1 for 3d
+ int startx = 0; // Starting x point of the route
+ int starty = 0; // Starting y point of the route
+ int i = 0;
+ int maxi = 0;
+ qreal x1, y1, x2, y2;
+ int x1Screen = 0;
+ int y1Screen = 0;
+ int x2Screen = 0;
+ int y2Screen = 0;
+ Vector v1, v2;
+ QPainter painter(this);
+
+ painter.setRenderHint(QPainter::Antialiasing, true);
+ painter.setPen(QPen((Qt::white),2));
+ painter.setBrush(QBrush((Qt::yellow), Qt::SolidPattern));
+
+ // Draw route window frame
+ /*painter.drawLine(left,top,right,top);
+ painter.drawLine(right,top,right,bottom);
+ painter.drawLine(left,top,left,bottom);
+ painter.drawLine(left,bottom,right,bottom);*/
+
+ maxi = vertexList.size();
+
+ for (i=0; i<maxi-1; i++)
+ {
+ v1 = vertexList.at(i);
+ v2 = vertexList.at(i+1);
+
+ if (type == 0)
+ { // 2d
+ x1 = v1.getX(); y1 = v1.getY();
+ x2 = v2.getX(); y2 = v2.getY();
+ //QString jono = QString("x: %1 y: %2").arg(x1).arg(y1);
+ //QMessageBox::about(0,"Tark",jono);
+
+ x1Screen = left + (x1-xmin)/(xmax-xmin)*(right-left);
+ y1Screen = top + (ymax-y1)/(ymax-ymin)*(bottom-top);
+ x2Screen = left + (x2-xmin)/(xmax-xmin)*(right-left);
+ y2Screen = top + (ymax-y2)/(ymax-ymin)*(bottom-top);
+ }
+ else if (type == 1)
+ { // 3d
+ transformseg( &view3d, &v1,&v2, &x1Screen, &y1Screen, &x2Screen, &y2Screen);
+ }
+
+ // Show with circle if starting point
+ if (i==0)
+ {
+ // Starting point
+ startx = x1Screen; starty = y1Screen;
+ // painter.drawEllipse( x1Screen-5, y1Screen-5, 10, 10);
+ drawFlag( this, &painter, x1Screen, y1Screen, "Start" );
+ }
+ painter.drawLine( x1Screen, y1Screen, x2Screen, y2Screen);
+ }
+ // Show the endig point if different than the starting point
+ if (x2Screen != startx || y2Screen != starty)
+ {
+ //painter.drawEllipse( x2Screen-5, y2Screen-5, 10, 10);
+ drawFlag( this, &painter, x2Screen, y2Screen, "Finish" );
+ }
+
+ {
+ qreal maxvx = 0; // max speed x point
+ qreal maxvy = 0; // max speed y point
+ qreal maxv = 0; // max speed
+ Vector v;
+
+ maxv = 0.0;
+ for (i=0; i<maxi-1; i++)
+ {
+ v = vertexList.at(i);
+ if (v.getV() > maxv)
+ {
+ maxv = v.getV();
+ maxvx = v.getX();
+ maxvy = v.getY();
+ }
+ }
+ // Translate world coordinates to screen coordinates
+ x1Screen = left + (maxvx-xmin)/(xmax-xmin)*(right-left);
+ y1Screen = top + (ymax-maxvy)/(ymax-ymin)*(bottom-top);
+
+ // Show max velocity point by yellow circle
+ painter.drawEllipse( x1Screen-5, y1Screen-5, 10, 10);
+ painter.drawEllipse( ui->maxSpeedLabel->geometry().x()-15, ui->maxSpeedLabel->geometry().y()+15, 10, 10);
+
+ QString jono;
+ //jono = QString("%1 km/h").arg(maxv);
+ jono.sprintf("%.1f km/h", maxv); // Show only 1 decimal
+ ui->speedValueLabel->setText(jono);
+ }
+}
+
+/**
+ *
+ * @param QString route file
+ */
+bool RouteDialog::readRouteFromFile( QString &routeFile )
+{
+ QString rFile = routeFile;
+ fileName = routeFile;
+ Vector temp;
+ QString rivi;
+ QFile file;
+ int progressbarInt = 5;
+ int count;
+
+ file.setFileName( rFile);
+ if (!file.open(QIODevice::ReadOnly))
+ {
+ QMessageBox::about(0, "Error", "Empty file");
+ return false;
+ }
+ emit progressbar(progressbarInt);
+ vertexList.clear();
+
+ while(!file.atEnd())
+ {
+ bool allRead;
+ QString astr1, astr2, astr3, astr4;
+ QString str1, str2, str3, str4;
+ rivi = file.readLine();
+ allRead = false;
+ count = 0;
+ while( !allRead)
+ {
+ astr1 = rivi.section(" ", count*4+1, count*4+1); // latitude=""
+ astr2 = rivi.section(" ", count*4+2, count*4+2); // longitude=""
+ astr3 = rivi.section(" ", count*4+3, count*4+3); // altitude=""
+ astr4 = rivi.section(" ", count*4+4, count*4+4); // speed=""
+
+ {
+ double x, y, z, v;
+ str1 = astr1.section('"',1,1);
+ str2 = astr2.section('"',1,1);
+ str3 = astr3.section('"',1,1);
+ str4 = astr4.section('"',1,1);
+
+ if (str1.length() > 0)
+ {
+ x = str2.toDouble();// latitude y-value
+ y = str1.toDouble();// longitude x-value
+ z = str3.toDouble();// altitude z-value
+ v = str4.toDouble();// speed km/h
+ temp.setX( x); // Longitude
+ temp.setY( y); // Latitude
+ temp.setZ( z); // altitude
+ temp.setV( v);
+
+ vertexList.append(temp);
+ count++;
+ }
+ else
+ {
+ allRead = true;
+ }
+ }
+ if(progressbarInt < 50)
+ progressbarInt++;
+ emit progressbar(progressbarInt);
+ }
+ }
+ file.close();
+
+ if(count == 1) // Check is file empty.
+ {
+ progressbarInt = 50;
+ emit progressbar(progressbarInt);
+ qDebug() << "count: " + QString::number(count);
+ /******** in 3d use only */
+ a = 400/2.;
+ b = 1 - a*(-1);
+ c = -300/2.;
+ d = 300 - c*(-1);
+ emit progressbar(60);
+ //angle = toradians(60);
+ view3d.setUp( 1.0, 0.0, 0.0);
+ emit progressbar(70);
+ view3d.setAngle(toradians(60));
+ emit progressbar(80);
+ setAtPoint( &view3d); // If file is empty software crash here.
+ emit progressbar(90);
+ xmin = objxmin; xmax = objxmax; ymin = objymin; ymax = objymax; // 2d viewing needs this !!!!
+ emit progressbar(95);
+ setFromPoint( &view3d);
+ emit progressbar(98);
+ view3d.setEye();
+ emit progressbar(99);
+ /****** end of 3d *****/
+ /*
+ //Testing distance counting
+ Vector a1, a2;
+ qreal dist;
+ //a1.setX( xmin); a1.setY( ymin);
+ //a2.setX( xmax); a2.setY( ymax);
+ a1.setX( 25.483); a1.setY( 65.017); // Oulu
+ a2.setX( 27.767); a2.setY( 64.283); // Kajaani
+ dist = countDistance( &a1, &a2);
+ QString str = QString("Min & Max datan välimatka %1").arg(dist);
+ QMessageBox::about( 0, "Testi", str);
+ */
+ emit progressbar(100);
+ return true;
+ }
+ else // Probably file is empty.
+ {
+ QMessageBox::about(0, "Error", "Empty file");
+ return false;
+ }
+}
+
+/**
+ * Find out data range for x-, y- and z-coordinates
+ */
+void dataMinMax( void)
+{
+ int i, maxi;
+ qreal x,y,z;
+ Vector temp;
+
+ temp = vertexList.at(0);
+ objxmax = objxmin = temp.getX();
+ objymax = objymin = temp.getY();
+ objzmax = objzmin = temp.getZ();
+
+ maxi = vertexList.size();
+ for (i=1; i<maxi; i++)
+ {
+ temp = vertexList.at(i);
+ x = temp.getX();
+ y = temp.getY();
+ z = temp.getZ();
+
+ if (x < objxmin)
+ {
+ objxmin = x;
+ }
+ else if (x > objxmax)
+ {
+ objxmax = x;
+ }
+
+ if (y < objymin)
+ {
+ objymin = y;
+ }
+ else if (y > objymax)
+ {
+ objymax = y;
+ }
+
+ if (z < objzmin)
+ {
+ objzmin = z;
+ }
+ else if (z > objzmax)
+ {
+ objzmax = z;
+ }
+ }
+ //QString jono = QString("ojxmin %1 objxmax %2").arg(objxmin).arg(objxmax);
+ //QString jono = QString("ojymin %1 objymax %2").arg(objymin).arg(objymax);
+ //QString jono = QString("ojzmin %1 objzmax %2").arg(objzmin).arg(objzmax);
+ //QMessageBox::about(0,"Tark", jono);
+}
+
+/**
+ * Setting the point where the viewed object is. In the middle of datapoints.
+ */
+void setAtPoint( Viewing *v)
+{
+ qreal x, y, z;
+ dataMinMax();
+ //Vector test;
+
+ x = (objxmax+objxmin)/2.0;
+ y= (objymax+objymin)/2.0;
+ z= (objzmax+objzmin)/2.0;
+
+ v->setAtPoint( x, y, z);
+ //QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(atPoint.x()).arg(atPoint.y()).arg(atPoint.z());
+ //QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(atPoint.x).arg(atPoint.y).arg(atPoint.z);
+
+ /* *
+ test = v->getAtPoint();
+ QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(test.getX()).arg(test.getY()).arg(test.getZ());
+ QMessageBox::about(0,"At point", jono);
+ * */
+}
+
+/**
+ * Setting the point where the object is viewed by eye.
+ */
+void setFromPoint( Viewing *v)