Skip to content

Commit

Permalink
Merge pull request #386 from AdenKoperczak/color_palette_fallback_war…
Browse files Browse the repository at this point in the history
…ning

Color palette fallback
  • Loading branch information
dpaulat authored Mar 2, 2025
2 parents b4f888a + dc3258d commit d5dadb5
Showing 1 changed file with 42 additions and 27 deletions.
69 changes: 42 additions & 27 deletions scwx-qt/source/scwx/qt/map/map_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1865,34 +1865,49 @@ void MapWidgetImpl::RadarProductManagerDisconnect()
void MapWidgetImpl::InitializeNewRadarProductView(
const std::string& colorPalette)
{
boost::asio::post(threadPool_,
[=, this]()
{
try
{
auto radarProductView =
context_->radar_product_view();

std::string colorTableFile =
settings::PaletteSettings::Instance()
.palette(colorPalette)
.GetValue();
if (!colorTableFile.empty())
{
std::unique_ptr<std::istream> colorTableStream =
util::OpenFile(colorTableFile);
std::shared_ptr<common::ColorTable> colorTable =
common::ColorTable::Load(*colorTableStream);
radarProductView->LoadColorTable(colorTable);
}
boost::asio::post(
threadPool_,
[colorPalette, this]()
{
try
{
auto radarProductView = context_->radar_product_view();

radarProductView->Initialize();
}
catch (const std::exception& ex)
{
logger_->error(ex.what());
}
});
auto& paletteSetting =
settings::PaletteSettings::Instance().palette(colorPalette);

std::string colorTableFile = paletteSetting.GetValue();
if (colorTableFile.empty())
{
colorTableFile = paletteSetting.GetDefault();
}

std::unique_ptr<std::istream> colorTableStream =
util::OpenFile(colorTableFile);
if (colorTableStream->fail())
{
logger_->warn("Could not open color table {}", colorTableFile);
colorTableStream = util::OpenFile(paletteSetting.GetDefault());
}

std::shared_ptr<common::ColorTable> colorTable =
common::ColorTable::Load(*colorTableStream);
if (!colorTable->IsValid())
{
logger_->warn("Could not load color table {}", colorTableFile);
colorTableStream = util::OpenFile(paletteSetting.GetDefault());
colorTable = common::ColorTable::Load(*colorTableStream);
}

radarProductView->LoadColorTable(colorTable);

radarProductView->Initialize();
}
catch (const std::exception& ex)
{
logger_->error(ex.what());
}
});

if (map_ != nullptr)
{
Expand Down

0 comments on commit d5dadb5

Please sign in to comment.