/** * Handler for the HMI language * $Id$ * $HeadURL$ * $Author$ */ #include "effect_show_mine_area.h" #include namespace EffectShowManagement { EffectShowMineArea::EffectShowMineArea(const AreaEffectSimulation::MineArea &mineArea) : m_mineArea(mineArea) , m_segment(getEffectShowSegment(mineArea)) , m_utmZone(-1) , m_rotation(0.0) , m_logger(getLogger("EffectShowMineArea")) { } //============================================================================= Database::EsmEffectShow EffectShowMineArea::getEffectShow() { calculatePositions(); Database::EsmEffectShow esmEffectShow; esmEffectShow.id = 0; esmEffectShow.name = QLatin1String("MIN"); esmEffectShow.startTime = m_mineArea.effectStart().is_set() ? m_mineArea.effectStart().get() : 0; esmEffectShow.duration = m_mineArea.effectDuration(); esmEffectShow.centerPosition = m_centerPos.geographic(); esmEffectShow.idAreaEffectSimulation = m_mineArea.id(); esmEffectShow.nameAreaEfffectSimulation = QString::fromStdString(m_mineArea.name()); esmEffectShow.esmParticipantId = -1; esmEffectShow.numOfVolley = 1; //Hardcode?? esmEffectShow.shotsPerVolley = 18; esmEffectShow.lowerLeftPosition = m_lowerLeftPos.geographic(); esmEffectShow.areaWidth = getEffectAreaWidth(); esmEffectShow.areaDepth = getEffectAreaDepth(); esmEffectShow.areaRotation = m_rotation; updateEffectShow(esmEffectShow); for (const auto &seg : m_mineArea.segments()) { const Core::GeoPosition2D &posGeo = seg.positionStart(); LtsCoordTrans::UtmCoordinate pos = LtsCoordTrans::UtmCoordinate::fromGeographic(posGeo.lon(), posGeo.lat(), m_utmZone); DEBUG_LOG(m_logger) << "Start Pos Segm.: " << pos.mgrs(); } DEBUG_LOG(m_logger) << "Center Pos Effect Show: " << LtsCoordTrans::mgrsFromGeographic(esmEffectShow.centerPosition.x(), esmEffectShow.centerPosition.y()); return esmEffectShow; } //----------------------------------------------------------------------------- void EffectShowMineArea::updateEffectShow(Database::EsmEffectShow &data) { data.nameAreaEfffectSimulation = QString::fromStdString(m_mineArea.name()); data.duration = m_mineArea.effectDuration() / 10; if (data.duration > (3600 * 1000)) data.duration = 3600 * 1000; if (m_mineArea.effectStart().is_set()) data.startTime = m_mineArea.effectStart().get() + m_mineArea.effectDuration() - data.duration; else data.startTime = 0; data.typeOfAmmunition = m_mineArea.chargeStruct().chargeTypeId(); } //----------------------------------------------------------------------------- void EffectShowMineArea::calculatePositions() { // start position of the segment Core::GeoPosition2D geoPosStart = m_segment.positionStart(); Core::GeoPosition2D geoPosEnd = m_segment.positionEnd(); LtsCoordTrans::UtmCoordinate startPositionUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(geoPosStart.lon(), geoPosStart.lat(), m_utmZone); if (m_utmZone == -1) m_utmZone = startPositionUtm.zone; LtsCoordTrans::UtmCoordinate endPositionUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(geoPosEnd.lon(), geoPosEnd.lat(), m_utmZone); const QLineF line({startPositionUtm.x, startPositionUtm.y}, {endPositionUtm.x, endPositionUtm.y}); // length/2 of the segment double halfSegmentLength = line.length() / 2.0; // rotation angle m_rotation = 90.0 - line.angle(); double angle = m_rotation * LtsCoordTrans::deg2rad(); // calculation center position LtsCoordTrans::UtmCoordinate centerPos = startPositionUtm; centerPos.x = centerPos.x + halfSegmentLength; m_centerPos = rotate(centerPos, startPositionUtm, angle); // calculation lower left position LtsCoordTrans::UtmCoordinate lowerLeftPos = startPositionUtm; lowerLeftPos.x = lowerLeftPos.x + halfSegmentLength - (getEffectAreaWidth() / 2.0); lowerLeftPos.y = lowerLeftPos.y - (getEffectAreaDepth() / 2.0); m_lowerLeftPos = rotate(lowerLeftPos, startPositionUtm, angle); } //----------------------------------------------------------------------------- int EffectShowMineArea::getEffectAreaWidth() const { Core::GeoPosition2D geoPosStart = m_segment.positionStart(); Core::GeoPosition2D geoPosEnd = m_segment.positionEnd(); LtsCoordTrans::UtmCoordinate startPositionUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(geoPosStart.lon(), geoPosStart.lat(), m_utmZone); LtsCoordTrans::UtmCoordinate endPositionUtm = LtsCoordTrans::UtmCoordinate::fromGeographic(geoPosEnd.lon(), geoPosEnd.lat(), m_utmZone); const QLineF line({startPositionUtm.x, startPositionUtm.y}, {endPositionUtm.x, endPositionUtm.y}); int segmentLength = line.length(); if (segmentLength <= 50) return 50; if (segmentLength >= 300) return 300; return (((segmentLength + 25) / 50) * 50); } //----------------------------------------------------------------------------- int EffectShowMineArea::getEffectAreaDepth() const { int segmentWidth = qRound(m_mineArea.width()); if (segmentWidth <= 50) return 50; if (segmentWidth >= 300) return 300; return (((segmentWidth + 25) / 50) * 50); } //static ---------------------------------------------------------------------- LtsCoordTrans::UtmCoordinate EffectShowMineArea::rotate(const LtsCoordTrans::UtmCoordinate &p, const LtsCoordTrans::UtmCoordinate &c, double angle) { LtsCoordTrans::UtmCoordinate res = p; // copy zone, northp res.x = ((p.x - c.x) * cos(angle)) - ((p.y - c.y) * sin(angle)) + c.x; res.y = ((p.x - c.x) * sin(angle)) + ((p.y - c.y) * cos(angle)) + c.y; return res; } //----------------------------------------------------------------------------- } // Namespace EffectShowManagement