Exemplo n.º 1
0
void
Loco::NewDestination (const QGeoCoordinate & whereTo,
                      const QString & name)
{
  locator->SetMoveStep (normalStep);
  steppingNormal = true;
  destination = whereTo;
  destName = name;
  QDateTime now = QDateTime::currentDateTime();
  mainUi.destination->setText (tr("going to %1 at %2")
                                 .arg (name)
                                 .arg (whereTo.toString()));
  double dist = lastLocation.distanceTo (whereTo);
  mainUi.msgLog->append (tr("At %1 destination %2 (%3)  %4 nm %5 mi %6 km")
                         .arg (now.toString("hh:mm:ss"))
                         .arg (name)
                         .arg (whereTo.toString())
                         .arg (dist/1852.0)
                         .arg (dist/1609.344)
                         .arg (dist/1000.0));
}
Exemplo n.º 2
0
void
Loco::NewPosition (const QGeoPositionInfo & here)
{
  static QGeoCoordinate old;
  QGeoCoordinate coord = here.coordinate();
  QString newPlace = coord.toString();
  qreal dist = old.distanceTo (coord);
  qreal azi = old.azimuthTo (coord);
  mainUi.displayMap->SetCourseAngle (azi);
  QString directions = QString (" %1 km head %2 (%3)")
                       .arg (dist/1000.0)
                       .arg (CompassDir(azi))
                       .arg (azi);
  old = coord;
  lastLocation = coord;
  QDateTime now = QDateTime::currentDateTime();
  dist = coord.distanceTo (destination);
  qreal destDist = coord.distanceTo (destination);
  qreal etaSecs = (destDist / locator->MoveStep()) * (locator->Interval()/1000.0);
  mainUi.destination->setText (tr("going %6 m %4 (%5) to %1 \n"
                        "at %2 \n"
                        "with %3 km left ETA %7 secs")
                               .arg (destName)
                               .arg (destination.toString())
                               .arg (qRound(dist/1000.0))
                               .arg (CompassDir (azi))
                               .arg (azi)
                               .arg (locator->MoveStep())
                               .arg (etaSecs, 10, 'g',4));
  QString stats ("Cache: Hits %1 Misses %2");
  mainUi.statLabel->setText (stats
                     .arg (mainUi.displayMap->CacheHits())
                     .arg (mainUi.displayMap->CacheMisses()));

  if (destDist < qreal (normalStep * 5)) {
    steppingNormal = false;
    locator->SetMoveStep (shortStep);
  } else {
    steppingNormal = true;
    locator->SetMoveStep (normalStep);
  }
}
Exemplo n.º 3
0
void Loco::reportPos(const QGeoCoordinate &here)
{
  mainUi.menuCur->setTitle(here.toString());
}
Exemplo n.º 4
0
void TRMainWindow::newLocationInfoReceived(const QGeoPositionInfo positionInfo)
{
    QGeoCoordinate currentCoords = positionInfo.coordinate();
    if(m_lastKnownPosition || !(currentCoords == *m_lastKnownPosition))
    {
        // We need to write to the file, let's initialize it
        if(m_outputKMLFile == NULL)
        {
            // File initialization
            QString timeStamp = positionInfo.timestamp().toString(Qt::ISODate);
            QString fileTimeStamp = positionInfo.timestamp().toString("hhmmssddMMyy");
            m_outputKMLFile = new QFile("c://Data//trackroute_"+fileTimeStamp+".kml");
            m_outputKMLFile->open(QIODevice::WriteOnly | QIODevice::Text);
            // File writer initialization
            if(m_kmlFileWriter == NULL)
            {
                // Header
                m_kmlFileWriter = new QXmlStreamWriter(m_outputKMLFile);
                m_kmlFileWriter->writeStartDocument();
                m_kmlFileWriter->writeNamespace("http://www.opengis.net/kml/2.2","kml");
                // Document
                m_kmlFileWriter->writeStartElement("Document");
                m_kmlFileWriter->writeTextElement("name","TrackRoute Path File");
                m_kmlFileWriter->writeTextElement("description","Pathfile generated by Trackroute on: "+timeStamp);
                // Style
                m_kmlFileWriter->writeStartElement("Style");
                m_kmlFileWriter->writeAttribute("id","yellowLineGreenPoly");
                // LineStyle
                m_kmlFileWriter->writeStartElement("LineStyle");
                m_kmlFileWriter->writeTextElement("color","7f00ffff");
                m_kmlFileWriter->writeTextElement("width","4");
                m_kmlFileWriter->writeEndElement();
                // PolyStyle
                m_kmlFileWriter->writeStartElement("PolyStyle");
                m_kmlFileWriter->writeTextElement("color","7f00ff00");
                m_kmlFileWriter->writeEndElement();
                // End Style
                m_kmlFileWriter->writeEndElement();
                // Placemark
                m_kmlFileWriter->writeStartElement("Placemark");
                m_kmlFileWriter->writeTextElement("name","TrackRoute Path "+timeStamp);
                m_kmlFileWriter->writeTextElement("description","Path generated by Trackroute on: "+timeStamp);
                m_kmlFileWriter->writeTextElement("styleUrl","#yellowLineGreenPoly");
                // LineString
                m_kmlFileWriter->writeStartElement("LineString");
                m_kmlFileWriter->writeTextElement("extrude","1");
                m_kmlFileWriter->writeTextElement("tessellate","1");
                m_kmlFileWriter->writeTextElement("altitudeMode","absolute");
                // Coordinates
                m_kmlFileWriter->writeStartElement("coordinates");
            }
        }

        // Update data
        m_numberOfUpdatesReceived++;
        m_currentSpeed = positionInfo.attribute(QGeoPositionInfo::GroundSpeed);
        m_currentSpeed = m_currentSpeed > 0 ? m_currentSpeed:0;
        m_totalSpeed += m_currentSpeed;
        m_averageSpeed = m_totalSpeed / m_numberOfUpdatesReceived;
        QString coordString = currentCoords.toString();

        // Update UI
        ui->latLonDataLabel->setText(coordString.left(coordString.lastIndexOf(",")));
        ui->altitudeDataLabel->setText(QString::number(currentCoords.altitude())+" m");
        ui->wptNumberDataLabel->setText(QString::number(m_numberOfUpdatesReceived));
        ui->currentSpdDataLabel->setText(QString::number(m_currentSpeed)+" km/h");
        ui->averageSpdDataLabel->setText(QString::number(m_averageSpeed)+" km/h");

        // Write to the KML file
        QString locationData = QString::number(currentCoords.latitude()).append(",").append(QString::number(currentCoords.longitude()))
                               .append(",").append(QString::number(currentCoords.altitude())).append(" ");
        m_kmlFileWriter->writeCharacters(locationData);
        m_outputKMLFile->flush();
    }
    m_lastKnownPosition = &currentCoords;
}