2025-01-04 04:12:51 +00:00
|
|
|
|
#include "SignalIndicatorLampUI.h"
|
|
|
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QGridLayout>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
|
|
#include "../DockTitleBar.h"
|
|
|
|
|
#include "../DockWidget.h"
|
|
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
|
|
#include <qdebug.h>
|
2025-01-05 11:12:18 +00:00
|
|
|
|
#include "common/SpdLogger.h"
|
|
|
|
|
#include "workspace/WorkSpace.h"
|
|
|
|
|
#include "workspace/Timestep.h"
|
|
|
|
|
#include "workspace/WorkSpaceManager.h"
|
2025-01-04 04:12:51 +00:00
|
|
|
|
|
|
|
|
|
SignalIndicatorLampUI::SignalIndicatorLampUI(QWidget* parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
2025-01-05 11:12:18 +00:00
|
|
|
|
connect(&WorkSpaceManager::Get(), &WorkSpaceManager::WorkSpaceChanged, this, &SignalIndicatorLampUI::OnWorkSpaceChanged);
|
2025-01-04 04:12:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SignalIndicatorLampUI::~SignalIndicatorLampUI()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SignalIndicatorLampUI::AttachDock(DockWidget* dockWidget)
|
|
|
|
|
{
|
|
|
|
|
if (nullptr == dockWidget) {
|
|
|
|
|
qDebug() << __FUNCTION__ << "dockwidget is nullptr";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dockWidget->SetDockWidgetTitleBar(nullptr);
|
|
|
|
|
dockWidget->setWidget(this);
|
|
|
|
|
|
|
|
|
|
DockTitleBar* dockTitleBar = new DockTitleBar;
|
|
|
|
|
|
|
|
|
|
dockTitleBar->SetTitle(tr("Signal Indicator Lamp"));
|
|
|
|
|
|
|
|
|
|
dockWidget->SetDockWidgetTitleBar(dockTitleBar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SignalIndicatorLampUI::InitIndicatorLamp(QStringList& lamps, LayoutType type, int nColCount)
|
|
|
|
|
{
|
|
|
|
|
QGridLayout* pMainLyt = new QGridLayout(this);
|
|
|
|
|
|
|
|
|
|
int nColIndex = 0;
|
|
|
|
|
int nRowIndex = 0;
|
|
|
|
|
|
|
|
|
|
for (auto i = 0; i < lamps.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
SignalLabel* pLampLab = new SignalLabel;
|
|
|
|
|
pLampLab->setFixedSize(24, 24);
|
|
|
|
|
pLampLab->setStyleSheet("QLabel{background-color: rgb(255, 0, 0);border-radius: 10px;}; ");
|
|
|
|
|
m_listLampPtr.push_back(pLampLab);
|
|
|
|
|
|
|
|
|
|
QLabel* pTextLab = new QLabel;
|
|
|
|
|
pTextLab->setText(lamps[i]);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout* pLyt = new QHBoxLayout;
|
|
|
|
|
pLyt->addWidget(pLampLab);
|
|
|
|
|
pLyt->addWidget(pTextLab);
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case SignalIndicatorLampUI::HLyt:
|
|
|
|
|
{
|
|
|
|
|
pMainLyt->addLayout(pLyt, 0, i);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SignalIndicatorLampUI::VLyt:
|
|
|
|
|
{
|
|
|
|
|
pMainLyt->addLayout(pLyt, i, 0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SignalIndicatorLampUI::GLyt:
|
|
|
|
|
{
|
|
|
|
|
pMainLyt->addLayout(pLyt, nRowIndex, nColIndex);
|
|
|
|
|
nColIndex++;
|
|
|
|
|
|
|
|
|
|
if (nColIndex >= nColCount)
|
|
|
|
|
{
|
|
|
|
|
nRowIndex++;
|
|
|
|
|
nColIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SignalIndicatorLampUI::SetLampState(std::vector<int> vecStatus)
|
|
|
|
|
{
|
|
|
|
|
int nIndexCount = 0;
|
|
|
|
|
if (m_listLampPtr.size() >= vecStatus.size())
|
|
|
|
|
{
|
|
|
|
|
nIndexCount = vecStatus.size();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nIndexCount = m_listLampPtr.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto i = 0; i < nIndexCount; ++i)
|
|
|
|
|
{
|
|
|
|
|
QLabel* pLampLab = m_listLampPtr[i];
|
|
|
|
|
if (1 == vecStatus[i])
|
|
|
|
|
{
|
|
|
|
|
pLampLab->setStyleSheet("QLabel{background-color: rgb(0, 255, 0);border-radius: 10px;}; ");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pLampLab->setStyleSheet("QLabel{background-color: rgb(255, 0, 0);border-radius: 10px;}; ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SignalIndicatorLampUI::UpdateIndicatorLamp(QStringList& lamps, LayoutType type, int nColCount)
|
|
|
|
|
{
|
|
|
|
|
QGridLayout* pMainLyt = (QGridLayout*)this->layout();
|
|
|
|
|
if (pMainLyt)
|
|
|
|
|
{
|
|
|
|
|
QList<QObject*> listChild = pMainLyt->children();
|
|
|
|
|
for (size_t i = 0; i < listChild.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
pMainLyt->removeWidget((QWidget*)listChild[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nColIndex = 0;
|
|
|
|
|
int nRowIndex = 0;
|
|
|
|
|
|
|
|
|
|
for (auto i = 0; i < lamps.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
SignalLabel* pLampLab = new SignalLabel;
|
|
|
|
|
pLampLab->setFixedSize(24, 24);
|
|
|
|
|
pLampLab->setStyleSheet("QLabel{background-color: rgb(255, 0, 0);border-radius: 10px;}; ");
|
|
|
|
|
m_listLampPtr.push_back(pLampLab);
|
|
|
|
|
|
|
|
|
|
QLabel* pTextLab = new QLabel;
|
|
|
|
|
pTextLab->setText(lamps[i]);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout* pLyt = new QHBoxLayout;
|
|
|
|
|
pLyt->addWidget(pLampLab);
|
|
|
|
|
pLyt->addWidget(pTextLab);
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case SignalIndicatorLampUI::HLyt:
|
|
|
|
|
{
|
|
|
|
|
pMainLyt->addLayout(pLyt, 0, i);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SignalIndicatorLampUI::VLyt:
|
|
|
|
|
{
|
|
|
|
|
pMainLyt->addLayout(pLyt, i, 0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SignalIndicatorLampUI::GLyt:
|
|
|
|
|
{
|
|
|
|
|
pMainLyt->addLayout(pLyt, nRowIndex, nColIndex);
|
|
|
|
|
nColIndex++;
|
|
|
|
|
|
|
|
|
|
if (nColIndex >= nColCount)
|
|
|
|
|
{
|
|
|
|
|
nRowIndex++;
|
|
|
|
|
nColIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SignalIndicatorLampUI::InitLamp(const QString& strFile)
|
|
|
|
|
{
|
|
|
|
|
ParseLamp(strFile);
|
|
|
|
|
|
|
|
|
|
QStringList listLamp;
|
|
|
|
|
for (size_t i = 0; i < m_iLampCount; i++)
|
|
|
|
|
{
|
|
|
|
|
listLamp <<tr("light") + QString::number(i+1); // ָʾ<D6B8><CABE>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InitIndicatorLamp(listLamp, SignalIndicatorLampUI::HLyt, listLamp.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SignalIndicatorLampUI::slotUpdateTime(double dTime)
|
|
|
|
|
{
|
|
|
|
|
if (dTime < 1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((dTime - 1) >= m_lampStatus.size())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<int> vecStatus;
|
|
|
|
|
for (size_t i = 0; i < m_iLampCount; i++)
|
|
|
|
|
{
|
|
|
|
|
vecStatus.push_back(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int iStatus = m_lampStatus[dTime - 1];
|
|
|
|
|
vecStatus[iStatus-1] = 1;
|
|
|
|
|
|
|
|
|
|
SetLampState(vecStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SignalIndicatorLampUI::onStatusChanged(int status) {
|
|
|
|
|
if ((status) >= m_lampStatus.size()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<int> vecStatus;
|
|
|
|
|
for (size_t i = 0; i < m_iLampCount; i++) {
|
|
|
|
|
vecStatus.push_back(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vecStatus[status - 1] = 1;
|
|
|
|
|
|
|
|
|
|
SetLampState(vecStatus);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-05 11:12:18 +00:00
|
|
|
|
void SignalIndicatorLampUI::OnWorkSpaceChanged(WorkSpace* worksapce) {
|
|
|
|
|
if (worksapce == nullptr) {
|
|
|
|
|
LOG_ERROR("worksapce is nullptr");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(worksapce, &WorkSpace::TimestepChanged, this, &SignalIndicatorLampUI::OnTimestepChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SignalIndicatorLampUI::OnTimestepChanged(Timestep* timestep) {
|
|
|
|
|
if (timestep == nullptr) {
|
|
|
|
|
LOG_ERROR("timestep is nullptr");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
connect(timestep, SIGNAL(TimeChanged(double)), this, SLOT(slotUpdateTime(double)));
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-04 04:12:51 +00:00
|
|
|
|
void SignalIndicatorLampUI::paintEvent(QPaintEvent* event)
|
|
|
|
|
{
|
|
|
|
|
QPainter painter(this);
|
|
|
|
|
|
|
|
|
|
QPen pen;
|
|
|
|
|
pen.setColor(Qt::black);
|
|
|
|
|
pen.setWidth(1);
|
|
|
|
|
|
|
|
|
|
painter.setPen(pen);
|
|
|
|
|
|
|
|
|
|
painter.drawRect(QRect(5,5,rect().width() - 10, rect().height() - 10));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SignalIndicatorLampUI::ParseLamp(const QString& strFile)
|
|
|
|
|
{
|
|
|
|
|
if (strFile.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::information(nullptr, QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Lamp<EFBFBD>ļ<EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_lampStatus.clear();
|
|
|
|
|
|
|
|
|
|
QFile file(strFile);
|
|
|
|
|
if (file.open(QIODevice::ReadOnly))
|
|
|
|
|
{
|
|
|
|
|
while (!file.atEnd())
|
|
|
|
|
{
|
|
|
|
|
QString strLine = file.readLine().simplified();
|
|
|
|
|
if (!strLine.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
int iLamp = (int)strLine.toDouble();
|
|
|
|
|
m_lampStatus.push_back(iLamp);
|
|
|
|
|
|
|
|
|
|
if (m_iLampCount < iLamp)
|
|
|
|
|
{
|
|
|
|
|
m_iLampCount = iLamp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
}
|
|
|
|
|
}
|