Pixhawk3DWidget.h 7.19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
///*=====================================================================
//
//QGroundControl Open Source Ground Control Station
//
//(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
//
//This file is part of the QGROUNDCONTROL project
//
//    QGROUNDCONTROL is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    QGROUNDCONTROL is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
//
//======================================================================*/

/**
 * @file
 *   @brief Definition of the class Pixhawk3DWidget.
 *
28
 *   @author Lionel Heng <hengli@inf.ethz.ch>
29 30 31 32 33 34 35 36
 *
 */

#ifndef PIXHAWK3DWIDGET_H
#define PIXHAWK3DWIDGET_H

#include <osgText/Text>

37
#include "HUDScaleGeode.h"
38
#include "Imagery.h"
39
#include "Q3DWidget.h"
40 41
#include "SystemContainer.h"
#include "ViewParamWidget.h"
42 43 44 45 46 47

class UASInterface;

/**
 * @brief A 3D View widget which displays vehicle-centric information.
 **/
48
class Pixhawk3DWidget : public QWidget
49 50 51 52 53 54 55 56
{
    Q_OBJECT

public:
    explicit Pixhawk3DWidget(QWidget* parent = 0);
    ~Pixhawk3DWidget();

public slots:
57 58 59
    void activeSystemChanged(UASInterface* uas);
    void systemCreated(UASInterface* uas);
    void localPositionChanged(UASInterface* uas, int component, double x, double y, double z, quint64 time);
60
    void localPositionChanged(UASInterface* uas, double x, double y, double z, quint64 time);
61
    void attitudeChanged(UASInterface* uas, int component, double roll, double pitch, double yaw, quint64 time);
62
    void attitudeChanged(UASInterface* uas, double roll, double pitch, double yaw, quint64 time);
63
    void homePositionChanged(int uasId, double lat, double lon, double alt);
64
    void setpointChanged(int uasId, float x, float y, float z, float yaw);
65 66 67

signals:
    void systemCreatedSignal(UASInterface* uas);
68
    void overlayCreatedSignal(int systemId, const QString& name);
69 70

private slots:
71
    void clearData(void);
72
    void showTerrainParamWindow(void);
73 74
    void showViewParamWindow(void);
    void followCameraChanged(int systemId);
75
    void imageryParamsChanged(void);
76 77
    void recenterActiveCamera(void);
    void modelChanged(int systemId, int index);
78
    void setBirdEyeView(void);
79
    void loadTerrainModel(void);
80

81
    void selectTargetHeading(void);
82
    void selectTarget(void);
83
    void setTarget(void);
84
    void insertWaypoint(void);
85 86
    void moveWaypointPosition(void);
    void moveWaypointHeading(void);
87 88 89 90
    void deleteWaypoint(void);
    void setWaypointAltitude(void);
    void clearAllWaypoints(void);

91 92 93 94
    void moveImagery(void);
    void moveTerrain(void);
    void rotateTerrain(void);

95
    void sizeChanged(int width, int height);
96
    void updateWidget(void);
97

98
protected:
99 100
    void addModels(QVector< osg::ref_ptr<osg::Node> >& models,
                   const QColor& systemColor);
101
    void buildLayout(void);
102

103 104 105 106 107 108 109 110 111
    void keyPressEvent(QKeyEvent* event);
    void keyReleaseEvent(QKeyEvent* event);
    void mousePressEvent(QMouseEvent* event);
    void mouseReleaseEvent(QMouseEvent* event);
    void mouseMoveEvent(QMouseEvent* event);
    void wheelEvent(QWheelEvent* event);

    void showEvent(QShowEvent* event);
    void hideEvent(QHideEvent* event);
112

113 114 115
signals:
    void visibilityChanged(bool visible);

116
private:
117 118 119 120 121
    void initializeSystem(int systemId, const QColor& systemColor);

    void getPose(UASInterface* uas,
                 MAV_FRAME frame,
                 double& x, double& y, double& z,
122
                 double& roll, double& pitch, double& yaw,
123 124 125 126 127 128 129 130 131 132 133 134
                 QString& utmZone) const;
    void getPose(UASInterface* uas,
                 MAV_FRAME frame,
                 double& x, double& y, double& z,
                 double& roll, double& pitch, double& yaw) const;
    void getPosition(UASInterface* uas,
                     MAV_FRAME frame,
                     double& x, double& y, double& z,
                     QString& utmZone) const;
    void getPosition(UASInterface* uas,
                     MAV_FRAME frame,
                     double& x, double& y, double& z) const;
135

136 137
    osg::ref_ptr<osg::Geode> createLocalGrid(void);
    osg::ref_ptr<osg::Geode> createWorldGrid(void);
138
    osg::ref_ptr<osg::Geometry> createTrail(const osg::Vec4& color);
139
    osg::ref_ptr<osg::Geometry> createLink(const QColor& color);
140 141 142
    osg::ref_ptr<Imagery> createImagery(void);
    osg::ref_ptr<osg::Geode> createPointCloud(void);
    osg::ref_ptr<osg::Node> createTarget(const QColor& color);
143

144
    void setupHUD(void);
145
    void resizeHUD(int width, int height);
146

147
    void updateHUD(UASInterface* uas, MAV_FRAME frame);
148 149
    void updateImagery(double originX, double originY,
                       const QString& zone, MAV_FRAME frame);
150 151 152 153 154 155
    void updateTarget(UASInterface* uas, MAV_FRAME frame,
                      double robotX, double robotY, double robotZ,
                      QVector4D& target,
                      osg::ref_ptr<osg::Node>& targetNode);
    void updateTrails(double robotX, double robotY, double robotZ,
                      osg::ref_ptr<osg::Geode>& trailNode,
156
                      osg::ref_ptr<osg::Group>& orientationNode,
157 158 159 160
                      QMap<int, QVector<osg::Vec3d> >& trailMap,
                      QMap<int, int>& trailIndexMap);
    void updateWaypoints(UASInterface* uas, MAV_FRAME frame,
                         osg::ref_ptr<WaypointGroupNode>& waypointGroupNode);
161

162
    int findWaypoint(const QPoint& mousePos);
163
    bool findTarget(int mouseX, int mouseY);
164
    bool findTerrain(const QPoint& mousePos);
165 166
    void showInsertWaypointMenu(const QPoint& cursorPos);
    void showEditWaypointMenu(const QPoint& cursorPos);
167
    void showTerrainMenu(const QPoint& cursorPos);
168

169 170
    const qreal kMessageTimeout; // message timeout in seconds

171 172
    enum Mode {
        DEFAULT_MODE,
173 174
        MOVE_WAYPOINT_POSITION_MODE,
        MOVE_WAYPOINT_HEADING_MODE,
175 176 177 178
        SELECT_TARGET_HEADING_MODE,
        MOVE_TERRAIN_MODE,
        ROTATE_TERRAIN_MODE,
        MOVE_IMAGERY_MODE
179
    };
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    Mode mMode;
    int mSelectedWpIndex;

    int mActiveSystemId;
    UASInterface* mActiveUAS;

    GlobalViewParamsPtr mGlobalViewParams;

    // maps system id to system-specific view parameters
    QMap<int, SystemViewParamsPtr> mSystemViewParamMap;

    // maps system id to system-specific data
    QMap<int, SystemContainer> mSystemContainerMap;

    osg::ref_ptr<osg::Geometry> mHudBackgroundGeometry;
    osg::ref_ptr<Imagery> mImageryNode;
    osg::ref_ptr<HUDScaleGeode> mScaleGeode;
    osg::ref_ptr<osgText::Text> mStatusText;
198
    osg::ref_ptr<osg::Node> mTerrainNode;
199
    osg::ref_ptr<osg::PositionAttitudeTransform> mTerrainPAT;
200
    osg::ref_ptr<osg::Geode> mWorldGridNode;
201

202 203 204 205
    QPoint mCachedMousePos;
    int mFollowCameraId;
    QVector3D mCameraPos;
    bool mInitCameraPos;
206

207 208
    Q3DWidget* m3DWidget;
    ViewParamWidget* mViewParamWidget;
209 210 211
};

#endif // PIXHAWK3DWIDGET_H