2025-01-04 04:12:51 +00:00
|
|
|
#include "PlayManagerMenu.h"
|
|
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
|
|
#include "ui/MainFrame.h"
|
|
|
|
|
#include "common/SpdLogger.h"
|
|
|
|
|
|
|
|
|
|
#include "workspace/Timestep.h"
|
|
|
|
|
#include "workspace/WorkSpaceManager.h"
|
|
|
|
|
|
|
|
|
|
#include "ui_PlayManagerMenu.h"
|
|
|
|
|
|
|
|
|
|
PlayManagerMenu::PlayManagerMenu(QWidget* parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, ui(new Ui::PlayManagerMenu) {
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
connect(&WorkSpaceManager::Get(), &WorkSpaceManager::WorkSpaceChanged,
|
|
|
|
|
this, &PlayManagerMenu::OnWorkspaceChange);
|
|
|
|
|
|
|
|
|
|
connect(ui->psbPlay, &QPushButton::clicked, this, &PlayManagerMenu::OnPlay);
|
|
|
|
|
connect(ui->psbStop, &QPushButton::clicked, this, &PlayManagerMenu::OnStop);
|
|
|
|
|
connect(ui->psbUp, &QPushButton::clicked, this, &PlayManagerMenu::OnUp);
|
|
|
|
|
connect(ui->psbDown, &QPushButton::clicked, this, &PlayManagerMenu::OnDown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayManagerMenu::~PlayManagerMenu() {
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlayManagerMenu::OnPlay() {
|
|
|
|
|
workSpace_ = WorkSpaceManager::Get().GetCurrent();
|
|
|
|
|
if (nullptr == workSpace_) {
|
2025-01-21 00:28:25 +00:00
|
|
|
QMessageBox::warning(&MainFrame::Get(), tr("warning"), tr("has not workspace"),
|
2025-01-04 04:12:51 +00:00
|
|
|
QMessageBox::Ok);
|
|
|
|
|
LOG_INFO("current is nullptr");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Timestep* timestep = workSpace_->GetTimestep();
|
|
|
|
|
if (nullptr == timestep) {
|
2025-07-06 14:34:23 +00:00
|
|
|
QMessageBox::warning(&MainFrame::Get(), tr("warning"), tr("not timestep"),
|
2025-01-04 04:12:51 +00:00
|
|
|
QMessageBox::Ok);
|
|
|
|
|
LOG_INFO("current is nullptr");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (timestep->IsStoped()) {
|
|
|
|
|
timestep->Start();
|
|
|
|
|
ui->psbPlay->setText(tr("pause"));
|
|
|
|
|
}
|
|
|
|
|
else if (timestep->IsPause()) {
|
|
|
|
|
timestep->Resume();
|
|
|
|
|
ui->psbPlay->setText(tr("pause"));
|
|
|
|
|
} else {
|
|
|
|
|
timestep->Pause();
|
|
|
|
|
ui->psbPlay->setText(tr("play"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlayManagerMenu::OnStop() {
|
|
|
|
|
workSpace_ = WorkSpaceManager::Get().GetCurrent();
|
|
|
|
|
if (nullptr == workSpace_) {
|
2025-01-21 00:28:25 +00:00
|
|
|
QMessageBox::warning(&MainFrame::Get(), tr("warning"), tr("has not workspace"),
|
2025-01-04 04:12:51 +00:00
|
|
|
QMessageBox::Ok);
|
|
|
|
|
LOG_INFO("current is nullptr");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Timestep* timestep = workSpace_->GetTimestep();
|
|
|
|
|
if (nullptr == timestep) {
|
2025-01-21 00:28:25 +00:00
|
|
|
QMessageBox::warning(&MainFrame::Get(), tr("warning"), tr("has not workspace"),
|
2025-01-04 04:12:51 +00:00
|
|
|
QMessageBox::Ok);
|
|
|
|
|
LOG_INFO("current is nullptr");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
timestep->Stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlayManagerMenu::OnUp() {
|
|
|
|
|
workSpace_ = WorkSpaceManager::Get().GetCurrent();
|
|
|
|
|
if (nullptr == workSpace_) {
|
2025-01-21 00:28:25 +00:00
|
|
|
QMessageBox::warning(&MainFrame::Get(), tr("warning"), tr("has not workspace"),
|
2025-01-04 04:12:51 +00:00
|
|
|
QMessageBox::Ok);
|
|
|
|
|
LOG_INFO("current is nullptr");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Timestep* timestep = workSpace_->GetTimestep();
|
|
|
|
|
if (nullptr == timestep) {
|
2025-01-21 00:28:25 +00:00
|
|
|
QMessageBox::warning(&MainFrame::Get(), tr("warning"), tr("has not workspace"),
|
2025-01-04 04:12:51 +00:00
|
|
|
QMessageBox::Ok);
|
|
|
|
|
LOG_INFO("current is nullptr");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
timestep->Up();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlayManagerMenu::OnDown() {
|
|
|
|
|
workSpace_ = WorkSpaceManager::Get().GetCurrent();
|
|
|
|
|
if (nullptr == workSpace_) {
|
2025-01-21 00:28:25 +00:00
|
|
|
QMessageBox::warning(&MainFrame::Get(), tr("warning"), tr("has not workspace"),
|
2025-01-04 04:12:51 +00:00
|
|
|
QMessageBox::Ok);
|
|
|
|
|
LOG_INFO("current is nullptr");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Timestep* timestep = workSpace_->GetTimestep();
|
|
|
|
|
if (nullptr == timestep) {
|
2025-01-21 00:28:25 +00:00
|
|
|
QMessageBox::warning(&MainFrame::Get(), tr("warning"), tr("has not workspace"),
|
2025-01-04 04:12:51 +00:00
|
|
|
QMessageBox::Ok);
|
|
|
|
|
LOG_INFO("current is nullptr");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
timestep->Down();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PlayManagerMenu::OnWorkspaceChange(WorkSpace* workSpace) {
|
|
|
|
|
if (nullptr == workSpace) {
|
2025-01-05 11:12:18 +00:00
|
|
|
LOG_WARN("current is nullptr");
|
2025-01-04 04:12:51 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
workSpace_ = workSpace;
|
2025-01-05 11:12:18 +00:00
|
|
|
connect(workSpace, &WorkSpace::TimestepChanged, this, &PlayManagerMenu::OnTimestepChanged);
|
|
|
|
|
}
|
2025-01-04 04:12:51 +00:00
|
|
|
|
2025-01-05 11:12:18 +00:00
|
|
|
void PlayManagerMenu::OnTimestepChanged(Timestep* timestep) {
|
2025-01-04 04:12:51 +00:00
|
|
|
double step = 0.0;
|
|
|
|
|
timestep->GetRange(minTime_, maxTime_, step);
|
|
|
|
|
ui->lbtime->setText(QString::number(minTime_, 'f', 3));
|
|
|
|
|
ui->lbtimeTotal->setText(QString("/%1(s)").arg(maxTime_));
|
|
|
|
|
ui->lbUp->setText(QString("x%1").arg(step));
|
|
|
|
|
|
|
|
|
|
ui->horizontalSlider->setRange((int)(minTime_ * 1000), (int)(maxTime_ * 1000));
|
|
|
|
|
|
|
|
|
|
connect(timestep, &Timestep::TimeChanged, [this](double dt) {
|
|
|
|
|
ui->lbtime->setText(QString::number(dt, 'f', 3));
|
|
|
|
|
dt *= 1000;
|
|
|
|
|
ui->horizontalSlider->setValue(int(dt));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
connect(timestep, &Timestep::StepChanged, [this](double step) {
|
|
|
|
|
ui->lbUp->setText(QString("x%1").arg(step));
|
|
|
|
|
}
|
|
|
|
|
);
|
2025-01-05 11:12:18 +00:00
|
|
|
|
|
|
|
|
connect(timestep, &Timestep::StatusChanged, [this](int statue) {
|
|
|
|
|
Timestep::PlayStatus state = static_cast<Timestep::PlayStatus>(statue);
|
|
|
|
|
switch (state) {
|
|
|
|
|
case Timestep::PlayStatus::PS_Started:
|
|
|
|
|
ui->psbPlay->setText(tr("pause"));
|
|
|
|
|
break;
|
|
|
|
|
case Timestep::PlayStatus::PS_Stoped: {
|
|
|
|
|
ui->psbPlay->setText(tr("play"));
|
|
|
|
|
ui->lbtime->setText(QString::number(minTime_, 'f', 3));
|
|
|
|
|
ui->lbtimeTotal->setText(QString("/%1(s)").arg(maxTime_));
|
|
|
|
|
ui->horizontalSlider->setValue(0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Timestep::PlayStatus::PS_Suspended:
|
|
|
|
|
ui->psbPlay->setText(tr("play"));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|