327 lines
12 KiB
C++
Executable File
327 lines
12 KiB
C++
Executable File
|
|
/**
|
|
* @RDE_HEADER@
|
|
* Dialog to create a new online report
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Hannes Baeuerle, SLSE, 2017-02-27
|
|
*/
|
|
|
|
#include "alm_config_participant_dialog.h"
|
|
#include "ui_alm_config_participant_dialog.h"
|
|
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <LtsUtilsSettings/settings.h>
|
|
|
|
#include <Plugins/ParticipantManagement/Gui/Common/participant_vulnerability_types.h>
|
|
|
|
namespace ParticipantAlarms
|
|
{
|
|
ConfigParticipantsDialog::ConfigParticipantsDialog(QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
|
, m_ui(new Ui::ConfigParticipantsDialog)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_typeClass(ParticipantManagement::TypeClass::Human)
|
|
, m_logger(AlarmManagement::getLogger("ConfigParticipantsDialog"))
|
|
{
|
|
|
|
LtsUtils::ProjectSettings *ps = LtsUtils::ProjectSettings::getInstance();
|
|
|
|
const bool enableNuclearContaminations = ps->value(QStringLiteral("aes"),
|
|
QStringLiteral("enableNuclearContaminations")).toBool();
|
|
const bool enableMineAreas = ps->value(QStringLiteral("aes"),
|
|
QStringLiteral("enableMineAreas")).toBool();
|
|
m_ui->setupUi(this);
|
|
|
|
if (!enableNuclearContaminations)
|
|
{
|
|
m_ui->cbxNbcAgent->hide();
|
|
}
|
|
if (!enableMineAreas)
|
|
{
|
|
m_ui->cbxMines->hide();
|
|
m_ui->cbxIndirectFire->hide();
|
|
}
|
|
|
|
#ifdef ETS_MODE
|
|
//hide Mil Things
|
|
m_ui->cbxFriendlyFire->hide();
|
|
m_ui->cbStatusFriendly->hide();
|
|
#endif
|
|
|
|
setNoTopicLock(); // as this topic is only related to an operator
|
|
}
|
|
|
|
ConfigParticipantsDialog::~ConfigParticipantsDialog()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
void ConfigParticipantsDialog::retranslate()
|
|
{
|
|
if (!m_participantData.equipmentNumber().is_set())
|
|
{
|
|
QString hierarchy = m_ppmDtc->hierarchyFromParticipant(m_participantData.id());
|
|
translate(m_ui, m_participantData, hierarchy, tr("Participant Alarm"));
|
|
}
|
|
else
|
|
translate(m_ui, m_participantData, QString::number(m_participantData.equipmentNumber().get()), tr("Participant Alarm"));
|
|
|
|
m_uiRequirements->clear();
|
|
m_uiRequirements->addRequirement( { m_ui->lbReaction, [this]() { return m_ui->cbxSetMarker->isChecked() || m_ui->cbxMessageWindow->isChecked(); }, tr("Select at least one reaction") });
|
|
}
|
|
|
|
bool ConfigParticipantsDialog::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
|
|
const std::shared_ptr<AlarmManagement::Interface::Dtc> &almDtc,
|
|
const std::shared_ptr<AlarmManagement::Interface::Ftc> &almFtc,
|
|
const ParticipantManagement::ParticipantData &participantData,
|
|
const std::vector<int> &participantVector,
|
|
const std::vector<int> &equipmentVector)
|
|
{
|
|
if (!ppmDtc || !almDtc || !almFtc)
|
|
return false;
|
|
|
|
m_ppmDtc = ppmDtc;
|
|
m_almFtc = almFtc;
|
|
m_almDtc = almDtc;
|
|
m_participantVector = participantVector;
|
|
m_participantData = participantData;
|
|
|
|
m_operatorId = LtsSessionData::LtsSessionData::getInstance()->getOperatorId();
|
|
|
|
m_ui->lbHierarchy->setText(m_ppmDtc->hierarchyFromParticipant(m_participantData.id()));
|
|
|
|
QString equipmentNumbersStr;
|
|
if (participantData.equipmentNumber().is_set())
|
|
{
|
|
equipmentNumbersStr.append(QString::number(participantData.equipmentNumber().get()));
|
|
equipmentNumbersStr.append(QStringLiteral(": "));
|
|
}
|
|
|
|
for (const int equipNo : equipmentVector)
|
|
equipmentNumbersStr += QString::number(equipNo) + QStringLiteral(", ");
|
|
equipmentNumbersStr.chop(2);
|
|
|
|
m_ui->equipmentNoContent->setText(equipmentNumbersStr);
|
|
|
|
DEBUG_LOG(m_logger) << "current participantId = " << participantData.id();
|
|
|
|
m_typeClass = ppmDtc->type(participantData.typeId()).typeClass();
|
|
DEBUG_LOG(m_logger) << "m_typeClass=" << m_typeClass << " TypeId=" << participantData.typeId();
|
|
fillCbx();
|
|
|
|
m_almDtc->alarmConfigs([this](const AlarmManagement::AlarmConfig &alarm) { setAlaramData(alarm); });
|
|
return true;
|
|
}
|
|
|
|
void ConfigParticipantsDialog::setAlaramData(const AlarmManagement::AlarmConfig &alarm)
|
|
{
|
|
DEBUG_LOG(m_logger) << "setAlaramData:" << alarm;
|
|
if (alarm.operatorId() != m_operatorId ||
|
|
alarm.participantId() != m_participantData.id() ||
|
|
alarm.global())
|
|
return;
|
|
|
|
switch (alarm.eventTypeId().underlying())
|
|
{
|
|
case ProjectDataManagement::EventType_def::Hit:
|
|
{
|
|
DEBUG_LOG(m_logger) << "Hit zuweisen ";
|
|
m_ui->cbxDirectFire->setChecked(true);
|
|
m_ui->cbxSetMarker->setChecked(alarm.setMarker());
|
|
m_ui->cbxMessageWindow->setChecked(alarm.messageWindow());
|
|
if (alarm.vulnerabilityState() >= 0)
|
|
{
|
|
ProjectDataManagement::VulnerabilityState vulState = static_cast<ProjectDataManagement::VulnerabilityState_def::type>(alarm.vulnerabilityState());
|
|
int index = m_ui->cbStatusDirect->findData(QVariant(vulState.underlying()));
|
|
m_ui->cbStatusDirect->setCurrentIndex(index);
|
|
}
|
|
break;
|
|
}
|
|
case ProjectDataManagement::EventType_def::HitEffectSimulation:
|
|
{
|
|
DEBUG_LOG(m_logger) << "HitIndirect zuweisen ";
|
|
m_ui->cbxIndirectFire->setChecked(true);
|
|
m_ui->cbxSetMarker->setChecked(alarm.setMarker());
|
|
m_ui->cbxMessageWindow->setChecked(alarm.messageWindow());
|
|
break;
|
|
}
|
|
case ProjectDataManagement::EventType_def::AirSupport:
|
|
{
|
|
DEBUG_LOG(m_logger) << "AirSupport zuweisen ";
|
|
m_ui->cbxAirSupport->setChecked(true);
|
|
m_ui->cbxSetMarker->setChecked(alarm.setMarker());
|
|
m_ui->cbxMessageWindow->setChecked(alarm.messageWindow());
|
|
break;
|
|
}
|
|
case ProjectDataManagement::EventType_def::HitMine:
|
|
{
|
|
DEBUG_LOG(m_logger) << "HitMine zuweisen ";
|
|
m_ui->cbxMines->setChecked(true);
|
|
m_ui->cbxSetMarker->setChecked(alarm.setMarker());
|
|
m_ui->cbxMessageWindow->setChecked(alarm.messageWindow());
|
|
break;
|
|
}
|
|
case ProjectDataManagement::EventType_def::HitB:
|
|
case ProjectDataManagement::EventType_def::HitN:
|
|
case ProjectDataManagement::EventType_def::HitC:
|
|
{
|
|
DEBUG_LOG(m_logger) << "Hit N/B/C zuweisen ";
|
|
m_ui->cbxNbcAgent->setChecked(true);
|
|
m_ui->cbxSetMarker->setChecked(alarm.setMarker());
|
|
m_ui->cbxMessageWindow->setChecked(alarm.messageWindow());
|
|
break;
|
|
}
|
|
case ProjectDataManagement::EventType_def::FriendlyFire:
|
|
{
|
|
DEBUG_LOG(m_logger) << "FriendlyFire zuweisen ";
|
|
m_ui->cbxFriendlyFire->setChecked(true);
|
|
m_ui->cbxSetMarker->setChecked(alarm.setMarker());
|
|
m_ui->cbxMessageWindow->setChecked(alarm.messageWindow());
|
|
if (alarm.vulnerabilityState() >= 0)
|
|
{
|
|
ProjectDataManagement::VulnerabilityState vulState = static_cast<ProjectDataManagement::VulnerabilityState_def::type>(alarm.vulnerabilityState());
|
|
int index = m_ui->cbStatusDirect->findData(QVariant(vulState.underlying()));
|
|
m_ui->cbStatusFriendly->setCurrentIndex(index);
|
|
}
|
|
break;
|
|
}
|
|
case ProjectDataManagement::EventType_def::Manipulation:
|
|
{
|
|
DEBUG_LOG(m_logger) << "Manipulation zuweisen ";
|
|
m_ui->cbxManipulation->setChecked(true);
|
|
m_ui->cbxSetMarker->setChecked(alarm.setMarker());
|
|
m_ui->cbxMessageWindow->setChecked(alarm.messageWindow());
|
|
break;
|
|
}
|
|
case ProjectDataManagement::EventType_def::CrossGlobalBorderline:
|
|
{
|
|
DEBUG_LOG(m_logger) << "CrossGlobalBorderline zuweisen ";
|
|
m_ui->cbxGlobalBorderLine->setChecked(true);
|
|
m_ui->cbxSetMarker->setChecked(alarm.setMarker());
|
|
m_ui->cbxMessageWindow->setChecked(alarm.messageWindow());
|
|
break;
|
|
}
|
|
case ProjectDataManagement::EventType_def::CrossLocalBorderline:
|
|
{
|
|
DEBUG_LOG(m_logger) << "CrossLocalBorderline zuweisen ";
|
|
m_ui->cbxLocalBorderLine->setChecked(true);
|
|
m_ui->cbxSetMarker->setChecked(alarm.setMarker());
|
|
m_ui->cbxMessageWindow->setChecked(alarm.messageWindow());
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
ERROR_LOG(m_logger) << "Not possible to set with Operator App!!!";
|
|
}
|
|
}
|
|
}
|
|
|
|
std::vector<AlarmManagement::AlarmAction> ConfigParticipantsDialog::getCheckedValues() const
|
|
{
|
|
AlarmManagement::AlarmAction alarmActionDds;
|
|
DEBUG_LOG(m_logger) << "getCheckedValues";
|
|
|
|
std::vector<AlarmManagement::AlarmAction> alarmsDds;
|
|
|
|
alarmActionDds.setMarker(m_ui->cbxSetMarker->isChecked());
|
|
alarmActionDds.messageWindow(m_ui->cbxMessageWindow->isChecked());
|
|
alarmActionDds.vulnerabilityState(-1); // Default All Types
|
|
|
|
if (alarmActionDds.setMarker() || alarmActionDds.messageWindow())
|
|
{
|
|
if (m_ui->cbxDirectFire->isChecked())
|
|
{
|
|
alarmActionDds.eventTypeId(ProjectDataManagement::EventType_def::Hit);
|
|
int statusDirect = -1;
|
|
if (m_ui->cbStatusDirect->currentIndex() > 0)
|
|
statusDirect = m_ui->cbStatusDirect->currentData().toInt();
|
|
alarmActionDds.vulnerabilityState(statusDirect);
|
|
alarmsDds.push_back(alarmActionDds);
|
|
}
|
|
if (m_ui->cbxFriendlyFire->isChecked())
|
|
{
|
|
alarmActionDds.eventTypeId(ProjectDataManagement::EventType_def::FriendlyFire);
|
|
int statusFriendly = -1;
|
|
if (m_ui->cbStatusFriendly->currentIndex() > 0)
|
|
statusFriendly = m_ui->cbStatusFriendly->currentData().toInt();
|
|
alarmActionDds.vulnerabilityState(statusFriendly);
|
|
alarmsDds.push_back(alarmActionDds);
|
|
}
|
|
alarmActionDds.vulnerabilityState(-1); // Default All Types
|
|
if (m_ui->cbxIndirectFire->isChecked())
|
|
{
|
|
alarmActionDds.eventTypeId(ProjectDataManagement::EventType_def::HitEffectSimulation);
|
|
alarmsDds.push_back(alarmActionDds);
|
|
}
|
|
if (m_ui->cbxAirSupport->isChecked())
|
|
{
|
|
alarmActionDds.eventTypeId(ProjectDataManagement::EventType_def::AirSupport);
|
|
alarmsDds.push_back(alarmActionDds);
|
|
}
|
|
if (m_ui->cbxMines->isChecked())
|
|
{
|
|
alarmActionDds.eventTypeId(ProjectDataManagement::EventType_def::HitMine);
|
|
alarmsDds.push_back(alarmActionDds);
|
|
}
|
|
if (m_ui->cbxNbcAgent->isChecked())
|
|
{
|
|
alarmActionDds.eventTypeId(ProjectDataManagement::EventType_def::HitN);
|
|
alarmsDds.push_back(alarmActionDds);
|
|
alarmActionDds.eventTypeId(ProjectDataManagement::EventType_def::HitB);
|
|
alarmsDds.push_back(alarmActionDds);
|
|
alarmActionDds.eventTypeId(ProjectDataManagement::EventType_def::HitC);
|
|
alarmsDds.push_back(alarmActionDds);
|
|
}
|
|
if (m_ui->cbxManipulation->isChecked())
|
|
{
|
|
alarmActionDds.eventTypeId(ProjectDataManagement::EventType_def::Manipulation);
|
|
alarmsDds.push_back(alarmActionDds);
|
|
}
|
|
if (m_ui->cbxGlobalBorderLine->isChecked())
|
|
{
|
|
alarmActionDds.eventTypeId(ProjectDataManagement::EventType_def::CrossGlobalBorderline);
|
|
alarmsDds.push_back(alarmActionDds);
|
|
}
|
|
if (m_ui->cbxLocalBorderLine->isChecked())
|
|
{
|
|
alarmActionDds.eventTypeId(ProjectDataManagement::EventType_def::CrossLocalBorderline);
|
|
alarmsDds.push_back(alarmActionDds);
|
|
}
|
|
}
|
|
return alarmsDds;
|
|
}
|
|
|
|
bool ConfigParticipantsDialog::apply()
|
|
{
|
|
DEBUG_LOG(m_logger) << "apply";
|
|
AlarmManagement::ConfigureAlarmsRequest req;
|
|
req.participantIds(m_participantVector);
|
|
req.alarms(getCheckedValues());
|
|
req.operatorId(m_operatorId);
|
|
req.global(false);
|
|
req.remove(false);
|
|
|
|
return m_requestHelper->startSingleRequest([req, this]()
|
|
{
|
|
return m_almFtc->configureAlarmsRequest(req, this);
|
|
});
|
|
}
|
|
|
|
void ConfigParticipantsDialog::fillCbx()
|
|
{
|
|
m_ui->cbStatusDirect->clear();
|
|
m_ui->cbStatusFriendly->clear();
|
|
//Vulnerability
|
|
m_ui->cbStatusDirect->addItem(tr("All Types"), -1);
|
|
m_ui->cbStatusFriendly->addItem(tr("All Types"), -1);
|
|
ParticipantManagement::insertVulnerabilityStates(m_ui->cbStatusDirect, m_typeClass);
|
|
ParticipantManagement::insertVulnerabilityStates(m_ui->cbStatusFriendly, m_typeClass);
|
|
m_ui->cbStatusDirect->removeItem(m_ui->cbStatusDirect->findData(ProjectDataManagement::VulnerabilityState::TemporarySeverance));
|
|
m_ui->cbStatusFriendly->removeItem(m_ui->cbStatusDirect->findData(ProjectDataManagement::VulnerabilityState::TemporarySeverance));
|
|
}
|
|
|
|
} // namespace ParticipantAlarms
|
|
|