#include "ism_mounting_point.h" #include #include #include #include #include #include #include #include #include namespace InfrastructureManagement { MountingPoint::MountingPoint() : m_data() , m_associatedAssetId(0) , m_aimState(MountingPointState::Undefined) , m_hasAssociatedAssetDefect(false) , m_isValid(false) , m_floor(-1) { } MountingPoint::MountingPoint(const StructureElement &data, int floorId) : m_data(data) , m_associatedAssetId(0) , m_aimState(MountingPointState::Undefined) , m_hasAssociatedAssetDefect(false) , m_isValid(true) , m_floor(floorId) { } void MountingPoint::init() { getImageTableInternal(); } QString MountingPoint::name() const { return QString::fromStdString(m_data.displayName()); } QString MountingPoint::fileName() const { return QString::fromStdString(m_data.name()); } QImage MountingPoint::toImage(int32_t edgeLength) const { QImage img(edgeLength, edgeLength, QImage::Format_ARGB32); img.fill(Qt::transparent); QPainter painter(&img); painter.setRenderHint(QPainter::Antialiasing); // Zeichne basierend auf aimState QColor color; switch (m_aimState) { case MountingPointState::Equipped: color = Qt::green; break; case MountingPointState::Empty: color = Qt::red; break; case MountingPointState::Idle: color = Qt::gray; break; default: color = Qt::blue; break; } painter.setBrush(color); painter.setPen(Qt::NoPen); painter.drawEllipse(2, 2, edgeLength - 4, edgeLength - 4); return img; } bool MountingPoint::writeFile(int32_t edgeLength) const { QImage img = toImage(edgeLength); QString fileName = this->fileName(); if (fileName.isEmpty()) { return false; } QImageWriter writer(fileName); return writer.write(img); } void MountingPoint::setAssociatedAssetId(int32_t id) { m_associatedAssetId = id; } void MountingPoint::setHasAssociatedAssetDefect(bool hasDefect) { m_hasAssociatedAssetDefect = hasDefect; } MountingPointState MountingPoint::getNextMountingPointState(const MountingPointState currState) { switch (currState) { case MountingPointState::Undefined: return MountingPointState::Empty; case MountingPointState::Equipped: return MountingPointState::Empty; case MountingPointState::Empty: return MountingPointState::Idle; case MountingPointState::Idle: return MountingPointState::Equipped; default: return MountingPointState::Undefined; } } QString MountingPoint::mpColorToString(MpColor mpColor) { switch (mpColor) { case MpColor::GRAY: return QString::fromUtf8("gray"); case MpColor::BLUE: return QString::fromUtf8("blue"); case MpColor::RED: return QString::fromUtf8("red"); case MpColor::GREEN: return QString::fromUtf8("green"); case MpColor::ORANGE: return QString::fromUtf8("orange"); default: return QString::fromUtf8("unknown"); } } QString MountingPoint::mpColorToPostfix(MpColor mpColor) { switch (mpColor) { case MpColor::GRAY: return QString::fromUtf8("_gray"); case MpColor::BLUE: return QString::fromUtf8("_blue"); case MpColor::RED: return QString::fromUtf8("_red"); case MpColor::GREEN: return QString::fromUtf8("_green"); case MpColor::ORANGE: return QString::fromUtf8("_orange"); default: return QString::fromUtf8("_unknown"); } } QMap &MountingPoint::getImageTable() { return getImageTableInternal(); } bool MountingPoint::getImageAttributePlanActivity(const MountingPoint& mp, QImage &imgOut, QString &attribNameOut) { return getImageAttribute(mp, MpColor::BLUE, imgOut, attribNameOut); } bool MountingPoint::getImageAttributePlanDefinition(const MountingPoint& mp, QImage &imgOut, QString &attribNameOut) { return getImageAttribute(mp, MpColor::GRAY, imgOut, attribNameOut); } bool MountingPoint::getImageAttribute(const MountingPoint& mp, MpColor mpColor, QImage &img, QString &attribName) { const auto &table = getImageTable(); auto it = table.find(mp.type()); if (it == table.end()) { return false; } const MpNameImageData &data = it.value(); switch (mpColor) { case MpColor::GRAY: img = data.nipGray.m_img; attribName = data.nipGray.m_name; break; case MpColor::BLUE: img = data.nipBlue.m_img; attribName = data.nipBlue.m_name; break; case MpColor::RED: img = data.nipRed.m_img; attribName = data.nipRed.m_name; break; case MpColor::GREEN: img = data.nipGreen.m_img; attribName = data.nipGreen.m_name; break; case MpColor::ORANGE: img = data.nipOrange.m_img; attribName = data.nipOrange.m_name; break; } return !img.isNull(); } QMap &MountingPoint::getImageTableInternal() { static QMap imageTable; static bool initialized = false; if (!initialized) { // Initialisiere mit Platzhalter-Daten insertHelper(MountingPointType::Generic, QString::fromUtf8("Generic"), QString::fromUtf8(":/gray/generic.png"), QString::fromUtf8(":/green/generic.png"), QString::fromUtf8(":/red/generic.png"), QString::fromUtf8(":/orange/generic.png")); insertHelper(MountingPointType::Sensor, QString::fromUtf8("Sensor"), QString::fromUtf8(":/gray/sensor.png"), QString::fromUtf8(":/green/sensor.png"), QString::fromUtf8(":/red/sensor.png"), QString::fromUtf8(":/orange/sensor.png")); insertHelper(MountingPointType::Actuator, QString::fromUtf8("Actuator"), QString::fromUtf8(":/gray/actuator.png"), QString::fromUtf8(":/green/actuator.png"), QString::fromUtf8(":/red/actuator.png"), QString::fromUtf8(":/orange/actuator.png")); insertHelper(MountingPointType::BuildingSensorModule, QString::fromUtf8("BSM"), QString::fromUtf8(":/gray/bsm.png"), QString::fromUtf8(":/green/bsm.png"), QString::fromUtf8(":/red/bsm.png"), QString::fromUtf8(":/orange/bsm.png")); insertHelper(MountingPointType::OutdoorCamera, QString::fromUtf8("OutdoorCamera"), QString::fromUtf8(":/gray/camera.png"), QString::fromUtf8(":/green/camera.png"), QString::fromUtf8(":/red/camera.png"), QString::fromUtf8(":/orange/camera.png")); insertHelper(MountingPointType::IndoorCamera, QString::fromUtf8("IndoorCamera"), QString::fromUtf8(":/gray/camera.png"), QString::fromUtf8(":/green/camera.png"), QString::fromUtf8(":/red/camera.png"), QString::fromUtf8(":/orange/camera.png")); insertHelper(MountingPointType::OutdoorIPS, QString::fromUtf8("OutdoorIPS"), QString::fromUtf8(":/gray/ips.png"), QString::fromUtf8(":/green/ips.png"), QString::fromUtf8(":/red/ips.png"), QString::fromUtf8(":/orange/ips.png")); insertHelper(MountingPointType::IndoorIPS, QString::fromUtf8("IndoorIPS"), QString::fromUtf8(":/gray/ips.png"), QString::fromUtf8(":/green/ips.png"), QString::fromUtf8(":/red/ips.png"), QString::fromUtf8(":/orange/ips.png")); insertHelper(MountingPointType::MeteoDataUnit, QString::fromUtf8("Meteo"), QString::fromUtf8(":/gray/meteo.png"), QString::fromUtf8(":/green/meteo.png"), QString::fromUtf8(":/red/meteo.png"), QString::fromUtf8(":/orange/meteo.png")); insertHelper(MountingPointType::AnnouncementUnit, QString::fromUtf8("Announcement"), QString::fromUtf8(":/gray/announcement.png"), QString::fromUtf8(":/green/announcement.png"), QString::fromUtf8(":/red/announcement.png"), QString::fromUtf8(":/orange/announcement.png")); insertHelper(MountingPointType::BuildingNetworkSwitch, QString::fromUtf8("Switch"), QString::fromUtf8(":/gray/switch.png"), QString::fromUtf8(":/green/switch.png"), QString::fromUtf8(":/red/switch.png"), QString::fromUtf8(":/orange/switch.png")); insertHelper(MountingPointType::EffectGenerationControlUnit, QString::fromUtf8("EGCU"), QString::fromUtf8(":/gray/egcu.png"), QString::fromUtf8(":/green/egcu.png"), QString::fromUtf8(":/red/egcu.png"), QString::fromUtf8(":/orange/egcu.png")); insertHelper(MountingPointType::Unknown, QString::fromUtf8("Unknown"), QString::fromUtf8(":/gray/unknown.png"), QString::fromUtf8(":/green/unknown.png"), QString::fromUtf8(":/red/unknown.png"), QString::fromUtf8(":/orange/unknown.png")); initialized = true; } return imageTable; } void MountingPoint::insertHelper(MountingPointType type, const QString &name, const QString &colorCodeGray, const QString &colorCodeGreen, const QString &colorCodeRed, const QString &colorCodeOrange, const QString &defName) { MpNameImageData data; data.nipGray = NameImagePair(name.isEmpty() ? defName : name + u"_gray", QImage(colorCodeGray)); data.nipBlue = NameImagePair(name.isEmpty() ? defName : name + u"_blue", QImage(colorCodeGray)); // blau = grau als Platzhalter data.nipGreen = NameImagePair(name.isEmpty() ? defName : name + u"_green", QImage(colorCodeGreen)); data.nipRed = NameImagePair(name.isEmpty() ? defName : name + u"_red", QImage(colorCodeRed)); data.nipOrange = NameImagePair(name.isEmpty() ? defName : name + u"_orange", QImage(colorCodeOrange)); getImageTableInternal()[type] = data; } } // namespace InfrastructureManagement