ViewParamWidget.cc 8.28 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
#include "ViewParamWidget.h"

#include <osg/LineWidth>
#include <QCheckBox>
#include <QFormLayout>
#include <QLabel>
#include <QPushButton>

#include "UASInterface.h"

ViewParamWidget::ViewParamWidget(GlobalViewParamsPtr& globalViewParams,
                                 QMap<int, SystemViewParamsPtr>& systemViewParamMap,
                                 QWidget* parent, QWidget* mainWindow)
 : QDockWidget(tr("View Parameters"), mainWindow)
 , mGlobalViewParams(globalViewParams)
 , mSystemViewParamMap(systemViewParamMap)
 , mParent(parent)
 , mFollowCameraComboBox(new QComboBox(this))
 , mTabWidget(new QTabWidget(this))
{
    QVBoxLayout* layout = new QVBoxLayout;
    QWidget* widget = new QWidget;
    widget->setLayout(layout);

    setWidget(widget);

    buildLayout(layout);

    mTabWidget->setFocusPolicy(Qt::NoFocus);

    connect(parent, SIGNAL(systemCreatedSignal(UASInterface*)),
            this, SLOT(systemCreated(UASInterface*)));
}

void
ViewParamWidget::setFollowCameraId(int id)
{
    for (int i = 0; i < mFollowCameraComboBox->count(); ++i)
    {
        if (mFollowCameraComboBox->itemText(i).endsWith(QString::number(id)))
        {
            mFollowCameraComboBox->setCurrentIndex(i);
            return;
        }
    }

    mFollowCameraComboBox->setCurrentIndex(0);
}

void
ViewParamWidget::systemCreated(UASInterface *uas)
{
    addTab(uas->getUASID());

    QString text("MAV ");
    text += QString::number(uas->getUASID());
    mFollowCameraComboBox->addItem(text);
}

60 61 62 63 64 65 66 67 68 69 70 71 72
void
ViewParamWidget::setpointsCheckBoxToggled(int state)
{
    if (state == Qt::Checked)
    {
        mSetpointHistoryLengthSpinBox->setEnabled(true);
    }
    else
    {
        mSetpointHistoryLengthSpinBox->setEnabled(false);
    }
}

73 74 75 76 77 78 79 80 81 82 83 84 85 86
void
ViewParamWidget::buildLayout(QVBoxLayout* layout)
{
    mFollowCameraComboBox->addItem("None");

    QComboBox* frameComboBox = new QComboBox(this);
    frameComboBox->addItem("Local");
    frameComboBox->addItem("Global");

    QComboBox* imageryComboBox = new QComboBox(this);
    imageryComboBox->addItem("None");
    imageryComboBox->addItem("Map (Google)");
    imageryComboBox->addItem("Satellite (Google)");

87 88 89
    QCheckBox* terrainModelCheckBox = new QCheckBox(this);
    terrainModelCheckBox->setChecked(mGlobalViewParams->displayTerrain());

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    QCheckBox* worldGridCheckBox = new QCheckBox(this);
    worldGridCheckBox->setChecked(mGlobalViewParams->displayWorldGrid());

    QMapIterator<int, SystemViewParamsPtr> it(mSystemViewParamMap);
    while (it.hasNext())
    {
        QString text("MAV ");
        text += QString::number(it.key());
        mFollowCameraComboBox->addItem(text);

        addTab(it.key());
    }

    QFormLayout* formLayout = new QFormLayout;
    formLayout->addRow(tr("Follow Camera"), mFollowCameraComboBox);
    formLayout->addRow(tr("Frame"), frameComboBox);
    formLayout->addRow(tr("Imagery"), imageryComboBox);
107
    formLayout->addRow(tr("Terrain"), terrainModelCheckBox);
108 109 110 111 112 113 114 115 116 117 118 119
    formLayout->addRow(tr("World Grid"), worldGridCheckBox);

    layout->addLayout(formLayout);
    layout->addWidget(mTabWidget);

    // connect signals/slots
    connect(mFollowCameraComboBox, SIGNAL(currentIndexChanged(const QString&)),
            mGlobalViewParams.data(), SLOT(followCameraChanged(const QString&)));
    connect(frameComboBox, SIGNAL(currentIndexChanged(const QString&)),
            mGlobalViewParams.data(), SLOT(frameChanged(const QString&)));
    connect(imageryComboBox, SIGNAL(currentIndexChanged(int)),
            mGlobalViewParams.data(), SLOT(imageryTypeChanged(int)));
120 121
    connect(terrainModelCheckBox, SIGNAL(stateChanged(int)),
            mGlobalViewParams.data(), SLOT(toggleTerrain(int)));
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
    connect(worldGridCheckBox, SIGNAL(stateChanged(int)),
            mGlobalViewParams.data(), SLOT(toggleWorldGrid(int)));
}

