static int OnTimer(WindowControl * Sender){ (void)Sender; #ifdef LKAIRSPACE airspaces.clear(); airspaces = CAirspaceManager::Instance().GetAirspacesInWarning(); Count = airspaces.size(); wAirspaceList->Redraw(); #endif return(0); }
// // Running every n seconds ONLY when the nearest airspace page is active and we are not drawing map. // Returns true if did calculations, false if ok to use old values bool DoAirspaces(NMEA_INFO *Basic, DERIVED_INFO *Calculated) { static int step = 0; bool ret = false; if (DoInit[MDI_DOAIRSPACES]) { memset(LKAirspaces, 0, sizeof(LKAirspaces)); LKNumAirspaces=0; memset(LKSortedAirspaces, -1, sizeof(LKSortedAirspaces)); for (int i=0; i<MAXNEARAIRSPACES; i++) { LKAirspaces[i].Valid = false; LKAirspaces[i].Pointer = NULL; } DoInit[MDI_DOAIRSPACES]=false; return true; } // DoAirspaces is called from MapWindow, in real time. We have enough CPU power there now // Consider replay mode... // Multicalc used below, we don't need this //if ( LastDoAirspaces > Basic->Time ) LastDoAirspaces=Basic->Time; //if ( Basic->Time < (LastDoAirspaces+PAGINGTIMEOUT) ) { // return false; //} // We need a valid GPS fix in FLY mode if (Basic->NAVWarning && !SIMMODE) return true; LastDoAirspaces=Basic->Time; #ifdef DEBUG_LKT StartupStore(_T("... DoAirspaces step%d started\n"),step); #endif switch (step) { // MULTICALC STEP0 - select airspaces in range based on bounds default: case 0: CAirspaceManager::Instance().SelectAirspacesForPage24(Basic->Latitude, Basic->Longitude, 100000.0); // 100km ++step; break; // MULTICALC STEP1 - Do distance calculations on selected airspaces case 1: CAirspaceManager::Instance().CalculateDistancesForPage24(); ++step; break; // MULTICALC STEP2 - Sort by different keys, and fill up result struct array case 2: // Lock airspace instances externally CCriticalSection::CGuard guard(CAirspaceManager::Instance().MutexRef()); // Get selected list from airspacemanager CAirspaceList airspaces = CAirspaceManager::Instance().GetAirspacesForPage24(); // Sort selected airspaces by distance first std::sort(airspaces.begin(), airspaces.end(), airspace_distance_sorter); // get first MAXNEARAIRSPACES to a new list CAirspaceList nearest_airspaces; CAirspaceList::iterator it = airspaces.begin(); for (int i=0; (i<MAXNEARAIRSPACES) && (it!=airspaces.end()); ++i, ++it) nearest_airspaces.push_back(*it); airspaces.clear(); //sort by given key switch (SortedMode[MSM_AIRSPACES]) { case 0: // ASP NAME std::sort(nearest_airspaces.begin(), nearest_airspaces.end(), airspace_name_sorter); break; case 1: // ASP TYPE std::sort(nearest_airspaces.begin(), nearest_airspaces.end(), airspace_type_sorter); break; default: case 2: // ASP DISTANCE // we don't need sorting, already sorted by distance break; case 3: // ASP BEARING std::sort(nearest_airspaces.begin(), nearest_airspaces.end(), airspace_bearing_sorter); break; case 4: // ACTIVE / NOT ACTIVE std::sort(nearest_airspaces.begin(), nearest_airspaces.end(), airspace_enabled_sorter); break; } //sw // Clear results memset(LKSortedAirspaces, -1, sizeof(LKSortedAirspaces)); LKNumAirspaces=0; for (int i=0; i<MAXNEARAIRSPACES; i++) { LKAirspaces[i].Valid = false; LKAirspaces[i].Pointer = NULL; } //copy result data to interface structs // we dont need LKSortedAirspaces[] array, every item will be // in correct order in airspaces list, thanks to std::sort, // we just fill up LKAirspaces[] array in the right order. int i = 0; for (it=nearest_airspaces.begin(); it!=nearest_airspaces.end(); ++it) { // sort key not used, iterator goes in right order after std::sort LKSortedAirspaces[i] = i; // copy name LK_tcsncpy(LKAirspaces[i].Name, (*it)->Name(), NAME_SIZE); // copy type string (type string comes from centralized type->str conversion function of CAirspaceManager) LK_tcsncpy(LKAirspaces[i].Type, CAirspaceManager::Instance().GetAirspaceTypeShortText((*it)->Type()), 4); // copy distance LKAirspaces[i].Distance = max((*it)->LastCalculatedHDistance(),0); // copy bearing LKAirspaces[i].Bearing = (*it)->LastCalculatedBearing(); // copy Enabled() LKAirspaces[i].Enabled = (*it)->Enabled(); // copy Selected() LKAirspaces[i].Selected = (*it)->Selected(); // copy Flyzone() LKAirspaces[i].Flyzone = (*it)->Flyzone(); // copy WarningLevel() LKAirspaces[i].WarningLevel = (*it)->WarningLevel(); // copy WarningAckLevel() LKAirspaces[i].WarningAckLevel = (*it)->WarningAckLevel(); // copy pointer LKAirspaces[i].Pointer = (*it); // Record is valid now. LKAirspaces[i].Valid = true; i++; if (i>=MAXNEARAIRSPACES) break; } LKNumAirspaces=i; ret = true; // ok to use new values. step = 0; break; } //sw step #ifdef DEBUG_LKT StartupStore(_T("... DoAirspaces finished, LKNumAirspaces=%d :\n"), LKNumAirspaces); // For sorting debug only /*for (i=0; i<MAXNEARAIRSPACES; i++) { if (LKSortedAirspaces[i]>=0) StartupStore(_T("... LKSortedAirspaces[%d]=LKAirspaces[%d] Name=<%s> Type=<%s> Dist=%2.0f beardiff=%2.0f enabled=%s\n"), i, LKSortedAirspaces[i], LKAirspaces[LKSortedAirspaces[i]].Name, LKAirspaces[LKSortedAirspaces[i]].Type, LKAirspaces[LKSortedAirspaces[i]].Distance, LKAirspaces[LKSortedAirspaces[i]].Bearing_difference, LKAirspaces[LKSortedAirspaces[i]].Enabled ? _TEXT("true"):_TEXT("false")); }*/ #endif return ret; }
bool dlgAirspaceWarningShowDlg(bool Force){ if (fDialogOpen) return(false); #ifndef LKAIRSPACE if (!actShow && !Force) return false; #endif #ifdef LKAIRSPACE airspaces = CAirspaceManager::Instance().GetAirspacesInWarning(); Count = airspaces.size(); #else Count = AirspaceWarnGetItemCount(); #endif if (Count == 0) return(false); if (wf==NULL) { StartupStore(_T("------ BAD SW ERROR AirspaceWarningDlg problem no window!%s"),NEWLINE); FailStore(_T("BAD SW ERROR AirspaceWarningDlg problem no window!")); return(false); } if (wAirspaceList==NULL) { StartupStore(_T("------ BAD SW ERROR AirspaceList empty!%s"),NEWLINE); FailStore(_T("BAD SW ERROR AirspaceList empty!")); return(false); } wAirspaceList->ResetList(); if (!fDialogOpen) { fDialogOpen = true; #ifndef DISABLEAUDIO if (EnableSoundModes) LKSound(_T("LK_AIRSPACE.WAV")); // 100819 #endif HWND oldFocusHwnd = GetFocus(); wf->ShowModal(); if (oldFocusHwnd) { SetFocus(oldFocusHwnd); } // JMW need to deselect everything on new reopening of dialog #ifndef LKAIRSPACE SelectedID = -1; #endif SelectedIdx = -1; #ifndef LKAIRSPACE FocusedID = -1; #endif FocusedIdx = -1; #ifdef LKAIRSPACE airspaces.clear(); #endif fDialogOpen = false; // SetFocus(hWndMapWindow); // JMW why do this? --- not necessary? // concerned it may interfere if a dialog is already open } return(true); }