Skip to content

Commit

Permalink
Code Improvements, IN TESTING
Browse files Browse the repository at this point in the history
  • Loading branch information
AKMaily committed Oct 3, 2024
1 parent 0115666 commit e5a69c1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 44 deletions.
82 changes: 52 additions & 30 deletions src/analyze_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,31 @@ void generate_analyze_menu( // generate the whole menu: Startpoint
ImGuiWindowFlags_AlwaysAutoResize)) {

// Frame
if(stateManager.getState() == State::Reset){
if(stateManager.getState() == State::RESET){
stateManager.reset(stateManager);
}
ImGui::Text(appLanguage[Key::AnalyzeData]);
stateManager.selectDataType(stateManager, open_analyze_menu, captureData); // select if Data should be loaded from File or from a current measurement
stateManager.selectData(stateManager, captureData); //select which device or which file the data should be loaded from
stateManager.loadData(stateManager, captureData);
stateManager.setMetaData(); // here there could be an array that is requested before from the API that loads the correct metadata files, currently no MetaData needed

// Send Data
if(ImGui::Button(appLanguage[Key::Send])){
stateManager.loadAndSendData(stateManager, captureData); // One function because of the loading bar
}

// Close PopUp
if (ImGui::Button(appLanguage[Key::Back])) {
stateManager.reset(stateManager);
open_analyze_menu = false;
ImGui::CloseCurrentPopup();
}
}

ImGui::EndPopup();
}

void AnalyzeStateManager::setState(State state) {
this->currentState = state;
std::cout << "Changed state" << std::endl;
}

State AnalyzeStateManager::getState() { return this->currentState; }
Expand All @@ -54,29 +57,35 @@ void AnalyzeStateManager::selectDataType(
ImGui::OpenPopup(appLanguage[Key::WvForms_warning],
ImGuiPopupFlags_NoOpenOverExistingPopup);
radioButtonCurrentData = false;
} else {
stateManager.setState(State::CurrentDataSelected);
stateManager.setState(State::NODATA);
} else if (radioButtonCurrentData)
{
stateManager.setState(State::CURRENTDATAWANTED);
}
else stateManager.setState(State::NODATA);
}

// OR select a File from Browser
if (ImGui::RadioButton(appLanguage[Key::Wv_from_file], radioButtonFileData)){
radioButtonFileData = !radioButtonFileData;
radioButtonCurrentData = false;
stateManager.setState(State::FileDataSelected);
if (radioButtonFileData){
stateManager.setState(State::FILEDATAWANTED);}
else stateManager.setState(State::NODATA);
}

info_popup(appLanguage[Key::WvForms_warning], appLanguage[Key::No_wave_made]);
}

