2025-01-04 04:12:51 +00:00
|
|
|
#include "utils/TransformPath.h"
|
|
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
|
|
|
|
|
#include "common/SpdLogger.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TransformPath::TransformPath(QObject* parent /*= nullptr*/)
|
|
|
|
|
: QObject(parent) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TransformPath::TransformPath(std::vector<Transform> transforms, QObject* parent /*= nullptr*/)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
, transforms_(std::move(transforms)){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TransformPath::~TransformPath() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TransformPath* TransformPath::LoadFromFile(const QString& path, QObject* parent) {
|
2025-01-21 18:42:57 +00:00
|
|
|
LOG_INFO("Loading transform path from file: {}", path.toLocal8Bit().constData());
|
2025-01-04 04:12:51 +00:00
|
|
|
QFile file(path);
|
|
|
|
|
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
2025-01-05 15:12:58 +00:00
|
|
|
LOG_WARN("Cannot open file for reading: path:{} error:{}",
|
2025-01-07 18:37:28 +00:00
|
|
|
path.toLocal8Bit().constData(), file.errorString().toLocal8Bit().constData());
|
2025-01-04 04:12:51 +00:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTextStream in(&file);
|
|
|
|
|
|
|
|
|
|
std::vector<Transform> transforms;
|
|
|
|
|
|
|
|
|
|
while (!in.atEnd()) {
|
|
|
|
|
Transform transform;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
|
QString line = in.readLine();
|
|
|
|
|
bool ok;
|
|
|
|
|
double value = line.toDouble(&ok);
|
|
|
|
|
if (ok) {
|
2025-01-21 18:42:57 +00:00
|
|
|
transform.GetLocation()[i] = value;
|
2025-01-04 04:12:51 +00:00
|
|
|
} else {
|
|
|
|
|
LOG_WARN("Failed to convert line to double: {}", line.toStdString());
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
|
QString line = in.readLine();
|
|
|
|
|
bool ok;
|
|
|
|
|
double value = line.toDouble(&ok);
|
|
|
|
|
if (ok) {
|
|
|
|
|
transform.GetRotation()[i] = value;
|
|
|
|
|
} else {
|
|
|
|
|
LOG_WARN("Failed to convert line to double: {}", line.toStdString());
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
transforms.push_back(transform);
|
|
|
|
|
}
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
|
return new TransformPath(std::move(transforms), parent);
|
|
|
|
|
}
|