Ref T112, moved simulator settings in subdir/settings namespace

This commit is contained in:
Klaus Basan
2017-08-06 00:29:37 +02:00
committed by Mathew Sutcliffe
parent f3847bd33c
commit 1387573e5b
29 changed files with 960 additions and 940 deletions

View File

@@ -44,6 +44,7 @@ using namespace BlackMisc::Network;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Simulation::Settings;
namespace BlackCore
{

View File

@@ -31,7 +31,7 @@
#include "blackmisc/simulation/simulatorplugininfo.h"
#include "blackmisc/simulation/simulatorplugininfolist.h"
#include "blackmisc/simulation/simulatorinternals.h"
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/settings/simulatorsettings.h"
#include "blackmisc/worker.h"
#include <QObject>
@@ -206,7 +206,7 @@ namespace BlackCore
BlackCore::CAircraftMatcher m_aircraftMatcher; //!< Model matcher
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this }; //!< load model set from caches
QMap<BlackMisc::Aviation::CCallsign, BlackMisc::CStatusMessageList> m_matchingMessages;
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::TSimulatorMessages> m_messageSettings { this }; //!< settings for messages
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TSimulatorMessages> m_messageSettings { this }; //!< settings for messages
BlackMisc::CSettingReadOnly<BlackCore::Application::TEnabledSimulators> m_enabledSimulators { this, &CContextSimulator::changeEnabledSimulators };
QString m_networkSessionId; //! Network session, if not connected empty
bool m_initallyAddAircrafts = false;

View File

@@ -28,7 +28,7 @@
#include "blackmisc/simulation/simulatorinfo.h"
#include "blackmisc/simulation/simulatorplugininfo.h"
#include "blackmisc/simulation/simulatorinternals.h"
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/settings/simulatorsettings.h"
#include "blackmisc/simulation/interpolationrenderingsetup.h"
#include "blackmisc/simulation/interpolationhints.h"
#include "blackmisc/simulation/interpolationlogger.h"
@@ -215,7 +215,7 @@ namespace BlackCore
bool m_isWeatherActivated = false; //!< Is simulator weather activated?
BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last
BlackMisc::CSetting<BlackMisc::Simulation::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorCommon::reloadWeatherSettings }; //!< Selected weather scenario
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSelectedWeatherScenario> m_weatherScenarioSettings { this, &CSimulatorCommon::reloadWeatherSettings }; //!< Selected weather scenario
//! Lookup against DB data
static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Simulation::CAircraftModel &model);

View File

@@ -14,7 +14,7 @@
#include "blackgui/components/dbmappingcomponentaware.h"
#include "blackgui/menus/menudelegate.h"
#include "blackmisc/simulation/modelsettings.h"
#include "blackmisc/simulation/settings/modelsettings.h"
#include "blackmisc/simulation/aircraftmodelinterfaces.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackmisc/simulation/aircraftmodelsetloader.h"
@@ -151,8 +151,8 @@ namespace BlackGui
QScopedPointer<Ui::CDbOwnModelSetComponent> ui;
QScopedPointer<CDbOwnModelSetDialog> m_modelSetDialog;
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this };
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::TDistributorListPreferences> m_distributorPreferences { this, &CDbOwnModelSetComponent::ps_distributorPreferencesChanged }; //!< distributor preferences
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::TModel> m_modelSettings { this, &CDbOwnModelSetComponent::ps_modelSettingsChanged }; //!< settings for models
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TDistributorListPreferences> m_distributorPreferences { this, &CDbOwnModelSetComponent::ps_distributorPreferencesChanged }; //!< distributor preferences
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TModel> m_modelSettings { this, &CDbOwnModelSetComponent::ps_modelSettingsChanged }; //!< settings for models
// -------------------------- custom menus -----------------------------------

View File

@@ -14,7 +14,7 @@
#include "blackmisc/settingscache.h"
#include "blackmisc/simulation/aircraftmodelsetloader.h"
#include "blackmisc/simulation/modelsettings.h"
#include "blackmisc/simulation/settings/modelsettings.h"
#include "blackmisc/simulation/simulatorinfo.h"
#include <QFrame>
@@ -70,7 +70,7 @@ namespace BlackGui
QScopedPointer<Ui::CDistributorPreferencesComponent> ui;
BlackGui::COverlayMessagesFrame *m_overlayMessageFrame = nullptr;
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this };
BlackMisc::CSetting<BlackMisc::Simulation::TDistributorListPreferences> m_distributorPreferences { this, &CDistributorPreferencesComponent::ps_preferencesChanged };
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TDistributorListPreferences> m_distributorPreferences { this, &CDistributorPreferencesComponent::ps_preferencesChanged };
//! Update
void updateContainerMaybeAsync(const BlackMisc::Simulation::CDistributorList &models, bool sortByOrder = true);

View File

@@ -42,7 +42,7 @@ namespace BlackGui
void saveSettings();
QScopedPointer<Ui::CModelConverterXSetupComponent> ui;
BlackMisc::CSetting<BlackMisc::Simulation::TModelConverterXBinary> m_setting { this };
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TModelConverterXBinary> m_setting { this };
};
} // ns
} // ns

View File

@@ -18,6 +18,7 @@
using namespace BlackMisc;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Simulation::FsCommon;
using namespace BlackMisc::Simulation::Settings;
using namespace BlackConfig;
namespace BlackGui

View File

