Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,382 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Gui Plugin for EffectShowClient
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2016-10-05
|
||||
*/
|
||||
|
||||
|
||||
#include "esc_effect_show_gui_plugin.h"
|
||||
#include "esc_order_list.h"
|
||||
#include "esc_operating_condition.h"
|
||||
#include "esc_firing_explosion.h"
|
||||
#include "esc_firing_smoke.h"
|
||||
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsWidgets/lts_base_layout_widget.h>
|
||||
#include <LtsNotification/lts_notification.h>
|
||||
#include <LtsWidgets/lts_events.h>
|
||||
|
||||
#include <Services/EffectShowClient/esc_operator_rights.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QUrlQuery>
|
||||
|
||||
namespace EffectShowClient
|
||||
{
|
||||
|
||||
std::shared_ptr<GuiPluginBase::Interface> GuiPlugin::createGuiInterface(LtsSession::LtsSession *session)
|
||||
{
|
||||
return std::make_shared<InterfaceImpl>(session);
|
||||
}
|
||||
|
||||
const QString InterfaceImpl::s_dmfOrderList = QStringLiteral("escOrderList");
|
||||
|
||||
|
||||
InterfaceImpl::InterfaceImpl(LtsSession::LtsSession *session)
|
||||
: GuiPluginBase::Interface(session, getLogger("Plugins.Gui.Esc.EffectShow"))
|
||||
, m_operationalStatusTimer(new QTimer)
|
||||
{
|
||||
qApp->installEventFilter(this);
|
||||
connect(m_operationalStatusTimer, &QTimer::timeout,
|
||||
this, &InterfaceImpl::onOperationalStatusTimeout);
|
||||
}
|
||||
|
||||
|
||||
bool InterfaceImpl::fetchInterfaces()
|
||||
{
|
||||
if (!m_session->getDtc<EffectShowClient::DataInterface>(m_dtc))
|
||||
return false;
|
||||
if (!m_session->getFtc<EffectShowClient::DataInterface>(m_ftc))
|
||||
return false;
|
||||
if (!m_session->getDtc<TrainingAreaBaseOC::DataInterface>(m_dtcTabOC))
|
||||
WARNING_LOG(m_logger) << "Got no TabOc Dtc. No Distance Measurement";
|
||||
|
||||
m_dtc->enableAll();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InterfaceImpl::clearInterfaces()
|
||||
{
|
||||
m_dtc = nullptr;
|
||||
m_ftc = nullptr;
|
||||
m_dtcTabOC = nullptr;
|
||||
}
|
||||
|
||||
|
||||
QString InterfaceImpl::menuGroup() const
|
||||
{
|
||||
return tr("Effect Representation");
|
||||
}
|
||||
|
||||
|
||||
QVector<LtsWidgets::PluginData> InterfaceImpl::getActions()
|
||||
{
|
||||
QVector<LtsWidgets::PluginData> ret;
|
||||
|
||||
LtsWidgets::PluginData plData;
|
||||
plData.menuGroup = menuGroup();
|
||||
plData.menuText = tr("Order List");
|
||||
plData.identifier = QLatin1String("escOrderList");
|
||||
plData.menuIcon = QIcon(QLatin1String("icon:effect_order_vehicle.svg"));
|
||||
//plData.operatorRight = OperatorRights::EffectShowEdit;
|
||||
plData.exercisePart = LtsWidgets::ExercisePart::eExecution;
|
||||
plData.createWidgetFunc = [this](QWidget * parent)
|
||||
{
|
||||
return onShowOrderList(parent);
|
||||
};
|
||||
m_effecShowAction = plData;
|
||||
|
||||
|
||||
|
||||
plData.menuText = tr("Relocation List");
|
||||
plData.identifier = QLatin1String("escRelocationList");
|
||||
plData.menuIcon = QIcon(QLatin1String("icon:reloc_vehicle.svg"));
|
||||
plData.createWidgetFunc = [this](QWidget * parent)
|
||||
{
|
||||
return onShowRelocationList(parent);
|
||||
};
|
||||
ret.append(plData);
|
||||
|
||||
|
||||
plData.menuText = tr("Operating Condition");
|
||||
plData.identifier = QLatin1String("escOperatingCondition");
|
||||
plData.menuIcon = QIcon(QLatin1String("icon:status_vehicle.svg"));
|
||||
//plData.operatorRight = OperatorRights::RelocationsEdit;
|
||||
plData.createWidgetFunc = [this](QWidget * parent)
|
||||
{
|
||||
return onShowOperatingCondition(parent);
|
||||
};
|
||||
ret.append(plData);
|
||||
|
||||
plData.menuGroup = menuGroup();
|
||||
plData.menuText = tr("Firing Explosive");
|
||||
plData.identifier = QLatin1String("escFiringExplosion");
|
||||
plData.menuIcon = QIcon(QLatin1String("icon:fire_vehicle.svg"));
|
||||
//plData.operatorRight = OperatorRights::ActorEdit;
|
||||
plData.createWidgetFunc = [this](QWidget * parent)
|
||||
{
|
||||
return onShowFiringExplosion(parent);
|
||||
};
|
||||
m_fireAction = plData;
|
||||
|
||||
|
||||
plData.menuGroup = menuGroup();
|
||||
plData.menuText = tr("Firing Smoke");
|
||||
plData.identifier = QLatin1String("escFiringSmoke");
|
||||
plData.menuIcon = QIcon(QLatin1String("icon:smoke_vehicle.svg"));
|
||||
//plData.operatorRight = OperatorRights::VehicleStatusShow;
|
||||
plData.createWidgetFunc = [this](QWidget * parent)
|
||||
{
|
||||
return onShowFiringSmoke(parent);
|
||||
};
|
||||
m_smokeAction = plData;
|
||||
|
||||
|
||||
// Noti:
|
||||
|
||||
plData.createInstant = LtsWidgets::CreateInstantType::CreateInstantAndDiscardAction;
|
||||
plData.identifier = QStringLiteral("DMFIcon");
|
||||
plData.menuText = QStringLiteral("DMFIcon");
|
||||
plData.createWidgetFunc = nullptr;
|
||||
plData.directFunc = [this](const LtsWidgets::PluginData &)
|
||||
{
|
||||
m_notiDmf = m_session->createNotification(QStringLiteral("DMF"));
|
||||
m_notiDmf->setIcon(QIcon(QStringLiteral("icon:status_dmf_red.svg")));
|
||||
m_notiDmf->setToolTip(tr("No DMF"));
|
||||
m_notiDmf->setAction([this]()
|
||||
{
|
||||
LtsWidgets::LtsMessageDialog::showMessage(m_session->baseLayout(), m_notiDmf->tooltip());
|
||||
});
|
||||
};
|
||||
ret.append(plData);
|
||||
m_timer = new QTimer(this);
|
||||
connect(m_timer, &QTimer::timeout, this, &InterfaceImpl::checkLastState);
|
||||
m_timer->start(3000);
|
||||
|
||||
connect(m_dtc.get(), &EffectShowClient::Interface::Dtc::operatingConditionEntityChanged,
|
||||
this, &InterfaceImpl::onOperatingConditionEntityChanged);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void InterfaceImpl::onOperatingConditionEntityChanged(const OperatingConditionEntity &data, DataModification modType)
|
||||
{
|
||||
Q_UNUSED(modType)
|
||||
|
||||
//change icons and actions depending of vehicle type
|
||||
if (data.vehicleFeature() != m_vehicleType)
|
||||
{
|
||||
|
||||
//Change state
|
||||
m_vehicleType = data.vehicleFeature();
|
||||
// Readd action EffectShowOrderList
|
||||
m_session->baseLayout()->addMenuAction(m_effecShowAction);
|
||||
|
||||
if (m_vehicleType == EffectShowManagement::Feature_e::NotSpecified)
|
||||
{
|
||||
m_session->baseLayout()->removeMenuAction(m_fireAction);
|
||||
m_session->baseLayout()->removeMenuAction(m_smokeAction);
|
||||
m_session->baseLayout()->removeMenuAction(m_effecShowAction);
|
||||
m_notiDmf->setIcon(QIcon(QStringLiteral("icon:status_dmf_red.svg")));
|
||||
m_notiDmf->setToolTip(tr("No Effect Show Connected"));
|
||||
// close dialogs
|
||||
if(m_session->baseLayout()->getWidget(menuGroup(), QStringLiteral("escFiringExplosion")))
|
||||
m_session->baseLayout()->getWidget(menuGroup(), QStringLiteral("escFiringExplosion"))->closeRequest();
|
||||
if(m_session->baseLayout()->getWidget(menuGroup(), QStringLiteral("escFiringSmoke")))
|
||||
m_session->baseLayout()->getWidget(menuGroup(), QStringLiteral("escFiringSmoke"))->closeRequest();
|
||||
if(m_session->baseLayout()->getWidget(menuGroup(), QStringLiteral("escOrderList")))
|
||||
m_session->baseLayout()->getWidget(menuGroup(), QStringLiteral("escOrderList"))->closeRequest();
|
||||
}
|
||||
else
|
||||
{
|
||||
QString feature = tr("Effect Show Connected: ");
|
||||
|
||||
if (m_vehicleType == EffectShowManagement::Feature_e::Smoke)
|
||||
{
|
||||
//Feature Smoke
|
||||
m_session->baseLayout()->removeMenuAction(m_fireAction);
|
||||
m_session->baseLayout()->addMenuAction(m_smokeAction);
|
||||
feature += tr("Smoke");
|
||||
if(m_session->baseLayout()->getWidget(menuGroup(), QStringLiteral("escFiringExplosion")))
|
||||
m_session->baseLayout()->getWidget(menuGroup(), QStringLiteral("escFiringExplosion"))->closeRequest();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_vehicleType == EffectShowManagement::Feature_e::Explosion24)
|
||||
feature += tr("Explosion (24)");
|
||||
else
|
||||
feature += tr("Explosion (48)");
|
||||
|
||||
//Feature Explosion
|
||||
m_session->baseLayout()->removeMenuAction(m_smokeAction);
|
||||
m_session->baseLayout()->addMenuAction(m_fireAction);
|
||||
if(m_session->baseLayout()->getWidget(menuGroup(), QStringLiteral("escFiringSmoke")))
|
||||
m_session->baseLayout()->getWidget(menuGroup(), QStringLiteral("escFiringSmoke"))->closeRequest();
|
||||
}
|
||||
m_notiDmf->setIcon(QIcon(QStringLiteral("icon:status_dmf_green.svg")));
|
||||
m_notiDmf->setToolTip(feature);
|
||||
}
|
||||
}
|
||||
|
||||
int currentSmokeLoad = 0;
|
||||
|
||||
// now we send our ammuniton to excon if changed
|
||||
if (m_vehicleType == EffectShowManagement::Feature_e::Smoke)
|
||||
{
|
||||
//send current smoke load to excon
|
||||
if (data.smokeCartridge1().underlying() == EffectShowClient::StatusSmokeCartridge_e_def::Ready)
|
||||
currentSmokeLoad++;
|
||||
if (data.smokeCartridge2().underlying() == EffectShowClient::StatusSmokeCartridge_e_def::Ready)
|
||||
currentSmokeLoad++;
|
||||
if (data.smokeCartridge3().underlying() == EffectShowClient::StatusSmokeCartridge_e_def::Ready)
|
||||
currentSmokeLoad++;
|
||||
if (data.smokeCartridge4().underlying() == EffectShowClient::StatusSmokeCartridge_e_def::Ready)
|
||||
currentSmokeLoad++;
|
||||
if (data.smokeCartridge5().underlying() == EffectShowClient::StatusSmokeCartridge_e_def::Ready)
|
||||
currentSmokeLoad++;
|
||||
|
||||
if (currentSmokeLoad != m_oldSmokeCount)
|
||||
{
|
||||
m_oldSmokeCount = currentSmokeLoad;
|
||||
onSendAmmunition(currentSmokeLoad);
|
||||
}
|
||||
}
|
||||
else if (m_vehicleType != EffectShowManagement::Feature_e::NotSpecified)
|
||||
{
|
||||
// send current magazin load to excon
|
||||
if (m_oldCondition.ammunitionMagazine() != data.ammunitionMagazine())
|
||||
onSendAmmunition();
|
||||
}
|
||||
|
||||
m_lastStatesTime = m_session->partitionTime();
|
||||
|
||||
if (data.readiness() && !m_oldCondition.readiness() && !m_operationalStatusTimer->isActive())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Operating condition: operational. Starting timer.";
|
||||
m_operationalStatusTimer->start(10 * 60 * 1000);
|
||||
} // if
|
||||
|
||||
m_oldCondition = data;
|
||||
m_oldSmokeCount = currentSmokeLoad;
|
||||
}
|
||||
|
||||
void InterfaceImpl::onSendAmmunition(int currentSmokeCount)
|
||||
{
|
||||
const OperatingConditionEntity &condition = m_dtc->operatingConditionEntity();
|
||||
SendAmmunitionRequest req;
|
||||
if (currentSmokeCount >= 0)
|
||||
req.ammunitionMagazine(currentSmokeCount);
|
||||
else
|
||||
req.ammunitionMagazine(condition.ammunitionMagazine());
|
||||
req.ammunitionAvailable(condition.ammunitionAvailable());
|
||||
m_ftc->sendAmmunitionRequest(req, this);
|
||||
}
|
||||
|
||||
void InterfaceImpl::checkLastState()
|
||||
{
|
||||
if ((m_session->partitionTime() - 10 * 1000) > m_lastStatesTime)
|
||||
{
|
||||
m_notiDmf->setIcon(QIcon(QStringLiteral("icon:status_dmf_red.svg")));
|
||||
m_notiDmf->setToolTip(tr("No Effect Show Connected"));
|
||||
m_vehicleType = EffectShowManagement::Feature_e::NotSpecified;
|
||||
}
|
||||
}
|
||||
|
||||
void InterfaceImpl::onOperationalStatusTimeout()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Sending operational status: " << (m_oldCondition.readiness() ? "operational." : "not operational.");
|
||||
SendReadinessRequest req;
|
||||
req.readiness(m_oldCondition.readiness());
|
||||
m_ftc->sendReadinessRequest(req, this);
|
||||
if (!m_oldCondition.readiness())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Operating condition: not operational. Stopping timer.";
|
||||
m_operationalStatusTimer->stop();
|
||||
} // if
|
||||
}
|
||||
|
||||
LtsWidgets::LtsDialog *InterfaceImpl::onShowRelocationList(QWidget *parent)
|
||||
{
|
||||
return LtsWidgets::initDialog(new OrderList(menuGroup(), m_session, parent),
|
||||
false, m_dtc, m_ftc, m_dtcTabOC);
|
||||
}
|
||||
|
||||
LtsWidgets::LtsDialog *InterfaceImpl::onShowOrderList(QWidget *parent)
|
||||
{
|
||||
return LtsWidgets::initDialog(new OrderList(menuGroup(), m_session, parent),
|
||||
true, m_dtc, m_ftc, m_dtcTabOC);
|
||||
}
|
||||
|
||||
void InterfaceImpl::onShowOrderList(bool isEffectShow)
|
||||
{
|
||||
OrderList *dialog = new OrderList(menuGroup(), m_session);
|
||||
if (!dialog->init(isEffectShow, m_dtc, m_ftc, m_dtcTabOC))
|
||||
{
|
||||
delete dialog;
|
||||
return;
|
||||
}
|
||||
m_session->addWidget(dialog, menuGroup(), s_dmfOrderList, LtsWidgets::LayoutArea::eDialogTab);
|
||||
}
|
||||
|
||||
LtsWidgets::LtsDialog *InterfaceImpl::onShowOperatingCondition(QWidget *parent)
|
||||
{
|
||||
return LtsWidgets::initDialog(new OperatingCondition(parent),
|
||||
m_dtc, m_ftc);
|
||||
}
|
||||
|
||||
LtsWidgets::LtsDialog *InterfaceImpl::onShowFiringExplosion(QWidget *parent)
|
||||
{
|
||||
//m_dtc->firingSmokeEntity()
|
||||
return LtsWidgets::initDialog(new FiringExplosion(parent),
|
||||
m_dtc, m_ftc, m_session, true);
|
||||
}
|
||||
|
||||
LtsWidgets::LtsDialog *InterfaceImpl::onShowFiringSmoke(QWidget *parent)
|
||||
{
|
||||
FiringSmoke *dialog = new FiringSmoke(parent);
|
||||
dialog->init(m_dtc, m_ftc, m_session, true);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
bool InterfaceImpl::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
|
||||
if (obj == qApp &&
|
||||
!event->isAccepted() &&
|
||||
event->type() == LtsWidgets::LtsLinkEvent::eventTypeId())
|
||||
{
|
||||
auto ev = static_cast<LtsWidgets::LtsLinkEvent*>(event);
|
||||
|
||||
const auto isChildOfSession = [this](QWidget *w)
|
||||
{
|
||||
if (!w)
|
||||
return true;
|
||||
const auto baseLayout = m_session->baseLayout();
|
||||
return baseLayout->isAncestorOf(w);
|
||||
};
|
||||
|
||||
bool isEffectShow = true;
|
||||
if (isChildOfSession(ev->sourceBaseLayoutWidget()) && ev->url().host() == s_dmfOrderList.toLower())
|
||||
{
|
||||
const QStringList params = ev->url().path().split(QStringLiteral("/"));
|
||||
DEBUG_LOG(m_logger) << "eventFilter onShowOrderList"
|
||||
<< ", path=" << ev->url().path()
|
||||
<< ", params.size=" << params.size();
|
||||
if (params.size() > 1)
|
||||
{
|
||||
isEffectShow = params.at(1).toInt();
|
||||
DEBUG_LOG(m_logger) << "isEffectShow=" << isEffectShow
|
||||
<< ", params.at(0)=" << params.at(0)
|
||||
<< ", params.at(1)=" << params.at(1);
|
||||
}
|
||||
onShowOrderList(isEffectShow);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
} // namespace EffectShowClient
|
||||
Reference in new issue
Block a user