diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 7c53eb000..f71cbd17b 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -248,6 +248,51 @@ void PresetComboBox::update(std::string select_preset_name) Thaw(); } +void PresetComboBox::edit_physical_printer() +{ + if (!m_preset_bundle->physical_printers.has_selection()) + return; + + PhysicalPrinterDialog dlg(this->GetString(this->GetSelection())); + if (dlg.ShowModal() == wxID_OK) + update(); +} + +void PresetComboBox::add_physical_printer() +{ + if (PhysicalPrinterDialog(wxEmptyString).ShowModal() == wxID_OK) + update(); +} + +bool PresetComboBox::del_physical_printer(const wxString& note_string/* = wxEmptyString*/) +{ + const std::string& printer_name = m_preset_bundle->physical_printers.get_selected_full_printer_name(); + if (printer_name.empty()) + return false; + + wxString msg; + if (!note_string.IsEmpty()) + msg += note_string + "\n"; + msg += format_wxstr(_L("Are you sure you want to delete \"%1%\" printer?"), printer_name); + + if (wxMessageDialog(this, msg, _L("Delete Physical Printer"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION).ShowModal() != wxID_YES) + return false; + + m_preset_bundle->physical_printers.delete_selected_printer(); + + this->update(); + + if (dynamic_cast(this) != nullptr) + wxGetApp().get_tab(m_type)->update_preset_choice(); + else if (dynamic_cast(this) != nullptr) + { + wxGetApp().get_tab(m_type)->update_btns_enabling(); + wxGetApp().plater()->sidebar().update_presets(m_type); + } + + return true; +} + void PresetComboBox::update() { this->update(into_u8(this->GetString(this->GetSelection()))); @@ -313,7 +358,7 @@ wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, bool wide_icons, con // Paint a red flag for incompatible presets. bmps.emplace_back(is_compatible ? bitmap_cache().mkclear(norm_icon_width, icon_height) : m_bitmapIncompatible.bmp()); - if (m_type == Preset::TYPE_FILAMENT) + if (m_type == Preset::TYPE_FILAMENT && !filament_rgb.empty()) { unsigned char rgb[3]; // Paint the color bars. @@ -642,28 +687,11 @@ void PlaterPresetComboBox::show_edit_menu() [this](wxCommandEvent&) { this->switch_to_tab(); }, "cog", menu, []() { return true; }, wxGetApp().plater()); if (this->is_selected_physical_printer()) { - append_menu_item(menu, wxID_ANY, _L("Edit physical printer"), "", - [this](wxCommandEvent&) { - PhysicalPrinterDialog dlg(this->GetString(this->GetSelection())); - if (dlg.ShowModal() == wxID_OK) - update(); - }, "cog", menu, []() { return true; }, wxGetApp().plater()); + append_menu_item(menu, wxID_ANY, _L("Edit physical printer"), "", + [this](wxCommandEvent&) { this->edit_physical_printer(); }, "cog", menu, []() { return true; }, wxGetApp().plater()); - append_menu_item(menu, wxID_ANY, _L("Delete physical printer"), "", - [this](wxCommandEvent&) { - const std::string& printer_name = m_preset_bundle->physical_printers.get_selected_full_printer_name(); - if (printer_name.empty()) - return; - - const wxString msg = from_u8((boost::format(_u8L("Are you sure you want to delete \"%1%\" printer?")) % printer_name).str()); - if (wxMessageDialog(this, msg, _L("Delete Physical Printer"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION).ShowModal() != wxID_YES) - return; - - m_preset_bundle->physical_printers.delete_selected_printer(); - - wxGetApp().get_tab(m_type)->update_preset_choice(); - update(); - }, "cross", menu, []() { return true; }, wxGetApp().plater()); + append_menu_item(menu, wxID_ANY, _L("Delete physical printer"), "", + [this](wxCommandEvent&) { this->del_physical_printer(); }, "cross", menu, []() { return true; }, wxGetApp().plater()); } else append_menu_item(menu, wxID_ANY, _L("Add/Remove presets"), "", @@ -672,11 +700,7 @@ void PlaterPresetComboBox::show_edit_menu() }, "edit_uni", menu, []() { return true; }, wxGetApp().plater()); append_menu_item(menu, wxID_ANY, _L("Add physical printer"), "", - [this](wxCommandEvent&) { - PhysicalPrinterDialog dlg(wxEmptyString); - if (dlg.ShowModal() == wxID_OK) - update(); - }, "edit_uni", menu, []() { return true; }, wxGetApp().plater()); + [this](wxCommandEvent&) { this->add_physical_printer(); }, "edit_uni", menu, []() { return true; }, wxGetApp().plater()); wxGetApp().plater()->PopupMenu(menu); } diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 25a2aa94a..2967ff263 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -59,6 +59,10 @@ public: void update(std::string select_preset); + void edit_physical_printer(); + void add_physical_printer(); + bool del_physical_printer(const wxString& note_string = wxEmptyString); + virtual void update(); virtual void msw_rescale(); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 70e739d93..a650a9473 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -202,9 +202,7 @@ void Tab::create_preset_tab() // TRN "Save current Settings" m_btn_save_preset->SetToolTip(from_u8((boost::format(_utf8(L("Save current %s"))) % m_title).str())); m_btn_delete_preset->SetToolTip(_(L("Delete this preset"))); - m_btn_delete_preset->Disable(); - if (m_btn_edit_ph_printer) - m_btn_edit_ph_printer->Disable(); + m_btn_delete_preset->Hide(); add_scaled_button(panel, &m_question_btn, "question"); m_question_btn->SetToolTip(_(L("Hover the cursor over buttons to find more information \n" @@ -339,11 +337,12 @@ void Tab::create_preset_tab() })); if (m_btn_edit_ph_printer) - m_btn_edit_ph_printer->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { - PhysicalPrinterDialog dlg(m_presets_choice->GetString(m_presets_choice->GetSelection())); - if (dlg.ShowModal() == wxID_OK) - update_tab_ui(); - })); + m_btn_edit_ph_printer->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) { + if (m_preset_bundle->physical_printers.has_selection()) + m_presets_choice->edit_physical_printer(); + else + m_presets_choice->add_physical_printer(); + }); // Fill cache for mode bitmaps m_mode_bitmap_cache.reserve(3); @@ -2927,17 +2926,15 @@ void Tab::rebuild_page_tree() void Tab::update_btns_enabling() { - // we can't delete last preset from the physical printer - if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) - m_btn_delete_preset->Enable(m_preset_bundle->physical_printers.get_selected_printer().preset_names.size() > 1); - else { - const Preset& preset = m_presets->get_edited_preset(); - m_btn_delete_preset->Enable(!preset.is_default && !preset.is_system); - } + // we can delete any preset from the physical printer + // and any user preset + const Preset& preset = m_presets->get_edited_preset(); + m_btn_delete_preset->Show(m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection() || + !preset.is_default && !preset.is_system); - // we can edit physical printer only if it's selected in the list if (m_btn_edit_ph_printer) - m_btn_edit_ph_printer->Enable(m_preset_bundle->physical_printers.has_selection()); + m_btn_edit_ph_printer->SetToolTip( m_preset_bundle->physical_printers.has_selection() ? + _L("Edit physical printer") : _L("Add physical printer")); } void Tab::update_preset_choice() @@ -3336,7 +3333,7 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach) // Update the selection boxes at the plater. on_presets_changed(); // If current profile is saved, "delete preset" button have to be enabled - m_btn_delete_preset->Enable(true); + m_btn_delete_preset->Show(); if (m_type == Preset::TYPE_PRINTER) static_cast(this)->m_initial_extruders_count = static_cast(this)->m_extruders_count; @@ -3389,8 +3386,16 @@ void Tab::delete_preset() PhysicalPrinterCollection& physical_printers = m_preset_bundle->physical_printers; wxString msg; if (m_presets_choice->is_selected_physical_printer()) - msg = from_u8((boost::format(_u8L("Are you sure you want to delete \"%1%\" preset from the physical printer \"%2%\"?")) - % current_preset.name % physical_printers.get_selected_printer_name()).str()); + { + PhysicalPrinter& printer = physical_printers.get_selected_printer(); + if (printer.preset_names.size() == 1) { + if (m_presets_choice->del_physical_printer(_L("It's a last preset for this physical printer."))) + Layout(); + return; + } + + msg = format_wxstr(_L("Are you sure you want to delete \"%1%\" preset from the physical printer \"%2%\"?"), current_preset.name, printer.name); + } else { if (m_type == Preset::TYPE_PRINTER && !physical_printers.empty()) @@ -3431,11 +3436,6 @@ void Tab::delete_preset() if (m_presets_choice->is_selected_physical_printer()) { PhysicalPrinter& printer = physical_printers.get_selected_printer(); - if (printer.preset_names.size() == 1) { - wxMessageDialog dialog(nullptr, _L("It's a last for this physical printer. We can't delete it"), _L("Information"), wxICON_INFORMATION | wxOK); - dialog.ShowModal(); - return; - } // just delete this preset from the current physical printer printer.delete_preset(m_presets->get_edited_preset().name); // select first from the possible presets for this printer