FIX: remove abnormal ui toggle in camerapopup

Change-Id: Id8b2b8f3be4a43e74e1e211b7bfb747b5552ca1d
This commit is contained in:
tao.jin 2022-11-30 14:56:21 +08:00 committed by Lane.Wei
parent fd3dee6a6d
commit 8f330d8b82
4 changed files with 31 additions and 15 deletions

View file

@ -133,7 +133,6 @@ void CameraPopup::on_switch_timelapse(wxCommandEvent& event)
return;
}
bool value = m_switch_timelapse->GetValue();
m_switch_timelapse->SetValue(!value);
m_obj->command_ipcam_timelapse(!value);
}
@ -145,7 +144,6 @@ void CameraPopup::on_switch_recording(wxCommandEvent& event)
return;
}
bool value = m_switch_recording->GetValue();
m_switch_recording->SetValue(!value);
m_obj->command_ipcam_record(!value);
}
@ -301,7 +299,6 @@ void CameraPopup::check_func_supported()
void CameraPopup::update()
{
if (!m_obj) return;
check_func_supported();
m_switch_timelapse->SetValue(m_obj->camera_timelapse);
m_switch_recording->SetValue(m_obj->camera_recording_when_printing);
sync_resolution_setting(m_obj->camera_resolution);

View file

@ -1605,6 +1605,7 @@ int MachineObject::command_ipcam_record(bool on_off)
j["camera"]["command"] = "ipcam_record_set";
j["camera"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
j["camera"]["control"] = on_off ? "enable" : "disable";
camera_recording_hold_count = HOLD_COUNT_MAX;
return this->publish_json(j.dump());
}
@ -1614,6 +1615,7 @@ int MachineObject::command_ipcam_timelapse(bool on_off)
j["camera"]["command"] = "ipcam_timelapse";
j["camera"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
j["camera"]["control"] = on_off ? "enable" : "disable";
camera_timelapse_hold_count = HOLD_COUNT_MAX;
return this->publish_json(j.dump());
}
@ -1624,6 +1626,8 @@ int MachineObject::command_ipcam_resolution_set(std::string resolution)
j["camera"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
j["camera"]["resolution"] = resolution;
BOOST_LOG_TRIVIAL(info) << "command:ipcam_resolution_set" << ", resolution:" << resolution;
camera_resolution_hold_count = HOLD_COUNT_MAX;
camera_recording_hold_count = HOLD_COUNT_MAX;
return this->publish_json(j.dump());
}
@ -2375,19 +2379,27 @@ int MachineObject::parse_json(std::string payload)
try {
if (jj.contains("ipcam")) {
if (jj["ipcam"].contains("ipcam_record")) {
if (jj["ipcam"]["ipcam_record"].get<std::string>() == "enable") {
camera_recording_when_printing = true;
}
if (camera_recording_hold_count > 0)
camera_recording_hold_count--;
else {
camera_recording_when_printing = false;
if (jj["ipcam"]["ipcam_record"].get<std::string>() == "enable") {
camera_recording_when_printing = true;
}
else {
camera_recording_when_printing = false;
}
}
}
if (jj["ipcam"].contains("timelapse")) {
if (jj["ipcam"]["timelapse"].get<std::string>() == "enable") {
camera_timelapse = true;
}
if (camera_timelapse_hold_count > 0)
camera_timelapse_hold_count--;
else {
camera_timelapse = false;
if (jj["ipcam"]["timelapse"].get<std::string>() == "enable") {
camera_timelapse = true;
}
else {
camera_timelapse = false;
}
}
}
if (jj["ipcam"].contains("ipcam_dev")) {
@ -2398,7 +2410,11 @@ int MachineObject::parse_json(std::string payload)
}
}
if (jj["ipcam"].contains("resolution")) {
camera_resolution = jj["ipcam"]["resolution"].get<std::string>();
if (camera_resolution_hold_count > 0)
camera_resolution_hold_count--;
else {
camera_resolution = jj["ipcam"]["resolution"].get<std::string>();
}
}
}
}

View file

@ -539,6 +539,9 @@ public:
bool camera_recording { false };
bool camera_recording_when_printing { false };
bool camera_timelapse { false };
int camera_recording_hold_count = 0;
int camera_timelapse_hold_count = 0;
int camera_resolution_hold_count = 0;
std::string camera_resolution = "";
bool xcam_first_layer_inspector { false };
int xcam_first_layer_hold_count = 0;

View file

@ -275,7 +275,7 @@ void MediaPlayCtrl::ToggleStream()
std::string file_ff_cfg = data_dir() + "/cameratools/ffmpeg.cfg";
#endif
if (!boost::filesystem::exists(file_source) || !boost::filesystem::exists(file_ffmpeg) || !boost::filesystem::exists(file_ff_cfg)) {
auto res = MessageDialog(this, _L("Virtual Camera Tools is required for this task!\nDo you want to install them?"), _L("Info"),
auto res = MessageDialog(this->GetParent(), _L("Virtual Camera Tools is required for this task!\nDo you want to install them?"), _L("Info"),
wxOK | wxCANCEL).ShowModal();
if (res == wxID_OK) {
// download tools
@ -321,7 +321,7 @@ void MediaPlayCtrl::ToggleStream()
process_ffmpeg.detach();
}
if (!url.empty() && wxGetApp().app_config->get("not_show_vcamera_stop_prev") != "1") {
MessageDialog dlg(this, _L("Another virtual camera is running.\nBambu Studio supports only a single virtual camera.\nDo you want to stop this virtual camera?"), _L("Warning"),
MessageDialog dlg(this->GetParent(), _L("Another virtual camera is running.\nBambu Studio supports only a single virtual camera.\nDo you want to stop this virtual camera?"), _L("Warning"),
wxYES | wxCANCEL | wxICON_INFORMATION);
dlg.show_dsa_button();
auto res = dlg.ShowModal();
@ -336,7 +336,7 @@ void MediaPlayCtrl::ToggleStream()
CallAfter([this, m, url] {
if (m != m_machine) return;
if (url.empty() || !boost::algorithm::starts_with(url, "bambu:///")) {
MessageDialog(this, wxString::Format(_L("Virtual camera initialize failed (%s)!"), url.empty() ? _L("Network unreachable") : from_u8(url)), _L("Information"),
MessageDialog(this->GetParent(), wxString::Format(_L("Virtual camera initialize failed (%s)!"), url.empty() ? _L("Network unreachable") : from_u8(url)), _L("Information"),
wxICON_INFORMATION)
.ShowModal();
return;