mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
353 lines
11 KiB
C++
353 lines
11 KiB
C++
#include <QString>
|
||
#include "docsupdater.h"
|
||
#include "tools.h"
|
||
|
||
|
||
DocsUpdater::DocsUpdater(UpdateController* updateController, QObject *parent):
|
||
QObject(parent),
|
||
updateController(updateController),
|
||
flagStop(false)
|
||
{
|
||
|
||
}
|
||
|
||
DocsUpdater::~DocsUpdater()
|
||
{
|
||
|
||
}
|
||
|
||
void DocsUpdater::lockAccessToDocs()
|
||
{
|
||
mtxAccess.lock();
|
||
}
|
||
|
||
void DocsUpdater::unLockAccessToDocs()
|
||
{
|
||
mtxAccess.unlock();
|
||
}
|
||
|
||
bool DocsUpdater::slot_update()
|
||
{
|
||
QMutexLocker locker(&mtxAccess);
|
||
|
||
QString nameDocsFile = tasksAMMfileName;
|
||
QString pathDocsFile = updateController->getPathAdditionalFile(nameDocsFile);
|
||
|
||
QDomDocument docTasksDOM;
|
||
if(! Tools::loadXMLtoDOM(pathDocsFile, &docTasksDOM))
|
||
return false;
|
||
|
||
QDomElement manifestElement = docTasksDOM.firstChildElement("manifest");
|
||
if(manifestElement.isNull())
|
||
return false;
|
||
|
||
deleteAllModulsAMM();
|
||
listTasksAMM.clear();
|
||
subProcMap.clear();
|
||
|
||
domElementParserAMM(manifestElement, nullptr);
|
||
|
||
if(! Tools::saveDOMtoXML(pathDocsFile, &docTasksDOM))
|
||
return false;
|
||
|
||
//emit signal_DocsChanged();
|
||
return true;
|
||
}
|
||
|
||
void DocsUpdater::domElementParserAMM(QDomElement element, Module* moduleParent)
|
||
{
|
||
QString name;
|
||
|
||
if(flagStop)
|
||
return;
|
||
|
||
QDomElement childElement = element.firstChildElement();
|
||
if(childElement.isNull())
|
||
return;
|
||
|
||
Module* module = nullptr;
|
||
|
||
do
|
||
{
|
||
name = childElement.nodeName();
|
||
|
||
QDomNamedNodeMap nodeMap = childElement.attributes();
|
||
|
||
if(name == "doc")
|
||
{
|
||
module = new PM();
|
||
}
|
||
else if(name == "pm")
|
||
{
|
||
module = new PM();
|
||
PM* PMmodul = static_cast<PM*>(module);
|
||
|
||
PMmodul->initialize(nodeMap.namedItem("modelIdentCode").nodeValue(),
|
||
nodeMap.namedItem("pmIssuer").nodeValue(),
|
||
nodeMap.namedItem("pmNumber").nodeValue(),
|
||
nodeMap.namedItem("pmVolume").nodeValue());
|
||
|
||
if(moduleParent)
|
||
{
|
||
PMmodul->setParentModule(moduleParent);
|
||
|
||
PM* PMmodulParent = static_cast<PM*>(moduleParent);
|
||
PMmodulParent->addChildModule(module);
|
||
}
|
||
}
|
||
else if(name == "dm")
|
||
{
|
||
module = new DM();
|
||
DM* DMmodul = static_cast<DM*>(module);
|
||
|
||
DMmodul->initialize(nodeMap.namedItem("modelIdentCode").nodeValue(),
|
||
nodeMap.namedItem("systemDiffCode").nodeValue(),
|
||
nodeMap.namedItem("systemCode").nodeValue(),
|
||
nodeMap.namedItem("subSystemCode").nodeValue(),
|
||
nodeMap.namedItem("subSubSystemCode").nodeValue(),
|
||
nodeMap.namedItem("assyCode").nodeValue(),
|
||
nodeMap.namedItem("disassyCode").nodeValue(),
|
||
nodeMap.namedItem("disassyCodeVariant").nodeValue(),
|
||
nodeMap.namedItem("infoCode").nodeValue(),
|
||
nodeMap.namedItem("infoCodeVariant").nodeValue(),
|
||
nodeMap.namedItem("itemLocationCode").nodeValue());
|
||
|
||
if(moduleParent)
|
||
{
|
||
DMmodul->setParentModule(moduleParent);
|
||
|
||
PM* PMmodulParent = static_cast<PM*>(moduleParent);
|
||
PMmodulParent->addChildModule(module);
|
||
}
|
||
}
|
||
else if(name == "rus" || name == "eng")
|
||
{
|
||
if(moduleParent)
|
||
{
|
||
if(moduleParent->getType() == ModuleType::TYPE_PM)
|
||
{//PM
|
||
PM* PMmodulParent = static_cast<PM*>(moduleParent);
|
||
|
||
if(name == "rus")
|
||
PMmodulParent->setLangStructRus(nodeMap.namedItem("title").nodeValue());
|
||
else
|
||
PMmodulParent->setLangStructEng(nodeMap.namedItem("title").nodeValue());
|
||
}
|
||
else
|
||
{//DM
|
||
DM* DMmodulParent = static_cast<DM*>(moduleParent);
|
||
|
||
if(name == "rus")
|
||
{
|
||
DMmodulParent->setLangStructRus(nodeMap.namedItem("techName").nodeValue(),
|
||
nodeMap.namedItem("infoName").nodeValue(),
|
||
nodeMap.namedItem("pdf").nodeValue(),
|
||
nodeMap.namedItem("bookmark").nodeValue(),
|
||
nodeMap.namedItem("xml").nodeValue());
|
||
|
||
//Активность
|
||
//QString canplay = nodeMap.namedItem("canplay").nodeValue();
|
||
|
||
|
||
//Обновление Активности и построение списка подпроцедур 1го уровня
|
||
/*
|
||
QString dmCode = DMmodulParent->dmCode();
|
||
|
||
QString canplay = defineCanplayByScenXML(dmCode);
|
||
|
||
DMmodulParent->setModeList(parseCanplay(canplay));
|
||
nodeMap.namedItem("canplay").setNodeValue(canplay);
|
||
*/
|
||
|
||
QString dmCode = DMmodulParent->dmCode();
|
||
QString canplay = "";
|
||
QList<SubProc> listSubProc;
|
||
if(processingScenXML(dmCode, canplay, listSubProc))
|
||
{
|
||
DMmodulParent->setModeList(parseCanplay(canplay));
|
||
nodeMap.namedItem("canplay").setNodeValue(canplay);
|
||
|
||
subProcMap.insert(dmCode, listSubProc);
|
||
}
|
||
else
|
||
{
|
||
DMmodulParent->setModeList(parseCanplay(canplay));
|
||
nodeMap.namedItem("canplay").setNodeValue(canplay);
|
||
}
|
||
}
|
||
else
|
||
DMmodulParent->setLangStructEng(nodeMap.namedItem("techName").nodeValue(),
|
||
nodeMap.namedItem("infoName").nodeValue(),
|
||
nodeMap.namedItem("pdf").nodeValue(),
|
||
nodeMap.namedItem("bookmark").nodeValue(),
|
||
nodeMap.namedItem("xml").nodeValue());
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
domElementParserAMM(childElement, module);
|
||
|
||
if(moduleParent == nullptr)
|
||
listAllModulesAMM.append(module);
|
||
|
||
if(module)
|
||
if(module->getType() == ModuleType::TYPE_DM)
|
||
{
|
||
TaskAmmFim* task = nullptr;
|
||
task = new TaskAmmFim();
|
||
task->setID(module->getID());
|
||
task->ammProcedure.title = static_cast<DM*>(module)->getLangStructRus().techName;
|
||
task->ammProcedure.dmCode = static_cast<DM*>(module)->dmCode();
|
||
|
||
listTasksAMM.append(*task);
|
||
delete task;
|
||
}
|
||
|
||
}while (! (childElement = childElement.nextSiblingElement()).isNull());
|
||
}
|
||
|
||
void DocsUpdater::deleteAllModulsAMM()
|
||
{
|
||
for(Module* module: listAllModulesAMM)
|
||
{
|
||
if(module->getType() == ModuleType::TYPE_PM)
|
||
delete static_cast<PM*>(module);
|
||
else
|
||
delete static_cast<DM*>(module);
|
||
}
|
||
listAllModulesAMM.clear();
|
||
}
|
||
|
||
ModeList DocsUpdater::parseCanplay(QString canplay)
|
||
{
|
||
ModeList modeList;
|
||
|
||
if(canplay == "")
|
||
{
|
||
modeList.demo = false;
|
||
modeList.train = false;
|
||
modeList.exam = false;
|
||
modeList.autoM = false;
|
||
}
|
||
else
|
||
{
|
||
QStringList list = canplay.split("/");
|
||
|
||
if(list.at(0) == "+")
|
||
modeList.demo = true;
|
||
else
|
||
modeList.demo = false;
|
||
|
||
if(list.at(1) == "+")
|
||
modeList.train = true;
|
||
else
|
||
modeList.train = false;
|
||
|
||
if(list.at(2) == "+")
|
||
modeList.exam = true;
|
||
else
|
||
modeList.exam = false;
|
||
|
||
if(list.at(3) == "+")
|
||
modeList.autoM = true;
|
||
else
|
||
modeList.autoM = false;
|
||
}
|
||
|
||
return modeList;
|
||
}
|
||
|
||
bool DocsUpdater::processingScenXML(const QString dmCode, QString &canplay, QList<SubProc> &listSubProc)
|
||
{
|
||
listSubProc.clear();
|
||
|
||
canplay = "";
|
||
QString signDemo = "-";
|
||
QString signTrain = "-";
|
||
QString signExam = "-";
|
||
QString signAuto = "-";
|
||
|
||
QString nameScenXMLFile = "/" + dmCode + ".xml";
|
||
QString pathScenXMLFile = updateController->getPathScensFile(nameScenXMLFile);
|
||
|
||
|
||
QDomDocument docScenDOM;
|
||
if(! Tools::loadXMLtoDOM(pathScenXMLFile, &docScenDOM))
|
||
return false;
|
||
|
||
QDomElement scenarioElement = docScenDOM.firstChildElement("scenario");
|
||
if(scenarioElement.isNull())
|
||
return false;
|
||
|
||
|
||
QDomElement demoElement = scenarioElement.firstChildElement("demo");
|
||
if(!demoElement.isNull())
|
||
{
|
||
//canplay
|
||
if(demoElement.toElement().attribute("canplay") == "True")
|
||
signDemo = "+";
|
||
|
||
//subProc
|
||
selectSubProc(demoElement, listSubProc);
|
||
}
|
||
|
||
QDomElement trainElement = scenarioElement.firstChildElement("train");
|
||
if(!trainElement.isNull())
|
||
{
|
||
//canplay
|
||
if(trainElement.toElement().attribute("canplay") == "True")
|
||
signTrain = "+";
|
||
|
||
//subProc
|
||
selectSubProc(trainElement, listSubProc);
|
||
}
|
||
|
||
QDomElement examElement = scenarioElement.firstChildElement("exam");
|
||
if(!examElement.isNull())
|
||
{
|
||
//canplay
|
||
if(examElement.toElement().attribute("canplay") == "True")
|
||
signExam = "+";
|
||
|
||
//subProc
|
||
selectSubProc(examElement, listSubProc);
|
||
}
|
||
|
||
QDomElement autoElement = scenarioElement.firstChildElement("auto");
|
||
if(!autoElement.isNull())
|
||
{
|
||
//canplay
|
||
if(autoElement.toElement().attribute("canplay") == "True")
|
||
signAuto = "+";
|
||
|
||
//subProc
|
||
//Из этого режима не берем!
|
||
}
|
||
|
||
canplay = QString("%1/%2/%3/%4").arg(signDemo, signTrain, signExam, signAuto);
|
||
|
||
return true;
|
||
}
|
||
|
||
void DocsUpdater::selectSubProc(QDomElement &modeElement, QList<SubProc> &listSubProc)
|
||
{
|
||
QDomNodeList nodeList = modeElement.elementsByTagName("node");
|
||
for(int i = 0; i < nodeList.count(); i++)
|
||
{
|
||
QDomNode node = nodeList.at(i);
|
||
if(node.toElement().attribute("type") == "Subproc")
|
||
{
|
||
QDomElement subProcElement = node.firstChildElement("subproc");
|
||
if(!subProcElement.isNull())
|
||
{
|
||
SubProc subProc;
|
||
subProc.dmCode = subProcElement.toElement().attribute("dmCode");
|
||
subProc.title = subProcElement.toElement().attribute("title");
|
||
|
||
listSubProc.append(subProc);
|
||
}
|
||
}
|
||
}
|
||
}
|