ENH: add printable check before cali

jira: 8816
Change-Id: I7df5676ecc80c27b516f47efe00ac40d04a4a5c9
This commit is contained in:
zhimin.zeng 2024-12-07 17:50:22 +08:00 committed by lane.wei
parent feb9b02067
commit 13a4edc97c
4 changed files with 140 additions and 36 deletions

View File

@ -415,7 +415,7 @@ void CalibrationWizard::cache_preset_info(MachineObject* obj, float nozzle_dia)
if (obj->is_multi_extruders()) {
int ams_id, slot_id, tray_id;
get_tray_ams_and_slot_id(result.extruder_id, ams_id, slot_id, tray_id);
get_tray_ams_and_slot_id(result.tray_id, ams_id, slot_id, tray_id);
result.extruder_id = preset_page->get_extruder_id(ams_id);
result.nozzle_volume_type = preset_page->get_nozzle_volume_type(result.extruder_id);
}
@ -1202,9 +1202,7 @@ void FlowRateWizard::on_cali_start(CaliPresetStage stage, float cali_value, Flow
}
wxString wx_err_string;
std::string error_message;
CalibUtils::calib_flowrate_X1C(calib_infos, error_message);
wx_err_string = from_u8(error_message);
CalibUtils::calib_flowrate_X1C(calib_infos, wx_err_string);
if (!wx_err_string.empty()) {
MessageDialog msg_dlg(nullptr, wx_err_string, wxEmptyString, wxICON_WARNING | wxOK);
msg_dlg.ShowModal();

View File

@ -1907,8 +1907,8 @@ void CalibrationPresetPage::init_with_machine(MachineObject* obj)
m_multi_exturder_ams_sizer->Add(m_deputy_sizer, 1, wxEXPAND | wxALL | wxALIGN_BOTTOM, 10);
m_multi_exturder_ams_sizer->Add(m_main_sizer, 1, wxEXPAND | wxALL | wxALIGN_BOTTOM, 10);
m_left_nozzle_volume_type_sizer->Add(m_comboBox_nozzle_volume_types[0]);
m_right_nozzle_volume_type_sizer->Add(m_comboBox_nozzle_volume_types[1]);
m_left_nozzle_volume_type_sizer->Add(m_comboBox_nozzle_volume_types[1]);
m_right_nozzle_volume_type_sizer->Add(m_comboBox_nozzle_volume_types[0]);
m_main_extruder_on_left = false;
}
@ -1924,8 +1924,8 @@ void CalibrationPresetPage::init_with_machine(MachineObject* obj)
m_multi_exturder_ams_sizer->Add(m_main_sizer, 1, wxEXPAND | wxALL | wxALIGN_BOTTOM, 10);
m_multi_exturder_ams_sizer->Add(m_deputy_sizer, 1, wxEXPAND | wxALL | wxALIGN_BOTTOM, 10);
m_left_nozzle_volume_type_sizer->Add(m_comboBox_nozzle_volume_types[1]);
m_right_nozzle_volume_type_sizer->Add(m_comboBox_nozzle_volume_types[0]);
m_left_nozzle_volume_type_sizer->Add(m_comboBox_nozzle_volume_types[0]);
m_right_nozzle_volume_type_sizer->Add(m_comboBox_nozzle_volume_types[1]);
m_main_extruder_on_left = true;
}

View File

