#include "utils/TransformPath.h" #include #include #include "common/SpdLogger.h" TransformPath::TransformPath(QObject* parent /*= nullptr*/) : QObject(parent) { } TransformPath::TransformPath(std::vector transforms, QObject* parent /*= nullptr*/) : QObject(parent) , transforms_(std::move(transforms)){ } TransformPath::~TransformPath() { } TransformPath* TransformPath::LoadFromFile(const QString& path, QObject* parent) { LOG_INFO("Loading transform path from file: {}", path.toLocal8Bit().constData()); QFile file(path); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { LOG_WARN("Cannot open file for reading: path:{} error:{}", path.toLocal8Bit().constData(), file.errorString().toLocal8Bit().constData()); return nullptr; } QTextStream in(&file); std::vector 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) { transform.GetLocation()[i] = value; } 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); }