mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 20:20:06 +00:00
Separate placefiles into their own layers
- Placefile rename is partially - Texture repack might be broken
This commit is contained in:
parent
0be94c4de3
commit
117a473689
5 changed files with 155 additions and 17 deletions
|
|
@ -109,7 +109,7 @@ bool PlacefileManager::placefile_thresholded(const std::string& name)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const gr::Placefile>
|
std::shared_ptr<gr::Placefile>
|
||||||
PlacefileManager::placefile(const std::string& name)
|
PlacefileManager::placefile(const std::string& name)
|
||||||
{
|
{
|
||||||
std::shared_lock lock(p->placefileRecordLock_);
|
std::shared_lock lock(p->placefileRecordLock_);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ public:
|
||||||
|
|
||||||
bool placefile_enabled(const std::string& name);
|
bool placefile_enabled(const std::string& name);
|
||||||
bool placefile_thresholded(const std::string& name);
|
bool placefile_thresholded(const std::string& name);
|
||||||
std::shared_ptr<const gr::Placefile> placefile(const std::string& name);
|
std::shared_ptr<gr::Placefile> placefile(const std::string& name);
|
||||||
|
|
||||||
void set_placefile_enabled(const std::string& name, bool enabled);
|
void set_placefile_enabled(const std::string& name, bool enabled);
|
||||||
void set_placefile_thresholded(const std::string& name, bool thresholded);
|
void set_placefile_thresholded(const std::string& name, bool thresholded);
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
#include <scwx/util/time.hpp>
|
#include <scwx/util/time.hpp>
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <backends/imgui_impl_opengl3.h>
|
#include <backends/imgui_impl_opengl3.h>
|
||||||
#include <backends/imgui_impl_qt.hpp>
|
#include <backends/imgui_impl_qt.hpp>
|
||||||
|
|
@ -124,12 +125,16 @@ public:
|
||||||
void RadarProductManagerDisconnect();
|
void RadarProductManagerDisconnect();
|
||||||
void RadarProductViewConnect();
|
void RadarProductViewConnect();
|
||||||
void RadarProductViewDisconnect();
|
void RadarProductViewDisconnect();
|
||||||
|
void RemovePlacefileLayer(const std::string& placefileName);
|
||||||
void SetRadarSite(const std::string& radarSite);
|
void SetRadarSite(const std::string& radarSite);
|
||||||
|
void UpdatePlacefileLayers();
|
||||||
bool UpdateStoredMapParameters();
|
bool UpdateStoredMapParameters();
|
||||||
|
|
||||||
common::Level2Product
|
common::Level2Product
|
||||||
GetLevel2ProductOrDefault(const std::string& productName) const;
|
GetLevel2ProductOrDefault(const std::string& productName) const;
|
||||||
|
|
||||||
|
static std::string GetPlacefileLayerName(const std::string& placefileName);
|
||||||
|
|
||||||
boost::asio::thread_pool threadPool_ {1u};
|
boost::asio::thread_pool threadPool_ {1u};
|
||||||
|
|
||||||
boost::uuids::uuid uuid_;
|
boost::uuids::uuid uuid_;
|
||||||
|
|
@ -158,6 +163,9 @@ public:
|
||||||
std::shared_ptr<PlacefileLayer> placefileLayer_;
|
std::shared_ptr<PlacefileLayer> placefileLayer_;
|
||||||
std::shared_ptr<ColorTableLayer> colorTableLayer_;
|
std::shared_ptr<ColorTableLayer> colorTableLayer_;
|
||||||
|
|
||||||
|
std::set<std::string> enabledPlacefiles_ {};
|
||||||
|
std::list<std::shared_ptr<PlacefileLayer>> placefileLayers_ {};
|
||||||
|
|
||||||
bool autoRefreshEnabled_;
|
bool autoRefreshEnabled_;
|
||||||
bool autoUpdateEnabled_;
|
bool autoUpdateEnabled_;
|
||||||
|
|
||||||
|
|
@ -199,11 +207,28 @@ void MapWidgetImpl::ConnectSignals()
|
||||||
connect(placefileManager_.get(),
|
connect(placefileManager_.get(),
|
||||||
&manager::PlacefileManager::PlacefileEnabled,
|
&manager::PlacefileManager::PlacefileEnabled,
|
||||||
widget_,
|
widget_,
|
||||||
[this]() { widget_->update(); });
|
[this](const std::string& name, bool enabled)
|
||||||
|
{
|
||||||
|
if (enabled && !enabledPlacefiles_.contains(name))
|
||||||
|
{
|
||||||
|
enabledPlacefiles_.emplace(name);
|
||||||
|
UpdatePlacefileLayers();
|
||||||
|
}
|
||||||
|
else if (!enabled && enabledPlacefiles_.contains(name))
|
||||||
|
{
|
||||||
|
enabledPlacefiles_.erase(name);
|
||||||
|
RemovePlacefileLayer(name);
|
||||||
|
}
|
||||||
|
widget_->update();
|
||||||
|
});
|
||||||
connect(placefileManager_.get(),
|
connect(placefileManager_.get(),
|
||||||
&manager::PlacefileManager::PlacefileRenamed,
|
&manager::PlacefileManager::PlacefileRenamed,
|
||||||
widget_,
|
widget_,
|
||||||
[this]() { widget_->update(); });
|
[this]()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
widget_->update();
|
||||||
|
});
|
||||||
connect(placefileManager_.get(),
|
connect(placefileManager_.get(),
|
||||||
&manager::PlacefileManager::PlacefileUpdated,
|
&manager::PlacefileManager::PlacefileUpdated,
|
||||||
widget_,
|
widget_,
|
||||||
|
|
@ -679,6 +704,7 @@ void MapWidget::AddLayers()
|
||||||
p->map_->removeLayer(id.c_str());
|
p->map_->removeLayer(id.c_str());
|
||||||
}
|
}
|
||||||
p->layerList_.clear();
|
p->layerList_.clear();
|
||||||
|
p->placefileLayers_.clear();
|
||||||
|
|
||||||
auto radarProductView = p->context_->radar_product_view();
|
auto radarProductView = p->context_->radar_product_view();
|
||||||
|
|
||||||
|
|
@ -724,13 +750,68 @@ void MapWidget::AddLayers()
|
||||||
|
|
||||||
p->alertLayer_->AddLayers("colorTable");
|
p->alertLayer_->AddLayers("colorTable");
|
||||||
|
|
||||||
p->placefileLayer_ = std::make_shared<PlacefileLayer>(p->context_);
|
p->UpdatePlacefileLayers();
|
||||||
p->AddLayer("placefile", p->placefileLayer_);
|
|
||||||
|
|
||||||
p->overlayLayer_ = std::make_shared<OverlayLayer>(p->context_);
|
p->overlayLayer_ = std::make_shared<OverlayLayer>(p->context_);
|
||||||
p->AddLayer("overlay", p->overlayLayer_);
|
p->AddLayer("overlay", p->overlayLayer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapWidgetImpl::RemovePlacefileLayer(const std::string& placefileName)
|
||||||
|
{
|
||||||
|
std::string layerName = GetPlacefileLayerName(placefileName);
|
||||||
|
|
||||||
|
// Remove layer from map
|
||||||
|
map_->removeLayer(layerName.c_str());
|
||||||
|
|
||||||
|
// Remove layer from internal layer list
|
||||||
|
auto layerIt = std::find(layerList_.begin(), layerList_.end(), layerName);
|
||||||
|
if (layerIt != layerList_.end())
|
||||||
|
{
|
||||||
|
layerList_.erase(layerIt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if a layer exists for the placefile
|
||||||
|
auto placefileIt =
|
||||||
|
std::find_if(placefileLayers_.begin(),
|
||||||
|
placefileLayers_.end(),
|
||||||
|
[&placefileName](auto& layer)
|
||||||
|
{ return placefileName == layer->placefile_name(); });
|
||||||
|
if (placefileIt != placefileLayers_.end())
|
||||||
|
{
|
||||||
|
placefileLayers_.erase(placefileIt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapWidgetImpl::UpdatePlacefileLayers()
|
||||||
|
{
|
||||||
|
// Loop through enabled placefiles
|
||||||
|
for (auto& placefileName : enabledPlacefiles_)
|
||||||
|
{
|
||||||
|
// Determine if a layer exists for the placefile
|
||||||
|
auto it = std::find_if(placefileLayers_.begin(),
|
||||||
|
placefileLayers_.end(),
|
||||||
|
[&placefileName](auto& layer) {
|
||||||
|
return placefileName == layer->placefile_name();
|
||||||
|
});
|
||||||
|
|
||||||
|
// If the layer doesn't exist, create it
|
||||||
|
if (it == placefileLayers_.end())
|
||||||
|
{
|
||||||
|
std::shared_ptr<PlacefileLayer> placefileLayer =
|
||||||
|
std::make_shared<PlacefileLayer>(context_, placefileName);
|
||||||
|
placefileLayers_.push_back(placefileLayer);
|
||||||
|
AddLayer(
|
||||||
|
GetPlacefileLayerName(placefileName), placefileLayer, "colorTable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
MapWidgetImpl::GetPlacefileLayerName(const std::string& placefileName)
|
||||||
|
{
|
||||||
|
return fmt::format("placefile-{}", placefileName);
|
||||||
|
}
|
||||||
|
|
||||||
void MapWidgetImpl::AddLayer(const std::string& id,
|
void MapWidgetImpl::AddLayer(const std::string& id,
|
||||||
std::shared_ptr<GenericLayer> layer,
|
std::shared_ptr<GenericLayer> layer,
|
||||||
const std::string& before)
|
const std::string& before)
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,19 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
|
||||||
class PlacefileLayer::Impl
|
class PlacefileLayer::Impl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Impl(std::shared_ptr<MapContext> context) :
|
explicit Impl(PlacefileLayer* self,
|
||||||
|
std::shared_ptr<MapContext> context,
|
||||||
|
const std::string& placefileName) :
|
||||||
|
self_ {self},
|
||||||
|
placefileName_ {placefileName},
|
||||||
placefileIcons_ {std::make_shared<gl::draw::PlacefileIcons>(context)}
|
placefileIcons_ {std::make_shared<gl::draw::PlacefileIcons>(context)}
|
||||||
{
|
{
|
||||||
|
ConnectSignals();
|
||||||
}
|
}
|
||||||
~Impl() = default;
|
~Impl() = default;
|
||||||
|
|
||||||
|
void ConnectSignals();
|
||||||
|
|
||||||
void
|
void
|
||||||
RenderIconDrawItem(const QMapLibreGL::CustomLayerRenderParameters& params,
|
RenderIconDrawItem(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const std::shared_ptr<gr::Placefile::IconDrawItem>& di);
|
const std::shared_ptr<gr::Placefile::IconDrawItem>& di);
|
||||||
|
|
@ -44,6 +51,11 @@ public:
|
||||||
float x,
|
float x,
|
||||||
float y);
|
float y);
|
||||||
|
|
||||||
|
PlacefileLayer* self_;
|
||||||
|
|
||||||
|
std::string placefileName_;
|
||||||
|
bool dirty_ {true};
|
||||||
|
|
||||||
std::uint32_t textId_ {};
|
std::uint32_t textId_ {};
|
||||||
glm::vec2 mapScreenCoordLocation_ {};
|
glm::vec2 mapScreenCoordLocation_ {};
|
||||||
float mapScale_ {1.0f};
|
float mapScale_ {1.0f};
|
||||||
|
|
@ -55,14 +67,43 @@ public:
|
||||||
std::shared_ptr<gl::draw::PlacefileIcons> placefileIcons_;
|
std::shared_ptr<gl::draw::PlacefileIcons> placefileIcons_;
|
||||||
};
|
};
|
||||||
|
|
||||||
PlacefileLayer::PlacefileLayer(std::shared_ptr<MapContext> context) :
|
PlacefileLayer::PlacefileLayer(std::shared_ptr<MapContext> context,
|
||||||
DrawLayer(context), p(std::make_unique<PlacefileLayer::Impl>(context))
|
const std::string& placefileName) :
|
||||||
|
DrawLayer(context),
|
||||||
|
p(std::make_unique<PlacefileLayer::Impl>(this, context, placefileName))
|
||||||
{
|
{
|
||||||
AddDrawItem(p->placefileIcons_);
|
AddDrawItem(p->placefileIcons_);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlacefileLayer::~PlacefileLayer() = default;
|
PlacefileLayer::~PlacefileLayer() = default;
|
||||||
|
|
||||||
|
void PlacefileLayer::Impl::ConnectSignals()
|
||||||
|
{
|
||||||
|
auto placefileManager = manager::PlacefileManager::Instance();
|
||||||
|
|
||||||
|
QObject::connect(placefileManager.get(),
|
||||||
|
&manager::PlacefileManager::PlacefileUpdated,
|
||||||
|
self_,
|
||||||
|
[this](const std::string& name)
|
||||||
|
{
|
||||||
|
if (name == placefileName_)
|
||||||
|
{
|
||||||
|
dirty_ = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PlacefileLayer::placefile_name() const
|
||||||
|
{
|
||||||
|
return p->placefileName_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlacefileLayer::set_placefile_name(const std::string& placefileName)
|
||||||
|
{
|
||||||
|
p->placefileName_ = placefileName;
|
||||||
|
p->dirty_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
void PlacefileLayer::Initialize()
|
void PlacefileLayer::Initialize()
|
||||||
{
|
{
|
||||||
logger_->debug("Initialize()");
|
logger_->debug("Initialize()");
|
||||||
|
|
@ -74,6 +115,11 @@ void PlacefileLayer::Impl::RenderIconDrawItem(
|
||||||
const QMapLibreGL::CustomLayerRenderParameters& params,
|
const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
const std::shared_ptr<gr::Placefile::IconDrawItem>& di)
|
const std::shared_ptr<gr::Placefile::IconDrawItem>& di)
|
||||||
{
|
{
|
||||||
|
if (!dirty_)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto distance =
|
auto distance =
|
||||||
(thresholded_) ?
|
(thresholded_) ?
|
||||||
util::GeographicLib::GetDistance(
|
util::GeographicLib::GetDistance(
|
||||||
|
|
@ -162,9 +208,6 @@ void PlacefileLayer::Render(
|
||||||
// Reset text ID per frame
|
// Reset text ID per frame
|
||||||
p->textId_ = 0;
|
p->textId_ = 0;
|
||||||
|
|
||||||
// Reset graphics
|
|
||||||
p->placefileIcons_->Reset();
|
|
||||||
|
|
||||||
// Update map screen coordinate and scale information
|
// Update map screen coordinate and scale information
|
||||||
p->mapScreenCoordLocation_ = util::maplibre::LatLongToScreenCoordinate(
|
p->mapScreenCoordLocation_ = util::maplibre::LatLongToScreenCoordinate(
|
||||||
{params.latitude, params.longitude});
|
{params.latitude, params.longitude});
|
||||||
|
|
@ -192,14 +235,21 @@ void PlacefileLayer::Render(
|
||||||
std::shared_ptr<manager::PlacefileManager> placefileManager =
|
std::shared_ptr<manager::PlacefileManager> placefileManager =
|
||||||
manager::PlacefileManager::Instance();
|
manager::PlacefileManager::Instance();
|
||||||
|
|
||||||
// Render text
|
auto placefile = placefileManager->placefile(p->placefileName_);
|
||||||
for (auto& placefile : placefileManager->GetActivePlacefiles())
|
|
||||||
|
// Render placefile
|
||||||
|
if (placefile != nullptr)
|
||||||
{
|
{
|
||||||
p->thresholded_ =
|
p->thresholded_ =
|
||||||
placefileManager->placefile_thresholded(placefile->name());
|
placefileManager->placefile_thresholded(placefile->name());
|
||||||
|
|
||||||
|
if (p->dirty_)
|
||||||
|
{
|
||||||
|
// Reset Placefile Icons
|
||||||
|
p->placefileIcons_->Reset();
|
||||||
p->placefileIcons_->SetIconFiles(placefile->icon_files(),
|
p->placefileIcons_->SetIconFiles(placefile->icon_files(),
|
||||||
placefile->name());
|
placefile->name());
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& drawItem : placefile->GetDrawItems())
|
for (auto& drawItem : placefile->GetDrawItems())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <scwx/qt/map/draw_layer.hpp>
|
#include <scwx/qt/map/draw_layer.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
namespace qt
|
namespace qt
|
||||||
|
|
@ -12,9 +14,14 @@ namespace map
|
||||||
class PlacefileLayer : public DrawLayer
|
class PlacefileLayer : public DrawLayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit PlacefileLayer(std::shared_ptr<MapContext> context);
|
explicit PlacefileLayer(std::shared_ptr<MapContext> context,
|
||||||
|
const std::string& placefileName);
|
||||||
~PlacefileLayer();
|
~PlacefileLayer();
|
||||||
|
|
||||||
|
std::string placefile_name() const;
|
||||||
|
|
||||||
|
void set_placefile_name(const std::string& placefileName);
|
||||||
|
|
||||||
void Initialize() override final;
|
void Initialize() override final;
|
||||||
void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final;
|
void Render(const QMapLibreGL::CustomLayerRenderParameters&) override final;
|
||||||
void Deinitialize() override final;
|
void Deinitialize() override final;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue