Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#include "ism_plan_tln_delegate.h"
|
||||
|
||||
#include <LtsTimeline/timeline_header_view.h>
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QModelIndex>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionViewItem>
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
|
||||
PlanTimelineDelegate::PlanTimelineDelegate(LtsTimeline::TimelineView *view)
|
||||
: LtsTimeline::ItemDelegate(view)
|
||||
{}
|
||||
|
||||
|
||||
void PlanTimelineDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
LtsTimeline::ItemDelegate::paint(painter, option, index);
|
||||
|
||||
if (index.column() == LtsTimeline::Section::eActuator)
|
||||
{
|
||||
painter->save();
|
||||
painter->setPen(QPen(QGuiApplication::palette().color(QPalette::Text), 2));
|
||||
painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
|
||||
painter->restore();
|
||||
return;
|
||||
}
|
||||
|
||||
painter->save();
|
||||
painter->setPen(Qt::black);
|
||||
painter->setBrush(QBrush(Qt::transparent));
|
||||
painter->drawLine(option.rect.left(), option.rect.bottom(), option.rect.right(), option.rect.bottom());
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
} // namespace InfrastructureManagement
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <LtsTimeline/item_delegate.h>
|
||||
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
|
||||
class PlanTimelineDelegate : public LtsTimeline::ItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PlanTimelineDelegate(LtsTimeline::TimelineView *view = nullptr);
|
||||
|
||||
private:
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
};
|
||||
|
||||
} // namespace InfrastructureManagement
|
||||
Executable
+360
@@ -0,0 +1,360 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Plans Overview Timeline Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Steve Kemayou, SLTE, 2021-07-26
|
||||
*/
|
||||
|
||||
#include "ism_plan_tln_dialog.h"
|
||||
#include "ui_ism_plan_tln_dialog.h"
|
||||
#include "ism_plan_dialog.h"
|
||||
#include "ism_plan_tln_delegate.h"
|
||||
|
||||
#include <InfrastructureManagement/logger.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsWidgets/lts_base_layout_widget.h>
|
||||
|
||||
#include <InfrastructureManagement/ism_ftc.h>
|
||||
#include <InfrastructureManagement/ism_dtc.h>
|
||||
#include <InfrastructureManagement/ism_enums.hpp>
|
||||
#include <InfrastructureManagement/settings.h>
|
||||
#include <QScrollBar>
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
static LtsTimeline::Zoom::Factor s_zoomFactor = LtsTimeline::Zoom::OneDay;
|
||||
|
||||
PlanTimeLineDialog::PlanTimeLineDialog(LtsSession::LtsSession *session, const QString &menuGroup, QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
||||
, m_session(session)
|
||||
, m_menuGroup(menuGroup)
|
||||
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
||||
, m_ui(new Ui::PlanTimeLineDialog)
|
||||
, m_logger(getLogger(QStringLiteral("PlanTimeLineDialog")))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << " ";
|
||||
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Load, this, &PlanTimeLineDialog::onLoad);
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Save, this, &PlanTimeLineDialog::onApply);
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &PlanTimeLineDialog::onRemove);
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Save)->setText(tr("Apply"));
|
||||
//default disabled
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, false);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, false);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Save, false);
|
||||
s_zoomFactor = LtsTimeline::Zoom::OneDay;
|
||||
setOnlineHelpFilename(QStringLiteral("Ressourcen-Timeline"));
|
||||
}
|
||||
|
||||
PlanTimeLineDialog::~PlanTimeLineDialog()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
bool PlanTimeLineDialog::init(const std::shared_ptr<InfrastructureManagement::Interface::Dtc> &dtc, const std::shared_ptr<Interface::Ftc> &ftc, const std::shared_ptr<ForeignDataInterface> &dataInterface, InfrastructureManagement::ForeignResourceManagementGuiInterface *ismGuiIfc)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Start init FileManagementDialogWidget...";
|
||||
|
||||
m_dtc = dtc;
|
||||
m_ftc = ftc;
|
||||
m_dataIfc = dataInterface;
|
||||
m_ismGuiIfc = ismGuiIfc;
|
||||
|
||||
bool bRet = true;
|
||||
bRet &= m_dtc->enableMainSchedule();
|
||||
bRet &= m_dtc->enableMainStructureElement();
|
||||
|
||||
bRet &= m_ftc->enableInstrumentationAssetModify();
|
||||
bRet &= m_ftc->enableMainScheduleRemove();
|
||||
|
||||
if (!bRet)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not enable DTC/FTC from ISM";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_scheduleId = m_dataIfc->scheduleId();
|
||||
|
||||
connect(m_dataIfc.get(), &ForeignDataInterface::scheduleIdChanged,
|
||||
this, &PlanTimeLineDialog::onScheduleIdChanged);
|
||||
connect(m_dtc.get(), &Interface::Dtc::mainScheduleChanged,
|
||||
this, &PlanTimeLineDialog::onMainScheduleChanged);
|
||||
|
||||
// timeline model initialization
|
||||
if (m_model != nullptr)
|
||||
delete m_model;
|
||||
m_model = new PlanTimelineModel(m_ui->timeline->view(), this);
|
||||
if (!m_model->initModel(m_dtc, m_dataIfc))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not init model";
|
||||
delete m_model;
|
||||
m_model = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_ui->timeline->setModel(m_model);
|
||||
#ifdef LTS_DEBUG
|
||||
m_ui->timeline->showDebugWidget();
|
||||
#endif
|
||||
m_ui->timeline->header()->setLimitsVisible(true);
|
||||
m_ui->timeline->setMinimumZoomFactor(LtsTimeline::Zoom::ceil(LtsTimeline::Zoom::OneDay));
|
||||
m_ui->timeline->setZoomFactor(s_zoomFactor);
|
||||
m_ui->timeline->view()->setItemDelegate(new PlanTimelineDelegate(m_ui->timeline->view()));
|
||||
resizeView();
|
||||
m_ui->timeline->show();
|
||||
|
||||
connect(m_ui->timeline->view(), &LtsTimeline::TimelineView::selectedItemsChanged,
|
||||
this, &PlanTimeLineDialog::onItemsSelected);
|
||||
connect(m_ui->timeline->view(), &LtsTimeline::TimelineView::currentItemTimeChanged,
|
||||
this, &PlanTimeLineDialog::onCurrentItemChanged);
|
||||
|
||||
connect(m_ui->timeline->view(), &LtsTimeline::TimelineView::zoomChanged,
|
||||
this, &PlanTimeLineDialog::onZoomChanged);
|
||||
|
||||
connect(m_ui->timeline->slider(), &QScrollBar::valueChanged,
|
||||
this, &PlanTimeLineDialog::onSliderValueChanged);
|
||||
|
||||
setScheduleId(m_scheduleId);
|
||||
|
||||
m_ui->timeline->view()->setDragEnabled(false);
|
||||
m_ui->timeline->timelineModel()->setEditable(true);
|
||||
m_ui->timeline->view()->setDragDropMode(LtsTimeline::TimelineView::NoDragDrop);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Save, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlanTimeLineDialog::setScheduleId(const int scheduleId)
|
||||
{
|
||||
m_scheduleId = scheduleId;
|
||||
|
||||
std::shared_ptr<InfrastructureManagement::ForeignDataInterface> ismIfc;
|
||||
if (!m_session->getForeignDataInterface<InfrastructureManagement::DataInterface>(ismIfc))
|
||||
{
|
||||
new LtsWidgets::LtsMessageDialogNew(this, tr("Infrastructure Management Interface is not available!"), tr("Cannot set Instrumentation Plan Id"));
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "ism_plan_tln_dialog: 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));
|
||||
|
||||
}
|
||||
|
||||
void PlanTimeLineDialog::retranslate()
|
||||
{
|
||||
//translate(m_ui, tr("Instrumentation Plan Timeline"));
|
||||
translate(m_ui, m_dtc->mainSchedule(m_scheduleId), tr("Instrumentation Plan Timeline"));
|
||||
}
|
||||
|
||||
void PlanTimeLineDialog::onLoad()
|
||||
{
|
||||
// get schedule id of selected item
|
||||
int scheduleId = m_model->getScheduleIdOfItem(m_selectedItem);
|
||||
if (scheduleId == -1)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "onLoad failed: Could not find model for selected item:" << m_selectedItem;
|
||||
return;
|
||||
}
|
||||
|
||||
emit m_dataIfc.get()->scheduleIdChanged(scheduleId);
|
||||
|
||||
}
|
||||
|
||||
void PlanTimeLineDialog::onRemove()
|
||||
{
|
||||
if (m_scheduleId == -1)
|
||||
return;
|
||||
|
||||
int scheduleId = m_model->getScheduleIdOfItem(m_selectedItem);
|
||||
MainSchedule item = m_dtc->mainSchedule(scheduleId);
|
||||
if (item.id() == m_scheduleId)
|
||||
{
|
||||
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Cannot remove current Instrumentation Plan"));
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void PlanTimeLineDialog::onApply()
|
||||
{
|
||||
if (!m_model)
|
||||
{
|
||||
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Invalid model!"));
|
||||
return;
|
||||
}
|
||||
QVector<int> itemIds = m_ui->timeline->timelineModel()->itemIds();
|
||||
for (auto itemId : qAsConst(itemIds))
|
||||
{
|
||||
int seId = m_model->getScheduleIdOfItem(itemId);
|
||||
if (seId == -1)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Could not find schedule for item id:" << itemId;
|
||||
continue;
|
||||
}
|
||||
InfrastructureManagement::MainSchedule mse = m_dtc->mainSchedule(seId);
|
||||
InfrastructureManagement::MainScheduleModifyRequest data;
|
||||
qint64 timeStart = m_ui->timeline->timelineModel()->item(itemId).startTime();
|
||||
qint64 timeEnd = timeStart + m_ui->timeline->timelineModel()->item(itemId).duration();
|
||||
data.id(mse.id());
|
||||
data.name(mse.name());
|
||||
data.statusId(mse.statusId());
|
||||
data.exerciseId(mse.exerciseId());
|
||||
data.timeCreated(mse.timeCreated());
|
||||
data.timeStart(timeStart);
|
||||
data.timeEnd(timeEnd);
|
||||
data.description(mse.description());
|
||||
|
||||
m_requestHelper->addRequest([data, this](){
|
||||
return m_ftc->mainScheduleModifyRequest(data, this);
|
||||
});
|
||||
}
|
||||
if (m_requestHelper->hasRequests())
|
||||
m_requestHelper->startRequests();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void PlanTimeLineDialog::onItemsSelected(const QVector<int> &itemIds)
|
||||
{
|
||||
if (itemIds.isEmpty())
|
||||
{
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, false);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui->timeline->setCurrentTime(m_model->getStartTime() - 10'000);
|
||||
m_selectedItem = itemIds.first();
|
||||
int32_t seId = m_model->getScheduleIdOfItem(m_selectedItem);
|
||||
if (m_scheduleId != seId && seId != -1)
|
||||
{
|
||||
MainSchedule mse = m_dtc->mainSchedule(seId);
|
||||
if (mse.timeStart().is_set())
|
||||
m_ui->timeline->setCurrentTime(mse.timeStart().get());
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, true);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, false);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlanTimeLineDialog::onScheduleIdChanged(int32_t id)
|
||||
{
|
||||
if (id == m_scheduleId)
|
||||
return;
|
||||
|
||||
m_scheduleId = id;
|
||||
setScheduleId(m_scheduleId);
|
||||
m_ismGuiIfc->setPlanId(m_scheduleId);
|
||||
updateTimeLine();
|
||||
|
||||
}
|
||||
void PlanTimeLineDialog::onMainScheduleChanged(const MainSchedule &data, DataModification modType)
|
||||
{
|
||||
updateTimeLine();
|
||||
Q_UNUSED(data);
|
||||
Q_UNUSED(modType);
|
||||
}
|
||||
|
||||
void PlanTimeLineDialog::updateTimeLine()
|
||||
{
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, false);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, false);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Save, false);
|
||||
|
||||
if (m_scheduleId == -1)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Invalid schedule id: timeline update aborted!";
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_model!= nullptr && !m_model->updateModel())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Invalid model!";
|
||||
return;
|
||||
}
|
||||
resizeView();
|
||||
}
|
||||
|
||||
void PlanTimeLineDialog::onCurrentItemChanged()
|
||||
{
|
||||
if (!m_buttonBox->getButton(LtsWidgets::DialogButton::Save)->isEnabled())
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Save, true);
|
||||
}
|
||||
|
||||
void PlanTimeLineDialog::onZoomChanged(LtsTimeline::ZoomFactor zoom)
|
||||
{
|
||||
s_zoomFactor = zoom;
|
||||
m_sliderCurrentTime = qint64(m_ui->timeline->slider()->value()) * 1000;
|
||||
}
|
||||
|
||||
void PlanTimeLineDialog::resizeView()
|
||||
{
|
||||
if (m_model == nullptr)
|
||||
return;
|
||||
qint64 startTime = m_model->getStartTime() - (2 * 60 * 60 * 1000);
|
||||
m_ui->timeline->setStartTime(startTime);
|
||||
qint64 duration = m_model->getDuration() + (4 * 60 * 60 * 1000);
|
||||
m_sliderCurrentTime = m_model->getStartTime();
|
||||
m_ui->timeline->setCurrentTime(m_model->getStartTime());
|
||||
m_ui->timeline->setDuration(duration);
|
||||
}
|
||||
|
||||
void PlanTimeLineDialog::onSliderValueChanged(int value)
|
||||
{
|
||||
m_sliderCurrentTime = qint64(value) *1000;
|
||||
}
|
||||
|
||||
} // namespace InfrastructureManagement
|
||||
Executable
+119
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Plans Overview Timeline Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
*$Autor: kemayou_s $
|
||||
* Created by Steve Kemayou, SLTE, 2021-07-26
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Timeline/ism_plan_tln_model.h"
|
||||
#include "ui_ism_plan_tln_dialog.h"
|
||||
|
||||
#include <LtsTimeline/timeline_utils.h>
|
||||
#include <LtsUtilsGuiDds/request_helper.h>
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
|
||||
#include <InfrastructureManagement/logger.h>
|
||||
|
||||
#include <LtsTimeline/item_delegate.h>
|
||||
#include <Plugins/InfrastructureManagement/Data/ism_data_plugin.h>
|
||||
#include <Plugins/InfrastructureManagement/ism_resource_management_gui_plugin_interface.h>
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class PlanTimeLineDialog;
|
||||
}
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
class LtsSession;
|
||||
}
|
||||
|
||||
namespace LtsPluginManager
|
||||
{
|
||||
class LtsPluginManager;
|
||||
}
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
|
||||
class PlanTimelineModel;
|
||||
|
||||
class PlanTimeLineDialog
|
||||
: public LtsWidgets::LtsDialog
|
||||
, protected Interface::Ftc::MainScheduleRemoveReplyHandler
|
||||
, protected Interface::Ftc::MainScheduleModifyReplyHandler
|
||||
, protected Interface::Ftc::InstrumentationAssetModifyReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PlanTimeLineDialog(LtsSession::LtsSession *session, const QString &menuGroup, QWidget *parent = nullptr);
|
||||
~PlanTimeLineDialog();
|
||||
|
||||
bool init(const std::shared_ptr<InfrastructureManagement::Interface::Dtc> &dtc,
|
||||
const std::shared_ptr<Interface::Ftc> &ftc,
|
||||
const std::shared_ptr<ForeignDataInterface> &dataInterface,
|
||||
ForeignResourceManagementGuiInterface *ismGuiIfc);
|
||||
|
||||
void retranslate() override;
|
||||
void setScheduleId(const int scheduleId);
|
||||
int getSelectedItem(){ return m_selectedItem;}
|
||||
|
||||
protected:
|
||||
void onMainScheduleRemoveReply(const Core::FunctionReplyObject &replyObject) override final
|
||||
{
|
||||
m_requestHelper->requestReply(replyObject);
|
||||
}
|
||||
void onInstrumentationAssetModifyReply(const Core::FunctionReplyObject &replyObject) override final
|
||||
{
|
||||
m_requestHelper->requestReply(replyObject);
|
||||
}
|
||||
void onMainScheduleModifyReply(const Core::FunctionReplyObject &replyObject) override final
|
||||
{
|
||||
m_requestHelper->requestReply(replyObject);
|
||||
}
|
||||
|
||||
private slots:
|
||||
void onLoad();
|
||||
void onRemove();
|
||||
void onApply();
|
||||
void onItemsSelected(const QVector<int> &itemIds);
|
||||
void onScheduleIdChanged(int32_t id);
|
||||
void onMainScheduleChanged(const MainSchedule &data, DataModification modType);
|
||||
void updateTimeLine();
|
||||
void onCurrentItemChanged();
|
||||
void onZoomChanged(LtsTimeline::ZoomFactor zoom);
|
||||
void resizeView();
|
||||
void onSliderValueChanged(int value);
|
||||
|
||||
private:
|
||||
LtsSession::LtsSession *m_session { nullptr };
|
||||
QString m_menuGroup;
|
||||
qint64 m_sliderCurrentTime{0};
|
||||
|
||||
int m_scheduleId{-1};
|
||||
int m_selectedItem{-1};
|
||||
|
||||
PlanTimelineModel *m_model { nullptr };
|
||||
std::shared_ptr<Interface::Dtc> m_dtc;
|
||||
std::shared_ptr<Interface::Ftc> m_ftc{nullptr};
|
||||
std::shared_ptr<ForeignDataInterface> m_dataIfc;
|
||||
ForeignResourceManagementGuiInterface *m_ismGuiIfc{nullptr};
|
||||
LtsUtils::RequestHelper *m_requestHelper{nullptr};
|
||||
|
||||
TimelineViewResizeHandler *m_resizeHandler { nullptr };
|
||||
QPoint m_cursorPosition;
|
||||
|
||||
Ui::PlanTimeLineDialog *m_ui{nullptr};
|
||||
LOGGER_T &m_logger;
|
||||
|
||||
};
|
||||
|
||||
} // namespace InfrastructureManagement
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PlanTimeLineDialog</class>
|
||||
<widget class="QWidget" name="PlanTimeLineDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="LtsTimeline::TimelineWidget" name="timeline" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>LtsTimeline::TimelineWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>LtsTimeline/timeline_widget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Executable
+213
@@ -0,0 +1,213 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Plans Overview Timeline Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Steve Kemayou, SLTE, 2021-07-26
|
||||
*/
|
||||
|
||||
#include "ism_plan_tln_model.h"
|
||||
#include <LtsWidgets/lts_message_dialog.h>
|
||||
#include <QDateTime>
|
||||
|
||||
//using namespace LtsTimelineClassic;
|
||||
using namespace LtsTimeline;
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
|
||||
PlanTimelineModel::PlanTimelineModel(TimelineView *tlv, QObject *parent)
|
||||
: LtsTimeline::TimelineModel(tlv, parent)
|
||||
, m_session(nullptr)
|
||||
, m_startTime(QDateTime::currentMSecsSinceEpoch())
|
||||
, m_endTime(m_startTime + (LtsTimeline::ZoomFactor::OneDay))
|
||||
, m_scheduleId(-1)
|
||||
, m_tlv(tlv)
|
||||
, m_logger(getLogger("PlanTimeLineModel"))
|
||||
{
|
||||
}
|
||||
|
||||
bool PlanTimelineModel::initModel(const std::shared_ptr<InfrastructureManagement::Interface::Dtc> &dtc, const std::shared_ptr<ForeignDataInterface> &dataInterface)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Start init FileManagement timeline model...";
|
||||
|
||||
if (m_dtc == dtc)
|
||||
return true;
|
||||
|
||||
m_dtc = dtc;
|
||||
bool bRet = true;
|
||||
bRet &= m_dtc->enableMainSchedule();
|
||||
bRet &= m_dtc->enableMainStructureElement();
|
||||
|
||||
m_dataInterface = dataInterface;
|
||||
m_scheduleId = m_dataInterface->scheduleId();
|
||||
|
||||
connect(m_dataInterface.get(), &ForeignDataInterface::scheduleIdChanged,
|
||||
this, &PlanTimelineModel::onScheduleIdChanged);
|
||||
|
||||
if (!bRet)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not enable ISM DTC Main schedule or Structure elements";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!setModel())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not set timeline model";
|
||||
return false;
|
||||
}
|
||||
|
||||
INFO_LOG(m_logger) << "initModel successful";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PlanTimelineModel::setModel()
|
||||
{
|
||||
if (m_scheduleId == -1)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Invalid scheduleId " << m_scheduleId;
|
||||
return false;
|
||||
}
|
||||
|
||||
QVector <int> scheduleIds{};
|
||||
scheduleIds = m_dtc->getIntersectedMainSchedulesIds(m_scheduleId);
|
||||
|
||||
int itemIndex = 0, itemId = 0;
|
||||
m_startTime = QDateTime::currentMSecsSinceEpoch();
|
||||
m_endTime = QDateTime::currentMSecsSinceEpoch() + (LtsTimeline::ZoomFactor::OneDay);
|
||||
m_duration = m_endTime - m_startTime;
|
||||
|
||||
for (auto scheduleId : qAsConst(scheduleIds))
|
||||
{
|
||||
MainSchedule mse = m_dtc->mainSchedule(scheduleId);
|
||||
|
||||
if (scheduleId == m_scheduleId)
|
||||
{
|
||||
if (!mse.timeStart().is_set() || !mse.timeEnd().is_set())
|
||||
{
|
||||
LtsWidgets::LtsMessageDialog::showMessage(m_tlv, tr("Invalid Begin/End time for Instrumentation Plan with Id = %1").arg(m_scheduleId));
|
||||
return true;
|
||||
}
|
||||
if (mse.timeStart().is_set())
|
||||
m_startTime = mse.timeStart().get();
|
||||
if (mse.timeEnd().is_set())
|
||||
m_endTime = mse.timeEnd().get();
|
||||
m_duration = m_endTime - m_startTime;
|
||||
}
|
||||
QColor color = (mse.id() == m_scheduleId) ? QColor(2,47,102) : getColor(mse.id());
|
||||
if (mse.timeStart().is_set() && mse.timeEnd().is_set())
|
||||
{
|
||||
try
|
||||
{
|
||||
this->addTrack<LtsTimeline::Track>(0, LtsTimeline::Track(QString::fromStdString(mse.name())));
|
||||
itemId = this->addItem<LtsTimeline::Item>(++itemIndex, LtsTimeline::Item(mse.timeStart().get(), (mse.timeEnd().get() - mse.timeStart().get()), color));
|
||||
m_itemIntersection.push_back({scheduleId,itemId});
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "## Unable to add item or track to model. Exception: " << e.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
WARNING_LOG(m_logger) << "Time start/end not set for schedule id " << mse.id();
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool PlanTimelineModel::updateModel()
|
||||
{
|
||||
this->clear();
|
||||
m_itemIntersection.clear();
|
||||
setModel();
|
||||
return true;
|
||||
}
|
||||
|
||||
qint64 PlanTimelineModel::getDuration() const
|
||||
{
|
||||
return m_duration;
|
||||
}
|
||||
|
||||
qint64 PlanTimelineModel::getStartTime() const
|
||||
{
|
||||
return m_startTime;
|
||||
}
|
||||
|
||||
qint64 PlanTimelineModel::getCurrentTime() const
|
||||
{
|
||||
return m_startTime;
|
||||
}
|
||||
|
||||
QVector<PlanTimelineModel::ItemIntersection> PlanTimelineModel::getIntersectedPlan() const
|
||||
{
|
||||
return m_itemIntersection;
|
||||
}
|
||||
|
||||
int32_t PlanTimelineModel::getScheduleIdOfItem(int itemId)
|
||||
{
|
||||
int32_t scheduleId = -1;
|
||||
for (auto item : qAsConst(m_itemIntersection))
|
||||
{
|
||||
if (item.itemId == itemId)
|
||||
{
|
||||
scheduleId = item.scheduleId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return scheduleId;
|
||||
}
|
||||
|
||||
void PlanTimelineModel::onScheduleIdChanged(int32_t scheduleId)
|
||||
{
|
||||
if (scheduleId == m_scheduleId)
|
||||
return;
|
||||
m_scheduleId = scheduleId;
|
||||
}
|
||||
|
||||
//QVariant PlanTimelineModel::data(const QModelIndex &index, int role) const
|
||||
//{
|
||||
//// if (isCurrentlyUpdating())
|
||||
//// return {};
|
||||
|
||||
// if (role != Qt::DisplayRole || !index.isValid() || index.column() != 0)
|
||||
// return {};
|
||||
|
||||
// // actuators column (0)
|
||||
// QString text;
|
||||
|
||||
// try
|
||||
// {
|
||||
// const Track &t = track(index.internalId());
|
||||
// text = QStringLiteral("%1").arg(t.text());
|
||||
// }
|
||||
// catch(...)
|
||||
// {
|
||||
// Q_ASSERT(false);
|
||||
// return QStringLiteral("[?????]");
|
||||
// }
|
||||
|
||||
// if (text.isEmpty())
|
||||
// text = tr("[unknown]");
|
||||
|
||||
// return text;
|
||||
//}
|
||||
|
||||
QColor PlanTimelineModel::getColor(int planId)
|
||||
{
|
||||
MainSchedule ms = m_dtc->mainSchedule(planId);
|
||||
switch (ms.statusId().underlying())
|
||||
{
|
||||
case ScheduleStatus::Active:
|
||||
return QColor(Qt::darkGreen);
|
||||
case ScheduleStatus::Inactive:
|
||||
return QColor(Qt::red);
|
||||
default:
|
||||
return QColor(Qt::lightGray);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace InfrastructureManagement
|
||||
Executable
+80
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Plans Overview Timeline Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Steve Kemayou, SLTE, 2021-07-26
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LtsUtilsGuiDds/request_helper.h>
|
||||
#include <LtsUtilsGuiDds/request_helper.h>
|
||||
|
||||
#include <InfrastructureManagement/logger.h>
|
||||
#include <Plugins/InfrastructureManagement/Data/ism_data_plugin.h>
|
||||
#include <Plugins/Timeline/tln_data_plugin_interface.h>
|
||||
#include <Plugins/InfrastructureManagement/ism_resource_management_gui_plugin_interface.h>
|
||||
|
||||
//#include <LtsEventTimeline/AbstractTimelineModel.h>
|
||||
#include <LtsTimeline/item.h>
|
||||
#include <LtsTimeline/timeline_model.h>
|
||||
#include <LtsTimeline/timeline_utils.h>
|
||||
#include <LtsTimeline/timeline_view.h>
|
||||
|
||||
namespace LtsSession { class LtsSession; }
|
||||
namespace LtsPluginManager { class LtsPluginManager; }
|
||||
namespace LtsTimeline { class TimelineView; }
|
||||
|
||||
using namespace LtsTimeline;
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
class PlanTimelineModel: public LtsTimeline::TimelineModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PlanTimelineModel(TimelineView *tlv, QObject *parent);
|
||||
|
||||
bool initModel(const std::shared_ptr<InfrastructureManagement::Interface::Dtc> &dtc, const std::shared_ptr<ForeignDataInterface> &dataInterface);
|
||||
|
||||
struct ItemIntersection
|
||||
{
|
||||
int scheduleId;
|
||||
int itemId;
|
||||
};
|
||||
|
||||
bool updateModel();
|
||||
qint64 getDuration() const;
|
||||
qint64 getStartTime() const;
|
||||
qint64 getCurrentTime() const;
|
||||
|
||||
//QVariant data(const QModelIndex &index, int role) const override;
|
||||
QVector<PlanTimelineModel::ItemIntersection> getIntersectedPlan() const;
|
||||
int32_t getScheduleIdOfItem(int itemId);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onScheduleIdChanged(int32_t scheduleId);
|
||||
|
||||
private:
|
||||
bool setModel();
|
||||
QColor getColor(int planId);
|
||||
LtsSession::LtsSession *m_session;
|
||||
|
||||
qint64 m_startTime{0};
|
||||
qint64 m_currentTime{0};
|
||||
qint64 m_endTime{0};
|
||||
qint64 m_duration{0};
|
||||
QVector<ItemIntersection> m_itemIntersection{};
|
||||
|
||||
std::shared_ptr<InfrastructureManagement::Interface::Dtc> m_dtc;
|
||||
std::shared_ptr<InfrastructureManagement::ForeignDataInterface> m_dataInterface;
|
||||
int32_t m_scheduleId{-1};
|
||||
TimelineView *m_tlv;
|
||||
|
||||
LOGGER_T &m_logger;
|
||||
};
|
||||
|
||||
} // namespace InfrastructureManagement
|
||||
Reference in new issue
Block a user