+bool RouteDialog::readRouteFromFile( QString &routeFile)
+ {
+ Vector temp;
+ QString rivi;
+ QFile file;
+
+ //QString fileName = QFileDialog::getOpenFileName(this,
+ // tr("Read Route"), "./", tr("Route Files (*.txt)"));
+
+ //file.setFileName( fileName);
+ file.setFileName( "routetemp.xml");
+ if (!file.open(QIODevice::ReadOnly))
+ {
+ QMessageBox::about(0, "Error", "File not found");
+ return false;
+ }
+
+ vertexList.clear();
+
+ while(!file.atEnd())
+ {
+ int count;
+ 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);
+ //QString str = QString("%1 %2 %3 %4").arg(str1).arg(str2).arg(str3).arg(str4);
+ //QMessageBox::about(0, "LUKEE", str);
+ /* */
+
+ 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 m/s
+ // QString str = QString("%1 %2 %3 %4").arg(x).arg(y).arg(z).arg(v);
+ // QMessageBox::about(0, "LUKEE", str);
+ temp.setX( x); // Longitude
+ temp.setY( y); // Latitude
+ temp.setZ( z); // altitude
+ temp.setV( v);
+
+ vertexList.append(temp);
+ count++;
+ }
+ else
+ {
+ allRead = true;
+ }
+ }
+ }
+ // Older version
+ /*
+ str1 = rivi.section(" ", 0, 0);
+ if (str1.compare("Start:") != 0 && str1.compare("Stop:") != 0)
+ {
+ str1 = rivi.section(" ", 2, 2); // latitude y-value
+ str2 = rivi.section(" ", 4, 4); // longitude x-value
+ str3 = rivi.section(" ", 6, 6); // altitude z-value
+ str4 = rivi.section(" ", 8, 8); // speed m/s
+ //QString str = QString("la: %1 lo: %2 al: %3").arg(str1).arg(str2).arg(str3);
+ //QMessageBox::about(0, "LUKEE", str);
+
+ if (str1.length() > 0)
+ {
+ double x, y, z, v;
+ x = str2.toDouble();
+ y = str1.toDouble();
+ z = str3.toDouble();
+ v = str4.toDouble();
+ temp.setX( x); // Longitude
+ temp.setY( y); // Latitude
+ temp.setZ( z); // altitude
+ temp.setV( v);
+
+ vertexList.append(temp);
+ }
+ }
+ */
+ }
+
+ file.close();
+
+ /******** in 3d use only */
+ a = 400/2.;
+ b = 1 - a*(-1);
+ c = -300/2.;
+ d = 300 - c*(-1);
+ //angle = toradians(60);
+
+ view3d.setUp( 1.0, 0.0, 0.0);
+ view3d.setAngle(toradians(60));
+ setAtPoint( &view3d);
+ xmin = objxmin; xmax = objxmax; ymin = objymin; ymax = objymax; // 2d viewing needs this !!!!
+ setFromPoint( &view3d);
+ view3d.setEye();
+ /****** 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);
+ */
+
+ return true;
+ }
+
+/*
+ * Find out data range for x-, y- and z-coordinates
+ */