2025-01-04 04:12:51 +00:00
|
|
|
#include "FileManagerMenu.h"
|
|
|
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
|
|
#include "app/Application.h"
|
|
|
|
|
#include "common/RecourceHelper.h"
|
|
|
|
|
|
|
|
|
|
#include "ui/MainFrame.h"
|
|
|
|
|
#include "ui/WorkSpace/WorkSpaceDlg.h"
|
2025-10-22 17:40:44 +00:00
|
|
|
#include "ui/WorkSpace/AddFileDialogFactory.h"
|
|
|
|
|
#include "ui/WorkSpace/BaseAddFileDlg.h"
|
2025-01-04 04:12:51 +00:00
|
|
|
|
|
|
|
|
#include "common/SpdLogger.h"
|
|
|
|
|
#include "workspace/WorkSpace.h"
|
|
|
|
|
#include "workspace/WorkSpaceManager.h"
|
2025-10-12 14:14:16 +00:00
|
|
|
#include "workspace/FileEntry.h"
|
2025-01-21 18:42:57 +00:00
|
|
|
#include "utils/FileUtils.h"
|
2025-01-04 04:12:51 +00:00
|
|
|
|
|
|
|
|
#include "ui_FileManagerMenu.h"
|
|
|
|
|
|
|
|
|
|
FileManagerMenu::FileManagerMenu(QWidget* parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, ui(new Ui::FileManagerMenu) {
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
InitConnect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileManagerMenu::~FileManagerMenu() {
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManagerMenu::InitConnect() {
|
|
|
|
|
connect(ui->menu_new_file, &QToolButton::clicked, this, &FileManagerMenu::NewWorkSpace);
|
|
|
|
|
connect(ui->menu_open_file, &QToolButton::clicked, this, &FileManagerMenu::OpenWorkSpace);
|
|
|
|
|
connect(ui->menu_save_file, &QToolButton::clicked, this, &FileManagerMenu::SaveWorkSpace);
|
2025-10-12 14:14:16 +00:00
|
|
|
|
|
|
|
|
// add file entity buttons
|
|
|
|
|
connect(ui->menu_wave_file, &QToolButton::clicked, this, &FileManagerMenu::AddWaveFile);
|
|
|
|
|
connect(ui->menu_surface_file, &QToolButton::clicked, this, &FileManagerMenu::AddSurfaceFile);
|
|
|
|
|
connect(ui->menu_table_file, &QToolButton::clicked, this, &FileManagerMenu::AddTableFile);
|
|
|
|
|
connect(ui->menu_light_file, &QToolButton::clicked, this, &FileManagerMenu::AddLightFile);
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManagerMenu::NewWorkSpace() {
|
|
|
|
|
LOG_INFO("click newworkspace");
|
|
|
|
|
WorkSpaceDlg* dlg = new WorkSpaceDlg(&MainFrame::Get());
|
|
|
|
|
dlg->exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManagerMenu::OpenWorkSpace() {
|
2025-10-20 18:17:40 +00:00
|
|
|
QString fileName = QFileDialog::getOpenFileName(&MainFrame::Get(),
|
|
|
|
|
QObject::tr("Open Workspace"), Application::GetWorkSpacePath(), QObject::tr("Dyt Files (*.dyt)"));
|
|
|
|
|
if (fileName.isEmpty()) {
|
2025-01-04 04:12:51 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-20 18:17:40 +00:00
|
|
|
LOG_INFO("open workspace: {}", fileName.toLocal8Bit().constData());
|
|
|
|
|
emit LoadDyt(fileName);
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManagerMenu::SaveWorkSpace() {
|
2025-10-20 18:17:40 +00:00
|
|
|
auto current = WorkSpaceManager::Get().GetCurrent();
|
|
|
|
|
if (nullptr == current) {
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first"));
|
2025-01-04 04:12:51 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-20 18:17:40 +00:00
|
|
|
QString fileName = current->GetPath();
|
|
|
|
|
if (fileName.isEmpty()) {
|
|
|
|
|
fileName = QFileDialog::getSaveFileName(&MainFrame::Get(),
|
|
|
|
|
QObject::tr("Save Workspace"), Application::GetWorkSpacePath(), QObject::tr("Dyt Files (*.dyt)"));
|
|
|
|
|
if (fileName.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
current->Save(fileName);
|
|
|
|
|
} else {
|
|
|
|
|
current->Save();
|
|
|
|
|
}
|
2025-01-21 18:42:57 +00:00
|
|
|
|
2025-10-20 18:17:40 +00:00
|
|
|
LOG_INFO("save workspace: {}", fileName.toLocal8Bit().constData());
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-22 17:40:44 +00:00
|
|
|
// Removed old AddFile method - replaced by specific type methods
|
|
|
|
|
|
|
|
|
|
void FileManagerMenu::AddWaveFile() {
|
2025-10-20 18:17:40 +00:00
|
|
|
auto current = WorkSpaceManager::Get().GetCurrent();
|
|
|
|
|
if (nullptr == current) {
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-22 17:40:44 +00:00
|
|
|
// Show curve file addition dialog
|
|
|
|
|
auto dialog = AddFileDialogFactory::createDialog(FileEntryType::Curve, &MainFrame::Get());
|
|
|
|
|
if (dialog && dialog->exec() == QDialog::Accepted) {
|
|
|
|
|
QString selectedPath = dialog->getSelectedFilePath();
|
2025-10-20 18:17:40 +00:00
|
|
|
|
|
|
|
|
// Create file entry
|
2025-10-22 17:40:44 +00:00
|
|
|
switch (current->CreateFileEntry(FileEntryType::Curve)) {
|
2025-10-20 18:17:40 +00:00
|
|
|
case WorkSpace::FileEntryResult::Ok: {
|
|
|
|
|
// Get the index of the newly created file entry
|
2025-10-22 17:40:44 +00:00
|
|
|
auto entries = current->GetFileEntries(FileEntryType::Curve);
|
2025-10-20 18:17:40 +00:00
|
|
|
int newIndex = static_cast<int>(entries.size()) - 1;
|
|
|
|
|
|
|
|
|
|
// Set file path
|
2025-10-22 17:40:44 +00:00
|
|
|
if (!current->SetFileEntryPath(FileEntryType::Curve, newIndex, selectedPath)) {
|
2025-10-20 18:17:40 +00:00
|
|
|
QMessageBox::warning(&MainFrame::Get(), QObject::tr("Error"),
|
|
|
|
|
QObject::tr("Failed to set file path"));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case WorkSpace::FileEntryResult::LimitExceeded:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("up to 9 files allowed for this type"));
|
|
|
|
|
break;
|
|
|
|
|
case WorkSpace::FileEntryResult::Duplicate:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("file already added for this type"));
|
|
|
|
|
break;
|
|
|
|
|
case WorkSpace::FileEntryResult::CopyFailed:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("copy file failed"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
2025-10-12 14:14:16 +00:00
|
|
|
|
|
|
|
|
void FileManagerMenu::AddSurfaceFile() {
|
|
|
|
|
auto current = WorkSpaceManager::Get().GetCurrent();
|
|
|
|
|
if (nullptr == current) {
|
2025-10-20 18:17:40 +00:00
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first"));
|
2025-10-12 14:14:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-22 17:40:44 +00:00
|
|
|
// Show surface file addition dialog
|
|
|
|
|
auto dialog = AddFileDialogFactory::createDialog(FileEntryType::Surface, &MainFrame::Get());
|
|
|
|
|
if (dialog && dialog->exec() == QDialog::Accepted) {
|
|
|
|
|
QString selectedPath = dialog->getSelectedFilePath();
|
|
|
|
|
|
|
|
|
|
// Create file entry
|
|
|
|
|
switch (current->CreateFileEntry(FileEntryType::Surface)) {
|
|
|
|
|
case WorkSpace::FileEntryResult::Ok: {
|
|
|
|
|
// Get the index of the newly created file entry
|
|
|
|
|
auto entries = current->GetFileEntries(FileEntryType::Surface);
|
|
|
|
|
int newIndex = static_cast<int>(entries.size()) - 1;
|
|
|
|
|
|
|
|
|
|
// Set file path
|
|
|
|
|
if (!current->SetFileEntryPath(FileEntryType::Surface, newIndex, selectedPath)) {
|
|
|
|
|
QMessageBox::warning(&MainFrame::Get(), QObject::tr("Error"),
|
|
|
|
|
QObject::tr("Failed to set file path"));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case WorkSpace::FileEntryResult::LimitExceeded:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("up to 9 files allowed for this type"));
|
|
|
|
|
break;
|
|
|
|
|
case WorkSpace::FileEntryResult::Duplicate:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("file already added for this type"));
|
|
|
|
|
break;
|
|
|
|
|
case WorkSpace::FileEntryResult::CopyFailed:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("copy file failed"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-10-12 14:14:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManagerMenu::AddTableFile() {
|
|
|
|
|
auto current = WorkSpaceManager::Get().GetCurrent();
|
|
|
|
|
if (nullptr == current) {
|
2025-10-20 18:17:40 +00:00
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first"));
|
2025-10-12 14:14:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2025-10-22 17:40:44 +00:00
|
|
|
|
|
|
|
|
// Show table file addition dialog
|
|
|
|
|
auto dialog = AddFileDialogFactory::createDialog(FileEntryType::Table, &MainFrame::Get());
|
|
|
|
|
if (dialog && dialog->exec() == QDialog::Accepted) {
|
|
|
|
|
QString selectedPath = dialog->getSelectedFilePath();
|
|
|
|
|
|
|
|
|
|
// Create file entry
|
|
|
|
|
switch (current->CreateFileEntry(FileEntryType::Table)) {
|
|
|
|
|
case WorkSpace::FileEntryResult::Ok: {
|
|
|
|
|
// Get the index of the newly created file entry
|
|
|
|
|
auto entries = current->GetFileEntries(FileEntryType::Table);
|
|
|
|
|
int newIndex = static_cast<int>(entries.size()) - 1;
|
|
|
|
|
|
|
|
|
|
// Set file path
|
|
|
|
|
if (!current->SetFileEntryPath(FileEntryType::Table, newIndex, selectedPath)) {
|
|
|
|
|
QMessageBox::warning(&MainFrame::Get(), QObject::tr("Error"),
|
|
|
|
|
QObject::tr("Failed to set file path"));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case WorkSpace::FileEntryResult::LimitExceeded:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("up to 9 files allowed for this type"));
|
|
|
|
|
break;
|
|
|
|
|
case WorkSpace::FileEntryResult::Duplicate:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("file already added for this type"));
|
|
|
|
|
break;
|
|
|
|
|
case WorkSpace::FileEntryResult::CopyFailed:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("copy file failed"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-10-12 14:14:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManagerMenu::AddLightFile() {
|
|
|
|
|
auto current = WorkSpaceManager::Get().GetCurrent();
|
|
|
|
|
if (nullptr == current) {
|
2025-10-20 18:17:40 +00:00
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first"));
|
2025-10-12 14:14:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-22 17:40:44 +00:00
|
|
|
// Show light file addition dialog
|
|
|
|
|
auto dialog = AddFileDialogFactory::createDialog(FileEntryType::Light, &MainFrame::Get());
|
|
|
|
|
if (dialog && dialog->exec() == QDialog::Accepted) {
|
|
|
|
|
QString selectedPath = dialog->getSelectedFilePath();
|
|
|
|
|
|
|
|
|
|
// Create file entry
|
|
|
|
|
switch (current->CreateFileEntry(FileEntryType::Light)) {
|
|
|
|
|
case WorkSpace::FileEntryResult::Ok: {
|
|
|
|
|
// Get the index of the newly created file entry
|
|
|
|
|
auto entries = current->GetFileEntries(FileEntryType::Light);
|
|
|
|
|
int newIndex = static_cast<int>(entries.size()) - 1;
|
|
|
|
|
|
|
|
|
|
// Set file path
|
|
|
|
|
if (!current->SetFileEntryPath(FileEntryType::Light, newIndex, selectedPath)) {
|
|
|
|
|
QMessageBox::warning(&MainFrame::Get(), QObject::tr("Error"),
|
|
|
|
|
QObject::tr("Failed to set file path"));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case WorkSpace::FileEntryResult::LimitExceeded:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("up to 9 files allowed for this type"));
|
|
|
|
|
break;
|
|
|
|
|
case WorkSpace::FileEntryResult::Duplicate:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("file already added for this type"));
|
|
|
|
|
break;
|
|
|
|
|
case WorkSpace::FileEntryResult::CopyFailed:
|
|
|
|
|
QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"),
|
|
|
|
|
QObject::tr("copy file failed"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-10-12 14:14:16 +00:00
|
|
|
}
|
2025-10-20 18:17:40 +00:00
|
|
|
}
|