diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 718c86b242..78ddb58116 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -2705,7 +2705,7 @@ GCode::LayerResult GCode::process_layer( if (print.calib_mode() == CalibMode::Calib_Temp_Tower) { auto offset = static_cast(print_z / 10.001) * 5; - gcode += writer().set_temperature(print.calib_params().start - offset); + gcode += writer().set_temperature(print.calib_params().end - offset); } else if (print.calib_mode() == CalibMode::Calib_Vol_speed_Tower) { auto _speed = print.calib_params().start + print_z * print.calib_params().step; @@ -3694,7 +3694,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description, } // calculate extrusion length per distance unit - auto _mm3_per_mm = path.mm3_per_mm * (m_curr_print->calib_mode() == CalibMode::Calib_Flow_Rate ? this->config().print_flow_ratio : 1); + auto _mm3_per_mm = path.mm3_per_mm * double(m_curr_print->calib_mode() == CalibMode::Calib_Flow_Rate ? this->config().print_flow_ratio.value : 1); double e_per_mm = m_writer.extruder()->e_per_mm3() * _mm3_per_mm; double min_speed = double(m_config.slow_down_min_speed.get_at(m_writer.extruder()->id())); diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 7b36aebc54..a12c344d53 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1939,8 +1939,9 @@ Preset& PresetCollection::load_preset(const std::string &path, const std::string } //BBS: add project embedded preset logic -void PresetCollection::save_current_preset(const std::string &new_name, bool detach, bool save_to_project) +void PresetCollection::save_current_preset(const std::string &new_name, bool detach, bool save_to_project, Preset* _curr_preset) { + Preset curr_preset = _curr_preset ? *_curr_preset : m_edited_preset; //BBS: add lock logic for sync preset in background std::string final_inherits; lock(); @@ -1959,7 +1960,7 @@ void PresetCollection::save_current_preset(const std::string &new_name, bool det return; } // Overwriting an existing preset. - preset.config = std::move(m_edited_preset.config); + preset.config = std::move(curr_preset.config); // The newly saved preset will be activated -> make it visible. preset.is_visible = true; //TODO: remove the detach logic @@ -1976,7 +1977,7 @@ void PresetCollection::save_current_preset(const std::string &new_name, bool det unlock(); } else { // Creating a new preset. - Preset &preset = *m_presets.insert(it, m_edited_preset); + Preset &preset = *m_presets.insert(it, curr_preset); std::string &inherits = preset.inherits(); std::string old_name = preset.name; preset.name = new_name; diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index e319f60cbc..c509dd8dac 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -474,7 +474,7 @@ public: // a new preset is stored into the list of presets. // All presets are marked as not modified and the new preset is activated. //BBS: add project embedded preset logic - void save_current_preset(const std::string &new_name, bool detach = false, bool save_to_project = false); + void save_current_preset(const std::string &new_name, bool detach = false, bool save_to_project = false, Preset* _curr_preset = nullptr); // Delete the current preset, activate the first visible preset. // returns true if the preset was deleted successfully. diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index ad9cd1e669..158b92766c 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -255,6 +255,8 @@ PresetsConfigSubstitutions PresetBundle::load_presets(AppConfig &config, Forward this->load_selections(config, preferred_selection); + set_calibrate_printer(""); + //BBS: add config related logs BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" finished, returned substitutions %1%")%substitutions.size(); return substitutions; @@ -539,6 +541,9 @@ PresetsConfigSubstitutions PresetBundle::load_user_presets(std::string user, For if (!errors_cummulative.empty()) throw Slic3r::RuntimeError(errors_cummulative); this->update_multi_material_filament_presets(); this->update_compatible(PresetSelectCompatibleType::Never); + + set_calibrate_printer(""); + return PresetsConfigSubstitutions(); } @@ -606,6 +611,8 @@ PresetsConfigSubstitutions PresetBundle::load_user_presets(AppConfig & this->update_compatible(PresetSelectCompatibleType::Never); //this->load_selections(config, PresetPreferences()); + set_calibrate_printer(""); + if (! errors_cummulative.empty()) throw Slic3r::RuntimeError(errors_cummulative); @@ -1441,7 +1448,8 @@ unsigned int PresetBundle::sync_ams_list(unsigned int &unknowns) { std::vector filament_presets; std::vector filament_colors; - for (auto &ams : filament_ams_list) { + for (auto &entry : filament_ams_list) { + auto & ams = entry.second; auto filament_id = ams.opt_string("filament_id", 0u); auto filament_color = ams.opt_string("filament_colour", 0u); auto filament_changed = !ams.has("filament_changed") || ams.opt_bool("filament_changed"); @@ -1478,6 +1486,29 @@ unsigned int PresetBundle::sync_ams_list(unsigned int &unknowns) return filament_presets.size(); } +void PresetBundle::set_calibrate_printer(std::string name) +{ + if (name.empty()) { + calibrate_filaments.clear(); + return; + } + if (!name.empty()) + calibrate_printer = printers.find_preset(name); + const Preset & printer_preset = calibrate_printer ? *calibrate_printer : printers.get_edited_preset(); + const PresetWithVendorProfile active_printer = printers.get_preset_with_vendor_profile(printer_preset); + DynamicPrintConfig config; + config.set_key_value("printer_preset", new ConfigOptionString(active_printer.preset.name)); + const ConfigOption *opt = active_printer.preset.config.option("nozzle_diameter"); + if (opt) config.set_key_value("num_extruders", new ConfigOptionInt((int) static_cast(opt)->values.size())); + calibrate_filaments.clear(); + for (size_t i = filaments.num_default_presets(); i < filaments.size(); ++i) { + const Preset & preset = filaments.m_presets[i]; + const PresetWithVendorProfile this_preset_with_vendor_profile = filaments.get_preset_with_vendor_profile(preset); + bool is_compatible = is_compatible_with_printer(this_preset_with_vendor_profile, active_printer, &config); + if (is_compatible) calibrate_filaments.insert(&preset); + } +} + //BBS: check whether this is the only edited filament bool PresetBundle::is_the_only_edited_filament(unsigned int filament_index) { diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 854baf804b..d28ccc1e0b 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -86,6 +86,8 @@ public: //BBS: check whether this is the only edited filament bool is_the_only_edited_filament(unsigned int filament_index); + void set_calibrate_printer(std::string name); + PresetCollection prints; PresetCollection sla_prints; PresetCollection filaments; @@ -98,7 +100,10 @@ public: // extruders.size() should be the same as printers.get_edited_preset().config.nozzle_diameter.size() std::vector filament_presets; // BBS: ams - std::vector filament_ams_list; + std::map filament_ams_list; + // Calibrate + Preset const * calibrate_printer = nullptr; + std::set calibrate_filaments; // The project configuration values are kept separated from the print/filament/printer preset, // they are being serialized / deserialized from / to the .amf, .3mf, .config, .gcode, diff --git a/src/slic3r/GUI/CalibrationPanel.cpp b/src/slic3r/GUI/CalibrationPanel.cpp index 1f5a1bde43..5b12b7fe8d 100644 --- a/src/slic3r/GUI/CalibrationPanel.cpp +++ b/src/slic3r/GUI/CalibrationPanel.cpp @@ -2,12 +2,12 @@ #include "I18N.hpp" namespace Slic3r { namespace GUI { +#define REFRESH_INTERVAL 1000 CalibrationPanel::CalibrationPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : wxPanel(parent, id, pos, size, style) { SetBackgroundColour(*wxWHITE); - //init_bitmaps(); init_tabpanel(); wxBoxSizer* sizer_main = new wxBoxSizer(wxVERTICAL); @@ -15,6 +15,9 @@ CalibrationPanel::CalibrationPanel(wxWindow* parent, wxWindowID id, const wxPoin SetSizerAndFit(sizer_main); Layout(); + + init_timer(); + Bind(wxEVT_TIMER, &CalibrationPanel::on_timer, this); } void CalibrationPanel::init_tabpanel() { @@ -25,8 +28,8 @@ void CalibrationPanel::init_tabpanel() { m_tabpanel = new Tabbook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, sizer_side_tools, wxNB_LEFT | wxTAB_TRAVERSAL | wxNB_NOPAGETHEME); m_tabpanel->SetBackgroundColour(*wxWHITE); - //m_pa_panel = new CalibrationWizard(m_tabpanel); - //m_tabpanel->AddPage(m_pa_panel, _L("Pressure Adavance"), "", true); + m_pa_panel = new PressureAdvanceWizard(m_tabpanel); + m_tabpanel->AddPage(m_pa_panel, _L("Pressure Adavance"), "", true); m_flow_panel = new FlowRateWizard(m_tabpanel); m_tabpanel->AddPage(m_flow_panel, _L("Flow Rate"), "", false); @@ -35,39 +38,38 @@ void CalibrationPanel::init_tabpanel() { m_tabpanel->AddPage(m_volumetric_panel, _L("Max Volumetric Speed"), "", false); m_temp_panel = new TemperatureWizard(m_tabpanel); - m_tabpanel->AddPage(m_temp_panel, _L("Temperature"), "", true); - - //m_vfa_panel = new CalibrationWizard(m_tabpanel); - //m_tabpanel->AddPage(m_vfa_panel, _L("VFA"), "", false); - - //m_tabpanel->Bind(wxEVT_BOOKCTRL_PAGE_CHANGED, [this](wxBookCtrlEvent& e) { - // CalibrationWizard* page = static_cast(m_tabpanel->GetCurrentPage()); - // if (page->get_frist_page()) { - // page->update_comboboxes(); - // } - // }, m_tabpanel->GetId()); + m_tabpanel->AddPage(m_temp_panel, _L("Temperature"), "", false); } -void CalibrationPanel::update_obj(MachineObject* obj) { - if (obj) { - if (m_pa_panel) - m_pa_panel->update_obj(obj); - if (m_flow_panel) { - m_flow_panel->update_obj(obj); - m_flow_panel->update_ams(obj); - } - if (m_volumetric_panel) { - m_volumetric_panel->update_obj(obj); - m_volumetric_panel->update_ams(obj); - } - if (m_temp_panel) { - m_temp_panel->update_obj(obj); - m_temp_panel->update_ams(obj); - m_temp_panel->update_progress(); - } - if (m_vfa_panel) { - m_vfa_panel->update_obj(obj); - } +void CalibrationPanel::init_timer() +{ + m_refresh_timer = new wxTimer(); + m_refresh_timer->SetOwner(this); + m_refresh_timer->Start(REFRESH_INTERVAL); + wxPostEvent(this, wxTimerEvent()); +} + +void CalibrationPanel::on_timer(wxTimerEvent& event) { + // todo only update at CalibrationPanel + update_all(); +} + +void CalibrationPanel::update_all() { + if (m_pa_panel) { + m_pa_panel->update_printer_selections(); + m_pa_panel->update_print_progress(); + } + if (m_flow_panel) { + m_flow_panel->update_printer_selections(); + m_flow_panel->update_print_progress(); + } + if (m_volumetric_panel) { + m_volumetric_panel->update_printer_selections(); + m_volumetric_panel->update_print_progress(); + } + if (m_temp_panel) { + m_temp_panel->update_printer_selections(); + m_temp_panel->update_print_progress(); } } diff --git a/src/slic3r/GUI/CalibrationPanel.hpp b/src/slic3r/GUI/CalibrationPanel.hpp index 200a6be1af..526f944471 100644 --- a/src/slic3r/GUI/CalibrationPanel.hpp +++ b/src/slic3r/GUI/CalibrationPanel.hpp @@ -12,14 +12,12 @@ public: CalibrationPanel(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL); ~CalibrationPanel() {}; Tabbook* get_tabpanel() { return m_tabpanel; }; - void update_obj(MachineObject* obj); + void update_all(); protected: - void init_bitmaps(); void init_tabpanel(); - - //void show_wizard(); - //CalibrationWizard* get_current_wizard(); + void init_timer(); + void on_timer(wxTimerEvent& event); private: Tabbook* m_tabpanel{ nullptr }; @@ -30,6 +28,8 @@ private: CalibrationWizard* m_volumetric_panel{ nullptr }; TemperatureWizard* m_temp_panel{ nullptr }; CalibrationWizard* m_vfa_panel{ nullptr }; + + wxTimer* m_refresh_timer = nullptr; }; }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/CalibrationWizard.cpp b/src/slic3r/GUI/CalibrationWizard.cpp index 6507ce4c3e..1a87170122 100644 --- a/src/slic3r/GUI/CalibrationWizard.cpp +++ b/src/slic3r/GUI/CalibrationWizard.cpp @@ -5,137 +5,509 @@ #include "../../libslic3r/Calib.hpp" #define CALIBRATION_COMBOX_SIZE wxSize(FromDIP(500), FromDIP(24)) +#define CALIBRATION_AMS_COMBOX_SIZE wxSize(FromDIP(250), FromDIP(24)) #define CALIBRATION_OPTIMAL_INPUT_SIZE wxSize(FromDIP(300), FromDIP(24)) #define CALIBRATION_FROM_TO_INPUT_SIZE wxSize(FromDIP(160), FromDIP(24)) +#define CALIBRATION_FGSIZER_HGAP FromDIP(50) +#define CALIBRATION_TEXT_MAX_LENGTH FromDIP(90) + CALIBRATION_FGSIZER_HGAP + 2 * CALIBRATION_AMS_COMBOX_SIZE.x +static const wxString NA_STR = _L("N/A"); + namespace Slic3r { namespace GUI { +wxDEFINE_EVENT(EVT_CALIBRATION_TRAY_SELECTION_CHANGED, SimpleEvent); + +FilamentComboBox::FilamentComboBox(wxWindow* parent, const wxPoint& pos, const wxSize& size) + : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL) +{ + wxBoxSizer* main_sizer = new wxBoxSizer(wxHORIZONTAL); + + m_comboBox = new CalibrateFilamentComboBox(this); + m_comboBox->SetSize(CALIBRATION_AMS_COMBOX_SIZE); + m_comboBox->SetMinSize(CALIBRATION_AMS_COMBOX_SIZE); + main_sizer->Add(m_comboBox->clr_picker, 0, wxALIGN_CENTER | wxRIGHT, FromDIP(8)); + main_sizer->Add(m_comboBox, 0, wxALIGN_CENTER); + + this->SetSizer(main_sizer); + this->Layout(); + main_sizer->Fit(this); +} + +void FilamentComboBox::set_select_mode(FilamentSelectMode mode) +{ + m_mode = mode; + if (m_checkBox) + m_checkBox->Show(m_mode == FSMCheckBoxMode); + if (m_radioBox) + m_radioBox->Show(m_mode == FSMRadioMode); + + Layout(); +} + +void FilamentComboBox::load_tray_from_ams(int id, DynamicPrintConfig& tray) +{ + m_tray_id = id; + m_comboBox->load_tray(tray); + Enable(m_comboBox->is_tray_exist()); +} + +void FilamentComboBox::update_from_preset() { m_comboBox->update(); } + +bool FilamentComboBox::Show(bool show) +{ + bool result = wxPanel::Show(show); + if (m_radioBox && m_mode == FSMRadioMode) + result = result && m_radioBox->Show(show); + if (m_checkBox && m_mode == FSMCheckBoxMode) + result = result && m_checkBox->Show(show); + return result; +} + +bool FilamentComboBox::Enable(bool enable) { + bool result = wxPanel::Enable(enable); + if (m_radioBox) + result = result && m_radioBox->Enable(enable); + if (m_checkBox) { + if (!enable) + m_checkBox->SetValue(false); + result = result && m_checkBox->Enable(enable); + } + return result; +} + +void FilamentComboBox::SetValue(bool value) { + if (m_radioBox) + m_radioBox->SetValue(value); + if (m_checkBox) + m_checkBox->SetValue(value); + SimpleEvent e(EVT_CALIBRATION_TRAY_SELECTION_CHANGED); + e.ResumePropagation(wxEVENT_PROPAGATE_MAX); + e.SetEventObject(this); + wxPostEvent(this, e); +} + CalibrationWizard::CalibrationWizard(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : wxPanel(parent, id, pos, size, style) { SetBackgroundColour(wxColour(0xEEEEEE)); - m_background_panel = new wxPanel(this); - m_background_panel->SetBackgroundColour(*wxWHITE); wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL); + m_scrolledWindow = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL | wxVSCROLL); + m_scrolledWindow->SetScrollRate(5, 5); + m_scrolledWindow->SetBackgroundColour(*wxWHITE); + + m_all_pages_sizer = new wxBoxSizer(wxVERTICAL); + + m_scrolledWindow->SetSizer(m_all_pages_sizer); + m_scrolledWindow->Layout(); + m_all_pages_sizer->Fit(m_scrolledWindow); + create_presets_panel(); init_presets_selections(); - create_progress_bar(); + create_send_progress_bar(); - main_sizer->Add(m_background_panel, 1, wxEXPAND | wxALL, FromDIP(10)); + create_print_panel(); + + main_sizer->Add(m_scrolledWindow, 1, wxEXPAND | wxALL, FromDIP(10)); this->SetSizer(main_sizer); this->Layout(); main_sizer->Fit(this); m_comboBox_printer->Bind(wxEVT_COMBOBOX, &CalibrationWizard::on_select_printer, this); - m_comboBox_filament->Bind(wxEVT_COMBOBOX, &CalibrationWizard::on_select_filament, this); + m_comboBox_nozzle_dia->Bind(wxEVT_COMBOBOX, &CalibrationWizard::on_select_nozzle, this); m_comboBox_bed_type->Bind(wxEVT_COMBOBOX, &CalibrationWizard::on_select_bed_type, this); - m_comboBox_process->Bind(wxEVT_COMBOBOX, &CalibrationWizard::on_select_process, this); + m_button_pause_resume->Bind(wxEVT_BUTTON, &CalibrationWizard::on_subtask_pause_resume, this); + m_button_abort->Bind(wxEVT_BUTTON, &CalibrationWizard::on_subtask_abort, this); + m_ams_sync_button->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) { + on_update_ams_filament(); + }); + m_ams_radiobox->Bind(wxEVT_RADIOBUTTON, &CalibrationWizard::on_choose_ams, this); + m_ext_spool_radiobox->Bind(wxEVT_RADIOBUTTON, &CalibrationWizard::on_choose_ext_spool, this); Bind(EVT_CALIBRATIONPAGE_PREV, &CalibrationWizard::on_click_btn_prev, this); Bind(EVT_CALIBRATIONPAGE_NEXT, &CalibrationWizard::on_click_btn_next, this); + Bind(EVT_CALIBRATION_TRAY_SELECTION_CHANGED, &CalibrationWizard::on_select_tray, this); +#if 1 /*debug*/ + this->Bind(wxEVT_CHAR_HOOK, [this](auto& evt) { + const int keyCode = evt.GetKeyCode(); + switch (keyCode) + { + case WXK_NUMPAD_PAGEUP: case WXK_PAGEUP: + show_page(get_curr_page()->get_prev_page()); + break; + case WXK_NUMPAD_PAGEDOWN: case WXK_PAGEDOWN: + { + show_page(get_curr_page()->get_next_page()); + break; + } + default: + evt.Skip(); + break; + } + }); +#endif } void CalibrationWizard::create_presets_panel() { - m_presets_panel = new wxPanel(m_background_panel); - auto panel_sizer = new wxBoxSizer(wxVERTICAL); + const int PRESET_GAP = FromDIP(25); - m_ams_control = new AMSControl(m_presets_panel); - m_ams_control->EnterSimpleMode(); - panel_sizer->Add(m_ams_control, 0, wxALL, 0); + m_presets_panel = new wxPanel(m_scrolledWindow); + auto panel_sizer = new wxBoxSizer(wxVERTICAL); auto printer_combo_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("Printer"), wxDefaultPosition, wxDefaultSize, 0); printer_combo_text->Wrap(-1); + printer_combo_text->SetFont(Label::Head_14); panel_sizer->Add(printer_combo_text, 0, wxALL, 0); - m_comboBox_printer = new ComboBox(m_presets_panel, wxID_ANY, "", wxDefaultPosition, CALIBRATION_COMBOX_SIZE, 0, nullptr, wxCB_READONLY); panel_sizer->Add(m_comboBox_printer, 0, wxALL, 0); - panel_sizer->Add(0, FromDIP(10), 0, wxEXPAND, 0); + panel_sizer->AddSpacer(PRESET_GAP); - auto filament_combo_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("Filament"), wxDefaultPosition, wxDefaultSize, 0); - filament_combo_text->Wrap(-1); - panel_sizer->Add(filament_combo_text, 0, wxALL, 0); + auto nozzle_combo_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("Nozzle"), wxDefaultPosition, wxDefaultSize, 0); + nozzle_combo_text->Wrap(-1); + nozzle_combo_text->SetFont(Label::Head_14); + panel_sizer->Add(nozzle_combo_text, 0, wxALL, 0); + m_comboBox_nozzle_dia = new ComboBox(m_presets_panel, wxID_ANY, "", wxDefaultPosition, CALIBRATION_COMBOX_SIZE, 0, nullptr, wxCB_READONLY); + panel_sizer->Add(m_comboBox_nozzle_dia, 0, wxALL, 0); - m_comboBox_filament = new ComboBox(m_presets_panel, wxID_ANY, "", wxDefaultPosition, CALIBRATION_COMBOX_SIZE, 0, nullptr, wxCB_READONLY); - panel_sizer->Add(m_comboBox_filament, 0, wxALL, 0); - - panel_sizer->Add(0, FromDIP(10), 0, wxEXPAND, 0); + panel_sizer->AddSpacer(PRESET_GAP); auto plate_type_combo_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("Plate Type"), wxDefaultPosition, wxDefaultSize, 0); plate_type_combo_text->Wrap(-1); + plate_type_combo_text->SetFont(Label::Head_14); panel_sizer->Add(plate_type_combo_text, 0, wxALL, 0); - m_comboBox_bed_type = new ComboBox(m_presets_panel, wxID_ANY, "", wxDefaultPosition, CALIBRATION_COMBOX_SIZE, 0, nullptr, wxCB_READONLY); panel_sizer->Add(m_comboBox_bed_type, 0, wxALL, 0); - panel_sizer->Add(0, FromDIP(10), 0, wxEXPAND, 0); + panel_sizer->AddSpacer(PRESET_GAP); - auto process_combo_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("Process"), wxDefaultPosition, wxDefaultSize, 0); - process_combo_text->Wrap(-1); - panel_sizer->Add(process_combo_text, 0, wxALL, 0); + {// Hide + auto process_combo_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("Process"), wxDefaultPosition, wxDefaultSize, 0); + process_combo_text->Hide(); + process_combo_text->Wrap(-1); + panel_sizer->Add(process_combo_text, 0, wxALL, 0); + m_comboBox_process = new ComboBox(m_presets_panel, wxID_ANY, "", wxDefaultPosition, CALIBRATION_COMBOX_SIZE, 0, nullptr, wxCB_READONLY); + m_comboBox_process->Hide(); + panel_sizer->Add(m_comboBox_process, 0, wxALL, 0); + }// Hide - m_comboBox_process = new ComboBox(m_presets_panel, wxID_ANY, "", wxDefaultPosition, CALIBRATION_COMBOX_SIZE, 0, nullptr, wxCB_READONLY); - panel_sizer->Add(m_comboBox_process, 0, wxALL, 0); + m_select_ams_mode_panel = new wxPanel(m_presets_panel); + auto choose_ams_sizer = new wxBoxSizer(wxVERTICAL); + auto filament_from_text = new wxStaticText(m_select_ams_mode_panel, wxID_ANY, _L("Filament From"), wxDefaultPosition, wxDefaultSize, 0); + filament_from_text->SetFont(Label::Head_14); + choose_ams_sizer->Add(filament_from_text, 0); + auto raioBox_sizer = new wxFlexGridSizer(2, 1, 0, FromDIP(10)); + m_ams_radiobox = new wxRadioButton(m_select_ams_mode_panel, wxID_ANY, _L("AMS")); + m_ams_radiobox->SetValue(true); + raioBox_sizer->Add(m_ams_radiobox, 0); + //auto ams_text = new wxStaticText(m_choose_ams_panel, wxID_ANY, _L("AMS"), wxDefaultPosition, wxDefaultSize, 0); + //raioBox_sizer->Add(ams_text); + m_ext_spool_radiobox = new wxRadioButton(m_select_ams_mode_panel, wxID_ANY, _L("External Spool")); + raioBox_sizer->Add(m_ext_spool_radiobox, 0); + //auto ext_spool_text = new wxStaticText(m_choose_ams_panel, wxID_ANY, _L("External Spool"), wxDefaultPosition, wxDefaultSize, 0); + //raioBox_sizer->Add(ext_spool_text, 0); + choose_ams_sizer->Add(raioBox_sizer, 0); + m_select_ams_mode_panel->SetSizer(choose_ams_sizer); + panel_sizer->Add(m_select_ams_mode_panel, 0); - m_presets_panel->SetSizer(panel_sizer); - m_presets_panel->Layout(); - panel_sizer->Fit(m_presets_panel); + panel_sizer->AddSpacer(PRESET_GAP); + + auto filament_for_title_sizer = new wxBoxSizer(wxHORIZONTAL); + auto filament_for_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("Filament For Calibration"), wxDefaultPosition, wxDefaultSize, 0); + filament_for_text->SetFont(Label::Head_14); + filament_for_title_sizer->Add(filament_for_text, 0, wxALIGN_CENTER); + filament_for_title_sizer->AddSpacer(FromDIP(25)); + m_ams_sync_button = new ScalableButton(m_presets_panel, wxID_ANY, "ams_fila_sync", wxEmptyString, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, false, 18); + m_ams_sync_button->SetBackgroundColour(*wxWHITE); + m_ams_sync_button->SetToolTip(_L("Synchronize filament list from AMS")); + filament_for_title_sizer->Add(m_ams_sync_button, 0, wxALIGN_CENTER, 0); + panel_sizer->Add(filament_for_title_sizer); + m_filament_list_panel = new wxPanel(m_presets_panel); + auto filament_list_sizer = new wxBoxSizer(wxVERTICAL); + auto filament_list_tips = new wxStaticText(m_filament_list_panel, wxID_ANY, _L("Please select same type of material, because plate temperature might not be compatible with different type of material"), wxDefaultPosition, wxDefaultSize, 0); + filament_list_tips->SetFont(Label::Body_13); + filament_list_tips->SetForegroundColour(wxColour(145, 145, 145)); + filament_list_tips->Wrap(CALIBRATION_TEXT_MAX_LENGTH); + filament_list_sizer->Add(filament_list_tips); + filament_list_sizer->AddSpacer(FromDIP(10)); + m_muilti_ams_panel = new wxPanel(m_filament_list_panel); + auto multi_ams_sizer = new wxBoxSizer(wxVERTICAL); + auto ams_items_sizer = new wxBoxSizer(wxHORIZONTAL); + for (int i = 0; i < 4; i++) { + AMSinfo temp_info = AMSinfo{ std::to_string(i), std::vector{} }; + auto amsitem = new AMSItem(m_muilti_ams_panel, wxID_ANY, temp_info); + amsitem->Bind(wxEVT_LEFT_DOWN, [this, amsitem](wxMouseEvent& e) { + on_switch_ams(amsitem->m_amsinfo.ams_id); + e.Skip(); + }); + m_ams_item_list.push_back(amsitem); + ams_items_sizer->Add(amsitem, 0, wxALIGN_CENTER | wxRIGHT, FromDIP(6)); + } + multi_ams_sizer->Add(ams_items_sizer, 0); + multi_ams_sizer->AddSpacer(FromDIP(10)); + m_muilti_ams_panel->SetSizer(multi_ams_sizer); + filament_list_sizer->Add(m_muilti_ams_panel); + m_muilti_ams_panel->Hide(); + auto filament_fgSizer = new wxFlexGridSizer(2, 2, FromDIP(10), CALIBRATION_FGSIZER_HGAP); + for (int i = 0; i < 16; i++) { + auto filament_comboBox_sizer = new wxBoxSizer(wxHORIZONTAL); + wxRadioButton* radio_btn = new wxRadioButton(m_filament_list_panel, wxID_ANY, ""); + CheckBox* check_box = new CheckBox(m_filament_list_panel); + check_box->SetBackgroundColour(*wxWHITE); + FilamentComboBox* fcb = new FilamentComboBox(m_filament_list_panel); + fcb->SetRadioBox(radio_btn); + fcb->SetCheckBox(check_box); + fcb->set_select_mode(FilamentSelectMode::FSMRadioMode); + filament_comboBox_sizer->Add(radio_btn, 0, wxALIGN_CENTER); + filament_comboBox_sizer->Add(check_box, 0, wxALIGN_CENTER | wxRIGHT, FromDIP(8)); + filament_comboBox_sizer->Add(fcb, 0, wxALIGN_CENTER); + filament_fgSizer->Add(filament_comboBox_sizer, 0); + radio_btn->Bind(wxEVT_RADIOBUTTON, [this](wxCommandEvent& event) { + SimpleEvent e(EVT_CALIBRATION_TRAY_SELECTION_CHANGED); + e.SetEventObject(this); + wxPostEvent(this, e); + event.Skip(); + }); + check_box->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& event) { + SimpleEvent e(EVT_CALIBRATION_TRAY_SELECTION_CHANGED); + e.SetEventObject(this); + wxPostEvent(this, e); + event.Skip(); + }); + m_filament_comboBox_list.push_back(fcb); + + if (i >= 4) + fcb->Show(false); + } + filament_list_sizer->Add(filament_fgSizer, 0); + m_filament_list_panel->SetSizer(filament_list_sizer); + panel_sizer->Add(m_filament_list_panel, 0); + + {// Hide + m_virtual_panel = new wxPanel(m_presets_panel); + auto virtual_sizer = new wxBoxSizer(wxHORIZONTAL); + virtual_sizer->AddSpacer(FromDIP(10)); + wxRadioButton* radio_btn = new wxRadioButton(m_virtual_panel, wxID_ANY, ""); + CheckBox* check_box = new CheckBox(m_virtual_panel); + m_virtual_tray_comboBox = new FilamentComboBox(m_virtual_panel); + m_virtual_tray_comboBox->SetRadioBox(radio_btn); + m_virtual_tray_comboBox->SetCheckBox(check_box); + m_virtual_tray_comboBox->set_select_mode(FilamentSelectMode::FSMRadioMode); + radio_btn->Bind(wxEVT_RADIOBUTTON, [this](wxCommandEvent& event) { + SimpleEvent e(EVT_CALIBRATION_TRAY_SELECTION_CHANGED); + e.SetEventObject(this); + wxPostEvent(this, e); + event.Skip(); + }); + virtual_sizer->Add(radio_btn, 0, wxALIGN_CENTER); + virtual_sizer->Add(check_box, 0, wxALIGN_CENTER); + virtual_sizer->Add(m_virtual_tray_comboBox, 0, wxALIGN_CENTER | wxRIGHT, FromDIP(8)); + m_virtual_panel->SetSizer(virtual_sizer); + m_virtual_panel->Hide(); + panel_sizer->Add(m_virtual_panel, 0); + }// Hide + + panel_sizer->AddSpacer(PRESET_GAP); - panel_sizer->Add(0, FromDIP(10), 0, wxEXPAND, 0); wxBoxSizer* horiz_sizer; horiz_sizer = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* from_sizer; from_sizer = new wxBoxSizer(wxVERTICAL); - m_from_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("From"), wxDefaultPosition, wxDefaultSize, 0); m_from_text->Wrap(-1); m_from_text->SetFont(::Label::Body_14); from_sizer->Add(m_from_text, 0, wxALL, 0); - m_from_value = new TextInput(m_presets_panel, wxEmptyString, _L("\u2103"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, 0); m_from_value->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); from_sizer->Add(m_from_value, 0, wxALL, 0); - horiz_sizer->Add(from_sizer, 0, wxEXPAND, 0); horiz_sizer->Add(FromDIP(10), 0, 0, wxEXPAND, 0); wxBoxSizer* to_sizer; to_sizer = new wxBoxSizer(wxVERTICAL); - m_to_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("To"), wxDefaultPosition, wxDefaultSize, 0); m_to_text->Wrap(-1); m_to_text->SetFont(::Label::Body_14); to_sizer->Add(m_to_text, 0, wxALL, 0); - m_to_value = new TextInput(m_presets_panel, wxEmptyString, _L("\u2103"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, 0); m_to_value->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); to_sizer->Add(m_to_value, 0, wxALL, 0); - horiz_sizer->Add(to_sizer, 0, wxEXPAND, 0); horiz_sizer->Add(FromDIP(10), 0, 0, wxEXPAND, 0); wxBoxSizer* step_sizer; step_sizer = new wxBoxSizer(wxVERTICAL); - m_step_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("Step"), wxDefaultPosition, wxDefaultSize, 0); m_step_text->Wrap(-1); m_step_text->SetFont(::Label::Body_14); step_sizer->Add(m_step_text, 0, wxALL, 0); - m_step = new TextInput(m_presets_panel, "5", _L("\u2103"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, 0); m_step->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); step_sizer->Add(m_step, 0, wxALL, 0); - horiz_sizer->Add(step_sizer, 0, wxEXPAND, 0); - panel_sizer->Add(horiz_sizer, 0, wxEXPAND, 0); + + panel_sizer->AddSpacer(PRESET_GAP * 6); + + auto info_sizer = new wxFlexGridSizer(0, 3, 0, FromDIP(10)); + info_sizer->SetFlexibleDirection(wxBOTH); + info_sizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); + + auto nozzle_temp_sizer = new wxBoxSizer(wxVERTICAL); + auto nozzle_temp_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("Nozzle temperature")); + m_nozzle_temp = new TextInput(m_presets_panel, wxEmptyString, _L("\u2103"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, wxTE_READONLY); + nozzle_temp_sizer->Add(nozzle_temp_text, 0, wxALIGN_LEFT); + nozzle_temp_sizer->Add(m_nozzle_temp, 0, wxEXPAND); + + auto bed_temp_sizer = new wxBoxSizer(wxVERTICAL); + auto bed_temp_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("Bed temperature")); + m_bed_temp = new TextInput(m_presets_panel, wxEmptyString, _L("\u2103"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, wxTE_READONLY); + bed_temp_sizer->Add(bed_temp_text, 0, wxALIGN_LEFT); + bed_temp_sizer->Add(m_bed_temp, 0, wxEXPAND); + + auto max_flow_sizer = new wxBoxSizer(wxVERTICAL); + auto max_flow_text = new wxStaticText(m_presets_panel, wxID_ANY, _L("Max volumetric speed")); + m_max_volumetric_speed = new TextInput(m_presets_panel, wxEmptyString, _L("mm\u00B3"), "", wxDefaultPosition, CALIBRATION_FROM_TO_INPUT_SIZE, wxTE_READONLY); + max_flow_sizer->Add(max_flow_text, 0, wxALIGN_LEFT); + max_flow_sizer->Add(m_max_volumetric_speed, 0, wxEXPAND); + + m_nozzle_temp->GetTextCtrl()->Bind(wxEVT_SET_FOCUS, [](auto&) {}); + m_bed_temp->GetTextCtrl()->Bind(wxEVT_SET_FOCUS, [](auto&) {}); + m_max_volumetric_speed->GetTextCtrl()->Bind(wxEVT_SET_FOCUS, [](auto&) {}); + + info_sizer->Add(nozzle_temp_sizer); + info_sizer->Add(bed_temp_sizer); + info_sizer->Add(max_flow_sizer); + panel_sizer->Add(info_sizer, 0, wxEXPAND); + + m_filaments_incompatible_tips = new wxStaticText(m_presets_panel, wxID_ANY, _L("filaments incompatible, please select same type of material")); + m_filaments_incompatible_tips->SetFont(Label::Body_13); + m_filaments_incompatible_tips->SetForegroundColour(wxColour(230, 92, 92)); + m_filaments_incompatible_tips->Wrap(CALIBRATION_TEXT_MAX_LENGTH); + m_filaments_incompatible_tips->Hide(); + panel_sizer->Add(m_filaments_incompatible_tips, 0, wxEXPAND); + + m_bed_type_incompatible_tips = new wxStaticText(m_presets_panel, wxID_ANY, _L("filaments incompatible, please select same type of material")); + m_bed_type_incompatible_tips->SetFont(Label::Body_13); + m_bed_type_incompatible_tips->SetForegroundColour(wxColour(230, 92, 92)); + m_bed_type_incompatible_tips->Wrap(CALIBRATION_TEXT_MAX_LENGTH); + m_bed_type_incompatible_tips->Hide(); + panel_sizer->Add(m_bed_type_incompatible_tips, 0, wxEXPAND); + + m_presets_panel->SetSizer(panel_sizer); + m_presets_panel->Layout(); + panel_sizer->Fit(m_presets_panel); +} + +void CalibrationWizard::create_print_panel() { + m_print_panel = new wxPanel(m_scrolledWindow); + m_print_panel->SetSize({ FromDIP(600),-1 }); + m_print_panel->SetMinSize({ FromDIP(600),-1 }); + auto panel_sizer = new wxBoxSizer(wxVERTICAL); + + wxPanel* panel_text = new wxPanel(m_print_panel); + panel_text->SetBackgroundColour(*wxWHITE); + + wxBoxSizer* text_sizer = new wxBoxSizer(wxHORIZONTAL); + + m_staticText_progress_percent = new wxStaticText(panel_text, wxID_ANY, "0%", wxDefaultPosition, wxDefaultSize, 0); + m_staticText_progress_percent->SetFont(::Label::Head_18); + m_staticText_progress_percent->SetForegroundColour(wxColour(0, 174, 66)); + + m_staticText_layers = new wxStaticText(panel_text, wxID_ANY, _L("Layer: N/A")); + m_staticText_layers->SetFont(::Label::Body_15); + m_staticText_layers->SetForegroundColour(wxColour(146, 146, 146)); + + m_staticText_progress_left_time = new wxStaticText(panel_text, wxID_ANY, NA_STR, wxDefaultPosition, wxDefaultSize, 0); + m_staticText_progress_left_time->Wrap(-1); + m_staticText_progress_left_time->SetFont(::Label::Body_15); + m_staticText_progress_left_time->SetForegroundColour(wxColour(146, 146, 146)); + + text_sizer->Add(m_staticText_progress_percent, 0, wxALIGN_CENTER, 0); + text_sizer->Add(0, 0, 1, wxEXPAND, 0); + text_sizer->Add(m_staticText_layers, 0, wxALIGN_CENTER | wxALL, 0); + text_sizer->Add(0, 0, 0, wxLEFT, FromDIP(20)); + text_sizer->Add(m_staticText_progress_left_time, 0, wxALIGN_CENTER | wxALL, 0); + text_sizer->AddSpacer(FromDIP(90)); + + panel_text->SetSizer(text_sizer); + + auto panel_progressbar = new wxPanel(m_print_panel, wxID_ANY); + panel_progressbar->SetBackgroundColour(*wxWHITE); + auto progressbar_sizer = new wxBoxSizer(wxHORIZONTAL); + + m_print_gauge_progress = new ProgressBar(panel_progressbar, wxID_ANY, 100, wxDefaultPosition, wxDefaultSize); + m_print_gauge_progress->SetValue(0); + m_print_gauge_progress->SetHeight(FromDIP(8)); + m_print_gauge_progress->SetSize(wxSize(FromDIP(400), -1)); + m_print_gauge_progress->SetMinSize(wxSize(FromDIP(400), -1)); + + m_button_pause_resume = new ScalableButton(panel_progressbar, wxID_ANY, "print_control_pause", wxEmptyString, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, true); + m_button_pause_resume->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) { + if (m_button_pause_resume->GetToolTipText() == _L("Pause")) { + m_button_pause_resume->SetBitmap_("print_control_pause_hover"); + } + + if (m_button_pause_resume->GetToolTipText() == _L("Resume")) { + m_button_pause_resume->SetBitmap_("print_control_resume_hover"); + } + }); + m_button_pause_resume->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) { + if (m_button_pause_resume->GetToolTipText() == _L("Pause")) { + m_button_pause_resume->SetBitmap_("print_control_pause"); + } + + if (m_button_pause_resume->GetToolTipText() == _L("Resume")) { + m_button_pause_resume->SetBitmap_("print_control_resume"); + } + }); + + m_button_abort = new ScalableButton(panel_progressbar, wxID_ANY, "print_control_stop", wxEmptyString, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER, true); + m_button_abort->SetToolTip(_L("Stop")); + m_button_abort->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) { + m_button_abort->SetBitmap_("print_control_stop_hover"); + }); + m_button_abort->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) { + m_button_abort->SetBitmap_("print_control_stop"); } + ); + + progressbar_sizer->Add(m_print_gauge_progress, 1, wxALIGN_CENTER_VERTICAL, 0); + progressbar_sizer->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(18)); + progressbar_sizer->Add(m_button_pause_resume, 0, wxALL, FromDIP(5)); + progressbar_sizer->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(18)); + progressbar_sizer->Add(m_button_abort, 0, wxALL, FromDIP(5)); + + panel_progressbar->SetSizer(progressbar_sizer); + + panel_sizer->AddSpacer(FromDIP(15)); + panel_sizer->Add(panel_text, 0, wxEXPAND, 0); + panel_sizer->Add(panel_progressbar, 0, wxEXPAND, 0); + panel_sizer->AddSpacer(FromDIP(15)); + + m_print_panel->SetSizer(panel_sizer); + + m_print_panel->SetSizer(panel_sizer); + m_print_panel->Layout(); + panel_sizer->Fit(m_print_panel); +} + +void CalibrationWizard::create_send_progress_bar() +{ + m_send_progress_panel = new wxPanel(m_scrolledWindow); + auto panel_sizer = new wxBoxSizer(wxVERTICAL); + m_send_progress_bar = std::shared_ptr(new BBLStatusBarSend(m_send_progress_panel)); + panel_sizer->Add(m_send_progress_bar->get_panel(), 0, wxEXPAND, 0); + m_send_progress_panel->Hide(); + + m_send_progress_panel->SetSizer(panel_sizer); + m_send_progress_panel->Layout(); + panel_sizer->Fit(m_send_progress_panel); } void CalibrationWizard::add_presets_panel_to_page(CalibrationWizardPage* page, wxBoxSizer* sizer) @@ -144,100 +516,23 @@ void CalibrationWizard::add_presets_panel_to_page(CalibrationWizardPage* page, w sizer->Add(m_presets_panel, 0, wxEXPAND, 0); } -void CalibrationWizard::create_progress_bar() +void CalibrationWizard::add_print_panel_to_page(CalibrationWizardPage* page, wxBoxSizer* sizer) { - m_progress_bar = new BBLStatusBarSend(m_background_panel); - m_progress_bar->get_panel()->Hide(); - m_progress_bar->hide_cancel_button(); + m_btn_recali = page->get_prev_btn(); + m_btn_next = page->get_next_btn(); + m_print_panel->Reparent(page); + sizer->Add(m_print_panel, 0, wxALIGN_CENTER, 0); } -void CalibrationWizard::add_progress_bar_to_page(CalibrationWizardPage* page, wxBoxSizer* sizer) +void CalibrationWizard::add_send_progress_to_page(CalibrationWizardPage* page, wxBoxSizer* sizer) { - m_progress_bar->get_panel()->Reparent(page); - sizer->Add(m_progress_bar->get_panel(), 0, wxEXPAND, 0); + m_send_progress_panel->Reparent(page); + sizer->Add(m_send_progress_panel, 0, wxEXPAND, 0); } -void CalibrationWizard::on_click_btn_prev(IntEvent& event) +void CalibrationWizard::show_send_progress_bar(bool show) { - ButtonType button_type = static_cast(event.get_data()); - switch (button_type) - { - case Slic3r::GUI::Back: - show_page(get_curr_page()->get_prev_page()); - break; - case Slic3r::GUI::Recalibrate: - show_page(get_frist_page()); - break; - } -} - -void CalibrationWizard::on_click_btn_next(IntEvent& event) -{ - ButtonType button_type = static_cast(event.get_data()); - switch (button_type) - { - case Slic3r::GUI::Start: - case Slic3r::GUI::Next: - show_page(get_curr_page()->get_next_page()); - break; - case Slic3r::GUI::Calibrate: { -#if 0 /*test*/ - show_page(get_curr_page()->get_next_page()); - return; -#endif - - if(!obj){ - MessageDialog msg_dlg(nullptr, _L("No Printer Connected!"), wxEmptyString, wxICON_WARNING | wxOK); - msg_dlg.ShowModal(); - return; - } - - if (m_comboBox_printer->GetValue().IsEmpty() || - m_comboBox_filament->GetValue().IsEmpty() || - m_comboBox_bed_type->GetValue().IsEmpty() || - m_comboBox_process->GetValue().IsEmpty()) { - MessageDialog msg_dlg(nullptr, _L("Please select presets"), wxEmptyString, wxICON_WARNING | wxOK); - msg_dlg.ShowModal(); - return; - } - - std::string ams_id = m_ams_control->GetCurentAms(); - std::string tray_id = m_ams_control->GetCurrentCan(ams_id); - if (ams_id.compare(std::to_string(VIRTUAL_TRAY_ID)) != 0) { - if (tray_id.empty()) { - wxString txt = _L("Please select an AMS slot before calibration"); - MessageDialog msg_dlg(nullptr, txt, wxEmptyString, wxICON_WARNING | wxOK); - msg_dlg.ShowModal(); - return; - } - else { - tray_id = std::to_string(atoi(tray_id.c_str()) + 4 * atoi(ams_id.c_str())); - } - } - else - tray_id = ams_id; - - std::string result = "[" + tray_id + "]"; - - if (start_calibration(result)) { - show_progress_bar(true); - m_progress_bar->set_cancel_callback([this]() {show_progress_bar(false); }); - //show_page(get_curr_page()->get_next_page()); - } - break; - } - case Slic3r::GUI::Save: - save_calibration_result(); - break; - default: - break; - } -} - -void CalibrationWizard::show_progress_bar(bool show) -{ - m_progress_bar->get_panel()->Show(show); - show ? m_progress_bar->show_cancel_button() : m_progress_bar->hide_cancel_button(); + m_send_progress_panel->Show(show); if (get_curr_page()->get_next_btn()->GetButtonType() == Calibrate) get_curr_page()->get_next_btn()->Show(!show); @@ -245,6 +540,28 @@ void CalibrationWizard::show_progress_bar(bool show) Layout(); } +void CalibrationWizard::on_choose_ams(wxCommandEvent& event) { + m_filament_list_panel->Show(); + m_virtual_panel->Hide(); + Layout(); + + m_virtual_tray_comboBox->SetValue(false); + + event.Skip(); +} + +void CalibrationWizard::on_choose_ext_spool(wxCommandEvent& event) { + m_virtual_panel->Show(); + m_filament_list_panel->Hide(); + Layout(); + + for (int i = 0; i < m_filament_comboBox_list.size(); i++) { + m_filament_comboBox_list[i]->SetValue(false); + } + + event.Skip(); +} + void CalibrationWizard::show_page(CalibrationWizardPage* page) { if (!page) return; @@ -261,484 +578,1042 @@ void CalibrationWizard::show_page(CalibrationWizardPage* page) { Layout(); } -void CalibrationWizard::update_ams(MachineObject* obj) +void CalibrationWizard::on_click_btn_prev(IntEvent& event) { - // update obj in sub dlg - bool is_none_ams_mode = false; - - if (!obj - || !obj->is_connected() - || obj->amsList.empty() - || obj->ams_exist_bits == 0) { - if (!obj || !obj->is_connected()) { - BOOST_LOG_TRIVIAL(trace) << "machine object" << obj->dev_name << " was disconnected, set show_ams_group is false"; + ButtonType button_type = static_cast(event.get_data()); + switch (button_type) + { + case Slic3r::GUI::Back: + show_page(get_curr_page()->get_prev_page()); + break; + case Slic3r::GUI::Recalibrate: + if (!curr_obj || + curr_obj->is_system_printing() || + curr_obj->is_in_calibration() ||// vs obj->is_in_extrusion_cali() ? + curr_obj->is_in_printing()) { + MessageDialog msg_dlg(nullptr, _L("Is in printing. Please wait for printing to complete"), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return; } - bool is_support_extrusion_cali = obj->is_function_supported(PrinterFunction::FUNC_EXTRUSION_CALI); - bool is_support_virtual_tray = obj->is_function_supported(PrinterFunction::FUNC_VIRTUAL_TYAY); - - if (is_support_virtual_tray) { - m_ams_control->update_vams_kn_value(obj->vt_tray, obj); - } - //show_ams_group(false, obj->is_function_supported(PrinterFunction::FUNC_VIRTUAL_TYAY), obj->is_function_supported(PrinterFunction::FUNC_EXTRUSION_CALI), obj->is_support_filament_edit_virtual_tray); - is_none_ams_mode = true; - //return; + show_page(get_frist_page()); + break; } - - bool is_support_extrusion_cali = obj->is_function_supported(PrinterFunction::FUNC_EXTRUSION_CALI); - bool is_support_virtual_tray = obj->is_function_supported(PrinterFunction::FUNC_VIRTUAL_TYAY); - bool is_support_filament_backup = obj->is_function_supported(PrinterFunction::FUNC_FILAMENT_BACKUP); - - m_ams_control->show_filament_backup(is_support_filament_backup); - - if (is_support_virtual_tray) { - m_ams_control->update_vams_kn_value(obj->vt_tray, obj); - } - - if (!is_none_ams_mode) { - m_ams_control->Show(true); - m_ams_control->show_noams_mode(true, obj->is_function_supported(PrinterFunction::FUNC_VIRTUAL_TYAY), obj->is_function_supported(PrinterFunction::FUNC_EXTRUSION_CALI), obj->is_support_filament_edit_virtual_tray, true); - } - - std::vector ams_info; - for (auto ams = obj->amsList.begin(); ams != obj->amsList.end(); ams++) { - AMSinfo info; - info.ams_id = ams->first; - if (ams->second->is_exists && info.parse_ams_info(ams->second, obj->ams_calibrate_remain_flag, obj->is_support_ams_humidity)) ams_info.push_back(info); - } - - // must select a current can - m_ams_control->UpdateAms(ams_info, false, is_support_extrusion_cali); - - - std::string curr_ams_id = m_ams_control->GetCurentAms(); - std::string curr_can_id = m_ams_control->GetCurrentCan(curr_ams_id); - bool is_vt_tray = false; - if (obj->m_tray_tar == std::to_string(VIRTUAL_TRAY_ID)) - is_vt_tray = true; - - // set segment 1, 2 - if (obj->m_tray_now == std::to_string(VIRTUAL_TRAY_ID)) { - m_ams_control->SetAmsStep(obj->m_ams_id, obj->m_tray_id, AMSPassRoadType::AMS_ROAD_TYPE_UNLOAD, AMSPassRoadSTEP::AMS_ROAD_STEP_NONE); - } - else { - if (obj->m_tray_now != "255" && obj->is_filament_at_extruder() && !obj->m_tray_id.empty()) { - m_ams_control->SetAmsStep(obj->m_ams_id, obj->m_tray_id, AMSPassRoadType::AMS_ROAD_TYPE_LOAD, AMSPassRoadSTEP::AMS_ROAD_STEP_COMBO_LOAD_STEP2); - } - else if (obj->m_tray_now != "255") { - m_ams_control->SetAmsStep(obj->m_ams_id, obj->m_tray_id, AMSPassRoadType::AMS_ROAD_TYPE_LOAD, AMSPassRoadSTEP::AMS_ROAD_STEP_COMBO_LOAD_STEP1); - } - else { - m_ams_control->SetAmsStep(obj->m_ams_id, obj->m_tray_id, AMSPassRoadType::AMS_ROAD_TYPE_UNLOAD, AMSPassRoadSTEP::AMS_ROAD_STEP_NONE); - } - } - - // set segment 3 - if (obj->m_tray_now == std::to_string(VIRTUAL_TRAY_ID)) { - m_ams_control->SetExtruder(obj->is_filament_at_extruder(), true, obj->vt_tray.get_color()); - } - else { - m_ams_control->SetExtruder(obj->is_filament_at_extruder(), false, m_ams_control->GetCanColour(obj->m_ams_id, obj->m_tray_id)); - - } - - if (obj->ams_status_main == AMS_STATUS_MAIN_FILAMENT_CHANGE) { - if (obj->m_tray_tar == std::to_string(VIRTUAL_TRAY_ID) && (obj->m_tray_now != std::to_string(VIRTUAL_TRAY_ID) || obj->m_tray_now != "255")) { - // wait to heat hotend - if (obj->ams_status_sub == 0x02) { - m_ams_control->SetFilamentStep(FilamentStep::STEP_HEAT_NOZZLE, FilamentStepType::STEP_TYPE_VT_LOAD); - } - else if (obj->ams_status_sub == 0x05) { - m_ams_control->SetFilamentStep(FilamentStep::STEP_FEED_FILAMENT, FilamentStepType::STEP_TYPE_VT_LOAD); - } - else if (obj->ams_status_sub == 0x06) { - m_ams_control->SetFilamentStep(FilamentStep::STEP_CONFIRM_EXTRUDED, FilamentStepType::STEP_TYPE_VT_LOAD); - } - else if (obj->ams_status_sub == 0x07) { - m_ams_control->SetFilamentStep(FilamentStep::STEP_PURGE_OLD_FILAMENT, FilamentStepType::STEP_TYPE_VT_LOAD); - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_IDLE, FilamentStepType::STEP_TYPE_VT_LOAD); - } - } - else { - // wait to heat hotend - if (obj->ams_status_sub == 0x02) { - if (curr_ams_id == obj->m_ams_id) { - if (!obj->is_ams_unload()) { - m_ams_control->SetFilamentStep(FilamentStep::STEP_HEAT_NOZZLE, FilamentStepType::STEP_TYPE_LOAD); - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_HEAT_NOZZLE, FilamentStepType::STEP_TYPE_UNLOAD); - } - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_IDLE, FilamentStepType::STEP_TYPE_UNLOAD); - } - } - else if (obj->ams_status_sub == 0x03) { - if (!obj->is_ams_unload()) { - m_ams_control->SetFilamentStep(FilamentStep::STEP_CUT_FILAMENT, FilamentStepType::STEP_TYPE_LOAD); - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_CUT_FILAMENT, FilamentStepType::STEP_TYPE_UNLOAD); - } - } - else if (obj->ams_status_sub == 0x04) { - if (!obj->is_ams_unload()) { - m_ams_control->SetFilamentStep(FilamentStep::STEP_PULL_CURR_FILAMENT, FilamentStepType::STEP_TYPE_LOAD); - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_PULL_CURR_FILAMENT, FilamentStepType::STEP_TYPE_UNLOAD); - } - } - else if (obj->ams_status_sub == 0x05) { - if (!obj->is_ams_unload()) { - if (/*m_is_load_with_temp*/false) { - m_ams_control->SetFilamentStep(FilamentStep::STEP_CUT_FILAMENT, FilamentStepType::STEP_TYPE_LOAD); - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_PUSH_NEW_FILAMENT, FilamentStepType::STEP_TYPE_LOAD); - } - - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_PUSH_NEW_FILAMENT, FilamentStepType::STEP_TYPE_UNLOAD); - } - } - else if (obj->ams_status_sub == 0x06) { - if (!obj->is_ams_unload()) { - m_ams_control->SetFilamentStep(FilamentStep::STEP_PUSH_NEW_FILAMENT, FilamentStepType::STEP_TYPE_LOAD); - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_PUSH_NEW_FILAMENT, FilamentStepType::STEP_TYPE_UNLOAD); - } - } - else if (obj->ams_status_sub == 0x07) { - if (!obj->is_ams_unload()) { - if (/*m_is_load_with_temp*/false) { - m_ams_control->SetFilamentStep(FilamentStep::STEP_PULL_CURR_FILAMENT, FilamentStepType::STEP_TYPE_LOAD); - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_PURGE_OLD_FILAMENT, FilamentStepType::STEP_TYPE_LOAD); - } - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_PURGE_OLD_FILAMENT, FilamentStepType::STEP_TYPE_UNLOAD); - } - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_IDLE, FilamentStepType::STEP_TYPE_UNLOAD); - } - } - } - else if (obj->ams_status_main == AMS_STATUS_MAIN_ASSIST) { - m_ams_control->SetFilamentStep(FilamentStep::STEP_IDLE, FilamentStepType::STEP_TYPE_LOAD); - } - else { - m_ams_control->SetFilamentStep(FilamentStep::STEP_IDLE, FilamentStepType::STEP_TYPE_LOAD); - } - - - for (auto ams_it = obj->amsList.begin(); ams_it != obj->amsList.end(); ams_it++) { - std::string ams_id = ams_it->first; - try { - int ams_id_int = atoi(ams_id.c_str()); - for (auto tray_it = ams_it->second->trayList.begin(); tray_it != ams_it->second->trayList.end(); tray_it++) { - std::string tray_id = tray_it->first; - int tray_id_int = atoi(tray_id.c_str()); - // new protocol - if ((obj->tray_reading_bits & (1 << (ams_id_int * 4 + tray_id_int))) != 0) { - m_ams_control->PlayRridLoading(ams_id, tray_id); - } - else { - m_ams_control->StopRridLoading(ams_id, tray_id); - } - } - } - catch (...) {} - } - - bool is_curr_tray_selected = false; - if (!curr_ams_id.empty() && !curr_can_id.empty() && (curr_ams_id != std::to_string(VIRTUAL_TRAY_ID))) { - if (curr_can_id == obj->m_tray_now) { - is_curr_tray_selected = true; - } - else { - std::map::iterator it = obj->amsList.find(curr_ams_id); - if (it == obj->amsList.end()) { - BOOST_LOG_TRIVIAL(trace) << "ams: find " << curr_ams_id << " failed"; - return; - } - auto tray_it = it->second->trayList.find(curr_can_id); - if (tray_it == it->second->trayList.end()) { - BOOST_LOG_TRIVIAL(trace) << "ams: find " << curr_can_id << " failed"; - return; - } - - if (!tray_it->second->is_exists) { - is_curr_tray_selected = true; - } - } - } - else if (curr_ams_id == std::to_string(VIRTUAL_TRAY_ID)) { - if (curr_ams_id == obj->m_tray_now) { - is_curr_tray_selected = true; - } - } - else { - is_curr_tray_selected = true; - } - - //update_ams_control_state(is_support_extrusion_cali, is_curr_tray_selected); } -void CalibrationWizard::update_progress() +void CalibrationWizard::on_click_btn_next(IntEvent& event) { - if (obj) { - if (/*obj->is_in_extrusion_cali()*/true) { - //show_info(true, false, wxString::Format(_L("Calibrating... %d%%"), obj->mc_print_percent)); - //m_cali_cancel->Show(); - //m_cali_cancel->Enable(); - //m_button_cali->Hide(); - //m_button_next_step->Hide(); + ButtonType button_type = static_cast(event.get_data()); + switch (button_type) + { + case Slic3r::GUI::Start: + case Slic3r::GUI::Next: + show_page(get_curr_page()->get_next_page()); + break; + case Slic3r::GUI::Calibrate: { + if(!curr_obj){ + MessageDialog msg_dlg(nullptr, _L("No Printer Connected!"), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return; } - else if (obj->is_extrusion_cali_finished()) { - if (/*m_bed_temp->GetTextCtrl()->GetValue().compare("0") == 0*/false) { - wxString tips = get_presets_incompatible(); - //show_info(true, true, tips); + + if (!m_printer_preset || !m_filament_preset || !m_print_preset) { + wxString tips; + if (!m_printer_preset || !m_print_preset) { + tips = _L("Please select a printer and nozzle for calibration."); } else { - get_presets_incompatible(); - //show_info(true, false, _L("Calibration completed")); + tips = _L("Please select filament for calibration."); } - //m_cali_cancel->Hide(); - //m_button_cali->Show(); - //m_button_next_step->Show(); + MessageDialog msg_dlg(nullptr, tips, wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return; } - else { - if (/*m_bed_temp->GetTextCtrl()->GetValue().compare("0") == 0*/false) { - wxString tips = get_presets_incompatible(); - //show_info(true, true, tips); - } - else { - get_presets_incompatible(); - //show_info(true, false, wxEmptyString); - } - //m_cali_cancel->Hide(); - //m_button_cali->Show(); - //m_button_next_step->Hide(); + + if (curr_obj->is_system_printing() || + curr_obj->is_in_calibration() || + curr_obj->is_in_printing()) { + MessageDialog msg_dlg(nullptr, _L("Is in printing. Please wait for printing to complete"), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return; } - Layout(); + + std::vector tray_ids = get_selected_tray(); + if (start_calibration(tray_ids)) { + m_send_progress_bar->set_cancel_callback_fina([this]() { + BOOST_LOG_TRIVIAL(info) << "CalibrationWizard::print_job: enter canceled"; + // todo cancel send print job related logic (PACalibration doesn't send a print job) + //if (Slic3r::GUI::print_job) { + // if (Slic3r::GUI::print_job->is_running()) { + // BOOST_LOG_TRIVIAL(info) << "calibration_print_job: canceled"; + // Slic3r::GUI::print_job->cancel(); + // } + // Slic3r::GUI::print_job->join(); + //} + show_send_progress_bar(false); + }); + } + break; + } + case Slic3r::GUI::Save: + if (!curr_obj || + curr_obj->is_system_printing() || + curr_obj->is_in_calibration() ||// vs obj->is_in_extrusion_cali() ? + curr_obj->is_in_printing()) { + MessageDialog msg_dlg(nullptr, _L("Is in printing. Please wait for printing to complete"), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return; + } + if(save_calibration_result()) + show_page(get_frist_page()); + + break; + default: + break; } } -void CalibrationWizard::on_select_printer(wxCommandEvent& evt) { - init_filaments_selections(); - init_process_selections(); - update_calibration_value(); +void CalibrationWizard::update_print_progress() +{ + if (!curr_obj) { + reset_printing_values(); + return; + } + + m_print_panel->Freeze(); + + static bool print_finish = false; + + if (curr_obj->is_support_layer_num) { + m_staticText_layers->Show(); + } + else { + m_staticText_layers->Hide(); + } + + //update_model_info(); //set model_task_id to subtask_id + + if (curr_obj->is_system_printing() + || curr_obj->is_in_calibration()) {// vs obj->is_in_extrusion_cali() ? + reset_printing_values(); + } + else if (curr_obj->is_in_printing() || curr_obj->print_status == "FINISH") { + if (curr_obj->is_in_prepare() || curr_obj->print_status == "SLICING") { + reset_printing_values(); + m_btn_recali->Hide(); + } + else { + if (curr_obj->can_resume()) { + m_button_pause_resume->SetBitmap_("print_control_resume"); + if (m_button_pause_resume->GetToolTipText() != _L("Resume")) { m_button_pause_resume->SetToolTip(_L("Resume")); } + } + else { + m_button_pause_resume->SetBitmap_("print_control_pause"); + if (m_button_pause_resume->GetToolTipText() != _L("Pause")) { m_button_pause_resume->SetToolTip(_L("Pause")); } + } + + if (curr_obj->print_status == "FINISH") {// obj->is_extrusion_cali_finished() also can get in + m_button_abort->Enable(false); + m_button_abort->SetBitmap_("print_control_stop_disable"); + m_button_pause_resume->Enable(false); + m_button_pause_resume->SetBitmap_("print_control_resume_disable"); + m_btn_next->Enable(true); + if (!print_finish && curr_obj->get_modeltask() && curr_obj->get_modeltask()->design_id > 0) { + print_finish = true; + //show_print_progress_bar(false); + //show_page(get_curr_page()->get_next_page()); + } + } + else { + m_button_abort->Enable(true); + m_button_abort->SetBitmap_("print_control_stop"); + m_button_pause_resume->Enable(true); + m_btn_next->Enable(false); + + if (print_finish) { + print_finish = false; + } + } + + // update left time + std::string left_time; + try { + left_time = get_bbl_monitor_time_dhm(curr_obj->mc_left_time); + } + catch (...) { + ; + } + wxString left_time_text = left_time.empty() ? NA_STR : wxString::Format("-%s", left_time); + m_staticText_progress_left_time->SetLabelText(left_time_text); + + if (curr_obj->subtask_) { + m_print_gauge_progress->SetValue(curr_obj->subtask_->task_progress); + m_staticText_progress_percent->SetLabelText(wxString::Format("%d%%", curr_obj->subtask_->task_progress)); + m_staticText_layers->SetLabelText(wxString::Format(_L("Layer: %d/%d"), curr_obj->curr_layer, curr_obj->total_layers)); + + } + else { + m_print_gauge_progress->SetValue(0); + m_staticText_progress_percent->SetLabelText(NA_STR); + m_staticText_layers->SetLabelText(wxString::Format(_L("Layer: %s"), NA_STR)); + } + } + } + else { + reset_printing_values(); + } + m_print_panel->Layout(); + + m_print_panel->Thaw(); } -void CalibrationWizard::on_select_filament(wxCommandEvent& evt) { - update_calibration_value(); + +void CalibrationWizard::reset_printing_values() +{ + m_button_pause_resume->Enable(false); + m_button_pause_resume->SetBitmap_("print_control_pause_disable"); + + m_button_abort->Enable(false); + m_button_abort->SetBitmap_("print_control_stop_disable"); + + m_btn_next->Enable(false); + m_btn_recali->Show(); + + m_print_gauge_progress->SetValue(0); + m_staticText_progress_left_time->SetLabelText(NA_STR); + m_staticText_layers->SetLabelText(wxString::Format(_L("Layer: %s"), NA_STR)); + m_staticText_progress_percent->SetLabelText(NA_STR); + m_print_panel->Layout(); } -void CalibrationWizard::on_select_bed_type(wxCommandEvent& evt) { - update_calibration_value(); + +void CalibrationWizard::on_subtask_pause_resume(wxCommandEvent& event) +{ + if (curr_obj) { + if (curr_obj->can_resume()) + curr_obj->command_task_resume(); + else + curr_obj->command_task_pause(); + } } -void CalibrationWizard::on_select_process(wxCommandEvent& evt) { - update_calibration_value(); + +void CalibrationWizard::on_subtask_abort(wxCommandEvent& event) +{ + MessageDialog msg_dlg(nullptr, _L("Are you sure you want to cancel this print?"), wxEmptyString, wxICON_WARNING | wxOK | wxCANCEL); + if (msg_dlg.ShowModal() == wxID_OK) { + if (curr_obj) curr_obj->command_task_abort(); + m_btn_recali->Show(); + } + //if (abort_dlg == nullptr) { + // abort_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Cancel print")); + // abort_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent& e) { + // if (obj) obj->command_task_abort(); + // }); + //} + //abort_dlg->update_text(_L("Are you sure you want to cancel this print?")); + //abort_dlg->on_show(); +} + +std::vector CalibrationWizard::get_selected_tray() +{ + std::vector tray_ids; + + if (m_filament_from_ext_spool) { + if(m_virtual_tray_comboBox->GetRadioBox()->GetValue()) + tray_ids.push_back(m_virtual_tray_comboBox->get_tray_id()); + } + else { + if (get_ams_select_mode() == FilamentSelectMode::FSMCheckBoxMode) { + for (auto fcb : m_filament_comboBox_list) { + if (fcb->GetCheckBox()->GetValue()) { + tray_ids.push_back(fcb->get_tray_id()); + } + } + } + else if (get_ams_select_mode() == FilamentSelectMode::FSMRadioMode) { + for (auto fcb : m_filament_comboBox_list) { + if (fcb->GetRadioBox()->GetValue()) { + tray_ids.push_back(fcb->get_tray_id()); + } + } + } + } + return tray_ids; +} + +FilamentComboBoxList CalibrationWizard::get_selected_filament_comboBox() +{ + FilamentComboBoxList fcb_list; + + if (m_filament_from_ext_spool) { + if (m_virtual_tray_comboBox->GetRadioBox()->GetValue()) + fcb_list.push_back(m_virtual_tray_comboBox); + } + else { + if (get_ams_select_mode() == FilamentSelectMode::FSMCheckBoxMode) { + for (auto fcb : m_filament_comboBox_list) { + if (fcb->GetCheckBox()->GetValue()) { + fcb_list.push_back(fcb); + } + } + } + else if (get_ams_select_mode() == FilamentSelectMode::FSMRadioMode) { + for (auto fcb : m_filament_comboBox_list) { + if (fcb->GetRadioBox()->GetValue()) { + fcb_list.push_back(fcb); + } + } + } + } + return fcb_list; +} + +void CalibrationWizard::update_filaments_from_preset() +{ + for (auto& fcb : m_filament_comboBox_list) + fcb->update_from_preset(); + m_virtual_tray_comboBox->update_from_preset(); + + Layout(); } void CalibrationWizard::init_presets_selections() { - init_printer_selections(); - init_filaments_selections(); + init_nozzle_selections(); init_bed_type_selections(); init_process_selections(); } -void CalibrationWizard::init_printer_selections() +void CalibrationWizard::update_printer_selections() { - m_comboBox_printer->SetValue(wxEmptyString); - int curr_selection = 1; - wxArrayString printer_items; - PresetBundle* preset_bundle = wxGetApp().preset_bundle; - if (preset_bundle) { - for (auto printer_it = preset_bundle->printers.begin(); printer_it != preset_bundle->printers.end(); printer_it++) { - wxString printer_name = wxString::FromUTF8(printer_it->name); - printer_items.Add(printer_name); + Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) return; + + // clear machine list + obj_list.clear(); + m_comboBox_printer->Clear(); + wxArrayString machine_list_name; + std::map option_list; + + // user machine list + option_list = dev->get_my_machine_list(); + for (auto it = option_list.begin(); it != option_list.end(); it++) { + if (it->second && (it->second->is_online() || it->second->is_connected())) { + obj_list.push_back(it->second); + wxString dev_name_text = from_u8(it->second->dev_name); + if (it->second->is_lan_mode_printer()) { + dev_name_text += "(LAN)"; + } + machine_list_name.Add(dev_name_text); } - m_comboBox_printer->Set(printer_items); - m_comboBox_printer->SetSelection(curr_selection); + } + m_comboBox_printer->Set(machine_list_name); + + // comboBox_printer : set a default value + MachineObject* obj = dev->get_selected_machine(); + if (obj) { + for (auto i = 0; i < obj_list.size(); i++) { + if (obj_list[i]->dev_id == obj->dev_id) { + m_comboBox_printer->SetSelection(i); + wxCommandEvent event(wxEVT_COMBOBOX); + event.SetEventObject(m_comboBox_printer); + wxPostEvent(m_comboBox_printer, event); + } + } + } + else { + int def_selection = obj_list.size() - 1; + m_comboBox_printer->SetSelection(def_selection); + wxCommandEvent event(wxEVT_COMBOBOX); + event.SetEventObject(m_comboBox_printer); + wxPostEvent(m_comboBox_printer, event); } } -void CalibrationWizard::init_filaments_selections() +void CalibrationWizard::init_nozzle_selections() { - m_comboBox_filament->SetValue(wxEmptyString); - int filament_index = -1; - int curr_selection = -1; - wxArrayString filament_items; - PresetBundle* preset_bundle = wxGetApp().preset_bundle; - if (preset_bundle) { - for (auto filament_it = preset_bundle->filaments.begin(); filament_it != preset_bundle->filaments.end(); filament_it++) { - ConfigOption* printer_opt = filament_it->config.option("compatible_printers"); - ConfigOptionStrings* printer_strs = dynamic_cast(printer_opt); - for (auto printer_str : printer_strs->values) { - if (printer_str == m_comboBox_printer->GetValue()) {// todo modify - // set default filament id - filament_index++; - if (filament_it->is_system - /*&& !ams_filament_id.empty()*/ - /*&& filament_it->filament_id == ams_filament_id*/) - ;//curr_selection = filament_index; - - wxString filament_name = wxString::FromUTF8(filament_it->name); - filament_items.Add(filament_name); - break; - } - } - } - m_comboBox_filament->Set(filament_items); - m_comboBox_filament->SetSelection(curr_selection); + m_comboBox_nozzle_dia->Clear(); + m_printer_preset = nullptr; + if (curr_obj) { + m_comboBox_nozzle_dia->AppendString(wxString::Format("%1.1f", 0.2)); + m_comboBox_nozzle_dia->AppendString(wxString::Format("%1.1f", 0.4)); + m_comboBox_nozzle_dia->AppendString(wxString::Format("%1.1f", 0.6)); + m_comboBox_nozzle_dia->AppendString(wxString::Format("%1.1f", 0.8)); + m_comboBox_nozzle_dia->SetSelection(-1); } } void CalibrationWizard::init_bed_type_selections() { - m_comboBox_bed_type->SetValue(wxEmptyString); + m_comboBox_bed_type->Clear(); int curr_selection = 0; - const ConfigOptionDef* bed_type_def = print_config_def.get("curr_bed_type"); - if (bed_type_def && bed_type_def->enum_keys_map) { - for (auto item : *bed_type_def->enum_keys_map) { - if (item.first == "Default Plate") - continue; - m_comboBox_bed_type->AppendString(_L(item.first)); + if (curr_obj) { + const ConfigOptionDef* bed_type_def = print_config_def.get("curr_bed_type"); + if (bed_type_def && bed_type_def->enum_keys_map) { + for (auto item : *bed_type_def->enum_keys_map) { + if (item.first == "Default Plate") + continue; + m_comboBox_bed_type->AppendString(_L(item.first)); + } + m_comboBox_bed_type->SetSelection(curr_selection); } - m_comboBox_bed_type->SetSelection(curr_selection); } } void CalibrationWizard::init_process_selections() { - m_comboBox_process->SetValue(wxEmptyString); - int process_index = -1; - int curr_selection = -1; - wxArrayString process_items; + m_comboBox_process->Clear(); + m_print_preset = nullptr; + wxArrayString print_items; PresetBundle* preset_bundle = wxGetApp().preset_bundle; - if (preset_bundle) { - for (auto process_it = preset_bundle->prints.begin(); process_it != preset_bundle->prints.end(); process_it++) { - ConfigOption* printer_opt = process_it->config.option("compatible_printers"); + + double nozzle_value = 0.4; + wxString nozzle_value_str = m_comboBox_nozzle_dia->GetValue(); + try { + nozzle_value_str.ToDouble(&nozzle_value); + } + catch (...) { + ; + } + + if (preset_bundle && curr_obj) { + for (auto print_it = preset_bundle->prints.begin(); print_it != preset_bundle->prints.end(); print_it++) { + ConfigOption* printer_opt = print_it->config.option("compatible_printers"); ConfigOptionStrings* printer_strs = dynamic_cast(printer_opt); for (auto printer_str : printer_strs->values) { - if (printer_str == m_comboBox_printer->GetValue()) {// todo modify - // set default filament id - process_index++; - if (process_it->is_system) - ;//curr_selection = process_index; - - wxString process_name = wxString::FromUTF8(process_it->name); - process_items.Add(process_name); + if (m_printer_preset && m_printer_preset->name == printer_str) { + wxString process_name = wxString::FromUTF8(print_it->name); + print_items.Add(process_name); break; } } } - m_comboBox_process->Set(process_items); - m_comboBox_process->SetSelection(curr_selection); + m_comboBox_process->Set(print_items); + m_comboBox_process->SetSelection((print_items.size() + 1) / 2 - 1); + + for (auto print_it = preset_bundle->prints.begin(); print_it != preset_bundle->prints.end(); print_it++) { + wxString print_name = wxString::FromUTF8(print_it->name); + if (print_name.compare(m_comboBox_process->GetValue()) == 0) { + m_print_preset = &*print_it; + } + } } } +void CalibrationWizard::on_select_printer(wxCommandEvent& evt) { + DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) return; + + auto selection = m_comboBox_printer->GetSelection(); + MachineObject* new_obj = nullptr; + for (int i = 0; i < obj_list.size(); i++) { + if (i == selection) { + // check lan mode machine + //if (obj_list[i]->is_lan_mode_printer() && !obj_list[i]->has_access_right()) { + // ConnectPrinterDialog dlg(wxGetApp().mainframe, wxID_ANY, _L("Input access code")); + // dlg.set_machine_object(obj_list[i]); + // auto res = dlg.ShowModal(); + // m_printer_last_select = ""; + // m_comboBox_printer->SetSelection(-1); + // m_comboBox_printer->Refresh(); + // m_comboBox_printer->Update(); + //} + new_obj = obj_list[i]; + break; + } + } + + if (new_obj && !new_obj->get_lan_mode_connection_state()) { + new_obj->command_get_version(); + new_obj->command_request_push_all(); + dev->set_selected_machine(new_obj->dev_id, true); + + wxGetApp().sidebar().load_ams_list(new_obj->dev_id, new_obj); + + if (new_obj != curr_obj) { + curr_obj = new_obj; + init_presets_selections(); + wxGetApp().preset_bundle->set_calibrate_printer(""); + update_filaments_from_preset(); + on_update_ams_filament(false); + } + } + else { + BOOST_LOG_TRIVIAL(error) << "CalibrationWizard::on_select_printer dev_id not found"; + return; + } +} + +void CalibrationWizard::on_select_nozzle(wxCommandEvent& evt) { + if (curr_obj) { + double nozzle_value = 0.4; + wxString nozzle_value_str = m_comboBox_nozzle_dia->GetValue(); + try { + nozzle_value_str.ToDouble(&nozzle_value); + } + catch (...) { + ; + } + PresetBundle* preset_bundle = wxGetApp().preset_bundle; + for (auto printer_it = preset_bundle->printers.begin(); printer_it != preset_bundle->printers.end(); printer_it++) { + // only use system printer preset + if (!printer_it->is_system) continue; + + ConfigOption* printer_nozzle_opt = printer_it->config.option("nozzle_diameter"); + ConfigOptionFloats* printer_nozzle_vals = nullptr; + if (printer_nozzle_opt) + printer_nozzle_vals = dynamic_cast(printer_nozzle_opt); + std::string model_id = printer_it->get_current_printer_type(preset_bundle); + if (model_id.compare(curr_obj->printer_type) == 0 + && printer_nozzle_vals + && abs(printer_nozzle_vals->get_at(0) - nozzle_value) < 1e-3) { + m_printer_preset = &*printer_it; + } + } + + if (m_printer_preset) { + preset_bundle->set_calibrate_printer(m_printer_preset->name); + update_filaments_from_preset(); + on_update_ams_filament(false); + + init_process_selections(); + } + } +} + +void CalibrationWizard::on_select_bed_type(wxCommandEvent& evt) { + recommend_input_value(); +} + +void CalibrationWizard::on_switch_ams(std::string ams_id) +{ + for (auto i = 0; i < m_ams_item_list.size(); i++) { + AMSItem* item = m_ams_item_list[i]; + if (item->m_amsinfo.ams_id == ams_id) { + item->OnSelected(); + } + else { + item->UnSelected(); + } + } + + for (int i = 0; i < m_filament_comboBox_list.size(); i++) { + if (stoi(ams_id) * 4 <= i && i < stoi(ams_id) * 4 + 4) + m_filament_comboBox_list[i]->Show(true); + else { + m_filament_comboBox_list[i]->SetValue(false); + m_filament_comboBox_list[i]->Show(false); + } + } + + Layout(); +} + +void CalibrationWizard::on_select_tray(SimpleEvent& evt) { + // when comboBox set selection or value of checkbox/radio changed will enter, + // check if preset names are same + + FilamentComboBoxList fcb_list = get_selected_filament_comboBox(); + if (fcb_list.empty()) { + m_filament_preset = nullptr; + m_filaments_incompatible_tips->Hide(); + recommend_input_value(); + return; + } + + auto first_preset = fcb_list[0]->GetComboBox()->get_selected_preset(); + if(!first_preset) { + m_filament_preset = nullptr; + recommend_input_value(); + return; + } + bool all_preset_same = true; + for (auto fcb : fcb_list) { + auto selected_preset = fcb->GetComboBox()->get_selected_preset(); + if (selected_preset && selected_preset->filament_id != first_preset->filament_id) + all_preset_same = false; + } + + if (!all_preset_same) { + m_filament_preset = nullptr; + m_filaments_incompatible_tips->Show(); + Layout(); + } + else { + m_filament_preset = const_cast(first_preset); + m_filaments_incompatible_tips->Hide(); + Layout(); + } + + recommend_input_value(); +} + +void CalibrationWizard::on_update_ams_filament(bool dialog) +{ + auto& list = wxGetApp().preset_bundle->filament_ams_list; + if (list.empty() && dialog) { + MessageDialog dlg(this, _L("No AMS filaments. Please select a printer in 'Device' page to load AMS info."), _L("Sync filaments with AMS"), wxOK); + dlg.ShowModal(); + return; + } + + for (auto& entry : list) { + if (entry.first < m_filament_comboBox_list.size()) { + m_filament_comboBox_list[entry.first]->load_tray_from_ams(entry.first, entry.second); + } + if (entry.first == VIRTUAL_TRAY_ID) + m_virtual_tray_comboBox->load_tray_from_ams(entry.first, entry.second); + } + + std::vector ams_info; + for (auto ams = curr_obj->amsList.begin(); ams != curr_obj->amsList.end(); ams++) { + AMSinfo info; + info.ams_id = ams->first; + if (ams->second->is_exists && info.parse_ams_info(ams->second, curr_obj->ams_calibrate_remain_flag, curr_obj->is_support_ams_humidity)) ams_info.push_back(info); + } + for (auto i = 0; i < m_ams_item_list.size(); i++) { + AMSItem* item = m_ams_item_list[i]; + if(ams_info.size() > 1) + m_muilti_ams_panel->Show(); + else + m_muilti_ams_panel->Hide(); + + if (i < ams_info.size() && ams_info.size() > 1) { + item->Update(ams_info[i]); + item->Open(); + if (i == 0) + item->OnSelected(); + } + else { + item->Close(); + } + } + Layout(); +} + +bool CalibrationWizard::recommend_input_value() { + if (!m_filament_preset){ + m_nozzle_temp->GetTextCtrl()->SetValue(wxEmptyString); + m_bed_temp->GetTextCtrl()->SetValue(wxEmptyString); + m_max_volumetric_speed->GetTextCtrl()->SetValue(wxEmptyString); + m_bed_type_incompatible_tips->SetLabel(""); + m_bed_type_incompatible_tips->Hide(); + return false; + } + + PresetBundle* preset_bundle = wxGetApp().preset_bundle; + int bed_temp_int = -1; + if (preset_bundle) { + // update nozzle temperature + ConfigOption* opt_nozzle_temp = m_filament_preset->config.option("nozzle_temperature"); + if (opt_nozzle_temp) { + ConfigOptionInts* opt_min_ints = dynamic_cast(opt_nozzle_temp); + if (opt_min_ints) { + wxString text_nozzle_temp = wxString::Format("%d", opt_min_ints->get_at(0)); + m_nozzle_temp->GetTextCtrl()->SetValue(text_nozzle_temp); + } + } + // update bed temperature + bed_temp_int = get_bed_temp(&m_filament_preset->config); + wxString bed_temp_text = wxString::Format("%d", bed_temp_int); + m_bed_temp->GetTextCtrl()->SetValue(bed_temp_text); + // update max flow speed + ConfigOption* opt_flow_speed = m_filament_preset->config.option("filament_max_volumetric_speed"); + if (opt_flow_speed) { + ConfigOptionFloats* opt_flow_floats = dynamic_cast(opt_flow_speed); + if (opt_flow_floats) { + wxString flow_val_text = wxString::Format("%0.2f", opt_flow_floats->get_at(0)); + m_max_volumetric_speed->GetTextCtrl()->SetValue(flow_val_text); + } + } + + // check compatibility + if (m_bed_temp->GetTextCtrl()->GetValue().compare("0") == 0) { + m_nozzle_temp->GetTextCtrl()->SetValue(wxEmptyString); + m_bed_temp->GetTextCtrl()->SetValue(wxEmptyString); + m_max_volumetric_speed->GetTextCtrl()->SetValue(wxEmptyString); + wxString tips = wxString::Format(_L("%s does not support %s"), m_comboBox_bed_type->GetValue(), m_filament_preset->alias); + m_bed_type_incompatible_tips->SetLabel(tips); + m_bed_type_incompatible_tips->Show(); + Layout(); + return false; + } + else { + m_bed_type_incompatible_tips->SetLabel(""); + m_bed_type_incompatible_tips->Hide(); + } + } + return true; +} + +int CalibrationWizard::get_bed_temp(DynamicPrintConfig* config) +{ + BedType curr_bed_type = BedType(m_comboBox_bed_type->GetSelection() + btDefault + 1); + const ConfigOptionInts* opt_bed_temp_ints = config->option(get_bed_temp_key(curr_bed_type)); + if (opt_bed_temp_ints) { + return opt_bed_temp_ints->get_at(0); + } + return -1; +} + +bool CalibrationWizard::save_presets(const std::string& config_key, ConfigOption* config_value) +{ + auto filament_presets = &wxGetApp().preset_bundle->filaments; + DynamicPrintConfig* filament_config = &m_filament_preset->config; + + SavePresetDialog dlg(this, Preset::Type::TYPE_FILAMENT, "Calibrated"); + if (dlg.ShowModal() != wxID_OK) + return false; + std::string name = dlg.get_name(); + bool save_to_project = dlg.get_save_to_project_selection(Preset::TYPE_FILAMENT); + + filament_config->set_key_value(config_key, config_value); + // Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini + filament_presets->save_current_preset(name, false, save_to_project, m_filament_preset); + + Preset* new_preset = filament_presets->find_preset(name, false, true); + if (!new_preset) { + BOOST_LOG_TRIVIAL(info) << "create new preset failed"; + return false; + } + + new_preset->sync_info = "create"; + if (wxGetApp().is_user_login()) + new_preset->user_id = wxGetApp().getAgent()->get_user_id(); + BOOST_LOG_TRIVIAL(info) << "sync_preset: create preset = " << new_preset->name; + + new_preset->save_info(); + + // Mark the print & filament enabled if they are compatible with the currently selected preset. + // If saving the preset changes compatibility with other presets, keep the now incompatible dependent presets selected, however with a "red flag" icon showing that they are no more compatible. + wxGetApp().preset_bundle->update_compatible(PresetSelectCompatibleType::Never); + + // update current comboBox selected preset + std::string curr_preset_name = filament_presets->get_edited_preset().name; + wxGetApp().plater()->sidebar().update_presets_from_to(Preset::TYPE_FILAMENT, curr_preset_name, new_preset->name); + + return true; +} + +PressureAdvanceWizard::PressureAdvanceWizard(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) + : CalibrationWizard(parent, id, pos, size, style) +{ + for (int i = 0; i < 4/*m_filament_comboBox_list.size()*/; i++) { + m_filament_comboBox_list[i]->set_select_mode(FSMCheckBoxMode); + } + // todo hide some comboBox + + create_pages(); +} + +void PressureAdvanceWizard::create_pages() +{ + // page 0 : start page + //m_page0 = new CalibrationWizardPage(m_scrolledWindow, false); + //m_page0->set_page_title(_L("Pressure Advance")); + //m_page0->set_page_index(_L("1/3")); + + //auto page0_top_sizer = m_page0->get_top_vsizer(); + //auto page0_top_description = new wxStaticText(m_page0, wxID_ANY, _L("Pressure advance is a technique used to compensate for the delay between the extruder motor and the actual extrusion of the filament. It works by increasing the pressure of the filament in the nozzle just before a rapid movement occurs, improving the accuracy of the printed object. It can be adjusted through the printer's firmware or slicer software, and is useful for objects with sharp corners or intricate details."), wxDefaultPosition, wxDefaultSize, 0); + //page0_top_description->SetFont(::Label::Body_14); + //page0_top_description->Wrap(CALIBRATION_TEXT_MAX_LENGTH); + //page0_top_description->SetMinSize(wxSize(CALIBRATION_TEXT_MAX_LENGTH, -1)); + //page0_top_sizer->Add(page1_top_description, 0, wxALL, 0); + //page0_top_sizer->AddSpacer(FromDIP(20)); + + //auto page0_content_sizer = m_page0->get_content_vsizer(); + //auto bitmap_sizer = new wxBoxSizer(wxHORIZONTAL); + //auto page0_bitmap1 = new wxStaticBitmap(m_page0, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); + //page0_bitmap1->SetMinSize(wxSize(560, 450)); // todo modify + //page0_bitmap1->SetBackgroundColour(*wxBLACK); // todo modify + //bitmap_sizer->Add(page1_bitmap1, 0, wxALL, 0); + + //auto page0_bitmap2 = new wxStaticBitmap(m_page0, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); + //page0_bitmap2->SetMinSize(wxSize(560, 450)); // todo modify + //page0_bitmap2->SetBackgroundColour(*wxBLACK); // todo modify + //bitmap_sizer->Add(page1_bitmap2, 0, wxALL, 0); + //page0_content_sizer->Add(bitmap_sizer, 0); + + //auto page0_prev_btn = m_page0->get_prev_btn(); + //page0_prev_btn->Hide(); + + //auto page0_next_btn = m_page0->get_next_btn(); + //page0_next_btn->SetLabel(_L("Start")); + //page0_next_btn->SetButtonType(ButtonType::Start); + + //m_all_pages_sizer->Add(m_page0, 1, wxEXPAND | wxALL, FromDIP(25)); + + // page 1 : preset page + m_page1 = new CalibrationWizardPage(m_scrolledWindow, true); + m_page1->set_page_title(_L("Pressure Advance")); + m_page1->set_page_index(_L("1/3")); + + auto page1_content_sizer = m_page1->get_content_vsizer(); + + m_from_text->Hide(); + m_to_text->Hide(); + m_from_value->Hide(); + m_to_value->Hide(); + m_step_text->Hide(); + m_step->Hide(); + + add_presets_panel_to_page(m_page1, page1_content_sizer); + + auto page1_prev_btn = m_page1->get_prev_btn(); + page1_prev_btn->Hide(); + + auto page1_next_btn = m_page1->get_next_btn(); + page1_next_btn->SetLabel(_L("Calibrate")); + page1_next_btn->SetButtonType(ButtonType::Calibrate); + + m_all_pages_sizer->Add(m_page1, 1, wxEXPAND | wxALL, FromDIP(25)); + + // page 2 : print page + m_page2 = new CalibrationWizardPage(m_scrolledWindow, false); + m_page2->set_page_title(_L("Pressure Advance")); + m_page2->set_page_index(_L("2/3")); + auto page2_content_sizer = m_page2->get_content_vsizer(); + auto page2_bitmap = new wxStaticBitmap(m_page2, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); + page2_bitmap->SetMinSize(wxSize(800, 600)); // todo modify + page2_bitmap->SetBackgroundColour(*wxBLACK); // todo modify + page2_content_sizer->Add(page2_bitmap, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 0); + page2_content_sizer->AddSpacer(FromDIP(20)); + add_print_panel_to_page(m_page2, page2_content_sizer); + + auto page2_prev_btn = m_page2->get_prev_btn(); + page2_prev_btn->SetLabel(_L("Re-Calibrate")); + page2_prev_btn->SetButtonType(ButtonType::Recalibrate); + page2_prev_btn->Hide(); + + auto page2_next_btn = m_page2->get_next_btn(); + page2_next_btn->SetLabel(_L("Next")); + page2_next_btn->SetButtonType(ButtonType::Next); + + m_all_pages_sizer->Add(m_page2, 1, wxEXPAND | wxALL, FromDIP(25)); + + // page 3 : save page + m_page3 = new CalibrationWizardPage(m_scrolledWindow, false); + m_page3->set_page_title(_L("Pressure Advance")); + m_page3->set_page_index(_L("3/3")); + + auto page3_top_sizer = m_page3->get_top_vsizer(); + auto page3_top_description = new wxStaticText(m_page3, wxID_ANY, _L("The calibration lines has been printed.\nPlease take out the build plate from the printer and find the line with the most uniform extrusion. The number next to it is the factor K. Fill in its value and click the Save button to save it to the printer. "), wxDefaultPosition, wxDefaultSize, 0); + page3_top_description->SetFont(::Label::Body_14); + page3_top_description->Wrap(CALIBRATION_TEXT_MAX_LENGTH); + page3_top_description->SetMinSize(wxSize(CALIBRATION_TEXT_MAX_LENGTH, -1)); + page3_top_sizer->Add(page3_top_description, 0, wxALIGN_CENTER, 0); + page3_top_sizer->AddSpacer(FromDIP(20)); + + auto page3_content_sizer = m_page3->get_content_vsizer(); + auto page3_bitmap = new wxStaticBitmap(m_page3, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); + page3_bitmap->SetMinSize(wxSize(800, 600)); // todo modify + page3_bitmap->SetBackgroundColour(*wxBLACK); // todo modify + page3_content_sizer->Add(page3_bitmap, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 0); + page3_content_sizer->AddSpacer(FromDIP(20)); + + auto value_sizer = new wxBoxSizer(wxHORIZONTAL); + auto k_value_text = new wxStaticText(m_page3, wxID_ANY, _L("Factor K"), wxDefaultPosition, wxDefaultSize, 0); + k_value_text->Wrap(-1); + k_value_text->SetFont(::Label::Body_14); + auto n_value_text = new wxStaticText(m_page3, wxID_ANY, _L("Factor N"), wxDefaultPosition, wxDefaultSize, 0); + n_value_text->Wrap(-1); + n_value_text->SetFont(::Label::Body_14); + m_k_val = new TextInput(m_page3, wxEmptyString, "", "", wxDefaultPosition, CALIBRATION_OPTIMAL_INPUT_SIZE, 0); + m_n_val = new TextInput(m_page3, wxEmptyString, "", "", wxDefaultPosition, CALIBRATION_OPTIMAL_INPUT_SIZE, 0); + value_sizer->Add(k_value_text, 0, wxALIGN_CENTER_VERTICAL, 0); + value_sizer->AddSpacer(FromDIP(10)); + value_sizer->Add(m_k_val, 0); + value_sizer->AddSpacer(FromDIP(50)); + value_sizer->Add(n_value_text, 0, wxALIGN_CENTER_VERTICAL, 0); + value_sizer->AddSpacer(FromDIP(10)); + value_sizer->Add(m_n_val, 0); + page3_content_sizer->Add(value_sizer, 0, wxALIGN_CENTER); + page3_content_sizer->AddSpacer(FromDIP(20)); + + auto page3_prev_btn = m_page3->get_prev_btn(); + page3_prev_btn->Hide(); + + auto page3_next_btn = m_page3->get_next_btn(); + page3_next_btn->SetLabel(_L("Save")); + page3_next_btn->SetButtonType(ButtonType::Save); + + m_all_pages_sizer->Add(m_page3, 1, wxEXPAND | wxALL, FromDIP(25)); + + // link page + m_page1->chain(m_page2)->chain(m_page3); + + m_first_page = m_page1; + m_curr_page = m_page1; + show_page(m_curr_page); +} + +bool PressureAdvanceWizard::start_calibration(std::vector tray_ids) +{ + int nozzle_temp = -1; + int bed_temp = -1; + float max_volumetric_speed = -1; + + nozzle_temp = stoi(m_nozzle_temp->GetTextCtrl()->GetValue().ToStdString()); + bed_temp = stoi(m_bed_temp->GetTextCtrl()->GetValue().ToStdString()); + max_volumetric_speed = stof(m_max_volumetric_speed->GetTextCtrl()->GetValue().ToStdString()); + + if (bed_temp < 0 || nozzle_temp < 0 || max_volumetric_speed < 0) { + MessageDialog msg_dlg(nullptr, _L("Make sure bed_temp > 0 \nnozzle_temp > 0\nmax_volumetric_speed > 0"), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return false; + } + + if (curr_obj->printer_type == "BL-P001" || curr_obj->printer_type == "BL-P002") { + X1CCalibInfos calib_infos; + for (int tray_id : tray_ids) { + X1CCalibInfos::X1CCalibInfo calib_info; + calib_info.tray_id = tray_id; + calib_info.setting_id = m_filament_preset->setting_id; + calib_info.bed_temp = bed_temp; + calib_info.nozzle_temp = nozzle_temp; + calib_info.max_volumetric_speed = max_volumetric_speed; + calib_infos.calib_infos.push_back(calib_info); + } + std::string error_message; + CalibUtils::calib_PA(calib_infos, error_message); + show_page(get_curr_page()->get_next_page()); + + if (error_message.empty()) + return true; + else + return false; + } + else if (curr_obj->printer_type == "C11") { + curr_obj->command_start_extrusion_cali(tray_ids[0], nozzle_temp, bed_temp, max_volumetric_speed, m_filament_preset->setting_id); + show_page(get_curr_page()->get_next_page()); + return true; + } + + return false; +} + +bool PressureAdvanceWizard::save_calibration_result() +{ + auto check_k_validation = [](wxString k_text) + { + if (k_text.IsEmpty()) + return false; + double k = 0.0; + try { + k_text.ToDouble(&k); + } + catch (...) { + ; + } + + if (k < 0 || k > 0.5) + return false; + return true; + }; + + auto check_k_n_validation = [](wxString k_text, wxString n_text) + { + if (k_text.IsEmpty() || n_text.IsEmpty()) + return false; + double k = 0.0; + try { + k_text.ToDouble(&k); + } + catch (...) { + ; + } + + double n = 0.0; + try { + n_text.ToDouble(&n); + } + catch (...) { + ; + } + if (k < 0 || k > 0.5) + return false; + if (n < 0.6 || n > 2.0) + return false; + return true; + }; + + wxString k_text = m_k_val->GetTextCtrl()->GetValue(); + wxString n_text = m_n_val->GetTextCtrl()->GetValue(); + if (!check_k_n_validation(k_text, n_text)) { + //wxString k_tips = _L("Please input a valid value (K in 0~0.5)"); + wxString kn_tips = _L("Please input a valid value (K in 0~0.5, N in 0.6~2.0)"); + MessageDialog msg_dlg(nullptr, kn_tips, wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return false; + } + + double k = 0.0; + k_text.ToDouble(&k); + + double n = 0.0; + n_text.ToDouble(&n); + + // set values + int nozzle_temp = -1; + int bed_temp = -1; + float max_volumetric_speed = -1; + std::string setting_id; + std::string name; + + nozzle_temp = stoi(m_nozzle_temp->GetTextCtrl()->GetValue().ToStdString()); + bed_temp = stoi(m_bed_temp->GetTextCtrl()->GetValue().ToStdString()); + max_volumetric_speed = stof(m_max_volumetric_speed->GetTextCtrl()->GetValue().ToStdString()); + setting_id = m_filament_preset->setting_id; + name = m_filament_preset->name; + + // send command + std::string ams_id = 0;// m_ams_control->GetCurentAms(); + std::string tray_id = 0;// m_ams_control->GetCurrentCan(ams_id); + if (ams_id.compare(std::to_string(VIRTUAL_TRAY_ID)) != 0) { + if (tray_id.empty()) { + } + else { + tray_id = std::to_string(atoi(tray_id.c_str()) + 4 * atoi(ams_id.c_str())); + } + } + else + tray_id = ams_id; + + curr_obj->command_extrusion_cali_set(stoi(tray_id), setting_id, name, k, n, bed_temp, nozzle_temp, max_volumetric_speed); + MessageDialog msg_dlg(nullptr, _L("Saved success."), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return true; +} + +bool PressureAdvanceWizard::recommend_input_value() +{ + return CalibrationWizard::recommend_input_value(); +} + FlowRateWizard::FlowRateWizard(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : CalibrationWizard(parent, id, pos, size, style) { create_pages(); + + m_page3->get_next_btn()->Bind(wxEVT_BUTTON, &FlowRateWizard::on_fine_tune, this); } -void FlowRateWizard::create_pages() -{ - wxBoxSizer* all_pages_sizer; - all_pages_sizer = new wxBoxSizer(wxVERTICAL); - - // page 1 - m_page1 = new CalibrationWizardPage(m_background_panel, false); - m_page1->set_page_title(_L("Flow Rate")); - m_page1->set_page_index(_L("1/5")); - - auto page1_top_sizer = m_page1->get_top_vsizer(); - auto page1_top_description = new wxStaticText(m_page1, wxID_ANY, _L("Flow rate calibration in 3D printing is an important process that ensures the printer is extruding the correct amount of filament during the printing process. It is suitable for materials with significant thermal shrinkage/expansion and materials with inaccurate filament diameter."), wxDefaultPosition, wxDefaultSize, 0); - page1_top_description->Wrap(FromDIP(1000)); - page1_top_description->SetMinSize(wxSize(1000, -1)); - page1_top_description->SetFont(::Label::Body_14); - page1_top_sizer->Add(page1_top_description, 0, wxALL, 0); - page1_top_sizer->AddSpacer(FromDIP(20)); - - auto page1_right_content_sizer = m_page1->get_right_content_vsizer(); - auto page1_bitmaps_sizer = new wxBoxSizer(wxHORIZONTAL); - auto page1_bitmap1 = new wxStaticBitmap(m_page1, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); - auto page1_bitmap2 = new wxStaticBitmap(m_page1, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); - page1_bitmaps_sizer->Add(page1_bitmap1, 1, wxEXPAND, 0); - page1_bitmaps_sizer->Add(page1_bitmap2, 1, wxEXPAND, 0); - page1_right_content_sizer->Add(page1_bitmaps_sizer, 0, wxEXPAND, 0); - - auto page1_prev_btn = m_page1->get_prev_btn(); - page1_prev_btn->Hide(); - - auto page1_next_btn = m_page1->get_next_btn(); - page1_next_btn->SetLabel(_L("Start")); - page1_next_btn->SetButtonType(ButtonType::Start); - - all_pages_sizer->Add(m_page1, 1, wxEXPAND | wxALL, FromDIP(10)); - - // page 2 - m_page2 = new CalibrationWizardPage(m_background_panel, true); - m_page2->set_page_title(_L("Flow Rate")); - m_page2->set_page_index(_L("2/5")); - - auto page2_left_sizer = m_page2->get_left_vsizer(); - - m_from_text->Hide(); - m_to_text->Hide(); - m_step_text->Hide(); - m_from_value->Hide(); - m_to_value->Hide(); - m_step->Hide(); - - add_presets_panel_to_page(m_page2, page2_left_sizer); - - auto page2_right_content_sizer = m_page2->get_right_content_vsizer(); - - auto page2_description = new wxStaticText(m_page2, wxID_ANY, _L("Please select the printer, the slot that contains the target filament, and fill the settings before calibrating.\n\nA test model will be printed.This step may take about 50 minutes."), wxDefaultPosition, wxDefaultSize, 0); - page2_description->Wrap(FromDIP(500)); - page2_description->SetFont(::Label::Body_14); - page2_right_content_sizer->Add(page2_description, 0, wxEXPAND, 0); - - auto page2_bitmap = new wxStaticBitmap(m_page2, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); - page2_right_content_sizer->Add(page2_bitmap, 0, wxEXPAND, 0); - - add_progress_bar_to_page(m_page2, page2_right_content_sizer); - - auto page2_prev_btn = m_page2->get_prev_btn(); - page2_prev_btn->SetLabel(_L("Back")); - page2_prev_btn->SetButtonType(ButtonType::Back); - - auto page2_next_btn = m_page2->get_next_btn(); - page2_next_btn->SetLabel(_L("Coarse Tune")); - page2_next_btn->SetButtonType(ButtonType::Calibrate); - - all_pages_sizer->Add(m_page2, 1, wxEXPAND | wxALL, FromDIP(10)); - - // page 3 - m_page3 = new CalibrationWizardPage(m_background_panel, false); +void FlowRateWizard::create_low_end_pages() { + // page 3 : save coarse result + m_page3 = new CalibrationWizardPage(m_scrolledWindow, false); m_page3->set_page_title(_L("Flow Rate")); - m_page3->set_page_index(_L("3/5")); + m_page3->set_page_index(_L("3")); auto page3_top_sizer = m_page3->get_top_vsizer(); auto page3_top_description = new wxStaticText(m_page3, wxID_ANY, _L("The calibration blocks has been printed. Examine the blocks and determine which one has the smoothest top surface."), wxDefaultPosition, wxDefaultSize, 0); page3_top_description->Wrap(-1); page3_top_description->SetFont(::Label::Body_14); - page3_top_sizer->Add(page3_top_description, 0, wxALL, 0); + page3_top_sizer->Add(page3_top_description, 0, wxALIGN_CENTER, 0); page3_top_sizer->AddSpacer(FromDIP(20)); - auto page3_right_content_sizer = m_page3->get_right_content_vsizer(); + auto page3_content_sizer = m_page3->get_content_vsizer(); auto page3_bitmap = new wxStaticBitmap(m_page3, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); - page3_right_content_sizer->Add(page3_bitmap, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 0); + page3_bitmap->SetMinSize(wxSize(560, 450)); // todo modify + page3_bitmap->SetBackgroundColour(*wxBLACK); // todo modify + page3_content_sizer->Add(page3_bitmap, 0, wxALIGN_CENTER, 0); + + page3_content_sizer->AddSpacer(FromDIP(20)); auto coarse_value_sizer = new wxBoxSizer(wxVERTICAL); auto coarse_value_text = new wxStaticText(m_page3, wxID_ANY, _L("Fill in the value above the block with smoothest top surface"), wxDefaultPosition, wxDefaultSize, 0); @@ -751,70 +1626,52 @@ void FlowRateWizard::create_pages() coarse_block_items.Add(std::to_string(-20 + (i * 5))); } m_optimal_block_coarse->Set(coarse_block_items); - coarse_value_sizer->Add(coarse_value_text, 0, wxBOTTOM, FromDIP(20)); - coarse_value_sizer->Add(m_optimal_block_coarse, 0); - page3_right_content_sizer->Add(coarse_value_sizer, 0, wxEXPAND); + coarse_value_sizer->Add(coarse_value_text, 0, wxALIGN_CENTER); + coarse_value_sizer->Add(m_optimal_block_coarse, 0, wxALIGN_CENTER); + page3_content_sizer->Add(coarse_value_sizer, 0, wxALIGN_CENTER, 0); + page3_content_sizer->AddSpacer(FromDIP(20)); + + // todo add skip calibration 2 auto page3_prev_btn = m_page3->get_prev_btn(); - page3_prev_btn->SetLabel(_L("Back")); - page3_prev_btn->SetButtonType(ButtonType::Back); + page3_prev_btn->Hide(); auto page3_next_btn = m_page3->get_next_btn(); - page3_next_btn->SetLabel(_L("Next")); - page3_next_btn->SetButtonType(ButtonType::Next); + page3_next_btn->SetLabel(_L("Save & Calibrate")); + page3_next_btn->SetButtonType(ButtonType::Calibrate); - all_pages_sizer->Add(m_page3, 1, wxEXPAND | wxALL, FromDIP(10)); + m_all_pages_sizer->Add(m_page3, 1, wxEXPAND | wxALL, FromDIP(25)); - // page 4 - m_page4 = new CalibrationWizardPage(m_background_panel, true); + // page 4 : print page + m_page4 = new CalibrationWizardPage(m_scrolledWindow, true); m_page4->set_page_title(_L("Flow Rate")); - m_page4->set_page_index(_L("4/5")); + m_page4->set_page_index(_L("4")); + auto page4_content_sizer = m_page4->get_content_vsizer(); + auto page4_bitmap = new wxStaticBitmap(m_page4, wxID_ANY, create_scaled_bitmap("max_volumetric_speed_wizard", nullptr, 400), wxDefaultPosition, wxDefaultSize, 0); + page4_content_sizer->Add(page4_bitmap, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 0); + page4_content_sizer->AddSpacer(FromDIP(20)); + m_all_pages_sizer->Add(m_page4, 1, wxEXPAND | wxALL, FromDIP(25)); - create_readonly_presets_panel(); - - auto page4_right_content_sizer = m_page4->get_right_content_vsizer(); - - auto page4_description = new wxStaticText(m_page4, wxID_ANY, _L("Perform find tunning for to find the more fitting flow rate. A test model will be printed. This step may take about 30 minutes."), wxDefaultPosition, wxDefaultSize, 0); - page4_description->Wrap(FromDIP(500)); - page4_description->SetFont(::Label::Body_14); - page4_right_content_sizer->Add(page4_description, 0, wxEXPAND, 0); - - auto page4_bitmap = new wxStaticBitmap(m_page4, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); - page4_right_content_sizer->Add(page4_bitmap, 0, wxEXPAND, 0); - - auto clear_tips = new wxStaticText(m_page4, wxID_ANY, _L("Clear the build plate and place it back to the hot bed before calibration"), wxDefaultPosition, wxDefaultSize, 0); - clear_tips->Wrap(FromDIP(500)); - clear_tips->SetFont(::Label::Body_14); - clear_tips->SetForegroundColour(wxColour(255, 151, 0)); - page4_right_content_sizer->Add(clear_tips, 0, wxEXPAND, 0); - - add_progress_bar_to_page(m_page4, page4_right_content_sizer); - - auto page4_prev_btn = m_page4->get_prev_btn(); - page4_prev_btn->SetLabel(_L("Back")); - page4_prev_btn->SetButtonType(ButtonType::Back); - - auto page4_next_btn = m_page4->get_next_btn(); - page4_next_btn->SetLabel(_L("Fine Tune")); - page4_next_btn->SetButtonType(ButtonType::Calibrate); - - all_pages_sizer->Add(m_page4, 1, wxEXPAND | wxALL, FromDIP(10)); - - // page 5 - m_page5 = new CalibrationWizardPage(m_background_panel, false); + // page 5 : save fine result + m_page5 = new CalibrationWizardPage(m_scrolledWindow, false); m_page5->set_page_title(_L("Flow Rate")); - m_page5->set_page_index(_L("5/5")); + m_page5->set_page_index(_L("5")); auto page5_top_sizer = m_page5->get_top_vsizer(); auto page5_top_description = new wxStaticText(m_page5, wxID_ANY, _L("The calibration blocks has been printed. Examine the blocks and determine which one has the smoothest top surface. Fill in the number above that block and click the Save button to save the calibrated flow rate to the filament preset."), wxDefaultPosition, wxDefaultSize, 0); - page5_top_description->Wrap(-1); page5_top_description->SetFont(::Label::Body_14); - page5_top_sizer->Add(page5_top_description, 0, wxALL, 0); + page5_top_description->Wrap(CALIBRATION_TEXT_MAX_LENGTH); + page5_top_description->SetMinSize(wxSize(CALIBRATION_TEXT_MAX_LENGTH, -1)); + page5_top_sizer->Add(page5_top_description, 0, wxALIGN_CENTER, 0); page5_top_sizer->AddSpacer(FromDIP(20)); - auto page5_right_content_sizer = m_page5->get_right_content_vsizer(); + auto page5_content_sizer = m_page5->get_content_vsizer(); auto page5_bitmap = new wxStaticBitmap(m_page5, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); - page5_right_content_sizer->Add(page5_bitmap, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 0); + page5_bitmap->SetMinSize(wxSize(560, 450)); // todo modify + page5_bitmap->SetBackgroundColour(*wxBLACK); // todo modify + page5_content_sizer->Add(page5_bitmap, 0, wxALIGN_CENTER, 0); + + page5_content_sizer->AddSpacer(FromDIP(20)); auto fine_value_sizer = new wxBoxSizer(wxVERTICAL); auto fine_value_text = new wxStaticText(m_page5, wxID_ANY, _L("Fill in the value above the block with smoothest top surface"), wxDefaultPosition, wxDefaultSize, 0); @@ -827,24 +1684,19 @@ void FlowRateWizard::create_pages() fine_block_items.Add(std::to_string(-9 + (i))); } m_optimal_block_fine->Set(fine_block_items); - fine_value_sizer->Add(fine_value_text, 0, wxBOTTOM, FromDIP(20)); - fine_value_sizer->Add(m_optimal_block_fine, 0); - page5_right_content_sizer->Add(fine_value_sizer, 0, wxEXPAND); + fine_value_sizer->Add(fine_value_text, 0, wxALIGN_CENTER); + fine_value_sizer->Add(m_optimal_block_fine, 0, wxALIGN_CENTER); + page5_content_sizer->Add(fine_value_sizer, 0, wxALIGN_CENTER, 0); + page5_content_sizer->AddSpacer(FromDIP(20)); auto page5_prev_btn = m_page5->get_prev_btn(); - page5_prev_btn->SetLabel(_L("Back")); - page5_prev_btn->SetButtonType(ButtonType::Back); + page5_prev_btn->Hide(); auto page5_next_btn = m_page5->get_next_btn(); page5_next_btn->SetLabel(_L("Save")); page5_next_btn->SetButtonType(ButtonType::Save); - all_pages_sizer->Add(m_page5, 1, wxEXPAND | wxALL, FromDIP(10)); - - - m_background_panel->SetSizer(all_pages_sizer); - m_background_panel->Layout(); - all_pages_sizer->Fit(m_background_panel); + m_all_pages_sizer->Add(m_page5, 1, wxEXPAND | wxALL, FromDIP(25)); // link page m_page1->chain(m_page2)->chain(m_page3)->chain(m_page4)->chain(m_page5); @@ -854,83 +1706,279 @@ void FlowRateWizard::create_pages() show_page(m_curr_page); } -void FlowRateWizard::create_readonly_presets_panel() -{ - auto page4_left_sizer = m_page4->get_left_vsizer(); +void FlowRateWizard::create_high_end_pages() { + // page 5 : save fine result + m_high_end_page3 = new CalibrationWizardPage(m_scrolledWindow, false); + m_high_end_page3->set_page_title(_L("Flow Rate")); + m_high_end_page3->set_page_index(_L("3")); - auto readonly_presets_panel = new wxPanel(m_page4); - auto panel_sizer = new wxBoxSizer(wxVERTICAL); + auto high_end_page3_top_sizer = m_high_end_page3->get_top_vsizer(); + auto high_end_page3_top_description = new wxStaticText(m_high_end_page3, wxID_ANY, _L("The calibration blocks has been printed. Examine the blocks and determine which one has the smoothest top surface. Fill in the number above that block and click the Save button to save the calibrated flow rate to the filament preset."), wxDefaultPosition, wxDefaultSize, 0); + high_end_page3_top_description->SetFont(::Label::Body_14); + high_end_page3_top_description->Wrap(CALIBRATION_TEXT_MAX_LENGTH); + high_end_page3_top_description->SetMinSize(wxSize(CALIBRATION_TEXT_MAX_LENGTH, -1)); + high_end_page3_top_sizer->Add(high_end_page3_top_description, 0, wxALIGN_CENTER, 0); + high_end_page3_top_sizer->AddSpacer(FromDIP(20)); - m_readonly_ams_control = new AMSControl(readonly_presets_panel); - m_readonly_ams_control->EnterSimpleMode(); - panel_sizer->Add(m_readonly_ams_control, 0, wxALL, 0); + auto high_end_page3_content_sizer = m_high_end_page3->get_content_vsizer(); + auto high_end_page3_bitmap = new wxStaticBitmap(m_high_end_page3, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); + high_end_page3_bitmap->SetMinSize(wxSize(560, 450)); // todo modify + high_end_page3_bitmap->SetBackgroundColour(*wxBLACK); // todo modify + high_end_page3_content_sizer->Add(high_end_page3_bitmap, 0, wxALIGN_CENTER, 0); - auto printer_text = new wxStaticText(readonly_presets_panel, wxID_ANY, _L("Printer"), wxDefaultPosition, wxDefaultSize, 0); - printer_text->Wrap(-1); - panel_sizer->Add(printer_text, 0, wxALL, 0); + high_end_page3_content_sizer->AddSpacer(FromDIP(20)); - m_readonly_printer = new TextInput(readonly_presets_panel, wxEmptyString, "", "", wxDefaultPosition, CALIBRATION_COMBOX_SIZE, wxTE_READONLY); - panel_sizer->Add(m_readonly_printer, 0, wxALL, 0); + auto high_end_page3_prev_btn = m_high_end_page3->get_prev_btn(); + high_end_page3_prev_btn->Hide(); - panel_sizer->Add(0, FromDIP(10), 0, wxEXPAND, 0); + auto high_end_page3_next_btn = m_high_end_page3->get_next_btn(); + high_end_page3_next_btn->SetLabel(_L("Save")); + high_end_page3_next_btn->SetButtonType(ButtonType::Save); - auto filament_text = new wxStaticText(readonly_presets_panel, wxID_ANY, _L("Filament"), wxDefaultPosition, wxDefaultSize, 0); - filament_text->Wrap(-1); - panel_sizer->Add(filament_text, 0, wxALL, 0); + m_all_pages_sizer->Add(m_high_end_page3, 1, wxEXPAND | wxALL, FromDIP(25)); - m_readonly_filament = new TextInput(readonly_presets_panel, wxEmptyString, "", "", wxDefaultPosition, CALIBRATION_COMBOX_SIZE, wxTE_READONLY); - panel_sizer->Add(m_readonly_filament, 0, wxALL, 0); + // link page + m_page1->chain(m_page2)->chain(m_high_end_page3); - panel_sizer->Add(0, FromDIP(10), 0, wxEXPAND, 0); - - auto plate_type_text = new wxStaticText(readonly_presets_panel, wxID_ANY, _L("Plate Type"), wxDefaultPosition, wxDefaultSize, 0); - plate_type_text->Wrap(-1); - panel_sizer->Add(plate_type_text, 0, wxALL, 0); - - m_readonly_bed_type = new TextInput(readonly_presets_panel, wxEmptyString, "", "", wxDefaultPosition, CALIBRATION_COMBOX_SIZE, wxTE_READONLY); - panel_sizer->Add(m_readonly_bed_type, 0, wxALL, 0); - - panel_sizer->Add(0, FromDIP(10), 0, wxEXPAND, 0); - - auto process_text = new wxStaticText(readonly_presets_panel, wxID_ANY, _L("Process"), wxDefaultPosition, wxDefaultSize, 0); - process_text->Wrap(-1); - panel_sizer->Add(process_text, 0, wxALL, 0); - - m_readonly_process = new TextInput(readonly_presets_panel, wxEmptyString, "", "", wxDefaultPosition, CALIBRATION_COMBOX_SIZE, wxTE_READONLY); - panel_sizer->Add(m_readonly_process, 0, wxALL, 0); - - readonly_presets_panel->SetSizer(panel_sizer); - readonly_presets_panel->Layout(); - panel_sizer->Fit(readonly_presets_panel); - - page4_left_sizer->Add(readonly_presets_panel, 0, wxEXPAND, 0); - - m_readonly_printer->GetTextCtrl()->Bind(wxEVT_SET_FOCUS, [](auto&) {}); - m_readonly_filament->GetTextCtrl()->Bind(wxEVT_SET_FOCUS, [](auto&) {}); - m_readonly_bed_type->GetTextCtrl()->Bind(wxEVT_SET_FOCUS, [](auto&) {}); - m_readonly_process->GetTextCtrl()->Bind(wxEVT_SET_FOCUS, [](auto&) {}); + m_first_page = m_page1; + m_curr_page = m_page1; + show_page(m_curr_page); } -bool FlowRateWizard::start_calibration(std::string tray_id) +void FlowRateWizard::create_pages() { - int pass = -1; - if (m_curr_page == m_page2) - pass = 1; - else if (m_curr_page == m_page4) - pass = 2; - else + // page 0 : start page + //m_page0 = new CalibrationWizardPage(m_scrolledWindow, false); + //m_page0->set_page_title(_L("Flow Rate")); + //m_page0->set_page_index(_L("0/5")); + + //auto page0_top_sizer = m_page0->get_top_vsizer(); + //auto page0_top_description = new wxStaticText(m_page0, wxID_ANY, _L("Flow rate calibration in 3D printing is an important process that ensures the printer is extruding the correct amount of filament during the printing process. It is suitable for materials with significant thermal shrinkage/expansion and materials with inaccurate filament diameter."), wxDefaultPosition, wxDefaultSize, 0); + //page0_top_description->SetFont(::Label::Body_14); + //page0_top_description->Wrap(CALIBRATION_TEXT_MAX_LENGTH); + //page0_top_description->SetMinSize(wxSize(CALIBRATION_TEXT_MAX_LENGTH, -1)); + //page0_top_sizer->Add(page1_top_description, 0, wxALL, 0); + //page0_top_sizer->AddSpacer(FromDIP(20)); + + //auto page0_content_sizer = m_page0->get_content_vsizer(); + //auto bitmap_sizer1 = new wxBoxSizer(wxHORIZONTAL); + //auto page0_bitmap1 = new wxStaticBitmap(m_page0, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); + //page0_bitmap1->SetMinSize(wxSize(560, 450)); // todo modify + //page0_bitmap1->SetBackgroundColour(*wxBLACK); // todo modify + //bitmap_sizer1->Add(page0_bitmap1, 0, wxALL, 0); + + //auto page0_bitmap2 = new wxStaticBitmap(m_page0, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); + //page0_bitmap2->SetMinSize(wxSize(560, 450)); // todo modify + //page0_bitmap2->SetBackgroundColour(*wxBLACK); // todo modify + //bitmap_sizer1->Add(page0_bitmap2, 0, wxALL, 0); + //page0_content_sizer->Add(bitmap_sizer1, 0, wxALL, 0); + + //auto page0_prev_btn = m_page0->get_prev_btn(); + //page0_prev_btn->Hide(); + + //auto page0_next_btn = m_page0->get_next_btn(); + //page0_next_btn->SetLabel(_L("Start")); + //page0_next_btn->SetButtonType(ButtonType::Start); + + //m_all_pages_sizer->Add(m_page0, 1, wxEXPAND | wxALL, FromDIP(25)); + + // page 1 : preset page + m_page1 = new CalibrationWizardPage(m_scrolledWindow, true); + m_page1->set_page_title(_L("Flow Rate")); + m_page1->set_page_index(_L("1")); + + auto page1_content_sizer = m_page1->get_content_vsizer(); + + m_from_text->Hide(); + m_to_text->Hide(); + m_step_text->Hide(); + m_from_value->Hide(); + m_to_value->Hide(); + m_step->Hide(); + + add_presets_panel_to_page(m_page1, page1_content_sizer); + + add_send_progress_to_page(m_page1, m_page1->get_btn_hsizer()); + + auto page1_prev_btn = m_page1->get_prev_btn(); + page1_prev_btn->Hide(); + + auto page1_next_btn = m_page1->get_next_btn(); + page1_next_btn->SetLabel(_L("Coarse Tune")); + page1_next_btn->SetButtonType(ButtonType::Calibrate); + + m_all_pages_sizer->Add(m_page1, 1, wxEXPAND | wxALL, FromDIP(25)); + + // page 2 : print page + m_page2 = new CalibrationWizardPage(m_scrolledWindow, false); + m_page2->set_page_title(_L("Flow Rate")); + m_page2->set_page_index(_L("2")); + auto page2_content_sizer = m_page2->get_content_vsizer(); + auto page2_bitmap = new wxStaticBitmap(m_page2, wxID_ANY, create_scaled_bitmap("max_volumetric_speed_wizard", nullptr, 400), wxDefaultPosition, wxDefaultSize, 0); + page2_content_sizer->Add(page2_bitmap, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 0); + page2_content_sizer->AddSpacer(FromDIP(20)); + add_print_panel_to_page(m_page2, page2_content_sizer); + + auto page2_prev_btn = m_page2->get_prev_btn(); + page2_prev_btn->SetLabel(_L("Re-Calibrate")); + page2_prev_btn->SetButtonType(ButtonType::Recalibrate); + page2_prev_btn->Hide(); + + auto page2_next_btn = m_page2->get_next_btn(); + page2_next_btn->SetLabel(_L("Next")); + page2_next_btn->SetButtonType(ButtonType::Next); + + m_all_pages_sizer->Add(m_page2, 1, wxEXPAND | wxALL, FromDIP(25)); + + create_low_end_pages(); + + m_first_page = m_page1; + m_curr_page = m_page1; + show_page(m_curr_page); +} + +void FlowRateWizard::on_select_printer(wxCommandEvent& evt) { + CalibrationWizard::on_select_printer(evt); + if (curr_obj) { + if (curr_obj->printer_type == "BL-P001" || curr_obj->printer_type == "BL-P002") + { + if (m_page3) { + m_page3->Destroy(); + m_page3 = nullptr; + } + if (m_page4) { + m_page4->Destroy(); + m_page4 = nullptr; + } + if (m_page5) { + m_page5->Destroy(); + m_page5 = nullptr; + } + if (!m_high_end_page3) + create_high_end_pages(); + } + else if (curr_obj->printer_type == "C11") + { + if (m_high_end_page3) { + m_high_end_page3->Destroy(); + m_high_end_page3 = nullptr; + } + if (!m_page3) + create_low_end_pages(); + } + } +} + +bool FlowRateWizard::start_calibration(std::vector tray_ids) +{ + int nozzle_temp = -1; + int bed_temp = -1; + float max_volumetric_speed = -1; + + nozzle_temp = stoi(m_nozzle_temp->GetTextCtrl()->GetValue().ToStdString()); + bed_temp = stoi(m_bed_temp->GetTextCtrl()->GetValue().ToStdString()); + max_volumetric_speed = stof(m_max_volumetric_speed->GetTextCtrl()->GetValue().ToStdString()); + + if (bed_temp < 0 || nozzle_temp < 0 || max_volumetric_speed < 0) { + MessageDialog msg_dlg(nullptr, _L("Make sure bed_temp > 0 \nnozzle_temp > 0\nmax_volumetric_speed > 0"), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); return false; + } - CalibUtils::calib_flowrate(pass, obj->dev_id, tray_id, std::shared_ptr(m_progress_bar)); - return true; + if (curr_obj->printer_type == "BL-P001" || curr_obj->printer_type == "BL-P002") { + X1CCalibInfos calib_infos; + for (int tray_id : tray_ids) { + X1CCalibInfos::X1CCalibInfo calib_info; + calib_info.tray_id = tray_id; + calib_info.setting_id = m_filament_preset->setting_id; + calib_info.bed_temp = bed_temp; + calib_info.nozzle_temp = nozzle_temp; + calib_info.max_volumetric_speed = max_volumetric_speed; + calib_infos.calib_infos.push_back(calib_info); + } + std::string error_message; + CalibUtils::calib_flowrate_X1C(calib_infos, error_message); + show_page(get_curr_page()->get_next_page()); + if (error_message.empty()) + return true; + else + return false; + } + else { + int pass = -1; + if (get_curr_page() == m_page1) + pass = 1; + else if (get_curr_page() == m_page3) + pass = 2; + else + return false; + + CalibInfo calib_info; + calib_info.dev_id = curr_obj->dev_id; + calib_info.select_ams = "[" + std::to_string(tray_ids[0]) + "]"; + calib_info.process_bar = m_send_progress_bar; + calib_info.bed_type = BedType(m_comboBox_bed_type->GetSelection() + btDefault + 1); + calib_info.printer_prest = m_printer_preset; + calib_info.filament_prest = m_filament_preset; + calib_info.print_prest = m_print_preset; + + std::string error_message; + CalibUtils::calib_flowrate(pass, calib_info, error_message); + show_send_progress_bar(true); + return true; + } } -void FlowRateWizard::update_calibration_value() +bool FlowRateWizard::save_calibration_result() { - m_readonly_printer->GetTextCtrl()->SetLabel(m_comboBox_printer->GetValue()); - m_readonly_filament->GetTextCtrl()->SetLabel(m_comboBox_filament->GetValue()); - m_readonly_bed_type->GetTextCtrl()->SetLabel(m_comboBox_bed_type->GetValue()); - m_readonly_process->GetTextCtrl()->SetLabel(m_comboBox_process->GetValue()); + if (curr_obj->printer_type == "C11") { + if (m_optimal_block_coarse->GetValue().IsEmpty() || m_optimal_block_fine->GetValue().IsEmpty()) + { + MessageDialog msg_dlg(nullptr, _L("Choose a block with smoothest top surface."), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return false; + } + + DynamicPrintConfig& filament_config = m_filament_preset->config; + auto old_flow_ratio = filament_config.option("filament_flow_ratio")->get_at(0); + int fine_value = stoi(m_optimal_block_fine->GetValue().ToStdString()); + auto new_flow_ratio = old_flow_ratio * (100 + fine_value) / 100; + if (save_presets("filament_flow_ratio", new ConfigOptionFloats{ new_flow_ratio })) { + add_send_progress_to_page(m_page1, m_page1->get_btn_hsizer()); + add_print_panel_to_page(m_page2, m_page2->get_content_vsizer()); + return true; + } + else { + return false; + } + } + else + return false; // todo high end machine save logic +} + +bool FlowRateWizard::recommend_input_value() +{ + return CalibrationWizard::recommend_input_value(); +} + +void FlowRateWizard::on_fine_tune(wxCommandEvent& e) { + if (m_optimal_block_coarse->GetValue().IsEmpty()){ + MessageDialog msg_dlg(nullptr, _L("Choose a block with smoothest top surface."), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return; + } + + DynamicPrintConfig& filament_config = m_filament_preset->config; + int coarse_value = stoi(m_optimal_block_coarse->GetValue().ToStdString()); + auto old_flow_ratio = filament_config.option("filament_flow_ratio")->get_at(0); + auto new_flow_ratio = old_flow_ratio * (100 + coarse_value) / 100; + filament_config.set_key_value("filament_flow_ratio", new ConfigOptionFloats{ new_flow_ratio }); + + add_send_progress_to_page(m_page3, m_page3->get_btn_hsizer()); + + add_print_panel_to_page(m_page4, m_page4->get_content_vsizer()); + + e.Skip(); } MaxVolumetricSpeedWizard::MaxVolumetricSpeedWizard(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) @@ -941,61 +1989,63 @@ MaxVolumetricSpeedWizard::MaxVolumetricSpeedWizard(wxWindow* parent, wxWindowID void MaxVolumetricSpeedWizard::create_pages() { - wxBoxSizer* all_pages_sizer; - all_pages_sizer = new wxBoxSizer(wxVERTICAL); + //// page 0 : start page + //m_page0 = new CalibrationWizardPage(m_scrolledWindow, false); + //m_page0->set_page_title(_L("Max Volumetric Speed")); + //m_page0->set_page_index(_L("1/3")); - // page 1 - m_page1 = new CalibrationWizardPage(m_background_panel, false); + //auto page0_top_sizer = m_page0->get_top_vsizer(); + //auto page0_top_description = new wxStaticText(m_page0, wxID_ANY, _L("This setting stands for how much volume of filament can be melted and extruded per second."), wxDefaultPosition, wxDefaultSize, 0); + //page0_top_description->Wrap(CALIBRATION_TEXT_MAX_LENGTH); + //page0_top_description->SetFont(::Label::Body_14); + //page0_top_description->SetMinSize(wxSize(CALIBRATION_TEXT_MAX_LENGTH, -1)); + //page0_top_sizer->Add(page1_top_description, 0, wxALL, 0); + //page0_top_sizer->AddSpacer(FromDIP(20)); + + //auto page0_content_sizer = m_page0->get_content_vsizer(); + + //wxFlexGridSizer* fgSizer; + //fgSizer = new wxFlexGridSizer(0, 2, FromDIP(60), FromDIP(20)); + //fgSizer->SetFlexibleDirection(wxBOTH); + //fgSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); + + //auto page0_description1 = new wxStaticText(m_page0, wxID_ANY, _L("If the value is set too high, under-extrusion will happen and cause poor apperance on the printed model."), wxDefaultPosition, wxDefaultSize, 0); + //page0_description1->Wrap(FromDIP(500)); + //page0_description1->SetFont(::Label::Body_14); + //fgSizer->Add(page0_description1, 1, wxALL | wxEXPAND, 0); + + //auto page0_bitmap1 = new wxStaticBitmap(m_page0, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); + //page0_bitmap1->SetMinSize(wxSize(450, 300)); // todo modify + //page0_bitmap1->SetBackgroundColour(*wxBLACK); // todo modify + //fgSizer->Add(page0_bitmap1, 0, wxALL, 0); + + //auto page1_description2 = new wxStaticText(m_page0, wxID_ANY, _L("If the value is set too low, the print speed will be limited and make the print time longer. Take the model on the right picture for example.\nmax volumetric speed [n] mm^3/s costs [x] minutes.\nmax volumetric speed [m] mm^3/s costs [y] minutes"), wxDefaultPosition, wxDefaultSize, 0); + //page1_description2->Wrap(FromDIP(500)); + //page1_description2->SetFont(::Label::Body_14); + //fgSizer->Add(page1_description2, 1, wxALL | wxEXPAND, 0); + + //auto page0_bitmap2 = new wxStaticBitmap(m_page0, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); + //page0_bitmap2->SetMinSize(wxSize(450, 300)); // todo modify + //page0_bitmap2->SetBackgroundColour(*wxBLACK); // todo modify + //fgSizer->Add(page0_bitmap2, 0, wxALL, 0); + + //page0_content_sizer->Add(fgSizer, 1, wxEXPAND, 0); + + //auto page0_prev_btn = m_page0->get_prev_btn(); + //page0_prev_btn->Hide(); + + //auto page0_next_btn = m_page0->get_next_btn(); + //page0_next_btn->SetLabel(_L("Start")); + //page0_next_btn->SetButtonType(ButtonType::Start); + + //m_all_pages_sizer->Add(m_page0, 1, wxEXPAND | wxALL, FromDIP(25)); + + // page 1 : preset page + m_page1 = new CalibrationWizardPage(m_scrolledWindow, true); m_page1->set_page_title(_L("Max Volumetric Speed")); m_page1->set_page_index(_L("1/3")); - auto page1_top_sizer = m_page1->get_top_vsizer(); - auto page1_top_description = new wxStaticText(m_page1, wxID_ANY, _L("This setting stands for how much volume of filament can be melted and extruded per second."), wxDefaultPosition, wxDefaultSize, 0); - page1_top_description->Wrap(-1); - page1_top_description->SetFont(::Label::Body_14); - page1_top_sizer->Add(page1_top_description, 0, wxALL, 0); - page1_top_sizer->AddSpacer(FromDIP(20)); - - auto page1_right_content_sizer = m_page1->get_right_content_vsizer(); - - wxFlexGridSizer* fgSizer; - fgSizer = new wxFlexGridSizer(0, 2, FromDIP(60), FromDIP(20)); - fgSizer->SetFlexibleDirection(wxBOTH); - fgSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); - - auto page1_description1 = new wxStaticText(m_page1, wxID_ANY, _L("If the value is set too high, under-extrusion will happen and cause poor apperance on the printed model."), wxDefaultPosition, wxDefaultSize, 0); - page1_description1->Wrap(FromDIP(500)); - page1_description1->SetFont(::Label::Body_14); - fgSizer->Add(page1_description1, 1, wxALL | wxEXPAND, 0); - - auto page1_bitmap1 = new wxStaticBitmap(m_page1, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); - fgSizer->Add(page1_bitmap1, 1, wxALL | wxEXPAND, 0); - - auto page1_description2 = new wxStaticText(m_page1, wxID_ANY, _L("If the value is set too low, the print speed will be limited and make the print time longer. Take the model on the right picture for example.\nmax volumetric speed [n] mm^3/s costs [x] minutes.\nmax volumetric speed [m] mm^3/s costs [y] minutes"), wxDefaultPosition, wxDefaultSize, 0); - page1_description2->Wrap(FromDIP(500)); - page1_description2->SetFont(::Label::Body_14); - fgSizer->Add(page1_description2, 1, wxALL | wxEXPAND, 0); - - auto page1_bitmap2 = new wxStaticBitmap(m_page1, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); - fgSizer->Add(page1_bitmap2, 1, wxALL | wxEXPAND, 0); - - page1_right_content_sizer->Add(fgSizer, 1, wxEXPAND, 0); - - auto page1_prev_btn = m_page1->get_prev_btn(); - page1_prev_btn->Hide(); - - auto page1_next_btn = m_page1->get_next_btn(); - page1_next_btn->SetLabel(_L("Start")); - page1_next_btn->SetButtonType(ButtonType::Start); - - all_pages_sizer->Add(m_page1, 1, wxEXPAND | wxALL, FromDIP(10)); - - // page 2 - m_page2 = new CalibrationWizardPage(m_background_panel, true); - m_page2->set_page_title(_L("Max Volumetric Speed")); - m_page2->set_page_index(_L("2/3")); - - auto page2_left_sizer = m_page2->get_left_vsizer(); + auto page1_content_sizer = m_page1->get_content_vsizer(); m_from_text->SetLabel(_L("From Speed")); m_to_text->SetLabel(_L("To Speed")); @@ -1004,31 +2054,42 @@ void MaxVolumetricSpeedWizard::create_pages() m_step->SetLabel(_L("mm\u00B3/s")); m_step->GetTextCtrl()->SetLabel("0.5"); - add_presets_panel_to_page(m_page2, page2_left_sizer); + add_presets_panel_to_page(m_page1, page1_content_sizer); - auto page2_right_content_sizer = m_page2->get_right_content_vsizer(); + add_send_progress_to_page(m_page1, m_page1->get_btn_hsizer()); - auto page2_description = new wxStaticText(m_page2, wxID_ANY, _L("Please select the printer, the slot that contains the target filament, and fill the settings before calibrating.\n\nA test model will be printed. This step may take about 50 minutes."), wxDefaultPosition, wxDefaultSize, 0); - page2_description->Wrap(FromDIP(500)); - page2_description->SetFont(::Label::Body_14); - page2_right_content_sizer->Add(page2_description, 0, wxEXPAND, 0); + auto page1_prev_btn = m_page1->get_prev_btn(); + page1_prev_btn->Hide(); + auto page1_next_btn = m_page1->get_next_btn(); + page1_next_btn->SetLabel(_L("Calibrate")); + page1_next_btn->SetButtonType(ButtonType::Calibrate); + + m_all_pages_sizer->Add(m_page1, 1, wxEXPAND | wxALL, FromDIP(25)); + + // page 2 : print page + m_page2 = new CalibrationWizardPage(m_scrolledWindow, false); + m_page2->set_page_title(_L("Max Volumetric Speed")); + m_page2->set_page_index(_L("2/3")); + auto page2_content_sizer = m_page2->get_content_vsizer(); auto page2_bitmap = new wxStaticBitmap(m_page2, wxID_ANY, create_scaled_bitmap("max_volumetric_speed_wizard", nullptr, 400), wxDefaultPosition, wxDefaultSize, 0); - page2_right_content_sizer->Add(page2_bitmap, 0, wxEXPAND, 0); - - add_progress_bar_to_page(m_page2, page2_right_content_sizer); + page2_content_sizer->Add(page2_bitmap, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 0); + page2_content_sizer->AddSpacer(FromDIP(20)); + add_print_panel_to_page(m_page2, page2_content_sizer); auto page2_prev_btn = m_page2->get_prev_btn(); + page2_prev_btn->SetLabel(_L("Re-Calibrate")); + page2_prev_btn->SetButtonType(ButtonType::Recalibrate); page2_prev_btn->Hide(); auto page2_next_btn = m_page2->get_next_btn(); - page2_next_btn->SetLabel(_L("Calibrate")); - page2_next_btn->SetButtonType(ButtonType::Calibrate); + page2_next_btn->SetLabel(_L("Next")); + page2_next_btn->SetButtonType(ButtonType::Next); - all_pages_sizer->Add(m_page2, 1, wxEXPAND | wxALL, FromDIP(10)); + m_all_pages_sizer->Add(m_page2, 1, wxEXPAND | wxALL, FromDIP(25)); - // page 3 - m_page3 = new CalibrationWizardPage(m_background_panel, false); + // page 3 : save page + m_page3 = new CalibrationWizardPage(m_scrolledWindow, false); m_page3->set_page_title(_L("Max Volumetric Speed")); m_page3->set_page_index(_L("3/3")); @@ -1039,32 +2100,34 @@ void MaxVolumetricSpeedWizard::create_pages() page3_top_sizer->Add(page3_top_description, 0, wxALL, 0); page3_top_sizer->AddSpacer(FromDIP(20)); - auto page3_right_content_sizer = m_page3->get_right_content_vsizer(); + auto page3_content_sizer = m_page3->get_content_vsizer(); auto page3_bitmap = new wxStaticBitmap(m_page3, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); - page3_right_content_sizer->Add(page3_bitmap, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 0); + page3_bitmap->SetMinSize(wxSize(800, 600)); // todo modify + page3_bitmap->SetBackgroundColour(*wxBLACK); // todo modify + page3_content_sizer->Add(page3_bitmap, 0, wxALL | wxALIGN_CENTER_HORIZONTAL, 0); + + page3_content_sizer->AddSpacer(FromDIP(20)); auto value_sizer = new wxBoxSizer(wxHORIZONTAL); auto value_text = new wxStaticText(m_page3, wxID_ANY, _L("Input Value"), wxDefaultPosition, wxDefaultSize, 0); value_text->Wrap(-1); value_text->SetFont(::Label::Body_14); m_optimal_max_speed = new TextInput(m_page3, wxEmptyString, "", "", wxDefaultPosition, CALIBRATION_OPTIMAL_INPUT_SIZE, 0); - value_sizer->Add(value_text, 0, wxRight, FromDIP(20)); + value_sizer->Add(value_text, 0, wxALIGN_CENTER_VERTICAL, 0); + value_sizer->Add(FromDIP(10), 0, 0, wxEXPAND, 0); value_sizer->Add(m_optimal_max_speed, 0); - page3_right_content_sizer->Add(value_sizer, 0, wxEXPAND); + page3_content_sizer->Add(value_sizer, 0, wxALIGN_CENTER); + + page3_content_sizer->AddSpacer(FromDIP(20)); auto page3_prev_btn = m_page3->get_prev_btn(); - page3_prev_btn->SetLabel(_L("Re-Calibrate")); - page3_prev_btn->SetButtonType(ButtonType::Recalibrate); + page3_prev_btn->Hide(); auto page3_next_btn = m_page3->get_next_btn(); page3_next_btn->SetLabel(_L("Save")); page3_next_btn->SetButtonType(ButtonType::Save); - all_pages_sizer->Add(m_page3, 1, wxEXPAND | wxALL, FromDIP(10)); - - m_background_panel->SetSizer(all_pages_sizer); - m_background_panel->Layout(); - all_pages_sizer->Fit(m_background_panel); + m_all_pages_sizer->Add(m_page3, 1, wxEXPAND | wxALL, FromDIP(25)); // link page m_page1->chain(m_page2)->chain(m_page3); @@ -1074,11 +2137,12 @@ void MaxVolumetricSpeedWizard::create_pages() show_page(m_curr_page); } -bool MaxVolumetricSpeedWizard::start_calibration(std::string tray_id) +bool MaxVolumetricSpeedWizard::start_calibration(std::vector tray_ids) { Calib_Params params; m_from_value->GetTextCtrl()->GetValue().ToDouble(¶ms.start); m_to_value->GetTextCtrl()->GetValue().ToDouble(¶ms.end); + m_step->GetTextCtrl()->GetValue().ToDouble(¶ms.step); params.mode = CalibMode::Calib_Vol_speed_Tower; if (params.start <= 0 || params.step <= 0 || params.end < (params.start + params.step)) { @@ -1087,24 +2151,48 @@ bool MaxVolumetricSpeedWizard::start_calibration(std::string tray_id) return false; } - CalibUtils::calib_max_vol_speed(params, obj->dev_id, tray_id, std::shared_ptr(m_progress_bar)); + CalibInfo calib_info; + calib_info.params = params; + calib_info.dev_id = curr_obj->dev_id; + calib_info.select_ams = "[" + std::to_string(tray_ids[0]) + "]"; + calib_info.process_bar = m_send_progress_bar; + calib_info.bed_type = BedType(m_comboBox_bed_type->GetSelection() + btDefault + 1); + calib_info.printer_prest = m_printer_preset; + calib_info.filament_prest = m_filament_preset; + calib_info.print_prest = m_print_preset; + + std::string error_message; + CalibUtils::calib_max_vol_speed(calib_info, error_message); + show_send_progress_bar(true); return true; } -void MaxVolumetricSpeedWizard::update_calibration_value() +bool MaxVolumetricSpeedWizard::save_calibration_result() { - if (m_comboBox_printer->GetValue().IsEmpty() || - m_comboBox_filament->GetValue().IsEmpty() || - m_comboBox_bed_type->GetValue().IsEmpty() || - m_comboBox_process->GetValue().IsEmpty()) + if (m_optimal_max_speed->GetTextCtrl()->GetValue().IsEmpty()) { - m_from_value->GetTextCtrl()->SetValue(wxEmptyString); - m_to_value->GetTextCtrl()->SetValue(wxEmptyString); - return; + MessageDialog msg_dlg(nullptr, _L("Input a value."), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return false; } - m_from_value->GetTextCtrl()->SetValue("5"); - m_to_value->GetTextCtrl()->SetValue("20"); + double max_volumetric_speed; + m_optimal_max_speed->GetTextCtrl()->GetValue().ToDouble(&max_volumetric_speed); + return save_presets("filament_max_volumetric_speed", new ConfigOptionFloats{ max_volumetric_speed }); +} + +bool MaxVolumetricSpeedWizard::recommend_input_value() +{ + if (!CalibrationWizard::recommend_input_value()) { + m_from_value->GetTextCtrl()->SetValue(wxEmptyString); + m_to_value->GetTextCtrl()->SetValue(wxEmptyString); + return false; + } + else { + m_from_value->GetTextCtrl()->SetValue("5"); + m_to_value->GetTextCtrl()->SetValue("20"); + return true; + } } TemperatureWizard::TemperatureWizard(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) @@ -1115,36 +2203,27 @@ TemperatureWizard::TemperatureWizard(wxWindow* parent, wxWindowID id, const wxPo void TemperatureWizard::create_pages() { - wxBoxSizer* all_pages_sizer; - all_pages_sizer = new wxBoxSizer(wxVERTICAL); - - // page 1 - m_page1 = new CalibrationWizardPage(m_background_panel, true); + // page 1 : preset page + m_page1 = new CalibrationWizardPage(m_scrolledWindow, true); m_page1->set_page_title(_L("Temperature Calibration")); - m_page1->set_page_index(_L("1/2")); + m_page1->set_page_index(_L("1/3")); - auto page1_left_sizer = m_page1->get_left_vsizer(); + auto page1_content_sizer = m_page1->get_content_vsizer(); - add_presets_panel_to_page(m_page1, page1_left_sizer); + add_presets_panel_to_page(m_page1, page1_content_sizer); - auto page1_right_content_sizer = m_page1->get_right_content_vsizer(); - auto description1 = new wxStaticText(m_page1, wxID_ANY, _L("Temp tower is a straightforward test. The temp tower is a vertical tower with multiple blocks, each printed at a different temperature. Once the print is complete, we can examine each block of the tower and determine the optimal temperature for the filament.\n\nBy click the \"Calibrate\" button, the temp tower will be sent to your printer and start printing. The printing job may take about 50 minutes."), wxDefaultPosition, wxDefaultSize, 0); - description1->Wrap(500); - description1->SetFont(::Label::Body_14); - description1->SetMinSize({ FromDIP(500), -1 }); - page1_right_content_sizer->Add(description1, 0, wxALL | wxEXPAND, 0); + //auto description1 = new wxStaticText(m_page1, wxID_ANY, _L("Temp tower is a straightforward test. The temp tower is a vertical tower with multiple blocks, each printed at a different temperature. Once the print is complete, we can examine each block of the tower and determine the optimal temperature for the filament.\n\nBy click the \"Calibrate\" button, the temp tower will be sent to your printer and start printing. The printing job may take about 50 minutes."), wxDefaultPosition, wxDefaultSize, 0); + //description1->Wrap(500); + //description1->SetFont(::Label::Body_14); + //description1->SetMinSize({ FromDIP(500), -1 }); + //page1_content_sizer->Add(description1, 0, wxALL | wxEXPAND, 0); - auto picture_description1 = new wxStaticBitmap(m_page1, wxID_ANY, create_scaled_bitmap("temperature_wizard1", nullptr, 450), wxDefaultPosition, wxDefaultSize, 0); - page1_right_content_sizer->Add(picture_description1, 1, wxALIGN_LEFT | wxEXPAND, 0); - - page1_right_content_sizer->Add(0, FromDIP(20), 0, wxEXPAND, 0); + add_send_progress_to_page(m_page1, m_page1->get_btn_hsizer()); m_from_text->SetLabel(_L("From Temp")); m_to_text->SetLabel(_L("To Temp")); m_step->Enable(false); - add_progress_bar_to_page(m_page1, page1_right_content_sizer); - auto page1_prev_btn = m_page1->get_prev_btn(); page1_prev_btn->Hide(); @@ -1152,176 +2231,168 @@ void TemperatureWizard::create_pages() page1_next_btn->SetLabel(_L("Calibrate")); page1_next_btn->SetButtonType(ButtonType::Calibrate); - all_pages_sizer->Add(m_page1, 1, wxEXPAND | wxALL, FromDIP(10)); + m_all_pages_sizer->Add(m_page1, 1, wxEXPAND | wxALL, FromDIP(25)); - // page 2 - m_page2 = new CalibrationWizardPage(m_background_panel, false); + // page 2 : print page + m_page2 = new CalibrationWizardPage(m_scrolledWindow, false); m_page2->set_page_title(_L("Temperature Calibration")); - m_page2->set_page_index(_L("2/2")); + m_page2->set_page_index(_L("2/3")); - auto page2_left_sizer = m_page2->get_left_vsizer(); - auto picture_description2 = new wxStaticBitmap(m_page2, wxID_ANY, create_scaled_bitmap("temperature_wizard2", nullptr, 650), wxDefaultPosition, wxDefaultSize, 0); - page2_left_sizer->Add(picture_description2, 1, wxALL | wxEXPAND, 0); + auto page2_content_sizer = m_page2->get_content_vsizer(); + auto page2_picture_description = new wxStaticBitmap(m_page2, wxID_ANY, create_scaled_bitmap("temperature_wizard1", nullptr, 400), wxDefaultPosition, wxDefaultSize, 0); + page2_content_sizer->Add(page2_picture_description, 0, wxALIGN_CENTER, 0); + add_print_panel_to_page(m_page2, page2_content_sizer); - auto page2_right_content_sizer = m_page2->get_right_content_vsizer(); - auto description2 = new wxStaticText(m_page2, wxID_ANY, _L("The calibration model has been printed.\nPlease find the optimal temperature is the one that produces the highest quality print with the least amount of issues, such as stringing, layer adhesion, warping (overhang), and bridging."), wxDefaultPosition, wxDefaultSize, 0); - description2->Wrap(500); - description2->SetFont(::Label::Body_14); - page2_right_content_sizer->Add(description2, 0, wxALL, 0); + auto page2_prev_btn = m_page2->get_prev_btn(); + page2_prev_btn->SetLabel(_L("Re-Calibrate")); + page2_prev_btn->SetButtonType(ButtonType::Recalibrate); + page2_prev_btn->Hide(); - page2_right_content_sizer->Add(0, FromDIP(20), 0, wxEXPAND, 0); + auto page2_next_btn = m_page2->get_next_btn(); + page2_next_btn->SetLabel(_L("Next")); + page2_next_btn->SetButtonType(ButtonType::Next); + + m_all_pages_sizer->Add(m_page2, 1, wxEXPAND | wxALL, FromDIP(25)); + + + // page 3 : save page + m_page3 = new CalibrationWizardPage(m_scrolledWindow, false); + m_page3->set_page_title(_L("Temperature Calibration")); + m_page3->set_page_index(_L("3/3")); + + auto page3_content_sizer = m_page3->get_content_vsizer(); + auto page3_picture_description = new wxStaticBitmap(m_page3, wxID_ANY, create_scaled_bitmap("temperature_wizard2", nullptr, 400), wxDefaultPosition, wxDefaultSize, 0); + page3_content_sizer->Add(page3_picture_description, 0, wxALIGN_CENTER, 0); + + auto description = new wxStaticText(m_page3, wxID_ANY, _L("The calibration model has been printed.\nPlease find the optimal temperature is the one that produces the highest quality print with the least amount of issues, such as stringing, layer adhesion, warping (overhang), and bridging."), wxDefaultPosition, wxDefaultSize, 0); + description->SetFont(::Label::Body_14); + description->Wrap(CALIBRATION_TEXT_MAX_LENGTH); + page3_content_sizer->Add(description, 0, wxALIGN_CENTER, 0); + + page3_content_sizer->Add(0, FromDIP(20), 0, wxEXPAND, 0); wxBoxSizer* optimal_temp_szier; optimal_temp_szier = new wxBoxSizer(wxHORIZONTAL); - auto optimal_temp_text = new wxStaticText(m_page2, wxID_ANY, _L("Optimal Temp"), wxDefaultPosition, wxDefaultSize, 0); + auto optimal_temp_text = new wxStaticText(m_page3, wxID_ANY, _L("Optimal Temp"), wxDefaultPosition, wxDefaultSize, 0); optimal_temp_text->Wrap(-1); optimal_temp_text->SetFont(::Label::Body_14); optimal_temp_szier->Add(optimal_temp_text, 0, wxALL | wxALIGN_CENTER_VERTICAL, 0); optimal_temp_szier->Add(FromDIP(10), 0, 0, wxEXPAND, 0); - m_optimal_temp = new TextInput(m_page2, wxEmptyString, _L("\u2103"), "", wxDefaultPosition, CALIBRATION_OPTIMAL_INPUT_SIZE, 0); + m_optimal_temp = new TextInput(m_page3, wxEmptyString, _L("\u2103"), "", wxDefaultPosition, CALIBRATION_OPTIMAL_INPUT_SIZE, 0); optimal_temp_szier->Add(m_optimal_temp, 0, wxALL, 0); - page2_right_content_sizer->Add(optimal_temp_szier, 0, wxEXPAND, 0); + page3_content_sizer->Add(optimal_temp_szier, 0, wxALIGN_CENTER, 0); - auto page2_prev_btn = m_page2->get_prev_btn(); - page2_prev_btn->SetLabel(_L("Re-Calibrate")); - page2_prev_btn->SetButtonType(ButtonType::Recalibrate); + page3_content_sizer->AddSpacer(FromDIP(20)); - auto page2_next_btn = m_page2->get_next_btn(); - page2_next_btn->SetLabel(_L("Save")); - page2_next_btn->SetButtonType(ButtonType::Save); + auto page3_prev_btn = m_page3->get_prev_btn(); + page3_prev_btn->Hide(); - all_pages_sizer->Add(m_page2, 1, wxEXPAND | wxALL, FromDIP(10)); + auto page3_next_btn = m_page3->get_next_btn(); + page3_next_btn->SetLabel(_L("Save")); + page3_next_btn->SetButtonType(ButtonType::Save); - m_background_panel->SetSizer(all_pages_sizer); - m_background_panel->Layout(); - all_pages_sizer->Fit(m_background_panel); + m_all_pages_sizer->Add(m_page3, 1, wxEXPAND | wxALL, FromDIP(25)); + // link pages - m_page1->chain(m_page2); + m_page1->chain(m_page2)->chain(m_page3); m_first_page = m_page1; m_curr_page = m_page1; show_page(m_curr_page); } -bool TemperatureWizard::start_calibration(std::string tray_id) +bool TemperatureWizard::start_calibration(std::vector tray_ids) { Calib_Params params; m_from_value->GetTextCtrl()->GetValue().ToDouble(¶ms.start); m_to_value->GetTextCtrl()->GetValue().ToDouble(¶ms.end); params.mode = CalibMode::Calib_Temp_Tower; - if (params.start < 180 || params.end > 350 || params.end < (params.start + 5)) { - MessageDialog msg_dlg(nullptr, _L("Please input valid values:\nFrom temp: >= 180\nTo temp: <= 350\nFrom temp <= To temp - Step"), wxEmptyString, wxICON_WARNING | wxOK); + if (params.start < 180 || params.end > 350 || params.end < (params.start + 5) || (params.end - params.start) >= 120) { // todo + MessageDialog msg_dlg(nullptr, _L("Please input valid values:\nFrom temp: >= 180\nTo temp: <= 350\nFrom temp <= To temp - Step\n From temp - To temp < 120"), wxEmptyString, wxICON_WARNING | wxOK); msg_dlg.ShowModal(); return false; } - CalibUtils::calib_temptue(params, obj->dev_id, tray_id, std::shared_ptr(m_progress_bar)); + CalibInfo calib_info; + calib_info.params = params; + calib_info.dev_id = curr_obj->dev_id; + calib_info.select_ams = "[" + std::to_string(tray_ids[0]) + "]"; + calib_info.process_bar = m_send_progress_bar; + calib_info.bed_type = BedType(m_comboBox_bed_type->GetSelection() + btDefault + 1); + calib_info.printer_prest = m_printer_preset; + calib_info.filament_prest = m_filament_preset; + calib_info.print_prest = m_print_preset; + + std::string error_message; + CalibUtils::calib_temptue(calib_info, error_message); + show_send_progress_bar(true); return true; } -void TemperatureWizard::save_calibration_result() +bool TemperatureWizard::save_calibration_result() { - SavePresetDialog dlg(m_parent, Preset::Type::TYPE_FILAMENT, ""); - if (dlg.ShowModal() != wxID_OK) - return; - std::string name = dlg.get_name(); - bool save_to_project = dlg.get_save_to_project_selection(Preset::TYPE_FILAMENT); // todo remove save_to_project chioce - - - auto m_presets = &wxGetApp().preset_bundle->filaments; - // BBS record current preset name - std::string curr_preset_name = m_presets->get_edited_preset().name; - - bool exist_preset = false; // todo remove new_preset->sync_info = "update" related logic - Preset* new_preset = m_presets->find_preset(name, false); - if (new_preset) { - exist_preset = true; + if (m_optimal_temp->GetTextCtrl()->GetValue().IsEmpty()) // todo need a valid range + { + MessageDialog msg_dlg(nullptr, _L("Input an optiaml temperature."), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + return false; } - // Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini - m_presets->save_current_preset(name, false, save_to_project); - - new_preset = m_presets->find_preset(name, false, true); - if (!new_preset) { - BOOST_LOG_TRIVIAL(info) << "create new preset failed"; - return; - } - - // set sync_info for sync service - if (exist_preset) { - new_preset->sync_info = "update"; - BOOST_LOG_TRIVIAL(info) << "sync_preset: update preset = " << new_preset->name; - } - else { - new_preset->sync_info = "create"; - if (wxGetApp().is_user_login()) - new_preset->user_id = wxGetApp().getAgent()->get_user_id(); - BOOST_LOG_TRIVIAL(info) << "sync_preset: create preset = " << new_preset->name; - } - new_preset->save_info(); - - // Mark the print & filament enabled if they are compatible with the currently selected preset. - // If saving the preset changes compatibility with other presets, keep the now incompatible dependent presets selected, however with a "red flag" icon showing that they are no more compatible. - wxGetApp().preset_bundle->update_compatible(PresetSelectCompatibleType::Never); - - // update current comboBox selected preset - if (!exist_preset) { - wxGetApp().plater()->sidebar().update_presets_from_to(Preset::TYPE_FILAMENT, curr_preset_name, new_preset->name); - } + int temp = stoi(m_optimal_temp->GetTextCtrl()->GetValue().ToStdString()); + return save_presets("nozzle_temperature", new ConfigOptionInts(1, temp)); } -void TemperatureWizard::update_calibration_value() +bool TemperatureWizard::recommend_input_value() { - if (m_comboBox_printer->GetValue().IsEmpty() || - m_comboBox_filament->GetValue().IsEmpty() || - m_comboBox_bed_type->GetValue().IsEmpty() || - m_comboBox_process->GetValue().IsEmpty()) - { + if (!CalibrationWizard::recommend_input_value()) { m_from_value->GetTextCtrl()->SetValue(wxEmptyString); m_to_value->GetTextCtrl()->SetValue(wxEmptyString); - return; - } - - wxString filament_name = m_comboBox_filament->GetValue(); - - unsigned long start, end; - if (filament_name.Contains("ABS") || filament_name.Contains("ASA")) {//todo supplement - start = 230; - end = 270; - } - else if (filament_name.Contains("PETG")) { - start = 230; - end = 260; - } - else if(filament_name.Contains("TPU")) { - start = 210; - end = 240; - } - else if(filament_name.Contains("PA-CF")) { - start = 280; - end = 320; - } - else if(filament_name.Contains("PET-CF")) { - start = 280; - end = 320; - } - else if(filament_name.Contains("PLA")) { - start = 190; - end = 230; + return false; } else { - start = 190; - end = 230; + wxString filament_name = m_filament_preset->alias; + + int start, end; + if (filament_name.Contains("ABS") || filament_name.Contains("ASA")) {//todo supplement + start = 230; + end = 270; + } + else if (filament_name.Contains("PETG")) { + start = 230; + end = 260; + } + else if (filament_name.Contains("TPU")) { + start = 210; + end = 240; + } + else if (filament_name.Contains("PA-CF")) { + start = 280; + end = 320; + } + else if (filament_name.Contains("PET-CF")) { + start = 280; + end = 320; + } + else if (filament_name.Contains("PLA")) { + start = 190; + end = 230; + } + else { + start = 190; + end = 230; + } + m_from_value->GetTextCtrl()->SetValue(std::to_string(start)); + m_to_value->GetTextCtrl()->SetValue(std::to_string(end)); + + return true; } - m_from_value->GetTextCtrl()->SetValue(std::to_string(start)); - m_to_value->GetTextCtrl()->SetValue(std::to_string(end)); } }} \ No newline at end of file diff --git a/src/slic3r/GUI/CalibrationWizard.hpp b/src/slic3r/GUI/CalibrationWizard.hpp index 7d0d232d33..360eb7eaeb 100644 --- a/src/slic3r/GUI/CalibrationWizard.hpp +++ b/src/slic3r/GUI/CalibrationWizard.hpp @@ -1,17 +1,57 @@ #ifndef slic3r_GUI_CalibrationWizard_hpp_ #define slic3r_GUI_CalibrationWizard_hpp_ -#include "GUI_Utils.hpp" #include "DeviceManager.hpp" #include "CalibrationWizardPage.hpp" #include "Widgets/ComboBox.hpp" #include "Widgets/TextInput.hpp" #include "Widgets/AMSControl.hpp" +#include "AMSMaterialsSetting.hpp" +#include "Widgets/ProgressBar.hpp" #include "SavePresetDialog.hpp" +#include "PresetComboBoxes.hpp" #include "../slic3r/Utils/CalibUtils.hpp" namespace Slic3r { namespace GUI { +wxDECLARE_EVENT(EVT_CALIBRATION_TRAY_SELECTION_CHANGED, SimpleEvent); + +enum FilamentSelectMode { + FSMCheckBoxMode, + FSMRadioMode +}; +class FilamentComboBox : public wxPanel +{ +public: + FilamentComboBox(wxWindow* parent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize); + ~FilamentComboBox() {}; + + void set_select_mode(FilamentSelectMode mode); + FilamentSelectMode get_select_mode() { return m_mode; } + void load_tray_from_ams(int id, DynamicPrintConfig& tray); + void update_from_preset(); + int get_tray_id() { return m_tray_id; } + CalibrateFilamentComboBox* GetComboBox() { return m_comboBox; } + CheckBox* GetCheckBox() { return m_checkBox; } + void SetCheckBox(CheckBox* cb) { m_checkBox = cb; } + wxRadioButton* GetRadioBox() { return m_radioBox; } + void SetRadioBox(wxRadioButton* btn) { m_radioBox = btn; } + virtual bool Show(bool show = true); + virtual bool Enable(bool enable); + virtual void SetValue(bool value); + +protected: + int m_tray_id; + + CheckBox* m_checkBox{nullptr}; + //RadioBox* m_radioBox; + wxRadioButton* m_radioBox{ nullptr }; + CalibrateFilamentComboBox* m_comboBox{ nullptr }; + FilamentSelectMode m_mode{ FSMRadioMode }; +}; + +typedef std::vector FilamentComboBoxList; + class CalibrationWizard : public wxPanel { public: CalibrationWizard(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL); @@ -19,70 +59,125 @@ public: CalibrationWizardPage* get_curr_page() { return m_curr_page; } CalibrationWizardPage* get_frist_page() { return m_first_page; } void show_page(CalibrationWizardPage* page); - void update_obj(MachineObject* rhs_obj) { obj = rhs_obj; } + void show_send_progress_bar(bool show); + void update_printer_selections(); void update_ams(MachineObject* obj); - void update_progress(); + void update_print_progress(); + void update_filaments_from_preset(); protected: virtual void create_pages() = 0; - virtual bool start_calibration(std::string tray_id) = 0; - virtual void save_calibration_result() {}; - virtual void update_calibration_value() = 0; + virtual bool start_calibration(std::vector tray_ids) = 0; + virtual bool save_calibration_result() = 0; + virtual bool recommend_input_value(); protected: - wxPanel* m_background_panel; + MachineObject* curr_obj{ nullptr }; + std::vector obj_list{ nullptr }; + + wxScrolledWindow* m_scrolledWindow; + wxBoxSizer* m_all_pages_sizer; + + CalibrationWizardPage* m_curr_page{ nullptr }; + CalibrationWizardPage* m_first_page{ nullptr }; + + // preset panel wxPanel* m_presets_panel; - AMSControl* m_ams_control; + wxPanel* m_select_ams_mode_panel; + //RadioBox* m_ams_radiobox; + //RadioBox* m_ext_spool_radiobox; + wxRadioButton* m_ams_radiobox; + wxRadioButton* m_ext_spool_radiobox; + bool m_filament_from_ext_spool{ false }; + wxPanel* m_muilti_ams_panel; + std::vector m_ams_item_list; + wxPanel* m_filament_list_panel; + ScalableButton* m_ams_sync_button; + FilamentComboBoxList m_filament_comboBox_list; + wxPanel* m_virtual_panel; + FilamentComboBox* m_virtual_tray_comboBox; ComboBox* m_comboBox_printer; - ComboBox* m_comboBox_filament; + ComboBox* m_comboBox_nozzle_dia; ComboBox* m_comboBox_bed_type; ComboBox* m_comboBox_process; + Preset* m_printer_preset{nullptr}; + Preset* m_filament_preset{ nullptr }; + Preset* m_print_preset{ nullptr }; wxStaticText* m_from_text; wxStaticText* m_to_text; wxStaticText* m_step_text; TextInput* m_from_value; TextInput* m_to_value; TextInput* m_step; - BBLStatusBarSend* m_progress_bar; + TextInput* m_nozzle_temp; + TextInput* m_bed_temp; + TextInput* m_max_volumetric_speed; + wxStaticText* m_filaments_incompatible_tips; + wxStaticText* m_bed_type_incompatible_tips; + wxPanel* m_send_progress_panel; + std::shared_ptr m_send_progress_bar; // for send - MachineObject* obj{ nullptr }; + // print panel + wxPanel* m_print_panel; + wxStaticText* m_staticText_progress_percent; + wxStaticText* m_staticText_progress_left_time; + wxStaticText* m_staticText_layers; + ScalableButton* m_button_pause_resume; + ScalableButton* m_button_abort; + ProgressBar* m_print_gauge_progress; // for print + PageButton* m_btn_next; + PageButton* m_btn_recali; + + // save panel + wxPanel* m_save_panel; - CalibrationWizardPage* m_curr_page{ nullptr }; - CalibrationWizardPage* m_first_page{ nullptr }; void add_presets_panel_to_page(CalibrationWizardPage* page, wxBoxSizer* sizer); - void add_progress_bar_to_page(CalibrationWizardPage* page, wxBoxSizer* sizer); - void show_progress_bar(bool show); - wxString get_presets_incompatible() { return wxString(); } + void add_print_panel_to_page(CalibrationWizardPage* page, wxBoxSizer* sizer); + void add_send_progress_to_page(CalibrationWizardPage* page, wxBoxSizer* sizer); - void on_select_printer(wxCommandEvent& evt); - void on_select_filament(wxCommandEvent& evt); + void reset_printing_values(); + bool save_presets(const std::string& config_key, ConfigOption* config_value); + int get_bed_temp(DynamicPrintConfig* config); + FilamentSelectMode get_ams_select_mode() { if (!m_filament_comboBox_list.empty()) return m_filament_comboBox_list[0]->get_select_mode(); return FilamentSelectMode::FSMRadioMode; } + void set_ams_select_mode(FilamentSelectMode mode) { for (auto fcb : m_filament_comboBox_list) fcb->set_select_mode(mode); }; + std::vector get_selected_tray(); + FilamentComboBoxList get_selected_filament_comboBox(); + + virtual void on_select_printer(wxCommandEvent& evt); + void on_select_nozzle(wxCommandEvent& evt); + void on_select_tray(SimpleEvent& evt); void on_select_bed_type(wxCommandEvent& evt); - void on_select_process(wxCommandEvent& evt); void on_click_btn_prev(IntEvent& event); void on_click_btn_next(IntEvent& event); + void on_subtask_abort(wxCommandEvent& event); + void on_subtask_pause_resume(wxCommandEvent& event); + void on_choose_ams(wxCommandEvent& event); + void on_choose_ext_spool(wxCommandEvent& event); + void on_update_ams_filament(bool dialog = true); + void on_switch_ams(std::string ams_id); private: void create_presets_panel(); - void create_progress_bar(); + void create_print_panel(); + void create_save_panel(); + void create_send_progress_bar(); - void init_printer_selections(); - void init_filaments_selections(); + void init_presets_selections(); + void init_nozzle_selections(); void init_bed_type_selections(); void init_process_selections(); - void init_presets_selections(); }; -class PressureAdvanceWizard : public CalibrationWizard{}; - -class FlowRateWizard : public CalibrationWizard { +class PressureAdvanceWizard : public CalibrationWizard{ public: - FlowRateWizard(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL); - ~FlowRateWizard() {}; + PressureAdvanceWizard(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL); + ~PressureAdvanceWizard() {}; protected: virtual void create_pages() override; - virtual bool start_calibration(std::string tray_id) override; - virtual void update_calibration_value() override; + virtual bool start_calibration(std::vector tray_ids) override; + virtual bool save_calibration_result() override; + virtual bool recommend_input_value() override; private: // page 1 CalibrationWizardPage* m_page1; @@ -92,21 +187,44 @@ private: // page 3 CalibrationWizardPage* m_page3; + TextInput* m_k_val; + TextInput* m_n_val; +}; + +class FlowRateWizard : public CalibrationWizard { +public: + FlowRateWizard(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL); + ~FlowRateWizard() {}; +protected: + void create_low_end_pages(); + void create_high_end_pages(); + virtual void create_pages() override; + virtual bool start_calibration(std::vector tray_ids) override; + virtual bool save_calibration_result() override; + virtual bool recommend_input_value() override; + + virtual void on_select_printer(wxCommandEvent& evt) override; +private: + // page 1 + CalibrationWizardPage* m_page1{ nullptr }; + + // page 2 + CalibrationWizardPage* m_page2{ nullptr }; + + // page 3 + CalibrationWizardPage* m_page3{ nullptr }; + CalibrationWizardPage* m_high_end_page3{ nullptr }; ComboBox* m_optimal_block_coarse; // page 4 - CalibrationWizardPage* m_page4; - AMSControl* m_readonly_ams_control; - TextInput* m_readonly_printer; - TextInput* m_readonly_filament; - TextInput* m_readonly_bed_type; - TextInput* m_readonly_process; + CalibrationWizardPage* m_page4{ nullptr }; + //BBLStatusBarSend* m_progress_bar2; // page 5 - CalibrationWizardPage* m_page5; + CalibrationWizardPage* m_page5{ nullptr }; ComboBox* m_optimal_block_fine; - void create_readonly_presets_panel(); + void on_fine_tune(wxCommandEvent&); }; class MaxVolumetricSpeedWizard : public CalibrationWizard { @@ -115,8 +233,9 @@ public: ~MaxVolumetricSpeedWizard() {}; protected: virtual void create_pages() override; - virtual bool start_calibration(std::string tray_id) override; - virtual void update_calibration_value() override; + virtual bool start_calibration(std::vector tray_ids) override; + virtual bool save_calibration_result() override; + virtual bool recommend_input_value() override; private: // page 1 CalibrationWizardPage* m_page1; @@ -135,9 +254,9 @@ public: ~TemperatureWizard() {}; protected: virtual void create_pages() override; - virtual bool start_calibration(std::string tray_id) override; - virtual void save_calibration_result(); - virtual void update_calibration_value() override; + virtual bool start_calibration(std::vector tray_ids) override; + virtual bool save_calibration_result() override; + virtual bool recommend_input_value() override; private: // page 1 CalibrationWizardPage* m_page1; @@ -145,6 +264,9 @@ private: // page 2 CalibrationWizardPage* m_page2; TextInput* m_optimal_temp; + + // page 3 + CalibrationWizardPage* m_page3; }; class VFAWizard : public CalibrationWizard {}; diff --git a/src/slic3r/GUI/CalibrationWizardPage.cpp b/src/slic3r/GUI/CalibrationWizardPage.cpp index 6c22a779be..2dae878119 100644 --- a/src/slic3r/GUI/CalibrationWizardPage.cpp +++ b/src/slic3r/GUI/CalibrationWizardPage.cpp @@ -1,6 +1,6 @@ #include "CalibrationWizardPage.hpp" -#include "CalibrationWizard.hpp" #include "I18N.hpp" +#include "Widgets/Label.hpp" namespace Slic3r { namespace GUI { @@ -11,12 +11,12 @@ PageButton::PageButton(wxWindow* parent, wxString text, ButtonType type) : m_type(type), Button(parent, text) { - StateColor btn_bg_green(std::pair(AMS_CONTROL_DISABLE_COLOUR, StateColor::Disabled), + StateColor btn_bg_green(std::pair(wxColour(206, 206, 206), StateColor::Disabled), std::pair(wxColour(27, 136, 68), StateColor::Pressed), std::pair(wxColour(61, 203, 115), StateColor::Hovered), std::pair(wxColour(0, 174, 66), StateColor::Normal)); - StateColor btn_bg_white(std::pair(AMS_CONTROL_DISABLE_COLOUR, StateColor::Disabled), + StateColor btn_bg_white(std::pair(wxColour(206, 206, 206), StateColor::Disabled), std::pair(wxColour(206, 206, 206), StateColor::Pressed), std::pair(wxColour(238, 238, 238), StateColor::Hovered), std::pair(wxColour(255, 255, 255), StateColor::Normal)); @@ -59,9 +59,8 @@ PageButton::PageButton(wxWindow* parent, wxString text, ButtonType type) SetCornerRadius(FromDIP(12)); } -CalibrationWizardPage::CalibrationWizardPage(wxWindow* parent, bool has_split_line, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) - : m_has_middle_line(has_split_line), - wxPanel(parent, id, pos, size, style) +CalibrationWizardPage::CalibrationWizardPage(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) + : wxPanel(parent, id, pos, size, style) { SetBackgroundColour(*wxWHITE); @@ -90,40 +89,21 @@ CalibrationWizardPage::CalibrationWizardPage(wxWindow* parent, bool has_split_li page_sizer->Add(m_top_sizer, 0, wxEXPAND, 0); - wxBoxSizer* horiz_sizer; - horiz_sizer = new wxBoxSizer(wxHORIZONTAL); + m_content_sizer = new wxBoxSizer(wxVERTICAL); - m_left_sizer = new wxBoxSizer(wxVERTICAL); - horiz_sizer->Add(m_left_sizer, 1, wxEXPAND, 0); + page_sizer->Add(m_content_sizer, 0, wxEXPAND, 0); - auto middle_line = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(1, -1), wxTAB_TRAVERSAL); - middle_line->SetBackgroundColour(wxColour(0, 0, 0)); + page_sizer->AddStretchSpacer(); - horiz_sizer->Add(middle_line, 0, wxEXPAND | wxRIGHT | wxLEFT, FromDIP(20)); - - if (!has_split_line) { - middle_line->Hide(); - } - - auto right_sizer = new wxBoxSizer(wxVERTICAL); - - m_right_content_sizer = new wxBoxSizer(wxVERTICAL); - - right_sizer->Add(m_right_content_sizer, 0, wxEXPAND, 0); - - m_right_btn_sizer = new wxBoxSizer(wxHORIZONTAL); - m_right_btn_sizer->Add(0, 0, 1, wxEXPAND, 0); + m_btn_sizer = new wxBoxSizer(wxHORIZONTAL); + m_btn_sizer->Add(0, 0, 1, wxEXPAND, 0); m_btn_prev = new PageButton(this, "Back", Back); - m_right_btn_sizer->Add(m_btn_prev, 0); - m_right_btn_sizer->AddSpacer(FromDIP(10)); + m_btn_sizer->Add(m_btn_prev, 0); + m_btn_sizer->AddSpacer(FromDIP(10)); m_btn_next = new PageButton(this, "Next", Next); - m_right_btn_sizer->Add(m_btn_next, 0); + m_btn_sizer->Add(m_btn_next, 0); - right_sizer->Add(m_right_btn_sizer, 0, wxEXPAND, 0); - - horiz_sizer->Add(right_sizer, 1, wxEXPAND, 0); - - page_sizer->Add(horiz_sizer, 1, wxEXPAND, 0); + page_sizer->Add(m_btn_sizer, 0, wxEXPAND, 0); this->SetSizer(page_sizer); this->Layout(); diff --git a/src/slic3r/GUI/CalibrationWizardPage.hpp b/src/slic3r/GUI/CalibrationWizardPage.hpp index 89f7cb8c9f..b3220f7ac0 100644 --- a/src/slic3r/GUI/CalibrationWizardPage.hpp +++ b/src/slic3r/GUI/CalibrationWizardPage.hpp @@ -34,7 +34,7 @@ private: class CalibrationWizardPage : public wxPanel { public: - CalibrationWizardPage(wxWindow* parent, bool has_split_line, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL); + CalibrationWizardPage(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL); ~CalibrationWizardPage() {}; CalibrationWizardPage* get_prev_page() { return m_prev_page; } @@ -49,8 +49,8 @@ public: } wxBoxSizer* get_top_vsizer() { return m_top_sizer; } - wxBoxSizer* get_left_vsizer() { return m_left_sizer; } - wxBoxSizer* get_right_content_vsizer() { return m_right_content_sizer; } + wxBoxSizer* get_content_vsizer() { return m_content_sizer; } + wxBoxSizer* get_btn_hsizer() { return m_btn_sizer; } PageButton* get_prev_btn() { return m_btn_prev; } PageButton* get_next_btn() { return m_btn_next; } @@ -58,14 +58,11 @@ public: void set_page_index(wxString index) { m_index->SetLabel(index); } private: - bool m_has_middle_line; - wxStaticText* m_title; wxStaticText* m_index; wxBoxSizer* m_top_sizer; - wxBoxSizer* m_left_sizer; - wxBoxSizer* m_right_content_sizer; - wxBoxSizer* m_right_btn_sizer; + wxBoxSizer* m_content_sizer; + wxBoxSizer* m_btn_sizer; PageButton* m_btn_prev; PageButton* m_btn_next; diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 25583a3075..57cf5bcc7b 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -1941,6 +1941,126 @@ int MachineObject::command_start_calibration(bool vibration, bool bed_leveling, } } +int MachineObject::command_start_pa_calibration(const CalibDatas &pa_data) +{ + pa_calib_results.clear(); + if ((printer_type == "BL-P001" || printer_type == "BL-P002")) { + json j; + j["print"]["command"] = "extrusion_cali"; + j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); + + for (int i = 0; i < pa_data.calib_datas.size(); ++i) { + j["print"]["filaments"][i]["bed_temp"] = pa_data.calib_datas[i].bed_temp; + j["print"]["filaments"][i]["tray_id"] = pa_data.calib_datas[i].tray_id; + j["print"]["filaments"][i]["filament_id"] = pa_data.calib_datas[i].filament_id; + j["print"]["filaments"][i]["setting_id"] = pa_data.calib_datas[i].setting_id; + j["print"]["filaments"][i]["nozzle_temp"] = pa_data.calib_datas[i].nozzle_temp; + j["print"]["filaments"][i]["max_volumetric_speed"] = std::to_string(pa_data.calib_datas[i].max_volumetric_speed); + } + + return this->publish_json(j.dump()); + } + return -1; +} + +int MachineObject::command_set_pa_calibration(const std::vector& pa_calib_values) +{ + if ((printer_type == "BL-P001" || printer_type == "BL-P002")) { + json j; + j["print"]["command"] = "extrusion_cali_set"; + j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); + + for (int i = 0; i < pa_calib_values.size(); ++i) { + j["print"]["filaments"][i]["tray_id"] = pa_calib_values[i].tray_id; + j["print"]["filaments"][i]["filament_id"] = pa_calib_values[i].filament_id; + j["print"]["filaments"][i]["setting_id"] = pa_calib_values[i].setting_id; + j["print"]["filaments"][i]["name"] = pa_calib_values[i].name; + j["print"]["filaments"][i]["k_value"] = std::to_string(pa_calib_values[i].k_value); + j["print"]["filaments"][i]["n_coef"] = std::to_string(pa_calib_values[i].n_coef); + } + + return this->publish_json(j.dump()); + } + + return -1; +} + +int MachineObject::command_delete_pa_calibration(const PACalibResult& pa_calib) +{ + if ((printer_type == "BL-P001" || printer_type == "BL-P002")) { + json j; + j["print"]["command"] = "extrusion_cali_del"; + j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); + j["print"]["tray_id"] = pa_calib.tray_id; + j["print"]["filament_id"] = pa_calib.filament_id; + j["print"]["setting_id"] = pa_calib.setting_id; + j["print"]["name"] = pa_calib.name; + j["print"]["k_value"] = std::to_string(pa_calib.k_value); + j["print"]["n_coef"] = std::to_string(pa_calib.n_coef); + + return this->publish_json(j.dump()); + } + return -1; +} + +int MachineObject::command_get_pa_calibration_infos(const std::string& filament_id) +{ + if ((printer_type == "BL-P001" || printer_type == "BL-P002")) { + json j; + j["print"]["command"] = "extrusion_cali_get"; + j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); + j["print"]["sequence_id"] = filament_id; + + return this->publish_json(j.dump()); + } + return -1; +} + +int MachineObject::command_get_pa_calibration_result() +{ + if ((printer_type == "BL-P001" || printer_type == "BL-P002")) { + json j; + j["print"]["command"] = "extrusion_cali_get_result"; + j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); + + return this->publish_json(j.dump()); + } + return -1; +} + +int MachineObject::command_start_flow_ratio_calibration(const CalibDatas& calib_data) +{ + if ((printer_type == "BL-P001" || printer_type == "BL-P002")) { + json j; + j["print"]["command"] = "flowrate_cali"; + j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); + + for (int i = 0; i < calib_data.calib_datas.size(); ++i) { + j["print"]["filaments"][i]["bed_temp"] = calib_data.calib_datas[i].bed_temp; + j["print"]["filaments"][i]["tray_id"] = calib_data.calib_datas[i].tray_id; + j["print"]["filaments"][i]["filament_id"] = calib_data.calib_datas[i].filament_id; + j["print"]["filaments"][i]["setting_id"] = calib_data.calib_datas[i].setting_id; + j["print"]["filaments"][i]["nozzle_temp"] = calib_data.calib_datas[i].nozzle_temp; + j["print"]["filaments"][i]["max_volumetric_speed"] = std::to_string(calib_data.calib_datas[i].max_volumetric_speed); + } + + return this->publish_json(j.dump()); + } + return -1; +} + +int MachineObject::command_get_flow_ratio_calibration_result() +{ + if ((printer_type == "BL-P001" || printer_type == "BL-P002")) { + json j; + j["print"]["command"] = "flowrate_get_result"; + j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++); + + return this->publish_json(j.dump()); + } + return -1; +} + int MachineObject::command_unload_filament() { if ((printer_type == "BL-P001" || printer_type == "BL-P002") @@ -3669,6 +3789,74 @@ int MachineObject::parse_json(std::string payload) extrusion_cali_set_tray_id = curr_tray_id; extrusion_cali_set_hold_start = std::chrono::system_clock::now(); } + else if (jj["command"].get() == "extrusion_cali_get") { + if (jj["filaments"].is_array()) { + try { + pa_calib_tab.clear(); + for (auto it = jj["filaments"].begin(); it != jj["filaments"].end(); it++) { + PACalibResult pa_calib_result; + pa_calib_result.filament_id = (*it)["filament_id"].get(); + pa_calib_result.setting_id = (*it)["setting_id"].get(); + pa_calib_result.name = (*it)["name"].get(); + + if ((*it)["k_value"].is_number_float()) + pa_calib_result.k_value = (*it)["k_value"].get(); + else if ((*it)["k_value"].is_string()) + pa_calib_result.k_value = stof((*it)["k_value"].get().c_str()); + + if ((*it)["n_coef"].is_number_float()) + pa_calib_result.n_coef = (*it)["n_coef"].get(); + else if ((*it)["n_coef"].is_string()) + pa_calib_result.n_coef = stof((*it)["n_coef"].get().c_str()); + + pa_calib_tab.push_back(pa_calib_result); + } + } + catch (...) { + + } + } + } + else if (jj["command"].get() == "extrusion_cali_get_result") { + if (jj["filaments"].is_array()) { + try { + pa_calib_results.clear(); + for (auto it = jj["filaments"].begin(); it != jj["filaments"].end(); it++) { + PACalibResult pa_calib_result; + pa_calib_result.tray_id = (*it)["tray_id"].get(); + pa_calib_result.filament_id = (*it)["filament_id"].get(); + pa_calib_result.setting_id = (*it)["setting_id"].get(); + if ((*it)["k_value"].is_number_float()) + pa_calib_result.k_value = (*it)["k_value"].get(); + else if ((*it)["k_value"].is_string()) + pa_calib_result.k_value = stof((*it)["k_value"].get().c_str()); + + if ((*it)["n_coef"].is_number_float()) + pa_calib_result.n_coef = (*it)["n_coef"].get(); + else if ((*it)["n_coef"].is_string()) + pa_calib_result.n_coef = stof((*it)["n_coef"].get().c_str()); + + pa_calib_results.push_back(pa_calib_result); + } + } catch (...) {} + } + } + else if (jj["command"].get() == "flowrate_get_result") { + if (jj["filaments"].is_array()) { + try { + flow_ratio_results.clear(); + for (auto it = jj["filaments"].begin(); it != jj["filaments"].end(); it++) { + FlowRatioCalibResult flow_ratio_calib_result; + flow_ratio_calib_result.tray_id = (*it)["tray_id"].get(); + flow_ratio_calib_result.filament_id = (*it)["filament_id"].get(); + flow_ratio_calib_result.setting_id = (*it)["setting_id"].get(); + flow_ratio_calib_result.flow_ratio = stof((*it)["flow_ratio"].get().c_str()); + + flow_ratio_results.push_back(flow_ratio_calib_result); + } + } catch (...) {} + } + } } } diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index 241a824461..77ca11c82e 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -308,6 +308,41 @@ public: static wxString get_hms_msg_level_str(HMSMessageLevel level); }; +class CalibDatas +{ +public: + struct CalibData + { + int tray_id; + int bed_temp; + int nozzle_temp; + std::string filament_id; + std::string setting_id; + float max_volumetric_speed; + }; + + std::vector calib_datas; +}; + +class PACalibResult +{ +public: + int tray_id; + std::string filament_id; + std::string setting_id; + std::string name; + float k_value; + float n_coef; +}; + +class FlowRatioCalibResult +{ +public: + int tray_id; + std::string filament_id; + std::string setting_id; + float flow_ratio; +}; #define UpgradeNoError 0 #define UpgradeDownloadFailed -1 @@ -608,6 +643,10 @@ public: int total_layers = 0; bool is_support_layer_num { false }; + std::vector pa_calib_tab; + std::vector pa_calib_results; + std::vector flow_ratio_results; + std::vector stage_list_info; int stage_curr = 0; int m_push_count = 0; @@ -766,6 +805,17 @@ public: bool is_support_command_calibration(); int command_start_calibration(bool vibration, bool bed_leveling, bool xcam_cali); + // PA calibration + int command_start_pa_calibration(const CalibDatas& pa_data); + int command_set_pa_calibration(const std::vector& pa_calib_values); + int command_delete_pa_calibration(const PACalibResult& pa_calib); + int command_get_pa_calibration_infos(const std::string& filament_id = ""); + int command_get_pa_calibration_result(); + + // flow ratio calibration + int command_start_flow_ratio_calibration(const CalibDatas& calib_data); + int command_get_flow_ratio_calibration_result(); + int command_unload_filament(); // camera control diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index ecc4356b38..830e373bfc 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1967,7 +1967,7 @@ void GUI_App::init_networking_callbacks() auto sel = this->m_device_manager->get_selected_machine(); if ((sel == obj || sel == nullptr) && obj->is_ams_need_update) { - GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj->amsList); + GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj); } } }); @@ -1991,7 +1991,7 @@ void GUI_App::init_networking_callbacks() if (obj) { obj->parse_json(msg); if (this->m_device_manager->get_selected_machine() == obj && obj->is_ams_need_update) { - GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj->amsList); + GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj); } } }); diff --git a/src/slic3r/GUI/Jobs/PrintJob.cpp b/src/slic3r/GUI/Jobs/PrintJob.cpp index 1149331cda..83a47ec0c6 100644 --- a/src/slic3r/GUI/Jobs/PrintJob.cpp +++ b/src/slic3r/GUI/Jobs/PrintJob.cpp @@ -5,6 +5,7 @@ #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI_App.hpp" +#include "slic3r/GUI/MainFrame.hpp" #include "bambu_networking.hpp" namespace Slic3r { @@ -461,6 +462,12 @@ void PrintJob::process() } else { BOOST_LOG_TRIVIAL(error) << "print_job: send ok."; wxCommandEvent* evt = new wxCommandEvent(m_print_job_completed_id); + if (m_print_job_completed_id == wxGetApp().plater()->get_send_calibration_finished_event()) { + int sel = wxGetApp().mainframe->get_calibration_curr_tab(); + if (sel >= 0) { + evt->SetInt(sel); + } + } evt->SetString(m_dev_id); wxQueueEvent(m_plater, evt); m_job_finished = true; diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 745f0cbc9e..cbb00f57ec 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -2998,6 +2998,12 @@ void MainFrame::request_select_tab(TabPosition pos) wxQueueEvent(this, evt); } +int MainFrame::get_calibration_curr_tab() { + if (m_calibration) + return m_calibration->get_tabpanel()->GetSelection(); + return -1; +} + // Set a camera direction, zoom to all objects. void MainFrame::select_view(const std::string& direction) { diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 7247c6da1d..e96ec85234 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -306,6 +306,7 @@ public: void select_tab(wxPanel* panel); void select_tab(size_t tab = size_t(-1)); void request_select_tab(TabPosition pos); + int get_calibration_curr_tab(); void select_view(const std::string& direction); // Propagate changed configuration from the Tab to the Plater and save changes to the AppConfig void on_config_changed(DynamicPrintConfig* cfg) const ; diff --git a/src/slic3r/GUI/Monitor.cpp b/src/slic3r/GUI/Monitor.cpp index 6ba0133c2c..3096afb87b 100644 --- a/src/slic3r/GUI/Monitor.cpp +++ b/src/slic3r/GUI/Monitor.cpp @@ -153,7 +153,7 @@ MonitorPanel::~MonitorPanel() if (!dev) return; MachineObject *obj_ = dev->get_selected_machine(); if (obj_) - GUI::wxGetApp().sidebar().load_ams_list(obj_->dev_id, obj_->amsList); + GUI::wxGetApp().sidebar().load_ams_list(obj_->dev_id, obj_); } void MonitorPanel::init_tabpanel() @@ -315,7 +315,7 @@ void MonitorPanel::on_update_all(wxMouseEvent &event) MachineObject *obj_ = dev->get_selected_machine(); if (obj_) - GUI::wxGetApp().sidebar().load_ams_list(obj_->dev_id, obj_->amsList); + GUI::wxGetApp().sidebar().load_ams_list(obj_->dev_id, obj_); Layout(); Refresh(); @@ -459,9 +459,6 @@ void MonitorPanel::update_all() m_hms_panel->update(obj); } - auto cali_panel = static_cast(wxGetApp().mainframe->m_calibration); - if(cali_panel) - cali_panel->update_obj(obj); #if !BBL_RELEASE_TO_PUBLIC if (m_upgrade_panel->IsShown()) { m_upgrade_panel->update(obj); @@ -490,7 +487,7 @@ bool MonitorPanel::Show(bool show) dev->load_last_machine(); obj = dev->get_selected_machine(); if (obj) - GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj->amsList); + GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj); } else { obj->reset_update_time(); } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 5e945e2144..08784b52a5 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1368,21 +1368,47 @@ void Sidebar::on_bed_type_change(BedType bed_type) m_bed_type_list->SetSelection(sel_idx); } -void Sidebar::load_ams_list(std::string const &device, std::map const &list) +void Sidebar::load_ams_list(std::string const &device, MachineObject* obj) { - std::vector filament_ams_list; + std::map filament_ams_list; + + if (!obj) { + p->ams_list_device = device; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1% items") % filament_ams_list.size(); + wxGetApp().preset_bundle->filament_ams_list = filament_ams_list; + for (auto c : p->combos_filament) + c->update(); + return; + } + + auto vt_tray = obj->vt_tray; + bool is_support_virtual_tray = obj->is_function_supported(PrinterFunction::FUNC_VIRTUAL_TYAY); + if (is_support_virtual_tray) { + DynamicPrintConfig vt_tray_config; + vt_tray_config.set_key_value("filament_id", new ConfigOptionStrings{ vt_tray.setting_id }); + vt_tray_config.set_key_value("filament_type", new ConfigOptionStrings{ vt_tray.type }); + vt_tray_config.set_key_value("tray_name", new ConfigOptionStrings{ std::string("Ext")}); + vt_tray_config.set_key_value("filament_colour", new ConfigOptionStrings{ "#" + vt_tray.color.substr(0, 8) }); + vt_tray_config.set_key_value("filament_exist", new ConfigOptionBools{ vt_tray.is_exists }); + + filament_ams_list.emplace(VIRTUAL_TRAY_ID, std::move(vt_tray_config)); + } + + auto list = obj->amsList; for (auto ams : list) { char n = ams.first.front() - '0' + 'A'; for (auto tray : ams.second->trayList) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": ams %1% tray %2% id %3% color %4%") % ams.first % tray.first % tray.second->setting_id % tray.second->color; char t = tray.first.front() - '0' + '1'; - DynamicPrintConfig ams; - ams.set_key_value("filament_id", new ConfigOptionStrings{tray.second->setting_id}); - ams.set_key_value("filament_type", new ConfigOptionStrings{tray.second->type}); - ams.set_key_value("tray_name", new ConfigOptionStrings{std::string(1, n) + std::string(1, t)}); - ams.set_key_value("filament_colour", new ConfigOptionStrings{"#" + tray.second->color.substr(0, 8)}); - filament_ams_list.emplace_back(std::move(ams)); + DynamicPrintConfig tray_config; + tray_config.set_key_value("filament_id", new ConfigOptionStrings{tray.second->setting_id}); + tray_config.set_key_value("filament_type", new ConfigOptionStrings{tray.second->type}); + tray_config.set_key_value("tray_name", new ConfigOptionStrings{std::string(1, n) + std::string(1, t)}); + tray_config.set_key_value("filament_colour", new ConfigOptionStrings{ "#" + tray.second->color.substr(0, 8) }); + tray_config.set_key_value("filament_exist", new ConfigOptionBools{ tray.second->is_exists }); + + filament_ams_list.emplace(((n - 'A') * 4 + t - '1'), std::move(tray_config)); } } p->ams_list_device = device; @@ -1425,9 +1451,11 @@ void Sidebar::sync_ams_list() auto res = dlg.ShowModal(); if (res == wxID_CANCEL) return; list2.resize(list.size()); - for (int i = 0; i < list.size(); ++i) { - auto filament_id = list[i].opt_string("filament_id", 0u); - list[i].set_key_value("filament_changed", new ConfigOptionBool{res == wxID_YES || list2[i] != filament_id}); + auto iter = list.begin(); + for (int i = 0; i < list.size(); ++i, ++iter) { + auto & ams = iter->second; + auto filament_id = ams.opt_string("filament_id", 0u); + ams.set_key_value("filament_changed", new ConfigOptionBool{res == wxID_YES || list2[i] != filament_id}); list2[i] = filament_id; } unsigned int unknowns = 0; @@ -10294,18 +10322,12 @@ int Plater::export_config_3mf(int plate_idx, Export3mfProgressFn proFn) //BBS void Plater::send_calibration_job_finished(wxCommandEvent & evt) { - Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); - if (!dev) return; - dev->set_selected_machine(evt.GetString().ToStdString()); - - p->hide_select_machine_dlg(); p->main_frame->request_select_tab(MainFrame::TabPosition::tpCalibration); - //jump to monitor and select device status panel - auto curr_calibration = p->main_frame->m_calibration; - if (curr_calibration) { - // todo select current tab - auto calibration_wizard = static_cast(curr_calibration->get_tabpanel()->GetPage(curr_calibration->get_tabpanel()->GetSelection())); - calibration_wizard->show_page(calibration_wizard->get_curr_page()->get_next_page()); + auto calibration_panel = p->main_frame->m_calibration; + if (calibration_panel) { + auto curr_wizard = static_cast(calibration_panel->get_tabpanel()->GetPage(evt.GetInt())); + curr_wizard->show_send_progress_bar(false); + curr_wizard->show_page(curr_wizard->get_curr_page()->get_next_page()); } } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 9ba568ba05..282a5937cc 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -125,7 +125,7 @@ public: void on_filaments_change(size_t num_filaments); // BBS void on_bed_type_change(BedType bed_type); - void load_ams_list(std::string const & device, std::map const &list); + void load_ams_list(std::string const & device, MachineObject* obj); void sync_ams_list(); ObjectList* obj_list(); diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 8a1ecd4782..9af10a1c26 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -231,11 +231,12 @@ int PresetComboBox::update_ams_color() if (color.empty()) return -1; } else { auto &ams_list = wxGetApp().preset_bundle->filament_ams_list; - if (idx >= ams_list.size()) { + auto iter = ams_list.find(idx); + if (iter == ams_list.end()) { BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": ams %1% out of range %2%") % idx % ams_list.size(); return -1; } - color = ams_list[idx].opt_string("filament_colour", 0u); + color = iter->second.opt_string("filament_colour", 0u); } DynamicPrintConfig *cfg = &wxGetApp().preset_bundle->project_config; auto colors = static_cast(cfg->option("filament_colour")->clone()); @@ -374,13 +375,14 @@ void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name) set_label_marker(Append(separator(L("AMS filaments")), wxNullBitmap)); m_first_ams_filament = GetCount(); auto &filaments = m_collection->get_presets(); - for (auto &f : m_preset_bundle->filament_ams_list) { - std::string filament_id = f.opt_string("filament_id", 0u); + for (auto &entry : m_preset_bundle->filament_ams_list) { + auto & tray = entry.second; + std::string filament_id = tray.opt_string("filament_id", 0u); if (filament_id.empty()) continue; auto iter = std::find_if(filaments.begin(), filaments.end(), [&filament_id](auto &f) { return f.is_compatible && f.is_system && f.filament_id == filament_id; }); if (iter == filaments.end()) { - auto filament_type = "Generic " + f.opt_string("filament_type", 0u); + auto filament_type = "Generic " + tray.opt_string("filament_type", 0u); iter = std::find_if(filaments.begin(), filaments.end(), [&filament_type](auto &f) { return f.is_compatible && f.is_system && boost::algorithm::starts_with(f.name, filament_type); }); } @@ -389,10 +391,10 @@ void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name) continue; } const_cast(*iter).is_visible = true; - auto color = f.opt_string("filament_colour", 0u); - auto name = f.opt_string("tray_name", 0u); + auto color = tray.opt_string("filament_colour", 0u); + auto name = tray.opt_string("tray_name", 0u); wxBitmap bmp(*get_extruder_color_icon(color, name, 24, 16)); - int item_id = Append(get_preset_name(*iter), bmp.ConvertToImage(), &m_first_ams_filament + (&f - &m_preset_bundle->filament_ams_list.front())); + int item_id = Append(get_preset_name(*iter), bmp.ConvertToImage(), &m_first_ams_filament + entry.first); //validate_selection(id->value == selected); // can not select } m_last_ams_filament = GetCount(); @@ -623,7 +625,7 @@ bool PresetComboBox::selection_is_changed_according_to_physical_printers() // --------------------------------- PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset_type) : - PresetComboBox(parent, preset_type, wxSize(15 * wxGetApp().em_unit(), 30 * wxGetApp().em_unit() / 10)) + PresetComboBox(parent, preset_type, wxSize(25 * wxGetApp().em_unit(), 30 * wxGetApp().em_unit() / 10)) { GetDropDown().SetUseContentWidth(true); @@ -1012,7 +1014,7 @@ void PlaterPresetComboBox::update() } if (m_type == Preset::TYPE_FILAMENT) - add_ams_filaments(into_u8(selected_user_preset), true); + add_ams_filaments(into_u8(selected_user_preset.empty() ? selected_system_preset : selected_user_preset), true); //BBS: add project embedded preset logic if (!project_embedded_presets.empty()) @@ -1373,4 +1375,142 @@ void TabPresetComboBox::update_dirty() #endif /* __APPLE __ */ } -}} // namespace Slic3r::GUI +} // namespace GUI +GUI::CalibrateFilamentComboBox::CalibrateFilamentComboBox(wxWindow *parent) +: PlaterPresetComboBox(parent, Preset::TYPE_FILAMENT) +{ + clr_picker->SetBackgroundColour(*wxWHITE); + clr_picker->SetBitmap(*get_extruder_color_icon("#FFFFFFFF", "", 16, 16)); + clr_picker->SetToolTip(""); + clr_picker->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) {}); +} + +GUI::CalibrateFilamentComboBox::~CalibrateFilamentComboBox() +{ +} + +void GUI::CalibrateFilamentComboBox::load_tray(DynamicPrintConfig &config) +{ + m_tray_name = config.opt_string("tray_name", 0u); + m_filament_id = config.opt_string("filament_id", 0u); + m_filament_type = config.opt_string("filament_type", 0u); + m_filament_color = config.opt_string("filament_colour", 0u); + m_filament_exist = config.opt_bool("filament_exist", 0u); + wxColor clr(m_filament_color); + clr_picker->SetBitmap(*get_extruder_color_icon(m_filament_color, m_tray_name, 16, 16)); +#ifdef __WXOSX__ + clr_picker->SetLabel(clr_picker->GetLabel()); // Let setBezelStyle: be called + clr_picker->Refresh(); +#endif + if (!m_filament_exist) { + SetValue(_L("Empty")); + clr_picker->SetBitmap(*get_extruder_color_icon("#F0F0F0FF", m_tray_name, 16, 16)); + } else { + auto &filaments = m_collection->get_presets(); + auto iter = std::find_if(filaments.begin(), filaments.end(), [this](auto &f) { return f.is_compatible && f.is_system && f.filament_id == m_filament_id; }); + if (iter == filaments.end() && !m_filament_type.empty()) { + auto filament_type = "Generic " + m_filament_type; + iter = std::find_if(filaments.begin(), filaments.end(), + [&filament_type](auto &f) { return f.is_compatible && f.is_system && boost::algorithm::starts_with(f.name, filament_type); }); + } + if (iter != filaments.end()) { + m_selected_preset = &*iter; + SetValue(get_preset_name(*iter)); + } + else + SetValue(_L("Incompatible")); + Enable(); + } +} + +void GUI::CalibrateFilamentComboBox::update() +{ + if (m_preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA) + return; + + // Otherwise fill in the list from scratch. + this->Freeze(); + this->Clear(); + invalidate_selection(); + + const Preset* selected_filament_preset = nullptr; + + std::map nonsys_presets; + std::map project_embedded_presets; + std::map system_presets; + + wxString selected_preset = m_selected_preset ? get_preset_name(*m_selected_preset) : GetValue(); + if (!m_selected_preset) + m_selected_preset = m_collection->find_preset(selected_preset.ToStdString()); + wxString tooltip; + const std::deque& presets = m_collection->get_presets(); + + for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i) + { + const Preset& preset = presets[i]; + auto name = get_preset_name(preset); + bool is_selected = m_selected_preset == &preset; + if (m_preset_bundle->calibrate_filaments.empty()) { + Thaw(); + return; + } + bool is_compatible = m_preset_bundle->calibrate_filaments.find(&preset) != m_preset_bundle->calibrate_filaments.end(); + ; + if (!preset.is_visible || (!is_compatible && !is_selected)) + continue; + + if (is_selected) { + tooltip = get_tooltip(preset); + } + + wxBitmap* bmp = get_bmp(preset); + assert(bmp); + + if (preset.is_default || preset.is_system) + system_presets.emplace(name, bmp); + else if (preset.is_project_embedded) + project_embedded_presets.emplace(name, bmp); + else + nonsys_presets.emplace(name, bmp); + } + + if (!nonsys_presets.empty()) + { + set_label_marker(Append(separator(L("User presets")), wxNullBitmap)); + for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { + Append(it->first, *it->second); + validate_selection(it->first == selected_preset); + } + } + if (!system_presets.empty()) + { + set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); + for (std::map::iterator it = system_presets.begin(); it != system_presets.end(); ++it) { + Append(it->first, *it->second); + validate_selection(it->first == selected_preset); + } + } + + update_selection(); + Thaw(); + + if (!tooltip.IsEmpty()) { +#ifdef __WXMSW__ + SetToolTip(NULL); +#endif + SetToolTip(tooltip); + } +} + +void GUI::CalibrateFilamentComboBox::OnSelect(wxCommandEvent &evt) +{ + std::string preset_name = m_collection->get_preset_name_by_alias(evt.GetString().ToUTF8().data()); + m_selected_preset = m_collection->find_preset(preset_name); + SimpleEvent e(EVT_CALIBRATION_TRAY_SELECTION_CHANGED); + auto cali_tab = wxGetApp().mainframe->m_calibration->get_tabpanel(); + auto calibration_wizard = static_cast(cali_tab->GetPage(cali_tab->GetSelection())); + e.SetEventObject(calibration_wizard); + wxPostEvent(calibration_wizard, e); +} + +} // namespace Slic3r diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 67aab0d65f..00a54813f8 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -214,6 +214,32 @@ public: Preset::Type type() const { return m_type; } }; +// --------------------------------- +// *** CalibrateFilamentComboBox *** +// --------------------------------- + +class CalibrateFilamentComboBox : public PlaterPresetComboBox +{ +public: + CalibrateFilamentComboBox(wxWindow *parent); + ~CalibrateFilamentComboBox(); + + void load_tray(DynamicPrintConfig & config); + + void update() override; + void OnSelect(wxCommandEvent &evt) override; + const Preset* get_selected_preset() { return m_selected_preset; } + bool is_tray_exist() { return m_filament_exist; } + +private: + std::string m_tray_name; + std::string m_filament_id; + std::string m_filament_type; + std::string m_filament_color; + bool m_filament_exist{false}; + const Preset* m_selected_preset = nullptr; +}; + } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index 358af6bc58..879b244fe5 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -2925,7 +2925,7 @@ void SelectMachineDialog::on_selection_changed(wxCommandEvent &event) obj->command_request_push_all(); dev->set_selected_machine(m_printer_last_select, true); // Has changed machine unrecoverably - GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj->amsList); + GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj); update_select_layout(obj); } else { BOOST_LOG_TRIVIAL(error) << "on_selection_changed dev_id not found"; diff --git a/src/slic3r/Utils/CalibUtils.cpp b/src/slic3r/Utils/CalibUtils.cpp index a22f42c9a3..7224aedb38 100644 --- a/src/slic3r/Utils/CalibUtils.cpp +++ b/src/slic3r/Utils/CalibUtils.cpp @@ -15,10 +15,17 @@ namespace Slic3r { namespace GUI { std::shared_ptr print_job; -static const std::string temp_dir = "D:/temp/"; -static const std::string temp_gcode_path = temp_dir + "temp.gcode"; -static const std::string path = temp_dir + "test.3mf"; -static const std::string config_3mf_path = temp_dir + "test_config.3mf"; +static const std::string temp_dir = fs::path(fs::temp_directory_path() / "calib").string(); +static const std::string temp_gcode_path = temp_dir + "/temp.gcode"; +static const std::string path = temp_dir + "/test.3mf"; +static const std::string config_3mf_path = temp_dir + "/test_config.3mf"; + +static std::string MachineBedTypeString[BED_TYPE_COUNT] = { + //"auto", + "pc", + "pei", + "pe", +}; static void cut_model(Model &model, std::array plane_points, ModelObjectCutAttributes attributes) { @@ -60,7 +67,140 @@ static void read_model_from_file(const std::string& input_file, Model& model) object->ensure_on_bed(); } -void CalibUtils::calib_flowrate(int pass, std::string dev_id, std::string select_ams, std::shared_ptr process_bar) +void CalibUtils::calib_PA(const X1CCalibInfos& calib_infos, std::string& error_message) +{ + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) + return; + + MachineObject *obj_ = dev->get_selected_machine(); + if (obj_ == nullptr) + return; + + CalibDatas pa_datas; + for (auto calib_info : calib_infos.calib_infos) { + CalibDatas::CalibData pa_calib; + pa_calib.tray_id = calib_info.tray_id; + pa_calib.setting_id = calib_info.setting_id; + pa_calib.bed_temp = calib_info.bed_temp; + pa_calib.nozzle_temp = calib_info.nozzle_temp; + pa_calib.max_volumetric_speed = calib_info.max_volumetric_speed; + + pa_datas.calib_datas.push_back(pa_calib); + } + + if (pa_datas.calib_datas.size() > 0) + obj_->command_start_pa_calibration(pa_datas); +} + +void CalibUtils::emit_get_PA_calib_results() +{ + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) + return; + + MachineObject *obj_ = dev->get_selected_machine(); + if (obj_ == nullptr) + return; + + obj_->command_get_pa_calibration_result(); +} + +bool CalibUtils::get_PA_calib_results(std::vector& pa_calib_results) +{ + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) + return false; + + MachineObject *obj_ = dev->get_selected_machine(); + if (obj_ == nullptr) + return false; + + pa_calib_results = obj_->pa_calib_results; + return pa_calib_results.size() > 0; +} + +void CalibUtils::emit_get_PA_calib_infos() +{ + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) + return; + + MachineObject *obj_ = dev->get_selected_machine(); + if (obj_ == nullptr) + return; + + obj_->command_get_pa_calibration_infos(); +} + +bool CalibUtils::get_PA_calib_tab(std::vector &pa_calib_infos) +{ + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) + return false; + + MachineObject *obj_ = dev->get_selected_machine(); + if (obj_ == nullptr) + return false; + + pa_calib_infos = obj_->pa_calib_tab; + return pa_calib_infos.size() > 0; +} + +void CalibUtils::calib_flowrate_X1C(const X1CCalibInfos& calib_infos, std::string& error_message) +{ + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) + return; + + MachineObject *obj_ = dev->get_selected_machine(); + if (obj_ == nullptr) + return; + + CalibDatas calib_datas; + for (auto calib_info : calib_infos.calib_infos) { + CalibDatas::CalibData pa_calib; + pa_calib.tray_id = calib_info.tray_id; + pa_calib.setting_id = calib_info.setting_id; + pa_calib.bed_temp = calib_info.bed_temp; + pa_calib.nozzle_temp = calib_info.nozzle_temp; + pa_calib.max_volumetric_speed = calib_info.max_volumetric_speed; + + calib_datas.calib_datas.push_back(pa_calib); + } + + if (calib_datas.calib_datas.size() > 0) + obj_->command_start_flow_ratio_calibration(calib_datas); +} + +void CalibUtils::emit_get_flow_ratio_calib_results() +{ + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) + return; + + MachineObject *obj_ = dev->get_selected_machine(); + if (obj_ == nullptr) + return; + + obj_->command_get_flow_ratio_calibration_result(); +} + +bool CalibUtils::get_flow_ratio_calib_results(std::vector& flow_ratio_calib_results) +{ + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) + return false; + + MachineObject *obj_ = dev->get_selected_machine(); + if (obj_ == nullptr) + return false; + + flow_ratio_calib_results = obj_->flow_ratio_results; + return flow_ratio_calib_results.size() > 0; +} + +void CalibUtils::calib_flowrate(int pass, const CalibInfo& calib_info, std::string& error_message) { if (pass != 1 && pass != 2) return; @@ -74,9 +214,9 @@ void CalibUtils::calib_flowrate(int pass, std::string dev_id, std::string select read_model_from_file(input_file, model); - DynamicConfig print_config = wxGetApp().preset_bundle->prints.get_edited_preset().config; - DynamicConfig printer_config = wxGetApp().preset_bundle->printers.get_edited_preset().config; - DynamicConfig filament_config = wxGetApp().preset_bundle->filaments.get_edited_preset().config; + DynamicConfig print_config = calib_info.print_prest->config; + DynamicConfig filament_config = calib_info.filament_prest->config; + DynamicConfig printer_config = calib_info.printer_prest->config; /// --- scale --- // model is created for a 0.4 nozzle, scale z with nozzle size. @@ -144,13 +284,17 @@ void CalibUtils::calib_flowrate(int pass, std::string dev_id, std::string select full_config.apply(printer_config); Calib_Params params; - params.mode = CalibMode::Calib_None; - process_and_store_3mf(&model, full_config, params); + params.mode = CalibMode::Calib_Flow_Rate; + process_and_store_3mf(&model, full_config, params, error_message); + if (!error_message.empty()) + return - send_to_print(dev_id, select_ams, process_bar); + send_to_print(calib_info.dev_id, calib_info.select_ams, calib_info.process_bar, calib_info.bed_type, error_message); } -void CalibUtils::calib_temptue(const Calib_Params& params, std::string dev_id, std::string select_ams, std::shared_ptr process_bar) { +void CalibUtils::calib_temptue(const CalibInfo& calib_info, std::string& error_message) +{ + const Calib_Params ¶ms = calib_info.params; if (params.mode != CalibMode::Calib_Temp_Tower) return; @@ -190,10 +334,9 @@ void CalibUtils::calib_temptue(const Calib_Params& params, std::string dev_id, s } // edit preset - PresetBundle * preset_bundle = wxGetApp().preset_bundle; - DynamicPrintConfig print_config = preset_bundle->prints.get_edited_preset().config; - DynamicPrintConfig filament_config = preset_bundle->filaments.get_edited_preset().config; - DynamicPrintConfig printer_config = preset_bundle->printers.get_edited_preset().config; + DynamicPrintConfig print_config = calib_info.print_prest->config; + DynamicPrintConfig filament_config = calib_info.filament_prest->config; + DynamicPrintConfig printer_config = calib_info.printer_prest->config; auto start_temp = lround(params.start); filament_config.set_key_value("nozzle_temperature_initial_layer", new ConfigOptionInts(1, (int) start_temp)); @@ -210,13 +353,16 @@ void CalibUtils::calib_temptue(const Calib_Params& params, std::string dev_id, s full_config.apply(filament_config); full_config.apply(printer_config); - process_and_store_3mf(&model, full_config, params); + process_and_store_3mf(&model, full_config, params, error_message); + if (!error_message.empty()) + return; - send_to_print(dev_id, select_ams, process_bar); + send_to_print(calib_info.dev_id, calib_info.select_ams, calib_info.process_bar, calib_info.bed_type, error_message); } -void CalibUtils::calib_max_vol_speed(const Calib_Params ¶ms, std::string dev_id, std::string select_ams, std::shared_ptr process_bar) +void CalibUtils::calib_max_vol_speed(const CalibInfo& calib_info, std::string& error_message) { + const Calib_Params ¶ms = calib_info.params; if (params.mode != CalibMode::Calib_Vol_speed_Tower) return; @@ -224,14 +370,11 @@ void CalibUtils::calib_max_vol_speed(const Calib_Params ¶ms, std::string dev std::string input_file = Slic3r::resources_dir() + "/calib/volumetric_speed/SpeedTestStructure.step"; read_model_from_file(input_file, model); - PresetBundle * preset_bundle = wxGetApp().preset_bundle; - DynamicPrintConfig print_config = preset_bundle->prints.get_edited_preset().config; - DynamicPrintConfig filament_config = preset_bundle->filaments.get_edited_preset().config; - DynamicPrintConfig printer_config = preset_bundle->printers.get_edited_preset().config; - + DynamicPrintConfig print_config = calib_info.print_prest->config; + DynamicPrintConfig filament_config = calib_info.filament_prest->config; + DynamicPrintConfig printer_config = calib_info.printer_prest->config; auto obj = model.objects[0]; - auto bed_shape = printer_config.option("printable_area")->values; BoundingBoxf bed_ext = get_extents(bed_shape); auto scale_obj = (bed_ext.size().x() - 10) / obj->bounding_box().size().x(); @@ -266,7 +409,7 @@ void CalibUtils::calib_max_vol_speed(const Calib_Params ¶ms, std::string dev // cut upper auto obj_bb = obj->bounding_box(); - auto height = (params.end - params.start + 1) / params.step; + double height = (params.end - params.start + 1) / params.step; if (height < obj_bb.size().z()) { std::array plane_pts; plane_pts[0] = Vec3d(obj_bb.min(0), obj_bb.min(1), height); @@ -288,13 +431,16 @@ void CalibUtils::calib_max_vol_speed(const Calib_Params ¶ms, std::string dev full_config.apply(filament_config); full_config.apply(printer_config); - process_and_store_3mf(&model, full_config, new_params); + process_and_store_3mf(&model, full_config, new_params, error_message); + if (!error_message.empty()) + return; - send_to_print(dev_id, select_ams, process_bar); + send_to_print(calib_info.dev_id, calib_info.select_ams, calib_info.process_bar, calib_info.bed_type, error_message); } -void CalibUtils::calib_VFA(const Calib_Params& params) +void CalibUtils::calib_VFA(const CalibInfo& calib_info, std::string& error_message) { + const Calib_Params ¶ms = calib_info.params; if (params.mode != CalibMode::Calib_VFA_Tower) return; @@ -302,10 +448,9 @@ void CalibUtils::calib_VFA(const Calib_Params& params) std::string input_file = Slic3r::resources_dir() + "/calib/vfa/VFA.stl"; read_model_from_file(input_file, model); - PresetBundle * preset_bundle = wxGetApp().preset_bundle; - DynamicPrintConfig print_config = preset_bundle->prints.get_edited_preset().config; - DynamicPrintConfig filament_config = preset_bundle->filaments.get_edited_preset().config; - DynamicPrintConfig printer_config = preset_bundle->printers.get_edited_preset().config; + DynamicPrintConfig print_config = calib_info.print_prest->config; + DynamicPrintConfig filament_config = calib_info.filament_prest->config; + DynamicPrintConfig printer_config = calib_info.printer_prest->config; filament_config.set_key_value("slow_down_layer_time", new ConfigOptionInts{0}); filament_config.set_key_value("filament_max_volumetric_speed", new ConfigOptionFloats{200}); @@ -331,6 +476,10 @@ void CalibUtils::calib_VFA(const Calib_Params& params) plane_pts[3] = Vec3d(obj_bb.min(0), obj_bb.max(1), height); cut_model(model, plane_pts, ModelObjectCutAttribute::KeepLower); } + else { + error_message = "The start, end or step is not valid value."; + return; + } DynamicPrintConfig full_config; full_config.apply(FullPrintConfig::defaults()); @@ -338,15 +487,14 @@ void CalibUtils::calib_VFA(const Calib_Params& params) full_config.apply(filament_config); full_config.apply(printer_config); - process_and_store_3mf(&model, full_config, params); + process_and_store_3mf(&model, full_config, params, error_message); + if (!error_message.empty()) + return; - std::string dev_id = "00M00A252000001"; // to do: hard code test - std::string select_ams = "[0]"; - std::shared_ptr process_bar(new BBLStatusBar(wxGetApp().plater())); - send_to_print(dev_id, select_ams, process_bar); + send_to_print(calib_info.dev_id, calib_info.select_ams, calib_info.process_bar, calib_info.bed_type, error_message); } -void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &full_config, const Calib_Params ¶ms) +void CalibUtils::process_and_store_3mf(Model* model, const DynamicPrintConfig& full_config, const Calib_Params& params, std::string& error_message) { Pointfs bedfs = full_config.opt("printable_area")->values; double print_height = full_config.opt_float("printable_height"); @@ -361,8 +509,7 @@ void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f if (model->objects.size() == 1) { ModelInstance *instance = model->objects[0]->instances[0]; instance->set_offset(instance->get_offset() + Vec3d(current_width / 2, current_depth / 2, 0)); - } - else { + } else { for (auto object : model->objects) { ModelInstance *instance = object->instances[0]; instance->set_offset(instance->get_offset() + Vec3d(100, 100, 0)); @@ -379,6 +526,13 @@ void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f int print_index; part_plate->get_print(&print, &gcode_result, &print_index); + BuildVolume build_volume(bedfs, print_height); + unsigned int count = model->update_print_volume_state(build_volume); + if (count == 0) { + error_message = "Nothing to be sliced, either the print is empty or no object is fully inside the print volume before apply."; + return; + } + // apply the new print config DynamicPrintConfig new_print_config = std::move(full_config); print->apply(*model, new_print_config); @@ -386,6 +540,13 @@ void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f Print *fff_print = dynamic_cast(print); fff_print->set_calib_params(params); + StringObjectException warning; + auto err = print->validate(&warning); + if (!err.string.empty()) { + error_message = "slice validate: " + err.string; + return; + } + fff_print->process(); part_plate->update_slice_result_valid_state(true); @@ -416,15 +577,42 @@ void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f success = Slic3r::store_bbs_3mf(store_params); } -void CalibUtils::send_to_print(const std::string &dev_id, const std::string &select_ams, std::shared_ptr process_bar) +void CalibUtils::send_to_print(const std::string& dev_id, const std::string& select_ams, std::shared_ptr process_bar, BedType bed_type, std::string& error_message) { - DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); - if (!dev) + DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) { + error_message = "Need select printer"; return; + } - MachineObject *obj_ = dev->get_selected_machine(); - if (obj_ == nullptr) + MachineObject* obj_ = dev->get_selected_machine(); + if (obj_ == nullptr) { + error_message = "Need select printer"; return; + } + + if (obj_->is_in_printing()) { + error_message = "Cannot send the print job when the printer is updating firmware"; + return; + } + else if (obj_->is_system_printing()) { + error_message = "The printer is executing instructions. Please restart printing after it ends"; + return; + } + else if (obj_->is_in_printing()) { + error_message = "The printer is busy on other print job"; + return; + } + else if (!obj_->is_function_supported(PrinterFunction::FUNC_PRINT_WITHOUT_SD) && (obj_->get_sdcard_state() == MachineObject::SdcardState::NO_SDCARD)) { + error_message = "An SD card needs to be inserted before printing."; + return; + } + if (obj_->is_lan_mode_printer()) { + if (obj_->get_sdcard_state() == MachineObject::SdcardState::NO_SDCARD) { + error_message = "An SD card needs to be inserted before printing via LAN."; + return; + } + } print_job = std::make_shared(std::move(process_bar), wxGetApp().plater(), dev_id); print_job->m_dev_ip = obj_->dev_ip; @@ -437,33 +625,37 @@ void CalibUtils::send_to_print(const std::string &dev_id, const std::string &sel print_job->set_print_job_finished_event(wxGetApp().plater()->get_send_calibration_finished_event()); PrintPrepareData job_data; - job_data.is_from_plater = false; - job_data.plate_idx = 0; + job_data.is_from_plater = false; + job_data.plate_idx = 0; job_data._3mf_config_path = config_3mf_path; - job_data._3mf_path = path; - job_data._temp_path = temp_dir; + job_data._3mf_path = path; + job_data._temp_path = temp_dir; PlateListData plate_data; - plate_data.is_valid = true; - plate_data.plate_count = 1; + plate_data.is_valid = true; + plate_data.plate_count = 1; plate_data.cur_plate_index = 0; - plate_data.bed_type = BedType::btPC; + plate_data.bed_type = bed_type; - print_job->job_data = job_data; + print_job->job_data = job_data; print_job->plate_data = plate_data; - if (!obj_->is_support_ams_mapping()) + if (!obj_->is_support_ams_mapping()) { + error_message = "It is not support ams mapping."; return; + } - if (!obj_->has_ams()) + if (!obj_->has_ams()) { + error_message = "There is no ams."; return; + } - print_job->task_ams_mapping = select_ams; + print_job->task_ams_mapping = select_ams; print_job->task_ams_mapping_info = ""; - print_job->task_use_ams = true; + print_job->task_use_ams = true; print_job->has_sdcard = obj_->has_sdcard(); - print_job->set_print_config("pc", true, false, false, false, true); + print_job->set_print_config(MachineBedTypeString[bed_type], true, false, false, false, true); print_job->start(); } diff --git a/src/slic3r/Utils/CalibUtils.hpp b/src/slic3r/Utils/CalibUtils.hpp index 50a565cb84..c9abe84b36 100644 --- a/src/slic3r/Utils/CalibUtils.hpp +++ b/src/slic3r/Utils/CalibUtils.hpp @@ -1,24 +1,65 @@ #pragma once #include "libslic3r/Calib.hpp" +#include "../GUI/DeviceManager.hpp" namespace Slic3r { class ProgressIndicator; +class Preset; namespace GUI { +class X1CCalibInfos +{ +public: + struct X1CCalibInfo + { + int tray_id; + std::string setting_id; + int bed_temp; + int nozzle_temp; + float max_volumetric_speed; + }; + + std::vector calib_infos; +}; + +class CalibInfo +{ +public: + Calib_Params params; + Preset* printer_prest; + Preset* filament_prest; + Preset* print_prest; + BedType bed_type; + std::string dev_id; + std::string select_ams; + std::shared_ptr process_bar; +}; + + class CalibUtils { public: CalibUtils(){}; - static void calib_flowrate(int pass, std::string dev_id, std::string select_ams, std::shared_ptr process_bar); - static void calib_temptue(const Calib_Params ¶ms, std::string dev_id, std::string select_ams, std::shared_ptr process_bar); - static void calib_max_vol_speed(const Calib_Params ¶ms, std::string dev_id, std::string select_ams, std::shared_ptr process_bar); - static void calib_VFA(const Calib_Params ¶ms); + static void calib_PA(const X1CCalibInfos& calib_infos, std::string& error_message); + static void emit_get_PA_calib_results(); + static bool get_PA_calib_results(std::vector &pa_calib_results); + static void emit_get_PA_calib_infos(); + static bool get_PA_calib_tab(std::vector &pa_calib_infos); + + static void calib_flowrate_X1C(const X1CCalibInfos& calib_infos, std::string& error_message); + static void emit_get_flow_ratio_calib_results(); + static bool get_flow_ratio_calib_results(std::vector &flow_ratio_calib_results); + static void calib_flowrate(int pass, const CalibInfo& calib_info, std::string& error_message); + + static void calib_temptue(const CalibInfo& calib_info, std::string& error_message); + static void calib_max_vol_speed(const CalibInfo& calib_info, std::string& error_message); + static void calib_VFA(const CalibInfo& calib_info, std::string& error_message); private: - static void process_and_store_3mf(Model *model, const DynamicPrintConfig &full_config, const Calib_Params ¶ms); - static void send_to_print(const std::string &dev_id, const std::string &select_ams, std::shared_ptr process_bar); + static void process_and_store_3mf(Model* model, const DynamicPrintConfig& full_config, const Calib_Params& params, std::string& error_message); + static void send_to_print(const std::string& dev_id, const std::string& select_ams, std::shared_ptr process_bar, BedType bed_type, std::string& error_message); }; }