]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/positioned.cxx
MapWidget: make use of the new POI system and display cities on the map.
[flightgear.git] / src / Navaids / positioned.cxx
index 18bb22f62b6e6717e494b5efe1680d5930dc3e01..450c755d94195b229424445fff6c78f19c6eb91d 100644 (file)
@@ -73,10 +73,25 @@ FGPositioned::~FGPositioned()
 FGPositioned*
 FGPositioned::createUserWaypoint(const std::string& aIdent, const SGGeod& aPos)
 {
-  PositionedID id = NavDataCache::instance()->createUserWaypoint(aIdent, aPos);
-  return NavDataCache::instance()->loadById(id);
+  NavDataCache* cache = NavDataCache::instance();
+  TypeFilter filter(WAYPOINT);
+  FGPositioned::List existing = cache->findAllWithIdent(aIdent, &filter, true);
+  if (!existing.empty()) {
+    SG_LOG(SG_NAVAID, SG_WARN, "attempt to insert duplicate WAYPOINT:" << aIdent);
+    return existing.front().ptr();
+  }
+  
+  PositionedID id = cache->createPOI(WAYPOINT, aIdent, aPos);
+  return cache->loadById(id);
+}
+
+void FGPositioned::deleteUserWaypoint(const std::string& aIdent)
+{
+  NavDataCache* cache = NavDataCache::instance();
+  cache->removePOI(WAYPOINT, aIdent);
 }
 
+
 const SGVec3d&
 FGPositioned::cart() const
 {
@@ -111,12 +126,20 @@ FGPositioned::Type FGPositioned::typeFromName(const std::string& aName)
     {"ground", FREQ_GROUND},
     {"approach", FREQ_APP_DEP},
     {"departure", FREQ_APP_DEP},
+    {"runway", RUNWAY},
+    {"helipad", HELIPAD},
+    {"country", COUNTRY},
+    {"city", CITY},
+    {"town", TOWN},
+    {"village", VILLAGE},
+      
   // aliases
     {"gnd", FREQ_GROUND},
     {"twr", FREQ_TOWER},
     {"waypoint", WAYPOINT},
     {"apt", AIRPORT},
     {"arpt", AIRPORT},
+    {"rwy", RUNWAY},
     {"any", INVALID},
     {"all", INVALID},
     
@@ -131,7 +154,7 @@ FGPositioned::Type FGPositioned::typeFromName(const std::string& aName)
     }
   }
   
-  SG_LOG(SG_GENERAL, SG_WARN, "FGPositioned::typeFromName: couldn't match:" << aName);
+  SG_LOG(SG_NAVAID, SG_WARN, "FGPositioned::typeFromName: couldn't match:" << aName);
   return INVALID;
 }
 
@@ -139,6 +162,7 @@ const char* FGPositioned::nameForType(Type aTy)
 {
  switch (aTy) {
  case RUNWAY: return "runway";
+ case HELIPAD: return "helipad";
  case TAXIWAY: return "taxiway";
  case PAVEMENT: return "pavement";
  case PARKING: return "parking stand";
@@ -165,6 +189,10 @@ const char* FGPositioned::nameForType(Type aTy)
  case FREQ_UNICOM: return "unicom";
  case FREQ_APP_DEP: return "approach-departure";
  case TAXI_NODE: return "taxi-node";
+ case COUNTRY: return "country";
+ case CITY: return "city";
+ case TOWN: return "town";
+ case VILLAGE: return "village";
  default:
   return "unknown";
  }
@@ -202,7 +230,20 @@ FGPositioned::findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilt
 
   List result;
   Octree::findAllWithinRange(SGVec3d::fromGeod(aPos), 
-    aRangeNm * SG_NM_TO_METER, aFilter, result);
+    aRangeNm * SG_NM_TO_METER, aFilter, result, 0xffffff);
+  return result;
+}
+
+FGPositioned::List
+FGPositioned::findWithinRangePartial(const SGGeod& aPos, double aRangeNm, Filter* aFilter, bool& aPartial)
+{
+  validateSGGeod(aPos);
+  
+  int limitMsec = 32;
+  List result;
+  aPartial = Octree::findAllWithinRange(SGVec3d::fromGeod(aPos),
+                             aRangeNm * SG_NM_TO_METER, aFilter, result,
+                                        limitMsec);
   return result;
 }
 
@@ -238,10 +279,23 @@ FGPositioned::findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm
   validateSGGeod(aPos);
   
   List result;
-  Octree::findNearestN(SGVec3d::fromGeod(aPos), aN, aCutoffNm * SG_NM_TO_METER, aFilter, result);
+  int limitMsec = 0xffff;
+  Octree::findNearestN(SGVec3d::fromGeod(aPos), aN, aCutoffNm * SG_NM_TO_METER, aFilter, result, limitMsec);
   return result;
 }
+
+FGPositioned::List
+FGPositioned::findClosestNPartial(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter, bool &aPartial)
+{
+    validateSGGeod(aPos);
+    
+    List result;
+    int limitMsec = 32;
+    aPartial = Octree::findNearestN(SGVec3d::fromGeod(aPos), aN, aCutoffNm * SG_NM_TO_METER, aFilter, result,
+                        limitMsec);
+    return result;
+}
+
 void
 FGPositioned::sortByRange(List& aResult, const SGGeod& aPos)
 {