Skip to content

Commit

Permalink
merge mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
dennispelle committed Oct 11, 2023
1 parent 0015a47 commit ea06431
Showing 1 changed file with 93 additions and 49 deletions.
142 changes: 93 additions & 49 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
#include "apihandler.hpp"
#include "create_training_data.hpp"
#include "get_from_github.hpp"
#include "look_up_saves.hpp"
#include "saves_popup.hpp"
#include "jasonhandler.hpp"
#include "settingspopup.hpp"
#include "saves_popup.hpp"
#include <ImGuiInstance/ImGuiInstance.hpp>
#include <algorithm>
#include <fmt/chrono.h>
Expand Down Expand Up @@ -78,6 +77,7 @@ int main() {
const std::string configpath = "config/config.json";
if (std::filesystem::exists(configpath)) {
fmt::print("found config.json\n\r");

} else {
fmt::print("Did not find config.json.\n Download from Github\n\r");
update_config_from_github();
Expand All @@ -87,6 +87,7 @@ int main() {
load_json<std::string>(config, ("languagepath")))) {
fmt::print("found language: {}\n\r",
load_json<std::string>(config, ("language")));

} else {
fmt::print("Did not find {}.\n Download from Github\n\r",
load_json<std::string>(config, ("language")));
Expand Down Expand Up @@ -136,6 +137,8 @@ int main() {
double xmax_paused{0};
static bool open_settings = false;
static bool upload_success = false;
static bool flagPaused = true;
static bool flagDataNotSaved = true;
static ImVec2 mainMenuBarSize;
std::optional<OmniscopeSampler> sampler{};
std::map<Omniscope::Id, std::vector<std::pair<double, double>>> captureData;
Expand Down Expand Up @@ -167,7 +170,6 @@ int main() {
}
return ImPlot::GetPlotLimits();
}();

auto addPlot = [&](auto const &plot) {
if (!plot.second.empty()) {
auto const start = [&]() {
Expand All @@ -189,7 +191,6 @@ int main() {
}
return p;
}();

std::size_t const stride = [&]() -> std::size_t {
auto const s = std::distance(start, end) / (plotRegion.x * 2.0);
if (1 >= s) {
Expand Down Expand Up @@ -253,7 +254,10 @@ int main() {
load_json<std::string>(language, "menubar", "menu", "reset")
.c_str())) {
sampler.reset();
devices.clear();
deviceManager.clearDevices();
captureData.clear();
flagPaused = true;
}
ImGui::EndMenu();
}
Expand All @@ -267,7 +271,8 @@ int main() {
if (ImGui::BeginMenu(
load_json<std::string>(language, "menubar", "help", "label")
.c_str())) {
if (ImGui::MenuItem(load_json<std::string>(config, "helplink").c_str())) {
if (ImGui::MenuItem(
load_json<std::string>(language, "helplink").c_str())) {
system(("start " + load_json<std::string>(config, "helplink")).c_str());
}

Expand All @@ -281,12 +286,14 @@ int main() {
// ##############################
ImGui::BeginChild("Live Capture", ImVec2(-1, 620));
if (sampler.has_value()) {
sampler->copyOut(captureData);
if (!flagPaused) {
sampler->copyOut(captureData);
}
}

addPlots("Aufnahme der Daten", captureData,
[&sampler, &xmax_paused](auto /*x_min*/, auto x_max) {
if (sampler.has_value()) {
if (!flagPaused) {
ImPlot::SetupAxes("x [Datenpunkte]", "y [ADC Wert]",
ImPlotAxisFlags_AutoFit,
ImPlotAxisFlags_AutoFit);
Expand Down Expand Up @@ -315,7 +322,6 @@ int main() {
// ##############################
if (ImGui::BeginPopupModal("Speichern der aufgenommenen Daten", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {

ImGui::SetItemDefaultFocus();
saves_popup(config, language, captureData, now, now_time_t, now_tm, path);

Expand All @@ -328,9 +334,31 @@ int main() {

ImGui::EndPopup();
}
// ############################ Popup Zurücksetzen
// ##############################
if (ImGui::BeginPopupModal("Zurücksetzen?", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SetItemDefaultFocus();
ImGui::Text("Die Messung wurde nicht gespeichert!\n"
"Möchten Sie diese vor dem Löschen speichern?\n");
if (ImGui::Button("Löschen fortsetzen",
ImVec2(load_json<Size>(config, "button")))) {
sampler.reset();
devices.clear();
deviceManager.clearDevices();
captureData.clear();
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("Zurück", ImVec2(load_json<Size>(config, "button")))) {
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}

ImGui::SetNextWindowPos(ImVec2(0, 100));
ImGui::SetNextWindowSize(ImVec2(0, 800));
if (!sampler.has_value()) {
if (flagPaused) {
if (ImGui::BeginPopupModal("Erstellung Lerndatensatz", nullptr,
ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoSavedSettings |
Expand Down Expand Up @@ -359,27 +387,33 @@ int main() {
ImGui::SetItemDefaultFocus();
ImGui::EndPopup();
}
// Start nur wenn Devices vorhanden soind, sonst Suche Geräte
if (ImGui::Button("Suche Geräte",
ImVec2(load_json<Size>(config, "button")))) {
devices.clear();
deviceManager.clearDevices();
initDevices();
// ######################## Buttonstripe
// ################################
// Start nur wenn Devices vorhanden sind, sonst Suche Geräte
if (!sampler.has_value()) {
if (ImGui::Button("Suche Geräte",
ImVec2(load_json<Size>(config, "button")))) {
devices.clear();
deviceManager.clearDevices();
initDevices();
}
ImGui::SameLine();
}

if (!devices.empty()) {
ImGui::SameLine();
// ############################ Start Button
// ##############################
set_button_style_to(config, "start");
if (ImGui::Button(
load_json<std::string>(language, "button", "start").c_str(),
ImVec2(load_json<Size>(config, "button")))) {
// sampler anlegen
// std::optinal<OmniscopeSampler> sampler{};
sampler.emplace(deviceManager, std::move(devices));
if (!sampler.has_value()) {
set_button_style_to(config, "start");
if (ImGui::Button(
load_json<std::string>(language, "button", "start").c_str(),
ImVec2(load_json<Size>(config, "button")))) {
sampler.emplace(deviceManager, std::move(devices));
flagPaused = false;
flagDataNotSaved = true;
}
ImGui::PopStyleColor(3);
}
ImGui::PopStyleColor(3);
}
// set_button_style_to(config, "standart");
} else {
Expand All @@ -389,46 +423,56 @@ int main() {
if (ImGui::Button(
load_json<std::string>(language, "button", "stop").c_str(),
ImVec2(load_json<Size>(config, "button")))) {
sampler.reset();
devices.clear();
deviceManager.clearDevices();
initDevices();
flagPaused = true;
}
ImGui::PopStyleColor(3);
// set_button_style_to(config, "standart");
}
if (!sampler.has_value()) {
if (flagPaused) {
ImGui::SameLine();

// Start / Zurücksetzen der Messung bei pausierter Messung
// mit anschließender Abfrage ob die alten Daten gespeichert
// werden sollen
if (sampler.has_value()) {
ImGui::SameLine();
set_button_style_to(config, "start");
if (ImGui::Button("Fortsetzen",
ImVec2(load_json<Size>(config, "button")))) {
flagPaused = false;
flagDataNotSaved = true;
}
ImGui::PopStyleColor(3);
ImGui::SameLine();

set_button_style_to(config, "stop");
if (ImGui::Button("Zurücksetzen",
ImVec2(load_json<Size>(config, "button")))) {
if (flagDataNotSaved) {
ImGui::OpenPopup("Zurücksetzen?");
} else {
sampler.reset();
devices.clear();
deviceManager.clearDevices();
captureData.clear();
flagPaused = true;
}
}
ImGui::PopStyleColor(3);
}
ImGui::SameLine();
if (ImGui::Button(
load_json<std::string>(language, "button", "save").c_str(),
ImVec2(load_json<Size>(config, "button")))) {
// savecontext = true;//Opens new overlay

ImGui::OpenPopup("Speichern der aufgenommenen Daten");
}
ImGui::SameLine();
ImGui::PushStyleColor(
ImGuiCol_Text, load_json<Color>(config, "text", "color", "inactive"));
// ImGui::FileBrowser fileBrowser;
if (ImGui::Button(
load_json<std::string>(language, "button", "analyse_data")
.c_str(),
ImVec2(load_json<Size>(config, "button")))) {
// fileBrowser.Open();
}
/*
//fileBrowser.Display();
if (fileBrowser.HasSelected()) {
// Hier kannst du auf die ausgewählten Dateien zugreifen
for (const auto &selectedFile : fileBrowser.GetSelected())
{ std::string filename = selectedFile.string();
// Verarbeite die ausgewählte Datei
// ...
}
fileBrowser.ClearSelected();
}
*/
ImGui::PopStyleColor();
ImGui::PushStyleColor(
ImGuiCol_Text, load_json<Color>(config, "text", "color", "normal"));
Expand Down Expand Up @@ -491,7 +535,7 @@ int main() {
// ImVec2(0.5f, 0.5f));

ImGui::Text("gefundene Geräte:");
if (ImGui::BeginListBox("##", ImVec2(1024, -1))) {
if (ImGui::BeginListBox("##deviceListBox", ImVec2(1024, -1))) {
auto doDevice = [&](auto &device, auto msg) {
auto &color = colorMap[device->getId().value()];
if (ImGui::ColorEdit3(
Expand Down Expand Up @@ -546,4 +590,4 @@ int main() {
while (window.run(render)) {
}
return 0;
}
}

0 comments on commit ea06431

Please sign in to comment.