From 3554c0b718a93f0a10aabed7a3cede52bd864bd5 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 30 Jul 2016 03:08:09 +0200 Subject: [PATCH] refs #716, value class / setting --- src/blackmisc/propertyindex.h | 5 +- .../simulation/registermetadatasimulation.cpp | 1 + .../simulation/settings/settingssimulator.cpp | 156 +++++++++++++++++- .../simulation/settings/settingssimulator.h | 123 +++++++++++++- 4 files changed, 280 insertions(+), 5 deletions(-) diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index 0cba03021..42e2e3e13 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -122,8 +122,9 @@ namespace BlackMisc GlobalIndexCTextMessage = 6900, GlobalIndexCSimulatorSetup = 7000, GlobalIndexCSimulatorSettings = 7100, - GlobalIndexCAircraftCfgEntries = 7200, - GlobalIndexCDistributor = 7300, + GlobalIndexCSimulatorMessageSettings = 7200, + GlobalIndexCAircraftCfgEntries = 7300, + GlobalIndexCDistributor = 7400, GlobalIndexCVPilotModelRule = 8000, GlobalIndexCVoiceRoom = 9000, GlobalIndexCSettingKeyboardHotkey = 10000, diff --git a/src/blackmisc/simulation/registermetadatasimulation.cpp b/src/blackmisc/simulation/registermetadatasimulation.cpp index 2edd1d0d6..813593f21 100644 --- a/src/blackmisc/simulation/registermetadatasimulation.cpp +++ b/src/blackmisc/simulation/registermetadatasimulation.cpp @@ -43,6 +43,7 @@ namespace BlackMisc CVPilotModelRule::registerMetadata(); CVPilotModelRuleSet::registerMetadata(); CSettingsSimulator::registerMetadata(); + CSettingsSimulatorMessages::registerMetadata(); } } // ns } // ns diff --git a/src/blackmisc/simulation/settings/settingssimulator.cpp b/src/blackmisc/simulation/settings/settingssimulator.cpp index 47f6cc118..48bc6471e 100644 --- a/src/blackmisc/simulation/settings/settingssimulator.cpp +++ b/src/blackmisc/simulation/settings/settingssimulator.cpp @@ -8,12 +8,13 @@ */ #include "settingssimulator.h" +#include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/fscommon/fscommonutil.h" #include "blackmisc/simulation/xplane/xplaneutil.h" #include "blackmisc/stringutils.h" - using namespace BlackMisc; +using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Simulation::FsCommon; using namespace BlackMisc::Simulation::XPlane; @@ -283,6 +284,159 @@ namespace BlackMisc s.resetPaths(); this->setAndSaveSettings(s, simulator); } + + CSettingsSimulatorMessages::CSettingsSimulatorMessages() + { + // void + } + + void CSettingsSimulatorMessages::setTechnicalLogSeverity(CStatusMessage::StatusSeverity severity) + { + this->m_technicalLogLevel = static_cast(severity); + } + + void CSettingsSimulatorMessages::disableTechnicalMessages() + { + this->m_technicalLogLevel = -1; + } + + bool CSettingsSimulatorMessages::isRelayedErrorsMessages() const + { + if (this->m_technicalLogLevel < 0) { return false; } + return (this->m_technicalLogLevel <= CStatusMessage::SeverityError); + } + + bool CSettingsSimulatorMessages::isRelayedWarningMessages() const + { + if (this->m_technicalLogLevel < 0) { return false; } + return (this->m_technicalLogLevel <= CStatusMessage::SeverityWarning); + } + + bool CSettingsSimulatorMessages::isRelayedInfoMessages() const + { + if (this->m_technicalLogLevel < 0) { return false; } + return (this->m_technicalLogLevel <= CStatusMessage::SeverityInfo); + } + + bool CSettingsSimulatorMessages::isRelayedTechnicalMessages() const + { + return (this->m_technicalLogLevel >= 0); + } + + void CSettingsSimulatorMessages::setRelayedTextMessages(CSettingsSimulatorMessages::TextMessageType messageType) + { + this->m_messageType = static_cast(messageType); + } + + bool CSettingsSimulatorMessages::isRelayedSupervisorTextMessages() const + { + return this->getRelayedTextMessageTypes().testFlag(TextMessageSupervisor); + } + + bool CSettingsSimulatorMessages::isRelayedPrivateTextMessages() const + { + return this->getRelayedTextMessageTypes().testFlag(TextMessagePrivate); + } + + bool CSettingsSimulatorMessages::isRelayedUnicomTextMessages() const + { + return this->getRelayedTextMessageTypes().testFlag(TextMessagesUnicom); + } + + bool CSettingsSimulatorMessages::isRelayedCom1TextMessages() const + { + return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom1); + } + + bool CSettingsSimulatorMessages::isRelayedCom2TextMessages() const + { + return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom2); + } + + bool CSettingsSimulatorMessages::isRelayedTextMessage(const Network::CTextMessage &msg, const BlackMisc::Simulation::CSimulatedAircraft &aircraft) const + { + if (msg.isEmpty()) { return false; } + if (!this->isGloballyEnabled()) { return false; } + if (this->m_messageType == NoTextMessages) { return false; } + + const TextMessageType mt = static_cast(this->m_messageType); + if (msg.isPrivateMessage() && mt.testFlag(TextMessagePrivate)) { return true; } + if (msg.isSupervisorMessage() && (mt.testFlag(TextMessagePrivate) || mt.testFlag(TextMessageSupervisor))) { return true; } + if (msg.isSendToUnicom() && mt.testFlag(TextMessagesUnicom)) { return true; } + + if (msg.isRadioMessage()) + { + const CFrequency f(msg.getFrequency()); + if (mt.testFlag(TextMessagesCom1)) + { + if (aircraft.getCom1System().isActiveFrequencyWithin8_33kHzChannel(f)) { return true; } + } + if (mt.testFlag(TextMessagesCom2)) + { + if (aircraft.getCom2System().isActiveFrequencyWithin8_33kHzChannel(f)) { return true; } + } + } + return false; + } + + CSettingsSimulatorMessages::TextMessageType CSettingsSimulatorMessages::getRelayedTextMessageTypes() const + { + return static_cast(this->m_messageType); + } + + QString CSettingsSimulatorMessages::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + QString s("Enabled %1, text messages: %2, severity: %3"); + QString severity; + if (this->isRelayedTechnicalMessages()) + { + severity = "No tech. msgs"; + } + else + { + severity = CStatusMessage::severityToString(static_cast(this->m_technicalLogLevel)); + } + return s.arg(boolToOnOff(this->m_globallyEnabled)).arg(this->m_messageType).arg(severity); + } + + CVariant CSettingsSimulatorMessages::propertyByIndex(const CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexTechnicalLogSeverity: + return CVariant::fromValue(this->m_technicalLogLevel); + case IndexTextMessageRelay: + return CVariant::from(this->m_messageType); + case IndexGloballyEnabled: + return CVariant::from(this->m_globallyEnabled); + default: + return CValueObject::propertyByIndex(index); + } + } + + void CSettingsSimulatorMessages::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexTechnicalLogSeverity: + this->setTechnicalLogSeverity(static_cast(variant.toInt())); + break; + case IndexTextMessageRelay: + this->setRelayedTextMessages(static_cast(variant.toInt())); + break; + case IndexGloballyEnabled: + this->setGloballyEnabled(variant.toBool()); + break; + default: + CValueObject::setPropertyByIndex(index, variant); + break; + } + } } // ns } // ns } // ns diff --git a/src/blackmisc/simulation/settings/settingssimulator.h b/src/blackmisc/simulation/settings/settingssimulator.h index 8e8b1c724..d51afaf24 100644 --- a/src/blackmisc/simulation/settings/settingssimulator.h +++ b/src/blackmisc/simulation/settings/settingssimulator.h @@ -12,9 +12,11 @@ #ifndef BLACKMISC_SIMULATION_SETTINGS_SETTINGSSIMULATOR_H #define BLACKMISC_SIMULATION_SETTINGS_SETTINGSSIMULATOR_H -#include "blackmisc/settingscache.h" -#include "blackmisc/blackmiscexport.h" #include "blackmisc/simulation/simulatorinfo.h" +#include "blackmisc/network/textmessage.h" +#include "blackmisc/settingscache.h" +#include "blackmisc/statusmessage.h" +#include "blackmisc/blackmiscexport.h" #include "blackmisc/propertyindex.h" #include @@ -24,6 +26,8 @@ namespace BlackMisc { namespace Simulation { + class CSimulatedAircraft; + namespace Settings { //! Settings for simulator @@ -174,6 +178,115 @@ namespace BlackMisc BlackMisc::CSetting m_simSettingsP3D {this}; //!< P3D cache BlackMisc::CSetting m_simSettingsXP {this}; //!< XP cache }; + + //! Settings regarding message handling. + //! Driver independent part, related to network + class BLACKMISC_EXPORT CSettingsSimulatorMessages : + public BlackMisc::CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexTechnicalLogSeverity = BlackMisc::CPropertyIndex::GlobalIndexCSimulatorMessageSettings, + IndexTextMessageRelay, + IndexGloballyEnabled + }; + + //! Enabled matching mode flags + enum TextMessageTypeFlag + { + NoTextMessages = 0, + TextMessagesUnicom = 1 << 0, + TextMessagesCom1 = 1 << 1, + TextMessagesCom2 = 1 << 2, + TextMessagePrivate = 1 << 3, + TextMessageSupervisor = 1 << 4, + TextMessagesAll = TextMessagesUnicom | TextMessagesCom1 | TextMessagesCom2 | TextMessagePrivate + }; + Q_DECLARE_FLAGS(TextMessageType, TextMessageTypeFlag) + + //! Default constructor + CSettingsSimulatorMessages(); + + //! Destructor. + ~CSettingsSimulatorMessages() {} + + //! Log severity + void setTechnicalLogSeverity(BlackMisc::CStatusMessage::StatusSeverity severity); + + //! Globally enable / disable + void setGloballyEnabled(bool enabled) { this->m_globallyEnabled = enabled; } + + //! Globally enabled? + bool isGloballyEnabled() const { return this->m_globallyEnabled; } + + //! No technical messages + void disableTechnicalMessages(); + + //! Relay (technical) error messages + bool isRelayedErrorsMessages() const; + + //! Relay (technical) warning messages + bool isRelayedWarningMessages() const; + + //! Relay (technical) info messages + bool isRelayedInfoMessages() const; + + //! Relay any message + bool isRelayedTechnicalMessages() const; + + //! Relay the following message types + void setRelayedTextMessages(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageType messageType); + + //! Relay supervisor messages + bool isRelayedSupervisorTextMessages() const; + + //! Relay private messages + bool isRelayedPrivateTextMessages() const; + + //! Relay UNICOM messages + bool isRelayedUnicomTextMessages() const; + + //! Relay given text message + bool isRelayedTextMessage(const BlackMisc::Network::CTextMessage &msg, const BlackMisc::Simulation::CSimulatedAircraft &aircraft) const; + + //! Relay COM1 text message + bool isRelayedCom1TextMessages() const; + + //! Relay COM2 text message + bool isRelayedCom2TextMessages() const; + + //! Relayed text messages + CSettingsSimulatorMessages::TextMessageType getRelayedTextMessageTypes() const; + + //! \copydoc BlackMisc::Mixin::String::toQString + QString convertToQString(bool i18n = false) const; + + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex + BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex + void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant); + + private: + int m_technicalLogLevel = BlackMisc::CStatusMessage::SeverityError; //!< Simulator directory + int m_messageType = static_cast(TextMessagePrivate | TextMessageSupervisor); + bool m_globallyEnabled = true; //!< messsage relay enabled to simulator + + BLACK_METACLASS( + CSettingsSimulatorMessages, + BLACK_METAMEMBER(technicalLogLevel), + BLACK_METAMEMBER(messageType) + ); + }; + + //! Trait for simulator message settings + struct SettingsSimulatorMessages : public BlackMisc::CSettingTrait + { + //! Key in data cache + static const char *key() { return "settingssimulatormessages"; } + }; } // ns } // ns } // ns @@ -181,5 +294,11 @@ namespace BlackMisc Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulator) Q_DECLARE_METATYPE(BlackMisc::CCollection) Q_DECLARE_METATYPE(BlackMisc::CSequence) +Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages) +Q_DECLARE_METATYPE(BlackMisc::CCollection) +Q_DECLARE_METATYPE(BlackMisc::CSequence) +Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageTypeFlag) +Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageType) +Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageType) #endif // guard