mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-04 18:11:01 -05:00
Add image list to the module and send it with the browser updates
This commit is contained in:
@@ -37,8 +37,6 @@
|
||||
namespace {
|
||||
constexpr std::string_view SubscribeEvent = "start_subscription";
|
||||
constexpr std::string_view UnsubscribeEvent = "stop_subscription";
|
||||
constexpr std::string_view ListOfImages = "get_list_of_images";
|
||||
constexpr std::string_view ImageCollectionUrl = "get_wwt_image_collection_url";
|
||||
} // namespace
|
||||
|
||||
using nlohmann::json;
|
||||
@@ -73,22 +71,19 @@ void SkyBrowserTopic::handleJson(const nlohmann::json& json) {
|
||||
_isDone = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (event != SubscribeEvent) {
|
||||
_isDone = true;
|
||||
if (event == SubscribeEvent) {
|
||||
ServerModule* module = global::moduleEngine->module<ServerModule>();
|
||||
_targetDataCallbackHandle = module->addPreSyncCallback(
|
||||
[this]() {
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
if (now - _lastUpdateTime > _skyBrowserUpdateTime) {
|
||||
sendBrowserData();
|
||||
_lastUpdateTime = std::chrono::system_clock::now();
|
||||
}
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
ServerModule* module = global::moduleEngine->module<ServerModule>();
|
||||
_targetDataCallbackHandle = module->addPreSyncCallback(
|
||||
[this]() {
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
if (now - _lastUpdateTime > _skyBrowserUpdateTime) {
|
||||
sendBrowserData();
|
||||
_lastUpdateTime = std::chrono::system_clock::now();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void SkyBrowserTopic::sendBrowserData() {
|
||||
@@ -99,7 +94,9 @@ void SkyBrowserTopic::sendBrowserData() {
|
||||
// Set general data
|
||||
nlohmann::json json = {
|
||||
{ "selectedBrowserId", module->selectedBrowserId() },
|
||||
{ "cameraInSolarSystem", module->isCameraInSolarSystem() }
|
||||
{ "cameraInSolarSystem", module->isCameraInSolarSystem() },
|
||||
{ "url", module->wwtImageCollectionUrl() },
|
||||
{ "imageList", module->imageList()}
|
||||
};
|
||||
|
||||
// Pass data for all the browsers and the corresponding targets
|
||||
@@ -120,7 +117,7 @@ void SkyBrowserTopic::sendBrowserData() {
|
||||
{ "type", "browser_data" },
|
||||
{ "data", diff }
|
||||
}));
|
||||
_lastUpdateJson = result;
|
||||
_lastUpdateJson = result;
|
||||
}
|
||||
}
|
||||
} // namespace openspace
|
||||
|
||||
@@ -478,6 +478,40 @@ std::string SkyBrowserModule::wwtImageCollectionUrl() const {
|
||||
return _wwtImageCollectionUrl;
|
||||
}
|
||||
|
||||
nlohmann::json SkyBrowserModule::imageList() {
|
||||
// Send image list to GUI
|
||||
// If no data has been loaded yet, download the data from the web
|
||||
if (nLoadedImages() == 0) {
|
||||
std::filesystem::path directory = absPath("${SYNC}/wwtimagedata/");
|
||||
loadImages(_wwtImageCollectionUrl, directory);
|
||||
}
|
||||
|
||||
// Create Lua table to send to the GUI
|
||||
nlohmann::json list = nlohmann::json::array();
|
||||
for (auto const& [id, img] : wwtDataHandler().images()) {
|
||||
std::vector<double> vec = { img.equatorialCartesian.x, img.equatorialCartesian.y,
|
||||
img.equatorialCartesian.z };
|
||||
nlohmann::json image = {
|
||||
{ "name", img.name },
|
||||
{ "key", img.identifier },
|
||||
{ "thumbnail", img.thumbnailUrl },
|
||||
{ "url", img.imageUrl },
|
||||
{ "ra", img.equatorialSpherical.x },
|
||||
{ "dec", img.equatorialSpherical.y },
|
||||
{ "fov", img.fov },
|
||||
{ "hasCelestialCoords", img.hasCelestialCoords },
|
||||
{ "cartesianDirection", vec },
|
||||
{ "credits", img.credits },
|
||||
{ "collection", img.collection },
|
||||
{ "creditsUrl", img.creditsUrl },
|
||||
{ "identifier", img.identifier }
|
||||
};
|
||||
list.push_back(image);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void SkyBrowserModule::setSelectedBrowser(std::string_view id) {
|
||||
TargetBrowserPair* p = pair(id);
|
||||
if (p) {
|
||||
|
||||
@@ -68,6 +68,7 @@ public:
|
||||
double spaceCraftAnimationTime() const;
|
||||
|
||||
std::string wwtImageCollectionUrl() const;
|
||||
nlohmann::json imageList();
|
||||
|
||||
bool isCameraInSolarSystem() const;
|
||||
bool isSelectedPairFacingCamera() const;
|
||||
|
||||
Reference in New Issue
Block a user