ViewParamWidget.cc 9.53 KB
Newer Older
1 2 3 4
#include "ViewParamWidget.h"

#include <osg/LineWidth>
#include <QCheckBox>
5
#include <QGroupBox>
6 7 8
#include <QLabel>
#include <QPushButton>

9
#include "ImageryParamDialog.h"
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#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);

32 33
    mOverlaySignalMapper = new QSignalMapper(this);

34 35
    connect(parent, SIGNAL(systemCreatedSignal(UASInterface*)),
            this, SLOT(systemCreated(UASInterface*)));
36 37 38

    connect(parent, SIGNAL(overlayCreatedSignal(int,QString)),
            this, SLOT(overlayCreated(int,QString)));
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
}

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);
}

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
void
ViewParamWidget::overlayCreated(int systemId, const QString& name)
{
    if (!mOverlayLayout.contains(systemId))
    {
        return;
    }

    SystemViewParamsPtr systemViewParams = mSystemViewParamMap[systemId];
    systemViewParams->displayOverlay().insert(name, true);

    QCheckBox* checkbox = new QCheckBox(this);
    checkbox->setChecked(systemViewParams->displayOverlay().value(name));
    mOverlayLayout[systemId]->addRow(name, checkbox);

    mOverlaySignalMapper->setMapping(checkbox, name);
    connect(checkbox, SIGNAL(clicked()),
            mOverlaySignalMapper, SLOT(map()));
    connect(mOverlaySignalMapper, SIGNAL(mapped(QString)),
            systemViewParams.data(), SLOT(toggleOverlay(QString)));
}

78 79 80 81 82 83 84 85 86 87
void
ViewParamWidget::systemCreated(UASInterface *uas)
{
    addTab(uas->getUASID());

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

88 89 90 91 92 93 94 95 96 97 98 99 100
void
ViewParamWidget::setpointsCheckBoxToggled(int state)
{
    if (state == Qt::Checked)
    {
        mSetpointHistoryLengthSpinBox->setEnabled(true);
    }
    else
    {
        mSetpointHistoryLengthSpinBox->setEnabled(false);
    }
}

101 102 103 104 105 106
void
ViewParamWidget::showImageryParamDialog(void)
{
    ImageryParamDialog::getImageryParams(mGlobalViewParams);
}

107 108 109 110 111 112 113 114 115
void
ViewParamWidget::buildLayout(QVBoxLayout* layout)
{
    mFollowCameraComboBox->addItem("None");

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

116 117 118
    QCheckBox* terrainModelCheckBox = new QCheckBox(this);
    terrainModelCheckBox->setChecked(mGlobalViewParams->displayTerrain());

119 120 121
    QCheckBox* worldGridCheckBox = new QCheckBox(this);
    worldGridCheckBox->setChecked(mGlobalViewParams->displayWorldGrid());

122 123 124
    QPushButton* imageryButton = new QPushButton(this);
    imageryButton->setText("View");

125 126 127 128 129 130 131 132 133 134 135 136 137
    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);
138
    formLayout->addRow(tr("Terrain"), terrainModelCheckBox);
139
    formLayout->addRow(tr("World Grid"), worldGridCheckBox);
140
    formLayout->addRow(tr("Imagery Options"), imageryButton);
141 142 143 144 145 146 147 148 149

    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&)));
150 151
    connect(terrainModelCheckBox, SIGNAL(stateChanged(int)),
            mGlobalViewParams.data(), SLOT(toggleTerrain(int)));
152 153
    connect(worldGridCheckBox, SIGNAL(stateChanged(int)),
            mGlobalViewParams.data(), SLOT(toggleWorldGrid(int)));
154 155 156 157
    connect(imageryButton, SIGNAL(clicked()),
            this, SLOT(showImageryParamDialog()));
//    connect(imageryComboBox, SIGNAL(currentIndexChanged(int)),
//            mGlobalViewParams.data(), SLOT(imageryTypeChanged(int)));
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
}

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());

192 193 194 195 196 197 198 199 200
    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());

201 202 203 204 205 206 207 208 209
    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());

210 211 212 213
    QGroupBox* overlayGroupBox = new QGroupBox(tr("Overlays"), this);
    mOverlayLayout[systemId] = new QFormLayout;
    overlayGroupBox->setLayout(mOverlayLayout[systemId]);

214 215 216 217 218 219 220 221 222 223
    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);
224 225
    formLayout->addRow(tr("Setpoints"), setpointsCheckBox);
    formLayout->addRow(tr("Setpoint History Length"), mSetpointHistoryLengthSpinBox);
226 227 228
    formLayout->addRow(tr("Target"), targetCheckBox);
    formLayout->addRow(tr("Trails"), trailsCheckBox);
    formLayout->addRow(tr("Waypoints"), waypointsCheckBox);
229
    formLayout->addRow(overlayGroupBox);
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250

    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)));
251 252 253 254 255 256
    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)));
257 258 259 260 261 262 263
    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)));
}