#include "PlayManagerMenu.h" #include #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_) { QMessageBox::warning(&MainFrame::Get(), tr("question"), tr("has not workspace"), QMessageBox::Ok); LOG_INFO("current is nullptr"); return; } Timestep* timestep = workSpace_->GetTimestep(); if (nullptr == timestep) { QMessageBox::warning(&MainFrame::Get(), tr("question"), tr("has not workspace"), 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_) { QMessageBox::warning(&MainFrame::Get(), tr("question"), tr("has not workspace"), QMessageBox::Ok); LOG_INFO("current is nullptr"); return; } Timestep* timestep = workSpace_->GetTimestep(); if (nullptr == timestep) { QMessageBox::warning(&MainFrame::Get(), tr("question"), tr("has not workspace"), QMessageBox::Ok); LOG_INFO("current is nullptr"); return; } timestep->Stop(); } void PlayManagerMenu::OnUp() { workSpace_ = WorkSpaceManager::Get().GetCurrent(); if (nullptr == workSpace_) { QMessageBox::warning(&MainFrame::Get(), tr("question"), tr("has not workspace"), QMessageBox::Ok); LOG_INFO("current is nullptr"); return; } Timestep* timestep = workSpace_->GetTimestep(); if (nullptr == timestep) { QMessageBox::warning(&MainFrame::Get(), tr("question"), tr("has not workspace"), QMessageBox::Ok); LOG_INFO("current is nullptr"); return; } timestep->Up(); } void PlayManagerMenu::OnDown() { workSpace_ = WorkSpaceManager::Get().GetCurrent(); if (nullptr == workSpace_) { QMessageBox::warning(&MainFrame::Get(), tr("question"), tr("has not workspace"), QMessageBox::Ok); LOG_INFO("current is nullptr"); return; } Timestep* timestep = workSpace_->GetTimestep(); if (nullptr == timestep) { QMessageBox::warning(&MainFrame::Get(), tr("question"), tr("has not workspace"), QMessageBox::Ok); LOG_INFO("current is nullptr"); return; } timestep->Down(); } void PlayManagerMenu::OnWorkspaceChange(WorkSpace* workSpace) { if (nullptr == workSpace) { return; } workSpace_ = workSpace; Timestep* timestep = workSpace_->GetTimestep(); if (nullptr == timestep) { LOG_INFO("current is nullptr"); return; } 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)); } ); }