#include <plib/puAux.h>
-#include <simgear/route/waypoint.hxx>
#include <simgear/structure/callback.hxx>
#include <simgear/sg_inlines.h>
#include <Navaids/positioned.hxx>
#include <Autopilot/route_mgr.hxx>
+// select if the widget grabs keys necessary to fly aircraft from the keyboard,
+// or not. See http://code.google.com/p/flightgear-bugs/issues/detail?id=338
+// for discussion about why / what is going on.
+#define AVOID_FLIGHT_KEYS 1
+
using namespace flightgear;
enum {
static const double BLINK_TIME = 0.3;
static const int DRAG_START_DISTANCE_PX = 5;
-class RouteManagerWaypointModel :
+class FlightPlanWaypointModel :
public WaypointList::Model,
public SGPropertyChangeListener
{
public:
- RouteManagerWaypointModel()
- {
- _rm = static_cast<FGRouteMgr*>(globals->get_subsystem("route-manager"));
-
+ FlightPlanWaypointModel(flightgear::FlightPlan* fp) :
+ _fp(fp)
+ {
SGPropertyNode* routeEdited = fgGetNode("/autopilot/route-manager/signals/edited", true);
+ SGPropertyNode* flightplanChanged = fgGetNode("/autopilot/route-manager/signals/flightplan-changed", true);
routeEdited->addChangeListener(this);
+ flightplanChanged->addChangeListener(this);
}
- virtual ~RouteManagerWaypointModel()
+ ~FlightPlanWaypointModel()
{
SGPropertyNode* routeEdited = fgGetNode("/autopilot/route-manager/signals/edited", true);
+ SGPropertyNode* flightplanChanged = fgGetNode("/autopilot/route-manager/signals/flightplan-changed", true);
routeEdited->removeChangeListener(this);
+ flightplanChanged->removeChangeListener(this);
}
// implement WaypointList::Model
virtual unsigned int numWaypoints() const
{
- return _rm->numWaypts();
+ return _fp->numLegs();
}
virtual int currentWaypoint() const
{
- return _rm->currentIndex();
+ return _fp->currentIndex();
}
virtual flightgear::Waypt* waypointAt(unsigned int index) const
return NULL;
}
- return _rm->wayptAtIndex(index);
+ return _fp->legAtIndex(index)->waypoint();
}
virtual void deleteAt(unsigned int index)
{
- _rm->removeWayptAtIndex(index);
+ _fp->deleteIndex(index);
}
virtual void moveWaypointToIndex(unsigned int srcIndex, unsigned int destIndex)
--destIndex;
}
- WayptRef w(_rm->removeWayptAtIndex(srcIndex));
- SG_LOG(SG_GENERAL, SG_INFO, "wpt:" << w->ident());
- _rm->insertWayptAtIndex(w, destIndex);
+ int currentWpIndex = currentWaypoint();
+
+ WayptRef w = _fp->legAtIndex(srcIndex)->waypoint();
+ _fp->deleteIndex(srcIndex);
+ _fp->insertWayptAtIndex(w, destIndex);
+
+ if ((signed int) srcIndex == currentWpIndex) {
+ // current waypoint was moved
+ _fp->setCurrentIndex(destIndex);
+ }
}
virtual void setUpdateCallback(SGCallback* cb)
// implement SGPropertyChangeListener
void valueChanged(SGPropertyNode *prop)
{
- if (_cb) {
- (*_cb)();
+ if (prop->getNameString() == "edited") {
+ if (_cb) {
+ (*_cb)();
+ }
+ }
+
+ if (prop->getNameString() == "flightplan-changed") {
+ _fp =
+ static_cast<FGRouteMgr*>(globals->get_subsystem("route-manager"))->flightPlan();
}
}
private:
- FGRouteMgr* _rm;
+ flightgear::FlightPlan* _fp;
SGCallback* _cb;
};
{
// pretend to be a list, so fgPopup doesn't mess with our mouse events
type |= PUCLASS_LIST;
- setModel(new RouteManagerWaypointModel());
+ flightgear::FlightPlan* fp =
+ static_cast<FGRouteMgr*>(globals->get_subsystem("route-manager"))->flightPlan();
+ setModel(new FlightPlanWaypointModel(fp));
setSize(width, height);
setValue(-1);
if (wp->flag(WPT_MISS)) {
drawBox = true;
puSetColor(col, 1.0, 0.0, 0.0, 0.3); // red
- } else if (wp->flag(WPT_ARRIVAL)) {
+ } else if (wp->flag(WPT_ARRIVAL) || wp->flag(WPT_DEPARTURE)) {
drawBox = true;
puSetColor(col, 0.0, 0.0, 0.0, 0.3);
- } else if (wp->flag(WPT_DEPARTURE)) {
+ } else if (wp->flag(WPT_APPROACH)) {
drawBox = true;
- puSetColor(col, 0.0, 0.0, 0.0, 0.3);
+ puSetColor(col, 0.0, 0.0, 0.1, 0.3);
}
if (isDragSource) {
} // of valid wp altitude
x += 60 + PUSTR_LGAP;
- if (wp->speedRestriction() != RESTRICT_NONE) {
+ if (wp->speedRestriction() == SPEED_RESTRICT_MACH) {
+ count = ::snprintf(buffer, 126, "%03.2fM", wp->speedMach());
+ f->drawString(buffer, x, yy);
+ } else if (wp->speedRestriction() != RESTRICT_NONE) {
count = ::snprintf(buffer, 126, "%dKts", (int) wp->speedKts());
f->drawString(buffer, x, yy);
}
if ((updown == PU_UP) || !isVisible () || !isActive () || (window != puGetWindow())) {
return FALSE ;
}
+
+#ifdef AVOID_FLIGHT_KEYS
+ return FALSE;
+#endif
switch (key)
{