uavitem.h 7.89 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
/**
******************************************************************************
*
* @file       uavitem.h
* @author     The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief      A graphicsItem representing a WayPoint
* @see        The GNU Public License (GPL) Version 3
* @defgroup   OPMapWidget
* @{
*
*****************************************************************************/
/*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef UAVITEM_H
#define UAVITEM_H

#include <QGraphicsItem>
#include <QPainter>
#include <QLabel>
#include "../internals/pointlatlng.h"
#include "mapgraphicitem.h"
#include "waypointitem.h"
#include <QObject>
#include "uavmapfollowtype.h"
#include "uavtrailtype.h"
#include <QtSvg/QSvgRenderer>
#include "opmapwidget.h"
#include "trailitem.h"
#include "traillineitem.h"
namespace mapcontrol
{
    class WayPointItem;
    class OPMapWidget;
    /**
* @brief A QGraphicsItem representing the UAV
*
* @class UAVItem uavitem.h "mapwidget/uavitem.h"
*/
    class UAVItem:public QObject,public QGraphicsItem
    {
        Q_OBJECT
        Q_INTERFACES(QGraphicsItem)
    public:
                enum { Type = UserType + 2 };
        UAVItem(MapGraphicItem* map,OPMapWidget* parent, QString uavPic=QString::fromUtf8(":/uavs/images/mapquad.png"));
        ~UAVItem();
        /**
        * @brief Sets the UAV position
        *
        * @param position LatLng point
        * @param altitude altitude in meters
        */
        void SetUAVPos(internals::PointLatLng const& position,int const& altitude, QColor const& color=QColor(Qt::red));
        /**
        * @brief Sets the UAV heading
        *
        * @param value heading angle (north=0deg)
        */
        void SetUAVHeading(qreal const& value);
        /**
        * @brief Returns the UAV position
        *
        * @return internals::PointLatLng
        */
        internals::PointLatLng UAVPos()const{return coord;}
        /**
        * @brief Sets the Map follow type
        *
        * @param value can be "none"(map doesnt follow UAV), "CenterMap"(map moves to keep UAV centered) or "CenterAndRotateMap"(map moves and rotates to keep UAV centered and straight)
        */
        void SetMapFollowType(UAVMapFollowType::Types const& value){mapfollowtype=value;}
        /**
        * @brief Sets the trail type
        *
        * @param value can be "NoTrail"(no trail is plotted), "ByTimeElapsed"(a trail point is plotted each TrailTime()) or ByDistance(a trail point is plotted if the distance between the UAV and the last trail point is bigger than TrailDistance())
        */
        void SetTrailType(UAVTrailType::Types const& value);
        /**
        * @brief Returns the map follow method used
        *
        * @return UAVMapFollowType::Types
        */
        UAVMapFollowType::Types GetMapFollowType()const{return mapfollowtype;}
        /**
        * @brief Returns the UAV trail type. It can be plotted by time elapsed or distance
        *
        * @return UAVTrailType::Types
        */
        UAVTrailType::Types GetTrailType()const{return trailtype;}

        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                    QWidget *widget);
        void RefreshPos();
        QRectF boundingRect() const;
        /**
        * @brief Sets the trail time to be used if TrailType is ByTimeElapsed
        *
        * @param seconds the UAV trail time elapsed value. If the trail type is time elapsed
        *        a trail point will be plotted each "value returned" seconds.
        */
        void SetTrailTime(int const& seconds){trailtime=seconds;}
        /**
        * @brief Returns the UAV trail time elapsed value. If the trail type is time elapsed
        *        a trail point will be plotted each "value returned" seconds.
        *
        * @return int
        */
        int TrailTime()const{return trailtime;}
        /**
        * @brief Sets the trail distance to be used if TrailType is ByDistance
        *
        * @param distance the UAV trail plot distance.
        *        If the trail type is ByDistance a trail dot is plotted if
        *        the distance between the current UAV position and the last trail point
        *        is bigger than the returned value
        */
        void SetTrailDistance(int const& distance){traildistance=distance;}
        /**
        * @brief Returns the UAV trail plot distance.
        *        If the trail type is distance diference a trail dot is plotted if
        *        the distance between the current UAV position and the last trail point
        *        is bigger than the returned value
        *
        * @return int
        */
        int TrailDistance()const{return traildistance;}
        /**
        * @brief Returns true if UAV trail is shown
        *
        * @return bool
        */
        bool ShowTrail()const{return showtrail;}
        /**
        * @brief Returns true if UAV trail line is shown
        *
        * @return bool
        */
        bool ShowTrailLine()const{return showtrailline;}
        /**
        * @brief Used to define if the UAV displays a trail
        *
        * @param value
        */
        void SetShowTrail(bool const& value);
        /**
        * @brief Used to define if the UAV displays a trail line
        *
        * @param value
        */
        void SetShowTrailLine(bool const& value);
        /**
        * @brief Deletes all the trail points
        */
        void DeleteTrail()const;
        /**
        * @brief Returns true if the UAV automaticaly sets WP reached value (changing its color)
        *
        * @return bool
        */
        bool AutoSetReached()const{return autosetreached;}
        /**
        * @brief Defines if the UAV can set the WP's "reached" value automaticaly.
        *
        * @param value
        */
        void SetAutoSetReached(bool const& value){autosetreached=value;}
        /**
        * @brief Returns the 3D distance in meters necessary for the UAV to set WP's to "reached"
        *
        * @return double
        */
        double AutoSetDistance()const{return autosetdistance;}
        /**
        * @brief Sets the  the 3D distance in meters necessary for the UAV to set WP's to "reached"
        *
        * @param value
        */
        void SetAutoSetDistance(double const& value){autosetdistance=value;}

        int type() const;

        void SetUavPic(QString UAVPic);

    protected:
        QPixmap pic;

    private:
        MapGraphicItem* map;

        int altitude;
        UAVMapFollowType::Types mapfollowtype;
        UAVTrailType::Types trailtype;
        internals::PointLatLng coord;
        internals::PointLatLng lastcoord;
        core::Point localposition;
        OPMapWidget* mapwidget;
        QGraphicsItemGroup* trail;
        QGraphicsItemGroup * trailLine;
        internals::PointLatLng lasttrailline;
        QTime timer;
        bool showtrail;
        bool showtrailline;
        int trailtime;
        int traildistance;
        bool autosetreached;
        double Distance3D(internals::PointLatLng const& coord, int const& altitude);
        double autosetdistance;
      //  QRectF rect;

    public slots:

    signals:
        void UAVReachedWayPoint(int const& waypointnumber,WayPointItem* waypoint);
        void UAVLeftSafetyBouble(internals::PointLatLng const& position);
    };
}
#endif // UAVITEM_H