satdump/src-interface/recorder/tracking/tracking_widget.cpp

198 lines
7 KiB
C++
Raw Normal View History

2023-07-17 23:11:13 +02:00
#include "tracking_widget.h"
#include "imgui/imgui.h"
2023-09-06 22:28:55 -04:00
#include "logger.h"
2023-07-17 23:11:13 +02:00
#include "core/config.h"
2023-07-18 12:27:58 +02:00
#include "main_ui.h"
2023-12-10 13:03:59 +01:00
#include "core/style.h"
#include "common/imgui_utils.h"
#include "common/tracking/rotator/rotcl_handler.h"
2023-07-20 19:31:46 +02:00
2023-07-17 23:11:13 +02:00
namespace satdump
{
TrackingWidget::TrackingWidget()
{
try
{
qth_lon = config::main_cfg["satdump_general"]["qth_lon"]["value"].get<double>();
qth_lat = config::main_cfg["satdump_general"]["qth_lat"]["value"].get<double>();
qth_alt = config::main_cfg["satdump_general"]["qth_alt"]["value"].get<double>();
}
catch (std::exception &e)
{
logger->error("Could not get QTH lon/lat! %s", e.what());
}
logger->trace("Using QTH %f %f Alt %f", qth_lon, qth_lat, qth_alt);
rotator_options = rotator::getRotatorHandlerOptions();
for (auto &st : rotator_options)
rotator_options_str += st.name + '\0';
rotator_handler = rotator_options[selected_rotator_handler].construct();
if (rotator_handler)
{
try
{
rotator_handler->set_settings(config::main_cfg["user"]["recorder_tracking"]["rotator_config"][rotator_handler->get_id()]);
}
2024-03-12 23:15:18 -04:00
catch (std::exception &)
{
}
}
2023-12-10 19:53:50 +01:00
// Init Obj Tracker
2023-12-10 13:03:59 +01:00
object_tracker.setQTH(qth_lon, qth_lat, qth_alt);
object_tracker.setRotator(rotator_handler);
object_tracker.setObject(object_tracker.TRACKING_SATELLITE, 25338);
2023-12-10 19:53:50 +01:00
// Init scheduler
2024-01-22 23:03:51 +01:00
auto_scheduler.eng_callback = [this](AutoTrackCfg, SatellitePass, TrackedObject obj)
2023-12-10 19:53:50 +01:00
{
object_tracker.setObject(object_tracker.TRACKING_SATELLITE, obj.norad);
saveConfig();
};
auto_scheduler.aos_callback = [this](AutoTrackCfg autotrack_cfg, SatellitePass pass, TrackedObject obj)
2023-12-10 19:53:50 +01:00
{
this->aos_callback(autotrack_cfg, pass, obj);
2023-12-10 19:53:50 +01:00
object_tracker.setObject(object_tracker.TRACKING_SATELLITE, obj.norad);
};
auto_scheduler.los_callback = [this](AutoTrackCfg autotrack_cfg, SatellitePass pass, TrackedObject obj)
2023-12-10 19:53:50 +01:00
{
this->los_callback(autotrack_cfg, pass, obj);
2023-12-10 19:53:50 +01:00
};
auto_scheduler.setQTH(qth_lon, qth_lat, qth_alt);
// Restore config
loadConfig();
// Start scheduler
auto_scheduler.start();
// Attempt to apply provided CLI settings
2023-11-09 12:04:09 +01:00
if (satdump::config::main_cfg.contains("cli"))
{
2023-11-09 12:04:09 +01:00
auto &cli_settings = satdump::config::main_cfg["cli"];
2023-11-09 12:04:09 +01:00
if (cli_settings.contains("engage_autotrack") && cli_settings["engage_autotrack"].get<bool>())
{
2023-12-10 19:53:50 +01:00
auto_scheduler.setEngaged(true, getTime());
}
}
2023-07-17 23:11:13 +02:00
}
TrackingWidget::~TrackingWidget()
{
2023-12-10 19:53:50 +01:00
saveConfig();
2023-07-17 23:11:13 +02:00
}
void TrackingWidget::render()
{
object_tracker.renderPolarPlot();
2023-07-18 16:59:32 +02:00
2023-08-02 23:32:14 +02:00
ImGui::Separator();
2023-12-10 13:03:59 +01:00
object_tracker.renderSelectionMenu();
2023-07-17 23:11:13 +02:00
ImGui::Spacing();
2023-12-10 13:03:59 +01:00
if (ImGui::CollapsingHeader("Object Information"))
2023-12-10 13:03:59 +01:00
object_tracker.renderObjectStatus();
if (ImGui::CollapsingHeader("Rotator Configuration"))
2023-12-10 13:03:59 +01:00
{
object_tracker.renderRotatorStatus();
ImGui::SameLine();
if (rotator_handler->is_connected())
style::beginDisabled();
2024-07-29 11:40:19 -04:00
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (ImGui::Combo("Type##rotatortype", &selected_rotator_handler, rotator_options_str.c_str()))
2023-12-10 13:03:59 +01:00
{
rotator_handler = rotator_options[selected_rotator_handler].construct();
object_tracker.setRotator(rotator_handler);
2023-12-10 13:03:59 +01:00
try
{
rotator_handler->set_settings(config::main_cfg["user"]["recorder_tracking"]["rotator_config"][rotator_handler->get_id()]);
}
2024-03-12 23:15:18 -04:00
catch (std::exception &)
2023-12-10 13:03:59 +01:00
{
}
}
if (rotator_handler->is_connected())
style::endDisabled();
rotator_handler->render();
}
2023-07-20 16:36:16 +02:00
ImGui::Spacing();
2023-08-02 23:32:14 +02:00
ImGui::Separator();
2023-07-20 15:55:38 +02:00
ImGui::Spacing();
2023-12-10 13:03:59 +01:00
2024-03-12 23:15:18 -04:00
float width_available = ImGui::GetContentRegionAvail().x;
std::string is_engaged = auto_scheduler.getEngaged() ? "YES" : "NO";
float centered_pos = width_available / 2.0f - ImGui::CalcTextSize(std::string("Autotrack Engaged: " + is_engaged).c_str()).x / 2.0f;
2024-08-10 14:57:35 +02:00
if (centered_pos > 0)
2024-03-12 23:15:18 -04:00
ImGui::SetCursorPosX(centered_pos);
ImGui::TextUnformatted("Autotrack Engaged:");
ImGui::SameLine();
ImGui::TextColored(auto_scheduler.getEngaged() ? style::theme.green : style::theme.red, "%s", is_engaged.c_str());
if (ImGui::Button("Schedule and Config", ImVec2(width_available, 0.0f)))
config_window_was_asked = show_window_config = true;
2024-03-12 23:15:18 -04:00
ImGui::Spacing();
2023-12-10 13:03:59 +01:00
renderConfig();
2023-07-17 23:11:13 +02:00
}
2023-12-10 13:03:59 +01:00
void TrackingWidget::renderConfig()
2023-07-17 23:11:13 +02:00
{
2023-12-10 13:03:59 +01:00
if (show_window_config)
{
2024-07-21 15:46:18 -04:00
ImGui::SetNextWindowSizeConstraints(ImVec2(800 * ui_scale, 300 * ui_scale), ImVec2(INFINITY, INFINITY));
2023-12-10 13:03:59 +01:00
ImGui::Begin("Tracking Configuration", &show_window_config);
2024-07-21 15:46:18 -04:00
ImGui::SetWindowSize(ImVec2(800 * ui_scale, 550 * ui_scale), ImGuiCond_FirstUseEver);
2023-12-10 13:03:59 +01:00
if (ImGui::BeginTabBar("##trackingtabbar"))
{
if (ImGui::BeginTabItem("Scheduling"))
{
2023-12-10 19:53:50 +01:00
ImGui::BeginChild("##trackingbarschedule", ImVec2(0, 0), false, ImGuiWindowFlags_NoResize);
auto_scheduler.renderAutotrackConfig(getTime());
2023-12-10 19:53:50 +01:00
ImGui::EndChild();
2023-12-10 13:03:59 +01:00
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Rotator Config"))
{
2023-12-10 19:53:50 +01:00
object_tracker.renderRotatorConfig();
2023-12-10 13:03:59 +01:00
ImGui::EndTabItem();
}
2024-10-06 10:03:15 -04:00
if (ImGui::BeginTabItem("Export/Import"))
2024-09-30 14:42:56 -04:00
{
2024-10-06 14:08:04 -04:00
ImGui::BeginChild("##trackingimportexport", ImVec2(0, 0), false, ImGuiWindowFlags_NoResize);
2024-10-06 10:03:15 -04:00
if (config_import_export.draw_export())
config_import_export.do_export(auto_scheduler, object_tracker, rotator_handler);
2024-10-06 14:08:04 -04:00
ImGui::Spacing();
bool disable_import = auto_scheduler.getEngaged();
if (disable_import)
style::beginDisabled();
2024-10-06 10:03:15 -04:00
if (config_import_export.draw_import())
config_import_export.do_import(auto_scheduler, object_tracker, rotator_handler);
2024-10-06 14:08:04 -04:00
if (disable_import)
style::endDisabled();
ImGui::EndChild();
2024-09-30 14:42:56 -04:00
ImGui::EndTabItem();
}
2023-12-10 13:03:59 +01:00
ImGui::EndTabBar();
}
2023-07-17 23:11:13 +02:00
2023-12-10 13:03:59 +01:00
if (config_window_was_asked)
ImGuiUtils_BringCurrentWindowToFront();
config_window_was_asked = false;
ImGui::End();
}
}
2023-07-17 23:11:13 +02:00
}