2022-03-30 15:41:23 +02:00
# include "settings.h"
2025-05-31 20:26:47 +02:00
# include "core/params.h"
# include "core/plugin.h"
2022-03-30 15:41:23 +02:00
# include "imgui/imgui.h"
# include <string>
# include "core/config.h"
2022-08-30 12:01:12 +02:00
# include "core/opencl.h"
2025-05-31 20:26:47 +02:00
# include "main_ui.h"
2022-03-30 15:41:23 +02:00
2022-05-07 17:06:56 +02:00
# include "common/tracking/tle.h"
2024-07-10 15:27:49 -04:00
# include "common/widgets/json_editor.h"
2025-05-31 20:26:47 +02:00
# include "common/widgets/timed_message.h"
# include "init.h"
2022-05-07 17:06:56 +02:00
2025-05-25 14:30:24 +02:00
# include "core/resources.h"
2025-05-31 20:26:47 +02:00
# include "core/style.h"
2022-11-28 00:27:39 +01:00
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
2024-01-22 23:39:05 -05:00
int selected_theme = 0 ;
std : : vector < std : : string > themes ;
std : : string themes_str = " " ;
2025-10-03 00:22:55 +02:00
bool iers_are_update = false ;
2022-11-28 00:27:39 +01:00
bool tles_are_update = false ;
2025-10-03 00:22:55 +02:00
char iers_last_update [ 80 ] ;
2023-10-25 12:11:17 -04:00
char tle_last_update [ 80 ] ;
2022-11-28 00:27:39 +01:00
2024-07-10 15:27:49 -04:00
bool advanced_mode = false ;
2023-01-30 12:12:04 +01:00
2024-01-19 15:54:21 -05:00
widgets : : TimedMessage saved_message ;
2023-11-29 21:36:40 -05:00
2022-03-30 15:41:23 +02:00
void setup ( )
{
2025-06-08 16:57:37 +02:00
nlohmann : : ordered_json params = satdump : : satdump_cfg . main_cfg [ " user_interface " ] ;
2022-03-30 15:41:23 +02:00
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
2025-06-08 16:57:37 +02:00
params = satdump : : satdump_cfg . main_cfg [ " satdump_general " ] ;
2022-04-21 16:10:00 +02:00
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
2025-06-08 16:57:37 +02:00
params = satdump : : satdump_cfg . main_cfg [ " satdump_directories " ] ;
2022-05-03 21:10:59 +02:00
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-05-03 21:10:59 +02:00
}
2022-04-24 18:31:30 +02:00
2024-01-22 23:39:05 -05:00
int theme_id = 0 ;
2025-06-08 16:57:37 +02:00
std : : string current_theme = satdump : : satdump_cfg . main_cfg [ " user_interface " ] [ " theme " ] [ " value " ] . get < std : : string > ( ) ;
2025-03-08 21:46:07 +01:00
for ( const auto & entry : std : : filesystem : : directory_iterator ( resources : : getResourcePath ( " themes " ) ) )
2024-01-22 23:39:05 -05:00
{
if ( entry . path ( ) . filename ( ) . extension ( ) ! = " .json " )
continue ;
std : : string this_name = entry . path ( ) . filename ( ) . stem ( ) . string ( ) ;
themes . push_back ( this_name ) ;
themes_str + = this_name ;
2024-01-22 23:56:54 -05:00
themes_str . push_back ( ' \0 ' ) ;
2024-01-22 23:39:05 -05:00
if ( this_name = = current_theme )
selected_theme = theme_id ;
theme_id + + ;
}
2025-06-08 16:57:37 +02:00
advanced_mode = getValueOrDefault ( satdump : : satdump_cfg . main_cfg [ " user_interface " ] [ " advanced_mode " ] [ " value " ] , false ) ;
2024-07-10 15:27:49 -04:00
2022-04-24 18:31:30 +02:00
# ifdef USE_OPENCL
opencl_devices_enum = opencl : : getAllDevices ( ) ;
2025-03-08 21:46:07 +01:00
opencl_devices_enum . push_back ( { - 1 , - 1 , " None (Use CPU) " } ) ;
2025-06-08 16:57:37 +02:00
int p = satdump : : satdump_cfg . main_cfg [ " satdump_general " ] [ " opencl_device " ] [ " platform " ] . get < int > ( ) ;
int d = satdump : : satdump_cfg . main_cfg [ " satdump_general " ] [ " opencl_device " ] [ " device " ] . get < int > ( ) ;
2022-04-24 18:31:30 +02:00
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
{
2024-02-10 15:16:17 -05:00
opencl_devices_str + = dev . name ;
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 + + ;
}
2024-02-10 15:16:17 -05:00
opencl_devices_str . push_back ( ' \0 ' ) ;
2022-04-24 18:31:30 +02:00
# endif
2022-03-30 15:41:23 +02:00
}
void render ( )
{
2024-11-15 10:19:51 -05:00
ImGui : : SeparatorText ( " Core Settings " ) ;
2022-03-30 15:41:23 +02:00
if ( ImGui : : CollapsingHeader ( " User Interface " ) )
{
if ( ImGui : : BeginTable ( " ##satdumpuisettings " , 2 , ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg ) )
{
2024-01-22 23:39:05 -05:00
// Theme Selection
ImGui : : TableNextRow ( ) ;
ImGui : : TableSetColumnIndex ( 0 ) ;
ImGui : : Text ( " Theme " ) ;
if ( ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( " Set the style and color of SatDump " ) ;
ImGui : : TableSetColumnIndex ( 1 ) ;
ImGui : : Combo ( " ##themeselection " , & selected_theme , themes_str . c_str ( ) ) ;
// Standard user interface settings
2022-03-30 15:41:23 +02:00
for ( std : : pair < std : : string , satdump : : params : : EditableParameter > & p : settings_user_interface )
p . second . draw ( ) ;
2023-01-30 12:12:04 +01:00
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
2026-05-30 11:12:24 +02:00
// Keplers (used to be TLEs)
2022-05-07 17:06:56 +02:00
ImGui : : TableNextRow ( ) ;
ImGui : : TableSetColumnIndex ( 0 ) ;
2026-05-30 11:12:24 +02:00
ImGui : : Text ( " Update Keplers Now " ) ;
2022-05-07 17:06:56 +02:00
ImGui : : TableSetColumnIndex ( 1 ) ;
2023-10-19 20:33:29 -04:00
bool disable_update_button = tles_are_update ;
if ( disable_update_button )
2022-11-28 00:27:39 +01:00
style : : beginDisabled ( ) ;
2026-05-30 11:12:24 +02:00
if ( ImGui : : Button ( " Update###updateKeplers " ) )
2022-11-28 00:27:39 +01:00
{
2025-05-31 20:26:47 +02:00
ui_thread_pool . push (
[ ] ( int )
{
tles_are_update = true ;
2026-05-30 11:12:24 +02:00
db_keplers - > updateKeplerDatabase ( ) ;
2025-05-31 20:26:47 +02:00
tles_are_update = false ;
} ) ;
2022-11-28 00:27:39 +01:00
}
2023-10-19 20:33:29 -04:00
if ( disable_update_button )
2022-11-28 00:27:39 +01:00
style : : endDisabled ( ) ;
2022-05-07 17:06:56 +02:00
2026-05-30 11:12:24 +02:00
time_t last_update = std : : stod ( db - > get_meta ( " kepler_last_updated " , " 0 " ) ) ;
2023-10-25 12:11:17 -04:00
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 ) ;
2025-10-03 00:22:55 +02:00
// IERS
ImGui : : TableNextRow ( ) ;
ImGui : : TableSetColumnIndex ( 0 ) ;
ImGui : : Text ( " Update IERS Bulletin Now " ) ;
ImGui : : TableSetColumnIndex ( 1 ) ;
disable_update_button = iers_are_update ;
if ( disable_update_button )
style : : beginDisabled ( ) ;
if ( ImGui : : Button ( " Update###updateIERS " ) )
{
ui_thread_pool . push (
[ ] ( int )
{
iers_are_update = true ;
db_iers - > updateIERS ( ) ;
iers_are_update = false ;
} ) ;
}
if ( disable_update_button )
style : : endDisabled ( ) ;
last_update = std : : stod ( db - > get_meta ( " iers_last_updated " , " 0 " ) ) ;
if ( last_update = = 0 )
strcpy ( iers_last_update , " Never " ) ;
else
{
struct tm ts ;
ts = * gmtime ( & last_update ) ;
strftime ( iers_last_update , sizeof ( iers_last_update ) , " %Y-%m-%d %H:%M:%S UTC " , & ts ) ;
}
ImGui : : SameLine ( 0.0f , 10.0f * ui_scale ) ;
ImGui : : TextDisabled ( " Last updated: %s " , iers_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 ( ) ;
}
}
2024-10-27 12:09:44 -04:00
if ( ImGui : : CollapsingHeader ( " File Input/Output " ) )
2022-05-03 21:10:59 +02:00
{
2022-05-03 23:55:39 +02:00
if ( ImGui : : BeginTable ( " ##satdumpoutput_directories " , 2 , ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg ) )
2022-05-03 21:10:59 +02:00
{
2022-05-03 23:55:39 +02:00
for ( std : : pair < std : : string , satdump : : params : : EditableParameter > & p : settings_output_directories )
2022-05-03 21:10:59 +02:00
p . second . draw ( ) ;
ImGui : : EndTable ( ) ;
}
}
2022-05-03 23:55:39 +02:00
2025-06-08 16:57:37 +02:00
if ( satdump_cfg . plugin_config_handlers . size ( ) > 0 )
2024-07-10 15:27:49 -04:00
{
2024-11-15 10:19:51 -05:00
ImGui : : SetCursorPosY ( ImGui : : GetCursorPosY ( ) + 10 * ui_scale ) ;
ImGui : : SeparatorText ( " Plugin Settings " ) ;
2025-06-08 16:57:37 +02:00
for ( auto & plugin_hdl : satdump_cfg . plugin_config_handlers )
2024-07-13 15:02:09 -04:00
{
2024-11-15 10:19:51 -05:00
if ( ImGui : : CollapsingHeader ( plugin_hdl . name . c_str ( ) ) )
{
plugin_hdl . render ( ) ;
}
2024-07-13 15:02:09 -04:00
}
2024-07-10 15:27:49 -04:00
}
2024-07-20 00:17:57 -04:00
if ( advanced_mode )
2023-09-14 10:38:02 +02:00
{
2024-07-21 09:09:37 -04:00
ImGui : : SetCursorPosY ( ImGui : : GetCursorPosY ( ) + 10 * ui_scale ) ;
ImGui : : SeparatorText ( " Advanced Settings " ) ;
2024-07-20 00:17:57 -04:00
if ( ImGui : : CollapsingHeader ( " TLE Settings " ) )
2023-09-14 10:38:02 +02:00
{
2025-06-08 16:57:37 +02:00
widgets : : JSONTreeEditor ( satdump : : satdump_cfg . main_cfg [ " tle_settings " ] , " tle_settings " , false ) ;
2024-07-20 00:17:57 -04:00
if ( ImGui : : Button ( " Reset##tle_settings " ) )
2025-06-08 16:57:37 +02:00
satdump : : satdump_cfg . main_cfg [ " tle_settings " ] = satdump : : satdump_cfg . default_cfg [ " tle_settings " ] ;
2024-07-20 00:17:57 -04:00
}
if ( ImGui : : CollapsingHeader ( " Advanced Settings " ) )
{
2025-06-08 16:57:37 +02:00
widgets : : JSONTreeEditor ( satdump : : satdump_cfg . main_cfg [ " advanced_settings " ] , " advanced_settings " ) ;
2024-07-20 00:17:57 -04:00
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Reset##advanced_settings " ) )
2025-06-08 16:57:37 +02:00
satdump : : satdump_cfg . main_cfg [ " advanced_settings " ] = satdump : : satdump_cfg . default_cfg [ " advanced_settings " ] ;
2024-07-20 00:17:57 -04:00
}
2024-07-21 09:09:37 -04:00
if ( ImGui : : CollapsingHeader ( " Default Pipeline Configs " ) )
2024-07-20 00:17:57 -04:00
{
2025-05-31 20:26:47 +02:00
widgets : : JSONTreeEditor ( pipeline : : pipelines_json , " pipelines " ) ;
2024-07-20 00:17:57 -04:00
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Reset##pipelines " ) )
2025-05-31 20:26:47 +02:00
pipeline : : pipelines_json = pipeline : : pipelines_system_json ;
2023-09-14 10:38:02 +02:00
}
}
2024-07-20 00:17:57 -04:00
ImGui : : SetCursorPosY ( ImGui : : GetCursorPosY ( ) + 5 * ui_scale ) ;
2022-03-30 15:41:23 +02:00
if ( ImGui : : Button ( " Save " ) )
{
2022-04-24 18:31:30 +02:00
# ifdef USE_OPENCL
2025-01-03 12:05:46 -05:00
// Save OpenCL Device selection
2025-06-08 16:57:37 +02:00
satdump : : satdump_cfg . main_cfg [ " satdump_general " ] [ " opencl_device " ] [ " platform " ] = opencl_devices_enum [ opencl_devices_id ] . platform_id ;
satdump : : satdump_cfg . main_cfg [ " satdump_general " ] [ " opencl_device " ] [ " device " ] = opencl_devices_enum [ opencl_devices_id ] . device_id ;
2024-02-13 15:03:42 -05:00
opencl : : resetOCLContext ( ) ;
2022-04-24 18:31:30 +02:00
# endif
2025-01-03 12:05:46 -05:00
// Most general settings
2022-03-30 15:41:23 +02:00
for ( std : : pair < std : : string , satdump : : params : : EditableParameter > & p : settings_user_interface )
2025-06-08 16:57:37 +02:00
satdump : : satdump_cfg . 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 )
2025-06-08 16:57:37 +02:00
satdump : : satdump_cfg . 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 )
2025-06-08 16:57:37 +02:00
satdump : : satdump_cfg . main_cfg [ " satdump_directories " ] [ p . first ] [ " value " ] = p . second . getValue ( ) ;
2023-09-14 10:38:02 +02:00
2025-01-03 12:05:46 -05:00
// Theme
2025-06-08 16:57:37 +02:00
satdump : : satdump_cfg . main_cfg [ " user_interface " ] [ " theme " ] [ " value " ] = themes [ selected_theme ] ;
2024-01-22 23:39:05 -05:00
2025-01-03 12:05:46 -05:00
// Plugin Settings
2025-06-08 16:57:37 +02:00
for ( auto & plugin_hdl : satdump_cfg . plugin_config_handlers )
2023-09-14 10:38:02 +02:00
plugin_hdl . save ( ) ;
2025-01-03 12:05:46 -05:00
// Re-initialize auto TLE update
2025-08-10 19:18:23 +02:00
ui_thread_pool . push (
[ ] ( int )
{
2025-09-26 10:25:46 +02:00
2025-08-10 19:18:23 +02:00
} ) ;
2025-01-03 12:05:46 -05:00
// Save config files
2025-06-08 16:57:37 +02:00
satdump_cfg . saveUser ( ) ;
2024-07-10 15:27:49 -04:00
if ( advanced_mode )
2025-05-31 20:26:47 +02:00
pipeline : : savePipelines ( ) ;
2025-01-03 12:05:46 -05:00
// Clean up
2025-06-08 16:57:37 +02:00
advanced_mode = getValueOrDefault ( satdump : : satdump_cfg . main_cfg [ " user_interface " ] [ " advanced_mode " ] [ " value " ] , false ) ;
2024-01-21 14:57:41 -05:00
saved_message . set_message ( style : : theme . green , " Settings saved " ) ;
2024-01-21 17:30:00 -05:00
satdump : : update_ui = true ;
2022-03-30 15:41:23 +02:00
}
2022-05-07 18:16:24 +02:00
2023-11-29 21:36:40 -05:00
saved_message . draw ( ) ;
2024-01-21 14:57:41 -05:00
ImGui : : TextColored ( style : : theme . yellow , " Note : Some settings will require SatDump to be restarted \n to take effect! " ) ;
2022-03-30 15:41:23 +02:00
}
2025-05-31 20:26:47 +02:00
} // namespace settings
} // namespace satdump