From 9ee85bef34aaabe7a4cef251f07e77f9af693a2f Mon Sep 17 00:00:00 2001 From: "zhimin.zeng" Date: Fri, 9 Aug 2024 17:46:11 +0800 Subject: [PATCH] FIX: enhance filament_map auto manual behavior 1. auto mode dragdrop is not allowed 2. not display filament_map when there is no result in auto mode jira:none Change-Id: I0800e0d832e27fe459a17bb1aa829b5e72d0ee8f --- src/libslic3r/Print.cpp | 1 + src/libslic3r/Print.hpp | 5 + src/slic3r/GUI/BackgroundSlicingProcess.cpp | 1 + src/slic3r/GUI/DragDropPanel.cpp | 6 +- src/slic3r/GUI/DragDropPanel.hpp | 3 +- src/slic3r/GUI/FilamentMapDialog.cpp | 121 ++++++++++++++++---- src/slic3r/GUI/FilamentMapDialog.hpp | 16 ++- src/slic3r/GUI/PartPlate.cpp | 10 ++ src/slic3r/GUI/PartPlate.hpp | 4 + src/slic3r/GUI/Plater.cpp | 8 +- 10 files changed, 147 insertions(+), 28 deletions(-) diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 993f015bb..f2c339e73 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -2342,6 +2342,7 @@ void Print::update_filament_maps_to_config(std::vector f_maps) t_config_option_keys keys(filament_options_with_variant.begin(), filament_options_with_variant.end()); m_config.apply_only(m_full_print_config, keys, true); } + m_has_auto_filament_map_result = true; } std::vector Print::get_filament_maps() const diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 93358285b..dd72b635a 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -868,6 +868,10 @@ public: void set_calib_params(const Calib_Params ¶ms); const Calib_Params& calib_params() const { return m_calib_params; } Vec2d translate_to_print_space(const Vec2d& point) const; + + bool has_auto_filament_map_result() const { return m_has_auto_filament_map_result; } + void set_auto_filament_map_result(bool has_result) { m_has_auto_filament_map_result = has_result; } + // scaled point Vec2d translate_to_print_space(const Point& point) const; static FilamentTempType get_filament_temp_type(const std::string& filament_type); @@ -940,6 +944,7 @@ private: //BBS ConflictResultOpt m_conflict_result; FakeWipeTower m_fake_wipe_tower; + bool m_has_auto_filament_map_result{false}; // OrcaSlicer: calibration Calib_Params m_calib_params; diff --git a/src/slic3r/GUI/BackgroundSlicingProcess.cpp b/src/slic3r/GUI/BackgroundSlicingProcess.cpp index 4a644350a..b19948b97 100644 --- a/src/slic3r/GUI/BackgroundSlicingProcess.cpp +++ b/src/slic3r/GUI/BackgroundSlicingProcess.cpp @@ -228,6 +228,7 @@ void BackgroundSlicingProcess::process_fff() if (m_current_plate->get_filament_map_mode() == FilamentMapMode::fmmAuto) { std::vector f_maps = m_fff_print->get_filament_maps(); m_current_plate->set_filament_maps(f_maps); + m_current_plate->set_auto_filament_map_result(m_fff_print->has_auto_filament_map_result()); } wxCommandEvent evt(m_event_slicing_completed_id); // Post the Slicing Finished message for the G-code viewer to update. diff --git a/src/slic3r/GUI/DragDropPanel.cpp b/src/slic3r/GUI/DragDropPanel.cpp index 62a93e0ba..6f88affe8 100644 --- a/src/slic3r/GUI/DragDropPanel.cpp +++ b/src/slic3r/GUI/DragDropPanel.cpp @@ -171,8 +171,9 @@ wxDragResult ColorDropTarget::OnData(wxCoord x, wxCoord y, wxDragResult def) /////////////// ColorDropTarget end //////////////////////// -DragDropPanel::DragDropPanel(wxWindow *parent, const wxString &label) +DragDropPanel::DragDropPanel(wxWindow *parent, const wxString &label, bool is_auto) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE) + , m_is_auto(is_auto) { SetBackgroundColour(*wxLIGHT_GREY); @@ -209,6 +210,9 @@ void DragDropPanel::RemoveColorBlock(ColorPanel *panel) void DragDropPanel::DoDragDrop(ColorPanel *panel, const wxColour &color, int filament_id) { + if (m_is_auto) + return; + ColorDropSource source(this, panel, color, filament_id); source.DoDragDrop(wxDrag_CopyOnly); } diff --git a/src/slic3r/GUI/DragDropPanel.hpp b/src/slic3r/GUI/DragDropPanel.hpp index 2965b0b50..573e48708 100644 --- a/src/slic3r/GUI/DragDropPanel.hpp +++ b/src/slic3r/GUI/DragDropPanel.hpp @@ -16,7 +16,7 @@ class ColorPanel; class DragDropPanel : public wxPanel { public: - DragDropPanel(wxWindow *parent, const wxString &label); + DragDropPanel(wxWindow *parent, const wxString &label, bool is_auto); void AddColorBlock(const wxColour &color, int filament_id); void RemoveColorBlock(ColorPanel *panel); @@ -30,6 +30,7 @@ public: private: wxBoxSizer *m_sizer; wxGridSizer *m_grid_item_sizer; + bool m_is_auto; private: bool m_is_draging = false; diff --git a/src/slic3r/GUI/FilamentMapDialog.cpp b/src/slic3r/GUI/FilamentMapDialog.cpp index 2ae37a75d..b03721e00 100644 --- a/src/slic3r/GUI/FilamentMapDialog.cpp +++ b/src/slic3r/GUI/FilamentMapDialog.cpp @@ -45,16 +45,21 @@ FilamentMapDialog::FilamentMapDialog(wxWindow *parent, const DynamicPrintConfig *config, const std::vector &filament_map, const std::vector &extruders, - bool is_auto) + bool is_auto, + bool has_auto_result +) : wxDialog(parent, wxID_ANY, _L("Filament arrangement method of plate"), wxDefaultPosition, wxSize(2000, 1500)) , m_config(config) , m_filament_map(filament_map) + , m_has_auto_result(has_auto_result) { wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL); wxStaticBoxSizer *mode_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _L("Mode")); m_auto_radio = new wxRadioButton(this, wxID_ANY, _L("Auto")); m_manual_radio = new wxRadioButton(this, wxID_ANY, _L("Customize")); + m_auto_radio->Bind(wxEVT_RADIOBUTTON, &FilamentMapDialog::on_auto_radio, this); + m_manual_radio->Bind(wxEVT_RADIOBUTTON, &FilamentMapDialog::on_manual_radio, this); if (is_auto) m_auto_radio->SetValue(true); @@ -68,10 +73,10 @@ FilamentMapDialog::FilamentMapDialog(wxWindow *parent, wxStaticText *tip_text = new wxStaticText(this, wxID_ANY, _L("You could arrange your filament like this, this is the best solution we calculated")); main_sizer->Add(tip_text, 0, wxALIGN_CENTER | wxALL, 5); - wxBoxSizer *panel_sizer = new wxBoxSizer(wxHORIZONTAL); + m_extruder_panel_sizer = new wxBoxSizer(wxHORIZONTAL); - m_left_panel = new DragDropPanel(this, wxT("Left nozzle:")); - m_right_panel = new DragDropPanel(this, wxT("Right nozzle:")); + m_manual_left_panel = new DragDropPanel(this, wxT("Left nozzle:"), false); + m_manual_right_panel = new DragDropPanel(this, wxT("Right nozzle:"), false); std::vector filament_color = config->option("filament_colour")->values; for (size_t i = 0; i < filament_map.size(); ++i) { @@ -80,23 +85,60 @@ FilamentMapDialog::FilamentMapDialog(wxWindow *parent, continue; if (filament_map[i] == 1) { - m_left_panel->AddColorBlock(hex_to_color(filament_color[i]), i + 1); + m_manual_left_panel->AddColorBlock(hex_to_color(filament_color[i]), i + 1); } else if (filament_map[i] == 2) { - m_right_panel->AddColorBlock(hex_to_color(filament_color[i]), i + 1); + m_manual_right_panel->AddColorBlock(hex_to_color(filament_color[i]), i + 1); } else { assert(false); } } - panel_sizer->Add(m_left_panel, 1, wxEXPAND | wxALL, 5); - panel_sizer->Add(m_right_panel, 1, wxEXPAND | wxALL, 5); - m_left_panel->Layout(); - m_left_panel->Fit(); - m_right_panel->Layout(); - m_right_panel->Fit(); - main_sizer->Add(panel_sizer, 1, wxEXPAND | wxALL, 10); + m_extruder_panel_sizer->Add(m_manual_left_panel, 1, wxEXPAND | wxALL, 5); + m_extruder_panel_sizer->Add(m_manual_right_panel, 1, wxEXPAND | wxALL, 5); + m_manual_left_panel->Layout(); + m_manual_left_panel->Fit(); + m_manual_right_panel->Layout(); + m_manual_right_panel->Fit(); + + m_auto_left_panel = new DragDropPanel(this, wxT("Left nozzle:"), true); + m_auto_right_panel = new DragDropPanel(this, wxT("Right nozzle:"), true); + + for (size_t i = 0; i < filament_map.size(); ++i) { + auto iter = std::find(extruders.begin(), extruders.end(), i + 1); + if (iter == extruders.end()) continue; + + if (filament_map[i] == 1) { + m_auto_left_panel->AddColorBlock(hex_to_color(filament_color[i]), i + 1); + } else if (filament_map[i] == 2) { + m_auto_right_panel->AddColorBlock(hex_to_color(filament_color[i]), i + 1); + } else { + assert(false); + } + } + + m_extruder_panel_sizer->Add(m_auto_left_panel, 1, wxEXPAND | wxALL, 5); + m_extruder_panel_sizer->Add(m_auto_right_panel, 1, wxEXPAND | wxALL, 5); + m_auto_left_panel->Layout(); + m_auto_left_panel->Fit(); + m_auto_right_panel->Layout(); + m_auto_right_panel->Fit(); + + main_sizer->Add(m_extruder_panel_sizer, 1, wxEXPAND | wxALL, 10); + + if (is_auto) { + m_manual_left_panel->Hide(); + m_manual_right_panel->Hide(); + if (!m_has_auto_result) { + m_auto_left_panel->Hide(); + m_auto_right_panel->Hide(); + } + } + else { + m_auto_left_panel->Hide(); + m_auto_right_panel->Hide(); + } wxBoxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL); Button * ok_btn = new Button(this, _L("OK")); @@ -125,15 +167,16 @@ bool FilamentMapDialog::is_auto() const void FilamentMapDialog::on_ok(wxCommandEvent &event) { - std::vector left_filaments = m_left_panel->GetAllFilaments(); - std::vector right_filaments = m_right_panel->GetAllFilaments(); + if (!is_auto()) { + std::vector left_filaments = m_manual_left_panel->GetAllFilaments(); + std::vector right_filaments = m_manual_right_panel->GetAllFilaments(); - for (int i = 0; i < m_filament_map.size(); ++i) { - if (std::find(left_filaments.begin(), left_filaments.end(), i + 1) != left_filaments.end()) { - m_filament_map[i] = 1; - } - else if (std::find(right_filaments.begin(), right_filaments.end(), i + 1) != right_filaments.end()) { - m_filament_map[i] = 2; + for (int i = 0; i < m_filament_map.size(); ++i) { + if (std::find(left_filaments.begin(), left_filaments.end(), i + 1) != left_filaments.end()) { + m_filament_map[i] = 1; + } else if (std::find(right_filaments.begin(), right_filaments.end(), i + 1) != right_filaments.end()) { + m_filament_map[i] = 2; + } } } @@ -145,4 +188,40 @@ void FilamentMapDialog::on_cancle(wxCommandEvent &event) EndModal(wxID_CANCEL); } +void FilamentMapDialog::on_auto_radio(wxCommandEvent& event) +{ + if (!m_has_auto_result) { + m_manual_left_panel->Hide(); + m_manual_right_panel->Hide(); + + m_auto_left_panel->Hide(); + m_auto_right_panel->Hide(); + + Layout(); + Fit(); + } + else { + m_auto_left_panel->Show(); + m_auto_right_panel->Show(); + + m_manual_left_panel->Hide(); + m_manual_right_panel->Hide(); + + Layout(); + Fit(); + } +} + +void FilamentMapDialog::on_manual_radio(wxCommandEvent& event) +{ + m_manual_left_panel->Show(); + m_manual_right_panel->Show(); + + m_auto_left_panel->Hide(); + m_auto_right_panel->Hide(); + + Layout(); + Fit(); +} + }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/FilamentMapDialog.hpp b/src/slic3r/GUI/FilamentMapDialog.hpp index e1e5f7e3b..e1860d518 100644 --- a/src/slic3r/GUI/FilamentMapDialog.hpp +++ b/src/slic3r/GUI/FilamentMapDialog.hpp @@ -19,24 +19,32 @@ public: const DynamicPrintConfig *config, const std::vector &filament_map, const std::vector &extruders, - bool is_auto); + bool is_auto, + bool has_auto_result + ); bool is_auto() const; - const std::vector& get_filament_maps() { return m_filament_map; } + const std::vector& get_filament_maps() const { return m_filament_map; } private: void on_ok(wxCommandEvent &event); void on_cancle(wxCommandEvent &event); + void on_auto_radio(wxCommandEvent &event); + void on_manual_radio(wxCommandEvent &event); private: wxRadioButton* m_auto_radio; wxRadioButton* m_manual_radio; - DragDropPanel* m_left_panel; - DragDropPanel* m_right_panel; + wxBoxSizer * m_extruder_panel_sizer; + DragDropPanel* m_manual_left_panel; + DragDropPanel* m_manual_right_panel; + DragDropPanel* m_auto_left_panel; + DragDropPanel* m_auto_right_panel; private: const DynamicPrintConfig* m_config; std::vector m_filament_map; + bool m_has_auto_result; }; }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index fc939f5df..5fdc6b54f 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -2911,6 +2911,16 @@ void PartPlate::set_filament_map_mode(const FilamentMapMode& mode) m_config.option>("filament_map_mode", true)->value = mode; } +bool PartPlate::has_auto_filament_map_reslut() +{ + return m_has_auto_filament_map_result; +} + +void PartPlate::set_auto_filament_map_result(bool has_result) +{ + m_has_auto_filament_map_result = has_result; +} + std::vector PartPlate::get_filament_maps() { std::vector& filament_maps = m_config.option("filament_map", true)->values; diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index 8e2e0c48c..ebdf61b81 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -104,6 +104,7 @@ private: bool m_slice_result_valid; bool m_apply_invalid {false}; float m_slice_percent; + bool m_has_auto_filament_map_result{false}; Print *m_print; //Print reference, not own it, no need to serialize GCodeProcessorResult *m_gcode_result; @@ -479,6 +480,9 @@ public: FilamentMapMode get_filament_map_mode(); void set_filament_map_mode(const FilamentMapMode& mode); + bool has_auto_filament_map_reslut(); + void set_auto_filament_map_result(bool has_result); + std::vector get_filament_maps(); void set_filament_maps(const std::vector& f_maps); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index dbe1dc6b2..635d8fa81 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -14344,11 +14344,17 @@ void Plater::open_platesettings_dialog(wxCommandEvent& evt) { void Plater::open_filament_map_setting_dialog(wxCommandEvent &evt) { PartPlate* curr_plate = p->partplate_list.get_curr_plate(); - FilamentMapDialog filament_dlg(this, config(), curr_plate->get_filament_maps(), curr_plate->get_extruders(true), curr_plate->get_filament_map_mode() == FilamentMapMode::fmmAuto); + FilamentMapDialog filament_dlg(this, config(), curr_plate->get_filament_maps(), curr_plate->get_extruders(true), + curr_plate->get_filament_map_mode() == FilamentMapMode::fmmAuto, curr_plate->has_auto_filament_map_reslut()); if (filament_dlg.ShowModal() == wxID_OK) { std::vector new_filament_maps = filament_dlg.get_filament_maps(); std::vector old_filament_maps = curr_plate->get_filament_maps(); FilamentMapMode new_map_mode = filament_dlg.is_auto() ? FilamentMapMode::fmmAuto : FilamentMapMode::fmmManual; + + if (new_map_mode == FilamentMapMode::fmmManual) { + curr_plate->set_auto_filament_map_result(false); + } + FilamentMapMode old_map_mode = curr_plate->get_filament_map_mode(); bool need_invalidate = false; if (new_map_mode != old_map_mode) {