/** * Updates all the dialogs fields, that are changing frequently. * e.g. climb speed, distance, height */ static void UpdateChanging() { TCHAR tmp[20]; const FLARM_TRAFFIC* target = XCSoarInterface::Basic().flarm.FindTraffic(target_id); // If target moved out of range -> return if (!target || !target->IsDefined()) return; // Fill distance field Units::FormatUserDistance(target->distance, tmp, 20); ((WndProperty *)wf->FindByName(_T("prpDistance")))->SetText(tmp); // Fill horizontal direction field Angle bearing = (target->Bearing() - XCSoarInterface::Basic().track).as_delta(); if (bearing.value_degrees() > fixed_one) _stprintf(tmp, _T("%2.0f")_T(DEG)_T(" »"), (double)bearing.value_degrees()); else if (bearing.value_degrees() < fixed_minus_one) _stprintf(tmp, _T("« ")_T("%2.0f")_T(DEG), (double)-bearing.value_degrees()); else _tcscpy(tmp, _T("«»")); ((WndProperty *)wf->FindByName(_T("prpDirectionH")))->SetText(tmp); // Fill altitude field if (target->altitude_available) Units::FormatUserAltitude(target->altitude, tmp, 20); else _tcscpy(tmp, _T("--")); ((WndProperty *)wf->FindByName(_T("prpAltitude")))->SetText(tmp); // Fill vertical direction field Angle dir = Angle::radians((fixed)atan2(target->relative_altitude, target->distance)).as_delta(); if (dir.magnitude_degrees() > fixed_one) _stprintf(tmp, _T("%+2.0f")_T(DEG), (double)dir.value_degrees()); else _tcscpy(tmp, _T("--")); ((WndProperty *)wf->FindByName(_T("prpDirectionV")))->SetText(tmp); // Fill climb speed field if (target->climb_rate_avg30s_available) Units::FormatUserVSpeed(target->climb_rate_avg30s, tmp, 20); else _tcscpy(tmp, _T("--")); ((WndProperty *)wf->FindByName(_T("prpVSpeed")))->SetText(tmp); }
void Units::LatitudeToDMS(Angle Latitude, int *dd, int *mm, int *ss, bool *north) { // if (Latitude is negative) -> Latitude is South otherwise North *north = (Latitude.sign() >= 0); unsigned value = (unsigned)(Latitude.magnitude_degrees() * 3600 + fixed_half); *ss = value % 60; value /= 60; *mm = value % 60; value /= 60; *dd = value; }
void Units::LongitudeToDMS(Angle Longitude, int *dd, int *mm, int *ss, bool *east) { // if (Longitude is negative) -> Longitude is West otherwise East *east = (Longitude.sign() >= 0); unsigned value = (unsigned)(Longitude.magnitude_degrees() * 3600 + fixed_half); *ss = value % 60; value /= 60; *mm = value % 60; value /= 60; *dd = value; }
bool Units::LatitudeToString(Angle Latitude, TCHAR *Buffer, size_t size) { (void)size; TCHAR EW[] = _T("SNN"); int dd, mm, ss; // Calculate Latitude sign int sign = Latitude.sign()+1; double mlat = Latitude.magnitude_degrees(); switch (CoordinateFormat) { case cfDDMMSS: // Calculate degrees dd = (int)mlat; // Calculate minutes mlat = (mlat - dd) * 60.0; mm = (int)(mlat); // Calculate seconds mlat = (mlat - mm) * 60.0; ss = (int)(mlat + 0.5); if (ss >= 60) { mm++; ss -= 60; } if (mm >= 60) { dd++; mm -= 60; } // Save the string to the Buffer _stprintf(Buffer, _T("%c%02d")_T(DEG)_T("%02d'%02d\""), EW[sign], dd, mm, ss); break; case cfDDMMSSss: // Calculate degrees dd = (int)mlat; // Calculate minutes mlat = (mlat - dd) * 60.0; mm = (int)(mlat); // Calculate seconds mlat = (mlat - mm) * 60.0; // Save the string to the Buffer _stprintf(Buffer, _T("%c%02d")_T(DEG)_T("%02d'%05.2f\""), EW[sign], dd, mm, mlat); break; case cfDDMMmmm: // Calculate degrees dd = (int)mlat; // Calculate minutes mlat = (mlat - dd) * 60.0; // Save the string to the Buffer _stprintf(Buffer, _T("%c%02d")_T(DEG)_T("%06.3f'"), EW[sign], dd, mlat); break; case cfDDdddd: // Save the string to the Buffer _stprintf(Buffer, _T("%c%07.4f")_T(DEG), EW[sign], mlat); break; default: return false; } return true; }