From aa8d66e5da34fb34ddcfacbb10ac6aa8838a13a2 Mon Sep 17 00:00:00 2001 From: milek7 Date: Mon, 25 Mar 2019 01:12:19 +0100 Subject: [PATCH] recording --- CMakeLists.txt | 1 + driveruilayer.cpp | 2 + driveruilayer.h | 2 + widgets/map.cpp | 6 +-- widgets/trainingcard.cpp | 110 +++++++++++++++++++++++++++++++++++++++ widgets/trainingcard.h | 30 +++++++++++ 6 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 widgets/trainingcard.cpp create mode 100644 widgets/trainingcard.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7db8b786..6247d4df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,6 +129,7 @@ set(SOURCES "widgets/popup.cpp" "widgets/time.cpp" "widgets/vehicleparams.cpp" +"widgets/trainingcard.cpp" "ref/glad/src/glad.c" diff --git a/driveruilayer.cpp b/driveruilayer.cpp index 3546e88c..d522a115 100644 --- a/driveruilayer.cpp +++ b/driveruilayer.cpp @@ -28,6 +28,7 @@ driver_ui::driver_ui() { add_external_panel( &m_debugpanel ); add_external_panel( &m_transcriptspanel ); + add_external_panel( &m_trainingcardpanel ); add_external_panel( &m_vehiclelist ); add_external_panel( &m_timepanel ); add_external_panel( &m_mappanel ); @@ -59,6 +60,7 @@ void driver_ui::render_menu_contents() { ImGui::MenuItem(m_debugpanel.name().c_str(), "F12", &m_debugpanel.is_open); ImGui::MenuItem(m_mappanel.name().c_str(), "Tab", &m_mappanel.is_open); ImGui::MenuItem(m_vehiclelist.name().c_str(), nullptr, &m_vehiclelist.is_open); + ImGui::MenuItem(m_trainingcardpanel.name().c_str(), nullptr, &m_trainingcardpanel.is_open); if (ImGui::MenuItem(m_timepanel.name().c_str())) m_timepanel.open(); diff --git a/driveruilayer.h b/driveruilayer.h index be71207e..a2b7556c 100644 --- a/driveruilayer.h +++ b/driveruilayer.h @@ -17,6 +17,7 @@ http://mozilla.org/MPL/2.0/. #include "widgets/vehicleparams.h" #include "widgets/map.h" #include "widgets/time.h" +#include "widgets/trainingcard.h" class driver_ui : public ui_layer { @@ -55,6 +56,7 @@ private: timetable_panel m_timetablepanel { "Timetable", false }; debug_panel m_debugpanel { "Debug Data", false }; transcripts_panel m_transcriptspanel { "Transcripts", true }; // voice transcripts + trainingcard_panel m_trainingcardpanel; bool m_paused { false }; bool m_pause_modal_opened { false }; diff --git a/widgets/map.cpp b/widgets/map.cpp index f30cefc3..3a0880ad 100644 --- a/widgets/map.cpp +++ b/widgets/map.cpp @@ -194,11 +194,11 @@ void ui::map_panel::render_contents() static enum { MODE_MANUAL = 0, MODE_CAMERA, MODE_VEHICLE } mode = MODE_MANUAL; - ImGui::RadioButton("manual", (int *)&mode, 0); + ImGui::RadioButton("Pan", (int *)&mode, 0); ImGui::SameLine(); - ImGui::RadioButton("cam", (int *)&mode, 1); + ImGui::RadioButton("Follow camera", (int *)&mode, 1); ImGui::SameLine(); - ImGui::RadioButton("vehicle", (int *)&mode, 2); + ImGui::RadioButton("Follow vehicle", (int *)&mode, 2); ImVec2 surface_size_im = ImGui::GetContentRegionAvail(); glm::vec2 surface_size(surface_size_im.x, surface_size_im.y); diff --git a/widgets/trainingcard.cpp b/widgets/trainingcard.cpp new file mode 100644 index 00000000..f2ec5ce2 --- /dev/null +++ b/widgets/trainingcard.cpp @@ -0,0 +1,110 @@ +#include "stdafx.h" +#include "widgets/trainingcard.h" + +trainingcard_panel::trainingcard_panel() + : ui_panel("Raport szkolenia", false) +{ + //size = {400, 500}; + clear(); +} + +void trainingcard_panel::clear() +{ + start_time_wall.reset(); + state.store(0); + + place.clear(); + trainee_name.clear(); + instructor_name.clear(); + remarks.clear(); + + place.resize(256, 0); + trainee_name.resize(256, 0); + instructor_name.resize(256, 0); + remarks.resize(4096, 0); +} + +void trainingcard_panel::save_thread_func() +{ + std::tm *tm = std::localtime(&(*start_time_wall)); + std::string rep = std::to_string(tm->tm_year + 1900) + std::to_string(tm->tm_mon + 1) + std::to_string(tm->tm_mday) + + std::to_string(tm->tm_hour) + std::to_string(tm->tm_min) + "_" + trainee_name + "_" + instructor_name; + state.store(EndRecording(rep)); +} + +void trainingcard_panel::render_contents() +{ + if (ImGui::BeginPopupModal("Zapisywanie danych")) { + ImGui::SetWindowSize(ImVec2(-1, -1)); + int s = state.load(); + + if (s == 1) { + ImGui::CloseCurrentPopup(); + clear(); + } + + if (s < 1) { + if (s == 0) + ImGui::TextUnformatted("Error occured please contact with administrator!"); + if (s == -1) + ImGui::TextUnformatted("The recording of the training has not been archived, please do not start the next training before manually archiving the file!"); + + if (ImGui::Button("OK")) { + ImGui::CloseCurrentPopup(); + clear(); + } + } + + if (s == 2) + ImGui::TextUnformatted(u8"Proszę czekać, trwa archiwizacja nagrania..."); + + ImGui::EndPopup(); + + return; + } + + if (start_time_wall) { + std::tm *tm = std::localtime(&(*start_time_wall)); + std::string rep = u8"Czas rozpoczęcia: " + std::to_string(tm->tm_year + 1900) + "-" + std::to_string(tm->tm_mon + 1) + "-" + std::to_string(tm->tm_mday) + + " " + std::to_string(tm->tm_hour) + ":" + std::to_string(tm->tm_min); + ImGui::TextUnformatted(rep.c_str()); + } + + ImGui::TextUnformatted("Miejsce:"); + ImGui::SameLine(); + ImGui::InputText("##place", &place[0], place.size()); + + ImGui::TextUnformatted("Szkolony:"); + ImGui::SameLine(); + ImGui::InputText("##trainee", &trainee_name[0], trainee_name.size()); + + ImGui::TextUnformatted("Instruktor:"); + ImGui::SameLine(); + ImGui::InputText("##instructor", &instructor_name[0], instructor_name.size()); + + /* + ImGui::TextUnformatted("Uwagi"); + ImGui::InputTextMultiline("##remarks", &remarks[0], remarks.size(), ImVec2(-1.0f, 200.0f)); + */ + + if (!start_time_wall) { + if (ImGui::Button("Rozpocznij szkolenie")) { + start_time_wall = std::time(nullptr); + + int ret = StartRecording(); + if (ret != 1) { + state.store(ret); + ImGui::OpenPopup("Zapisywanie danych"); + } + } + } + else { + if (ImGui::Button(u8"Zakończ szkolenie")) { + state.store(2); + if (save_thread.joinable()) + save_thread.join(); + save_thread = std::thread(&trainingcard_panel::save_thread_func, this); + ImGui::OpenPopup("Zapisywanie danych"); + } + } +} diff --git a/widgets/trainingcard.h b/widgets/trainingcard.h new file mode 100644 index 00000000..5b7890e1 --- /dev/null +++ b/widgets/trainingcard.h @@ -0,0 +1,30 @@ +#include "uilayer.h" + +class trainingcard_panel : public ui_panel +{ + std::string place; + std::string trainee_name; + std::string instructor_name; + std::string remarks; + + std::optional start_time_wall; + + std::thread save_thread; + std::atomic state; + + void save_thread_func(); + void clear(); + + virtual int StartRecording( void ) { + return 1; + } + virtual int EndRecording( std::string training_identifier ) { + std::this_thread::sleep_for(std::chrono::duration(5.0f)); + return 1; + } + + public: + trainingcard_panel(); + + void render_contents() override; +};