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,33 +64,14 @@ private:
/////////////// ColorPanel start ////////////////////////
// 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);
Bind(wxEVT_LEFT_DOWN, &ColorPanel::OnLeftDown, this);
Bind(wxEVT_LEFT_UP, &ColorPanel::OnLeftUp, 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;
};
SetBackgroundColour(color);
Bind(wxEVT_LEFT_DOWN, &ColorPanel::OnLeftDown, this);
Bind(wxEVT_LEFT_UP, &ColorPanel::OnLeftUp, this);
Bind(wxEVT_PAINT, &ColorPanel::OnPaint, this);
}
void ColorPanel::OnLeftDown(wxMouseEvent &event)
{
@ -198,6 +179,7 @@ void DragDropPanel::AddColorBlock(const wxColour &color, int filament_id)
ColorPanel *panel = new ColorPanel(this, color, filament_id);
panel->SetMinSize(wxSize(50, 50));
m_grid_item_sizer->Add(panel, 0, wxALIGN_CENTER | wxALL, 5);
m_filament_blocks.push_back(panel);
Layout();
}
@ -205,6 +187,7 @@ void DragDropPanel::RemoveColorBlock(ColorPanel *panel)
{
m_sizer->Detach(panel);
panel->Destroy();
m_filament_blocks.erase(std::remove(m_filament_blocks.begin(), m_filament_blocks.end(), panel), m_filament_blocks.end());
Layout();
}

View File

@ -11,7 +11,6 @@
namespace Slic3r { namespace GUI {
class ColorPanel;
class DragDropPanel : public wxPanel
{
@ -27,14 +26,37 @@ public:
void set_is_draging(bool is_draging) { m_is_draging = is_draging; }
bool is_draging() const { return m_is_draging; }
std::vector<ColorPanel *> get_filament_blocks() const { return m_filament_blocks; }
private:
wxBoxSizer *m_sizer;
wxGridSizer *m_grid_item_sizer;
bool m_is_auto;
std::vector<ColorPanel *> m_filament_blocks;
private:
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
#endif /* slic3r_DragDropPanel_hpp_ */

View File

@ -1,10 +1,23 @@
#include "FilamentMapDialog.hpp"
#include "DragDropPanel.hpp"
#include "Widgets/Button.hpp"
#include "Widgets/SwitchButton.hpp"
#include "I18N.hpp"
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)
{
if ((hex.length() != 7 && hex.length() != 9) || hex[0] != '#') {
@ -53,25 +66,20 @@ FilamentMapDialog::FilamentMapDialog(wxWindow *parent,
, m_filament_map(filament_map)
, m_has_auto_result(has_auto_result)
{
SetMinSize(wxSize(500, 100));
SetMaxSize(wxSize(500, 1500));
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);
m_mode_switch_btn = new SwitchButton(this);
m_mode_switch_btn->SetMaxSize({em_unit(this) * 12, -1});
m_mode_switch_btn->SetLabels(_L("Customize"), _L("Auto"));
m_mode_switch_btn->Bind(wxEVT_TOGGLEBUTTON, &FilamentMapDialog::on_switch_mode, this);
m_mode_switch_btn->SetValue(is_auto);
main_sizer->Add(m_mode_switch_btn, 0, wxCENTER | wxALL, 10);
if (is_auto)
m_auto_radio->SetValue(true);
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_tip_text = new wxStaticText(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
main_sizer->Add(m_tip_text, 0, wxALIGN_LEFT | wxALL, 5);
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_switch_filament_btn, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
m_extruder_panel_sizer->Add(m_manual_right_panel, 1, wxEXPAND | wxALL, 5);
m_manual_left_panel->Layout();
m_manual_left_panel->Fit();
@ -130,14 +143,20 @@ FilamentMapDialog::FilamentMapDialog(wxWindow *parent,
if (is_auto) {
m_manual_left_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_right_panel->Hide();
m_tip_text->SetLabel(auto_tips);
}
}
else {
m_auto_left_panel->Hide();
m_auto_right_panel->Hide();
m_tip_text->SetLabel(manual_tips);
}
wxBoxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);
@ -159,7 +178,7 @@ FilamentMapDialog::FilamentMapDialog(wxWindow *parent,
bool FilamentMapDialog::is_auto() const
{
if (m_auto_radio->GetValue()) {
if (m_mode_switch_btn->GetValue()) {
return true;
}
return false;
@ -188,38 +207,51 @@ void FilamentMapDialog::on_cancle(wxCommandEvent &event)
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_right_panel->Hide();
m_switch_filament_btn->Hide();
if (m_has_auto_result) {
m_auto_left_panel->Show();
m_auto_right_panel->Show();
m_tip_text->SetLabel(auto_tips_with_result);
}
else {
m_auto_left_panel->Hide();
m_auto_right_panel->Hide();
m_tip_text->SetLabel(auto_tips);
}
} else { // manual
m_manual_left_panel->Show();
m_manual_right_panel->Show();
m_switch_filament_btn->Show();
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();
m_tip_text->SetLabel(manual_tips);
}
Layout();
Fit();
event.Skip();
}
void FilamentMapDialog::on_manual_radio(wxCommandEvent& event)
void FilamentMapDialog::on_switch_filaments(wxCommandEvent &event)
{
m_manual_left_panel->Show();
m_manual_right_panel->Show();
m_auto_left_panel->Hide();
m_auto_right_panel->Hide();
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();
Fit();
}

View File

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