ENH: modify the UI of filament map dialog

jira: none
Change-Id: I513a518de4509fb7adbc81d9fc3b0fc43fb3244a
This commit is contained in:
zhimin.zeng 2024-09-23 11:38:10 +08:00 committed by lane.wei
parent f68a8aed24
commit 631baa3999
4 changed files with 111 additions and 69 deletions

View File

@ -64,14 +64,8 @@ private:
/////////////// ColorPanel start //////////////////////// /////////////// ColorPanel start ////////////////////////
// The UI panel of drag item // The UI panel of drag item
class ColorPanel : public wxPanel ColorPanel::ColorPanel(DragDropPanel *parent, const wxColour &color, int filament_id)
{ : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(50, 50), wxBORDER_SIMPLE), m_parent(parent), m_color(color), m_filament_id(filament_id)
public:
ColorPanel(DragDropPanel *parent, const wxColour &color, int filament_id)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(50, 50), wxBORDER_SIMPLE)
, m_parent(parent)
, m_color(color)
, m_filament_id(filament_id)
{ {
SetBackgroundColour(color); SetBackgroundColour(color);
Bind(wxEVT_LEFT_DOWN, &ColorPanel::OnLeftDown, this); Bind(wxEVT_LEFT_DOWN, &ColorPanel::OnLeftDown, this);
@ -79,19 +73,6 @@ public:
Bind(wxEVT_PAINT, &ColorPanel::OnPaint, this); Bind(wxEVT_PAINT, &ColorPanel::OnPaint, this);
} }
wxColour GetColor() const { return GetBackgroundColour(); }
int GetFilamentId() const { return m_filament_id; }
private:
void OnLeftDown(wxMouseEvent &event);
void OnLeftUp(wxMouseEvent &event);
void OnPaint(wxPaintEvent &event);
DragDropPanel *m_parent;
wxColor m_color;
int m_filament_id;
};
void ColorPanel::OnLeftDown(wxMouseEvent &event) void ColorPanel::OnLeftDown(wxMouseEvent &event)
{ {
m_parent->set_is_draging(true); m_parent->set_is_draging(true);
@ -198,6 +179,7 @@ void DragDropPanel::AddColorBlock(const wxColour &color, int filament_id)
ColorPanel *panel = new ColorPanel(this, color, filament_id); ColorPanel *panel = new ColorPanel(this, color, filament_id);
panel->SetMinSize(wxSize(50, 50)); panel->SetMinSize(wxSize(50, 50));
m_grid_item_sizer->Add(panel, 0, wxALIGN_CENTER | wxALL, 5); m_grid_item_sizer->Add(panel, 0, wxALIGN_CENTER | wxALL, 5);
m_filament_blocks.push_back(panel);
Layout(); Layout();
} }
@ -205,6 +187,7 @@ void DragDropPanel::RemoveColorBlock(ColorPanel *panel)
{ {
m_sizer->Detach(panel); m_sizer->Detach(panel);
panel->Destroy(); panel->Destroy();
m_filament_blocks.erase(std::remove(m_filament_blocks.begin(), m_filament_blocks.end(), panel), m_filament_blocks.end());
Layout(); Layout();
} }

View File

