modify commond
This commit is contained in:
parent
c3f7978df9
commit
5bafe0d383
@ -1780,17 +1780,12 @@
|
|||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../ui/Menu/SimuRunMenu.cpp" line="80"/>
|
<location filename="../ui/Menu/SimuRunMenu.cpp" line="72"/>
|
||||||
<source>OnCreate</source>
|
<source>Commands</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../ui/Menu/SimuRunMenu.cpp" line="83"/>
|
<location filename="../ui/Menu/SimuRunMenu.cpp" line="87"/>
|
||||||
<source>OnLoad</source>
|
|
||||||
<translation type="unfinished"></translation>
|
|
||||||
</message>
|
|
||||||
<message>
|
|
||||||
<location filename="../ui/Menu/SimuRunMenu.cpp" line="99"/>
|
|
||||||
<source>unnamed</source>
|
<source>unnamed</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|||||||
@ -187,7 +187,9 @@ const QString QWorkspaceAttribute::GetCommondFilePath() const
|
|||||||
if (nullptr == workspace_) {
|
if (nullptr == workspace_) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return workspace_->GetCommondFilePath();
|
|
||||||
|
QString path = QString("%1/%2").arg(workspace_->GetDir(), workspace_->GetCommondFilePath());
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<FileEntry> QWorkspaceAttribute::GetFileEntries(FileEntryType type) const {
|
std::vector<FileEntry> QWorkspaceAttribute::GetFileEntries(FileEntryType type) const {
|
||||||
|
|||||||
@ -21,7 +21,7 @@ void CommandManager::Reload(WorkSpace* ws) {
|
|||||||
onLoad_.clear();
|
onLoad_.clear();
|
||||||
if (!ws) return;
|
if (!ws) return;
|
||||||
|
|
||||||
const QString cmdPath = ws->GetCommondFilePath();
|
const QString cmdPath = QString("%1/%2").arg(ws->GetDir(), ws->GetCommondFilePath());
|
||||||
if (cmdPath.isEmpty()) {
|
if (cmdPath.isEmpty()) {
|
||||||
LOG_INFO("no command xml configured");
|
LOG_INFO("no command xml configured");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -54,11 +54,6 @@ void WorkSpace::SetCommondFilePath(const QString& path) {
|
|||||||
commondPath_ = fileInfo.fileName();
|
commondPath_ = fileInfo.fileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString WorkSpace::GetCommondFilePath() const {
|
|
||||||
QString path = QString("%1/%2").arg(GetDir(), commondPath_);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkSpace::SetSimMatlab(const QString& path) {
|
void WorkSpace::SetSimMatlab(const QString& path) {
|
||||||
QFileInfo fileInfo(path);
|
QFileInfo fileInfo(path);
|
||||||
QString dirPath = QString("%1/%2").arg(GetDir(), fileInfo.fileName());
|
QString dirPath = QString("%1/%2").arg(GetDir(), fileInfo.fileName());
|
||||||
|
|||||||
@ -52,7 +52,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SetCommondFilePath(const QString& path);
|
void SetCommondFilePath(const QString& path);
|
||||||
const QString GetCommondFilePath() const;
|
const QString GetCommondFilePath() const {
|
||||||
|
return commondPath_;
|
||||||
|
}
|
||||||
|
|
||||||
// Execute command xml according to trigger
|
// Execute command xml according to trigger
|
||||||
enum class CommandWhen { OnCreate, OnLoad };
|
enum class CommandWhen { OnCreate, OnLoad };
|
||||||
@ -183,5 +185,6 @@ private:
|
|||||||
public:
|
public:
|
||||||
std::uint64_t GetFilesSeq() const { return filesSeq_; }
|
std::uint64_t GetFilesSeq() const { return filesSeq_; }
|
||||||
friend class WorkSpaceXMLWrite;
|
friend class WorkSpaceXMLWrite;
|
||||||
|
friend class WorkSpaceXMLParse;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -84,6 +84,23 @@ bool WorkSpaceXMLParse::ParseLamp(const tinyxml2::XMLElement* element) {
|
|||||||
return workSpace_->SetLampPath(path);
|
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) {
|
bool WorkSpaceXMLParse::ParseFiles(const tinyxml2::XMLElement* element) {
|
||||||
if (nullptr == element) {
|
if (nullptr == element) {
|
||||||
LOG_WARN("element is nullptr");
|
LOG_WARN("element is nullptr");
|
||||||
@ -252,6 +269,8 @@ bool WorkSpaceXMLParse::Load(const QString& dyt) {
|
|||||||
ParseTimestep(xmlElement);
|
ParseTimestep(xmlElement);
|
||||||
} else if (0 == strcmp(name, "lamp")) {
|
} else if (0 == strcmp(name, "lamp")) {
|
||||||
ParseLamp(xmlElement);
|
ParseLamp(xmlElement);
|
||||||
|
} else if (0 == strcmp(name, "commond")) {
|
||||||
|
ParseCommond(xmlElement);
|
||||||
}
|
}
|
||||||
else if (0 == strcmp(name, "charts")) {
|
else if (0 == strcmp(name, "charts")) {
|
||||||
ParseChart(xmlElement);
|
ParseChart(xmlElement);
|
||||||
|
|||||||
@ -31,6 +31,7 @@ private:
|
|||||||
bool ParseScene(const tinyxml2::XMLElement* element);
|
bool ParseScene(const tinyxml2::XMLElement* element);
|
||||||
bool ParseTimestep(const tinyxml2::XMLElement* element);
|
bool ParseTimestep(const tinyxml2::XMLElement* element);
|
||||||
bool ParseLamp(const tinyxml2::XMLElement* element);
|
bool ParseLamp(const tinyxml2::XMLElement* element);
|
||||||
|
bool ParseCommond(const tinyxml2::XMLElement* element);
|
||||||
bool ParseEntities(const tinyxml2::XMLElement* element);
|
bool ParseEntities(const tinyxml2::XMLElement* element);
|
||||||
bool ParseChart(const tinyxml2::XMLElement* element);
|
bool ParseChart(const tinyxml2::XMLElement* element);
|
||||||
bool ParseReport(const tinyxml2::XMLElement* element);
|
bool ParseReport(const tinyxml2::XMLElement* element);
|
||||||
|
|||||||
@ -12,6 +12,8 @@
|
|||||||
#include "workspace/WorkSpaceManager.h"
|
#include "workspace/WorkSpaceManager.h"
|
||||||
#include "workspace/FileEntry.h"
|
#include "workspace/FileEntry.h"
|
||||||
|
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
WorkSpaceXMLWrite::WorkSpaceXMLWrite(WorkSpace* workspace, QObject* parent) noexcept
|
WorkSpaceXMLWrite::WorkSpaceXMLWrite(WorkSpace* workspace, QObject* parent) noexcept
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, workSpace_(workspace) {}
|
, workSpace_(workspace) {}
|
||||||
@ -36,6 +38,7 @@ bool WorkSpaceXMLWrite::Save(const QString& path) {
|
|||||||
SaveChart(scene, &doc);
|
SaveChart(scene, &doc);
|
||||||
SaveTimeStep(scene);
|
SaveTimeStep(scene);
|
||||||
SaveLamp(scene);
|
SaveLamp(scene);
|
||||||
|
SaveCommond(scene);
|
||||||
SaveFiles(scene, &doc);
|
SaveFiles(scene, &doc);
|
||||||
|
|
||||||
tinyxml2::XMLElement* entitiesXml = scene->InsertNewChildElement("entities");
|
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("describe", workSpace_->GetDescribe().toStdString().c_str());
|
||||||
scene->SetAttribute("uuid", workSpace_->GetUUid().toStdString().c_str());
|
scene->SetAttribute("uuid", workSpace_->GetUUid().toStdString().c_str());
|
||||||
scene->SetAttribute("viewpoint", StringUtils::ViewpointToString(workSpace_->GetHomeViewpoint()).c_str());
|
scene->SetAttribute("viewpoint", StringUtils::ViewpointToString(workSpace_->GetHomeViewpoint()).c_str());
|
||||||
|
scene->SetAttribute("commondPath", "");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,12 +77,22 @@ bool WorkSpaceXMLWrite::SaveTimeStep(tinyxml2::XMLElement* scene) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool WorkSpaceXMLWrite::SaveLamp(tinyxml2::XMLElement* scene) {
|
bool WorkSpaceXMLWrite::SaveLamp(tinyxml2::XMLElement* scene) {
|
||||||
LampStatus* lampStatus = workSpace_->GetLampStatus();
|
tinyxml2::XMLElement* lamp = scene->InsertNewChildElement("lamp");
|
||||||
if (nullptr == lampStatus) {
|
const QString lampPath = workSpace_->GetLampStatus()->GetPath();
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,7 @@ protected:
|
|||||||
bool SaveScene(tinyxml2::XMLElement* scene);
|
bool SaveScene(tinyxml2::XMLElement* scene);
|
||||||
bool SaveTimeStep(tinyxml2::XMLElement* scene);
|
bool SaveTimeStep(tinyxml2::XMLElement* scene);
|
||||||
bool SaveLamp(tinyxml2::XMLElement* scene);
|
bool SaveLamp(tinyxml2::XMLElement* scene);
|
||||||
|
bool SaveCommond(tinyxml2::XMLElement* scene);
|
||||||
bool SaveEntities(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc);
|
bool SaveEntities(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc);
|
||||||
bool SaveChart(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc);
|
bool SaveChart(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc);
|
||||||
bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc);
|
bool SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc);
|
||||||
|
|||||||
51
workspace/command.xml
Normal file
51
workspace/command.xml
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<commands>
|
||||||
|
<!-- 创建时执行的命令 -->
|
||||||
|
<command name="初始化环境"
|
||||||
|
program="cmd.exe"
|
||||||
|
path="echo Initializing workspace environment..."
|
||||||
|
description="初始化工作空间环境"
|
||||||
|
when="oncreate"
|
||||||
|
enabled="true" />
|
||||||
|
|
||||||
|
<command name="检查Python版本"
|
||||||
|
program="python"
|
||||||
|
args="--version"
|
||||||
|
description="检查Python版本信息"
|
||||||
|
when="oncreate"
|
||||||
|
enabled="true" />
|
||||||
|
|
||||||
|
<!-- 加载时执行的命令 -->
|
||||||
|
<command name="启动服务"
|
||||||
|
program="cmd.exe"
|
||||||
|
path="echo Starting services..."
|
||||||
|
description="启动相关服务"
|
||||||
|
when="onload"
|
||||||
|
enabled="true" />
|
||||||
|
|
||||||
|
<command name="检查系统状态"
|
||||||
|
program="powershell.exe"
|
||||||
|
args="Get-Process | Select-Object -First 5"
|
||||||
|
description="检查系统进程状态"
|
||||||
|
when="onload"
|
||||||
|
enabled="true" />
|
||||||
|
|
||||||
|
<!-- 通用命令(默认为oncreate) -->
|
||||||
|
<command name="打开记事本"
|
||||||
|
program="notepad.exe"
|
||||||
|
description="打开Windows记事本"
|
||||||
|
enabled="true" />
|
||||||
|
|
||||||
|
<command name="查看目录"
|
||||||
|
program="cmd.exe"
|
||||||
|
args="/c dir"
|
||||||
|
description="查看当前目录内容"
|
||||||
|
enabled="true" />
|
||||||
|
|
||||||
|
<!-- 禁用的命令示例 -->
|
||||||
|
<command name="禁用命令"
|
||||||
|
program="cmd.exe"
|
||||||
|
path="echo This command is disabled"
|
||||||
|
description="这是一个被禁用的命令示例"
|
||||||
|
enabled="false" />
|
||||||
|
</commands>
|
||||||
Loading…
Reference in New Issue
Block a user