483 lines
13 KiB
C++
Executable File
483 lines
13 KiB
C++
Executable File
|
|
|
|
|
|
#include "ism_mounting_point.h"
|
|
|
|
#include <QIcon>
|
|
#include <QPainter>
|
|
#include <QMap>
|
|
#include <QDir>
|
|
#include <QElapsedTimer>
|
|
#include <QDebug>
|
|
|
|
namespace InfrastructureManagement
|
|
{
|
|
MountingPoint::MountingPoint()
|
|
: MountingPoint(StructureElement(), -10)
|
|
{
|
|
m_data.id(-1);
|
|
}
|
|
|
|
MountingPoint::MountingPoint(const StructureElement &data, int floorId)
|
|
: m_data(data)
|
|
, m_associatedAssetId(-1)
|
|
, m_aimState(MountingPointState::Idle)
|
|
, m_hasAssociatedAssetDefect(false)
|
|
, m_isValid(true)
|
|
, m_floor(floorId)
|
|
{
|
|
}
|
|
|
|
QString MountingPoint::name() const
|
|
{
|
|
if (m_data.displayName().size() > 0)
|
|
return QString::fromStdString(m_data.displayName());
|
|
if (m_data.name().size() > 0)
|
|
return QString::fromStdString(m_data.name());
|
|
return QStringLiteral("MP_%1").arg(m_data.id());
|
|
}
|
|
|
|
void MountingPoint::setHasAssociatedAssetDefect(bool hasAssociatedAssetDefect)
|
|
{
|
|
m_hasAssociatedAssetDefect = hasAssociatedAssetDefect;
|
|
}
|
|
|
|
MountingPointState MountingPoint::getNextMountingPointState(MountingPointState currState)
|
|
{
|
|
if (currState == MountingPointState::Empty)
|
|
return MountingPointState::Idle;
|
|
else if( currState == MountingPointState::Idle)
|
|
return MountingPointState::Equipped;
|
|
else if (currState == MountingPointState::Equipped)
|
|
return MountingPointState::Empty;
|
|
else
|
|
return MountingPointState::Idle;
|
|
}
|
|
|
|
QImage MountingPoint::toImage(int32_t edgeLength) const
|
|
{
|
|
QImage result = getImage(*this);
|
|
|
|
if (result.isNull())
|
|
return result;
|
|
|
|
if (edgeLength == 100)
|
|
return result;
|
|
return result.scaled(edgeLength, edgeLength);
|
|
}
|
|
|
|
QString MountingPoint::fileName() const
|
|
{
|
|
return QStringLiteral("%1/mp_%2.png").arg(QDir::tempPath()).arg(m_data.id());
|
|
}
|
|
|
|
bool MountingPoint::writeFile(int32_t edgeLength) const
|
|
{
|
|
const QImage img(toImage(edgeLength));
|
|
if (img.isNull())
|
|
return false;
|
|
return img.save(fileName(), "PNG");
|
|
}
|
|
|
|
void MountingPoint::setAssociatedAssetId(int32_t id)
|
|
{
|
|
m_associatedAssetId = id;
|
|
}
|
|
|
|
void MountingPoint::insertHelper(MountingPointType_def::type type,
|
|
const QString &name,
|
|
const QString &colorCodeGray,
|
|
const QString &colorCodeGreen,
|
|
const QString &colorCodeRed,
|
|
const QString &colorCodeOrange,
|
|
const QString &defName)
|
|
{
|
|
QMap<MountingPointType_def::type, MountingPoint::MpNameImageData> &imageCont = MountingPoint::getImageTableInternal();
|
|
|
|
MountingPoint::MpNameImageData mnid;
|
|
|
|
static QString path(QStringLiteral(":/style/"));
|
|
|
|
|
|
{
|
|
|
|
QString curFilename = path + name + QStringLiteral(".svg");
|
|
if (!defName.isEmpty())
|
|
curFilename = path + defName + QStringLiteral(".svg");
|
|
|
|
QFile file(curFilename);
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
{
|
|
qCritical() << " insertHelper: file could not be opened: filename= '" << curFilename << "'";
|
|
return;
|
|
}
|
|
|
|
QByteArray fileData;
|
|
fileData = file.readAll();
|
|
const QString &text = QString::fromUtf8(fileData);
|
|
fileData = text.toUtf8();
|
|
|
|
QImage currentImg;
|
|
if (!currentImg.loadFromData(fileData))
|
|
{
|
|
qCritical() << " insertHelper: loadFromData failed: filename= '" << curFilename << "'";
|
|
return;
|
|
}
|
|
|
|
mnid.nipBlue = MountingPoint::NameImagePair(name + MountingPoint::mpColorToPostfix(MountingPoint::MpColor::BLUE), currentImg);
|
|
}
|
|
|
|
|
|
{
|
|
|
|
QString curFilename = path + name + QStringLiteral("_fillcolor.svg.template");
|
|
QFile file(curFilename);
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
{
|
|
qCritical() << " insertHelper: file could not be opened: filename= '" << curFilename << "'";
|
|
return;
|
|
}
|
|
|
|
QByteArray fileData;
|
|
fileData = file.readAll();
|
|
const QString &textTemplate = QString::fromUtf8(fileData);
|
|
|
|
QString temp;
|
|
{
|
|
temp = textTemplate;
|
|
temp.replace(QString(QStringLiteral("@@FILLCOLOR@@")), colorCodeGray);
|
|
fileData = temp.toUtf8();
|
|
|
|
QImage currentImg;
|
|
if (!currentImg.loadFromData(fileData))
|
|
{
|
|
qCritical() << " insertHelper: loadFromData failed: filename= '" << curFilename << "'";
|
|
return;
|
|
}
|
|
mnid.nipGray = MountingPoint::NameImagePair(name + MountingPoint::mpColorToPostfix(MountingPoint::MpColor::GRAY), currentImg);
|
|
}
|
|
{
|
|
temp = textTemplate;
|
|
temp.replace(QString(QStringLiteral("@@FILLCOLOR@@")), colorCodeRed);
|
|
fileData = temp.toUtf8();
|
|
|
|
QImage currentImg;
|
|
if (!currentImg.loadFromData(fileData))
|
|
{
|
|
qCritical() << " insertHelper: loadFromData failed: filename= '" << curFilename << "'";
|
|
return;
|
|
}
|
|
|
|
currentImg.save(QStringLiteral("/tmp/") + name + QStringLiteral("_red.png"));
|
|
|
|
mnid.nipRed = MountingPoint::NameImagePair(name + MountingPoint::mpColorToPostfix(MountingPoint::MpColor::RED), currentImg);
|
|
}
|
|
{
|
|
temp = textTemplate;
|
|
temp.replace(QString(QStringLiteral("@@FILLCOLOR@@")), colorCodeGreen);
|
|
fileData = temp.toUtf8();
|
|
|
|
QImage currentImg;
|
|
if (!currentImg.loadFromData(fileData))
|
|
{
|
|
qCritical() << " insertHelper: loadFromData failed: filename= '" << curFilename << "'";
|
|
return;
|
|
}
|
|
mnid.nipGreen = MountingPoint::NameImagePair(name + MountingPoint::mpColorToPostfix(MountingPoint::MpColor::GREEN), currentImg);
|
|
}
|
|
{
|
|
temp = textTemplate;
|
|
temp.replace(QString(QStringLiteral("@@FILLCOLOR@@")), colorCodeOrange);
|
|
fileData = temp.toUtf8();
|
|
|
|
QImage currentImg;
|
|
if (!currentImg.loadFromData(fileData))
|
|
{
|
|
qCritical() << " insertHelper: loadFromData failed: filename= '" << curFilename << "'";
|
|
return;
|
|
}
|
|
mnid.nipOrange = MountingPoint::NameImagePair(name + MountingPoint::mpColorToPostfix(MountingPoint::MpColor::ORANGE), currentImg);
|
|
}
|
|
}
|
|
imageCont.insert(type, mnid);
|
|
}
|
|
|
|
void MountingPoint::init()
|
|
{
|
|
|
|
|
|
|
|
if (MountingPoint::getImageTableInternal().isEmpty())
|
|
{
|
|
#ifdef BENCHMARK
|
|
QElapsedTimer elapsedTimer1;
|
|
elapsedTimer1.start();
|
|
#endif
|
|
|
|
|
|
static QString colorCodeGray (QStringLiteral("808080"));
|
|
static QString colorCodeGreen (QStringLiteral("00FF00"));
|
|
static QString colorCodeRed (QStringLiteral("FF0000"));
|
|
static QString colorCodeOrange(QStringLiteral("FF5F1F"));
|
|
|
|
insertHelper(MountingPointType_def::BuildingSensorModule, QStringLiteral("reference_module"), colorCodeGray, colorCodeGreen, colorCodeRed, colorCodeOrange);
|
|
insertHelper(MountingPointType_def::OutdoorCamera, QStringLiteral("mobile_video"), colorCodeGray, colorCodeGreen, colorCodeRed, colorCodeOrange);
|
|
insertHelper(MountingPointType_def::IndoorCamera, QStringLiteral("fixed_video_announcement"), colorCodeGray, colorCodeGreen, colorCodeRed, colorCodeOrange);
|
|
|
|
|
|
|
|
|
|
insertHelper(MountingPointType_def::OutdoorIPS, QStringLiteral("ips"), colorCodeGray, colorCodeGreen, colorCodeRed, colorCodeOrange);
|
|
insertHelper(MountingPointType_def::IndoorIPS, QStringLiteral("ips"), colorCodeGray, colorCodeGreen, colorCodeRed, colorCodeOrange);
|
|
|
|
insertHelper(MountingPointType_def::MeteoDataUnit, QStringLiteral("meteorological_data"), colorCodeGray, colorCodeGreen, colorCodeRed, colorCodeOrange);
|
|
|
|
|
|
insertHelper(MountingPointType_def::AnnouncementUnit, QStringLiteral("announcement"), colorCodeGray, colorCodeGreen, colorCodeRed, colorCodeOrange);
|
|
insertHelper(MountingPointType_def::BuildingNetworkSwitch, QStringLiteral("presets"), colorCodeGray, colorCodeGreen, colorCodeRed, colorCodeOrange);
|
|
|
|
|
|
insertHelper(MountingPointType_def::EffectGenerationControlUnit, QStringLiteral("egcu"), colorCodeGray, colorCodeGreen, colorCodeRed, colorCodeOrange, QStringLiteral("egcu_enabled"));
|
|
|
|
|
|
|
|
insertHelper(MountingPointType_def::Unknown, QStringLiteral("unknown"), colorCodeGray, colorCodeGreen, colorCodeRed, colorCodeOrange);
|
|
|
|
#ifdef BENCHMARK
|
|
|
|
qCritical() << " MountingPoint::init-BENCHMARK: took " << elapsedTimer1.elapsed() << " [ms]";
|
|
#endif
|
|
}
|
|
}
|
|
|
|
QString MountingPoint::mpColorToString(MpColor mpColor)
|
|
{
|
|
switch (mpColor) {
|
|
case MpColor::BLUE:
|
|
return QStringLiteral("BLUE");
|
|
break;
|
|
case MpColor::GRAY:
|
|
return QStringLiteral("GRAY");
|
|
break;
|
|
case MpColor::GREEN:
|
|
return QStringLiteral("GREEN");
|
|
break;
|
|
case MpColor::RED:
|
|
return QStringLiteral("RED");
|
|
break;
|
|
case MpColor::ORANGE:
|
|
return QStringLiteral("ORANGE");
|
|
break;
|
|
default:
|
|
|
|
break;
|
|
}
|
|
return QStringLiteral("MpColorUndefined");
|
|
}
|
|
QString MountingPoint::mpColorToPostfix(MpColor mpColor)
|
|
{
|
|
return QStringLiteral("_") + MountingPoint::mpColorToString(mpColor);
|
|
}
|
|
|
|
|
|
|
|
QMap<MountingPointType_def::type, MountingPoint::MpNameImageData> &MountingPoint::getImageTableInternal()
|
|
{
|
|
static QMap<MountingPointType_def::type, MpNameImageData> s_imageTable;
|
|
return s_imageTable;
|
|
}
|
|
QMap<MountingPointType_def::type, MountingPoint::MpNameImageData> &MountingPoint::getImageTable()
|
|
{
|
|
MountingPoint::init();
|
|
return getImageTableInternal();
|
|
}
|
|
|
|
bool MountingPoint::getImageAttributePlanActivity(const MountingPoint &mp,
|
|
QImage &imgOut, QString &attribNameOut)
|
|
{
|
|
const MpNameImageData *mnip = getNameImageData(mp);
|
|
|
|
|
|
#ifdef LTS_DEBUG
|
|
Q_ASSERT(mnip);
|
|
#endif
|
|
|
|
if (!mnip)
|
|
return false;
|
|
|
|
const NameImagePair *nip = nullptr;
|
|
const bool hasAsset = mp.hasAssociatedAsset();
|
|
const InfrastructureManagement::MountingPointState_def::type aimState = mp.aimState().underlying();
|
|
|
|
if ( ((aimState==InfrastructureManagement::MountingPointState_def::Empty) && !hasAsset ) ||
|
|
((aimState==InfrastructureManagement::MountingPointState_def::Equipped) && hasAsset )
|
|
)
|
|
nip = &mnip->nipGreen;
|
|
else if ((aimState==InfrastructureManagement::MountingPointState_def::Empty) && hasAsset )
|
|
nip = &mnip->nipRed;
|
|
else if ((aimState==InfrastructureManagement::MountingPointState_def::Equipped) && !hasAsset )
|
|
nip = &mnip->nipBlue;
|
|
|
|
|
|
if (!nip)
|
|
nip = &mnip->nipGray;
|
|
|
|
imgOut = nip->m_img;
|
|
attribNameOut = nip->m_name;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool MountingPoint::getImageAttributePlanDefinition(const MountingPoint &mp, QImage &imgOut, QString &attribNameOut)
|
|
{
|
|
const MpNameImageData *mnip = getNameImageData(mp);
|
|
|
|
|
|
#ifdef LTS_DEBUG
|
|
Q_ASSERT(mnip);
|
|
#endif
|
|
|
|
if (!mnip)
|
|
return false;
|
|
|
|
const NameImagePair *nip = nullptr;
|
|
const InfrastructureManagement::MountingPointState_def::type aimState = mp.aimState().underlying();
|
|
|
|
switch (aimState) {
|
|
case InfrastructureManagement::MountingPointState_def::Empty:
|
|
nip = &mnip->nipRed;
|
|
break;
|
|
case InfrastructureManagement::MountingPointState_def::Idle:
|
|
nip = &mnip->nipGray;
|
|
break;
|
|
case InfrastructureManagement::MountingPointState_def::Equipped:
|
|
nip = &mnip->nipBlue;
|
|
break;
|
|
default:
|
|
|
|
break;
|
|
}
|
|
|
|
imgOut = nip->m_img;
|
|
attribNameOut = nip->m_name;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool MountingPoint::getImageAttribute(const MountingPoint &mp, MpColor mpColor, QImage &img, QString &attribName)
|
|
{
|
|
const MpNameImageData *mnip = getNameImageData(mp);
|
|
|
|
|
|
#ifdef LTS_DEBUG
|
|
Q_ASSERT(mnip);
|
|
#endif
|
|
|
|
if (!mnip)
|
|
return false;
|
|
|
|
const NameImagePair *nip = nullptr;
|
|
|
|
switch (mpColor) {
|
|
case MpColor::BLUE:
|
|
nip = &mnip->nipBlue;
|
|
break;
|
|
case MpColor::GRAY:
|
|
nip = &mnip->nipGray;
|
|
break;
|
|
case MpColor::GREEN:
|
|
nip = &mnip->nipGreen;
|
|
break;
|
|
case MpColor::RED:
|
|
nip = &mnip->nipRed;
|
|
break;
|
|
case MpColor::ORANGE:
|
|
nip = &mnip->nipOrange;
|
|
break;
|
|
default:
|
|
|
|
break;
|
|
}
|
|
|
|
img = nip->m_img;
|
|
attribName = nip->m_name;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
QImage MountingPoint::getImage(const MountingPoint &mp)
|
|
{
|
|
const NameImagePair *nip = getNameImagePair(mp);
|
|
|
|
|
|
#ifdef LTS_DEBUG
|
|
Q_ASSERT(nip);
|
|
#endif
|
|
|
|
if (!nip)
|
|
return {};
|
|
|
|
return nip->m_img;
|
|
}
|
|
|
|
const MountingPoint::MpNameImageData *MountingPoint::getNameImageData(const MountingPoint &mp)
|
|
{
|
|
QMap<MountingPointType_def::type, MountingPoint::MpNameImageData> &imageCont = MountingPoint::getImageTable();
|
|
|
|
const MountingPointType_def::type type = mp.type().underlying();
|
|
|
|
auto it = imageCont.find(type);
|
|
if (it == imageCont.end())
|
|
{
|
|
|
|
#ifdef LTS_DEBUG
|
|
qCritical() << " MountingPointType not found: type= " << type;
|
|
Q_ASSERT(nullptr);
|
|
#endif
|
|
return {};
|
|
}
|
|
|
|
const MpNameImageData *mnip = nullptr;
|
|
|
|
mnip = &(*it);
|
|
|
|
return mnip;
|
|
}
|
|
|
|
const MountingPoint::NameImagePair* MountingPoint::getNameImagePair(const MountingPoint &mp)
|
|
{
|
|
QMap<MountingPointType_def::type, MountingPoint::MpNameImageData> &imageCont = MountingPoint::getImageTable();
|
|
|
|
const MountingPointType_def::type type = mp.type().underlying();
|
|
|
|
auto it = imageCont.find(type);
|
|
if (it == imageCont.end())
|
|
return {};
|
|
|
|
const MountingPoint::MpNameImageData &mnid = *it;
|
|
const NameImagePair *nip = nullptr;
|
|
|
|
switch (mp.aimState().underlying())
|
|
{
|
|
case MountingPointState_def::Equipped:
|
|
nip = &mnid.nipBlue;
|
|
break;
|
|
case MountingPointState_def::Empty:
|
|
nip = &mnid.nipRed;
|
|
break;
|
|
case MountingPointState_def::Idle:
|
|
nip = &mnid.nipGray;
|
|
break;
|
|
}
|
|
|
|
|
|
#ifdef LTS_DEBUG
|
|
Q_ASSERT(nip);
|
|
#endif
|
|
|
|
return nip;
|
|
}
|
|
|
|
}
|