Skip to content

Commit

Permalink
Clean Up
Browse files Browse the repository at this point in the history
  • Loading branch information
AKMaily committed Oct 24, 2024
1 parent 253c1c1 commit f257617
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 70 deletions.
12 changes: 2 additions & 10 deletions src/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -301,8 +295,6 @@ void setupSW(mainWindow &mWindow){
load_json<std::string>(mWindow.config, "language") + ".json");
}

//TODO : Set this also up for saved OmniScope files

void AddPlotFromFile(fs::path &filePath) {

// set object with chosen filePath
Expand Down
2 changes: 1 addition & 1 deletion src/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &);

Expand Down
26 changes: 8 additions & 18 deletions src/loadingFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void generateLoadFilesMenu(std::vector<std::filesystem::path> &externDataFilePat
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SetItemDefaultFocus();
static ImGui::FileBrowser fileBrowser;
static std::vector<std::string> pathArr;
static std::vector<std::string> pathArr; // paths for the fileBrowser

if (pathArr.empty())
pathArr.emplace_back("");
Expand All @@ -33,24 +33,22 @@ void generateLoadFilesMenu(std::vector<std::filesystem::path> &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("");
}

Expand All @@ -65,7 +63,7 @@ void generateLoadFilesMenu(std::vector<std::filesystem::path> &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();
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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<std::filesystem::path> &externDataFilePaths, std::vector<externData> &dataObjects) { // Show list of files in Devices Region
ImGui::BeginGroup();
int index = 0;

if (!dataObjects.empty()) {
Expand Down Expand Up @@ -243,8 +235,6 @@ void filesList(std::vector<std::filesystem::path> &externDataFilePaths, std::vec
index++;
}
}

ImGui::EndGroup();
}


Expand Down
3 changes: 0 additions & 3 deletions src/loadingFiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class externData{
~externData();

void loadDataFromFile();

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

};

void generateLoadFilesMenu(std::vector<std::filesystem::path> &, std::vector<externData> &, bool &);
Expand Down
23 changes: 4 additions & 19 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<externData> externDatas
auto loadedFiles = captureData;
std::map<Omniscope::Id, std::string> loadedFilenames;

// main loop
auto render = [&]() {
std::call_once(mWindow.configFlag, set_inital_config, std::ref(mWindow.config));
Expand All @@ -40,15 +33,15 @@ 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});

if (sampler.has_value() && !mWindow.flagPaused)
sampler->copyOut(captureData);

set_toolbar(mWindow, loadedFiles); // style.cpp
set_toolbar(mWindow); // style.cpp

generatePopUpMenus(mWindow); // style.cpp

Expand Down Expand Up @@ -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,
Expand Down
41 changes: 24 additions & 17 deletions src/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Omniscope::Id, std::string> &loadedFilenames) {
void set_side_menu(mainWindow &mWindow) {

// Variables
auto windowSize{ImGui::GetIO().DisplaySize};
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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
Expand All @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Omniscope::Id, std::string> &);
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();
Expand Down

0 comments on commit f257617

Please sign in to comment.