同步代码

This commit is contained in:
zyuan 2025-06-25 17:44:40 +08:00
parent 8ec0ce43e3
commit 5956959e08
12 changed files with 1102 additions and 28 deletions

View File

@ -133,7 +133,15 @@ enum CMD
CMD_certify_EEDI, //发证EEDI编辑器
CMD_certify_check_EEDI, //发证EEDI编辑器数检
CMD_certify_save_EEDI, //发证EEDI编辑器保存
CMD_certify_OK_EEDI //发证EEDI编辑器确认
CMD_certify_OK_EEDI, //发证EEDI编辑器确认
CMD_calculate_section = 3300, //型材计算
CMD_calculate_section_open, //型材计算打开
CMD_calculate_diagonal, //斜杆计算
CMD_calculate_diagonal_open, //斜杆计算打开
CMD_calculate_strut_open, //支柱计算打开
CMD_calculate_strut //支柱计算
};

View File

@ -119,5 +119,11 @@ public:
void certify_EEDI_save(const QString &message);
void certify_EEDI_check(const QString &message);
void calculate_section(const QString &message);
void calculate_diagonal(const QString &message);
void calculate_strut(const QString &message);
void calculate_strut_open(const QString &message);
void calculate_section_open(const QString &message);
void calculate_diagonal_open(const QString &message);
};
#endif // MessageHandle_H

View File

@ -33,6 +33,31 @@ extern "C"
XMLFile_Type_dxf,
XMLFile_Type_size
};
enum DATAMANAGER_DLL_API_EXPORTS calculate_section_type
{
SECTION_FLAT_BAR_ROUND, // 球扁钢
SECTION_ANGLE, // 角钢
SECTION_EQUAL_ANGLE, // 等边角钢
SECTION_T_SHAPE, // 丄型钢倒T型钢
SECTION_BENT_PLATE, // 折边板
SECTION_FLAT_BAR, // 扁钢
SECTION_OTHER // 其他
};
enum DATAMANAGER_DLL_API_EXPORTS calculate_diagonal
{
DIAGONAL_SINGLE_ANGLE, // 单角钢
DIAGONAL_DOUBLE_ANGLE // 双角钢
};
enum DATAMANAGER_DLL_API_EXPORTS calculate_strut
{
STRUT_PIPE, // 管型
STRUT_CROSS // 十字型
};
class DATAMANAGER_DLL_API_EXPORTS DataManager : public BaseDataManager
{
@ -350,6 +375,24 @@ extern "C"
bool isTonnagechecked = false;
void calculate_section(int &errorCode, QString &outMsg, QString &data, const QString &message);
void calculate_strut(int &errorCode, QString &outMsg, QString &data, const QString &message);
void calculate_diagonal(int &errorCode, QString &outMsg, QString &data, const QString &message);
double Gjpmms(double h, double A, double Y, double I, double dbkd, double dbhd,double& ii, double& ww, double& yy);
void calculate_strut_open(int &errorCode, QString &outMsg, QString &data, const QString &message);
void calculate_diagonal_open(int &errorCode, QString &outMsg, QString &data, const QString &message);
void calculate_section_open(int &errorCode, QString &outMsg, QString &data, const QString &message);
std::vector<std::string> extract_ids_from_file(const QString &filePath, const std::string &rootName);
private:
DataManager();
~DataManager();

View File

@ -9,6 +9,8 @@
#include <QObject>
#include <QMetaProperty>
#include <QDebug>
#include <string>
struct DataRowInf : public QObject
{
@ -196,13 +198,28 @@ public:
}
void toXml(pugi::xml_node xRoot, QMap<QString, DataRowInf*>& _DataRows, QMap<QString, DataRowInf*>& _childModules)
void toXml(pugi::xml_node xRoot, QMap<QString, DataRowInf*>& _DataRows, QMap<QString, DataRowInf*>& _childModules, std::vector<std::string>& _childModuleNames)
{
pugi::xml_node xDicDataRows = xRoot.append_child("DataRows");
serializeObjDic(_DataRows, xDicDataRows);
pugi::xml_node xDic = xRoot.append_child("ChildModulus");
serializeObjDic(_childModules, xDic);
for (auto it = _childModuleNames.begin(); it != _childModuleNames.end(); ++it)
{
std::string key = *it;
DataRowInf* o = _childModules.value(QString::fromStdString(key));
if (!o)
{
continue;
}
pugi::xml_node xo = xDic.append_child(o->ID().toStdString().c_str());
serializeToXml(xo, o);
}
}
void fromXmlEx(const pugi::xml_node xml, QMap<QString, DataRowInf*>& _childModules, std::vector<std::string>& _childModuleNames, QMap<QString, DataRowInf*>& _DataRows, std::vector<std::string>& _DataRowsNames) ;

View File

@ -16,13 +16,22 @@ public:
}
~StabCalculationData()
{
for (auto it = m_DataRows.begin(); it != m_DataRows.end(); ++it) {
delete it.value();
}
m_DataRows.clear();
for (auto it = m_childModules.begin(); it != m_childModules.end(); ++it) {
delete it.value();
}
m_childModules.clear();
}
void addHydroBInfo(BInf& info);
BInf* FindByParamID(std::string strParamID);
int fromXml(const pugi::xml_node node);
int toXml(pugi::xml_node node, QString outFilePath);
int toXml(pugi::xml_node node);
void AddXLabelRow(XLabel& data);
void AddStationLabelRow(StationLabel& data);

