diff --git a/common/model-views.cpp b/common/model-views.cpp index ccd1b964db..8dd109b0be 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -4949,7 +4949,9 @@ namespace rs2 ux_window& window, std::string& error_message, viewer_model& viewer, - bool update_read_only_options) + bool update_read_only_options, + bool load_json_if_streaming, + json_loading_func json_loading) { const float panel_height = 40.f; auto panel_pos = ImGui::GetCursorPos(); @@ -5152,26 +5154,33 @@ namespace rs2 std::string upload_button_name = to_string() << textual_icons::upload << "##" << id; ImGui::PushStyleColor(ImGuiCol_Text, light_grey); ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, light_grey); - if (ImGui::ButtonEx(upload_button_name.c_str(), icons_size, is_streaming ? ImGuiButtonFlags_Disabled : buttons_flags)) + + if (ImGui::ButtonEx(upload_button_name.c_str(), icons_size, (is_streaming && !load_json_if_streaming) ? ImGuiButtonFlags_Disabled : buttons_flags)) { if (is_advanced_mode_enabled) { auto ret = file_dialog_open(open_file, "JavaScript Object Notation (JSON)\0*.json\0", NULL, NULL); - if (ret) + json_loading([&]() { - error_message = safe_call([&]() { load_json(ret); }); - } + auto ret = file_dialog_open(open_file, "JavaScript Object Notation (JSON)\0*.json\0", NULL, NULL); + if (ret) + { + error_message = safe_call([&]() { load_json(ret); }); + } + }); } else { require_advanced_mode_enable_prompt = true; } } + if (ImGui::IsItemHovered()) { - std::string tooltip = to_string() << "Load pre-configured settings" << (is_streaming ? " (Disabled while streaming)" : ""); + std::string tooltip = to_string() << "Load pre-configured settings" << (is_streaming && !load_json_if_streaming ? " (Disabled while streaming)" : ""); ImGui::SetTooltip("%s", tooltip.c_str()); } + ImGui::SameLine(); //////////////////////////////////////// @@ -5220,7 +5229,10 @@ namespace rs2 device_model*& device_to_remove, viewer_model& viewer, float windows_width, bool update_read_only_options, - std::vector>& draw_later, bool draw_device_outline) + std::vector>& draw_later, + bool load_json_if_streaming, + json_loading_func json_loading, + bool draw_device_outline) { //////////////////////////////////////// // draw device header @@ -5333,7 +5345,7 @@ namespace rs2 const float horizontal_space_before_device_control = 3.0f; auto advanced_mode_pos = ImVec2{ pos.x + horizontal_space_before_device_control, pos.y + vertical_space_before_advanced_mode_control }; ImGui::SetCursorPos(advanced_mode_pos); - const float advanced_mode_panel_height = draw_preset_panel(panel_width, window, error_message, viewer, update_read_only_options); + const float advanced_mode_panel_height = draw_preset_panel(panel_width, window, error_message, viewer, update_read_only_options, load_json_if_streaming, json_loading); ImGui::SetCursorPos({ advanced_mode_pos.x, advanced_mode_pos.y + advanced_mode_panel_height }); } diff --git a/common/model-views.h b/common/model-views.h index d8f04b7042..7d67ae06ed 100644 --- a/common/model-views.h +++ b/common/model-views.h @@ -448,6 +448,8 @@ namespace rs2 class device_model { public: + typedef std::function load)> json_loading_func; + void reset(); explicit device_model(device& dev, std::string& error_message, viewer_model& viewer); void start_recording(const std::string& path, std::string& error_message); @@ -462,7 +464,10 @@ namespace rs2 device_model*& device_to_remove, viewer_model& viewer, float windows_width, bool update_read_only_options, - std::vector>& draw_later, bool draw_device_outline = true); + std::vector>& draw_later, + bool load_json_if_streaming = false, + json_loading_func json_loading = [](std::function load) {load(); }, + bool draw_device_outline = true); void handle_harware_events(const std::string& serialized_data); std::vector> subdevices; @@ -503,7 +508,9 @@ namespace rs2 ux_window& window, std::string& error_message, viewer_model& viewer, - bool update_read_only_options); + bool update_read_only_options, + bool load_json_if_streaming, + json_loading_func json_loading); bool prompt_toggle_advanced_mode(bool enable_advanced_mode, const std::string& message_text, std::vector& restarting_device_info, viewer_model& view, diff --git a/tools/depth-quality/depth-quality-model.cpp b/tools/depth-quality/depth-quality-model.cpp index e03043153a..041d22b420 100644 --- a/tools/depth-quality/depth-quality-model.cpp +++ b/tools/depth-quality/depth-quality-model.cpp @@ -475,13 +475,35 @@ namespace rs2 device_model* device_to_remove = nullptr; std::vector> draw_later; auto windows_width = ImGui::GetContentRegionMax().x; - + auto json_loaded = false; _device_model->draw_controls(_viewer_model.panel_width, _viewer_model.panel_y, win, _error_message, device_to_remove, _viewer_model, windows_width, _update_readonly_options_timer, - draw_later, false); + draw_later, true, + [&](std::functionfunc) + { + auto profile =_pipe.get_active_profile(); + _pipe.stop(); + func(); + + auto streams = profile.get_streams(); + config cfg; + for (auto&& s : streams) + { + cfg.enable_stream(s.stream_type(), s.stream_index(), s.format(), s.fps()); + } + _pipe.start(cfg); + + json_loaded = true; + }, + false); + + if (json_loaded) + { + update_configuration(); + } ImGui::SetContentRegionWidth(windows_width); auto pos = ImGui::GetCursorScreenPos();