@ -400,8 +400,11 @@ void CalibUtils::calib_PA(const X1CCalibInfos& calib_infos, int mode, wxString&
if (obj_ == nullptr)
return;
if (calib_infos.calib_datas.size() > 0)
if (calib_infos.calib_datas.size() > 0) {
if (!check_printable_status_before_cali(obj_, calib_infos, error_message))
return;
obj_->command_start_pa_calibration(calib_infos, mode);
}
}
void CalibUtils::emit_get_PA_calib_results(float nozzle_diameter)
@ -499,7 +502,7 @@ void CalibUtils::delete_PA_calib_result(const PACalibIndexInfo& pa_calib_info)
obj_->command_delete_pa_calibration(pa_calib_info);
}
void CalibUtils::calib_flowrate_X1C(const X1CCalibInfos& calib_infos, std::string& error_message)
void CalibUtils::calib_flowrate_X1C(const X1CCalibInfos& calib_infos, wxString& error_message)
{
DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev)
@ -509,8 +512,11 @@ void CalibUtils::calib_flowrate_X1C(const X1CCalibInfos& calib_infos, std::strin
if (obj_ == nullptr)
return;
if (calib_infos.calib_datas.size() > 0)
if (calib_infos.calib_datas.size() > 0) {
if (!check_printable_status_before_cali(obj_, calib_infos, error_message))
return;
obj_->command_start_flow_ratio_calibration(calib_infos);
}
else {
BOOST_LOG_TRIVIAL(info) << "flow_rate_cali: auto | send info | cali_datas is empty.";
}
@ -545,6 +551,21 @@ bool CalibUtils::get_flow_ratio_calib_results(std::vector<FlowRatioCalibResult>&
bool CalibUtils::calib_flowrate(int pass, const CalibInfo &calib_info, wxString &error_message)
{
DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) {
error_message = _L("Need select printer");
return false;
}
MachineObject *obj_ = dev->get_selected_machine();
if (obj_ == nullptr) {
error_message = _L("Need select printer");
return false;
}
if (!check_printable_status_before_cali(obj_, calib_info, error_message))
return false;
if (pass != 1 && pass != 2)
return false;
@ -647,18 +668,6 @@ bool CalibUtils::calib_flowrate(int pass, const CalibInfo &calib_info, wxString
if (!process_and_store_3mf(&model, full_config, params, error_message))
return false;
DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) {
error_message = _L("Need select printer");
return false;
}
MachineObject *obj_ = dev->get_selected_machine();
if (obj_ == nullptr) {
error_message = _L("Need select printer");
return false;
}
try {
json js;
if (pass == 1)
@ -736,6 +745,21 @@ void CalibUtils::calib_pa_pattern(const CalibInfo &calib_info, Model& model)
bool CalibUtils::calib_generic_PA(const CalibInfo &calib_info, wxString &error_message)
{
DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) {
error_message = _L("Need select printer");
return false;
}
MachineObject *obj_ = dev->get_selected_machine();
if (obj_ == nullptr) {
error_message = _L("Need select printer");
return false;
}
if (!check_printable_status_before_cali(obj_, calib_info, error_message))
return false;
const Calib_Params &params = calib_info.params;
if (params.mode != CalibMode::Calib_PA_Line && params.mode != CalibMode::Calib_PA_Pattern)
return false;
@ -769,18 +793,6 @@ bool CalibUtils::calib_generic_PA(const CalibInfo &calib_info, wxString &error_m
if (!process_and_store_3mf(&model, full_config, params, error_message))
return false;
DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) {
error_message = _L("Need select printer");
return false;
}
MachineObject *obj_ = dev->get_selected_machine();
if (obj_ == nullptr) {
error_message = _L("Need select printer");
return false;
}
try {
json js;
if (params.mode == CalibMode::Calib_PA_Line)
@ -1092,6 +1104,97 @@ bool CalibUtils::get_pa_k_n_value_by_cali_idx(const MachineObject *obj, int cali
return false;
}
bool CalibUtils::check_printable_status_before_cali(const MachineObject *obj, const X1CCalibInfos &cali_infos, wxString &error_message)
{
if (!obj) {
error_message = _L("Need select printer");
return false;
}
float diameter = obj->m_extder_data.extders[0].current_nozzle_diameter;
bool is_multi_extruder = obj->is_multi_extruders();
std::vector<NozzleFlowType> nozzle_volume_types;
if (is_multi_extruder) {
for (const Extder& extruder : obj->m_extder_data.extders) {
nozzle_volume_types.emplace_back(extruder.current_nozzle_flow_type);
}
}
for (const auto &cali_info : cali_infos.calib_datas) {
if (!is_approx(cali_info.nozzle_diameter, diameter)) {
error_message = _L("The selected diameter is inconsistent with the printer diameter.");
return false;
}
if (is_multi_extruder) {
if (nozzle_volume_types[cali_info.extruder_id] == NozzleFlowType::NONE_FLOWTYPE) {
wxString name = _L("left");
if (cali_info.extruder_id == 0) {
name = _L("right");
}
error_message = wxString::Format("The nozzle type of the %s extruder is not set. Please set it first and then start calibration.", name);
return false;
}
if (NozzleVolumeType(nozzle_volume_types[cali_info.extruder_id] - 1) != cali_info.nozzle_volume_type) {
wxString name = _L("left");
if (cali_info.extruder_id == 0) {
name = _L("right");
}
error_message = wxString::Format("The selected nozzle type of %s extruder is inconsistent with the actual nozzle type of the printer.\n"
"Please synchronize the printer information first and then start calibration.", name);
return false;
}
}
}
return true;
}
bool CalibUtils::check_printable_status_before_cali(const MachineObject* obj, const CalibInfo& cali_info, wxString& error_message)
{
if (!obj) {
error_message = _L("Need select printer");
return false;
}
const ConfigOptionFloatsNullable *nozzle_diameter_config = cali_info.printer_prest->config.option<ConfigOptionFloatsNullable>("nozzle_diameter");
float nozzle_diameter = nozzle_diameter_config->values[0];
float diameter = obj->m_extder_data.extders[0].current_nozzle_diameter;
bool is_multi_extruder = obj->is_multi_extruders();
std::vector<NozzleFlowType> nozzle_volume_types;
if (is_multi_extruder) {
for (const Extder& extruder : obj->m_extder_data.extders) {
nozzle_volume_types.emplace_back(extruder.current_nozzle_flow_type);
}
}
if (!is_approx(nozzle_diameter, diameter)) {
error_message = _L("The selected diameter is inconsistent with the printer diameter.");
return false;
}
if (is_multi_extruder) {
if (nozzle_volume_types[cali_info.extruder_id] == NozzleFlowType::NONE_FLOWTYPE) {
wxString name = _L("left");
if (cali_info.extruder_id == 0) { name = _L("right"); }
error_message = wxString::Format("The nozzle type of the %s extruder is not set. Please set it first and then start calibration.", name);
return false;
}
if (NozzleVolumeType(nozzle_volume_types[cali_info.extruder_id] - 1) != cali_info.nozzle_volume_type) {
wxString name = _L("left");
if (cali_info.extruder_id == 0) { name = _L("right"); }
error_message = wxString::Format("The selected nozzle type of %s extruder is inconsistent with the actual nozzle type of the printer.\n"
"Please synchronize the printer information first and then start calibration.",
name);
return false;
}
}
return true;
}
bool CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &full_config, const Calib_Params &params, wxString &error_message)
{
Pointfs bedfs = full_config.opt<ConfigOptionPoints>("printable_area")->values;

View File

@ -50,7 +50,7 @@ public:
static void select_PA_calib_result(const PACalibIndexInfo &pa_calib_info);
static void delete_PA_calib_result(const PACalibIndexInfo &pa_calib_info);
static void calib_flowrate_X1C(const X1CCalibInfos& calib_infos, std::string& error_message);
static void calib_flowrate_X1C(const X1CCalibInfos& calib_infos, wxString& error_message);
static void emit_get_flow_ratio_calib_results(float nozzle_diameter);
static bool get_flow_ratio_calib_results(std::vector<FlowRatioCalibResult> &flow_ratio_calib_results);
static bool calib_flowrate(int pass, const CalibInfo &calib_info, wxString &error_message);
@ -71,6 +71,9 @@ public:
static bool validate_input_k_value(wxString k_text, float* output_value);
static bool validate_input_flow_ratio(wxString flow_ratio, float* output_value);
static bool check_printable_status_before_cali(const MachineObject *obj, const X1CCalibInfos &cali_infos, wxString &error_message);
static bool check_printable_status_before_cali(const MachineObject *obj, const CalibInfo &cali_info, wxString &error_message);
private:
static bool process_and_store_3mf(Model* model, const DynamicPrintConfig& full_config, const Calib_Params& params, wxString& error_message);
static void send_to_print(const CalibInfo &calib_info, wxString& error_message, int flow_ratio_mode = 0); // 0: none 1: coarse 2: fine