COMPASSi/trunk/code/projects/DataManager/Infrastructure.Data/DataContainer/StructureCalculationData.cpp

188 lines
5.3 KiB
C++
Raw Normal View History

2025-06-27 17:52:01 +08:00
#include "DataContainer/StructureCalculationData.h"
int StructureCalculationData::fromXml(const pugi::xml_node node)
{
if (node.empty())
{
return -1;
}
m_StructureCal.fromXmlEx(node, m_childModules, m_childModuleNames, m_DataRows, m_ModuleNames);
xercesc::XMLPlatformUtils::Initialize();
::xml_schema::properties props;
std::string xml_string = "";
// 总纵强度
if (getDataRowValue("Strength") != "")
{
xml_string = getDataRowValue("Strength").toStdString();
try
{
std::istringstream iss(xml_string);
m_StrengthSet = strength_set::StrengthSet_(iss, ::xml_schema::flags::dont_validate, props);
}
catch (const xsd::cxx::tree::error<char> &e)
{
std::cerr << "错误行号: " << e.line() << std::endl; // 注意是 line() 不是 line
}
}
// 规范校核--TODO
if (getDataRowValue("Scantlings") != "")
{
xml_string = getDataRowValue("Scantlings").toStdString();
// try
// {
// std::istringstream iss(xml_string);
// m_StrengthSet = strength_set::StrengthSet_(iss, ::xml_schema::flags::dont_validate, props);
// }
// catch (const xsd::cxx::tree::error<char> &e)
// {
// std::cerr << "错误行号: " << e.line() << std::endl; // 注意是 line() 不是 line
// }
}
xercesc::XMLPlatformUtils::Terminate();
return EXECUTE_SUCCESS;
}
void StructureCalculationData::saveStructureCalcData(QString path)
{
xercesc::XMLPlatformUtils::Initialize();
std::ostringstream ofs(path.toStdString());
::xml_schema::namespace_infomap ns_map;
// 总纵强度
{
ns_map[""].name = "http://tempuri.org/StrengthSet.xsd";
// 使用全局命名空间下的 flags
strength_set::StrengthSet_(ofs, *m_StrengthSet, ns_map, "UTF-8", ::xml_schema::flags::no_xml_declaration); // format_pretty);
}
// 规范校核
{
ns_map[""].name = "http://tempuri.org/ScantlingSet.xsd";
// 使用全局命名空间下的 flags
// scantling_set::ScantlingSet_(ofs, *m_ScantlingsSet, ns_map, "UTF-8", ::xml_schema::flags::no_xml_declaration); // format_pretty);
// xercesc::XMLPlatformUtils::Terminate();
}
xercesc::XMLPlatformUtils::Terminate();
return 0;
}
std::vector<std::string> &StructureCalculationData::getAnalyseNameList()
{
return m_childModuleNames;
}
int StructureCalculationData::toXml(pugi::xml_node node)
{
xercesc::XMLPlatformUtils::Initialize();
std::ostringstream ofs("temp.xml");
::xml_schema::namespace_infomap ns_map;
// 总纵强度
{
ns_map[""].name = "http://tempuri.org/StrengthSet.xsd";
// 使用全局命名空间下的 flags
std::string strValue = strength_set::StrengthSet_(ofs, *m_StrengthSet, ns_map, "UTF-8", ::xml_schema::flags::no_xml_declaration); // format_pretty);
addOrUpdateDataRow("Structure", QString::fromStdString(strValue));
m_StructureCal.toXml(node, m_DataRows, m_childModules, m_childModuleNames);
}
// 规范校核
{
ns_map[""].name = "http://tempuri.org/ScantlingSet.xsd";
// 使用全局命名空间下的 flags
// std::string strValue = scantling_set::ScantlingSet_(ofs, *m_ScantlingsSet, ns_map, "UTF-8", ::xml_schema::flags::no_xml_declaration); // format_pretty);
// addOrUpdateDataRow("Scantlings", QString::fromStdString(strValue));
// m_StructureCal.toXml(node, m_DataRows, m_childModules, m_childModuleNames);
}
xercesc::XMLPlatformUtils::Terminate();
return 0;
}
bool StructureCalculationData::isEmpty()
{
if (m_DataRows.size() > 0)
{
return false;
}
return true;
}
QString StructureCalculationData::getDataRowValue(const QString &key)
{
if (!m_DataRows.contains(key))
return "";
QString dd = m_DataRows[key]->Value();
return dd;
}
void StructureCalculationData::addOrUpdateDataRow(const QString &key, QString value, QString caption, QString remark)
{
if (key.isEmpty())
return;
if (!m_DataRows.contains(key))
{
DataRowInf *o = new DataRowInf();
o->setID(key);
o->setCaption(caption);
o->setRemark(remark);
o->setValue(value);
m_DataRows.insert(key, o);
}
else
{
DataRowInf *o = m_DataRows.value(key);
o->setCaption(caption);
o->setRemark(remark);
o->setValue(value);
}
}
bool StructureCalculationData::createDataRow(const QString &key, QString value, QString caption, QString remark)
{
if (!m_DataRows.contains(key))
{
DataRowInf *o = new DataRowInf();
o->setID(key);
o->setCaption(caption);
o->setRemark(remark);
o->setValue(value);
m_DataRows.insert(key, o);
return true;
}
return false;
}
bool StructureCalculationData::CreateChildModulus(const QString &key, QString caption, QString remark)
{
if (!m_childModules.contains(key))
{
DataRowInf *o = new DataRowInf();
o->setID(key);
o->setCaption(caption);
o->setRemark(remark);
o->setValue("");
m_childModules.insert(key, o);
m_childModuleNames.push_back(key.toStdString());
return true;
}
return false;
}