From 1e7538796a35eb5a6bef3bdddca14547cb33b052 Mon Sep 17 00:00:00 2001 From: brige Date: Sun, 26 Oct 2025 17:48:34 +0800 Subject: [PATCH] modify AddSurfaceFileDlg --- .gitignore | 1 + src/translations/Dyt_zh_CN.ts | 224 +++++++--- src/ui/WorkSpace/AddSurfaceFileDlg.cpp | 485 +++++++++++++++----- src/ui/WorkSpace/AddSurfaceFileDlg.h | 72 ++- src/ui/WorkSpace/AddSurfaceFileDlg.ui | 585 ++++++++++++++++++------- src/workspace/FileEntry.cpp | 54 ++- src/workspace/FileEntry.h | 62 ++- 7 files changed, 1148 insertions(+), 335 deletions(-) diff --git a/.gitignore b/.gitignore index 5ae90f68..8d70c6c4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ build/ bin/ thirdparty/ tritoin/ +CMakeFiles/ QWEN.md diff --git a/src/translations/Dyt_zh_CN.ts b/src/translations/Dyt_zh_CN.ts index 3308cc7d..6e9c6e2e 100644 --- a/src/translations/Dyt_zh_CN.ts +++ b/src/translations/Dyt_zh_CN.ts @@ -683,11 +683,6 @@ AddSurfaceFileDlg - - - Add Surface Data File - - File Selection @@ -695,113 +690,242 @@ - File Path: - - - - Select surface data file... + + + Add Surface File + + + + + Browse... + + - ... + Chart Properties - - File Name: + + X Axis Title: - - - - + + Y Axis Title: - - File Size: + + Z Axis Title: - - Surface Parameters + + Time Parameter: - + + X Range: + + + + + + + to + + + + + X Count: + + + + + Y Range: + + + + + Y Count: + + + + + Z Range: + + + + + Z Count: + + + + + Surface Management + + + + + Add Surface + + + + + Remove + + + + + Surface Properties + + + + + Name: + + + + + Color: + + + + + Select Color + + + + + Start Point: + + + + + End Point: + + + + + Data Format Parameters + + + + X Column: - + Y Column: - + Z Column: - + Separator: - - Comma (,) + + , - - Tab + + Has Header Row - - Space - - - - - Semicolon (;) - - - - + X Grid Size: - + Y Grid Size: - - File has header row + + Select Surface Data File - - Description (Optional) + + Please add at least one surface. - - Enter file description... + + Surface Data Files (*.txt *.dat *.csv);;All Files (*.*) - - Add File + + + Warning - - Cancel + + Please fill in all axis titles. + + + + + Select Surface Color + + + + + + + Error + + + + + Failed to create surface file entry. + + + + + Unable to get current workspace + + + + + Surface file count has reached the limit (9 files) + + + + + File already exists + + + + + File copy failed + + + + + Invalid file + + + + + Failed to add file diff --git a/src/ui/WorkSpace/AddSurfaceFileDlg.cpp b/src/ui/WorkSpace/AddSurfaceFileDlg.cpp index c924087f..c95b6e4d 100644 --- a/src/ui/WorkSpace/AddSurfaceFileDlg.cpp +++ b/src/ui/WorkSpace/AddSurfaceFileDlg.cpp @@ -1,135 +1,414 @@ #include "AddSurfaceFileDlg.h" - -#include -#include -#include -#include "app/Application.h" +#include "ui_AddSurfaceFileDlg.h" +#include "workspace/WorkSpaceManager.h" +#include "workspace/WorkSpace.h" #include "common/SpdLogger.h" -#include "ui_AddSurfaceFileDlg.h" +#include +#include +#include +#include +#include +#include +#include -AddSurfaceFileDlg::AddSurfaceFileDlg(QWidget* parent) +AddSurfaceFileDlg::AddSurfaceFileDlg(QWidget *parent) : BaseAddFileDlg(FileEntryType::Surface, parent) - , ui_(new Ui::AddSurfaceFileDlg) { - - ui_->setupUi(this); + , ui(new Ui::AddSurfaceFileDlg) + , currentSurfaceIndex_(-1) + , selectedColor_(Qt::blue) +{ + SetupUI(ui); SetTitle(getDialogTitle()); setupConnections(); -} - -AddSurfaceFileDlg::~AddSurfaceFileDlg() { - delete ui_; -} - -void AddSurfaceFileDlg::setupConnections() { - connect(ui_->selectFileBtn, &QToolButton::clicked, this, &AddSurfaceFileDlg::onSelectFileClicked); - connect(ui_->filePathEdit, &QLineEdit::textChanged, this, &AddSurfaceFileDlg::onFilePathChanged); - connect(ui_->addBtn, &QPushButton::clicked, this, [this]() { OnSure(); }); - connect(ui_->cancelBtn, &QPushButton::clicked, this, &QDialog::reject); -} - -void AddSurfaceFileDlg::onSelectFileClicked() { - const QString workspacePath = Application::GetWorkSpacePath(); - QString filePath = QFileDialog::getOpenFileName( - this, - QStringLiteral("Select Surface Data File"), - workspacePath, - getFileFilter() - ); - if (filePath.isEmpty()) { - return; - } + // Initialize chart properties with default values + chartProperties_.xCount = 100; + chartProperties_.yCount = 100; + chartProperties_.zCount = 100; + chartProperties_.xMin = 0.0; + chartProperties_.xMax = 1.0; + chartProperties_.yMin = 0.0; + chartProperties_.yMax = 1.0; + chartProperties_.zMin = 0.0; + chartProperties_.zMax = 1.0; + chartProperties_.timeParam = 0.0; + chartProperties_.xTitle = "X Axis"; + chartProperties_.yTitle = "Y Axis"; + chartProperties_.zTitle = "Z Axis"; - ui_->filePathEdit->setText(filePath); - updateFileInfo(filePath); + // Set default UI values + ui->xCountSpinBox->setValue(chartProperties_.xCount); + ui->yCountSpinBox->setValue(chartProperties_.yCount); + ui->zCountSpinBox->setValue(chartProperties_.zCount); + ui->xMinSpinBox->setValue(chartProperties_.xMin); + ui->xMaxSpinBox->setValue(chartProperties_.xMax); + ui->yMinSpinBox->setValue(chartProperties_.yMin); + ui->yMaxSpinBox->setValue(chartProperties_.yMax); + ui->zMinSpinBox->setValue(chartProperties_.zMin); + ui->zMaxSpinBox->setValue(chartProperties_.zMax); + ui->timeParamSpinBox->setValue(chartProperties_.timeParam); + ui->xTitleLineEdit->setText(chartProperties_.xTitle); + ui->yTitleLineEdit->setText(chartProperties_.yTitle); + ui->zTitleLineEdit->setText(chartProperties_.zTitle); - LOG_INFO("Selected surface file: {}", filePath.toStdString()); + // Initialize color preview + updateColorPreview(ui->surfaceColorButton, selectedColor_); + + // Clear surface properties initially + clearSurfaceProperties(); } -void AddSurfaceFileDlg::onFilePathChanged() { - QString filePath = ui_->filePathEdit->text(); - if (!filePath.isEmpty()) { - updateFileInfo(filePath); - } +AddSurfaceFileDlg::~AddSurfaceFileDlg() +{ + delete ui; } -void AddSurfaceFileDlg::updateFileInfo(const QString& filePath) { - QFileInfo fileInfo(filePath); - ui_->fileNameValue->setText(fileInfo.fileName()); +void AddSurfaceFileDlg::setupConnections() +{ + // File selection connections + connect(ui->browseButton, &QPushButton::clicked, this, &AddSurfaceFileDlg::onSelectFile); + connect(ui->filePathLineEdit, &QLineEdit::textChanged, this, &AddSurfaceFileDlg::onFilePathChanged); - qint64 size = fileInfo.size(); - QString sizeText; - if (size < 1024) { - sizeText = QString("%1 B").arg(size); - } else if (size < 1024 * 1024) { - sizeText = QString("%1 KB").arg(size / 1024.0, 0, 'f', 1); - } else { - sizeText = QString("%1 MB").arg(size / (1024.0 * 1024.0), 0, 'f', 1); - } - ui_->fileSizeValue->setText(sizeText); + // Surface management connections + connect(ui->surfaceColorButton, &QPushButton::clicked, this, &AddSurfaceFileDlg::onSurfaceColorButtonClicked); + connect(ui->addSurfaceButton, &QPushButton::clicked, this, &AddSurfaceFileDlg::onAddSurfaceClicked); + connect(ui->removeSurfaceButton, &QPushButton::clicked, this, &AddSurfaceFileDlg::onRemoveSurfaceClicked); + connect(ui->surfaceListWidget, &QListWidget::itemClicked, this, &AddSurfaceFileDlg::onSurfaceListItemClicked); + connect(ui->surfaceListWidget, &QListWidget::itemSelectionChanged, this, &AddSurfaceFileDlg::onSurfaceSelectionChanged); + + // Surface properties connections + connect(ui->surfaceNameLineEdit, &QLineEdit::textChanged, this, &AddSurfaceFileDlg::onSurfaceNameChanged); + connect(ui->surfaceStartSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &AddSurfaceFileDlg::onSurfaceDataChanged); + connect(ui->surfaceStopSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &AddSurfaceFileDlg::onSurfaceDataChanged); + + // Chart properties connections (save to member variables when changed) + connect(ui->xCountSpinBox, QOverload::of(&QSpinBox::valueChanged), [this](int value) { chartProperties_.xCount = value; }); + connect(ui->yCountSpinBox, QOverload::of(&QSpinBox::valueChanged), [this](int value) { chartProperties_.yCount = value; }); + connect(ui->zCountSpinBox, QOverload::of(&QSpinBox::valueChanged), [this](int value) { chartProperties_.zCount = value; }); + connect(ui->xMinSpinBox, QOverload::of(&QDoubleSpinBox::valueChanged), [this](double value) { chartProperties_.xMin = value; }); + connect(ui->xMaxSpinBox, QOverload::of(&QDoubleSpinBox::valueChanged), [this](double value) { chartProperties_.xMax = value; }); + connect(ui->yMinSpinBox, QOverload::of(&QDoubleSpinBox::valueChanged), [this](double value) { chartProperties_.yMin = value; }); + connect(ui->yMaxSpinBox, QOverload::of(&QDoubleSpinBox::valueChanged), [this](double value) { chartProperties_.yMax = value; }); + connect(ui->zMinSpinBox, QOverload::of(&QDoubleSpinBox::valueChanged), [this](double value) { chartProperties_.zMin = value; }); + connect(ui->zMaxSpinBox, QOverload::of(&QDoubleSpinBox::valueChanged), [this](double value) { chartProperties_.zMax = value; }); + connect(ui->timeParamSpinBox, QOverload::of(&QDoubleSpinBox::valueChanged), [this](double value) { chartProperties_.timeParam = value; }); + connect(ui->xTitleLineEdit, &QLineEdit::textChanged, [this](const QString& text) { chartProperties_.xTitle = text; }); + connect(ui->yTitleLineEdit, &QLineEdit::textChanged, [this](const QString& text) { chartProperties_.yTitle = text; }); + connect(ui->zTitleLineEdit, &QLineEdit::textChanged, [this](const QString& text) { chartProperties_.zTitle = text; }); + + // Dialog button connections + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AddSurfaceFileDlg::accept); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &AddSurfaceFileDlg::reject); } -bool AddSurfaceFileDlg::validateSpecificParams() { - if (ui_->filePathEdit->text().isEmpty()) { - QMessageBox::warning(this, QStringLiteral("Warning"), - QStringLiteral("Please select a surface data file.")); +QString AddSurfaceFileDlg::getFileFilter() const +{ + return tr("Surface Data Files (*.txt *.dat *.csv);;All Files (*.*)"); +} + +QString AddSurfaceFileDlg::getDialogTitle() const +{ + return tr("Select Surface Data File"); +} + +bool AddSurfaceFileDlg::validateSpecificParams() +{ + if (surfaces_.isEmpty()) { + QMessageBox::warning(this, tr("Warning"), tr("Please add at least one surface.")); return false; } - QFileInfo fileInfo(ui_->filePathEdit->text()); - if (!fileInfo.exists()) { - QMessageBox::warning(this, QStringLiteral("Warning"), - QStringLiteral("The selected file does not exist.")); - return false; - } - - if (ui_->xColumnSpinBox->value() == ui_->yColumnSpinBox->value() || - ui_->xColumnSpinBox->value() == ui_->zColumnSpinBox->value() || - ui_->yColumnSpinBox->value() == ui_->zColumnSpinBox->value()) { - QMessageBox::warning(this, QStringLiteral("Warning"), - QStringLiteral("X, Y, and Z columns must be different.")); + // Validate chart properties + if (chartProperties_.xTitle.isEmpty() || chartProperties_.yTitle.isEmpty() || chartProperties_.zTitle.isEmpty()) { + QMessageBox::warning(this, tr("Warning"), tr("Please fill in all axis titles.")); return false; } return true; } -QString AddSurfaceFileDlg::getFileFilter() const { - return QStringLiteral("Surface Data Files (*.txt *.csv *.dat *.xyz);;All Files (*.*)"); +void AddSurfaceFileDlg::updateFileInfo(const QString& filePath) +{ + ui->filePathLineEdit->setText(filePath); } -QString AddSurfaceFileDlg::getDialogTitle() const { - return QStringLiteral("Add Surface Data File"); -} - -QString AddSurfaceFileDlg::getSelectedFilePath() const { - return ui_->filePathEdit->text(); -} - -QString AddSurfaceFileDlg::getDescription() const { - return ui_->descriptionEdit->toPlainText().trimmed(); -} - -AddSurfaceFileDlg::SurfaceParams AddSurfaceFileDlg::getSurfaceParams() const { - SurfaceParams params; - params.xColumn = ui_->xColumnSpinBox->value(); - params.yColumn = ui_->yColumnSpinBox->value(); - params.zColumn = ui_->zColumnSpinBox->value(); - params.xGridSize = ui_->xGridSizeSpinBox->value(); - params.yGridSize = ui_->yGridSizeSpinBox->value(); - params.hasHeader = ui_->hasHeaderCheckBox->isChecked(); - params.description = ui_->descriptionEdit->toPlainText().trimmed(); +void AddSurfaceFileDlg::onSelectFile() +{ + QString documentsPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); + QString fileName = QFileDialog::getOpenFileName(this, getDialogTitle(), documentsPath, getFileFilter()); - // Get delimiter from combo box - int index = ui_->separatorComboBox->currentIndex(); - switch (index) { - case 0: params.delimiter = ","; break; - case 1: params.delimiter = "\t"; break; - case 2: params.delimiter = " "; break; - case 3: params.delimiter = ";"; break; - default: params.delimiter = ","; break; + if (!fileName.isEmpty()) { + updateFileInfo(fileName); + } +} + +void AddSurfaceFileDlg::onFilePathChanged() +{ + // File path changed, could update preview or validation here +} + +void AddSurfaceFileDlg::onSurfaceColorButtonClicked() +{ + QColor color = QColorDialog::getColor(selectedColor_, this, tr("Select Surface Color")); + if (color.isValid()) { + selectedColor_ = color; + updateColorPreview(ui->surfaceColorButton, selectedColor_); + + // Update current surface color if one is selected + if (currentSurfaceIndex_ >= 0 && currentSurfaceIndex_ < surfaces_.size()) { + surfaces_[currentSurfaceIndex_].color = selectedColor_; + + // Update list item color + QListWidgetItem* item = ui->surfaceListWidget->item(currentSurfaceIndex_); + if (item) { + QPixmap pixmap(16, 16); + pixmap.fill(selectedColor_); + item->setIcon(QIcon(pixmap)); + } + } + } +} + +void AddSurfaceFileDlg::onAddSurfaceClicked() +{ + FileEntrySurface::SurfaceProperty surface; + surface.name = generateSurfaceName(); + surface.color = generateSurfaceColor(); + surface.start = 0; + surface.stop = 1000; + surface.x = QString::number(ui->xColumnSpinBox->value()); + surface.y = QString::number(ui->yColumnSpinBox->value()); + surface.z = QString::number(ui->zColumnSpinBox->value()); + + surfaces_.append(surface); + addSurfaceToList(surface); + + // Select the newly added surface + ui->surfaceListWidget->setCurrentRow(surfaces_.size() - 1); +} + +void AddSurfaceFileDlg::onRemoveSurfaceClicked() +{ + int currentRow = ui->surfaceListWidget->currentRow(); + if (currentRow >= 0 && currentRow < surfaces_.size()) { + surfaces_.removeAt(currentRow); + delete ui->surfaceListWidget->takeItem(currentRow); + + // Update current surface index + if (currentRow < surfaces_.size()) { + ui->surfaceListWidget->setCurrentRow(currentRow); + } else if (surfaces_.size() > 0) { + ui->surfaceListWidget->setCurrentRow(surfaces_.size() - 1); + } else { + currentSurfaceIndex_ = -1; + clearSurfaceProperties(); + } + } +} + +void AddSurfaceFileDlg::onSurfaceListItemClicked(QListWidgetItem* item) +{ + int row = ui->surfaceListWidget->row(item); + if (row >= 0 && row < surfaces_.size()) { + saveSurfaceProperties(); // Save current surface properties + currentSurfaceIndex_ = row; + updateSurfaceProperties(); // Load new surface properties + } +} + +void AddSurfaceFileDlg::onSurfaceSelectionChanged() +{ + int currentRow = ui->surfaceListWidget->currentRow(); + if (currentRow >= 0 && currentRow < surfaces_.size()) { + saveSurfaceProperties(); // Save current surface properties + currentSurfaceIndex_ = currentRow; + updateSurfaceProperties(); // Load new surface properties + } else { + currentSurfaceIndex_ = -1; + clearSurfaceProperties(); + } +} + +void AddSurfaceFileDlg::onSurfaceNameChanged() +{ + if (currentSurfaceIndex_ >= 0 && currentSurfaceIndex_ < surfaces_.size()) { + QString newName = ui->surfaceNameLineEdit->text(); + surfaces_[currentSurfaceIndex_].name = newName; + + // Update list item text + QListWidgetItem* item = ui->surfaceListWidget->item(currentSurfaceIndex_); + if (item) { + item->setText(newName); + } + } +} + +void AddSurfaceFileDlg::onSurfaceDataChanged() +{ + if (currentSurfaceIndex_ >= 0 && currentSurfaceIndex_ < surfaces_.size()) { + surfaces_[currentSurfaceIndex_].start = ui->surfaceStartSpinBox->value(); + surfaces_[currentSurfaceIndex_].stop = ui->surfaceStopSpinBox->value(); + } +} + +void AddSurfaceFileDlg::updateColorPreview(QPushButton* button, const QColor& color) +{ + if (button && color.isValid()) { + QString styleSheet = QString("QPushButton { background-color: %1; }").arg(color.name()); + button->setStyleSheet(styleSheet); + } +} + +void AddSurfaceFileDlg::addSurfaceToList(const FileEntrySurface::SurfaceProperty& surface) +{ + QListWidgetItem* item = new QListWidgetItem(surface.name); + + // Set color icon + QPixmap pixmap(16, 16); + pixmap.fill(surface.color); + item->setIcon(QIcon(pixmap)); + + ui->surfaceListWidget->addItem(item); +} + +void AddSurfaceFileDlg::updateSurfaceProperties() +{ + if (currentSurfaceIndex_ >= 0 && currentSurfaceIndex_ < surfaces_.size()) { + const auto& surface = surfaces_[currentSurfaceIndex_]; + + ui->surfaceNameLineEdit->setText(surface.name); + ui->surfaceStartSpinBox->setValue(surface.start); + ui->surfaceStopSpinBox->setValue(surface.stop); + + selectedColor_ = surface.color; + updateColorPreview(ui->surfaceColorButton, selectedColor_); + + ui->surfacePropertiesGroupBox->setEnabled(true); + } else { + clearSurfaceProperties(); + } +} + +void AddSurfaceFileDlg::saveSurfaceProperties() +{ + if (currentSurfaceIndex_ >= 0 && currentSurfaceIndex_ < surfaces_.size()) { + surfaces_[currentSurfaceIndex_].name = ui->surfaceNameLineEdit->text(); + surfaces_[currentSurfaceIndex_].start = ui->surfaceStartSpinBox->value(); + surfaces_[currentSurfaceIndex_].stop = ui->surfaceStopSpinBox->value(); + surfaces_[currentSurfaceIndex_].color = selectedColor_; + } +} + +void AddSurfaceFileDlg::clearSurfaceProperties() +{ + ui->surfaceNameLineEdit->clear(); + ui->surfaceStartSpinBox->setValue(0); + ui->surfaceStopSpinBox->setValue(1000); + selectedColor_ = Qt::blue; + updateColorPreview(ui->surfaceColorButton, selectedColor_); + ui->surfacePropertiesGroupBox->setEnabled(false); +} + +QString AddSurfaceFileDlg::generateSurfaceName() const +{ + return QString("Surface %1").arg(surfaces_.size() + 1); +} + +QColor AddSurfaceFileDlg::generateSurfaceColor() const +{ + // Generate different colors for each surface + static const QColor colors[] = { + Qt::blue, Qt::red, Qt::green, Qt::magenta, Qt::cyan, Qt::yellow, + Qt::darkBlue, Qt::darkRed, Qt::darkGreen, Qt::darkMagenta, Qt::darkCyan, Qt::darkYellow + }; + + int colorIndex = surfaces_.size() % (sizeof(colors) / sizeof(colors[0])); + return colors[colorIndex]; +} + +AddSurfaceFileDlg::SurfaceParams AddSurfaceFileDlg::GetSurfaceParams() const +{ + SurfaceParams params; + params.xColumn = ui->xColumnSpinBox->value(); + params.yColumn = ui->yColumnSpinBox->value(); + params.zColumn = ui->zColumnSpinBox->value(); + params.separator = ui->separatorLineEdit->text(); + params.xGridSize = ui->xGridSizeSpinBox->value(); + params.yGridSize = ui->yGridSizeSpinBox->value(); + params.hasHeader = ui->hasHeaderCheckBox->isChecked(); + return params; +} + +QString AddSurfaceFileDlg::GetSelectedFilePath() const +{ + return ui->filePathLineEdit->text(); +} + +QString AddSurfaceFileDlg::GetDescription() const +{ + return getDescription(); // 使用基类的getDescription方法 +} + +void AddSurfaceFileDlg::accept() +{ + if (!validateSpecificParams()) { + return; } - return params; + // Save current surface properties before creating FileEntry + saveSurfaceProperties(); + + // Create FileEntrySurface + auto fileEntry = std::dynamic_pointer_cast(CreateFileEntrySurface(GetSelectedFilePath())); + if (!fileEntry) { + QMessageBox::critical(this, tr("Error"), tr("Failed to create surface file entry.")); + return; + } + + // Set chart properties + fileEntry->SetChartProperties(chartProperties_); + + // Set surface properties + for (const auto& surface : surfaces_) { + fileEntry->AddSurfaceProperty(surface); + } + + // Set description + fileEntry->SetDescription(GetDescription()); + + // Add to workspace + WorkSpace* workspace = WorkSpaceManager::Get().GetCurrent(); + if (!workspace) { + QMessageBox::critical(this, tr("Error"), tr("Unable to get current workspace")); + return; + } + + // Add FileEntrySurface to workspace using SetFileEntry method + auto result = workspace->SetFileEntry(fileEntry); + if (result != WorkSpace::FileEntryResult::Ok) { + QString errorMsg; + switch (result) { + case WorkSpace::FileEntryResult::LimitExceeded: + errorMsg = tr("Surface file count has reached the limit (9 files)"); + break; + case WorkSpace::FileEntryResult::Duplicate: + errorMsg = tr("File already exists"); + break; + case WorkSpace::FileEntryResult::CopyFailed: + errorMsg = tr("File copy failed"); + break; + case WorkSpace::FileEntryResult::InvalidFile: + errorMsg = tr("Invalid file"); + break; + default: + errorMsg = tr("Failed to add file"); + break; + } + QMessageBox::warning(this, tr("Error"), errorMsg); + return; + } + + LOG_INFO("Added surface file to workspace: {}", GetSelectedFilePath().toUtf8().constData()); + QDialog::accept(); } \ No newline at end of file diff --git a/src/ui/WorkSpace/AddSurfaceFileDlg.h b/src/ui/WorkSpace/AddSurfaceFileDlg.h index 07738b19..9a6531e7 100644 --- a/src/ui/WorkSpace/AddSurfaceFileDlg.h +++ b/src/ui/WorkSpace/AddSurfaceFileDlg.h @@ -1,56 +1,86 @@ #pragma once #include "BaseAddFileDlg.h" +#include "workspace/FileEntry.h" +#include +#include +#include +#include -QT_BEGIN_NAMESPACE class QLineEdit; -class QCheckBox; class QSpinBox; -class QComboBox; +class QCheckBox; class QTextEdit; -class QToolButton; -class QLabel; -QT_END_NAMESPACE +class QComboBox; +class QPushButton; +class QListWidget; +class QListWidgetItem; +class QDoubleSpinBox; namespace Ui { - class AddSurfaceFileDlg; +class AddSurfaceFileDlg; } -class AddSurfaceFileDlg : public BaseAddFileDlg { +class AddSurfaceFileDlg : public BaseAddFileDlg +{ Q_OBJECT public: struct SurfaceParams { - QString delimiter; - bool hasHeader; int xColumn; int yColumn; int zColumn; + QString separator; int xGridSize; int yGridSize; - QString description; + bool hasHeader; }; - explicit AddSurfaceFileDlg(QWidget* parent = nullptr); - ~AddSurfaceFileDlg() override; +public: + explicit AddSurfaceFileDlg(QWidget *parent = nullptr); + ~AddSurfaceFileDlg(); - SurfaceParams getSurfaceParams() const; - QString getSelectedFilePath() const; - QString getDescription() const; - -protected: + // BaseAddFileDlg interface QString getFileFilter() const override; QString getDialogTitle() const override; bool validateSpecificParams() override; + void updateFileInfo(const QString& filePath) override; + + // Get surface parameters + SurfaceParams GetSurfaceParams() const; + QString GetSelectedFilePath() const; + QString GetDescription() const; private slots: - void onSelectFileClicked(); + void onSelectFile(); void onFilePathChanged(); + + // Surface management slots + void onSurfaceColorButtonClicked(); + void onAddSurfaceClicked(); + void onRemoveSurfaceClicked(); + void onSurfaceListItemClicked(QListWidgetItem* item); + void onSurfaceSelectionChanged(); + void onSurfaceNameChanged(); + void onSurfaceDataChanged(); + +public slots: + void accept() override; private: void setupConnections(); - void updateFileInfo(const QString& filePath); + void updateColorPreview(QPushButton* button, const QColor& color); + void addSurfaceToList(const FileEntrySurface::SurfaceProperty& surface); + void updateSurfaceProperties(); + void saveSurfaceProperties(); + void clearSurfaceProperties(); + QString generateSurfaceName() const; + QColor generateSurfaceColor() const; private: - Ui::AddSurfaceFileDlg* ui_; + Ui::AddSurfaceFileDlg *ui; + int currentSurfaceIndex_; + QColor selectedColor_; + FileEntrySurface::ChartProperties chartProperties_; + FileEntrySurface::SurfaceProperties surfaces_; }; \ No newline at end of file diff --git a/src/ui/WorkSpace/AddSurfaceFileDlg.ui b/src/ui/WorkSpace/AddSurfaceFileDlg.ui index e7446dae..5a91dc25 100644 --- a/src/ui/WorkSpace/AddSurfaceFileDlg.ui +++ b/src/ui/WorkSpace/AddSurfaceFileDlg.ui @@ -6,12 +6,12 @@ 0 0 - 500 - 520 + 800 + 726 - Add Surface Data File + Add Surface File @@ -19,56 +19,18 @@ File Selection - - - - - File Path: - - - - - + + + Select surface data file... - - true - - - + + - ... - - - - - - - File Name: - - - - - - - - - - - - - - - File Size: - - - - - - - - + Browse... @@ -76,11 +38,372 @@ - + - Surface Parameters + Chart Properties - + + + + + X Axis Title: + + + + + + + + + + Y Axis Title: + + + + + + + + + + Z Axis Title: + + + + + + + + + + Time Parameter: + + + + + + + 6 + + + -999999.000000000000000 + + + 999999.000000000000000 + + + + + + + X Range: + + + + + + + + + 6 + + + -999999.000000000000000 + + + 999999.000000000000000 + + + + + + + to + + + + + + + 6 + + + -999999.000000000000000 + + + 999999.000000000000000 + + + + + + + + + X Count: + + + + + + + 1 + + + 10000 + + + 100 + + + + + + + Y Range: + + + + + + + + + 6 + + + -999999.000000000000000 + + + 999999.000000000000000 + + + + + + + to + + + + + + + 6 + + + -999999.000000000000000 + + + 999999.000000000000000 + + + + + + + + + Y Count: + + + + + + + 1 + + + 10000 + + + 100 + + + + + + + Z Range: + + + + + + + + + 6 + + + -999999.000000000000000 + + + 999999.000000000000000 + + + + + + + to + + + + + + + 6 + + + -999999.000000000000000 + + + 999999.000000000000000 + + + + + + + + + Z Count: + + + + + + + 1 + + + 10000 + + + 100 + + + + + + + + + + Surface Management + + + + + + + + Add Surface + + + + + + + + 200 + 150 + + + + + + + + Remove + + + + + + + + + Surface Properties + + + + + + Name: + + + + + + + + + + Color: + + + + + + + + 100 + 30 + + + + Select Color + + + + + + + Start Point: + + + + + + + 0 + + + 999999 + + + + + + + End Point: + + + + + + + 0 + + + 999999 + + + + + + + + + + + + + Data Format Parameters + + @@ -94,92 +417,75 @@ 1 - 100 + 1000 1 - + Y Column: - + 1 - 100 + 1000 2 - + Z Column: - + 1 - 100 + 1000 3 - + Separator: - - - - - Comma (,) - - - - - Tab - - - - - Space - - - - - Semicolon (;) - - + + + + , + - + X Grid Size: - + 1 @@ -192,14 +498,14 @@ - + Y Grid Size: - + 1 @@ -212,13 +518,10 @@ - + - File has header row - - - true + Has Header Row @@ -226,76 +529,50 @@ - - - Description (Optional) - - - - - - - 16777215 - 80 - - - - Enter file description... - - - - - - - - + - Qt::Vertical + Qt::Horizontal - - - 20 - 40 - + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Add File - - - true - - - - - - - Cancel - - - - + - + + + buttonBox + accepted() + AddSurfaceFileDlg + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AddSurfaceFileDlg + reject() + + + 316 + 260 + + + 286 + 274 + + + + \ No newline at end of file diff --git a/src/workspace/FileEntry.cpp b/src/workspace/FileEntry.cpp index 706f8131..9598ecc5 100644 --- a/src/workspace/FileEntry.cpp +++ b/src/workspace/FileEntry.cpp @@ -46,13 +46,16 @@ std::shared_ptr CreateFileEntryCurve(const QString& filePath) { } std::shared_ptr CreateFileEntrySurface(const QString& filePath) { - auto fileEntry = std::make_shared(); - fileEntry->SetType(FileEntryType::Surface); - - if (!filePath.isEmpty()) { - fileEntry->SetPath(filePath); + QFileInfo fileInfo(filePath); + if (!fileInfo.exists()) { + LOG_ERROR("File does not exist: {}", filePath.toUtf8().constData()); + return nullptr; } + auto fileEntry = std::make_shared(); + fileEntry->SetPath(filePath); + fileEntry->SetName(fileInfo.baseName()); // Use base name as default display name + return fileEntry; } @@ -79,4 +82,45 @@ std::shared_ptr CreateFileEntryLight(const QString& filePath) { fileEntry->SetName(fileInfo.baseName()); // Use base name as default display name return fileEntry; +} + +// 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_; } \ No newline at end of file diff --git a/src/workspace/FileEntry.h b/src/workspace/FileEntry.h index 33cf4326..a3791cfe 100644 --- a/src/workspace/FileEntry.h +++ b/src/workspace/FileEntry.h @@ -31,6 +31,7 @@ inline bool FileEntryTypeFromString(const char* s, FileEntryType& out) { class FileEntryCurve; class FileEntryLight; +class FileEntrySurface; class FileEntry { public: @@ -48,8 +49,9 @@ public: void SetName(const QString& name) { name_ = name; } QString GetName() const { return name_; } - virtual FileEntryCurve* AsCurve() { return nullptr; } - virtual FileEntryLight* AsLight() { return nullptr; } + virtual FileEntryCurve* AsCurve() { return nullptr; } + virtual FileEntryLight* AsLight() { return nullptr; } + virtual FileEntrySurface* AsSurface() { return nullptr; } protected: FileEntryType type_; @@ -105,6 +107,62 @@ private: CurveProperties curveProperties_; }; +class FileEntrySurface : public FileEntry { +public: + struct ChartProperties { + int xCount; + int yCount; // Added missing yCount + int zCount; // Added missing zCount + QString xTitle; + QString yTitle; + QString zTitle; + double xMin; + double xMax; + double yMin; + double yMax; + double zMin; + double zMax; + double timeParam; + }; + + struct SurfaceProperty { + QString name; + QColor color; + int start; + int stop; + QString x; + QString y; + QString z; + }; + + using SurfaceProperties = QList; + +public: + FileEntrySurface() { type_ = FileEntryType::Surface; } + + // Chart properties management + void SetChartProperties(const ChartProperties& properties); + const ChartProperties& GetChartProperties() const; + + // Surface properties management + void AddSurfaceProperty(const SurfaceProperty& surface); + void RemoveSurfaceProperty(int index); + void SetSurfaceProperty(int index, const SurfaceProperty& surface); + const SurfaceProperties& GetSurfaceProperties() const; + + // Type conversion + FileEntrySurface* AsSurface() override; + + // Description management + void SetDescription(const QString& description); + const QString& GetDescription() const; + +private: + ChartProperties chartProperties_; + SurfaceProperties surfaceProperties_; + QString description_; +}; + class FileEntryLight : public FileEntry { public: struct ColorProperties {