Skip to content

Commit

Permalink
IN TESTING: Loading and Showing data in the Plot region
Browse files Browse the repository at this point in the history
  • Loading branch information
AKMaily committed Oct 24, 2024
1 parent 959a3f5 commit 7cce4c0
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 46 deletions.
50 changes: 42 additions & 8 deletions src/LoadFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand All @@ -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++;
}

Expand All @@ -166,3 +161,42 @@ void externData::loadDataFromFile() {
std::cout << "Data from file " << filepath.string() << " was loaded sucessfully\n";
}


void filesList(std::vector<externData> &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) {

}

13 changes: 8 additions & 5 deletions src/LoadFiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <map>
#include <filesystem>
#include <imgui.h>
#include <implot.h>
#include "languages.hpp"
#include "../imgui-stdlib/imgui_stdlib.h"
#include "../imgui-filebrowser/imfilebrowser.h"
Expand All @@ -23,23 +24,25 @@ class externData{
std::vector<double> xValues;
std::vector<double> 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&);
~externData();

void loadDataFromFile();


//void filesList(std::vector<externData> &); // generates, shows and functionality of the filesList in the DeviceRegion

//void ShowPlot(); // alternative to AddPlotsFromFile for various .csv formats

};

void generateLoadFilesMenu(std::vector<std::filesystem::path> &, std::vector<externData> &, bool &);

void loadMultipleExternFiles(std::vector<std::filesystem::path> &, std::vector<externData> &);
void loadMultipleExternFiles(std::vector<std::filesystem::path> &, std::vector<externData> &);

void filesList(std::vector<externData> &); // generates, shows and functionality of the filesList in the DeviceRegion

void addPlotFromFile(externData &);
void addPlotFromFFTFile(externData &);

#endif
46 changes: 46 additions & 0 deletions src/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>::max();
Expand Down Expand Up @@ -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<int>(dataObj.xValues.size()), 0, 0, sizeof(double));
std::cout << "falsche funktion" << std::endl;
}
1 change: 1 addition & 0 deletions src/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &);

Expand Down
34 changes: 1 addition & 33 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<externData>)
// instead of captureData.emplace() --> externData[i].loadChecked = true;
if (!loadedFiles.empty()) { // if devices were successfully loaded from file
static std::map<Omniscope::Id, BoolWrapper> 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();
Expand Down
1 change: 1 addition & 0 deletions src/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7cce4c0

Please sign in to comment.