void
ViewParamWidget::addTab(int systemId)
{
    // add widgets that configure system-specific parameters
    SystemViewParamsPtr systemViewParams = mSystemViewParamMap[systemId];

    QWidget* page = new QWidget;

    QCheckBox* colorPointCloudCheckBox = new QCheckBox(this);
    colorPointCloudCheckBox->setChecked(systemViewParams->colorPointCloudByDistance());

    QCheckBox* localGridCheckBox = new QCheckBox(this);
    localGridCheckBox->setChecked(systemViewParams->displayLocalGrid());

    QComboBox* modelComboBox = new QComboBox(this);
    for (int i = 0; i < systemViewParams->modelNames().size(); ++i)
    {
        modelComboBox->addItem(systemViewParams->modelNames().at(i));
    }

    QCheckBox* obstacleListCheckBox = new QCheckBox(this);
    obstacleListCheckBox->setChecked(systemViewParams->displayObstacleList());

    QCheckBox* plannedPathCheckBox = new QCheckBox(this);
    plannedPathCheckBox->setChecked(systemViewParams->displayPlannedPath());

    QCheckBox* pointCloudCheckBox = new QCheckBox(this);
    pointCloudCheckBox->setChecked(systemViewParams->displayPointCloud());

    QCheckBox* rgbdCheckBox = new QCheckBox(this);
    rgbdCheckBox->setChecked(systemViewParams->displayRGBD());

158 159 160 161 162 163 164 165 166
    QCheckBox* setpointsCheckBox = new QCheckBox(this);
    setpointsCheckBox->setChecked(systemViewParams->displaySetpoints());

    mSetpointHistoryLengthSpinBox = new QSpinBox(this);
    mSetpointHistoryLengthSpinBox->setRange(1, 10000);
    mSetpointHistoryLengthSpinBox->setSingleStep(10);
    mSetpointHistoryLengthSpinBox->setValue(systemViewParams->setpointHistoryLength());
    mSetpointHistoryLengthSpinBox->setEnabled(systemViewParams->displaySetpoints());

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
    QCheckBox* targetCheckBox = new QCheckBox(this);
    targetCheckBox->setChecked(systemViewParams->displayTarget());

    QCheckBox* trailsCheckBox = new QCheckBox(this);
    trailsCheckBox->setChecked(systemViewParams->displayTrails());

    QCheckBox* waypointsCheckBox = new QCheckBox(this);
    waypointsCheckBox->setChecked(systemViewParams->displayWaypoints());

    QFormLayout* formLayout = new QFormLayout;
    page->setLayout(formLayout);

    formLayout->addRow(tr("Color Point Cloud"), colorPointCloudCheckBox);
    formLayout->addRow(tr("Local Grid"), localGridCheckBox);
    formLayout->addRow(tr("Model"), modelComboBox);
    formLayout->addRow(tr("Obstacles"), obstacleListCheckBox);
    formLayout->addRow(tr("Planned Path"), plannedPathCheckBox);
    formLayout->addRow(tr("Point Cloud"), pointCloudCheckBox);
    formLayout->addRow(tr("RGBD"), rgbdCheckBox);
186 187
    formLayout->addRow(tr("Setpoints"), setpointsCheckBox);
    formLayout->addRow(tr("Setpoint History Length"), mSetpointHistoryLengthSpinBox);
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    formLayout->addRow(tr("Target"), targetCheckBox);
    formLayout->addRow(tr("Trails"), trailsCheckBox);
    formLayout->addRow(tr("Waypoints"), waypointsCheckBox);

    QString label("MAV ");
    label += QString::number(systemId);

    mTabWidget->addTab(page, label);

    // connect signals / slots
    connect(colorPointCloudCheckBox, SIGNAL(stateChanged(int)),
            systemViewParams.data(), SLOT(toggleColorPointCloud(int)));
    connect(localGridCheckBox, SIGNAL(stateChanged(int)),
            systemViewParams.data(), SLOT(toggleLocalGrid(int)));
    connect(modelComboBox, SIGNAL(currentIndexChanged(int)),
            systemViewParams.data(), SLOT(modelChanged(int)));
    connect(obstacleListCheckBox, SIGNAL(stateChanged(int)),
            systemViewParams.data(), SLOT(toggleObstacleList(int)));
    connect(plannedPathCheckBox, SIGNAL(stateChanged(int)),
            systemViewParams.data(), SLOT(togglePlannedPath(int)));
    connect(pointCloudCheckBox, SIGNAL(stateChanged(int)),
            systemViewParams.data(), SLOT(togglePointCloud(int)));
    connect(rgbdCheckBox, SIGNAL(stateChanged(int)),
            systemViewParams.data(), SLOT(toggleRGBD(int)));
212 213 214 215 216 217
    connect(setpointsCheckBox, SIGNAL(stateChanged(int)),
            systemViewParams.data(), SLOT(toggleSetpoints(int)));
    connect(setpointsCheckBox, SIGNAL(stateChanged(int)),
            this, SLOT(setpointsCheckBoxToggled(int)));
    connect(mSetpointHistoryLengthSpinBox, SIGNAL(valueChanged(int)),
            systemViewParams.data(), SLOT(setSetpointHistoryLength(int)));
218 219 220 221 222 223 224
    connect(targetCheckBox, SIGNAL(stateChanged(int)),
            systemViewParams.data(), SLOT(toggleTarget(int)));
    connect(trailsCheckBox, SIGNAL(stateChanged(int)),
            systemViewParams.data(), SLOT(toggleTrails(int)));
    connect(waypointsCheckBox, SIGNAL(stateChanged(int)),
            systemViewParams.data(), SLOT(toggleWaypoints(int)));
}