From f257617e99b7269610d783f19ed7877df4413018 Mon Sep 17 00:00:00 2001 From: AKMaily Date: Thu, 24 Oct 2024 16:54:25 +0200 Subject: [PATCH] Clean Up --- src/handler.cpp | 12 ++---------- src/handler.hpp | 2 +- src/loadingFiles.cpp | 26 ++++++++------------------ src/loadingFiles.hpp | 3 --- src/main.cpp | 23 ++++------------------- src/style.cpp | 41 ++++++++++++++++++++++++----------------- src/style.hpp | 5 +++-- 7 files changed, 42 insertions(+), 70 deletions(-) diff --git a/src/handler.cpp b/src/handler.cpp index 09f0e38e..200832ec 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -277,19 +277,13 @@ void set_inital_config(nlohmann::json &config) { config["text"]["active_language"] == "German" ? germanLan : englishLan; } -void rstSettings(const decltype(captureData) &loadedFiles) { +void rstSettings() { sampler.reset(); devices.clear(); savedFileNames.clear(); deviceManager.clearDevices(); plotAxes.clear(); - // erase all elements excpet loadedFiles - for (auto it = captureData.begin(); it != captureData.end();) { - if (!loadedFiles.contains(it->first)) - it = captureData.erase(it); - else - ++it; - } + captureData.clear(); } void setupSW(mainWindow &mWindow){ @@ -301,8 +295,6 @@ void setupSW(mainWindow &mWindow){ load_json(mWindow.config, "language") + ".json"); } -//TODO : Set this also up for saved OmniScope files - void AddPlotFromFile(fs::path &filePath) { // set object with chosen filePath diff --git a/src/handler.hpp b/src/handler.hpp index b4ddf360..0df18142 100644 --- a/src/handler.hpp +++ b/src/handler.hpp @@ -32,7 +32,7 @@ void set_config(mainWindow &); void set_json(mainWindow &); void set_inital_config(nlohmann::json &); void setupSW(mainWindow &); -void rstSettings(const decltype(captureData) &); +void rstSettings(); void AddPlotFromFile(fs::path &); void addPlotFromFile(externData &); diff --git a/src/loadingFiles.cpp b/src/loadingFiles.cpp index 8931efa3..f4c1eb15 100644 --- a/src/loadingFiles.cpp +++ b/src/loadingFiles.cpp @@ -12,7 +12,7 @@ void generateLoadFilesMenu(std::vector &externDataFilePat ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::SetItemDefaultFocus(); static ImGui::FileBrowser fileBrowser; - static std::vector pathArr; + static std::vector pathArr; // paths for the fileBrowser if (pathArr.empty()) pathArr.emplace_back(""); @@ -33,24 +33,22 @@ void generateLoadFilesMenu(std::vector &externDataFilePat fileBrowser.ClearSelected(); } - // Validierung des Dateipfads + // Validade path if (!path.empty()) { if (fs::path(path).extension() != ".csv") { // only accept .csv data ImGui::OpenPopup("Wrong File Type"); path.clear(); } else { if (std::find(externDataFilePaths.begin(), externDataFilePaths.end(), path) == externDataFilePaths.end()) { - // Füge den Pfad nur hinzu, wenn er nicht bereits vorhanden ist externDataFilePaths.emplace_back(path); } else { - std::cout << "Path " << path << " was already chosen.\n"; } } } ImGui::PopID(); } - if (ImGui::Button(" + ")) { + if (ImGui::Button(" + ")) { // for extra file pathArr.emplace_back(""); } @@ -65,7 +63,7 @@ void generateLoadFilesMenu(std::vector &externDataFilePat // Load Files if (ImGui::Button("Load Files")) { - loadMultipleExternFiles(externDataFilePaths, externDatas); + loadMultipleExternFiles(externDataFilePaths, externDatas); // Show files is implemented in filesList() pathArr.clear(); close = false; ImGui::CloseCurrentPopup(); @@ -103,8 +101,9 @@ void externData::loadDataFromFile() { std::string line; - bool firstLineIsData = false; // Flag, um zu überprüfen, ob die erste Zeile Werte enthält - bool secondLineIsData = false; // Flag, ob die zweite Zeile Werte enthält + // check for multiple data formats + bool firstLineIsData = false; + bool secondLineIsData = false; units.clear(); // Check for OmniScope in the first line or if it's data @@ -117,14 +116,10 @@ void externData::loadDataFromFile() { std::cout << "Old OmnAIScope file detected\n"; sampling_rate = 100000; // Set the sampling rate for the OmniScope format } - else if (std::getline(iss, unit, ',') && !std::isdigit(unit[0])) { - // Speichere den ersten Teil der Zeile + else if (std::getline(iss, unit, ',') && !std::isdigit(unit[0])) { // check if units are in first line std::string unit1 = unit; - - // Versuche, den zweiten Teil der Zeile zu lesen std::string unit2; if (std::getline(iss, unit2) && !std::isdigit(unit2[0])) { - // Wenn beide Einheiten weniger als oder genau 5 Zeichen haben if (unit1.length() <= 5 && unit2.length() <= 5) { units.push_back(unit1); units.push_back(unit2); @@ -197,16 +192,13 @@ void externData::loadDataFromFile() { index++; } - // Schließe die Datei file.close(); - // Bestätige, dass die Daten erfolgreich geladen wurden std::cout << "Data from file " << filepath.string() << " was loaded sucessfully\n"; } void filesList(std::vector &externDataFilePaths, std::vector &dataObjects) { // Show list of files in Devices Region - ImGui::BeginGroup(); int index = 0; if (!dataObjects.empty()) { @@ -243,8 +235,6 @@ void filesList(std::vector &externDataFilePaths, std::vec index++; } } - - ImGui::EndGroup(); } diff --git a/src/loadingFiles.hpp b/src/loadingFiles.hpp index 4b302091..6e41155c 100644 --- a/src/loadingFiles.hpp +++ b/src/loadingFiles.hpp @@ -31,9 +31,6 @@ class externData{ ~externData(); void loadDataFromFile(); - - //void ShowPlot(); // alternative to AddPlotsFromFile for various .csv formats - }; void generateLoadFilesMenu(std::vector &, std::vector &, bool &); diff --git a/src/main.cpp b/src/main.cpp index 01101e03..8387121f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,13 +10,6 @@ int main() { setupSW(mWindow); // Set up config and old language file - // temporary solution - // TODO:: Change loadedFiles from datatype Scope to a concrete Filetype - - // TODO:: Create Array std::vector externDatas - auto loadedFiles = captureData; - std::map loadedFilenames; - // main loop auto render = [&]() { std::call_once(mWindow.configFlag, set_inital_config, std::ref(mWindow.config)); @@ -40,7 +33,7 @@ int main() { ImGui::EndPopup(); } - set_side_menu(mWindow, loadedFiles, loadedFilenames); // style.cpp + set_side_menu(mWindow); // style.cpp ImGui::SameLine(); ImGui::BeginChild("Right Side", {0.f, 0.f}); @@ -48,7 +41,7 @@ int main() { if (sampler.has_value() && !mWindow.flagPaused) sampler->copyOut(captureData); - set_toolbar(mWindow, loadedFiles); // style.cpp + set_toolbar(mWindow); // style.cpp generatePopUpMenus(mWindow); // style.cpp @@ -85,18 +78,10 @@ int main() { ImGui::EndChild(); // end child Record Data ImGui::PopStyleVar(); PopPlotRegionColors(); - // ############################ Devicelist - SetDeviceMenuStyle(); - ImGui::Dummy({0.f, windowSize.y * .01f}); - ImGui::BeginChild("Devicelist"); - ImGui::Dummy({windowSize.x * .36f, 0.f}); - ImGui::SameLine(); - ImGui::Text(appLanguage[Key::Devices_found]); - devicesList(mWindow.flagPaused); - filesList(mWindow.externDataFilePaths, mWindow.externDatas); - ImGui::EndChild(); // end child "Devicelist" + set_devices_menu(mWindow); //Devicelist -> current data as well as loaded Files are presented here ImGui::EndChild(); // end child "Right Side" ImGui::End(); + }; ImGuiInstance window{1500, 800, fmt::format("{} {}", CMakeGitVersion::Target::Name, diff --git a/src/style.cpp b/src/style.cpp index 3ae99aaf..924ae339 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -249,9 +249,7 @@ bool LoadTextureFromHeader(unsigned char const *png_data, int png_data_len, return true; } -void set_side_menu(mainWindow &mWindow, - decltype(captureData) &loadedFiles, - std::map &loadedFilenames) { +void set_side_menu(mainWindow &mWindow) { // Variables auto windowSize{ImGui::GetIO().DisplaySize}; @@ -304,8 +302,7 @@ void set_side_menu(mainWindow &mWindow, deviceManager.clearDevices(); initDevices(); } - - static bool loadFile; + if (loaded_png[++PngRenderedCnt] && // load old files data, popup and data loading ImGui::ImageButtonWithText( (void *)(intptr_t)image_texture[PngRenderedCnt], @@ -368,7 +365,7 @@ void set_side_menu(mainWindow &mWindow, ImGui::EndChild(); } -void set_toolbar(mainWindow &mWindow, const decltype(captureData) &loadedFiles) { +void set_toolbar(mainWindow &mWindow) { // variable declaration static auto now = std::chrono::system_clock::now(); @@ -377,7 +374,6 @@ void set_toolbar(mainWindow &mWindow, const decltype(captureData) &loadedFiles) auto windowSize{ImGui::GetIO().DisplaySize}; static bool flagDataNotSaved = true; static decltype(captureData) liveDvcs; - static bool has_loaded_file; // begin Toolbar ############################################ ImGui::BeginChild("Buttonstripe", {-1.f, windowSize.y * .1f}, false, @@ -386,8 +382,7 @@ void set_toolbar(mainWindow &mWindow, const decltype(captureData) &loadedFiles) if (ImGui::BeginPopupModal(appLanguage[Key::Save_Recorded_Data], nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::SetItemDefaultFocus(); - saves_popup(mWindow.config, mWindow.language, now, now_time_t, now_tm, flagDataNotSaved, - has_loaded_file ? liveDvcs : captureData); + saves_popup(mWindow.config, mWindow.language, now, now_time_t, now_tm, flagDataNotSaved, liveDvcs); ImGui::EndPopup(); } // ############################ Popup Reset @@ -396,7 +391,7 @@ void set_toolbar(mainWindow &mWindow, const decltype(captureData) &loadedFiles) ImGui::SetItemDefaultFocus(); ImGui::Text(appLanguage[Key::Measure_not_saved]); if (ImGui::Button(appLanguage[Key::Continue_del])) { - rstSettings(loadedFiles); + rstSettings(); ImGui::CloseCurrentPopup(); } ImGui::SameLine(); @@ -497,7 +492,7 @@ void set_toolbar(mainWindow &mWindow, const decltype(captureData) &loadedFiles) ImGui::OpenPopup(appLanguage[Key::Reset_q]); } else { mWindow.LOADANALYSISDATA = false; - rstSettings(loadedFiles); + rstSettings(); mWindow.flagPaused = true; } } @@ -517,15 +512,9 @@ void set_toolbar(mainWindow &mWindow, const decltype(captureData) &loadedFiles) ImVec2(image_width[PngRenderedCnt] * iconsSacle, image_height[PngRenderedCnt] * iconsSacle))) { liveDvcs.clear(); // get updated live devices for saving - if (!loadedFiles.empty()) { - has_loaded_file = true; for (const auto &[device, values] : captureData) - if (!loadedFiles.contains(device)) liveDvcs.emplace( device, values); // extract live devices (the little overhead) - } else - has_loaded_file = false; - if (sampler.has_value()) ImGui::OpenPopup(appLanguage[Key::Save_Recorded_Data]); else @@ -550,6 +539,24 @@ void set_toolbar(mainWindow &mWindow, const decltype(captureData) &loadedFiles) ImGui::EndChild(); // end child "Buttonstripe" } +void set_devices_menu(mainWindow &mWindow){ + auto windowSize{ImGui::GetIO().DisplaySize}; + SetDeviceMenuStyle(); + ImGui::Dummy({0.f, windowSize.y * .01f}); + ImGui::BeginChild("Devicelist"); + ImGui::Dummy({windowSize.x * .36f, 0.f}); + ImGui::SameLine(); + ImGui::Text(appLanguage[Key::Devices_found]); + ImGui::BeginGroup(); + devicesList(mWindow.flagPaused); + ImGui::EndGroup(); + ImGui::SameLine(); + ImGui::BeginGroup(); + filesList(mWindow.externDataFilePaths, mWindow.externDatas); + ImGui::EndGroup(); + ImGui::EndChild(); // end child "Devicelist" +} + void PopupStyleEditor() { // For Development ImGuiStyle &style = ImGui::GetStyle(); ImPlotStyle &styleImPlot = ImPlot::GetStyle(); diff --git a/src/style.hpp b/src/style.hpp index cf291f29..3379249c 100644 --- a/src/style.hpp +++ b/src/style.hpp @@ -17,8 +17,9 @@ inline constexpr ImVec4 normColStyle{0.1f, 0.1f, 0.1f, 1.f}; void SetupImGuiStyle(bool, float); void set_button_style_to(const nlohmann::json &, const std::string &); bool LoadTextureFromHeader(unsigned char const *, int, GLuint *, int *, int *); -void set_side_menu(mainWindow &, decltype(captureData) &, std::map &); -void set_toolbar(mainWindow &, const decltype(captureData) &); +void set_side_menu(mainWindow &); +void set_toolbar(mainWindow &); +void set_devices_menu(mainWindow&); void PopupStyleEditor(); void PushPlotRegionColors(); void PopPlotRegionColors();