void AnalyzeStateManager::selectData(AnalyzeStateManager &stateManager, const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &captureData) {
// Select Device from which to get the data, else select a file from which data can be loaded
if(stateManager.getState() == State::CurrentDataSelected){
if(stateManager.getState() == State::CURRENTDATAWANTED){
if(ImGui::BeginCombo("##ComboDevice", "Devices & Waveforms Menu")){
stateManager.selectCurrentDevice(captureData);
stateManager.selectCurrentDevice(stateManager, captureData);
ImGui::EndCombo();
}
}
else if(stateManager.getState() == State::FileDataSelected){
else if(stateManager.getState() == State::FILEDATAWANTED){
ImGui::InputTextWithHint("##inputLabel", appLanguage[Key::Csv_file],
&fileNameBuf, ImGuiInputTextFlags_ReadOnly);
if(ImGui::Button(appLanguage[Key::Browse])) {
Expand All @@ -90,12 +99,13 @@ void AnalyzeStateManager::selectData(AnalyzeStateManager &stateManager, const st
if(fs::path(AnalyzeFileBrowser.GetSelected().string()).extension() == ".csv"){
fileNameBuf = AnalyzeFileBrowser.GetSelected().string();
AnalyzeFileBrowser.ClearSelected();
stateManager.setState(State::FILEDATASELECTED);
}
else {
ImGui::OpenPopup(appLanguage[Key::Wrong_file_warning],
ImGuiPopupFlags_NoOpenOverExistingPopup);
AnalyzeFileBrowser.ClearSelected();
stateManager.setState(State::Reset);
stateManager.setState(State::RESET);
}
}
}
Expand All @@ -104,46 +114,58 @@ void AnalyzeStateManager::selectData(AnalyzeStateManager &stateManager, const st
appLanguage[Key::Wrong_file_type]);
}

void AnalyzeStateManager::loadData(AnalyzeStateManager &stateManager, const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &captureData){};
void AnalyzeStateManager::loadAndSendData(AnalyzeStateManager &stateManager, const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &captureData){
loadData(stateManager, captureData); // The data will be loaded into a json file
//sendData() from sendData.hpp on the Json.dump() output
}

void AnalyzeStateManager::loadData(AnalyzeStateManager &stateManager, const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &captureData){
if(stateManager.getState() == State::CURRENTDATASELECTED){
auto selectedDevice(captureData.find(selectedDeviceId));
if(selectedDevice != captureData.end()){
//TODO Load Data
}

}
else if (stateManager.getState() == State::FILEDATASELECTED){

}

};

void AnalyzeStateManager::reset(AnalyzeStateManager &stateManager) {
radioButtonCurrentData = false;
radioButtonFileData = false;
stateManager.setState(State::NoDataSelected);
stateManager.setState(State::NODATA);

}

void AnalyzeStateManager::setMetaData() {
std::cout << "Not used" << std::endl;
void AnalyzeStateManager::setMetaData() {
// will be implemented when there are analysis where Metadata is needed
}
void AnalyzeStateManager::clearMetaData() {
std::cout << "Not used" << std::endl;
// will be implemented when there are analysis where Metadata is needed
}

// extra functions:

void AnalyzeStateManager::selectCurrentDevice( const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &captureData) {
for(const auto &[device, values] : captureData){
if(ImGui::Checkbox(device.serial.c_str(), &DeviceChecked)){
void AnalyzeStateManager::selectCurrentDevice( AnalyzeStateManager &stateManager, const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &captureData) {
for(const auto &[deviceId, values] : captureData){
if(ImGui::Checkbox(deviceId.serial.c_str(), &DeviceChecked)){
if(DeviceChecked){
selectedDevice = device;
std::cout << "Device selected:" << device.serial.c_str() << std::endl;
selectedDeviceId = deviceId;
stateManager.setState(State::CURRENTDATASELECTED);
std::cout << "Device selected:" << deviceId.serial.c_str() << std::endl;
}
else {
selectedDevice = {};
std::cout << "Device Changed:" << device.serial.c_str() << std::endl;
selectedDeviceId = {};
stateManager.setState(State::CURRENTDATAWANTED);
std::cout << "Device Changed:" << deviceId.serial.c_str() << 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;
}
30 changes: 16 additions & 14 deletions src/analyze_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// extra boolean references for the RadioButtons

static bool radioButtonCurrentData{false}, radioButtonFileData{false}, DeviceChecked{false};

Check warning on line 17 in src/analyze_data.hpp

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-C++ CI

‘DeviceChecked’ defined but not used [-Wunused-variable]

Check warning on line 17 in src/analyze_data.hpp

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-C++ CI

‘radioButtonFileData’ defined but not used [-Wunused-variable]

Check warning on line 17 in src/analyze_data.hpp

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-C++ CI

‘radioButtonCurrentData’ defined but not used [-Wunused-variable]
static Omniscope::Id selectedDevice{};
static Omniscope::Id selectedDeviceId{};
static ImGui::FileBrowser AnalyzeFileBrowser;
static std::string fileNameBuf;
static std::string fileNameBuf; // path for a chosen file to load data from

// declare functions and classes

Expand All @@ -27,21 +27,23 @@ void generate_analyze_menu(

// Menustates
enum class State {
NoDataSelected,
FileDataSelected,
FileDataLoaded,
CurrentDataSelected,
CurrentDataLoaded,
DataWasSend,
Reset
NODATA,
FILEDATAWANTED,
FILEDATASELECTED,
FILEDATALOADED,
CURRENTDATAWANTED,
CURRENTDATASELECTED,
CURRENTDATALOADED,
DATAWASSEND,
RESET
};

class AnalyzeStateManager {
public:
AnalyzeStateManager() { currentState = State::NoDataSelected; }
AnalyzeStateManager() { currentState = State::NODATA; }
~AnalyzeStateManager() = default;

void setState(State state = State::NoDataSelected);
void setState(State state = State::NODATA);
State getState();

void selectDataType(
Expand All @@ -50,16 +52,16 @@ class AnalyzeStateManager {
void selectData(AnalyzeStateManager &, const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &);
void loadData(AnalyzeStateManager &, const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &);

void loadAndSendData(AnalyzeStateManager &, const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &);

void reset(AnalyzeStateManager &);

void setMetaData();
void clearMetaData();

// extra functions:

void selectCurrentDevice(const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &);
void selectFileData();
void checkFileFormat();
void selectCurrentDevice(AnalyzeStateManager &, const std::map<Omniscope::Id, std::vector<std::pair<double, double>>> &);

void writeAnalysisAnswerIntoFile();

Expand Down

0 comments on commit e5a69c1

Please sign in to comment.