ViewParamWidget.cc 9.57 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
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);
68
    checkbox->setAccessibleName(name);
69 70 71
    checkbox->setChecked(systemViewParams->displayOverlay().value(name));
    mOverlayLayout[systemId]->addRow(name, checkbox);

72 73
    mOverlaySignalMapper->setMapping(checkbox, checkbox);

74 75
    connect(checkbox, SIGNAL(clicked()),
            mOverlaySignalMapper, SLOT(map()));
76 77
    connect(mOverlaySignalMapper, SIGNAL(mapped(QWidget*)),
            systemViewParams.data(), SLOT(toggleOverlay(QWidget*)));
78 79
}

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

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

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

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

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

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

118 119 120
    QCheckBox* terrainModelCheckBox = new QCheckBox(this);
    terrainModelCheckBox->setChecked(mGlobalViewParams->displayTerrain());

121 122 123
    QCheckBox* worldGridCheckBox = new QCheckBox(this);
    worldGridCheckBox->setChecked(mGlobalViewParams->displayWorldGrid());

124 125 126
    QPushButton* imageryButton = new QPushButton(this);
    imageryButton->setText("View");

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

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

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

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

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

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

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

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