WaypointGlobalView.cc 11.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#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();

James Goppert's avatar
James Goppert committed
15 16 17
    // set type
    wp->setType(Waypoint::GLOBAL);

18 19 20
    // Read values and set user interface
    updateValues();

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

24 25 26
    //for spinBox Latitude
    connect(ui->m_latitudGrados_spinBox, SIGNAL(valueChanged(int)), this, SLOT(updateLatitudeWP(int)));
    connect(ui->m_latitudMinutos_spinBox, SIGNAL(valueChanged(double)), this, SLOT(updateLatitudeMinuteWP(double)));
27 28
    connect(ui->m_dirLatitudeN_radioButton, SIGNAL(clicked()), this, SLOT(changeDirectionLatitudeWP()));
    connect(ui->m_dirLatitudeS_radioButton, SIGNAL(clicked()), this, SLOT(changeDirectionLatitudeWP()));
29 30 31 32

    //for spinBox Longitude
    connect(ui->m_longitudGrados_spinBox, SIGNAL(valueChanged(int)), this, SLOT(updateLongitudeWP(int)));
    connect(ui->m_longitudMinutos_spinBox, SIGNAL(valueChanged(double)), this, SLOT(updateLongitudeMinuteWP(double)));
33 34
    connect(ui->m_dirLongitudeW_radioButton, SIGNAL(clicked()), this, SLOT(changeDirectionLongitudeWP()));
    connect(ui->m_dirLongitudeE_radioButton, SIGNAL(clicked()), this, SLOT(changeDirectionLongitudeWP()));
35 36 37



38
   connect(ui->m_orbitCheckBox, SIGNAL(stateChanged(int)), this, SLOT(changeOrbitalState(int)));
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


//    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()
{
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
            int gradoLat, gradoLon;
            float minLat, minLon;
            QString dirLat, dirLon;

            getLatitudeGradoMin(wp->getY(), &gradoLat, &minLat, &dirLat);
            getLongitudGradoMin(wp->getX(), &gradoLon, &minLon, &dirLon);

            //latitude on spinBox
            ui->m_latitudGrados_spinBox->setValue(gradoLat);
            ui->m_latitudMinutos_spinBox->setValue(minLat);
            if(dirLat == "N")
            {
                ui->m_dirLatitudeN_radioButton->setChecked(true);
                ui->m_dirLatitudeS_radioButton->setChecked(false);
            }
            else
            {
                ui->m_dirLatitudeS_radioButton->setChecked(true);
                ui->m_dirLatitudeN_radioButton->setChecked(false);

            }

             //longitude on spinBox
            ui->m_longitudGrados_spinBox->setValue(gradoLon);
            ui->m_longitudMinutos_spinBox->setValue(minLon);
            if(dirLon == "W")
            {
                ui->m_dirLongitudeW_radioButton->setChecked(true);
                ui->m_dirLongitudeE_radioButton->setChecked(false);
            }
            else
            {
               ui->m_dirLongitudeE_radioButton->setChecked(true);
               ui->m_dirLongitudeW_radioButton->setChecked(false);

            }

            ui->idWP_label->setText(QString("WP-%1").arg(wp->getId()));
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
}

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();
James Goppert's avatar
James Goppert committed
203
        wp->setType(Waypoint::GLOBAL_ORBIT);
204 205 206 207 208
    }
    else
    {
        ui->m_orbitalSpinBox->setEnabled(false);
        ui->m_orbitalSpinBox->hide();
James Goppert's avatar
James Goppert committed
209
        wp->setType(Waypoint::GLOBAL);
210 211 212
    }
}

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
void WaypointGlobalView::getLatitudeGradoMin(float latitud, int *gradoLat, float *minLat, QString *dirLat)
{

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

   if (latitud<0){*dirLat="S"; latitud = latitud * -1;}
   else {*dirLat="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);

        *gradoLat = grados;
        *minLat = minutos;


   }
   else
   {
       *gradoLat = -1;
       *minLat = -1;
       *dirLat="N/A";

   }

}

void WaypointGlobalView::getLongitudGradoMin(float longitud, int *gradoLon, float *minLon, QString *dirLon)
{

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

    if (longitud<0){*dirLon="W"; longitud = longitud * -1;}
    else {*dirLon="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);

         *gradoLon = grados;
         *minLon = minutos;

    }
    else
    {
        *gradoLon = -1;
        *minLon = -1;
        *dirLon="N/A";
    }
}

