241 lines
8.5 KiB
C++
Executable File
241 lines
8.5 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Klasse fuer das Importieren von SAAB-Dateien
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <nglwidgets/ngldialog.h>
|
|
#include "saab_logging.h"
|
|
#include "saab_types.h"
|
|
#include "zwmssaab_export.h"
|
|
|
|
#include <QModelIndex>
|
|
#include <Plugins/ParticipantManagement/Gui/Common/participant_edit_model.h>
|
|
|
|
#include <memory>
|
|
#include <ParticipantManagement/ppm_dtc.h>
|
|
#include <ParticipantManagement/ppm_ftc.h>
|
|
#include <LtsUtilsGuiDds/request_helper.h>
|
|
|
|
#include <PluginInterfaces/gui_plugin_interface.h>
|
|
#include <Plugins/ParticipantManagement/ppm_participants_gui_plugin_interface.h>
|
|
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
|
|
#include <Plugins/ParticipantManagement/ppm_templates_gui_plugin_interface.h>
|
|
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
|
|
|
|
#include <QXmlStreamReader>
|
|
#include <QFile>
|
|
#include "saab_xml_strings.h"
|
|
|
|
class QXmlStreamReader;
|
|
|
|
namespace LtsSession
|
|
{
|
|
class LtsSession;
|
|
}
|
|
|
|
class Ui_SAABImport;
|
|
|
|
namespace saab
|
|
{
|
|
class ImportSaabShow;
|
|
|
|
class ZWMSSAAB_EXPORT ImportSaab : public NGLDialog, protected ParticipantManagement::Interface::Ftc::ModifyTypeReplyHandler
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
ImportSaab(ParticipantManagement::ParticipantEditModel *pModel, const QModelIndex &index, QWidget *parent, LtsSession::LtsSession *pSession);
|
|
virtual ~ImportSaab();
|
|
|
|
private slots:
|
|
void slotOpenImportDialog();
|
|
void slotOpenConfigDialog();
|
|
void slotStartImport();
|
|
|
|
private: // methods
|
|
void onModifyTypeReply(const Core::FunctionReplyObject &replyObject) override { m_requestHelper->requestReply(replyObject); }
|
|
ParticipantManagement::ParticipantData createParticipant(SaabPlayer *player);
|
|
void insertParticipant(SaabPlayer *player, const QModelIndex &index);
|
|
void insertParty(SaabUnit *party);
|
|
void createNode(const ParticipantManagement::ParticipantData &participant, const QModelIndex &index, SaabPlayer *parent);
|
|
SaabPerson saabPersonByGUID(const QString &guid) const;
|
|
SaabVehicle saabVehicleByGUID(const QString &guid) const;
|
|
void importOrbat();
|
|
void importConfig();
|
|
QVector<SaabPlayer *> flattenedPlayersWithoutRootUnits() const;
|
|
QVector<SaabPlayer *> inferiors(SaabPlayer *player) const;
|
|
SaabPlayer *readUnit(QXmlStreamReader *reader) const;
|
|
SaabPlayer *readOcPlayer(QXmlStreamReader *reader) const;
|
|
SaabPlayer *readPersonPlayer(QXmlStreamReader *reader) const;
|
|
SaabPlayer *readVehiclePlayer(QXmlStreamReader *reader) const;
|
|
SaabSymbol readSymbol(QXmlStreamReader *reader) const;
|
|
SaabEchelon readEchelon(QXmlStreamReader *reader) const;
|
|
static int playerIndexByGuid(const QString &guid, const QVector<SaabPlayer *> &vec);
|
|
void importExerciseScenario();
|
|
QVector<SaabPlayer *> resolveImportMapping(const QVector<SaabPlayer *> &playerVec);
|
|
QVector<SaabPlayer *> showMappingDialog(const QMap<QString, QVector<SaabPlayer *> > &mapConflictMap, bool typeClassIsUnit);
|
|
void buildImportTreeView(const QVector<SaabPlayer *> &vecUnitsWithValidDISTypes);
|
|
bool isValidSaabOrbatFile() const;
|
|
bool isValidConfigFile() const;
|
|
bool hasValidType(SaabPlayer *player) const;
|
|
|
|
// import vehicles and persons
|
|
template <typename T>
|
|
void importRefData(QVector<T> &vec,
|
|
const QString &parentTag,
|
|
const QString &childTag,
|
|
const QString &firstDataTag,
|
|
const QString &secondDataTag) // TODO: better naming
|
|
{
|
|
vec.clear();
|
|
|
|
if (!m_xmlFile)
|
|
{
|
|
ERROR_LOG(m_logger) << "Not possible to import " << parentTag << ": No file selected";
|
|
return;
|
|
}
|
|
|
|
if (!m_xmlFile->open(QIODevice::ReadOnly))
|
|
{
|
|
ERROR_LOG(m_logger) << "Not possible to import " << parentTag << ": Could not open file \""
|
|
<< m_xmlFile->fileName()
|
|
<< "\" for reading.";
|
|
return;
|
|
}
|
|
|
|
QXmlStreamReader reader(m_xmlFile);
|
|
|
|
while (!reader.atEnd())
|
|
{
|
|
if (reader.readNextStartElement() && reader.name() == parentTag)
|
|
{
|
|
QXmlStreamReader::TokenType currentToken;
|
|
|
|
do
|
|
{
|
|
currentToken = reader.readNext();
|
|
|
|
if (reader.name() == childTag && currentToken == QXmlStreamReader::StartElement)
|
|
{
|
|
QString guid = reader.attributes().value(XmlStrings::SAAB_ID()).toString();
|
|
|
|
do
|
|
{
|
|
if (!reader.readNextStartElement())
|
|
break;
|
|
|
|
}
|
|
while (reader.name().toString() != firstDataTag);
|
|
|
|
QString value = reader.readElementText();
|
|
|
|
do
|
|
{
|
|
if (!reader.readNextStartElement())
|
|
break;
|
|
|
|
}
|
|
while (reader.name().toString() != secondDataTag);
|
|
|
|
vec.append({ guid, value, reader.readElementText() });
|
|
}
|
|
|
|
}
|
|
while (currentToken != QXmlStreamReader::EndElement || reader.name() != parentTag);
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (m_logger.isDebugEnabled())
|
|
{
|
|
for (const T ¤t : qAsConst(vec))
|
|
DEBUG_LOG(m_logger) << childTag << ": " << current.toString();
|
|
}
|
|
|
|
m_xmlFile->close();
|
|
}
|
|
|
|
template <typename T>
|
|
T *readPlayerBaseData(QXmlStreamReader *reader, const QString &mainTag, const QString &refTag) const
|
|
{
|
|
T *result = new T;
|
|
|
|
using namespace XmlStrings;
|
|
|
|
result->guid = reader->attributes().value(SAAB_ID()).toString();
|
|
|
|
while (!(reader->readNext() == QXmlStreamReader::EndElement && reader->name() == mainTag))
|
|
{
|
|
if (reader->tokenType() != QXmlStreamReader::StartElement)
|
|
continue;
|
|
|
|
if (reader->name() == SAAB_DESIGNATION())
|
|
result->designation = reader->readElementText();
|
|
else if (reader->name() == SAAB_FORCE())
|
|
result->force = reader->readElementText();
|
|
else if (reader->name() == SAAB_SYMBOL())
|
|
result->symbol = reader->readElementText();
|
|
else if (reader->name() == SAAB_TRASHCAN())
|
|
result->trashcan = reader->readElementText() == SAAB_TRUE();
|
|
else if (reader->name() == refTag)
|
|
result->refId = reader->readElementText();
|
|
else if (reader->name() == SAAB_CHANGE_INFO())
|
|
result->isDeletedByDefault = reader->attributes().value(SAAB_CHANGE_TYPE()).toString() == SAAB_DELETE();
|
|
else if (reader->name() == SAAB_SIMULATOR_ID())
|
|
result->simulatorId = reader->readElementText().toInt();
|
|
else if (reader->name() == SAAB_EXTERNAL_PLAYER())
|
|
result->isExternalPlayer = reader->readElementText() == SAAB_TRUE();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
template <typename T>
|
|
T *readPersonOcPlayer(QXmlStreamReader *reader, const QString &mainTag) const
|
|
{
|
|
T *result = readPlayerBaseData<T>(reader, mainTag, XmlStrings::SAAB_PERSON_REF_ID());
|
|
|
|
if (!result->refId.isEmpty())
|
|
{
|
|
SaabPerson person = saabPersonByGUID(result->refId);
|
|
|
|
if (person.guid.isEmpty())
|
|
WARNING_LOG(m_logger) << XmlStrings::SAAB_PERSON_REF_ID() << " set, but GUID " << result->refId << " could not be found.";
|
|
else
|
|
{
|
|
result->personalID = person.personalID;
|
|
result->name = person.name;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private: // attributes
|
|
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
|
|
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ppmFtc;
|
|
QVector<SaabPerson> m_saabPersons;
|
|
QVector<SaabVehicle> m_saabVehicles;
|
|
QVector<SaabUnit *> m_rootUnits;
|
|
QFile *m_xmlFile;
|
|
QFile *m_configFile;
|
|
QMap<QString, int32_t> m_mapSaabSymbolToType; // <SAAB symbol.code, type.id>
|
|
QMap<QString, QVector<SaabPlayer *> > m_unknownTypes; // <Symbol (from SAAB xml), saab players with the symbol Symbol>
|
|
QMap<qint32, ParticipantManagement::Type> m_mapTypes; // E.g. participant id "47" to type id
|
|
QMap<QString, SaabSymbol> m_mapSymbols;
|
|
QMap<QString, SaabEchelon> m_mapEchelons;
|
|
QMap<SaabPlayer *, QModelIndex> m_parentIndexCache; // Used to create the treeview with the imported participants
|
|
QModelIndex m_indexRoot; // Used to append parties/forces to the tree
|
|
ParticipantManagement::ParticipantEditModel *m_pModel;
|
|
LtsUtils::RequestHelper *m_requestHelper;
|
|
Ui_SAABImport *m_pUi;
|
|
saab::LOGGER_T m_logger;
|
|
};
|
|
}
|
|
|