From 01fb301f6cebd9640f39bdcb049ce3764071c761 Mon Sep 17 00:00:00 2001 From: "zhimin.zeng" Date: Fri, 12 Apr 2024 12:14:32 +0800 Subject: [PATCH] FIX: fix some cali problem of P series jira: none Change-Id: Id57ea8d65da22ab653cca49509cb923ff065e43f --- src/slic3r/GUI/CaliHistoryDialog.cpp | 35 +++++++-------- src/slic3r/GUI/CalibrationWizard.cpp | 43 +++++++++++++++++++ src/slic3r/GUI/CalibrationWizard.hpp | 1 + .../GUI/CalibrationWizardPresetPage.cpp | 2 +- src/slic3r/GUI/Widgets/AMSControl.cpp | 6 +-- 5 files changed, 64 insertions(+), 23 deletions(-) diff --git a/src/slic3r/GUI/CaliHistoryDialog.cpp b/src/slic3r/GUI/CaliHistoryDialog.cpp index bcd67e51c..96ba66ab1 100644 --- a/src/slic3r/GUI/CaliHistoryDialog.cpp +++ b/src/slic3r/GUI/CaliHistoryDialog.cpp @@ -364,6 +364,12 @@ float HistoryWindow::get_nozzle_value() void HistoryWindow::on_click_new_button(wxCommandEvent& event) { + if (curr_obj && curr_obj->get_printer_series() == PrinterSeries::SERIES_P1P && m_calib_results_history.size() >= 16) { + MessageDialog msg_dlg(nullptr, wxString::Format(_L("This machine type can only hold %d history results per nozzle."), 16), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return; + } + NewCalibrationHistoryDialog dlg(this, m_calib_results_history); dlg.ShowModal(); } @@ -701,26 +707,17 @@ void NewCalibrationHistoryDialog::on_ok(wxCommandEvent &event) // Check for duplicate names from history { - struct PACalibResult - { - size_t operator()(const std::pair &item) const - { - return std::hash()(item.first) * std::hash()(item.second); - } - }; - std::unordered_set, PACalibResult> set; - set.insert({m_new_result.name, m_new_result.filament_id}); + auto iter = std::find_if(m_history_results.begin(), m_history_results.end(), [this](const PACalibResult &item) { + return item.name == m_new_result.name && item.filament_id == m_new_result.filament_id; + }); - for (auto &result : m_history_results) { - if (!set.insert({result.name, result.filament_id}).second) { - MessageDialog msg_dlg(nullptr, - wxString::Format(_L("There is already a historical calibration result with the same name: %s. Only one of the results with the same name " - "is saved. Are you sure you want to override the historical result?"), - result.name), - wxEmptyString, wxICON_WARNING | wxYES_NO); - if (msg_dlg.ShowModal() != wxID_YES) - return; - } + if (iter != curr_obj->pa_calib_tab.end()) { + MessageDialog msg_dlg(nullptr, + wxString::Format(_L("There is already a historical calibration result with the same name: %s. Only one of the results with the same name " + "is saved. Are you sure you want to override the historical result?"), + m_new_result.name), + wxEmptyString, wxICON_WARNING | wxYES_NO); + if (msg_dlg.ShowModal() != wxID_YES) return; } } diff --git a/src/slic3r/GUI/CalibrationWizard.cpp b/src/slic3r/GUI/CalibrationWizard.cpp index 84ac846b5..934052ad8 100644 --- a/src/slic3r/GUI/CalibrationWizard.cpp +++ b/src/slic3r/GUI/CalibrationWizard.cpp @@ -18,6 +18,7 @@ static const wxString NA_STR = _L("N/A"); static const float MIN_PA_K_VALUE = 0.0; static const float MAX_PA_K_VALUE = 0.3; static const float MIN_PA_K_VALUE_STEP = 0.001; +static const int MAX_PA_HISTORY_RESULTS_NUMS = 16; std::map get_cached_selected_filament(MachineObject* obj) { std::map selected_filament_map; @@ -467,7 +468,15 @@ void PressureAdvanceWizard::on_cali_action(wxCommandEvent& evt) void PressureAdvanceWizard::update(MachineObject* obj) { + if (!obj) + return; + CalibrationWizard::update(obj); + + if (obj->cali_version != -1 && obj->cali_version != cali_version) { + cali_version = obj->cali_version; + CalibUtils::emit_get_PA_calib_info(obj->nozzle_diameter, ""); + } } void PressureAdvanceWizard::on_device_connected(MachineObject* obj) @@ -648,6 +657,16 @@ void PressureAdvanceWizard::on_cali_start() cali_page->set_pa_cali_image(int(pa_cali_method)); curr_obj->manual_pa_cali_method = pa_cali_method; + if (curr_obj->pa_calib_tab.size() >= MAX_PA_HISTORY_RESULTS_NUMS) { + MessageDialog msg_dlg(nullptr, wxString::Format(_L("This machine type can only hold 16 history results per nozzle. " + "You can delete the existing historical results and then start calibration. " + "Or you can continue the calibration, but you cannot create new calibration historical results. \n" + "Do you still want to continue the calibration?"), MAX_PA_HISTORY_RESULTS_NUMS), wxEmptyString, wxICON_WARNING | wxYES | wxCANCEL); + if (msg_dlg.ShowModal() != wxID_YES) { + return; + } + } + if (!CalibUtils::calib_generic_PA(calib_info, wx_err_string)) { if (!wx_err_string.empty()) { MessageDialog msg_dlg(nullptr, wx_err_string, wxEmptyString, wxICON_WARNING | wxOK); @@ -713,6 +732,30 @@ void PressureAdvanceWizard::on_cali_save() if (!save_page->get_manual_result(new_pa_cali_result)) { return; } + + + auto iter = std::find_if(curr_obj->pa_calib_tab.begin(), curr_obj->pa_calib_tab.end(), [&new_pa_cali_result](const PACalibResult &item) { + return item.name == new_pa_cali_result.name && item.filament_id == item.filament_id; + }); + + if (iter != curr_obj->pa_calib_tab.end()) { + MessageDialog + msg_dlg(nullptr, + wxString::Format(_L("There is already a historical calibration result with the same name: %s. Only one of the results with the same name " + "is saved. Are you sure you want to override the historical result?"), + new_pa_cali_result.name), + wxEmptyString, wxICON_WARNING | wxYES_NO); + if (msg_dlg.ShowModal() != wxID_YES) + return; + } + else if (curr_obj->pa_calib_tab.size() >= MAX_PA_HISTORY_RESULTS_NUMS) { + MessageDialog msg_dlg(nullptr, + wxString::Format(_L("This machine type can only hold %d history results per nozzle. This result will not be saved."), MAX_PA_HISTORY_RESULTS_NUMS), + wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return; + } + CalibUtils::set_PA_calib_result({new_pa_cali_result}, false); } else { auto save_page = static_cast(save_step->page); diff --git a/src/slic3r/GUI/CalibrationWizard.hpp b/src/slic3r/GUI/CalibrationWizard.hpp index 14cfd50a9..d5f2284b9 100644 --- a/src/slic3r/GUI/CalibrationWizard.hpp +++ b/src/slic3r/GUI/CalibrationWizard.hpp @@ -122,6 +122,7 @@ protected: void on_device_connected(MachineObject* obj) override; std::vector m_calib_results_history; + int cali_version = -1; }; class FlowRateWizard : public CalibrationWizard { diff --git a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp index 9be138862..972e93524 100644 --- a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp +++ b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp @@ -1205,7 +1205,7 @@ void CalibrationPresetPage::update_show_status() show_status(CaliPresetPageStatus::CaliPresetStatusInPrinting); return; } - else if (need_check_sdcard(obj_) && obj_->get_sdcard_state() == MachineObject::SdcardState::NO_SDCARD) { + else if (!obj_->is_support_print_without_sd && (obj_->get_sdcard_state() == MachineObject::SdcardState::NO_SDCARD)) { show_status(CaliPresetPageStatus::CaliPresetStatusNoSdcard); return; } diff --git a/src/slic3r/GUI/Widgets/AMSControl.cpp b/src/slic3r/GUI/Widgets/AMSControl.cpp index bc7fcdbcd..79554d432 100644 --- a/src/slic3r/GUI/Widgets/AMSControl.cpp +++ b/src/slic3r/GUI/Widgets/AMSControl.cpp @@ -88,7 +88,7 @@ bool AMSinfo::parse_ams_info(MachineObject *obj, Ams *ams, bool remain_flag, boo wxColour(255, 255, 255); } - if (obj->get_printer_series() == PrinterSeries::SERIES_X1 && it->second->is_tray_info_ready()) { + if (it->second->is_tray_info_ready() && obj->cali_version >= 0) { CalibUtils::get_pa_k_n_value_by_cali_idx(obj, it->second->cali_idx, info.k, info.n); } else { @@ -840,7 +840,7 @@ void AMSLib::render_extra_text(wxDC& dc) void AMSLib::render_generic_text(wxDC &dc) { bool show_k_value = true; - if (m_obj && (m_obj->get_printer_series() == PrinterSeries::SERIES_X1) && (abs(m_info.k - 0) < 1e-3)) { + if (m_obj && (m_obj->cali_version >= 0) && (abs(m_info.k - 0) < 1e-3)) { show_k_value = false; } @@ -3308,7 +3308,7 @@ void AMSControl::show_vams_kn_value(bool show) void AMSControl::update_vams_kn_value(AmsTray tray, MachineObject* obj) { m_vams_lib->m_obj = obj; - if (obj->get_printer_series() == PrinterSeries::SERIES_X1) { + if (obj->cali_version >= 0) { float k_value = 0; float n_value = 0; CalibUtils::get_pa_k_n_value_by_cali_idx(obj, tray.cali_idx, k_value, n_value);