PrimaryFlightDisplay.h 5.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#ifndef PRIMARYFLIGHTDISPLAY_H
#define PRIMARYFLIGHTDISPLAY_H

#include <QWidget>
#include <QPen>
#include "UASInterface.h"

class PrimaryFlightDisplay : public QWidget
{
    Q_OBJECT
public:
12
    PrimaryFlightDisplay(QWidget* parent = NULL);
13 14
    ~PrimaryFlightDisplay();

15
public slots:
16 17 18 19
    /** @brief Attitude from main autopilot / system state */
    void updateAttitude(UASInterface* uas, double roll, double pitch, double yaw, quint64 timestamp);
    /** @brief Attitude from one specific component / redundant autopilot */
    void updateAttitude(UASInterface* uas, int component, double roll, double pitch, double yaw, quint64 timestamp);
20

21
    void updateSpeed(UASInterface* uas, double _groundSpeed, double _airSpeed, quint64 timestamp);
22
    void updateAltitude(UASInterface* uas, double _altitudeAMSL, double _altitudeWGS84, double _altitudeRelative, double _climbRate, quint64 timestamp);
23
    void updateNavigationControllerErrors(UASInterface* uas, double altitudeError, double speedError, double xtrackError);
24
    void UpdateNavigationControllerData(UASInterface *uas, float navRoll, float navPitch, float navBearing, float targetBearing, float targetDistance);
25

26
    /** @brief Set the currently monitored UAS */
27
    void forgetUAS(UASInterface* uas);
28
    void setActiveUAS(UASInterface* uas);
29

30 31
    void checkUpdate();

32
protected:
33 34 35 36

    bool _valuesChanged;
    quint64 _valuesLastPainted;

dongfang's avatar
dongfang committed
37
    enum Layout {
38
        COMPASS_INTEGRATED,
dongfang's avatar
dongfang committed
39 40 41 42
        COMPASS_SEPARATED               // For a very high container. Feature panels are at bottom.
    };

    enum Style {
43 44 45
        NO_OVERLAYS,                    // Hzon not visible through tapes nor through feature panels. Frames with margins between.
        OVERLAY_HORIZONTAL,             // Hzon visible through tapes and (frameless) feature panels.
        OVERLAY_HSI                     // Hzon visible through everything except bottom feature panels.
dongfang's avatar
dongfang committed
46 47
    };

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    void paintEvent(QPaintEvent *event);
    void resizeEvent(QResizeEvent *e);

    // from HUD.h:

    /** @brief Preferred Size */
    QSize sizeHint() const;
    /** @brief Start updating widget */
    void showEvent(QShowEvent* event);
    /** @brief Stop updating widget */
    void hideEvent(QHideEvent* event);

signals:
    void visibilityChanged(bool visible);

private:
64 65 66 67 68
    /*
     * There are at least these differences between airplane and copter PDF view:
     * - Airplane show absolute altutude in altimeter, copter shows relative to home
     */
    bool isAirplane();
69
    bool shouldDisplayNavigationData();
70 71 72 73 74 75

    void drawTextCenter(QPainter& painter, QString text, float fontSize, float x, float y);
    void drawTextLeftCenter(QPainter& painter, QString text, float fontSize, float x, float y);
    void drawTextRightCenter(QPainter& painter, QString text, float fontSize, float x, float y);
    void drawTextCenterBottom(QPainter& painter, QString text, float fontSize, float x, float y);
    void drawTextCenterTop(QPainter& painter, QString text, float fontSize, float x, float y);
76
    void drawAIGlobalFeatures(QPainter& painter, QRectF mainArea, QRectF paintArea);
77
    void drawAIAirframeFixedFeatures(QPainter& painter, QRectF area);
dongfang's avatar
dongfang committed
78
    void drawPitchScale(QPainter& painter, QRectF area, float intrusion, bool drawNumbersLeft, bool drawNumbersRight);
79
    void drawRollScale(QPainter& painter, QRectF area, bool drawTicks, bool drawNumbers);
dongfang's avatar
dongfang committed
80 81
    void drawAIAttitudeScales(QPainter& painter, QRectF area, float intrusion);
    void drawAICompassDisk(QPainter& painter, QRectF area, float halfspan);
dongfang's avatar
dongfang committed
82 83
    void drawSeparateCompassDisk(QPainter& painter, QRectF area);

84 85
    void drawAltimeter(QPainter& painter, QRectF area);
    void drawVelocityMeter(QPainter& painter, QRectF area);
86
    void fillInstrumentBackground(QPainter& painter, QRectF edge);
dongfang's avatar
dongfang committed
87
    void fillInstrumentOpagueBackground(QPainter& painter, QRectF edge);
88 89
    void drawInstrumentBackground(QPainter& painter, QRectF edge);

dongfang's avatar
dongfang committed
90
    /* This information is not currently included. These headers left in as a memo for restoration later.
91 92 93 94
    void drawLinkStatsPanel(QPainter& painter, QRectF area);
    void drawSysStatsPanel(QPainter& painter, QRectF area);
    void drawMissionStatsPanel(QPainter& painter, QRectF area);
    void drawSensorsStatsPanel(QPainter& painter, QRectF area);
dongfang's avatar
dongfang committed
95
    */
96 97 98

    void doPaint();

99 100
    UASInterface* uas;          ///< The uas currently monitored

101
    bool didReceiveSpeed;
102

103 104 105 106
    float roll;
    float pitch;
    float heading;

107
    float altitudeAMSL;
108
    float altitudeWGS84;
109
    float altitudeRelative;
110 111 112

    // APM: GPS and baro mix above home (GPS) altitude. This value comes from the GLOBAL_POSITION_INT message.
    // Do !!!NOT!!! ever do altitude calculations at the ground station. There are enough pitfalls already.
113
    // If the MP "set home altitude" button is migrated to here, it must set the UAS home altitude, not a GS-local one.
114 115
    float aboveHomeAltitude;

116 117 118
    float groundSpeed;
    float airSpeed;
    float climbRate;
119

120 121 122 123 124
    float navigationAltitudeError;
    float navigationSpeedError;
    float navigationCrosstrackError;
    float navigationTargetBearing;

dongfang's avatar
dongfang committed
125
    Layout layout;      // The display layout.
126
    Style style;        // The AI style (tapes translucent or opague)
dongfang's avatar
dongfang committed
127

128
    // TODO: Use stylesheet colors?
dongfang's avatar
dongfang committed
129 130 131 132 133 134 135
    QColor redColor;
    QColor amberColor;
    QColor greenColor;

    qreal lineWidth;
    qreal fineLineWidth;

136
    qreal smallTextSize;
dongfang's avatar
dongfang committed
137 138
    qreal mediumTextSize;
    qreal largeTextSize;
139

dongfang's avatar
dongfang committed
140
    // Globally used stuff only.
141 142
    QPen instrumentEdgePen;
    QBrush instrumentBackground;
dongfang's avatar
dongfang committed
143
    QBrush instrumentOpagueBackground;
144 145 146 147 148 149 150 151

    QFont font;

    QTimer* refreshTimer;       ///< The main timer, controls the update rate

    static const int tickValues[];
    static const QString compassWindNames[];

Lorenz Meier's avatar
Lorenz Meier committed
152
    static const int updateInterval = 50;
153 154 155
};

#endif // PRIMARYFLIGHTDISPLAY_H