2025-01-04 04:12:51 +00:00
|
|
|
#include "workspace/WorkSpaceXMLParse.h"
|
|
|
|
|
|
|
|
|
|
#include "workspace/WorkSpace.h"
|
|
|
|
|
#include "entities/EntitiesManager.h"
|
|
|
|
|
|
|
|
|
|
#include "common/SpdLogger.h"
|
2025-01-05 18:18:16 +00:00
|
|
|
#include "workspace/WorkSpaceManager.h"
|
|
|
|
|
#include "utils/StringUtils.h"
|
2025-01-04 04:12:51 +00:00
|
|
|
|
|
|
|
|
WorkSpaceXMLParse::WorkSpaceXMLParse(WorkSpace* workspace, QObject* parent) noexcept
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
, workSpace_(workspace) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLParse::Save(const QString& path) {
|
|
|
|
|
path_ = path;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLParse::ParseScene(const tinyxml2::XMLElement* element) {
|
|
|
|
|
if (nullptr == element) {
|
|
|
|
|
LOG_WARN("element is nullptr");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-05 18:18:16 +00:00
|
|
|
const tinyxml2::XMLAttribute* current = element->FirstAttribute();
|
|
|
|
|
bool flag = false;
|
|
|
|
|
while (nullptr != current) {
|
|
|
|
|
const char* eleName = current->Name();
|
|
|
|
|
if (0 == strcmp(eleName, "name")) {
|
|
|
|
|
const char* name = current->Value();
|
|
|
|
|
|
|
|
|
|
workSpace_->SetName(name);
|
|
|
|
|
flag = true;
|
|
|
|
|
|
|
|
|
|
} else if (0 == strcmp(eleName, "describe")) {
|
|
|
|
|
const char* value = current->Value();
|
|
|
|
|
|
|
|
|
|
workSpace_->SetDescribe(value);
|
|
|
|
|
flag = true;
|
|
|
|
|
} else if (0 == strcmp(eleName, "uuid")) {
|
|
|
|
|
const char* value = current->Value();
|
|
|
|
|
|
|
|
|
|
workSpace_->SetUUid(value);
|
|
|
|
|
flag = true;
|
|
|
|
|
} else if (0 == strcmp(eleName, "viewpoint")) {
|
|
|
|
|
const char* value = current->Value();
|
|
|
|
|
workSpace_->SetHomeViewpoint(StringUtils::StringToViewpoint("home", value));
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
current = current->Next();
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
2025-01-05 18:18:16 +00:00
|
|
|
|
|
|
|
|
return flag;
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLParse::ParseTimestep(const tinyxml2::XMLElement* element) {
|
|
|
|
|
if (nullptr == element) {
|
|
|
|
|
LOG_WARN("element is nullptr");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* path = element->Attribute("path");
|
|
|
|
|
if (nullptr == path) {
|
|
|
|
|
LOG_WARN("element not has path");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return workSpace_->SetTimestepPath(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLParse::ParseLamp(const tinyxml2::XMLElement* element) {
|
|
|
|
|
if (nullptr == element) {
|
|
|
|
|
LOG_WARN("element is nullptr");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* path = element->Attribute("path");
|
|
|
|
|
if (nullptr == path) {
|
|
|
|
|
LOG_WARN("element not has path");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-10-14 16:41:12 +00:00
|
|
|
|
2025-01-04 04:12:51 +00:00
|
|
|
return workSpace_->SetLampPath(path);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-14 16:41:12 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-12 14:14:16 +00:00
|
|
|
bool WorkSpaceXMLParse::ParseFiles(const tinyxml2::XMLElement* element) {
|
|
|
|
|
if (nullptr == element) {
|
|
|
|
|
LOG_WARN("element is nullptr");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
FileEntryType enumType;
|
|
|
|
|
if (FileEntryTypeFromString(name, enumType)) {
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
workSpace_->CreateFileEntry(enumType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
typeElement = typeElement->NextSiblingElement("type");
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-04 04:12:51 +00:00
|
|
|
bool WorkSpaceXMLParse::ParseEntities(const tinyxml2::XMLElement* element) {
|
|
|
|
|
if (nullptr == element) {
|
|
|
|
|
LOG_WARN("element is nullptr");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* eleName = element->Name();
|
|
|
|
|
if (0 == strcmp(eleName, "entities")) {
|
|
|
|
|
return EntitiesManager::Get().Parse(element, workSpace_);
|
|
|
|
|
}
|
|
|
|
|
LOG_WARN("element not has entities");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLParse::ParseChart(const tinyxml2::XMLElement* element)
|
|
|
|
|
{
|
|
|
|
|
if (nullptr == element) {
|
|
|
|
|
LOG_WARN("element is nullptr");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tinyxml2::XMLElement* xmlElement = element->FirstChildElement();
|
|
|
|
|
while (nullptr != xmlElement) {
|
|
|
|
|
const char* name = xmlElement->Name();
|
|
|
|
|
if (0 == strcmp(name, "Wave"))
|
|
|
|
|
{
|
|
|
|
|
QVariantMap varChart;
|
|
|
|
|
const tinyxml2::XMLAttribute* attribute = xmlElement->FirstAttribute();
|
|
|
|
|
while (nullptr != attribute) {
|
|
|
|
|
|
2025-01-07 15:45:23 +00:00
|
|
|
workSpace_->SetWavePath(QString::fromLocal8Bit(attribute->Value()));
|
2025-01-04 04:12:51 +00:00
|
|
|
attribute = attribute->Next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (0 == strcmp(name, "Report"))
|
|
|
|
|
{
|
|
|
|
|
QVariantMap varChart;
|
|
|
|
|
const tinyxml2::XMLAttribute* attribute = xmlElement->FirstAttribute();
|
|
|
|
|
while (nullptr != attribute) {
|
|
|
|
|
|
2025-01-07 15:45:23 +00:00
|
|
|
workSpace_->SetReportPath(QString::fromLocal8Bit(attribute->Value()));
|
2025-01-04 04:12:51 +00:00
|
|
|
attribute = attribute->Next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (0 == strcmp(name, "RD"))
|
|
|
|
|
{
|
|
|
|
|
QVariantMap varChart;
|
|
|
|
|
const tinyxml2::XMLAttribute* attribute = xmlElement->FirstAttribute();
|
|
|
|
|
while (nullptr != attribute) {
|
|
|
|
|
|
2025-01-07 15:45:23 +00:00
|
|
|
workSpace_->SetRDPath(QString::fromLocal8Bit(attribute->Value()));
|
2025-01-04 04:12:51 +00:00
|
|
|
attribute = attribute->Next();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-07 15:45:23 +00:00
|
|
|
else if (0 == strcmp(name, "SimMatlab"))
|
2025-01-05 14:29:59 +00:00
|
|
|
{
|
|
|
|
|
QVariantMap varChart;
|
|
|
|
|
const tinyxml2::XMLAttribute* attribute = xmlElement->FirstAttribute();
|
|
|
|
|
while (nullptr != attribute) {
|
|
|
|
|
|
2025-01-07 15:45:23 +00:00
|
|
|
workSpace_->SetSimMatlab(QString::fromLocal8Bit(attribute->Value()));
|
2025-01-07 14:04:19 +00:00
|
|
|
attribute = attribute->Next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-04 04:12:51 +00:00
|
|
|
xmlElement = xmlElement->NextSiblingElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-05 04:07:30 +00:00
|
|
|
bool WorkSpaceXMLParse::ParseSimMatlab(const tinyxml2::XMLElement* element)
|
|
|
|
|
{
|
|
|
|
|
if (nullptr == element) {
|
|
|
|
|
LOG_WARN("element is nullptr");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tinyxml2::XMLElement* xmlElement = element->FirstChildElement();
|
|
|
|
|
while (nullptr != xmlElement) {
|
|
|
|
|
const char* name = xmlElement->Name();
|
|
|
|
|
if (0 == strcmp(name, "SimMatlab"))
|
|
|
|
|
{
|
|
|
|
|
QVariantMap varChart;
|
|
|
|
|
const tinyxml2::XMLAttribute* attribute = xmlElement->FirstAttribute();
|
|
|
|
|
while (nullptr != attribute) {
|
|
|
|
|
|
|
|
|
|
WorkSpaceManager::Get().GetCurrent()->SetSimMatlab(QString::fromLocal8Bit(attribute->Value()));
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xmlElement = xmlElement->NextSiblingElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-04 04:12:51 +00:00
|
|
|
bool WorkSpaceXMLParse::ParseReport(const tinyxml2::XMLElement* element)
|
|
|
|
|
{
|
|
|
|
|
QString strFile = "";
|
|
|
|
|
int iBatch = 0;
|
|
|
|
|
|
|
|
|
|
const tinyxml2::XMLAttribute* attribute = element->FirstAttribute();
|
|
|
|
|
while (nullptr != attribute) {
|
|
|
|
|
if (0 == strcmp(attribute->Name(), "file"))
|
|
|
|
|
{
|
|
|
|
|
strFile = QString::fromLocal8Bit(attribute->Value());
|
|
|
|
|
}
|
|
|
|
|
else if (0 == strcmp(attribute->Name(), "batch"))
|
|
|
|
|
{
|
|
|
|
|
iBatch = atoi(attribute->Value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLParse::Load(const QString& dyt) {
|
2025-01-21 18:42:57 +00:00
|
|
|
std::string path = dyt.toLocal8Bit().constData();
|
2025-01-04 04:12:51 +00:00
|
|
|
LOG_INFO("load path:{}", path);
|
|
|
|
|
tinyxml2::XMLDocument xmlDocument;
|
|
|
|
|
tinyxml2::XMLError error = xmlDocument.LoadFile(path.c_str());
|
|
|
|
|
if (tinyxml2::XMLError::XML_SUCCESS != error) {
|
|
|
|
|
LOG_INFO("load feiled:{}", static_cast<int>(error));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tinyxml2::XMLElement* root = xmlDocument.RootElement();
|
|
|
|
|
if (!ParseScene(root)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tinyxml2::XMLElement* xmlElement = root->FirstChildElement();
|
|
|
|
|
while (nullptr != xmlElement) {
|
|
|
|
|
const char* name = xmlElement->Name();
|
|
|
|
|
if (0 == strcmp(name, "entities")) {
|
|
|
|
|
ParseEntities(xmlElement);
|
|
|
|
|
} else if (0 == strcmp(name, "timestep")) {
|
|
|
|
|
ParseTimestep(xmlElement);
|
|
|
|
|
} else if (0 == strcmp(name, "lamp")) {
|
|
|
|
|
ParseLamp(xmlElement);
|
2025-10-14 16:41:12 +00:00
|
|
|
} else if (0 == strcmp(name, "commond")) {
|
|
|
|
|
ParseCommond(xmlElement);
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
else if (0 == strcmp(name, "charts")) {
|
|
|
|
|
ParseChart(xmlElement);
|
|
|
|
|
}
|
|
|
|
|
else if (0 == strcmp(name, "ReportInfo")) {
|
|
|
|
|
ParseReport(xmlElement);
|
|
|
|
|
}
|
2025-07-05 04:07:30 +00:00
|
|
|
else if (0 == strcmp(name, "SimMatlab")) {
|
|
|
|
|
ParseSimMatlab(xmlElement);
|
|
|
|
|
}
|
2025-10-12 14:14:16 +00:00
|
|
|
else if (0 == strcmp(name, "files")) {
|
|
|
|
|
ParseFiles(xmlElement);
|
|
|
|
|
}
|
2025-01-04 04:12:51 +00:00
|
|
|
xmlElement = xmlElement->NextSiblingElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|