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
(cherry picked from commit 9ee85bef34aaabe7a4cef251f07e77f9af693a2f)
This commit is contained in:
zhimin.zeng
2024-08-09 17:46:11 +08:00
committed by Noisyfox
parent 00388756ed
commit 1ada437979
10 changed files with 147 additions and 28 deletions

View File

@@ -45,16 +45,21 @@ FilamentMapDialog::FilamentMapDialog(wxWindow *parent,
const DynamicPrintConfig *config,
const std::vector<int> &filament_map,
const std::vector<int> &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<std::string> filament_color = config->option<ConfigOptionStrings>("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<int> left_filaments = m_left_panel->GetAllFilaments();
std::vector<int> right_filaments = m_right_panel->GetAllFilaments();
if (!is_auto()) {
std::vector<int> left_filaments = m_manual_left_panel->GetAllFilaments();
std::vector<int> 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