Newer
Older
#include "MMMPlayerGuiPlugin.h"
#include "MMMPlayerConfigDialog.h"
#include "ui_MMMPlayerConfigDialog.h"
#include <ArmarXCore/core/system/ArmarXDataPath.h>
#include <ArmarXCore/observers/variant/SingleTypeVariantList.h>
#include <ArmarXCore/util/variants/eigen3/MatrixVariant.h>
#include <ArmarXCore/observers/variant/TimestampVariant.h>
#include <IceUtil/Time.h>
// Qt headers
#include <QInputDialog>
#include <Qt>
#include <QtGlobal>
#include <QtGui/QPushButton>
#include <QtGui/QComboBox>
#include <QtGui/QMenu>
#include <boost/filesystem.hpp>
using namespace armarx;
#define MMMPLAYER_DEFAULT_NAME "MMMPlayer"
#define PROJECT_DEFAULT "Armar4"
MMMPlayerGuiPlugin::MMMPlayerGuiPlugin()
{
addWidget<MMMPlayerWidget>();
}
MMMPlayerWidget::MMMPlayerWidget()
{
// init gui
ui.setupUi(getWidget());
fileDialog2 = new QFileDialog();
fileDialog2->setModal(true);
fileDialog2->setFileMode(QFileDialog::ExistingFiles);
QStringList fileTypes;
fileTypes << tr("XML (*.xml)") << tr("All Files (*.*)");
fileDialog2->setNameFilters(fileTypes);
jointList = new QListWidget();
updateTimer = new QTimer(this);
}
/*
QPointer<QDialog> MMMPlayerWidget::getConfigDialog(QWidget* parent)
{
if(!dialog)
{
dialog = new MMMPlayerConfigDialog(parent);
boost::filesystem::path dir(CONFIG_FILE_DEFAULT);
dialog->fileDialog->setDirectory(QString::fromStdString(dir.remove_filename().string()));
dialog->ui->editConfigFile->setText(QString::fromStdString(CONFIG_FILE_DEFAULT));
}
return qobject_cast<MMMPlayerConfigDialog*>(dialog);
}
void MMMPlayerWidget::configured()
{
ARMARX_VERBOSE << "MMMPlayerWidget::configured()";
configFile = dialog->ui->editConfigFile->text().toStdString();
ARMARX_VERBOSE << "config file " + configFile;
}
*/
void MMMPlayerWidget::onInitComponent()
{
usingProxy(MMMPLAYER_DEFAULT_NAME);
connectSlots();
}
void MMMPlayerWidget::onConnectComponent()
{
MMMPlayer = getProxy<MMMPlayerInterfacePrx>(MMMPLAYER_DEFAULT_NAME);
configFile = MMMPlayer->getMotionPath();
ui.editConfigFile->setText(QString::fromStdString(configFile));
boost::filesystem::path dir(configFile);
fileDialog2->setDirectory(QString::fromStdString(dir.remove_filename().string()));
setupJointList();
ui.frameSlider->blockSignals(true);
ui.frameSlider->setMaximum(MMMPlayer->getNumberOfFrames());
on_loopPlayback_toggled(false);
}
void MMMPlayerWidget::onExitComponent()
{
}
void MMMPlayerWidget::onDisconnectComponent()
{
}
void MMMPlayerWidget::loadSettings(QSettings* settings)
void MMMPlayerWidget::saveSettings(QSettings* settings)
{
}
void MMMPlayerWidget::connectSlots()
{
Jonas Beil
committed
connect(ui.initializeButton, SIGNAL(clicked()), this, SLOT(on_initializeButton_clicked()));
connect(ui.startButton, SIGNAL(clicked()), this, SLOT(on_startButton_clicked()));
connect(ui.pauseButton, SIGNAL(clicked()), this, SLOT(on_pauseButton_clicked()));
connect(ui.stopButton, SIGNAL(clicked()), this, SLOT(on_stopButton_clicked()));
connect(ui.btnSelectConfig, SIGNAL(clicked()), fileDialog2, SLOT(show()));
connect(ui.selectJoints, SIGNAL(clicked()), jointList, SLOT(show()));
connect(fileDialog2, SIGNAL(accepted()), this, SLOT(configFileSelected()));
connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateSlider()));
// connect(ui.frameSlider, SIGNAL(valueChanged(int)), this, SLOT(setFrameNumber(int)));
connect(ui.loopPlayback, SIGNAL(toggled(bool)), this, SLOT(on_loopPlayback_toggled(bool)));
connect(ui.spinBoxFPS, SIGNAL(valueChanged(int)), this, SLOT(on_spinBoxFPS_valueChanged(int)));
connect(ui.controlMode, SIGNAL(currentIndexChanged(int)), this, SLOT(on_controlMode_changed(int)));
connect(jointList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(jointListChanged(QListWidgetItem*)));
Jonas Beil
committed
void armarx::MMMPlayerWidget::on_initializeButton_clicked()
Jonas Beil
committed
// set position control mode and move to first frame as initial pose
on_controlMode_changed(0);
Jonas Beil
committed
ui.startButton->setEnabled(true);
}
void armarx::MMMPlayerWidget::on_startButton_clicked()
{
bool started = MMMPlayer->startMMMPlayer();
if (started)
{
updateTimer->start(100);
Jonas Beil
committed
ui.initializeButton->setDisabled(started);
ui.startButton->setDisabled(started);
ui.pauseButton->setEnabled(started);
ui.pauseButton->setText("Pause");
ui.btnSelectConfig->setEnabled(false);
ui.stopButton->setEnabled(started);
}
}
void MMMPlayerWidget::on_pauseButton_clicked()
{
bool paused = MMMPlayer->pauseMMMPlayer();
ui.pauseButton->setText("Resume");
}
else
{
ui.pauseButton->setText("Pause");
}
ui.frameSlider->setEnabled(paused);
ui.spinBoxFPS->setEnabled(paused);
ui.frameSlider->blockSignals(!paused);
}
void armarx::MMMPlayerWidget::on_stopButton_clicked()
{
bool stopped = MMMPlayer->stopMMMPlayer();
{
updateTimer->stop();
Jonas Beil
committed
ui.initializeButton->setEnabled(stopped);
ui.startButton->setEnabled(stopped);
ui.pauseButton->setText("Pause");
ui.btnSelectConfig->setEnabled(true);
ui.controlMode->setEnabled(stopped);
ui.spinBoxFPS->setEnabled(stopped);
ui.frameSlider->blockSignals(false);
ui.pauseButton->setDisabled(stopped);
ui.stopButton->setDisabled(stopped);
}
}
void MMMPlayerWidget::setFrameNumber(int frameNumber)
{
MMMPlayer->setCurrentFrame(frameNumber);
ui.currentFrame->display(frameNumber);
}
void MMMPlayerWidget::configFileSelected()
{
configFile = (this->fileDialog2->selectedFiles()[0]).toStdString();
ui.editConfigFile->setText(this->fileDialog2->selectedFiles()[0]);
MMMPlayer->loadTrajectory(configFile, "");
ui.frameSlider->setMaximum(MMMPlayer->getNumberOfFrames());
ARMARX_INFO << "loaded new trajectory " + configFile;
setupJointList();
}
void MMMPlayerWidget::setupJointList()
{
StringList jointNames = MMMPlayer->getJointNames();
jointList->clear();
for (size_t i = 0; i < jointNames.size(); ++i)
{
std::string jointName = jointNames.at(i);
QListWidgetItem* joint = new QListWidgetItem(QString::fromStdString(jointName), jointList);
joint->setCheckState(Qt::Checked);
}
}
void MMMPlayerWidget::updateSlider()
{
int currentFrame = MMMPlayer->getCurrentFrame();
ui.frameSlider->blockSignals(true);
ui.frameSlider->setSliderPosition(currentFrame);
if (currentFrame >= ui.frameSlider->maximum() || currentFrame < 0)
on_stopButton_clicked();
ui.frameSlider->blockSignals(false);
ui.currentFrame->display(currentFrame);
}
void MMMPlayerWidget::jointListChanged(QListWidgetItem* joint)
if (joint->checkState() == Qt::Checked)
{
jointState = MMMPlayer->setJointsInUse(joint->text().toStdString(), true);
jointState = MMMPlayer->setJointsInUse(joint->text().toStdString(), false);
void MMMPlayerWidget::on_loopPlayback_toggled(bool state)
{
ui.loopPlayback->setChecked(MMMPlayer->setLoopPlayback(state));
}
void MMMPlayerWidget::on_controlMode_changed(int controlMode)
ui.controlMode->setCurrentIndex(MMMPlayer->setUsePID(controlMode));
}
Q_EXPORT_PLUGIN2(robotapi_gui_MMMPlayerGuiPlugin, MMMPlayerGuiPlugin)