mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:40:04 +00:00 
			
		
		
		
	Initial impact based warning palette settings
TODO: - Update settings to use line component data - Add interface to data
This commit is contained in:
		
							parent
							
								
									7101cdf183
								
							
						
					
					
						commit
						8fc392681a
					
				
					 2 changed files with 134 additions and 46 deletions
				
			
		|  | @ -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,7 +77,82 @@ static const awips::Phenomenon kDefaultPhenomenon_ {awips::Phenomenon::Marine}; | ||||||
| class PaletteSettings::Impl | class PaletteSettings::Impl | ||||||
| { | { | ||||||
| public: | 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()); |    palette_.reserve(kPaletteKeys_.size()); | ||||||
| 
 | 
 | ||||||
|  | @ -93,7 +169,10 @@ public: | ||||||
| 
 | 
 | ||||||
|       variables_.push_back(&settingsVariable); |       variables_.push_back(&settingsVariable); | ||||||
|    }; |    }; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
|  | void PaletteSettings::Impl::InitializeLegacyAlerts() | ||||||
|  | { | ||||||
|    activeAlertColor_.reserve(kAlertColors_.size()); |    activeAlertColor_.reserve(kAlertColors_.size()); | ||||||
|    inactiveAlertColor_.reserve(kAlertColors_.size()); |    inactiveAlertColor_.reserve(kAlertColors_.size()); | ||||||
| 
 | 
 | ||||||
|  | @ -113,8 +192,7 @@ public: | ||||||
|       SettingsVariable<std::string>& inactiveVariable = |       SettingsVariable<std::string>& inactiveVariable = | ||||||
|          inactiveResult.first->second; |          inactiveResult.first->second; | ||||||
| 
 | 
 | ||||||
|          activeVariable.SetDefault( |       activeVariable.SetDefault(util::color::ToArgbString(alert.second.first)); | ||||||
|             util::color::ToArgbString(alert.second.first)); |  | ||||||
|       inactiveVariable.SetDefault( |       inactiveVariable.SetDefault( | ||||||
|          util::color::ToArgbString(alert.second.second)); |          util::color::ToArgbString(alert.second.second)); | ||||||
| 
 | 
 | ||||||
|  | @ -126,37 +204,46 @@ public: | ||||||
|    } |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|    ~Impl() {} | void PaletteSettings::Impl::InitializeAlerts() | ||||||
| 
 |  | ||||||
|    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) |  | ||||||
| { | { | ||||||
|    static constexpr LazyRE2 re = {"#[0-9A-Fa-f]{8}"}; |    for (auto phenomenon : PaletteSettings::alert_phenomena()) | ||||||
|    return RE2::FullMatch(value, *re); |    { | ||||||
|  |       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() : |    self_->RegisterSubcategoryArray("alerts", alertSettings_); | ||||||
|     SettingsCategory("palette"), p(std::make_unique<Impl>()) |  | ||||||
| { |  | ||||||
|    RegisterVariables(p->variables_); |  | ||||||
|    SetDefaults(); |  | ||||||
| 
 |  | ||||||
|    p->variables_.clear(); |  | ||||||
| } | } | ||||||
| PaletteSettings::~PaletteSettings() = default; |  | ||||||
| 
 | 
 | ||||||
| PaletteSettings::PaletteSettings(PaletteSettings&&) noexcept = default; | void PaletteSettings::Impl::AlertData::RegisterVariables( | ||||||
| PaletteSettings& |    SettingsCategory& settings) | ||||||
| PaletteSettings::operator=(PaletteSettings&&) noexcept = default; | { | ||||||
|  |    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 | ||||||
|  |  | ||||||
|  | @ -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> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat