241 lines
7.0 KiB
C++
Executable File
241 lines
7.0 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* HMI Plugin for Observer Controller - Fault Message Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Patric Karwat, SLSE, 2018-03-27
|
|
*/
|
|
|
|
#include "osc_equip_player.h"
|
|
#include "ui_osc_equip_player.h"
|
|
#include <AdvancedSymbology/asb_data_plugin_interface.h>
|
|
#include <PluginInterfaces/gui_plugin_interface.h>
|
|
#include <ParticipantManagement/ppm_ftc.h>
|
|
|
|
namespace OcSituationClient
|
|
{
|
|
|
|
EquipPlayer::EquipPlayer(LtsSession::LtsSession *session, QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
|
, m_session(session)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_selectedParticipantId(-1)
|
|
, m_maxChars(255)
|
|
, m_maxPartChars(35)
|
|
, m_isValid(false)
|
|
, m_model(nullptr)
|
|
, m_ftc(nullptr)
|
|
, m_ppmFtc(nullptr)
|
|
, m_tabocDtc(nullptr)
|
|
, m_ppmDtc(nullptr)
|
|
, m_ppmCbxGui(nullptr)
|
|
, m_ui(new Ui::EquipPlayer)
|
|
, m_logger(getLogger("EquipPlayerDialog"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
setOnlineHelpFilename(QStringLiteral("OC-Equip_Player"));
|
|
|
|
}
|
|
|
|
EquipPlayer::~EquipPlayer()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
bool EquipPlayer::init(const std::shared_ptr<Interface::Ftc> &ftc)
|
|
{
|
|
if (!ftc)
|
|
return false;
|
|
|
|
m_ftc = ftc;
|
|
std::shared_ptr<ParticipantManagement::Interface::Dtc> dtcPpm;
|
|
if (!m_session->getDtc<ParticipantManagement::DataInterface>(dtcPpm))
|
|
return false;
|
|
|
|
if (!m_session->getFtc<ParticipantManagement::DataInterface>(m_ppmFtc))
|
|
return false;
|
|
|
|
|
|
if (!m_session->getDtc<TrainingAreaBaseOC::DataInterface>(m_tabocDtc))
|
|
return false;
|
|
|
|
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
|
|
return false;
|
|
|
|
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(m_ppmCbxGui))
|
|
return false;
|
|
#ifdef TABLET_MODE
|
|
//css didn"t worked
|
|
m_ui->dvParticipants->setIconSize(QSize(50,50));
|
|
#endif
|
|
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> asb;
|
|
m_session->getForeignDataInterface<AdvancedSymbology::DataInterface>(asb);
|
|
m_model = new ParticipantManagement::ParticipantEditModel(this, dtcPpm, asb);
|
|
// only needed to set recursiveFilteringEnabled
|
|
m_proxyModel = new ParticipantManagement::ParticipantTreeFilterProxyModel(this);
|
|
m_proxyModel->setSourceModel(m_model);
|
|
m_proxyModel->setRecursiveFilteringEnabled(true);
|
|
m_ui->dvParticipants->setModel(m_proxyModel);
|
|
|
|
m_ppmCbxGui->fillPartyComboBox(m_ui->cbParty);
|
|
connect(m_ui->dvParticipants, &LtsDataView::LtsDataView::signalSelectionChanged,
|
|
this, &EquipPlayer::onSlotSelectionChanged);
|
|
|
|
|
|
connect(m_ui->cbParty, &LtsWidgets::LtsComboBox::currentTextChanged, this, [this]
|
|
{
|
|
m_model->onReinitModel(m_ui->cbParty->currentData().toInt());
|
|
m_ui->dvParticipants->expandAll();
|
|
});
|
|
|
|
m_model->onReinitModel(m_ui->cbParty->currentData().toInt());
|
|
m_ui->dvParticipants->expandAll();
|
|
m_ui->dvParticipants->setSortIndicator(0, Qt::AscendingOrder);
|
|
|
|
m_ui->leParticipant->setValidator( new QIntValidator(0, 10000, this) );
|
|
|
|
m_ui->lblMaxEq->setText(QStringLiteral("-"));
|
|
m_ui->lblMinEq->setText(QStringLiteral("-"));
|
|
return true;
|
|
}
|
|
|
|
void EquipPlayer::onSlotSelectionChanged()
|
|
{
|
|
m_selectedParticipantId = 0;
|
|
|
|
const auto selIndexes = m_ui->dvParticipants->selectedRows();
|
|
ParticipantManagement::ParticipantData part;
|
|
ParticipantManagement::TypeClass tc;
|
|
if (!selIndexes.isEmpty())
|
|
{
|
|
part = m_model->getParticipantData(selIndexes.first());
|
|
ParticipantManagement::Type tp = m_ppmDtc->type(part.typeId());
|
|
ParticipantManagement::EquipmentType eq= m_ppmDtc->equipmentType(tp.equipmentTypeId());
|
|
m_ui->lblMinEq->setText(QString::number(eq.minEquipNo()));
|
|
m_ui->lblMaxEq->setText(QString::number(eq.maxEquipNo()));
|
|
|
|
tc = tp.typeClass();
|
|
|
|
if ( (tc == ParticipantManagement::TypeClass::Human)
|
|
|| (tc == ParticipantManagement::TypeClass::GroundVehicle)
|
|
|| (tc == ParticipantManagement::TypeClass::Aircraft)
|
|
|| (tc == ParticipantManagement::TypeClass::Vessel)
|
|
|| (tc == ParticipantManagement::TypeClass::WeaponSystem)
|
|
|| (tc == ParticipantManagement::TypeClass::VehicleWithGear) )
|
|
m_isValid = true;
|
|
else
|
|
m_isValid = false;
|
|
|
|
if (part.id())
|
|
m_selectedParticipantId = part.id();
|
|
else
|
|
m_selectedParticipantId = -1;
|
|
}
|
|
else
|
|
{
|
|
m_isValid = false;
|
|
m_selectedParticipantId = -1;
|
|
}
|
|
|
|
slotChangesMade();
|
|
|
|
if (m_selectedParticipantId > 0 && part.equipmentNumber().is_set())
|
|
m_ui->leParticipant->setText(QString::number(part.equipmentNumber().get()));
|
|
else
|
|
m_ui->leParticipant->setText(QString::number(0));
|
|
|
|
m_ui->leParticipant->setEnabled(m_isValid);
|
|
|
|
}
|
|
|
|
void EquipPlayer::retranslate()
|
|
{
|
|
translate(m_ui, tr("Equip Player") );
|
|
m_uiRequirements->clear();
|
|
|
|
m_uiRequirements->addRequirement({m_ui->lblParticpant, [this]() { return checkEqNr(); },
|
|
tr("Set to a valid Number or Equipment Number already exists!")});
|
|
|
|
m_uiRequirements->addRequirement({m_ui->label, [this]() { return m_isValid; },
|
|
tr("Only Participants are Allowed!")});
|
|
|
|
|
|
}
|
|
|
|
bool EquipPlayer::apply()
|
|
{
|
|
if (m_ui->leParticipant->text().toInt() < 0)
|
|
return false;
|
|
SendEquipmentRegistrationRequest req;
|
|
req.equipmentNumber(m_ui->leParticipant->text().toInt());
|
|
req.participantId(m_selectedParticipantId);
|
|
|
|
bool ret = m_requestHelper->startSingleRequest([req, this]()
|
|
{
|
|
return m_ftc->sendEquipmentRegistrationRequest(req, this);
|
|
});
|
|
|
|
//if( ret)
|
|
{
|
|
if (m_ppmDtc->participant(m_selectedParticipantId).equipmentNumber().is_set())
|
|
{
|
|
ParticipantManagement::RegisterParticipantRequest req3;
|
|
req3.participantId(m_selectedParticipantId);
|
|
req3.equipmentNumber(0);
|
|
req3.assignState(ParticipantManagement::ParticipantAssignState::NotAssigned);
|
|
m_requestHelper->startSingleRequest([req3, this]()
|
|
{
|
|
return m_ppmFtc->registerParticipantRequest(req3, this);
|
|
});
|
|
}
|
|
ParticipantManagement::RegisterParticipantRequest req2;
|
|
req2.participantId(m_selectedParticipantId);
|
|
req2.equipmentNumber(req.equipmentNumber());
|
|
req2.assignState(ParticipantManagement::ParticipantAssignState::HandoutExcon);
|
|
m_requestHelper->startSingleRequest([req2, this]()
|
|
{
|
|
return m_ppmFtc->registerParticipantRequest(req2, this);
|
|
});
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
|
|
bool EquipPlayer::checkEqNr()
|
|
{
|
|
m_ui->lblError->setText(QString());
|
|
|
|
if (!m_isValid)
|
|
{
|
|
m_ui->lblError->setText(tr("No valid Participant selected!"));
|
|
return false;;
|
|
}
|
|
|
|
if(m_ui->leParticipant->text().isEmpty())
|
|
{
|
|
m_ui->lblError->setText(tr("Equipment Number is not valid!"));
|
|
return false;;
|
|
}
|
|
|
|
int equipNr = m_ui->leParticipant->text().toInt();
|
|
if (equipNr <= 0)
|
|
return true;
|
|
|
|
std::vector<ParticipantManagement::ParticipantData> data = m_model->participantData(false);
|
|
|
|
for (const auto &part : data)
|
|
{
|
|
if (!part.equipmentNumber().is_set())
|
|
continue;
|
|
if (part.equipmentNumber().is_set() && part.equipmentNumber().get() == equipNr)
|
|
{
|
|
m_ui->lblError->setText(tr("Equipment Number already exists!"));
|
|
return false;;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
} // namespace OcSituationClient
|