void WaypointGlobalView::updateCoordValues(float lat, float lon)
{

}

void WaypointGlobalView::updateLatitudeWP(int value)
{
    Q_UNUSED(value);


    int gradoLat;
    float minLat;
    float Latitud;
    QString dirLat;

    gradoLat = ui->m_latitudGrados_spinBox->value();
    minLat = ui->m_latitudMinutos_spinBox->value();
    if(ui->m_dirLatitudeN_radioButton->isChecked())
    {
        dirLat = "N";
    }
    else
    {
        dirLat = "S";
    }
    //dirLat = ui->m_dirLatitud_label->text();

    Latitud = gradoLat + (minLat/60);
    if(dirLat == "S"){Latitud = Latitud * -1;}

    wp->setY(Latitud);

    //emit signal waypoint position was changed

    emit changePositionWP(wp);

}

void WaypointGlobalView::updateLatitudeMinuteWP(double value)
{
    Q_UNUSED(value);

    int gradoLat;
    float minLat;
    float Latitud;
    QString dirLat;

    gradoLat = ui->m_latitudGrados_spinBox->value();
    minLat = ui->m_latitudMinutos_spinBox->value();
    //dirLat = ui->m_dirLatitud_label->text();
    if(ui->m_dirLatitudeN_radioButton->isChecked())
    {
        dirLat = "N";
    }
    else
    {
        dirLat = "S";
    }

    Latitud = gradoLat + (minLat/60);
    if(dirLat == "S"){Latitud = Latitud * -1;}

    wp->setY(Latitud);

    //emit signal waypoint position was changed
    emit changePositionWP(wp);


}

void WaypointGlobalView::updateLongitudeWP(int value)
{
    Q_UNUSED(value);

    int gradoLon;
    float minLon;
    float Longitud;
    QString dirLon;

    gradoLon = ui->m_longitudGrados_spinBox->value();
    minLon = ui->m_longitudMinutos_spinBox->value();
   // dirLon = ui->m_dirLongitud_label->text();
    if(ui->m_dirLongitudeW_radioButton->isChecked())
    {
        dirLon = "W";
    }
    else
    {
        dirLon = "E";
    }

    Longitud = gradoLon + (minLon/60);
    if(dirLon == "W"){Longitud = Longitud * -1;}

    wp->setX(Longitud);

    //emit signal waypoint position was changed
    emit changePositionWP(wp);


}



void WaypointGlobalView::updateLongitudeMinuteWP(double value)
{
    Q_UNUSED(value);

    int gradoLon;
    float minLon;
    float Longitud;
    QString dirLon;

    gradoLon = ui->m_longitudGrados_spinBox->value();
    minLon = ui->m_longitudMinutos_spinBox->value();
   // dirLon = ui->m_dirLongitud_label->text();
    if(ui->m_dirLongitudeW_radioButton->isChecked())
    {
        dirLon = "W";
    }
    else
    {
        dirLon = "E";
    }

    Longitud = gradoLon + (minLon/60);
    if(dirLon == "W"){Longitud = Longitud * -1;}

    wp->setX(Longitud);

    //emit signal waypoint position was changed
    emit changePositionWP(wp);

}

413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
void WaypointGlobalView::changeDirectionLatitudeWP()
{
    if(ui->m_dirLatitudeN_radioButton->isChecked())
    {
        if(wp->getY() < 0)
        {
            wp->setY(wp->getY()* -1);
            //emit signal waypoint position was changed
            emit changePositionWP(wp);
        }

    }
    if(ui->m_dirLatitudeS_radioButton->isChecked())
    {
        if(wp->getY() > 0)
        {
            wp->setY(wp->getY()*-1);
            //emit signal waypoint position was changed
            emit changePositionWP(wp);

        }

    }

}

void WaypointGlobalView::changeDirectionLongitudeWP()
{
    if(ui->m_dirLongitudeW_radioButton->isChecked())
    {
        if(wp->getX() > 0)
        {
           wp->setX(wp->getX()*-1);
           //emit signal waypoint position was changed
           emit changePositionWP(wp);
        }

    }

    if(ui->m_dirLongitudeE_radioButton->isChecked())
    {
        if(wp->getX() < 0)
        {
            wp->setX(wp->getX()*-1);
            //emit signal waypoint position was changed
            emit changePositionWP(wp);
        }

    }



}
466

467