diff --git a/src/handler.cpp b/src/handler.cpp index c733792b..81e52048 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -58,7 +58,7 @@ std::vector getDeviceInfos() { return axisInfos; } -void addPlots(const char *name, bool const flagPaused, +void addPlots(const char *name, std::function axesSetup) { static std::set firstRun; diff --git a/src/handler.hpp b/src/handler.hpp index 6b695c04..0c76d1af 100644 --- a/src/handler.hpp +++ b/src/handler.hpp @@ -31,7 +31,7 @@ inline std::map>> inline std::vector plotAxes; void addPlots( - const char *, const bool, + const char *, std::function); void parseDeviceMetaData(Omniscope::MetaData, std::shared_ptr &); diff --git a/src/main.cpp b/src/main.cpp index fdd17d7c..fdd75558 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,21 +12,15 @@ int main() { load_json_file(load_json(config, "languagepath") + load_json(config, "language") + ".json"); // local variables - auto now = std::chrono::system_clock::now(); - std::time_t now_time_t = std::chrono::system_clock::to_time_t(now); - std::tm now_tm = *std::gmtime(&now_time_t); - bool flagPaused{true}; - bool Development{false}, flagInitState{true}, - open_generate_training_data{false}, open_settings{false}; + bool flagPaused{true}, development{false}, open_generate_training_data{false}, + open_settings{false}; + std::once_flag flag; auto loadedFiles = captureData; std::map loadedFilenames; // main loop auto render = [&]() { - if (flagInitState) { - set_inital_config(config); - flagInitState = false; - } + std::call_once(flag, set_inital_config, std::ref(config)); SetupImGuiStyle(false, 0.99f); ImGui::SetNextWindowPos({0.f, 0.f}); auto windowSize{ImGui::GetIO().DisplaySize}; @@ -35,7 +29,7 @@ int main() { ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar); - if (Development && ImGui::Button("Development")) + if (development && ImGui::Button("Development")) ImGui::OpenPopup("Development Colors"); // Popup-Window content @@ -91,36 +85,33 @@ int main() { ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, windowSize.x * .009f); ImGui::BeginChild("Record Data", {0.f, windowSize.y * 0.62f}, ImGuiChildFlags_Border); - // Axes 1 to 3 // Check if time base for axes are same // check if egu and timescale for plot are same // error if third device is added - addPlots( - "Recording the data", flagPaused, - [&flagPaused](double x_max, std::string yLabel, ImAxis_ axis, - double yMin, double yMax) { - ImPlot::SetupLegend(ImPlotLocation_NorthEast | - ImPlotLegendFlags_Outside); - auto auxFlagsMeasuring = - ImPlotAxisFlags_AutoFit | ImPlotAxisFlags_NoGridLines; - auto auxFlagsPaused = ImPlotAxisFlags_NoGridLines; - ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, true); + addPlots("Recording the data", [flagPaused]( + double x_max, std::string yLabel, + ImAxis_ axis, double yMin, double yMax) { + ImPlot::SetupLegend(ImPlotLocation_NorthEast); + // auto auxFlagsMeasuring = + // ImPlotAxisFlags_AutoFit | ImPlotAxisFlags_NoGridLines; + // auto auxFlagsPaused = ImPlotAxisFlags_NoGridLines; + ImPlot::SetupAxisTicks(ImAxis_Y1, -10, 200, 22, nullptr, true); - if (!flagPaused) { - ImPlot::SetupAxis(axis, yLabel.c_str(), ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxis(ImAxis_X1, "time [s]", ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxisLimits(axis, yMin - 2, yMax + 2, ImGuiCond_Always); - ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 1, x_max + 9, - ImGuiCond_Always); + if (!flagPaused) { + ImPlot::SetupAxis(axis, yLabel.c_str(), ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxis(ImAxis_X1, "time [s]", ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisLimits(axis, yMin - 2, yMax + 2, ImGuiCond_Always); + ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 1, x_max + 9, + ImGuiCond_Always); - } else { - ImPlot::SetupAxis(ImAxis_X1, "time [s]"); - ImPlot::SetupAxis(axis, yLabel.c_str()); - ImPlot::SetupAxisLimits(ImAxis_X1, 0, 10); - ImPlot::SetupAxisLimits(axis, yMin - 2, yMax + 2); - } - }); + } else { + ImPlot::SetupAxis(ImAxis_X1, "time [s]"); + ImPlot::SetupAxis(axis, yLabel.c_str()); + ImPlot::SetupAxisLimits(ImAxis_X1, 0, 10); + ImPlot::SetupAxisLimits(axis, yMin - 2, yMax + 2); + } + }); ImGui::EndChild(); // end child Record Data ImGui::PopStyleVar(); PopPlotRegionColors();