260 lines
8.1 KiB
C++
Executable File
260 lines
8.1 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* AreaEffectSimulation - NContamination Edit Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Patric Karwat, SLSE, 2016-07-07
|
|
*/
|
|
|
|
|
|
#include "aes_danger_area_edit.h"
|
|
#include "ui_aes_danger_area_edit.h"
|
|
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <Plugins/AreaEffectSimulation/aes_data_plugin_interface.h>
|
|
#include <Plugins/SituationMapPlugin/situation_map_gui_plugin_interface.h>
|
|
#include <Plugins/AreaEffectSimulation/aes_info_gui_plugin_interface.h>
|
|
#include <PluginInterfaces/gui_plugin_interface.h>
|
|
|
|
#include <QDoubleSpinBox>
|
|
|
|
namespace AreaEffectSimulation
|
|
{
|
|
|
|
DangerAreaEdit::DangerAreaEdit(const QString &menuGroup, QWidget *parent)
|
|
: BaseEdit(menuGroup, QLatin1String("DangerAreaEdit"), parent)
|
|
, m_ui(new Ui::DangerAreaEdit)
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
m_uiRequirements->addRequirement({m_ui->lblGeometry, [this]() { return (!m_ui->positionEdit_1->coordinate().isNull() &&
|
|
!m_ui->positionEdit_2->coordinate().isNull() &&
|
|
!m_ui->positionEdit_3->coordinate().isNull()
|
|
); }});
|
|
m_uiRequirements->addRequirement({m_ui->lblIdentifier, [this]() { return (!m_ui->leIdentifier->text().isEmpty()); }});
|
|
m_uiRequirements->addRequirement({m_ui->lblEffectStart, [this]() { return hasValidEffectStart(m_ui->dteEffectStart); }});
|
|
|
|
connect(m_ui->pbAesItems, &QPushButton::clicked, this, &DangerAreaEdit::onPbAesItemsClicked);
|
|
connect(m_ui->pbClear, &QPushButton::clicked, this, &DangerAreaEdit::clearCoordinates);
|
|
|
|
enaDisa();
|
|
|
|
setOnlineHelpFilename(QStringLiteral("Situation-Add_Danger_Area"));
|
|
}
|
|
|
|
DangerAreaEdit::~DangerAreaEdit()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
std::vector<LtsCoordWidget::LtsCoordWidget *> DangerAreaEdit::coordWidgets() const
|
|
{
|
|
return {m_ui->positionEdit_1,
|
|
m_ui->positionEdit_2,
|
|
m_ui->positionEdit_3,
|
|
m_ui->positionEdit_4,
|
|
m_ui->positionEdit_5};
|
|
}
|
|
|
|
void DangerAreaEdit::retranslate()
|
|
{
|
|
translate(m_ui, m_aesItem, tr("Danger Area"));
|
|
}
|
|
|
|
void DangerAreaEdit::enableUiElements(bool enable)
|
|
{
|
|
m_ui->leIdentifier->setMaxLength(30);
|
|
|
|
m_ui->pbPosition->setEnabled(m_sitMapGuiIfc && enable);
|
|
enabledCoordinates(enable);
|
|
m_ui->pbClear->setEnabled(enable);
|
|
m_ui->leIdentifier->setEnabled(enable || isOnlyNameModifiable());
|
|
setEffectStartEnabled(m_ui->dteEffectStart, enable);
|
|
if (m_aesItem.effectStateId() == AesEffectState_def::EsExpired)
|
|
{
|
|
m_ui->leIdentifier->setText(QString::fromStdString(m_aesItem.name()));
|
|
__unchange__();
|
|
}
|
|
if (m_aesItem.effectStateId() == AesEffectState_def::EsActivated)
|
|
{
|
|
QString name = m_ui->leIdentifier->text();
|
|
auto baseData = m_dtc->dangerArea(m_aesItem.id());
|
|
setData(baseData, false);
|
|
__unchange__();
|
|
if (name != m_ui->leIdentifier->text())
|
|
m_ui->leIdentifier->setText(name);
|
|
}
|
|
}
|
|
|
|
bool DangerAreaEdit::init(int aesItemId, bool copy,
|
|
LtsSession::LtsSession *session)
|
|
{
|
|
if (!BaseEdit::init(aesItemId, session))
|
|
return false;
|
|
|
|
bool editable = LtsSessionData::LtsSessionData::getInstance()->hasOperatorRight(OperatorRights::DangerAreasEdit) ||
|
|
m_session->app() == LtsAppDescriptor::App::OC;
|
|
bool readable = LtsSessionData::LtsSessionData::getInstance()->hasOperatorRight(OperatorRights::DangerAreasShow);
|
|
|
|
if (!readable && !editable)
|
|
return false;
|
|
|
|
// Todo: Older allowed?
|
|
m_ui->dteEffectStart->setMinimumTimeMSec(m_session->partitionTime());
|
|
m_ui->dteEffectStart->setRetrieveCurrentTimeCallback([this]() { return m_session->partitionTime(); });
|
|
|
|
if (m_sitMapGuiIfc)
|
|
connect(m_ui->pbPosition, &QPushButton::clicked, this, &DangerAreaEdit::getPolygon);
|
|
else
|
|
m_ui->pbPosition->setEnabled(false);
|
|
|
|
if (aesItemId > 0)
|
|
{
|
|
auto baseData = m_dtc->dangerArea(aesItemId);
|
|
setData(baseData, copy);
|
|
}
|
|
|
|
auto cb = [this](const DangerAreaCorrelatedAesItem &item)
|
|
{
|
|
if (item.dangerAreaId() == m_aesItem.id()) // AesItemId === DangerAreaId
|
|
m_otherAesItemIds << item.aesItemId();
|
|
};
|
|
m_dtc->dangerAreaCorrelatedAesItems(cb);
|
|
setPbAesItemsText();
|
|
|
|
enableUiElements(editable && isModifiable() && !isOnlyNameModifiable());
|
|
|
|
connect(m_dtc.get(), &AreaEffectSimulation::Interface::Dtc::dangerAreaCorrelatedAesItemChanged,
|
|
this, &DangerAreaEdit::onCorrelatedItemsChanged);
|
|
|
|
connect(m_dtc.get(), &AreaEffectSimulation::Interface::Dtc::dangerAreaChanged,
|
|
this, &BaseEdit::onAreaChanged);
|
|
|
|
return true;
|
|
}
|
|
|
|
void DangerAreaEdit::setPbAesItemsText()
|
|
{
|
|
QStringList sl;
|
|
for (int idx : qAsConst(m_otherAesItemIds))
|
|
{
|
|
AesItem item;
|
|
m_dtc->aesItemFromId(idx, item);
|
|
if (item.id() <= 0)
|
|
continue;
|
|
// Todo: Correct?
|
|
if (item.effectStateId() != AesEffectState_def::EsActivated)
|
|
continue;
|
|
sl << QString::fromStdString(item.name().c_str());
|
|
}
|
|
m_ui->pbAesItems->setEnabled(sl.size());
|
|
m_ui->pbAesItems->setText(sl.join(QStringLiteral(", ")));
|
|
}
|
|
|
|
void DangerAreaEdit::setData(const DangerArea &aesItem, bool copy)
|
|
{
|
|
m_aesItem = aesItem;
|
|
if (copy)
|
|
{
|
|
m_aesItem.id(0);
|
|
m_aesItem.effectStateId(AreaEffectSimulation::AesEffectState_def::get_default());
|
|
}
|
|
m_ui->leIdentifier->setText(QString::fromStdString(aesItem.name()));
|
|
m_ui->dteEffectStart->setMsecsSinceEpoch(aesItem.effectStart().is_set() ? aesItem.effectStart().get() : 0);
|
|
setCoordinates(aesItem.segments());
|
|
}
|
|
|
|
void DangerAreaEdit::getPolygon()
|
|
{
|
|
if (!has2DMap())
|
|
return;
|
|
|
|
QPolygonF coordinates = getCoordinatesQPointF();
|
|
|
|
m_sitMapGuiIfc->getPolygon(this,
|
|
SLOT(onPolygonData(QPolygonF)),
|
|
nullptr,
|
|
3,
|
|
5,
|
|
-1,
|
|
-1,
|
|
coordinates);
|
|
}
|
|
|
|
void DangerAreaEdit::onPolygonData(const QPolygonF &poly)
|
|
{
|
|
if (poly.size() < 3)
|
|
return;
|
|
|
|
m_previewPolygon = poly;
|
|
|
|
// Don't reverse Polygon
|
|
setCoordinates(poly, false);
|
|
|
|
showPreviewObject();
|
|
}
|
|
|
|
bool DangerAreaEdit::apply()
|
|
{
|
|
std::string name = m_ui->leIdentifier->text().toStdString();
|
|
qint64 effectStart = m_ui->dteEffectStart->msecsSinceEpoch();
|
|
const DangerAreaModifyRequest req(m_aesItem.id(),
|
|
name,
|
|
0,
|
|
311, //danger area charge id Uleis
|
|
LtsUtils::toOptional(effectStart),
|
|
getCoordinates(),
|
|
dds::core::optional<int32_t>(),
|
|
dds::core::optional<int32_t>(),
|
|
dds::core::optional<int32_t>());
|
|
m_requestHelper->addRequest([this,req]()
|
|
{
|
|
return m_ftc->dangerAreaModifyRequest(req, this);
|
|
});
|
|
|
|
return m_requestHelper->startRequests();
|
|
}
|
|
|
|
void DangerAreaEdit::onCorrelatedItemsChanged(const DangerAreaCorrelatedAesItem &data, DataModification modType)
|
|
{
|
|
if (data.dangerAreaId() != m_aesItem.id())
|
|
return;
|
|
|
|
if (modType == DataModification::eAdded)
|
|
m_otherAesItemIds += data.aesItemId();
|
|
|
|
if (modType == DataModification::eRemoved)
|
|
m_otherAesItemIds -= data.aesItemId();
|
|
// Note: Modification cannot happen as the key is unique for the combination.
|
|
|
|
setPbAesItemsText();
|
|
}
|
|
|
|
void DangerAreaEdit::onPbAesItemsClicked()
|
|
{
|
|
if (m_otherAesItemIds.isEmpty())
|
|
return;
|
|
|
|
std::shared_ptr<ForeignInfoGuiInterface> infoGuiInterface;
|
|
if (!m_session->getForeignGuiInterface<ForeignInfoGuiInterface>(infoGuiInterface))
|
|
return;
|
|
|
|
LtsWidgets::LtsDialog *dialog = infoGuiInterface->showDangerAreaAesItemInfo({m_aesItem.id()}, m_otherAesItemIds);
|
|
|
|
addDialog(dialog, m_menuGroup, tr("Danger Areas for BC Contamination %1").arg(m_ui->leIdentifier->text()), LtsWidgets::LayoutArea::eInfoTab);
|
|
}
|
|
|
|
void DangerAreaEdit::showPreviewObject()
|
|
{
|
|
if (!m_sitMapGuiIfc)
|
|
return;
|
|
|
|
if (m_previewPolygon.isEmpty())
|
|
return;
|
|
|
|
m_sitMapGuiIfc->displayPreviewObject(this, m_previewPolygon, true);
|
|
}
|
|
|
|
} // namespace AreaEffectSimulation
|