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>
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#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 CONFIG_FILE_DEFAULT "/home/SMBAD/grube/armarx/Armar4/data/Armar4/motions/armar4.walking.mmm.xml"
#define PROJECT_DEFAULT "Armar4"
#define CONFIG_FILE_DEFAULT "Armar4/motions/armar4.walking.mmm.xml"
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);
// ui.frameSlider->setEnabled(false);
}
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());
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
on_loopPlayback_toggled(false);
connectSlots();
}
void MMMPlayerWidget::onExitComponent()
{
}
void MMMPlayerWidget::onDisconnectComponent()
{
}
void MMMPlayerWidget::loadSettings(QSettings *settings)
{
}
void MMMPlayerWidget::saveSettings(QSettings *settings)
{
}
void MMMPlayerWidget::connectSlots()
{
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*)));
}
void armarx::MMMPlayerWidget::on_startButton_clicked()
{
bool started = MMMPlayer->startMMMPlayer();
if (started)
{
updateTimer->start(100);
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();
if(paused)
{
updateTimer->stop();
ui.pauseButton->setText("Resume");
}
else
{
updateTimer->start(100);
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();
if(stopped)
{
updateTimer->stop();
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(!(ui.loopPlayback->isChecked()))
if(currentFrame >= ui.frameSlider->maximum() || currentFrame <= 0)
on_stopButton_clicked();
ui.frameSlider->blockSignals(false);
ui.currentFrame->display(currentFrame);
}
void MMMPlayerWidget::jointListChanged(QListWidgetItem* joint)
jointState = MMMPlayer->setJointsInUse(joint->text().toStdString(), true);
else
jointState = MMMPlayer->setJointsInUse(joint->text().toStdString(), false);
if(jointState)
joint->setCheckState(Qt::Checked);
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)