27 #include <QProgressDialog>
28 #include <qnamespace.h>
35 #include <QFileDialog>
37 #include <QMessageBox>
38 #include <IceUtil/UUID.h>
40 #define REQUEST_TIMEKEEPER_TIME_FREQUENCY 30
68 this->setPausedGuiMode();
69 widget.pushButton_play->setEnabled(
false);
70 widget.pushButton_load->setFocus();
76 connect(widget.pushButton_load, SIGNAL(clicked()),
this, SLOT(loadFile()));
77 connect(widget.pushButton_play, SIGNAL(clicked()),
this, SLOT(resumeReplay()));
78 connect(widget.pushButton_pause, SIGNAL(clicked()),
this, SLOT(pauseReplay()));
79 connect(widget.checkBox_loop, SIGNAL(toggled()),
this, SLOT(loopReplay()));
80 connect(widget.horizontalSlider_replaySpeed, SIGNAL(valueChanged(
int)),
this, SLOT(replaySpeedSliderChanged()));
81 connect(widget.doubleSpinBox_replaySpeed, SIGNAL(editingFinished()),
this, SLOT(replaySpeedSpinBoxChanged()));
83 connect(widget.horizontalSlider_replayPosition, SIGNAL(valueChanged(
int)),
this, SLOT(replayPositionSliderChanged()));
85 connect(widget.horizontalSlider_replayPosition, SIGNAL(sliderPressed()),
this, SLOT(stopSliderUpdater()));
86 connect(widget.horizontalSlider_replayPosition, SIGNAL(sliderReleased()),
this, SLOT(startSliderUpdater()));
88 connect(widget.horizontalSlider_replayPosition, SIGNAL(sliderReleased()),
this, SLOT(jumpToPosition()));
91 void TopicReplayerWidgetController::onDisconnectComponent()
93 this->killTimer(replayPositionSliderUpdaterTimer);
100 void armarx::TopicReplayerWidgetController::loadFile()
102 widget.pushButton_load->setEnabled(
false);
104 QFileDialog fileDialog(getWidget(),
"Open Topic Recording File");
105 fileDialog.setFileMode(QFileDialog::ExistingFile);
107 filters << tr(
"TopicRecorder files (*.bag)");
108 filters << tr(
"All files (*.*)");
109 fileDialog.setNameFilters(filters);
112 fileDialog.setViewMode(QFileDialog::Detail);
113 fileDialog.setVisible(
true);
116 if (fileDialog.exec() == QDialog::Accepted)
118 fileName = fileDialog.selectedFiles().first();
121 getArmarXManager()->removeObjectBlocking(topicReplayer->getName());
124 if (!fileName.isEmpty())
127 properties->setProperty(
"ArmarX.TopicReplayer.RecordFile", fileName.toStdString());
128 topicReplayer = armarx::Component::create<TopicReplayer>(properties);
129 topicReplayer->setAutoplay(
false);
130 widget.doubleSpinBox_replaySpeed->setValue(1.0);
131 QProgressDialog dProgress;
132 dProgress.setMaximum(0);
133 dProgress.setMinimum(0);
134 getArmarXManager()->addObject(topicReplayer,
false, topicReplayer->getDefaultName() + IceUtil::generateUUID());
137 while (topicReplayer->getObjectScheduler()->getObject()->getState() < eManagedIceObjectStarted)
143 if (topicReplayer->getReplayLength().toMilliSeconds() == 0)
145 this->setPausedGuiMode();
146 widget.pushButton_play->setEnabled(
false);
147 widget.lineEdit_fileName->setText(
"");
148 widget.horizontalSlider_replayPosition->setValue(0);
149 widget.horizontalSlider_replayPosition->setEnabled(
false);
150 widget.horizontalSlider_replaySpeed->setEnabled(
false);
151 widget.listWidget_topics->clear();
154 msg.setWindowTitle(
"TopicReplayerGui");
155 msg.setText(
"The format of the selected file is not supported.");
156 msg.setIcon(QMessageBox::Warning);
161 widget.lineEdit_fileName->setText(fileName);
162 this->fillListOfRecordedTopics();
163 this->setUpReplayPositionSlider();
164 widget.pushButton_play->setEnabled(
true);
165 widget.horizontalSlider_replayPosition->setEnabled(
true);
166 widget.horizontalSlider_replaySpeed->setEnabled(
true);
173 widget.pushButton_load->setEnabled(
true);
176 void armarx::TopicReplayerWidgetController::pauseReplay()
178 this->setPausedGuiMode();
182 topicReplayer->pauseReplay();
186 void armarx::TopicReplayerWidgetController::loopReplay()
194 void armarx::TopicReplayerWidgetController::resumeReplay()
196 if (topicReplayer && !(this->replayLength.toMilliSeconds() == widget.horizontalSlider_replayPosition->value()))
198 std::vector<std::string> replayingTopics;
199 for (
int i = 0; i < widget.listWidget_topics->count(); i++)
201 auto item = widget.listWidget_topics->item(i);
202 if (item->checkState() == Qt::Checked)
204 replayingTopics.push_back(item->text().toStdString());
207 topicReplayer->setReplayingTopics(replayingTopics);
210 topicReplayer->resumeReplay();
212 this->setPlayingGuiMode();
216 void armarx::TopicReplayerWidgetController::setReplaySpeed()
220 topicReplayer->setReplaySpeed(widget.doubleSpinBox_replaySpeed->value());
224 void armarx::TopicReplayerWidgetController::replaySpeedSliderChanged()
226 updateReplayPositionSlider();
228 double spinBoxValue = 0.0;
229 int sliderValue = widget.horizontalSlider_replaySpeed->value();
230 int m = widget.horizontalSlider_replaySpeed->maximum() / 2;
234 spinBoxValue = (double) sliderValue / (
double) m;
238 spinBoxValue = 1 + 9.0 * ((double) sliderValue / (
double) m - 1);
241 widget.doubleSpinBox_replaySpeed->setValue(spinBoxValue);
245 void TopicReplayerWidgetController::replaySpeedSpinBoxChanged()
247 double spinBoxValue = widget.doubleSpinBox_replaySpeed->value();
249 int m = widget.horizontalSlider_replaySpeed->maximum() / 2;
251 if (spinBoxValue <= 1.0)
253 sliderValue = (int)(spinBoxValue * m);
257 sliderValue = (int)(m * (1 + (spinBoxValue - 1) / 9));
260 widget.horizontalSlider_replaySpeed->setValue(sliderValue);
265 void TopicReplayerWidgetController::fillListOfRecordedTopics()
267 QListWidget* topicsListWidget = widget.listWidget_topics;
268 topicsListWidget->clear();
270 const Qt::CheckState checkState = widget.checkBoxLoadTopicsEnabled->checkState();
272 if (this->topicReplayer)
274 std::vector<std::string> recordedTopics = topicReplayer->getRecordedTopics();
275 std::sort(recordedTopics.begin(), recordedTopics.end());
277 for (std::string topic : recordedTopics)
279 QListWidgetItem* item =
new QListWidgetItem;
280 item->setData(Qt::DisplayRole, QString::fromStdString(topic));
281 item->setData(Qt::CheckStateRole, checkState);
282 topicsListWidget->addItem(item);
287 void TopicReplayerWidgetController::setPausedGuiMode()
289 widget.pushButton_pause->setEnabled(
false);
291 widget.pushButton_load->setEnabled(
true);
292 widget.pushButton_play->setEnabled(
true);
293 widget.pushButton_play->setFocus();
294 widget.listWidget_topics->setEnabled(
true);
296 this->stopSliderUpdater();
299 void TopicReplayerWidgetController::setPlayingGuiMode()
301 widget.pushButton_load->setEnabled(
false);
302 widget.listWidget_topics->setEnabled(
false);
303 widget.pushButton_play->setEnabled(
false);
305 widget.pushButton_pause->setEnabled(
true);
306 widget.pushButton_pause->setFocus();
308 widget.horizontalSlider_replayPosition->setEnabled(
true);
309 widget.horizontalSlider_replaySpeed->setEnabled(
true);
311 this->startSliderUpdater();
314 void TopicReplayerWidgetController::setUpReplayPositionSlider()
318 replayLength = topicReplayer->getReplayLength();
320 t = t.addMSecs((
int)replayLength.toMilliSeconds());
321 widget.label_replayLength->setText(t.toString(
"h:mm:ss.zzz"));
322 widget.horizontalSlider_replayPosition->setMaximum((
int) replayLength.toMilliSeconds());
323 widget.horizontalSlider_replayPosition->setTickInterval((
int) replayLength.toMilliSeconds() / 100);
324 widget.horizontalSlider_replayPosition->setSingleStep((
int) replayLength.toMilliSeconds() / 100);
325 widget.horizontalSlider_replayPosition->setValue(0);
329 void TopicReplayerWidgetController::updateReplayPositionSlider()
333 int currentTime = (int) topicReplayer->getCurrentTimePosition().toMilliSeconds();
334 widget.horizontalSlider_replayPosition->setValue(currentTime);
335 if (currentTime >= replayLength.toMilliSeconds())
339 if (widget.checkBox_loop->isChecked())
341 widget.horizontalSlider_replayPosition->setSliderPosition(0);
349 void TopicReplayerWidgetController::replayPositionSliderChanged()
352 t = t.addMSecs(widget.horizontalSlider_replayPosition->value());
353 widget.label_replayPosition->setText(t.toString(
"h:mm:ss.zzz"));
357 void TopicReplayerWidgetController::timerEvent(QTimerEvent* event)
359 if (event->timerId() == this->replayPositionSliderUpdaterTimer)
361 this->updateReplayPositionSlider();
365 void TopicReplayerWidgetController::stopSliderUpdater()
367 this->killTimer(replayPositionSliderUpdaterTimer);
370 void TopicReplayerWidgetController::startSliderUpdater()
375 void TopicReplayerWidgetController::jumpToPosition()
379 topicReplayer->jumpToPosition(
IceUtil::Time().milliSeconds(widget.horizontalSlider_replayPosition->value()));