308 lines
11 KiB
C++
Executable File
308 lines
11 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* ContaminationManangement - Contamination Overview Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Patric Karwat, SLSE, 2016-07-07
|
|
*/
|
|
|
|
#include "aes_itemlist.h"
|
|
#include "aes_base_model.h"
|
|
#include "ui_aes_itemlist.h"
|
|
|
|
#include <QCheckBox>
|
|
#include <QKeyEvent>
|
|
|
|
#include <LtsSession/lts_session.h>
|
|
#include <LtsUtilsGuiDds/request_helper.h>
|
|
#include <PluginInterfaces/gui_plugin_interface.h>
|
|
#include <Plugins/AreaEffectSimulation/aes_data_plugin_interface.h>
|
|
#include <Plugins/SituationMapPlugin/situation_map_gui_plugin_interface.h>
|
|
#include <Viewer/LtsDataView/lts_data_view.h>
|
|
|
|
#include <QJsonDocument>
|
|
#include <QTreeView>
|
|
#include <LtsPrinting/printing.h>
|
|
|
|
static const auto ADLER_BTN = LtsWidgets::DialogButton::Export;
|
|
|
|
namespace AreaEffectSimulation
|
|
{
|
|
|
|
AesItemList::AesItemList(const QString &menuGroup, QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
|
, m_ftc(nullptr)
|
|
, m_dtc(nullptr)
|
|
, m_menuGroup(menuGroup)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_showExpired(false)
|
|
, m_bHasAddEditOperatorRights(true)
|
|
, m_bHasAddAdlerOperatorRights(false)
|
|
, m_session(nullptr)
|
|
, m_ui(new Ui::AesItemList)
|
|
, m_logger(getLogger("AesItemList"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
QCheckBox *cbExpired = new QCheckBox(tr("Show expired"), m_ui->widget);
|
|
cbExpired->setProperty("const", true);
|
|
m_ui->widget->setCustomWidget(cbExpired);
|
|
connect(cbExpired, &QCheckBox::toggled, this, &AesItemList::setShowExpired);
|
|
}
|
|
|
|
AesItemList::~AesItemList() { delete m_ui; }
|
|
|
|
bool AesItemList::init(LtsSession::LtsSession *session)
|
|
{
|
|
if (m_session)
|
|
{
|
|
ERROR_LOG(m_logger) << "double init()!";
|
|
return false;
|
|
}
|
|
m_session = session;
|
|
|
|
if (!m_session->getFtc<AreaEffectSimulation::DataInterface>(m_ftc))
|
|
return false;
|
|
if (!m_session->getDtc<AreaEffectSimulation::DataInterface>(m_dtc))
|
|
return false;
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Print, this, &AesItemList::onPrint);
|
|
if (m_session->app() != LtsAppDescriptor::App::OC)
|
|
{
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &AesItemList::onAddAesItem);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &AesItemList::onRemoveAesItem);
|
|
}
|
|
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &AesItemList::onEditAesItem);
|
|
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Save)->setText(tr("Center on Map"));
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Save)->setIcon(QIcon(QStringLiteral("icon:center_to_object.svg")));
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Save, this, &AesItemList::onCenterAesItem);
|
|
m_buttonBox->getButton(ADLER_BTN)->hide();
|
|
m_buttonBox->connectButton(ADLER_BTN, this, &AesItemList::onAdlerBtn);
|
|
|
|
QCheckBox *cb = qobject_cast<QCheckBox *>(m_ui->widget->customWidget());
|
|
bool showExpired = (!cb || cb->isChecked());
|
|
|
|
createModel();
|
|
model()->setShowExpired(showExpired);
|
|
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged, this, &AesItemList::enaDisa);
|
|
connect(m_session, &LtsSession::LtsSession::signalExerciseDataChanged, this, &AesItemList::enaDisa);
|
|
connect(m_dtc.get(), &AreaEffectSimulation::Interface::Dtc::explosionClusterChanged, this, &AesItemList::onHandleAdler);
|
|
connect(m_dtc.get(), &AreaEffectSimulation::Interface::Dtc::effectClusterChanged, this, &AesItemList::onHandleAdler);
|
|
|
|
return true;
|
|
}
|
|
|
|
void AesItemList::enaDisa()
|
|
{
|
|
const int curSelRow = currentRow();
|
|
onHandleAdler();
|
|
LtsWidgets::ExerciseStates allowedStates = LtsWidgets::ExerciseState::eCreated | LtsWidgets::ExerciseState::eStarted | LtsWidgets::ExerciseState::ePaused;
|
|
bool bEnableEditRemove = false;
|
|
bool bIsAllowedInState = allowedStates.testFlag(m_session->exerciseState());
|
|
bool isOc = (m_session->app() == LtsAppDescriptor::App::OC);
|
|
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Save, !model()->isExpired(curSelRow));
|
|
|
|
if (curSelRow >= 0)
|
|
bEnableEditRemove = !model()->isExpired(curSelRow) && !model()->isExternal(curSelRow);
|
|
if (!m_bHasAddEditOperatorRights)
|
|
{
|
|
bEnableEditRemove = false;
|
|
bIsAllowedInState = false;
|
|
}
|
|
|
|
if (!m_session->isReplayPartition())
|
|
{
|
|
if (!model()->isExternal(curSelRow))
|
|
{
|
|
m_buttonBox->setText(LtsWidgets::DialogButton::Edit, tr("Edit"));
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, bEnableEditRemove && bIsAllowedInState);
|
|
}
|
|
else
|
|
{
|
|
m_buttonBox->setText(LtsWidgets::DialogButton::Edit, tr("Show Details"));
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, bIsAllowedInState);
|
|
}
|
|
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, bEnableEditRemove && bIsAllowedInState);
|
|
|
|
// Adler Add Button
|
|
bool isEsAdler = false;
|
|
if (curSelRow >= 0)
|
|
{
|
|
const ProjectDataManagement::EffectSource &es = model()->aesEffectSourceId(curSelRow);
|
|
|
|
if (es == ProjectDataManagement::EffectSource::ES_ADLER || es == ProjectDataManagement::EffectSource::ES_ADLER_STANDALONE)
|
|
isEsAdler = true;
|
|
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, bIsAllowedInState && !isEsAdler);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, m_bHasAddAdlerOperatorRights && isEsAdler);
|
|
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Load, !isOc);
|
|
}
|
|
else
|
|
{
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, bIsAllowedInState);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, m_bHasAddAdlerOperatorRights);
|
|
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Load, !isOc);
|
|
}
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Load)->setText(tr("Add ADLER"));
|
|
}
|
|
else
|
|
{
|
|
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Add, false);
|
|
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Remove, false);
|
|
|
|
m_buttonBox->setText(LtsWidgets::DialogButton::Edit, tr("Show Details"));
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, bEnableEditRemove);
|
|
}
|
|
|
|
if (bEnableEditRemove && bIsAllowedInState)
|
|
{
|
|
m_doubleClickConnection = connect(m_ui->widget, &LtsDataView::LtsDataView::signalDoubleClicked, this, &AesItemList::onEditAesItem, Qt::UniqueConnection);
|
|
}
|
|
else
|
|
{
|
|
if (m_doubleClickConnection)
|
|
disconnect(m_doubleClickConnection);
|
|
}
|
|
}
|
|
|
|
void AesItemList::onPrint() { LtsPrinting::printView(m_session, this, m_ui->widget->treeView()); }
|
|
|
|
void AesItemList::onAdlerBtn()
|
|
{
|
|
AesEffectState aesEffectState = model()->aesEffectStateId(currentRow());
|
|
ProjectDataManagement::EffectSource effectSource = model()->aesEffectSourceId(currentRow());
|
|
|
|
DEBUG_LOG(m_logger) << "onAdlerBtn aesEffectState=" << aesEffectState;
|
|
|
|
switch (aesEffectState.underlying())
|
|
{
|
|
case AreaEffectSimulation::AesEffectState::EsReceived:
|
|
{
|
|
switch (effectSource.underlying())
|
|
{
|
|
case ProjectDataManagement::EffectSource::ES_ADLER:
|
|
{
|
|
AcknowledgeExternalAesItemRequest req;
|
|
int aesId = model()->aesId(currentRow());
|
|
req.aesId(aesId);
|
|
m_requestHelper->startSingleRequest([req, this]() { return m_ftc->acknowledgeExternalAesItemRequest(req, this); });
|
|
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
ExplosionClusterReleaseReceivedRequest req;
|
|
int aesId = model()->aesId(currentRow());
|
|
req.id(aesId);
|
|
m_requestHelper->startSingleRequest([req, this]() { return m_ftc->explosionClusterReleaseReceivedRequest(req, this); });
|
|
break;
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
case AreaEffectSimulation::AesEffectState::EsCreated:
|
|
case AreaEffectSimulation::AesEffectState::EsPrepared:
|
|
{
|
|
if (effectSource == ProjectDataManagement::EffectSource::ES_ADLER ||
|
|
effectSource == ProjectDataManagement::EffectSource::ES_ADLER_STANDALONE)
|
|
{
|
|
AreaEffectSimulation::SetAesItemEffectorStateRequest req;
|
|
req.aesId(model()->aesId(currentRow()));
|
|
req.newEffectorState(AesEffectorState::EsReadyToFire);
|
|
DEBUG_LOG(m_logger) << "Send setAesItemEffectorStateRequest with aesId: " << req.aesId() << ", AesEffectorState: " << req.newEffectorState();
|
|
|
|
m_requestHelper->startSingleRequest([req, this]() { return m_ftc->setAesItemEffectorStateRequest(req, this); });
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
m_buttonBox->getButton(ADLER_BTN)->hide();
|
|
}
|
|
}
|
|
|
|
// enable Adler-Btn
|
|
void AesItemList::onHandleAdler()
|
|
{
|
|
AesEffectState aesEffectState = model()->aesEffectStateId(currentRow());
|
|
DEBUG_LOG(m_logger) << "onHandleAdler aesEffectState=" << aesEffectState;
|
|
auto *adlerBtn = m_buttonBox->getButton(ADLER_BTN);
|
|
|
|
switch (aesEffectState.underlying())
|
|
{
|
|
case AreaEffectSimulation::AesEffectState::EsReceived:
|
|
{
|
|
adlerBtn->setText(tr("Mark received"));
|
|
adlerBtn->setIcon(QIcon(QStringLiteral("icon:mortar_ammunition_administration.svg")));
|
|
adlerBtn->show();
|
|
break;
|
|
}
|
|
case AreaEffectSimulation::AesEffectState::EsCreated:
|
|
case AreaEffectSimulation::AesEffectState::EsPrepared:
|
|
{
|
|
ProjectDataManagement::EffectSource effectSource = model()->aesEffectSourceId(currentRow());
|
|
if (effectSource.underlying() == ProjectDataManagement::EffectSource::ES_ADLER ||
|
|
effectSource.underlying() == ProjectDataManagement::EffectSource::ES_ADLER_STANDALONE)
|
|
{
|
|
const EffectCluster &ecData = m_dtc->effectCluster(model()->aesId(currentRow()));
|
|
if (ecData.effectorState() == AreaEffectSimulation::AesEffectorState::EsNotReadyToFire)
|
|
{
|
|
adlerBtn->setText(tr("Ready To Fire"));
|
|
adlerBtn->show();
|
|
}
|
|
else
|
|
adlerBtn->hide();
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
adlerBtn->hide();
|
|
}
|
|
}
|
|
|
|
void AesItemList::onCenterAesItem()
|
|
{
|
|
int aesId = model()->aesId(currentRow());
|
|
std::shared_ptr<SituationMap::ForeignGuiInterface> ifc;
|
|
if (m_session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(ifc))
|
|
ifc->centerMapToAesObject(aesId);
|
|
}
|
|
|
|
void AesItemList::hideColumn(int col) { m_ui->widget->hideColumn(col); }
|
|
|
|
void AesItemList::showColumn(int col) { m_ui->widget->showColumn(col); }
|
|
|
|
int AesItemList::currentRow() const
|
|
{
|
|
const auto selRows = m_ui->widget->selectedRows();
|
|
if (selRows.count() != 1)
|
|
return -1;
|
|
return selRows.first().row();
|
|
}
|
|
|
|
void AesItemList::setDataViewModel(QAbstractItemModel *model, const std::function<LtsDataView::AbstractDisplayWidget *()> &customDisplayWidgetCreator)
|
|
{
|
|
m_ui->widget->setModel(model, customDisplayWidgetCreator);
|
|
}
|
|
|
|
void AesItemList::setDataViewModel(QAbstractItemModel *model) { m_ui->widget->setModel(model); }
|
|
|
|
void AesItemList::setShowExpired(bool show) { model()->setShowExpired(show); }
|
|
|
|
void AesItemList::setSortIndicator(int col) { m_ui->widget->setSortIndicator(col, Qt::AscendingOrder); }
|
|
|
|
void AesItemList::translateBase(const QString &windowTitle) { translate(m_ui, windowTitle); }
|
|
|
|
void AesItemList::tableColumnOrganiserSetting()
|
|
{
|
|
// LtsColumnOrganiser
|
|
m_ui->widget->setColumnsOrganiserEnabled(identifier(), true);
|
|
}
|
|
|
|
} // namespace AreaEffectSimulation
|