312 lines
9.4 KiB
C++
Executable File
312 lines
9.4 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* ExerciseManangement - Exercise Overview Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Christian Ehrlicher, SLSE, 2016-02-29
|
|
*/
|
|
|
|
|
|
#include "asm_training_area_dialog.h"
|
|
#include "ui_asm_training_area_dialog.h"
|
|
#include "asm_edit_training_area_dialog.h"
|
|
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
|
|
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <LtsUtilsSettings/settings.h>
|
|
#include <LtsCoordTrans/lts_coord_trans.h>
|
|
#include <Proxies/CombatNetRadio/helper.h>
|
|
#include <AssetManagement/asm_ftc_types.h>
|
|
|
|
using namespace CombatNetRadio;
|
|
namespace AssetManagement
|
|
{
|
|
//---------------------------------
|
|
// AsmTrainingAreaDialog
|
|
//---------------------------------
|
|
AsmTrainingAreaDialog::AsmTrainingAreaDialog(const QString &menuGroup, QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
|
, m_ui(new Ui::AsmTrainingAreaDialog)
|
|
, m_session(nullptr)
|
|
, m_menuGroup(menuGroup)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_logger(getLogger("AsmTrainingAreaDialog"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
setOnlineHelpFilename(QStringLiteral("Asset_Management-Training_Area"));
|
|
|
|
// m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &AsmTrainingAreaDialog::onAddTrainingArea);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &AsmTrainingAreaDialog::onAddTrainingArea);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &AsmTrainingAreaDialog::onEditTrainingArea);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &AsmTrainingAreaDialog::onRemoveTrainingArea);
|
|
|
|
connect(m_ui->trainingAreaView, &LtsDataView::LtsDataView::signalSelectionChanged,
|
|
this, &AsmTrainingAreaDialog::onSelectionChanged);
|
|
enaDisa();
|
|
}
|
|
|
|
AsmTrainingAreaDialog::~AsmTrainingAreaDialog()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
void AsmTrainingAreaDialog::retranslate()
|
|
{
|
|
translate(m_ui, tr("Training Area Overview"));
|
|
}
|
|
|
|
void AsmTrainingAreaDialog::tableColumnOrganiserSetting()
|
|
{
|
|
//LtsColumnOrganiser
|
|
m_ui->trainingAreaView->setColumnsOrganiserEnabled(identifier(), true);
|
|
}
|
|
|
|
/*!
|
|
* \brief AsmTrainingAreaDialog::init
|
|
* \param session
|
|
* \return
|
|
*/
|
|
bool AsmTrainingAreaDialog::init(LtsSession::LtsSessionDataDds *session, const std::shared_ptr<SituationMap::ForeignGuiInterface> &sitMapGuiIfc)
|
|
{
|
|
m_session = session;
|
|
|
|
if (!m_session->getDtc<AssetManagement::DataInterface>(m_asmDtc)) // TODO: not obli
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not enable DTC from ASM";
|
|
return false;
|
|
}
|
|
if(!m_session->getFtc<AssetManagement::DataInterface>(m_asmFtc))
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not enable FTC from ASM";
|
|
return false;
|
|
}
|
|
|
|
m_sitMapGuiIfc = sitMapGuiIfc;
|
|
if(!m_sitMapGuiIfc)
|
|
{
|
|
ERROR_LOG(m_logger) << "m_sitMapGuiIfc is invalid ";
|
|
return false;
|
|
}
|
|
bool bRet = true;
|
|
bRet &= m_asmDtc->enableTrainingArea(true);
|
|
|
|
bRet &= m_asmFtc->enableTrainingAreaModify(true);
|
|
bRet &= m_asmFtc->enableTrainingAreaRemove(true);
|
|
|
|
if(!bRet)
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not enable dtc or ftc from ASM";
|
|
return false;
|
|
}
|
|
|
|
INFO_LOG(m_logger) << "Ftc && Dtc enabled from ASM";
|
|
|
|
delete m_model;
|
|
m_model = new AsmTrainingAreaDialogModel(this);
|
|
m_model->initModel(m_asmDtc, false);
|
|
m_ui->trainingAreaView->setModel(m_model);
|
|
connect(m_ui->trainingAreaView, &LtsDataView::LtsDataView::signalDoubleClicked, this, &AsmTrainingAreaDialog::onEditTrainingArea);
|
|
|
|
// show all areas at the beginning
|
|
showAllTrainingAreas();
|
|
|
|
return true;
|
|
}
|
|
|
|
void AsmTrainingAreaDialog::enaDisa()
|
|
{
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, false);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, false);
|
|
|
|
QModelIndexList indexList = m_ui->trainingAreaView->selectedRows();
|
|
if (indexList.size() == 0)
|
|
return;
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, (indexList.size() == 1) );
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, (indexList.size() == 1) );
|
|
}
|
|
|
|
void AsmTrainingAreaDialog::onAddTrainingArea()
|
|
{
|
|
const QString identifier = QStringLiteral("AsmAddTrainingArea");
|
|
|
|
if(!focusDialog(m_menuGroup,identifier, LtsWidgets::LayoutArea::eDialogTab))
|
|
{
|
|
|
|
AsmEditTrainingAreaDialog *dialog = new AsmEditTrainingAreaDialog(this);
|
|
|
|
if(!dialog->init(m_session,0,m_sitMapGuiIfc,m_menuGroup))
|
|
{
|
|
delete dialog;
|
|
return;
|
|
}
|
|
connect(this, &AsmTrainingAreaDialog::destroyed, dialog, &QObject::deleteLater);
|
|
addDialog(dialog, m_menuGroup, identifier, LtsWidgets::LayoutArea::eDialogTab);
|
|
}
|
|
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " adding temp training Area ";
|
|
}
|
|
|
|
void AsmTrainingAreaDialog::onRemoveTrainingArea()
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START" ;
|
|
QModelIndexList indexList = m_ui->trainingAreaView->selectedRows();
|
|
if (indexList.size() == 0)
|
|
return;
|
|
|
|
TrainingArea req = m_model->getRowData(indexList.front().row());
|
|
if (req.id() < 0)
|
|
{
|
|
ERROR_LOG(m_logger) << LOGFUNCTION << " invalid id:bt"<< req.id();
|
|
return;
|
|
}
|
|
if (!m_viewedTaIds.contains(req.id()))
|
|
{
|
|
bool success = m_requestHelper->startSingleRequest([this, req]()
|
|
{
|
|
return m_asmFtc->trainingAreaRemoveRequest(TrainingAreaRemoveRequest(req.id()), this);
|
|
});
|
|
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " success = " << success;
|
|
}
|
|
else
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Warning"),
|
|
tr("Cannot remove currently edited Training Area"));
|
|
}
|
|
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
}
|
|
|
|
void AsmTrainingAreaDialog::onEditTrainingArea()
|
|
{
|
|
QModelIndexList indexList = m_ui->trainingAreaView->selectedRows();
|
|
if (indexList.size() == 0)
|
|
return;
|
|
TrainingArea taItem = m_model->getRowData(indexList.front().row());
|
|
if (taItem.id() < 0)
|
|
{
|
|
ERROR_LOG(m_logger) << "onEditTrainingArea invalid id = "<< taItem.id();
|
|
return;
|
|
}
|
|
|
|
const QString identifier = QStringLiteral("AsmEditTrainingArea_%1").arg(taItem.id());
|
|
if(focusDialog(m_menuGroup,identifier, LtsWidgets::LayoutArea::eDialogTab))
|
|
{
|
|
return;
|
|
}
|
|
|
|
AsmEditTrainingAreaDialog *dialog = new AsmEditTrainingAreaDialog(this);
|
|
|
|
if(!dialog->init(m_session,taItem.id(),m_sitMapGuiIfc,m_menuGroup))
|
|
{
|
|
delete dialog;
|
|
return;
|
|
}
|
|
|
|
connect(this, &AsmTrainingAreaDialog::destroyed, dialog, &QObject::deleteLater);
|
|
|
|
connect(dialog, &AsmEditTrainingAreaDialog::destroyed, this, [this](){
|
|
clearSelection(); });
|
|
addDialog(dialog, m_menuGroup, identifier, LtsWidgets::LayoutArea::eDialogTab);
|
|
|
|
}
|
|
|
|
void AsmTrainingAreaDialog::onSelectionChanged()
|
|
{
|
|
enaDisa();
|
|
DEBUG_LOG(m_logger) << "onSelectionChanged() called !";
|
|
const QModelIndex curIdx = m_ui->trainingAreaView->currentIndex();
|
|
if (!curIdx.isValid())
|
|
return;
|
|
|
|
AssetManagement::TrainingArea taItem = m_model->getRowData(curIdx.row());
|
|
DEBUG_LOG(m_logger) << "onSelectionChanged() selected training area id: "<<taItem.id();
|
|
if(taItem.id() < 0)
|
|
{
|
|
ERROR_LOG(m_logger) << "onEditTrainingArea invalid id"<< taItem.id();
|
|
return;
|
|
}
|
|
|
|
m_previewPolygon = getTrainingArea(taItem.id());
|
|
showPreviewObject();
|
|
|
|
}
|
|
|
|
void AsmTrainingAreaDialog::clearSelection()
|
|
{
|
|
m_ui->trainingAreaView->clearSelection();
|
|
if(m_sitMapGuiIfc)
|
|
{
|
|
m_sitMapGuiIfc->removePreviewObject();
|
|
}
|
|
}
|
|
|
|
QPolygonF AsmTrainingAreaDialog::getTrainingArea(int trainingAreaId)
|
|
{
|
|
if(!m_asmDtc)
|
|
{
|
|
ERROR_LOG(m_logger) << LOGFUNCTION << " m_asmDtc is not valid!";
|
|
return {};
|
|
}
|
|
const AssetManagement::TrainingArea &ddsTrainingArea = m_asmDtc->trainingArea(trainingAreaId);
|
|
if (ddsTrainingArea.id() != trainingAreaId)
|
|
{
|
|
ERROR_LOG(m_logger) << LOGFUNCTION << " TrainingArea not found, trainingAreaId = " << trainingAreaId;
|
|
return {};
|
|
}
|
|
|
|
return getTrainingArea(ddsTrainingArea);
|
|
}
|
|
|
|
QPolygonF AsmTrainingAreaDialog::getTrainingArea(const TrainingArea &ddsTrainingArea)
|
|
{
|
|
QPolygonF polygonF;
|
|
|
|
// bottom left
|
|
LtsCoordTrans::UtmCoordinate utmCoordinate = LtsCoordTrans::UtmCoordinate::fromGeographic(ddsTrainingArea.bottomLeft().lon(), ddsTrainingArea.bottomLeft().lat());
|
|
polygonF.push_back(QPointF((ddsTrainingArea.bottomLeft().lon()),(ddsTrainingArea.bottomLeft().lat())));
|
|
|
|
// bottom right
|
|
polygonF.push_back(utmCoordinate.geographic(ddsTrainingArea.width()));
|
|
|
|
// upper right
|
|
polygonF.push_back(utmCoordinate.geographic(ddsTrainingArea.width(), ddsTrainingArea.height()));
|
|
|
|
// upper left
|
|
polygonF.push_back(utmCoordinate.geographic(0, ddsTrainingArea.height()));
|
|
|
|
return polygonF;
|
|
}
|
|
|
|
|
|
void AsmTrainingAreaDialog::showAllTrainingAreas()
|
|
{
|
|
if (!m_sitMapGuiIfc)
|
|
return;
|
|
|
|
QVector<QPolygonF> polyVec;
|
|
const int rowCount = m_model->rowCount();
|
|
for (int row = 0; row < rowCount; ++row)
|
|
{
|
|
const TrainingArea ¤tArea = m_model->getRowData(row);
|
|
INFO_LOG(m_logger) << " row = " << row << " ; currentArea = " << currentArea;
|
|
const QPolygonF &poly = getTrainingArea(currentArea);
|
|
polyVec.append(poly);
|
|
} // for
|
|
if (!polyVec.isEmpty())
|
|
m_sitMapGuiIfc->displayPreviewObjects(this, polyVec, true);
|
|
}
|
|
|
|
void AsmTrainingAreaDialog::showPreviewObject()
|
|
{
|
|
if (!this->m_sitMapGuiIfc || m_previewPolygon.size() == 0)
|
|
{
|
|
TRACE_LOG(m_logger) << " showPreviewObject(): m_sitMapGuiIfc invalid or polygon empty ";
|
|
return;
|
|
}
|
|
this->m_sitMapGuiIfc->displayPreviewObject(this, m_previewPolygon, true);
|
|
}
|
|
|
|
} // namespace AssetManagement
|