313 lines
9.2 KiB
C++
Executable File
313 lines
9.2 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* AreaEffectSimulation - Charge Effect Edit Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Astrid Müller, ESZE, 2025-08-19
|
|
*/
|
|
|
|
|
|
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <LtsUtilsSettings/settings.h>
|
|
#include <ParticipantManagement/ppm_translation.h>
|
|
#include <Plugins/AreaEffectSimulation/aes_data_plugin_interface.h>
|
|
#include <Plugins/SituationMapPlugin/situation_map_gui_plugin_interface.h>
|
|
#include <PluginInterfaces/gui_plugin_interface.h>
|
|
|
|
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
|
|
#include <Plugins/ParticipantManagement/Gui/ParticipantSelection/participant_selection.h>
|
|
#include <Plugins/ParticipantManagement/Gui/Common/participant_edit_model.h>
|
|
#include <AreaEffectSimulation/Utils/polygons.h>
|
|
#include <AreaEffectSimulation/aes_translation.h>
|
|
#include <SituationMap/Map/map.h>
|
|
|
|
|
|
#include "aes_charge_effect_edit.h"
|
|
#include "ui_aes_charge_effect_edit.h"
|
|
#include <QDebug>
|
|
|
|
|
|
namespace AreaEffectSimulation
|
|
{
|
|
|
|
ChargeEffectEdit::ChargeEffectEdit(const QString &menuGroup, QWidget *parent)
|
|
: BaseEdit(menuGroup, QLatin1String("ChargeEffectEdit"), parent, LtsWidgets::ButtonCombination::CloseOnly)
|
|
, m_ui(new Ui::ChargeEffectEdit)
|
|
{
|
|
m_ui->setupUi(this);
|
|
m_ui->pbPosition->setEnabled(false);
|
|
m_ui->lblFuze->setVisible(false);
|
|
m_ui->cbFuze->setVisible(false);
|
|
m_ui->lblWeapon->setVisible(false);
|
|
m_ui->cbWeapon->setVisible(false);
|
|
enaDisa();
|
|
setOnlineHelpFilename(QStringLiteral("Situation-Add_Charge_Effect"));
|
|
}
|
|
|
|
ChargeEffectEdit::~ChargeEffectEdit()
|
|
{
|
|
m_sitMapGuiIfc = nullptr;
|
|
delete m_ui;
|
|
}
|
|
|
|
bool ChargeEffectEdit::apply()
|
|
{
|
|
DEBUG_LOG(m_logger) << "Apply";
|
|
return true;
|
|
}
|
|
|
|
void ChargeEffectEdit::showPreviewObject()
|
|
{
|
|
|
|
}
|
|
|
|
bool ChargeEffectEdit::init(int areaId, bool copy,
|
|
LtsSession::LtsSession *session)
|
|
{
|
|
Q_UNUSED(copy)
|
|
|
|
if (!BaseEdit::init(areaId, session)) //areaId is aesItemId
|
|
return false;
|
|
|
|
if (!session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(m_sitMapGuiIfc))
|
|
return false;
|
|
|
|
if (!session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
|
|
return false;
|
|
|
|
// PDM
|
|
if (!session->getDtc<ProjectDataManagement::DataInterface>(m_pdmDtc))
|
|
{
|
|
ERROR_LOG(m_logger) << " failed to get pdmDtc";
|
|
return false;
|
|
}
|
|
m_pdmDtc->waitForHistoricalDataChargeType(1000);
|
|
m_pdmDtc->waitForHistoricalDataGearType(1000);
|
|
m_pdmDtc->waitForHistoricalDataGearTypeChargeType(1000);
|
|
|
|
connect(m_ui->cbPlayer, &QCheckBox::toggled, this, &ChargeEffectEdit::onChangeParty);
|
|
|
|
bool editable = LtsSessionData::LtsSessionData::getInstance()->hasOperatorRight(OperatorRights::ChargeEffectEdit) &&
|
|
m_session->app() != LtsAppDescriptor::App::OC;
|
|
|
|
if (!editable)
|
|
return false;
|
|
|
|
session->getForeignDataInterface<AdvancedSymbology::DataInterface>(m_asb);
|
|
m_participantModel = new ParticipantManagement::ParticipantEditModel(this, m_ppmDtc, m_asb);
|
|
m_participantModel->setUnitsSelectable(false);
|
|
// only needed to set recursiveFilteringEnabled
|
|
auto proxyModel = new ParticipantManagement::ParticipantTreeFilterProxyModel(this);
|
|
proxyModel->setSourceModel(m_participantModel);
|
|
proxyModel->setRecursiveFilteringEnabled(true);
|
|
m_ui->dvParticipants->setModel(proxyModel);
|
|
m_ui->dvParticipants->setToolButtonsVisible(false);
|
|
#ifndef LTS_DEBUG
|
|
m_ui->dvParticipants->hideColumn(ParticipantManagement::ParticipantEditModel::ColParticipantId);
|
|
#endif
|
|
m_ui->dvParticipants->setSortIndicator(0, Qt::AscendingOrder);
|
|
|
|
connect(m_ui->dvParticipants, &LtsDataView::LtsDataView::selectionChanged,
|
|
this, &ChargeEffectEdit::onSelectionChanged);
|
|
|
|
connect(m_ui->cbParty,
|
|
static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged),
|
|
this, &ChargeEffectEdit::onChangeParty);
|
|
|
|
m_ppmGuiCbxIfc->fillPartyComboBox(m_ui->cbParty);
|
|
onChangeParty();
|
|
|
|
fillCharges();
|
|
if (m_ui->cbChargeType->count())
|
|
m_ui->pbPosition->setEnabled(true);
|
|
|
|
// enableUiElements(editable && isModifiable() && !isOnlyNameModifiable());
|
|
|
|
m_ui->pbPosition->setIcon(QIcon(QStringLiteral("icon:position.svg")));
|
|
|
|
connect(m_ui->pbPosition, &QPushButton::toggled, this, &ChargeEffectEdit::onPositionButtonToggled);
|
|
|
|
return true;
|
|
}
|
|
|
|
void ChargeEffectEdit::retranslate()
|
|
{
|
|
translate(m_ui, m_aesItem, tr("Charge Effect"));
|
|
}
|
|
|
|
void ChargeEffectEdit::enableUiElements(bool enable)
|
|
{
|
|
Q_UNUSED(enable);
|
|
}
|
|
|
|
void ChargeEffectEdit::onChangeParty()
|
|
{
|
|
if (m_ui->cbPlayer->isChecked())
|
|
{
|
|
m_ui->dvParticipants->setEnabled(true);
|
|
m_participantModel->onReinitModel(m_ui->cbParty->currentData().toInt());
|
|
m_ui->dvParticipants->expandAll();
|
|
m_ui->pbPosition->setEnabled(false);
|
|
cancelPositionTrigger();
|
|
}
|
|
else
|
|
{
|
|
m_ui->dvParticipants->setEnabled(false);
|
|
m_participantModel->resetModel();
|
|
if (m_ui->cbChargeType->count())
|
|
m_ui->pbPosition->setEnabled(true);
|
|
}
|
|
}
|
|
|
|
void ChargeEffectEdit::onSelectionChanged()
|
|
{
|
|
m_ui->pbPosition->setEnabled(false);
|
|
|
|
if (m_ui->dvParticipants->selectedRows().isEmpty())
|
|
return;
|
|
|
|
const ParticipantManagement::ParticipantData data(m_participantModel->getParticipantData(m_ui->dvParticipants->selectedRows().first()));
|
|
DEBUG_LOG(m_logger) << "ParticipantId: " << data.id();
|
|
|
|
if (m_ppmDtc->type(data.typeId()).typeClass() == ParticipantManagement::TypeClass_def::Unit)
|
|
return;
|
|
|
|
DEBUG_LOG(m_logger) << "typeClass: " << m_ppmDtc->type(data.typeId()).typeClass()
|
|
<< " eqNr.isSet(): " << data.equipmentNumber().is_set();
|
|
|
|
if (data.equipmentNumber().is_set())
|
|
{
|
|
if (m_ui->cbChargeType->count())
|
|
m_ui->pbPosition->setEnabled(true);
|
|
}
|
|
}
|
|
|
|
void ChargeEffectEdit::onPositionButtonToggled(bool isChecked)
|
|
{
|
|
if (isChecked)
|
|
{
|
|
m_ui->pbPosition->setStyleSheet(QStringLiteral("background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop: 0 rgb(254, 45, 102), stop: 1 rgb(255, 92, 61));"));
|
|
getPosition();
|
|
}
|
|
else
|
|
{
|
|
m_ui->pbPosition->setStyleSheet(QStringLiteral(""));
|
|
m_sitMapGuiIfc->cancelActiveRubberbands();
|
|
}
|
|
}
|
|
|
|
void ChargeEffectEdit::getPosition()
|
|
{
|
|
|
|
if (!m_sitMapGuiIfc) //sanity
|
|
return;
|
|
|
|
if (m_sitMapGuiIfc->mapMode() != SituationMap::MapMode::MapMode_2D)
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Only available in 2D mode"));
|
|
return;
|
|
}
|
|
m_sitMapGuiIfc->getCoordinate(this, SLOT(onGetCoordinate(QPointF)), SLOT(onEscapePressed(QString)));
|
|
}
|
|
|
|
void ChargeEffectEdit::onGetCoordinate(const QPointF &coordinate)
|
|
{
|
|
ParticipantManagement::ParticipantData participantData;
|
|
const QModelIndexList indexList = m_ui->dvParticipants->selectedRows();
|
|
int checked = m_ui->cbPlayer->isChecked();
|
|
if (checked && indexList.size())
|
|
participantData = m_participantModel->getParticipantData(indexList.first());
|
|
|
|
const int chargeTypeId = m_ui->cbChargeType->currentData().toInt();
|
|
const int partyId = m_ui->cbParty->currentData().toInt();
|
|
DEBUG_LOG(m_logger) << "ParticipantId=" << participantData.id()
|
|
<< " EquipmentNr=" << participantData.equipmentNumber()
|
|
<< " partyId=" << partyId
|
|
<< " chargeType=" << chargeTypeId
|
|
<< " onGetCoordinate x=" << coordinate.x() << " y=" << coordinate.y();
|
|
|
|
// Button zurücksetzen
|
|
cancelPositionTrigger();
|
|
int gearType = 0;
|
|
for (const auto >c : m_pdmDtc->gearTypeChargeTypes())
|
|
{
|
|
if (gtc.chargeTypeId() == chargeTypeId)
|
|
gearType = gtc.gearTypeId();
|
|
}
|
|
|
|
const auto chargeType = m_pdmDtc->chargeType(chargeTypeId);
|
|
|
|
|
|
|
|
ChargeEffectModifyRequest request;
|
|
int id;
|
|
ProjectDataManagement::StateChangeOriginator originatorTypeId;
|
|
if (m_ui->cbPlayer->isChecked())
|
|
{
|
|
id = participantData.id();
|
|
originatorTypeId = ProjectDataManagement::StateChangeOriginator::Participant;
|
|
}
|
|
else
|
|
{
|
|
id = partyId;
|
|
originatorTypeId = ProjectDataManagement::StateChangeOriginator::Party;
|
|
}
|
|
|
|
|
|
request.name(chargeType.shortName());
|
|
request.chargeTypeId(chargeTypeId);
|
|
request.igniterTypeId(0);//(m_pdmDtc->fuseTypes(chargeTypeId).first()); <-- check by inserting error
|
|
request.gearTypeId(gearType);
|
|
request.originatorId(id);
|
|
request.originatorTypeId(originatorTypeId);
|
|
request.effectDuration(1000);
|
|
request.effectStart(m_session->partitionTime() + 6000);
|
|
request.position(Core::GeoPosition(coordinate.x(), coordinate.y(), 0.0));
|
|
|
|
m_requestHelper->addRequest([this,request]()
|
|
{
|
|
return m_ftc->chargeEffectModifyRequest(request, this);
|
|
});
|
|
m_requestHelper->startRequests();
|
|
}
|
|
|
|
void ChargeEffectEdit::onEscapePressed(const QString &value)
|
|
{
|
|
Q_UNUSED(value)
|
|
DEBUG_LOG(m_logger) << "################## onEscapePressed";
|
|
cancelPositionTrigger();
|
|
}
|
|
|
|
void ChargeEffectEdit::fillCharges()
|
|
{
|
|
DEBUG_LOG(m_logger) << " fillCharges";
|
|
|
|
m_ui->cbChargeType->clear();
|
|
|
|
if (!m_pdmDtc)
|
|
{
|
|
ERROR_LOG(m_logger) << " no m_pdmDtc";
|
|
return;
|
|
}
|
|
|
|
for (const auto &charge : m_pdmDtc->chargeTypes())
|
|
{
|
|
if(!m_pdmDtc->isVirtuallyFireable(charge.id()))
|
|
continue;
|
|
|
|
m_ui->cbChargeType->addItem(QString::fromStdString(charge.name()), charge.id());
|
|
}
|
|
m_ui->cbChargeType->setEnabled(m_ui->cbChargeType->count() > 1);
|
|
}
|
|
|
|
void ChargeEffectEdit::cancelPositionTrigger()
|
|
{
|
|
DEBUG_LOG(m_logger) << " cancelPositionTrigger";
|
|
m_ui->pbPosition->setChecked(false);
|
|
onPositionButtonToggled(m_ui->pbPosition->isChecked());
|
|
}
|
|
|
|
} // namespace AreaEffectSimulation
|