Initial impact based warning palette settings

TODO:
- Update settings to use line component data
- Add interface to data
This commit is contained in:
Dan Paulat 2024-09-16 22:02:41 -05:00
parent 7101cdf183
commit 8fc392681a
2 changed files with 134 additions and 46 deletions

View file

@ -2,6 +2,7 @@
#include <scwx/qt/settings/settings_variable.hpp> #include <scwx/qt/settings/settings_variable.hpp>
#include <scwx/qt/util/color.hpp> #include <scwx/qt/util/color.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/gil.hpp> #include <boost/gil.hpp>
#include <fmt/format.h> #include <fmt/format.h>
#include <re2/re2.h> #include <re2/re2.h>
@ -76,66 +77,59 @@ static const awips::Phenomenon kDefaultPhenomenon_ {awips::Phenomenon::Marine};
class PaletteSettings::Impl class PaletteSettings::Impl
{ {
public: public:
explicit Impl() struct AlertData
{ {
palette_.reserve(kPaletteKeys_.size()); AlertData(awips::Phenomenon phenomenon) : phenomenon_ {phenomenon}
for (const auto& name : kPaletteKeys_)
{ {
const std::string& defaultValue = kDefaultPalettes_.at(name); auto& info = awips::ibw::GetImpactBasedWarningInfo(phenomenon);
for (auto& threatCategory : info.threatCategories_)
auto result = {
palette_.emplace(name, SettingsVariable<std::string> {name}); std::string threatCategoryName =
awips::ibw::GetThreatCategoryName(threatCategory);
SettingsVariable<std::string>& settingsVariable = result.first->second; boost::algorithm::to_lower(threatCategoryName);
threatCategoryMap_.emplace(threatCategory, threatCategoryName);
settingsVariable.SetDefault(defaultValue); }
variables_.push_back(&settingsVariable);
};
activeAlertColor_.reserve(kAlertColors_.size());
inactiveAlertColor_.reserve(kAlertColors_.size());
for (auto& alert : kAlertColors_)
{
std::string phenomenonCode = awips::GetPhenomenonCode(alert.first);
std::string activeName = fmt::format("{}-active", phenomenonCode);
std::string inactiveName = fmt::format("{}-inactive", phenomenonCode);
auto activeResult = activeAlertColor_.emplace(
alert.first, SettingsVariable<std::string> {activeName});
auto inactiveResult = inactiveAlertColor_.emplace(
alert.first, SettingsVariable<std::string> {inactiveName});
SettingsVariable<std::string>& activeVariable =
activeResult.first->second;
SettingsVariable<std::string>& inactiveVariable =
inactiveResult.first->second;
activeVariable.SetDefault(
util::color::ToArgbString(alert.second.first));
inactiveVariable.SetDefault(
util::color::ToArgbString(alert.second.second));
activeVariable.SetValidator(&ValidateColor);
inactiveVariable.SetValidator(&ValidateColor);
variables_.push_back(&activeVariable);
variables_.push_back(&inactiveVariable);
} }
void RegisterVariables(SettingsCategory& settings);
awips::Phenomenon phenomenon_;
std::map<awips::ibw::ThreatCategory, SettingsVariable<std::string>>
threatCategoryMap_ {};
SettingsVariable<std::string> observed_ {"observed"};
SettingsVariable<std::string> tornadoPossible_ {"tornado_possible"};
SettingsVariable<std::string> inactive_ {"inactive"};
};
explicit Impl(PaletteSettings* self) : self_ {self}
{
InitializeColorTables();
InitializeLegacyAlerts();
InitializeAlerts();
} }
~Impl() {} ~Impl() {}
void InitializeColorTables();
void InitializeLegacyAlerts();
void InitializeAlerts();
static bool ValidateColor(const std::string& value); static bool ValidateColor(const std::string& value);
PaletteSettings* self_;
std::unordered_map<std::string, SettingsVariable<std::string>> palette_ {}; std::unordered_map<std::string, SettingsVariable<std::string>> palette_ {};
std::unordered_map<awips::Phenomenon, SettingsVariable<std::string>> std::unordered_map<awips::Phenomenon, SettingsVariable<std::string>>
activeAlertColor_ {}; activeAlertColor_ {};
std::unordered_map<awips::Phenomenon, SettingsVariable<std::string>> std::unordered_map<awips::Phenomenon, SettingsVariable<std::string>>
inactiveAlertColor_ {}; inactiveAlertColor_ {};
std::vector<SettingsVariableBase*> variables_ {}; std::vector<SettingsVariableBase*> variables_ {};
std::unordered_map<awips::Phenomenon, AlertData> alertDataMap_ {};
std::vector<SettingsCategory> alertSettings_ {};
}; };
bool PaletteSettings::Impl::ValidateColor(const std::string& value) bool PaletteSettings::Impl::ValidateColor(const std::string& value)
@ -145,7 +139,7 @@ bool PaletteSettings::Impl::ValidateColor(const std::string& value)
} }
PaletteSettings::PaletteSettings() : PaletteSettings::PaletteSettings() :
SettingsCategory("palette"), p(std::make_unique<Impl>()) SettingsCategory("palette"), p(std::make_unique<Impl>(this))
{ {
RegisterVariables(p->variables_); RegisterVariables(p->variables_);
SetDefaults(); SetDefaults();
@ -158,6 +152,99 @@ PaletteSettings::PaletteSettings(PaletteSettings&&) noexcept = default;
PaletteSettings& PaletteSettings&
PaletteSettings::operator=(PaletteSettings&&) noexcept = default; PaletteSettings::operator=(PaletteSettings&&) noexcept = default;
void PaletteSettings::Impl::InitializeColorTables()
{
palette_.reserve(kPaletteKeys_.size());
for (const auto& name : kPaletteKeys_)
{
const std::string& defaultValue = kDefaultPalettes_.at(name);
auto result =
palette_.emplace(name, SettingsVariable<std::string> {name});
SettingsVariable<std::string>& settingsVariable = result.first->second;
settingsVariable.SetDefault(defaultValue);
variables_.push_back(&settingsVariable);
};
}
void PaletteSettings::Impl::InitializeLegacyAlerts()
{
activeAlertColor_.reserve(kAlertColors_.size());
inactiveAlertColor_.reserve(kAlertColors_.size());
for (auto& alert : kAlertColors_)
{
std::string phenomenonCode = awips::GetPhenomenonCode(alert.first);
std::string activeName = fmt::format("{}-active", phenomenonCode);
std::string inactiveName = fmt::format("{}-inactive", phenomenonCode);
auto activeResult = activeAlertColor_.emplace(
alert.first, SettingsVariable<std::string> {activeName});
auto inactiveResult = inactiveAlertColor_.emplace(
alert.first, SettingsVariable<std::string> {inactiveName});
SettingsVariable<std::string>& activeVariable =
activeResult.first->second;
SettingsVariable<std::string>& inactiveVariable =
inactiveResult.first->second;
activeVariable.SetDefault(util::color::ToArgbString(alert.second.first));
inactiveVariable.SetDefault(
util::color::ToArgbString(alert.second.second));
activeVariable.SetValidator(&ValidateColor);
inactiveVariable.SetValidator(&ValidateColor);
variables_.push_back(&activeVariable);
variables_.push_back(&inactiveVariable);
}
}
void PaletteSettings::Impl::InitializeAlerts()
{
for (auto phenomenon : PaletteSettings::alert_phenomena())
{
auto pair = alertDataMap_.emplace(
std::make_pair(phenomenon, AlertData {phenomenon}));
auto& alertData = pair.first->second;
// Variable registration
auto& settings = alertSettings_.emplace_back(
SettingsCategory {awips::GetPhenomenonCode(phenomenon)});
alertData.RegisterVariables(settings);
}
self_->RegisterSubcategoryArray("alerts", alertSettings_);
}
void PaletteSettings::Impl::AlertData::RegisterVariables(
SettingsCategory& settings)
{
auto& info = awips::ibw::GetImpactBasedWarningInfo(phenomenon_);
for (auto& threatCategory : threatCategoryMap_)
{
settings.RegisterVariables({&threatCategory.second});
}
if (info.hasObservedTag_)
{
settings.RegisterVariables({&observed_});
}
if (info.hasTornadoPossibleTag_)
{
settings.RegisterVariables({&tornadoPossible_});
}
settings.RegisterVariables({&inactive_});
}
SettingsVariable<std::string>& SettingsVariable<std::string>&
PaletteSettings::palette(const std::string& name) const PaletteSettings::palette(const std::string& name) const
{ {

View file

@ -2,6 +2,7 @@
#include <scwx/qt/settings/settings_category.hpp> #include <scwx/qt/settings/settings_category.hpp>
#include <scwx/qt/settings/settings_variable.hpp> #include <scwx/qt/settings/settings_variable.hpp>
#include <scwx/awips/impact_based_warnings.hpp>
#include <scwx/awips/phenomenon.hpp> #include <scwx/awips/phenomenon.hpp>
#include <memory> #include <memory>