58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
#include "workspace/LampStatus.h"
|
|
|
|
#include <QFile>
|
|
#include <QTextStream>
|
|
|
|
#include "workspace/WorkSpace.h"
|
|
|
|
#include "common/RecourceHelper.h"
|
|
#include "common/SpdLogger.h"
|
|
|
|
LampStatus::LampStatus(const std::vector<int>& status, const QString& path, WorkSpace* parent /*= nullptr*/) noexcept
|
|
: QObject((QObject*)parent)
|
|
, status_(status)
|
|
, path_(path)
|
|
, workSpace_(parent) {
|
|
}
|
|
|
|
LampStatus* LampStatus::Load(const QString& path, WorkSpace* parent) {
|
|
const QString filePath = QString("%1/%2").arg(RecourceHelper::Get().GetBasePath()).arg(path);
|
|
LOG_INFO("Load LampStatus: {}", filePath.toStdString());
|
|
|
|
QFile file(filePath);
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
LOG_WARN("Cannot open file for reading: {}", file.errorString().toStdString());
|
|
return nullptr;
|
|
}
|
|
|
|
QTextStream in(&file);
|
|
std::vector<int> numbers;
|
|
|
|
while (!in.atEnd()) {
|
|
QString line = in.readLine();
|
|
bool ok;
|
|
double value = line.toDouble(&ok);
|
|
if (ok) {
|
|
int status = static_cast<int>(value);
|
|
numbers.push_back(status);
|
|
} else {
|
|
LOG_WARN("Cannot open file for reading: {}", line.toStdString());
|
|
}
|
|
}
|
|
|
|
file.close();
|
|
|
|
LampStatus* lampStatus = new LampStatus(numbers, path, parent);
|
|
return lampStatus;
|
|
}
|
|
|
|
void LampStatus::OnFrame(double dt) {
|
|
int status = static_cast<int>(dt);
|
|
if (status >= status_.size()) {
|
|
return;
|
|
}
|
|
|
|
current_ = status;
|
|
emit StatusChanged(GetCurrent());
|
|
}
|