Files
MI-38/s1000d/Converter14/console.cpp
2022-07-04 13:15:35 +03:00

232 lines
11 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "console.h"
#include "s1000d_manager.h"
#include <iostream>
#include <QDebug>
#include <QDir>
using namespace std;
// -SCORM -p "FULL, 2p" E:\C++\Test\01\auk-01_mi-38.lyx E:\C++\Test\01
// -SCORM -p "FULL" E:\C++\Test\AUK-01\01_mi-38.lyx E:\C++\Test\AUK-01
// -SCORM E:\C++\Test\AUK02_Mi38\auk-02_mi-38.lyx E:\C++\Test\AUK02_Mi38
console::console()
{
}
int console::exec(int argc, char *argv[])
{
//Q_UNUSED(argc)
if(QString(argv[1]) == "-?" || QString(argv[1]) == "-h" || QString(argv[1]) == "/h" || argc < 3)
{ printHelp(); return 0; }
exportSCORM = exportS1000D = false;
for(int i = 1; i < argc-2; i++)
{
if(QString(argv[i]).toUpper() == "-SCORM") exportSCORM = true;
if(QString(argv[i]).toUpper() == "-S1000D") exportS1000D = true;
if(QString(argv[i]).toLower() == "-p" && (i+1<argc-2))
{
QStringList l = QString(argv[i+1]).replace(" ", "").replace("\"","").split(",");
packageNames.append(l);
i++;
}
}
if(!exportSCORM && !exportS1000D) {exportSCORM = exportS1000D = true;}
lyxFile = QString(argv[argc-2]); dstPath = QString(argv[argc-1]);
QFileInfo lyxFileInfo(lyxFile); QDir dstdir(dstPath);
qDebug() << "Конвертация " << lyxFileInfo.fileName() << ":";
if(!lyxFileInfo.exists()) {
qDebug() << " Файл LyX не найден: " << lyxFile;
qDebug() << " Запустите конвертер с параметром -h для описания.";
return 1;
}
if(!dstdir.exists()) {
qDebug() << " Папка назначения не найдена: " << dstPath;
qDebug() << " Запустите конвертер с параметром -h для описания.";
return 1;
}
QString pckFileName = lyxFile;
pckFileName.replace(".lyx", ".xml");
if(!QFileInfo::exists(pckFileName)) {
qDebug() << " Файл пакетов в папке АУК не найден: " << pckFileName;
qDebug() << " Запустите конвертер в оконном режиме и создайте конфигурацию пакетов экспорта.";
return 1;
}
SM.isConsole = true;
SM.rootLyXfile = lyxFile;
SM.LoadPackagesXML();
QStringList configPackageNames;
foreach(S1000D_Manager::PackageStruct pack, SM.packages)
configPackageNames.append(pack.cfgName);
if(packageNames.count() == 0)
packageNames = configPackageNames;
else {
foreach(QString n, packageNames)
if(!configPackageNames.contains(n)) {
qDebug() << " Пакет " << n << " не сконфигурирован.";
qDebug() << " Запустите конвертер в оконном режиме и создайте конфигурацию пакетов экспорта.";
return 1;
}
}
printf(" LyX -> HTML (%d sec) .. ", SM.timeConvert); std::cout << std::flush;
QElapsedTimer timer; timer.start();
if(!lyx.Import(&SM, lyxFile, NULL)) {
printf("ОШИБКА импорта LyX.\n");
return 1;
}
SM.LoadPackagesXML();
if(!isCodingFilled()) {
printf("Ошибка: кодирование S1000D не заполнено.\n");
return 1;
}
html.Generate(&SM, false, NULL);
SM.LoadPackagesXML();
SM.timeConvert = (int)timer.elapsed()/1000;
SM.SaveProject();
printf("Ok\n");
if(exportSCORM) {
printf(" SCORM (%d sec):\n", SM.timeSCORM*packageNames.count());
if(packageNames.count() == 0)
printf("Пакеты не заданы. Пропущено.\n");
else
foreach(S1000D_Manager::PackageStruct pack, SM.packages)
if(packageNames.contains(pack.cfgName))
{
for(int i=0;i<SM.items.count();i++)
SM.items[i].toExport = SM.items[i].inPackages.contains(pack.cfgName);
QString s = " \""+pack.cfgName+"\" -> "+pack.exportFileName+"_SCORM"+".zip .. " ;
printf("%s", s.toLocal8Bit().toStdString().c_str()); std::cout << std::flush;
QApplication::processEvents();
bool res = SM.exportSCORM(dstPath, pack.exportFileName, pack.title, NULL);
if(res)
printf("Ok\n");
else
printf("ОШИБКА экспорта\n");
}
}
if(exportS1000D) {
printf(" S1000D (%d sec):\n", SM.timeS1000D*packageNames.count()) ;
if(packageNames.count() == 0)
printf("Пакеты не заданы. Пропущено.\n");
else
foreach(S1000D_Manager::PackageStruct pack, SM.packages)
if(packageNames.contains(pack.cfgName))
{
for(int i=0;i<SM.items.count();i++)
SM.items[i].toExport = SM.items[i].inPackages.contains(pack.cfgName);
QString s = " \""+pack.cfgName+"\" -> "+pack.exportFileName+".zip .. ";
printf("%s", s.toLocal8Bit().toStdString().c_str()); std::cout << std::flush;
QApplication::processEvents();
bool res = SM.exportS1000D(dstPath, pack.exportFileName, pack.title, NULL);
if(res)
printf("Ok\n");
else
printf("ОШИБКА экспорта\n");
}
}
SM.SaveProject(); //SM.SavePackagesXML();
return 0;
}
void console::printHelp()
{
setlocale(LC_ALL,"Russian");
qDebug() << "Конвертер АУК с формата LyX в пакеты стандартов S1000D и SCORM\n";
qDebug() << "Для запуска в оконном режиме запустите без параметров.";
qDebug() << "Формирование пакетов в консольном режиме выполняется со следующими параметрами:";
qDebug() << "CONVERTER [-SCORM] [-S1000D] [-p \"package1, ...\"] lyxfile destpath\n";
qDebug() << " -SCORM - тип формируемого пакета - SCORM;";
qDebug() << " -S1000D - тип формируемого пакета - S1000D, без явного указания формируются оба типа; ";
qDebug() << " -p - сформировать пакеты с именами package1,... (список через запятую в \"кавычках\");";
qDebug() << " без данной опции формируются все созданные в оконном режиме пакеты;";
qDebug() << " lyxfile - путь и имя файла LyX;";
qDebug() << " dstpath - путь для размещения сформировнных пакетов.";
}
QString console::delYYY(QString st) {
return st.replace("X", "").replace("Y", "").replace("N", "");
}
bool console::isCodingFilled() {
tmpStrList.clear(); tmpIntList.clear();
if(SM.items.count() == 0) return false;
for(int i=0;i<SM.items.count();i++)
if(SM.items[i].parent == -1)
if(!isCodingFilledRecurs(i))
return false;
return true;
}
bool console::isCodingFilledRecurs(int ind) {
SM.setCurItem(ind);
QString fCode, title;
if(SM.item->moduleType == mtPM) {
QString pmTitle, modelIdentCode, pmIssuer, pmNumber, pmVolume;
title = pmTitle = SM.getNodeText("identAndStatusSection.pmAddress.pmAddressItems.pmTitle");
modelIdentCode = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "modelIdentCode");
pmIssuer = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "pmIssuer");
pmNumber = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "pmNumber");
pmVolume = SM.getNodeAttr("identAndStatusSection.pmAddress.pmIdent.pmCode", "pmVolume");
if(pmTitle.isEmpty() || delYYY(pmIssuer).isEmpty() || delYYY(pmNumber).isEmpty() || delYYY(pmVolume).isEmpty()) {
return false;
}
fCode = SM.pmIdentString("identAndStatusSection.pmAddress.pmIdent");
}
if(SM.item->moduleType == mtDM) {
QString modelIdentCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "modelIdentCode");
QString systemDiffCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "systemDiffCode");
QString systemCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "systemCode");
QString subSystemCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "subSystemCode");
QString subSubSystemCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "subSubSystemCode");
QString assyCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "assyCode");
QString disassyCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "disassyCode");
QString disassyCodeVariant = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "disassyCodeVariant");
QString infoCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "infoCode");
QString infoCodeVariant = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "infoCodeVariant");
QString itemLocationCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "itemLocationCode");
QString learnCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "learnCode");
QString learnEventCode = SM.getNodeAttr("identAndStatusSection.dmAddress.dmIdent.dmCode", "learnEventCode");
QString techName = SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.techName");
//QString infoName = SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.infoName");
if(delYYY(modelIdentCode).isEmpty() || delYYY(systemDiffCode).isEmpty() || delYYY(systemCode).isEmpty() || delYYY(subSystemCode).isEmpty() || delYYY(subSubSystemCode).isEmpty() ||
delYYY(assyCode).isEmpty() || delYYY(disassyCode).isEmpty() || delYYY(disassyCodeVariant).isEmpty() || delYYY(infoCode).isEmpty() || delYYY(infoCodeVariant).isEmpty() ||
delYYY(itemLocationCode).isEmpty() || delYYY(learnCode).isEmpty() || delYYY(learnEventCode).isEmpty() || delYYY(techName).isEmpty() ) {
return false;
}
title = techName;
fCode = SM.dmIdentString("identAndStatusSection.dmAddress.dmIdent");
}
int tmpInd = tmpStrList.indexOf(fCode);
if(tmpInd != -1) {
SM.setCurItem(tmpIntList[tmpInd]);
QString title2;
if(SM.item->moduleType == mtDM)
title2 = SM.getNodeText("identAndStatusSection.dmAddress.dmAddressItems.dmTitle.techName");
else
title2 = SM.getNodeText("identAndStatusSection.pmAddress.pmAddressItems.pmTitle");
return false;
}
tmpStrList.append(fCode); tmpIntList.append(ind);
for(int i=0;i<SM.items[ind].child.count();i++)
if(!isCodingFilledRecurs(SM.items[ind].child[i]))
return false;
return true;
}