2025-07-08 17:42:18 +01:00
|
|
|
#include "processing.h"
|
2025-12-08 17:50:52 +01:00
|
|
|
#include "../../../src-interface/main_ui.h"
|
2025-07-08 17:42:18 +01:00
|
|
|
#include "core/config.h"
|
2025-12-08 17:50:52 +01:00
|
|
|
#include "core/plugin.h"
|
2025-07-08 17:42:18 +01:00
|
|
|
#include "imgui/imgui.h"
|
|
|
|
|
#include "imgui/imgui_internal.h"
|
|
|
|
|
#include "logger.h"
|
2025-07-16 12:56:24 +02:00
|
|
|
#include <filesystem>
|
2025-07-08 17:42:18 +01:00
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
namespace satdump
|
|
|
|
|
{
|
|
|
|
|
namespace handlers
|
|
|
|
|
{
|
|
|
|
|
OffProcessingHandler::OffProcessingHandler(pipeline::Pipeline downlink_pipeline, std::string input_level, std::string input_file, std::string output_file, nlohmann::json parameters)
|
|
|
|
|
{
|
|
|
|
|
ui_call_list = std::make_shared<std::vector<std::shared_ptr<pipeline::ProcessingModule>>>();
|
|
|
|
|
ui_call_list_mutex = std::make_shared<std::mutex>();
|
|
|
|
|
|
|
|
|
|
proc_thread = std::thread(&OffProcessingHandler::process, this, downlink_pipeline, input_level, input_file, output_file, parameters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OffProcessingHandler::OffProcessingHandler(std::string downlink_pipeline, std::string input_level, std::string input_file, std::string output_file, nlohmann::json parameters)
|
|
|
|
|
{
|
|
|
|
|
ui_call_list = std::make_shared<std::vector<std::shared_ptr<pipeline::ProcessingModule>>>();
|
|
|
|
|
ui_call_list_mutex = std::make_shared<std::mutex>();
|
|
|
|
|
|
|
|
|
|
// Get pipeline
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
pipeline::Pipeline pipeline = pipeline::getPipelineFromID(downlink_pipeline);
|
|
|
|
|
proc_thread = std::thread(&OffProcessingHandler::process, this, pipeline, input_level, input_file, output_file, parameters);
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
logger->error("Error processing! %s", e.what());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OffProcessingHandler::~OffProcessingHandler()
|
|
|
|
|
{
|
|
|
|
|
if (proc_thread.joinable())
|
|
|
|
|
proc_thread.join();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OffProcessingHandler::process(pipeline::Pipeline downlink_pipeline, std::string input_level, std::string input_file, std::string output_file, nlohmann::json parameters)
|
|
|
|
|
{
|
2025-07-18 12:19:40 +02:00
|
|
|
eventBus->fire_event<SetIsProcessingEvent>({});
|
|
|
|
|
|
2025-07-13 14:40:31 +02:00
|
|
|
pipeline_name = downlink_pipeline.name;
|
|
|
|
|
|
2025-07-08 17:42:18 +01:00
|
|
|
logger->info("Starting processing pipeline " + downlink_pipeline.id + "...");
|
|
|
|
|
logger->debug("Input file (" + input_level + ") : " + input_file);
|
|
|
|
|
logger->debug("Output file : " + output_file);
|
|
|
|
|
|
|
|
|
|
if (!std::filesystem::exists(output_file))
|
|
|
|
|
std::filesystem::create_directories(output_file);
|
|
|
|
|
|
|
|
|
|
ui_call_list_mutex->lock();
|
|
|
|
|
ui_call_list->clear();
|
|
|
|
|
ui_call_list_mutex->unlock();
|
|
|
|
|
|
2025-07-14 20:22:56 +02:00
|
|
|
std::string final_file;
|
|
|
|
|
|
2025-07-08 17:42:18 +01:00
|
|
|
try
|
|
|
|
|
{
|
2025-07-14 20:22:56 +02:00
|
|
|
downlink_pipeline.run(input_file, output_file, parameters, input_level, true, ui_call_list, ui_call_list_mutex, &final_file);
|
2025-07-08 17:42:18 +01:00
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
logger->error("Fatal error running pipeline : " + std::string(e.what()));
|
2025-12-24 17:45:14 +01:00
|
|
|
goto exit_handler;
|
2025-07-08 17:42:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger->info("Done! Goodbye");
|
|
|
|
|
|
2025-07-14 20:22:56 +02:00
|
|
|
logger->critical("FINAL FILE : " + final_file); // TODOREWORK!
|
|
|
|
|
|
2025-07-08 17:42:18 +01:00
|
|
|
// TODOREWORKUI
|
|
|
|
|
if (satdump_cfg.main_cfg["user_interface"]["open_explorer_post_processing"]["value"].get<bool>())
|
|
|
|
|
{
|
|
|
|
|
if (std::filesystem::exists(output_file + "/dataset.json"))
|
|
|
|
|
{
|
|
|
|
|
logger->info("Opening explorer!");
|
2025-12-08 17:50:52 +01:00
|
|
|
eventBus->fire_event<TryOpenFileInMainExplorerEvent>({output_file + "/dataset.json"}); // TODOREWORK Maybe just try to open the final file produced?
|
2025-07-08 17:42:18 +01:00
|
|
|
}
|
2025-07-16 12:56:24 +02:00
|
|
|
else if (std::filesystem::exists(final_file))
|
|
|
|
|
{
|
|
|
|
|
logger->info("Opening explorer!");
|
2025-12-08 17:50:52 +01:00
|
|
|
eventBus->fire_event<TryOpenFileInMainExplorerEvent>({final_file}); // TODOREWORK Maybe just try to open the final file produced?
|
2025-07-16 12:56:24 +02:00
|
|
|
}
|
2025-07-08 17:42:18 +01:00
|
|
|
}
|
2025-07-13 14:40:31 +02:00
|
|
|
|
2025-12-24 17:45:14 +01:00
|
|
|
exit_handler:
|
2026-05-22 17:54:17 +02:00
|
|
|
eventBus->fire_event<SetIsDoneProcessingEvent>({});
|
2025-12-24 17:45:14 +01:00
|
|
|
pipeline_name = "PROCESSING_DONE"; // TODOREWORK MASSIVE HACK!
|
2025-07-08 17:42:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OffProcessingHandler::drawMenu() {}
|
|
|
|
|
|
|
|
|
|
void OffProcessingHandler::drawContents(ImVec2 win_size)
|
|
|
|
|
{
|
|
|
|
|
auto &dims = win_size;
|
|
|
|
|
|
|
|
|
|
float currentPosx = ImGui::GetCursorPos().x;
|
|
|
|
|
|
|
|
|
|
// ImGui::BeginChild("OfflineProcessingChild");
|
|
|
|
|
ui_call_list_mutex->lock();
|
|
|
|
|
|
|
|
|
|
if (ui_call_list->size())
|
|
|
|
|
{
|
|
|
|
|
int live_width = dims.x; // ImGui::GetWindowWidth();
|
|
|
|
|
int live_height = /*ImGui::GetWindowHeight();*/ dims.y - ImGui::GetCursorPos().y;
|
|
|
|
|
float winheight = ui_call_list->size() > 0 ? live_height / ui_call_list->size() : live_height;
|
|
|
|
|
float currentPos = ImGui::GetCursorPos().y;
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_TitleBg, ImGui::GetStyleColorVec4(ImGuiCol_TitleBgActive));
|
|
|
|
|
for (std::shared_ptr<pipeline::ProcessingModule> module : *ui_call_list)
|
|
|
|
|
{
|
|
|
|
|
ImGui::SetNextWindowPos({currentPosx, currentPos});
|
|
|
|
|
currentPos += winheight;
|
|
|
|
|
ImGui::SetNextWindowSize({(float)live_width, (float)winheight});
|
|
|
|
|
module->drawUI(false);
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-07-13 14:41:08 +02:00
|
|
|
ImGui::Text("Done processing! You can close this, if it didn't close itself.");
|
2025-07-08 17:42:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui_call_list_mutex->unlock();
|
|
|
|
|
// ImGui::EndChild();
|
|
|
|
|
}
|
|
|
|
|
} // namespace handlers
|
|
|
|
|
} // namespace satdump
|