View File

@ -95,7 +95,8 @@ public:
void loadStabModelDS(const std::string &xml_str);
std::string saveSerializationXMLFile(QString xmlfile_path);
void saveSerializationXMLFile(QString xmlfile_path);
std::string saveSerializationXMLString();
// 反序列化 从modelDS中获取 数据
BInf_Table* getBInf_table();

View File

@ -29,7 +29,15 @@ extern "C"
void structure_patp_editor(json &outjson);
void structure_zcmt_editor(json &outjson);
void structure_cprt_editor(json &outjson);
void calculate_section(int &errorCode, QString &outMsg, QString &data, const QString &message);
void calculate_strut(int &errorCode, QString &outMsg, QString &data, const QString &message);
void calculate_diagonal(int &errorCode, QString &outMsg, QString &data, const QString &message);
void calculate_strut_open(int &errorCode, QString &outMsg, QString &data, const QString &message);
void calculate_section_open(int &errorCode, QString &outMsg, QString &data, const QString &message);
void calculate_diagonal_open(int &errorCode, QString &outMsg, QString &data, const QString &message);
private:
StructureModel();
~StructureModel();

View File

@ -71,11 +71,14 @@ ToolUIFunction::ToolUIFunction()
ccsMessageHandle::instance()->register_callback(BIND(certify_delete_cal), CMD_certify_delete_cal);
ccsMessageHandle::instance()->register_callback(BIND(certify_EEDI), CMD_certify_EEDI);
ccsMessageHandle::instance()->register_callback(BIND(certify_EEDI_save), CMD_certify_save_EEDI);
ccsMessageHandle::instance()->register_callback(BIND(certify_EEDI_check), CMD_certify_check_EEDI);
ccsMessageHandle::instance()->register_callback(BIND(calculate_section), CMD_calculate_section);
ccsMessageHandle::instance()->register_callback(BIND(calculate_diagonal), CMD_calculate_diagonal);
ccsMessageHandle::instance()->register_callback(BIND(calculate_strut), CMD_calculate_strut);
ccsMessageHandle::instance()->register_callback(BIND(calculate_strut_open), CMD_calculate_strut_open);
ccsMessageHandle::instance()->register_callback(BIND(calculate_section_open), CMD_calculate_section_open);
ccsMessageHandle::instance()->register_callback(BIND(calculate_diagonal_open), CMD_calculate_diagonal_open);
LOG_DEBUG("ToolUIFunction Constructed");
}
@ -135,6 +138,12 @@ ToolUIFunction::~ToolUIFunction()
ccsMessageHandle::instance()->unregister_callback(CMD_certify_EEDI);
ccsMessageHandle::instance()->unregister_callback(CMD_certify_save_EEDI);
ccsMessageHandle::instance()->unregister_callback(CMD_certify_check_EEDI);
ccsMessageHandle::instance()->unregister_callback(CMD_calculate_section);
ccsMessageHandle::instance()->unregister_callback(CMD_calculate_diagonal);
ccsMessageHandle::instance()->unregister_callback(CMD_calculate_strut);
ccsMessageHandle::instance()->unregister_callback(CMD_calculate_strut_open);
ccsMessageHandle::instance()->unregister_callback(CMD_calculate_section_open);
ccsMessageHandle::instance()->unregister_callback(CMD_calculate_diagonal_open);
LOG_DEBUG("ToolUIFunction Destroyed");
}
@ -1215,3 +1224,58 @@ void ToolUIFunction::certify_EEDI_check(const QString& message)
QtToWebFunction::getInstance().qt2web(CMD_certify_check_EEDI, errorCode, outMsg, data);
}
void ToolUIFunction::calculate_section(const QString& message)
{
int errorCode = 0;
QString data = "";
QString outMsg;
getStructureModelPtr()->calculate_section(errorCode, outMsg, data, message);
QtToWebFunction::getInstance().qt2web(CMD_calculate_section, errorCode, outMsg, data);
}
void ToolUIFunction::calculate_diagonal(const QString& message)
{
int errorCode = 0;
QString data = "";
QString outMsg;
getStructureModelPtr()->calculate_diagonal(errorCode, outMsg, data, message);
QtToWebFunction::getInstance().qt2web(CMD_calculate_diagonal, errorCode, outMsg, data);
}
void ToolUIFunction::calculate_strut(const QString& message)
{
int errorCode = 0;
QString data = "";
QString outMsg;
getStructureModelPtr()->calculate_strut(errorCode, outMsg, data, message);
QtToWebFunction::getInstance().qt2web(CMD_calculate_strut, errorCode, outMsg, data);
}
void ToolUIFunction::calculate_strut_open(const QString& message)
{
int errorCode = 0;
QString data = "";
QString outMsg;
getStructureModelPtr()->calculate_strut_open(errorCode, outMsg, data, message);
QtToWebFunction::getInstance().qt2web(CMD_calculate_strut_open, errorCode, outMsg, data);
}
void ToolUIFunction::calculate_section_open(const QString& message)
{
int errorCode = 0;
QString data = "";
QString outMsg;
getStructureModelPtr()->calculate_section_open(errorCode, outMsg, data, message);
QtToWebFunction::getInstance().qt2web(CMD_calculate_section_open, errorCode, outMsg, data);
}
void ToolUIFunction::calculate_diagonal_open(const QString& message)
{
int errorCode = 0;
QString data = "";
QString outMsg;
getStructureModelPtr()->calculate_diagonal_open(errorCode, outMsg, data, message);
QtToWebFunction::getInstance().qt2web(CMD_calculate_diagonal_open, errorCode, outMsg, data);
}

