1
0
Fork 0

Display AI traffic route in map.

Add some helpers so MapWidget can show the
origin and destination of AIAircraft with a FlightPlan.
This commit is contained in:
James Turner 2013-09-14 12:17:33 +01:00
parent 39c129cee6
commit 38a373ba84
5 changed files with 75 additions and 27 deletions

View file

@ -483,3 +483,13 @@ FGParking* FGAIFlightPlan::getParkingGate()
{
return gate.parking();
}
FGAirportRef FGAIFlightPlan::departureAirport() const
{
return departure;
}
FGAirportRef FGAIFlightPlan::arrivalAirport() const
{
return arrival;
}

View file

@ -168,6 +168,8 @@ public:
void setGate(const ParkingAssignment& pka);
FGParking* getParkingGate();
FGAirportRef departureAirport() const;
FGAirportRef arrivalAirport() const;
private:
FGAIFlightPlan *sid;
typedef std::vector <FGAIWaypoint*> wpt_vector_type;

View file

@ -287,7 +287,7 @@ FGAIManager::attach(FGAIBase *model)
}
int
FGAIManager::getNumAiObjects(void) const
FGAIManager::getNumAiObjects() const
{
return ai_list.size();
}
@ -405,6 +405,17 @@ bool FGAIManager::removeObject(const SGPropertyNode* args)
return false;
}
FGAIBasePtr FGAIManager::getObjectFromProperty(const SGPropertyNode* aProp) const
{
BOOST_FOREACH(FGAIBase* ai, get_ai_list()) {
if (ai->_getProps() == aProp) {
return ai;
}
} // of AI objects iteration
return NULL;
}
bool
FGAIManager::loadScenario( const string &filename )
{

View file

@ -46,16 +46,6 @@ class FGAIManager : public SGSubsystem
{
public:
// A list of pointers to AI objects
typedef std::list <FGAIBasePtr> ai_list_type;
typedef ai_list_type::iterator ai_list_iterator;
typedef ai_list_type::const_iterator ai_list_const_iterator;
const ai_list_type& get_ai_list() const {
return ai_list;
}
FGAIManager();
virtual ~FGAIManager();
@ -79,8 +69,6 @@ public:
inline double get_user_roll() const { return user_roll; }
inline double get_user_agl() const { return user_altitude_agl; }
int getNumAiObjects(void) const;
bool loadScenario( const std::string &filename );
static SGPropertyNode_ptr loadScenarioFile(const std::string& filename);
@ -90,7 +78,26 @@ public:
FGAIBasePtr addObject(const SGPropertyNode* definition);
/**
* @brief given a reference to an /ai/models/<foo>[n] node, return the
* corresponding AIObject implementation, or NULL.
*/
FGAIBasePtr getObjectFromProperty(const SGPropertyNode* aProp) const;
private:
// FGSubmodelMgr is a friend for access to the AI_list
friend class FGSubmodelMgr;
// A list of pointers to AI objects
typedef std::list <FGAIBasePtr> ai_list_type;
typedef ai_list_type::iterator ai_list_iterator;
typedef ai_list_type::const_iterator ai_list_const_iterator;
const ai_list_type& get_ai_list() const {
return ai_list;
}
int getNumAiObjects() const;
void removeDeadItem(FGAIBase* base);
double calcRangeFt(const SGVec3d& aCartPos, FGAIBase* aObject) const;

View file

@ -26,6 +26,8 @@
#include <Main/fg_os.hxx> // fgGetKeyModifiers()
#include <Navaids/routePath.hxx>
#include <Aircraft/FlightHistory.hxx>
#include <AIModel/AIAircraft.hxx>
#include <AIModel/AIFlightPlan.hxx>
const char* RULER_LEGEND_KEY = "ruler-legend";
@ -1561,22 +1563,38 @@ void MapWidget::drawAIAircraft(const SGPropertyNode* model, const SGGeod& pos, d
drawLine(p, project(advance));
}
// try to access the flight-plan of the aircraft. There are several layers
// of potential NULL-ness here, so we have to be defensive at each stage.
std::string originICAO, destinationICAO;
FGAIManager* aiManager = static_cast<FGAIManager*>(globals->get_subsystem("ai-model"));
FGAIBasePtr aircraft = aiManager ? aiManager->getObjectFromProperty(model) : NULL;
if (aircraft) {
FGAIAircraft* p = static_cast<FGAIAircraft*>(aircraft.get());
if (p->GetFlightPlan()) {
originICAO = p->GetFlightPlan()->departureAirport()->ident();
destinationICAO = p->GetFlightPlan()->arrivalAirport()->ident();
}
}
// draw callsign / altitude / speed
char buffer[1024];
::snprintf(buffer, 1024, "%s\n%d'\n%dkts",
model->getStringValue("callsign", "<>"),
static_cast<int>(pos.getElevationFt() / 50.0) * 50,
speedKts);
MapData* d = getOrCreateDataForKey((void*) model);
d->setText(buffer);
d->setLabel(model->getStringValue("callsign", "<>"));
d->setPriority(speedKts > 5 ? 60 : 10); // low priority for parked aircraft
d->setOffset(MapData::VALIGN_CENTER | MapData::HALIGN_LEFT, 10);
d->setAnchor(p);
int altFt50 = static_cast<int>(pos.getElevationFt() / 50.0) * 50;
std::ostringstream ss;
ss << model->getStringValue("callsign", "<>");
if (speedKts > 1) {
ss << "\n" << altFt50 << "' " << speedKts << "kts";
}
if (!originICAO.empty() || ! destinationICAO.empty()) {
ss << "\n" << originICAO << " -> " << destinationICAO;
}
MapData* d = getOrCreateDataForKey((void*) model);
d->setText(ss.str().c_str());
d->setLabel(model->getStringValue("callsign", "<>"));
d->setPriority(speedKts > 5 ? 60 : 10); // low priority for parked aircraft
d->setOffset(MapData::VALIGN_CENTER | MapData::HALIGN_LEFT, 10);
d->setAnchor(p);
}
void MapWidget::drawAIShip(const SGPropertyNode* model, const SGGeod& pos, double hdg)