Beispiel #1
0
void SettingsPageTask::setDistanceValue( Distance& dest, DoubleNumberEditor* src)
{
  if( m_distUnit == Distance::kilometers ) // user gets kilometers
    {
      dest.setKilometers( src->value() );
    }
  else if( m_distUnit == Distance::miles ) // user gets miles
    {
      dest.setMiles( src->value() );
    }
  else // ( distUnit == Distance::nautmiles )
    {
      dest.setNautMiles( src->value() );
    }
}
Beispiel #2
0
/**
 * Calculate course, distance and reachability from the current position
 * to the elements contained in the limited list. If a glider is defined
 * the glide path is taken into account and the arrival altitude is
 * calculated too.
 */
void ReachableList::calculateDataInList()
{
  // QTime t;
  // t.start();
  int counter = 0;
  setInitValues();
  arrivalAltMap.clear();
  distanceMap.clear();

  for (int i = 0; i < count(); i++)
    {
      // recalculate Distance
      ReachablePoint& p = (*this)[i];
      WGSPoint pt = p.getWaypoint()->wgsPoint;
      Altitude arrivalAlt;
      Distance distance;
      Speed bestSpeed;

      distance.setKilometers( MapCalc::dist(&lastPosition, &pt) );

      if ( lastPosition == pt || distance.getMeters() <= 100.0 )
        {
          // @AP: there is nearly no difference between the two points,
          // therefore we have no distance and no bearing
          distance.setMeters(0.0);
          p.setDistance( distance );
          p.setBearing( 0 );
          p.setArrivalAlt( calculator->getAltitudeCollection().gpsAltitude  );
        }
      else
        {
          p.setDistance( distance );

          // recalculate Bearing
          p.setBearing( short (rint(MapCalc::getBearingWgs(lastPosition, pt) * 180/M_PI)) );

          // Calculate glide path. Returns false, if no glider is known.
          calculator->glidePath( p.getBearing(), p.getDistance(),
                                 Altitude(p.getElevation()),
                                 arrivalAlt, bestSpeed );

          // Save arrival altitude. Is set to invalid, if no glider is defined in calculator.
          p.setArrivalAlt( arrivalAlt );
        }

      if ( arrivalAlt.isValid() )
        {
          // add only valid altitudes to the map
          arrivalAltMap[ coordinateString ( pt ) ] = (int) arrivalAlt.getMeters() + safetyAlt;
        }

      distanceMap[ coordinateString ( pt ) ] = distance;

      if ( arrivalAlt.getMeters() > 0 )
        {
          counter++;
        }
    }

  // sorting of items depends on the glider selection
  if ( calculator->glider() )
    {
      modeAltitude = true; // glider is known, sort by arrival altitudes
    }
  else
    {
      modeAltitude = false; // glider is unknown, sort by distances
    }

  qSort( begin(), end() );
  // qDebug("Number of reachable sites (arriv >0): %d", counter );
  // qDebug("Time for glide path calculation: %d msec", t.restart() );
  emit newReachList();
}
Beispiel #3
0
void ReachableList::addItemsToList(enum MapContents::ListID item)
{
  Distance distance;
  QRect bbox = MapCalc::areaBox(lastPosition, _maxReach);
  int r=0, a=0;
  //qDebug("bounding box: (%d, %d), (%d, %d) (%d x %d km)", bbox.left(),bbox.top(),bbox.right(),bbox.bottom(),0,0);

  if( item == MapContents::WaypointList )
    {
      // Waypoints have different structure treat them here
      QList<Waypoint> &wpList = _globalMapContents->getWaypointList();
      // qDebug("Nr of Waypoints: %d", wpList.count() );

      for ( int i=0; i < wpList.count(); i++ )
        {
          WGSPoint pt = wpList.at(i).wgsPoint;

          if (! bbox.contains(pt))
            {
              //qDebug("Not in bounding box, so ignore! (distance: %d, (%d, %d), %s)", (int)distance.getKilometers(), pt.x(),pt.y(), wpList.at(i)->name.latin1());
              r++;
              continue;
            }
          else
            {
              a++;
              //qDebug("In bounding box, so accept! (distance: %d, %s)", (int)distance.getKilometers(), wpList.at(i)->name.latin1());
            }

          distance.setKilometers(MapCalc::dist(&lastPosition, &pt));

          bool isLandable = false;

          if( wpList.at(i).rwyList.size() > 0 )
            {
              isLandable = wpList.at(i).rwyList.at(0).m_isOpen;
            }


          // check if point is a potential reachable candidate at best LD
          if ( (distance.getKilometers() > _maxReach ) ||
               ! (isLandable ||
                 (wpList.at(i).type == BaseMapElement::Outlanding) )  )
            {
              continue;
            }

          // calculate bearing
          double result = MapCalc::getBearing(lastPosition, pt);
          int bearing = int(rint(result * 180./M_PI));
          Altitude altitude(0);

          ReachablePoint rp( wpList[i],
                             false,
                             distance,
                             bearing,
                             altitude );

          append(rp);
        }
    }
  else
    {
      // get number of elements in the list
      int nr = _globalMapContents->getListLength(item);

      // qDebug("No of sites: %d type %d", nr, item );
      for (int i=0; i<nr; i++ )
        {
          // Get specific site data from current list. We have to distinguish
          // between AirfieldList, GilderSiteList and OutlandingList.
          Airfield* site;

          if( item == MapContents::AirfieldList )
            {
              // Fetch data from airport list
              site = _globalMapContents->getAirfield(i);
            }
          else if( item == MapContents::GliderfieldList )
            {
              // fetch data from glider site list
              site = _globalMapContents->getGliderfield(i);
            }
          else if( item == MapContents::OutLandingList )
            {
              // fetch data from glider site list
              site = _globalMapContents->getOutlanding(i);
            }
          else
            {
              qWarning( "ReachableList::addItemsToList: ListType %d is unknown",
                        item );
              break;
            }

          QString siteName = site->getWPName();
          QString siteIcao = site->getICAO();
          QString siteDescription = site->getName();
          QString siteCountry = site->getCountry();
          short siteType = site->getTypeID();
          float siteFrequency = site->getFrequency();
          WGSPoint siteWgsPosition = site->getWGSPosition();
          QPoint sitePosition = site->getPosition();
          float siteElevation = site->getElevation();
          QString siteComment = site->getComment();
          QList<Runway> siteRwyList = site->getRunwayList();

          if (! bbox.contains(siteWgsPosition) )
            {
              //qDebug("Not in bounding box, so ignore! (distance: %d, (%d, %d), %s)", (int)distance.getKilometers(), pt.x(),pt.y(), site->getName().latin1());
              r++;
              continue;
            }
          else
            {
              a++;
              //qDebug("In bounding box, so accept! (distance: %d, %s)", (int)distance.getKilometers(), site->getName().latin1());
            }
          distance.setKilometers(MapCalc::dist(&lastPosition,&siteWgsPosition));
          // qDebug("%d  %f %f", i, (float)distance.getKilometers(),_maxReach );
          // check if point is a potential reachable candidate at best LD
          if ( distance.getKilometers() > _maxReach )
            {
              continue;
            }

          // calculate bearing
          double result = MapCalc::getBearing(lastPosition, siteWgsPosition);
          short bearing = short(rint(result * 180./M_PI));
          Altitude altitude(0);

          // add all potential reachable points to the list, altitude is calculated later
          ReachablePoint rp( siteName,
                             siteIcao,
                             siteDescription,
                             siteCountry,
                             true,
                             siteType,
                             siteFrequency,
                             siteWgsPosition,
                             sitePosition,
                             siteElevation,
                             siteComment,
                             distance,
                             bearing,
                             altitude,
                             siteRwyList );
          append(rp);

          // qDebug("%s(%d) %f %d° %d", rp.getName().toLatin1().data(), rp.getElevation(),  rp.getDistance().getKilometers(), rp.getBearing(), (int)rp->getArrivalAlt().getMeters() );

        }
    }
  // qDebug("accepted: %d, rejected: %d. Percent reject: %f",a,r,(100.0*r)/(a+r));
}