View File

@ -22,6 +22,7 @@
#include "CommandStreamProcessing.h"
#include "StructureCalculation/StrengthCalculation.h"
#include "CertifyCalculation/CertifyCalculation.h"
#include "StructureModel.h"
DataManager *DataManager::m_pDataManagerInstance = nullptr;
@ -403,6 +404,8 @@ void DataManager::saveFile(QString &savefilePath)
pugi::xml_node model_stab_cal = root.append_child("StabilityCal");
m_StabCalData.toXml(model_stab_cal);
pugi::xml_node model_certify_cal = root.append_child("CertifyCal");
m_CertifyCal->toXml(model_certify_cal);
@ -5927,3 +5930,888 @@ std::string DataManager::CheckV5()
return error;
}
void DataManager::calculate_section(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
nlohmann::json myjson;
try
{
myjson = nlohmann::json::parse(message.toStdString());
}
catch (const nlohmann::json::parse_error &e)
{
outMsg = e.what();
errorCode = 1;
return;
}
int type = myjson["type"].get<int>();
double dblH;
// double b = typeNode.child("b").text().as_double();
// double t1 = typeNode.child("t1").text().as_double();
double dblA;
double dblI;
double dblY;
switch (type)
{
case SECTION_FLAT_BAR_ROUND:
{
QString filePath = PathUtil::bin_dir() + "qbg.xml";
pugi::xml_document temp_xmldoc;
pugi::xml_parse_result result = temp_xmldoc.load_file(filePath.toStdWString().c_str());
if (!result)
{
qDebug() << "XML解析错误" << result.description()
<< "\n错误位置:" << result.offset
<< "\n错误信息:" << result.description();
return;
}
if(result)
{
const pugi::xml_node &root = temp_xmldoc.child("qbg");
std::string value = myjson["value"].get<std::string>();
// 遍历 type 节点,查找 id 属性等于目标值
for (pugi::xml_node typeNode : root.children("type"))
{
std::string id = typeNode.attribute("id").as_string();
if (id == value)
{
// 找到匹配的 type 节点,提取其值
dblH = typeNode.child("h").text().as_double() / 10;
// double b = typeNode.child("b").text().as_double();
// double t1 = typeNode.child("t1").text().as_double();
dblA = typeNode.child("A1").text().as_double();
dblI = typeNode.child("Ix1").text().as_double();
dblY = typeNode.child("y1").text().as_double();
}
break; // 找到后退出循环
}
}
}
case SECTION_ANGLE:
{
QString filePath = PathUtil::bin_dir() + "jq.xml";
pugi::xml_document temp_xmldoc;
pugi::xml_parse_result result = temp_xmldoc.load_file(filePath.toStdWString().c_str());
if (!result)
{
qDebug() << "XML解析错误" << result.description()
<< "\n错误位置:" << result.offset
<< "\n错误信息:" << result.description();
return;
}
if(result)
{
const pugi::xml_node &root = temp_xmldoc.child("qbg");
std::string value = myjson["value"].get<std::string>();
// 遍历 type 节点,查找 id 属性等于目标值
for (pugi::xml_node typeNode : root.children("type"))
{
std::string id = typeNode.attribute("id").as_string();
if (id == value)
{
dblH = typeNode.child("h").text().as_double() / 10;
// double b = typeNode.child("b").text().as_double();
// double t1 = typeNode.child("t1").text().as_double();
dblA = typeNode.child("A1").text().as_double();
dblI = typeNode.child("Ix1").text().as_double();
dblY = typeNode.child("y1").text().as_double();
}
}
}
}
break;
case SECTION_EQUAL_ANGLE:
{
QString filePath = PathUtil::bin_dir() + "dbjq.xml";
pugi::xml_document temp_xmldoc;
pugi::xml_parse_result result = temp_xmldoc.load_file(filePath.toStdWString().c_str());
if (!result)
{
qDebug() << "XML解析错误" << result.description()
<< "\n错误位置:" << result.offset
<< "\n错误信息:" << result.description();
return;
}
if (result)
{
const pugi::xml_node &root = temp_xmldoc.child("qbg");
std::string value = myjson["value"].get<std::string>();
// 遍历 type 节点,查找 id 属性等于目标值
for (pugi::xml_node typeNode : root.children("type"))
{
std::string id = typeNode.attribute("id").as_string();
if (id == value)
{
dblH = typeNode.child("h").text().as_double() / 10;
// double b = typeNode.child("b").text().as_double();
// double t1 = typeNode.child("t1").text().as_double();
dblA = typeNode.child("A1").text().as_double();
dblI = typeNode.child("Ix1").text().as_double();
dblY = typeNode.child("y1").text().as_double();
}
}
}
}
break;
case SECTION_T_SHAPE:
{
double mbkd = myjson["mbkd"].get<double>();
double mbhd = myjson["mbhd"].get<double>();
double fbgd = myjson["fbgd"].get<double>();
double fbhd = myjson["fbhd"].get<double>();
dblH = mbhd + fbhd;
double A1 = mbkd * mbhd;
double A2 = fbgd * fbhd;
dblA = A1 + A2;
// 计算两个部分的惯性矩(对各自中心轴)
double I1 = mbkd * std::pow(mbhd, 3) / 12.0;
double I2 = fbhd * std::pow(fbgd, 3) / 12.0;
// 计算中和轴位置(整体重心高度)
dblY = ((fbgd + mbhd / 2.0) * A1 + (fbgd / 2.0) * A2) / (A1 + A2);
// 计算合成惯性矩(平行轴定理)
dblI = I1 + I2 + std::pow(dblY - fbgd / 2.0, 2) * A2 + std::pow(fbgd + mbhd / 2.0 - dblY, 2) * A1;
}
break;
case SECTION_BENT_PLATE:
{
double Mbkd = myjson["mbkd"].get<double>() / 10.0;
double Mbhd = myjson["bchd"].get<double>() / 10.0;
double Fbgd = myjson["fbgd"].get<double>() / 10.0;
double Fbhd = Mbhd;
Fbgd = Fbgd - Mbhd;
if (Mbkd == 0.0)
{
Mbkd = Fbhd;
}
dblH = Mbhd + Fbgd;
double A1 = Mbkd * Mbhd;
double A2 = Fbgd * Fbhd;
dblA = A1 + A2;
double I1 = Mbkd * std::pow(Mbhd, 3) / 12.0;
double I2 = Fbhd * std::pow(Fbgd, 3) / 12.0;
dblY = ((Fbgd + Mbhd / 2.0) * A1 + (Fbgd / 2.0) * A2) / (A1 + A2);
dblI = I1 + I2 + std::pow(dblY - Fbgd / 2.0, 2) * A2 + std::pow(Fbgd + Mbhd / 2.0 - dblY, 2) * A1;
}
break;
case SECTION_FLAT_BAR:
{
double Fbgd = myjson["fbgd"] / 10.0;
double Fbhd = myjson["bchd"] / 10.0;
dblH = Fbgd;
double A2 = Fbgd * Fbhd;
dblA = A2;
double I2 = Fbhd * std::pow(Fbgd, 3) / 12.0;
dblY = Fbgd / 2.0;
dblI = I2 + std::pow(dblY - Fbgd / 2.0, 2) * A2;
}
break;
case SECTION_OTHER:
{
return;
}
break;
}
double Dbkd = myjson["Dbkd"].get<double>();
double Dbhd = myjson["Dbhd"].get<double>();
double dblDbkd = Dbkd / 10;
double dblDbhd = Dbhd / 10;
double dblII = 0; // 惯性距
double dblWW = 0; // 剖面模数
double GCAndPmj = 0; // 骨材连同带板剖面积
double dblYY = 0;
GCAndPmj = Gjpmms(dblH, dblA, dblY, dblI, dblDbkd, dblDbhd, dblII, dblWW, dblYY);
dblII = std::round(dblII * 1000.0) / 1000.0;
dblWW = std::round(dblWW * 1000.0) / 1000.0;
dblYY = std::round(dblYY * 10.0 * 100.0) / 100.0; // 即保留两位小数
json obj = {
{"I", dblII},
{"W", dblWW},
{"YY", dblYY},
{"GCAndPmj", GCAndPmj},
{"Pmj", dblDbkd * dblDbhd},
{"gxbj", std::sqrt(dblII / GCAndPmj)}};
errorCode = 0;
data = QString::fromStdString(obj.dump());
return;
}
void DataManager::calculate_strut(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
nlohmann::json myjson;
try
{
myjson = nlohmann::json::parse(message.toStdString());
}
catch (const nlohmann::json::parse_error &e)
{
outMsg = e.what();
errorCode = 1;
return;
}
int type = myjson["type"].get<int>();
json resultjson;
switch (type)
{
case STRUT_PIPE:
{
double diameter = myjson["diameter"].get<double>(); //直径
double thickness = myjson["thickness"].get<double>(); //厚度
double length = myjson["length"].get<double>();
QString filePath = PathUtil::bin_dir() + "Zz.xml";
pugi::xml_document docZz;
pugi::xml_parse_result result = docZz.load_file(filePath.toStdWString().c_str());
if (!result)
{
outMsg = "XML parse failed: " + QString::fromStdString(result.description());
errorCode = 1;
return;
}
const pugi::xml_node &root = docZz.child("支柱").child("管型");
double load = 0.0;
bool foundDiameter = false;
bool foundThickness = false;
bool foundLength = false;
std::vector<double> lengths;
std::vector<double> loads;
for (pugi::xml_node diameterNode : root.children("型号"))
{
if (diameter == diameterNode.attribute("直径").as_double())
{
foundDiameter = true;
for (pugi::xml_node thicknessNode : diameterNode.children("型号"))
{
if (thickness == thicknessNode.attribute("厚度").as_double())
{
foundThickness = true;
for (pugi::xml_node lenNode : thicknessNode.children("型号"))
{
double len = lenNode.attribute("长度").as_double();
double tempLoad = lenNode.attribute("许用负荷").as_double();
if( len == length)
{
foundLength = true;
// 获取许用负荷
load = tempLoad;
}
lengths.push_back(len);
loads.push_back(tempLoad);
}
break; // 找到厚度后跳出
}
}
break; // 找到直径后跳出
}
}
if(foundLength)
{
resultjson = {
{"P", load}
};
errorCode = 0;
data = QString::fromStdString(resultjson.dump());
return;
}
else
{
//插值计算
double L = length;
int i1 = 0;
if( length > lengths[lengths.size() - 1])
{
errorCode = 1;
outMsg = "长度超过最大值";
return;
}
else if(length < lengths[0])
{
i1 = 0;
}
else
{
for(int i = 0; i < lengths.size(); i++)
{
if(length < lengths[i])
{
i1 = i - 1;
break;
}
}
}
double L1 = lengths[i1];
double L2 = lengths[i1 + 1];
double P1 = loads[i1];
double P2 = loads[i1 + 1];
double P = (L - L1) * (P2 - P1) / (L2 - L1) + P1;
resultjson = {
{"P", P}
};
errorCode = 0;
data = QString::fromStdString(resultjson.dump());
return;
}
}
break;
case STRUT_CROSS:
{
std::string id = myjson["id"].get<std::string>();
double length = myjson["length"].get<double>();
QString filePath = PathUtil::bin_dir() + "Zz.xml";
pugi::xml_document docZz;
pugi::xml_parse_result result = docZz.load_file(filePath.toStdWString().c_str());
if (!result)
{
outMsg = "XML parse failed: " + QString::fromStdString(result.description());
errorCode = 1;
return;
}
const pugi::xml_node &root = docZz.child("支柱").child("十字");
double load = 0.0;
bool foundId = false;
bool foundLength = false;
std::vector<double> lengths;
std::vector<double> loads;
for (pugi::xml_node modelNode : root.children("型号"))
{
// 第一层型号(有“编号”属性)
const char *idAttr = modelNode.attribute("编号").value();
if (idAttr && id == idAttr)
{
foundId = true;
for (pugi::xml_node lenNode : modelNode.children("型号"))
{
if (!lenNode.attribute("长度") || !lenNode.attribute("许用负荷"))
continue;
double len = lenNode.attribute("长度").as_double();
double tempLoad = lenNode.attribute("许用负荷").as_double();
lengths.push_back(len);
loads.push_back(tempLoad);
if (std::abs(len - length) < 1e-6)
{
foundLength = true;
load = tempLoad;
}
}
break; // 找到对应编号后就退出
}
}
if(foundLength)
{
resultjson = {
{"P", load}
};
errorCode = 0;
data = QString::fromStdString(resultjson.dump());
return;
}
else
{
//插值计算
double L = length;
int i1 = 0;
if( length > lengths[lengths.size() - 1])
{
errorCode = 1;
outMsg = "长度超过最大值";
return;
}
else if(length < lengths[0])
{
i1 = 0;
}
else
{
for(int i = 0; i < lengths.size(); i++)
{
if(length < lengths[i])
{
i1 = i - 1;
break;
}
}
}
double L1 = lengths[i1];
double L2 = lengths[i1 + 1];
double P1 = loads[i1];
double P2 = loads[i1 + 1];
double P = (L - L1) * (P2 - P1) / (L2 - L1) + P1;
resultjson = {
{"P", P}
};
errorCode = 0;
data = QString::fromStdString(resultjson.dump());
return;
}
}
break;
}
}
void DataManager::calculate_diagonal(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
nlohmann::json myjson;
try
{
myjson = nlohmann::json::parse(message.toStdString());
}
catch (const nlohmann::json::parse_error &e)
{
outMsg = e.what();
errorCode = 1;
return;
}
int type = myjson["type"].get<int>();
json resultjson;
switch (type)
{
case DIAGONAL_SINGLE_ANGLE:
{
bool both_direction = myjson["both"].get<bool>();
double xgcd = myjson["xgcd"].get<double>();
if(xgcd ==0)
{
return;
}
if(both_direction)
{
xgcd = xgcd * 0.6;
}
//根据 先取换算长度的list
QString filePath = PathUtil::bin_dir() + "Xg.xml";
pugi::xml_document temp_xmldoc;
pugi::xml_parse_result result = temp_xmldoc.load_file(filePath.toStdWString().c_str());
if (!result)
{
qDebug() << "XML解析错误" << result.description()
<< "\n错误位置:" << result.offset
<< "\n错误信息:" << result.description();
return;
}
if (result)
{
const pugi::xml_node &root = temp_xmldoc.child("斜杆").child("单角钢");
std::string djgxh = myjson["djgxh"].get<std::string>(); // 例如:"5.0×3"
std::vector<std::pair<double, double>> lengthLoadList; // <换算长度, 许用负荷>
for (pugi::xml_node model = root.child("型号"); model; model = model.next_sibling("型号"))
{
if (djgxh == model.attribute("编号").value())
{
for (pugi::xml_node sub = model.child("型号"); sub; sub = sub.next_sibling("型号"))
{
const char *lengthStr = sub.attribute("换算长度").value();
if (lengthStr && *lengthStr)
{
double length = std::stod(sub.attribute("换算长度").value());
double load = std::stod(sub.attribute("许用负荷").value());
lengthLoadList.emplace_back(length, load);
}
}
break; // 找到该型号后退出
}
}
//根据斜杆长度 再取换算长度
double P = 0.0;
bool flag = false;
int cdIndex = 0;
int count = static_cast<int>(lengthLoadList.size());
if (xgcd <= lengthLoadList[0].first)
{
cdIndex = 0;
flag = true;
}
else if (xgcd >= lengthLoadList[count - 1].first)
{
cdIndex = count - 1;
flag = true;
}
else
{
for (int i = 1; i < count; ++i)
{
if (xgcd < lengthLoadList[i].first)
{
cdIndex = i - 1;
break;
}
}
}
//取许用负荷
double L1 = lengthLoadList[cdIndex].first;
double p1 = lengthLoadList[cdIndex].second;
if (flag)
{
P = p1;
}
else
{
double L2 = lengthLoadList[cdIndex + 1].first;
double p2 = lengthLoadList[cdIndex + 1].second;
P = ((xgcd - L1) * (p2 - p1)) / (L2 - L1) + p1; // 插值计算
}
resultjson = {
{"P", P}
};
}
}
break;
case DIAGONAL_DOUBLE_ANGLE:
{
bool both_direction = myjson["both"].get<bool>();
double xgcd = myjson["xgcd"].get<double>();
if(xgcd ==0)
{
return;
}
if(both_direction)
{
xgcd = xgcd * 0.6;
}
//根据 先取换算长度的list
QString filePath = PathUtil::bin_dir() + "Xg.xml";
pugi::xml_document temp_xmldoc;
pugi::xml_parse_result result = temp_xmldoc.load_file(filePath.toStdWString().c_str());
if (!result)
{
qDebug() << "XML解析错误" << result.description()
<< "\n错误位置:" << result.offset
<< "\n错误信息:" << result.description();
return;
}
if (result)
{
const pugi::xml_node &root = temp_xmldoc.child("斜杆").child("双角钢");
std::string djgxh = myjson["djgxh"].get<std::string>(); // 例如:"5.0×3"
std::vector<std::pair<double, double>> lengthLoadList; // <换算长度, 许用负荷>
for (pugi::xml_node model = root.child("型号"); model; model = model.next_sibling("型号"))
{
if (djgxh == model.attribute("编号").value())
{
for (pugi::xml_node sub = model.child("型号"); sub; sub = sub.next_sibling("型号"))
{
const char *lengthStr = sub.attribute("换算长度").value();
if (lengthStr && *lengthStr)
{
double length = std::stod(sub.attribute("换算长度").value());
double load = std::stod(sub.attribute("许用负荷").value());
lengthLoadList.emplace_back(length, load);
}
}
break; // 找到该型号后退出
}
}
//根据斜杆长度 再取换算长度
double P = 0.0;
bool flag = false;
int cdIndex = 0;
int count = static_cast<int>(lengthLoadList.size());
if (xgcd <= lengthLoadList[0].first)
{
cdIndex = 0;
flag = true;
}
else if (xgcd >= lengthLoadList[count - 1].first)
{
cdIndex = count - 1;
flag = true;
}
else
{
for (int i = 1; i < count; ++i)
{
if (xgcd < lengthLoadList[i].first)
{
cdIndex = i - 1;
break;
}
}
}
//取许用负荷
double L1 = lengthLoadList[cdIndex].first;
double p1 = lengthLoadList[cdIndex].second;
if (flag)
{
P = p1;
}
else
{
double L2 = lengthLoadList[cdIndex + 1].first;
double p2 = lengthLoadList[cdIndex + 1].second;
P = ((xgcd - L1) * (p2 - p1)) / (L2 - L1) + p1; // 插值计算
}
resultjson = {
{"P", P}
};
}
}
break;
}
data = QString::fromStdString(resultjson.dump());
errorCode = 0;
}
// 计算构件连带板的截面特性
// 原计算结果的原点默认为腹板末端中和轴垂向坐标yy可能出现负值不合理
// 现修正为:当带板存在时,原点变为带板中心(与腹板末端相差 t/2
// 不存在带板时dbkd*dbhd=0仍然为腹板末端
double DataManager::Gjpmms(double h, double A, double Y, double I, double dbkd, double dbhd,
double& ii, double& ww, double& yy)
{
double dblArea = 0;
double dblY = 0;
double dbldbA = 0;
// dbkd /= 10; //20220517 by czb单位已经一致了不需要再转换
// dbhd /= 10;
dbldbA = dbhd * dbkd;
dblArea = A + dbldbA;
if (dbldbA == 0)
{
dblY = Y;
ii = I;
ww = std::min(ii / std::abs(h - dblY), ii / std::abs(dblY));
yy = dblY;
}
else
{
dblY = (A * Y - dbldbA * dbhd / 2.0) / dblArea;
ii = I + dbkd * std::pow(dbhd, 3) / 12.0
+ A * std::pow(Y - dblY, 2)
+ dbldbA * std::pow(dblY + dbhd / 2.0, 2);
double ww1 = ii / std::abs(h - dblY);
double ww2 = ii / std::abs(dblY + dbhd / 2.0);
ww = std::min(ww1, ww2);
yy = dblY + dbhd / 2.0; // 中和轴原点修正
}
return dblArea;
}
void DataManager::calculate_strut_open(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
nlohmann::json resultJson;
pugi::xml_document doc;
QString filePath = PathUtil::bin_dir() + "Zz.xml";
pugi::xml_parse_result loadResult = doc.load_file(filePath.toStdWString().c_str());
if (!loadResult)
{
qDebug() << "XML parse failed:" << loadResult.description();
errorCode = 1;
outMsg = "XML parse failed: " + QString::fromStdString(loadResult.description());
return ;
}
pugi::xml_node zhizhuNode = doc.child("支柱");
// Parse 管型 (pipe)
nlohmann::json pipeArray = nlohmann::json::array();
pugi::xml_node pipeNode = zhizhuNode.child("管型");
for (pugi::xml_node diameterNode : pipeNode.children("型号"))
{
double diameter = diameterNode.attribute("直径").as_double();
nlohmann::json thicknessList = nlohmann::json::array();
for (pugi::xml_node thickNode : diameterNode.children("型号"))
{
double thickness = thickNode.attribute("厚度").as_double();
nlohmann::json lengthList = nlohmann::json::array();
for (pugi::xml_node lenNode : thickNode.children("型号"))
{
double length = lenNode.attribute("长度").as_double();
lengthList.push_back(length);
}
nlohmann::json thickObj;
thickObj["thickness"] = thickness;
thickObj["length"] = lengthList;
thicknessList.push_back(thickObj);
}
nlohmann::json pipeObj;
pipeObj["diameter"] = diameter;
pipeObj["thicknessList"] = thicknessList;
pipeArray.push_back(pipeObj);
}
// Parse 十字 (cross)
nlohmann::json crossArray = nlohmann::json::array();
pugi::xml_node crossNode = zhizhuNode.child("十字");
for (pugi::xml_node typeNode : crossNode.children("型号"))
{
std::string id = typeNode.attribute("编号").as_string();
nlohmann::json lengthList = nlohmann::json::array();
for (pugi::xml_node lenNode : typeNode.children("型号"))
{
double length = lenNode.attribute("长度").as_double();
lengthList.push_back(length);
}
nlohmann::json crossObj;
crossObj["id"] = id;
crossObj["length"] = lengthList;
crossArray.push_back(crossObj);
}
resultJson["pipe"] = pipeArray;
resultJson["cross"] = crossArray;
data = QString::fromStdString(resultJson.dump());
errorCode = 0;
}
void DataManager::calculate_section_open(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
json result;
QString dir = PathUtil::bin_dir();
result["qbg"] = extract_ids_from_file(dir + "qbg.xml", "qbg");
result["jg"] = extract_ids_from_file(dir + "jg.xml", "jg");
result["dbjg"] = extract_ids_from_file(dir + "dbjg.xml", "dbjg");
data = QString::fromStdString(result.dump());
errorCode = 0;
return;
}
std::vector<std::string> DataManager::extract_ids_from_file(const QString& filePath, const std::string& rootName)
{
std::vector<std::string> ids;
pugi::xml_document doc;
if (!doc.load_file(filePath.toStdWString().c_str()))
{
qDebug() << "无法解析 XML 文件:" << filePath;
return ids;
}
pugi::xml_node root = doc.child(rootName.c_str());
for (pugi::xml_node node : root.children("type"))
{
std::string id = node.attribute("id").value();
if (!id.empty())
ids.push_back(id);
}
return ids;
}
void DataManager::calculate_diagonal_open(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
json result;
pugi::xml_document doc;
QString filePath = PathUtil::bin_dir() + "Xg.xml";
if (!doc.load_file(filePath.toStdWString().c_str()))
{
qDebug() << "无法加载 XML 文件:" << filePath;
errorCode = 1;
outMsg = "无法加载 XML 文件:" + filePath;
return;
}
pugi::xml_node root = doc.child("斜杆");
if (!root)
{
qDebug() << "未找到根节点 <斜杆>";
errorCode = 1;
outMsg = "未找到根节点 <斜杆>";
return;
}
// 处理“双角钢”
std::vector<std::string> sjgList;
pugi::xml_node sjgNode = root.child("双角钢");
if (sjgNode)
{
for (pugi::xml_node node : sjgNode.children("型号"))
{
const char* id = node.attribute("编号").value();
if (id && strlen(id) > 0)
{
sjgList.emplace_back(id);
}
}
result["sjg"] = sjgList;
}
// 处理“单角钢”
std::vector<std::string> djgList;
pugi::xml_node djgNode = root.child("单角钢");
if (djgNode)
{
for (pugi::xml_node node : djgNode.children("型号"))
{
const char* id = node.attribute("编号").value();
if (id && strlen(id) > 0)
{
djgList.emplace_back(id);
}
}
result["djg"] = djgList;
}
data = QString::fromStdString(result.dump());
errorCode = 0;
}

