15#include <boost/program_options/parsers.hpp>
17#include <implot_internal.h>
18#include <fmt/ranges.h>
23#include <boost/tokenizer.hpp>
29namespace bpo = boost::program_options;
46 (
"config", bpo::value<std::vector<std::string>>()->multitoken(),
"List of configuration files to read parameters from" )
47 (
"version,v",
"Display the version number" )
48 (
"help,h",
"Display this help message" )
49 (
"sigterm", bpo::bool_switch()->default_value(
false),
"Programm waits for -SIGUSR1 / -SIGINT / -SIGTERM" )
50 (
"duration", bpo::value<size_t>()->default_value(0),
"Program execution duration [sec]" )
51 (
"nogui", bpo::bool_switch()->default_value(
false),
"Launch without the gui" )
52 (
"noinit", bpo::bool_switch()->default_value(
false),
"Do not initialize flows after loading them" )
53 (
"load,l", bpo::value<std::string>(),
"Flow file to load" )
54 (
"rotate-output", bpo::bool_switch()->default_value(
false),
"Create new folders for output files" )
55 (
"output-path,o", bpo::value<std::string>()->default_value(
"logs"),
"Directory path for logs and output files" )
56 (
"input-path,i", bpo::value<std::string>()->default_value(
"data"),
"Directory path for searching input files" )
57 (
"flow-path,f", bpo::value<std::string>()->default_value(
"flow"),
"Directory path for searching flow files" )
58 (
"implot-config", bpo::value<std::string>()->default_value(
"implot.json"),
"Config file to read implot settings from" )
59 (
"global-log-level", bpo::value<std::string>()->default_value(
"trace"),
"Global log level of all sinks (possible values: trace/debug/info/warning/error/critical/off" )
60 (
"console-log-level", bpo::value<std::string>()->default_value(
"info"),
"Log level on the console (possible values: trace/debug/info/warning/error/critical/off" )
61 (
"file-log-level", bpo::value<std::string>()->default_value(
"debug"),
"Log level to the log file (possible values: trace/debug/info/warning/error/critical/off" )
62 (
"flush-log-level", bpo::value<std::string>()->default_value(
"info"),
"Log level to flush on (possible values: trace/debug/info/warning/error/critical/off" )
63 (
"log-filter", bpo::value<std::string>(),
"Filter/Regex for log messages" )
83 std::vector<std::string> failedConfigFiles;
86 if (
vm.count(
"config"))
88 for (
const std::string& configFile :
vm[
"config"].as<std::vector<std::string>>())
90 std::filesystem::path filepath{ configFile };
91 if (filepath.is_relative())
94 filepath /= configFile;
97 std::ifstream ifs{ filepath };
104 failedConfigFiles.push_back(configFile);
111 return failedConfigFiles;
116 LOG_DEBUG(
"{} arguments were provided over the command line", argc);
118 for (
const char* logger : {
"global-log-level",
"console-log-level",
"file-log-level",
"flush-log-level" })
120 if (
vm[logger].as<std::string>() !=
"trace"
121 &&
vm[logger].as<std::string>() !=
"debug"
122 &&
vm[logger].as<std::string>() !=
"info"
123 &&
vm[logger].as<std::string>() !=
"warning"
124 &&
vm[logger].as<std::string>() !=
"error"
125 &&
vm[logger].as<std::string>() !=
"critical"
126 &&
vm[logger].as<std::string>() !=
"off")
128 LOG_CRITICAL(
"The command line argument '{}' has to be one of 'trace/debug/info/warning/error/critical/off' but the value '{}' was provided", logger,
vm[logger].as<std::string>());
132 for (
int i = 0; i < argc; i++)
134 LOG_DEBUG(
"\targument[{}] = '{}'", i, argv[i]);
137 LOG_DEBUG(
"{} arguments are set in the allowed variable map",
vm.size());
139 for (
const auto& value :
vm)
141 if ([[maybe_unused]]
const auto* v = boost::any_cast<size_t>(&value.second.value()))
143 LOG_DEBUG(
"\tvm[{}] = '{}'", value.first, *v);
145 else if ([[maybe_unused]]
const auto* v = boost::any_cast<bool>(&value.second.value()))
147 LOG_DEBUG(
"\tvm[{}] = '{}'", value.first, *v);
149 else if ([[maybe_unused]]
const auto* v = boost::any_cast<std::string>(&value.second.value()))
151 LOG_DEBUG(
"\tvm[{}] = '{}'", value.first, *v);
153 else if ([[maybe_unused]]
const auto* v = boost::any_cast<std::vector<std::string>>(&value.second.value()))
155 LOG_DEBUG(
"\tvm[{}] = '{}'", value.first, fmt::join(v->begin(), v->end(),
", "));
159 LOG_ERROR(
"The Log option vm[{}] could not be casted. Please report this to the developers.", value.first);
166 return vm.count(key);
171 std::vector<std::string> keys;
173 for (
auto& param :
vm)
175 keys.push_back(param.first);
186#ifdef IMGUI_IMPL_OPENGL_LOADER_GL3W
187 j[
"plotScreenshotImPlotStyleFile"] = gui::windows::plotScreenshotImPlotStyleFile;
188 j[
"copyScreenshotsToClipboard"] = gui::windows::copyScreenshotsToClipboard;
192 ImPlotContext& gp = *ImPlot::GetCurrentContext();
193 j[
"selectedImPlotColormap"] = gp.Style.Colormap;
195 constexpr int CMAP_USER_START = ImPlotColormap_Greys + 2;
196 for (
int i = CMAP_USER_START; i < gp.ColormapData.Count; ++i)
198 j[
"ImPlotColormaps"][
static_cast<size_t>(i - CMAP_USER_START)][
"name"] = gp.ColormapData.GetName(i);
199 j[
"ImPlotColormaps"][
static_cast<size_t>(i - CMAP_USER_START)][
"qual"] = gp.ColormapData.IsQual(i);
200 for (
int c = 0; c < gp.ColormapData.GetKeyCount(i); ++c)
202 j[
"ImPlotColormaps"][
static_cast<size_t>(i - CMAP_USER_START)][
"colors"][
static_cast<size_t>(c)] =
203 ImGui::ColorConvertU32ToFloat4(gp.ColormapData.GetKeyColor(i, c));
207 filestream << std::setw(4) << j << std::endl;
213 std::ifstream filestream(filepath);
215 if (!filestream.good())
217 LOG_ERROR(
"Load Flow error: Could not open file: {}", filepath);
223 if (j.contains(
"colormaps"))
227#ifdef IMGUI_IMPL_OPENGL_LOADER_GL3W
228 if (j.contains(
"plotScreenshotImPlotStyleFile"))
230 j.at(
"plotScreenshotImPlotStyleFile").get_to(gui::windows::plotScreenshotImPlotStyleFile);
232 if (j.contains(
"copyScreenshotsToClipboard"))
234 j.at(
"copyScreenshotsToClipboard").get_to(gui::windows::copyScreenshotsToClipboard);
237 if (j.contains(
"ImPlotColormaps"))
239 for (
size_t i = 0; i < j[
"ImPlotColormaps"].size(); ++i)
241 ImVector<ImVec4> custom;
242 for (
const auto& c : j.at(
"ImPlotColormaps").at(i).at(
"colors"))
244 custom.push_back(c.get<ImVec4>());
247 ImPlot::AddColormap(j.at(
"ImPlotColormaps").at(i).at(
"name").get<std::string>().c_str(),
248 custom.Data, custom.Size, j.at(
"ImPlotColormaps").at(i).at(
"qual").get<
bool>());
249 ImPlot::BustItemCache();
252 if (j.contains(
"selectedImPlotColormap"))
254 ImPlotContext& gp = *ImPlot::GetCurrentContext();
255 gp.Style.Colormap = j.at(
"selectedImPlotColormap").get<
int>();
256 ImPlot::BustItemCache();
bpo::options_description program_options
Program option description.
Config management for the Project.
nlohmann::json json
json namespace
Defines how to save certain datatypes to json.
Utility class for logging to console and file.
#define LOG_CRITICAL(...)
Critical Event, which causes the program to work entirely and throws an exception.
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
void LoadGlobalSettings()
Loads the global settings.
void initialize()
Initializes the config manager. Call this function before using other functions.
boost::program_options::variables_map vm
Map which stores all options.
void CheckOptions(const int argc, const char *argv[])
Writes all command line options into the log.
bool HasKey(const std::string &key)
Checks if a corresponding key exists in the configuration.
std::vector< std::string > GetKeys()
Returns all keys in the configuration, as a vector.
std::vector< std::string > FetchConfigs(const int argc, const char *argv[])
Fetches the configs from the command line parameters.
const boost::program_options::options_description & GetProgramOptions()
Get the Program Options object.
void deinitialize()
Deinitializes the config manager. Call this if you want to Fetch config again.
void SaveGlobalSettings()
Saves the global settings.
std::filesystem::path GetConfigPath()
Get the path where config files are searched.
std::filesystem::path GetProgramRootPath()
Get the program root path.
std::vector< Colormap > ColormapsGlobal
Global colormaps.