Files
qt5-legatus-legacy/Lts/Proxies/WarehouseManagement/interface_wms2ecc_impl.cpp
T
2026-08-13 18:33:10 +02:00

499 lines
16 KiB
C++
Executable File

/**
* @RDE_HEADER@
* Interface Impl zwischen WMS und ECC
* $Id$
* $HeadURL$
* $Author$
*/
#include "interface_wms2ecc_impl.h"
#include "exercises_handler.h"
#include <ExerciseManagement/exm.hpp>
#include <ExerciseManagement/exm_translation.h>
#include <ParticipantManagement/ppm.hpp>
#include <QString>
#include <vector>
namespace WarehouseManagement
{
IWMS2ECC_Impl::IWMS2ECC_Impl(const std::shared_ptr<ExercisesHandler> &exercisesHandler)
: m_exercisesHandler(exercisesHandler)
, m_logger(getLogger("Wms2Ecc"))
{
connect(m_exercisesHandler.get(), &ExercisesHandler::registrationReturnValue,
this, &IWMS2ECC_Impl::onRegistrationReturnValue);
}
IWMS2ECC::Exercise IWMS2ECC_Impl::convert(const ExerciseManagement::Exercise &ex)
{
IWMS2ECC::Exercise ret;
ret.id = ex.id();
ret.name = QString::fromStdString(ex.name());
if (ex.state() == ExerciseManagement::ExerciseState_def::Started ||
ex.state() == ExerciseManagement::ExerciseState_def::Paused)
ret.actExercise = 1;
else
ret.actExercise = 0;
ret.start = ex.beginTime() / 1000; // ms -> s
ret.end = ex.endTime() / 1000; // ms -> s
ret.stateAsString = ExerciseManagement::toString(ex.state());
return ret;
}
IWMS2ECC::PlayerInfo IWMS2ECC_Impl::convert(const ParticipantManagement::Participant &part, int exerciseId, const QMap<int, ParticipantManagement::Participant> &allParticipants) const
{
IWMS2ECC::PlayerInfo pi;
pi.alias = QString::fromStdString(part.identification());
pi.assignState = convert(part.assignState());
pi.designator = QString::fromStdString(part.designator());
if (part.equipmentNumber().is_set())
pi.equipNo = part.equipmentNumber().get();
else if (part.assignState() == ParticipantManagement::ParticipantAssignState_def::HandoutExcon)
pi.equipNo = 0;
pi.exerciseId = exerciseId;
pi.forceId = part.partyId();
DEBUG_LOG(m_logger) << "Force Id = " << pi.forceId;
pi.info = QString::fromStdString(part.info());
pi.parentPlayerId = part.superiorId();
pi.playerId = part.id();
pi.playerState = part.isDeleted() ? IWMS2ECC::PlayerState::DELETED : IWMS2ECC::PlayerState::FOUND;
pi.tactIdent = QString::fromStdString(part.tacticalIdentifier());
const ParticipantManagement::Type partType = m_exercisesHandler->participantType(part.typeId());
if (partType.id() == part.typeId())
{
pi.equipTypeId = partType.equipmentTypeId();
pi.typeClassId = convert(partType.typeClass());
TRACE_LOG(m_logger) << "Found participant type with id " << part.typeId() << ", " << pi.typeClassId << ", " << pi.equipTypeId;
}
else
WARNING_LOG(m_logger) << "Can not find participant type with id " << part.typeId();
pi.typeId = part.typeId();
pi.isDeleted = part.isDeleted();
pi.hierarchy = m_exercisesHandler->getHierarchyFromParticipant(part.id(), exerciseId, allParticipants);
const ParticipantManagement::Party party = m_exercisesHandler->getParty(part.partyId(), exerciseId);
pi.forceName = QString::fromStdString(party.name());
pi.symbolColor = party.color();
DEBUG_LOG(m_logger) << "party.name: " << pi.forceName;
DEBUG_LOG(m_logger) << "symbolColor: " << pi.symbolColor << ", playerId: " << pi.playerId << ", exerciseId: " << exerciseId;
// TODO
//pi.symbolPNG
return pi;
}
IWMS2ECC::exerciseMap IWMS2ECC_Impl::getExercises() const
{
const QMap<qint32, ExerciseManagement::Exercise> exMap = m_exercisesHandler->getExercises();
IWMS2ECC::exerciseMap retMap;
for (const ExerciseManagement::Exercise &ex : exMap)
{
if (ex.sendToWMS())
retMap.insert(ex.id(), convert(ex));
}
INFO_LOG(m_logger) << "IN getExercises, exMap.size(): " << exMap.size()
<< ", retMap.size: " << retMap.size();
return retMap;
}
IWMS2ECC::Exercise IWMS2ECC_Impl::getActualExercise() const
{
return IWMS2ECC::Exercise();
}
int IWMS2ECC_Impl::getPlayerId(int equipNo, int exerciseId) const
{
Q_ASSERT(false);
Q_UNUSED(equipNo);
Q_UNUSED(exerciseId);
return -1;
}
int IWMS2ECC_Impl::getEquipNo(int playerId, int exerciseId) const
{
Q_ASSERT(false);
Q_UNUSED(playerId);
Q_UNUSED(exerciseId);
return -1;
}
QMap<int, IWMS2ECC::PlayerInfo> IWMS2ECC_Impl::getAllPlayers(int exerciseId) const
{
return getAllParticipants(exerciseId);
}
QMap<int, IWMS2ECC::PlayerInfo> IWMS2ECC_Impl::getAllParticipants(int exerciseId) const
{
INFO_LOG(m_logger) << "IN getAllParticipants";
QMap<int, IWMS2ECC::PlayerInfo> retMap;
const QMap<qint32, ParticipantManagement::Participant> map = m_exercisesHandler->getParticipants(exerciseId);
INFO_LOG(m_logger) << "getAllPlayers map.size() : " << map.size();
for (const ParticipantManagement::Participant &exePart : map)
{
IWMS2ECC::PlayerInfo pi = convert(exePart, exerciseId, map);
// add exerciseId and 1000000 to partcipantId to distinguish the different exercises
// if there are more than one current exercise
pi.playerId = (exerciseId * 1000000) + pi.playerId;
pi.parentPlayerId = (exerciseId * 1000000) + pi.parentPlayerId;
if (pi.playerState == PlayerState::FOUND)
retMap.insert(pi.playerId, pi);
}
return retMap;
}
QMap<int, IWMS2ECC::PlayerInfo> IWMS2ECC_Impl::getAllVehicles(int exerciseId) const
{
Q_ASSERT(false);
Q_UNUSED(exerciseId);
return {};
}
IWMS2ECC::RegisterReturnValue IWMS2ECC_Impl::registerPlayer(int playerId, int equipNo, const IWMS2ECC::PlayerAssignState &playerAssignState,
const QString &alias, const QString &info, int exerciseId)
{
ParticipantManagement::ParticipantAssignState assignState = convert(playerAssignState);
m_exercisesHandler->registerParticipant(exerciseId, playerId, assignState, equipNo, alias, info);
return IWMS2ECC::RegistrationFailed;
}
void IWMS2ECC_Impl::onRegistrationReturnValue(int exerciseId, qint32 participantId, ParticipantManagement::RegisterReturnValue retValue)
{
INFO_LOG(m_logger) << "IN onRegistrationReturnValue ";
INFO_LOG(m_logger) << "exerciseId: " << exerciseId << ", participantId: " << participantId << ", retValue: " << retValue;
emit registrationReturnValue(exerciseId, participantId, convert(retValue));
}
IWMS2ECC::UnregisterReturnValue IWMS2ECC_Impl::unregister(int equipNo, int exerciseId)
{
if (!m_exercisesHandler->unregisterParticipant(exerciseId, equipNo))
return IWMS2ECC::UnregisterFailed;
return IWMS2ECC::UnregisterOk; // ok -> unregister is in progress
}
IWMS2ECC::PlayerInfo IWMS2ECC_Impl::getPlayerInfo(int playerId, int exerciseId)
{
DEBUG_LOG(m_logger) << "IN getPlayerInfo: "
<< " playerId = " << playerId << ", exerciseId = " << exerciseId;
if (playerId <= 0 || exerciseId <= 0)
{
WARNING_LOG(m_logger) << "Invalid Player (0,0)";
IWMS2ECC::PlayerInfo pi;
pi.playerState = NOT_FOUND;
return pi;
}
// HR 10.04.14 vorerst mit zurueckgeben
// Nur Player zurueckgeben, die nicht(!) von EXCON angemeldet sind ( != HANDOUT_EXCON(1))
ParticipantManagement::Participant part = m_exercisesHandler->getParticipant(playerId, exerciseId);
IWMS2ECC::PlayerInfo pi;
if (part.assignState() == ParticipantManagement::ParticipantAssignState_def::HandoutExcon)
{
pi.playerState = NOT_FOUND;
return pi;
}
pi = convert(part, exerciseId);
pi.forceName = QString::fromStdString(m_exercisesHandler->getParty(part.partyId(), exerciseId).name());
//pi.symbolPNG = getSymbol(q.value(4).toInt(), exerciseId, teamData.color, teamData.role);
pi.playerState = FOUND;
INFO_LOG(m_logger) << "Player (" << pi.playerId << "," << exerciseId << ") found: "
<< "AssignState: " << pi.assignState << ", forceName: " << pi.forceName;
return pi;
}
QMap<int, int> IWMS2ECC_Impl::getEquipRequirements(int exerciseId) const
{
/*
QString tableName = getTableName( exerciseId, "tln");
NSqlQuery q;
QString stmt = "SELECT count(ty.typausstg_id), ty.typausstg_id from " + tableName + " t, typen ty "
"WHERE ty.id = t.typ_id AND t.ausstattung = 1 AND t.loeschkennung = 0 "
"GROUP BY ty.typausstg_id";
*/
const QMap<qint32, ParticipantManagement::Participant> map = m_exercisesHandler->getParticipants(exerciseId);
INFO_LOG(m_logger) << "getAllPlayers map.size() : " << map.size();
QMap<int, int> reqPartTypes;
for (const ParticipantManagement::Participant &part : map)
{
if (part.isDeleted())
continue;
reqPartTypes[part.typeId()]++;
}
QMap<int, int> reqEquipTypes;
QMap<int, int>::ConstIterator cIt = reqPartTypes.constBegin();
for (; cIt != reqPartTypes.constEnd(); ++cIt)
{
const int typeId = cIt.key();
const ParticipantManagement::Type partType = m_exercisesHandler->participantType(typeId);
if (partType.id() == typeId)
{
DEBUG_LOG(m_logger) << "Key: " << typeId;
ParticipantManagement::TypeClass typeClass = partType.typeClass();
int equipTypeId = partType.equipmentTypeId();
if (typeClass != ParticipantManagement::TypeClass_def::Unit && typeClass != ParticipantManagement::TypeClass_def::SupportUnit)
{
reqEquipTypes[equipTypeId] = cIt.value();
DEBUG_LOG(m_logger) << "equipTypeId: " << equipTypeId << ", amount: " << cIt.value();
}
}
else
WARNING_LOG(m_logger) << "Can not find participant type with id " << typeId;
}
return reqEquipTypes;
}
// TODO: really needed?
int IWMS2ECC_Impl::getTypeClassId(int equipTypeId) const
{
return convert(m_exercisesHandler->typeClassIdFromEquipmentTypeId(equipTypeId));
}
QByteArray IWMS2ECC_Impl::getSymbol(int symbolId, int exerciseId, const QColor &color, int role) const
{
Q_ASSERT(false);
Q_UNUSED(symbolId);
Q_UNUSED(exerciseId);
Q_UNUSED(color);
Q_UNUSED(role);
return {};
}
//------------------------------------------------------------------------------------------------------------------------------------------
IWMS2ECC::EquipmentType IWMS2ECC_Impl::convert(const ParticipantManagement::EquipmentType &et)
{
IWMS2ECC::EquipmentType ret;
ret.id = et.id();
ret.name = QString::fromStdString(et.name());
ret.minEquipNo = et.minEquipNo();
ret.maxEquipNo = et.maxEquipNo();
ret.specialType = int(et.wmsTypeClass().underlying());
ret.taVulnerabilityModelId = et.traVulnerabilityModelId();
ret.taPlayerTypeId = et.traPlayerTypeId();
ret.deletedInWMS = et.deletedInWms();
return ret;
}
ParticipantManagement::EquipmentType IWMS2ECC_Impl::convert(const IWMS2ECC::EquipmentType &et)
{
ParticipantManagement::EquipmentType ret;
ret.id(et.id);
ret.name(et.name.toStdString());
ret.minEquipNo(et.minEquipNo);
ret.maxEquipNo(et.maxEquipNo);
ParticipantManagement::WmsTypeClass wmsTypeClass = convert(et.specialType);
ret.wmsTypeClass(wmsTypeClass);
ret.traVulnerabilityModelId(et.taVulnerabilityModelId);
ret.traPlayerTypeId(et.taPlayerTypeId);
ret.deletedInWms(et.deletedInWMS);
return ret;
}
ParticipantManagement::WmsTypeClass IWMS2ECC_Impl::convert(int specialType)
{
switch (specialType)
{
case 0:
return ParticipantManagement::WmsTypeClass_def::None;
case 1:
return ParticipantManagement::WmsTypeClass_def::Building;
case 2:
return ParticipantManagement::WmsTypeClass_def::Vehicle;
case 3:
return ParticipantManagement::WmsTypeClass_def::Human;
case 4:
return ParticipantManagement::WmsTypeClass_def::TargetVehicle;
case 5:
return ParticipantManagement::WmsTypeClass_def::TargetHuman;
case 6:
return ParticipantManagement::WmsTypeClass_def::Airborne;
case 7:
return ParticipantManagement::WmsTypeClass_def::VehicleMarker;
default:
Q_ASSERT(false);
break;
}
return ParticipantManagement::WmsTypeClass_def::None;
}
ParticipantManagement::TypeClass IWMS2ECC_Impl::convertTypeClass(int typeClass)
{
switch (typeClass)
{
case 1:
return ParticipantManagement::TypeClass_def::Unit;
case 2: // WeaponSystem
return ParticipantManagement::TypeClass_def::VehicleWithGear;
case 3: // Vehicle Light
case 4: // Vehicle Armored
return ParticipantManagement::TypeClass_def::GroundVehicle;
case 5:
return ParticipantManagement::TypeClass_def::Human;
case 6: // OCSoldier
case 7: // OCVehicle
return ParticipantManagement::TypeClass_def::SupportEntity;
case 8:
return ParticipantManagement::TypeClass_def::Aircraft;
case 10:
return ParticipantManagement::TypeClass_def::SupportUnit;
default:
Q_ASSERT(false);
break;
}
return ParticipantManagement::TypeClass_def::Unit;
}
int IWMS2ECC_Impl::convert(ParticipantManagement::TypeClass typeClass)
{
switch (typeClass.underlying())
{
case ParticipantManagement::TypeClass_def::Unknown:
return 0; // Unknown
case ParticipantManagement::TypeClass_def::Unit:
return 1; // Unit
case ParticipantManagement::TypeClass_def::Human:
return 5; // Soldier
case ParticipantManagement::TypeClass_def::VehicleWithGear:
case ParticipantManagement::TypeClass_def::WeaponSystem:
return 2; // WeaponSystem
case ParticipantManagement::TypeClass_def::GroundVehicle:
return 3; // Vehicle light
case ParticipantManagement::TypeClass_def::SupportUnit:
return 10; // OCUnit
case ParticipantManagement::TypeClass_def::SupportEntity:
return 7; // OCVehicle
case ParticipantManagement::TypeClass_def::Aircraft:
return 8; // Aircraft
default:
Q_ASSERT(false);
break;
}
return 1; // Unit, Vessel
}
bool IWMS2ECC_Impl::setEquipmentType(const EquipmentType &et)
{
std::vector<ParticipantManagement::EquipmentType> vEquipTypes;
const ParticipantManagement::EquipmentType &etData = convert(et);
vEquipTypes.push_back(etData);
return m_exercisesHandler->modifyEquipmentTypes(vEquipTypes);
}
bool IWMS2ECC_Impl::setEquipmentTypes(const equipTypeMap &map)
{
INFO_LOG(m_logger) << "IN setEquipmentTypes: equipMap.size: " << map.size();
std::vector<ParticipantManagement::EquipmentType> vEquipTypes;
vEquipTypes.reserve(map.size());
for (const IWMS2ECC::EquipmentType &et : map)
vEquipTypes.push_back(convert(et));
return m_exercisesHandler->modifyEquipmentTypes(vEquipTypes);
}
IWMS2ECC::PlayerAssignState IWMS2ECC_Impl::convert(const ParticipantManagement::ParticipantAssignState &state)
{
switch (state.underlying())
{
case ParticipantManagement::ParticipantAssignState_def::NotAssigned:
return IWMS2ECC::NOT_ASSIGNED;
case ParticipantManagement::ParticipantAssignState_def::AssignedWms:
return IWMS2ECC::ASSIGNED;
case ParticipantManagement::ParticipantAssignState_def::HandoutWms:
return IWMS2ECC::HANDOUT_WMS;
case ParticipantManagement::ParticipantAssignState_def::HandoutExcon:
return IWMS2ECC::HANDOUT_EXCON;
case ParticipantManagement::ParticipantAssignState_def::ExconWmsOverruled:
return IWMS2ECC::HANDOUT_EXCON_OVERRULED_WMS;
}
Q_ASSERT(false);
return IWMS2ECC::UNDEFINED;
}
ParticipantManagement::ParticipantAssignState IWMS2ECC_Impl::convert(const IWMS2ECC::PlayerAssignState &state)
{
switch (state)
{
case IWMS2ECC::UNDEFINED:
return ParticipantManagement::ParticipantAssignState_def::NotAssigned;
case IWMS2ECC::NOT_ASSIGNED:
return ParticipantManagement::ParticipantAssignState_def::NotAssigned;
case IWMS2ECC::ASSIGNED:
return ParticipantManagement::ParticipantAssignState_def::AssignedWms;
case IWMS2ECC::HANDOUT_WMS:
return ParticipantManagement::ParticipantAssignState_def::HandoutWms;
case IWMS2ECC::HANDOUT_EXCON:
return ParticipantManagement::ParticipantAssignState_def::HandoutExcon;
case IWMS2ECC::HANDOUT_EXCON_OVERRULED_WMS:
return ParticipantManagement::ParticipantAssignState_def::ExconWmsOverruled;
}
Q_ASSERT(false);
return ParticipantManagement::ParticipantAssignState_def::NotAssigned;
}
IWMS2ECC::RegisterReturnValue IWMS2ECC_Impl::convert(const ParticipantManagement::RegisterReturnValue retValue)
{
switch (retValue.underlying())
{
case ParticipantManagement::RegisterReturnValue_def::AssignmentIncorrect:
return IWMS2ECC::AssignmentIncorrect;
case ParticipantManagement::RegisterReturnValue_def::PlayerDeleted:
return IWMS2ECC::PlayerDeleted;
case ParticipantManagement::RegisterReturnValue_def::PlayerNotFound:
return IWMS2ECC::PlayerNotFound;
case ParticipantManagement::RegisterReturnValue_def::RegistrationFailed:
return IWMS2ECC::RegistrationFailed;
case ParticipantManagement::RegisterReturnValue_def::RegistrationOk:
return IWMS2ECC::RegistrationOk;
case ParticipantManagement::RegisterReturnValue_def::EquipNoAlreadyAssigned:
return IWMS2ECC::EquipNoAlreadyAssigned;
}
Q_ASSERT(false);
return IWMS2ECC::RegistrationFailed;
}
} // Namespace WarehouseManagement