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-01-04 04:12:51 +00:00
|
|
|
|
|
|
|
WorkSpaceXMLWrite::WorkSpaceXMLWrite(WorkSpace* workspace, QObject* parent) noexcept
|
|
|
|
: QObject(parent)
|
|
|
|
, workSpace_(workspace) {}
|
|
|
|
|
|
|
|
bool WorkSpaceXMLWrite::Save(const QString& path) {
|
|
|
|
LOG_INFO("save path: {}", path.toStdString());
|
|
|
|
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);
|
|
|
|
|
|
|
|
tinyxml2::XMLElement* entitiesXml = scene->InsertNewChildElement("entities");
|
|
|
|
std::vector<Entity*>& entities = workSpace_->GetEntities();
|
|
|
|
for (auto entity : entities) {
|
|
|
|
entity->UnSerialize(entitiesXml);
|
|
|
|
}
|
|
|
|
|
|
|
|
tinyxml2::XMLError xmlError = doc.SaveFile(path.toStdString().c_str(), false);
|
|
|
|
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-01-07 15:45:23 +00:00
|
|
|
chart->SetAttribute("SimMatlab", workSpace_->GetSimMatlab().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;
|
|
|
|
}
|