Skip to content

Commit

Permalink
1st setp in refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Abbasi committed Sep 16, 2024
1 parent 99bbf01 commit 38659d1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ std::vector<AxisInfo> getDeviceInfos() {
return axisInfos;
}

void addPlots(const char *name, bool const flagPaused,
void addPlots(const char *name,
std::function<void(double, std::string, ImAxis_, double, double)>
axesSetup) {
static std::set<std::string> firstRun;
Expand Down
2 changes: 1 addition & 1 deletion src/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ inline std::map<Omniscope::Id, std::vector<std::pair<double, double>>>

inline std::vector<AxisInfo> plotAxes;
void addPlots(
const char *, const bool,
const char *,
std::function<void(double, std::string, ImAxis_, double, double)>);
void parseDeviceMetaData(Omniscope::MetaData,
std::shared_ptr<OmniscopeDevice> &);
Expand Down
61 changes: 26 additions & 35 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@ int main() {
load_json_file(load_json<std::string>(config, "languagepath") +
load_json<std::string>(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<Omniscope::Id, std::string> 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};
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 38659d1

Please sign in to comment.