SlugsPadCameraControl.cpp 4.87 KB
Newer Older
1 2 3 4
#include "SlugsPadCameraControl.h"
#include "ui_SlugsPadCameraControl.h"

SlugsPadCameraControl::SlugsPadCameraControl(QWidget *parent) :
5
    QWidget(parent),
6
    ui(new Ui::SlugsPadCameraControl),
7
    dragging(0)
8 9 10 11 12 13 14 15 16 17 18 19 20 21
{
    ui->setupUi(this);
    x1= 0;
    y1 = 0;
    motion = NONE;
}

SlugsPadCameraControl::~SlugsPadCameraControl()
{
    delete ui;
}

void SlugsPadCameraControl::activeUasSet(UASInterface *uas)
{
22 23
    if(uas) {
        this->activeUAS= uas;
24 25 26 27 28 29 30
    }
}

void SlugsPadCameraControl::mouseMoveEvent(QMouseEvent *event)
{
    Q_UNUSED(event);

31
    if(dragging) {
32 33 34 35 36 37
        getDeltaPositionPad(event->x(), event->y());
    }
}

void SlugsPadCameraControl::mousePressEvent(QMouseEvent *event)
{
38
    if(!dragging) {
39 40 41 42 43 44 45 46
        dragging = true;
        x1 = event->x();
        y1 = event->y();
    }
}

void SlugsPadCameraControl::mouseReleaseEvent(QMouseEvent *event)
{
47
    if(dragging) {
48 49 50 51 52 53 54 55 56 57 58 59
        dragging = false;
        getDeltaPositionPad(event->x(), event->y());

        xFin = event->x();
        yFin = event->y();
    }
}

void SlugsPadCameraControl::getDeltaPositionPad(int x2, int y2)
{
    QPointF localMeasures = ObtenerMarcacionDistanciaPixel(y1,x1,y2,x2);

60
    if(localMeasures.y()>10) {
61 62 63 64 65 66
        QString dir = "nd";

        double bearing = localMeasures.x();

        bearing = bearing +90;

67
        if(bearing>= 360) {
68 69 70
            bearing = bearing - 360;
        }

71
        if(bearing >337.5 || bearing <=22.5) {
72 73 74
            motion= UP;
            movePad = QPoint(0, 1);
            dir = "UP";
75
        } else if(bearing >22.5 && bearing <=67.5) {
76 77 78
            motion= RIGHT_UP;
            movePad = QPoint(1, 1);
            dir = "RIGHT UP";
79
        } else if(bearing >67.5 && bearing <=112.5) {
80 81 82
            motion= RIGHT;
            movePad = QPoint(1, 0);
            dir = "RIGHT";
83
        } else if(bearing >112.5 && bearing <= 157.5) {
84 85 86
            motion= RIGHT_DOWN;
            movePad = QPoint(1, -1);
            dir = "RIGHT DOWN";
87
        } else if(bearing >157.5 && bearing <=202.5) {
88 89 90
            motion= DOWN;
            movePad = QPoint(0, -1);
            dir = "DOWN";
91
        } else if(bearing >202.5 && bearing <=247.5) {
92 93 94
            motion= LEFT_DOWN;
            movePad = QPoint(-1, -1);
            dir = "LEFT DOWN";
95
        } else if(bearing >247.5 && bearing <=292.5) {
96 97 98
            motion= LEFT;
            movePad = QPoint(-1, 0);
            dir = "LEFT";
99
        } else if(bearing >292.5 && bearing <=337.5) {
100 101 102 103 104 105 106 107 108 109
            motion= LEFT_UP;
            movePad = QPoint(-1, 1);
            dir = "LEFT UP";
        }

        emit changeMotionCamera(motion);

        ui->lbPixel->setText(QString::number(localMeasures.y()));
        ui->lbDirection->setText(dir);

110
        //qDebug()<<dir;
111 112 113 114 115
        update();
    }
}

QPointF SlugsPadCameraControl::ObtenerMarcacionDistanciaPixel(double lon1, double lat1,
116
        double lon2, double lat2)
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
{
    double cateto_opuesto,cateto_adyacente, hipotenusa;//, distancia;
    double marcacion = 0.0;

    //latitude and longitude first point

    if(lat1<0) lat1= lat1*(-1);
    if(lat2<0) lat2= lat2*(-1);
    if(lon1<0) lon1= lon1*(-1);
    if(lon2<0) lon1= lon1*(-1);

    cateto_opuesto = abs((lat1-lat2));
    cateto_adyacente = abs((lon1-lon2));

    hipotenusa = sqrt(pow(cateto_opuesto,2) + pow(cateto_adyacente,2));
    //distancia = hipotenusa*60.0;


    if ((lat1 < lat2) && (lon1 > lon2)) //primer cuadrante
        marcacion = 360 -((asin(cateto_adyacente/hipotenusa))/ 0.017453292);
    else if ((lat1 < lat2) && (lon1 < lon2)) //segundo cuadrante
        marcacion = (asin(cateto_adyacente/hipotenusa))/ 0.017453292;
    else if((lat1 > lat2) && (lon1 < lon2)) //tercer cuadrante
        marcacion = 180 -((asin(cateto_adyacente/hipotenusa))/ 0.017453292);
    else if((lat1 > lat2) && (lon1 > lon2)) //cuarto cuadrante
        marcacion = 180 +((asin(cateto_adyacente/hipotenusa))/ 0.017453292);
    else if((lat1 < lat2) && (lon1 == lon2)) //360
        marcacion = 360;
    else if((lat1 == lat2) && (lon1 > lon2)) //270
        marcacion = 270;
    else if((lat1 > lat2) && (lon1 == lon2)) //180
        marcacion = 180;
    else if((lat1 == lat2) && (lon1 < lon2)) //90
        marcacion =90;
    else if((lat1 == lat2) && (lon1 == lon2)) //0
        marcacion = 0.0;

    return QPointF(marcacion,hipotenusa);// distancia);
}

void SlugsPadCameraControl::keyPressEvent(QKeyEvent *event)
{
159 160 161
    switch (event->key()) {
    case Qt::Key_Left:
        emit changeMotionCamera(LEFT);
162 163
        break;

164 165
    case Qt::Key_Right:
        emit changeMotionCamera(RIGHT);
166 167
        break;

168 169
    case Qt::Key_Down:
        emit changeMotionCamera(DOWN);
170 171
        break;

172 173
    case Qt::Key_Up:
        emit changeMotionCamera(UP);
174 175
        break;

176
    default:
177 178 179
        QWidget::keyPressEvent(event);
    }
}