2025-05-08 15:00:13 +00:00
|
|
|
|
#include "WBFZAlgComponetXmlParaseOperator.h"
|
2025-05-09 07:25:29 +00:00
|
|
|
|
|
|
|
|
|
WBFZAlgComponetXmlParamenterItem::WBFZAlgComponetXmlParamenterItem(QDomElement* itemparameter, QObject* parent) :QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
if (nullptr == itemparameter) {
|
|
|
|
|
qDebug() << "itemparameter is nullptr.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-10 18:34:49 +00:00
|
|
|
|
|
|
|
|
|
this->ParaName = itemparameter->firstChildElement("ParaName").isNull() ? QString() : itemparameter->firstChildElement("ParaName").text();
|
|
|
|
|
this->ParaChsName = itemparameter->firstChildElement("ParaChsName").isNull() ? QString() : itemparameter->firstChildElement("ParaChsName").text();
|
|
|
|
|
this->Description = itemparameter->firstChildElement("Description").isNull() ? QString() : itemparameter->firstChildElement("Description").text();
|
|
|
|
|
this->Datatype = itemparameter->firstChildElement("DataType").isNull() ? QString() : itemparameter->firstChildElement("DataType").text();
|
|
|
|
|
this->ParaType = itemparameter->firstChildElement("ParaType").isNull() ? QString() : itemparameter->firstChildElement("ParaType").text();
|
|
|
|
|
this->ValueStr = itemparameter->firstChildElement("ParaValue").isNull() ? QString() : itemparameter->firstChildElement("ParaValue").text();
|
2025-05-09 07:25:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WBFZAlgComponetXmlParamenterItem::~WBFZAlgComponetXmlParamenterItem()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WBFZAlgComponetXmlParaseOperator::WBFZAlgComponetXmlParaseOperator(QObject* parent) :QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WBFZAlgComponetXmlParaseOperator::~WBFZAlgComponetXmlParaseOperator()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WBFZAlgComponetXmlParaseOperator::loadXmlFile(const QString& fileName)
|
|
|
|
|
{
|
|
|
|
|
this->xmlFilePath = fileName;
|
|
|
|
|
this->parseXmlFile();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-10 19:04:56 +00:00
|
|
|
|
void WBFZAlgComponetXmlParaseOperator::writeXmlFile(const QString& formatfilepath, QString outfilepath, QString workspace, QMap<QString, QString> inputParamslist)
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>xml<6D>ļ<EFBFBD>
|
|
|
|
|
QFile inputFile(formatfilepath);
|
|
|
|
|
if (!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
|
qDebug() << "Failed to open input XML file.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>QDomDocument<6E><74><EFBFBD><EFBFBD>
|
|
|
|
|
QDomDocument doc;
|
|
|
|
|
if (!doc.setContent(&inputFile)) {
|
|
|
|
|
qDebug() << "Failed to parse input XML file.";
|
|
|
|
|
inputFile.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// <20>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
inputFile.close();
|
|
|
|
|
|
|
|
|
|
// <20>Ĺ<DEB8><C4B9><EFBFBD><EFBFBD>ռ<EFBFBD>·<EFBFBD><C2B7>
|
|
|
|
|
QDomElement root = doc.documentElement();
|
|
|
|
|
QDomNodeList workspacePathNodes = root.elementsByTagName("WorkSpace");
|
|
|
|
|
if (workspacePathNodes.count() > 0) {
|
|
|
|
|
QDomElement workspacePathElement = workspacePathNodes.at(0).toElement();
|
|
|
|
|
workspacePathElement.firstChild().setNodeValue(workspace);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
qDebug() << "WorkspacePath not found.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><EFBFBD>Input<75><74>ǩ<EFBFBD>µ<EFBFBD>Param<61><6D>ǩ<EFBFBD>µ<EFBFBD>ParaValue<75><65>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD>
|
|
|
|
|
QDomNodeList InputsNodes = root.elementsByTagName("Inputs");
|
|
|
|
|
if (InputsNodes.count() > 0) {
|
|
|
|
|
QDomElement InputsElement = InputsNodes.at(0).toElement();
|
|
|
|
|
QDomNodeList parameterNodes = InputsElement.elementsByTagName("Parameter");
|
|
|
|
|
for (int i = 0; i < parameterNodes.count(); ++i) {
|
|
|
|
|
QDomElement parameterElement = parameterNodes.at(i).toElement();
|
|
|
|
|
QString paraName = parameterElement.firstChildElement("ParaName").text();
|
|
|
|
|
if (inputParamslist.contains(paraName)) {
|
|
|
|
|
QDomNodeList valueNodes = parameterElement.elementsByTagName("ParaValue");
|
|
|
|
|
if (valueNodes.count() > 0) {
|
|
|
|
|
valueNodes.at(0).firstChild().setNodeValue(inputParamslist.value(paraName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
qDebug() << "Inputs not found.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 7. <20><><EFBFBD><EFBFBD><EFBFBD>ĺ<DEB8><C4BA><EFBFBD>XML<4D>ļ<EFBFBD>
|
|
|
|
|
QFile outputFile(outfilepath);
|
|
|
|
|
if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
|
|
|
qDebug() << "Failed to open output XML file.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// <20><><EFBFBD>ĺ<DEB8><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
QTextStream out(&outputFile);
|
|
|
|
|
out.setCodec("UTF-8");
|
|
|
|
|
doc.save(out, 4); // 4<><34>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
outputFile.close();
|
|
|
|
|
qDebug() << "XML file written successfully.";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-05-09 07:25:29 +00:00
|
|
|
|
void WBFZAlgComponetXmlParaseOperator::parseXmlFile()
|
|
|
|
|
{
|
|
|
|
|
// 1. Load the XML file
|
|
|
|
|
QFile file(xmlFilePath);
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
|
qDebug() << "Failed to open XML file.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 2. Create a QDomDocument object
|
|
|
|
|
QDomDocument doc;
|
|
|
|
|
if (!doc.setContent(&file)) {
|
|
|
|
|
qDebug() << "Failed to parse XML file.";
|
|
|
|
|
file.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 3. Close the file
|
|
|
|
|
file.close();
|
|
|
|
|
// 4. Get the root element
|
|
|
|
|
QDomElement root = doc.documentElement();
|
|
|
|
|
// 5. Get the child elements of the root
|
|
|
|
|
QDomNodeList childNodes = root.childNodes();
|
|
|
|
|
// 6. get the workspace path node
|
2025-05-10 18:34:49 +00:00
|
|
|
|
QDomNodeList workspacePathNodes = root.elementsByTagName("WorkSpace");
|
2025-05-09 07:25:29 +00:00
|
|
|
|
if (workspacePathNodes.count() > 0) {
|
|
|
|
|
QDomElement workspacePathElement = workspacePathNodes.at(0).toElement();
|
|
|
|
|
this->workSpacePath = workspacePathElement.text();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
qDebug() << "WorkspacePath not found.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 7. get Root/AlgCompt/Inputs <20>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>Parameter<65>ӽڵ<D3BD>
|
2025-05-10 18:34:49 +00:00
|
|
|
|
QDomNodeList InputsNodes = root.elementsByTagName("Inputs");
|
|
|
|
|
QDomNodeList parameterNodes = InputsNodes.at(0).toElement().elementsByTagName("Parameter");
|
2025-05-09 07:25:29 +00:00
|
|
|
|
if (parameterNodes.count() > 0) {
|
|
|
|
|
for (int i = 0; i < parameterNodes.count(); ++i) {
|
|
|
|
|
QDomElement parameterElement = parameterNodes.at(i).toElement();
|
|
|
|
|
WBFZAlgComponetXmlParamenterItem* item = new WBFZAlgComponetXmlParamenterItem(¶meterElement,this);
|
|
|
|
|
this->ParameterList.append(item);
|
2025-05-10 18:34:49 +00:00
|
|
|
|
qDebug() << "read Parameter Name:" << item->getParaName();
|
|
|
|
|
if (item->getParaName().isEmpty()) {
|
|
|
|
|
QMessageBox::warning(nullptr, u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>xml<6D>ļ<EFBFBD><C4BC><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>");
|
|
|
|
|
qDebug() << "read Parameter Name Error:" << item->getParaName();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-09 07:25:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
qDebug() << "Parameter not found.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WBFZAlgComponetXmlParaseOperator::displayParsedData()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-10 18:34:49 +00:00
|
|
|
|
QString WBFZAlgComponetXmlParaseOperator::getWorkSpacePath() const
|
|
|
|
|
{
|
|
|
|
|
return this->workSpacePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WBFZAlgComponetXmlParaseOperator::setWorkSpacePath(const QString& path)
|
|
|
|
|
{
|
|
|
|
|
this->workSpacePath = path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<WBFZAlgComponetXmlParamenterItem*> WBFZAlgComponetXmlParaseOperator::getParameterList() const
|
|
|
|
|
{
|
|
|
|
|
return ParameterList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WBFZAlgComponetXmlParaseOperator::setParameterList(const QList<WBFZAlgComponetXmlParamenterItem*>& list)
|
|
|
|
|
{
|
|
|
|
|
this->ParameterList = list;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-09 07:25:29 +00:00
|
|
|
|
QString WBFZAlgComponetXmlParamenterItem::getParaName() const
|
|
|
|
|
{
|
|
|
|
|
return this->ParaName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WBFZAlgComponetXmlParamenterItem::setParaName(const QString& name)
|
|
|
|
|
{
|
|
|
|
|
this->ParaName = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString WBFZAlgComponetXmlParamenterItem::getParaChsName() const
|
|
|
|
|
{
|
|
|
|
|
return this->ParaChsName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WBFZAlgComponetXmlParamenterItem::setParaChsName(const QString& name)
|
|
|
|
|
{
|
|
|
|
|
this->ParaChsName = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString WBFZAlgComponetXmlParamenterItem::getDescription() const
|
|
|
|
|
{
|
2025-05-10 18:34:49 +00:00
|
|
|
|
return this->Description;
|
2025-05-09 07:25:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WBFZAlgComponetXmlParamenterItem::setDescription(const QString& description)
|
|
|
|
|
{
|
|
|
|
|
this->Description = description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString WBFZAlgComponetXmlParamenterItem::getDatatype() const
|
|
|
|
|
{
|
|
|
|
|
return this->Datatype;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WBFZAlgComponetXmlParamenterItem::setDatatype(const QString& datatype)
|
|
|
|
|
{
|
|
|
|
|
this->Datatype = datatype;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString WBFZAlgComponetXmlParamenterItem::getParaType() const
|
|
|
|
|
{
|
|
|
|
|
return this->ParaType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WBFZAlgComponetXmlParamenterItem::setParaType(const QString& type)
|
|
|
|
|
{
|
|
|
|
|
this->ParaType = type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString WBFZAlgComponetXmlParamenterItem::getValueStr() const
|
|
|
|
|
{
|
|
|
|
|
return this->ValueStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WBFZAlgComponetXmlParamenterItem::setValueStr(const QString& value)
|
|
|
|
|
{
|
|
|
|
|
this->ValueStr = value;
|
|
|
|
|
}
|