satdump/src-interface/settings.cpp

210 lines
9.3 KiB
C++
Raw Permalink Normal View History

2022-03-30 15:41:23 +02:00
#include "settings.h"
#include "imgui/imgui.h"
#include <string>
#include "core/params.h"
#include "core/config.h"
#include "main_ui.h"
2022-08-30 12:01:12 +02:00
#include "core/opencl.h"
2022-03-30 15:41:23 +02:00
2022-05-07 17:06:56 +02:00
#include "init.h"
#include "common/tracking/tle.h"
2022-11-28 00:27:39 +01:00
#include "core/style.h"
2022-03-30 15:41:23 +02:00
namespace satdump
{
namespace settings
{
std::vector<std::pair<std::string, satdump::params::EditableParameter>> settings_user_interface;
2022-04-21 16:10:00 +02:00
std::vector<std::pair<std::string, satdump::params::EditableParameter>> settings_general;
2022-05-03 23:55:39 +02:00
std::vector<std::pair<std::string, satdump::params::EditableParameter>> settings_output_directories;
2022-03-30 15:41:23 +02:00
2022-04-24 18:31:30 +02:00
#ifdef USE_OPENCL
// OpenCL Selection
int opencl_devices_id = 0;
std::string opencl_devices_str;
2022-08-30 12:01:12 +02:00
std::vector<opencl::OCLDevice> opencl_devices_enum;
2022-04-24 18:31:30 +02:00
#endif
2022-11-28 00:27:39 +01:00
bool tles_are_update = false;
2023-10-25 12:11:17 -04:00
char tle_last_update[80];
2022-11-28 00:27:39 +01:00
bool show_imgui_demo = false;
2022-03-30 15:41:23 +02:00
void setup()
{
nlohmann::ordered_json params = satdump::config::main_cfg["user_interface"];
for (nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::ordered_json>> cfg : params.items())
{
// Check setting type, and create an EditableParameter if possible
if (cfg.value().contains("type") && cfg.value().contains("value") && cfg.value().contains("name"))
settings_user_interface.push_back({cfg.key(), params::EditableParameter(nlohmann::json(cfg.value()))});
}
2022-04-21 16:10:00 +02:00
params = satdump::config::main_cfg["satdump_general"];
for (nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::ordered_json>> cfg : params.items())
{
// Check setting type, and create an EditableParameter if possible
if (cfg.value().contains("type") && cfg.value().contains("value") && cfg.value().contains("name"))
settings_general.push_back({cfg.key(), params::EditableParameter(nlohmann::json(cfg.value()))});
}
2022-05-03 23:55:39 +02:00
params = satdump::config::main_cfg["satdump_directories"];
for (nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::ordered_json>> cfg : params.items())
{
// Check setting type, and create an EditableParameter if possible
if (cfg.value().contains("type") && cfg.value().contains("value") && cfg.value().contains("name"))
2022-05-03 23:55:39 +02:00
settings_output_directories.push_back({cfg.key(), params::EditableParameter(nlohmann::json(cfg.value()))});
}
2022-04-24 18:31:30 +02:00
#ifdef USE_OPENCL
opencl_devices_enum = opencl::getAllDevices();
int p = satdump::config::main_cfg["satdump_general"]["opencl_device"]["platform"].get<int>();
int d = satdump::config::main_cfg["satdump_general"]["opencl_device"]["device"].get<int>();
int dev_id = 0;
2022-11-16 17:17:41 +01:00
opencl_devices_str = "";
2022-08-30 12:01:12 +02:00
for (opencl::OCLDevice &dev : opencl_devices_enum)
2022-04-24 18:31:30 +02:00
{
2022-11-27 22:25:30 +01:00
if (dev_id == (int)opencl_devices_enum.size() - 1)
2022-11-16 17:17:41 +01:00
opencl_devices_str += dev.name;
else
opencl_devices_str += dev.name + " \0";
2022-08-30 12:01:12 +02:00
if (dev.platform_id == p && dev.device_id == d)
2022-04-24 18:31:30 +02:00
opencl_devices_id = dev_id;
dev_id++;
}
#endif
2022-03-30 15:41:23 +02:00
}
void render()
{
if (ImGui::CollapsingHeader("User Interface"))
{
if (ImGui::BeginTable("##satdumpuisettings", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
{
for (std::pair<std::string, satdump::params::EditableParameter> &p : settings_user_interface)
p.second.draw();
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("Show ImGui Demo");
if (ImGui::IsItemHovered())
ImGui::SetTooltip("For developers only!");
ImGui::TableSetColumnIndex(1);
ImGui::Checkbox("##showimguidebugcheckbox", &show_imgui_demo);
2022-03-30 15:41:23 +02:00
ImGui::EndTable();
}
}
2022-04-21 16:10:00 +02:00
if (ImGui::CollapsingHeader("General SatDump"))
{
if (ImGui::BeginTable("##satdumpgeneralsettings", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
{
2022-04-24 18:31:30 +02:00
#ifdef USE_OPENCL
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("OpenCL Device");
if (ImGui::IsItemHovered())
ImGui::SetTooltip("OpenCL Device SatDump will use for accelerated computing where it can help, eg, for some image processing tasks such as projections.");
ImGui::TableSetColumnIndex(1);
ImGui::Combo("##opencldeviceselection", &opencl_devices_id, opencl_devices_str.c_str());
#endif
2022-04-21 16:10:00 +02:00
for (std::pair<std::string, satdump::params::EditableParameter> &p : settings_general)
p.second.draw();
2022-05-07 17:06:56 +02:00
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("Update TLEs Now");
ImGui::TableSetColumnIndex(1);
bool disable_update_button = tles_are_update;
if (disable_update_button)
2022-11-28 00:27:39 +01:00
style::beginDisabled();
2022-05-07 17:06:56 +02:00
if (ImGui::Button("Update###updateTLEs"))
2022-11-28 00:27:39 +01:00
{
ui_thread_pool.push([](int)
{ tles_are_update = true;
updateTLEFile(satdump::user_path + "/satdump_tles.txt");
tles_are_update = false; });
}
if (disable_update_button)
2022-11-28 00:27:39 +01:00
style::endDisabled();
2022-05-07 17:06:56 +02:00
2023-10-25 12:11:17 -04:00
time_t last_update = getValueOrDefault<time_t>(config::main_cfg["user"]["tles_last_updated"], 0);
if (last_update == 0)
strcpy(tle_last_update, "Never");
else
{
struct tm ts;
ts = *gmtime(&last_update);
strftime(tle_last_update, sizeof(tle_last_update), "%Y-%m-%d %H:%M:%S UTC", &ts);
}
ImGui::SameLine(0.0f, 10.0f * ui_scale);
ImGui::TextDisabled("Last updated: %s", tle_last_update);
2022-09-15 15:53:48 +02:00
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("Clear Tile Map (OSM) Cache");
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Delete all cached tiles (OSM, and other sources).");
ImGui::TableSetColumnIndex(1);
if (ImGui::Button("Clear Cache###deleteosmtiles"))
if (std::filesystem::exists(satdump::user_path + "/osm_tiles/"))
std::filesystem::remove_all(satdump::user_path + "/osm_tiles/");
2022-04-21 16:10:00 +02:00
ImGui::EndTable();
}
}
2022-05-04 00:51:13 +02:00
if (ImGui::CollapsingHeader("Output Directories"))
{
2022-05-03 23:55:39 +02:00
if (ImGui::BeginTable("##satdumpoutput_directories", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
{
2022-05-03 23:55:39 +02:00
for (std::pair<std::string, satdump::params::EditableParameter> &p : settings_output_directories)
p.second.draw();
ImGui::EndTable();
}
}
2022-05-03 23:55:39 +02:00
2023-09-14 10:38:02 +02:00
for (auto &plugin_hdl : config::plugin_config_handlers)
{
if (ImGui::CollapsingHeader(plugin_hdl.name.c_str()))
{
plugin_hdl.render();
}
}
2022-03-30 15:41:23 +02:00
if (ImGui::Button("Save"))
{
2022-04-24 18:31:30 +02:00
#ifdef USE_OPENCL
2022-07-30 20:16:17 +02:00
if (opencl_devices_enum.size() > 0)
{
2022-08-30 12:01:12 +02:00
satdump::config::main_cfg["satdump_general"]["opencl_device"]["platform"] = opencl_devices_enum[opencl_devices_id].platform_id;
satdump::config::main_cfg["satdump_general"]["opencl_device"]["device"] = opencl_devices_enum[opencl_devices_id].device_id;
2022-07-30 20:16:17 +02:00
}
2022-04-24 18:31:30 +02:00
#endif
2022-03-30 15:41:23 +02:00
for (std::pair<std::string, satdump::params::EditableParameter> &p : settings_user_interface)
satdump::config::main_cfg["user_interface"][p.first]["value"] = p.second.getValue();
2022-04-21 16:10:00 +02:00
for (std::pair<std::string, satdump::params::EditableParameter> &p : settings_general)
satdump::config::main_cfg["satdump_general"][p.first]["value"] = p.second.getValue();
2022-05-03 23:55:39 +02:00
for (std::pair<std::string, satdump::params::EditableParameter> &p : settings_output_directories)
satdump::config::main_cfg["satdump_directories"][p.first]["value"] = p.second.getValue();
2023-09-14 10:38:02 +02:00
for (auto &plugin_hdl : config::plugin_config_handlers)
plugin_hdl.save();
2022-03-30 15:41:23 +02:00
config::saveUserConfig();
}
2022-05-07 18:16:24 +02:00
ImGui::TextColored(ImColor(255, 255, 0), "Note : Some settings will require SatDump to be restarted\nto take effect!");
2022-03-30 15:41:23 +02:00
}
}
}