254 lines
7.0 KiB
C++
Executable File
254 lines
7.0 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* HMI Plugin for Messaging - Messaging Model
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Chrsitian Roeskens, NLSE, 2018-05-03
|
|
*/
|
|
|
|
#include "taboc_sfm_messaging_model.h"
|
|
#include <LtsSession/lts_session.h>
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <QtGui/QFont>
|
|
#include <QtGlobal>
|
|
|
|
#include <ngltools/ngltools_dtg.h>
|
|
#include <LtsUtilsSettings/settings.h>
|
|
|
|
namespace TrainingAreaBaseOC
|
|
{
|
|
//---------------------------------
|
|
// Messaging
|
|
//---------------------------------
|
|
MessagingModel::MessagingModel(QObject *parent)
|
|
: LtsWidgets::LtsAbstractTableModel<Entry>({tr("Time"), tr("Message")}, parent)
|
|
, m_dtc(nullptr)
|
|
, m_operatorId(0)
|
|
, m_lastClearTime(0)
|
|
, m_logger(getLogger("MessagingModel"))
|
|
{}
|
|
|
|
|
|
bool MessagingModel::initModel(const std::shared_ptr<TrainingAreaBaseOC::Interface::Dtc> &dtc, qint64 lastClearTime)
|
|
{
|
|
m_dtc = dtc;
|
|
m_operatorId = LtsSessionData::LtsSessionData::getInstance()->getOperatorId();
|
|
m_lastClearTime = lastClearTime;
|
|
connect(m_dtc.get(), &Interface::Dtc::freeTextChanged, this,
|
|
[this](const TrainingAreaBaseOC::FreeText & data, DataModification modType) { insertData(data, modType);});
|
|
|
|
connect(m_dtc.get(), &Interface::Dtc::shortMessageChanged, this,
|
|
[this](const TrainingAreaBaseOC::ShortMessage & data, DataModification modType) { insertData(data, modType);});
|
|
|
|
// init Model
|
|
m_dtc->freeTexts([this](const TrainingAreaBaseOC::FreeText & data) { insertData(data); });
|
|
m_dtc->shortMessages([this](const TrainingAreaBaseOC::ShortMessage & data) { insertData(data); });
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
void MessagingModel::insertData(const TrainingAreaBaseOC::FreeText &data, DataModification modType)
|
|
{
|
|
if (modType == DataModification::eRemoved)
|
|
return;
|
|
|
|
if (dontAdd(data.timeStamp()))
|
|
return;
|
|
|
|
QString text = QString::fromStdString(data.text().c_str());
|
|
if (text.size() > 1)
|
|
text.chop(1);
|
|
QString msg = tr("Text: %1").arg(text);
|
|
|
|
insertRow({QDateTime::fromMSecsSinceEpoch(data.timeStamp()), msg});
|
|
}
|
|
|
|
void MessagingModel::insertData(const TrainingAreaBaseOC::ShortMessage &data, DataModification modType)
|
|
{
|
|
if (modType == DataModification::eRemoved)
|
|
return;
|
|
|
|
if (dontAdd(data.timeStamp()))
|
|
return;
|
|
|
|
/*
|
|
QString msg = tr("Type: %1 VGB: %2 VBA: %3")
|
|
.arg(textTypeToString(static_cast<TextType>(data.textType())))
|
|
.arg(data.indexVbg())
|
|
.arg(data.indexVba());
|
|
}
|
|
*/
|
|
QString msg = tr("Type: %1 - %2")
|
|
.arg(textTypeToString(static_cast<TextType>(data.textType())),
|
|
vbgVbaIndexToText(data.textType(), data.indexVbg()));
|
|
|
|
insertRow({QDateTime::fromMSecsSinceEpoch(data.timeStamp()), msg});
|
|
}
|
|
|
|
|
|
bool MessagingModel::dontAdd(qint64 timeToCheck)
|
|
{
|
|
qint64 checktime = m_lastClearTime;
|
|
if (checktime == 0)
|
|
{
|
|
checktime = QDateTime::currentMSecsSinceEpoch()-10000;
|
|
}
|
|
|
|
if (timeToCheck < (QDateTime::currentMSecsSinceEpoch() - (60 * 60 * 1000 * 1)))
|
|
return true;
|
|
|
|
if(timeToCheck < checktime)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
QString MessagingModel::textTypeToString(TextType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case TextType::test : return tr("Test");
|
|
case TextType::UnderFire : return tr("UnderFire");
|
|
case TextType::Injury : return tr("Injury");
|
|
case TextType::Manipulation : return tr("Manipulation");
|
|
case TextType::Kill : return tr("Kill");
|
|
case TextType::State : return tr("State");
|
|
case TextType::Error : return tr("Error");
|
|
case TextType::Activation : return tr("Activation");
|
|
case TextType::Messages : return tr("Messages");
|
|
case TextType::AcousticOutputOnly : return tr("AcousticOutputOnly");
|
|
case TextType::ClearDisplay : return tr("ClearDisplay");
|
|
}
|
|
return tr("Unknown (%1)").arg(int(type));
|
|
}
|
|
|
|
QString MessagingModel::vbgVbaIndexToText(int type, int vbg)
|
|
{
|
|
|
|
QString defaultError = tr("Unknown Message: (%1)").arg(vbg);
|
|
switch (type)
|
|
{
|
|
case 5:
|
|
{
|
|
switch (vbg)
|
|
{
|
|
case 1:
|
|
return tr("Active Equipment");
|
|
case 3:
|
|
return tr("Active Player Unit");
|
|
case 4:
|
|
return tr("Active Equipment");
|
|
case 5:
|
|
return tr("Connection Setup to Player Unit");
|
|
case 6:
|
|
return tr("Active Radio Communication");
|
|
case 7:
|
|
return tr("Ready for Action");
|
|
default:
|
|
return defaultError;
|
|
} // vbg5
|
|
}
|
|
case 6:
|
|
{
|
|
QString ret = tr("Error:") + QLatin1Char(' ');
|
|
switch (vbg)
|
|
{
|
|
case 10:
|
|
return ret + tr("Configuration");
|
|
case 11:
|
|
return ret + tr("No Radio Communication");
|
|
case 12:
|
|
return ret + tr("Login");
|
|
case 13:
|
|
return ret + tr("Licensing");
|
|
case 20:
|
|
return ret + tr("Player Unit");
|
|
case 21:
|
|
return ret + tr("Voltage Player Unit");
|
|
case 40:
|
|
return ret + tr("Effect Display");
|
|
case 50:
|
|
return ret + tr("Mine Sensor System");
|
|
case 60:
|
|
return ret + tr("Tactical Engagement Simulator"); //AGDUS
|
|
case 70:
|
|
return ret + tr("Special Sensor System");
|
|
case 80:
|
|
return ret + tr("Disply Unit");
|
|
case 90:
|
|
{
|
|
LtsUtils::ProjectSettings *ps = LtsUtils::ProjectSettings::getInstance();
|
|
bool enableB = ps->value(QStringLiteral("aes"),
|
|
QStringLiteral("enableBiologicalContamination")).toBool();
|
|
bool enableC = ps->value(QStringLiteral("aes"),
|
|
QStringLiteral("enableChemicalContamination")).toBool();
|
|
bool enableN = ps->value(QStringLiteral("aes"),
|
|
QStringLiteral("enableNuclearContaminations")).toBool();
|
|
|
|
if (!enableB && !enableC && enableN)
|
|
return ret + tr("N Protection Sensor System");
|
|
else if (enableB && !enableC && enableN)
|
|
return ret + tr("NB Protection Sensor System");
|
|
else if (!enableB && enableC && enableN)
|
|
return ret + tr("NC Protection Sensor System");
|
|
else if (enableB && !enableC && !enableN)
|
|
return ret + tr("B Protection Sensor System");
|
|
else if (enableB && enableC && !enableN)
|
|
return ret + tr("BC Protection Sensor System");
|
|
else if (!enableB && enableC && !enableN)
|
|
return ret + tr("C Protection Sensor System");
|
|
else
|
|
return ret + tr("NBC Protection Sensor System");
|
|
}
|
|
default:
|
|
return defaultError;
|
|
}
|
|
}
|
|
case 8:
|
|
{
|
|
return tr("Active Pos");
|
|
}
|
|
|
|
default:
|
|
return defaultError;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
QVariant MessagingModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (!indexIsValid(index))
|
|
return QVariant();
|
|
|
|
const Entry &data = m_vecData.at(index.row());
|
|
|
|
if (role == Qt::DisplayRole)
|
|
{
|
|
switch (index.column())
|
|
{
|
|
case 0:
|
|
return data.m_date;
|
|
case 1:
|
|
return data.m_msg;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return QVariant();
|
|
}
|
|
|
|
void MessagingModel::clearModel()
|
|
{
|
|
ERROR_LOG(m_logger) << QDateTime::currentMSecsSinceEpoch();
|
|
m_lastClearTime = QDateTime::currentMSecsSinceEpoch();
|
|
ERROR_LOG(m_logger) << m_lastClearTime;
|
|
|
|
clear();
|
|
}
|
|
|
|
} // namespace TrainingAreaBaseOC
|