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

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

class PrimaryFlightDisplay : public QWidget
{
    Q_OBJECT
public:
    PrimaryFlightDisplay(int width = 640, int height = 480, QWidget* parent = NULL);
    ~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 22 23 24 25 26 27
    void updatePrimarySpeed(UASInterface* uas, double speed, quint64 timstamp);
    void updateGPSSpeed(UASInterface* uas, double speed, quint64 timstamp);
    void updateClimbRate(UASInterface* uas, double altitude, quint64 timestamp);
    void updatePrimaryAltitude(UASInterface* uas, double altitude, quint64 timestamp);
    void updateGPSAltitude(UASInterface* uas, double altitude, quint64 timestamp);
    void updateNavigationControllerErrors(UASInterface* uas, double altitudeError, double speedError, double xtrackError);

28
    /** @brief Set the currently monitored UAS */
29 30
    //void addUAS(UASInterface* uas);
    void forgetUAS(UASInterface* uas);
31
    void setActiveUAS(UASInterface* uas);
32

33
protected:
dongfang's avatar
dongfang committed
34
    enum Layout {
35
        COMPASS_INTEGRATED,
dongfang's avatar
dongfang committed
36 37 38 39
        COMPASS_SEPARATED               // For a very high container. Feature panels are at bottom.
    };

    enum Style {
40 41 42
        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
43 44
    };

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    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);

    // dongfang: We have no context menu. Viewonly.
    // void contextMenuEvent (QContextMenuEvent* event);

    // dongfang: What is that?
dongfang's avatar
dongfang committed
61
    // dongfang: OK it's for UI interaction. Presently, there is none.
62 63 64 65 66 67
    void createActions();

signals:
    void visibilityChanged(bool visible);

private:
68
    /*
69 70 71 72 73 74 75 76 77 78 79 80 81 82
    enum AltimeterMode {
        PRIMARY_MAIN_GPS_SUB,   // Show the primary alt. on tape and GPS as extra info
        GPS_MAIN                // Show GPS on tape and no extra info
    };

    enum AltimeterFrame {
        ASL,                    // Show ASL altitudes (plane pilots' normal preference)
        RELATIVE_TO_HOME        // Show relative-to-home altitude (copter pilots)
    };

    enum SpeedMode {
        PRIMARY_MAIN_GROUND_SUB,// Show primary speed (often airspeed) on tape and groundspeed as extra
        GROUND_MAIN             // Show groundspeed on tape and no extra info
    };
83
    */
84 85 86 87 88 89

    /*
     * 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();
90
    bool shouldDisplayNavigationData();
91 92 93 94 95 96

    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);
97
    void drawAIGlobalFeatures(QPainter& painter, QRectF mainArea, QRectF paintArea);
98
    void drawAIAirframeFixedFeatures(QPainter& painter, QRectF area);
dongfang's avatar
dongfang committed
99
    void drawPitchScale(QPainter& painter, QRectF area, float intrusion, bool drawNumbersLeft, bool drawNumbersRight);
100
    void drawRollScale(QPainter& painter, QRectF area, bool drawTicks, bool drawNumbers);
dongfang's avatar
dongfang committed
101 102
    void drawAIAttitudeScales(QPainter& painter, QRectF area, float intrusion);
    void drawAICompassDisk(QPainter& painter, QRectF area, float halfspan);
dongfang's avatar
dongfang committed
103 104
    void drawSeparateCompassDisk(QPainter& painter, QRectF area);

105 106
    void drawAltimeter(QPainter& painter, QRectF area, float altitude, float secondaryAltitude, float vv);
    void drawVelocityMeter(QPainter& painter, QRectF area, float speed, float secondarySpeed);
107
    void fillInstrumentBackground(QPainter& painter, QRectF edge);
dongfang's avatar
dongfang committed
108
    void fillInstrumentOpagueBackground(QPainter& painter, QRectF edge);
109 110
    void drawInstrumentBackground(QPainter& painter, QRectF edge);

dongfang's avatar
dongfang committed
111
    /* This information is not currently included. These headers left in as a memo for restoration later.
112 113 114 115
    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
116
    */
117 118 119

    void doPaint();

120 121
    UASInterface* uas;          ///< The uas currently monitored

122
    /*
123 124 125
    AltimeterMode altimeterMode;
    AltimeterFrame altimeterFrame;
    SpeedMode speedMode;
126
    */
127 128 129 130

    bool didReceivePrimaryAltitude;
    bool didReceivePrimarySpeed;

131 132 133 134
    float roll;
    float pitch;
    float heading;

135
    float primaryAltitude;
136 137 138 139
    float GPSAltitude;

    // 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.
140
    // If the MP "set home altitude" button is migrated to here, it must set the UAS home altitude, not a GS-local one.
141 142
    float aboveHomeAltitude;

143
    float primarySpeed;
144
    float groundspeed;
dongfang's avatar
dongfang committed
145
    float verticalVelocity;
146

147 148 149 150 151
    float navigationAltitudeError;
    float navigationSpeedError;
    float navigationCrosstrackError;
    float navigationTargetBearing;

dongfang's avatar
dongfang committed
152
    Layout layout;      // The display layout.
153
    Style style;        // The AI style (tapes translucent or opague)
dongfang's avatar
dongfang committed
154

155
    // TODO: Use stylesheet colors?
dongfang's avatar
dongfang committed
156 157 158 159 160 161 162
    QColor redColor;
    QColor amberColor;
    QColor greenColor;

    qreal lineWidth;
    qreal fineLineWidth;

163
    qreal smallTextSize;
dongfang's avatar
dongfang committed
164 165
    qreal mediumTextSize;
    qreal largeTextSize;
166

dongfang's avatar
dongfang committed
167
    // Globally used stuff only.
168 169
    QPen instrumentEdgePen;
    QBrush instrumentBackground;
dongfang's avatar
dongfang committed
170
    QBrush instrumentOpagueBackground;
171 172 173 174 175 176 177 178

    QFont font;

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

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

179
    static const int updateInterval = 40;   
180 181 182
};

#endif // PRIMARYFLIGHTDISPLAY_H