2025-01-04 04:12:51 +00:00
|
|
|
#include "workspace/WorkSpaceXMLWrite.h"
|
|
|
|
|
|
|
|
|
|
#include "workspace/WorkSpace.h"
|
|
|
|
|
#include "entities/EntitiesManager.h"
|
|
|
|
|
#include "entities/Entity.h"
|
|
|
|
|
#include "workspace/Timestep.h"
|
|
|
|
|
#include "workspace/LampStatus.h"
|
|
|
|
|
|
|
|
|
|
#include "common/SpdLogger.h"
|
2025-01-05 18:18:16 +00:00
|
|
|
#include "utils/StringUtils.h"
|
2025-01-04 04:12:51 +00:00
|
|
|
|
2025-01-05 18:18:16 +00:00
|
|
|
#include "workspace/WorkSpaceManager.h"
|
2025-10-12 14:14:16 +00:00
|
|
|
#include "workspace/FileEntry.h"
|
2025-01-04 04:12:51 +00:00
|
|
|
|
|
|
|
|
WorkSpaceXMLWrite::WorkSpaceXMLWrite(WorkSpace* workspace, QObject* parent) noexcept
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
, workSpace_(workspace) {}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLWrite::Save(const QString& path) {
|
2025-01-21 18:42:57 +00:00
|
|
|
LOG_INFO("save path: {}", path.toLocal8Bit().constData());
|
2025-01-04 04:12:51 +00:00
|
|
|
if (nullptr == workSpace_) {
|
|
|
|
|
LOG_WARN("worksapce is nullptr");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
tinyxml2::XMLDocument doc;
|
|
|
|
|
|
|
|
|
|
doc.LinkEndChild(doc.NewDeclaration("xml version=\"1.0\" encoding=\"UTF-8\""));
|
|
|
|
|
|
|
|
|
|
tinyxml2::XMLElement* scene = doc.NewElement("scene");
|
|
|
|
|
if (!SaveScene(scene)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doc.LinkEndChild(scene);
|
|
|
|
|
|
|
|
|
|
SaveChart(scene, &doc);
|
|
|
|
|
SaveTimeStep(scene);
|
2025-07-06 16:12:06 +00:00
|
|
|
SaveLamp(scene);
|
2025-10-12 14:14:16 +00:00
|
|
|
SaveFiles(scene, &doc);
|
2025-01-04 04:12:51 +00:00
|
|
|
|
|
|
|
|
tinyxml2::XMLElement* entitiesXml = scene->InsertNewChildElement("entities");
|
|
|
|
|
std::vector<Entity*>& entities = workSpace_->GetEntities();
|
|
|
|
|
for (auto entity : entities) {
|
|
|
|
|
entity->UnSerialize(entitiesXml);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-21 18:42:57 +00:00
|
|
|
tinyxml2::XMLError xmlError = doc.SaveFile(path.toLocal8Bit().constData(), false);
|
2025-01-04 04:12:51 +00:00
|
|
|
if (tinyxml2::XML_SUCCESS != xmlError) {
|
|
|
|
|
LOG_WARN("worksapce is nullptr");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLWrite::SaveScene(tinyxml2::XMLElement* scene) {
|
|
|
|
|
const QString name = workSpace_->GetName();
|
|
|
|
|
scene->SetAttribute("name", name.toStdString().c_str());
|
|
|
|
|
scene->SetAttribute("describe", workSpace_->GetDescribe().toStdString().c_str());
|
|
|
|
|
scene->SetAttribute("uuid", workSpace_->GetUUid().toStdString().c_str());
|
2025-01-05 18:18:16 +00:00
|
|
|
scene->SetAttribute("viewpoint", StringUtils::ViewpointToString(workSpace_->GetHomeViewpoint()).c_str());
|
2025-01-04 04:12:51 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLWrite::SaveTimeStep(tinyxml2::XMLElement* scene) {
|
|
|
|
|
Timestep* timestep = workSpace_->GetTimestep();
|
|
|
|
|
if (nullptr == timestep) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
tinyxml2::XMLElement* timestepXml = scene->InsertNewChildElement("timestep");
|
|
|
|
|
timestepXml->SetAttribute("path", timestep->GetPath().toStdString().c_str());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLWrite::SaveLamp(tinyxml2::XMLElement* scene) {
|
|
|
|
|
LampStatus* lampStatus = workSpace_->GetLampStatus();
|
|
|
|
|
if (nullptr == lampStatus) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
tinyxml2::XMLElement* timestepXml = scene->InsertNewChildElement("lamp");
|
|
|
|
|
timestepXml->SetAttribute("path", lampStatus->GetPath().toStdString().c_str());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLWrite::SaveEntities(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) {
|
|
|
|
|
tinyxml2::XMLElement* entitics = doc->NewElement("entities");
|
|
|
|
|
scene->LinkEndChild(entitics);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WorkSpaceXMLWrite::SaveChart(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc)
|
|
|
|
|
{
|
|
|
|
|
tinyxml2::XMLElement* charts= doc->NewElement("charts");
|
|
|
|
|
scene->LinkEndChild(charts);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
tinyxml2::XMLElement* chart = doc->NewElement("Wave");
|
|
|
|
|
charts->LinkEndChild(chart);
|
|
|
|
|
|
2025-01-07 15:45:23 +00:00
|
|
|
chart->SetAttribute("file", workSpace_->GetWavePath().toLocal8Bit().constData());
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
tinyxml2::XMLElement* chart = doc->NewElement("Report");
|
|
|
|
|
charts->LinkEndChild(chart);
|
|
|
|
|
|
2025-01-07 15:45:23 +00:00
|
|
|
chart->SetAttribute("Report", workSpace_->GetReportPath().toLocal8Bit().constData());
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
tinyxml2::XMLElement* chart = doc->NewElement("RD");
|
|
|
|
|
charts->LinkEndChild(chart);
|
|
|
|
|
|
2025-01-07 15:45:23 +00:00
|
|
|
chart->SetAttribute("RD", workSpace_->GetRDPath().toLocal8Bit().constData());
|
2025-01-04 04:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-05 14:29:59 +00:00
|
|
|
{
|
2025-01-07 15:45:23 +00:00
|
|
|
tinyxml2::XMLElement* chart = doc->NewElement("SimMatlab");
|
2025-01-05 14:29:59 +00:00
|
|
|
charts->LinkEndChild(chart);
|
|
|
|
|
|
2025-07-05 04:07:30 +00:00
|
|
|
chart->SetAttribute("SimMatlab", workSpace_->GetSimMatlabName().toLocal8Bit().constData());
|
2025-01-07 14:04:19 +00:00
|
|
|
}
|
2025-01-07 15:45:23 +00:00
|
|
|
|
2025-01-04 04:12:51 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2025-10-12 14:14:16 +00:00
|
|
|
|
|
|
|
|
bool WorkSpaceXMLWrite::SaveFiles(tinyxml2::XMLElement* scene, tinyxml2::XMLDocument* doc) {
|
|
|
|
|
// Persist multi-file entries per type as counts
|
|
|
|
|
tinyxml2::XMLElement* files = doc->NewElement("files");
|
|
|
|
|
scene->LinkEndChild(files);
|
|
|
|
|
|
|
|
|
|
for (const auto& kv : workSpace_->files_) {
|
|
|
|
|
const FileEntryType type = kv.first;
|
|
|
|
|
const auto& vec = kv.second;
|
|
|
|
|
tinyxml2::XMLElement* typeElem = doc->NewElement("type");
|
|
|
|
|
typeElem->SetAttribute("name", FileEntryTypeToString(type));
|
|
|
|
|
typeElem->SetAttribute("count", static_cast<int>(vec.size()));
|
|
|
|
|
files->LinkEndChild(typeElem);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|