236 lines
7.0 KiB
C++
Executable File
236 lines
7.0 KiB
C++
Executable File
/**
|
|
The PdfCreator class creates a PDF file with the information given by a collateral damage simulation
|
|
* @RDE_HEADER@
|
|
* $Id: ppm_msdl_edit.h 52239 2020-10-05 11:33:12Z thoden $
|
|
* $HeadURL: svn://192.168.133.21/TDS/branches/product/features/3dws_devel/Lts/Plugins/ParticipantManagement/Gui/MSDL/ppm_msdl_edit.h $
|
|
* $Author: thoden $
|
|
* Created by Hannes Fritsche, ESZS, 2024-08-26
|
|
*/
|
|
|
|
#include "cds_pdf_creator.h"
|
|
|
|
#include <InfrastructureManagement/ism_dtc.h>
|
|
#include <ParticipantManagement/ppm_dtc.h>
|
|
#include <FileManagement/flm_ftc.h>
|
|
|
|
#include <QDateTime>
|
|
#include <QTemporaryFile>
|
|
#include <QDateTime>
|
|
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <LtsUtilsCore/dds_vector.h>
|
|
#include <LtsWidgets/lts_message_dialog.h>
|
|
|
|
#include <KDReports/KDReports.h>
|
|
|
|
#include <ngltools/ngltools_dtg.h>
|
|
|
|
namespace CollateralDamageSimulation
|
|
{
|
|
|
|
CollateralDamageSimulation::PdfCreator::PdfCreator(QWidget *parent)
|
|
: QObject(parent)
|
|
{}
|
|
|
|
PdfCreator::~PdfCreator()
|
|
{
|
|
if (m_report)
|
|
{
|
|
delete m_report;
|
|
m_report = nullptr;
|
|
}
|
|
}
|
|
|
|
void PdfCreator::init(const std::shared_ptr<InfrastructureManagement::Interface::Dtc> &ismDtc, const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc, const std::shared_ptr<FileManagement::Interface::Ftc> &flmFtc)
|
|
{
|
|
if (m_report != nullptr)
|
|
{
|
|
delete m_report;
|
|
m_report = nullptr;
|
|
}
|
|
|
|
m_report = new KDReports::Report();
|
|
|
|
m_ismDtc = ismDtc;
|
|
m_ppmDtc = ppmDtc;
|
|
m_flmFtc = flmFtc;
|
|
}
|
|
|
|
void PdfCreator::addInformation(const QString &name, const QString &charge, const QString &igniterType, const QString &position)
|
|
{
|
|
if (!m_report)
|
|
return;
|
|
|
|
KDReports::TextElement heading(tr("Collateral Damage Report"));
|
|
heading.setBold(true);
|
|
heading.setPointSize(24);
|
|
|
|
KDReports::TextElement nameText(tr("Name: %1").arg(name));
|
|
KDReports::TextElement chargeText(tr("Charge: %1").arg(charge));
|
|
KDReports::TextElement fuseText(tr("Igniter type: %1").arg(igniterType));
|
|
KDReports::TextElement positionText(tr("Position: %1").arg(position));
|
|
KDReports::TextElement time(tr("Time: %1").arg(DTG::toStringMSec(QDateTime::currentMSecsSinceEpoch())));
|
|
|
|
m_report->addElement(heading, Qt::AlignmentFlag::AlignCenter);
|
|
m_report->addElement(nameText);
|
|
m_report->addElement(chargeText);
|
|
m_report->addElement(fuseText);
|
|
m_report->addElement(positionText);
|
|
m_report->addElement(time);
|
|
}
|
|
|
|
void PdfCreator::addBuildings(const QVector<int> &buildingIds)
|
|
{
|
|
if (!m_report)
|
|
return;
|
|
|
|
KDReports::TextElement tableHeading(tr("Buildings"));
|
|
tableHeading.setBold(true);
|
|
tableHeading.setPointSize(16.0);
|
|
|
|
m_report->addElement(tableHeading);
|
|
|
|
KDReports::TableElement table;
|
|
table.setWidth(100, KDReports::Percent);
|
|
table.setHeaderRowCount(1);
|
|
|
|
KDReports::TextElement nameHeader(tr("Name"));
|
|
|
|
table.cell(0, 0).addElement(nameHeader);
|
|
|
|
int row = 1;
|
|
|
|
for (int currentBuildingId : buildingIds)
|
|
{
|
|
const InfrastructureManagement::MainStructureElement ¤tBuilding = m_ismDtc->mainStructureElement(currentBuildingId);
|
|
|
|
KDReports::TextElement name(QString::fromStdString(currentBuilding.name()));
|
|
|
|
table.cell(row, 0).addElement(name);
|
|
|
|
++row;
|
|
}
|
|
|
|
m_report->addElement(table);
|
|
}
|
|
|
|
void PdfCreator::addParticipantsWithProtection(const QVector<int> &participantIds)
|
|
{
|
|
addParticipantTable(participantIds, tr("Participants with protection"));
|
|
}
|
|
|
|
void PdfCreator::addParticipantsWithoutProtection(const QVector<int> &participantIds)
|
|
{
|
|
addParticipantTable(participantIds, tr("Participants without protection"));
|
|
}
|
|
|
|
void PdfCreator::save(const QString &name, int folderId, int exerciseId)
|
|
{
|
|
QTemporaryFile saveFile;
|
|
|
|
saveFile.rename(QString(QStringLiteral("%1.pdf")).arg(saveFile.fileName()));
|
|
|
|
if (!saveFile.open())
|
|
return;
|
|
|
|
m_report->exportToFile(saveFile.fileName());
|
|
|
|
FileManagement::FileContentModifyRequest data;
|
|
|
|
data.name(name.toStdString());
|
|
data.isTemplate(false);
|
|
data.isHidden(false);
|
|
data.folderId(folderId);
|
|
data.fileStatus(FileManagement::FileStatus::Valid);
|
|
data.fileCategory(FileManagement::FileCategory::Exercise);
|
|
data.fileType(FileManagement::FileType::Pdf);
|
|
data.operatorId(LtsSessionData::LtsSessionData::getInstance()->getOperatorId());
|
|
data.lastModified(QDateTime::currentMSecsSinceEpoch());
|
|
data.content(LtsUtils::convert<std::vector<uint8_t>>(saveFile.readAll()));
|
|
data.exerciseId(exerciseId);
|
|
|
|
bool isModifyRequestOk = m_flmFtc->fileContentModifyRequest(data, [this](const Core::FunctionReplyObject &reply)
|
|
{
|
|
if (reply.error())
|
|
warnSafeDidNotWork(QLatin1String("Could not save plan: %1").arg(QString::fromStdString(reply.str())));
|
|
});
|
|
|
|
if (!isModifyRequestOk)
|
|
warnSafeDidNotWork(QLatin1String("Could not save plan."));
|
|
}
|
|
|
|
void PdfCreator::clear()
|
|
{
|
|
if (m_report != nullptr)
|
|
{
|
|
delete m_report;
|
|
m_report = nullptr;
|
|
}
|
|
|
|
m_report = new KDReports::Report();
|
|
}
|
|
|
|
void PdfCreator::warnSafeDidNotWork(const QString &message) const
|
|
{
|
|
new LtsWidgets::LtsMessageDialogNew(static_cast<QWidget*>(parent()), message, tr("Save failed"));
|
|
}
|
|
|
|
void PdfCreator::addParticipantTable(const QVector<int> &participantIds, const QString &tableName)
|
|
{
|
|
if (!m_report)
|
|
return;
|
|
|
|
KDReports::TextElement tableHeading(tableName);
|
|
tableHeading.setBold(true);
|
|
tableHeading.setPointSize(16.0);
|
|
|
|
m_report->addElement(tableHeading);
|
|
|
|
KDReports::TableElement table;
|
|
table.setWidth(100, KDReports::Percent);
|
|
table.setHeaderRowCount(1);
|
|
|
|
KDReports::TextElement partyHeader(tr("Party"));
|
|
KDReports::TextElement equipmentNumberHeader(tr("Equipment No."));
|
|
KDReports::TextElement designationHeader(tr("Designator"));
|
|
KDReports::TextElement tacticalIdentifierHeader(tr("Tactical Identifier"));
|
|
|
|
table.cell(0, 0).addElement(partyHeader);
|
|
table.cell(0, 1).addElement(equipmentNumberHeader);
|
|
table.cell(0, 2).addElement(designationHeader);
|
|
table.cell(0, 3).addElement(tacticalIdentifierHeader);
|
|
|
|
QHash<int, QString> partyNames;
|
|
int row = 1;
|
|
|
|
for (int currentParticipantId : participantIds)
|
|
{
|
|
int column = 0;
|
|
const ParticipantManagement::Participant ¤tParticipant = m_ppmDtc->participant(currentParticipantId);
|
|
|
|
if (!partyNames.contains(currentParticipant.partyId()))
|
|
{
|
|
const ParticipantManagement::Party &party = m_ppmDtc->party(currentParticipant.partyId());
|
|
|
|
partyNames.insert(party.id(), QString::fromStdString(party.name()));
|
|
}
|
|
|
|
KDReports::TextElement party(partyNames.value(currentParticipant.partyId()));
|
|
KDReports::TextElement equipmentNumber(QString::number(currentParticipant.equipmentNumber().is_set() ? currentParticipant.equipmentNumber().get() : 0));
|
|
KDReports::TextElement designation(QString::fromStdString(currentParticipant.designator()));
|
|
KDReports::TextElement tacticalIdentifier(QString::fromStdString(currentParticipant.tacticalIdentifier()));
|
|
|
|
table.cell(row, column++).addElement(party);
|
|
table.cell(row, column++).addElement(equipmentNumber);
|
|
table.cell(row, column++).addElement(designation);
|
|
table.cell(row, column++).addElement(tacticalIdentifier);
|
|
|
|
++row;
|
|
}
|
|
|
|
m_report->addElement(table);
|
|
}
|
|
|
|
|
|
} //namespace CollateralDamageSimulation
|