2022-03-07 20:29:23 +01:00
|
|
|
#include "offline.h"
|
|
|
|
|
#include "imgui/imgui.h"
|
|
|
|
|
#include <string>
|
|
|
|
|
#include "core/params.h"
|
|
|
|
|
#include "core/pipeline.h"
|
|
|
|
|
#include "pfd/widget.h"
|
|
|
|
|
#include "core/config.h"
|
|
|
|
|
#include "processing.h"
|
2022-03-10 19:56:37 +01:00
|
|
|
#include "main_ui.h"
|
|
|
|
|
#include "common/utils.h"
|
2022-03-20 20:56:32 +01:00
|
|
|
#include "imgui/imgui_stdlib.h"
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
namespace satdump
|
2022-03-07 20:29:23 +01:00
|
|
|
{
|
2022-03-10 19:56:37 +01:00
|
|
|
namespace offline
|
|
|
|
|
{
|
|
|
|
|
FileSelectWidget inputfileselect("Input File", "Select Input File");
|
|
|
|
|
FileSelectWidget outputdirselect("Output Directory", "Select Output Directory", true);
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
int pipelines_levels_select_id = -1;
|
|
|
|
|
std::string pipeline_levels_str;
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
std::vector<std::pair<std::string, satdump::params::EditableParameter>> parameters_ui;
|
|
|
|
|
std::vector<std::pair<std::string, satdump::params::EditableParameter>> parameters_ui_pipeline;
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-20 20:56:32 +01:00
|
|
|
std::string pipeline_search_in;
|
2022-03-10 19:56:37 +01:00
|
|
|
int pipeline_id = 0;
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
std::string error_message = "";
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
void setup()
|
|
|
|
|
{
|
2022-03-30 15:41:23 +02:00
|
|
|
nlohmann::ordered_json params = satdump::config::main_cfg["user_interface"]["default_offline_parameters"];
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
for (nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::ordered_json>> cfg : params.items())
|
2022-03-20 20:56:32 +01:00
|
|
|
parameters_ui.push_back({cfg.key(), satdump::params::EditableParameter(nlohmann::json(cfg.value()))});
|
2022-03-10 19:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateSelectedPipeline()
|
2022-03-07 20:29:23 +01:00
|
|
|
{
|
|
|
|
|
parameters_ui_pipeline.clear();
|
|
|
|
|
for (nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::json>> cfg : pipelines[pipeline_id].editable_parameters.items())
|
|
|
|
|
{
|
|
|
|
|
auto it = std::find_if(parameters_ui.begin(),
|
|
|
|
|
parameters_ui.end(),
|
|
|
|
|
[&cfg](const std::pair<std::string, satdump::params::EditableParameter> &e)
|
|
|
|
|
{
|
|
|
|
|
return e.first == cfg.key();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (it == parameters_ui.end())
|
|
|
|
|
parameters_ui_pipeline.push_back({cfg.key(), satdump::params::EditableParameter(cfg.value())});
|
|
|
|
|
else
|
|
|
|
|
it->second.setValue(cfg.value()["value"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pipeline_levels_str = "";
|
|
|
|
|
if (pipeline_id != -1)
|
|
|
|
|
for (int i = 0; i < (int)pipelines[pipeline_id].steps.size() - 1; i++)
|
|
|
|
|
pipeline_levels_str += pipelines[pipeline_id].steps[i].level_name + '\0';
|
|
|
|
|
|
|
|
|
|
if (pipelines_levels_select_id == -1)
|
|
|
|
|
pipelines_levels_select_id = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
void render()
|
|
|
|
|
{
|
2022-03-20 20:56:32 +01:00
|
|
|
ImGui::InputTextWithHint("##pipelinesearchbox", "Search pipelines...", &pipeline_search_in);
|
2022-03-10 19:56:37 +01:00
|
|
|
if (ImGui::BeginListBox("##pipelineslistbox"))
|
|
|
|
|
{
|
|
|
|
|
for (int n = 0; n < pipelines.size(); n++)
|
|
|
|
|
{
|
|
|
|
|
bool show = true;
|
2022-03-20 20:56:32 +01:00
|
|
|
if (pipeline_search_in.size() != 0)
|
|
|
|
|
show = isStringPresent(pipelines[n].readable_name, pipeline_search_in);
|
2022-03-10 19:56:37 +01:00
|
|
|
|
|
|
|
|
if (show)
|
|
|
|
|
{
|
|
|
|
|
const bool is_selected = (pipeline_id == n);
|
|
|
|
|
if (ImGui::Selectable(pipelines[n].readable_name.c_str(), is_selected))
|
|
|
|
|
{
|
|
|
|
|
pipeline_id = n;
|
|
|
|
|
updateSelectedPipeline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_selected)
|
|
|
|
|
ImGui::SetItemDefaultFocus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndListBox();
|
|
|
|
|
}
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
ImGui::Spacing();
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
|
|
|
|
|
ImGui::BeginTable("##pipelinesmainoptions", 2);
|
|
|
|
|
ImGui::TableSetupColumn("##pipelinesmaincolumn1", ImGuiTableColumnFlags_WidthFixed, 100);
|
|
|
|
|
ImGui::TableSetupColumn("##pipelinesmaincolumn2", ImGuiTableColumnFlags_WidthStretch, 100);
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableSetColumnIndex(0);
|
|
|
|
|
ImGui::Text("Input File");
|
|
|
|
|
ImGui::TableSetColumnIndex(1);
|
|
|
|
|
inputfileselect.draw();
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableSetColumnIndex(0);
|
|
|
|
|
ImGui::Text("Output Directory");
|
|
|
|
|
ImGui::TableSetColumnIndex(1);
|
|
|
|
|
outputdirselect.draw();
|
|
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
ImGui::TableSetColumnIndex(0);
|
|
|
|
|
ImGui::Text("Input Level");
|
|
|
|
|
ImGui::TableSetColumnIndex(1);
|
|
|
|
|
ImGui::Combo("##pipelinelevel", &pipelines_levels_select_id, pipeline_levels_str.c_str());
|
|
|
|
|
ImGui::EndTable();
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
ImGui::Spacing();
|
|
|
|
|
// ImGui::Separator();
|
|
|
|
|
ImGui::Spacing();
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
if (ImGui::BeginTable("##pipelineoptions", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
|
|
|
|
|
{
|
|
|
|
|
for (std::pair<std::string, satdump::params::EditableParameter> &p : parameters_ui)
|
|
|
|
|
p.second.draw();
|
|
|
|
|
for (std::pair<std::string, satdump::params::EditableParameter> &p : parameters_ui_pipeline)
|
|
|
|
|
p.second.draw();
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
|
}
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
if (ImGui::Button("Start"))
|
|
|
|
|
{
|
|
|
|
|
nlohmann::json params2;
|
|
|
|
|
for (std::pair<std::string, satdump::params::EditableParameter> &p : parameters_ui)
|
|
|
|
|
params2[p.first] = p.second.getValue();
|
|
|
|
|
for (std::pair<std::string, satdump::params::EditableParameter> &p : parameters_ui_pipeline)
|
|
|
|
|
params2[p.first] = p.second.getValue();
|
|
|
|
|
|
|
|
|
|
if (!inputfileselect.file_valid)
|
|
|
|
|
error_message = "Input file is invalid!";
|
|
|
|
|
else if (!outputdirselect.file_valid)
|
|
|
|
|
error_message = "Output folder is invalid!";
|
|
|
|
|
else
|
|
|
|
|
ui_thread_pool.push([&, params2](int)
|
|
|
|
|
{ processing::process(pipelines[pipeline_id].name,
|
|
|
|
|
pipelines[pipeline_id].steps[pipelines_levels_select_id].level_name,
|
|
|
|
|
inputfileselect.getPath(),
|
|
|
|
|
outputdirselect.getPath(),
|
|
|
|
|
params2); });
|
|
|
|
|
}
|
2022-03-07 20:29:23 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
if (error_message.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::TextColored(ImColor(255, 0, 0), "%s", error_message.c_str());
|
|
|
|
|
}
|
2022-03-07 20:29:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-10 19:56:37 +01:00
|
|
|
}
|