diff --git a/src/analyze_data.cpp b/src/analyze_data.cpp index 5e845c6e..2a3cc6f5 100644 --- a/src/analyze_data.cpp +++ b/src/analyze_data.cpp @@ -1,78 +1,105 @@ #include "analyze_data.hpp" -void generate_analyze_menu(bool &open_analyze_menu){ +void generate_analyze_menu( // generate the whole menu: Startpoint + bool &open_analyze_menu, + const std::map>> + &captureData) { + // Initialize AnalyzeStateManager - // Initialize AnalyzeStateManager + static AnalyzeStateManager stateManager; + // generate the PopUpMenu - static AnalyzeStateManager stateManager; - - // generate the PopUpMenu + ImGui::OpenPopup(appLanguage[Key::AnalyzeData]); - ImGui::OpenPopup(appLanguage[Key::AnalyzeData]); + if (ImGui::BeginPopupModal(appLanguage[Key::AnalyzeData], nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { - if(ImGui::BeginPopupModal(appLanguage[Key::AnalyzeData], nullptr, ImGuiWindowFlags_AlwaysAutoResize)){ + // Frame + ImGui::Text(appLanguage[Key::AnalyzeData]); - ImGui::Text(appLanguage[Key::AnalyzeData]); + // select Data from File or current Data + stateManager.selectData(stateManager, open_analyze_menu, captureData); + } - if(ImGui::RadioButton(appLanguage[Key::Usr_curnt_wave], radioButtonCurrentData)){ - radioButtonCurrentData = !radioButtonCurrentData; - stateManager.setState(State::CurrentDataSelected); - } + // Close PopUp + if (ImGui::Button(appLanguage[Key::Back])) { + open_analyze_menu = false; + ImGui::CloseCurrentPopup(); + } - } + ImGui::EndPopup(); +} +void AnalyzeStateManager::setState(State state) { + this->currentState = state; + std::cout << "Changed state" << std::endl; +} - //Close PopUp - if (ImGui::Button(appLanguage[Key::Back])) { - open_analyze_menu = false; - ImGui::CloseCurrentPopup(); +State AnalyzeStateManager::getState() { return this->currentState; } + +void AnalyzeStateManager::selectData( + AnalyzeStateManager &stateManager, bool &open_analyze_menu, + const std::map>> + &captureData) { + + // Select Current Wave + if (ImGui::RadioButton(appLanguage[Key::Usr_curnt_wave], + radioButtonCurrentData)) { + radioButtonCurrentData = !radioButtonCurrentData; + // Check for current measurement, else error Popup + if (!captureData.size()) { + ImGui::OpenPopup(appLanguage[Key::WvForms_warning], + ImGuiPopupFlags_NoOpenOverExistingPopup); + radioButtonCurrentData = false; + } else { + stateManager.setState(State::CurrentDataSelected); + if(ImGui::BeginCombo("##ComboDevice", "Devices & Waveforms Menu")){ //choose the device from which the data is taken + stateManager.selectCurrentDevice(captureData); + } } + } - ImGui::EndPopup(); + // Else select File from Browser + // Default info popup for rendering + info_popup(appLanguage[Key::WvForms_warning], appLanguage[Key::No_wave_made]); } +void AnalyzeStateManager::loadData() { std::cout << "Not used" << std::endl; } +void AnalyzeStateManager::reset() { std::cout << "Not used" << std::endl; } - void AnalyzeStateManager::setState(State state){ - - this->currentState= state ; - std::cout << "Changed state" << std::endl; - } - State AnalyzeStateManager::getState(){ - return this->currentState; - } - - void AnalyzeStateManager::selectData(){ - std::cout << "Not used" << std::endl; - } - void AnalyzeStateManager::loadData(){ - std::cout << "Not used" << std::endl; - } - - void AnalyzeStateManager::reset(){ - std::cout << "Not used" << std::endl; - } +void AnalyzeStateManager::setMetaData() { + std::cout << "Not used" << std::endl; +} +void AnalyzeStateManager::clearMetaData() { + std::cout << "Not used" << std::endl; +} - void AnalyzeStateManager::setMetaData(){ - std::cout << "Not used" << std::endl; - } - void AnalyzeStateManager::clearMetaData(){ - std::cout << "Not used" << std::endl; +// extra functions: + +void AnalyzeStateManager::selectCurrentDevice( const std::map>> &captureData) { + for(const auto &[device, values] : captureData){ + if(ImGui::Checkbox(device.serial.c_str(), &DeviceChecked)){ + if(DeviceChecked){ + selectedDevice = device; + std::cout << "Device selected:" << device.serial.c_str() << std::endl; + } + else { + selectedDevice = {}; + std::cout << "Device Changed:" << device.serial.c_str() << std::endl; + } } + } +} - // extra functions: - - void AnalyzeStateManager::selectCurrentDevice(){ - std::cout << "Not used" << std::endl; - } - void AnalyzeStateManager::selectFileData(){ - std::cout << "Not used" << std::endl; - } - void AnalyzeStateManager::checkFileFormat(){ - std::cout << "Not used" << std::endl; - } +void AnalyzeStateManager::selectFileData() { + std::cout << "Not used" << std::endl; +} +void AnalyzeStateManager::checkFileFormat() { + std::cout << "Not used" << std::endl; +} - void AnalyzeStateManager::writeAnalysisAnswerIntoFile(){ - std::cout << "Not used" << std::endl; - } +void AnalyzeStateManager::writeAnalysisAnswerIntoFile() { + std::cout << "Not used" << std::endl; +} diff --git a/src/analyze_data.hpp b/src/analyze_data.hpp index 226b1027..ae10145d 100644 --- a/src/analyze_data.hpp +++ b/src/analyze_data.hpp @@ -12,58 +12,55 @@ #include "sendData.hpp" #include "../imgui-stdlib/imgui_stdlib.h" #include "jasonhandler.hpp" +// extra boolean references for the RadioButtons +static bool radioButtonCurrentData{false}, radioButtonFileData{false}, DeviceChecked{false}; +static Omniscope::Id selectedDevice{}; - // extra boolean references for the RadioButtons +// declare functions and classes - static bool radioButtonCurrentData{false}, radioButtonFileData{false}; +void generate_analyze_menu( + bool &, + const std::map>> &); - -// declare functions and classes - -void generate_analyze_menu(bool &); - - -// Menustates +// Menustates enum class State { - NoDataSelected, - FileDataSelected, - FileDataLoaded, - CurrentDataSelected, - CurrentDataLoaded, - DataWasSend, - Reset -}; - -class AnalyzeStateManager{ -public: - AnalyzeStateManager(){ - currentState = State::NoDataSelected; - } - ~AnalyzeStateManager() = default; - - void setState(State state = State::NoDataSelected); - State getState(); + NoDataSelected, + FileDataSelected, + FileDataLoaded, + CurrentDataSelected, + CurrentDataLoaded, + DataWasSend, + Reset +}; - void selectData(); - void loadData(); +class AnalyzeStateManager { +public: + AnalyzeStateManager() { currentState = State::NoDataSelected; } + ~AnalyzeStateManager() = default; - void reset(); + void setState(State state = State::NoDataSelected); + State getState(); - void setMetaData(); - void clearMetaData(); + void selectData( + AnalyzeStateManager &, bool &, + const std::map>> &); + void loadData(); - // extra functions: + void reset(); - void selectCurrentDevice(); - void selectFileData(); - void checkFileFormat(); + void setMetaData(); + void clearMetaData(); - void writeAnalysisAnswerIntoFile(); + // extra functions: + void selectCurrentDevice(const std::map>> &); + void selectFileData(); + void checkFileFormat(); -private: + void writeAnalysisAnswerIntoFile(); - State currentState; - const std::map>> data; +private: + State currentState; + const std::map>> data; }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 12d05135..07cab6e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,7 +82,7 @@ int main() { // Generate analyze data popup if (open_analyze_menu) - generate_analyze_menu(open_analyze_menu); + generate_analyze_menu(open_analyze_menu, captureData); // ############################ addPlots("Recording the data", ...) ImGui::Dummy({0.f, windowSize.y * .01f});