View File

@ -34,14 +34,14 @@ std::vector<std::string>& StabCalculationData::getAnalyseNameList()
return m_childModuleNames;
}
int StabCalculationData::toXml(pugi::xml_node node,QString outFilePath)
int StabCalculationData::toXml(pugi::xml_node node)
{
m_CalcBaseData.toXml();
XmlSerialization* xmlPtr = XmlSerialization::getXmlSerializationInstance();
std::string strValue = xmlPtr->saveSerializationXMLFile(outFilePath);
std::string strValue = xmlPtr->saveSerializationXMLString();
addOrUpdateDataRow("Stab", QString::fromStdString(strValue));
m_StabilityCal.toXml(node, m_DataRows, m_childModules);
m_StabilityCal.toXml(node, m_DataRows, m_childModules, m_childModuleNames);
return 0;
}

View File

@ -9,19 +9,8 @@
extern "C"
{
#endif
std::string XmlSerialization::saveSerializationXMLFile(QString xmlfile_path)
void XmlSerialization::saveSerializationXMLFile(QString xmlfile_path)
{
// std::ofstream ofs(xmlfile_path);
// ::xml_schema::namespace_infomap ns_map;
// ns_map[""].name = "http://tempuri.org/ModelDS.xsd";
// // 使用全局命名空间下的 flags
// model_ds::ModelDS_(ofs, m_ModelDS, ns_map, "UTF-8", ::xml_schema::flags::keep_dom); // format_pretty);
// xercesc::XMLPlatformUtils::Terminate();
xercesc::XMLPlatformUtils::Initialize();
@ -48,12 +37,23 @@ extern "C"
// 关闭文件
file.close();
xercesc::XMLPlatformUtils::Terminate();
}
std::string XmlSerialization::saveSerializationXMLString()
{
xercesc::XMLPlatformUtils::Initialize();
std::ostringstream ofs;
::xml_schema::namespace_infomap ns_map;
ns_map[""].name = "http://tempuri.org/ModelDS.xsd";
// 使用全局命名空间下的 flags
model_ds::ModelDS_(ofs, *m_ModelDS, ns_map, "UTF-8", ::xml_schema::flags::no_xml_declaration); // format_pretty);
xercesc::XMLPlatformUtils::Terminate();
return ofs.str();
}

View File

@ -119,6 +119,36 @@ extern "C"
m_pDataManager->structure_cprt_editor(outjson);
}
void StructureModel::calculate_section(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
m_pDataManager->calculate_section(errorCode, outMsg, data, message);
}
void StructureModel::calculate_strut(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
m_pDataManager->calculate_strut(errorCode, outMsg, data, message);
}
void StructureModel::calculate_diagonal(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
m_pDataManager->calculate_diagonal(errorCode, outMsg, data, message);
}
void StructureModel::calculate_strut_open(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
m_pDataManager->calculate_strut_open(errorCode, outMsg, data, message);
}
void StructureModel::calculate_section_open(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
m_pDataManager->calculate_section_open(errorCode, outMsg, data, message);
}
void StructureModel::calculate_diagonal_open(int &errorCode, QString &outMsg, QString &data, const QString &message)
{
m_pDataManager->calculate_diagonal_open(errorCode, outMsg, data, message);
}
#ifdef __cplusplus
}
#endif