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/util/color.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/gil.hpp>
#include <fmt/format.h>
#include <re2/re2.h>
@ -76,7 +77,82 @@ static const awips::Phenomenon kDefaultPhenomenon_ {awips::Phenomenon::Marine};
class PaletteSettings::Impl
{
public:
explicit Impl()
struct AlertData
{
AlertData(awips::Phenomenon phenomenon) : phenomenon_ {phenomenon}
{
auto& info = awips::ibw::GetImpactBasedWarningInfo(phenomenon);
for (auto& threatCategory : info.threatCategories_)
{
std::string threatCategoryName =
awips::ibw::GetThreatCategoryName(threatCategory);
boost::algorithm::to_lower(threatCategoryName);
threatCategoryMap_.emplace(threatCategory, threatCategoryName);
}
}
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() {}
void InitializeColorTables();
void InitializeLegacyAlerts();
void InitializeAlerts();
static bool ValidateColor(const std::string& value);
PaletteSettings* self_;
std::unordered_map<std::string, SettingsVariable<std::string>> palette_ {};
std::unordered_map<awips::Phenomenon, SettingsVariable<std::string>>
activeAlertColor_ {};
std::unordered_map<awips::Phenomenon, SettingsVariable<std::string>>
inactiveAlertColor_ {};
std::vector<SettingsVariableBase*> variables_ {};
std::unordered_map<awips::Phenomenon, AlertData> alertDataMap_ {};
std::vector<SettingsCategory> alertSettings_ {};
};
bool PaletteSettings::Impl::ValidateColor(const std::string& value)
{
static constexpr LazyRE2 re = {"#[0-9A-Fa-f]{8}"};
return RE2::FullMatch(value, *re);
}
PaletteSettings::PaletteSettings() :
SettingsCategory("palette"), p(std::make_unique<Impl>(this))
{
RegisterVariables(p->variables_);
SetDefaults();
p->variables_.clear();
}
PaletteSettings::~PaletteSettings() = default;
PaletteSettings::PaletteSettings(PaletteSettings&&) noexcept = default;
PaletteSettings&
PaletteSettings::operator=(PaletteSettings&&) noexcept = default;
void PaletteSettings::Impl::InitializeColorTables()
{
palette_.reserve(kPaletteKeys_.size());
@ -93,7 +169,10 @@ public:
variables_.push_back(&settingsVariable);
};
}
void PaletteSettings::Impl::InitializeLegacyAlerts()
{
activeAlertColor_.reserve(kAlertColors_.size());
inactiveAlertColor_.reserve(kAlertColors_.size());
@ -113,8 +192,7 @@ public:
SettingsVariable<std::string>& inactiveVariable =
inactiveResult.first->second;
activeVariable.SetDefault(
util::color::ToArgbString(alert.second.first));
activeVariable.SetDefault(util::color::ToArgbString(alert.second.first));
inactiveVariable.SetDefault(
util::color::ToArgbString(alert.second.second));
@ -126,37 +204,46 @@ public:
}
}
~Impl() {}
static bool ValidateColor(const std::string& value);
std::unordered_map<std::string, SettingsVariable<std::string>> palette_ {};
std::unordered_map<awips::Phenomenon, SettingsVariable<std::string>>
activeAlertColor_ {};
std::unordered_map<awips::Phenomenon, SettingsVariable<std::string>>
inactiveAlertColor_ {};
std::vector<SettingsVariableBase*> variables_ {};
};
bool PaletteSettings::Impl::ValidateColor(const std::string& value)
void PaletteSettings::Impl::InitializeAlerts()
{
static constexpr LazyRE2 re = {"#[0-9A-Fa-f]{8}"};
return RE2::FullMatch(value, *re);
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);
}
PaletteSettings::PaletteSettings() :
SettingsCategory("palette"), p(std::make_unique<Impl>())
{
RegisterVariables(p->variables_);
SetDefaults();
p->variables_.clear();
self_->RegisterSubcategoryArray("alerts", alertSettings_);
}
PaletteSettings::~PaletteSettings() = default;
PaletteSettings::PaletteSettings(PaletteSettings&&) noexcept = default;
PaletteSettings&
PaletteSettings::operator=(PaletteSettings&&) noexcept = default;
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>&
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_variable.hpp>
#include <scwx/awips/impact_based_warnings.hpp>
#include <scwx/awips/phenomenon.hpp>
#include <memory>