void
TaskStatusPanel::Refresh()
{
  if (protected_task_manager == NULL)
    return;

  const DerivedInfo &calculated = CommonInterface::Calculated();
  const TaskStats &task_stats = calculated.task_stats;

  TCHAR Temp[80];

  FormatSignedTimeHHMM(Temp, (int)protected_task_manager->GetOrderedTaskBehaviour().aat_min_time);
  ShowFormControl(form, _T("prpTaskTime"), task_stats.has_targets);
  if (task_stats.has_targets)
    SetFormValue(form, _T("prpTaskTime"), Temp);

  int ete_time(task_stats.total.time_elapsed +
               task_stats.total.time_remaining);
  FormatSignedTimeHHMM(Temp, ete_time);
  SetFormValue(form, _T("prpETETime"), Temp);

  FormatSignedTimeHHMM(Temp, (int)task_stats.total.time_remaining);
  SetFormValue(form, _T("prpRemainingTime"), Temp);

  if (task_stats.total.planned.IsDefined()) {
    Units::FormatUserDistanceSmart(task_stats.total.planned.get_distance(),
                              Temp, ARRAY_SIZE(Temp));
    SetFormValue(form, _T("prpTaskDistance"), Temp);
  } else
    SetFormValue(form, _T("prpTaskDistance"), _T(""));

  if (task_stats.total.remaining.IsDefined()) {
    Units::FormatUserDistanceSmart(task_stats.total.remaining.get_distance(),
                              Temp, ARRAY_SIZE(Temp));
    SetFormValue(form, _T("prpRemainingDistance"), Temp);
  }

  if (task_stats.total.planned.IsDefined()) {
    Units::FormatUserTaskSpeed(task_stats.total.planned.get_speed(),
                               Temp, ARRAY_SIZE(Temp));
    SetFormValue(form, _T("prpEstimatedSpeed"), Temp);
  } else
    SetFormValue(form, _T("prpEstimatedSpeed"), _T(""));

  if (task_stats.total.travelled.IsDefined()) {
    Units::FormatUserTaskSpeed(task_stats.total.travelled.get_speed(),
                               Temp, ARRAY_SIZE(Temp));
    SetFormValue(form, _T("prpAverageSpeed"), Temp);
  } else
    SetFormValue(form, _T("prpAverageSpeed"), _T(""));
}
Exemple #2
0
void
TaskStatusPanel::Refresh()
{
  if (protected_task_manager == NULL)
    return;

  const DerivedInfo &calculated = CommonInterface::Calculated();
  const TaskStats &task_stats = calculated.ordered_task_stats;

  TCHAR Temp[80];

  SetRowVisible(TaskTime, task_stats.has_targets);
  if (task_stats.has_targets) {
    FormatSignedTimeHHMM(Temp, (int)protected_task_manager->GetOrderedTaskSettings().aat_min_time);
    SetText(TaskTime, Temp);
  }

  int ete_time(task_stats.GetEstimatedTotalTime());
  FormatSignedTimeHHMM(Temp, ete_time);
  SetText(ETETime, Temp);

  FormatSignedTimeHHMM(Temp, (int)task_stats.total.time_remaining_now);
  SetText(RemainingTime, Temp);

  if (task_stats.total.planned.IsDefined()) {
    FormatUserDistanceSmart(task_stats.total.planned.GetDistance(),
                              Temp, ARRAY_SIZE(Temp));
    SetText(TaskDistance, Temp);
  } else
    SetText(TaskDistance, _T(""));

  if (task_stats.total.remaining.IsDefined()) {
    FormatUserDistanceSmart(task_stats.total.remaining.GetDistance(),
                              Temp, ARRAY_SIZE(Temp));
    SetText(RemainingDistance, Temp);
  }

  if (task_stats.total.planned.IsDefined()) {
    FormatUserTaskSpeed(task_stats.total.planned.GetSpeed(),
                               Temp, ARRAY_SIZE(Temp));
    SetText(EstimatedSpeed, Temp);
  } else
    SetText(EstimatedSpeed, _T(""));

  if (task_stats.total.travelled.IsDefined()) {
    FormatUserTaskSpeed(task_stats.total.travelled.GetSpeed(),
                               Temp, ARRAY_SIZE(Temp));
    SetText(AverageSpeed, Temp);
  } else
    SetText(AverageSpeed, _T(""));
}
void
MapItemListRenderer::Draw(Canvas &canvas, const PixelRect rc,
                          const MarkerMapItem &item,
                          const DialogLook &dialog_look,
                          const MarkerLook &look)
{
  const PixelScalar line_height = rc.bottom - rc.top;

  const Marker &marker = item.marker;

  const RasterPoint pt(rc.left + line_height / 2,
                       rc.top + line_height / 2);

  look.icon.Draw(canvas, pt);

  const Font &name_font = *dialog_look.list.font_bold;
  const Font &small_font = *dialog_look.small_font;

  PixelScalar left = rc.left + line_height + Layout::FastScale(2);

  StaticString<256> buffer;
  buffer.Format(_T("%s #%d"), _("Marker"), item.id + 1);
  canvas.Select(name_font);
  canvas.DrawClippedText(left, rc.top + Layout::FastScale(2), rc, buffer);

  TCHAR time_buffer[32], timespan_buffer[32];
  FormatSignedTimeHHMM(time_buffer, TimeLocal(marker.time.GetSecondOfDay()));
  FormatTimespanSmart(timespan_buffer, BrokenDateTime::NowUTC() - marker.time);
  buffer.Format(_("dropped %s ago"), timespan_buffer);
  buffer.AppendFormat(_T(" (%s)"), time_buffer);
  canvas.Select(small_font);
  canvas.DrawClippedText(left,
                         rc.top + name_font.GetHeight() + Layout::FastScale(4),
                         rc, buffer);
}
Exemple #4
0
void
InputEvents::eventTaskTransition(const TCHAR *misc)
{
  if (protected_task_manager == NULL)
    return;

  if (StringIsEqual(misc, _T("start"))) {
    AircraftState start_state = protected_task_manager->GetStartState();

    TCHAR TempTime[40];
    TCHAR TempAlt[40];
    TCHAR TempSpeed[40];
    
    FormatSignedTimeHHMM(TempTime, (int)TimeLocal((int)start_state.time));
    FormatUserAltitude(start_state.altitude, TempAlt, true);
    FormatUserSpeed(start_state.ground_speed,TempSpeed, true);
    
    TCHAR TempAll[120];
    _stprintf(TempAll, _T("\r\nAltitude: %s\r\nSpeed:%s\r\nTime: %s"),
              TempAlt, TempSpeed, TempTime);
    Message::AddMessage(_("Task start"), TempAll);
  } else if (StringIsEqual(misc, _T("tp"))) {
    Message::AddMessage(_("Next turnpoint"));
  } else if (StringIsEqual(misc, _T("finish"))) {
    Message::AddMessage(_("Task finished"));
  } else if (StringIsEqual(misc, _T("ready"))) {
    Message::AddMessage(_("In sector, arm advance when ready"));
  }
}
Exemple #5
0
gcc_const
static inline StringBuffer<TCHAR, 8>
FormatSignedTimeHHMM(int time)
{
  StringBuffer<TCHAR, 8> buffer;
  FormatSignedTimeHHMM(buffer.data(), time);
  return buffer;
}
Exemple #6
0
void
TimeConfigPanel::SetLocalTime(int utc_offset)
{
  TCHAR temp[20];
  int time(XCSoarInterface::Basic().time);
  FormatSignedTimeHHMM(temp, TimeLocal(time, utc_offset));

  WndProperty &wp = GetControl(LocalTime);

  wp.SetText(temp);
  wp.RefreshDisplay();
}
void
MapItemListRenderer::Draw(Canvas &canvas, const PixelRect rc,
                          const ThermalMapItem &item,
                          const DialogLook &dialog_look,
                          const MapLook &look)
{
  const PixelScalar line_height = rc.bottom - rc.top;

  const ThermalSource &thermal = item.thermal;

  RasterPoint pt = { PixelScalar(rc.left + line_height / 2),
                     PixelScalar(rc.top + line_height / 2) };

  look.thermal_source_icon.Draw(canvas, pt);

  const Font &name_font = *dialog_look.list.font;
  const Font &small_font = *dialog_look.small_font;
  canvas.SetTextColor(COLOR_BLACK);

  PixelScalar left = rc.left + line_height + Layout::FastScale(2);

  canvas.Select(name_font);
  canvas.text_clipped(left, rc.top + Layout::FastScale(2), rc, _("Thermal"));

  StaticString<256> buffer;
  TCHAR lift_buffer[32], time_buffer[32], timespan_buffer[32];
  FormatUserVerticalSpeed(thermal.lift_rate, lift_buffer, 32);
  FormatSignedTimeHHMM(time_buffer, TimeLocal((int)thermal.time));

  int timespan = BrokenDateTime::NowUTC().GetSecondOfDay() - (int)thermal.time;
  if (timespan < 0)
    timespan += 24 * 60 * 60;

  FormatTimespanSmart(timespan_buffer, timespan);

  buffer.Format(_T("%s: %s"), _("Avg. lift"), lift_buffer);
  buffer.append(_T(" - "));
  buffer.AppendFormat(_("left %s ago"), timespan_buffer);
  buffer.AppendFormat(_T(" (%s)"), time_buffer);
  canvas.Select(small_font);
  canvas.text_clipped(left,
                      rc.top + name_font.GetHeight() + Layout::FastScale(4),
                      rc, buffer);
}
void
TimesStatusPanel::Refresh()
{
  const NMEAInfo &basic = CommonInterface::Basic();
  const FlyingState &flight = CommonInterface::Calculated().flight;
  const ComputerSettings &settings = CommonInterface::GetComputerSettings();

  StaticString<64> temp;

  if (basic.location_available && basic.date_time_utc.IsDatePlausible()) {
    SunEphemeris::Result sun =
      SunEphemeris::CalcSunTimes(basic.location, basic.date_time_utc,
                                 settings.utc_offset);

    const unsigned sunrisehours = (int)sun.time_of_sunrise;
    const unsigned sunrisemins = (int)((sun.time_of_sunrise - double(sunrisehours)) * 60);
    const unsigned sunsethours = (int)sun.time_of_sunset;
    const unsigned sunsetmins = (int)((sun.time_of_sunset - double(sunsethours)) * 60);

    temp.Format(_T("%02u:%02u - %02u:%02u"), sunrisehours, sunrisemins, sunsethours, sunsetmins);
    SetText(Daylight, temp);
  } else {
    ClearText(Daylight);
  }

  if (basic.time_available) {
    SetText(LocalTime,
            FormatLocalTimeHHMM((int)basic.time, settings.utc_offset));
    SetText(UTCTime, FormatSignedTimeHHMM((int)basic.time));
  } else {
    ClearText(LocalTime);
    ClearText(UTCTime);
  }

  if (basic.date_time_utc.IsDatePlausible()) {
    temp.Format(_T("%04d-%02d-%02d"), basic.date_time_utc.year,
                basic.date_time_utc.month, basic.date_time_utc.day);
    SetText(UTCDate, temp);
  } else {
    ClearText(UTCDate);
  }

  if (flight.flying) {
    SetText(TakeoffTime,
            FormatLocalTimeHHMM((int)flight.takeoff_time,
                                settings.utc_offset));
  } else {
    ClearText(TakeoffTime);
  }

  if (flight.landing_time >= 0) {
    SetText(LandingTime,
            FormatLocalTimeHHMM(int(flight.landing_time),
                                settings.utc_offset));
  } else {
    ClearText(LandingTime);
  }

  if (flight.flight_time > 0) {
    SetText(FlightTime, FormatSignedTimeHHMM((int)flight.flight_time));
  } else {
    ClearText(FlightTime);
  }
}
static void
TestHHMM()
{
  TCHAR buffer[256];

  FormatSignedTimeHHMM(buffer, 0);
  ok1(StringIsEqual(buffer, _T("00:00")));

  FormatSignedTimeHHMM(buffer, 1);
  ok1(StringIsEqual(buffer, _T("00:00")));

  FormatSignedTimeHHMM(buffer, 59);
  ok1(StringIsEqual(buffer, _T("00:00")));

  FormatSignedTimeHHMM(buffer, 60);
  ok1(StringIsEqual(buffer, _T("00:01")));

  FormatSignedTimeHHMM(buffer, 60 * 5);
  ok1(StringIsEqual(buffer, _T("00:05")));

  FormatSignedTimeHHMM(buffer, 60 * 59);
  ok1(StringIsEqual(buffer, _T("00:59")));

  FormatSignedTimeHHMM(buffer, 60 * 60);
  ok1(StringIsEqual(buffer, _T("01:00")));

  FormatSignedTimeHHMM(buffer, 60 * 60 * 3 + 60 * 25);
  ok1(StringIsEqual(buffer, _T("03:25")));

  FormatSignedTimeHHMM(buffer, 60 * 60 * 19 + 60 * 47);
  ok1(StringIsEqual(buffer, _T("19:47")));

  FormatSignedTimeHHMM(buffer, -(60 * 59));
  ok1(StringIsEqual(buffer, _T("-00:59")));

  FormatSignedTimeHHMM(buffer, -(60 * 60 * 19 + 60 * 47));
  ok1(StringIsEqual(buffer, _T("-19:47")));
}
Exemple #10
0
void
TimesStatusPanel::Refresh()
{
  const NMEAInfo &basic = CommonInterface::Basic();
  const FlyingState &flight = CommonInterface::Calculated().flight;

  StaticString<64> temp;

  if (basic.location_available && basic.date_available) {
    SunEphemeris::Result sun = SunEphemeris::CalcSunTimes(
        basic.location, basic.date_time_utc, fixed(GetUTCOffset()) / 3600);

    const unsigned sunrisehours = (int)sun.time_of_sunrise;
    const unsigned sunrisemins = (int)((sun.time_of_sunrise - fixed(sunrisehours)) * 60);
    const unsigned sunsethours = (int)sun.time_of_sunset;
    const unsigned sunsetmins = (int)((sun.time_of_sunset - fixed(sunsethours)) * 60);

    temp.Format(_T("%02u:%02u - %02u:%02u"), sunrisehours, sunrisemins, sunsethours, sunsetmins);
    SetText(Daylight, temp);
  } else {
    SetText(Daylight, _T(""));
  }

  if (basic.time_available) {
    FormatSignedTimeHHMM(temp.buffer(), DetectCurrentTime(basic));
    SetText(LocalTime, temp);
    FormatSignedTimeHHMM(temp.buffer(), (int) basic.time);
    SetText(UTCTime, temp);
  } else {
    SetText(LocalTime, _T(""));
    SetText(UTCTime, _T(""));
  }

  if (basic.date_available) {
    temp.Format(_T("%04d-%02d-%02d"), basic.date_time_utc.year,
                basic.date_time_utc.month, basic.date_time_utc.day);
    SetText(UTCDate, temp);
  } else {
    SetText(UTCDate, _T(""));
  }

  if (positive(flight.flight_time)) {
    FormatSignedTimeHHMM(temp.buffer(), TimeLocal((int)flight.takeoff_time));
    SetText(TakeoffTime, temp);
  } else {
    SetText(TakeoffTime, _T(""));
  }

  if (!flight.flying && positive(flight.flight_time)) {
    FormatSignedTimeHHMM(temp.buffer(),
                      TimeLocal((long)(flight.takeoff_time
                                       + flight.flight_time)));
    SetText(LandingTime, temp);
  } else {
    SetText(LandingTime, _T(""));
  }

  if (positive(flight.flight_time)) {
    FormatSignedTimeHHMM(temp.buffer(), (int)flight.flight_time);
    SetText(FlightTime, temp);
  } else {
    SetText(FlightTime, _T(""));
  }
}
Exemple #11
0
void
TaskStatusPanel::Refresh()
{
  if (protected_task_manager == nullptr)
    return;

  const DerivedInfo &calculated = CommonInterface::Calculated();
  const TaskStats &task_stats = calculated.ordered_task_stats;

  SetRowVisible(TaskTime, task_stats.has_targets);
  if (task_stats.has_targets)
    SetText(TaskTime,
            FormatSignedTimeHHMM((int)protected_task_manager->GetOrderedTaskSettings().aat_min_time));

  SetText(ETETime,
          FormatSignedTimeHHMM((int)task_stats.GetEstimatedTotalTime()));

  SetText(RemainingTime,
          FormatSignedTimeHHMM((int)task_stats.total.time_remaining_now));

  if (task_stats.total.planned.IsDefined())
    SetText(TaskDistance,
            FormatUserDistanceSmart(task_stats.total.planned.GetDistance()));
  else
    ClearText(TaskDistance);

  if (task_stats.total.remaining.IsDefined())
    SetText(RemainingDistance,
            FormatUserDistanceSmart(task_stats.total.remaining.GetDistance()));

  if (task_stats.total.planned.IsDefined())
    SetText(EstimatedSpeed,
            FormatUserTaskSpeed(task_stats.total.planned.GetSpeed()));
  else
    ClearText(EstimatedSpeed);

  if (task_stats.total.travelled.IsDefined())
    SetText(AverageSpeed,
            FormatUserTaskSpeed(task_stats.total.travelled.GetSpeed()));
  else
    ClearText(AverageSpeed);

  LoadValue(MC,
            CommonInterface::GetComputerSettings().polar.glide_polar_task.GetMC(),
            UnitGroup::VERTICAL_SPEED);

  if (task_stats.total.planned.IsDefined()) {
    auto rMax = task_stats.distance_max;
    auto rMin = task_stats.distance_min;

    if (rMin < rMax) {
      auto range = 2 * (task_stats.total.planned.GetDistance() - rMin) / (rMax - rMin) - 1;
      LoadValue(RANGE, range * 100);
    } else
      ClearValue(RANGE);
  } else
    ClearValue(RANGE);

  if (task_stats.total.remaining_effective.IsDefined())
    LoadValue(SPEED_REMAINING, task_stats.total.remaining_effective.GetSpeed(),
              UnitGroup::TASK_SPEED);
  else
    ClearValue(SPEED_REMAINING);

  LoadValue(EFFECTIVE_MC, task_stats.effective_mc, UnitGroup::VERTICAL_SPEED);

  if (task_stats.total.travelled.IsDefined())
    LoadValue(SPEED_ACHIEVED, task_stats.total.travelled.GetSpeed(),
              UnitGroup::TASK_SPEED);
  else
    ClearValue(SPEED_ACHIEVED);

  LoadValue(CRUISE_EFFICIENCY, task_stats.cruise_efficiency * 100);
}