378 lines
12 KiB
C++
Executable File
378 lines
12 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* ResourceManangement - Plan Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "ism_plan_dialog.h"
|
|
#include "ui_ism_plan_dialog.h"
|
|
#include "ism_plan_dialog_model.h"
|
|
#include "ism_plan_edit_dialog.h"
|
|
#include <InfrastructureManagement/ism_operator_rights.h>
|
|
#include "Overview/ism_overview_mounting_point_list_dialog.h"
|
|
|
|
#include <InfrastructureManagement/logger.h>
|
|
#include <InfrastructureManagement/ism_data_plugin_interface.h>
|
|
#include <InfrastructureManagement/ism_resource_management_gui_plugin_interface.h>
|
|
#include <LtsSession/lts_session.h>
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <LtsWidgets/lts_base_layout_widget.h>
|
|
#include <LtsPrinting/printing.h>
|
|
#include <QTreeView>
|
|
|
|
|
|
namespace InfrastructureManagement
|
|
{
|
|
|
|
PlanDialog::PlanDialog(const QString &menuGroup, LtsSession::LtsSession * session, QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
|
, m_session(session)
|
|
, m_menuGroup(menuGroup)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_ui(new Ui::PlanDialog)
|
|
, m_logger(getLogger(QStringLiteral("PlanDialog")))
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
|
m_ui->setupUi(this);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Print, this, &PlanDialog::onPrint);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &PlanDialog::onRemove);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Load, this, &PlanDialog::onLoad);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &PlanDialog::onEdit);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &PlanDialog::onAdd);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Show, this, &PlanDialog::onCopy);
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setText(tr("Copy"));
|
|
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Save, this, &PlanDialog::onCheck);
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Save)->setText(tr("Completeness Check"));
|
|
|
|
connect(m_ui->planView, &LtsDataView::LtsDataView::signalSelectionChanged, this, &PlanDialog::enaDisa);
|
|
connect(m_ui->planView, &LtsDataView::LtsDataView::doubleClicked, this, &PlanDialog::onEdit);
|
|
|
|
setOnlineHelpFilename(QStringLiteral("Ressourcen-Plans"));
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
}
|
|
|
|
PlanDialog::~PlanDialog()
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
|
delete m_ui;
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
}
|
|
|
|
void PlanDialog::retranslate()
|
|
{
|
|
translate(m_ui, tr("Instrumentation Plans"));
|
|
}
|
|
|
|
void PlanDialog::tableColumnOrganiserSetting()
|
|
{
|
|
//LtsColumnOrganiser
|
|
m_ui->planView->setColumnsOrganiserEnabled(identifier(), true);
|
|
}
|
|
|
|
bool PlanDialog::init(int scheduleId, const std::shared_ptr<Interface::Dtc> &dtc,
|
|
const std::shared_ptr<Interface::Ftc> &ftc,
|
|
const std::shared_ptr<ForeignGuiComboboxInterface> &ismGuiCbx,
|
|
const std::shared_ptr<ForeignDataInterface> &dataInterface,
|
|
ForeignResourceManagementGuiInterface *ismGuiIfc)
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
|
|
|
m_scheduleId = scheduleId;
|
|
m_dtc = dtc;
|
|
m_ftc = ftc;
|
|
m_ismGuiCbx = ismGuiCbx;
|
|
m_ismGuiIfc = ismGuiIfc;
|
|
m_dataIfc = dataInterface;
|
|
|
|
bool bRet = true;
|
|
bRet &= m_dtc->enableInstrumentationAsset();
|
|
bRet &= m_dtc->enableMountingPointAsset();
|
|
bRet &= m_dtc->enableMainSchedule();
|
|
bRet &= m_dtc->enableMainStructureElement();
|
|
|
|
bRet &= m_ftc->enableMainScheduleModify();
|
|
bRet &= m_ftc->enableMainScheduleCopy();
|
|
bRet &= m_ftc->enableMainScheduleRemove();
|
|
bRet &= m_ftc->enableInstrumentationAssetModify();
|
|
|
|
if (!bRet)
|
|
{
|
|
ERROR_LOG(m_logger) << "Could not enable DTC or FTC from ISM";
|
|
return false;
|
|
}
|
|
|
|
delete m_model;
|
|
m_model = new PlanDialogModel(this);
|
|
m_model->initModel(m_dtc);
|
|
m_ui->planView->setModel(m_model);
|
|
#ifndef LTS_DEBUG
|
|
m_ui->planView->hideColumn(PlanDialogModel::Columns::CREATED);
|
|
#endif
|
|
|
|
connect(m_dataIfc.get(), &ForeignDataInterface::scheduleIdChanged, this, &PlanDialog::onScheduleIdchanged);
|
|
m_ui->planView->setToolTip(tr("Current Instrumentation Plan Id = %1").arg(m_scheduleId));
|
|
|
|
DEBUG_LOG(m_logger) << "m_scheduleId = " << m_scheduleId;
|
|
|
|
setScheduleId(m_scheduleId);
|
|
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
return true;
|
|
}
|
|
|
|
void PlanDialog::setScheduleId(const int scheduleId)
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
|
m_scheduleId = scheduleId;
|
|
|
|
std::shared_ptr<InfrastructureManagement::ForeignDataInterface> ismIfc;
|
|
if (!m_session->getForeignDataInterface<InfrastructureManagement::DataInterface>(ismIfc))
|
|
{
|
|
new LtsWidgets::LtsMessageDialogNew(m_session->baseLayoutWidget(), tr("The Infrastructure Management is not available!"), tr("Cannot set Instrumentation Plan Id"));
|
|
return;
|
|
}
|
|
|
|
DEBUG_LOG(m_logger) << "setScheduleId = " << m_scheduleId;
|
|
|
|
ismIfc->setScheduleId(m_scheduleId);
|
|
|
|
// set name to "title":
|
|
MainSchedule ms = ismIfc->mainSchedule(m_scheduleId);
|
|
QString msName = QString::fromStdString(ms.name());
|
|
|
|
if (m_session && m_session->baseLayout())
|
|
m_session->baseLayout()->setCustomText(tr("Instrumentation Plan: '%1'").arg(msName));
|
|
|
|
m_ui->planView->setToolTip(tr("Current Instrumentation Plan Id = %1").arg(m_scheduleId));
|
|
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
}
|
|
|
|
void PlanDialog::onPrint()
|
|
{
|
|
LtsPrinting::printView(m_session, this, m_ui->planView->treeView() );
|
|
}
|
|
|
|
void PlanDialog::onMainScheduleChanged(const MainSchedule &data, DataModification modType)
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
|
m_scheduleId = data.id();
|
|
enaDisa();
|
|
Q_UNUSED(modType);
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
}
|
|
|
|
void PlanDialog::onScheduleIdchanged(int32_t id)
|
|
{
|
|
m_scheduleId = id;
|
|
enaDisa();
|
|
}
|
|
|
|
void PlanDialog::onLoad()
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
|
QModelIndexList indexList = m_ui->planView->selectedRows();
|
|
|
|
if (indexList.size() == 0)
|
|
return;
|
|
|
|
MainSchedule item{m_model->getRowData(indexList.front().row())};
|
|
|
|
if (item.id() == m_scheduleId)
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("This instrumentation plan is already loaded"));
|
|
return;
|
|
}
|
|
|
|
m_scheduleId = item.id();
|
|
setScheduleId(m_scheduleId);
|
|
m_ismGuiIfc->setPlanId(m_scheduleId);
|
|
enaDisa();
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
}
|
|
|
|
void PlanDialog::onRemove()
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
|
QModelIndexList indexList = m_ui->planView->selectedRows();
|
|
|
|
if (indexList.size() == 0)
|
|
return;
|
|
|
|
MainSchedule item{m_model->getRowData(indexList.front().row())};
|
|
|
|
if (item.id() == m_scheduleId)
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Cannot remove current instrumentation plan"));
|
|
return;
|
|
}
|
|
|
|
// unmount MountingPoints
|
|
InstrumentationAssetModifyRequest req;
|
|
InstrumentationAsset asset;
|
|
|
|
for (const auto &element : qAsConst(item.elements()))
|
|
{
|
|
QMap<qint32, MountingPointAsset> mntPntAssets = m_dtc->mountingPointAssets();
|
|
for (const auto &mntPntAsset : qAsConst(mntPntAssets))
|
|
{
|
|
if (mntPntAsset.structureElementId() == element.structureElementId())
|
|
{
|
|
asset = m_dtc->instrumentationAsset(mntPntAsset.assetId());
|
|
req = InstrumentationAssetModifyRequest(
|
|
1,
|
|
asset.name(),
|
|
asset.mountingPointTypeId(),
|
|
asset.barcode(),
|
|
asset.hostname(),
|
|
asset.properties(),
|
|
InstrumentationAssetState_def::Unmounted, // <- unmount
|
|
asset.lastUpdated(),
|
|
asset.availableInExercise()
|
|
);
|
|
// m_requestHelper->addRequest([req, this](){
|
|
// return m_ftc->instrumentationAssetModifyRequest(req, this);
|
|
// });
|
|
} // if
|
|
} // for
|
|
} // for
|
|
if (m_requestHelper->hasRequests())
|
|
m_requestHelper->startRequests();
|
|
|
|
// remove MainSchedule
|
|
Core::RemoveElementRequest rmReq{item.id()};
|
|
m_requestHelper->startSingleRequest([rmReq, this]()
|
|
{
|
|
return m_ftc->mainScheduleRemoveRequest(rmReq, this);
|
|
});
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
}
|
|
|
|
void PlanDialog::enaDisa()
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, true);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Print, true);
|
|
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, false);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, false);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, false);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Show, false);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Save, false);
|
|
|
|
QModelIndexList indexList = m_ui->planView->selectedRows();
|
|
if (indexList.size() == 0)
|
|
return;
|
|
|
|
MainSchedule item{m_model->getRowData(indexList.front().row())};
|
|
bool isComplete = m_dtc->checkSchedule(item.id());
|
|
|
|
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, !(item.id() == m_scheduleId || item.statusId() == ScheduleStatus::Active) );
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, !(item.id() == m_scheduleId) );
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, (indexList.size() == 1) );
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Show, (indexList.size() == 1) );
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Save, (indexList.size() == 1 && !isComplete) );
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
}
|
|
|
|
void PlanDialog::onEdit()
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
|
QModelIndexList indexList = m_ui->planView->selectedRows();
|
|
if (indexList.size() == 0)
|
|
return;
|
|
|
|
MainSchedule item{m_model->getRowData(indexList.front().row())};
|
|
if (item.id() < 0 )
|
|
return;
|
|
|
|
DEBUG_LOG(m_logger) << "onEdit schedule with id = " << item.id();
|
|
|
|
PlanEditDialog *dialog = new PlanEditDialog(this);
|
|
if (!dialog->init(m_session, item.id(), m_dtc, m_ftc, m_ismGuiCbx))
|
|
{
|
|
delete dialog;
|
|
return;
|
|
}
|
|
|
|
addDialog(dialog, m_menuGroup, QStringLiteral("EditSchedule%1").arg(item.id()), LtsWidgets::LayoutArea::eDialogTab);
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
}
|
|
|
|
void PlanDialog::onAdd()
|
|
{
|
|
DEBUG_LOG(m_logger) << "onAdd";
|
|
PlanEditDialog *dialog = new PlanEditDialog(this);
|
|
if (!dialog->init(m_session, 0, m_dtc, m_ftc, m_ismGuiCbx))
|
|
{
|
|
delete dialog;
|
|
return;
|
|
}
|
|
addDialog(dialog, m_menuGroup, QStringLiteral("AddSchedule"), LtsWidgets::LayoutArea::eDialogTab);
|
|
}
|
|
|
|
void PlanDialog::onCheck()
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
|
QModelIndexList indexList = m_ui->planView->selectedRows();
|
|
if (indexList.size() == 0)
|
|
return;
|
|
|
|
MainSchedule item{m_model->getRowData(indexList.front().row())};
|
|
if (item.id() < 0 )
|
|
return;
|
|
|
|
DEBUG_LOG(m_logger) << "show Differences schedule with id = " << item.id();
|
|
|
|
// replace old dialog (created by Iuliana Ojog):
|
|
// ScheduleDifferencesListDialog *dialog = new ScheduleDifferencesListDialog(m_menuGroup, this);
|
|
// if (!dialog->init(m_session, m_dtc, item.id()))
|
|
// {
|
|
// delete dialog;
|
|
// return;
|
|
// }
|
|
|
|
OverviewMountingPointListDialog *dialog = new OverviewMountingPointListDialog(m_menuGroup, this);
|
|
const int32_t scheduleId = item.id();
|
|
if (!dialog->init(m_session, m_dtc, m_ftc, m_dataIfc, scheduleId))
|
|
{
|
|
delete dialog;
|
|
return;
|
|
}
|
|
|
|
addDialog(dialog, m_menuGroup, QStringLiteral("ShowDifferences%1").arg(item.id()), LtsWidgets::LayoutArea::eDialogTab);
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
}
|
|
|
|
|
|
void PlanDialog::onCopy()
|
|
{
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
|
QModelIndexList indexList = m_ui->planView->selectedRows();
|
|
if (indexList.size() == 0)
|
|
return;
|
|
|
|
MainSchedule item{m_model->getRowData(indexList.front().row())};
|
|
if (item.id() < 0 )
|
|
return;
|
|
|
|
DEBUG_LOG(m_logger) << "onCopy schedule with id = " << item.id();
|
|
|
|
MainScheduleCopyRequest req;
|
|
req.id(item.id());
|
|
|
|
m_requestHelper->startSingleRequest([req, this]()
|
|
{
|
|
return m_ftc->mainScheduleCopyRequest(req, this);
|
|
});
|
|
|
|
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
|
}
|
|
|
|
|
|
} // namespace InfrastructureManagement
|