@ -11,7 +11,6 @@
namespace Slic3r { namespace GUI { namespace Slic3r { namespace GUI {
class ColorPanel; class ColorPanel;
class DragDropPanel : public wxPanel class DragDropPanel : public wxPanel
{ {
@ -27,14 +26,37 @@ public:
void set_is_draging(bool is_draging) { m_is_draging = is_draging; } void set_is_draging(bool is_draging) { m_is_draging = is_draging; }
bool is_draging() const { return m_is_draging; } bool is_draging() const { return m_is_draging; }
std::vector<ColorPanel *> get_filament_blocks() const { return m_filament_blocks; }
private: private:
wxBoxSizer *m_sizer; wxBoxSizer *m_sizer;
wxGridSizer *m_grid_item_sizer; wxGridSizer *m_grid_item_sizer;
bool m_is_auto; bool m_is_auto;
std::vector<ColorPanel *> m_filament_blocks;
private: private:
bool m_is_draging = false; bool m_is_draging = false;
}; };
/////////////// ColorPanel start ////////////////////////
// The UI panel of drag item
class ColorPanel : public wxPanel
{
public:
ColorPanel(DragDropPanel *parent, const wxColour &color, int filament_id);
wxColour GetColor() const { return GetBackgroundColour(); }
int GetFilamentId() const { return m_filament_id; }
private:
void OnLeftDown(wxMouseEvent &event);
void OnLeftUp(wxMouseEvent &event);
void OnPaint(wxPaintEvent &event);
DragDropPanel *m_parent;
wxColor m_color;
int m_filament_id;
};
}} // namespace Slic3r::GUI }} // namespace Slic3r::GUI
#endif /* slic3r_DragDropPanel_hpp_ */ #endif /* slic3r_DragDropPanel_hpp_ */

View File

@ -1,10 +1,23 @@
#include "FilamentMapDialog.hpp" #include "FilamentMapDialog.hpp"
#include "DragDropPanel.hpp" #include "DragDropPanel.hpp"
#include "Widgets/Button.hpp" #include "Widgets/Button.hpp"
#include "Widgets/SwitchButton.hpp"
#include "I18N.hpp" #include "I18N.hpp"
namespace Slic3r { namespace GUI { namespace Slic3r { namespace GUI {
const wxString manual_tips = _L("You can drag the filaments to change which extruder they are assigned to,\n"
"and we will slice according to this grouping method.\n"
"But your filament arrangement may not be the most filament-efficient.");
const wxString auto_tips = _L("Automatic filament grouping will be performed to reduce flushing consumption\n"
"and filament changes during the slicing process.\n"
"The recommended results will be displayed below after slicing:");
const wxString auto_tips_with_result = _L("Automatic filament grouping will be performed to reduce flushing consumption\n"
"and filament changes during the slicing process.\n"
"The recommended results are shown below:");
wxColour hex_to_color(const std::string &hex) wxColour hex_to_color(const std::string &hex)
{ {
if ((hex.length() != 7 && hex.length() != 9) || hex[0] != '#') { if ((hex.length() != 7 && hex.length() != 9) || hex[0] != '#') {
@ -53,25 +66,20 @@ FilamentMapDialog::FilamentMapDialog(wxWindow *parent,
, m_filament_map(filament_map) , m_filament_map(filament_map)
, m_has_auto_result(has_auto_result) , m_has_auto_result(has_auto_result)
{ {
SetMinSize(wxSize(500, 100));
SetMaxSize(wxSize(500, 1500));
wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticBoxSizer *mode_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _L("Mode")); m_mode_switch_btn = new SwitchButton(this);
m_auto_radio = new wxRadioButton(this, wxID_ANY, _L("Auto")); m_mode_switch_btn->SetMaxSize({em_unit(this) * 12, -1});
m_manual_radio = new wxRadioButton(this, wxID_ANY, _L("Customize")); m_mode_switch_btn->SetLabels(_L("Customize"), _L("Auto"));
m_auto_radio->Bind(wxEVT_RADIOBUTTON, &FilamentMapDialog::on_auto_radio, this); m_mode_switch_btn->Bind(wxEVT_TOGGLEBUTTON, &FilamentMapDialog::on_switch_mode, this);
m_manual_radio->Bind(wxEVT_RADIOBUTTON, &FilamentMapDialog::on_manual_radio, this); m_mode_switch_btn->SetValue(is_auto);
main_sizer->Add(m_mode_switch_btn, 0, wxCENTER | wxALL, 10);
if (is_auto) m_tip_text = new wxStaticText(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
m_auto_radio->SetValue(true); main_sizer->Add(m_tip_text, 0, wxALIGN_LEFT | wxALL, 5);
else
m_manual_radio->SetValue(true);
mode_sizer->Add(m_auto_radio, 1, wxALL, 5);
mode_sizer->Add(m_manual_radio, 1, wxALL, 5);
main_sizer->Add(mode_sizer, 0, wxEXPAND | wxALL, 10);
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);
m_extruder_panel_sizer = new wxBoxSizer(wxHORIZONTAL); m_extruder_panel_sizer = new wxBoxSizer(wxHORIZONTAL);
@ -95,7 +103,12 @@ FilamentMapDialog::FilamentMapDialog(wxWindow *parent,
} }
} }
m_switch_filament_btn = new Button(this, "", "switch_filament_maps", 12, 12);
m_switch_filament_btn->Bind(wxEVT_BUTTON, &FilamentMapDialog::on_switch_filaments, this);
m_switch_filament_btn->SetCanFocus(false);
m_extruder_panel_sizer->Add(m_manual_left_panel, 1, wxEXPAND | wxALL, 5); m_extruder_panel_sizer->Add(m_manual_left_panel, 1, wxEXPAND | wxALL, 5);
m_extruder_panel_sizer->Add(m_switch_filament_btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
m_extruder_panel_sizer->Add(m_manual_right_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->Layout();
m_manual_left_panel->Fit(); m_manual_left_panel->Fit();
@ -130,14 +143,20 @@ FilamentMapDialog::FilamentMapDialog(wxWindow *parent,
if (is_auto) { if (is_auto) {
m_manual_left_panel->Hide(); m_manual_left_panel->Hide();
m_manual_right_panel->Hide(); m_manual_right_panel->Hide();
if (!m_has_auto_result) { m_switch_filament_btn->Hide();
if (m_has_auto_result) {
m_tip_text->SetLabel(auto_tips_with_result);
}
else {
m_auto_left_panel->Hide(); m_auto_left_panel->Hide();
m_auto_right_panel->Hide(); m_auto_right_panel->Hide();
m_tip_text->SetLabel(auto_tips);
} }
} }
else { else {
m_auto_left_panel->Hide(); m_auto_left_panel->Hide();
m_auto_right_panel->Hide(); m_auto_right_panel->Hide();
m_tip_text->SetLabel(manual_tips);
} }
wxBoxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);
@ -159,7 +178,7 @@ FilamentMapDialog::FilamentMapDialog(wxWindow *parent,
bool FilamentMapDialog::is_auto() const bool FilamentMapDialog::is_auto() const
{ {
if (m_auto_radio->GetValue()) { if (m_mode_switch_btn->GetValue()) {
return true; return true;
} }
return false; return false;
@ -188,38 +207,51 @@ void FilamentMapDialog::on_cancle(wxCommandEvent &event)
EndModal(wxID_CANCEL); EndModal(wxID_CANCEL);
} }
void FilamentMapDialog::on_auto_radio(wxCommandEvent& event) void FilamentMapDialog::on_switch_mode(wxCommandEvent &event)
{ {
if (!m_has_auto_result) { bool value = dynamic_cast<SwitchButton *>(event.GetEventObject())->GetValue();
if (value) { // auto
m_manual_left_panel->Hide(); m_manual_left_panel->Hide();
m_manual_right_panel->Hide(); m_manual_right_panel->Hide();
m_switch_filament_btn->Hide();
m_auto_left_panel->Hide(); if (m_has_auto_result) {
m_auto_right_panel->Hide();
Layout();
Fit();
}
else {
m_auto_left_panel->Show(); m_auto_left_panel->Show();
m_auto_right_panel->Show(); m_auto_right_panel->Show();
m_tip_text->SetLabel(auto_tips_with_result);
m_manual_left_panel->Hide();
m_manual_right_panel->Hide();
Layout();
Fit();
} }
else {
m_auto_left_panel->Hide();
m_auto_right_panel->Hide();
m_tip_text->SetLabel(auto_tips);
} }
} else { // manual
void FilamentMapDialog::on_manual_radio(wxCommandEvent& event)
{
m_manual_left_panel->Show(); m_manual_left_panel->Show();
m_manual_right_panel->Show(); m_manual_right_panel->Show();
m_switch_filament_btn->Show();
m_auto_left_panel->Hide(); m_auto_left_panel->Hide();
m_auto_right_panel->Hide(); m_auto_right_panel->Hide();
m_tip_text->SetLabel(manual_tips);
}
Layout();
Fit();
event.Skip();
}
void FilamentMapDialog::on_switch_filaments(wxCommandEvent &event)
{
std::vector<ColorPanel *> left_blocks = m_manual_left_panel->get_filament_blocks();
std::vector<ColorPanel *> right_blocks = m_manual_right_panel->get_filament_blocks();
for (ColorPanel* block : left_blocks) {
m_manual_right_panel->AddColorBlock(block->GetColor(), block->GetFilamentId());
m_manual_left_panel->RemoveColorBlock(block);
}
for (auto block : right_blocks) {
m_manual_left_panel->AddColorBlock(block->GetColor(), block->GetFilamentId());
m_manual_right_panel->RemoveColorBlock(block);
}
Layout(); Layout();
Fit(); Fit();
} }

View File

@ -7,6 +7,10 @@
#include <wx/timer.h> #include <wx/timer.h>
#include <vector> #include <vector>
class SwitchButton;
class Button;
class wxStaticText;
namespace Slic3r { namespace Slic3r {
class DynamicPrintConfig; class DynamicPrintConfig;
@ -29,17 +33,18 @@ public:
private: private:
void on_ok(wxCommandEvent &event); void on_ok(wxCommandEvent &event);
void on_cancle(wxCommandEvent &event); void on_cancle(wxCommandEvent &event);
void on_auto_radio(wxCommandEvent &event); void on_switch_mode(wxCommandEvent &event);
void on_manual_radio(wxCommandEvent &event); void on_switch_filaments(wxCommandEvent &event);
private: private:
wxRadioButton* m_auto_radio; wxStaticText * m_tip_text;
wxRadioButton* m_manual_radio; SwitchButton * m_mode_switch_btn;
wxBoxSizer * m_extruder_panel_sizer; wxBoxSizer * m_extruder_panel_sizer;
DragDropPanel* m_manual_left_panel; DragDropPanel* m_manual_left_panel;
DragDropPanel* m_manual_right_panel; DragDropPanel* m_manual_right_panel;
DragDropPanel* m_auto_left_panel; DragDropPanel* m_auto_left_panel;
DragDropPanel* m_auto_right_panel; DragDropPanel* m_auto_right_panel;
Button * m_switch_filament_btn;
private: private:
const DynamicPrintConfig* m_config; const DynamicPrintConfig* m_config;