WaypointGlobalView.cpp 4.03 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
#include "WaypointGlobalView.h"
#include "ui_WaypointGlobalView.h"

#include <math.h>

WaypointGlobalView::WaypointGlobalView(Waypoint* wp,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::WaypointGlobalView)
{
    ui->setupUi(this);
    this->wp = wp;

    ui->m_orbitalSpinBox->hide();

    connect(ui->m_orbitalSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setOrbit(double)));
    connect(ui->m_heigthSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setZ(double)));

    connect(ui->m_orbitCheckBox, SIGNAL(stateChanged(int)), this, SLOT(changeOrbitalState(int)));


    // Read values and set user interface
    updateValues();


//    connect(m_ui->xSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setX(double)));
//    connect(m_ui->ySpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setY(double)));
//    connect(m_ui->zSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setZ(double)));

//    //hidden degree to radian conversion of the yaw angle
//    connect(m_ui->yawSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setYaw(int)));
//    connect(this, SIGNAL(setYaw(double)), wp, SLOT(setYaw(double)));

//    connect(m_ui->upButton, SIGNAL(clicked()), this, SLOT(moveUp()));
//    connect(m_ui->downButton, SIGNAL(clicked()), this, SLOT(moveDown()));
//    connect(m_ui->removeButton, SIGNAL(clicked()), this, SLOT(remove()));

//    connect(m_ui->autoContinue, SIGNAL(stateChanged(int)), this, SLOT(changedAutoContinue(int)));
//    connect(m_ui->selectedBox, SIGNAL(stateChanged(int)), this, SLOT(changedCurrent(int)));

//
//    connect(m_ui->holdTimeSpinBox, SIGNAL(valueChanged(int)), wp, SLOT(setHoldTime(int)));
}

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

void WaypointGlobalView::updateValues()
{
    ui->m_latitudtextEdit->setText(getLatitudString(wp->getY()));
    ui->m_longitudtextEdit->setText(getLongitudString(wp->getX()));
    ui->idWP_label->setText(QString("%1").arg(wp->getId()));\

}

void WaypointGlobalView::changeEvent(QEvent *e)
{
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void WaypointGlobalView::remove()
{
    emit removeWaypoint(wp);
    delete this;
}

QString WaypointGlobalView::getLatitudString(float latitud)
{
   QString tempNS ="";
   QString stringLatitudTemp = "";

   float minutos = 0;
   float grados = 0;
   float entero = 0;
   float dec = 0;

   if (latitud<0){tempNS="S"; latitud = latitud * -1;}
   else {tempNS="N";}

   if(latitud< 90 || latitud > -90)
   {
       dec = latitud - (entero = ::floor(latitud));;
        minutos = dec * 60;
        grados = entero;
        if(grados < 0) grados = grados * (-1);
        if(minutos < 0) minutos = minutos * (-1);

       stringLatitudTemp = QString::number(grados)+ "   "+ QString::number(minutos)+"'  "+ tempNS;

       return stringLatitudTemp;
   }
   else
   {
       stringLatitudTemp = "erroneous latitude";
       return stringLatitudTemp;
   }

}

QString WaypointGlobalView::getLongitudString(float longitud)
{
    QString tempEW ="";
    QString stringLongitudTemp = "";

    float minutos = 0;
    float grados = 0;
    float entero = 0;
    float dec = 0;

    if (longitud<0){tempEW="W"; longitud = longitud * -1;}
    else {tempEW="E";}

    if(longitud<180 || longitud > -180)
    {
        dec = longitud - (entero = ::floor(longitud));;
         minutos = dec * 60;
         grados = entero;
         if(grados < 0) grados = grados * (-1);
         if(minutos < 0) minutos = minutos * (-1);

        stringLongitudTemp = QString::number(grados)+ "   "+ QString::number(minutos)+"'  "+ tempEW;

        return stringLongitudTemp;
    }
    else
    {
        stringLongitudTemp = "erroneous longitude";
        return stringLongitudTemp;
    }
}

void WaypointGlobalView::changeOrbitalState(int state)
{
    Q_UNUSED(state);

    if(ui->m_orbitCheckBox->isChecked())
    {
        ui->m_orbitalSpinBox->setEnabled(true);
        ui->m_orbitalSpinBox->show();
    }
    else
    {
        ui->m_orbitalSpinBox->setEnabled(false);
        ui->m_orbitalSpinBox->hide();
    }
}