FIX: the pa profile name cannot be repeated when edit k value

jira: STUDIO-10992
Change-Id: I50d61e9581e188a10a4f804df163b3d50eb7caa0
(cherry picked from commit 431925adf0749faafeaf46ac0b8d60c6d4e5972a)
This commit is contained in:
zhimin.zeng
2025-03-19 21:40:56 +08:00
committed by Noisyfox
parent b9ad057d1a
commit 08aef5bf53
4 changed files with 37 additions and 7 deletions

View File

@@ -393,7 +393,7 @@ void HistoryWindow::sync_history_data() {
PACalibResult result_buffer = result;
result_buffer.k_value = stof(k_value->GetLabel().ToStdString());
result_buffer.name = name_value->GetLabel().ToUTF8().data();
EditCalibrationHistoryDialog dlg(this, result_buffer, curr_obj);
EditCalibrationHistoryDialog dlg(this, result_buffer, curr_obj, m_calib_results_history);
if (dlg.ShowModal() == wxID_OK) {
auto new_result = dlg.get_result();
@@ -471,10 +471,16 @@ void HistoryWindow::on_click_new_button(wxCommandEvent& event)
dlg.ShowModal();
}
EditCalibrationHistoryDialog::EditCalibrationHistoryDialog(wxWindow *parent, const PACalibResult &result, const MachineObject *obj)
EditCalibrationHistoryDialog::EditCalibrationHistoryDialog(wxWindow *parent,
const PACalibResult &result,
const MachineObject *obj,
const std::vector<PACalibResult> history_results)
: DPIDialog(parent, wxID_ANY, _L("Edit Flow Dynamics Calibration"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
, m_new_result(result)
, m_history_results(history_results)
{
curr_obj = obj;
this->SetBackgroundColour(*wxWHITE);
auto main_sizer = new wxBoxSizer(wxVERTICAL);
@@ -598,6 +604,22 @@ void EditCalibrationHistoryDialog::on_save(wxCommandEvent& event) {
m_k_value->GetTextCtrl()->SetValue(k_str);
m_new_result.k_value = k;
auto iter = std::find_if(m_history_results.begin(), m_history_results.end(), [this](const PACalibResult &item) {
bool has_same_name = item.name == m_new_result.name && item.filament_id == m_new_result.filament_id;
if (curr_obj && curr_obj->is_multi_extruders()) {
has_same_name &= (item.extruder_id == m_new_result.extruder_id && item.nozzle_volume_type == m_new_result.nozzle_volume_type);
}
return has_same_name;
});
if (iter != m_history_results.end()) {
wxString duplicate_name_info = wxString::Format(
_L("Within the same extruder, the name '%s' must be unique when the filament type, nozzle diameter, and nozzle flow are identical. Please choose a different name."),
m_new_result.name);
MessageDialog msg_dlg(nullptr, duplicate_name_info, wxEmptyString, wxICON_WARNING | wxOK);
msg_dlg.ShowModal();
return;
}
EndModal(wxID_OK);
}