Skip to content
Snippets Groups Projects
WaypointView.cc 4.87 KiB
Newer Older
  • Learn to ignore specific revisions
  • pixhawk's avatar
    pixhawk committed
    /*=====================================================================
    
    PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
    
    (c) 2009, 2010 PIXHAWK PROJECT  <http://pixhawk.ethz.ch>
    
    This file is part of the PIXHAWK project
    
        PIXHAWK 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.
    
        PIXHAWK 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.
    
    ======================================================================*/
    
    /**
     * @file
     *   @brief Displays one waypoint
     *
     *   @author Lorenz Meier <mavteam@student.ethz.ch>
     *   @author Benjamin Knecht <mavteam@student.ethz.ch>
    
     *   @author Petri Tanskanen <mavteam@student.ethz.ch>
    
    pixhawk's avatar
    pixhawk committed
     *
     */
    
    #include <QDoubleSpinBox>
    #include <QDebug>
    
    
    pixhawk's avatar
    pixhawk committed
    #include <cmath>    //M_PI
    
    
    pixhawk's avatar
    pixhawk committed
    #include "WaypointView.h"
    #include "ui_WaypointView.h"
    
    WaypointView::WaypointView(Waypoint* wp, QWidget* parent) :
        QWidget(parent),
        m_ui(new Ui::WaypointView)
    {
        m_ui->setupUi(this);
    
        this->wp = wp;
    
    James Goppert's avatar
    James Goppert committed
        wp->setType(Waypoint::LOCAL);
        m_ui->orbitSpinBox->setEnabled(false);
        m_ui->orbitSpinBox->hide();
    
    pixhawk's avatar
    pixhawk committed
    
        // Read values and set user interface
    
    pixhawk's avatar
    pixhawk committed
    
        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)));
    
    pixhawk's avatar
    pixhawk committed
    
        //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)));
    
    pixhawk's avatar
    pixhawk committed
    
        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()));
    
    
    pixhawk's avatar
    pixhawk committed
        connect(m_ui->autoContinue, SIGNAL(stateChanged(int)), this, SLOT(changedAutoContinue(int)));
        connect(m_ui->selectedBox, SIGNAL(stateChanged(int)), this, SLOT(changedCurrent(int)));
    
    James Goppert's avatar
    James Goppert committed
        connect(m_ui->orbitCheckBox, SIGNAL(stateChanged(int)), this, SLOT(changeOrbitalState(int)));
    
    
    
    pixhawk's avatar
    pixhawk committed
    
        connect(m_ui->orbitSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setOrbit(double)));
        connect(m_ui->holdTimeSpinBox, SIGNAL(valueChanged(int)), wp, SLOT(setHoldTime(int)));
    
    pixhawk's avatar
    pixhawk committed
    }
    
    void WaypointView::setYaw(int yawDegree)
    {
        emit setYaw((double)yawDegree*M_PI/180.);
    
    pixhawk's avatar
    pixhawk committed
    }
    
    void WaypointView::moveUp()
    {
        emit moveUpWaypoint(wp);
    }
    
    void WaypointView::moveDown()
    {
        emit moveDownWaypoint(wp);
    }
    
    void WaypointView::remove()
    {
        emit removeWaypoint(wp);
        delete this;
    }
    
    
    pixhawk's avatar
    pixhawk committed
    void WaypointView::changedAutoContinue(int state)
    
    pixhawk's avatar
    pixhawk committed
    {
        if (state == 0)
    
            wp->setAutocontinue(false);
    
    pixhawk's avatar
    pixhawk committed
        else
    
            wp->setAutocontinue(true);
    
    pixhawk's avatar
    pixhawk committed
    }
    
    
    pixhawk's avatar
    pixhawk committed
    void WaypointView::changedCurrent(int state)
    
    pixhawk's avatar
    pixhawk committed
    {
    
    pixhawk's avatar
    pixhawk committed
        if (state == 0)
        {
    
            //m_ui->selectedBox->setChecked(true);
            //m_ui->selectedBox->setCheckState(Qt::Checked);
            //wp->setCurrent(false);
    
    pixhawk's avatar
    pixhawk committed
        }
        else
        {
    
            emit changeCurrentWaypoint(wp->getId());   //the slot changeCurrentWaypoint() in WaypointList sets all other current flags to false
    
    pixhawk's avatar
    pixhawk committed
        }
    
    pixhawk's avatar
    pixhawk committed
    }
    
    
    void WaypointView::updateValues()
    {
        m_ui->xSpinBox->setValue(wp->getX());
        m_ui->ySpinBox->setValue(wp->getY());
        m_ui->zSpinBox->setValue(wp->getZ());
        m_ui->yawSpinBox->setValue(wp->getYaw()/M_PI*180.);
        m_ui->selectedBox->setChecked(wp->getCurrent());
        m_ui->autoContinue->setChecked(wp->getAutoContinue());
        m_ui->idLabel->setText(QString("%1").arg(wp->getId()));\
        m_ui->orbitSpinBox->setValue(wp->getOrbit());
        m_ui->holdTimeSpinBox->setValue(wp->getHoldTime());
    }
    
    
    pixhawk's avatar
    pixhawk committed
    void WaypointView::setCurrent(bool state)
    
    pixhawk's avatar
    pixhawk committed
    {
    
    pixhawk's avatar
    pixhawk committed
        if (state)
        {
    
    pixhawk's avatar
    pixhawk committed
            m_ui->selectedBox->setCheckState(Qt::Checked);
    
    pixhawk's avatar
    pixhawk committed
        }
        else
        {
             m_ui->selectedBox->setCheckState(Qt::Unchecked);
        }
    
    pixhawk's avatar
    pixhawk committed
    }
    
    WaypointView::~WaypointView()
    {
        delete m_ui;
    }
    
    void WaypointView::changeEvent(QEvent *e)
    {
        switch (e->type()) {
        case QEvent::LanguageChange:
            m_ui->retranslateUi(this);
            break;
        default:
            break;
        }
    }
    
    James Goppert's avatar
    James Goppert committed
    
    void WaypointView::changeOrbitalState(int state)
    {
        Q_UNUSED(state);
    
        if(m_ui->orbitCheckBox->isChecked())
        {
            m_ui->orbitSpinBox->setEnabled(true);
            m_ui->orbitSpinBox->show();
            wp->setType(Waypoint::LOCAL_ORBIT);
        }
        else
        {
            m_ui->orbitSpinBox->setEnabled(false);
            m_ui->orbitSpinBox->hide();
            wp->setType(Waypoint::LOCAL);
        }
    }