diff --git a/src/translations/Dyt_zh_CN.ts b/src/translations/Dyt_zh_CN.ts
index cfe84b05..a4141f94 100644
--- a/src/translations/Dyt_zh_CN.ts
+++ b/src/translations/Dyt_zh_CN.ts
@@ -116,6 +116,11 @@
+ Lamp文件
+
+
+
+
Run Simu
@@ -1550,12 +1555,12 @@
-
+
Signal Indicator Lamp
-
+
light
diff --git a/src/ui/Layout/SignalIndicatorLampUI.cpp b/src/ui/Layout/SignalIndicatorLampUI.cpp
index da5d3acb..472f0b98 100644
--- a/src/ui/Layout/SignalIndicatorLampUI.cpp
+++ b/src/ui/Layout/SignalIndicatorLampUI.cpp
@@ -15,6 +15,7 @@
#include "workspace/WorkSpace.h"
#include "workspace/Timestep.h"
#include "workspace/WorkSpaceManager.h"
+#include "workspace/LampStatus.h"
SignalIndicatorLampUI::SignalIndicatorLampUI(QWidget* parent)
: QWidget(parent)
@@ -196,7 +197,6 @@ void SignalIndicatorLampUI::InitLamp(const QString& strFile)
void SignalIndicatorLampUI::slotUpdateTime(double dTime)
{
- return;
if (dTime < 1)
{
return;
@@ -241,7 +241,12 @@ void SignalIndicatorLampUI::OnWorkSpaceChanged(WorkSpace* worksapce) {
}
connect(worksapce, &WorkSpace::TimestepChanged, this, &SignalIndicatorLampUI::OnTimestepChanged);
- InitLamp(worksapce->GetRDPath());
+ auto lamp = worksapce->GetLampStatus();
+ if (nullptr != lamp) {
+ InitLamp(lamp->GetPath());
+ }
+ // Initialize the lamp with the current workspace's lamp file
+
}
void SignalIndicatorLampUI::OnTimestepChanged(Timestep* timestep) {
diff --git a/src/ui/Menu/ChartPlotMenu.cpp b/src/ui/Menu/ChartPlotMenu.cpp
index 29882576..6599800b 100644
--- a/src/ui/Menu/ChartPlotMenu.cpp
+++ b/src/ui/Menu/ChartPlotMenu.cpp
@@ -4,6 +4,8 @@
#include "../../common/RecourceHelper.h"
#include "workspace/WorkSpace.h"
#include "workspace/WorkSpaceManager.h"
+#include "workspace/LampStatus.h"
+#include "utils/FileUtils.h"
#include
#include
@@ -188,4 +190,52 @@ void ChartPlotMenu::InitMenu()
current->SetReportPath(strSel);
});
+
+ connect(ui.toolButton_6, &QToolButton::clicked, this, [=] {
+ auto current = WorkSpaceManager::Get().GetCurrent();
+ if (nullptr == current) {
+ QMessageBox::information(nullptr, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("请先创建空间!"));
+ return;
+ }
+ QString strSel = QFileDialog::getOpenFileName(this, u8"选择Lamp文件", RecourceHelper::Get().GetBasePath() + "/workspace/", "*.txt");
+ if (strSel.isEmpty()) {
+ LOG_WARN("选择文件为空");
+ return;
+ }
+
+ auto lampStatus = current->GetLampStatus();
+ if (nullptr != lampStatus) {
+ const QString& old = lampStatus->GetPath();
+ if (old == strSel) {
+ LOG_INFO("选择文件与当前文件相同");
+ return;
+ }
+ else if (!old.isEmpty()) {
+ if (QFileInfo(old).isFile() && QFile::exists(old)) {
+ if (QMessageBox::Yes == QMessageBox::question(nullptr,
+ QString::fromLocal8Bit("询问"),
+ QString::fromLocal8Bit("替换当前Lamp文件!"),
+ QMessageBox::Yes | QMessageBox::No)
+ ) {
+ if (!QFile::remove(old)) {
+ LOG_WARN("删除文件失败");
+ QMessageBox::information(nullptr,
+ QString::fromLocal8Bit("提示"),
+ QString::fromLocal8Bit("删除文件失败!"));
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ QFileInfo fileInfo(strSel);
+ QString dirPath = QString("%1/%2").arg(current->GetDir(), fileInfo.fileName());
+ bool sucess = FileUtils::CopyFileToPath(strSel, dirPath, true);
+ LOG_INFO("copy Wave file {}: {} to {}",
+ strSel.toLocal8Bit().data(),
+ dirPath.toLocal8Bit().data(),
+ sucess);
+ current->SetLampPath(dirPath);
+ });
}
diff --git a/src/ui/Menu/ChartPlotMenu.ui b/src/ui/Menu/ChartPlotMenu.ui
index bb5c389d..9e92758d 100644
--- a/src/ui/Menu/ChartPlotMenu.ui
+++ b/src/ui/Menu/ChartPlotMenu.ui
@@ -68,6 +68,19 @@
+ -
+
+
+
+ 60
+ 30
+
+
+
+ Lamp文件
+
+
+
-
diff --git a/src/workspace/LampStatus.cpp b/src/workspace/LampStatus.cpp
index 93a8f4db..d373e937 100644
--- a/src/workspace/LampStatus.cpp
+++ b/src/workspace/LampStatus.cpp
@@ -16,7 +16,7 @@ LampStatus::LampStatus(const std::vector& status, const QString& path, Work
}
LampStatus* LampStatus::Load(const QString& path, WorkSpace* parent) {
- const QString filePath = QString("%1/%2").arg(RecourceHelper::Get().GetBasePath()).arg(path);
+ const QString filePath = path;
LOG_INFO("Load LampStatus: {}", filePath.toStdString());
QFile file(filePath);
diff --git a/src/workspace/WorkSpaceXMLWrite.cpp b/src/workspace/WorkSpaceXMLWrite.cpp
index 8a55034e..917be532 100644
--- a/src/workspace/WorkSpaceXMLWrite.cpp
+++ b/src/workspace/WorkSpaceXMLWrite.cpp
@@ -34,6 +34,7 @@ bool WorkSpaceXMLWrite::Save(const QString& path) {
SaveChart(scene, &doc);
SaveTimeStep(scene);
+ SaveLamp(scene);
tinyxml2::XMLElement* entitiesXml = scene->InsertNewChildElement("entities");
std::vector& entities = workSpace_->GetEntities();