calib wizard

This commit is contained in:
SoftFever
2024-04-27 12:27:31 +08:00
parent b739b875e4
commit 377fb54680
7 changed files with 96 additions and 41 deletions

View File

@@ -55,9 +55,10 @@ static wxString get_preset_name_by_filament_id(std::string filament_id)
return preset_name;
}
HistoryWindow::HistoryWindow(wxWindow* parent, const std::vector<PACalibResult>& calib_results_history)
HistoryWindow::HistoryWindow(wxWindow* parent, const std::vector<PACalibResult>& calib_results_history, bool& show)
: DPIDialog(parent, wxID_ANY, _L("Flow Dynamics Calibration Result"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
, m_calib_results_history(calib_results_history)
, m_show_history_dialog(show)
{
this->SetBackgroundColour(*wxWHITE);
auto main_sizer = new wxBoxSizer(wxVERTICAL);
@@ -138,11 +139,14 @@ HistoryWindow::HistoryWindow(wxWindow* parent, const std::vector<PACalibResult>&
m_refresh_timer->SetOwner(this);
m_refresh_timer->Start(200);
Bind(wxEVT_TIMER, &HistoryWindow::on_timer, this);
m_show_history_dialog = true;
}
HistoryWindow::~HistoryWindow()
{
m_refresh_timer->Stop();
m_show_history_dialog = false;
}
void HistoryWindow::sync_history_result(MachineObject* obj)
@@ -566,7 +570,7 @@ wxArrayString NewCalibrationHistoryDialog::get_all_filaments(const MachineObject
}
NewCalibrationHistoryDialog::NewCalibrationHistoryDialog(wxWindow *parent, const std::vector<PACalibResult> history_results)
: DPIDialog(parent, wxID_ANY, _L("New Flow Dynamics Calibration"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
: DPIDialog(parent, wxID_ANY, _L("New Flow Dynamic Calibration"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
, m_history_results(history_results)
{
Slic3r::DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
@@ -576,6 +580,8 @@ NewCalibrationHistoryDialog::NewCalibrationHistoryDialog(wxWindow *parent, const
if (!obj)
return;
curr_obj = obj;
this->SetBackgroundColour(*wxWHITE);
auto main_sizer = new wxBoxSizer(wxVERTICAL);
@@ -709,13 +715,14 @@ void NewCalibrationHistoryDialog::on_ok(wxCommandEvent &event)
return item.name == m_new_result.name && item.filament_id == m_new_result.filament_id;
});
if (iter != curr_obj->pa_calib_tab.end()) {
if (iter != m_history_results.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;
if (msg_dlg.ShowModal() != wxID_YES)
return;
}
}

View File

@@ -11,7 +11,7 @@ namespace GUI {
class HistoryWindow : public DPIDialog {
public:
HistoryWindow(wxWindow* parent, const std::vector<PACalibResult>& calib_results_history);
HistoryWindow(wxWindow* parent, const std::vector<PACalibResult>& calib_results_history, bool& show);
~HistoryWindow();
void on_dpi_changed(const wxRect& suggested_rect) {}
void on_select_nozzle(wxCommandEvent& evt);
@@ -33,6 +33,7 @@ protected:
wxTimer* m_refresh_timer { nullptr };
bool& m_show_history_dialog;
std::vector<PACalibResult> m_calib_results_history;
MachineObject* curr_obj { nullptr };
int history_version = -1;
@@ -74,6 +75,7 @@ protected:
protected:
PACalibResult m_new_result;
std::vector<PACalibResult> m_history_results;
MachineObject * curr_obj;
TextInput *m_name_value{nullptr};
TextInput *m_k_value{nullptr};

View File

@@ -430,7 +430,7 @@ void PressureAdvanceWizard::on_cali_action(wxCommandEvent& evt)
{
CaliPageActionType action = static_cast<CaliPageActionType>(evt.GetInt());
if (action == CaliPageActionType::CALI_ACTION_MANAGE_RESULT) {
HistoryWindow history_dialog(this, m_calib_results_history);
HistoryWindow history_dialog(this, m_calib_results_history, m_show_result_dialog);
history_dialog.on_device_connected(curr_obj);
history_dialog.ShowModal();
}
@@ -473,9 +473,11 @@ void PressureAdvanceWizard::update(MachineObject* obj)
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, "");
if (!m_show_result_dialog) {
if (obj->cali_version != -1 && obj->cali_version != cali_version) {
cali_version = obj->cali_version;
CalibUtils::emit_get_PA_calib_info(obj->nozzle_diameter, "");
}
}
}
@@ -1063,7 +1065,13 @@ void FlowRateWizard::on_cali_start(CaliPresetStage stage, float cali_value, Flow
calib_info.filament_prest = temp_filament_preset;
if (cali_stage > 0) {
CalibUtils::calib_flowrate(cali_stage, calib_info, wx_err_string);
if (!CalibUtils::calib_flowrate(cali_stage, calib_info, wx_err_string)) {
if (!wx_err_string.empty()) {
MessageDialog msg_dlg(nullptr, wx_err_string, wxEmptyString, wxICON_WARNING | wxOK);
msg_dlg.ShowModal();
}
return;
}
}
else {
wx_err_string = _L("Internal Error") + wxString(": Invalid calibration stage");

View File

@@ -121,6 +121,7 @@ protected:
void on_device_connected(MachineObject* obj) override;
bool m_show_result_dialog = false;
std::vector<PACalibResult> m_calib_results_history;
int cali_version = -1;
};

View File

@@ -1,3 +1,4 @@
#include <regex>
#include "CalibrationWizardPresetPage.hpp"
#include "I18N.hpp"
#include "Widgets/Label.hpp"
@@ -312,7 +313,7 @@ void CaliPresetCustomRangePanel::create_panel(wxWindow* parent)
m_title_texts[i]->Wrap(-1);
m_title_texts[i]->SetFont(::Label::Body_14);
item_sizer->Add(m_title_texts[i], 0, wxALL, 0);
m_value_inputs[i] = new TextInput(parent, wxEmptyString, _L("\u2103"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, 0);
m_value_inputs[i] = new TextInput(parent, wxEmptyString, wxString::FromUTF8("°C"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, 0);
m_value_inputs[i]->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
m_value_inputs[i]->GetTextCtrl()->Bind(wxEVT_TEXT, [this, i](wxCommandEvent& event) {
std::string number = m_value_inputs[i]->GetTextCtrl()->GetValue().ToStdString();
@@ -391,7 +392,7 @@ void CaliPresetTipsPanel::create_panel(wxWindow* parent)
auto nozzle_temp_sizer = new wxBoxSizer(wxVERTICAL);
auto nozzle_temp_text = new Label(parent, _L("Nozzle temperature"));
nozzle_temp_text->SetFont(Label::Body_12);
m_nozzle_temp = new TextInput(parent, wxEmptyString, _L("\u2103"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, wxTE_READONLY);
m_nozzle_temp = new TextInput(parent, wxEmptyString, wxString::FromUTF8("°C"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, wxTE_READONLY);
m_nozzle_temp->SetBorderWidth(0);
nozzle_temp_sizer->Add(nozzle_temp_text, 0, wxALIGN_LEFT);
nozzle_temp_sizer->Add(m_nozzle_temp, 0, wxEXPAND);
@@ -406,7 +407,7 @@ void CaliPresetTipsPanel::create_panel(wxWindow* parent)
auto bed_temp_text = new Label(parent, _L("Bed temperature"));
bed_temp_text->SetFont(Label::Body_12);
m_bed_temp = new Label(parent, _L("- \u2103"));
m_bed_temp = new Label(parent, wxString::FromUTF8("- °C"));
m_bed_temp->SetFont(Label::Body_12);
bed_temp_sizer->Add(bed_temp_text, 0, wxALIGN_CENTER | wxRIGHT, FromDIP(10));
bed_temp_sizer->Add(m_bed_temp, 0, wxALIGN_CENTER);
@@ -414,7 +415,7 @@ void CaliPresetTipsPanel::create_panel(wxWindow* parent)
auto max_flow_sizer = new wxBoxSizer(wxVERTICAL);
auto max_flow_text = new Label(parent, _L("Max volumetric speed"));
max_flow_text->SetFont(Label::Body_12);
m_max_volumetric_speed = new TextInput(parent, wxEmptyString, _L("mm\u00B3"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, wxTE_READONLY);
m_max_volumetric_speed = new TextInput(parent, wxEmptyString, wxString::FromUTF8("mm³"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, wxTE_READONLY);
m_max_volumetric_speed->SetBorderWidth(0);
max_flow_sizer->Add(max_flow_text, 0, wxALIGN_LEFT);
max_flow_sizer->Add(m_max_volumetric_speed, 0, wxEXPAND);
@@ -1424,10 +1425,10 @@ void CalibrationPresetPage::set_cali_method(CalibrationMethod method)
m_custom_range_panel->set_titles(titles);
wxArrayString values;
values.push_back(_L("0"));
values.push_back(_L("0.5"));
values.push_back(_L("0.005"));
m_custom_range_panel->set_values(values);
values.push_back(wxString::Format(wxT("%.0f"), 0));
values.push_back(wxString::Format(wxT("%.2f"), 0.05));
values.push_back(wxString::Format(wxT("%.3f"), 0.005));
m_custom_range_panel->set_values(values);
m_custom_range_panel->set_unit("");
m_custom_range_panel->Show();
@@ -1479,7 +1480,7 @@ void CalibrationPresetPage::on_cali_cancel_job()
{
BOOST_LOG_TRIVIAL(info) << "CalibrationWizard::print_job: enter canceled";
if (CalibUtils::print_worker) {
BOOST_LOG_TRIVIAL(info) << "calibration_print_job: canceled";
BOOST_LOG_TRIVIAL(info) << "calibration_print_job: canceled";
CalibUtils::print_worker->cancel_all();
CalibUtils::print_worker->wait_for_idle();
}
@@ -1913,7 +1914,7 @@ MaxVolumetricSpeedPresetPage::MaxVolumetricSpeedPresetPage(
titles.push_back(_L("Step"));
m_custom_range_panel->set_titles(titles);
m_custom_range_panel->set_unit(_L("mm\u00B3/s"));
m_custom_range_panel->set_unit("mm³/s");
}
}
}}

View File

@@ -122,7 +122,16 @@ static bool is_same_nozzle_type(const DynamicPrintConfig &full_config, const Mac
std::string filament_type = full_config.opt_string("filament_type", 0);
error_msg = wxString::Format(_L("*Printing %s material with %s may cause nozzle damage"), filament_type, to_wstring_name(obj->nozzle_type));
error_msg += "\n";
return false;
MessageDialog msg_dlg(nullptr, error_msg, wxEmptyString, wxICON_WARNING | wxOK | wxCANCEL);
auto result = msg_dlg.ShowModal();
if (result == wxID_OK) {
error_msg.clear();
return true;
} else {
error_msg.clear();
return false;
}
}
}
@@ -484,10 +493,10 @@ bool CalibUtils::get_flow_ratio_calib_results(std::vector<FlowRatioCalibResult>&
return flow_ratio_calib_results.size() > 0;
}
void CalibUtils::calib_flowrate(int pass, const CalibInfo &calib_info, wxString &error_message)
bool CalibUtils::calib_flowrate(int pass, const CalibInfo &calib_info, wxString &error_message)
{
if (pass != 1 && pass != 2)
return;
return false;
Model model;
std::string input_file;
@@ -572,11 +581,24 @@ void CalibUtils::calib_flowrate(int pass, const CalibInfo &calib_info, wxString
Calib_Params params;
params.mode = CalibMode::Calib_Flow_Rate;
process_and_store_3mf(&model, full_config, params, error_message);
if (!error_message.empty())
return;
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;
}
send_to_print(calib_info, error_message, pass);
return true;
}
void CalibUtils::calib_pa_pattern(const CalibInfo &calib_info, Model& model)
@@ -633,11 +655,11 @@ void CalibUtils::calib_pa_pattern(const CalibInfo &calib_info, Model& model)
model.calib_pa_pattern = std::make_unique<CalibPressureAdvancePattern>(pa_pattern);
}
void CalibUtils::calib_generic_PA(const CalibInfo &calib_info, wxString &error_message)
bool CalibUtils::calib_generic_PA(const CalibInfo &calib_info, wxString &error_message)
{
const Calib_Params &params = calib_info.params;
if (params.mode != CalibMode::Calib_PA_Line && params.mode != CalibMode::Calib_PA_Pattern)
return;
return false;
Model model;
std::string input_file;
@@ -663,11 +685,24 @@ void CalibUtils::calib_generic_PA(const CalibInfo &calib_info, wxString &error_m
full_config.apply(filament_config);
full_config.apply(printer_config);
process_and_store_3mf(&model, full_config, params, error_message);
if (!error_message.empty())
return;
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;
}
send_to_print(calib_info, error_message);
return true;
}
void CalibUtils::calib_temptue(const CalibInfo &calib_info, wxString &error_message)
@@ -935,7 +970,7 @@ bool CalibUtils::get_pa_k_n_value_by_cali_idx(const MachineObject *obj, int cali
return false;
}
void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &full_config, const Calib_Params &params, wxString &error_message)
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;
double print_height = full_config.opt_float("printable_height");
@@ -952,7 +987,7 @@ void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f
int count = std::llround(std::ceil((params.end - params.start) / params.step)) + 1;
if (count > max_line_nums) {
error_message = _L("Unable to calibrate: maybe because the set calibration value range is too large, or the step is too small");
return;
return false;
}
}
@@ -988,11 +1023,11 @@ void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f
unsigned int count = model->update_print_volume_state(build_volume);
if (count == 0) {
error_message = _L("Unable to calibrate: maybe because the set calibration value range is too large, or the step is too small");
return;
return false;
}
// apply the new print config
DynamicPrintConfig new_print_config = std::move(full_config);
DynamicPrintConfig new_print_config = full_config;
print->apply(*model, new_print_config);
Print *fff_print = dynamic_cast<Print *>(print);
@@ -1006,7 +1041,7 @@ void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f
//}
if (!check_nozzle_diameter_and_type(full_config, error_message))
return;
return false;
fff_print->process();
part_plate->update_slice_result_valid_state(true);
@@ -1045,7 +1080,7 @@ void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f
const ModelVolume &model_volume = *model_object.volumes[volume_idx];
for (int instance_idx = 0; instance_idx < (int)model_object.instances.size(); ++ instance_idx) {
const ModelInstance &model_instance = *model_object.instances[instance_idx];
glvolume_collection.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, "volume", false, true);
glvolume_collection.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, "volume", true, false, true);
glvolume_collection.volumes.back()->set_render_color(new_color);
glvolume_collection.volumes.back()->set_color(new_color);
//glvolume_collection.volumes.back()->printable = model_instance.printable;
@@ -1097,6 +1132,7 @@ void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f
success = Slic3r::store_bbs_3mf(store_params);
release_PlateData_list(plate_data_list);
return true;
}
void CalibUtils::send_to_print(const CalibInfo &calib_info, wxString &error_message, int flow_ratio_mode)

View File

@@ -49,11 +49,11 @@ public:
static void calib_flowrate_X1C(const X1CCalibInfos& calib_infos, std::string& 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 void calib_flowrate(int pass, const CalibInfo &calib_info, wxString &error_message);
static bool calib_flowrate(int pass, const CalibInfo &calib_info, wxString &error_message);
static void calib_pa_pattern(const CalibInfo &calib_info, Model &model);
static void calib_generic_PA(const CalibInfo &calib_info, wxString &error_message);
static bool calib_generic_PA(const CalibInfo &calib_info, wxString &error_message);
static void calib_temptue(const CalibInfo &calib_info, wxString &error_message);
static void calib_max_vol_speed(const CalibInfo &calib_info, wxString &error_message);
static void calib_VFA(const CalibInfo &calib_info, wxString &error_message);
@@ -68,9 +68,9 @@ public:
static bool validate_input_flow_ratio(wxString flow_ratio, float* output_value);
private:
static void process_and_store_3mf(Model* model, const DynamicPrintConfig& full_config, const Calib_Params& params, wxString& error_message);
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
};
}
}
}