From d96b5f360661feaa2f964d9f4b18d1e586d2607b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 26 Jun 2020 09:58:39 +0200 Subject: PhysicalPrinter : Next improvements: * Create full printer name as a PrinterName + RelatedPresetName * Added printer model to the PhysicalPrinter.config => Enable to select just between presets with same printer model * When physical printer is selected and create new preset ask if should we use this preset for selected ph_printer or just to switch for it --- src/libslic3r/Preset.cpp | 33 ++++++- src/libslic3r/Preset.hpp | 24 +++-- src/slic3r/GUI/PresetComboBoxes.cpp | 175 ++++++++++++++++++++++++++---------- src/slic3r/GUI/PresetComboBoxes.hpp | 9 ++ src/slic3r/GUI/Tab.cpp | 33 ++++++- src/slic3r/GUI/Tab.hpp | 1 + src/slic3r/GUI/wxExtensions.cpp | 7 +- src/slic3r/GUI/wxExtensions.hpp | 4 +- 8 files changed, 225 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index abc508b48..9af3dacf0 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -1351,6 +1352,7 @@ const std::vector& PhysicalPrinter::printer_options() s_opts = { "preset_name", "printer_technology", + "printer_model", "host_type", "print_host", "printhost_apikey", @@ -1363,21 +1365,28 @@ const std::vector& PhysicalPrinter::printer_options() return s_opts; } -const std::string& PhysicalPrinter::get_preset_name() +const std::string& PhysicalPrinter::get_preset_name() const { return config.opt_string("preset_name"); } +const std::string& PhysicalPrinter::get_printer_model() const +{ + return config.opt_string("printer_model"); +} + void PhysicalPrinter::update_from_preset(const Preset& preset) { config.apply_only(preset.config, printer_options(), false); // add preset name to the options list config.set_key_value("preset_name", new ConfigOptionString(preset.name)); + update_full_name(); } void PhysicalPrinter::update_from_config(const DynamicPrintConfig& new_config) { config.apply_only(new_config, printer_options(), false); + update_full_name(); } PhysicalPrinter::PhysicalPrinter(const std::string& name, const Preset& preset) : @@ -1386,6 +1395,24 @@ PhysicalPrinter::PhysicalPrinter(const std::string& name, const Preset& preset) update_from_preset(preset); } +void PhysicalPrinter::set_name(const std::string& name) +{ + this->name = name; + update_full_name(); +} + +void PhysicalPrinter::update_full_name() +{ + full_name = name + " * " + get_preset_name(); +} + +std::string PhysicalPrinter::get_short_name(std::string full_name) +{ + int pos = full_name.find_first_of(" * "); + boost::erase_tail(full_name, full_name.length() - pos); + return full_name; +} + // ----------------------------------- // *** PhysicalPrinterCollection *** @@ -1470,6 +1497,7 @@ void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_print // Printer with the same name found. // Overwriting an existing preset. it->config = std::move(edited_printer.config); + it->full_name = edited_printer.full_name; } else { // Creating a new printer. @@ -1516,8 +1544,9 @@ bool PhysicalPrinterCollection::delete_selected_printer() return true; } -PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(const std::string& name) +PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(std::string name) { + name = PhysicalPrinter::get_short_name(name); auto it = this->find_printer_internal(name); assert(it != m_printers.end()); diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index a5837a9fe..6eb1fd2db 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -538,20 +538,24 @@ public: PhysicalPrinter() {} PhysicalPrinter(const std::string& name) : name(name){} PhysicalPrinter(const std::string& name, const Preset& preset); + void set_name(const std::string &name); + void update_full_name(); // Name of the Physical Printer, usually derived form the file name. std::string name; + // Full name of the Physical Printer, included related preset name + std::string full_name; // File name of the Physical Printer. std::string file; + // Configuration data, loaded from a file, or set from the defaults. + DynamicPrintConfig config; // Has this profile been loaded? bool loaded = false; - // Configuration data, loaded from a file, or set from the defaults. - DynamicPrintConfig config; - static const std::vector& printer_options(); - const std::string& get_preset_name(); + const std::string& get_preset_name() const; + const std::string& get_printer_model() const; void save() { this->config.save(this->file); } void save_to(const std::string& file_name) const { this->config.save(file_name); } @@ -570,6 +574,9 @@ public: // Sort lexicographically by a preset name. The preset name shall be unique across a single PresetCollection. bool operator<(const PhysicalPrinter& other) const { return this->name < other.name; } + // get printer name from the full name uncluded preset name + static std::string get_short_name(std::string full_name); + protected: friend class PhysicalPrinterCollection; }; @@ -622,10 +629,17 @@ public: size_t get_selected_idx() const { return m_idx_selected; } // Returns the name of the selected preset, or an empty string if no preset is selected. std::string get_selected_printer_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().name; } + // Returns the full name of the selected preset, or an empty string if no preset is selected. + std::string get_selected_full_printer_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().full_name; } + // Returns the printer model of the selected preset, or an empty string if no preset is selected. + std::string get_selected_printer_model() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_printer_model(); } + // Returns the printer model of the selected preset, or an empty string if no preset is selected. + std::string get_selected_printer_preset_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_preset_name(); } + // Returns the config of the selected preset, or nullptr if no preset is selected. DynamicPrintConfig* get_selected_printer_config() { return (m_idx_selected == size_t(-1)) ? nullptr : &(this->get_selected_printer().config); } // select printer with name and return reference on it - PhysicalPrinter& select_printer_by_name(const std::string& name); + PhysicalPrinter& select_printer_by_name(std::string name); bool has_selection() const { return m_idx_selected != size_t(-1); } void unselect_printer() { m_idx_selected = size_t(-1); } diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index b39582ee0..88dd4b739 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -104,6 +104,7 @@ PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const m_bitmapCompatible = ScalableBitmap(this, "flag_green"); m_bitmapIncompatible = ScalableBitmap(this, "flag_red"); m_bitmapLock = ScalableBitmap(this, "lock_closed"); + m_bitmapLockDisabled = ScalableBitmap(this, "lock_closed", 16, true); // parameters for an icon's drawing fill_width_height(); @@ -125,6 +126,7 @@ void PresetComboBox::msw_rescale() m_em_unit = em_unit(this); m_bitmapLock.msw_rescale(); + m_bitmapLockDisabled.msw_rescale(); m_bitmapIncompatible.msw_rescale(); m_bitmapCompatible.msw_rescale(); @@ -241,6 +243,7 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset if (marker >= LABEL_ITEM_MARKER && marker < LABEL_ITEM_MAX) { this->SetSelection(this->m_last_selected); evt.StopPropagation(); + /* if (marker == LABEL_ITEM_PHYSICAL_PRINTERS) { PhysicalPrinterDialog dlg(wxEmptyString); @@ -258,6 +261,19 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset } wxTheApp->CallAfter([sp]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, sp); }); } + */ + if (marker == LABEL_ITEM_WIZARD_PRINTERS) + show_add_menu(); + else + { + ConfigWizard::StartPage sp = ConfigWizard::SP_WELCOME; + switch (marker) { + case LABEL_ITEM_WIZARD_FILAMENTS: sp = ConfigWizard::SP_FILAMENTS; break; + case LABEL_ITEM_WIZARD_MATERIALS: sp = ConfigWizard::SP_MATERIALS; break; + default: break; + } + wxTheApp->CallAfter([sp]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, sp); }); + } } else if (marker == LABEL_ITEM_PHYSICAL_PRINTER || this->m_last_selected != selected_item || m_collection->current_is_dirty() ) { this->m_last_selected = selected_item; evt.SetInt(this->m_type); @@ -377,6 +393,25 @@ bool PlaterPresetComboBox::switch_to_tab() return true; } +void PlaterPresetComboBox::show_add_menu() +{ + wxMenu* menu = new wxMenu(); + + append_menu_item(menu, wxID_ANY, _L("Add/Remove logical printers"), "", + [this](wxCommandEvent&) { + wxTheApp->CallAfter([]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); }); + }, "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()); + + wxGetApp().plater()->PopupMenu(menu); +} + void PlaterPresetComboBox::show_edit_menu() { wxMenu* menu = new wxMenu(); @@ -393,7 +428,7 @@ void PlaterPresetComboBox::show_edit_menu() append_menu_item(menu, wxID_ANY, _L("Delete physical printer"), "", [this](wxCommandEvent&) { - const std::string& printer_name = m_preset_bundle->physical_printers.get_selected_printer_name(); + const std::string& printer_name = m_preset_bundle->physical_printers.get_selected_full_printer_name(); if (printer_name.empty()) return; @@ -550,36 +585,6 @@ void PlaterPresetComboBox::update() } } - if (m_type == Preset::TYPE_PRINTER || m_type == Preset::TYPE_SLA_MATERIAL) { - std::string bitmap_key = ""; - // If the filament preset is not compatible and there is a "red flag" icon loaded, show it left - // to the filament color image. - if (wide_icons) - bitmap_key += "wide,"; - bitmap_key += "edit_preset_list"; - bitmap_key += "-h" + std::to_string(icon_height); - - wxBitmap* bmp = m_bitmap_cache->find(bitmap_key); - if (bmp == nullptr) { - // Create the bitmap with color bars.update_plater_ui - std::vector bmps; - if (wide_icons) - // Paint a red flag for incompatible presets. - bmps.emplace_back(m_bitmap_cache->mkclear(norm_icon_width, icon_height)); - // Paint the color bars. - bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height)); - bmps.emplace_back(create_scaled_bitmap(m_main_bitmap_name)); - // Paint a lock at the system presets. - bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height)); - bmps.emplace_back(create_scaled_bitmap("edit_uni")); - bmp = m_bitmap_cache->insert(bitmap_key, bmps); - } - if (m_type == Preset::TYPE_SLA_MATERIAL) - set_label_marker(Append(separator(L("Add/Remove materials")), *bmp), LABEL_ITEM_WIZARD_MATERIALS); - else - set_label_marker(Append(separator(L("Add/Remove printers")), *bmp), LABEL_ITEM_WIZARD_PRINTERS); - } - if (m_type == Preset::TYPE_PRINTER) { // add Physical printers, if any exists @@ -608,7 +613,7 @@ void PlaterPresetComboBox::update() bmp = m_bitmap_cache->insert(bitmap_key, bmps); } - set_label_marker(Append(wxString::FromUTF8((it->name).c_str()), *bmp), LABEL_ITEM_PHYSICAL_PRINTER); + set_label_marker(Append(wxString::FromUTF8((it->full_name).c_str()), *bmp), LABEL_ITEM_PHYSICAL_PRINTER); if (ph_printers.has_selection() && it->name == ph_printers.get_selected_printer_name() || // just in case: mark selected_preset_item as a first added element selected_preset_item == INT_MAX) @@ -616,6 +621,7 @@ void PlaterPresetComboBox::update() } } +/* // add LABEL_ITEM_PHYSICAL_PRINTERS std::string bitmap_key; if (wide_icons) @@ -639,6 +645,37 @@ void PlaterPresetComboBox::update() bmp = m_bitmap_cache->insert(bitmap_key, bmps); } set_label_marker(Append(separator(L("Add physical printer")), *bmp), LABEL_ITEM_PHYSICAL_PRINTERS); +*/ + } + + if (m_type == Preset::TYPE_PRINTER || m_type == Preset::TYPE_SLA_MATERIAL) { + std::string bitmap_key = ""; + // If the filament preset is not compatible and there is a "red flag" icon loaded, show it left + // to the filament color image. + if (wide_icons) + bitmap_key += "wide,"; + bitmap_key += "edit_preset_list"; + bitmap_key += "-h" + std::to_string(icon_height); + + wxBitmap* bmp = m_bitmap_cache->find(bitmap_key); + if (bmp == nullptr) { + // Create the bitmap with color bars.update_plater_ui + std::vector bmps; + if (wide_icons) + // Paint a red flag for incompatible presets. + bmps.emplace_back(m_bitmap_cache->mkclear(norm_icon_width, icon_height)); + // Paint the color bars. + bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height)); + bmps.emplace_back(create_scaled_bitmap(m_main_bitmap_name)); + // Paint a lock at the system presets. + bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height)); + bmps.emplace_back(create_scaled_bitmap("edit_uni")); + bmp = m_bitmap_cache->insert(bitmap_key, bmps); + } + if (m_type == Preset::TYPE_SLA_MATERIAL) + set_label_marker(Append(separator(L("Add/Remove materials")), *bmp), LABEL_ITEM_WIZARD_MATERIALS); + else + set_label_marker(Append(separator(L("Add/Remove printers")), *bmp), LABEL_ITEM_WIZARD_PRINTERS); } /* But, if selected_preset_item is still equal to INT_MAX, it means that @@ -680,7 +717,7 @@ TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type) auto selected_item = evt.GetSelection(); auto marker = reinterpret_cast(this->GetClientData(selected_item)); - if (marker >= LABEL_ITEM_MARKER && marker < LABEL_ITEM_MAX) { + if (marker >= LABEL_ITEM_DISABLED && marker < LABEL_ITEM_MAX) { this->SetSelection(this->m_last_selected); if (marker == LABEL_ITEM_WIZARD_PRINTERS) wxTheApp->CallAfter([this]() { @@ -710,7 +747,7 @@ void TabPresetComboBox::update() const std::deque& presets = m_collection->get_presets(); - std::map nonsys_presets; + std::map> nonsys_presets; wxString selected = ""; if (!presets.front().is_visible) set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); @@ -719,13 +756,24 @@ void TabPresetComboBox::update() const Preset& preset = presets[i]; if (!preset.is_visible || (!show_incompatible && !preset.is_compatible && i != idx_selected)) continue; + + // marker used for disable incompatible printer models for the selected physical printer + bool is_enabled = true; + // check this value just for printer presets, when physical printer is selected + if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) { + is_enabled = m_enable_all ? true : + preset.name == m_preset_bundle->physical_printers.get_selected_printer_preset_name() || + preset.config.opt_string("printer_model") == m_preset_bundle->physical_printers.get_selected_printer_model(); + } std::string bitmap_key = "tab"; - wxBitmap main_bmp = create_scaled_bitmap(m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name, this); + wxBitmap main_bmp = create_scaled_bitmap(m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name, this, 16, !is_enabled); if (m_type == Preset::TYPE_PRINTER) { bitmap_key += "_printer"; if (preset.printer_technology() == ptSLA) bitmap_key += "_sla"; + if (!is_enabled) + bitmap_key += "_disabled"; } bitmap_key += preset.is_compatible ? ",cmpt" : ",ncmpt"; bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst"; @@ -737,13 +785,14 @@ void TabPresetComboBox::update() std::vector bmps; bmps.emplace_back(m_type == Preset::TYPE_PRINTER ? main_bmp : preset.is_compatible ? m_bitmapCompatible.bmp() : m_bitmapIncompatible.bmp()); // Paint a lock at the system presets. - bmps.emplace_back((preset.is_system || preset.is_default) ? m_bitmapLock.bmp() : m_bitmap_cache->mkclear(norm_icon_width, icon_height)); + bmps.emplace_back((preset.is_system || preset.is_default) ? (is_enabled ? m_bitmapLock.bmp() : m_bitmapLockDisabled.bmp()) : m_bitmap_cache->mkclear(norm_icon_width, icon_height)); bmp = m_bitmap_cache->insert(bitmap_key, bmps); } if (preset.is_default || preset.is_system) { - Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), - (bmp == 0) ? main_bmp : *bmp); + int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), !bmp ? main_bmp : *bmp); + if (!is_enabled) + set_label_marker(item_id, LABEL_ITEM_DISABLED); if (i == idx_selected || // just in case: mark selected_preset_item as a first added element selected_preset_item == INT_MAX) @@ -751,7 +800,8 @@ void TabPresetComboBox::update() } else { - nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), bmp); + std::pair pair(bmp, is_enabled); + nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), std::pair(bmp, is_enabled)); if (i == idx_selected) selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); } @@ -761,8 +811,11 @@ void TabPresetComboBox::update() if (!nonsys_presets.empty()) { set_label_marker(Append(separator(L("User presets")), wxNullBitmap)); - for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { - Append(it->first, *it->second); + for (std::map>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { + int item_id = Append(it->first, *it->second.first); + bool is_enabled = it->second.second; + if (!is_enabled) + set_label_marker(item_id, LABEL_ITEM_DISABLED); if (it->first == selected || // just in case: mark selected_preset_item as a first added element selected_preset_item == INT_MAX) @@ -845,6 +898,17 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) int border = 10; m_printer_presets = new TabPresetComboBox(this, Preset::TYPE_PRINTER); + + if (printer_name.IsEmpty()) { + // if printer_name is empty it means that new printer is created, so enable all items in the preset list + m_printer_presets->set_enable_all(); + printer_name = _L("My Printer Device"); + } + else { + std::string full_name = into_u8(printer_name); + printer_name = from_u8(PhysicalPrinter::get_short_name(full_name)); + } + m_printer_presets->set_selection_changed_function([this](int selection) { std::string selected_string = Preset::remove_suffix_modified(m_printer_presets->GetString(selection).ToUTF8().data()); Preset* preset = wxGetApp().preset_bundle->printers.find_preset(selected_string); @@ -854,17 +918,22 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) preset = &edited_preset; m_printer.update_from_preset(*preset); + update_printer_name(); + // update values m_optgroup->reload_config(); update(); }); m_printer_presets->update(); - wxString preset_name = m_printer_presets->GetString(m_printer_presets->GetSelection()); + wxStaticText* label_top = new wxStaticText(this, wxID_ANY, _("Descriptive name for the printer device") + ":"); + m_printer_name = new wxTextCtrl(this, wxID_ANY, printer_name, wxDefaultPosition, wxDefaultSize); + m_printer_name->Bind(wxEVT_TEXT, [this](wxEvent&) { this->update_printer_name(); }); + + wxStaticText* label_bottom = new wxStaticText(this, wxID_ANY, _("This printer name will be shown in the presets list") + ":"); + m_full_printer_name = new wxStaticText(this, wxID_ANY, ""); - if (printer_name.IsEmpty()) - printer_name = preset_name + " - "+_L("Physical Printer"); - m_printer_name = new wxTextCtrl(this, wxID_ANY, printer_name, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); + update_printer_name(); PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; PhysicalPrinter* printer = printers.find_printer(into_u8(printer_name)); @@ -887,8 +956,11 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); + topSizer->Add(label_top , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); topSizer->Add(m_printer_name , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); topSizer->Add(m_printer_presets , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); + topSizer->Add(label_bottom , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); + topSizer->Add(m_full_printer_name , 0, wxEXPAND | wxLEFT | wxRIGHT, border); topSizer->Add(m_optgroup->sizer , 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); topSizer->Add(btns , 0, wxEXPAND | wxALL, border); @@ -1053,6 +1125,15 @@ void PhysicalPrinterDialog::update() this->Layout(); } +void PhysicalPrinterDialog::update_printer_name() +{ + wxString printer_name = m_printer_name->GetValue(); + wxString preset_name = m_printer_presets->GetString(m_printer_presets->GetSelection()); + + m_full_printer_name->SetLabelText("\t" + printer_name + " * " + preset_name); + this->Layout(); +} + void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) { const int& em = em_unit(); @@ -1096,8 +1177,8 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) printers.delete_printer(into_u8(printer_name)); } - //upadte printer name, if it was changed - m_printer.name = into_u8(printer_name); + //update printer name, if it was changed + m_printer.set_name(into_u8(printer_name)); // save new physical printer printers.save_printer(m_printer); diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 196c4368e..653c0e540 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -13,6 +13,7 @@ class wxString; class wxTextCtrl; +class wxStatictext; class ScalableButton; namespace Slic3r { @@ -35,6 +36,7 @@ public: enum LabelItemType { LABEL_ITEM_PHYSICAL_PRINTER = 0xffffff01, + LABEL_ITEM_DISABLED, LABEL_ITEM_MARKER, LABEL_ITEM_PHYSICAL_PRINTERS, LABEL_ITEM_WIZARD_PRINTERS, @@ -66,6 +68,8 @@ protected: ScalableBitmap m_bitmapIncompatible; // Indicator, that the preset is system and not modified. ScalableBitmap m_bitmapLock; + // Disabled analogue of the m_bitmapLock . + ScalableBitmap m_bitmapLockDisabled; int m_last_selected; int m_em_unit; @@ -125,6 +129,7 @@ public: bool is_selected_physical_printer(); bool switch_to_tab(); + void show_add_menu(); void show_edit_menu(); void update() override; @@ -142,6 +147,7 @@ private: class TabPresetComboBox : public PresetComboBox { bool show_incompatible {false}; + bool m_enable_all {false}; std::function on_selection_changed { nullptr }; public: @@ -156,6 +162,7 @@ public: void msw_rescale() override; void set_selection_changed_function(std::function sel_changed) { on_selection_changed = sel_changed; } + void set_enable_all(bool enable=true) { m_enable_all = enable; } }; @@ -169,6 +176,7 @@ class PhysicalPrinterDialog : public DPIDialog DynamicPrintConfig* m_config { nullptr }; wxTextCtrl* m_printer_name { nullptr }; + wxStaticText* m_full_printer_name { nullptr }; TabPresetComboBox* m_printer_presets { nullptr }; ConfigOptionsGroup* m_optgroup { nullptr }; @@ -178,6 +186,7 @@ class PhysicalPrinterDialog : public DPIDialog void build_printhost_settings(ConfigOptionsGroup* optgroup); void update(); + void update_printer_name(); void OnOK(wxEvent& event); public: diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index da5d51dc5..595283e98 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -162,10 +162,9 @@ void Tab::create_preset_tab() // preset chooser m_presets_choice = new TabPresetComboBox(panel, m_type); m_presets_choice->set_selection_changed_function([this](int selection) { - // unselect pthysical printer, if it was selected - m_preset_bundle->physical_printers.unselect_printer(); - // select preset std::string selected_string = m_presets_choice->GetString(selection).ToUTF8().data(); + update_physical_printers(selected_string); + // select preset select_preset(selected_string); }); @@ -763,6 +762,32 @@ void Tab::update_tab_ui() m_presets_choice->update(); } +void Tab::update_physical_printers(std::string preset_name) +{ + if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) + { + std::string printer_name = m_preset_bundle->physical_printers.get_selected_full_printer_name(); + wxString msg_text = from_u8((boost::format(_u8L("You have selected physical printer \"%1%\".")) % printer_name).str()); + msg_text += "\n\n" + _L("Would you like to change related preset for this printer?") + "\n\n" + + _L("Select YES if you want to change related preset for this printer \n" + "or NO to switch to the another preset (logical printer)."); + wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO); + + if (dialog.ShowModal() == wxID_YES) { + preset_name = Preset::remove_suffix_modified(preset_name); + Preset* preset = m_presets->find_preset(preset_name); + assert(preset); + Preset& edited_preset = m_presets->get_edited_preset(); + if (preset->name == edited_preset.name) + preset = &edited_preset; + m_preset_bundle->physical_printers.get_selected_printer().update_from_preset(*preset); + } + else + // unselect physical printer, if it was selected + m_preset_bundle->physical_printers.unselect_printer(); + } +} + // Load a provied DynamicConfig into the tab, modifying the active preset. // This could be used for example by setting a Wipe Tower position by interactive manipulation in the 3D view. void Tab::load_config(const DynamicPrintConfig& config) @@ -3269,6 +3294,8 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach) // Mark the print & filament enabled if they are compatible with the currently selected preset. // If saving the preset changes compatibility with other presets, keep the now incompatible dependent presets selected, however with a "red flag" icon showing that they are no more compatible. m_preset_bundle->update_compatible(PresetSelectCompatibleType::Never); + //update physical printer's related printer preset if it's needed + update_physical_printers(name); // Add the new item into the UI component, remove dirty flags and activate the saved item. update_tab_ui(); // Update the selection boxes at the plater. diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index bc15efa35..69720ff65 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -306,6 +306,7 @@ public: void load_initial_data(); void update_dirty(); void update_tab_ui(); + void update_physical_printers(std::string preset_name); void load_config(const DynamicPrintConfig& config); virtual void reload_config(); void update_mode(); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 39b3e154b..67b5a18f7 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -731,11 +731,12 @@ void MenuWithSeparators::SetSecondSeparator() // ---------------------------------------------------------------------------- ScalableBitmap::ScalableBitmap( wxWindow *parent, const std::string& icon_name/* = ""*/, - const int px_cnt/* = 16*/): + const int px_cnt/* = 16*/, + const bool grayscale/* = false*/): m_parent(parent), m_icon_name(icon_name), m_px_cnt(px_cnt) { - m_bmp = create_scaled_bitmap(icon_name, parent, px_cnt); + m_bmp = create_scaled_bitmap(icon_name, parent, px_cnt, grayscale); } wxSize ScalableBitmap::GetBmpSize() const @@ -768,7 +769,7 @@ int ScalableBitmap::GetBmpHeight() const void ScalableBitmap::msw_rescale() { - m_bmp = create_scaled_bitmap(m_icon_name, m_parent, m_px_cnt); + m_bmp = create_scaled_bitmap(m_icon_name, m_parent, m_px_cnt, m_grayscale); } // ---------------------------------------------------------------------------- diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 17fe8992c..9be3361bd 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -130,7 +130,8 @@ public: ScalableBitmap() {}; ScalableBitmap( wxWindow *parent, const std::string& icon_name = "", - const int px_cnt = 16); + const int px_cnt = 16, + const bool grayscale = false); ~ScalableBitmap() {} @@ -151,6 +152,7 @@ private: wxBitmap m_bmp = wxBitmap(); std::string m_icon_name = ""; int m_px_cnt {16}; + bool m_grayscale {false}; }; -- cgit v1.2.3