diff --git a/src/translations/Dyt_zh_CN.ts b/src/translations/Dyt_zh_CN.ts index 0bf8e388..1df46af7 100644 --- a/src/translations/Dyt_zh_CN.ts +++ b/src/translations/Dyt_zh_CN.ts @@ -1780,17 +1780,12 @@ - - OnCreate + + Commands - - OnLoad - - - - + unnamed diff --git a/src/ui/PropertyBrowser/qtworkspaceattribute.cpp b/src/ui/PropertyBrowser/qtworkspaceattribute.cpp index 9dbf0a8c..164dac0e 100644 --- a/src/ui/PropertyBrowser/qtworkspaceattribute.cpp +++ b/src/ui/PropertyBrowser/qtworkspaceattribute.cpp @@ -187,7 +187,9 @@ const QString QWorkspaceAttribute::GetCommondFilePath() const if (nullptr == workspace_) { return ""; } - return workspace_->GetCommondFilePath(); + + QString path = QString("%1/%2").arg(workspace_->GetDir(), workspace_->GetCommondFilePath()); + return path; } std::vector QWorkspaceAttribute::GetFileEntries(FileEntryType type) const { diff --git a/src/workspace/CommandManager.cpp b/src/workspace/CommandManager.cpp index 0bd2a401..353161c2 100644 --- a/src/workspace/CommandManager.cpp +++ b/src/workspace/CommandManager.cpp @@ -21,7 +21,7 @@ void CommandManager::Reload(WorkSpace* ws) { onLoad_.clear(); if (!ws) return; - const QString cmdPath = ws->GetCommondFilePath(); + const QString cmdPath = QString("%1/%2").arg(ws->GetDir(), ws->GetCommondFilePath()); if (cmdPath.isEmpty()) { LOG_INFO("no command xml configured"); return; diff --git a/src/workspace/WorkSpace.cpp b/src/workspace/WorkSpace.cpp index b971b926..511520cd 100644 --- a/src/workspace/WorkSpace.cpp +++ b/src/workspace/WorkSpace.cpp @@ -54,11 +54,6 @@ void WorkSpace::SetCommondFilePath(const QString& path) { commondPath_ = fileInfo.fileName(); } -const QString WorkSpace::GetCommondFilePath() const { - QString path = QString("%1/%2").arg(GetDir(), commondPath_); - return path; -} - void WorkSpace::SetSimMatlab(const QString& path) { QFileInfo fileInfo(path); QString dirPath = QString("%1/%2").arg(GetDir(), fileInfo.fileName()); diff --git a/src/workspace/WorkSpace.h b/src/workspace/WorkSpace.h index e649b2ba..6205bfd1 100644 --- a/src/workspace/WorkSpace.h +++ b/src/workspace/WorkSpace.h @@ -52,7 +52,9 @@ public: } void SetCommondFilePath(const QString& path); - const QString GetCommondFilePath() const; + const QString GetCommondFilePath() const { + return commondPath_; + } // Execute command xml according to trigger enum class CommandWhen { OnCreate, OnLoad }; @@ -183,5 +185,6 @@ private: public: std::uint64_t GetFilesSeq() const { return filesSeq_; } friend class WorkSpaceXMLWrite; + friend class WorkSpaceXMLParse; }; diff --git a/src/workspace/WorkSpaceXMLParse.cpp b/src/workspace/WorkSpaceXMLParse.cpp index f4089e24..0af5857d 100644 --- a/src/workspace/WorkSpaceXMLParse.cpp +++ b/src/workspace/WorkSpaceXMLParse.cpp @@ -80,10 +80,27 @@ bool WorkSpaceXMLParse::ParseLamp(const tinyxml2::XMLElement* element) { LOG_WARN("element not has path"); return false; } - + return workSpace_->SetLampPath(path); } +bool WorkSpaceXMLParse::ParseCommond(const tinyxml2::XMLElement* element) { + if (nullptr == element) { + LOG_WARN("commond element is nullptr"); + return false; + } + + const char* path = element->Attribute("path"); + if (nullptr == path) { + LOG_WARN("commond element not has path"); + return false; + } + + // Set the command file path using the filename stored in XML + workSpace_->commondPath_ = path; + return true; +} + bool WorkSpaceXMLParse::ParseFiles(const tinyxml2::XMLElement* element) { if (nullptr == element) { LOG_WARN("element is nullptr"); @@ -252,6 +269,8 @@ bool WorkSpaceXMLParse::Load(const QString& dyt) { ParseTimestep(xmlElement); } else if (0 == strcmp(name, "lamp")) { ParseLamp(xmlElement); + } else if (0 == strcmp(name, "commond")) { + ParseCommond(xmlElement); } else if (0 == strcmp(name, "charts")) { ParseChart(xmlElement); diff --git a/src/workspace/WorkSpaceXMLParse.h b/src/workspace/WorkSpaceXMLParse.h index 626af5b2..8a52bf91 100644 --- a/src/workspace/WorkSpaceXMLParse.h +++ b/src/workspace/WorkSpaceXMLParse.h @@ -31,6 +31,7 @@ private: bool ParseScene(const tinyxml2::XMLElement* element); bool ParseTimestep(const tinyxml2::XMLElement* element); bool ParseLamp(const tinyxml2::XMLElement* element); + bool ParseCommond(const tinyxml2::XMLElement* element); bool ParseEntities(const tinyxml2::XMLElement* element); bool ParseChart(const tinyxml2::XMLElement* element); bool ParseReport(const tinyxml2::XMLElement* element); diff --git a/src/workspace/WorkSpaceXMLWrite.cpp b/src/workspace/WorkSpaceXMLWrite.cpp index dc4e2625..4e4d00f6 100644 --- a/src/workspace/WorkSpaceXMLWrite.cpp +++ b/src/workspace/WorkSpaceXMLWrite.cpp @@ -12,6 +12,8 @@ #include "workspace/WorkSpaceManager.h" #include "workspace/FileEntry.h" +#include + WorkSpaceXMLWrite::WorkSpaceXMLWrite(WorkSpace* workspace, QObject* parent) noexcept : QObject(parent) , workSpace_(workspace) {} @@ -36,6 +38,7 @@ bool WorkSpaceXMLWrite::Save(const QString& path) { SaveChart(scene, &doc); SaveTimeStep(scene); SaveLamp(scene); + SaveCommond(scene); SaveFiles(scene, &doc); tinyxml2::XMLElement* entitiesXml = scene->InsertNewChildElement("entities"); @@ -58,6 +61,8 @@ bool WorkSpaceXMLWrite::SaveScene(tinyxml2::XMLElement* scene) { scene->SetAttribute("describe", workSpace_->GetDescribe().toStdString().c_str()); scene->SetAttribute("uuid", workSpace_->GetUUid().toStdString().c_str()); scene->SetAttribute("viewpoint", StringUtils::ViewpointToString(workSpace_->GetHomeViewpoint()).c_str()); + scene->SetAttribute("commondPath", ""); + return true; } @@ -72,12 +77,22 @@ bool WorkSpaceXMLWrite::SaveTimeStep(tinyxml2::XMLElement* scene) { } bool WorkSpaceXMLWrite::SaveLamp(tinyxml2::XMLElement* scene) { - LampStatus* lampStatus = workSpace_->GetLampStatus(); - if (nullptr == lampStatus) { - return false; + tinyxml2::XMLElement* lamp = scene->InsertNewChildElement("lamp"); + const QString lampPath = workSpace_->GetLampStatus()->GetPath(); + if (!lampPath.isEmpty()) { + lamp->SetAttribute("path", lampPath.toStdString().c_str()); + } + return true; +} + +bool WorkSpaceXMLWrite::SaveCommond(tinyxml2::XMLElement* scene) { + const QString commondPath = workSpace_->GetCommondFilePath(); + if (!commondPath.isEmpty()) { + tinyxml2::XMLElement* commond = scene->InsertNewChildElement("commond"); + // Extract just the filename from the full path for storage + QFileInfo fileInfo(commondPath); + commond->SetAttribute("path", fileInfo.fileName().toStdString().c_str()); } - tinyxml2::XMLElement* timestepXml = scene->InsertNewChildElement("lamp"); - timestepXml->SetAttribute("path", lampStatus->GetPath().toStdString().c_str()); return true; } diff --git a/src/workspace/WorkSpaceXMLWrite.h b/src/workspace/WorkSpaceXMLWrite.h index 2e3785e8..06299cf9 100644 --- a/src/workspace/WorkSpaceXMLWrite.h +++ b/src/workspace/WorkSpaceXMLWrite.h @@ -19,6 +19,7 @@ protected: bool SaveScene(tinyxml2::XMLElement* scene); bool SaveTimeStep(tinyxml2::XMLElement* scene); bool SaveLamp(tinyxml2::XMLElement* scene); + bool SaveCommond(tinyxml2::XMLElement* scene); bool SaveEntities(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc); bool SaveChart(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc); bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc); diff --git a/workspace/command.xml b/workspace/command.xml new file mode 100644 index 00000000..87a47783 --- /dev/null +++ b/workspace/command.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file