示例#1
0
bool MapWindow::Event_InteriorAirspaceDetails(double lon, double lat) {
  bool found=false;
  CAirspaceList reslist = CAirspaceManager::Instance().GetVisibleAirspacesAtPoint(lon, lat);
  CAirspaceList::iterator it;
  for (it = reslist.begin(); it != reslist.end(); ++it) {
	dlgAirspaceDetails(*it);
	found = true;
  }
  return found; // nothing found..
}
示例#2
0
static void PrepareData(void){

  TCHAR sTmp[5];

  if (NumberOfAirspaces==0) return;

  sNameFilter[0] =_T('\0');
  AirspaceSelectInfo = (AirspaceSelectInfo_t*)
    malloc(sizeof(AirspaceSelectInfo_t) * NumberOfAirspaces);

  if (AirspaceSelectInfo==NULL) {
	OutOfMemory(_T(__FILE__),__LINE__);
	return;
  }

  StrIndex = (int*)malloc(sizeof(int)*(NumberOfAirspaces+1));
  if (StrIndex==NULL) {
        OutOfMemory(_T(__FILE__),__LINE__);

        return;
  }

  int index=0;
  double bearing;
  double distance;
  CAirspaceList Airspaces = CAirspaceManager::Instance().GetAllAirspaces();
  CAirspaceList::const_iterator it;
  for (it=Airspaces.begin(); it != Airspaces.end(); ++it) {
    AirspaceSelectInfo[index].airspace = *it;

	distance = DISTANCEMODIFY * (*it)->Range(Longitude, Latitude, bearing);
	if (distance<0) distance=0;
    AirspaceSelectInfo[index].Distance = distance;
	AirspaceSelectInfo[index].Direction = bearing;

    LK_tcsncpy(sTmp, (*it)->Name(), 4);
    CharUpper(sTmp);

    AirspaceSelectInfo[index].FourChars =
                    (((unsigned)sTmp[0] & 0xff) << 24)
                  + (((unsigned)sTmp[1] & 0xff) << 16)
                  + (((unsigned)sTmp[2] & 0xff) << 8)
                  + (((unsigned)sTmp[3] & 0xff) );

    AirspaceSelectInfo[index].Type = (*it)->Type();

    index++;
  }

  qsort(AirspaceSelectInfo, UpLimit,
      sizeof(AirspaceSelectInfo_t), AirspaceNameCompare);

}
示例#3
0
bool MapWindow::Event_NearestWaypointDetails(double lon, double lat) {

    double Dist;
    unsigned int i;
    const double range = zoom.RealScale()*500;  
    double dyn_range = std::max(5000.0, range*3.5);

    //StartupStore(_T("RANGE=%f\n"),dyn_range);
    LKSound(TEXT("LK_BELL.WAV"));

start_search:

#ifdef BUTTONS_MS
    LockFlightData();
    DistanceBearing(lat,lon, GPS_INFO.Latitude,GPS_INFO.Longitude, &Dist, NULL);
    UnlockFlightData();

    if(Dist < dyn_range) {
	#ifdef OWN_POS_MS
  	dlgAddMultiSelectListItem(NULL,0, IM_OWN_POS, Dist);
	#endif
	#ifdef ORACLE_MS
  	dlgAddMultiSelectListItem(NULL,0, IM_ORACLE, Dist);
	#endif
	#ifdef TEAM_CODE_MS
  	dlgAddMultiSelectListItem(NULL,0, IM_TEAM, Dist);
	#endif
    }
#endif	// BUTTONS_MS


    for(size_t i=NUMRESWP;i<WayPointList.size();++i) {    // Consider only valid markers
        if ((WayPointCalc[i].WpType==WPT_AIRPORT)|| (WayPointCalc[i].WpType==WPT_OUTLANDING)) {
            DistanceBearing(lat,lon, WayPointList[i].Latitude, WayPointList[i].Longitude, &Dist, NULL);
            if(Dist < dyn_range) {
    	        dlgAddMultiSelectListItem(NULL,i, IM_WAYPOINT, Dist);
            }
        }
    }

#ifdef FLARM_MS
    if((MapWindow::mode.Is(MapWindow::Mode::MODE_PAN) || MapWindow::mode.Is(MapWindow::Mode::MODE_TARGET_PAN))) {
        LastDoTraffic=0;
        DoTraffic(&DrawInfo,&DerivedDrawInfo);
        for (unsigned i=0; i<FLARM_MAX_TRAFFIC; ++i) {
	    if (LKTraffic[i].Status != LKT_EMPTY) {
                DistanceBearing(lat,lon, LKTraffic[i].Latitude, LKTraffic[i].Longitude, &Dist, NULL);
                if(Dist < range) {
    	            dlgAddMultiSelectListItem((long*)&LKTraffic[i],i, IM_FLARM, Dist);
                }
            }
        }
    }
#endif

    int  HorDist=0, Bearing=0, VertDist=0; 
    CAirspaceList reslist = CAirspaceManager::Instance().GetNearAirspacesAtPoint(lon, lat, (int)(dyn_range/2));

    for (CAirspaceList::const_iterator it = reslist.begin(); it != reslist.end(); ++it) {
        LKASSERT((*it));
        (*it)->CalculateDistance(&HorDist, &Bearing, &VertDist,lon, lat);
        dlgAddMultiSelectListItem((long*) (*it),0, IM_AIRSPACE, HorDist);
    }


    for(i=1;i<WayPointList.size();i++) {    // Consider only valid markers
        if ((WayPointCalc[i].WpType != WPT_AIRPORT)|| (WayPointCalc[i].WpType != WPT_OUTLANDING)) {
            DistanceBearing(lat,lon, WayPointList[i].Latitude, WayPointList[i].Longitude, &Dist, NULL);
            if(Dist < (dyn_range)) {
    	        dlgAddMultiSelectListItem(NULL,i, IM_WAYPOINT, Dist);
            }
        }
    }


    // TASK MULTISELECT
    int SecType= DAe;
    double SecRadius =0;
    double Bear=0;
    bool Angleinside = false;

    LockTaskData();
    for(i=0; ValidTaskPoint(i); i++) {
        LKASSERT(Task[i].Index <=(int)WayPointList.size());
        DistanceBearing(lat,lon,
            WayPointList[Task[i].Index].Latitude,
            WayPointList[Task[i].Index].Longitude, &Dist, &Bear);

        GetTaskSectorParameter(i, &SecType, &SecRadius);

        Angleinside = true;
        if( SecRadius < (dyn_range)) SecRadius =dyn_range;

        if((Dist < SecRadius) && Angleinside) {
  	    dlgAddMultiSelectListItem(NULL,i, IM_TASK_PT, Dist);
        }
    }
    UnlockTaskData();

    #if (WINDOWSPC>0)
    if (EnableSoundModes) Poco::Thread::sleep(1000); // let the sound be heard in sequence
    #endif
    if(dlgGetNoElements() ==0) { 
        if(dyn_range < 120000) {
            dyn_range *=2;
            goto start_search;
        } else {
            DoStatusMessage(gettext(TEXT("_@M2248_")));  // _@M2248_  "No Near Object found!"
        }
    } else {
        LKSound(TEXT("LK_GREEN.WAV"));
        dlgMultiSelectListShowModal();
        if(ValidTaskPoint(PanTaskEdit)) {
            MapWindow::Event_Pan(1);
        }
        return true;
    }

    return false;
}
示例#4
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;
}