@@ -12,7 +12,7 @@
#ifndef BLACKGUI_COMPONENTS_SETTINGSSIMULATORBASICSCOMPONENT_H
#define BLACKGUI_COMPONENTS_SETTINGSSIMULATORBASICSCOMPONENT_H
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/settings/simulatorsettings.h"
#include "blackmisc/simulation/fscommon/fscommonutil.h"
#include <QFrame>
#include <QFileDialog>
@@ -58,7 +58,7 @@ namespace BlackGui
private:
QScopedPointer<Ui::CSettingsSimulatorBasicsComponent> ui;
BlackMisc::Simulation::CMultiSimulatorSettings m_settings { this };
BlackMisc::Simulation::Settings::CMultiSimulatorSettings m_settings { this };
Qt::CaseSensitivity m_fileCaseSensitivity = BlackMisc::CFileUtils::osFileNameCaseSensitivity();
//! Optimize for small layout
@@ -77,7 +77,7 @@ namespace BlackGui
void displayModelDirectories(const QStringList &dirs);
//! Current settings
BlackMisc::Simulation::CSimulatorSettings getSettings(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
BlackMisc::Simulation::Settings::CSimulatorSettings getSettings(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Display simulator`s settings
void displaySettings(const BlackMisc::Simulation::CSimulatorInfo &simulator);

View File

@@ -9,10 +9,11 @@
#include "settingssimulatormessagescomponent.h"
#include "ui_settingssimulatormessagescomponent.h"
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/settings/simulatorsettings.h"
using namespace BlackMisc;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Simulation::Settings;
namespace BlackGui
{

View File

@@ -12,7 +12,7 @@
#ifndef BLACKGUI_COMPONENTS_SETTINGSSIMULATORMESSAGESCOMPONENT_H
#define BLACKGUI_COMPONENTS_SETTINGSSIMULATORMESSAGESCOMPONENT_H
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/settings/simulatorsettings.h"
#include <QFrame>
#include <QScopedPointer>
@@ -44,7 +44,7 @@ namespace BlackGui
private:
QScopedPointer<Ui::CSettingsSimulatorMessagesComponent> ui;
BlackMisc::CSetting<BlackMisc::Simulation::TSimulatorMessages> m_settings { this }; //!< settings for messages
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSimulatorMessages> m_settings { this }; //!< settings for messages
};
} // ns
} // ns

View File

@@ -16,7 +16,7 @@
#include "blackgui/blackguiexport.h"
#include "blackcore/actionbind.h"
#include "blackmisc/geo/coordinategeodetic.h"
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/settings/simulatorsettings.h"
#include "blackmisc/weather/weatherscenario.h"
#include "blackmisc/identifiable.h"
@@ -77,7 +77,7 @@ namespace BlackGui
QVector<BlackMisc::Weather::CWeatherScenario> m_weatherScenarios;
QTimer m_weatherUpdateTimer { this };
BlackMisc::Geo::CCoordinateGeodetic m_lastOwnAircraftPosition;
BlackMisc::CSetting<BlackMisc::Simulation::TSelectedWeatherScenario> m_weatherScenarioSetting { this };
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSelectedWeatherScenario> m_weatherScenarioSetting { this };
BlackCore::CActionBindings m_hotkeyBindings;
bool m_isWeatherActivated = false;
};

View File

@@ -13,7 +13,7 @@
#define BLACKGUI_EDITORS_OWNMODELSETFORM_H
#include "form.h"
#include "blackmisc/simulation/modelsettings.h"
#include "blackmisc/simulation/settings/modelsettings.h"
#include <QObject>
#include <QScopedPointer>
@@ -109,7 +109,7 @@ namespace BlackGui
QScopedPointer<Ui::COwnModelSetForm> ui;
BlackMisc::Simulation::CSimulatorInfo m_simulator;
BlackMisc::CSetting<BlackMisc::Simulation::TDistributorListPreferences> m_distributorPreferences { this, &COwnModelSetForm::ps_preferencesChanged };
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TDistributorListPreferences> m_distributorPreferences { this, &COwnModelSetForm::ps_preferencesChanged };
};
} // ns
} // ns

View File

@@ -16,7 +16,7 @@
#include "blackmisc/simulation/aircraftmodelinterfaces.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackmisc/simulation/data/modelcaches.h"
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/settings/simulatorsettings.h"
#include "blackmisc/simulation/simulatorinfo.h"
#include "blackmisc/statusmessage.h"
@@ -179,7 +179,7 @@ namespace BlackMisc
std::atomic<bool> m_cancelLoading { false }; //!< flag, requesting to cancel loading
std::atomic<bool> m_loadingInProgress { false }; //!< Loading in progress
BlackMisc::Simulation::Data::CModelCaches m_caches { false, this }; //!< caches
BlackMisc::Simulation::CMultiSimulatorSettings m_settings { this }; //!< settings
BlackMisc::Simulation::Settings::CMultiSimulatorSettings m_settings { this }; //!< settings
BlackMisc::CStatusMessageList m_loadingMessages; //!< loading messages
protected slots:

View File

@@ -16,6 +16,7 @@
using namespace BlackConfig;
using namespace BlackMisc;
using namespace BlackMisc::Simulation::Settings;
namespace BlackMisc
{

View File

@@ -44,20 +44,23 @@ namespace BlackMisc
static QProcess *s_proccess; //!< 0..1 process running
};
//! Binary of MCX
struct TModelConverterXBinary : public BlackMisc::TSettingTrait<QString>
namespace Settings
{
//! \copydoc BlackMisc::TSettingTrait::key
static const char *key() { return "mapping/modelconverterxbin"; }
//! \copydoc BlackMisc::TSettingTrait::isValid
static bool isValid(const QString &value)
//! Binary of MCX
struct TModelConverterXBinary : public BlackMisc::TSettingTrait<QString>
{
if (value.isEmpty()) { return true; }
const QFile f(value);
return f.exists();
}
};
//! \copydoc BlackMisc::TSettingTrait::key
static const char *key() { return "mapping/modelconverterxbin"; }
//! \copydoc BlackMisc::TSettingTrait::isValid
static bool isValid(const QString &value)
{
if (value.isEmpty()) { return true; }
const QFile f(value);
return f.exists();
}
};
} // ns
} // ns
} // ns

View File

@@ -1,55 +0,0 @@
/* Copyright (C) 2016
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "modelsettings.h"
#include "blackmisc/stringutils.h"
namespace BlackMisc
{
namespace Simulation
{
CModelSettings::CModelSettings()
{ }
QString CModelSettings::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
static const QString ms("Allow exclude: %1");
return ms.arg(boolToYesNo(this->m_allowExcludeModels));
}
CVariant CModelSettings::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexAllowExclude:
return CVariant::fromValue(this->m_allowExcludeModels);
default:
return CValueObject::propertyByIndex(index);
}
}
void CModelSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CModelSettings>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexAllowExclude:
this->setAllowExcludedModels(variant.toBool());
break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;
}
}
} // ns
} // ns

View File

@@ -1,82 +0,0 @@
/* Copyright (C) 2016
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_SIMULATION_MODELSETTINGS_H
#define BLACKMISC_SIMULATION_MODELSETTINGS_H
#include "blackmisc/simulation/distributorlistpreferences.h"
#include "blackmisc/settingscache.h"
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/propertyindex.h"
namespace BlackMisc
{
namespace Simulation
{
//! Settings for models
class BLACKMISC_EXPORT CModelSettings :
public BlackMisc::CValueObject<CModelSettings>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexAllowExclude = BlackMisc::CPropertyIndex::GlobalIndexCSimulatorSettings
};
//! Default constructor
CModelSettings();
//! Allow excluded models?
bool getAllowExcludedModels() const { return m_allowExcludeModels; }
//! Allow excluded models?
void setAllowExcludedModels(bool allow) { m_allowExcludeModels = allow; }
//! \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:
bool m_allowExcludeModels = false; //!< Allow excluded models in sets
BLACK_METACLASS(
CModelSettings,
BLACK_METAMEMBER(allowExcludeModels)
);
};
//! Trait for simulator settings
struct TModel : public BlackMisc::TSettingTrait<CModelSettings>
{
//! Key in data cache
static const char *key() { return "settingsmodels"; }
};
//! Mapping preferences for model distributor list
struct TDistributorListPreferences : public BlackMisc::TSettingTrait<BlackMisc::Simulation::CDistributorListPreferences>
{
//! \copydoc BlackMisc::TSettingTrait::key
static const char *key() { return "mapping/distributorpreferences"; }
};
} // ns
} // ns
Q_DECLARE_METATYPE(BlackMisc::Simulation::CModelSettings)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::CModelSettings>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::CModelSettings>)
#endif // guard

View File

@@ -0,0 +1,58 @@
/* Copyright (C) 2016
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "modelsettings.h"
#include "blackmisc/stringutils.h"
namespace BlackMisc
{
namespace Simulation
{
namespace Settings
{
CModelSettings::CModelSettings()
{ }
QString CModelSettings::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
static const QString ms("Allow exclude: %1");
return ms.arg(boolToYesNo(this->m_allowExcludeModels));
}
CVariant CModelSettings::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexAllowExclude:
return CVariant::fromValue(this->m_allowExcludeModels);
default:
return CValueObject::propertyByIndex(index);
}
}
void CModelSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CModelSettings>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexAllowExclude:
this->setAllowExcludedModels(variant.toBool());
break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;
}
}
} // ns
} // ns
} // ns

View File

@@ -0,0 +1,85 @@
/* Copyright (C) 2016
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_SIMULATION_SETTINGS_MODELSETTINGS_H
#define BLACKMISC_SIMULATION_SETTINGS_MODELSETTINGS_H
#include "blackmisc/simulation/distributorlistpreferences.h"
#include "blackmisc/settingscache.h"
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/propertyindex.h"
namespace BlackMisc
{
namespace Simulation
{
namespace Settings
{
//! Settings for models
class BLACKMISC_EXPORT CModelSettings :
public BlackMisc::CValueObject<CModelSettings>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexAllowExclude = BlackMisc::CPropertyIndex::GlobalIndexCSimulatorSettings
};
//! Default constructor
CModelSettings();
//! Allow excluded models?
bool getAllowExcludedModels() const { return m_allowExcludeModels; }
//! Allow excluded models?
void setAllowExcludedModels(bool allow) { m_allowExcludeModels = allow; }
//! \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:
bool m_allowExcludeModels = false; //!< Allow excluded models in sets
BLACK_METACLASS(
CModelSettings,
BLACK_METAMEMBER(allowExcludeModels)
);
};
//! Trait for simulator settings
struct TModel : public BlackMisc::TSettingTrait<CModelSettings>
{
//! Key in data cache
static const char *key() { return "settingsmodels"; }
};
//! Mapping preferences for model distributor list
struct TDistributorListPreferences : public BlackMisc::TSettingTrait<BlackMisc::Simulation::CDistributorListPreferences>
{
//! \copydoc BlackMisc::TSettingTrait::key
static const char *key() { return "mapping/distributorpreferences"; }
};
} // ns
} // ns
} // ns
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CModelSettings)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::Settings::CModelSettings>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::Settings::CModelSettings>)
#endif // guard

View File

@@ -0,0 +1,450 @@
/* Copyright (C) 2016
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "simulatorsettings.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;
namespace BlackMisc
{
namespace Simulation
{
namespace Settings
{
CSimulatorSettings::CSimulatorSettings()
{ }
void CSimulatorSettings::setSimulatorDirectory(const QString &simulatorDirectory)
{
this->m_simulatorDirectory = simulatorDirectory.trimmed();
}
const QString &CSimulatorSettings::getSimulatorDirectory() const
{
return this->m_simulatorDirectory;
}
void CSimulatorSettings::setModelDirectories(const QStringList &modelDirectories)
{
this->m_modelDirectories = modelDirectories;
}
void CSimulatorSettings::setModelDirectory(const QString &modelDirectory)
{
this->m_modelDirectories = QStringList({ modelDirectory });
}
const QStringList &CSimulatorSettings::getModelDirectories() const
{
return this->m_modelDirectories;
}
void CSimulatorSettings::setModelExcludeDirectories(const QStringList &excludeDirectories)
{
this->m_excludeDirectoryPatterns = excludeDirectories;
}
const QStringList &CSimulatorSettings::getModelExcludeDirectoryPatterns() const
{
return m_excludeDirectoryPatterns;
}
void CSimulatorSettings::resetPaths()
{
this->m_excludeDirectoryPatterns.clear();
this->m_modelDirectories.clear();
this->m_simulatorDirectory.clear();
}
QString CSimulatorSettings::convertToQString(bool i18n) const
{
return convertToQString(", ", i18n);
}
QString CSimulatorSettings::convertToQString(const QString &separator, bool i18n) const
{
Q_UNUSED(i18n);
QString s("model directories: ");
s.append(this->m_modelDirectories.join(','));
s.append(separator);
s.append("exclude directories: ");
s.append(this->m_excludeDirectoryPatterns.join(','));
return s;
}
CVariant CSimulatorSettings::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexSimulatorDirectory:
return CVariant::fromValue(this->m_simulatorDirectory);
case IndexModelDirectory:
return CVariant::fromValue(this->m_modelDirectories);
case IndexModelExcludeDirectoryPatterns:
return CVariant::fromValue(this->m_excludeDirectoryPatterns);
default:
return CValueObject::propertyByIndex(index);
}
}
void CSimulatorSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CSimulatorSettings>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexSimulatorDirectory:
this->setSimulatorDirectory(variant.toQString());
break;
case IndexModelDirectory:
this->setSimulatorDirectory(variant.toQString());
break;
case IndexModelExcludeDirectoryPatterns:
this->m_excludeDirectoryPatterns = variant.value<QStringList>();
break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;
}
}
CMultiSimulatorSettings::CMultiSimulatorSettings(QObject *parent) : QObject(parent)
{
// void
}
CSimulatorSettings CMultiSimulatorSettings::getSettings(const CSimulatorInfo &simulator) const
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.get();
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.get();
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.get();
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.get();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return CSimulatorSettings();
}
CStatusMessage CMultiSimulatorSettings::setSettings(const CSimulatorSettings &settings, const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.set(settings);
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.set(settings);
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.set(settings);
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.set(settings);
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
}
CStatusMessage CMultiSimulatorSettings::setAndSaveSettings(const CSimulatorSettings &settings, const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.setAndSave(settings);
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.setAndSave(settings);
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.setAndSave(settings);
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.setAndSave(settings);
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
}
CStatusMessage CMultiSimulatorSettings::saveSettings(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.save();
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.save();
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.save();
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.save();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
}
QString CMultiSimulatorSettings::getSimulatorDirectoryOrDefault(const CSimulatorInfo &simulator) const
{
const CSimulatorSettings s = this->getSettings(simulator);
if (s.getSimulatorDirectory().isEmpty())
{
return this->getDefaultSimulatorDirectory(simulator);
}
return s.getSimulatorDirectory();
}
QString CMultiSimulatorSettings::getDefaultSimulatorDirectory(const CSimulatorInfo &simulator) const
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9Dir();
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxDir();
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dDir();
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneRootDir(); //! check XP
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return "";
}
QStringList CMultiSimulatorSettings::getModelDirectoriesOrDefault(const CSimulatorInfo &simulator) const
{
const CSimulatorSettings s = this->getSettings(simulator);
if (s.getModelDirectories().isEmpty())
{
return this->getDefaultModelDirectories(simulator);
}
return s.getModelDirectories();
}
QString CMultiSimulatorSettings::getFirstModelDirectoryOrDefault(const CSimulatorInfo &simulator) const
{
const QStringList models(getModelDirectoriesOrDefault(simulator));
if (models.isEmpty()) { return ""; }
return models.first();
}
QStringList CMultiSimulatorSettings::getDefaultModelDirectories(const CSimulatorInfo &simulator) const
{
static const QStringList e;
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9AircraftDir().isEmpty() ? e : QStringList({ CFsCommonUtil::fs9AircraftDir() });
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxSimObjectsDir().isEmpty() ? e : QStringList({ CFsCommonUtil::fsxSimObjectsDir() });
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dSimObjectsDir().isEmpty() ? e : QStringList({ CFsCommonUtil::p3dSimObjectsDir()});
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneModelDirectories();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return QStringList();
}
QStringList CMultiSimulatorSettings::getModelExcludeDirectoryPatternsOrDefault(const CSimulatorInfo &simulator) const
{
const CSimulatorSettings s = this->getSettings(simulator);
QStringList exclude(s.getModelExcludeDirectoryPatterns());
if (!exclude.isEmpty()) { return exclude; }
exclude = this->getDefaultModelExcludeDirectoryPatterns(simulator);
return exclude;
}
QStringList CMultiSimulatorSettings::getDefaultModelExcludeDirectoryPatterns(const CSimulatorInfo &simulator) const
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9AircraftObjectsExcludeDirectoryPatterns();
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxSimObjectsExcludeDirectoryPatterns();
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dSimObjectsExcludeDirectoryPatterns();
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneModelExcludeDirectoryPatterns();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return QStringList();
}
void CMultiSimulatorSettings::resetToDefaults(const CSimulatorInfo &simulator)
{
CSimulatorSettings s = this->getSettings(simulator);
s.resetPaths();
this->setAndSaveSettings(s, simulator);
}
CSimulatorMessagesSettings::CSimulatorMessagesSettings()
{
// void
}
void CSimulatorMessagesSettings::setTechnicalLogSeverity(CStatusMessage::StatusSeverity severity)
{
this->m_technicalLogLevel = static_cast<int>(severity);
}
void CSimulatorMessagesSettings::disableTechnicalMessages()
{
this->m_technicalLogLevel = -1;
}
bool CSimulatorMessagesSettings::isRelayedErrorsMessages() const
{
if (this->m_technicalLogLevel < 0) { return false; }
return (this->m_technicalLogLevel <= CStatusMessage::SeverityError);
}
bool CSimulatorMessagesSettings::isRelayedWarningMessages() const
{
if (this->m_technicalLogLevel < 0) { return false; }
return (this->m_technicalLogLevel <= CStatusMessage::SeverityWarning);
}
bool CSimulatorMessagesSettings::isRelayedInfoMessages() const
{
if (this->m_technicalLogLevel < 0) { return false; }
return (this->m_technicalLogLevel <= CStatusMessage::SeverityInfo);
}
bool CSimulatorMessagesSettings::isRelayedTechnicalMessages() const
{
return (this->m_technicalLogLevel >= 0);
}
void CSimulatorMessagesSettings::setRelayedTextMessages(CSimulatorMessagesSettings::TextMessageType messageType)
{
this->m_messageType = static_cast<int>(messageType);
}
bool CSimulatorMessagesSettings::isRelayedSupervisorTextMessages() const
{
return this->getRelayedTextMessageTypes().testFlag(TextMessageSupervisor);
}
bool CSimulatorMessagesSettings::isRelayedPrivateTextMessages() const
{
return this->getRelayedTextMessageTypes().testFlag(TextMessagePrivate);
}
bool CSimulatorMessagesSettings::isRelayedUnicomTextMessages() const
{
return this->getRelayedTextMessageTypes().testFlag(TextMessagesUnicom);
}
bool CSimulatorMessagesSettings::isRelayedCom1TextMessages() const
{
return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom1);
}
bool CSimulatorMessagesSettings::isRelayedCom2TextMessages() const
{
return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom2);
}
bool CSimulatorMessagesSettings::relayThisStatusMessage(const CStatusMessage &message) const
{
if (message.isEmpty()) { return false; }
if (!this->isGloballyEnabled()) { return false; }
if (!this->isRelayedTechnicalMessages()) { return false; }
int s = static_cast<int>(message.getSeverity());
return (s >= this->m_technicalLogLevel);
}
bool CSimulatorMessagesSettings::relayThisTextMessage(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<TextMessageType>(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;
}
CSimulatorMessagesSettings::TextMessageType CSimulatorMessagesSettings::getRelayedTextMessageTypes() const
{
return static_cast<CSimulatorMessagesSettings::TextMessageType>(this->m_messageType);
}
QString CSimulatorMessagesSettings::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<CStatusMessage::StatusSeverity>(this->m_technicalLogLevel));
}
return s.arg(boolToOnOff(this->m_globallyEnabled)).arg(this->m_messageType).arg(severity);
}
CVariant CSimulatorMessagesSettings::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
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 CSimulatorMessagesSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CSimulatorMessagesSettings>(); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexTechnicalLogSeverity:
this->setTechnicalLogSeverity(static_cast<CStatusMessage::StatusSeverity>(variant.toInt()));
break;
case IndexTextMessageRelay:
this->setRelayedTextMessages(static_cast<CSimulatorMessagesSettings::TextMessageType>(variant.toInt()));
break;
case IndexGloballyEnabled:
this->setGloballyEnabled(variant.toBool());
break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;
}
}
} // ns
} // ns
} // ns

View File

@@ -0,0 +1,315 @@
/* Copyright (C) 2016
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_SIMULATION_SETTINGS_SIMULATORSETTINGS_H
#define BLACKMISC_SIMULATION_SETTINGS_SIMULATORSETTINGS_H
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/simulation/simulatorinfo.h"
#include "blackmisc/network/textmessage.h"
#include "blackmisc/weather/weatherscenario.h"
#include "blackmisc/settingscache.h"
#include "blackmisc/statusmessage.h"
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/propertyindex.h"
#include <QStringList>
#include <QObject>
namespace BlackMisc
{
namespace Simulation
{
namespace Settings
{
//! Settings for simulator
//! Driver independent part also used in loaders (such as directories)
class BLACKMISC_EXPORT CSimulatorSettings :
public BlackMisc::CValueObject<CSimulatorSettings>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexSimulatorDirectory = BlackMisc::CPropertyIndex::GlobalIndexCSimulatorSettings,
IndexModelDirectory,
IndexModelExcludeDirectoryPatterns
};
//! Default constructor
CSimulatorSettings();
//! Set simulator directory
void setSimulatorDirectory(const QString &simulatorDirectory);
//! Simulator directory
const QString &getSimulatorDirectory() const;
//! Set model directories
void setModelDirectories(const QStringList &modelDirectories);
//! Set single model directory
void setModelDirectory(const QString &modelDirectory);
//! Model directory
const QStringList &getModelDirectories() const;
//! Set exclude directories
void setModelExcludeDirectories(const QStringList &excludeDirectories);
//! Margins for given dock widget
const QStringList &getModelExcludeDirectoryPatterns() const;
//! Reset the paths
void resetPaths();
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
//! To string
QString convertToQString(const QString &separator, 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:
QString m_simulatorDirectory; //! Simulator directory
QStringList m_modelDirectories; //!< Model directory
QStringList m_excludeDirectoryPatterns; //!< Exclude model directory
BLACK_METACLASS(
CSimulatorSettings,
BLACK_METAMEMBER(simulatorDirectory),
BLACK_METAMEMBER(modelDirectories),
BLACK_METAMEMBER(excludeDirectoryPatterns)
);
};
//! Trait for simulator settings
struct TSimulatorFsx : public BlackMisc::TSettingTrait<CSimulatorSettings>
{
//! Key in data cache
static const char *key() { return "settingssimulatorfsx"; }
};
//! Trait for simulator settings
struct TSimulatorFs9 : public BlackMisc::TSettingTrait<CSimulatorSettings>
{
//! Key in data cache
static const char *key() { return "settingssimulatorfs9"; }
};
//! Trait for simulator settings
struct TSimulatorP3D : public BlackMisc::TSettingTrait<CSimulatorSettings>
{
//! Key in data cache
static const char *key() { return "settingssimulatorp3d"; }
};
//! Trait for simulator settings
struct TSimulatorXP : public BlackMisc::TSettingTrait<CSimulatorSettings>
{
//! Key in data cache
static const char *key() { return "settingssimulatorxplane"; }
};
//! Bundle of settings for all simulators
class BLACKMISC_EXPORT CMultiSimulatorSettings : public QObject
{
Q_OBJECT
public:
//! Construtor
CMultiSimulatorSettings(QObject *parent = nullptr);
//! Settings per simulator
CSimulatorSettings getSettings(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Set settings per simulator
BlackMisc::CStatusMessage setSettings(const BlackMisc::Simulation::Settings::CSimulatorSettings &settings, const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Set settings per simulator
BlackMisc::CStatusMessage setAndSaveSettings(const BlackMisc::Simulation::Settings::CSimulatorSettings &settings, const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Set settings per simulator
BlackMisc::CStatusMessage saveSettings(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Simulator directory or default model path per simulator
QString getSimulatorDirectoryOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Default simulator path per simulator
QString getDefaultSimulatorDirectory(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Model directory or default model path per simulator
QStringList getModelDirectoriesOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! First model directoy
QString getFirstModelDirectoryOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Default model path per simulator
QStringList getDefaultModelDirectories(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Model exclude paths per simulator
QStringList getModelExcludeDirectoryPatternsOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Default model exclude paths per simulator
QStringList getDefaultModelExcludeDirectoryPatterns(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Reset to defaults
void resetToDefaults(const BlackMisc::Simulation::CSimulatorInfo &simulator);
private:
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSimulatorFsx> m_simSettingsFsx {this}; //!< FSX cache
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSimulatorFs9> m_simSettingsFs9 {this}; //!< FS9 cache
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSimulatorP3D> m_simSettingsP3D {this}; //!< P3D cache
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSimulatorXP> m_simSettingsXP {this}; //!< XP cache
};
//! Settings regarding message handling.
//! Driver independent part, related to network
class BLACKMISC_EXPORT CSimulatorMessagesSettings :
public BlackMisc::CValueObject<CSimulatorMessagesSettings>
{
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
CSimulatorMessagesSettings();
//! 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::CSimulatorMessagesSettings::TextMessageType messageType);
//! Relay supervisor messages
bool isRelayedSupervisorTextMessages() const;
//! Relay private messages
bool isRelayedPrivateTextMessages() const;
//! Relay UNICOM messages
bool isRelayedUnicomTextMessages() const;
//! Relay COM1 text message
bool isRelayedCom1TextMessages() const;
//! Relay COM2 text message
bool isRelayedCom2TextMessages() const;
//! Relay given text message
bool relayThisTextMessage(const BlackMisc::Network::CTextMessage &msg, const BlackMisc::Simulation::CSimulatedAircraft &aircraft) const;
//! Relay this particular message
bool relayThisStatusMessage(const BlackMisc::CStatusMessage &message) const;
//! Relayed text messages
CSimulatorMessagesSettings::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<int>(TextMessagePrivate | TextMessageSupervisor);
bool m_globallyEnabled = true; //!< messsage relay enabled to simulator
BLACK_METACLASS(
CSimulatorMessagesSettings,
BLACK_METAMEMBER(technicalLogLevel),
BLACK_METAMEMBER(messageType)
);
};
//! Trait for simulator message settings
struct TSimulatorMessages : public BlackMisc::TSettingTrait<CSimulatorMessagesSettings>
{
//! Key in data cache
static const char *key() { return "settingssimulatormessages"; }
};
//! Selected weather scenario
struct TSelectedWeatherScenario : public BlackMisc::TSettingTrait<BlackMisc::Weather::CWeatherScenario>
{
//! \copydoc BlackMisc::TSettingTrait::key
static const char *key() { return "simulator/selectedweatherscenario"; }
//! \copydoc BlackMisc::TSettingTrait::defaultValue
static const BlackMisc::Weather::CWeatherScenario &defaultValue()
{
static const BlackMisc::Weather::CWeatherScenario scenario {};
return scenario;
}
};
} // ns
} // ns
} // ns
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSimulatorSettings)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::Settings::CSimulatorSettings>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::Settings::CSimulatorSettings>)
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSimulatorMessagesSettings)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::Settings::CSimulatorMessagesSettings>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::Settings::CSimulatorMessagesSettings>)
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSimulatorMessagesSettings::TextMessageTypeFlag)
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSimulatorMessagesSettings::TextMessageType)
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::Settings::CSimulatorMessagesSettings::TextMessageType)
#endif // guard

View File

@@ -22,17 +22,17 @@
#include "blackmisc/simulation/interpolationhints.h"
#include "blackmisc/simulation/interpolationrenderingsetup.h"
#include "blackmisc/simulation/matchingstatistics.h"
#include "blackmisc/simulation/modelsettings.h"
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/simulation/simulatedaircraftlist.h"
#include "blackmisc/simulation/simulatorinfolist.h"
#include "blackmisc/simulation/simulatorinternals.h"
#include "blackmisc/simulation/simulatorplugininfo.h"
#include "blackmisc/simulation/simulatorplugininfolist.h"
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/fscommon/aircraftcfgentrieslist.h"
#include "blackmisc/simulation/fscommon/vpilotmodelruleset.h"
#include "blackmisc/simulation/fsx/simconnectutilities.h"
#include "blackmisc/simulation/settings/modelsettings.h"
#include "blackmisc/simulation/settings/simulatorsettings.h"
#include "blackmisc/simulation/settings/swiftpluginsettings.h"
#endif // guard

View File

@@ -1,447 +0,0 @@
/* Copyright (C) 2016
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "simulatorsettings.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;
namespace BlackMisc
{
namespace Simulation
{
CSimulatorSettings::CSimulatorSettings()
{ }
void CSimulatorSettings::setSimulatorDirectory(const QString &simulatorDirectory)
{
this->m_simulatorDirectory = simulatorDirectory.trimmed();
}
const QString &CSimulatorSettings::getSimulatorDirectory() const
{
return this->m_simulatorDirectory;
}
void CSimulatorSettings::setModelDirectories(const QStringList &modelDirectories)
{
this->m_modelDirectories = modelDirectories;
}
void CSimulatorSettings::setModelDirectory(const QString &modelDirectory)
{
this->m_modelDirectories = QStringList({ modelDirectory });
}
const QStringList &CSimulatorSettings::getModelDirectories() const
{
return this->m_modelDirectories;
}
void CSimulatorSettings::setModelExcludeDirectories(const QStringList &excludeDirectories)
{
this->m_excludeDirectoryPatterns = excludeDirectories;
}
const QStringList &CSimulatorSettings::getModelExcludeDirectoryPatterns() const
{
return m_excludeDirectoryPatterns;
}
void CSimulatorSettings::resetPaths()
{
this->m_excludeDirectoryPatterns.clear();
this->m_modelDirectories.clear();
this->m_simulatorDirectory.clear();
}
QString CSimulatorSettings::convertToQString(bool i18n) const
{
return convertToQString(", ", i18n);
}
QString CSimulatorSettings::convertToQString(const QString &separator, bool i18n) const
{
Q_UNUSED(i18n);
QString s("model directories: ");
s.append(this->m_modelDirectories.join(','));
s.append(separator);
s.append("exclude directories: ");
s.append(this->m_excludeDirectoryPatterns.join(','));
return s;
}
CVariant CSimulatorSettings::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexSimulatorDirectory:
return CVariant::fromValue(this->m_simulatorDirectory);
case IndexModelDirectory:
return CVariant::fromValue(this->m_modelDirectories);
case IndexModelExcludeDirectoryPatterns:
return CVariant::fromValue(this->m_excludeDirectoryPatterns);
default:
return CValueObject::propertyByIndex(index);
}
}
void CSimulatorSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CSimulatorSettings>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexSimulatorDirectory:
this->setSimulatorDirectory(variant.toQString());
break;
case IndexModelDirectory:
this->setSimulatorDirectory(variant.toQString());
break;
case IndexModelExcludeDirectoryPatterns:
this->m_excludeDirectoryPatterns = variant.value<QStringList>();
break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;
}
}
CMultiSimulatorSettings::CMultiSimulatorSettings(QObject *parent) : QObject(parent)
{
// void
}
CSimulatorSettings CMultiSimulatorSettings::getSettings(const CSimulatorInfo &simulator) const
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.get();
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.get();
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.get();
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.get();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return CSimulatorSettings();
}
CStatusMessage CMultiSimulatorSettings::setSettings(const CSimulatorSettings &settings, const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.set(settings);
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.set(settings);
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.set(settings);
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.set(settings);
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
}
CStatusMessage CMultiSimulatorSettings::setAndSaveSettings(const CSimulatorSettings &settings, const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.setAndSave(settings);
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.setAndSave(settings);
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.setAndSave(settings);
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.setAndSave(settings);
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
}
CStatusMessage CMultiSimulatorSettings::saveSettings(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.save();
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.save();
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.save();
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.save();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
}
QString CMultiSimulatorSettings::getSimulatorDirectoryOrDefault(const CSimulatorInfo &simulator) const
{
const CSimulatorSettings s = this->getSettings(simulator);
if (s.getSimulatorDirectory().isEmpty())
{
return this->getDefaultSimulatorDirectory(simulator);
}
return s.getSimulatorDirectory();
}
QString CMultiSimulatorSettings::getDefaultSimulatorDirectory(const CSimulatorInfo &simulator) const
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9Dir();
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxDir();
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dDir();
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneRootDir(); //! check XP
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return "";
}
QStringList CMultiSimulatorSettings::getModelDirectoriesOrDefault(const CSimulatorInfo &simulator) const
{
const CSimulatorSettings s = this->getSettings(simulator);
if (s.getModelDirectories().isEmpty())
{
return this->getDefaultModelDirectories(simulator);
}
return s.getModelDirectories();
}
QString CMultiSimulatorSettings::getFirstModelDirectoryOrDefault(const CSimulatorInfo &simulator) const
{
const QStringList models(getModelDirectoriesOrDefault(simulator));
if (models.isEmpty()) { return ""; }
return models.first();
}
QStringList CMultiSimulatorSettings::getDefaultModelDirectories(const CSimulatorInfo &simulator) const
{
static const QStringList e;
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9AircraftDir().isEmpty() ? e : QStringList({ CFsCommonUtil::fs9AircraftDir() });
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxSimObjectsDir().isEmpty() ? e : QStringList({ CFsCommonUtil::fsxSimObjectsDir() });
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dSimObjectsDir().isEmpty() ? e : QStringList({ CFsCommonUtil::p3dSimObjectsDir()});
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneModelDirectories();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return QStringList();
}
QStringList CMultiSimulatorSettings::getModelExcludeDirectoryPatternsOrDefault(const CSimulatorInfo &simulator) const
{
const CSimulatorSettings s = this->getSettings(simulator);
QStringList exclude(s.getModelExcludeDirectoryPatterns());
if (!exclude.isEmpty()) { return exclude; }
exclude = this->getDefaultModelExcludeDirectoryPatterns(simulator);
return exclude;
}
QStringList CMultiSimulatorSettings::getDefaultModelExcludeDirectoryPatterns(const CSimulatorInfo &simulator) const
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9AircraftObjectsExcludeDirectoryPatterns();
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxSimObjectsExcludeDirectoryPatterns();
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dSimObjectsExcludeDirectoryPatterns();
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneModelExcludeDirectoryPatterns();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
break;
}
return QStringList();
}
void CMultiSimulatorSettings::resetToDefaults(const CSimulatorInfo &simulator)
{
CSimulatorSettings s = this->getSettings(simulator);
s.resetPaths();
this->setAndSaveSettings(s, simulator);
}
CSimulatorMessagesSettings::CSimulatorMessagesSettings()
{
// void
}
void CSimulatorMessagesSettings::setTechnicalLogSeverity(CStatusMessage::StatusSeverity severity)
{
this->m_technicalLogLevel = static_cast<int>(severity);
}
void CSimulatorMessagesSettings::disableTechnicalMessages()
{
this->m_technicalLogLevel = -1;
}
bool CSimulatorMessagesSettings::isRelayedErrorsMessages() const
{
if (this->m_technicalLogLevel < 0) { return false; }
return (this->m_technicalLogLevel <= CStatusMessage::SeverityError);
}
bool CSimulatorMessagesSettings::isRelayedWarningMessages() const
{
if (this->m_technicalLogLevel < 0) { return false; }
return (this->m_technicalLogLevel <= CStatusMessage::SeverityWarning);
}
bool CSimulatorMessagesSettings::isRelayedInfoMessages() const
{
if (this->m_technicalLogLevel < 0) { return false; }
return (this->m_technicalLogLevel <= CStatusMessage::SeverityInfo);
}
bool CSimulatorMessagesSettings::isRelayedTechnicalMessages() const
{
return (this->m_technicalLogLevel >= 0);
}
void CSimulatorMessagesSettings::setRelayedTextMessages(CSimulatorMessagesSettings::TextMessageType messageType)
{
this->m_messageType = static_cast<int>(messageType);
}
bool CSimulatorMessagesSettings::isRelayedSupervisorTextMessages() const
{
return this->getRelayedTextMessageTypes().testFlag(TextMessageSupervisor);
}
bool CSimulatorMessagesSettings::isRelayedPrivateTextMessages() const
{
return this->getRelayedTextMessageTypes().testFlag(TextMessagePrivate);
}
bool CSimulatorMessagesSettings::isRelayedUnicomTextMessages() const
{
return this->getRelayedTextMessageTypes().testFlag(TextMessagesUnicom);
}
bool CSimulatorMessagesSettings::isRelayedCom1TextMessages() const
{
return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom1);
}
bool CSimulatorMessagesSettings::isRelayedCom2TextMessages() const
{
return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom2);
}
bool CSimulatorMessagesSettings::relayThisStatusMessage(const CStatusMessage &message) const
{
if (message.isEmpty()) { return false; }
if (!this->isGloballyEnabled()) { return false; }
if (!this->isRelayedTechnicalMessages()) { return false; }
int s = static_cast<int>(message.getSeverity());
return (s >= this->m_technicalLogLevel);
}
bool CSimulatorMessagesSettings::relayThisTextMessage(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<TextMessageType>(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;
}
CSimulatorMessagesSettings::TextMessageType CSimulatorMessagesSettings::getRelayedTextMessageTypes() const
{
return static_cast<CSimulatorMessagesSettings::TextMessageType>(this->m_messageType);
}
QString CSimulatorMessagesSettings::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<CStatusMessage::StatusSeverity>(this->m_technicalLogLevel));
}
return s.arg(boolToOnOff(this->m_globallyEnabled)).arg(this->m_messageType).arg(severity);
}
CVariant CSimulatorMessagesSettings::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
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 CSimulatorMessagesSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CSimulatorMessagesSettings>(); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexTechnicalLogSeverity:
this->setTechnicalLogSeverity(static_cast<CStatusMessage::StatusSeverity>(variant.toInt()));
break;
case IndexTextMessageRelay:
this->setRelayedTextMessages(static_cast<CSimulatorMessagesSettings::TextMessageType>(variant.toInt()));
break;
case IndexGloballyEnabled:
this->setGloballyEnabled(variant.toBool());
break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;
}
}
} // ns
} // ns

View File

@@ -1,313 +0,0 @@
/* Copyright (C) 2016
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_SIMULATION_SIMULATORSETTINGS_H
#define BLACKMISC_SIMULATION_SIMULATORSETTINGS_H
#include "blackmisc/simulation/simulatorinfo.h"
#include "blackmisc/network/textmessage.h"
#include "blackmisc/weather/weatherscenario.h"
#include "blackmisc/settingscache.h"
#include "blackmisc/statusmessage.h"
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/propertyindex.h"
#include <QStringList>
#include <QObject>
namespace BlackMisc
{
namespace Simulation
{
class CSimulatedAircraft;
//! Settings for simulator
//! Driver independent part also used in loaders (such as directories)
class BLACKMISC_EXPORT CSimulatorSettings :
public BlackMisc::CValueObject<CSimulatorSettings>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexSimulatorDirectory = BlackMisc::CPropertyIndex::GlobalIndexCSimulatorSettings,
IndexModelDirectory,
IndexModelExcludeDirectoryPatterns
};
//! Default constructor
CSimulatorSettings();
//! Set simulator directory
void setSimulatorDirectory(const QString &simulatorDirectory);
//! Simulator directory
const QString &getSimulatorDirectory() const;
//! Set model directories
void setModelDirectories(const QStringList &modelDirectories);
//! Set single model directory
void setModelDirectory(const QString &modelDirectory);
//! Model directory
const QStringList &getModelDirectories() const;
//! Set exclude directories
void setModelExcludeDirectories(const QStringList &excludeDirectories);
//! Margins for given dock widget
const QStringList &getModelExcludeDirectoryPatterns() const;
//! Reset the paths
void resetPaths();
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
//! To string
QString convertToQString(const QString &separator, 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:
QString m_simulatorDirectory; //! Simulator directory
QStringList m_modelDirectories; //!< Model directory
QStringList m_excludeDirectoryPatterns; //!< Exclude model directory
BLACK_METACLASS(
CSimulatorSettings,
BLACK_METAMEMBER(simulatorDirectory),
BLACK_METAMEMBER(modelDirectories),
BLACK_METAMEMBER(excludeDirectoryPatterns)
);
};
//! Trait for simulator settings
struct TSimulatorFsx : public BlackMisc::TSettingTrait<CSimulatorSettings>
{
//! Key in data cache
static const char *key() { return "settingssimulatorfsx"; }
};
//! Trait for simulator settings
struct TSimulatorFs9 : public BlackMisc::TSettingTrait<CSimulatorSettings>
{
//! Key in data cache
static const char *key() { return "settingssimulatorfs9"; }
};
//! Trait for simulator settings
struct TSimulatorP3D : public BlackMisc::TSettingTrait<CSimulatorSettings>
{
//! Key in data cache
static const char *key() { return "settingssimulatorp3d"; }
};
//! Trait for simulator settings
struct TSimulatorXP : public BlackMisc::TSettingTrait<CSimulatorSettings>
{
//! Key in data cache
static const char *key() { return "settingssimulatorxplane"; }
};
//! Bundle of settings for all simulators
class BLACKMISC_EXPORT CMultiSimulatorSettings : public QObject
{
Q_OBJECT
public:
//! Construtor
CMultiSimulatorSettings(QObject *parent = nullptr);
//! Settings per simulator
CSimulatorSettings getSettings(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Set settings per simulator
BlackMisc::CStatusMessage setSettings(const BlackMisc::Simulation::CSimulatorSettings &settings, const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Set settings per simulator
BlackMisc::CStatusMessage setAndSaveSettings(const BlackMisc::Simulation::CSimulatorSettings &settings, const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Set settings per simulator
BlackMisc::CStatusMessage saveSettings(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Simulator directory or default model path per simulator
QString getSimulatorDirectoryOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Default simulator path per simulator
QString getDefaultSimulatorDirectory(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Model directory or default model path per simulator
QStringList getModelDirectoriesOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! First model directoy
QString getFirstModelDirectoryOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Default model path per simulator
QStringList getDefaultModelDirectories(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Model exclude paths per simulator
QStringList getModelExcludeDirectoryPatternsOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Default model exclude paths per simulator
QStringList getDefaultModelExcludeDirectoryPatterns(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Reset to defaults
void resetToDefaults(const BlackMisc::Simulation::CSimulatorInfo &simulator);
private:
BlackMisc::CSetting<BlackMisc::Simulation::TSimulatorFsx> m_simSettingsFsx {this}; //!< FSX cache
BlackMisc::CSetting<BlackMisc::Simulation::TSimulatorFs9> m_simSettingsFs9 {this}; //!< FS9 cache
BlackMisc::CSetting<BlackMisc::Simulation::TSimulatorP3D> m_simSettingsP3D {this}; //!< P3D cache
BlackMisc::CSetting<BlackMisc::Simulation::TSimulatorXP> m_simSettingsXP {this}; //!< XP cache
};
//! Settings regarding message handling.
//! Driver independent part, related to network
class BLACKMISC_EXPORT CSimulatorMessagesSettings :
public BlackMisc::CValueObject<CSimulatorMessagesSettings>
{
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
CSimulatorMessagesSettings();
//! 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::CSimulatorMessagesSettings::TextMessageType messageType);
//! Relay supervisor messages
bool isRelayedSupervisorTextMessages() const;
//! Relay private messages
bool isRelayedPrivateTextMessages() const;
//! Relay UNICOM messages
bool isRelayedUnicomTextMessages() const;
//! Relay COM1 text message
bool isRelayedCom1TextMessages() const;
//! Relay COM2 text message
bool isRelayedCom2TextMessages() const;
//! Relay given text message
bool relayThisTextMessage(const BlackMisc::Network::CTextMessage &msg, const BlackMisc::Simulation::CSimulatedAircraft &aircraft) const;
//! Relay this particular message
bool relayThisStatusMessage(const BlackMisc::CStatusMessage &message) const;
//! Relayed text messages
CSimulatorMessagesSettings::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<int>(TextMessagePrivate | TextMessageSupervisor);
bool m_globallyEnabled = true; //!< messsage relay enabled to simulator
BLACK_METACLASS(
CSimulatorMessagesSettings,
BLACK_METAMEMBER(technicalLogLevel),
BLACK_METAMEMBER(messageType)
);
};
//! Trait for simulator message settings
struct TSimulatorMessages : public BlackMisc::TSettingTrait<CSimulatorMessagesSettings>
{
//! Key in data cache
static const char *key() { return "settingssimulatormessages"; }
};
//! Selected weather scenario
struct TSelectedWeatherScenario : public BlackMisc::TSettingTrait<BlackMisc::Weather::CWeatherScenario>
{
//! \copydoc BlackMisc::TSettingTrait::key
static const char *key() { return "simulator/selectedweatherscenario"; }
//! \copydoc BlackMisc::TSettingTrait::defaultValue
static const BlackMisc::Weather::CWeatherScenario &defaultValue()
{
static const BlackMisc::Weather::CWeatherScenario scenario {};
return scenario;
}
};
} // ns
} // ns
Q_DECLARE_METATYPE(BlackMisc::Simulation::CSimulatorSettings)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::CSimulatorSettings>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::CSimulatorSettings>)
Q_DECLARE_METATYPE(BlackMisc::Simulation::CSimulatorMessagesSettings)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::CSimulatorMessagesSettings>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::CSimulatorMessagesSettings>)
Q_DECLARE_METATYPE(BlackMisc::Simulation::CSimulatorMessagesSettings::TextMessageTypeFlag)
Q_DECLARE_METATYPE(BlackMisc::Simulation::CSimulatorMessagesSettings::TextMessageType)
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::CSimulatorMessagesSettings::TextMessageType)
#endif // guard

View File

@@ -16,7 +16,7 @@
#include "fs9client.h"
#include "lobbyclient.h"
#include "../fscommon/simulatorfscommon.h"
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/settings/simulatorsettings.h"
#include "blackcore/simulator.h"
#include "blackmisc/simulation/interpolator.h"
#include "blackmisc/simulation/simulatedaircraft.h"

View File

@@ -18,7 +18,7 @@
#include "blackcore/simulator.h"
#include "blackmisc/simulation/interpolatorlinear.h"
#include "blackmisc/simulation/simulatorplugininfo.h"
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/settings/simulatorsettings.h"
#include "blackmisc/simulation/aircraftmodel.h"
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/aviation/airportlist.h"

View File

@@ -22,7 +22,7 @@
#include "blackmisc/pq/units.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackmisc/simulation/data/modelcaches.h"
#include "blackmisc/simulation/simulatorsettings.h"
#include "blackmisc/simulation/settings/simulatorsettings.h"
#include "blackmisc/weather/weathergrid.h"
#include "blackmisc/settingscache.h"
#include "blackmisc/statusmessage.h"