215 lines
6.6 KiB
C++
Executable File
215 lines
6.6 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Notifcation plugin for TAB connection states
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Philipp Dassow, SLST, 2017-09-19
|
|
*/
|
|
|
|
#include "taboc_gui_plugin.h"
|
|
|
|
#include <LtsSession/lts_session.h>
|
|
#include <LtsNotification/lts_notification.h>
|
|
#include <TrainingAreaBaseOC/logger.h>
|
|
#include <LtsUtilsSettings/settings.h>
|
|
#include <LtsWidgets/lts_message_dialog.h>
|
|
#include <LtsWidgets/lts_base_layout_widget.h> // as parent for message dialogs
|
|
|
|
#include <QCoreApplication>
|
|
|
|
namespace TrainingAreaBaseOC
|
|
{
|
|
std::shared_ptr<GuiPluginBase::Interface> GuiPlugin::createGuiInterface(LtsSession::LtsSession *session)
|
|
{
|
|
return std::make_shared<InterfaceImpl>(session);
|
|
}
|
|
|
|
InterfaceImpl::InterfaceImpl(LtsSession::LtsSession *session)
|
|
: GuiPluginBase::Interface(session, getLogger("Notification"))
|
|
, m_dtc(nullptr)
|
|
, m_ppmDtc(nullptr)
|
|
, m_sitMapGuiIfc(nullptr)
|
|
, m_notiPos(nullptr)
|
|
, m_notiRadio(nullptr)
|
|
, m_notiSfm(nullptr)
|
|
{
|
|
connect(m_session, &LtsSession::LtsSession::signalDoneInitializingSession, // workaround to only receive the signal once
|
|
this, &InterfaceImpl::onInitDone);
|
|
}
|
|
|
|
QVector<LtsWidgets::PluginData> InterfaceImpl::getActions()
|
|
{
|
|
QVector<LtsWidgets::PluginData> ret;
|
|
|
|
LtsWidgets::PluginData plData;
|
|
plData.menuGroup = menuGroup();
|
|
plData.createInstant = LtsWidgets::CreateInstantType::CreateInstantAndDiscardAction;
|
|
|
|
//center to own postion:
|
|
plData.directFunc = [this](const LtsWidgets::PluginData &)
|
|
{
|
|
m_notiPos = m_session->createNotification(QStringLiteral("tabOcCenterToPos"));
|
|
m_notiPos->setIcon(QIcon(QLatin1String("icon:center_to_object.svg")));
|
|
m_notiPos->setToolTip(tr("Center Map to Position"));
|
|
m_notiPos->setAction([this]()
|
|
{
|
|
//do the map thing here
|
|
int participantId = m_ppmDtc->participantIdByEquipmentNumber(m_dtc->specificsEquipment(1).equipmentNumber());
|
|
if (participantId > 0)
|
|
m_sitMapGuiIfc->centerMapToParticipant(participantId);
|
|
}
|
|
);
|
|
|
|
};
|
|
ret.append(plData);
|
|
|
|
//Radio Connection:
|
|
plData.directFunc = [this](const LtsWidgets::PluginData &)
|
|
{
|
|
m_notiRadio = m_session->createNotification(QStringLiteral("TabOcTetraConnection"));
|
|
setDefaultToolTipRadio();
|
|
m_notiRadio->setAction([this]()
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(m_session->baseLayout(), m_notiRadio->tooltip());
|
|
});
|
|
};
|
|
ret.append(plData);
|
|
|
|
//Sfm Connection
|
|
plData.directFunc = [this](const LtsWidgets::PluginData &)
|
|
{
|
|
m_notiSfm = m_session->createNotification(QStringLiteral("TabOcSfmConnection"));
|
|
setDefaultToolTipSfm();
|
|
m_notiSfm->setAction([this]()
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(m_session->baseLayout(), m_notiSfm->tooltip());
|
|
});
|
|
};
|
|
ret.append(plData);
|
|
|
|
connect(m_dtc.get(), &TrainingAreaBaseOC::Interface::Dtc::technicalStateSfmChanged, this, &InterfaceImpl::onStatusSfmChanged);
|
|
|
|
return ret;
|
|
}
|
|
|
|
bool InterfaceImpl::fetchInterfaces()
|
|
{
|
|
if (!m_session->getDtc<TrainingAreaBaseOC::DataInterface>(m_dtc))
|
|
return false;
|
|
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
|
|
return false;
|
|
if (!m_session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(m_sitMapGuiIfc))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
void InterfaceImpl::clearInterfaces()
|
|
{
|
|
m_dtc = nullptr;
|
|
m_ppmDtc = nullptr;
|
|
m_sitMapGuiIfc = nullptr;
|
|
}
|
|
|
|
void InterfaceImpl::onStatusSfmChanged(const TechnicalStateSfm &data, DataModification modType)
|
|
{
|
|
Q_UNUSED(modType)
|
|
setRadioStatus(data.radioAvailable(), data.licensed());
|
|
setSfmStatus(data.sfmConnected());
|
|
|
|
if (m_notiRadio != nullptr)
|
|
m_notiRadio->setToolTip(data.licensed() ? tr("Licensed") : tr("Not Licensed")); //set licenced text
|
|
}
|
|
|
|
void InterfaceImpl::setRadioStatus(bool isAvilable, bool isLicensed)
|
|
{
|
|
if (!m_notiRadio)
|
|
return;
|
|
|
|
if (isAvilable && isLicensed)
|
|
m_notiRadio->setIcon(QIcon(QStringLiteral("icon:network-wireless-green.svg")));
|
|
else if (isAvilable)
|
|
m_notiRadio->setIcon(QIcon(QStringLiteral("icon:network-wireless-yellow.svg")));
|
|
else
|
|
m_notiRadio->setIcon(QIcon(QStringLiteral("icon:network-wireless-red.svg")));
|
|
}
|
|
|
|
void InterfaceImpl::setSfmStatus(bool isConnected)
|
|
{
|
|
if (!m_notiSfm)
|
|
return;
|
|
|
|
if (isConnected)
|
|
{
|
|
m_notiSfm->setIcon(QIcon(QStringLiteral("icon:pu-green.svg")));
|
|
m_notiSfm->setToolTip(tr("Connected to Sfm"));
|
|
}
|
|
else
|
|
{
|
|
m_notiSfm->setIcon(QIcon(QStringLiteral("icon:pu-red.svg")));
|
|
m_notiSfm->setToolTip(tr("No Sfm connection"));
|
|
}
|
|
}
|
|
|
|
void InterfaceImpl::setDefaultToolTipRadio()
|
|
{
|
|
m_notiRadio->setToolTip(tr("No Radio Connection"));
|
|
}
|
|
|
|
void InterfaceImpl::setDefaultToolTipSfm()
|
|
{
|
|
m_notiSfm->setToolTip(tr("No Connection to Sfm"));
|
|
m_notiSfm->setAction([this]()
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(m_session->baseLayout(), m_notiSfm->tooltip());
|
|
});
|
|
}
|
|
|
|
void InterfaceImpl::onInitDone()
|
|
{
|
|
disconnect(m_session, &LtsSession::LtsSession::signalDoneInitializingSession,
|
|
this, nullptr); // workaround to only receive the signal once
|
|
|
|
if (appId() != LtsAppDescriptor::App::OC)
|
|
return;
|
|
|
|
if (m_dtc)
|
|
{
|
|
TechnicalStateSfm currentState = m_dtc->technicalStateSfm(1);
|
|
onStatusSfmChanged(currentState, DataModification());
|
|
}
|
|
|
|
connect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::participantPositionChanged, this, &InterfaceImpl::onPositionChanged);
|
|
connect(m_dtc.get(), &TrainingAreaBaseOC::Interface::Dtc::specificsEquipmentChanged, this, &InterfaceImpl::onSpecificsEquipmentChanged);
|
|
|
|
m_curParticipantId = m_ppmDtc->participantIdByEquipmentNumber(m_dtc->specificsEquipment(1).equipmentNumber());
|
|
if (m_curParticipantId)
|
|
onPositionChanged(m_ppmDtc->participantPosition(m_curParticipantId), DataModification::eAdded);
|
|
|
|
}
|
|
|
|
void InterfaceImpl::onPositionChanged(const ParticipantManagement::ParticipantPosition &data, DataModification modType)
|
|
{
|
|
if (modType == DataModification::eRemoved)
|
|
return;
|
|
|
|
if (m_curParticipantId <= 0)
|
|
m_curParticipantId = m_ppmDtc->participantIdByEquipmentNumber(m_dtc->specificsEquipment(1).equipmentNumber());
|
|
|
|
if (data.participantId() == m_curParticipantId)
|
|
{
|
|
if (LtsUtils::OperatorSettings::getInstance()->value(QStringLiteral("ObserverController"), QStringLiteral("MovingMapToSelf"), false).toBool())
|
|
m_sitMapGuiIfc->setCenterPoint(QPointF(data.pos().lon(), data.pos().lat())); // setCenterPoint, as the sitmapPlugin could still have an old position
|
|
}
|
|
}
|
|
|
|
void InterfaceImpl::onSpecificsEquipmentChanged(const TrainingAreaBaseOC::SpecificsEquipment &data, DataModification modType)
|
|
{
|
|
if (modType == DataModification::eRemoved)
|
|
return;
|
|
m_curParticipantId = m_ppmDtc->participantIdByEquipmentNumber(data.equipmentNumber());
|
|
}
|
|
|
|
} // namespace TrainingAreaBaseOC
|