From 963fe4fa764a87f26d8a29b35c85b6a8de66e14f Mon Sep 17 00:00:00 2001 From: brige Date: Tue, 21 Oct 2025 02:17:40 +0800 Subject: [PATCH] moidy fileentity --- src/entities/LabelComponent.cpp | 7 +- src/entities/LabelComponent.h | 3 +- src/scene/OEScene.h | 2 +- src/scene/ui/QueryElevationWidget.cpp | 4 +- src/scene/ui/ZoomManager.cpp | 4 +- src/translations/Dyt_zh_CN.ts | 401 +++++++++--------- src/ui/Layout/CodeEdtUI.cpp | 10 +- src/ui/MainWindow.cpp | 5 - src/ui/MainWindow.h | 5 - src/ui/Menu/FileManagerMenu.cpp | 120 ++++-- src/ui/Menu/FileManagerMenu.h | 11 +- src/ui/Panel/CurvePanel.cpp | 296 ++++++++++++- src/ui/Panel/CurvePanel.h | 32 ++ src/ui/Panel/DataPanel.h | 5 +- src/ui/Panel/DataPanelFactory.cpp | 9 +- src/ui/Panel/DataPanelFactory.h | 54 +-- src/ui/Panel/DataPanelManager.cpp | 2 +- src/ui/PropertyBrowser/qtpropertymanager.cpp | 6 +- .../PropertyBrowser/qtworkspaceattribute.cpp | 2 +- src/ui/Table/targetlistwgt.cpp | 4 +- src/ui/Table/targetlistwgt.h | 4 +- src/ui/WorkSpace/AddFileDlg.cpp | 125 ++++++ src/ui/WorkSpace/AddFileDlg.h | 37 ++ src/ui/WorkSpace/AddFileDlg.ui | 266 ++++++++++++ src/ui/chartPlot/DYTChart.cpp | 144 +++---- src/ui/chartPlot/FitCurveDialog.cpp | 30 +- src/utils/UiLayoutManager.h | 4 +- src/viewer/CameraControlManipulator.cpp | 15 - src/workspace/ChartData.h | 109 +++++ src/workspace/WorkSpace.cpp | 56 +++ src/workspace/WorkSpace.h | 9 + src/workspace/WorkSpaceXMLParse.cpp | 268 ++++++++++++ src/workspace/WorkSpaceXMLParse.h | 1 + test_chart_parsing.cpp | 129 ++++++ test_workspace.xml | 45 ++ 35 files changed, 1774 insertions(+), 450 deletions(-) create mode 100644 src/ui/WorkSpace/AddFileDlg.cpp create mode 100644 src/ui/WorkSpace/AddFileDlg.h create mode 100644 src/ui/WorkSpace/AddFileDlg.ui create mode 100644 src/workspace/ChartData.h create mode 100644 test_chart_parsing.cpp create mode 100644 test_workspace.xml diff --git a/src/entities/LabelComponent.cpp b/src/entities/LabelComponent.cpp index 43ca3967..4f00a70e 100644 --- a/src/entities/LabelComponent.cpp +++ b/src/entities/LabelComponent.cpp @@ -70,7 +70,6 @@ bool LabelComponent::SaveAttribute(tinyxml2::XMLElement* element) { element->SetAttribute("fontSize", fontSize_); element->SetAttribute("visible", visible_ ? "true" : "false"); - // 保存颜色 char colorStr[64]; sprintf(colorStr, "%.2f,%.2f,%.2f,%.2f", color_.r(), color_.g(), color_.b(), color_.a()); element->SetAttribute("color", colorStr); @@ -148,24 +147,20 @@ void LabelComponent::CreateTextNode() { return; } - // 使用布告板来显示文本,确保文本始终面向相机 if (!billboard_.valid()) { billboard_ = new osg::Billboard(); billboard_->setMode(osg::Billboard::POINT_ROT_EYE); textNode_ = new osgText::Text(); - // 设置文本对齐方式为底部居中,这样文本会显示在指定位置的上方 textNode_->setAlignment(osgText::Text::CENTER_BOTTOM); textNode_->setAxisAlignment(osgText::Text::SCREEN); textNode_->setCharacterSizeMode(osgText::Text::SCREEN_COORDS); textNode_->setText(text_); - textNode_->setPosition(osg::Vec3(0.0f, 0.0f, 0.0f)); // 文本相对于布告板的位置 + textNode_->setPosition(osg::Vec3(0.0f, 0.0f, 0.0f)); - // 直接将文本对象添加到布告板,并设置位置偏移 billboard_->addDrawable(textNode_.get(), osg::Vec3(0.0f, 0.0f, 5.0f)); - // 设置渲染状态 osg::StateSet* stateSet = billboard_->getOrCreateStateSet(); stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON); diff --git a/src/entities/LabelComponent.h b/src/entities/LabelComponent.h index 7b82b93c..912a63aa 100644 --- a/src/entities/LabelComponent.h +++ b/src/entities/LabelComponent.h @@ -27,7 +27,6 @@ public: void End() override; void AddToRender() override; - // 标签相关方法 void SetText(const std::string& text); const std::string& GetText() const { return text_; } @@ -55,4 +54,4 @@ protected: //osg::ref_ptr scutcheon_; osg::ref_ptr billboard_; osg::ref_ptr textNode_; -}; \ No newline at end of file +}; \ No newline at end of file diff --git a/src/scene/OEScene.h b/src/scene/OEScene.h index 7dcf6292..d56a954c 100644 --- a/src/scene/OEScene.h +++ b/src/scene/OEScene.h @@ -49,5 +49,5 @@ private: osg::ref_ptr skyDome_; osg::ref_ptr sceneUI_; osgViewer::View* curentView_ {nullptr}; - bool homeViewpointSet_ {false}; // 跟踪home viewpoint是否已经设置 + bool homeViewpointSet_ {false}; }; diff --git a/src/scene/ui/QueryElevationWidget.cpp b/src/scene/ui/QueryElevationWidget.cpp index 51c9f954..7d3abd95 100644 --- a/src/scene/ui/QueryElevationWidget.cpp +++ b/src/scene/ui/QueryElevationWidget.cpp @@ -1,4 +1,4 @@ -#include "scene/ui/QueryElevationWidget.h" +#include "scene/ui/QueryElevationWidget.h" #include #include @@ -58,7 +58,7 @@ void QueryElevationWidget::DetachViewUI(OsgViewUI* ui) { void QueryElevationWidget::OnUpdateGeoPoint(double x, double y, double z) { - // x 保存小数点后6位 c++14 + dyt_check(nullptr != label_); label_->setLabel(GetElevationString(x, y, z)); diff --git a/src/scene/ui/ZoomManager.cpp b/src/scene/ui/ZoomManager.cpp index 64b1b807..60b4d41a 100644 --- a/src/scene/ui/ZoomManager.cpp +++ b/src/scene/ui/ZoomManager.cpp @@ -1,4 +1,4 @@ -#include "ZoomManager.h" +#include "ZoomManager.h" #include @@ -79,7 +79,7 @@ void ZoomManager::AttachViewUI(OsgViewUI* ui) { void ZoomManager::slotZoom() { double val = _zoomNum[0]; - double dx = val*(-1.0)*(0.0005);// dx不起作用 + double dx = val*(-1.0)*(0.0005); double dy = val*(-1.0)*(0.0005); return; diff --git a/src/translations/Dyt_zh_CN.ts b/src/translations/Dyt_zh_CN.ts index b6311aa8..ed070fcc 100644 --- a/src/translations/Dyt_zh_CN.ts +++ b/src/translations/Dyt_zh_CN.ts @@ -1,6 +1,95 @@ + + AddFileDlg + + + Add File to Workspace + + + + + File Path + + + + + Select file to add... + + + + + ... + + + + + File Type + + + + + Curve Data + + + + + Surface Data + + + + + Table Data + + + + + Light Data + + + + + File Information + + + + + File Name: + + + + + + - + + + + + File Size: + + + + + Description (Optional) + + + + + Enter file description... + + + + + Add File + + + + + Cancel + + + AddParamSetting @@ -401,83 +490,6 @@ new light file - - - Dyt (*.dyt) - - - - - open dyt file - - - - - Dyt (*.dyt);;All files (*.*) - - - - - warning - - - - - workspace is nullptr - - - - - - - - - - - - - - - - - - - - prompt - - - - - - - - please create workspace first - - - - - - - - up to 9 files allowed for this type - - - - - - - - file already added for this type - - - - - - - - copy file failed - - FitCurveChartView @@ -494,36 +506,6 @@ FitCurveDialog - - - - 2D Curve -- %1 - - - - - - - - %1 -- %2 - - - - - - 2D(y(lg)) Curve -- %1 - - - - - 2D Curve - - - - - 2D(y(lg)) Curve - - FrameTitleBar @@ -592,132 +574,132 @@ - + model elements - + attribte - + Main View - + Wave Curve - + Speed Curve - + 3D Curve - + Target number - + Signal-to-noise ratio - + Azimuth line of sight - + Pitch gaze angle - + azimuth - + Pitch angle - + attribute - + Doppler - + course - + Speed - + longitude - + latitude - + distance - + velocity - + Radial dimensions - + Target RCS - + Report Table - + Signal Indicator Lamp - + ParamSetting - + bat File @@ -995,6 +977,94 @@ Light[%1] + + + Open Workspace + + + + + + Dyt Files (*.dyt) + + + + + + + + + + + + + + + + + + + + + + + + + prompt + + + + + + + + + + please create workspace first + + + + + Save Workspace + + + + + Error + + + + + Failed to set file path + + + + + + + + + up to 9 files allowed for this type + + + + + + + + + file already added for this type + + + + + + + + + copy file failed + + QtBoolEdit @@ -1751,21 +1821,6 @@ SignalIndicatorLampUI - - - Signal Indicator Lamp - - - - - %1 -- %2 - - - - - light - - SimuRunMenu @@ -1805,16 +1860,6 @@ DSurfaceDialog - - - 3D Curve - - - - - 3D Curve -- %1 - - SystemManagerMenu @@ -1856,46 +1901,6 @@ TargetListWgt - - - 停止更新 - - - - - 显示行数 - - - - - 前一页 - - - - - / - - - - - 后一页 - - - - - 跳转 - - - - - Data Table - - - - - %1 -- %2 - - ViewManagerMenu diff --git a/src/ui/Layout/CodeEdtUI.cpp b/src/ui/Layout/CodeEdtUI.cpp index eab66aa2..c15670b9 100644 --- a/src/ui/Layout/CodeEdtUI.cpp +++ b/src/ui/Layout/CodeEdtUI.cpp @@ -1,4 +1,4 @@ -#include "CodeEdtUI.h" +#include "CodeEdtUI.h" #include #include @@ -25,7 +25,6 @@ CodeEdtUI::CodeEdtUI(QWidget *parent) { ui.setupUi(this); - // 创建代码编辑器 editor = new QPlainTextEdit(this); QFont serifFont("Times", 20, QFont::Bold); @@ -38,7 +37,6 @@ CodeEdtUI::CodeEdtUI(QWidget *parent) InitBat(); - // // 创建菜单 // QMenu* fileMenu = menuBar()->addMenu(tr("&file")); // QAction* openMainAction = new QAction(tr("&Import the template"), this); ///* QAction* openLDAction = new QAction(tr("&Import the LD template"), this); @@ -55,7 +53,6 @@ CodeEdtUI::CodeEdtUI(QWidget *parent) // connect(saveAction, &QAction::triggered, this, &CodeEdtUI::saveFile); - // // 状态栏 // statusBar(); } @@ -182,20 +179,15 @@ void CodeEdtUI::runFile() { saveFile(); - // 创建QProcess对象 QProcess process; - // 启动批处理文件 process.start(m_strCurOpenFile); - // 等待过程完成 process.waitForFinished(); - // 获取输出 QString output = process.readAllStandardOutput(); QString errorOutput = process.readAllStandardError(); - // 打印输出 qDebug() << "Output:" << output; qDebug() << "Error Output:" << errorOutput; } diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 6c54995b..4988443a 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -27,7 +27,6 @@ #include "Matlab/MatlabObject.h" -// 曲线面板管理器 #include "Panel/DataPanelManager.h" #include "ui_MainWindow.h" @@ -81,7 +80,6 @@ void MainWindow::InitUI() { qtOsgViewWidget_ = new OsgWidget; qtOsgViewWidget_->Initialize(); - // 主视图改为 DockWidget,支持自由停靠 DockWidget* viewDock = new DockWidget(tr("Main View"), 0); viewDock->SetDockWidgetTitleBar(new DockTitleBar(viewDock)); viewDock->setObjectName("Dock.MainView"); @@ -214,10 +212,8 @@ void MainWindow::InitUI() { // InitDockLayout(); - // 初始化数据面板管理器 dataPanelManager_ = new DataPanelManager(this, this); - // 连接工作空间变化信号 connect(&WorkSpaceManager::Get(), &WorkSpaceManager::WorkSpaceChanged, dataPanelManager_, &DataPanelManager::OnWorkspaceChanged); @@ -241,7 +237,6 @@ void MainWindow::UninitUI() { // Save layout state before tearing down widgets UiLayoutManager::Save(this, 1); - // 清理数据面板管理器 if (dataPanelManager_) { delete dataPanelManager_; dataPanelManager_ = nullptr; diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 110276bb..e7868529 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -39,10 +39,6 @@ public: return surfaceDlg_; } - /** - * @brief 获取数据面板管理器 - * @return 数据面板管理器指针 - */ DataPanelManager* GetDataPanelManager() const { return dataPanelManager_; } @@ -78,7 +74,6 @@ private: class CodeEdtUI* matlabFileDlg_{ nullptr }; class AddParamSetting* addParamDlg_{ nullptr }; - // 数据面板管理器 DataPanelManager* dataPanelManager_{ nullptr }; QMap m_mapDockWidget; diff --git a/src/ui/Menu/FileManagerMenu.cpp b/src/ui/Menu/FileManagerMenu.cpp index 653ea602..a0b4f18e 100644 --- a/src/ui/Menu/FileManagerMenu.cpp +++ b/src/ui/Menu/FileManagerMenu.cpp @@ -8,6 +8,7 @@ #include "ui/MainFrame.h" #include "ui/WorkSpace/WorkSpaceDlg.h" +#include "ui/WorkSpace/AddFileDlg.h" #include "common/SpdLogger.h" #include "workspace/WorkSpace.h" @@ -48,44 +49,85 @@ void FileManagerMenu::NewWorkSpace() { } void FileManagerMenu::OpenWorkSpace() { - LOG_INFO("click newworkspace"); - QString selfilter = tr("Dyt (*.dyt)"); - - const QString workspacePath = Application::GetWorkSpacePath(); - QString dytFile = QFileDialog::getOpenFileName(&MainFrame::Get(), tr("open dyt file"), workspacePath, - tr("Dyt (*.dyt);;All files (*.*)"), - &selfilter); - LOG_INFO("user select file: {}", dytFile.toStdString()); - if (dytFile.isEmpty()) { + QString fileName = QFileDialog::getOpenFileName(&MainFrame::Get(), + QObject::tr("Open Workspace"), Application::GetWorkSpacePath(), QObject::tr("Dyt Files (*.dyt)")); + if (fileName.isEmpty()) { return; } - emit LoadDyt(dytFile); + LOG_INFO("open workspace: {}", fileName.toLocal8Bit().constData()); + emit LoadDyt(fileName); } void FileManagerMenu::SaveWorkSpace() { - LOG_INFO("click SaveWorkSpace"); - - WorkSpace* workspace = WorkSpaceManager::Get().GetCurrent(); - if (nullptr == workspace) { - LOG_WARN("workspace is nullptr"); - QMessageBox::warning(&MainFrame::Get(), tr("warning"), tr("workspace is nullptr")); + auto current = WorkSpaceManager::Get().GetCurrent(); + if (nullptr == current) { + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first")); return; } - const QString name = workspace->GetName(); - QString dytFile = workspace->GetPath(); - LOG_INFO("save {} dyt file: {}", name.toLocal8Bit().constData(), - dytFile.toLocal8Bit().constData()); + 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(); + } - bool success = workspace->Save(dytFile); - LOG_INFO("save dyt: {}", success); + LOG_INFO("save workspace: {}", fileName.toLocal8Bit().constData()); +} + +void FileManagerMenu::AddFile() { + auto current = WorkSpaceManager::Get().GetCurrent(); + if (nullptr == current) { + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first")); + return; + } + + // Show file addition dialog + AddFileDlg dlg(&MainFrame::Get()); + if (dlg.exec() == QDialog::Accepted) { + FileEntryType selectedType = dlg.getSelectedFileType(); + QString selectedPath = dlg.getSelectedFilePath(); + + // Create file entry + switch (current->CreateFileEntry(selectedType)) { + case WorkSpace::FileEntryResult::Ok: { + // Get the index of the newly created file entry + auto entries = current->GetFileEntries(selectedType); + int newIndex = static_cast(entries.size()) - 1; + + // Set file path + if (!current->SetFileEntryPath(selectedType, 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; + } + } } void FileManagerMenu::AddWaveFile() { auto current = WorkSpaceManager::Get().GetCurrent(); if (nullptr == current) { - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("please create workspace first")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first")); return; } @@ -93,13 +135,13 @@ void FileManagerMenu::AddWaveFile() { case WorkSpace::FileEntryResult::Ok: break; case WorkSpace::FileEntryResult::LimitExceeded: - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("up to 9 files allowed for this type")); + 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(), tr("prompt"), tr("file already added for this type")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("file already added for this type")); break; case WorkSpace::FileEntryResult::CopyFailed: - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("copy file failed")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("copy file failed")); break; } } @@ -107,7 +149,7 @@ void FileManagerMenu::AddWaveFile() { void FileManagerMenu::AddSurfaceFile() { auto current = WorkSpaceManager::Get().GetCurrent(); if (nullptr == current) { - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("please create workspace first")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first")); return; } @@ -115,13 +157,13 @@ void FileManagerMenu::AddSurfaceFile() { case WorkSpace::FileEntryResult::Ok: break; case WorkSpace::FileEntryResult::LimitExceeded: - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("up to 9 files allowed for this type")); + 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(), tr("prompt"), tr("file already added for this type")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("file already added for this type")); break; case WorkSpace::FileEntryResult::CopyFailed: - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("copy file failed")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("copy file failed")); break; } } @@ -129,20 +171,20 @@ void FileManagerMenu::AddSurfaceFile() { void FileManagerMenu::AddTableFile() { auto current = WorkSpaceManager::Get().GetCurrent(); if (nullptr == current) { - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("please create workspace first")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first")); return; } switch (current->CreateFileEntry(FileEntryType::Table)) { case WorkSpace::FileEntryResult::Ok: break; case WorkSpace::FileEntryResult::LimitExceeded: - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("up to 9 files allowed for this type")); + 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(), tr("prompt"), tr("file already added for this type")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("file already added for this type")); break; case WorkSpace::FileEntryResult::CopyFailed: - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("copy file failed")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("copy file failed")); break; } } @@ -150,7 +192,7 @@ void FileManagerMenu::AddTableFile() { void FileManagerMenu::AddLightFile() { auto current = WorkSpaceManager::Get().GetCurrent(); if (nullptr == current) { - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("please create workspace first")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first")); return; } @@ -158,13 +200,13 @@ void FileManagerMenu::AddLightFile() { case WorkSpace::FileEntryResult::Ok: break; case WorkSpace::FileEntryResult::LimitExceeded: - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("up to 9 files allowed for this type")); + 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(), tr("prompt"), tr("file already added for this type")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("file already added for this type")); break; case WorkSpace::FileEntryResult::CopyFailed: - QMessageBox::information(&MainFrame::Get(), tr("prompt"), tr("copy file failed")); + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("copy file failed")); break; } -} +} diff --git a/src/ui/Menu/FileManagerMenu.h b/src/ui/Menu/FileManagerMenu.h index ff93612e..3924ffe1 100644 --- a/src/ui/Menu/FileManagerMenu.h +++ b/src/ui/Menu/FileManagerMenu.h @@ -13,22 +13,25 @@ public: FileManagerMenu(QWidget* parent = 0); ~FileManagerMenu() override; -Q_SIGNALS: - void LoadDyt(const QString& path); - protected: void InitConnect(); -private: void NewWorkSpace(); void OpenWorkSpace(); void SaveWorkSpace(); + // New unified file addition method + void AddFile(); + + // Keep original methods for backward compatibility void AddWaveFile(); void AddSurfaceFile(); void AddTableFile(); void AddLightFile(); +signals: + void LoadDyt(const QString& path); + private: Ui::FileManagerMenu* ui; }; \ No newline at end of file diff --git a/src/ui/Panel/CurvePanel.cpp b/src/ui/Panel/CurvePanel.cpp index 865222c8..da4713c0 100644 --- a/src/ui/Panel/CurvePanel.cpp +++ b/src/ui/Panel/CurvePanel.cpp @@ -5,13 +5,32 @@ #include #include #include +#include +#include +#include +#include CurvePanel::CurvePanel(int index, const QString& filePath, QWidget* parent) : DataPanel(index, FileEntryType::Curve, filePath, parent) + , hasChartData_(false) { LOG_INFO("Created CurvePanel {} for file: {}", index, filePath.toStdString()); } +CurvePanel::CurvePanel(int index, std::shared_ptr chartData, QWidget* parent) + : DataPanel(index, FileEntryType::Curve, chartData ? chartData->path : QString(), parent) + , chartData_(chartData) + , hasChartData_(chartData != nullptr) +{ + if (chartData) { + LOG_INFO("Created CurvePanel {} for chart: {}", index, chartData->name.toStdString()); + // Override the title with chart name + title_ = QString("Curve Panel %1 - %2").arg(index).arg(chartData->name); + } else { + LOG_WARN("Created CurvePanel {} with null chart data", index); + } +} + CurvePanel::~CurvePanel() { LOG_INFO("Destroyed CurvePanel {}", GetIndex()); @@ -20,26 +39,277 @@ CurvePanel::~CurvePanel() void CurvePanel::RefreshPanel() { // Implement curve-specific refresh logic here - // For now, just call the base class implementation DataPanel::RefreshPanel(); + if (hasChartData_) { + UpdateCurveDisplay(); + } + LOG_INFO("Refreshed CurvePanel {}", GetIndex()); } +void CurvePanel::SetChartData(std::shared_ptr chartData) +{ + chartData_ = chartData; + hasChartData_ = (chartData != nullptr); + + if (chartData) { + // Update title + title_ = QString("Curve Panel %1 - %2").arg(GetIndex()).arg(chartData->name); + + // Refresh the display + UpdateCurveDisplay(); + + LOG_INFO("Set chart data for CurvePanel {}: {}", GetIndex(), chartData->name.toStdString()); + } else { + LOG_WARN("Set null chart data for CurvePanel {}", GetIndex()); + } +} + +void CurvePanel::UpdateCurveDisplay() +{ + if (!hasChartData_ || !chartData_) { + return; + } + + // Clear existing layout and recreate + if (layout()) { + QLayoutItem* item; + while ((item = layout()->takeAt(0)) != nullptr) { + delete item->widget(); + delete item; + } + delete layout(); + } + + // Create new layout with chart information + QVBoxLayout* mainLayout = new QVBoxLayout(this); + + // Chart info section + QGroupBox* chartInfoGroup = new QGroupBox(QString("Chart: %1").arg(chartData_->name)); + QVBoxLayout* chartInfoLayout = new QVBoxLayout(chartInfoGroup); + + // Chart details - handle different chart types + QLabel* pathLabel = new QLabel(QString("File: %1").arg(QFileInfo(chartData_->path).fileName())); + chartInfoLayout->addWidget(pathLabel); + + // Type-specific information + if (auto curveChart = std::dynamic_pointer_cast(chartData_)) { + QLabel* titleLabel = new QLabel(QString("Title: X=%1, Y=%2").arg(curveChart->xTitle, curveChart->yTitle)); + QLabel* rangeLabel = new QLabel(QString("Range: X[%1-%2], Y[%3-%4]") + .arg(curveChart->xMin).arg(curveChart->xMax) + .arg(curveChart->yMin).arg(curveChart->yMax)); + QLabel* countLabel = new QLabel(QString("Count: X=%1, T=%2").arg(curveChart->xCount).arg(curveChart->t)); + + chartInfoLayout->addWidget(titleLabel); + chartInfoLayout->addWidget(rangeLabel); + chartInfoLayout->addWidget(countLabel); + + // Curves section + if (!curveChart->curves.isEmpty()) { + QGroupBox* curvesGroup = new QGroupBox(QString("Curves (%1)").arg(curveChart->curves.size())); + QVBoxLayout* curvesLayout = new QVBoxLayout(curvesGroup); + + // Add scroll area for curves + QScrollArea* scrollArea = new QScrollArea(); + QWidget* scrollWidget = new QWidget(); + QVBoxLayout* scrollLayout = new QVBoxLayout(scrollWidget); + + for (const CurveData& curve : curveChart->curves) { + QHBoxLayout* curveLayout = new QHBoxLayout(); + + // Curve checkbox for show/hide + QCheckBox* curveCheckBox = new QCheckBox(curve.name); + curveCheckBox->setChecked(true); + + // Curve info + QLabel* curveInfo = new QLabel(QString("Range: %1-%2, Color: %3") + .arg(curve.start).arg(curve.stop).arg(curve.color)); + curveInfo->setStyleSheet(QString("QLabel { color: rgb(%1); }").arg(curve.color)); + + curveLayout->addWidget(curveCheckBox); + curveLayout->addWidget(curveInfo); + curveLayout->addStretch(); + + scrollLayout->addLayout(curveLayout); + } + + scrollWidget->setLayout(scrollLayout); + scrollArea->setWidget(scrollWidget); + scrollArea->setWidgetResizable(true); + scrollArea->setMaximumHeight(200); + + curvesLayout->addWidget(scrollArea); + mainLayout->addWidget(curvesGroup); + } + + } else if (auto surfaceChart = std::dynamic_pointer_cast(chartData_)) { + QLabel* titleLabel = new QLabel(QString("Title: X=%1, Y=%2, Z=%3") + .arg(surfaceChart->xTitle, surfaceChart->yTitle, surfaceChart->zTitle)); + QLabel* rangeLabel = new QLabel(QString("Range: X[%1-%2], Y[%3-%4], Z[%5-%6]") + .arg(surfaceChart->xMin).arg(surfaceChart->xMax) + .arg(surfaceChart->yMin).arg(surfaceChart->yMax) + .arg(surfaceChart->zMin).arg(surfaceChart->zMax)); + QLabel* countLabel = new QLabel(QString("Count: X=%1, Y=%2, Z=%3, T=%4") + .arg(surfaceChart->xCount).arg(surfaceChart->yCount) + .arg(surfaceChart->zCount).arg(surfaceChart->t)); + + chartInfoLayout->addWidget(titleLabel); + chartInfoLayout->addWidget(rangeLabel); + chartInfoLayout->addWidget(countLabel); + + // Surface curves section + if (!surfaceChart->curves.isEmpty()) { + QGroupBox* curvesGroup = new QGroupBox(QString("Surface Curves (%1)").arg(surfaceChart->curves.size())); + QVBoxLayout* curvesLayout = new QVBoxLayout(curvesGroup); + + QScrollArea* scrollArea = new QScrollArea(); + QWidget* scrollWidget = new QWidget(); + QVBoxLayout* scrollLayout = new QVBoxLayout(scrollWidget); + + for (const SurfaceCurveData& curve : surfaceChart->curves) { + QHBoxLayout* curveLayout = new QHBoxLayout(); + + QCheckBox* curveCheckBox = new QCheckBox(curve.name); + curveCheckBox->setChecked(true); + + QLabel* curveInfo = new QLabel(QString("Range: %1-%2, Color: %3, Pos: (%4,%5,%6)") + .arg(curve.start).arg(curve.stop).arg(curve.color) + .arg(curve.x).arg(curve.y).arg(curve.z)); + curveInfo->setStyleSheet(QString("QLabel { color: rgb(%1); }").arg(curve.color)); + + curveLayout->addWidget(curveCheckBox); + curveLayout->addWidget(curveInfo); + curveLayout->addStretch(); + + scrollLayout->addLayout(curveLayout); + } + + scrollWidget->setLayout(scrollLayout); + scrollArea->setWidget(scrollWidget); + scrollArea->setWidgetResizable(true); + scrollArea->setMaximumHeight(200); + + curvesLayout->addWidget(scrollArea); + mainLayout->addWidget(curvesGroup); + } + + } else if (auto tableChart = std::dynamic_pointer_cast(chartData_)) { + QLabel* headLabel = new QLabel(QString("Head: %1").arg(tableChart->head)); + QLabel* timeLabel = new QLabel(QString("Time: %1").arg(tableChart->t)); + + chartInfoLayout->addWidget(headLabel); + chartInfoLayout->addWidget(timeLabel); + + // Table curves section + if (!tableChart->curves.isEmpty()) { + QGroupBox* curvesGroup = new QGroupBox(QString("Table Data (%1)").arg(tableChart->curves.size())); + QVBoxLayout* curvesLayout = new QVBoxLayout(curvesGroup); + + QScrollArea* scrollArea = new QScrollArea(); + QWidget* scrollWidget = new QWidget(); + QVBoxLayout* scrollLayout = new QVBoxLayout(scrollWidget); + + for (const TableCurveData& curve : tableChart->curves) { + QHBoxLayout* curveLayout = new QHBoxLayout(); + + QCheckBox* curveCheckBox = new QCheckBox(curve.name); + curveCheckBox->setChecked(true); + + QLabel* curveInfo = new QLabel(QString("Color: %1, Data: %2") + .arg(curve.color).arg(curve.data)); + curveInfo->setStyleSheet(QString("QLabel { color: rgb(%1); }").arg(curve.color)); + + curveLayout->addWidget(curveCheckBox); + curveLayout->addWidget(curveInfo); + curveLayout->addStretch(); + + scrollLayout->addLayout(curveLayout); + } + + scrollWidget->setLayout(scrollLayout); + scrollArea->setWidget(scrollWidget); + scrollArea->setWidgetResizable(true); + scrollArea->setMaximumHeight(200); + + curvesLayout->addWidget(scrollArea); + mainLayout->addWidget(curvesGroup); + } + + } else if (auto lightChart = std::dynamic_pointer_cast(chartData_)) { + QLabel* colorLabel = new QLabel(QString("Open Color: %1, Close Color: %2") + .arg(lightChart->openColor).arg(lightChart->closeColor)); + QLabel* timeLabel = new QLabel(QString("Time: %1").arg(lightChart->t)); + + chartInfoLayout->addWidget(colorLabel); + chartInfoLayout->addWidget(timeLabel); + + // Light curves section + if (!lightChart->curves.isEmpty()) { + QGroupBox* curvesGroup = new QGroupBox(QString("Light Data (%1)").arg(lightChart->curves.size())); + QVBoxLayout* curvesLayout = new QVBoxLayout(curvesGroup); + + QScrollArea* scrollArea = new QScrollArea(); + QWidget* scrollWidget = new QWidget(); + QVBoxLayout* scrollLayout = new QVBoxLayout(scrollWidget); + + for (const LightCurveData& curve : lightChart->curves) { + QHBoxLayout* curveLayout = new QHBoxLayout(); + + QCheckBox* curveCheckBox = new QCheckBox(curve.name); + curveCheckBox->setChecked(true); + + QLabel* curveInfo = new QLabel(QString("Data: %1").arg(curve.data)); + + curveLayout->addWidget(curveCheckBox); + curveLayout->addWidget(curveInfo); + curveLayout->addStretch(); + + scrollLayout->addLayout(curveLayout); + } + + scrollWidget->setLayout(scrollLayout); + scrollArea->setWidget(scrollWidget); + scrollArea->setWidgetResizable(true); + scrollArea->setMaximumHeight(200); + + curvesLayout->addWidget(scrollArea); + mainLayout->addWidget(curvesGroup); + } + } + + mainLayout->addWidget(chartInfoGroup); + + // Placeholder for actual curve rendering + QLabel* renderLabel = new QLabel("Curve Rendering Area\n(To be implemented by rendering team)"); + renderLabel->setAlignment(Qt::AlignCenter); + renderLabel->setStyleSheet("QLabel { color: #666; font-size: 12px; padding: 20px; border: 1px dashed #ccc; }"); + renderLabel->setMinimumHeight(200); + + mainLayout->addWidget(renderLabel); + mainLayout->addStretch(); + + setLayout(mainLayout); +} + void CurvePanel::InitUI() { - // Create basic layout - QVBoxLayout* layout = new QVBoxLayout(this); - - // Add placeholder label showing panel information - QLabel* infoLabel = new QLabel(QString("Curve Panel %1\nFile: %2\n\nCurve Drawing Area\nPlease inherit this class to implement specific drawing functionality") - .arg(GetIndex()) - .arg(QFileInfo(GetFilePath()).fileName())); - infoLabel->setAlignment(Qt::AlignCenter); - infoLabel->setStyleSheet("QLabel { color: #666; font-size: 12px; padding: 20px; }"); - - layout->addWidget(infoLabel); - setLayout(layout); + if (hasChartData_) { + UpdateCurveDisplay(); + } else { + // Create basic layout for file-based panel + QVBoxLayout* layout = new QVBoxLayout(this); + + // Add placeholder label showing panel information + QLabel* infoLabel = new QLabel(QString("Curve Panel %1\nFile: %2\n\nCurve Drawing Area\nPlease inherit this class to implement specific drawing functionality") + .arg(GetIndex()) + .arg(QFileInfo(GetFilePath()).fileName())); + infoLabel->setAlignment(Qt::AlignCenter); + infoLabel->setStyleSheet("QLabel { color: #666; font-size: 12px; padding: 20px; }"); + + layout->addWidget(infoLabel); + setLayout(layout); + } } QString CurvePanel::GetTypeDisplayName() const diff --git a/src/ui/Panel/CurvePanel.h b/src/ui/Panel/CurvePanel.h index 1fa7e231..fa7752ad 100644 --- a/src/ui/Panel/CurvePanel.h +++ b/src/ui/Panel/CurvePanel.h @@ -1,6 +1,8 @@ #pragma once #include "DataPanel.h" +#include "workspace/ChartData.h" +#include /** * @file CurvePanel.h @@ -25,6 +27,14 @@ public: */ explicit CurvePanel(int index, const QString& filePath, QWidget* parent = nullptr); + /** + * @brief Constructor with chart data + * @param index Panel index + * @param chartData Chart data containing curve information + * @param parent Parent widget + */ + explicit CurvePanel(int index, std::shared_ptr chartData, QWidget* parent = nullptr); + /** * @brief Destructor */ @@ -41,6 +51,18 @@ public: */ void RefreshPanel() override; + /** + * @brief Set chart data + * @param chartData Chart data to display + */ + void SetChartData(std::shared_ptr chartData); + + /** + * @brief Get current chart data + * @return Current chart data + */ + std::shared_ptr GetChartData() const { return chartData_; } + protected: /** * @brief Initialize UI for curve-specific layout @@ -52,4 +74,14 @@ protected: * @return Display name for curve type */ QString GetTypeDisplayName() const override; + +private: + /** + * @brief Update curve display based on chart data + */ + void UpdateCurveDisplay(); + +private: + std::shared_ptr chartData_; // Chart data containing curve information + bool hasChartData_; // Flag indicating if chart data is available }; \ No newline at end of file diff --git a/src/ui/Panel/DataPanel.h b/src/ui/Panel/DataPanel.h index 611a7879..b75372ba 100644 --- a/src/ui/Panel/DataPanel.h +++ b/src/ui/Panel/DataPanel.h @@ -16,8 +16,7 @@ class DockWidget; * @brief Data panel base class * Provides panel framework structure for different data types, specific functionality implemented by derived classes */ -class DataPanel : public QWidget -{ +class DataPanel : public QWidget { Q_OBJECT public: @@ -106,7 +105,7 @@ protected: */ virtual QString GetTypeDisplayName() const; -private: + // Protected members accessible by derived classes int index_; // Panel index FileEntryType fileType_; // File type QString filePath_; // Associated file path diff --git a/src/ui/Panel/DataPanelFactory.cpp b/src/ui/Panel/DataPanelFactory.cpp index 2e59f7a7..49ae32f6 100644 --- a/src/ui/Panel/DataPanelFactory.cpp +++ b/src/ui/Panel/DataPanelFactory.cpp @@ -8,7 +8,7 @@ // #include "TablePanel.h" // #include "LightPanel.h" -DataPanel* DataPanelFactory::CreatePanel(int index, FileEntryType fileType, const QString& filePath, QWidget* parent) +DataPanel* DataPanelFactory::CreatePanel(FileEntryType fileType, int index, const QString& filePath, QWidget* parent) { switch (fileType) { case FileEntryType::Curve: @@ -37,6 +37,13 @@ DataPanel* DataPanelFactory::CreatePanel(int index, FileEntryType fileType, cons } } +DataPanel* DataPanelFactory::CreatePanelWithChartData(FileEntryType type, int index, std::shared_ptr chartData, QWidget* parent) +{ + // Currently only CurvePanel supports ChartData + // In the future, other panel types may also support chart data + return new CurvePanel(index, chartData, parent); +} + bool DataPanelFactory::IsTypeSupported(FileEntryType fileType) { switch (fileType) { diff --git a/src/ui/Panel/DataPanelFactory.h b/src/ui/Panel/DataPanelFactory.h index a72b631c..988722ec 100644 --- a/src/ui/Panel/DataPanelFactory.h +++ b/src/ui/Panel/DataPanelFactory.h @@ -1,49 +1,21 @@ #pragma once +#include "ui/Panel/DataPanel.h" +#include "workspace/ChartData.h" #include -#include "workspace/FileEntry.h" -class DataPanel; -class QWidget; - -/** - * @file DataPanelFactory.h - * @brief Data Panel Factory - * Creates appropriate panel instances based on file type - */ - -/** - * @brief Data panel factory class - * Creates appropriate panel instances based on file type using factory pattern - */ class DataPanelFactory { public: - /** - * @brief Create panel based on file type - * @param index Panel index - * @param fileType File type - * @param filePath File path - * @param parent Parent widget - * @return Created panel pointer (caller takes ownership) - */ - static DataPanel* CreatePanel(int index, FileEntryType fileType, const QString& filePath, QWidget* parent = nullptr); - - /** - * @brief Check if file type is supported - * @param fileType File type to check - * @return True if supported, false otherwise - */ - static bool IsTypeSupported(FileEntryType fileType); - - /** - * @brief Get display name for file type - * @param fileType File type - * @return Display name - */ - static QString GetTypeDisplayName(FileEntryType fileType); - -private: - // Private constructor to prevent instantiation - DataPanelFactory() = default; + // Create panel with file path + static DataPanel* CreatePanel(FileEntryType type, int index, const QString& filePath, QWidget* parent = nullptr); + + // Create panel with chart data + static DataPanel* CreatePanelWithChartData(FileEntryType type, int index, std::shared_ptr chartData, QWidget* parent = nullptr); + + // Check if a panel type is supported + static bool IsTypeSupported(FileEntryType type); + + // Get display name for a panel type + static QString GetTypeDisplayName(FileEntryType type); }; \ No newline at end of file diff --git a/src/ui/Panel/DataPanelManager.cpp b/src/ui/Panel/DataPanelManager.cpp index 8764e78b..46eb1b64 100644 --- a/src/ui/Panel/DataPanelManager.cpp +++ b/src/ui/Panel/DataPanelManager.cpp @@ -186,7 +186,7 @@ DataPanel* DataPanelManager::CreateDataPanel(FileEntryType fileType, const QStri mainWindow_->addDockWidget(Qt::RightDockWidgetArea, dockWidget); // Create panel using factory - DataPanel* panel = DataPanelFactory::CreatePanel(index, fileType, filePath, dockWidget); + DataPanel* panel = DataPanelFactory::CreatePanel(fileType, index, filePath, dockWidget); if (!panel) { LOG_ERROR("Failed to create panel for type: {}", FileEntryTypeToString(fileType)); dockWidget->deleteLater(); diff --git a/src/ui/PropertyBrowser/qtpropertymanager.cpp b/src/ui/PropertyBrowser/qtpropertymanager.cpp index 2b4d5162..7d17810f 100644 --- a/src/ui/PropertyBrowser/qtpropertymanager.cpp +++ b/src/ui/PropertyBrowser/qtpropertymanager.cpp @@ -8719,7 +8719,7 @@ void QtEntityPropertyManager::initializeProperty(QtProperty* property) { \reimp */ void QtEntityPropertyManager::uninitializeProperty(QtProperty* property) { - // 清理 Name 属性 + QtProperty* prop = d_ptr->m_properyToName.value(property, nullptr); if (prop) { d_ptr->m_nameToPropery.remove(prop); @@ -8727,7 +8727,7 @@ void QtEntityPropertyManager::uninitializeProperty(QtProperty* property) { } d_ptr->m_properyToName.remove(property); - // 清理 Visible 属性 + prop = d_ptr->m_properyToVisible.value(property, nullptr); if (prop) { d_ptr->m_visibleToPropery.remove(prop); @@ -8735,7 +8735,7 @@ void QtEntityPropertyManager::uninitializeProperty(QtProperty* property) { } d_ptr->m_properyToVisible.remove(property); - // 清理 Transform 属性 + prop = d_ptr->m_properyTotrans.value(property, nullptr); if (prop) { d_ptr->m_transToPropery.remove(prop); diff --git a/src/ui/PropertyBrowser/qtworkspaceattribute.cpp b/src/ui/PropertyBrowser/qtworkspaceattribute.cpp index e9c42cbb..b402d5f9 100644 --- a/src/ui/PropertyBrowser/qtworkspaceattribute.cpp +++ b/src/ui/PropertyBrowser/qtworkspaceattribute.cpp @@ -188,7 +188,7 @@ const QString QWorkspaceAttribute::GetCommondFilePath() const return ""; } - // 只返回文件名,不包含完整路径 + return workspace_->GetCommondFilePath(); } diff --git a/src/ui/Table/targetlistwgt.cpp b/src/ui/Table/targetlistwgt.cpp index 1ba0c782..f492c8a5 100644 --- a/src/ui/Table/targetlistwgt.cpp +++ b/src/ui/Table/targetlistwgt.cpp @@ -1,4 +1,4 @@ -#include "targetlistwgt.h" +#include "targetlistwgt.h" #include #include @@ -28,7 +28,7 @@ TargetListWgt::TargetListWgt(QWidget * parent) : QWidget(parent) { setWindowFlags(/*Qt::FramelessWindowHint | */Qt::Window); QHeaderView* horizontalHeader = ui.tableWidget->horizontalHeader(); - QColor headerColor = QColor(100, 100, 100); // 灰色 + QColor headerColor = QColor(100, 100, 100); horizontalHeader->setStyleSheet(QString("QHeaderView::section {background-color: %1;}").arg(headerColor.name())); horizontalHeader->setStretchLastSection(true); diff --git a/src/ui/Table/targetlistwgt.h b/src/ui/Table/targetlistwgt.h index 82dad9db..410b1906 100644 --- a/src/ui/Table/targetlistwgt.h +++ b/src/ui/Table/targetlistwgt.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include "ui/Dialog.h" @@ -37,7 +37,7 @@ protected slots: void slotSortTabCol(int nCol); void slotUpdateTime(double dTime); - void slotDoubleClickedItem(QTableWidgetItem *pItem); // 双击行 + void slotDoubleClickedItem(QTableWidgetItem *pItem); void slotClickedItem(QTableWidgetItem *pItem); void OnWorkSpaceChanged(class WorkSpace*); diff --git a/src/ui/WorkSpace/AddFileDlg.cpp b/src/ui/WorkSpace/AddFileDlg.cpp new file mode 100644 index 00000000..6502137b --- /dev/null +++ b/src/ui/WorkSpace/AddFileDlg.cpp @@ -0,0 +1,125 @@ +#include "AddFileDlg.h" +#include "ui_AddFileDlg.h" + +#include +#include +#include +#include + +#include "app/Application.h" +#include "common/SpdLogger.h" + +AddFileDlg::AddFileDlg(QWidget* parent) + : Dialog(parent) + , ui(new Ui::AddFileDlg) + , selectedFileType_(FileEntryType::Curve) { + ui->setupUi(this); + + // 设置对话框标题 + SetTitle(QStringLiteral("Add File to Workspace")); + + InitConnect(); + UpdateUI(); +} + +AddFileDlg::~AddFileDlg() { + delete ui; +} + +void AddFileDlg::InitConnect() { + connect(ui->tbSelectFile, &QToolButton::clicked, this, &AddFileDlg::OnSelectFile); + connect(ui->cbFileType, QOverload::of(&QComboBox::currentIndexChanged), + this, &AddFileDlg::OnFileTypeChanged); + connect(ui->pbAdd, &QPushButton::clicked, this, &AddFileDlg::OnSure); + connect(ui->pbCancel, &QPushButton::clicked, this, &AddFileDlg::reject); +} + +void AddFileDlg::OnSelectFile() { + const QString workspacePath = Application::GetWorkSpacePath(); + QString filePath = QFileDialog::getOpenFileName( + this, + QStringLiteral("Select File"), + workspacePath, + QStringLiteral("Text Files (*.txt);;All Files (*.*)") + ); + + if (filePath.isEmpty()) { + return; + } + + selectedFilePath_ = filePath; + ui->leFilePath->setText(filePath); + + QFileInfo fileInfo(filePath); + ui->lblFileName->setText(fileInfo.fileName()); + + 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->lblFileSize->setText(sizeText); + + LOG_INFO("Selected file: {}", filePath.toStdString()); +} + +void AddFileDlg::OnFileTypeChanged() { + int index = ui->cbFileType->currentIndex(); + switch (index) { + case 0: selectedFileType_ = FileEntryType::Curve; break; + case 1: selectedFileType_ = FileEntryType::Surface; break; + case 2: selectedFileType_ = FileEntryType::Table; break; + case 3: selectedFileType_ = FileEntryType::Light; break; + default: selectedFileType_ = FileEntryType::Curve; break; + } + + LOG_INFO("File type changed to: {}", static_cast(selectedFileType_)); +} + +void AddFileDlg::OnSure() { + if (!ValidateInput()) { + return; + } + + accept(); +} + +void AddFileDlg::UpdateUI() { + ui->lblFileName->setText(QStringLiteral("-")); + ui->lblFileSize->setText(QStringLiteral("-")); + ui->cbFileType->setCurrentIndex(0); + selectedFileType_ = FileEntryType::Curve; +} + +bool AddFileDlg::ValidateInput() { + if (selectedFilePath_.isEmpty()) { + QMessageBox::warning(this, QStringLiteral("Warning"), + QStringLiteral("Please select a file first.")); + return false; + } + + QFileInfo fileInfo(selectedFilePath_); + if (!fileInfo.exists()) { + QMessageBox::warning(this, QStringLiteral("Warning"), + QStringLiteral("Selected file does not exist.")); + return false; + } + + return true; +} + +FileEntryType AddFileDlg::getSelectedFileType() const { + return selectedFileType_; +} + +QString AddFileDlg::getSelectedFilePath() const { + return selectedFilePath_; +} + +QString AddFileDlg::getDescription() const { + return ui->teDescription->toPlainText().trimmed(); +} \ No newline at end of file diff --git a/src/ui/WorkSpace/AddFileDlg.h b/src/ui/WorkSpace/AddFileDlg.h new file mode 100644 index 00000000..25d4734d --- /dev/null +++ b/src/ui/WorkSpace/AddFileDlg.h @@ -0,0 +1,37 @@ +#pragma once + +#include "ui/Dialog.h" +#include "workspace/FileEntry.h" + +namespace Ui { + class AddFileDlg; +} + +class AddFileDlg : public Dialog { + Q_OBJECT + +public: + AddFileDlg(QWidget* parent = nullptr); + ~AddFileDlg() override; + + FileEntryType getSelectedFileType() const; + + QString getSelectedFilePath() const; + + QString getDescription() const; + +protected: + void InitConnect(); + void OnSure(); + void OnSelectFile(); + void OnFileTypeChanged(); + +private: + void UpdateUI(); + bool ValidateInput(); + +private: + Ui::AddFileDlg* ui; + QString selectedFilePath_; + FileEntryType selectedFileType_; +}; \ No newline at end of file diff --git a/src/ui/WorkSpace/AddFileDlg.ui b/src/ui/WorkSpace/AddFileDlg.ui new file mode 100644 index 00000000..0af1c6ad --- /dev/null +++ b/src/ui/WorkSpace/AddFileDlg.ui @@ -0,0 +1,266 @@ + + + AddFileDlg + + + + 0 + 0 + 480 + 320 + + + + Add File to Workspace + + + + + + + + File Path + + + + 80 + 0 + + + + + + + + true + + + Select file to add... + + + + + + + ... + + + + 30 + 25 + + + + + + + + + + + + File Type + + + + 80 + 0 + + + + + + + + + Curve Data + + + + + Surface Data + + + + + Table Data + + + + + Light Data + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + File Information + + + + + + + + File Name: + + + + + + + - + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + File Size: + + + + + + + - + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + Description (Optional) + + + + + + + + 16777215 + 60 + + + + Enter file description... + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add File + + + + 80 + 30 + + + + + + + + Cancel + + + + 80 + 30 + + + + + + + + + + + \ No newline at end of file diff --git a/src/ui/chartPlot/DYTChart.cpp b/src/ui/chartPlot/DYTChart.cpp index 402b9acf..904f77f0 100644 --- a/src/ui/chartPlot/DYTChart.cpp +++ b/src/ui/chartPlot/DYTChart.cpp @@ -104,7 +104,7 @@ void DYTChart::InitChartData(QVariant var) InitXTable(strFilePathX); InitYTable(strFilePathY); - // ά + // ��ά���� if (m_iCurveType == 3) { QString strFilePathZ = varCurParamMap.value("zFile").toString(); @@ -130,7 +130,7 @@ void DYTChart::InitChart(int iType) ui.comboBox->hide(); - if (1 == iType) // ά + if (1 == iType) // ��ά���� { /*m_p2DCurve = new FitCurveDialog(1); m_p2DCurve->show(); @@ -150,7 +150,7 @@ void DYTChart::InitChart(int iType) ui.label_7->hide(); ui.toolButton_10->hide(); } - else if (2 == iType) // άߣy + else if (2 == iType) // ��ά���ߣ�y������� { //m_p2DLgCurve = new FitCurveDialog(2); ////ui.stackedWidget->insertWidget(0, m_p2DLgCurve); @@ -171,7 +171,7 @@ void DYTChart::InitChart(int iType) ui.label_7->hide(); ui.toolButton_10->hide(); } - else // ά + else // ��ά���� { ui.label_13->hide(); ui.comboBox_3->hide(); @@ -210,7 +210,7 @@ void DYTChart::ParseAnimationPath(const QString& strFile, std::vector& vecTime { if (strFile.isEmpty()) { - QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("TimeStepļ·")); + QMessageBox::information(nullptr, QStringLiteral("Error"), QStringLiteral("Please check TimeStep file path")); return; } @@ -267,11 +267,11 @@ void DYTChart::ParseAntennaPatternFile(const QString& strFile, std::vector>& { if (strFile.isEmpty()) { - QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("RDļ·")); + QMessageBox::information(nullptr, QString::fromLocal8Bit("��ʾ"), QString::fromLocal8Bit("��������RD�ļ�·����")); return; } @@ -332,7 +332,7 @@ void DYTChart::ParseRD(const QString& strFile, std::vector>& if (file.open(QIODevice::ReadOnly)) { int iRow = 0; - int iStartReadRow = iRowCount * m_iCurTime; // ʼ + int iStartReadRow = iRowCount * m_iCurTime; // ��ʼ �� while (!file.atEnd()) { if (iRow >= iStartReadRow && (iRow - iStartReadRow) <= iRowCount) @@ -366,7 +366,7 @@ void DYTChart::ParseWave(const QString& strFile, std::vector> { if (strFile.isEmpty()) { - QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("Waveļ·")); + QMessageBox::information(nullptr, QString::fromLocal8Bit("��ʾ"), QString::fromLocal8Bit("��������Wave�ļ�·����")); return; } @@ -374,7 +374,7 @@ void DYTChart::ParseWave(const QString& strFile, std::vector> if (file.open(QIODevice::ReadOnly)) { int iRow = 0; - int iStartReadRow = iRowCount * m_iCurTime; // ʼ + int iStartReadRow = iRowCount * m_iCurTime; // ��ʼ �� while (!file.atEnd()) { if (iRow >= iStartReadRow && (iRow - iStartReadRow) <= iRowCount) @@ -769,33 +769,33 @@ void DYTChart::UpdateRDCurve(int iTime, int iSelRowCount) varCurDataList.push_back(varX); } - // ɫ + // ������ɫ QColor curColor; curColor.setNamedColor(ui.label_4->text()); - // + // �������� QString strName = ui.lineEdit_2->text(); - // y 0һ1 + // y������ 0һ��1���� int iYType = 0; if (2 == m_iCurveType) { iYType = 1; } - // x + // x������ QString strFilePathX = ui.lineEdit->text(); - // y + // y������ QString strFilePathY = ui.lineEdit_3->text(); - // Z + // Z������ QString strFilePathZ = ui.lineEdit_9->text(); - // + // �������� //int iCurveType = ui.comboBox_2->currentIndex(); - // x + // x���� QString strXTitle = ui.lineEdit_10->text(); - // y + // y���� QString strYTitle = ui.lineEdit_11->text(); - // z + // z���� QString strZTitle = ui.lineEdit_12->text(); int iXCol = 0, iYCol = 0, iZCol = 0; @@ -866,10 +866,10 @@ void DYTChart::Clear() void DYTChart::slotSelXFile() { - QString strFilePath = QFileDialog::getOpenFileName(nullptr, QString::fromLocal8Bit("ѡļ"), "home", "*.txt"); + QString strFilePath = QFileDialog::getOpenFileName(nullptr, QString::fromLocal8Bit("ѡ�������ļ�"), "home", "*.txt"); if (strFilePath.isEmpty()) { - QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("ѡЧļ·")); + QMessageBox::information(nullptr, QString::fromLocal8Bit("��ʾ"), QString::fromLocal8Bit("��ѡ����Ч���ļ�·����")); return; } @@ -880,10 +880,10 @@ void DYTChart::slotSelXFile() void DYTChart::slotSelYFile() { - QString strFilePath = QFileDialog::getOpenFileName(nullptr, QString::fromLocal8Bit("ѡļ"), "home", "*.txt"); + QString strFilePath = QFileDialog::getOpenFileName(nullptr, QString::fromLocal8Bit("ѡ�������ļ�"), "home", "*.txt"); if (strFilePath.isEmpty()) { - QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("ѡЧļ·")); + QMessageBox::information(nullptr, QString::fromLocal8Bit("��ʾ"), QString::fromLocal8Bit("��ѡ����Ч���ļ�·����")); return; } @@ -894,10 +894,10 @@ void DYTChart::slotSelYFile() void DYTChart::slotSelZFile() { - QString strFilePath = QFileDialog::getOpenFileName(nullptr, QString::fromLocal8Bit("ѡļ"), "home", "*.txt"); + QString strFilePath = QFileDialog::getOpenFileName(nullptr, QString::fromLocal8Bit("ѡ�������ļ�"), "home", "*.txt"); if (strFilePath.isEmpty()) { - QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("ѡЧļ·")); + QMessageBox::information(nullptr, QString::fromLocal8Bit("��ʾ"), QString::fromLocal8Bit("��ѡ����Ч���ļ�·����")); return; } @@ -997,19 +997,19 @@ void DYTChart::slotAdd() } - // x + // x������ QString strFilePathX = ui.lineEdit->text(); - // y + // y������ QString strFilePathY = ui.lineEdit_3->text(); - // Z + // Z������ QString strFilePathZ = ui.lineEdit_9->text(); - // + // �������� //int iCurveType = ui.comboBox_2->currentIndex(); - // x + // x���� QString strXTitle = ui.lineEdit_10->text(); - // y + // y���� QString strYTitle = ui.lineEdit_11->text(); - // z + // z���� QString strZTitle = ui.lineEdit_12->text(); std::vector vecX; @@ -1017,7 +1017,7 @@ void DYTChart::slotAdd() std::vector> vecZ; int iXCol = 0, iYCol = 0, iZCol = 0; - // ȡx + // ��ȡx������ { iXCol = ui.comboBox_2->currentIndex(); int iRowCount = ui.tableWidget->rowCount(); @@ -1037,12 +1037,12 @@ void DYTChart::slotAdd() } else { - //QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("XļʧܣļǷ")); + //QMessageBox::information(nullptr, QString::fromLocal8Bit("��ʾ"), QString::fromLocal8Bit("X�������ļ�����ʧ�ܣ������ļ��Ƿ�������")); return; } } - // ȡy + // ��ȡy������ { iYCol = ui.comboBox_4->currentIndex(); int iRowCount = ui.tableWidget_2->rowCount(); @@ -1059,12 +1059,12 @@ void DYTChart::slotAdd() } else { - //QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("YļʧܣļǷ")); + //QMessageBox::information(nullptr, QString::fromLocal8Bit("��ʾ"), QString::fromLocal8Bit("Y�������ļ�����ʧ�ܣ������ļ��Ƿ�������")); return; } } - // ά + // ��ά���� if (m_iCurveType == 3) { //iZCol = ui.comboBox_5->currentIndex(); @@ -1089,23 +1089,23 @@ void DYTChart::slotAdd() } else { - //QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("ZļʧܣļǷ")); + //QMessageBox::information(nullptr, QString::fromLocal8Bit("��ʾ"), QString::fromLocal8Bit("Z�������ļ�����ʧ�ܣ������ļ��Ƿ�������")); return; } } - // ݵijȣСȶ + // �����������ݵij��ȣ�����С���ȶ��� size_t min_size = std::min({ vecX.size(), vecY.size() }); if (vecZ.size() > 0) { min_size = std::min({ min_size, vecZ.size() }); } - // ϲ + // �ϲ����� QVariantList varCurDataList; for (size_t i = 0; i < min_size; i++) { - if (m_iCurveType == 3) // ά + if (m_iCurveType == 3) // ��ά�������� { std::vector vecZRow = vecZ[i]; @@ -1128,21 +1128,21 @@ void DYTChart::slotAdd() } } - // ɫ + // ������ɫ QColor curColor; curColor.setNamedColor(ui.label_4->text()); - // + // �������� QString strName = ui.lineEdit_2->text(); - // y 0һ1 + // y������ 0һ��1���� int iYType = 0; if (2 == m_iCurveType) { iYType = 1; } - // ID + // ����ID m_iCurveID++; m_iCurSelID = m_iCurveID; @@ -1200,19 +1200,19 @@ void DYTChart::slotUpdate() return; } - // x + // x������ QString strFilePathX = ui.lineEdit->text(); - // y + // y������ QString strFilePathY = ui.lineEdit_3->text(); - // Z + // Z������ QString strFilePathZ = ui.lineEdit_9->text(); - // + // �������� //int iCurveType = ui.comboBox_2->currentIndex(); - // x + // x���� QString strXTitle = ui.lineEdit_10->text(); - // y + // y���� QString strYTitle = ui.lineEdit_11->text(); - // z + // z���� QString strZTitle = ui.lineEdit_12->text(); std::vector vecX; @@ -1220,7 +1220,7 @@ void DYTChart::slotUpdate() std::vector> vecZ; int iXCol = 0, iYCol = 0, iZCol = 0; - // ȡx + // ��ȡx������ { iXCol = ui.comboBox_2->currentIndex(); int iRowCount = ui.tableWidget->rowCount(); @@ -1240,12 +1240,12 @@ void DYTChart::slotUpdate() } else { - QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("XļʧܣļǷ")); + QMessageBox::information(nullptr, QString::fromLocal8Bit("��ʾ"), QString::fromLocal8Bit("X�������ļ�����ʧ�ܣ������ļ��Ƿ�������")); return; } } - // ȡy + // ��ȡy������ { iYCol = ui.comboBox_4->currentIndex(); int iRowCount = ui.tableWidget_2->rowCount(); @@ -1262,12 +1262,12 @@ void DYTChart::slotUpdate() } else { - QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("YļʧܣļǷ")); + QMessageBox::information(nullptr, QString::fromLocal8Bit("��ʾ"), QString::fromLocal8Bit("Y�������ļ�����ʧ�ܣ������ļ��Ƿ�������")); return; } } - // ά + // ��ά���� if (m_iCurveType == 3) { //iZCol = ui.comboBox_5->currentIndex(); @@ -1292,23 +1292,23 @@ void DYTChart::slotUpdate() } else { - QMessageBox::information(nullptr, QString::fromLocal8Bit("ʾ"), QString::fromLocal8Bit("ZļʧܣļǷ")); + QMessageBox::information(nullptr, QString::fromLocal8Bit("��ʾ"), QString::fromLocal8Bit("Z�������ļ�����ʧ�ܣ������ļ��Ƿ�������")); return; } } - // ݵijȣСȶ + // �����������ݵij��ȣ�����С���ȶ��� size_t min_size = std::min({ vecX.size(), vecY.size() }); if (vecZ.size() > 0) { min_size = std::min({ min_size, vecZ.size() }); } - // ϲ + // �ϲ����� QVariantList varCurDataList; for (size_t i = 0; i < min_size; i++) { - if (m_iCurveType == 3) // ά + if (m_iCurveType == 3) // ��ά�������� { std::vector vecZRow = vecZ[i]; @@ -1331,14 +1331,14 @@ void DYTChart::slotUpdate() } } - // ɫ + // ������ɫ QColor curColor; curColor.setNamedColor(ui.label_4->text()); - // + // �������� QString strName = ui.lineEdit_2->text(); - // y 0һ1 + // y������ 0һ��1���� int iYType = 0; if (2 == m_iCurveType) { @@ -1458,7 +1458,7 @@ void DYTChart::slotUpdateTime(double iTime) std::vector vecY; std::vector> vecZ; - // ȡx + // ��ȡx������ { int iRowCount = ui.tableWidget->rowCount(); if (iRowCount > 0) @@ -1477,7 +1477,7 @@ void DYTChart::slotUpdateTime(double iTime) } } - // ȡy + // ��ȡy������ { int iRowCount = ui.tableWidget_2->rowCount(); if (iRowCount > 0) @@ -1493,14 +1493,14 @@ void DYTChart::slotUpdateTime(double iTime) } } - // ݵijȣСȶ + // �����������ݵij��ȣ�����С���ȶ��� size_t min_size = std::min({ vecX.size(), vecY.size() }); if (vecZ.size() > 0) { min_size = std::min({ min_size, vecZ.size() }); } - // ϲ + // �ϲ����� QVariantList varCurDataList; for (size_t i = 0; i < min_size; i++) { diff --git a/src/ui/chartPlot/FitCurveDialog.cpp b/src/ui/chartPlot/FitCurveDialog.cpp index 39abb4bc..297baf95 100644 --- a/src/ui/chartPlot/FitCurveDialog.cpp +++ b/src/ui/chartPlot/FitCurveDialog.cpp @@ -1,4 +1,4 @@ -#include "fitcurvedialog.h" +#include "fitcurvedialog.h" #include @@ -25,57 +25,47 @@ FitCurveDialog::FitCurveDialog(QWidget* parent) : } void FitCurveDialog::initQChartView() { - //创建图表框架 curveChartView = new FitCurveChartView(this); curveChartView->setMaximumWidth(1730); curveChartView->setMinimumHeight(480); curveChart = new QChart(); curveChart->setTheme(QChart::ChartThemeBlueIcy); - //curveChart->setContentsMargins(0, 0, 0, 0); //设置外边界全部为0, 根据自己实际情况设置 - //curveChart->setMargins(QMargins(5, -30, 5, 10)); //设置内边界, 根据自己实际情况设置 - curveChart->setBackgroundRoundness(0); //设置表格边框圆角半径 + curveChart->setBackgroundRoundness(0); curveChartView->setChart(curveChart); - //创建坐标轴 m_pAxisX = new QValueAxis; m_pAxisX->setRange(0, 10); - //m_pAxisX->setTickCount(21); - //m_pAxisX->setLabelFormat("%d"); - m_pAxisX->setLabelsAngle(-90); //坐标刻度文字显示角度 + m_pAxisX->setLabelsAngle(-90); curveChart->addAxis(m_pAxisX, Qt::AlignBottom); m_pAxisY = new QValueAxis; m_pAxisY->setRange(0, 10); - //m_pAxisY->setTickCount(11); - //m_pAxisY->setLabelFormat("%d"); curveChart->addAxis(m_pAxisY, Qt::AlignLeft); - curveChartView->setRenderHint(QPainter::Antialiasing); //除锯齿 - //connect(curveChartView, &FitCurveChartView::signalMouseEvent, this, &FitCurveDialog::theSlotMouseEvent); - //connect(curveChartView, &FitCurveChartView::signalWheelEvent, this, &FitCurveDialog::theSlotWheelEvent); + curveChartView->setRenderHint(QPainter::Antialiasing); QHBoxLayout* pLayout = new QHBoxLayout(this); pLayout->addWidget(curveChartView); } void FitCurveDialog::theSlotMouseEvent(int eventId, QMouseEvent* event) { - if (eventId == 0) { //单击按下 + if (eventId == 0) { isPressed = true; QMouseEvent* mouseEvent = static_cast(event); pressedPoint = mouseEvent->pos(); } - else if (eventId == 1) { //鼠标移动 + else if (eventId == 1) { if (isPressed) { QMouseEvent* mouseEvent = static_cast(event); curveChart->scroll(-(mouseEvent->pos().x() - pressedPoint.x()) / 10, (mouseEvent->pos().y() - pressedPoint.y()) / 10); } } - else if (eventId == 2) { //单击抬起 + else if (eventId == 2) { isPressed = false; } - else if (eventId == 3) { //双击 + else if (eventId == 3) { resetZoomAndScroll(); } } @@ -187,7 +177,7 @@ void FitCurveDialog::updateParseWaveFile(const QString& strFile, int nT, QVarian { if (strFile.isEmpty()) { - QMessageBox::information(nullptr, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("请检查数据Wave文件路径!")); + QMessageBox::information(nullptr, QStringLiteral("Error"), QStringLiteral("Please check Wave file path")); return; } @@ -304,7 +294,7 @@ void FitCurveDialog::updateParseReportFile(const QString & strFile, int nT, QVar { if (strFile.isEmpty()) { - QMessageBox::information(nullptr, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("请检查数据文件路径!")); + QMessageBox::information(nullptr, QStringLiteral("Error"), QStringLiteral("Please check data file path")); return; } diff --git a/src/utils/UiLayoutManager.h b/src/utils/UiLayoutManager.h index 4d1796e7..a022bf39 100644 --- a/src/utils/UiLayoutManager.h +++ b/src/utils/UiLayoutManager.h @@ -1,13 +1,11 @@ -#pragma once +#pragma once #include class QMainWindow; class UiLayoutManager { public: - // 保存主窗口布局到 workspace/UIState.ini static void Save(QMainWindow* mainWindow, int version = 1); - // 从 workspace/UIState.ini 恢复布局 static void Restore(QMainWindow* mainWindow, int version = 1); }; \ No newline at end of file diff --git a/src/viewer/CameraControlManipulator.cpp b/src/viewer/CameraControlManipulator.cpp index 76b4ee36..b5469fb9 100644 --- a/src/viewer/CameraControlManipulator.cpp +++ b/src/viewer/CameraControlManipulator.cpp @@ -826,21 +826,6 @@ bool CameraControlManipulator::handleFrame(const osgGA::GUIEventAdapter& ea, osg // rotation = rotation_matrix.getRotate().inverse(); // } - // QString str = - // QString::fromLocal8Bit("摄像机位置 X=") + QString::number(eye.x()) + - // QString::fromLocal8Bit(", Y=") + QString::number(eye.y()) + - // QString::fromLocal8Bit(", Z=") + QString::number(eye.z()) + - // QString::fromLocal8Bit(", 摄像机角度 X=") + QString::number(rotation.x()) + - // QString::fromLocal8Bit(", Y=") + QString::number(rotation.y()) + - // QString::fromLocal8Bit(", Z=") + QString::number(rotation.z()) + - // QString::fromLocal8Bit(", W=") + QString::number(rotation.w()); - - // if (_pMainWindow) - // { - // //_pMainWindow->SetStatusInfo(str); - // } - //} - return false; } diff --git a/src/workspace/ChartData.h b/src/workspace/ChartData.h new file mode 100644 index 00000000..947bd0cc --- /dev/null +++ b/src/workspace/ChartData.h @@ -0,0 +1,109 @@ +#ifndef CHARTDATA_H +#define CHARTDATA_H + +#include +#include +#include + +#include "workspace/FileEntry.h" + +struct BaseCurveData { + QString name; + + BaseCurveData() = default; + virtual ~BaseCurveData() = default; +}; + +struct CurveColorData : public BaseCurveData { + QString color; +}; + +struct CurveData : public CurveColorData { + double start; + double stop; +}; + +struct TableCurveData : public CurveColorData { + QString data; +}; + +struct SurfaceCurveData : public CurveColorData { + double start; + double stop; + double x; + double y; + double z; +}; + +struct LightCurveData : public BaseCurveData { + QString data; +}; + +class BaseChartData { +public: + QString name; + QString path; + QString t; + + BaseChartData() = default; + virtual ~BaseChartData() = default; + virtual FileEntryType getType() const = 0; +}; + +class CurveChartData : public BaseChartData { +public: + QString xTitle; + QString yTitle; + double xMin; + double xMax; + double yMin; + double yMax; + int xCount; + QList curves; + + FileEntryType getType() const override { return FileEntryType::Curve; } +}; + +class SurfaceChartData : public BaseChartData { +public: + QString xTitle; + QString yTitle; + QString zTitle; + double xMin; + double xMax; + double yMin; + double yMax; + double zMin; + double zMax; + int xCount; + int yCount; + int zCount; + QList curves; + + FileEntryType getType() const override { return FileEntryType::Surface; } +}; + +class TableChartData : public BaseChartData { +public: + QString head; + QList curves; + + FileEntryType getType() const override { return FileEntryType::Table; } +}; + +class LightChartData : public BaseChartData { +public: + QString openColor; + QString closeColor; + QList curves; + + FileEntryType getType() const override { return FileEntryType::Light; } +}; + +struct FileTypeData { + QString typeName; + int count; + QList> charts; +}; + +#endif // CHARTDATA_H \ No newline at end of file diff --git a/src/workspace/WorkSpace.cpp b/src/workspace/WorkSpace.cpp index 511520cd..7605814f 100644 --- a/src/workspace/WorkSpace.cpp +++ b/src/workspace/WorkSpace.cpp @@ -388,3 +388,59 @@ void WorkSpace::ExecuteCommands(CommandWhen when) { } cmdMgr_->Execute(this, when); } + +// Chart data management implementation +void WorkSpace::SetFileTypeData(const QList& fileTypes) { + fileTypeData_ = fileTypes; + ++filesSeq_; + // Emit signals for each type that has data + for (const auto& fileType : fileTypes) { + FileEntryType type; + if (FileEntryTypeFromString(fileType.typeName.toLocal8Bit().constData(), type)) { + emit FilesChanged(type); + } + } +} + +const QList& WorkSpace::GetFileTypeData() const { + return fileTypeData_; +} + +void WorkSpace::AddChartData(FileEntryType type, const std::shared_ptr& chart) { + QString typeName = FileEntryTypeToString(type); + + // Find existing file type data or create new one + auto it = std::find_if(fileTypeData_.begin(), fileTypeData_.end(), + [&typeName](const FileTypeData& data) { + return data.typeName == typeName; + }); + + if (it != fileTypeData_.end()) { + it->charts.append(chart); + it->count = it->charts.size(); + } else { + FileTypeData newData; + newData.typeName = typeName; + newData.count = 1; + newData.charts.append(chart); + fileTypeData_.append(newData); + } + + ++filesSeq_; + emit FilesChanged(type); +} + +QList> WorkSpace::GetChartData(FileEntryType type) const { + QString typeName = FileEntryTypeToString(type); + + auto it = std::find_if(fileTypeData_.begin(), fileTypeData_.end(), + [&typeName](const FileTypeData& data) { + return data.typeName == typeName; + }); + + if (it != fileTypeData_.end()) { + return it->charts; + } + + return QList>(); +} diff --git a/src/workspace/WorkSpace.h b/src/workspace/WorkSpace.h index 6205bfd1..30a3db3d 100644 --- a/src/workspace/WorkSpace.h +++ b/src/workspace/WorkSpace.h @@ -12,6 +12,7 @@ #include "config.h" #include "common/SpdLogger.h" #include "workspace/FileEntry.h" +#include "workspace/ChartData.h" //#include "../ui/chartPlot/DYTChart.h" @@ -89,6 +90,12 @@ public: bool SetFileEntryPath(FileEntryType type, int index, const QString& path); QString GetFileEntryAbsPath(FileEntryType type, int index) const; + // Chart data management + void SetFileTypeData(const QList& fileTypes); + const QList& GetFileTypeData() const; + void AddChartData(FileEntryType type, const std::shared_ptr& chart); + QList> GetChartData(FileEntryType type) const; + inline void SetHomeViewpoint(const osgEarth::Viewpoint& viewpoint) { homeViewpoint_ = viewpoint; homeViewpoint_.setHeading(0.0); // Ensure heading is set to 0.0 @@ -178,6 +185,8 @@ private: class Entity* trackedEntity_{ nullptr }; // Stored as file entries under workspace dir, keyed by type std::map> files_; + // Chart data storage + QList fileTypeData_; // Monotonic sequence for file entries changes, used to trigger UI refresh std::uint64_t filesSeq_{ 0 }; // Executor for command XML actions diff --git a/src/workspace/WorkSpaceXMLParse.cpp b/src/workspace/WorkSpaceXMLParse.cpp index 0af5857d..b6614015 100644 --- a/src/workspace/WorkSpaceXMLParse.cpp +++ b/src/workspace/WorkSpaceXMLParse.cpp @@ -107,12 +107,276 @@ bool WorkSpaceXMLParse::ParseFiles(const tinyxml2::XMLElement* element) { return false; } + QList fileTypes; + const tinyxml2::XMLElement* typeElement = element->FirstChildElement("type"); while (nullptr != typeElement) { const char* name = typeElement->Attribute("name"); int count = 0; typeElement->QueryIntAttribute("count", &count); + if (nullptr != name && count > 0) { + FileTypeData fileTypeData; + fileTypeData.typeName = QString::fromLocal8Bit(name); + fileTypeData.count = count; + + QString typeName = QString::fromLocal8Bit(name); + + // Parse chart elements within this type + const tinyxml2::XMLElement* chartElement = typeElement->FirstChildElement("chart"); + while (nullptr != chartElement) { + std::shared_ptr chartData; + + // Create appropriate chart type based on the file type + if (typeName == FileEntryTypeToString(FileEntryType::Curve)) { + auto curveChart = std::make_shared(); + + // Parse curve-specific attributes + if (const char* chartName = chartElement->Attribute("name")) { + curveChart->name = QString::fromLocal8Bit(chartName); + } + if (const char* path = chartElement->Attribute("path")) { + curveChart->path = QString::fromLocal8Bit(path); + } + if (const char* xTitle = chartElement->Attribute("xTitle")) { + curveChart->xTitle = QString::fromLocal8Bit(xTitle); + } + if (const char* yTitle = chartElement->Attribute("yTitle")) { + curveChart->yTitle = QString::fromLocal8Bit(yTitle); + } + if (const char* xMin = chartElement->Attribute("xMin")) { + curveChart->xMin = QString::fromLocal8Bit(xMin).toDouble(); + } + if (const char* xMax = chartElement->Attribute("xMax")) { + curveChart->xMax = QString::fromLocal8Bit(xMax).toDouble(); + } + if (const char* yMin = chartElement->Attribute("yMin")) { + curveChart->yMin = QString::fromLocal8Bit(yMin).toDouble(); + } + if (const char* yMax = chartElement->Attribute("yMax")) { + curveChart->yMax = QString::fromLocal8Bit(yMax).toDouble(); + } + if (const char* xCount = chartElement->Attribute("xCount")) { + curveChart->xCount = QString::fromLocal8Bit(xCount).toInt(); + } + if (const char* t = chartElement->Attribute("t")) { + curveChart->t = QString::fromLocal8Bit(t); + } + + // Parse curve elements + const tinyxml2::XMLElement* curveElement = chartElement->FirstChildElement("curve"); + while (nullptr != curveElement) { + CurveData curveData; + + if (const char* curveName = curveElement->Attribute("name")) { + curveData.name = QString::fromLocal8Bit(curveName); + } + if (const char* color = curveElement->Attribute("color")) { + curveData.color = QString::fromLocal8Bit(color); + } + if (const char* start = curveElement->Attribute("start")) { + curveData.start = QString::fromLocal8Bit(start).toDouble(); + } + if (const char* stop = curveElement->Attribute("stop")) { + curveData.stop = QString::fromLocal8Bit(stop).toDouble(); + } + + curveChart->curves.append(curveData); + curveElement = curveElement->NextSiblingElement("curve"); + } + + chartData = curveChart; + + } else if (typeName == FileEntryTypeToString(FileEntryType::Surface)) { + auto surfaceChart = std::make_shared(); + + // Parse surface-specific attributes + if (const char* chartName = chartElement->Attribute("name")) { + surfaceChart->name = QString::fromLocal8Bit(chartName); + } + if (const char* chartName = chartElement->Attribute("Name")) { // Handle both cases + surfaceChart->name = QString::fromLocal8Bit(chartName); + } + if (const char* path = chartElement->Attribute("path")) { + surfaceChart->path = QString::fromLocal8Bit(path); + } + if (const char* xTitle = chartElement->Attribute("xTitle")) { + surfaceChart->xTitle = QString::fromLocal8Bit(xTitle); + } + if (const char* yTitle = chartElement->Attribute("yTitle")) { + surfaceChart->yTitle = QString::fromLocal8Bit(yTitle); + } + if (const char* zTitle = chartElement->Attribute("zTitle")) { + surfaceChart->zTitle = QString::fromLocal8Bit(zTitle); + } + if (const char* xMin = chartElement->Attribute("xMin")) { + surfaceChart->xMin = QString::fromLocal8Bit(xMin).toDouble(); + } + if (const char* xMax = chartElement->Attribute("xMax")) { + surfaceChart->xMax = QString::fromLocal8Bit(xMax).toDouble(); + } + if (const char* yMin = chartElement->Attribute("yMin")) { + surfaceChart->yMin = QString::fromLocal8Bit(yMin).toDouble(); + } + if (const char* yMax = chartElement->Attribute("yMax")) { + surfaceChart->yMax = QString::fromLocal8Bit(yMax).toDouble(); + } + if (const char* zMin = chartElement->Attribute("zMin")) { + surfaceChart->zMin = QString::fromLocal8Bit(zMin).toDouble(); + } + if (const char* zMax = chartElement->Attribute("zMax")) { + surfaceChart->zMax = QString::fromLocal8Bit(zMax).toDouble(); + } + if (const char* xCount = chartElement->Attribute("xCount")) { + surfaceChart->xCount = QString::fromLocal8Bit(xCount).toInt(); + } + if (const char* yCount = chartElement->Attribute("yCount")) { + surfaceChart->yCount = QString::fromLocal8Bit(yCount).toInt(); + } + if (const char* zCount = chartElement->Attribute("zCount")) { + surfaceChart->zCount = QString::fromLocal8Bit(zCount).toInt(); + } + if (const char* t = chartElement->Attribute("t")) { + surfaceChart->t = QString::fromLocal8Bit(t); + } + + // Parse curve elements + const tinyxml2::XMLElement* curveElement = chartElement->FirstChildElement("curve"); + while (nullptr != curveElement) { + SurfaceCurveData curveData; + + if (const char* curveName = curveElement->Attribute("name")) { + curveData.name = QString::fromLocal8Bit(curveName); + } + if (const char* curveName = curveElement->Attribute("Name")) { // Handle both cases + curveData.name = QString::fromLocal8Bit(curveName); + } + if (const char* color = curveElement->Attribute("color")) { + curveData.color = QString::fromLocal8Bit(color); + } + if (const char* color = curveElement->Attribute("Color")) { // Handle both cases + curveData.color = QString::fromLocal8Bit(color); + } + if (const char* start = curveElement->Attribute("start")) { + curveData.start = QString::fromLocal8Bit(start).toDouble(); + } + if (const char* start = curveElement->Attribute("Start")) { // Handle both cases + curveData.start = QString::fromLocal8Bit(start).toDouble(); + } + if (const char* stop = curveElement->Attribute("stop")) { + curveData.stop = QString::fromLocal8Bit(stop).toDouble(); + } + if (const char* stop = curveElement->Attribute("Stop")) { // Handle both cases + curveData.stop = QString::fromLocal8Bit(stop).toDouble(); + } + if (const char* x = curveElement->Attribute("x")) { + curveData.x = QString::fromLocal8Bit(x).toDouble(); + } + if (const char* y = curveElement->Attribute("y")) { + curveData.y = QString::fromLocal8Bit(y).toDouble(); + } + if (const char* z = curveElement->Attribute("z")) { + curveData.z = QString::fromLocal8Bit(z).toDouble(); + } + + surfaceChart->curves.append(curveData); + curveElement = curveElement->NextSiblingElement("curve"); + } + + chartData = surfaceChart; + + } else if (typeName == FileEntryTypeToString(FileEntryType::Table)) { + auto tableChart = std::make_shared(); + + // Parse table-specific attributes + if (const char* chartName = chartElement->Attribute("name")) { + tableChart->name = QString::fromLocal8Bit(chartName); + } + if (const char* chartName = chartElement->Attribute("Name")) { // Handle both cases + tableChart->name = QString::fromLocal8Bit(chartName); + } + if (const char* path = chartElement->Attribute("path")) { + tableChart->path = QString::fromLocal8Bit(path); + } + if (const char* head = chartElement->Attribute("head")) { + tableChart->head = QString::fromLocal8Bit(head); + } + if (const char* t = chartElement->Attribute("t")) { + tableChart->t = QString::fromLocal8Bit(t); + } + + // Parse curve elements + const tinyxml2::XMLElement* curveElement = chartElement->FirstChildElement("curve"); + while (nullptr != curveElement) { + TableCurveData curveData; + + if (const char* curveName = curveElement->Attribute("name")) { + curveData.name = QString::fromLocal8Bit(curveName); + } + if (const char* curveName = curveElement->Attribute("Name")) { // Handle both cases + curveData.name = QString::fromLocal8Bit(curveName); + } + if (const char* color = curveElement->Attribute("color")) { + curveData.color = QString::fromLocal8Bit(color); + } + if (const char* data = curveElement->Attribute("data")) { + curveData.data = QString::fromLocal8Bit(data); + } + + tableChart->curves.append(curveData); + curveElement = curveElement->NextSiblingElement("curve"); + } + + chartData = tableChart; + + } else if (typeName == FileEntryTypeToString(FileEntryType::Light)) { + auto lightChart = std::make_shared(); + + // Parse light-specific attributes + if (const char* chartName = chartElement->Attribute("name")) { + lightChart->name = QString::fromLocal8Bit(chartName); + } + if (const char* path = chartElement->Attribute("path")) { + lightChart->path = QString::fromLocal8Bit(path); + } + if (const char* openColor = chartElement->Attribute("openColor")) { + lightChart->openColor = QString::fromLocal8Bit(openColor); + } + if (const char* closeColor = chartElement->Attribute("closeColor")) { + lightChart->closeColor = QString::fromLocal8Bit(closeColor); + } + if (const char* t = chartElement->Attribute("t")) { + lightChart->t = QString::fromLocal8Bit(t); + } + + // Parse curve elements + const tinyxml2::XMLElement* curveElement = chartElement->FirstChildElement("curve"); + while (nullptr != curveElement) { + LightCurveData curveData; + + if (const char* curveName = curveElement->Attribute("name")) { + curveData.name = QString::fromLocal8Bit(curveName); + } + if (const char* data = curveElement->Attribute("data")) { + curveData.data = QString::fromLocal8Bit(data); + } + + lightChart->curves.append(curveData); + curveElement = curveElement->NextSiblingElement("curve"); + } + + chartData = lightChart; + } + + if (chartData) { + fileTypeData.charts.append(chartData); + } + chartElement = chartElement->NextSiblingElement("chart"); + } + + fileTypes.append(fileTypeData); + + // Also create file entries for backward compatibility FileEntryType enumType; if (FileEntryTypeFromString(name, enumType)) { for (int i = 0; i < count; ++i) { @@ -122,6 +386,10 @@ bool WorkSpaceXMLParse::ParseFiles(const tinyxml2::XMLElement* element) { } typeElement = typeElement->NextSiblingElement("type"); } + + // Store the parsed chart data + workSpace_->SetFileTypeData(fileTypes); + return true; } diff --git a/src/workspace/WorkSpaceXMLParse.h b/src/workspace/WorkSpaceXMLParse.h index 8a52bf91..f0e40949 100644 --- a/src/workspace/WorkSpaceXMLParse.h +++ b/src/workspace/WorkSpaceXMLParse.h @@ -3,6 +3,7 @@ #include #include "xml/tinyxml2.h" +#include "workspace/ChartData.h" class WorkSpace; diff --git a/test_chart_parsing.cpp b/test_chart_parsing.cpp new file mode 100644 index 00000000..f67d5917 --- /dev/null +++ b/test_chart_parsing.cpp @@ -0,0 +1,129 @@ +#include +#include +#include +#include "workspace/WorkSpaceXMLParse.h" +#include "common/ChartData.h" + +void printChartData(const std::shared_ptr& chartData) { + if (!chartData) { + std::cout << " Chart data is null" << std::endl; + return; + } + + std::cout << " Chart Name: " << chartData->name.toStdString() << std::endl; + std::cout << " Chart Path: " << chartData->path.toStdString() << std::endl; + + // Handle different chart types + if (auto curveChart = std::dynamic_pointer_cast(chartData)) { + std::cout << " Chart Type: Curve" << std::endl; + std::cout << " X Title: " << curveChart->xTitle.toStdString() << std::endl; + std::cout << " Y Title: " << curveChart->yTitle.toStdString() << std::endl; + std::cout << " X Range: [" << curveChart->xMin << " - " << curveChart->xMax << "]" << std::endl; + std::cout << " Y Range: [" << curveChart->yMin << " - " << curveChart->yMax << "]" << std::endl; + std::cout << " X Count: " << curveChart->xCount << std::endl; + std::cout << " Time: " << curveChart->t << std::endl; + std::cout << " Curves (" << curveChart->curves.size() << "):" << std::endl; + + for (const auto& curve : curveChart->curves) { + std::cout << " - Name: " << curve.name.toStdString() + << ", Range: [" << curve.start << " - " << curve.stop << "]" + << ", Color: " << curve.color.toStdString() << std::endl; + } + + } else if (auto surfaceChart = std::dynamic_pointer_cast(chartData)) { + std::cout << " Chart Type: Surface" << std::endl; + std::cout << " X Title: " << surfaceChart->xTitle.toStdString() << std::endl; + std::cout << " Y Title: " << surfaceChart->yTitle.toStdString() << std::endl; + std::cout << " Z Title: " << surfaceChart->zTitle.toStdString() << std::endl; + std::cout << " X Range: [" << surfaceChart->xMin << " - " << surfaceChart->xMax << "]" << std::endl; + std::cout << " Y Range: [" << surfaceChart->yMin << " - " << surfaceChart->yMax << "]" << std::endl; + std::cout << " Z Range: [" << surfaceChart->zMin << " - " << surfaceChart->zMax << "]" << std::endl; + std::cout << " X Count: " << surfaceChart->xCount << std::endl; + std::cout << " Y Count: " << surfaceChart->yCount << std::endl; + std::cout << " Z Count: " << surfaceChart->zCount << std::endl; + std::cout << " Time: " << surfaceChart->t << std::endl; + std::cout << " Surface Curves (" << surfaceChart->curves.size() << "):" << std::endl; + + for (const auto& curve : surfaceChart->curves) { + std::cout << " - Name: " << curve.name.toStdString() + << ", Range: [" << curve.start << " - " << curve.stop << "]" + << ", Color: " << curve.color.toStdString() + << ", Position: (" << curve.x << "," << curve.y << "," << curve.z << ")" << std::endl; + } + + } else if (auto tableChart = std::dynamic_pointer_cast(chartData)) { + std::cout << " Chart Type: Table" << std::endl; + std::cout << " Head: " << tableChart->head.toStdString() << std::endl; + std::cout << " Time: " << tableChart->t << std::endl; + std::cout << " Table Data (" << tableChart->curves.size() << "):" << std::endl; + + for (const auto& curve : tableChart->curves) { + std::cout << " - Name: " << curve.name.toStdString() + << ", Color: " << curve.color.toStdString() + << ", Data: " << curve.data.toStdString() << std::endl; + } + + } else if (auto lightChart = std::dynamic_pointer_cast(chartData)) { + std::cout << " Chart Type: Light" << std::endl; + std::cout << " Open Color: " << lightChart->openColor.toStdString() << std::endl; + std::cout << " Close Color: " << lightChart->closeColor.toStdString() << std::endl; + std::cout << " Time: " << lightChart->t << std::endl; + std::cout << " Light Data (" << lightChart->curves.size() << "):" << std::endl; + + for (const auto& curve : lightChart->curves) { + std::cout << " - Name: " << curve.name.toStdString() + << ", Data: " << curve.data.toStdString() << std::endl; + } + } else { + std::cout << " Chart Type: Unknown" << std::endl; + } +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + std::cout << "Testing XML Chart Parsing with New Inheritance Structure..." << std::endl; + + // Test XML file path + QString xmlFilePath = "test_workspace.xml"; + + // Create parser instance + WorkSpaceXMLParse parser; + + // Parse the XML file + FileTypeData fileData; + bool success = parser.ParseFiles(xmlFilePath, fileData); + + if (!success) { + std::cout << "Failed to parse XML file: " << xmlFilePath.toStdString() << std::endl; + return -1; + } + + std::cout << "Successfully parsed XML file!" << std::endl; + std::cout << "=== File Type Data ===" << std::endl; + std::cout << "Files count: " << fileData.files.size() << std::endl; + std::cout << "Charts count: " << fileData.charts.size() << std::endl; + + // Print file information + std::cout << "\n=== Files ===" << std::endl; + for (int i = 0; i < fileData.files.size(); ++i) { + const auto& file = fileData.files[i]; + std::cout << "File " << i << ":" << std::endl; + std::cout << " Name: " << file.name.toStdString() << std::endl; + std::cout << " Path: " << file.path.toStdString() << std::endl; + std::cout << " Type: " << static_cast(file.type) << std::endl; + } + + // Print chart information + std::cout << "\n=== Charts ===" << std::endl; + for (int i = 0; i < fileData.charts.size(); ++i) { + std::cout << "Chart " << i << ":" << std::endl; + printChartData(fileData.charts[i]); + std::cout << std::endl; + } + + std::cout << "Test completed successfully!" << std::endl; + + return 0; +} \ No newline at end of file diff --git a/test_workspace.xml b/test_workspace.xml new file mode 100644 index 00000000..4bf37e07 --- /dev/null +++ b/test_workspace.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file