/** * Handler for the HMI language * $Id$ * $HeadURL$ * $Author$ */ #include "object_effect_show.h" #include "initialization.h" #include namespace EffectShowManagement { //============================================================================= ObjectEffectShow::ObjectEffectShow(Initialization *mainHandler, QObject *parent) : QObject(parent) , m_mainHandler(mainHandler) , m_logger(getLogger("ObjectEffectShow")) { } // end of ctor() //============================================================================= ObjectEffectShow::~ObjectEffectShow() { if (m_bRemoveFromDdsOnDestruction && m_data.id > 0) m_mainHandler->dds()->dts()->removeEffectShowByKey(m_data.id); } // end of dtor() //============================================================================= Core::FunctionReplyObject ObjectEffectShow::createObject(const Database::EsmEffectShow &data, bool bForceUpdateDb) { m_data = data; if (m_data.id <= 0) { if (!m_mainHandler->db()->insert(m_data)) return Core::FunctionReplyObject(0, tr_lts("dds", "Error inserting Effect Show into database.")); } else { if (bForceUpdateDb && !m_mainHandler->db()->update(m_data)) return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "Error updating EffectShow into database")); } DEBUG_LOG(m_logger) << "createObject(db) complete ->" << "\n id " << m_data.id << "\n centerPosition " << LtsCoordTrans::mgrsFromGeographic(m_data.centerPosition.x(), m_data.centerPosition.y()) << "\n idAreaEffectSimulation " << m_data.idAreaEffectSimulation << "\n esmParticipantId " << m_data.esmParticipantId << "\n numOfVolley " << m_data.numOfVolley << "\n shotsPerVolley " << m_data.shotsPerVolley << "\n orderConfirmation " << m_data.orderConfirmation << "\n answerText " << m_data.answerText << "\n startTime " << m_data.startTime << "\n duration " << m_data.duration << "\n lowerLeftPosition " << LtsCoordTrans::mgrsFromGeographic(m_data.lowerLeftPosition.x(), m_data.lowerLeftPosition.y()) << "\n areaWidth " << m_data.areaWidth << "\n areaDepth " << m_data.areaDepth << "\n areaRotation " << m_data.areaRotation << "\n typeOfAmmunition " << (int)m_data.typeOfAmmunition; // Publish Data via DTS onPublishData(); return Core::FunctionReplyObject(m_data.id); } // end of createObject() //============================================================================= Core::FunctionReplyObject ObjectEffectShow::removeObject() { if (!m_mainHandler->db()->removeEsmEffectShow(m_data.id)) return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "EffectShow %1 can not be removed")).arg(m_data.id); return Core::FunctionReplyObject(m_data.id); } // end of removeObject() //============================================================================= Core::FunctionReplyObject ObjectEffectShow::updateObject(const EffectShowManagement::EffectShow &data) { if (data.id <= 0) return Core::FunctionReplyObject(data.id, tr_lts("dds", "Object not valid/blocked")); if (m_data.orderConfirmation == static_cast(EffectShowManagement::OrderConfirmation_e::Execution)) return Core::FunctionReplyObject(data.id, tr_lts("dds", "Changes rejected due to Effect Show in execution.")); DEBUG_LOG(m_logger) << "updateObject(data topic) complete ->" << "\n id " << m_data.id << " new: " << data.id << "\n centerPosition x " << m_data.centerPosition.x() << " new: " << data.position.lon << "\n centerPosition y " << m_data.centerPosition.y() << " new: " << data.position.lat << "\n idAreaEffectSimulation " << m_data.idAreaEffectSimulation << " new: " << data.idAreaEffectSimulation << "\n esmParticipantId " << m_data.esmParticipantId << " new: " << data.esmParticipantId << "\n numOfVolley " << m_data.numOfVolley << " new: " << data.numOfVolley << "\n shotsPerVolley " << m_data.shotsPerVolley << " new: " << data.shotsPerVolley << "\n orderConfirmation " << m_data.orderConfirmation << " new: " << data.orderConfirmation << "\n answerText " << m_data.answerText << " new: " << QString::fromStdString((data.answerText)) << "\n startTime " << m_data.startTime << "\n duration " << m_data.duration << "\n lowerLeftPosition x " << m_data.lowerLeftPosition.x() << "\n lowerLeftPosition y " << m_data.lowerLeftPosition.y() << "\n areaWidth " << m_data.areaWidth << "\n areaDepth " << m_data.areaDepth << "\n areaRotation " << m_data.areaRotation << "\n typeOfAmmunition " << m_data.typeOfAmmunition; m_data.id = data.id; m_data.name = QString::fromStdString(data.name); m_data.startTime = data.startTime.is_set() ? data.startTime.get() : 0; m_data.duration = data.duration; m_data.idAreaEffectSimulation = data.idAreaEffectSimulation; m_data.nameAreaEfffectSimulation = QString::fromStdString(data.nameAreaEffectSimulation); m_data.esmParticipantId = data.esmParticipantId; m_data.centerPosition.setX(data.position.lon); m_data.centerPosition.setY(data.position.lat); m_data.numOfVolley = data.numOfVolley; m_data.shotsPerVolley = data.shotsPerVolley; m_data.lowerLeftPosition.setX(data.lowerLeftPosition.lon); m_data.lowerLeftPosition.setY(data.lowerLeftPosition.lat); m_data.areaDepth = data.areaDepth; m_data.areaWidth = data.areaWidth; m_data.areaRotation = data.areaRotation; m_data.orderConfirmation = static_cast(data.orderConfirmation); m_data.answerText = QString::fromStdString((data.answerText)); if (!m_mainHandler->db()->update(m_data)) return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "Error updating EffectShow into database")); DEBUG_LOG(m_logger) << "Data changed for EffectShow Id: " << m_data.id; // Publish Data via DTS onPublishData(); return Core::FunctionReplyObject(m_data.id); } // end of updateObject() //============================================================================= bool ObjectEffectShow::updateObject(const ConvertFromTab::OrderConfirmation_t &data) { DEBUG_LOG(m_logger) << "updateObject() partly ->" << "\n orderConfirmation " << m_data.orderConfirmation << " new: " << data.confirmation << "\n answerText " << m_data.answerText << " new: " << data.answerText; m_data.orderConfirmation = static_cast(data.confirmation); m_data.answerText = data.answerText; if (!m_mainHandler->db()->update(m_data)) { ERROR_LOG(m_logger) << "Effect Show Order Confirmation can_t be updated Id: " << m_data.id; return false; } // Publish Data via DTS onPublishData(); return true; } // end of updateObject() //============================================================================= bool ObjectEffectShow::updateObject(const Database::EsmEffectShow &data) { DEBUG_LOG(m_logger) << "updateObject(db) complete ->" << "\n id " << m_data.id << " new: " << data.id << "\n centerPosition x " << m_data.centerPosition.x() << " new: " << data.centerPosition.x() << "\n centerPosition y " << m_data.centerPosition.y() << " new: " << data.centerPosition.y() << "\n idAreaEffectSimulation " << m_data.idAreaEffectSimulation << " new: " << data.idAreaEffectSimulation << "\n esmParticipantId " << m_data.esmParticipantId << " new: " << data.esmParticipantId << "\n numOfVolley " << m_data.numOfVolley << " new: " << data.numOfVolley << "\n shotsPerVolley " << m_data.shotsPerVolley << " new: " << data.shotsPerVolley << "\n orderConfirmation " << m_data.orderConfirmation << " new: " << data.orderConfirmation << "\n answerText " << m_data.answerText << " new: " << data.answerText << "\n startTime " << m_data.startTime << " new: " << data.startTime << "\n duration " << m_data.duration << " new: " << data.duration << "\n lowerLeftPosition x " << m_data.lowerLeftPosition.x() << " new: " << data.lowerLeftPosition.x() << "\n lowerLeftPosition y " << m_data.lowerLeftPosition.y() << " new: " << data.lowerLeftPosition.y() << "\n areaWidth " << m_data.areaWidth << " new: " << data.areaWidth << "\n areaDepth " << m_data.areaDepth << " new: " << data.areaDepth << "\n areaRotation " << m_data.areaRotation << " new: " << data.areaRotation << "\n typeOfAmmunition " << m_data.typeOfAmmunition << " new: " << data.typeOfAmmunition; qint64 id = m_data.id; // ID must be unchanged m_data = data; m_data.id = id; if (!m_mainHandler->db()->update(m_data)) { ERROR_LOG(m_logger) << "Failed effect Show updated Id: " << m_data.id; return false; } // Publish Data via DTS onPublishData(); return true; } // end of updateObject() //============================================================================= bool ObjectEffectShow::resetOrderConfirmation() { m_data.orderConfirmation = static_cast(EffectShowManagement::OrderConfirmation_e::WaitingForAcceptance); m_data.answerText.clear(); if (!m_mainHandler->db()->update(m_data)) { ERROR_LOG(m_logger) << "Effect Show Order Confirmation can_t be updated Id: " << m_data.id; return false; } // Publish Data via DTS onPublishData(); return true; } // end of resetOrderConfirmation() //============================================================================= ConvertToTab::EffectShowOrder_t ObjectEffectShow::getEffectShowOrder() const { ConvertToTab::EffectShowOrder_t order; order.idEffectShow = m_data.id; order.areaDepth = m_data.areaDepth; order.areaWidth = m_data.areaWidth; order.centerPosition = Core::GeoPosition2D(m_data.centerPosition.x(), m_data.centerPosition.y()); order.duration = m_data.duration / 1000; // [ms] -> [s] order.lowerLeftPosition = Core::GeoPosition2D(m_data.lowerLeftPosition.x(), m_data.lowerLeftPosition.y()); order.numOfVolley = m_data.numOfVolley; order.shotsPerVolley = m_data.shotsPerVolley; order.rotation = m_data.areaRotation; order.startTime = m_data.startTime / 1000; // [ms] -> [s] order.typeOfAmmunition = m_data.typeOfAmmunition; order.name = m_data.nameAreaEfffectSimulation; DEBUG_LOG(m_logger) << "getEffectShowOrder():" << "\n idEffectShow " << order.idEffectShow << "\n areaDepth " << order.areaDepth << "\n areaWidth " << order.areaWidth << "\n centerPosition " << order.centerPosition << "\n duration " << (int)order.duration << "\n lowerLeftPosition " << order.lowerLeftPosition << "\n numOfVolley " << (int)order.numOfVolley << "\n shotsPerVolely " << (int)order.shotsPerVolley << "\n rotation " << order.rotation << "\n startTime " << (int)order.startTime << "\n typeOfAmmunition " << order.typeOfAmmunition; return order; } //============================================================================= ConvertToTab::RetractOrder_t ObjectEffectShow::getRetractOrder() const { ConvertToTab::RetractOrder_t order; order.id = m_data.id; order.orderType = 1; DEBUG_LOG(m_logger) << "getRetractOrder():" << "\n id " << order.id << "\n orderType " << (int)order.orderType; return order; } //============================================================================= ConvertToTab::EffectShowContinue_t ObjectEffectShow::getContinueOrder() const { ConvertToTab::EffectShowContinue_t order; order.idEffectShow = m_data.id; order.executionTime = m_data.startTime / 1000; // [ms] -> [s] DEBUG_LOG(m_logger) << "getContinueOrder():" << "\n id " << order.idEffectShow << "\n orderType " << order.executionTime; return order; } //============================================================================= void ObjectEffectShow::onPublishData() { EffectShowManagement::EffectShow ddsData; ddsData.id = m_data.id; ddsData.name = m_data.name.toStdString(); ddsData.startTime = m_data.startTime; ddsData.duration = m_data.duration; ddsData.idAreaEffectSimulation = m_data.idAreaEffectSimulation; ddsData.nameAreaEffectSimulation = m_data.nameAreaEfffectSimulation.toStdString(); ddsData.esmParticipantId = m_data.esmParticipantId; ddsData.position = Core::GeoPosition2D(m_data.centerPosition.x(), m_data.centerPosition.y()); ddsData.numOfVolley = m_data.numOfVolley; ddsData.shotsPerVolley = m_data.shotsPerVolley; //we need this for the smoke type ddsData.lowerLeftPosition = Core::GeoPosition2D(m_data.lowerLeftPosition.x(), m_data.lowerLeftPosition.y()); ddsData.areaDepth = m_data.areaDepth; ddsData.areaWidth = m_data.areaWidth; ddsData.areaRotation = m_data.areaRotation; ddsData.typeOfAmmunition = m_data.typeOfAmmunition; ddsData.orderConfirmation = static_cast(m_data.orderConfirmation); ddsData.answerText = m_data.answerText.toStdString(); ddsData.isDeleted = false; ddsData.isUsed = false; INFO_LOG(m_logger) << "Publish EsmEffectShow-data to dds (" << m_data.id << ") ..."; if (!m_mainHandler->dds()->dts()->publish(ddsData)) ERROR_LOG(m_logger) << "Error publishing EsmEffectShow-data to dds"; } // end of onPublishData() //----------------------------------------------------------------------------- } // Namespace EffectShowManagement