SlugsPadCameraControl.cpp 7.34 KB
Newer Older
1 2
#include "SlugsPadCameraControl.h"
#include "ui_SlugsPadCameraControl.h"
3 4 5 6
#include <QMouseEvent>
#include <QDebug>
#include <qmath.h>
#include <QPainter>
7 8

SlugsPadCameraControl::SlugsPadCameraControl(QWidget *parent) :
9 10 11
   QWidget(parent), //QGraphicsView(parent),
    ui(new Ui::SlugsPadCameraControl),
     dragging(0)
12 13
{
    ui->setupUi(this);
14 15
    x1= 0;
    y1 = 0;
16 17 18
    bearingPad = 0;
    distancePad = 0;
    directionPad = "no";
19

20 21 22 23 24 25
}

SlugsPadCameraControl::~SlugsPadCameraControl()
{
    delete ui;
}
26 27 28

void SlugsPadCameraControl::mouseMoveEvent(QMouseEvent *event)
{
29
  Q_UNUSED(event);
30
    //emit mouseMoveCoord(event->x(),event->y());
31

32 33 34
    if(dragging)
    {

tecnosapiens's avatar
tecnosapiens committed
35 36
      // getDeltaPositionPad(event->x(), event->y());

37 38
    }

39 40 41 42 43

}

void SlugsPadCameraControl::mousePressEvent(QMouseEvent *event)
{
44 45
    //emit mousePressCoord(event->x(),event->y());
    dragging = true;
46 47 48 49 50 51 52
    x1 = event->x();
    y1 = event->y();

}

void SlugsPadCameraControl::mouseReleaseEvent(QMouseEvent *event)
{
53 54
     dragging = false;
    //emit mouseReleaseCoord(event->x(),event->y());
tecnosapiens's avatar
tecnosapiens committed
55
    getDeltaPositionPad(event->x(), event->y());
56

57 58 59
     xFin = event->x();
     yFin = event->y();

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

}

void SlugsPadCameraControl::paintEvent(QPaintEvent *pe)
{
    Q_UNUSED(pe);
    QPainter painter(this);
    painter.setPen(Qt::blue);
    painter.setFont(QFont("Arial", 30));

//    QRectF rectangle(tL.x(), tL.y(), ui->padCamContro_frame->width(), ui->padCamContro_frame->height());
//     int startAngle = 30 * 16;
//     int spanAngle = 120 * 16;

    painter.drawLine(QPoint(ui->frame->width()/2,ui->frame->geometry().topLeft().y()),
                     QPoint(ui->frame->width()/2,ui->frame->geometry().bottomRight().y()));

    painter.drawLine(QPoint(ui->frame->geometry().topLeft().x(),ui->frame->height()/2),
                     QPoint(ui->frame->geometry().bottomRight().x(),ui->frame->height()/2));

80 81 82 83 84 85 86
    painter.setPen(Qt::white);

    //QPointF coordTemp = getPointBy_BearingDistance(ui->frame->width()/2,ui->frame->height()/2,bearingPad,distancePad);

    painter.drawLine(QPoint(ui->frame->width()/2,ui->frame->height()/2),
                     QPoint(xFin,yFin));

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

   // painter.drawLine(QPoint());
    //painter.drawLines(padLines);


    // painter.drawPie(rectangle, startAngle, spanAngle);

    //painter.drawText(rect(), Qt::AlignCenter, "Qt");
}

void SlugsPadCameraControl::getDeltaPositionPad(int x2, int y2)
{

    QString dir = "nd";
    QPointF localMeasures = ObtenerMarcacionDistanciaPixel(y1,x1,y2,x2);

    double bearing = localMeasures.x();
    double dist = getDistPixel(y1,x1,y2,x2);

tecnosapiens's avatar
tecnosapiens committed
106 107 108 109
    // this only convert real bearing to frame widget bearing
    bearing = bearing +90;
    if(bearing>= 360) bearing = bearing - 360;

110 111 112 113 114 115 116 117 118 119 120 121 122 123


    if(((bearing > 330)&&(bearing < 360)) || ((bearing >= 0)&&(bearing <= 30)))
    {
         emit dirCursorText("up");
        //bearing = 315;
        dir = "up";
    }
    else
    {
        if((bearing > 30)&&(bearing <= 60) )
        {
            emit dirCursorText("right up");
            //bearing = 315;
124
            dir = "right up";
125 126 127 128 129 130 131
        }
        else
        {
            if((bearing > 60)&&(bearing <= 105) )
            {
               emit dirCursorText("right");
                //bearing = 315;
132
                dir = "right";
133 134 135 136 137 138 139
            }
            else
            {
                if((bearing > 105)&&(bearing <= 150) )
                {
                   emit dirCursorText("right down");
                    //bearing = 315;
140
                    dir = "right down";
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
                }
                else
                {
                    if((bearing > 150)&&(bearing <= 195) )
                    {
                       emit dirCursorText("down");
                        //bearing = 315;
                        dir = "down";
                    }
                    else
                    {
                        if((bearing > 195)&&(bearing <= 240) )
                        {
                            emit dirCursorText("left down");
                            //bearing = 315;
                            dir = "left down";
                        }
                        else
                        {
                            if((bearing > 240)&&(bearing <= 300) )
                            {
                               emit dirCursorText("left");
                                //bearing = 315;
                                dir = "left";
                            }
                            else
                            {
                                if((bearing > 300)&&(bearing <= 330) )
                                {
                                    emit dirCursorText("left up");
                                    //bearing = 315;
                                    dir = "left up";
                                }

                            }

                        }

                    }

                }

            }

        }

    }


190 191 192
    bearingPad = bearing;
    distancePad = dist;
    directionPad = dir;
193 194
    emit changeCursorPosition(bearing, dist, dir);

195 196 197 198
    update();



199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
}

double SlugsPadCameraControl::getDistPixel(int x1, int y1, int x2, int y2)
{
    double cateto_opuesto,cateto_adyacente;
     //latitud y longitud del primer punto


    cateto_opuesto = abs((x1-x2)); //diferencia de latitudes entre PCR1 y PCR2
    cateto_adyacente = abs((y1-y2));//diferencia de longitudes entre PCR1 y PCR2

    return  sqrt(pow(cateto_opuesto,2) + pow(cateto_adyacente,2));

      // distancia = (float) hipotenusa;
}

tecnosapiens's avatar
tecnosapiens committed
215 216 217

QPointF SlugsPadCameraControl::ObtenerMarcacionDistanciaPixel(double lon1, double lat1,
                                                              double lon2, double lat2)
218
{
219 220
    double cateto_opuesto,cateto_adyacente, hipotenusa, distancia;
    double marcacion = 0.0;
221 222 223 224 225 226 227 228 229 230 231 232

    //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));
233
    distancia = hipotenusa*60.0;
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254


    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;

tecnosapiens's avatar
tecnosapiens committed
255

256 257 258 259

    return QPointF(marcacion,distancia);

}
260 261


262 263 264 265 266 267 268 269 270 271 272 273 274 275

QPointF SlugsPadCameraControl::getPointBy_BearingDistance(double lat1, double lon1, double rumbo, double distancia)
{
    double lon2 = 0;
    double lat2 = 0;
    double rad= M_PI/180;

    rumbo = rumbo*rad;
    lon2=(lon1 + ((distancia/60) * (sin(rumbo))));
    lat2=(lat1 + ((distancia/60) * (cos(rumbo))));

    return QPointF(lon2,lat2);
}