From 7cce4c0da4e0e9592cac22ff7e238ee91b6683fb Mon Sep 17 00:00:00 2001 From: AKMaily Date: Thu, 24 Oct 2024 10:49:41 +0200 Subject: [PATCH] IN TESTING: Loading and Showing data in the Plot region --- src/LoadFiles.cpp | 50 +++++++++++++++++++++++++++++++++++++++-------- src/LoadFiles.hpp | 13 +++++++----- src/handler.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++ src/handler.hpp | 1 + src/main.cpp | 34 +------------------------------- src/style.cpp | 1 + 6 files changed, 99 insertions(+), 46 deletions(-) diff --git a/src/LoadFiles.cpp b/src/LoadFiles.cpp index d134bb66..ee1586f9 100644 --- a/src/LoadFiles.cpp +++ b/src/LoadFiles.cpp @@ -96,7 +96,6 @@ void externData::loadDataFromFile() { return; } - // Öffne die Datei std::ifstream file(filepath); if (!file.is_open()) { throw std::runtime_error("Error: File cant be opened " + filepath.string()); @@ -124,12 +123,11 @@ void externData::loadDataFromFile() { } if (units.size() < 2) { std::cout << "No units provided, standard units (V) and (s) are set" << std::endl; - units = {"s", "V"}; // Standardwerte setzen (s für Zeit, V für Spannung) + units = {"s", "V"}; // set standard units } } else { - // Falls die Zeile mit den Einheiten fehlt, setze Standardwerte std::cout << "No Units provided. Standard Units (V) and (s) are set" << std::endl; - units = {"s", "V"}; // Standardwerte setzen + units = {"s", "V"}; } double x = 0.0, y = 0.0; @@ -139,23 +137,20 @@ void externData::loadDataFromFile() { std::istringstream iss(line); if (isOmnAIScope) { - // OmniScope-Modus: Nur Y-Werte vorhanden, X-Werte basierend auf Sampling-Rate berechnen + // if old omniscope data x = index / sampling_rate; // X-Wert berechnen if (!(iss >> y)) { throw std::runtime_error("Error: Y-Values could not be read correctly"); } } else { - // Normaler Modus: X- und Y-Werte aus der Datei lesen if (!(iss >> x >> y)) { throw std::runtime_error("Error: Y and X-Values could not be read correctly"); } } - // Speichere die gelesenen Werte xValues.push_back(x); yValues.push_back(y); - // Erhöhe den Index für die nächste Berechnung (Sampling-Rate) bei OmniScope index++; } @@ -166,3 +161,42 @@ void externData::loadDataFromFile() { std::cout << "Data from file " << filepath.string() << " was loaded sucessfully\n"; } + +void filesList(std::vector &dataObjects) { // Show list of files in Devices Region + ImGui::BeginGroup(); + + if (!dataObjects.empty()) { + for (auto it = dataObjects.begin(); it != dataObjects.end(); ) { + externData& obj = *it; + + if (ImGui::Checkbox("##", &obj.loadChecked)) { + if (obj.loadChecked) { + obj.showData = true; + //TODO:: Filter if FFT and Plot a Histogram + + } else { + obj.showData = false; + } + } + + ImGui::SameLine(); + ImGui::TextUnformatted(obj.filepath.c_str()); + ImGui::SameLine(); + + //Deleting Loaded Data + if (ImGui::Button(appLanguage[Key::Reset])) { + it = dataObjects.erase(it); + } else { + ++it; + } + } + } + + ImGui::EndGroup(); +} + + +void addPlotFromFFTFile(externData &dataObj) { + +} + diff --git a/src/LoadFiles.hpp b/src/LoadFiles.hpp index 177d6e5b..99b00cdd 100644 --- a/src/LoadFiles.hpp +++ b/src/LoadFiles.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "languages.hpp" #include "../imgui-stdlib/imgui_stdlib.h" #include "../imgui-filebrowser/imfilebrowser.h" @@ -23,7 +24,7 @@ class externData{ std::vector xValues; std::vector yValues; std::filesystem::path filepath; - bool isOmnAIScope, loadChecked, isLoaded{false}; + bool isOmnAIScope, loadChecked{false}, isLoaded{false}, showData{false}; double sampling_rate = 0.0; externData(const std::filesystem::path&); @@ -31,15 +32,17 @@ class externData{ void loadDataFromFile(); - - //void filesList(std::vector &); // generates, shows and functionality of the filesList in the DeviceRegion - //void ShowPlot(); // alternative to AddPlotsFromFile for various .csv formats }; void generateLoadFilesMenu(std::vector &, std::vector &, bool &); -void loadMultipleExternFiles(std::vector &, std::vector &); +void loadMultipleExternFiles(std::vector &, std::vector &); + +void filesList(std::vector &); // generates, shows and functionality of the filesList in the DeviceRegion + +void addPlotFromFile(externData &); +void addPlotFromFFTFile(externData &); #endif \ No newline at end of file diff --git a/src/handler.cpp b/src/handler.cpp index 7b85681a..e862407b 100644 --- a/src/handler.cpp +++ b/src/handler.cpp @@ -92,6 +92,13 @@ void addPlots(const char *name, mainWindow &mWindow, ImPlot::PopStyleColor(); } else { + if(!mWindow.externDatas.empty()){ + for(externData& objData : mWindow.externDatas){ + if(objData.showData){ + addPlotFromFile(objData); + } + } + } // TODO: if bool areFilesLoading = false this , else AddPlotFromFile double x_min = std::numeric_limits::max(); @@ -438,4 +445,43 @@ void LoadedFiles::parseData(const std::string& line) { // Speichere das Paar in der Datenstruktur data.emplace_back(value1, value2); +} + +void addPlotFromFile(externData &dataObj) { + + //check and set axis + if (dataObj.units.size() < 2) { + std::cerr << "Error: Not enough units provided for axis labels." << std::endl; + return; + } + if (dataObj.units.size() > 2) { + std::cerr << "Error: To much units provided for axis labels." << std::endl; + return; + } + std::cout << dataObj.units[0].c_str() << std::endl; + std::cout << dataObj.units[1].c_str() << std::endl; + + ImPlot::SetupAxis(ImAxis_X1, dataObj.units[0].c_str()); + ImPlot::SetupAxis(ImAxis_Y1, dataObj.units[1].c_str()); + + // check data + if (dataObj.xValues.empty() || dataObj.yValues.empty()) { + std::cerr << "Error: xValues or yValues are empty." << std::endl; + return; + } + + if (dataObj.xValues.size() != dataObj.yValues.size()) { + std::cerr << "Error: Mismatched sizes of xValues and yValues." << std::endl; + return; + } + + // draw data + ImPlot::PushStyleColor(ImPlotCol_Fill, ImVec4{0.686f, 0.0f, 0.007f, 1.000f}); + ImPlot::SetNextLineStyle(ImVec4{0.686f, 0.0f, 0.007f, 1.000f}); + + ImPlot::PlotLine(dataObj.filepath.string().c_str(), + dataObj.xValues.data(), + dataObj.yValues.data(), + static_cast(dataObj.xValues.size()), 0, 0, sizeof(double)); + std::cout << "falsche funktion" << std::endl; } \ No newline at end of file diff --git a/src/handler.hpp b/src/handler.hpp index 4250b96d..b4ddf360 100644 --- a/src/handler.hpp +++ b/src/handler.hpp @@ -34,6 +34,7 @@ void set_inital_config(nlohmann::json &); void setupSW(mainWindow &); void rstSettings(const decltype(captureData) &); void AddPlotFromFile(fs::path &); +void addPlotFromFile(externData &); std::string trim(const std::string &); diff --git a/src/main.cpp b/src/main.cpp index 69272907..b6f610ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -93,43 +93,11 @@ int main() { ImGui::SameLine(); ImGui::Text(appLanguage[Key::Devices_found]); devicesList(mWindow.flagPaused); + filesList(mWindow.externDatas); // TODO:: Load File names // function:: filesCheckboxList(std::vector) // instead of captureData.emplace() --> externData[i].loadChecked = true; - if (!loadedFiles.empty()) { // if devices were successfully loaded from file - static std::map loadedFilesChkBxs; - for (auto it = loadedFiles.begin(); it != loadedFiles.end();) { - ImGui::PushID(&it->first); // make unique IDs - if (ImGui::Checkbox("##", &loadedFilesChkBxs[it->first].b)) - if (loadedFilesChkBxs[it->first].b) { // if checked - if (!captureData.contains(it->first)) { - captureData.emplace(it->first, it->second); - // set different colors for files data - if (!colorMap.contains(it->first)) { - ImPlot::PushColormap(ImPlotColormap_Dark); - auto color = - ImPlot::GetColormapColor((colorMap.size() % 7) + 1); - colorMap[it->first] = {color.x, color.y, color.z}; - ImPlot::PopColormap(); - } - } - } else - captureData.erase(it->first); - ImGui::SameLine(); - ImGui::TextUnformatted(loadedFilenames[it->first].c_str()); - ImGui::SameLine(); - if (ImGui::Button(appLanguage[Key::Reset])) { - captureData.erase(it->first); - loadedFilenames.erase(it->first); - loadedFilesChkBxs[it->first].b = false; - it = loadedFiles.erase(it); - mWindow.setAnalyzePath(""); - } else - it++; - ImGui::PopID(); - } // end of for-loop - } ImGui::EndChild(); // end child "Devicelist" ImGui::EndChild(); // end child "Right Side" ImGui::End(); diff --git a/src/style.cpp b/src/style.cpp index 3497344c..3ae99aaf 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -138,6 +138,7 @@ void SetDeviceMenuStyle() { style.Colors[ImGuiCol_FrameBg] = {0.9f, 0.9f, 0.9f, 1.0f}; style.Colors[ImGuiCol_FrameBgHovered] = {1.0f, 1.0f, 1.0f, 1.0f}; style.Colors[ImGuiCol_FrameBgActive] = {0.8f, 0.8f, 0.8f, 0.8f}; + style.Colors[ImGuiCol_Button] = {0.7f, 0.7f, 0.7f, 1.0f}; } namespace ImGui {