2025-10-26 07:55:41 +00:00
|
|
|
#include "workspace/FileEntry.h"
|
|
|
|
|
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
|
|
|
|
#include "common/SpdLogger.h"
|
|
|
|
|
|
|
|
|
|
void FileEntry::SetPath(const QString& path) {
|
|
|
|
|
QFileInfo fileInfo(path);
|
|
|
|
|
if (!fileInfo.exists()) {
|
|
|
|
|
LOG_WARN("file not exist: {}", path.toLocal8Bit().constData());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
path_ = fileInfo.path();
|
|
|
|
|
fileName_ = fileInfo.fileName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Factory function implementations
|
|
|
|
|
std::shared_ptr<FileEntry> CreateFileEntry(FileEntryType type, const QString& filePath) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case FileEntryType::Curve:
|
|
|
|
|
return CreateFileEntryCurve(filePath);
|
|
|
|
|
case FileEntryType::Surface:
|
|
|
|
|
return CreateFileEntrySurface(filePath);
|
|
|
|
|
case FileEntryType::Table:
|
|
|
|
|
return CreateFileEntryTable(filePath);
|
|
|
|
|
case FileEntryType::Light:
|
|
|
|
|
return CreateFileEntryLight(filePath);
|
|
|
|
|
default:
|
|
|
|
|
LOG_ERROR("Unknown FileEntryType: {}", static_cast<int>(type));
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<FileEntryCurve> CreateFileEntryCurve(const QString& filePath) {
|
|
|
|
|
QFileInfo fileInfo(filePath);
|
|
|
|
|
if (!fileInfo.exists()) {
|
|
|
|
|
LOG_ERROR("File does not exist: {}", filePath.toUtf8().constData());
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto fileEntry = std::make_shared<FileEntryCurve>();
|
|
|
|
|
fileEntry->SetPath(filePath);
|
|
|
|
|
fileEntry->SetName(fileInfo.baseName()); // Use base name as default display name
|
|
|
|
|
|
|
|
|
|
return fileEntry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<FileEntry> CreateFileEntrySurface(const QString& filePath) {
|
2025-10-26 09:48:34 +00:00
|
|
|
QFileInfo fileInfo(filePath);
|
|
|
|
|
if (!fileInfo.exists()) {
|
|
|
|
|
LOG_ERROR("File does not exist: {}", filePath.toUtf8().constData());
|
|
|
|
|
return nullptr;
|
2025-10-26 07:55:41 +00:00
|
|
|
}
|
|
|
|
|
|
2025-10-26 09:48:34 +00:00
|
|
|
auto fileEntry = std::make_shared<FileEntrySurface>();
|
|
|
|
|
fileEntry->SetPath(filePath);
|
|
|
|
|
fileEntry->SetName(fileInfo.baseName()); // Use base name as default display name
|
|
|
|
|
|
2025-10-26 07:55:41 +00:00
|
|
|
return fileEntry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<FileEntry> CreateFileEntryTable(const QString& filePath) {
|
|
|
|
|
auto fileEntry = std::make_shared<FileEntry>();
|
|
|
|
|
fileEntry->SetType(FileEntryType::Table);
|
|
|
|
|
|
|
|
|
|
if (!filePath.isEmpty()) {
|
|
|
|
|
fileEntry->SetPath(filePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fileEntry;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-26 08:44:23 +00:00
|
|
|
std::shared_ptr<FileEntryLight> CreateFileEntryLight(const QString& filePath) {
|
|
|
|
|
QFileInfo fileInfo(filePath);
|
|
|
|
|
if (!fileInfo.exists()) {
|
|
|
|
|
LOG_ERROR("File does not exist: {}", filePath.toUtf8().constData());
|
|
|
|
|
return nullptr;
|
2025-10-26 07:55:41 +00:00
|
|
|
}
|
2025-10-26 08:44:23 +00:00
|
|
|
|
|
|
|
|
auto fileEntry = std::make_shared<FileEntryLight>();
|
|
|
|
|
fileEntry->SetPath(filePath);
|
|
|
|
|
fileEntry->SetName(fileInfo.baseName()); // Use base name as default display name
|
|
|
|
|
|
2025-10-26 07:55:41 +00:00
|
|
|
return fileEntry;
|
2025-10-26 09:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FileEntrySurface method implementations
|
|
|
|
|
void FileEntrySurface::SetChartProperties(const ChartProperties& properties) {
|
|
|
|
|
chartProperties_ = properties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FileEntrySurface::ChartProperties& FileEntrySurface::GetChartProperties() const {
|
|
|
|
|
return chartProperties_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntrySurface::AddSurfaceProperty(const SurfaceProperty& surface) {
|
|
|
|
|
surfaceProperties_.append(surface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntrySurface::RemoveSurfaceProperty(int index) {
|
|
|
|
|
if (index >= 0 && index < surfaceProperties_.size()) {
|
|
|
|
|
surfaceProperties_.removeAt(index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntrySurface::SetSurfaceProperty(int index, const SurfaceProperty& surface) {
|
|
|
|
|
if (index >= 0 && index < surfaceProperties_.size()) {
|
|
|
|
|
surfaceProperties_[index] = surface;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FileEntrySurface::SurfaceProperties& FileEntrySurface::GetSurfaceProperties() const {
|
|
|
|
|
return surfaceProperties_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileEntrySurface* FileEntrySurface::AsSurface() {
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileEntrySurface::SetDescription(const QString& description) {
|
|
|
|
|
description_ = description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString& FileEntrySurface::GetDescription() const {
|
|
|
|
|
return description_;
|
2025-10-26 07:55:41 +00:00
|
|
|
}
|