- PartialIdentFilter pf(aId, aFilter);
- List matches = spatialGetClosest(aPos, aOffset + 1, 1000.0, &pf);
-
- if ((int) matches.size() <= aOffset) {
- SG_LOG(SG_GENERAL, SG_INFO, "FGPositioned::findClosestWithPartialId, couldn't match enough with prefix:" << aId);
- return NULL; // couldn't find a match within the cutoff distance
- }
-
- return matches[aOffset];
+ string resultPath = arg->getStringValue("results");
+ if (resultPath.empty()) {
+ SG_LOG(SG_GENERAL, SG_WARN, "commandFindByIdent: no results path defined");
+ return false;
+ }
+
+ std::auto_ptr<FGPositioned::Filter> filt(createSearchFilter(arg));
+ SGGeod pos = commandSearchPos(arg);
+ commandClearExisting(arg);
+
+ FGPositioned::List results;
+ bool exact = arg->getBoolValue("exact", true);
+ if (arg->hasChild("name")) {
+ results = FGPositioned::findAllWithName(arg->getStringValue("name"), filt.get(), exact);
+ } else if (arg->hasChild("ident")) {
+ results = FGPositioned::findAllWithIdent(arg->getStringValue("ident"), filt.get(), exact);
+ } else {
+ SG_LOG(SG_GENERAL, SG_WARN, "commandFindByIdent: no search term defined");
+ return false;
+ }
+
+ bool orderByRange = arg->getBoolValue("order-by-distance", true);
+ if (orderByRange) {
+ FGPositioned::sortByRange(results, pos);
+ }
+
+ for (unsigned int i=0; i<results.size(); ++i) {
+ SGPropertyNode* resultsNode = fgGetNode(resultPath.c_str(), i, true);
+ flightgear::PositionedBinding::bind(results[i], resultsNode);
+ }
+
+ return true;
+}
+
+void
+FGPositioned::installCommands()
+{
+ SGCommandMgr::instance()->addCommand("find-nearest", commandFindClosest);
+ SGCommandMgr::instance()->addCommand("find-by-ident", commandFindByIdent);
+}
+
+FGPositioned::TypeFilter::TypeFilter(Type aTy)
+{
+ types.push_back(aTy);
+}
+
+void FGPositioned::TypeFilter::addType(Type aTy)
+{
+ types.push_back(aTy);
+}
+
+bool
+FGPositioned::TypeFilter::pass(FGPositioned* aPos) const
+{
+ std::vector<Type>::const_iterator it = types.begin(),
+ end = types.end();
+ for (; it != end; ++it) {
+ return aPos->type() == *it;
+ }
+
+ return false;