Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

@@ -0,0 +1,48 @@
#
# $Id$
# $HeadURL$
# $Author$
# Created by Patric Karwat, SLSE, 2018-01-17
#
SET(obd_base_downloader_gui_SRCS
obd_base_downloader_gui_plugin.cpp
obd_base_downloader_gui_plugin.h
obd_base_downloader.cpp
obd_base_downloader.h
obd_ex_model.cpp
obd_ex_model.h
obd_base_downloader_message.cpp
obd_base_downloader_message.h
obd_base_downloader_pdf_selector.cpp
obd_base_downloader_pdf_selector.h
)
NGL_WRAP_UI(obd_base_downloader_gui_SRCS
obd_base_downloader.ui
obd_base_downloader_message.ui
obd_base_downloader_pdf_selector.ui
)
NGL_ADD_LIBRARY(WS ObdBaseDownloaderGuiPlugin MODULE ${obd_base_downloader_gui_SRCS})
NGL_TARGET_LINK_LIBRARIES(ObdBaseDownloaderGuiPlugin
NGLLogger
ngltools
svcObdClient
svcExmClient
LtsPrinting
LtsSession
LtsDataView
LtsSessionData
LtsWidgets
LtsUtilsGuiDds
LtsUtilsSettings
nglsettings
ObdBaseDownloaderGuiPluginInterface
ObdDataPluginInterface
Qt5::Widgets
Qt5::Network
Qt5::WebSockets
)
NGL_INSTALL_TARGET(ObdBaseDownloaderGuiPlugin)
@@ -0,0 +1,524 @@
/**
* @RDE_HEADER@
* HMI Plugin for Observer Controller - BaseDownloader Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2018-03-17
*/
#include "obd_base_downloader.h"
#include "ui_obd_base_downloader.h"
#include "obd_base_downloader_pdf_selector.h"
#include <LtsSession/lts_session_data.h>
#include <nglsettings/nglsettings_connections.h>
#include <LtsUtilsSettings/settings.h>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QTimer>
#include <QWebSocket>
namespace OcBaseDownload
{
BaseDownloader::BaseDownloader(const QString &menuGroup, LtsSession::LtsSession *session, QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::SeamlessDialog)
, m_menuGroup(menuGroup)
, m_errorMsg(QString())
, m_model(new ExModel(this))
, m_session(session)
, m_messageDlg(nullptr)
, m_state(ConnectionState::Start)
, m_socket(new QWebSocket(QString(), QWebSocketProtocol::Version13, this))
, m_timer(new QTimer(this))
, m_ftcTimer(new QTimer(this))
, m_exmDtc(nullptr)
, m_requestHelper(new LtsUtils::RequestHelper(this))
, m_ui(new Ui::BaseDownloader)
, m_logger(getLogger("BaseDownloaderDialog"))
{
m_ui->setupUi(this);
m_ui->leStatus->setText(tr("Not Connected"));
#ifndef LTS_DEBUG
//hide server things
m_ui->leServer->setVisible(false);
m_ui->lblServer->setVisible(false);
m_ui->spPort->setVisible(false);
#endif
setUnchangeable(true);
m_timer->setSingleShot(true);
m_timer->setInterval(5000);
connect(m_timer, &QTimer::timeout, this, &BaseDownloader::onTimerTimeout);
m_ftcTimer->setInterval(5*60*1000);
connect(m_ftcTimer, &QTimer::timeout, this, &BaseDownloader::onFtcTimerTimeout);
connect(m_ui->pbDownload, &QPushButton::clicked, this, &BaseDownloader::startBaseDownload);
connect(m_ui->tvExercises, &LtsDataView::LtsDataView::selectionChanged, this, &BaseDownloader::selectionChanged);
connect(m_ui->pbConnect, &QPushButton::clicked, this, &BaseDownloader::downloadExercises);
//connect(m_ui->leServer, &QLineEdit::editingFinished , this, &BaseDownloader::downloadExercises);
connect(m_ui->leServer, &QLineEdit::textChanged, this, [this]
{
m_ui->pbConnect->setEnabled(!m_ui->leServer->text().isEmpty());
});
connect(m_socket, &QWebSocket::stateChanged,
this, &BaseDownloader::onNewSocketState);
connect(m_socket, &QWebSocket::textMessageReceived,
this, &BaseDownloader::onNewTextMessageFromSocket);
} // end of ctor()
BaseDownloader::~BaseDownloader()
{
m_socket->disconnect(this);
delete m_ui;
delete m_messageDlg;
}
bool BaseDownloader::init()
{
if (!m_session->getFtc<OcBaseDownload::DataInterface>(m_ftc))
return false;
if (!m_session->getDtc<ExerciseManagement::DataInterface>(m_exmDtc))
return false;
if (strcmp(PROJECTBUILD, "guez") == 0)
m_ui->pbPdfDownload->hide();
m_proxyModel = new ExProxyModel(this);
m_proxyModel->setSourceModel(m_model);
m_ui->tvExercises->setModel(m_proxyModel);
#ifndef LTS_DEBUG
m_ui->tvExercises->setColumnHidden(ExModel::Id, true);
#endif
m_ui->leServer->setText(NGL::Connections::hostName(NGL::Connections::eConnection::SCM_WEBSOCKET));
m_ui->spPort->setValue(NGL::Connections::port(NGL::Connections::eConnection::SCM_WEBSOCKET));
selectionChanged();
m_messageDlg = new BaseDownloaderMessage(this);
connect(m_messageDlg, &BaseDownloaderMessage::finished, this, [this]
{
if (m_ui)
{
m_ui->pbDownload->setEnabled(true);
m_ui->pbPdfDownload->setEnabled(true);
}
});
connect(m_ui->pbPdfDownload, &QPushButton::clicked,
this, &BaseDownloader::onPdfDownloadClicked);
connect(m_ui->pbOcPdfDownload, &QPushButton::clicked,
this, &BaseDownloader::onOcPdfDownloadClicked);
m_ui->pbOcPdfDownload->hide();
return true;
}
void BaseDownloader::onStartBaseDownloadReply(const BaseDownloadReply &replyObject)
{
DEBUG_LOG(m_logger) << "NEW STATE REPLY: " << replyObject.currentStep() << " \n" << replyObject.progress();
switch (replyObject.replyState().underlying())
{
case Core::FtReplyState::InProgress:
{
//restart Timer
m_ftcTimer->start();
m_messageDlg->setText(tr("Download in Progress <br> %1").arg(QCoreApplication::translate("dds", replyObject.currentStep().c_str())));
m_messageDlg->setProgress(replyObject.progress());
break;
}
case Core::FtReplyState::Completed:
{
m_ftcTimer->stop();
m_messageDlg->setText(tr("Download Complete"));
m_messageDlg->setCloseable(true);
m_messageDlg->setProgress(100);
m_ui->pbDownload->setEnabled(true);
m_ui->pbPdfDownload->setEnabled(true);
break;
}
case Core::FtReplyState::NotStarted:
break;
case Core::FtReplyState::Error:
{
m_ftcTimer->stop();
m_messageDlg->setText(tr("Error Downloading Base Data for Exercise %1 <br> Error: %2").arg(m_exerciseId).arg(QString::fromStdString(replyObject.errorString())));
m_messageDlg->setCloseable(true);
m_ui->pbDownload->setEnabled(true);
m_ui->pbPdfDownload->setEnabled(true);
break;
}
}
}
void BaseDownloader::onStartPdfDownloadReply(const PdfDownloadReply &reply)
{
m_messageDlg->setText(QString::fromStdString(reply.currentStep()) + QStringLiteral(" ") + QString::number(reply.replyState().underlying()));
switch (reply.replyState().underlying())
{
case Core::FtReplyState::InProgress:
//restart Timer
m_ftcTimer->start();
m_messageDlg->setText(tr("Download in Progress <br> %1").arg(QCoreApplication::translate("dds", reply.currentStep().c_str())));
m_messageDlg->setProgress(reply.progress());
break;
case Core::FtReplyState::Completed:
{
m_ftcTimer->stop();
m_messageDlg->setText(tr("Download Complete"));
m_messageDlg->setCloseable(true);
m_messageDlg->setProgress(100);
m_ui->pbDownload->setEnabled(true);
m_ui->pbPdfDownload->setEnabled(true);
break;
}
case Core::FtReplyState::NotStarted:
break;
case Core::FtReplyState::Error:
m_ftcTimer->stop();
m_messageDlg->setText(tr("Error Downloading PDF data"));
m_messageDlg->setCloseable(true);
m_ui->pbDownload->setEnabled(true);
m_ui->pbPdfDownload->setEnabled(true);
break;
}
}
void BaseDownloader::startBaseDownload()
{
auto ret = LtsWidgets::LtsMessageDialog::showMessage(this,
tr("Currently downloaded exercise will be deleted. This may take some time."),
windowTitle(),
LtsWidgets::Behaviour::Modal,
LtsWidgets::Button::Ok | LtsWidgets::Button::Cancel);
if (ret != LtsWidgets::Button::Ok)
return;
m_exerciseId = m_model->getRowData(m_ui->tvExercises->currentIndex().row()).id();
const StartBaseDownloadRequest req(m_exerciseId,
LtsSessionData::LtsSessionData::getInstance()->getOperatorId(),
m_ui->spPort->value(),
m_ui->leServer->text().toStdString(),
QDateTime::currentMSecsSinceEpoch());
DEBUG_LOG(m_logger) << "EXERCISE ID: " << m_exerciseId;
// NO request helper here, as we got a custom function with a state
if (m_ftc->startBaseDownloadRequest(req, this))
{
m_ui->pbDownload->setEnabled(false);
m_ui->pbPdfDownload->setEnabled(false);
m_messageDlg->setText(tr("Start Base Download for Exercise %1").arg(m_exerciseId));
m_messageDlg->show();
}
}
void BaseDownloader::selectionChanged()
{
bool isEnabled = m_ui->tvExercises->selectionModel()->selectedRows().size() == 1;
m_ui->pbDownload->setEnabled(isEnabled);
m_ui->pbPdfDownload->setEnabled(isEnabled);
}
void BaseDownloader::downloadExercises()
{
if (m_state != ConnectionState::Start)
{
m_socket->close();
m_state = ConnectionState::Start;
}
else
m_socket->open(getUrl(m_ui->leServer->text(), m_ui->spPort->value()));
}
void BaseDownloader::onNewSocketState(QAbstractSocket::SocketState state)
{
bool enable = true;
switch (state)
{
case QAbstractSocket::UnconnectedState:
{
m_ui->leStatus->setText(tr("Not Connected: %1").arg(m_errorMsg));
break;
}
case QAbstractSocket::ConnectingState:
{
enable = false;
m_errorMsg.clear();
m_ui->leStatus->setText(tr("Connecting to: %1").arg(m_ui->leServer->text()));
m_ui->pbDownload->setEnabled(false);
m_ui->pbPdfDownload->setEnabled(false);
break;
}
case QAbstractSocket::ConnectedState:
{
enable = false;
if (m_state == ConnectionState::Start)
{
m_state = ConnectionState::ConnectedToExternalServer;
m_ui->leStatus->setText(tr("Connected to: %1 (Service Management").arg(m_ui->leServer->text()));
sendProcessListRequest();
}
else if (m_state == ConnectionState::ConnectedToExternalServer)
{
m_state = ConnectionState::ConnectedToExerciseManagement;
m_ui->leStatus->setText(tr("Connected to: %1 (Exercise Management").arg(m_ui->leServer->text()));
sendExerciseListRequest();
}
m_ui->pbConnect->setEnabled(true);
m_ui->pbConnect->setText(tr("Disconnect"));
break;
}
case QAbstractSocket::ClosingState:
{
if (m_state == ConnectionState::ConnectedToExerciseManagement)
{
//go back to start
m_state = ConnectionState::Start;
}
m_model->clear();
m_ui->pbConnect->setEnabled(true);
m_ui->pbConnect->setText(tr("Get Exercises"));
m_ui->pbDownload->setEnabled(false);
m_ui->pbPdfDownload->setEnabled(false);
break;
}
case QAbstractSocket::HostLookupState:
{
m_errorMsg = QStringLiteral(": ") + tr("Can't connect to: %1").arg(m_ui->leServer->text());
break;
}
case QAbstractSocket::ListeningState:
case QAbstractSocket::BoundState:
break;
}
m_ui->leServer->setEnabled(enable);
m_ui->spPort->setEnabled(enable);
}
void BaseDownloader::onNewTextMessageFromSocket(const QString &message)
{
// stop timer first then handle message
m_timer->stop();
if (m_state == ConnectionState::ConnectedToExternalServer)
{
DEBUG_LOG(m_logger) << "message from SVC " << message;
doConnectToExerciseManagement(message);
}
else if (m_state == ConnectionState::ConnectedToExerciseManagement)
{
DEBUG_LOG(m_logger) << "message from EXM " << message;
fillExerciseModel(message);
}
}
void BaseDownloader::onTimerTimeout()
{
QString processName = m_state == ConnectionState::ConnectedToExerciseManagement ? tr("Exercise Management") : tr("Service Management");
m_errorMsg = QStringLiteral(": ") + tr("No Answer from %1 (%2)").arg(m_ui->leServer->text(), processName);
m_socket->close();
}
void BaseDownloader::onFtcTimerTimeout()
{
//can't use singleshot
m_ftcTimer->stop();
m_messageDlg->setText(tr("Error while downloading data: bailing out."));
m_messageDlg->setCloseable(true);
m_ui->pbDownload->setEnabled(true);
m_ui->pbPdfDownload->setEnabled(true);
}
void BaseDownloader::onPdfDownloadClicked()
{
m_exerciseId = m_model->getRowData(m_ui->tvExercises->currentIndex().row()).id();
if (m_exmDtc->exercise(m_exerciseId).id() != m_exerciseId)
{
LtsWidgets::LtsMessageDialog::showMessage(this,
tr("Make sure to download exercise with ID %1 first.").arg(m_exerciseId),
windowTitle(),
LtsWidgets::Behaviour::Modal,
LtsWidgets::Button::Ok);
return;
}
BaseDownloaderPdfSelector *pdfSel = new BaseDownloaderPdfSelector(this);
pdfSel->show();
GetPdfListRequest req(m_exerciseId,
m_ui->leServer->text().toStdString(),
m_ui->spPort->value());
m_ftc->getPdfListRequest(req, pdfSel);
connect(pdfSel, &BaseDownloaderPdfSelector::ok,
this, [this, pdfSel]()
{
if (m_ftc->startPdfDownloadRequest({pdfSel->checkedPdfIds(),
m_ui->leServer->text().toStdString(),
m_model->getRowData(m_ui->tvExercises->currentIndex().row()).id()
},
this))
{
m_ui->pbDownload->setEnabled(false);
m_ui->pbPdfDownload->setEnabled(false);
m_messageDlg->setText(tr("Start PDF download for Exercise %1").arg(m_exerciseId));
m_messageDlg->show();
}
pdfSel->close();
});
}
void BaseDownloader::onOcPdfDownloadClicked()
{
LtsUtils::ProjectSettings *ps = LtsUtils::ProjectSettings::getInstance();
const int folderId = ps->value(QStringLiteral("obd"), QStringLiteral("ocPdfDownloadFolderId")).toInt();
if(folderId <= 0)
{
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Couldn't download pdf files: Folder id invalid!"));
return;
}
const QString matrixOperator = LtsSessionData::LtsSessionData::getInstance()->getOperatorName();
DEBUG_LOG(m_logger)<<LOGFUNCTION<<" folderId:" <<folderId<<" operatorName: "<<matrixOperator;
OcPdfDownloadRequest req(folderId,matrixOperator.toStdString());
m_ftc->ocPdfDownloadRequest(req, this);
}
void BaseDownloader::retranslate()
{
translate(m_ui, tr("Base Downloader"));
}
void BaseDownloader::doConnectToExerciseManagement(const QString &message)
{
m_socket->close();
int exPort = -1;
QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8());
if (!doc.isObject())
{
WARNING_LOG(m_logger) << "No Valid Object in " << message;
return;
}
if (!doc.object().value(QStringLiteral("data")).isArray())
{
WARNING_LOG(m_logger) << "No Data Array in" << message;
return;
}
const QJsonArray exercises = doc.object().value(QStringLiteral("data")).toArray();
QJsonArray services;
for (const QJsonValue &exercise : exercises)
{
const QJsonObject &exe = exercise.toObject();
if (exe.value(QStringLiteral("exerciseId")).toInt(-1) == 0)
{
services = exe.value(QStringLiteral("services")).toArray();
break;
}
}
for (const QJsonValue &service : qAsConst(services))
{
const QJsonObject &obj = service.toObject();
if (obj.value(QStringLiteral("name")).toString() == QStringLiteral("ExerciseManagement"))
{
const QJsonArray ports = obj.value(QStringLiteral("ports")).toArray();
for (const QJsonValue &port : ports)
{
if (port.toObject().value(QStringLiteral("typeId")).toInt() == 1)
exPort = port.toObject().value(QStringLiteral("number")).toInt(-1);
}
}
}
if (exPort > 0)
{
DEBUG_LOG(m_logger) << "Connect To EXM";
m_socket->open(getUrl(m_ui->leServer->text(), exPort));
}
}
QUrl BaseDownloader::getUrl(const QString &adress, unsigned short port) const
{
QString url = QLatin1String("ws://") + adress + QLatin1Char(':') + QString::number(port);
DEBUG_LOG(m_logger) << "Connect to: " << url;
return QUrl(url);
}
void BaseDownloader::sendProcessListRequest()
{
DEBUG_LOG(m_logger) << "send processListRequest message to SVC";
m_timer->start();
m_socket->sendTextMessage(QStringLiteral("{\"type\": \"servicePortsInformationRequest\",\"uuid\": \"7777\"}"));
m_ui->leStatus->setText(tr("Wait for Service Data."));
}
void BaseDownloader::sendExerciseListRequest()
{
DEBUG_LOG(m_logger) << "send exerciseListRequest message to EXM";
m_timer->start();
m_ftcTimer->start();
m_socket->sendTextMessage(QStringLiteral("{\"type\": \"exerciseInformationRequest\",\"uuid\": \"7777\"}"));
m_ui->leStatus->setText(tr("Wait for Exercise Data."));
}
void BaseDownloader::fillExerciseModel(const QString &exerciseList)
{
//Exercise{"data":[{"description":"","endTime":1523688359000,"id":35,"name":"Test Exercise 35","startTime":1522824359000,"status":1,"timeZone":"Z"},{"description":"","endTime":1523688359000,"id":42,"name":"Test Exercise 42","startTime":1522824359000,"status":2,"timeZone":"Z"}],"type":"exerciseInformation","uuid":"7777"} (OcBaseDownload/Gui/BaseDownloader/obd_ex_model.cpp:45)
m_ui->leStatus->setText(tr("Got Data from Exercise Management."));
QJsonDocument doc = QJsonDocument::fromJson(exerciseList.toUtf8());
if (!doc.isObject() || !doc.object().value(QStringLiteral("data")).isArray())
{
WARNING_LOG(m_logger) << "No Valid Object in " << exerciseList;
m_ui->leStatus->setText(tr("Got Invalid Data from Exercise Management."));
return;
}
m_model->clear();
const QJsonArray exercises = doc.object().value(QStringLiteral("data")).toArray();
for (const QJsonValue &exercise : exercises)
{
const QJsonObject &exe = exercise.toObject();
m_model->addExercise(exe);
}
}
} // namespace OcBaseDownload
@@ -0,0 +1,109 @@
/**
* @RDE_HEADER@
* HMI Plugin for Observer Controller - Base Downloader Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2018-03-17
*/
#pragma once
#include "obd_base_downloader_message.h"
#include <LtsWidgets/lts_dialog.h>
#include <LtsSession/lts_session.h>
#include <LtsUtilsGuiDds/request_helper.h>
#include <OcBaseDownload/logger.h>
#include <Plugins/OcBaseDownload/obd_data_plugin_interface.h>
#include "obd_ex_model.h"
#include <ExerciseManagement/exm_data_plugin_interface.h>
#include <AssetManagement/asm_data_plugin_interface.h>
#include <FileManagement/flm_data_plugin_interface.h>
#include <QtNetwork/QAbstractSocket>
class QWebSocket;
namespace Ui
{
class BaseDownloader;
}
namespace OcBaseDownload
{
enum class ConnectionState
{
Start = 0,
ConnectedToExternalServer,
ConnectedToExerciseManagement,
Finished
};
class BaseDownloader : public LtsWidgets::LtsDialog
, protected OcBaseDownload::Interface::Ftc::StartBaseDownloadReplyHandler
, protected OcBaseDownload::Interface::Ftc::StartPdfDownloadReplyHandler
, protected OcBaseDownload::Interface::Ftc::OcPdfDownloadReplyHandler
{
Q_OBJECT
public:
explicit BaseDownloader(const QString &menuGroup, LtsSession::LtsSession *session, QWidget *parent = nullptr);
~BaseDownloader();
bool init();
//ftc
void onStartBaseDownloadReply(const BaseDownloadReply &replyObject) override final;
void onStartPdfDownloadReply(const PdfDownloadReply &reply) override final;
void onOcPdfDownloadReply(const Core::FunctionReplyObject &replyObject) override final { m_requestHelper->requestReply(replyObject);}
private Q_SLOTS:
void startBaseDownload();
void selectionChanged();
void downloadExercises();
void onNewSocketState(QAbstractSocket::SocketState state);
void onNewTextMessageFromSocket(const QString &message);
void onTimerTimeout();
void onFtcTimerTimeout();
void onPdfDownloadClicked();
void onOcPdfDownloadClicked();
private:
void retranslate() override;
void doConnectToExerciseManagement(const QString &message);
QUrl getUrl(const QString &adress, unsigned short port) const;
void sendProcessListRequest();
void sendExerciseListRequest();
void fillExerciseModel(const QString &exerciseList);
private:
QString m_menuGroup;
QString m_errorMsg;
ExModel *m_model;
ExProxyModel *m_proxyModel;
LtsSession::LtsSession *m_session;
BaseDownloaderMessage *m_messageDlg;
ConnectionState m_state;
QWebSocket *m_socket;
QTimer *m_timer;
QTimer *m_ftcTimer;
std::shared_ptr<OcBaseDownload::Interface::Ftc> m_ftc;
std::shared_ptr<ExerciseManagement::Interface::Dtc> m_exmDtc;
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
LtsUtils::RequestHelper *m_requestHelper{nullptr};
int m_exerciseId = 0;
Ui::BaseDownloader *m_ui;
LOGGER_T m_logger;
};
} // namespace OcBaseDownload
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BaseDownloader</class>
<widget class="QWidget" name="BaseDownloader">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>688</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">MessagingView</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLineEdit" name="leServer">
<property name="text">
<string>EXCTDS01</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblServer">
<property name="text">
<string>Server:</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QPushButton" name="pbConnect">
<property name="text">
<string>Get Exercises</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QSpinBox" name="spPort">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>99999</number>
</property>
<property name="value">
<number>7300</number>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QPushButton" name="pbPdfDownload">
<property name="text">
<string>PDF Download</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="6">
<widget class="LtsDataView::LtsDataView" name="tvExercises" native="true"/>
</item>
<item row="3" column="0" colspan="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="5">
<widget class="QPushButton" name="pbDownload">
<property name="text">
<string>Base Download</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="6">
<widget class="QLineEdit" name="leStatus">
<property name="enabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QPushButton" name="pbOcPdfDownload">
<property name="text">
<string>OC Pdf Download</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsDataView::LtsDataView</class>
<extends>QWidget</extends>
<header>LtsDataView/lts_data_view.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,119 @@
/**
* @RDE_HEADER@
* Gui Plugin for BaseDownloader
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2017-03-17
*/
#include "obd_base_downloader_gui_plugin.h"
#include <OcBaseDownload/logger.h>
#include "obd_base_downloader.h"
namespace OcBaseDownload
{
std::shared_ptr<GuiPluginBase::Interface> GuiPlugin::createGuiInterface(LtsSession::LtsSession *session)
{
return std::make_shared<InterfaceImpl>(session);
}
InterfaceImpl::InterfaceImpl(LtsSession::LtsSession *session)
: GuiPluginBase::Interface(session,getLogger("InterfaceImpl"))
{
}
bool InterfaceImpl::fetchInterfaces()
{
return true;
}
void InterfaceImpl::clearInterfaces()
{}
QString InterfaceImpl::menuGroup() const
{
return tr("Base Downloader");
}
QVector<LtsWidgets::PluginData> InterfaceImpl::getActions()
{
QVector<LtsWidgets::PluginData> ret;
LtsWidgets::PluginData plData;
plData.menuGroup = menuGroup();
if(m_session->partitionType() == IDL::PartitionType::Global)
{
plData.createWidgetFunc = [this](QWidget * parent)
{
return onShowBaseDownloader(parent);
};
plData.menuText = tr("OC Base Downloader");
plData.identifier = QStringLiteral("baseDownloader");
plData.menuIcon = QIcon(QLatin1String("icon:oc_basedownload.svg"));
plData.operatorRight = 0;
if (getFlags().testFlag(LtsAppDescriptor::PluginInfo::Flag::MAIN))
{
plData.layoutArea = LtsWidgets::LayoutArea::eMainTab;
plData.createInstant = LtsWidgets::CreateInstantType::CreateInstantAndDiscardAction;
ret.append(plData);
}else
{
plData.layoutArea = LtsWidgets::LayoutArea::eDialogTab;
ret.append(plData);
}
}
/*
if(m_session->partitionType() == IDL::PartitionType::Exercise)
{
plData.menuText = tr("SYNC");
plData.identifier = QStringLiteral("sync");
plData.menuIcon = QIcon(QLatin1String("icon:oc_basedownload.svg"));
plData.operatorRight = 0;
plData.directFunc = [this](const LtsWidgets::PluginData &)
{
onSyncWithDb();
};
ret.append(plData);
}
*/
return ret;
}
void InterfaceImpl::onSyncWithDb()
{
if (!m_session->getFtc<OcBaseDownload::DataInterface>(m_ftc))
return;
const LiveUpdateRequest req(QDateTime::currentMSecsSinceEpoch(), m_session->exerciseId());
ERROR_LOG(m_logger) << "Start Sycn: ";
// NO request helper here, as we got a custom function with a state
m_ftc->lifeUpdateRequest(req, this);
//setFunctionTopic stuff
}
LtsWidgets::LtsDialog *InterfaceImpl::onShowBaseDownloader(QWidget *parent)
{
BaseDownloader *diag = new BaseDownloader(menuGroup(), m_session, parent);
if (!diag->init())
{
delete diag;
return nullptr;
}
return diag;
}
} // namespace OcBaseDownload
@@ -0,0 +1,64 @@
/**
* @RDE_HEADER@
* Gui Plugin for BaseDownloader
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2017-03-17
*/
#pragma once
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/OcBaseDownload/obd_base_downloader_gui_plugin_interface.h>
#include <Plugins/OcBaseDownload/obd_data_plugin_interface.h>
namespace OcBaseDownload
{
class GuiPlugin final : public QObject, public GuiPluginBase::Plugin
{
Q_PLUGIN_METADATA(IID "gui:3:obd.basedownloader")
Q_INTERFACES(GuiPluginBase::Plugin)
Q_OBJECT
public:
GuiPlugin() = default;
~GuiPlugin() = default;
QString pluginName() override { return QStringLiteral("OcBaseDownload.BaseDownlaoder"); }
std::shared_ptr<GuiPluginBase::Interface> createGuiInterface(LtsSession::LtsSession *session) override;
bool availableInPartition(IDL::PartitionType partition) const override
{
return (partition == IDL::PartitionType::Global || partition == IDL::PartitionType::Exercise);
}
};
class InterfaceImpl final : public QObject, public ForeignBaseDownloaderInterface, public GuiPluginBase::Interface
, protected OcBaseDownload::Interface::Ftc::LifeUpdateReplyHandler
{
Q_OBJECT
public:
explicit InterfaceImpl(LtsSession::LtsSession *session);
bool fetchInterfaces() override;
void clearInterfaces() override;
QString menuGroup() const override;
QVector<LtsWidgets::PluginData> getActions() override;
bool availableInPartition(IDL::PartitionType partition) const override
{
return partition == IDL::PartitionType::Global || partition == IDL::PartitionType::Exercise;
}
private:
void onLifeUpdateReply(const Core::FunctionReplyObject &replyObject) override { Q_UNUSED(replyObject) }
private:
void onSyncWithDb();
std::shared_ptr<OcBaseDownload::Interface::Ftc> m_ftc;
LtsWidgets::LtsDialog *onShowBaseDownloader(QWidget *parent);
};
} // namespace OcBaseDownload
@@ -0,0 +1,56 @@
/**
* @RDE_HEADER@
* HMI Plugin for Observer Controller - BaseDownloaderMessage Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2018-03-17
*/
#include "obd_base_downloader_message.h"
#include "ui_obd_base_downloader_message.h"
#include <LtsWidgets/lts_frameless_dialog.h>
namespace OcBaseDownload
{
BaseDownloaderMessage::BaseDownloaderMessage(QWidget *parent)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_ui(new Ui::BaseDownloaderMessage)
, m_logger(getLogger("BaseDownloaderMessageDialog"))
{
m_ui->setupUi(this);
connect(m_ui->pbClose, &QPushButton::clicked, this, &BaseDownloaderMessage::close);
setCloseable(false);
}
BaseDownloaderMessage::~BaseDownloaderMessage()
{
delete m_ui;
}
void BaseDownloaderMessage::setText(const QString &text)
{
m_ui->lblText->setText(text);
}
void BaseDownloaderMessage::setCloseable(bool closable)
{
m_ui->pbClose->setEnabled(closable);
}
void BaseDownloaderMessage::setProgress(int value)
{
m_ui->prbProgress->setValue(value);
}
void BaseDownloaderMessage::keyPressEvent(QKeyEvent *e)
{
if(e->key() != Qt::Key_Escape)
QDialog::keyPressEvent(e);
}
} // namespace OcBaseDownload
@@ -0,0 +1,48 @@
/**
* @RDE_HEADER@
* HMI Plugin for Observer Controller - BaseDownloaderMessage Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2018-03-17
*/
#pragma once
#include <LtsWidgets/lts_dialog.h>
#include <OcBaseDownload/logger.h>
namespace Ui
{
class BaseDownloaderMessage;
}
namespace OcBaseDownload
{
class BaseDownloaderMessage : public LtsWidgets::LtsFramelessDialog
{
Q_OBJECT
public:
explicit BaseDownloaderMessage(QWidget *parent = nullptr);
~BaseDownloaderMessage();
void setText(const QString &text);
void setCloseable(bool closable);
void setProgress(int value);
void keyPressEvent(QKeyEvent *e) override;
private Q_SLOTS:
private:
private:
Ui::BaseDownloaderMessage *m_ui;
LOGGER_T m_logger;
};
} // namespace OcBaseDownload
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BaseDownloaderMessage</class>
<widget class="QWidget" name="BaseDownloaderMessage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>219</width>
<height>109</height>
</rect>
</property>
<property name="windowTitle">
<string>Base Download</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<widget class="QPushButton" name="pbClose">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>112</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="lblText">
<property name="text">
<string notr="true">&lt;TEXT&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QProgressBar" name="prbProgress">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,88 @@
/**
* @RDE_HEADER@
* HMI Plugin for Observer Controller - BaseDownloaderPdfSelector Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Fritsche, NLE, 2019-04-25
*/
#include "obd_base_downloader_pdf_selector.h"
#include "ui_obd_base_downloader_pdf_selector.h"
#include <LtsWidgets/lts_frameless_dialog.h>
namespace OcBaseDownload
{
const char *BaseDownloaderPdfSelector::ID = "id";
BaseDownloaderPdfSelector::BaseDownloaderPdfSelector(QWidget *parent)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_ui(new Ui::BaseDownloaderPdfSelector)
, m_logger(getLogger("BaseDownloaderPdfSelectorDialog"))
{
m_ui->setupUi(this);
connect(m_ui->pbCancel, &QPushButton::clicked,
this, &BaseDownloaderPdfSelector::close);
connect(m_ui->pbOk, &QPushButton::clicked,
this, &BaseDownloaderPdfSelector::ok);
m_ui->chkSelectAll->hide();
}
BaseDownloaderPdfSelector::~BaseDownloaderPdfSelector()
{
delete m_ui;
}
void BaseDownloaderPdfSelector::keyPressEvent(QKeyEvent *e)
{
if (e->key() != Qt::Key_Escape)
QDialog::keyPressEvent(e);
}
void BaseDownloaderPdfSelector::onGetPdfListReply(const PdfListReply &reply)
{
for (const OcBaseDownload::PdfInfo &currentDocument : reply.documents())
addFile(currentDocument);
m_ui->lblTotal->setText(tr("Total: %1").arg(m_chks.size()));
}
std::vector<int32_t> BaseDownloaderPdfSelector::checkedPdfIds() const
{
std::vector<int32_t> result;
for (const QCheckBox *current : m_chks)
{
if (current->isChecked())
result.push_back(current->property(ID).toInt());
}
return result;
}
void BaseDownloaderPdfSelector::addFile(const OcBaseDownload::PdfInfo &document)
{
QCheckBox *chk = new QCheckBox(this);
chk->setText(QString::fromStdString(document.name()));
chk->setProperty(ID, QVariant(document.id()));
m_chks.append(chk);
QLayout *contentlayout = m_ui->scrollAreaContent->layout();
QLayoutItem *spacer = contentlayout->takeAt(contentlayout->count() - 1); // taking the spacer ...
contentlayout->addWidget(chk);
contentlayout->addItem(spacer); // ... to place it back, at the end of the layout
connect(m_ui->chkSelectAll, &QCheckBox::toggled,
chk, &QCheckBox::setChecked);
}
} // namespace OcBaseDownload
@@ -0,0 +1,57 @@
/**
* @RDE_HEADER@
* HMI Plugin for Observer Controller - BaseDownloaderPdfSelector Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Hannes Fritsche, NLE, 2019-04-25
*/
#pragma once
#include <LtsWidgets/lts_dialog.h>
#include <OcBaseDownload/logger.h>
#include <Plugins/OcBaseDownload/obd_data_plugin_interface.h>
namespace Ui
{
class BaseDownloaderPdfSelector;
}
namespace OcBaseDownload
{
class BaseDownloaderPdfSelector
: public LtsWidgets::LtsFramelessDialog
, public OcBaseDownload::Interface::Ftc::GetPdfListReplyHandler
{
Q_OBJECT
public:
explicit BaseDownloaderPdfSelector(QWidget *parent = nullptr);
~BaseDownloaderPdfSelector();
void keyPressEvent(QKeyEvent *e) override;
void onGetPdfListReply(const PdfListReply &reply) override final;
std::vector<int32_t> checkedPdfIds() const;
Q_SIGNALS:
void ok();
private: // methods
void addFile(const PdfInfo &document);
private: // attributes
static const char *ID;
Ui::BaseDownloaderPdfSelector *m_ui;
std::shared_ptr<OcBaseDownload::Interface::Ftc> m_ftc;
QVector<QCheckBox *> m_chks;
LOGGER_T m_logger;
};
} // namespace OcBaseDownload
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BaseDownloaderPdfSelector</class>
<widget class="QWidget" name="BaseDownloaderPdfSelector">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>368</width>
<height>500</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>800</height>
</size>
</property>
<property name="windowTitle">
<string notr="true">PDF Selection</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaContent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>429</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="chkSelectAll">
<property name="text">
<string>Select All</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="pbOk">
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblTotal">
<property name="text">
<string>Total: 0</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="pbCancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,107 @@
/**
* @RDE_HEADER@
* HMI Plugin for ExerciseManangement - Exercise Overview Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2018-03-17
*/
#include "obd_ex_model.h"
#include <ngltools/ngltools_dtg.h>
#include <QJsonObject>
namespace OcBaseDownload
{
//---------------------------------
// ExModel
//---------------------------------
ExModel::ExModel(QObject *parent)
: LtsWidgets::LtsAbstractTableModel<ExerciseManagement::Exercise>({tr("Name"),
tr("Begin"),
tr("End"),
tr("Description"),
QStringLiteral("Id")},
parent)
, m_logger(getLogger("ExModel"))
{}
void ExModel::addExercise(const QJsonObject &exercise)
{
// ERROR_LOG(m_logger) << "Got Exercise" << exercise;
ExerciseManagement::Exercise ex;
ex.name(exercise.value(QLatin1String("name")).toString().toStdString());
ex.beginTime(exercise.value(QLatin1String("beginTime")).toDouble());
ex.endTime(exercise.value(QLatin1String("endTime")).toDouble());
ex.defaultTimeZone(exercise.value(QLatin1String("timeZone")).toString().toStdString().c_str()[0]);
ex.startTime(exercise.value(QLatin1String("startTime")).toDouble());
ex.stopTime(exercise.value(QLatin1String("stopTime")).toDouble());
ex.state(static_cast<ExerciseManagement::ExerciseState::inner_enum>(exercise.value(QLatin1String("status")).toInt()));
ex.description(exercise.value(QLatin1String("description")).toString().toStdString());
ex.id(exercise.value(QLatin1String("id")).toInt());
ex.trainingAreaId(exercise.value(QLatin1String("trainingAreaId")).toInt());
//add to model
if (ex.id() > 0 && (ex.state() == ExerciseManagement::ExerciseState::Started || ex.state() == ExerciseManagement::ExerciseState::Paused ) )
insertRow(ex);
}
QVariant ExModel::data(const QModelIndex &index, int role) const
{
if (role != Qt::DisplayRole || !indexIsValid(index))
return QVariant();
const ExerciseManagement::Exercise &ex = m_vecData.at(index.row());
switch (index.column())
{
case ExModel::Columns::Name:
return QString::fromStdString(ex.name());
case ExModel::Columns::Begin:
return QDateTime::fromMSecsSinceEpoch(ex.beginTime());
case ExModel::Columns::End:
return QDateTime::fromMSecsSinceEpoch(ex.endTime());
case ExModel::Columns::Description:
return QString::fromStdString(ex.description());
case ExModel::Columns::Id:
return ex.id();
}
return QVariant();
}
void ExProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
{
m_sourceModel = qobject_cast<ExModel*>(sourceModel);
LtsWidgets::LtsColumnFilterProxyModel::setSourceModel(sourceModel);
}
bool ExProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
{
if (!m_sourceModel ||
source_left.column() != source_right.column() ||
!source_left.isValid() ||
!source_right.isValid())
return LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right);
const auto &dataLeft = m_sourceModel->m_vecData.at(source_left.row());
const auto dataRight = m_sourceModel->m_vecData.at(source_right.row());
switch (source_left.column())
{
case ExModel::Begin:
return dataLeft.beginTime() < dataRight.beginTime();
case ExModel::End:
return dataLeft.endTime() < dataRight.endTime();
case ExModel::Name:
case ExModel::Description:
case ExModel::Id:
break;
}
return LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right);
}
} // namespace ExerciseManagement
@@ -0,0 +1,57 @@
/**
* @RDE_HEADER@
* ExerciseManangement - Exercise Overview Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2018-03-17
*/
#pragma once
#include <OcBaseDownload/logger.h>
#include <LtsWidgets/lts_abstract_table_model.h>
#include <LtsWidgets/lts_column_filter_proxy_model.h>
#include <Services/ExerciseManagement/exm.hpp>
namespace OcBaseDownload
{
class ExModel final : public LtsWidgets::LtsAbstractTableModel<ExerciseManagement::Exercise>
{
Q_OBJECT
public:
enum Columns
{
Name,
Begin,
End,
Description,
Id
};
explicit ExModel(QObject *parent = nullptr);
void addExercise(const QJsonObject &exercise);
QVariant data(const QModelIndex &, int) const override final;
private:
friend class ExProxyModel;
LOGGER_T m_logger;
};
class ExProxyModel final : public LtsWidgets::LtsColumnFilterProxyModel
{
Q_OBJECT
public:
using LtsWidgets::LtsColumnFilterProxyModel::LtsColumnFilterProxyModel;
void setSourceModel(QAbstractItemModel *sourceModel) override;
protected:
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
private:
ExModel *m_sourceModel = nullptr;
};
}
+8
View File
@@ -0,0 +1,8 @@
#
# $Id$
# $HeadURL$
# $Author$
#
ADD_SUBDIRECTORY(BaseDownloader)