#include <set>
#include <algorithm> // for sort
#include <queue>
+#include <memory>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
+#include <osg/Math> // for osg::isNaN
+
#include <simgear/timing/timestamp.hxx>
+#include <simgear/props/props.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/exception.hxx>
#include <simgear/math/SGGeometry.hxx>
+#include <simgear/sg_inlines.h>
+#include <simgear/structure/commands.hxx>
-
+#include "Airports/simple.hxx"
+#include "Main/fg_props.hxx"
typedef std::multimap<std::string, FGPositioned*> NamedPositionedIndex;
typedef std::pair<NamedPositionedIndex::const_iterator, NamedPositionedIndex::const_iterator> NamedIndexRange;
return result;
}
+static void validateSGGeod(const SGGeod& geod)
+{
+ if (osg::isNaN(geod.getLatitudeDeg()) ||
+ osg::isNaN(geod.getLongitudeDeg()))
+ {
+ throw sg_range_exception("position is invalid, NaNs");
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
bool
static FGPositioned::List
findAll(const NamedPositionedIndex& aIndex,
- const std::string& aName, FGPositioned::Filter* aFilter)
+ const std::string& aName,
+ FGPositioned::Filter* aFilter,
+ bool aExact)
{
FGPositioned::List result;
if (aName.empty()) {
}
std::string name = boost::to_upper_copy(aName);
- std::string upperBoundId = name;
- upperBoundId[upperBoundId.size()-1]++;
- NamedPositionedIndex::const_iterator upperBound = aIndex.lower_bound(upperBoundId);
+ NamedPositionedIndex::const_iterator upperBound;
+
+ if (aExact) {
+ upperBound = aIndex.upper_bound(name);
+ } else {
+ std::string upperBoundId = name;
+ upperBoundId[upperBoundId.size()-1]++;
+ upperBound = aIndex.lower_bound(upperBoundId);
+ }
+
NamedPositionedIndex::const_iterator it = aIndex.lower_bound(name);
for (; it != upperBound; ++it) {
const NameTypeEntry names[] = {
{"airport", AIRPORT},
{"vor", VOR},
+ {"loc", LOC},
+ {"ils", ILS},
+ {"gs", GS},
{"ndb", NDB},
{"wpt", WAYPOINT},
{"fix", FIX},
{"tacan", TACAN},
{"dme", DME},
+ {"atis", FREQ_ATIS},
+ {"awos", FREQ_AWOS},
+ {"tower", FREQ_TOWER},
+ {"ground", FREQ_GROUND},
+ {"approach", FREQ_APP_DEP},
+ {"departure", FREQ_APP_DEP},
// aliases
+ {"gnd", FREQ_GROUND},
+ {"twr", FREQ_TOWER},
{"waypoint", WAYPOINT},
{"apt", AIRPORT},
{"arpt", AIRPORT},
case WAYPOINT: return "waypoint";
case DME: return "dme";
case TACAN: return "tacan";
+ case FREQ_TOWER: return "tower";
+ case FREQ_ATIS: return "atis";
+ case FREQ_AWOS: return "awos";
+ case FREQ_GROUND: return "ground";
+ case FREQ_CLEARANCE: return "clearance";
+ case FREQ_UNICOM: return "unicom";
+ case FREQ_APP_DEP: return "approach-departure";
default:
return "unknown";
}
FGPositionedRef
FGPositioned::findClosestWithIdent(const std::string& aIdent, const SGGeod& aPos, Filter* aFilter)
{
- FGPositioned::List r(findAll(global_identIndex, aIdent, aFilter));
+ validateSGGeod(aPos);
+
+ FGPositioned::List r(findAll(global_identIndex, aIdent, aFilter, true));
if (r.empty()) {
return FGPositionedRef();
}
FGPositioned::List
FGPositioned::findWithinRange(const SGGeod& aPos, double aRangeNm, Filter* aFilter)
{
+ validateSGGeod(aPos);
+
List result;
Octree::findAllWithinRange(SGVec3d::fromGeod(aPos),
aRangeNm * SG_NM_TO_METER, aFilter, result);
}
FGPositioned::List
-FGPositioned::findAllWithIdent(const std::string& aIdent, Filter* aFilter)
+FGPositioned::findAllWithIdent(const std::string& aIdent, Filter* aFilter, bool aExact)
{
- return findAll(global_identIndex, aIdent, aFilter);
+ return findAll(global_identIndex, aIdent, aFilter, aExact);
}
FGPositioned::List
-FGPositioned::findAllWithName(const std::string& aName, Filter* aFilter)
+FGPositioned::findAllWithName(const std::string& aName, Filter* aFilter, bool aExact)
{
- return findAll(global_nameIndex, aName, aFilter);
+ return findAll(global_nameIndex, aName, aFilter, aExact);
}
FGPositionedRef
FGPositioned::findClosest(const SGGeod& aPos, double aCutoffNm, Filter* aFilter)
{
- List l(findClosestN(aPos, 1, aCutoffNm, aFilter));
- if (l.empty()) {
- return NULL;
- }
-
- assert(l.size() == 1);
- return l.front();
+ validateSGGeod(aPos);
+
+ List l(findClosestN(aPos, 1, aCutoffNm, aFilter));
+ if (l.empty()) {
+ return NULL;
+ }
+
+ assert(l.size() == 1);
+ return l.front();
}
FGPositioned::List
FGPositioned::findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter)
{
+ validateSGGeod(aPos);
+
List result;
Octree::findNearestN(SGVec3d::fromGeod(aPos), aN, aCutoffNm * SG_NM_TO_METER, aFilter, result);
return result;
void
FGPositioned::sortByRange(List& aResult, const SGGeod& aPos)
{
+ validateSGGeod(aPos);
+
SGVec3d cartPos(SGVec3d::fromGeod(aPos));
// computer ordering values
Octree::FindNearestResults r;
aResult[i] = r[i].get();
}
}
+
+FGPositioned::TypeFilter::TypeFilter(Type aTy)
+{
+ addType(aTy);
+}
+
+void FGPositioned::TypeFilter::addType(Type aTy)
+{
+ if (aTy == INVALID) {
+ return;
+
+ }
+
+ types.push_back(aTy);
+}
+
+bool
+FGPositioned::TypeFilter::pass(FGPositioned* aPos) const
+{
+ if (types.empty()) {
+ return true;
+ }
+
+ std::vector<Type>::const_iterator it = types.begin(),
+ end = types.end();
+ for (; it != end; ++it) {
+ return aPos->type() == *it;
+ }
+
+ return false;
+}
+