From 8f0a32869eb6f652f526c0ffcaa22005cc1742f7 Mon Sep 17 00:00:00 2001 From: brige Date: Sun, 6 Jul 2025 23:33:27 +0800 Subject: [PATCH] modify worksapce mansger onframe --- src/app/Application.cpp | 11 ++ src/app/Application.h | 9 ++ src/scene/OEScene.cpp | 11 +- src/translations/Dyt_zh_CN.ts | 4 +- src/ui/Layout/SignalIndicatorLampUI.cpp | 2 + src/ui/Menu/ChartPlotMenu.cpp | 2 +- src/ui/Table/targetlistwgt.cpp | 19 +++- src/ui/chartPlot/FitCurveDialog.cpp | 143 ++++++++++++------------ src/ui/chartPlot/SurfaceDialog.cpp | 1 + src/viewer/OsgWidget.cpp | 1 - src/workspace/Timestep.h | 4 + 11 files changed, 126 insertions(+), 81 deletions(-) diff --git a/src/app/Application.cpp b/src/app/Application.cpp index a0884bd1..1adb4a48 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -23,6 +23,10 @@ QString Application::GetWorkSpacePath() { return path; } +QString Application::GetBinPath() { + return applicationDirPath(); +} + void Application::Init() { Singleton::Create(this); Singleton::Create(this); @@ -30,6 +34,13 @@ void Application::Init() { Singleton::Create(this); Singleton::Create(this); //Singleton::Create(this); + + connect(&timer_, &QTimer::timeout, this, &Application::OnTimeout); + timer_.start(1000 / 60); // 60 FPS +} + +void Application::OnTimeout() { + WorkSpaceManager::Get().OnFrame(); } void Application::Uninit() { diff --git a/src/app/Application.h b/src/app/Application.h index e049ff99..f2239e91 100644 --- a/src/app/Application.h +++ b/src/app/Application.h @@ -2,6 +2,8 @@ #include +#include + class Application : public QApplication { Q_OBJECT @@ -10,7 +12,14 @@ public: ~Application() override; static QString GetWorkSpacePath(); + static QString GetBinPath(); void Uninit(); protected: void Init(); + +private: + void OnTimeout(); + +protected: + QTimer timer_; }; \ No newline at end of file diff --git a/src/scene/OEScene.cpp b/src/scene/OEScene.cpp index 7646f95f..f5ce9c5e 100644 --- a/src/scene/OEScene.cpp +++ b/src/scene/OEScene.cpp @@ -14,12 +14,14 @@ #include #include "config.h" +#include "app/Application.h" #include "common/SpdLogger.h" #include "common/RecourceHelper.h" #include "scene/ScopedTimer.h" #include "viewer/OsgView.h" #include "viewer/OsgCameraManipulator.h" #include "scene/ScaleBarHandler.h" +#include "utils/FileUtils.h" const osgEarth::SpatialReference* g_srs_{ nullptr }; @@ -107,7 +109,14 @@ const osgEarth::SpatialReference* OEScene::GetSrs() { } void OEScene::Init() { - std::string earthPath = "D:/Project/DYT/Tool/TritonSample/TritonSample/triton.earth"; + QString earthFile = QString("%1/earth/triton.earth").arg(Application::GetBinPath()); + if (!FileUtils::IsExist(earthFile)) { + LOG_ERROR("earth file not found: {}", earthFile.toStdString()); + return; + } + + std::string earthPath(earthFile.toLocal8Bit().constData()); + LOG_INFO("Loading earth file from: {}", earthPath); // earthRootNode_ = osgDB::readNodeFile("triton.earth"); earthRootNode_ = osgDB::readNodeFile(earthPath); dyt_check(nullptr != earthRootNode_); diff --git a/src/translations/Dyt_zh_CN.ts b/src/translations/Dyt_zh_CN.ts index 2272fcf4..cfe84b05 100644 --- a/src/translations/Dyt_zh_CN.ts +++ b/src/translations/Dyt_zh_CN.ts @@ -418,12 +418,12 @@ - + 2D Curve - + 2D(y(lg)) Curve diff --git a/src/ui/Layout/SignalIndicatorLampUI.cpp b/src/ui/Layout/SignalIndicatorLampUI.cpp index 9e8514f6..da5d3acb 100644 --- a/src/ui/Layout/SignalIndicatorLampUI.cpp +++ b/src/ui/Layout/SignalIndicatorLampUI.cpp @@ -196,6 +196,7 @@ void SignalIndicatorLampUI::InitLamp(const QString& strFile) void SignalIndicatorLampUI::slotUpdateTime(double dTime) { + return; if (dTime < 1) { return; @@ -240,6 +241,7 @@ void SignalIndicatorLampUI::OnWorkSpaceChanged(WorkSpace* worksapce) { } connect(worksapce, &WorkSpace::TimestepChanged, this, &SignalIndicatorLampUI::OnTimestepChanged); + InitLamp(worksapce->GetRDPath()); } void SignalIndicatorLampUI::OnTimestepChanged(Timestep* timestep) { diff --git a/src/ui/Menu/ChartPlotMenu.cpp b/src/ui/Menu/ChartPlotMenu.cpp index aee1b365..29882576 100644 --- a/src/ui/Menu/ChartPlotMenu.cpp +++ b/src/ui/Menu/ChartPlotMenu.cpp @@ -1,4 +1,4 @@ -#include "ChartPlotMenu.h" +#include "ChartPlotMenu.h" #include "../Matlab/MatlabObject.h" #include "../../common/RecourceHelper.h" diff --git a/src/ui/Table/targetlistwgt.cpp b/src/ui/Table/targetlistwgt.cpp index 3cd442a4..cd366f6a 100644 --- a/src/ui/Table/targetlistwgt.cpp +++ b/src/ui/Table/targetlistwgt.cpp @@ -233,12 +233,16 @@ void TargetListWgt::slotNextPage() } void TargetListWgt::OnWorkSpaceChanged(WorkSpace* worksapce) { - if (worksapce == nullptr) { - LOG_ERROR("worksapce is nullptr"); - return; - } + if (worksapce == nullptr) { + LOG_ERROR("worksapce is nullptr"); + return; + } - connect(worksapce, &WorkSpace::TimestepChanged, this, &TargetListWgt::OnTimestepChanged); + connect(worksapce, &WorkSpace::TimestepChanged, this, &TargetListWgt::OnTimestepChanged); + Timestep* timestep = worksapce->GetTimestep(); + if (nullptr != timestep) { + InitFile(worksapce->GetReportPath(), timestep->GetSteps().size()); + } } void TargetListWgt::OnTimestepChanged(Timestep* timestep) { @@ -247,6 +251,11 @@ void TargetListWgt::OnTimestepChanged(Timestep* timestep) { return; } connect(timestep, SIGNAL(TimeChanged(double)), this, SLOT(slotUpdateTime(double))); + + auto worksapce = timestep->GetWorkSpace(); + if (nullptr != worksapce) { + InitFile(worksapce->GetReportPath(), timestep->GetSteps().size()); + } } void TargetListWgt::slotTimeChanged(double dTime) diff --git a/src/ui/chartPlot/FitCurveDialog.cpp b/src/ui/chartPlot/FitCurveDialog.cpp index 10dea141..38b9176f 100644 --- a/src/ui/chartPlot/FitCurveDialog.cpp +++ b/src/ui/chartPlot/FitCurveDialog.cpp @@ -1,4 +1,4 @@ -#include "fitcurvedialog.h" +#include "fitcurvedialog.h" #include @@ -31,21 +31,21 @@ FitCurveDialog::FitCurveDialog(int iType, 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->setContentsMargins(0, 0, 0, 0); //设置外边界全部为0, 根据自己实际情况设置 + //curveChart->setMargins(QMargins(5, -30, 5, 10)); //设置内边界, 根据自己实际情况设置 + curveChart->setBackgroundRoundness(0); //设置表格边框圆角半径 curveChartView->setChart(curveChart); //QObject::connect(fitPointsSeriesS, &QSplineSeries::clicked, [=](const QPointF& point)mutable { // QPointF tempPoint; - // QVector tempList(fitPointsSeriesS->pointsVector()); //еݽм, Ϊֱʹûᵼ¿ + // QVector tempList(fitPointsSeriesS->pointsVector()); //复制曲线中的数据进行计算, 因为直接使用会导致卡顿 // int tempX = qRound(point.x()); // int tempY = -999; // for (int i = 0; i < tempList.size(); i++) { @@ -65,12 +65,12 @@ void FitCurveDialog::initQChartView() { // } // }); - // + //创建坐标轴 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); //xGuideSeries->attachAxis(m_pAxisX); @@ -98,13 +98,13 @@ void FitCurveDialog::initQChartView() { curveChart->addAxis(m_pLgAxisY, Qt::AlignLeft); } - // axisX->setGridLineVisible(false); //رX - // axisY->setGridLineVisible(false); //رY + // axisX->setGridLineVisible(false); //隐藏背景网格X轴框线 + // axisY->setGridLineVisible(false); //隐藏背景网格Y轴框线 /*curveChart->legend()->markers()[0]->setVisible(false); curveChart->legend()->markers()[1]->setVisible(false); curveChart->legend()->markers()[2]->setVisible(false); curveChart->legend()->markers()[3]->setVisible(false);*/ - curveChartView->setRenderHint(QPainter::Antialiasing); // + curveChartView->setRenderHint(QPainter::Antialiasing); //除锯齿 connect(curveChartView, &FitCurveChartView::signalMouseEvent, this, &FitCurveDialog::theSlotMouseEvent); connect(curveChartView, &FitCurveChartView::signalWheelEvent, this, &FitCurveDialog::theSlotWheelEvent); @@ -117,12 +117,12 @@ void FitCurveDialog::initQChartView() { } 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, @@ -130,10 +130,10 @@ void FitCurveDialog::theSlotMouseEvent(int eventId, QMouseEvent* event) { updateXYGuideLine(); } } - else if (eventId == 2) { //̧ + else if (eventId == 2) { //单击抬起 isPressed = false; } - else if (eventId == 3) { //˫ + else if (eventId == 3) { //双击 resetZoomAndScroll(); updateXYGuideLine(); } @@ -153,24 +153,24 @@ void FitCurveDialog::theSlotWheelEvent(QWheelEvent* event) { void FitCurveDialog::slotAddSeries(QVariant varSeriesData) { - // Ч + // 数据无效 if (!varSeriesData.isValid()) { return; } - QString strName = varSeriesData.toMap().value("Name").toString(); // - QVariantList varCurDataList = varSeriesData.toMap().value("Data").toList(); // - int iYType = varSeriesData.toMap().value("yType").toInt(); // y - QColor color = varSeriesData.toMap().value("Color").value(); // ɫ - QString strXName = varSeriesData.toMap().value("xTitle").toString(); // x - QString strYName = varSeriesData.toMap().value("yTitle").toString(); // y - QString strZName = varSeriesData.toMap().value("zTitle").toString(); // z - int iCurveType = varSeriesData.toMap().value("curveType").toInt(); // - int iID = varSeriesData.toMap().value("ID").toInt(); // y - bool bAdd = varSeriesData.toMap().value("Add").toBool(); // + QString strName = varSeriesData.toMap().value("Name").toString(); // 曲线名称 + QVariantList varCurDataList = varSeriesData.toMap().value("Data").toList(); // 数据 + int iYType = varSeriesData.toMap().value("yType").toInt(); // y轴类型 + QColor color = varSeriesData.toMap().value("Color").value(); // 曲线颜色 + QString strXName = varSeriesData.toMap().value("xTitle").toString(); // x轴名称 + QString strYName = varSeriesData.toMap().value("yTitle").toString(); // y轴名称 + QString strZName = varSeriesData.toMap().value("zTitle").toString(); // z轴名称 + int iCurveType = varSeriesData.toMap().value("curveType").toInt(); // 曲线类型 + int iID = varSeriesData.toMap().value("ID").toInt(); // y轴类型 + bool bAdd = varSeriesData.toMap().value("Add").toBool(); // 曲线名称 - if (iCurveType == 3) // Ƕά + if (iCurveType == 3) // 非二维曲线 { return; } @@ -180,8 +180,8 @@ void FitCurveDialog::slotAddSeries(QVariant varSeriesData) if (m_seriesIDMap.contains(iID)) { pSeries = m_seriesIDMap.value(iID); - pSeries->setName(strName); // - pSeries->setColor(color); // ɫ + pSeries->setName(strName); // 设置曲线名称 + pSeries->setColor(color); // 设置曲线颜色 pSeries->setUseOpenGL(true); } else @@ -192,38 +192,38 @@ void FitCurveDialog::slotAddSeries(QVariant varSeriesData) } pSeries = new QSplineSeries(this); - pSeries->setName(strName); // - pSeries->setColor(color); // ɫ + pSeries->setName(strName); // 设置曲线名称 + pSeries->setColor(color); // 设置曲线颜色 pSeries->setUseOpenGL(true); bNew = true; } - m_pAxisX->setTitleText(strXName); // x + m_pAxisX->setTitleText(strXName); // 设置x轴名称 - // xyķΧ - m_iXMax = m_pAxisX->max(); // ǰxֵ - m_iXMin = m_pAxisX->min(); // ǰxСֵ + // xy轴的范围 + m_iXMax = m_pAxisX->max(); // 当前x轴的最大值 + m_iXMin = m_pAxisX->min(); // 当前x轴的最小值 - if (0 == iYType) // һ + if (0 == iYType) // 一般曲线 { - m_iYMax = m_pAxisY->max(); // ǰyֵ - m_iYMin = m_pAxisY->min(); // ǰyֵ + m_iYMax = m_pAxisY->max(); // 当前y轴的最大值 + m_iYMin = m_pAxisY->min(); // 当前y轴的最大值 } - else // + else // 对数曲线 { - m_iYMax = m_pLgAxisY->max(); // ǰyֵ - m_iYMin = m_pLgAxisY->min(); // ǰyֵ + m_iYMax = m_pLgAxisY->max(); // 当前y轴的最大值 + m_iYMin = m_pLgAxisY->min(); // 当前y轴的最大值 } - // + // 曲线数据 QVector listKey; for (size_t i = 0; i < varCurDataList.size(); i++) { QPointF ptKey = varCurDataList[i].toPointF(); listKey.push_back(ptKey); - // xֵСֵ + // 更新x轴最大值最小值 if (m_iXMin > ptKey.x()) { m_iXMin = ptKey.x(); @@ -245,7 +245,7 @@ void FitCurveDialog::slotAddSeries(QVariant varSeriesData) } } - // x᷶Χ + // 更新x轴范围 m_pAxisX->setRange(m_iXMin, m_iXMax); pSeries->replace(listKey); @@ -254,7 +254,7 @@ void FitCurveDialog::slotAddSeries(QVariant varSeriesData) curveChart->addSeries(pSeries); } - // y᷶Χ + // 更新y轴范围 if (iYType == 0) { m_pAxisY->setRange(m_iYMin, m_iYMax); @@ -286,7 +286,7 @@ void FitCurveDialog::slotAddSeries(QVariant varSeriesData) //QObject::connect(fitPointsSeriesS, &QSplineSeries::clicked, [=](const QPointF& point)mutable { // QPointF tempPoint; - // QVector tempList(fitPointsSeriesS->pointsVector()); //еݽм, Ϊֱʹûᵼ¿ + // QVector tempList(fitPointsSeriesS->pointsVector()); //复制曲线中的数据进行计算, 因为直接使用会导致卡顿 // int tempX = qRound(point.x()); // int tempY = -999; // for (int i = 0; i < tempList.size(); i++) { @@ -388,14 +388,14 @@ void FitCurveDialog::slotUpdateTime(double dTime) std::vector> batch = m_vecWavePoint[dTime - 1]; - m_pAxisX->setTitleText("x"); // x + m_pAxisX->setTitleText("x"); // 设置x轴名称 - // xyķΧ - m_iXMax = m_pAxisX->max(); // ǰxֵ - m_iXMin = m_pAxisX->min(); // ǰxСֵ + // xy轴的范围 + m_iXMax = m_pAxisX->max(); // 当前x轴的最大值 + m_iXMin = m_pAxisX->min(); // 当前x轴的最小值 - m_iYMax = m_pAxisY->max(); // ǰyֵ - m_iYMin = m_pAxisY->min(); // ǰyֵ + m_iYMax = m_pAxisY->max(); // 当前y轴的最大值 + m_iYMin = m_pAxisY->min(); // 当前y轴的最大值 m_iXMin = 0; @@ -416,14 +416,14 @@ void FitCurveDialog::slotUpdateTime(double dTime) bNew = true; } - QString strName = QString::fromLocal8Bit("Ŀ") + QString::number(i+1); - pSeries->setName(strName); // + QString strName = QString::fromLocal8Bit("目标") + QString::number(i+1); + pSeries->setName(strName); // 设置曲线名称 if (bNew) { - qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); // ʼ + qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); // 初始化随机数生成器 QColor color(QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255)); - pSeries->setColor(color); // ɫ + pSeries->setColor(color); // 设置曲线颜色 } pSeries->setUseOpenGL(true); @@ -467,7 +467,7 @@ void FitCurveDialog::slotUpdateTime(double dTime) pSeries->attachAxis(m_pAxisY); } - m_pAxisY->setTitleText(QString::fromLocal8Bit("ֵ")); + m_pAxisY->setTitleText(QString::fromLocal8Bit("幅值")); if (bNew) { @@ -497,15 +497,15 @@ void FitCurveDialog::slotUpdateTime(double dTime) std::vector> batch = m_vecReportPoint[dTime - 1]; - m_pAxisX->setTitleText(QString::fromLocal8Bit("")); // x + m_pAxisX->setTitleText(QString::fromLocal8Bit("距离")); // 设置x轴名称 - // xyķΧ - m_iXMax = m_pAxisX->max(); // ǰxֵ - m_iXMin = m_pAxisX->min(); // ǰxСֵ + // xy轴的范围 + m_iXMax = m_pAxisX->max(); // 当前x轴的最大值 + m_iXMin = m_pAxisX->min(); // 当前x轴的最小值 - m_iYMax = m_pAxisY->max(); // ǰyֵ - m_iYMin = m_pAxisY->min(); // ǰyֵ + m_iYMax = m_pAxisY->max(); // 当前y轴的最大值 + m_iYMin = m_pAxisY->min(); // 当前y轴的最大值 for (int i = 0; i < batch.size(); i++) { @@ -522,14 +522,14 @@ void FitCurveDialog::slotUpdateTime(double dTime) bNew = true; } - QString strName = QString::fromLocal8Bit("Ŀ") + QString::number(i + 1); - pSeries->setName(strName); // + QString strName = QString::fromLocal8Bit("目标") + QString::number(i + 1); + pSeries->setName(strName); // 设置曲线名称 if (bNew) { - qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); // ʼ + qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); // 初始化随机数生成器 QColor color(QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255)); - pSeries->setColor(color); // ɫ + pSeries->setColor(color); // 设置曲线颜色 } pSeries->setUseOpenGL(true); @@ -575,7 +575,7 @@ void FitCurveDialog::slotUpdateTime(double dTime) pSeries->attachAxis(m_pAxisY); } - m_pAxisY->setTitleText(QString::fromLocal8Bit("ٶ")); + m_pAxisY->setTitleText(QString::fromLocal8Bit("速度")); if (bNew) { @@ -648,7 +648,7 @@ void FitCurveDialog::ParseWave(const QString& strFile, std::vector vecLine; for (size_t i = 0; i < listLine.size(); i++) { - if (12 == i || i == 13) // 롢ٶ + if (12 == i || i == 13) // 距离、速度 { vecLine.push_back(listLine[i].toFloat()); } @@ -740,6 +740,7 @@ void FitCurveDialog::OnWorkSpaceChanged(WorkSpace* worksapce) { } connect(worksapce, &WorkSpace::TimestepChanged, this, &FitCurveDialog::OnTimestepChanged); + InitWaveFile(worksapce->GetWavePath()); } void FitCurveDialog::OnTimestepChanged(Timestep* timestep) { diff --git a/src/ui/chartPlot/SurfaceDialog.cpp b/src/ui/chartPlot/SurfaceDialog.cpp index 30105a15..b2c0a14a 100644 --- a/src/ui/chartPlot/SurfaceDialog.cpp +++ b/src/ui/chartPlot/SurfaceDialog.cpp @@ -287,6 +287,7 @@ void SurfaceDialog::OnWorkSpaceChanged(WorkSpace* worksapce) { } connect(worksapce, &WorkSpace::TimestepChanged, this, &SurfaceDialog::OnTimestepChanged); + InitRD(worksapce->GetRDPath()); } void SurfaceDialog::OnTimestepChanged(Timestep* timestep) { diff --git a/src/viewer/OsgWidget.cpp b/src/viewer/OsgWidget.cpp index 326d71c6..c2902f79 100644 --- a/src/viewer/OsgWidget.cpp +++ b/src/viewer/OsgWidget.cpp @@ -178,7 +178,6 @@ void OsgWidget::resizeEvent(QResizeEvent* event) { } void OsgWidget::paintEvent(QPaintEvent*) { - WorkSpaceManager::Get().OnFrame(); frame(); } diff --git a/src/workspace/Timestep.h b/src/workspace/Timestep.h index ba763e33..320b5c0d 100644 --- a/src/workspace/Timestep.h +++ b/src/workspace/Timestep.h @@ -45,6 +45,10 @@ public: void Up(); void Down(); + WorkSpace* GetWorkSpace() const { + return workSpace_; + } + Q_SIGNALS: void StatusChanged(int); void StepChanged(double);