29 #include <QFileDialog>
30 #include <QMessageBox>
31 #include <QProgressDialog>
32 #include <qnamespace.h>
34 #include <IceUtil/UUID.h>
40 #define REQUEST_TIMEKEEPER_TIME_FREQUENCY 30
66 this->setPausedGuiMode();
67 widget.pushButton_play->setEnabled(
false);
68 widget.pushButton_load->setFocus();
74 connect(widget.pushButton_load, SIGNAL(clicked()),
this, SLOT(loadFile()));
75 connect(widget.pushButton_play, SIGNAL(clicked()),
this, SLOT(resumeReplay()));
76 connect(widget.pushButton_pause, SIGNAL(clicked()),
this, SLOT(pauseReplay()));
77 connect(widget.checkBox_loop, SIGNAL(toggled()),
this, SLOT(loopReplay()));
78 connect(widget.horizontalSlider_replaySpeed,
79 SIGNAL(valueChanged(
int)),
81 SLOT(replaySpeedSliderChanged()));
82 connect(widget.doubleSpinBox_replaySpeed,
83 SIGNAL(editingFinished()),
85 SLOT(replaySpeedSpinBoxChanged()));
87 connect(widget.horizontalSlider_replayPosition,
88 SIGNAL(valueChanged(
int)),
90 SLOT(replayPositionSliderChanged()));
92 connect(widget.horizontalSlider_replayPosition,
93 SIGNAL(sliderPressed()),
95 SLOT(stopSliderUpdater()));
96 connect(widget.horizontalSlider_replayPosition,
97 SIGNAL(sliderReleased()),
99 SLOT(startSliderUpdater()));
101 connect(widget.horizontalSlider_replayPosition,
102 SIGNAL(sliderReleased()),
104 SLOT(jumpToPosition()));
108 TopicReplayerWidgetController::onDisconnectComponent()
110 this->killTimer(replayPositionSliderUpdaterTimer);
118 armarx::TopicReplayerWidgetController::loadFile()
120 widget.pushButton_load->setEnabled(
false);
122 QFileDialog fileDialog(getWidget(),
"Open Topic Recording File");
123 fileDialog.setFileMode(QFileDialog::ExistingFile);
125 filters << tr(
"TopicRecorder files (*.bag)");
126 filters << tr(
"All files (*.*)");
127 fileDialog.setNameFilters(filters);
130 fileDialog.setViewMode(QFileDialog::Detail);
131 fileDialog.setVisible(
true);
134 if (fileDialog.exec() == QDialog::Accepted)
136 fileName = fileDialog.selectedFiles().first();
139 getArmarXManager()->removeObjectBlocking(topicReplayer->getName());
142 if (!fileName.isEmpty())
145 properties->setProperty(
"ArmarX.TopicReplayer.RecordFile", fileName.toStdString());
146 topicReplayer = armarx::Component::create<TopicReplayer>(properties);
147 topicReplayer->setAutoplay(
false);
148 widget.doubleSpinBox_replaySpeed->setValue(1.0);
149 QProgressDialog dProgress;
150 dProgress.setMaximum(0);
151 dProgress.setMinimum(0);
152 getArmarXManager()->addObject(topicReplayer,
154 topicReplayer->getDefaultName() +
155 IceUtil::generateUUID());
158 while (topicReplayer->getObjectScheduler()->getObject()->getState() <
159 eManagedIceObjectStarted)
165 if (topicReplayer->getReplayLength().toMilliSeconds() == 0)
167 this->setPausedGuiMode();
168 widget.pushButton_play->setEnabled(
false);
169 widget.lineEdit_fileName->setText(
"");
170 widget.horizontalSlider_replayPosition->setValue(0);
171 widget.horizontalSlider_replayPosition->setEnabled(
false);
172 widget.horizontalSlider_replaySpeed->setEnabled(
false);
173 widget.listWidget_topics->clear();
176 msg.setWindowTitle(
"TopicReplayerGui");
177 msg.setText(
"The format of the selected file is not supported.");
178 msg.setIcon(QMessageBox::Warning);
183 widget.lineEdit_fileName->setText(fileName);
184 this->fillListOfRecordedTopics();
185 this->setUpReplayPositionSlider();
186 widget.pushButton_play->setEnabled(
true);
187 widget.horizontalSlider_replayPosition->setEnabled(
true);
188 widget.horizontalSlider_replaySpeed->setEnabled(
true);
190 replayPositionSliderUpdaterTimer =
196 widget.pushButton_load->setEnabled(
true);
200 armarx::TopicReplayerWidgetController::pauseReplay()
202 this->setPausedGuiMode();
206 topicReplayer->pauseReplay();
211 armarx::TopicReplayerWidgetController::loopReplay()
220 armarx::TopicReplayerWidgetController::resumeReplay()
222 if (topicReplayer && !(this->replayLength.toMilliSeconds() ==
223 widget.horizontalSlider_replayPosition->value()))
225 std::vector<std::string> replayingTopics;
226 for (
int i = 0; i < widget.listWidget_topics->count(); i++)
228 auto item = widget.listWidget_topics->item(i);
229 if (item->checkState() == Qt::Checked)
231 replayingTopics.push_back(item->text().toStdString());
234 topicReplayer->setReplayingTopics(replayingTopics);
237 topicReplayer->resumeReplay();
239 this->setPlayingGuiMode();
244 armarx::TopicReplayerWidgetController::setReplaySpeed()
248 topicReplayer->setReplaySpeed(widget.doubleSpinBox_replaySpeed->value());
253 armarx::TopicReplayerWidgetController::replaySpeedSliderChanged()
255 updateReplayPositionSlider();
257 double spinBoxValue = 0.0;
258 int sliderValue = widget.horizontalSlider_replaySpeed->value();
259 int m = widget.horizontalSlider_replaySpeed->maximum() / 2;
263 spinBoxValue = (double)sliderValue / (
double)m;
267 spinBoxValue = 1 + 9.0 * ((double)sliderValue / (
double)m - 1);
270 widget.doubleSpinBox_replaySpeed->setValue(spinBoxValue);
275 TopicReplayerWidgetController::replaySpeedSpinBoxChanged()
277 double spinBoxValue = widget.doubleSpinBox_replaySpeed->value();
279 int m = widget.horizontalSlider_replaySpeed->maximum() / 2;
281 if (spinBoxValue <= 1.0)
283 sliderValue = (int)(spinBoxValue * m);
287 sliderValue = (int)(m * (1 + (spinBoxValue - 1) / 9));
290 widget.horizontalSlider_replaySpeed->setValue(sliderValue);
295 TopicReplayerWidgetController::fillListOfRecordedTopics()
297 QListWidget* topicsListWidget = widget.listWidget_topics;
298 topicsListWidget->clear();
300 const Qt::CheckState checkState = widget.checkBoxLoadTopicsEnabled->checkState();
302 if (this->topicReplayer)
304 std::vector<std::string> recordedTopics = topicReplayer->getRecordedTopics();
305 std::sort(recordedTopics.begin(), recordedTopics.end());
307 for (std::string topic : recordedTopics)
309 QListWidgetItem* item =
new QListWidgetItem;
310 item->setData(Qt::DisplayRole, QString::fromStdString(topic));
311 item->setData(Qt::CheckStateRole, checkState);
312 topicsListWidget->addItem(item);
318 TopicReplayerWidgetController::setPausedGuiMode()
320 widget.pushButton_pause->setEnabled(
false);
322 widget.pushButton_load->setEnabled(
true);
323 widget.pushButton_play->setEnabled(
true);
324 widget.pushButton_play->setFocus();
325 widget.listWidget_topics->setEnabled(
true);
327 this->stopSliderUpdater();
331 TopicReplayerWidgetController::setPlayingGuiMode()
333 widget.pushButton_load->setEnabled(
false);
334 widget.listWidget_topics->setEnabled(
false);
335 widget.pushButton_play->setEnabled(
false);
337 widget.pushButton_pause->setEnabled(
true);
338 widget.pushButton_pause->setFocus();
340 widget.horizontalSlider_replayPosition->setEnabled(
true);
341 widget.horizontalSlider_replaySpeed->setEnabled(
true);
343 this->startSliderUpdater();
347 TopicReplayerWidgetController::setUpReplayPositionSlider()
351 replayLength = topicReplayer->getReplayLength();
353 t = t.addMSecs((
int)replayLength.toMilliSeconds());
354 widget.label_replayLength->setText(t.toString(
"h:mm:ss.zzz"));
355 widget.horizontalSlider_replayPosition->setMaximum((
int)replayLength.toMilliSeconds());
356 widget.horizontalSlider_replayPosition->setTickInterval(
357 (
int)replayLength.toMilliSeconds() / 100);
358 widget.horizontalSlider_replayPosition->setSingleStep(
359 (
int)replayLength.toMilliSeconds() / 100);
360 widget.horizontalSlider_replayPosition->setValue(0);
365 TopicReplayerWidgetController::updateReplayPositionSlider()
369 int currentTime = (int)topicReplayer->getCurrentTimePosition().toMilliSeconds();
370 widget.horizontalSlider_replayPosition->setValue(currentTime);
371 if (currentTime >= replayLength.toMilliSeconds())
375 if (widget.checkBox_loop->isChecked())
377 widget.horizontalSlider_replayPosition->setSliderPosition(0);
386 TopicReplayerWidgetController::replayPositionSliderChanged()
389 t = t.addMSecs(widget.horizontalSlider_replayPosition->value());
390 widget.label_replayPosition->setText(t.toString(
"h:mm:ss.zzz"));
394 TopicReplayerWidgetController::timerEvent(QTimerEvent* event)
396 if (event->timerId() == this->replayPositionSliderUpdaterTimer)
398 this->updateReplayPositionSlider();
403 TopicReplayerWidgetController::stopSliderUpdater()
405 this->killTimer(replayPositionSliderUpdaterTimer);
409 TopicReplayerWidgetController::startSliderUpdater()
415 TopicReplayerWidgetController::jumpToPosition()
419 topicReplayer->jumpToPosition(
420 IceUtil::Time().milliSeconds(widget.horizontalSlider_replayPosition->value()));