FIX: fix some cali problem of P series

jira: none
Change-Id: Id57ea8d65da22ab653cca49509cb923ff065e43f
This commit is contained in:
zhimin.zeng 2024-04-12 12:14:32 +08:00 committed by Lane.Wei
parent bda0d138b5
commit 01fb301f6c
5 changed files with 64 additions and 23 deletions

View File

@ -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<std::string, std::string> &item) const
{
return std::hash<string>()(item.first) * std::hash<string>()(item.second);
}
};
std::unordered_set<std::pair<std::string, std::string>, 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;
}
}

View File

@ -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<int, Preset*> get_cached_selected_filament(MachineObject* obj) {
std::map<int, Preset*> 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<CalibrationPASavePage *>(save_step->page);

View File

@ -122,6 +122,7 @@ protected:
void on_device_connected(MachineObject* obj) override;
std::vector<PACalibResult> m_calib_results_history;
int cali_version = -1;
};
class FlowRateWizard : public CalibrationWizard {

View File

@ -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;
}

View File

@ -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);