From 43e6e4f18c89257d2df547253fda600ed093d324 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 16 Jun 2020 12:57:49 +0200 Subject: [PATCH 01/31] Code refactoring: - PresetCombpBoxes are extracted to the separate file. - All preset icons are moved to the PresetComboBox from Preset and PresetBundle - First "steps" to add physical printers to the printers list on the sidebar. --- src/slic3r/CMakeLists.txt | 2 + src/slic3r/GUI/GUI_ObjectList.cpp | 3 - src/slic3r/GUI/MainFrame.cpp | 12 - src/slic3r/GUI/Plater.cpp | 212 ++------ src/slic3r/GUI/Plater.hpp | 41 +- src/slic3r/GUI/Preset.cpp | 410 ++++---------- src/slic3r/GUI/Preset.hpp | 228 ++++++-- src/slic3r/GUI/PresetBundle.cpp | 270 +--------- src/slic3r/GUI/PresetBundle.hpp | 22 - src/slic3r/GUI/PresetComboBoxes.cpp | 794 ++++++++++++++++++++++++++++ src/slic3r/GUI/PresetComboBoxes.hpp | 179 +++++++ src/slic3r/GUI/Tab.cpp | 46 +- src/slic3r/GUI/Tab.hpp | 7 +- src/slic3r/GUI/wxExtensions.cpp | 88 --- src/slic3r/GUI/wxExtensions.hpp | 31 -- 15 files changed, 1304 insertions(+), 1041 deletions(-) create mode 100644 src/slic3r/GUI/PresetComboBoxes.cpp create mode 100644 src/slic3r/GUI/PresetComboBoxes.hpp diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 7e02c0fdd..98389e7da 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -80,6 +80,8 @@ set(SLIC3R_GUI_SOURCES GUI/MainFrame.cpp GUI/MainFrame.hpp GUI/Plater.cpp + GUI/PresetComboBoxes.hpp + GUI/PresetComboBoxes.cpp GUI/Plater.hpp GUI/GUI_ObjectList.cpp GUI/GUI_ObjectList.hpp diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index c11ed66ab..2f201180a 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -88,9 +88,6 @@ ObjectList::ObjectList(wxWindow* parent) : { // Fill CATEGORY_ICON { - // Note: `this` isn't passed to create_scaled_bitmap() here because of bugs in the widget, - // see note in PresetBundle::load_compatible_bitmaps() - // ptFFF CATEGORY_ICON[L("Layers and Perimeters")] = create_scaled_bitmap("layers"); CATEGORY_ICON[L("Infill")] = create_scaled_bitmap("infill"); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index ef837c200..d4ce21fc0 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -74,11 +74,6 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S SLIC3R_VERSION + _(L(" - Remember to check for updates at http://github.com/prusa3d/PrusaSlicer/releases"))); - /* Load default preset bitmaps before a tabpanel initialization, - * but after filling of an em_unit value - */ - wxGetApp().preset_bundle->load_default_preset_bitmaps(); - // initialize tabpanel and menubar init_tabpanel(); init_menubar(); @@ -540,11 +535,6 @@ void MainFrame::on_dpi_changed(const wxRect &suggested_rect) wxGetApp().update_fonts(); this->SetFont(this->normal_font()); - /* Load default preset bitmaps before a tabpanel initialization, - * but after filling of an em_unit value - */ - wxGetApp().preset_bundle->load_default_preset_bitmaps(); - // update Plater wxGetApp().plater()->msw_rescale(); @@ -586,8 +576,6 @@ void MainFrame::on_sys_color_changed() // update label colors in respect to the system mode wxGetApp().init_label_colours(); - wxGetApp().preset_bundle->load_default_preset_bitmaps(); - // update Plater wxGetApp().plater()->sys_color_changed(); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 8c3a90370..339badc96 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -77,6 +76,7 @@ #include "../Utils/UndoRedo.hpp" #include "RemovableDriveManager.hpp" #include "InstanceCheck.hpp" +#include "PresetComboBoxes.hpp" #ifdef __APPLE__ #include "Gizmos/GLGizmosManager.hpp" @@ -253,153 +253,6 @@ void SlicedInfo::SetTextAndShow(SlicedInfoIdx idx, const wxString& text, const w info_vec[idx].second->Show(show); } -PresetComboBox::PresetComboBox(wxWindow *parent, Preset::Type preset_type) : -PresetBitmapComboBox(parent, wxSize(15 * wxGetApp().em_unit(), -1)), - preset_type(preset_type), - last_selected(wxNOT_FOUND), - m_em_unit(wxGetApp().em_unit()) -{ - SetFont(wxGetApp().normal_font()); -#ifdef _WIN32 - // Workaround for ignoring CBN_EDITCHANGE events, which are processed after the content of the combo box changes, so that - // the index of the item inside CBN_EDITCHANGE may no more be valid. - EnableTextChangedEvents(false); -#endif /* _WIN32 */ - Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &evt) { - auto selected_item = evt.GetSelection(); - - auto marker = reinterpret_cast(this->GetClientData(selected_item)); - if (marker >= LABEL_ITEM_MARKER && marker < LABEL_ITEM_MAX) { - this->SetSelection(this->last_selected); - evt.StopPropagation(); - if (marker >= LABEL_ITEM_WIZARD_PRINTERS) { - ConfigWizard::StartPage sp = ConfigWizard::SP_WELCOME; - switch (marker) { - case LABEL_ITEM_WIZARD_PRINTERS: sp = ConfigWizard::SP_PRINTERS; break; - case LABEL_ITEM_WIZARD_FILAMENTS: sp = ConfigWizard::SP_FILAMENTS; break; - case LABEL_ITEM_WIZARD_MATERIALS: sp = ConfigWizard::SP_MATERIALS; break; - } - wxTheApp->CallAfter([sp]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, sp); }); - } - } else if ( this->last_selected != selected_item || - wxGetApp().get_tab(this->preset_type)->get_presets()->current_is_dirty() ) { - this->last_selected = selected_item; - evt.SetInt(this->preset_type); - evt.Skip(); - } else { - evt.StopPropagation(); - } - }); - - if (preset_type == Slic3r::Preset::TYPE_FILAMENT) - { - Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &event) { - PresetBundle* preset_bundle = wxGetApp().preset_bundle; - const Preset* selected_preset = preset_bundle->filaments.find_preset(preset_bundle->filament_presets[extruder_idx]); - // Wide icons are shown if the currently selected preset is not compatible with the current printer, - // and red flag is drown in front of the selected preset. - bool wide_icons = selected_preset != nullptr && !selected_preset->is_compatible; - float scale = m_em_unit*0.1f; - - int shifl_Left = wide_icons ? int(scale * 16 + 0.5) : 0; -#if defined(wxBITMAPCOMBOBOX_OWNERDRAWN_BASED) - shifl_Left += int(scale * 4 + 0.5f); // IMAGE_SPACING_RIGHT = 4 for wxBitmapComboBox -> Space left of image -#endif - int icon_right_pos = shifl_Left + int(scale * (24+4) + 0.5); - int mouse_pos = event.GetLogicalPosition(wxClientDC(this)).x; - if (mouse_pos < shifl_Left || mouse_pos > icon_right_pos ) { - // Let the combo box process the mouse click. - event.Skip(); - return; - } - - // Swallow the mouse click and open the color picker. - - // get current color - DynamicPrintConfig* cfg = wxGetApp().get_tab(Preset::TYPE_PRINTER)->get_config(); - auto colors = static_cast(cfg->option("extruder_colour")->clone()); - wxColour clr(colors->values[extruder_idx]); - if (!clr.IsOk()) - clr = wxColour(0,0,0); // Don't set alfa to transparence - - auto data = new wxColourData(); - data->SetChooseFull(1); - data->SetColour(clr); - - wxColourDialog dialog(this, data); - dialog.CenterOnParent(); - if (dialog.ShowModal() == wxID_OK) - { - colors->values[extruder_idx] = dialog.GetColourData().GetColour().GetAsString(wxC2S_HTML_SYNTAX).ToStdString(); - - DynamicPrintConfig cfg_new = *cfg; - cfg_new.set_key_value("extruder_colour", colors); - - wxGetApp().get_tab(Preset::TYPE_PRINTER)->load_config(cfg_new); - preset_bundle->update_plater_filament_ui(extruder_idx, this); - wxGetApp().plater()->on_config_change(cfg_new); - } - }); - } - - edit_btn = new ScalableButton(parent, wxID_ANY, "cog"); - edit_btn->SetToolTip(_L("Click to edit preset")); - - edit_btn->Bind(wxEVT_BUTTON, ([preset_type, this](wxCommandEvent) - { - Tab* tab = wxGetApp().get_tab(preset_type); - if (!tab) - return; - - int page_id = wxGetApp().tab_panel()->FindPage(tab); - if (page_id == wxNOT_FOUND) - return; - - wxGetApp().tab_panel()->SetSelection(page_id); - - // Switch to Settings NotePad - wxGetApp().mainframe->select_tab(); - - /* In a case of a multi-material printing, for editing another Filament Preset - * it's needed to select this preset for the "Filament settings" Tab - */ - if (preset_type == Preset::TYPE_FILAMENT && wxGetApp().extruders_edited_cnt() > 1) - { - const std::string& selected_preset = GetString(GetSelection()).ToUTF8().data(); - - // Call select_preset() only if there is new preset and not just modified - if ( !boost::algorithm::ends_with(selected_preset, Preset::suffix_modified()) ) - { - const std::string& preset_name = wxGetApp().preset_bundle->filaments.get_preset_name_by_alias(selected_preset); - tab->select_preset(/*selected_preset*/preset_name); - } - } - })); -} - -PresetComboBox::~PresetComboBox() -{ - if (edit_btn) - edit_btn->Destroy(); -} - - -void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type) -{ - this->SetClientData(item, (void*)label_item_type); -} - -void PresetComboBox::check_selection(int selection) -{ - this->last_selected = selection; -} - -void PresetComboBox::msw_rescale() -{ - m_em_unit = wxGetApp().em_unit(); - edit_btn->msw_rescale(); -} - // Frequently changed parameters class FreqChangedParams : public OG_Settings @@ -697,12 +550,12 @@ struct Sidebar::priv ModeSizer *mode_sizer; wxFlexGridSizer *sizer_presets; - PresetComboBox *combo_print; - std::vector combos_filament; + PlaterPresetComboBox *combo_print; + std::vector combos_filament; wxBoxSizer *sizer_filaments; - PresetComboBox *combo_sla_print; - PresetComboBox *combo_sla_material; - PresetComboBox *combo_printer; + PlaterPresetComboBox *combo_sla_print; + PlaterPresetComboBox *combo_sla_material; + PlaterPresetComboBox *combo_printer; wxBoxSizer *sizer_params; FreqChangedParams *frequently_changed_parameters{ nullptr }; @@ -801,10 +654,10 @@ Sidebar::Sidebar(Plater *parent) p->sizer_filaments = new wxBoxSizer(wxVERTICAL); - auto init_combo = [this](PresetComboBox **combo, wxString label, Preset::Type preset_type, bool filament) { + auto init_combo = [this](PlaterPresetComboBox **combo, wxString label, Preset::Type preset_type, bool filament) { auto *text = new wxStaticText(p->presets_panel, wxID_ANY, label + " :"); text->SetFont(wxGetApp().small_font()); - *combo = new PresetComboBox(p->presets_panel, preset_type); + *combo = new PlaterPresetComboBox(p->presets_panel, preset_type); auto combo_and_btn_sizer = new wxBoxSizer(wxHORIZONTAL); combo_and_btn_sizer->Add(*combo, 1, wxEXPAND); @@ -941,8 +794,8 @@ Sidebar::Sidebar(Plater *parent) Sidebar::~Sidebar() {} -void Sidebar::init_filament_combo(PresetComboBox **combo, const int extr_idx) { - *combo = new PresetComboBox(p->presets_panel, Slic3r::Preset::TYPE_FILAMENT); +void Sidebar::init_filament_combo(PlaterPresetComboBox **combo, const int extr_idx) { + *combo = new PlaterPresetComboBox(p->presets_panel, Slic3r::Preset::TYPE_FILAMENT); // # copy icons from first choice // $choice->SetItemBitmap($_, $choices->[0]->GetItemBitmap($_)) for 0..$#presets; @@ -977,18 +830,18 @@ void Sidebar::update_all_preset_comboboxes() // Update the print choosers to only contain the compatible presets, update the dirty flags. if (print_tech == ptFFF) - preset_bundle.prints.update_plater_ui(p->combo_print); + p->combo_print->update(); else { - preset_bundle.sla_prints.update_plater_ui(p->combo_sla_print); - preset_bundle.sla_materials.update_plater_ui(p->combo_sla_material); + p->combo_sla_print->update(); + p->combo_sla_material->update(); } // Update the printer choosers, update the dirty flags. - preset_bundle.printers.update_plater_ui(p->combo_printer); + p->combo_printer->update(); // Update the filament choosers to only contain the compatible presets, update the color preview, // update the dirty flags. if (print_tech == ptFFF) { - for (size_t i = 0; i < p->combos_filament.size(); ++i) - preset_bundle.update_plater_filament_ui(i, p->combos_filament[i]); + for (PlaterPresetComboBox* cb : p->combos_filament) + cb->update(); } } @@ -1010,23 +863,22 @@ void Sidebar::update_presets(Preset::Type preset_type) preset_bundle.set_filament_preset(0, name); } - for (size_t i = 0; i < filament_cnt; i++) { - preset_bundle.update_plater_filament_ui(i, p->combos_filament[i]); - } + for (size_t i = 0; i < filament_cnt; i++) + p->combos_filament[i]->update(); break; } case Preset::TYPE_PRINT: - preset_bundle.prints.update_plater_ui(p->combo_print); + p->combo_print->update(); break; case Preset::TYPE_SLA_PRINT: - preset_bundle.sla_prints.update_plater_ui(p->combo_sla_print); + p->combo_sla_print->update(); break; case Preset::TYPE_SLA_MATERIAL: - preset_bundle.sla_materials.update_plater_ui(p->combo_sla_material); + p->combo_sla_material->update(); break; case Preset::TYPE_PRINTER: @@ -1062,18 +914,14 @@ void Sidebar::msw_rescale() p->mode_sizer->msw_rescale(); - // Rescale preset comboboxes in respect to the current em_unit ... - for (PresetComboBox* combo : std::vector { p->combo_print, + for (PlaterPresetComboBox* combo : std::vector { p->combo_print, p->combo_sla_print, p->combo_sla_material, p->combo_printer } ) combo->msw_rescale(); - for (PresetComboBox* combo : p->combos_filament) + for (PlaterPresetComboBox* combo : p->combos_filament) combo->msw_rescale(); - // ... then refill them and set min size to correct layout of the sidebar - update_all_preset_comboboxes(); - p->frequently_changed_parameters->msw_rescale(); p->object_list->msw_rescale(); p->object_manipulation->msw_rescale(); @@ -1096,12 +944,12 @@ void Sidebar::sys_color_changed() { // Update preset comboboxes in respect to the system color ... // combo->msw_rescale() updates icon on button, so use it - for (PresetComboBox* combo : std::vector{ p->combo_print, + for (PlaterPresetComboBox* combo : std::vector{ p->combo_print, p->combo_sla_print, p->combo_sla_material, p->combo_printer }) combo->msw_rescale(); - for (PresetComboBox* combo : p->combos_filament) + for (PlaterPresetComboBox* combo : p->combos_filament) combo->msw_rescale(); // ... then refill them and set min size to correct layout of the sidebar @@ -1458,7 +1306,7 @@ void Sidebar::update_ui_from_settings() update_sliced_info_sizer(); } -std::vector& Sidebar::combos_filament() +std::vector& Sidebar::combos_filament() { return p->combos_filament; } @@ -3339,7 +3187,7 @@ void Plater::priv::set_current_panel(wxPanel* panel) void Plater::priv::on_select_preset(wxCommandEvent &evt) { auto preset_type = static_cast(evt.GetInt()); - auto *combo = static_cast(evt.GetEventObject()); + auto *combo = static_cast(evt.GetEventObject()); // see https://github.com/prusa3d/PrusaSlicer/issues/3889 // Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender"), @@ -3368,7 +3216,7 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt) // TODO: ? if (preset_type == Preset::TYPE_FILAMENT && sidebar->is_multifilament()) { // Only update the plater UI for the 2nd and other filaments. - wxGetApp().preset_bundle->update_plater_filament_ui(idx, combo); + combo->update(); } else { wxWindowUpdateLocker noUpdates(sidebar->presets_panel()); @@ -5154,12 +5002,12 @@ void Plater::on_extruders_change(size_t num_extruders) size_t i = choices.size(); while ( i < num_extruders ) { - PresetComboBox* choice/*{ nullptr }*/; + PlaterPresetComboBox* choice/*{ nullptr }*/; sidebar().init_filament_combo(&choice, i); choices.push_back(choice); // initialize selection - wxGetApp().preset_bundle->update_plater_filament_ui(i, choice); + choice->update(); ++i; } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 5d60e006b..d2acc7632 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -6,14 +6,12 @@ #include #include -#include #include "Preset.hpp" #include "Selection.hpp" #include "libslic3r/BoundingBox.hpp" #include "Jobs/Job.hpp" -#include "wxExtensions.hpp" #include "Search.hpp" class wxButton; @@ -50,46 +48,13 @@ class Mouse3DController; struct Camera; class Bed3D; class GLToolbar; +class PlaterPresetComboBox; using t_optgroups = std::vector >; class Plater; enum class ActionButtonType : int; -class PresetComboBox : public PresetBitmapComboBox -{ -public: - PresetComboBox(wxWindow *parent, Preset::Type preset_type); - ~PresetComboBox(); - - ScalableButton* edit_btn { nullptr }; - - enum LabelItemType { - LABEL_ITEM_MARKER = 0xffffff01, - LABEL_ITEM_WIZARD_PRINTERS, - LABEL_ITEM_WIZARD_FILAMENTS, - LABEL_ITEM_WIZARD_MATERIALS, - - LABEL_ITEM_MAX, - }; - - void set_label_marker(int item, LabelItemType label_item_type = LABEL_ITEM_MARKER); - void set_extruder_idx(const int extr_idx) { extruder_idx = extr_idx; } - int get_extruder_idx() const { return extruder_idx; } - int em_unit() const { return m_em_unit; } - void check_selection(int selection); - - void msw_rescale(); - -private: - typedef std::size_t Marker; - - Preset::Type preset_type; - int last_selected; - int extruder_idx = -1; - int m_em_unit; -}; - class Sidebar : public wxPanel { ConfigOptionMode m_mode; @@ -101,7 +66,7 @@ public: Sidebar &operator=(const Sidebar &) = delete; ~Sidebar(); - void init_filament_combo(PresetComboBox **combo, const int extr_idx); + void init_filament_combo(PlaterPresetComboBox **combo, const int extr_idx); void remove_unused_filament_combos(const size_t current_extruder_count); void update_all_preset_comboboxes(); void update_presets(Slic3r::Preset::Type preset_type); @@ -139,7 +104,7 @@ public: void update_searcher(); void update_ui_from_settings(); - std::vector& combos_filament(); + std::vector& combos_filament(); Search::OptionsSearcher& get_searcher(); std::string& get_search_line(); diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp index d810c399d..883dc438a 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/slic3r/GUI/Preset.cpp @@ -2,9 +2,7 @@ #include "Preset.hpp" #include "AppConfig.hpp" -#include "BitmapCache.hpp" #include "I18N.hpp" -#include "wxExtensions.hpp" #ifdef _MSC_VER #define WIN32_LEAN_AND_MEAN @@ -30,15 +28,9 @@ #include #include -#include -#include -#include -#include - #include "libslic3r/libslic3r.h" #include "libslic3r/Utils.hpp" #include "libslic3r/PlaceholderParser.hpp" -#include "Plater.hpp" using boost::property_tree::ptree; @@ -590,10 +582,7 @@ const std::vector& Preset::sla_printer_options() PresetCollection::PresetCollection(Preset::Type type, const std::vector &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name) : m_type(type), m_edited_preset(type, "", false), - m_idx_selected(0), - m_bitmap_main_frame(new wxBitmap), - m_bitmap_add(new wxBitmap), - m_bitmap_cache(new GUI::BitmapCache) + m_idx_selected(0) { // Insert just the default preset. this->add_default_preset(keys, defaults, default_name); @@ -602,12 +591,6 @@ PresetCollection::PresetCollection(Preset::Type type, const std::vectorget_selected_idx() == size_t(-1)) @@ -1119,279 +1092,15 @@ size_t PresetCollection::update_compatible_internal(const PresetWithVendorProfil // Delete the current preset, activate the first visible preset. //void PresetCollection::delete_current_preset(); -// Update the wxChoice UI component from this list of presets. -// Hide the -void PresetCollection::update_plater_ui(GUI::PresetComboBox *ui) -{ - if (ui == nullptr) - return; - - // Otherwise fill in the list from scratch. - ui->Freeze(); - ui->Clear(); - size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected - - const Preset &selected_preset = this->get_selected_preset(); - // Show wide icons if the currently selected preset is not compatible with the current printer, - // and draw a red flag in front of the selected preset. - bool wide_icons = ! selected_preset.is_compatible && m_bitmap_incompatible != nullptr; - - /* It's supposed that standard size of an icon is 16px*16px for 100% scaled display. - * So set sizes for solid_colored icons used for filament preset - * and scale them in respect to em_unit value - */ - const float scale_f = ui->em_unit() * 0.1f; - const int icon_height = 16 * scale_f + 0.5f; - const int icon_width = 16 * scale_f + 0.5f; - const int thin_space_icon_width = 4 * scale_f + 0.5f; - const int wide_space_icon_width = 6 * scale_f + 0.5f; - - std::map nonsys_presets; - wxString selected = ""; - wxString tooltip = ""; - if (!this->m_presets.front().is_visible) - ui->set_label_marker(ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap)); - for (size_t i = this->m_presets.front().is_visible ? 0 : m_num_default_presets; i < this->m_presets.size(); ++ i) { - const Preset &preset = this->m_presets[i]; - if (! preset.is_visible || (! preset.is_compatible && i != m_idx_selected)) - continue; - - std::string bitmap_key = ""; - // !!! Temporary solution, till refactoring: create and use "sla_printer" icon instead of m_bitmap_main_frame - wxBitmap main_bmp = m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap; - if (m_type == Preset::TYPE_PRINTER && preset.printer_technology()==ptSLA ) { - bitmap_key = "sla_printer"; - main_bmp = create_scaled_bitmap("sla_printer"); - } - - // 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 += preset.is_compatible ? ",cmpt" : ",ncmpt"; - bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst"; - wxBitmap *bmp = m_bitmap_cache->find(bitmap_key); - if (bmp == nullptr) { - // Create the bitmap with color bars. - std::vector bmps; - if (wide_icons) - // Paint a red flag for incompatible presets. - bmps.emplace_back(preset.is_compatible ? m_bitmap_cache->mkclear(icon_width, icon_height) : *m_bitmap_incompatible); - // Paint the color bars. - bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height)); - bmps.emplace_back(main_bmp); - // Paint a lock at the system presets. - bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height)); - bmps.emplace_back((preset.is_system || preset.is_default) ? *m_bitmap_lock : m_bitmap_cache->mkclear(icon_width, icon_height)); - bmp = m_bitmap_cache->insert(bitmap_key, bmps); - } - - const std::string name = preset.alias.empty() ? preset.name : preset.alias; - if (preset.is_default || preset.is_system) { - ui->Append(wxString::FromUTF8((/*preset.*/name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), - (bmp == 0) ? main_bmp : *bmp); - if (i == m_idx_selected || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX) { - selected_preset_item = ui->GetCount() - 1; - tooltip = wxString::FromUTF8(preset.name.c_str()); - } - } - else - { - nonsys_presets.emplace(wxString::FromUTF8((/*preset.*/name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), bmp/*preset.is_compatible*/); - if (i == m_idx_selected) { - selected = wxString::FromUTF8((/*preset.*/name + (preset.is_dirty ? g_suffix_modified : "")).c_str()); - tooltip = wxString::FromUTF8(preset.name.c_str()); - } - } - if (i + 1 == m_num_default_presets) - ui->set_label_marker(ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap)); - } - if (!nonsys_presets.empty()) - { - ui->set_label_marker(ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap)); - for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { - ui->Append(it->first, *it->second); - if (it->first == selected || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX) - selected_preset_item = ui->GetCount() - 1; - } - } - 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"; - wxBitmap *bmp = m_bitmap_cache->find(bitmap_key); - if (bmp == nullptr) { - // Create the bitmap with color bars. - std::vector bmps; - if (wide_icons) - // Paint a red flag for incompatible presets. - bmps.emplace_back(m_bitmap_cache->mkclear(icon_width, icon_height)); - // Paint the color bars. - bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height)); - bmps.emplace_back(*m_bitmap_main_frame); - // Paint a lock at the system presets. - bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height)); -// bmps.emplace_back(m_bitmap_add ? *m_bitmap_add : wxNullBitmap); - bmps.emplace_back(create_scaled_bitmap("edit_uni")); - bmp = m_bitmap_cache->insert(bitmap_key, bmps); - } - if (m_type == Preset::TYPE_SLA_MATERIAL) - ui->set_label_marker(ui->Append(PresetCollection::separator(L("Add/Remove materials")), *bmp), GUI::PresetComboBox::LABEL_ITEM_WIZARD_MATERIALS); - else - ui->set_label_marker(ui->Append(PresetCollection::separator(L("Add/Remove printers")), *bmp), GUI::PresetComboBox::LABEL_ITEM_WIZARD_PRINTERS); - } - - /* But, if selected_preset_item is still equal to INT_MAX, it means that - * there is no presets added to the list. - * So, select last combobox item ("Add/Remove preset") - */ - if (selected_preset_item == INT_MAX) - selected_preset_item = ui->GetCount() - 1; - - ui->SetSelection(selected_preset_item); - ui->SetToolTip(tooltip.IsEmpty() ? ui->GetString(selected_preset_item) : tooltip); - ui->check_selection(selected_preset_item); - ui->Thaw(); - - // Update control min size after rescale (changed Display DPI under MSW) - if (ui->GetMinWidth() != 20 * ui->em_unit()) - ui->SetMinSize(wxSize(20 * ui->em_unit(), ui->GetSize().GetHeight())); -} - -size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompatible, const int em/* = 10*/) -{ - if (ui == nullptr) - return 0; - ui->Freeze(); - ui->Clear(); - size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected - - /* It's supposed that standard size of an icon is 16px*16px for 100% scaled display. - * So set sizes for solid_colored(empty) icons used for preset - * and scale them in respect to em_unit value - */ - const float scale_f = em * 0.1f; - const int icon_height = 16 * scale_f + 0.5f; - const int icon_width = 16 * scale_f + 0.5f; - - std::map nonsys_presets; - wxString selected = ""; - if (!this->m_presets.front().is_visible) - ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap); - for (size_t i = this->m_presets.front().is_visible ? 0 : m_num_default_presets; i < this->m_presets.size(); ++i) { - const Preset &preset = this->m_presets[i]; - if (! preset.is_visible || (! show_incompatible && ! preset.is_compatible && i != m_idx_selected)) - continue; - std::string bitmap_key = "tab"; - - // !!! Temporary solution, till refactoring: create and use "sla_printer" icon instead of m_bitmap_main_frame - wxBitmap main_bmp = m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap; - if (m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA) { - bitmap_key = "sla_printer"; - main_bmp = create_scaled_bitmap("sla_printer"); - } - - bitmap_key += preset.is_compatible ? ",cmpt" : ",ncmpt"; - bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst"; - wxBitmap *bmp = m_bitmap_cache->find(bitmap_key); - if (bmp == nullptr) { - // Create the bitmap with color bars. - std::vector bmps; - const wxBitmap* tmp_bmp = preset.is_compatible ? m_bitmap_compatible : m_bitmap_incompatible; - bmps.emplace_back((tmp_bmp == 0) ? main_bmp : *tmp_bmp); - // Paint a lock at the system presets. - bmps.emplace_back((preset.is_system || preset.is_default) ? *m_bitmap_lock : m_bitmap_cache->mkclear(icon_width, icon_height)); - bmp = m_bitmap_cache->insert(bitmap_key, bmps); - } - - if (preset.is_default || preset.is_system) { - ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), - (bmp == 0) ? main_bmp : *bmp); - if (i == m_idx_selected || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX) - selected_preset_item = ui->GetCount() - 1; - } - else - { - nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), bmp/*preset.is_compatible*/); - if (i == m_idx_selected) - selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()); - } - if (i + 1 == m_num_default_presets) - ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap); - } - if (!nonsys_presets.empty()) - { - ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap); - for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { - ui->Append(it->first, *it->second); - if (it->first == selected || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX) - selected_preset_item = ui->GetCount() - 1; - } - } - if (m_type == Preset::TYPE_PRINTER) { - wxBitmap *bmp = m_bitmap_cache->find("edit_printer_list"); - if (bmp == nullptr) { - // Create the bitmap with color bars. - std::vector bmps; - bmps.emplace_back(*m_bitmap_main_frame); -// bmps.emplace_back(m_bitmap_add ? *m_bitmap_add : wxNullBitmap); - bmps.emplace_back(create_scaled_bitmap("edit_uni")); - bmp = m_bitmap_cache->insert("add_printer_tab", bmps); - } - ui->Append(PresetCollection::separator("Add a new printer"), *bmp); - } - - /* But, if selected_preset_item is still equal to INT_MAX, it means that - * there is no presets added to the list. - * So, select last combobox item ("Add/Remove preset") - */ - if (selected_preset_item == INT_MAX) - selected_preset_item = ui->GetCount() - 1; - - ui->SetSelection(selected_preset_item); - ui->SetToolTip(ui->GetString(selected_preset_item)); - ui->Thaw(); - return selected_preset_item; -} - -// Update a dirty floag of the current preset, update the labels of the UI component accordingly. +// Update a dirty flag of the current preset // Return true if the dirty flag changed. -bool PresetCollection::update_dirty_ui(wxBitmapComboBox *ui) +bool PresetCollection::update_dirty() { - wxWindowUpdateLocker noUpdates(ui); - // 1) Update the dirty flag of the current preset. bool was_dirty = this->get_selected_preset().is_dirty; bool is_dirty = current_is_dirty(); this->get_selected_preset().is_dirty = is_dirty; this->get_edited_preset().is_dirty = is_dirty; - // 2) Update the labels. - for (unsigned int ui_id = 0; ui_id < ui->GetCount(); ++ ui_id) { - std::string old_label = ui->GetString(ui_id).utf8_str().data(); - std::string preset_name = Preset::remove_suffix_modified(old_label); - const Preset *preset = this->find_preset(preset_name, false); -// The old_label could be the "----- system presets ------" or the "------- user presets --------" separator. -// assert(preset != nullptr); - if (preset != nullptr) { - std::string new_label = preset->is_dirty ? preset->name + g_suffix_modified : preset->name; - if (old_label != new_label) - ui->SetString(ui_id, wxString::FromUTF8(new_label.c_str())); - } - } -#ifdef __APPLE__ - // wxWidgets on OSX do not upload the text of the combo box line automatically. - // Force it to update by re-selecting. - ui->SetSelection(ui->GetSelection()); -#endif /* __APPLE __ */ + return was_dirty != is_dirty; } @@ -1605,16 +1314,6 @@ std::string PresetCollection::path_from_name(const std::string &new_name) const return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string(); } -void PresetCollection::clear_bitmap_cache() -{ - m_bitmap_cache->clear(); -} - -wxString PresetCollection::separator(const std::string &label) -{ - return wxString::FromUTF8(PresetCollection::separator_head()) + _(label) + wxString::FromUTF8(PresetCollection::separator_tail()); -} - const Preset& PrinterPresetCollection::default_preset_for(const DynamicPrintConfig &config) const { const ConfigOptionEnumGeneric *opt_printer_technology = config.opt("printer_technology"); @@ -1631,7 +1330,108 @@ const Preset* PrinterPresetCollection::find_by_model_id(const std::string &model return it != cend() ? &*it : nullptr; } +/* +PhysicalPrinter& PhysicalPrinterCollection::load_external_printer( + // Path to the profile source file (a G-code, an AMF or 3MF file, a config file) + const std::string& path, + // Name of the profile, derived from the source file name. + const std::string& name, + // Original name of the profile, extracted from the loaded config. Empty, if the name has not been stored. + const std::string& original_name, + // Config to initialize the preset from. + const DynamicPrintConfig& config, + // Select the preset after loading? + bool select) +{ + // Load the preset over a default preset, so that the missing fields are filled in from the default preset. + DynamicPrintConfig cfg(this->default_printer().config); + cfg.apply_only(config, cfg.keys(), true); + // Is there a preset already loaded with the name stored inside the config? + std::deque::iterator it = this->find_printer_internal(original_name); + bool found = it != m_printers.end() && it->name == original_name; + if (!found) { + // Try to match the original_name against the "renamed_from" profile names of loaded system profiles. + / * + it = this->find_preset_renamed(original_name); + found = it != m_presets.end(); + * / + } + if (found) { + if (profile_print_params_same(it->config, cfg)) { + // The preset exists and it matches the values stored inside config. + if (select) + this->select_printer(it - m_printers.begin()); + return *it; + } + if (profile_host_params_same_or_anonymized(it->config, cfg) == ProfileHostParams::Anonymized) { + // The project being loaded is anonymized. Replace the empty host keys of the loaded profile with the data from the original profile. + // See "Octoprint Settings when Opening a .3MF file" GH issue #3244 + auto opt_update = [it, &cfg](const std::string& opt_key) { + auto opt = it->config.option(opt_key); + if (opt != nullptr) + cfg.set_key_value(opt_key, opt->clone()); + }; + opt_update("print_host"); + opt_update("printhost_apikey"); + opt_update("printhost_cafile"); + } + } + // The external preset does not match an internal preset, load the external preset. + std::string new_name; + for (size_t idx = 0;; ++idx) { + std::string suffix; + if (original_name.empty()) { + if (idx > 0) + suffix = " (" + std::to_string(idx) + ")"; + } + else { + if (idx == 0) + suffix = " (" + original_name + ")"; + else + suffix = " (" + original_name + "-" + std::to_string(idx) + ")"; + } + new_name = name + suffix; + it = this->find_printer_internal(new_name); + if (it == m_printers.end() || it->name != new_name) + // Unique profile name. Insert a new profile. + break; + if (profile_print_params_same(it->config, cfg)) { + // The preset exists and it matches the values stored inside config. + if (select) + this->select_printer(it - m_printers.begin()); + return *it; + } + // Form another profile name. + } + // Insert a new profile. + PhysicalPrinter& printer = this->load_printer(path, new_name, std::move(cfg), select); + return printer; +} + +void PhysicalPrinterCollection::save_printer(const std::string& new_name) +{ + // 1) Find the printer with a new_name or create a new one, + // initialize it with the edited config. + auto it = this->find_printer_internal(new_name); + if (it != m_printers.end() && it->name == new_name) { + // Preset with the same name found. + PhysicalPrinter& printer = *it; + // Overwriting an existing preset. + printer.config = std::move(m_edited_printer.config); + } + else { + // Creating a new printer. + PhysicalPrinter& printer = *m_printers.insert(it, m_edited_printer); + std::string old_name = printer.name; + printer.name = new_name; + } + // 2) Activate the saved preset. + this->select_printer_by_name(new_name, true); + // 3) Store the active preset to disk. + this->get_selected_preset().save(); +} +*/ namespace PresetUtils { const VendorProfile::PrinterModel* system_printer_model(const Preset &preset) { diff --git a/src/slic3r/GUI/Preset.hpp b/src/slic3r/GUI/Preset.hpp index dc0078091..8a8fa024b 100644 --- a/src/slic3r/GUI/Preset.hpp +++ b/src/slic3r/GUI/Preset.hpp @@ -24,11 +24,6 @@ namespace Slic3r { class AppConfig; class PresetBundle; -namespace GUI { - class BitmapCache; - class PresetComboBox; -} - enum ConfigFileType { CONFIG_FILE_TYPE_UNKNOWN, @@ -322,18 +317,6 @@ public: // returns true if the preset was deleted successfully. bool delete_preset(const std::string& name); - // Load default bitmap to be placed at the wxBitmapComboBox of a MainFrame. - void load_bitmap_default(const std::string &file_name); - - // Load "add new printer" bitmap to be placed at the wxBitmapComboBox of a MainFrame. - void load_bitmap_add(const std::string &file_name); - - // Compatible & incompatible marks, to be placed at the wxBitmapComboBox items. - void set_bitmap_compatible (const wxBitmap *bmp) { m_bitmap_compatible = bmp; } - void set_bitmap_incompatible(const wxBitmap *bmp) { m_bitmap_incompatible = bmp; } - void set_bitmap_lock (const wxBitmap *bmp) { m_bitmap_lock = bmp; } - void set_bitmap_lock_open (const wxBitmap *bmp) { m_bitmap_lock_open = bmp; } - // Enable / disable the "- default -" preset. void set_default_suppressed(bool default_suppressed); bool is_default_suppressed() const { return m_default_suppressed; } @@ -446,18 +429,9 @@ public: // Return a sorted list of system preset names. std::vector system_preset_names() const; - // Update the choice UI from the list of presets. - // If show_incompatible, all presets are shown, otherwise only the compatible presets are shown. - // If an incompatible preset is selected, it is shown as well. - size_t update_tab_ui(wxBitmapComboBox *ui, bool show_incompatible, const int em = 10); - // Update the choice UI from the list of presets. - // Only the compatible presets are shown. - // If an incompatible preset is selected, it is shown as well. - void update_plater_ui(GUI::PresetComboBox *ui); - - // Update a dirty floag of the current preset, update the labels of the UI component accordingly. + // Update a dirty flag of the current preset // Return true if the dirty flag changed. - bool update_dirty_ui(wxBitmapComboBox *ui); + bool update_dirty(); // Select a profile by its name. Return true if the selection changed. // Without force, the selection is only updated if the index changes. @@ -467,16 +441,7 @@ public: // Generate a file path from a profile name. Add the ".ini" suffix if it is missing. std::string path_from_name(const std::string &new_name) const; - void clear_bitmap_cache(); - -#ifdef __linux__ - static const char* separator_head() { return "------- "; } - static const char* separator_tail() { return " -------"; } -#else /* __linux__ */ - static const char* separator_head() { return "————— "; } - static const char* separator_tail() { return " —————"; } -#endif /* __linux__ */ - static wxString separator(const std::string &label); + size_t num_default_presets() { return m_num_default_presets; } protected: // Select a preset, if it exists. If it does not exist, select an invalid (-1) index. @@ -547,23 +512,10 @@ private: // Is the "- default -" preset suppressed? bool m_default_suppressed = true; size_t m_num_default_presets = 0; - // Compatible & incompatible marks, to be placed at the wxBitmapComboBox items of a Plater. - // These bitmaps are not owned by PresetCollection, but by a PresetBundle. - const wxBitmap *m_bitmap_compatible = nullptr; - const wxBitmap *m_bitmap_incompatible = nullptr; - const wxBitmap *m_bitmap_lock = nullptr; - const wxBitmap *m_bitmap_lock_open = nullptr; - // Marks placed at the wxBitmapComboBox of a MainFrame. - // These bitmaps are owned by PresetCollection. - wxBitmap *m_bitmap_main_frame; - // "Add printer profile" icon, owned by PresetCollection. - wxBitmap *m_bitmap_add; + // Path to the directory to store the config files into. std::string m_dir_path; - // Caching color bitmaps for the filament combo box. - GUI::BitmapCache *m_bitmap_cache = nullptr; - // to access select_preset_by_name_strict() friend class PresetBundle; }; @@ -585,6 +537,178 @@ namespace PresetUtils { const VendorProfile::PrinterModel* system_printer_model(const Preset &preset); } // namespace PresetUtils + +////////////////////////////////////////////////////////////////////// + +class PhysicalPrinter +{ +public: + PhysicalPrinter(const std::string& name) : name(name) {} + + // Name of the Physical Printer, usually derived form the file name. + std::string name; + // File name of the Physical Printer. + std::string file; + // Name of the related Printer preset + std::string preset_name; + + // Has this profile been loaded? + bool loaded = false; + + // Configuration data, loaded from a file, or set from the defaults. + DynamicPrintConfig config; + + void save() { this->config.save(this->file); } + + // Return a printer technology, return ptFFF if the printer technology is not set. + static PrinterTechnology printer_technology(const DynamicPrintConfig& cfg) { + auto* opt = cfg.option>("printer_technology"); + // The following assert may trigger when importing some legacy profile, + // but it is safer to keep it here to capture the cases where the "printer_technology" key is queried, where it should not. + return (opt == nullptr) ? ptFFF : opt->value; + } + PrinterTechnology printer_technology() const { return printer_technology(this->config); } + + // Sort lexicographically by a preset name. The preset name shall be unique across a single PresetCollection. + bool operator<(const Preset& other) const { return this->name < other.name; } + +protected: + friend class PhysicalPrinterCollection; +}; +/* +// Collections of presets of the same type (one of the Print, Filament or Printer type). +class PhysicalPrinterCollection +{ +public: + // Initialize the PresetCollection with the "- default -" preset. + PhysicalPrinterCollection(const std::vector& keys) : m_idx_selected(0) {} + ~PhysicalPrinterCollection() {} + + typedef std::deque::iterator Iterator; + typedef std::deque::const_iterator ConstIterator; + Iterator begin() { return m_printers.begin(); } + ConstIterator begin() const { return m_printers.cbegin(); } + ConstIterator cbegin() const { return m_printers.cbegin(); } + Iterator end() { return m_printers.end(); } + ConstIterator end() const { return m_printers.cend(); } + ConstIterator cend() const { return m_printers.cend(); } + + void reset(bool delete_files) {}; + + const std::deque& operator()() const { return m_printers; } + + // Load ini files of the particular type from the provided directory path. + void load_printers(const std::string& dir_path, const std::string& subdir){}; + + // Load a preset from an already parsed config file, insert it into the sorted sequence of presets + // and select it, losing previous modifications. + PhysicalPrinter& load_printer(const std::string& path, const std::string& name, const DynamicPrintConfig& config, bool select = true); + PhysicalPrinter& load_printer(const std::string& path, const std::string& name, DynamicPrintConfig&& config, bool select = true); + + PhysicalPrinter& load_external_printer( + // Path to the profile source file (a G-code, an AMF or 3MF file, a config file) + const std::string& path, + // Name of the profile, derived from the source file name. + const std::string& name, + // Original name of the profile, extracted from the loaded config. Empty, if the name has not been stored. + const std::string& original_name, + // Config to initialize the preset from. + const DynamicPrintConfig& config, + // Select the preset after loading? + bool select = true); + + // Save the printer under a new name. If the name is different from the old one, + // a new printer is stored into the list of printers. + // ? New printer is activated. + void save_printer(const std::string& new_name); + + // Delete the current preset, activate the first visible preset. + // returns true if the preset was deleted successfully. + bool delete_current_printer() {return true;} + // Delete the current preset, activate the first visible preset. + // returns true if the preset was deleted successfully. + bool delete_printer(const std::string& name) { return true; } + + // Select a printer. If an invalid index is provided, the first visible printer is selected. + PhysicalPrinter& select_printer(size_t idx); + // Return the selected preset, without the user modifications applied. + PhysicalPrinter& get_selected_preset() { return m_printers[m_idx_selected]; } + const PhysicalPrinter& get_selected_preset() const { return m_printers[m_idx_selected]; } + 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_preset_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_preset().name; } + PhysicalPrinter& get_edited_preset() { return m_edited_printer; } + const PhysicalPrinter& get_edited_preset() const { return m_edited_printer; } + + // Return a preset possibly with modifications. + PhysicalPrinter& default_printer(size_t idx = 0) { return m_printers[idx]; } + const PhysicalPrinter& default_printer(size_t idx = 0) const { return m_printers[idx]; } + + // used to update preset_choice from Tab + const std::deque& get_presets() const { return m_printers; } + size_t get_idx_selected() { return m_idx_selected; } + + // Return a preset by an index. If the preset is active, a temporary copy is returned. + PhysicalPrinter& printer(size_t idx) { return (idx == m_idx_selected) ? m_edited_printer : m_printers[idx]; } + const PhysicalPrinter& printer(size_t idx) const { return const_cast(this)->printer(idx); } + + // Return a preset by its name. If the preset is active, a temporary copy is returned. + // If a preset is not found by its name, null is returned. + PhysicalPrinter* find_printer(const std::string& name, bool first_visible_if_not_found = false); + const PhysicalPrinter* find_printer(const std::string& name, bool first_visible_if_not_found = false) const + { + return const_cast(this)->find_printer(name, first_visible_if_not_found); + } + + // Return number of presets including the "- default -" preset. + size_t size() const { return m_printers.size(); } + + // Select a profile by its name. Return true if the selection changed. + // Without force, the selection is only updated if the index changes. + // With force, the changes are reverted if the new index is the same as the old index. + bool select_printer_by_name(const std::string& name, bool force) {}; + + // Generate a file path from a profile name. Add the ".ini" suffix if it is missing. + std::string path_from_name(const std::string& new_name) const; + +private: +// PhysicalPrinterCollection(); + PhysicalPrinterCollection(const PhysicalPrinterCollection& other); + PhysicalPrinterCollection& operator=(const PhysicalPrinterCollection& other); + + // Find a preset position in the sorted list of presets. + // The "-- default -- " preset is always the first, so it needs + // to be handled differently. + // If a preset does not exist, an iterator is returned indicating where to insert a preset with the same name. + std::deque::iterator find_printer_internal(const std::string& name) + { + PhysicalPrinter key(name); + auto it = std::lower_bound(m_printers.begin()+0, m_printers.end(), key); + return it; + } + std::deque::const_iterator find_printer_internal(const std::string& name) const + { + return const_cast(this)->find_printer_internal(name); + } + + static std::vector dirty_options(const Preset* edited, const Preset* reference, const bool is_printer_type = false); + + // List of presets, starting with the "- default -" preset. + // Use deque to force the container to allocate an object per each entry, + // so that the addresses of the presets don't change during resizing of the container. + std::deque m_printers; + // Initially this printer contains a copy of the selected printer. Later on, this copy may be modified by the user. + PhysicalPrinter m_edited_printer; + // Selected preset. + size_t m_idx_selected; + + // Path to the directory to store the config files into. + std::string m_dir_path; +}; + +////////////////////////////////////////////////////////////////////// +*/ + } // namespace Slic3r #endif /* slic3r_Preset_hpp_ */ diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp index ba806a0b2..024884b00 100644 --- a/src/slic3r/GUI/PresetBundle.cpp +++ b/src/slic3r/GUI/PresetBundle.cpp @@ -1,12 +1,10 @@ #include #include "PresetBundle.hpp" -#include "BitmapCache.hpp" #include "Plater.hpp" -#include "I18N.hpp" -#include "wxExtensions.hpp" #include +#include #include #include #include @@ -21,16 +19,13 @@ #include #include -#include #include -#include -#include -#include #include "libslic3r/libslic3r.h" #include "libslic3r/Utils.hpp" #include "libslic3r/Model.hpp" #include "GUI_App.hpp" +#include "libslic3r/CustomGCode.hpp" // Store the print/filament/printer presets into a "presets" subdirectory of the Slic3rPE config dir. @@ -52,12 +47,7 @@ PresetBundle::PresetBundle() : filaments(Preset::TYPE_FILAMENT, Preset::filament_options(), static_cast(FullPrintConfig::defaults())), sla_materials(Preset::TYPE_SLA_MATERIAL, Preset::sla_material_options(), static_cast(SLAFullPrintConfig::defaults())), sla_prints(Preset::TYPE_SLA_PRINT, Preset::sla_print_options(), static_cast(SLAFullPrintConfig::defaults())), - printers(Preset::TYPE_PRINTER, Preset::printer_options(), static_cast(FullPrintConfig::defaults()), "- default FFF -"), - m_bitmapCompatible(new wxBitmap), - m_bitmapIncompatible(new wxBitmap), - m_bitmapLock(new wxBitmap), - m_bitmapLockOpen(new wxBitmap), - m_bitmapCache(new GUI::BitmapCache) + printers(Preset::TYPE_PRINTER, Preset::printer_options(), static_cast(FullPrintConfig::defaults()), "- default FFF -") { if (wxImage::FindHandler(wxBITMAP_TYPE_PNG) == nullptr) wxImage::AddHandler(new wxPNGHandler); @@ -112,16 +102,6 @@ PresetBundle::PresetBundle() : preset.inherits(); } - // Load the default preset bitmaps. - // #ys_FIXME_to_delete we'll load them later, using em_unit() -// this->prints .load_bitmap_default("cog"); -// this->sla_prints .load_bitmap_default("package_green.png"); -// this->filaments .load_bitmap_default("spool.png"); -// this->sla_materials.load_bitmap_default("package_green.png"); -// this->printers .load_bitmap_default("printer_empty.png"); -// this->printers .load_bitmap_add("add.png"); -// this->load_compatible_bitmaps(); - // Re-activate the default presets, so their "edited" preset copies will be updated with the additional configuration values above. this->prints .select_preset(0); this->sla_prints .select_preset(0); @@ -134,20 +114,6 @@ PresetBundle::PresetBundle() : PresetBundle::~PresetBundle() { - assert(m_bitmapCompatible != nullptr); - assert(m_bitmapIncompatible != nullptr); - assert(m_bitmapLock != nullptr); - assert(m_bitmapLockOpen != nullptr); - delete m_bitmapCompatible; - m_bitmapCompatible = nullptr; - delete m_bitmapIncompatible; - m_bitmapIncompatible = nullptr; - delete m_bitmapLock; - m_bitmapLock = nullptr; - delete m_bitmapLockOpen; - m_bitmapLockOpen = nullptr; - delete m_bitmapCache; - m_bitmapCache = nullptr; } void PresetBundle::reset(bool delete_files) @@ -486,36 +452,6 @@ void PresetBundle::export_selections(AppConfig &config) config.set("presets", "printer", printers.get_selected_preset_name()); } -void PresetBundle::load_compatible_bitmaps() -{ - *m_bitmapCompatible = create_scaled_bitmap("flag_green"); - *m_bitmapIncompatible = create_scaled_bitmap("flag_red"); - *m_bitmapLock = create_scaled_bitmap("lock_closed"); - *m_bitmapLockOpen = create_scaled_bitmap("lock_open"); - - prints .set_bitmap_compatible(m_bitmapCompatible); - filaments .set_bitmap_compatible(m_bitmapCompatible); - sla_prints .set_bitmap_compatible(m_bitmapCompatible); - sla_materials.set_bitmap_compatible(m_bitmapCompatible); - - prints .set_bitmap_incompatible(m_bitmapIncompatible); - filaments .set_bitmap_incompatible(m_bitmapIncompatible); - sla_prints .set_bitmap_incompatible(m_bitmapIncompatible); - sla_materials.set_bitmap_incompatible(m_bitmapIncompatible); - - prints .set_bitmap_lock(m_bitmapLock); - filaments .set_bitmap_lock(m_bitmapLock); - sla_prints .set_bitmap_lock(m_bitmapLock); - sla_materials.set_bitmap_lock(m_bitmapLock); - printers .set_bitmap_lock(m_bitmapLock); - - prints .set_bitmap_lock_open(m_bitmapLock); - filaments .set_bitmap_lock_open(m_bitmapLock); - sla_prints .set_bitmap_lock_open(m_bitmapLock); - sla_materials.set_bitmap_lock_open(m_bitmapLock); - printers .set_bitmap_lock_open(m_bitmapLock); -} - DynamicPrintConfig PresetBundle::full_config() const { return (this->printers.get_edited_preset().printer_technology() == ptFFF) ? @@ -886,7 +822,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool // 4) Load the project config values (the per extruder wipe matrix etc). this->project_config.apply_only(config, s_project_options); - update_custom_gcode_per_print_z_from_config(GUI::wxGetApp().plater()->model().custom_gcode_per_print_z, &this->project_config); + CustomGCode::update_custom_gcode_per_print_z_from_config(GUI::wxGetApp().plater()->model().custom_gcode_per_print_z, &this->project_config); break; } @@ -1544,207 +1480,11 @@ void PresetBundle::export_configbundle(const std::string &path, bool export_syst // an optional "(modified)" suffix will be removed from the filament name. void PresetBundle::set_filament_preset(size_t idx, const std::string &name) { - if (name.find_first_of(PresetCollection::separator_head()) == 0) - return; - - if (idx >= filament_presets.size()) + if (idx >= filament_presets.size()) filament_presets.resize(idx + 1, filaments.default_preset().name); filament_presets[idx] = Preset::remove_suffix_modified(name); } -void PresetBundle::load_default_preset_bitmaps() -{ - // Clear bitmap cache, before load new scaled default preset bitmaps - m_bitmapCache->clear(); - this->prints.clear_bitmap_cache(); - this->sla_prints.clear_bitmap_cache(); - this->filaments.clear_bitmap_cache(); - this->sla_materials.clear_bitmap_cache(); - this->printers.clear_bitmap_cache(); - - this->prints.load_bitmap_default("cog"); - this->sla_prints.load_bitmap_default("cog"); - this->filaments.load_bitmap_default("spool.png"); - this->sla_materials.load_bitmap_default("resin"); - this->printers.load_bitmap_default("printer"); - this->printers.load_bitmap_add("add.png"); - this->load_compatible_bitmaps(); -} - -void PresetBundle::update_plater_filament_ui(unsigned int idx_extruder, GUI::PresetComboBox *ui) -{ - if (ui == nullptr || this->printers.get_edited_preset().printer_technology() == ptSLA || - this->filament_presets.size() <= idx_extruder ) - return; - - unsigned char rgb[3]; - std::string extruder_color = this->printers.get_edited_preset().config.opt_string("extruder_colour", idx_extruder); - if (!m_bitmapCache->parse_color(extruder_color, rgb)) - // Extruder color is not defined. - extruder_color.clear(); - - // Fill in the list from scratch. - ui->Freeze(); - ui->Clear(); - size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected - - const Preset *selected_preset = this->filaments.find_preset(this->filament_presets[idx_extruder]); - // Show wide icons if the currently selected preset is not compatible with the current printer, - // and draw a red flag in front of the selected preset. - bool wide_icons = selected_preset != nullptr && ! selected_preset->is_compatible && m_bitmapIncompatible != nullptr; - assert(selected_preset != nullptr); - std::map nonsys_presets; - wxString selected_str = ""; - if (!this->filaments().front().is_visible) - ui->set_label_marker(ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap)); - - /* It's supposed that standard size of an icon is 16px*16px for 100% scaled display. - * So set sizes for solid_colored icons used for filament preset - * and scale them in respect to em_unit value - */ - const float scale_f = ui->em_unit() * 0.1f; - - // To avoid the errors of number rounding for different combination of monitor configuration, - // let use scaled 8px, as a smallest icon unit - const int icon_unit = 8 * scale_f + 0.5f; - const int normal_icon_width = 2 * icon_unit; //16 * scale_f + 0.5f; - const int thin_icon_width = icon_unit; //8 * scale_f + 0.5f; - const int wide_icon_width = 3 * icon_unit; //24 * scale_f + 0.5f; - - const int space_icon_width = 2 * scale_f + 0.5f; - - // To avoid asserts, each added bitmap to wxBitmapCombobox should be the same size, so - // set a bitmap height to m_bitmapLock->GetHeight() - // - // To avoid asserts, each added bitmap to wxBitmapCombobox should be the same size. - // But for some display scaling (for example 125% or 175%) normal_icon_width differs from icon width. - // So: - // for nonsystem presets set a width of empty bitmap to m_bitmapLock->GetWidth() - // for compatible presets set a width of empty bitmap to m_bitmapIncompatible->GetWidth() - // - // Note, under OSX we should use a Scaled Height/Width because of Retina scale -#ifdef __APPLE__ - const int icon_height = m_bitmapLock->GetScaledHeight(); - const int lock_icon_width = m_bitmapLock->GetScaledWidth(); - const int flag_icon_width = m_bitmapIncompatible->GetScaledWidth(); -#else - const int icon_height = m_bitmapLock->GetHeight(); - const int lock_icon_width = m_bitmapLock->GetWidth(); - const int flag_icon_width = m_bitmapIncompatible->GetWidth(); -#endif - - wxString tooltip = ""; - - for (int i = this->filaments().front().is_visible ? 0 : 1; i < int(this->filaments().size()); ++i) { - const Preset &preset = this->filaments.preset(i); - bool selected = this->filament_presets[idx_extruder] == preset.name; - if (! preset.is_visible || (! preset.is_compatible && ! selected)) - continue; - // Assign an extruder color to the selected item if the extruder color is defined. - std::string filament_rgb = preset.config.opt_string("filament_colour", 0); - std::string extruder_rgb = (selected && !extruder_color.empty()) ? extruder_color : filament_rgb; - bool single_bar = filament_rgb == extruder_rgb; - std::string bitmap_key = single_bar ? filament_rgb : filament_rgb + extruder_rgb; - // 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 += preset.is_compatible ? ",cmpt" : ",ncmpt"; - bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst"; - if (preset.is_dirty) - bitmap_key += ",drty"; - wxBitmap *bitmap = m_bitmapCache->find(bitmap_key); - if (bitmap == nullptr) { - // Create the bitmap with color bars. - std::vector bmps; - if (wide_icons) - // Paint a red flag for incompatible presets. - bmps.emplace_back(preset.is_compatible ? m_bitmapCache->mkclear(flag_icon_width, icon_height) : *m_bitmapIncompatible); - // Paint the color bars. - m_bitmapCache->parse_color(filament_rgb, rgb); - bmps.emplace_back(m_bitmapCache->mksolid(single_bar ? wide_icon_width : normal_icon_width, icon_height, rgb)); - if (! single_bar) { - m_bitmapCache->parse_color(extruder_rgb, rgb); - bmps.emplace_back(m_bitmapCache->mksolid(thin_icon_width, icon_height, rgb)); - } - // Paint a lock at the system presets. - bmps.emplace_back(m_bitmapCache->mkclear(space_icon_width, icon_height)); - bmps.emplace_back((preset.is_system || preset.is_default) ? *m_bitmapLock : m_bitmapCache->mkclear(lock_icon_width, icon_height)); -// (preset.is_dirty ? *m_bitmapLockOpen : *m_bitmapLock) : m_bitmapCache->mkclear(16, 16)); - bitmap = m_bitmapCache->insert(bitmap_key, bmps); - } - - const std::string name = preset.alias.empty() ? preset.name : preset.alias; - if (preset.is_default || preset.is_system) { - ui->Append(wxString::FromUTF8((/*preset.*/name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), - (bitmap == 0) ? wxNullBitmap : *bitmap); - if (selected || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX ) { - selected_preset_item = ui->GetCount() - 1; - tooltip = wxString::FromUTF8(preset.name.c_str()); - } - } - else - { - nonsys_presets.emplace(wxString::FromUTF8((/*preset.*/name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), - (bitmap == 0) ? &wxNullBitmap : bitmap); - if (selected) { - selected_str = wxString::FromUTF8((/*preset.*/name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); - tooltip = wxString::FromUTF8(preset.name.c_str()); - } - } - if (preset.is_default) - ui->set_label_marker(ui->Append(PresetCollection::separator(L("System presets")), wxNullBitmap)); - } - - if (!nonsys_presets.empty()) - { - ui->set_label_marker(ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap)); - for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { - ui->Append(it->first, *it->second); - if (it->first == selected_str || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX) { - selected_preset_item = ui->GetCount() - 1; - } - } - } - - std::string bitmap_key = ""; - if (wide_icons) - bitmap_key += "wide,"; - bitmap_key += "edit_preset_list"; - wxBitmap* bmp = m_bitmapCache->find(bitmap_key); - if (bmp == nullptr) { - // Create the bitmap with color bars. - std::vector bmps; - if (wide_icons) - // Paint a red flag for incompatible presets. - bmps.emplace_back(m_bitmapCache->mkclear(flag_icon_width, icon_height)); - // Paint the color bars + a lock at the system presets. - bmps.emplace_back(m_bitmapCache->mkclear(wide_icon_width+space_icon_width, icon_height)); - bmps.emplace_back(create_scaled_bitmap("edit_uni")); - bmp = m_bitmapCache->insert(bitmap_key, bmps); - } - ui->set_label_marker(ui->Append(PresetCollection::separator(L("Add/Remove filaments")), *bmp), GUI::PresetComboBox::LABEL_ITEM_WIZARD_FILAMENTS); - - /* But, if selected_preset_item is still equal to INT_MAX, it means that - * there is no presets added to the list. - * So, select last combobox item ("Add/Remove filaments") - */ - if (selected_preset_item == INT_MAX) - selected_preset_item = ui->GetCount() - 1; - - ui->SetSelection(selected_preset_item); - ui->SetToolTip(tooltip.IsEmpty() ? ui->GetString(selected_preset_item) : tooltip); - ui->check_selection(selected_preset_item); - ui->Thaw(); - - // Update control min size after rescale (changed Display DPI under MSW) - if (ui->GetMinWidth() != 20 * ui->em_unit()) - ui->SetMinSize(wxSize(20 * ui->em_unit(), ui->GetSize().GetHeight())); -} - void PresetBundle::set_default_suppressed(bool default_suppressed) { prints.set_default_suppressed(default_suppressed); diff --git a/src/slic3r/GUI/PresetBundle.hpp b/src/slic3r/GUI/PresetBundle.hpp index bf1bba21d..7d137bb7a 100644 --- a/src/slic3r/GUI/PresetBundle.hpp +++ b/src/slic3r/GUI/PresetBundle.hpp @@ -5,7 +5,6 @@ #include "Preset.hpp" #include -#include #include #include @@ -13,10 +12,6 @@ class wxWindow; namespace Slic3r { -namespace GUI { - class BitmapCache; -}; - // Bundle of Print + Filament + Printer presets. class PresetBundle { @@ -110,9 +105,6 @@ public: // Export a config bundle file containing all the presets and the names of the active presets. void export_configbundle(const std::string &path, bool export_system_settings = false); - // Update a filament selection combo box on the plater for an idx_extruder. - void update_plater_filament_ui(unsigned int idx_extruder, GUI::PresetComboBox *ui); - // Enable / disable the "- default -" preset. void set_default_suppressed(bool default_suppressed); @@ -132,8 +124,6 @@ public: void update_compatible(PresetSelectCompatibleType select_other_print_if_incompatible, PresetSelectCompatibleType select_other_filament_if_incompatible); void update_compatible(PresetSelectCompatibleType select_other_if_incompatible) { this->update_compatible(select_other_if_incompatible, select_other_if_incompatible); } - void load_default_preset_bitmaps(); - // Set the is_visible flag for printer vendors, printer models and printer variants // based on the user configuration. // If the "vendor" section is missing, enable all models and variants of the particular vendor. @@ -163,21 +153,9 @@ private: // If it is not an external config, then the config will be stored into the user profile directory. void load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config); void load_config_file_config_bundle(const std::string &path, const boost::property_tree::ptree &tree); - void load_compatible_bitmaps(); DynamicPrintConfig full_fff_config() const; DynamicPrintConfig full_sla_config() const; - - // Indicator, that the preset is compatible with the selected printer. - wxBitmap *m_bitmapCompatible; - // Indicator, that the preset is NOT compatible with the selected printer. - wxBitmap *m_bitmapIncompatible; - // Indicator, that the preset is system and not modified. - wxBitmap *m_bitmapLock; - // Indicator, that the preset is system and user modified. - wxBitmap *m_bitmapLockOpen; - // Caching color bitmaps for the filament combo box. - GUI::BitmapCache *m_bitmapCache; }; } // namespace Slic3r diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp new file mode 100644 index 000000000..380edb48a --- /dev/null +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -0,0 +1,794 @@ +#include "PresetComboBoxes.hpp" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "libslic3r/libslic3r.h" +#include "libslic3r/PrintConfig.hpp" + +#include "GUI.hpp" +#include "GUI_App.hpp" +#include "Plater.hpp" +#include "MainFrame.hpp" +#include "format.hpp" +#include "Tab.hpp" +#include "PresetBundle.hpp" +#include "PrintHostDialogs.hpp" +#include "ConfigWizard.hpp" +#include "../Utils/ASCIIFolding.hpp" +#include "../Utils/PrintHost.hpp" +#include "../Utils/FixModelByWin10.hpp" +#include "../Utils/UndoRedo.hpp" +#include "RemovableDriveManager.hpp" +#include "BitmapCache.hpp" + +using Slic3r::GUI::format_wxstr; + +static const std::pair THUMBNAIL_SIZE_3MF = { 256, 256 }; + +namespace Slic3r { +namespace GUI { + +// --------------------------------- +// *** PresetComboBox *** +// --------------------------------- + +/* For PresetComboBox we use bitmaps that are created from images that are already scaled appropriately for Retina + * (Contrary to the intuition, the `scale` argument for Bitmap's constructor doesn't mean + * "please scale this to such and such" but rather + * "the wxImage is already sized for backing scale such and such". ) + * Unfortunately, the constructor changes the size of wxBitmap too. + * Thus We need to use unscaled size value for bitmaps that we use + * to avoid scaled size of control items. + * For this purpose control drawing methods and + * control size calculation methods (virtual) are overridden. + **/ + +PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const wxSize& size) : + wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, size, 0, nullptr, wxCB_READONLY), + m_type(preset_type), + m_last_selected(wxNOT_FOUND), + m_em_unit(wxGetApp().em_unit()), + m_preset_bundle(wxGetApp().preset_bundle), + m_bitmap_cache(new BitmapCache) +{ + SetFont(wxGetApp().normal_font()); +#ifdef _WIN32 + // Workaround for ignoring CBN_EDITCHANGE events, which are processed after the content of the combo box changes, so that + // the index of the item inside CBN_EDITCHANGE may no more be valid. + EnableTextChangedEvents(false); +#endif /* _WIN32 */ + + switch (m_type) + { + case Preset::TYPE_PRINT: { + m_collection = &m_preset_bundle->prints; + m_main_bitmap_name = "cog"; + break; + } + case Preset::TYPE_FILAMENT: { + m_collection = &m_preset_bundle->filaments; + m_main_bitmap_name = "spool"; + break; + } + case Preset::TYPE_SLA_PRINT: { + m_collection = &m_preset_bundle->sla_prints; + m_main_bitmap_name = "cog"; + break; + } + case Preset::TYPE_SLA_MATERIAL: { + m_collection = &m_preset_bundle->sla_materials; + m_main_bitmap_name = "resin"; + break; + } + case Preset::TYPE_PRINTER: { + m_collection = &m_preset_bundle->printers; + m_main_bitmap_name = "printer"; + break; + } + default: break; + } + + m_bitmapCompatible = ScalableBitmap(nullptr, "flag_green"); + m_bitmapIncompatible = ScalableBitmap(nullptr, "flag_red"); + m_bitmapLock = ScalableBitmap(nullptr, "lock_closed"); + + // parameters for an icon's drawing + fill_width_height(); +} + +PresetComboBox::~PresetComboBox() +{ + delete m_bitmap_cache; + m_bitmap_cache = nullptr; +} + +void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type) +{ + this->SetClientData(item, (void*)label_item_type); +} + +void PresetComboBox::msw_rescale() +{ + m_em_unit = wxGetApp().em_unit(); + + m_bitmapLock.msw_rescale(); + m_bitmapIncompatible.msw_rescale(); + m_bitmapCompatible.msw_rescale(); + + // parameters for an icon's drawing + fill_width_height(); + + // update the control to redraw the icons + update(); +} + +void PresetComboBox::fill_width_height() +{ + // To avoid asserts, each added bitmap to wxBitmapCombobox should be the same size, so + // set a bitmap's height to m_bitmapLock->GetHeight() and norm_icon_width to m_bitmapLock->GetWidth() + icon_height = m_bitmapLock.GetBmpHeight(); + norm_icon_width = m_bitmapLock.GetBmpWidth(); + + /* It's supposed that standard size of an icon is 16px*16px for 100% scaled display. + * So set sizes for solid_colored icons used for filament preset + * and scale them in respect to em_unit value + */ + const float scale_f = (float)m_em_unit * 0.1f; + + thin_icon_width = lroundf(8 * scale_f); // analogue to 8px; + wide_icon_width = norm_icon_width + thin_icon_width; + + space_icon_width = lroundf(2 * scale_f); + thin_space_icon_width = 2 * space_icon_width; + wide_space_icon_width = 3 * space_icon_width; +} + +wxString PresetComboBox::separator(const std::string& label) +{ + return wxString::FromUTF8(separator_head()) + _(label) + wxString::FromUTF8(separator_tail()); +} + +#ifdef __APPLE__ +bool PresetComboBox::OnAddBitmap(const wxBitmap& bitmap) +{ + if (bitmap.IsOk()) + { + // we should use scaled! size values of bitmap + int width = (int)bitmap.GetScaledWidth(); + int height = (int)bitmap.GetScaledHeight(); + + if (m_usedImgSize.x < 0) + { + // If size not yet determined, get it from this image. + m_usedImgSize.x = width; + m_usedImgSize.y = height; + + // Adjust control size to vertically fit the bitmap + wxWindow* ctrl = GetControl(); + ctrl->InvalidateBestSize(); + wxSize newSz = ctrl->GetBestSize(); + wxSize sz = ctrl->GetSize(); + if (newSz.y > sz.y) + ctrl->SetSize(sz.x, newSz.y); + else + DetermineIndent(); + } + + wxCHECK_MSG(width == m_usedImgSize.x && height == m_usedImgSize.y, + false, + "you can only add images of same size"); + + return true; + } + + return false; +} + +void PresetComboBox::OnDrawItem(wxDC& dc, + const wxRect& rect, + int item, + int flags) const +{ + const wxBitmap& bmp = *(wxBitmap*)m_bitmaps[item]; + if (bmp.IsOk()) + { + // we should use scaled! size values of bitmap + wxCoord w = bmp.GetScaledWidth(); + wxCoord h = bmp.GetScaledHeight(); + + const int imgSpacingLeft = 4; + + // Draw the image centered + dc.DrawBitmap(bmp, + rect.x + (m_usedImgSize.x - w) / 2 + imgSpacingLeft, + rect.y + (rect.height - h) / 2, + true); + } + + wxString text = GetString(item); + if (!text.empty()) + dc.DrawText(text, + rect.x + m_imgAreaWidth + 1, + rect.y + (rect.height - dc.GetCharHeight()) / 2); +} +#endif + + +// --------------------------------- +// *** PlaterPresetComboBox *** +// --------------------------------- + +PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset_type) : + PresetComboBox(parent, preset_type, wxSize(15 * wxGetApp().em_unit(), -1)) +{ + Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &evt) { + auto selected_item = evt.GetSelection(); + + auto marker = reinterpret_cast(this->GetClientData(selected_item)); + 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; + dlg.ShowModal(); + return; + } + if (marker >= LABEL_ITEM_WIZARD_PRINTERS) { + ConfigWizard::StartPage sp = ConfigWizard::SP_WELCOME; + switch (marker) { + case LABEL_ITEM_WIZARD_PRINTERS: sp = ConfigWizard::SP_PRINTERS; break; + 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 ( this->m_last_selected != selected_item || m_collection->current_is_dirty() ) { + this->m_last_selected = selected_item; + evt.SetInt(this->m_type); + evt.Skip(); + } else { + evt.StopPropagation(); + } + }); + + if (m_type == Preset::TYPE_FILAMENT) + { + Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &event) { + const Preset* selected_preset = m_collection->find_preset(m_preset_bundle->filament_presets[m_extruder_idx]); + // Wide icons are shown if the currently selected preset is not compatible with the current printer, + // and red flag is drown in front of the selected preset. + bool wide_icons = selected_preset != nullptr && !selected_preset->is_compatible; + float scale = m_em_unit*0.1f; + + int shifl_Left = wide_icons ? int(scale * 16 + 0.5) : 0; +#if defined(wxBITMAPCOMBOBOX_OWNERDRAWN_BASED) + shifl_Left += int(scale * 4 + 0.5f); // IMAGE_SPACING_RIGHT = 4 for wxBitmapComboBox -> Space left of image +#endif + int icon_right_pos = shifl_Left + int(scale * (24+4) + 0.5); + int mouse_pos = event.GetLogicalPosition(wxClientDC(this)).x; + if (mouse_pos < shifl_Left || mouse_pos > icon_right_pos ) { + // Let the combo box process the mouse click. + event.Skip(); + return; + } + + // Swallow the mouse click and open the color picker. + + // get current color + DynamicPrintConfig* cfg = wxGetApp().get_tab(Preset::TYPE_PRINTER)->get_config(); + auto colors = static_cast(cfg->option("extruder_colour")->clone()); + wxColour clr(colors->values[m_extruder_idx]); + if (!clr.IsOk()) + clr = wxColour(0,0,0); // Don't set alfa to transparence + + auto data = new wxColourData(); + data->SetChooseFull(1); + data->SetColour(clr); + + wxColourDialog dialog(this, data); + dialog.CenterOnParent(); + if (dialog.ShowModal() == wxID_OK) + { + colors->values[m_extruder_idx] = dialog.GetColourData().GetColour().GetAsString(wxC2S_HTML_SYNTAX).ToStdString(); + + DynamicPrintConfig cfg_new = *cfg; + cfg_new.set_key_value("extruder_colour", colors); + + wxGetApp().get_tab(Preset::TYPE_PRINTER)->load_config(cfg_new); + this->update(); + wxGetApp().plater()->on_config_change(cfg_new); + } + }); + } + + edit_btn = new ScalableButton(parent, wxID_ANY, "cog"); + edit_btn->SetToolTip(_L("Click to edit preset")); + + edit_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent) + { + Tab* tab = wxGetApp().get_tab(m_type); + if (!tab) + return; + + int page_id = wxGetApp().tab_panel()->FindPage(tab); + if (page_id == wxNOT_FOUND) + return; + + wxGetApp().tab_panel()->SetSelection(page_id); + + // Switch to Settings NotePad + wxGetApp().mainframe->select_tab(); + + /* In a case of a multi-material printing, for editing another Filament Preset + * it's needed to select this preset for the "Filament settings" Tab + */ + if (m_type == Preset::TYPE_FILAMENT && wxGetApp().extruders_edited_cnt() > 1) + { + const std::string& selected_preset = GetString(GetSelection()).ToUTF8().data(); + + // Call select_preset() only if there is new preset and not just modified + if ( !boost::algorithm::ends_with(selected_preset, Preset::suffix_modified()) ) + { + const std::string& preset_name = wxGetApp().preset_bundle->filaments.get_preset_name_by_alias(selected_preset); + tab->select_preset(preset_name); + } + } + }); +} + +PlaterPresetComboBox::~PlaterPresetComboBox() +{ + if (edit_btn) + edit_btn->Destroy(); +} + +// Only the compatible presets are shown. +// If an incompatible preset is selected, it is shown as well. +void PlaterPresetComboBox::update() +{ + if (m_type == Preset::TYPE_FILAMENT && + (m_collection->get_edited_preset().printer_technology() == ptSLA || + m_preset_bundle->filament_presets.size() <= m_extruder_idx) ) + return; + + // Otherwise fill in the list from scratch. + this->Freeze(); + this->Clear(); + size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected + + const Preset* selected_filament_preset; + std::string extruder_color; + if (m_type == Preset::TYPE_FILAMENT) + { + unsigned char rgb[3]; + extruder_color = m_preset_bundle->printers.get_edited_preset().config.opt_string("extruder_colour", (unsigned int)m_extruder_idx); + if (!m_bitmap_cache->parse_color(extruder_color, rgb)) + // Extruder color is not defined. + extruder_color.clear(); + selected_filament_preset = m_collection->find_preset(m_preset_bundle->filament_presets[m_extruder_idx]); + assert(selected_filament_preset); + } + + const Preset& selected_preset = m_type == Preset::TYPE_FILAMENT ? *selected_filament_preset : m_collection->get_selected_preset(); + // Show wide icons if the currently selected preset is not compatible with the current printer, + // and draw a red flag in front of the selected preset. + bool wide_icons = !selected_preset.is_compatible; + + std::map nonsys_presets; + std::map physical_printers; + + wxString selected = ""; + wxString tooltip = ""; + const std::deque& presets = m_collection->get_presets(); + + if (!presets.front().is_visible) + this->set_label_marker(this->Append(separator(L("System presets")), wxNullBitmap)); + + for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i) + { + const Preset& preset = presets[i]; + bool is_selected = m_type == Preset::TYPE_FILAMENT ? + m_preset_bundle->filament_presets[m_extruder_idx] == preset.name : + i == m_collection->get_selected_idx(); + + if (!preset.is_visible || (!preset.is_compatible && !is_selected)) + continue; + + std::string bitmap_key, filament_rgb, extruder_rgb; + bool single_bar = false; + if (m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA) + bitmap_key = "sla_printer"; + else if (m_type == Preset::TYPE_FILAMENT) + { + // Assign an extruder color to the selected item if the extruder color is defined. + filament_rgb = preset.config.opt_string("filament_colour", 0); + extruder_rgb = (selected && !extruder_color.empty()) ? extruder_color : filament_rgb; + single_bar = filament_rgb == extruder_rgb; + + bitmap_key = single_bar ? filament_rgb : filament_rgb + extruder_rgb; + } + wxBitmap main_bmp = create_scaled_bitmap(m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name); + + // 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 += preset.is_compatible ? ",cmpt" : ",ncmpt"; + bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst"; + 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. + std::vector bmps; + if (wide_icons) + // Paint a red flag for incompatible presets. + bmps.emplace_back(preset.is_compatible ? m_bitmap_cache->mkclear(norm_icon_width, icon_height) : m_bitmapIncompatible.bmp()); + + if (m_type == Preset::TYPE_FILAMENT) + { + unsigned char rgb[3]; + // Paint the color bars. + m_bitmap_cache->parse_color(filament_rgb, rgb); + bmps.emplace_back(m_bitmap_cache->mksolid(single_bar ? wide_icon_width : norm_icon_width, icon_height, rgb)); + if (!single_bar) { + m_bitmap_cache->parse_color(extruder_rgb, rgb); + bmps.emplace_back(m_bitmap_cache->mksolid(thin_icon_width, icon_height, rgb)); + } + // Paint a lock at the system presets. + bmps.emplace_back(m_bitmap_cache->mkclear(space_icon_width, icon_height)); + } + else + { + // Paint the color bars. + bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height)); + bmps.emplace_back(main_bmp); + // Paint a lock at the system presets. + bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height)); + } + bmps.emplace_back((preset.is_system || preset.is_default) ? m_bitmapLock.bmp() : m_bitmap_cache->mkclear(norm_icon_width, icon_height)); + bmp = m_bitmap_cache->insert(bitmap_key, bmps); + } + + const std::string name = preset.alias.empty() ? preset.name : preset.alias; + if (preset.is_default || preset.is_system) { + Append(wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), + !bmp ? main_bmp : *bmp); + if (is_selected || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) { + selected_preset_item = GetCount() - 1; + tooltip = wxString::FromUTF8(preset.name.c_str()); + } + } + else + { + nonsys_presets.emplace(wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), bmp); + if (is_selected) { + selected = wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); + tooltip = wxString::FromUTF8(preset.name.c_str()); + } + } + if (i + 1 == m_collection->num_default_presets()) + set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); + } + 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); + if (it->first == selected || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) + selected_preset_item = GetCount() - 1; + } + } + if (!physical_printers.empty()) + { + set_label_marker(Append(separator(L("Physical printers")), wxNullBitmap)); + for (std::map::iterator it = physical_printers.begin(); it != physical_printers.end(); ++it) { + Append(it->first, *it->second); + if (it->first == selected || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) + selected_preset_item = GetCount() - 1; + } + } + + 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) { + std::string bitmap_key = ""; + 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. + 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("printer")); + // 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); + } + set_label_marker(Append(separator(L("Add physical printer")), *bmp), LABEL_ITEM_PHYSICAL_PRINTERS); + } + + /* But, if selected_preset_item is still equal to INT_MAX, it means that + * there is no presets added to the list. + * So, select last combobox item ("Add/Remove preset") + */ + if (selected_preset_item == INT_MAX) + selected_preset_item = GetCount() - 1; + + SetSelection(selected_preset_item); + SetToolTip(tooltip.IsEmpty() ? GetString(selected_preset_item) : tooltip); + m_last_selected = selected_preset_item; + Thaw(); + + // Update control min size after rescale (changed Display DPI under MSW) + if (GetMinWidth() != 20 * m_em_unit) + SetMinSize(wxSize(20 * m_em_unit, GetSize().GetHeight())); +} + +void PlaterPresetComboBox::msw_rescale() +{ + PresetComboBox::msw_rescale(); + edit_btn->msw_rescale(); +} + + +// --------------------------------- +// *** PlaterPresetComboBox *** +// --------------------------------- + +TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type) : + PresetComboBox(parent, preset_type, wxSize(35 * wxGetApp().em_unit(), -1)) +{ + Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& evt) { + // see https://github.com/prusa3d/PrusaSlicer/issues/3889 + // Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender") + // m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive. + // So, use GetSelection() from event parameter + auto selected_item = evt.GetSelection(); + + auto marker = reinterpret_cast(this->GetClientData(selected_item)); + if (marker >= LABEL_ITEM_MARKER && marker < LABEL_ITEM_MAX) { + this->SetSelection(this->m_last_selected); + if (marker == LABEL_ITEM_WIZARD_PRINTERS) + wxTheApp->CallAfter([]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); }); + } + else if (m_last_selected != selected_item || m_collection->current_is_dirty()) { + std::string selected_string = this->GetString(selected_item).ToUTF8().data(); + Tab* tab = wxGetApp().get_tab(this->m_type); + assert (tab); + tab->select_preset(selected_string); + } + + evt.StopPropagation(); + }); +} + +// Update the choice UI from the list of presets. +// If show_incompatible, all presets are shown, otherwise only the compatible presets are shown. +// If an incompatible preset is selected, it is shown as well. +void TabPresetComboBox::update() +{ + Freeze(); + Clear(); + size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected + + const std::deque& presets = m_collection->get_presets(); + + std::map nonsys_presets; + wxString selected = ""; + if (!presets.front().is_visible) + set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); + int idx_selected = m_collection->get_selected_idx(); + for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i) { + const Preset& preset = presets[i]; + if (!preset.is_visible || (!show_incompatible && !preset.is_compatible && i != idx_selected)) + continue; + + 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); + if (m_type == Preset::TYPE_PRINTER) { + bitmap_key += "_printer"; + if (preset.printer_technology() == ptSLA) + bitmap_key += "_sla"; + } + bitmap_key += preset.is_compatible ? ",cmpt" : ",ncmpt"; + bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst"; + 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. + 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)); + 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); + if (i == idx_selected || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) + selected_preset_item = GetCount() - 1; + } + else + { + nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), bmp); + if (i == idx_selected) + selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); + } + if (i + 1 == m_collection->num_default_presets()) + set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); + } + 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); + if (it->first == selected || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) + selected_preset_item = GetCount() - 1; + } + } + if (m_type == Preset::TYPE_PRINTER) { + std::string 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. + std::vector bmps; + bmps.emplace_back(create_scaled_bitmap(m_main_bitmap_name)); + bmps.emplace_back(create_scaled_bitmap("edit_uni")); + bmp = m_bitmap_cache->insert(bitmap_key, bmps); + } + 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 + * there is no presets added to the list. + * So, select last combobox item ("Add/Remove preset") + */ + if (selected_preset_item == INT_MAX) + selected_preset_item = GetCount() - 1; + + SetSelection(selected_preset_item); + SetToolTip(GetString(selected_preset_item)); + Thaw(); + + m_last_selected = selected_preset_item; +} + +void TabPresetComboBox::msw_rescale() +{ + PresetComboBox::msw_rescale(); + wxSize sz = wxSize(35 * m_em_unit, -1); + SetMinSize(sz); + SetSize(sz); +} + +void TabPresetComboBox::update_dirty() +{ + // 1) Update the dirty flag of the current preset. + m_collection->update_dirty(); + + // 2) Update the labels. + wxWindowUpdateLocker noUpdates(this); + for (unsigned int ui_id = 0; ui_id < GetCount(); ++ui_id) { + std::string old_label = GetString(ui_id).utf8_str().data(); + std::string preset_name = Preset::remove_suffix_modified(old_label); + const Preset* preset = m_collection->find_preset(preset_name, false); + if (preset) { + std::string new_label = preset->is_dirty ? preset->name + Preset::suffix_modified() : preset->name; + if (old_label != new_label) + SetString(ui_id, wxString::FromUTF8(new_label.c_str())); + } + } +#ifdef __APPLE__ + // wxWidgets on OSX do not upload the text of the combo box line automatically. + // Force it to update by re-selecting. + SetSelection(GetSelection()); +#endif /* __APPLE __ */ +} + + +//------------------------------------------ +// PhysicalPrinterDialog +//------------------------------------------ + + +PhysicalPrinterDialog::PhysicalPrinterDialog() + : DPIDialog(NULL, wxID_ANY, _L("Search"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) +{ + SetFont(wxGetApp().normal_font()); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + + int border = 10; + int em = em_unit(); + + printer_text = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); + printer_presets = new PlaterPresetComboBox(this, Preset::TYPE_PRINTER); + + wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); + + wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); + + topSizer->Add(printer_text , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); + topSizer->Add(printer_presets , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); + topSizer->Add(btns , 0, wxEXPAND | wxALL, border); + + SetSizer(topSizer); + topSizer->SetSizeHints(this); +} + +void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) +{ + const int& em = em_unit(); + + msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL }); + + const wxSize& size = wxSize(40 * em, 30 * em); + SetMinSize(size); + + Fit(); + Refresh(); +} + + +}} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp new file mode 100644 index 000000000..63110e432 --- /dev/null +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -0,0 +1,179 @@ +#ifndef slic3r_PresetComboBoxes_hpp_ +#define slic3r_PresetComboBoxes_hpp_ + +#include + +#include +#include +#include + +#include "Preset.hpp" +#include "wxExtensions.hpp" +#include "GUI_Utils.hpp" + +class wxString; +class wxTextCtrl; + +namespace Slic3r { + +namespace GUI { + +class BitmapCache; + + +// --------------------------------- +// *** PresetComboBox *** +// --------------------------------- + +// BitmapComboBox used to presets list on Sidebar and Tabs +class PresetComboBox : public wxBitmapComboBox +{ +public: + PresetComboBox(wxWindow* parent, Preset::Type preset_type, const wxSize& size = wxDefaultSize); + ~PresetComboBox(); + + enum LabelItemType { + LABEL_ITEM_MARKER = 0xffffff01, + LABEL_ITEM_PHYSICAL_PRINTERS, + LABEL_ITEM_WIZARD_PRINTERS, + LABEL_ITEM_WIZARD_FILAMENTS, + LABEL_ITEM_WIZARD_MATERIALS, + + LABEL_ITEM_MAX, + }; + + void set_label_marker(int item, LabelItemType label_item_type = LABEL_ITEM_MARKER); + int em_unit() const { return m_em_unit; } + + virtual void update() {}; + virtual void msw_rescale(); + +protected: + typedef std::size_t Marker; + + Preset::Type m_type; + std::string m_main_bitmap_name; + + PresetBundle* m_preset_bundle {nullptr}; + PresetCollection* m_collection {nullptr}; + + // Caching color bitmaps for the filament combo box. + BitmapCache* m_bitmap_cache {nullptr}; + // Indicator, that the preset is compatible with the selected printer. + ScalableBitmap m_bitmapCompatible; + // Indicator, that the preset is NOT compatible with the selected printer. + ScalableBitmap m_bitmapIncompatible; + // Indicator, that the preset is system and not modified. + ScalableBitmap m_bitmapLock; + + int m_last_selected; + int m_em_unit; + + // parameters for an icon's drawing + int icon_height; + int norm_icon_width; + int thin_icon_width; + int wide_icon_width; + int space_icon_width; + int thin_space_icon_width; + int wide_space_icon_width; + +#ifdef __linux__ + static const char* separator_head() { return "------- "; } + static const char* separator_tail() { return " -------"; } +#else // __linux__ + static const char* separator_head() { return "————— "; } + static const char* separator_tail() { return " —————"; } +#endif // __linux__ + static wxString separator(const std::string& label); + +#ifdef __APPLE__ + /* For PresetComboBox we use bitmaps that are created from images that are already scaled appropriately for Retina + * (Contrary to the intuition, the `scale` argument for Bitmap's constructor doesn't mean + * "please scale this to such and such" but rather + * "the wxImage is already sized for backing scale such and such". ) + * Unfortunately, the constructor changes the size of wxBitmap too. + * Thus We need to use unscaled size value for bitmaps that we use + * to avoid scaled size of control items. + * For this purpose control drawing methods and + * control size calculation methods (virtual) are overridden. + **/ + virtual bool OnAddBitmap(const wxBitmap& bitmap) override; + virtual void OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const override; +#endif + +private: + void fill_width_height(); +}; + + +// --------------------------------- +// *** PlaterPresetComboBox *** +// --------------------------------- + +class PlaterPresetComboBox : public PresetComboBox +{ +public: + PlaterPresetComboBox(wxWindow *parent, Preset::Type preset_type); + ~PlaterPresetComboBox(); + + ScalableButton* edit_btn { nullptr }; + + void set_extruder_idx(const int extr_idx) { m_extruder_idx = extr_idx; } + int get_extruder_idx() const { return m_extruder_idx; } + + void update() override; + void msw_rescale() override; + +private: + int m_extruder_idx = -1; +}; + + +// --------------------------------- +// *** PlaterPresetComboBox *** +// --------------------------------- + +class TabPresetComboBox : public PresetComboBox +{ +public: + TabPresetComboBox(wxWindow *parent, Preset::Type preset_type); + ~TabPresetComboBox() {} + void set_show_incompatible_presets(bool show_incompatible_presets) { + show_incompatible = show_incompatible_presets; + } + + void update() override; + void update_dirty(); + void msw_rescale() override; + +private: + bool show_incompatible{false}; +}; + + +//------------------------------------------ +// PhysicalPrinterDialog +//------------------------------------------ + +class PhysicalPrinterDialog : public DPIDialog +{ + std::string printer_name; + std::string preset_name; + + wxTextCtrl* printer_text { nullptr }; + PresetComboBox* printer_presets; + +public: + PhysicalPrinterDialog(); + ~PhysicalPrinterDialog() {} + +protected: + void on_dpi_changed(const wxRect& suggested_rect) override; + void on_sys_color_changed() override {}; +}; + +} // namespace GUI +} // namespace Slic3r + +#endif diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 84bc5a572..b128ec03d 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -27,6 +27,7 @@ #include #include "wxExtensions.hpp" +#include "PresetComboBoxes.hpp" #include #include "GUI_App.hpp" @@ -160,10 +161,7 @@ void Tab::create_preset_tab() #endif //__WXOSX__ // preset chooser - m_presets_choice = new PresetBitmapComboBox(panel, wxSize(35 * m_em_unit, -1)); - - // search combox -// m_search = new Search::SearchCtrl(panel); + m_presets_choice = new TabPresetComboBox(panel, m_type); auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); @@ -278,35 +276,6 @@ void Tab::create_preset_tab() m_treectrl->Bind(wxEVT_TREE_SEL_CHANGED, &Tab::OnTreeSelChange, this); m_treectrl->Bind(wxEVT_KEY_DOWN, &Tab::OnKeyDown, this); - m_presets_choice->Bind(wxEVT_COMBOBOX, ([this](wxCommandEvent e) { - //! Because of The MSW and GTK version of wxBitmapComboBox derived from wxComboBox, - //! but the OSX version derived from wxOwnerDrawnCombo, instead of: - //! select_preset(m_presets_choice->GetStringSelection().ToUTF8().data()); - //! we doing next: - // int selected_item = m_presets_choice->GetSelection(); - - // see https://github.com/prusa3d/PrusaSlicer/issues/3889 - // Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender") - // m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive. - // So, use GetSelection() from event parameter - int selected_item = e.GetSelection(); - if (m_selected_preset_item == size_t(selected_item) && !m_presets->current_is_dirty()) - return; - if (selected_item >= 0) { - std::string selected_string = m_presets_choice->GetString(selected_item).ToUTF8().data(); - if (selected_string.find(PresetCollection::separator_head()) == 0 - /*selected_string == "------- System presets -------" || - selected_string == "------- User presets -------"*/) { - m_presets_choice->SetSelection(m_selected_preset_item); - if (wxString::FromUTF8(selected_string.c_str()) == PresetCollection::separator(L("Add a new printer"))) - wxTheApp->CallAfter([]() { wxGetApp().run_wizard(ConfigWizard::RR_USER); }); - return; - } - m_selected_preset_item = selected_item; - select_preset(selected_string); - } - })); - m_btn_save_preset->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { save_preset(); })); m_btn_delete_preset->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { delete_preset(); })); m_btn_hide_incompatible_presets->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { @@ -778,14 +747,14 @@ void Tab::on_roll_back_value(const bool to_sys /*= true*/) // comparing the selected preset config with $self->{config}. void Tab::update_dirty() { - m_presets->update_dirty_ui(m_presets_choice); + m_presets_choice->update_dirty(); on_presets_changed(); update_changed_ui(); } void Tab::update_tab_ui() { - m_selected_preset_item = m_presets->update_tab_ui(m_presets_choice, m_show_incompatible_presets, m_em_unit); + m_presets_choice->update(); } // Load a provied DynamicConfig into the tab, modifying the active preset. @@ -850,12 +819,10 @@ void Tab::msw_rescale() m_em_unit = wxGetApp().em_unit(); m_mode_sizer->msw_rescale(); + m_presets_choice->msw_rescale(); - m_presets_choice->SetSize(35 * m_em_unit, -1); m_treectrl->SetMinSize(wxSize(20 * m_em_unit, -1)); - update_tab_ui(); - // rescale buttons and cached bitmaps for (const auto btn : m_scaled_buttons) btn->msw_rescale(); @@ -963,7 +930,7 @@ void Tab::load_key_value(const std::string& opt_key, const boost::any& value, bo // Don't select another profile if this profile happens to become incompatible. m_preset_bundle->update_compatible(PresetSelectCompatibleType::Never); } - m_presets->update_dirty_ui(m_presets_choice); + m_presets_choice->update_dirty(); on_presets_changed(); update(); } @@ -3360,6 +3327,7 @@ void Tab::delete_preset() void Tab::toggle_show_hide_incompatible() { m_show_incompatible_presets = !m_show_incompatible_presets; + m_presets_choice->set_show_incompatible_presets(m_show_incompatible_presets); update_show_hide_incompatible_button(); update_tab_ui(); } diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 5805809bf..a0bf536c1 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -39,6 +39,8 @@ namespace Slic3r { namespace GUI { +class TabPresetComboBox; + // Single Tab page containing a{ vsizer } of{ optgroups } // package Slic3r::GUI::Tab::Page; using ConfigOptionsGroupShp = std::shared_ptr; @@ -113,7 +115,7 @@ protected: Preset::Type m_type; std::string m_name; const wxString m_title; - PresetBitmapComboBox* m_presets_choice; + TabPresetComboBox* m_presets_choice; ScalableButton* m_search_btn; ScalableButton* m_btn_save_preset; ScalableButton* m_btn_delete_preset; @@ -206,8 +208,6 @@ protected: bool m_is_nonsys_values{ true }; bool m_postpone_update_ui {false}; - size_t m_selected_preset_item{ 0 }; - void set_type(); int m_em_unit; @@ -320,7 +320,6 @@ public: DynamicPrintConfig* get_config() { return m_config; } PresetCollection* get_presets() { return m_presets; } - size_t get_selected_preset_item() { return m_selected_preset_item; } void on_value_change(const std::string& opt_key, const boost::any& value); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index ad9f0a121..39b3e154b 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -300,94 +300,6 @@ void wxCheckListBoxComboPopup::OnListBoxSelection(wxCommandEvent& evt) } -namespace Slic3r { -namespace GUI { - -// *** PresetBitmapComboBox *** - -/* For PresetBitmapComboBox we use bitmaps that are created from images that are already scaled appropriately for Retina - * (Contrary to the intuition, the `scale` argument for Bitmap's constructor doesn't mean - * "please scale this to such and such" but rather - * "the wxImage is already sized for backing scale such and such". ) - * Unfortunately, the constructor changes the size of wxBitmap too. - * Thus We need to use unscaled size value for bitmaps that we use - * to avoid scaled size of control items. - * For this purpose control drawing methods and - * control size calculation methods (virtual) are overridden. - **/ - -PresetBitmapComboBox::PresetBitmapComboBox(wxWindow* parent, const wxSize& size) : - wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, size, 0, nullptr, wxCB_READONLY) -{} - -#ifdef __APPLE__ -bool PresetBitmapComboBox::OnAddBitmap(const wxBitmap& bitmap) -{ - if (bitmap.IsOk()) - { - // we should use scaled! size values of bitmap - int width = (int)bitmap.GetScaledWidth(); - int height = (int)bitmap.GetScaledHeight(); - - if (m_usedImgSize.x < 0) - { - // If size not yet determined, get it from this image. - m_usedImgSize.x = width; - m_usedImgSize.y = height; - - // Adjust control size to vertically fit the bitmap - wxWindow* ctrl = GetControl(); - ctrl->InvalidateBestSize(); - wxSize newSz = ctrl->GetBestSize(); - wxSize sz = ctrl->GetSize(); - if (newSz.y > sz.y) - ctrl->SetSize(sz.x, newSz.y); - else - DetermineIndent(); - } - - wxCHECK_MSG(width == m_usedImgSize.x && height == m_usedImgSize.y, - false, - "you can only add images of same size"); - - return true; - } - - return false; -} - -void PresetBitmapComboBox::OnDrawItem(wxDC& dc, - const wxRect& rect, - int item, - int flags) const -{ - const wxBitmap& bmp = *(wxBitmap*)m_bitmaps[item]; - if (bmp.IsOk()) - { - // we should use scaled! size values of bitmap - wxCoord w = bmp.GetScaledWidth(); - wxCoord h = bmp.GetScaledHeight(); - - const int imgSpacingLeft = 4; - - // Draw the image centered - dc.DrawBitmap(bmp, - rect.x + (m_usedImgSize.x - w) / 2 + imgSpacingLeft, - rect.y + (rect.height - h) / 2, - true); - } - - wxString text = GetString(item); - if (!text.empty()) - dc.DrawText(text, - rect.x + m_imgAreaWidth + 1, - rect.y + (rect.height - dc.GetCharHeight()) / 2); -} -#endif -} -} - - // *** wxDataViewTreeCtrlComboPopup *** const unsigned int wxDataViewTreeCtrlComboPopup::DefaultWidth = 270; diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 569257e1b..17fe8992c 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -95,37 +95,6 @@ public: void OnListBoxSelection(wxCommandEvent& evt); }; -namespace Slic3r { -namespace GUI { -// *** PresetBitmapComboBox *** - -// BitmapComboBox used to presets list on Sidebar and Tabs -class PresetBitmapComboBox: public wxBitmapComboBox -{ -public: - PresetBitmapComboBox(wxWindow* parent, const wxSize& size = wxDefaultSize); - ~PresetBitmapComboBox() {} - -#ifdef __APPLE__ -protected: - /* For PresetBitmapComboBox we use bitmaps that are created from images that are already scaled appropriately for Retina - * (Contrary to the intuition, the `scale` argument for Bitmap's constructor doesn't mean - * "please scale this to such and such" but rather - * "the wxImage is already sized for backing scale such and such". ) - * Unfortunately, the constructor changes the size of wxBitmap too. - * Thus We need to use unscaled size value for bitmaps that we use - * to avoid scaled size of control items. - * For this purpose control drawing methods and - * control size calculation methods (virtual) are overridden. - **/ - virtual bool OnAddBitmap(const wxBitmap& bitmap) override; - virtual void OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const override; -#endif -}; - -} -} - // *** wxDataViewTreeCtrlComboBox *** From 19c4f3260429ba6db33411fd78b6bfc74ac2b8e9 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 16 Jun 2020 16:58:41 +0200 Subject: [PATCH 02/31] Preset and PresetBundle are moved to the _libslic3r_ folder --- src/libslic3r/CMakeLists.txt | 4 ++++ src/{slic3r/GUI => libslic3r}/Preset.cpp | 23 +++++++++++++------ src/{slic3r/GUI => libslic3r}/Preset.hpp | 14 +++-------- .../GUI => libslic3r}/PresetBundle.cpp | 17 +++----------- .../GUI => libslic3r}/PresetBundle.hpp | 3 +-- src/slic3r/CMakeLists.txt | 4 ---- src/slic3r/Config/Snapshot.cpp | 3 +-- src/slic3r/GUI/3DBed.cpp | 2 +- src/slic3r/GUI/ConfigManipulation.cpp | 2 +- src/slic3r/GUI/ConfigWizard_private.hpp | 2 +- src/slic3r/GUI/GLCanvas3D.cpp | 2 +- src/slic3r/GUI/GUI_App.cpp | 4 ++-- src/slic3r/GUI/GUI_App.hpp | 2 +- src/slic3r/GUI/GUI_ObjectLayers.cpp | 2 +- src/slic3r/GUI/GUI_ObjectList.cpp | 2 +- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 2 +- src/slic3r/GUI/GUI_ObjectSettings.cpp | 2 +- src/slic3r/GUI/GUI_Preview.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 2 +- src/slic3r/GUI/I18N.hpp | 2 +- src/slic3r/GUI/Jobs/SLAImportJob.cpp | 2 +- src/slic3r/GUI/MainFrame.cpp | 2 +- src/slic3r/GUI/Mouse3DController.cpp | 2 +- src/slic3r/GUI/Plater.cpp | 4 +++- src/slic3r/GUI/Plater.hpp | 2 +- src/slic3r/GUI/PresetComboBoxes.cpp | 2 +- src/slic3r/GUI/PresetComboBoxes.hpp | 2 +- src/slic3r/GUI/PresetHints.cpp | 1 - src/slic3r/GUI/PresetHints.hpp | 2 +- src/slic3r/GUI/Search.cpp | 2 +- src/slic3r/GUI/Search.hpp | 2 +- src/slic3r/GUI/Tab.cpp | 3 +-- src/slic3r/GUI/Tab.hpp | 2 +- src/slic3r/Utils/PresetUpdater.cpp | 2 +- 38 files changed, 61 insertions(+), 73 deletions(-) rename src/{slic3r/GUI => libslic3r}/Preset.cpp (99%) rename src/{slic3r/GUI => libslic3r}/Preset.hpp (99%) rename src/{slic3r/GUI => libslic3r}/PresetBundle.cpp (99%) rename src/{slic3r/GUI => libslic3r}/PresetBundle.hpp (99%) diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 1a58bdbbd..1605c52cd 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -147,6 +147,10 @@ add_library(libslic3r STATIC PolygonTrimmer.hpp Polyline.cpp Polyline.hpp + Preset.cpp + Preset.hpp + PresetBundle.cpp + PresetBundle.hpp Print.cpp Print.hpp PrintBase.cpp diff --git a/src/slic3r/GUI/Preset.cpp b/src/libslic3r/Preset.cpp similarity index 99% rename from src/slic3r/GUI/Preset.cpp rename to src/libslic3r/Preset.cpp index 883dc438a..e46cd6c82 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1,8 +1,7 @@ #include #include "Preset.hpp" -#include "AppConfig.hpp" -#include "I18N.hpp" +#include "slic3r/GUI/AppConfig.hpp" #ifdef _MSC_VER #define WIN32_LEAN_AND_MEAN @@ -10,6 +9,16 @@ #include #endif /* _MSC_VER */ +// instead of #include "slic3r/GUI/I18N.hpp" : +#ifndef L +// !!! If you needed to translate some string, +// !!! please use _L(string) +// !!! _() - is a standard wxWidgets macro to translate +// !!! L() is used only for marking localizable string +// !!! It will be used in "xgettext" to create a Locating Message Catalog. +#define L(s) s +#endif /* L */ + #include #include #include @@ -28,9 +37,9 @@ #include #include -#include "libslic3r/libslic3r.h" -#include "libslic3r/Utils.hpp" -#include "libslic3r/PlaceholderParser.hpp" +#include "libslic3r.h" +#include "Utils.hpp" +#include "PlaceholderParser.hpp" using boost::property_tree::ptree; @@ -237,9 +246,9 @@ const std::string& Preset::suffix_modified() return g_suffix_modified; } -void Preset::update_suffix_modified() +void Preset::update_suffix_modified(const std::string& new_suffix_modified) { - g_suffix_modified = (" (" + _(L("modified")) + ")").ToUTF8().data(); + g_suffix_modified = new_suffix_modified; } // Remove an optional "(modified)" suffix from a name. // This converts a UI name to a unique preset identifier. diff --git a/src/slic3r/GUI/Preset.hpp b/src/libslic3r/Preset.hpp similarity index 99% rename from src/slic3r/GUI/Preset.hpp rename to src/libslic3r/Preset.hpp index 8a8fa024b..b0af2f142 100644 --- a/src/slic3r/GUI/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -8,16 +8,8 @@ #include #include -#include "libslic3r/libslic3r.h" -#include "libslic3r/PrintConfig.hpp" -#include "libslic3r/Semver.hpp" - -class wxBitmap; -class wxBitmapComboBox; -class wxChoice; -class wxItemContainer; -class wxString; -class wxWindow; +#include "PrintConfig.hpp" +#include "Semver.hpp" namespace Slic3r { @@ -231,7 +223,7 @@ public: static const std::vector& sla_material_options(); static const std::vector& sla_print_options(); - static void update_suffix_modified(); + static void update_suffix_modified(const std::string& new_suffix_modified); static const std::string& suffix_modified(); static std::string remove_suffix_modified(const std::string& name); static void normalize(DynamicPrintConfig &config); diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp similarity index 99% rename from src/slic3r/GUI/PresetBundle.cpp rename to src/libslic3r/PresetBundle.cpp index 024884b00..9da7731a4 100644 --- a/src/slic3r/GUI/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -1,7 +1,9 @@ #include #include "PresetBundle.hpp" -#include "Plater.hpp" +#include "libslic3r.h" +#include "Utils.hpp" +#include "Model.hpp" #include #include @@ -19,14 +21,6 @@ #include #include -#include - -#include "libslic3r/libslic3r.h" -#include "libslic3r/Utils.hpp" -#include "libslic3r/Model.hpp" -#include "GUI_App.hpp" -#include "libslic3r/CustomGCode.hpp" - // Store the print/filament/printer presets into a "presets" subdirectory of the Slic3rPE config dir. // This breaks compatibility with the upstream Slic3r if the --datadir is used to switch between the two versions. @@ -49,9 +43,6 @@ PresetBundle::PresetBundle() : sla_prints(Preset::TYPE_SLA_PRINT, Preset::sla_print_options(), static_cast(SLAFullPrintConfig::defaults())), printers(Preset::TYPE_PRINTER, Preset::printer_options(), static_cast(FullPrintConfig::defaults()), "- default FFF -") { - if (wxImage::FindHandler(wxBITMAP_TYPE_PNG) == nullptr) - wxImage::AddHandler(new wxPNGHandler); - // The following keys are handled by the UI, they do not have a counterpart in any StaticPrintConfig derived classes, // therefore they need to be handled differently. As they have no counterpart in StaticPrintConfig, they are not being // initialized based on PrintConfigDef(), but to empty values (zeros, empty vectors, empty strings). @@ -822,8 +813,6 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool // 4) Load the project config values (the per extruder wipe matrix etc). this->project_config.apply_only(config, s_project_options); - CustomGCode::update_custom_gcode_per_print_z_from_config(GUI::wxGetApp().plater()->model().custom_gcode_per_print_z, &this->project_config); - break; } case ptSLA: diff --git a/src/slic3r/GUI/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp similarity index 99% rename from src/slic3r/GUI/PresetBundle.hpp rename to src/libslic3r/PresetBundle.hpp index 7d137bb7a..19d4093d6 100644 --- a/src/slic3r/GUI/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -1,14 +1,13 @@ #ifndef slic3r_PresetBundle_hpp_ #define slic3r_PresetBundle_hpp_ -#include "AppConfig.hpp" #include "Preset.hpp" #include #include #include -class wxWindow; +#include "slic3r/GUI/AppConfig.hpp" namespace Slic3r { diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 98389e7da..49e069285 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -61,10 +61,6 @@ set(SLIC3R_GUI_SOURCES GUI/GLToolbar.cpp GUI/Preferences.cpp GUI/Preferences.hpp - GUI/Preset.cpp - GUI/Preset.hpp - GUI/PresetBundle.cpp - GUI/PresetBundle.hpp GUI/PresetHints.cpp GUI/PresetHints.hpp GUI/GUI.cpp diff --git a/src/slic3r/Config/Snapshot.cpp b/src/slic3r/Config/Snapshot.cpp index 2264afa7d..f7d313418 100644 --- a/src/slic3r/Config/Snapshot.cpp +++ b/src/slic3r/Config/Snapshot.cpp @@ -1,6 +1,5 @@ #include "Snapshot.hpp" #include "../GUI/AppConfig.hpp" -#include "../GUI/PresetBundle.hpp" #include @@ -11,7 +10,7 @@ #include #include - +#include "libslic3r/PresetBundle.hpp" #include "libslic3r/libslic3r.h" #include "libslic3r/Time.hpp" #include "libslic3r/Config.hpp" diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index 6c070ca99..f2f9f6301 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -7,7 +7,7 @@ #include "libslic3r/BoundingBox.hpp" #include "GUI_App.hpp" -#include "PresetBundle.hpp" +#include "libslic3r/PresetBundle.hpp" #include "GLCanvas3D.hpp" #include diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index a0df4c659..cd8463a77 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -2,7 +2,7 @@ #include "ConfigManipulation.hpp" #include "I18N.hpp" #include "GUI_App.hpp" -#include "PresetBundle.hpp" +#include "libslic3r/PresetBundle.hpp" #include diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index c99c5952b..be2919861 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -20,9 +20,9 @@ #include #include "libslic3r/PrintConfig.hpp" +#include "libslic3r/PresetBundle.hpp" #include "slic3r/Utils/PresetUpdater.hpp" #include "AppConfig.hpp" -#include "PresetBundle.hpp" #include "BedShapeDialog.hpp" #include "GUI.hpp" #include "wxExtensions.hpp" diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index b4e672c4f..b5cd9fb2a 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -13,11 +13,11 @@ #include "libslic3r/Utils.hpp" #include "libslic3r/Technologies.hpp" #include "libslic3r/Tesselate.hpp" +#include "libslic3r/PresetBundle.hpp" #include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/BackgroundSlicingProcess.hpp" #include "slic3r/GUI/GLShader.hpp" #include "slic3r/GUI/GUI.hpp" -#include "slic3r/GUI/PresetBundle.hpp" #include "slic3r/GUI/Tab.hpp" #include "slic3r/GUI/GUI_Preview.hpp" #include "slic3r/GUI/OpenGLManager.hpp" diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 3c000f62e..157875e70 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -31,11 +31,11 @@ #include "libslic3r/Utils.hpp" #include "libslic3r/Model.hpp" #include "libslic3r/I18N.hpp" +#include "libslic3r/PresetBundle.hpp" #include "GUI.hpp" #include "GUI_Utils.hpp" #include "AppConfig.hpp" -#include "PresetBundle.hpp" #include "3DScene.hpp" #include "MainFrame.hpp" #include "Plater.hpp" @@ -935,7 +935,7 @@ bool GUI_App::load_language(wxString language, bool initial) m_imgui->set_language(into_u8(language_info->CanonicalName)); //FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only. wxSetlocale(LC_NUMERIC, "C"); - Preset::update_suffix_modified(); + Preset::update_suffix_modified((" (" + _L("modified") + ")").ToUTF8().data()); return true; } diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index c2b257f45..23567695c 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -3,10 +3,10 @@ #include #include -#include "Preset.hpp" #include "ImGuiWrapper.hpp" #include "ConfigWizard.hpp" #include "OpenGLManager.hpp" +#include "libslic3r/Preset.hpp" #include #include diff --git a/src/slic3r/GUI/GUI_ObjectLayers.cpp b/src/slic3r/GUI/GUI_ObjectLayers.cpp index b1a5512d4..90a725fbf 100644 --- a/src/slic3r/GUI/GUI_ObjectLayers.cpp +++ b/src/slic3r/GUI/GUI_ObjectLayers.cpp @@ -3,7 +3,7 @@ #include "OptionsGroup.hpp" #include "GUI_App.hpp" -#include "PresetBundle.hpp" +#include "libslic3r/PresetBundle.hpp" #include "libslic3r/Model.hpp" #include "GLCanvas3D.hpp" #include "Plater.hpp" diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 2f201180a..b87565b03 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1,4 +1,5 @@ #include "libslic3r/libslic3r.h" +#include "libslic3r/PresetBundle.hpp" #include "GUI_ObjectList.hpp" #include "GUI_ObjectManipulation.hpp" #include "GUI_ObjectLayers.hpp" @@ -7,7 +8,6 @@ #include "Plater.hpp" #include "OptionsGroup.hpp" -#include "PresetBundle.hpp" #include "Tab.hpp" #include "wxExtensions.hpp" #include "libslic3r/Model.hpp" diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 2c35fc316..7243e8c73 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -6,7 +6,7 @@ #include "OptionsGroup.hpp" #include "GUI_App.hpp" #include "wxExtensions.hpp" -#include "PresetBundle.hpp" +#include "libslic3r/PresetBundle.hpp" #include "libslic3r/Model.hpp" #include "libslic3r/Geometry.hpp" #include "Selection.hpp" diff --git a/src/slic3r/GUI/GUI_ObjectSettings.cpp b/src/slic3r/GUI/GUI_ObjectSettings.cpp index ef78123a4..398cd51d4 100644 --- a/src/slic3r/GUI/GUI_ObjectSettings.cpp +++ b/src/slic3r/GUI/GUI_ObjectSettings.cpp @@ -4,8 +4,8 @@ #include "OptionsGroup.hpp" #include "GUI_App.hpp" #include "wxExtensions.hpp" -#include "PresetBundle.hpp" #include "Plater.hpp" +#include "libslic3r/PresetBundle.hpp" #include "libslic3r/Model.hpp" #include diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index c1e8b4c33..f068ef37d 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -8,7 +8,7 @@ #include "BackgroundSlicingProcess.hpp" #include "OpenGLManager.hpp" #include "GLCanvas3D.hpp" -#include "PresetBundle.hpp" +#include "libslic3r/PresetBundle.hpp" #include "DoubleSlider.hpp" #include "Plater.hpp" diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp index cd4285724..7aa516845 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp @@ -6,9 +6,9 @@ #include #include "slic3r/GUI/GUI_App.hpp" -#include "slic3r/GUI/PresetBundle.hpp" #include "slic3r/GUI/Camera.hpp" #include "slic3r/GUI/Plater.hpp" +#include "libslic3r/PresetBundle.hpp" #include "libslic3r/Model.hpp" diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 658db64ca..273384da2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -9,7 +9,7 @@ #include "slic3r/GUI/GUI_ObjectSettings.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp" #include "slic3r/GUI/Plater.hpp" -#include "slic3r/GUI/PresetBundle.hpp" +#include "libslic3r/PresetBundle.hpp" #include "libslic3r/Model.hpp" diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 908fe27b1..2856bb35d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -16,7 +16,7 @@ #include "slic3r/GUI/GUI_ObjectSettings.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp" #include "slic3r/GUI/Plater.hpp" -#include "slic3r/GUI/PresetBundle.hpp" +#include "libslic3r/PresetBundle.hpp" #include "libslic3r/SLAPrint.hpp" diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index 051e9cf88..6742f5cde 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -8,7 +8,7 @@ #include "slic3r/GUI/Camera.hpp" #include "slic3r/GUI/Plater.hpp" -#include "slic3r/GUI/PresetBundle.hpp" +#include "libslic3r/PresetBundle.hpp" #include diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 511c68735..c33ba2850 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -5,7 +5,6 @@ #include "slic3r/GUI/Camera.hpp" #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_ObjectManipulation.hpp" -#include "slic3r/GUI/PresetBundle.hpp" #include "slic3r/GUI/Plater.hpp" #include "slic3r/Utils/UndoRedo.hpp" @@ -19,6 +18,7 @@ #include "slic3r/GUI/Gizmos/GLGizmoHollow.hpp" #include "libslic3r/Model.hpp" +#include "libslic3r/PresetBundle.hpp" #include diff --git a/src/slic3r/GUI/I18N.hpp b/src/slic3r/GUI/I18N.hpp index 25e46930b..7bad6880e 100644 --- a/src/slic3r/GUI/I18N.hpp +++ b/src/slic3r/GUI/I18N.hpp @@ -12,7 +12,7 @@ #ifndef L // !!! If you needed to translate some wxString, -// !!! please use _(L(string)) +// !!! please use _L(string) // !!! _() - is a standard wxWidgets macro to translate // !!! L() is used only for marking localizable string // !!! It will be used in "xgettext" to create a Locating Message Catalog. diff --git a/src/slic3r/GUI/Jobs/SLAImportJob.cpp b/src/slic3r/GUI/Jobs/SLAImportJob.cpp index 4e9f08ff2..cc779df2a 100644 --- a/src/slic3r/GUI/Jobs/SLAImportJob.cpp +++ b/src/slic3r/GUI/Jobs/SLAImportJob.cpp @@ -4,11 +4,11 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/AppConfig.hpp" #include "slic3r/GUI/Plater.hpp" -#include "slic3r/GUI/PresetBundle.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp" #include "slic3r/Utils/SLAImport.hpp" #include "libslic3r/Model.hpp" +#include "libslic3r/PresetBundle.hpp" #include #include diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index d4ce21fc0..08caf299b 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -15,9 +15,9 @@ #include "libslic3r/Print.hpp" #include "libslic3r/Polygon.hpp" #include "libslic3r/SLAPrint.hpp" +#include "libslic3r/PresetBundle.hpp" #include "Tab.hpp" -#include "PresetBundle.hpp" #include "ProgressStatusBar.hpp" #include "3DScene.hpp" #include "AppConfig.hpp" diff --git a/src/slic3r/GUI/Mouse3DController.cpp b/src/slic3r/GUI/Mouse3DController.cpp index baa9356b6..91d2414d5 100644 --- a/src/slic3r/GUI/Mouse3DController.cpp +++ b/src/slic3r/GUI/Mouse3DController.cpp @@ -1,9 +1,9 @@ #include "libslic3r/libslic3r.h" +#include "libslic3r/PresetBundle.hpp" #include "Mouse3DController.hpp" #include "Camera.hpp" #include "GUI_App.hpp" -#include "PresetBundle.hpp" #include "AppConfig.hpp" #include "GLCanvas3D.hpp" #include "Plater.hpp" diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 339badc96..a78683bd4 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -43,6 +43,7 @@ #include "libslic3r/PrintConfig.hpp" #include "libslic3r/SLAPrint.hpp" #include "libslic3r/Utils.hpp" +#include "libslic3r/PresetBundle.hpp" #include "GUI.hpp" #include "GUI_App.hpp" @@ -65,7 +66,6 @@ #include "Jobs/ArrangeJob.hpp" #include "Jobs/RotoptimizeJob.hpp" #include "Jobs/SLAImportJob.hpp" -#include "PresetBundle.hpp" #include "BackgroundSlicingProcess.hpp" #include "ProgressStatusBar.hpp" #include "PrintHostDialogs.hpp" @@ -2120,6 +2120,8 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (!config.empty()) { Preset::normalize(config); wxGetApp().preset_bundle->load_config_model(filename.string(), std::move(config)); + if (printer_technology == ptFFF) + CustomGCode::update_custom_gcode_per_print_z_from_config(model.custom_gcode_per_print_z, &wxGetApp().preset_bundle->project_config); wxGetApp().load_current_presets(); is_project_file = true; } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index d2acc7632..38fc67982 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -7,9 +7,9 @@ #include -#include "Preset.hpp" #include "Selection.hpp" +#include "libslic3r/Preset.hpp" #include "libslic3r/BoundingBox.hpp" #include "Jobs/Job.hpp" #include "Search.hpp" diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 380edb48a..51b5a0c8d 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -15,6 +15,7 @@ #include "libslic3r/libslic3r.h" #include "libslic3r/PrintConfig.hpp" +#include "libslic3r/PresetBundle.hpp" #include "GUI.hpp" #include "GUI_App.hpp" @@ -22,7 +23,6 @@ #include "MainFrame.hpp" #include "format.hpp" #include "Tab.hpp" -#include "PresetBundle.hpp" #include "PrintHostDialogs.hpp" #include "ConfigWizard.hpp" #include "../Utils/ASCIIFolding.hpp" diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 63110e432..3d9a13490 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -7,7 +7,7 @@ #include #include -#include "Preset.hpp" +#include "libslic3r/Preset.hpp" #include "wxExtensions.hpp" #include "GUI_Utils.hpp" diff --git a/src/slic3r/GUI/PresetHints.cpp b/src/slic3r/GUI/PresetHints.cpp index 24afeb526..c40c4c6ac 100644 --- a/src/slic3r/GUI/PresetHints.cpp +++ b/src/slic3r/GUI/PresetHints.cpp @@ -4,7 +4,6 @@ #include "libslic3r/Slicing.hpp" #include "libslic3r/libslic3r.h" -#include "PresetBundle.hpp" #include "PresetHints.hpp" #include diff --git a/src/slic3r/GUI/PresetHints.hpp b/src/slic3r/GUI/PresetHints.hpp index be049c2c8..a61310f40 100644 --- a/src/slic3r/GUI/PresetHints.hpp +++ b/src/slic3r/GUI/PresetHints.hpp @@ -3,7 +3,7 @@ #include -#include "PresetBundle.hpp" +#include "libslic3r/PresetBundle.hpp" namespace Slic3r { diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index 613a39cce..242e3d725 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -9,10 +9,10 @@ #include "wx/dataview.h" #include "libslic3r/PrintConfig.hpp" +#include "libslic3r/PresetBundle.hpp" #include "GUI_App.hpp" #include "Plater.hpp" #include "Tab.hpp" -#include "PresetBundle.hpp" #define FTS_FUZZY_MATCH_IMPLEMENTATION #include "fts_fuzzy_match.h" diff --git a/src/slic3r/GUI/Search.hpp b/src/slic3r/GUI/Search.hpp index 9701e6808..8202222e9 100644 --- a/src/slic3r/GUI/Search.hpp +++ b/src/slic3r/GUI/Search.hpp @@ -14,8 +14,8 @@ #include #include "GUI_Utils.hpp" -#include "Preset.hpp" #include "wxExtensions.hpp" +#include "libslic3r/Preset.hpp" namespace Slic3r { diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index b128ec03d..88c11030d 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1,8 +1,8 @@ // #include "libslic3r/GCodeSender.hpp" #include "slic3r/Utils/Serial.hpp" #include "Tab.hpp" -#include "PresetBundle.hpp" #include "PresetHints.hpp" +#include "libslic3r/PresetBundle.hpp" #include "libslic3r/Utils.hpp" #include "libslic3r/Model.hpp" @@ -32,7 +32,6 @@ #include "GUI_App.hpp" #include "GUI_ObjectList.hpp" -#include "ConfigWizard.hpp" #include "Plater.hpp" #include "MainFrame.hpp" #include "format.hpp" diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index a0bf536c1..bc15efa35 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -33,8 +33,8 @@ #include "Event.hpp" #include "wxExtensions.hpp" #include "ConfigManipulation.hpp" -#include "Preset.hpp" #include "OptionsGroup.hpp" +#include "libslic3r/Preset.hpp" namespace Slic3r { namespace GUI { diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index c32613c46..dec251858 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -19,9 +19,9 @@ #include "libslic3r/libslic3r.h" #include "libslic3r/format.hpp" #include "libslic3r/Utils.hpp" +#include "libslic3r/PresetBundle.hpp" #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/I18N.hpp" -#include "slic3r/GUI/PresetBundle.hpp" #include "slic3r/GUI/UpdateDialogs.hpp" #include "slic3r/GUI/ConfigWizard.hpp" #include "slic3r/GUI/GUI_App.hpp" From 7c7dcab03299932cab681fe82996ac96e579f0df Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 18 Jun 2020 11:39:25 +0200 Subject: [PATCH 03/31] First filling of the PhysicalPrinterDialog + Fixed scaling of the icons for the BitmapComboBoxes + Fixed calling of the blinking icons on the Tabs --- src/slic3r/GUI/Field.cpp | 1 + src/slic3r/GUI/PresetComboBoxes.cpp | 46 +++++++++++++++++------------ src/slic3r/GUI/PresetComboBoxes.hpp | 7 ++--- src/slic3r/GUI/Tab.cpp | 4 ++- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 3a06c3056..8ab82e20d 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -295,6 +295,7 @@ void Field::msw_rescale(bool rescale_sidetext) { m_Undo_to_sys_btn->msw_rescale(); m_Undo_btn->msw_rescale(); + m_blinking_bmp->msw_rescale(); // update em_unit value m_em_unit = em_unit(m_parent); diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 51b5a0c8d..6c38c866d 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -58,7 +58,7 @@ PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, size, 0, nullptr, wxCB_READONLY), m_type(preset_type), m_last_selected(wxNOT_FOUND), - m_em_unit(wxGetApp().em_unit()), + m_em_unit(em_unit(this)), m_preset_bundle(wxGetApp().preset_bundle), m_bitmap_cache(new BitmapCache) { @@ -99,9 +99,9 @@ PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const default: break; } - m_bitmapCompatible = ScalableBitmap(nullptr, "flag_green"); - m_bitmapIncompatible = ScalableBitmap(nullptr, "flag_red"); - m_bitmapLock = ScalableBitmap(nullptr, "lock_closed"); + m_bitmapCompatible = ScalableBitmap(this, "flag_green"); + m_bitmapIncompatible = ScalableBitmap(this, "flag_red"); + m_bitmapLock = ScalableBitmap(this, "lock_closed"); // parameters for an icon's drawing fill_width_height(); @@ -120,7 +120,7 @@ void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type) void PresetComboBox::msw_rescale() { - m_em_unit = wxGetApp().em_unit(); + m_em_unit = em_unit(this); m_bitmapLock.msw_rescale(); m_bitmapIncompatible.msw_rescale(); @@ -241,7 +241,7 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset evt.StopPropagation(); if (marker == LABEL_ITEM_PHYSICAL_PRINTERS) { - PhysicalPrinterDialog dlg; + PhysicalPrinterDialog dlg(_L("New Physical Printer"), this->m_last_selected); dlg.ShowModal(); return; } @@ -360,7 +360,7 @@ PlaterPresetComboBox::~PlaterPresetComboBox() void PlaterPresetComboBox::update() { if (m_type == Preset::TYPE_FILAMENT && - (m_collection->get_edited_preset().printer_technology() == ptSLA || + (m_preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA || m_preset_bundle->filament_presets.size() <= m_extruder_idx) ) return; @@ -586,13 +586,13 @@ void PlaterPresetComboBox::msw_rescale() // --------------------------------- -// *** PlaterPresetComboBox *** +// *** TabPresetComboBox *** // --------------------------------- -TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type) : +TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type, bool is_from_physical_printer/* = false*/) : PresetComboBox(parent, preset_type, wxSize(35 * wxGetApp().em_unit(), -1)) { - Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& evt) { + Bind(wxEVT_COMBOBOX, [this, is_from_physical_printer](wxCommandEvent& evt) { // see https://github.com/prusa3d/PrusaSlicer/issues/3889 // Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender") // m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive. @@ -603,9 +603,16 @@ TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type) if (marker >= LABEL_ITEM_MARKER && marker < LABEL_ITEM_MAX) { this->SetSelection(this->m_last_selected); if (marker == LABEL_ITEM_WIZARD_PRINTERS) - wxTheApp->CallAfter([]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); }); + wxTheApp->CallAfter([this, is_from_physical_printer]() { + wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); + if (is_from_physical_printer) + update(); + }); } - else if (m_last_selected != selected_item || m_collection->current_is_dirty()) { + else if ( is_from_physical_printer) { + // do nothing + } + else if (m_last_selected != selected_item || m_collection->current_is_dirty() ) { std::string selected_string = this->GetString(selected_item).ToUTF8().data(); Tab* tab = wxGetApp().get_tab(this->m_type); assert (tab); @@ -638,7 +645,7 @@ void TabPresetComboBox::update() continue; 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); + wxBitmap main_bmp = create_scaled_bitmap(m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name, this); if (m_type == Preset::TYPE_PRINTER) { bitmap_key += "_printer"; if (preset.printer_technology() == ptSLA) @@ -694,8 +701,8 @@ void TabPresetComboBox::update() if (bmp == nullptr) { // Create the bitmap with color bars. std::vector bmps; - bmps.emplace_back(create_scaled_bitmap(m_main_bitmap_name)); - bmps.emplace_back(create_scaled_bitmap("edit_uni")); + bmps.emplace_back(create_scaled_bitmap(m_main_bitmap_name, this)); + bmps.emplace_back(create_scaled_bitmap("edit_uni", this)); bmp = m_bitmap_cache->insert(bitmap_key, bmps); } set_label_marker(Append(separator(L("Add/Remove printers")), *bmp), LABEL_ITEM_WIZARD_PRINTERS); @@ -753,8 +760,8 @@ void TabPresetComboBox::update_dirty() //------------------------------------------ -PhysicalPrinterDialog::PhysicalPrinterDialog() - : DPIDialog(NULL, wxID_ANY, _L("Search"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) +PhysicalPrinterDialog::PhysicalPrinterDialog(const wxString& printer_name, int last_selected_preset) + : DPIDialog(NULL, wxID_ANY, _L("PhysicalPrinter"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { SetFont(wxGetApp().normal_font()); SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); @@ -762,8 +769,9 @@ PhysicalPrinterDialog::PhysicalPrinterDialog() int border = 10; int em = em_unit(); - printer_text = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); - printer_presets = new PlaterPresetComboBox(this, Preset::TYPE_PRINTER); + printer_text = new wxTextCtrl(this, wxID_ANY, printer_name, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); + printer_presets = new TabPresetComboBox(this, Preset::TYPE_PRINTER, true); + printer_presets->update(); wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 3d9a13490..38b98d658 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -43,7 +43,6 @@ public: }; void set_label_marker(int item, LabelItemType label_item_type = LABEL_ITEM_MARKER); - int em_unit() const { return m_em_unit; } virtual void update() {}; virtual void msw_rescale(); @@ -131,13 +130,13 @@ private: // --------------------------------- -// *** PlaterPresetComboBox *** +// *** TabPresetComboBox *** // --------------------------------- class TabPresetComboBox : public PresetComboBox { public: - TabPresetComboBox(wxWindow *parent, Preset::Type preset_type); + TabPresetComboBox(wxWindow *parent, Preset::Type preset_type, bool is_from_physical_printer = false); ~TabPresetComboBox() {} void set_show_incompatible_presets(bool show_incompatible_presets) { show_incompatible = show_incompatible_presets; @@ -165,7 +164,7 @@ class PhysicalPrinterDialog : public DPIDialog PresetComboBox* printer_presets; public: - PhysicalPrinterDialog(); + PhysicalPrinterDialog(const wxString& printer_name, int last_selected_preset); ~PhysicalPrinterDialog() {} protected: diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 88c11030d..bb19e139d 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -815,7 +815,7 @@ void Tab::update_visibility() void Tab::msw_rescale() { - m_em_unit = wxGetApp().em_unit(); + m_em_unit = em_unit(m_parent); m_mode_sizer->msw_rescale(); m_presets_choice->msw_rescale(); @@ -827,6 +827,8 @@ void Tab::msw_rescale() btn->msw_rescale(); for (const auto bmp : m_scaled_bitmaps) bmp->msw_rescale(); + for (const auto ikon : m_blinking_ikons) + ikon.second->msw_rescale(); for (ScalableBitmap& bmp : m_mode_bitmap_cache) bmp.msw_rescale(); From 02624689ce345dc20d24194d4c6b4d8c438d7907 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 24 Jun 2020 08:50:01 +0200 Subject: [PATCH 04/31] Physical Printers. - save/load printers - consistency between selection on Tab and Plater --- src/libslic3r/Preset.cpp | 250 ++++++++++++-------- src/libslic3r/Preset.hpp | 109 ++++----- src/libslic3r/PresetBundle.cpp | 24 +- src/libslic3r/PresetBundle.hpp | 1 + src/libslic3r/PrintConfig.cpp | 20 ++ src/slic3r/GUI/Plater.cpp | 30 ++- src/slic3r/GUI/PresetComboBoxes.cpp | 342 ++++++++++++++++++++++++---- src/slic3r/GUI/PresetComboBoxes.hpp | 37 ++- src/slic3r/GUI/Tab.cpp | 10 + 9 files changed, 600 insertions(+), 223 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index e46cd6c82..94c9577df 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1339,108 +1339,178 @@ const Preset* PrinterPresetCollection::find_by_model_id(const std::string &model return it != cend() ? &*it : nullptr; } -/* -PhysicalPrinter& PhysicalPrinterCollection::load_external_printer( - // Path to the profile source file (a G-code, an AMF or 3MF file, a config file) - const std::string& path, - // Name of the profile, derived from the source file name. - const std::string& name, - // Original name of the profile, extracted from the loaded config. Empty, if the name has not been stored. - const std::string& original_name, - // Config to initialize the preset from. - const DynamicPrintConfig& config, - // Select the preset after loading? - bool select) -{ - // Load the preset over a default preset, so that the missing fields are filled in from the default preset. - DynamicPrintConfig cfg(this->default_printer().config); - cfg.apply_only(config, cfg.keys(), true); - // Is there a preset already loaded with the name stored inside the config? - std::deque::iterator it = this->find_printer_internal(original_name); - bool found = it != m_printers.end() && it->name == original_name; - if (!found) { - // Try to match the original_name against the "renamed_from" profile names of loaded system profiles. - / * - it = this->find_preset_renamed(original_name); - found = it != m_presets.end(); - * / - } - if (found) { - if (profile_print_params_same(it->config, cfg)) { - // The preset exists and it matches the values stored inside config. - if (select) - this->select_printer(it - m_printers.begin()); - return *it; - } - if (profile_host_params_same_or_anonymized(it->config, cfg) == ProfileHostParams::Anonymized) { - // The project being loaded is anonymized. Replace the empty host keys of the loaded profile with the data from the original profile. - // See "Octoprint Settings when Opening a .3MF file" GH issue #3244 - auto opt_update = [it, &cfg](const std::string& opt_key) { - auto opt = it->config.option(opt_key); - if (opt != nullptr) - cfg.set_key_value(opt_key, opt->clone()); - }; - opt_update("print_host"); - opt_update("printhost_apikey"); - opt_update("printhost_cafile"); - } - } - // The external preset does not match an internal preset, load the external preset. - std::string new_name; - for (size_t idx = 0;; ++idx) { - std::string suffix; - if (original_name.empty()) { - if (idx > 0) - suffix = " (" + std::to_string(idx) + ")"; - } - else { - if (idx == 0) - suffix = " (" + original_name + ")"; - else - suffix = " (" + original_name + "-" + std::to_string(idx) + ")"; - } - new_name = name + suffix; - it = this->find_printer_internal(new_name); - if (it == m_printers.end() || it->name != new_name) - // Unique profile name. Insert a new profile. - break; - if (profile_print_params_same(it->config, cfg)) { - // The preset exists and it matches the values stored inside config. - if (select) - this->select_printer(it - m_printers.begin()); - return *it; - } - // Form another profile name. - } - // Insert a new profile. - PhysicalPrinter& printer = this->load_printer(path, new_name, std::move(cfg), select); - return printer; +// ------------------------- +// *** PhysicalPrinter *** +// ------------------------- + +const std::vector& PhysicalPrinter::printer_options() +{ + static std::vector s_opts; + if (s_opts.empty()) { + s_opts = { + "preset_name", + "printer_technology", + "host_type", + "print_host", + "printhost_apikey", + "printhost_cafile", + "login", + "password" + }; + } + return s_opts; } -void PhysicalPrinterCollection::save_printer(const std::string& new_name) +const std::string& PhysicalPrinter::get_preset_name() +{ + return config.opt_string("preset_name"); +} + +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)); +} + +void PhysicalPrinter::update_from_config(const DynamicPrintConfig& new_config) +{ + config.apply_only(new_config, printer_options(), false); +} + +PhysicalPrinter::PhysicalPrinter(const std::string& name, const Preset& preset) : + name(name) +{ + update_from_preset(preset); +} + + +// ----------------------------------- +// *** PhysicalPrinterCollection *** +// ----------------------------------- + +PhysicalPrinterCollection::PhysicalPrinterCollection( const std::vector& keys) +{ +} + +// Load all presets found in dir_path. +// Throws an exception on error. +void PhysicalPrinterCollection::load_printers(const std::string& dir_path, const std::string& subdir) +{ + boost::filesystem::path dir = boost::filesystem::canonical(boost::filesystem::path(dir_path) / subdir).make_preferred(); + m_dir_path = dir.string(); + std::string errors_cummulative; + // Store the loaded printers into a new vector, otherwise the binary search for already existing presets would be broken. + std::deque printers_loaded; + for (auto& dir_entry : boost::filesystem::directory_iterator(dir)) + if (Slic3r::is_ini_file(dir_entry)) { + std::string name = dir_entry.path().filename().string(); + // Remove the .ini suffix. + name.erase(name.size() - 4); + if (this->find_printer(name, false)) { + // This happens when there's is a preset (most likely legacy one) with the same name as a system preset + // that's already been loaded from a bundle. + BOOST_LOG_TRIVIAL(warning) << "Preset already present, not loading: " << name; + continue; + } + try { + PhysicalPrinter printer(name); + printer.file = dir_entry.path().string(); + // Load the preset file, apply preset values on top of defaults. + try { + DynamicPrintConfig config; + config.load_from_ini(printer.file); + printer.update_from_config(config); + printer.loaded = true; + } + catch (const std::ifstream::failure& err) { + throw std::runtime_error(std::string("The selected preset cannot be loaded: ") + printer.file + "\n\tReason: " + err.what()); + } + catch (const std::runtime_error& err) { + throw std::runtime_error(std::string("Failed loading the preset file: ") + printer.file + "\n\tReason: " + err.what()); + } + printers_loaded.emplace_back(printer); + } + catch (const std::runtime_error& err) { + errors_cummulative += err.what(); + errors_cummulative += "\n"; + } + } + m_printers.insert(m_printers.end(), std::make_move_iterator(printers_loaded.begin()), std::make_move_iterator(printers_loaded.end())); + std::sort(m_printers.begin(), m_printers.end()); +//! this->select_preset(first_visible_idx()); + if (!errors_cummulative.empty()) + throw std::runtime_error(errors_cummulative); +} + +PhysicalPrinter* PhysicalPrinterCollection::find_printer( const std::string& name, bool first_visible_if_not_found) +{ + PhysicalPrinter key(name); + auto it = this->find_printer_internal(name); + // Ensure that a temporary copy is returned if the preset found is currently selected. + return (it != m_printers.end() && it->name == key.name) ? &this->printer(it - m_printers.begin()) : + first_visible_if_not_found ? &this->printer(0) : nullptr; +} + +// Generate a file path from a profile name. Add the ".ini" suffix if it is missing. +std::string PhysicalPrinterCollection::path_from_name(const std::string& new_name) const +{ + std::string file_name = boost::iends_with(new_name, ".ini") ? new_name : (new_name + ".ini"); + return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string(); +} + +void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_printer) { // 1) Find the printer with a new_name or create a new one, // initialize it with the edited config. - auto it = this->find_printer_internal(new_name); - if (it != m_printers.end() && it->name == new_name) { - // Preset with the same name found. - PhysicalPrinter& printer = *it; + auto it = this->find_printer_internal(edited_printer.name); + if (it != m_printers.end() && it->name == edited_printer.name) { + // Printer with the same name found. // Overwriting an existing preset. - printer.config = std::move(m_edited_printer.config); + it->config = std::move(edited_printer.config); } else { // Creating a new printer. - PhysicalPrinter& printer = *m_printers.insert(it, m_edited_printer); - std::string old_name = printer.name; - printer.name = new_name; + it = m_printers.insert(it, edited_printer); } - // 2) Activate the saved preset. - this->select_printer_by_name(new_name, true); - // 3) Store the active preset to disk. - this->get_selected_preset().save(); + assert(it != m_printers.end()); + + // 2) Save printer + PhysicalPrinter& printer = *it; + if (printer.file.empty()) + printer.file = this->path_from_name(printer.name); + printer.save(); + + // update idx_selected + m_idx_selected = it - m_printers.begin(); } -*/ + +bool PhysicalPrinterCollection::delete_printer(const std::string& name) +{ + auto it = this->find_printer_internal(name); + + const PhysicalPrinter& printer = *it; + if (it == m_printers.end()) + return false; + + // Erase the preset file. + boost::nowide::remove(printer.file.c_str()); + m_printers.erase(it); + return true; +} + +PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(const std::string& name) +{ + auto it = this->find_printer_internal(name); + assert(it != m_printers.end()); + + // update idx_selected + m_idx_selected = it - m_printers.begin(); + return *it; +} + + namespace PresetUtils { const VendorProfile::PrinterModel* system_printer_model(const Preset &preset) { diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index b0af2f142..c08a1a0fb 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -535,14 +535,14 @@ namespace PresetUtils { class PhysicalPrinter { public: - PhysicalPrinter(const std::string& name) : name(name) {} + PhysicalPrinter() {} + PhysicalPrinter(const std::string& name) : name(name){} + PhysicalPrinter(const std::string& name, const Preset& preset); // Name of the Physical Printer, usually derived form the file name. std::string name; // File name of the Physical Printer. std::string file; - // Name of the related Printer preset - std::string preset_name; // Has this profile been loaded? bool loaded = false; @@ -550,7 +550,13 @@ public: // 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(); + void save() { this->config.save(this->file); } + void save_to(const std::string& file_name) const { this->config.save(file_name); } + void update_from_preset(const Preset& preset); + void update_from_config(const DynamicPrintConfig &new_config); // Return a printer technology, return ptFFF if the printer technology is not set. static PrinterTechnology printer_technology(const DynamicPrintConfig& cfg) { @@ -562,18 +568,22 @@ public: PrinterTechnology printer_technology() const { return printer_technology(this->config); } // Sort lexicographically by a preset name. The preset name shall be unique across a single PresetCollection. - bool operator<(const Preset& other) const { return this->name < other.name; } + bool operator<(const PhysicalPrinter& other) const { return this->name < other.name; } protected: friend class PhysicalPrinterCollection; }; -/* -// Collections of presets of the same type (one of the Print, Filament or Printer type). + + +// --------------------------------- +// *** PhysicalPrinterCollection *** +// --------------------------------- + +// Collections of physical printers class PhysicalPrinterCollection { public: - // Initialize the PresetCollection with the "- default -" preset. - PhysicalPrinterCollection(const std::vector& keys) : m_idx_selected(0) {} + PhysicalPrinterCollection(const std::vector& keys); ~PhysicalPrinterCollection() {} typedef std::deque::iterator Iterator; @@ -585,63 +595,39 @@ public: ConstIterator end() const { return m_printers.cend(); } ConstIterator cend() const { return m_printers.cend(); } + bool empty() const {return m_printers.empty(); } + void reset(bool delete_files) {}; const std::deque& operator()() const { return m_printers; } // Load ini files of the particular type from the provided directory path. - void load_printers(const std::string& dir_path, const std::string& subdir){}; - - // Load a preset from an already parsed config file, insert it into the sorted sequence of presets - // and select it, losing previous modifications. - PhysicalPrinter& load_printer(const std::string& path, const std::string& name, const DynamicPrintConfig& config, bool select = true); - PhysicalPrinter& load_printer(const std::string& path, const std::string& name, DynamicPrintConfig&& config, bool select = true); - - PhysicalPrinter& load_external_printer( - // Path to the profile source file (a G-code, an AMF or 3MF file, a config file) - const std::string& path, - // Name of the profile, derived from the source file name. - const std::string& name, - // Original name of the profile, extracted from the loaded config. Empty, if the name has not been stored. - const std::string& original_name, - // Config to initialize the preset from. - const DynamicPrintConfig& config, - // Select the preset after loading? - bool select = true); + void load_printers(const std::string& dir_path, const std::string& subdir); // Save the printer under a new name. If the name is different from the old one, // a new printer is stored into the list of printers. - // ? New printer is activated. - void save_printer(const std::string& new_name); + // New printer is activated. + void save_printer(const PhysicalPrinter& printer); // Delete the current preset, activate the first visible preset. // returns true if the preset was deleted successfully. - bool delete_current_printer() {return true;} - // Delete the current preset, activate the first visible preset. - // returns true if the preset was deleted successfully. - bool delete_printer(const std::string& name) { return true; } + bool delete_printer(const std::string& name); - // Select a printer. If an invalid index is provided, the first visible printer is selected. - PhysicalPrinter& select_printer(size_t idx); // Return the selected preset, without the user modifications applied. - PhysicalPrinter& get_selected_preset() { return m_printers[m_idx_selected]; } - const PhysicalPrinter& get_selected_preset() const { return m_printers[m_idx_selected]; } + PhysicalPrinter& get_selected_printer() { return m_printers[m_idx_selected]; } + const PhysicalPrinter& get_selected_printer() const { return m_printers[m_idx_selected]; } 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_preset_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_preset().name; } - PhysicalPrinter& get_edited_preset() { return m_edited_printer; } - const PhysicalPrinter& get_edited_preset() const { return m_edited_printer; } + std::string get_selected_printer_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().name; } + DynamicPrintConfig* get_selected_printer_config() { return (m_idx_selected == size_t(-1)) ? nullptr : &(this->get_selected_printer().config); } - // Return a preset possibly with modifications. - PhysicalPrinter& default_printer(size_t idx = 0) { return m_printers[idx]; } - const PhysicalPrinter& default_printer(size_t idx = 0) const { return m_printers[idx]; } + // select printer with name and return reference on it + PhysicalPrinter& select_printer_by_name(const std::string& name); + bool has_selection() const { return m_idx_selected != size_t(-1); } + void unselect_printer() { m_idx_selected = size_t(-1); } - // used to update preset_choice from Tab - const std::deque& get_presets() const { return m_printers; } - size_t get_idx_selected() { return m_idx_selected; } - - // Return a preset by an index. If the preset is active, a temporary copy is returned. - PhysicalPrinter& printer(size_t idx) { return (idx == m_idx_selected) ? m_edited_printer : m_printers[idx]; } + // Return a printer by an index. If the printer is active, a temporary copy is returned. + PhysicalPrinter& printer(size_t idx) { return m_printers[idx]; } const PhysicalPrinter& printer(size_t idx) const { return const_cast(this)->printer(idx); } // Return a preset by its name. If the preset is active, a temporary copy is returned. @@ -652,20 +638,10 @@ public: return const_cast(this)->find_printer(name, first_visible_if_not_found); } - // Return number of presets including the "- default -" preset. - size_t size() const { return m_printers.size(); } - - // Select a profile by its name. Return true if the selection changed. - // Without force, the selection is only updated if the index changes. - // With force, the changes are reverted if the new index is the same as the old index. - bool select_printer_by_name(const std::string& name, bool force) {}; - // Generate a file path from a profile name. Add the ".ini" suffix if it is missing. std::string path_from_name(const std::string& new_name) const; private: -// PhysicalPrinterCollection(); - PhysicalPrinterCollection(const PhysicalPrinterCollection& other); PhysicalPrinterCollection& operator=(const PhysicalPrinterCollection& other); // Find a preset position in the sorted list of presets. @@ -674,8 +650,8 @@ private: // If a preset does not exist, an iterator is returned indicating where to insert a preset with the same name. std::deque::iterator find_printer_internal(const std::string& name) { - PhysicalPrinter key(name); - auto it = std::lower_bound(m_printers.begin()+0, m_printers.end(), key); + PhysicalPrinter printer(name); + auto it = std::lower_bound(m_printers.begin(), m_printers.end(), printer); return it; } std::deque::const_iterator find_printer_internal(const std::string& name) const @@ -683,23 +659,18 @@ private: return const_cast(this)->find_printer_internal(name); } - static std::vector dirty_options(const Preset* edited, const Preset* reference, const bool is_printer_type = false); - - // List of presets, starting with the "- default -" preset. + // List of printers // Use deque to force the container to allocate an object per each entry, // so that the addresses of the presets don't change during resizing of the container. std::deque m_printers; - // Initially this printer contains a copy of the selected printer. Later on, this copy may be modified by the user. - PhysicalPrinter m_edited_printer; - // Selected preset. - size_t m_idx_selected; + + // Selected printer. + size_t m_idx_selected = size_t(-1); // Path to the directory to store the config files into. std::string m_dir_path; }; -////////////////////////////////////////////////////////////////////// -*/ } // namespace Slic3r diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 9da7731a4..7c4fa1cb2 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -41,7 +41,8 @@ PresetBundle::PresetBundle() : filaments(Preset::TYPE_FILAMENT, Preset::filament_options(), static_cast(FullPrintConfig::defaults())), sla_materials(Preset::TYPE_SLA_MATERIAL, Preset::sla_material_options(), static_cast(SLAFullPrintConfig::defaults())), sla_prints(Preset::TYPE_SLA_PRINT, Preset::sla_print_options(), static_cast(SLAFullPrintConfig::defaults())), - printers(Preset::TYPE_PRINTER, Preset::printer_options(), static_cast(FullPrintConfig::defaults()), "- default FFF -") + printers(Preset::TYPE_PRINTER, Preset::printer_options(), static_cast(FullPrintConfig::defaults()), "- default FFF -"), + physical_printers(PhysicalPrinter::printer_options()) { // The following keys are handled by the UI, they do not have a counterpart in any StaticPrintConfig derived classes, // therefore they need to be handled differently. As they have no counterpart in StaticPrintConfig, they are not being @@ -139,14 +140,16 @@ void PresetBundle::setup_directories() data_dir / "presets" / "filament", data_dir / "presets" / "sla_print", data_dir / "presets" / "sla_material", - data_dir / "presets" / "printer" + data_dir / "presets" / "printer", + data_dir / "presets" / "physical_printer" #else // Store the print/filament/printer presets at the same location as the upstream Slic3r. data_dir / "print", data_dir / "filament", data_dir / "sla_print", data_dir / "sla_material", - data_dir / "printer" + data_dir / "printer", + data_dir / "physical_printer" #endif }; for (const boost::filesystem::path &path : paths) { @@ -196,6 +199,11 @@ void PresetBundle::load_presets(AppConfig &config, const std::string &preferred_ } catch (const std::runtime_error &err) { errors_cummulative += err.what(); } + try { + this->physical_printers.load_printers(dir_user_presets, "physical_printer"); + } catch (const std::runtime_error &err) { + errors_cummulative += err.what(); + } this->update_multi_material_filament_presets(); this->update_compatible(PresetSelectCompatibleType::Never); if (! errors_cummulative.empty()) @@ -422,6 +430,14 @@ void PresetBundle::load_selections(AppConfig &config, const std::string &preferr // exist. this->update_compatible(PresetSelectCompatibleType::Always); this->update_multi_material_filament_presets(); + + // Parse the initial physical printer name. + std::string initial_physical_printer_name = remove_ini_suffix(config.get("extras", "physical_printer")); + + // Activate physical printer from the config + const PhysicalPrinter* initial_physical_printer = physical_printers.find_printer(initial_physical_printer_name); + if (initial_physical_printer) + physical_printers.select_printer_by_name(initial_physical_printer_name); } // Export selections (current print, current filaments, current printer) into config.ini @@ -441,6 +457,8 @@ void PresetBundle::export_selections(AppConfig &config) config.set("presets", "sla_print", sla_prints.get_selected_preset_name()); config.set("presets", "sla_material", sla_materials.get_selected_preset_name()); config.set("presets", "printer", printers.get_selected_preset_name()); + + config.set("extras", "physical_printer", physical_printers.get_selected_printer_name()); } DynamicPrintConfig PresetBundle::full_config() const diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 19d4093d6..2906584d3 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -39,6 +39,7 @@ public: PresetCollection& materials(PrinterTechnology pt) { return pt == ptFFF ? this->filaments : this->sla_materials; } const PresetCollection& materials(PrinterTechnology pt) const { return pt == ptFFF ? this->filaments : this->sla_materials; } PrinterPresetCollection printers; + PhysicalPrinterCollection physical_printers; // Filament preset names for a multi-extruder or multi-material print. // extruders.size() should be the same as printers.get_edited_preset().config.nozzle_diameter.size() std::vector filament_presets; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index d6a23d75d..93ef170fb 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -130,6 +130,26 @@ void PrintConfigDef::init_common_params() def->min = 0; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloat(0.2)); + + // Options used by physical printers + + def = this->add("login", coString); + def->label = L("Login"); +// def->tooltip = L(""); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionString("")); + + def = this->add("password", coString); + def->label = L("Password"); +// def->tooltip = L(""); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionString("")); + + def = this->add("preset_name", coString); + def->label = L("Printer preset name"); + def->tooltip = L("Related printer preset name"); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionString("")); } void PrintConfigDef::init_fff_params() diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index a78683bd4..048e17926 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -942,8 +942,6 @@ void Sidebar::msw_rescale() void Sidebar::sys_color_changed() { - // Update preset comboboxes in respect to the system color ... - // combo->msw_rescale() updates icon on button, so use it for (PlaterPresetComboBox* combo : std::vector{ p->combo_print, p->combo_sla_print, p->combo_sla_material, @@ -952,12 +950,8 @@ void Sidebar::sys_color_changed() for (PlaterPresetComboBox* combo : p->combos_filament) combo->msw_rescale(); - // ... then refill them and set min size to correct layout of the sidebar - update_all_preset_comboboxes(); - p->object_list->sys_color_changed(); p->object_manipulation->sys_color_changed(); -// p->object_settings->msw_rescale(); p->object_layers->sys_color_changed(); // btn...->msw_rescale() updates icon on button, so use it @@ -3208,12 +3202,23 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt) //! instead of //! combo->GetStringSelection().ToUTF8().data()); - const std::string preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type, + std::string preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type, Preset::remove_suffix_modified(combo->GetString(selection).ToUTF8().data())); if (preset_type == Preset::TYPE_FILAMENT) { wxGetApp().preset_bundle->set_filament_preset(idx, preset_name); } + + if (preset_type == Preset::TYPE_PRINTER) { + if(combo->is_selected_physical_printer()) { + // Select related printer preset on the Printer Settings Tab + const std::string printer_name = combo->GetString(selection).ToUTF8().data(); + PhysicalPrinter& printer = wxGetApp().preset_bundle->physical_printers.select_printer_by_name(printer_name); + preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type, printer.get_preset_name()); + } + else + wxGetApp().preset_bundle->physical_printers.unselect_printer(); + } // TODO: ? if (preset_type == Preset::TYPE_FILAMENT && sidebar->is_multifilament()) { @@ -3974,7 +3979,12 @@ void Plater::priv::show_action_buttons(const bool ready_to_slice) const this->ready_to_slice = ready_to_slice; wxWindowUpdateLocker noUpdater(sidebar); - const auto prin_host_opt = config->option("print_host"); + + DynamicPrintConfig* selected_printer_config = wxGetApp().preset_bundle->physical_printers.get_selected_printer_config(); + if (!selected_printer_config) + selected_printer_config = config; + + const auto prin_host_opt = selected_printer_config->option("print_host"); const bool send_gcode_shown = prin_host_opt != nullptr && !prin_host_opt->value.empty(); // when a background processing is ON, export_btn and/or send_btn are showing @@ -4893,7 +4903,9 @@ void Plater::send_gcode() { if (p->model.objects.empty()) { return; } - PrintHostJob upload_job(p->config); + // if physical_printer is selected, send gcode for this printer + DynamicPrintConfig* physical_printer_config = wxGetApp().preset_bundle->physical_printers.get_selected_printer_config(); + PrintHostJob upload_job(physical_printer_config ? physical_printer_config : p->config); if (upload_job.empty()) { return; } // Obtain default output path diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 6c38c866d..ce25d5690 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -31,6 +31,7 @@ #include "../Utils/UndoRedo.hpp" #include "RemovableDriveManager.hpp" #include "BitmapCache.hpp" +#include "BonjourDialog.hpp" using Slic3r::GUI::format_wxstr; @@ -241,8 +242,9 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset evt.StopPropagation(); if (marker == LABEL_ITEM_PHYSICAL_PRINTERS) { - PhysicalPrinterDialog dlg(_L("New Physical Printer"), this->m_last_selected); - dlg.ShowModal(); + PhysicalPrinterDialog dlg(wxEmptyString); + if (dlg.ShowModal() == wxID_OK) + this->update(); return; } if (marker >= LABEL_ITEM_WIZARD_PRINTERS) { @@ -255,7 +257,7 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset } wxTheApp->CallAfter([sp]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, sp); }); } - } else if ( this->m_last_selected != selected_item || m_collection->current_is_dirty() ) { + } 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); evt.Skip(); @@ -319,6 +321,16 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset edit_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent) { + // In a case of a physical printer, for its editing open PhysicalPrinterDialog + if (m_type == Preset::TYPE_PRINTER && this->is_selected_physical_printer()) + { + PhysicalPrinterDialog dlg(this->GetString(this->GetSelection())); + if (dlg.ShowModal() == wxID_OK) { + update(); + return; + } + } + Tab* tab = wxGetApp().get_tab(m_type); if (!tab) return; @@ -355,6 +367,13 @@ PlaterPresetComboBox::~PlaterPresetComboBox() edit_btn->Destroy(); } +bool PlaterPresetComboBox::is_selected_physical_printer() +{ + auto selected_item = this->GetSelection(); + auto marker = reinterpret_cast(this->GetClientData(selected_item)); + return marker == LABEL_ITEM_PHYSICAL_PRINTER; +} + // Only the compatible presets are shown. // If an incompatible preset is selected, it is shown as well. void PlaterPresetComboBox::update() @@ -388,7 +407,6 @@ void PlaterPresetComboBox::update() bool wide_icons = !selected_preset.is_compatible; std::map nonsys_presets; - std::map physical_printers; wxString selected = ""; wxString tooltip = ""; @@ -400,9 +418,11 @@ void PlaterPresetComboBox::update() for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i) { const Preset& preset = presets[i]; - bool is_selected = m_type == Preset::TYPE_FILAMENT ? - m_preset_bundle->filament_presets[m_extruder_idx] == preset.name : - i == m_collection->get_selected_idx(); + bool is_selected = m_type == Preset::TYPE_FILAMENT ? + m_preset_bundle->filament_presets[m_extruder_idx] == preset.name : + // The case, when some physical printer is selected + m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection() ? false : + i == m_collection->get_selected_idx(); if (!preset.is_visible || (!preset.is_compatible && !is_selected)) continue; @@ -495,17 +515,6 @@ void PlaterPresetComboBox::update() selected_preset_item = GetCount() - 1; } } - if (!physical_printers.empty()) - { - set_label_marker(Append(separator(L("Physical printers")), wxNullBitmap)); - for (std::map::iterator it = physical_printers.begin(); it != physical_printers.end(); ++it) { - Append(it->first, *it->second); - if (it->first == selected || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX) - selected_preset_item = GetCount() - 1; - } - } if (m_type == Preset::TYPE_PRINTER || m_type == Preset::TYPE_SLA_MATERIAL) { std::string bitmap_key = ""; @@ -536,8 +545,45 @@ void PlaterPresetComboBox::update() else set_label_marker(Append(separator(L("Add/Remove printers")), *bmp), LABEL_ITEM_WIZARD_PRINTERS); } - if (m_type == Preset::TYPE_PRINTER) { - std::string bitmap_key = ""; + + if (m_type == Preset::TYPE_PRINTER) + { + // add Physical printers, if any exists + if (!m_preset_bundle->physical_printers.empty()) { + set_label_marker(Append(separator(L("Physical printers")), wxNullBitmap)); + const PhysicalPrinterCollection& ph_printers = m_preset_bundle->physical_printers; + + for (PhysicalPrinterCollection::ConstIterator it = ph_printers.begin(); it != ph_printers.end(); ++it) { + std::string bitmap_key = it->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; + if (wide_icons) + bitmap_key += "wide,"; + 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. + 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(it->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name)); + // Paint a lock at the system presets. + bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width+norm_icon_width, icon_height)); + bmp = m_bitmap_cache->insert(bitmap_key, bmps); + } + + set_label_marker(Append(wxString::FromUTF8((it->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) + selected_preset_item = GetCount() - 1; + } + } + + // add LABEL_ITEM_PHYSICAL_PRINTERS + std::string bitmap_key; if (wide_icons) bitmap_key += "wide,"; bitmap_key += "edit_preset_list"; @@ -589,10 +635,10 @@ void PlaterPresetComboBox::msw_rescale() // *** TabPresetComboBox *** // --------------------------------- -TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type, bool is_from_physical_printer/* = false*/) : +TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type) : PresetComboBox(parent, preset_type, wxSize(35 * wxGetApp().em_unit(), -1)) { - Bind(wxEVT_COMBOBOX, [this, is_from_physical_printer](wxCommandEvent& evt) { + Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& evt) { // see https://github.com/prusa3d/PrusaSlicer/issues/3889 // Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender") // m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive. @@ -603,21 +649,17 @@ TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type, if (marker >= LABEL_ITEM_MARKER && marker < LABEL_ITEM_MAX) { this->SetSelection(this->m_last_selected); if (marker == LABEL_ITEM_WIZARD_PRINTERS) - wxTheApp->CallAfter([this, is_from_physical_printer]() { + wxTheApp->CallAfter([this]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); - if (is_from_physical_printer) + + // update combobox if its parent is a PhysicalPrinterDialog + PhysicalPrinterDialog* parent = dynamic_cast(this->GetParent()); + if (parent != nullptr) update(); }); } - else if ( is_from_physical_printer) { - // do nothing - } - else if (m_last_selected != selected_item || m_collection->current_is_dirty() ) { - std::string selected_string = this->GetString(selected_item).ToUTF8().data(); - Tab* tab = wxGetApp().get_tab(this->m_type); - assert (tab); - tab->select_preset(selected_string); - } + else if (on_selection_changed && (m_last_selected != selected_item || m_collection->current_is_dirty()) ) + on_selection_changed(selected_item); evt.StopPropagation(); }); @@ -760,35 +802,212 @@ void TabPresetComboBox::update_dirty() //------------------------------------------ -PhysicalPrinterDialog::PhysicalPrinterDialog(const wxString& printer_name, int last_selected_preset) +PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) : DPIDialog(NULL, wxID_ANY, _L("PhysicalPrinter"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { SetFont(wxGetApp().normal_font()); SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); int border = 10; - int em = em_unit(); - printer_text = new wxTextCtrl(this, wxID_ANY, printer_name, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); - printer_presets = new TabPresetComboBox(this, Preset::TYPE_PRINTER, true); - printer_presets->update(); + m_printer_presets = new TabPresetComboBox(this, Preset::TYPE_PRINTER); + 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); + assert(preset); + Preset& edited_preset = wxGetApp().preset_bundle->printers.get_edited_preset(); + if (preset->name == edited_preset.name) + preset = &edited_preset; + m_printer.update_from_preset(*preset); + + // update values + m_optgroup->reload_config(); + update_octoprint_visible(); + }); + m_printer_presets->update(); + + wxString preset_name = m_printer_presets->GetString(m_printer_presets->GetSelection()); + + 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); + + PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; + PhysicalPrinter* printer = printers.find_printer(into_u8(printer_name)); + if (!printer) { + const Preset& preset = wxGetApp().preset_bundle->printers.get_edited_preset(); + printer = new PhysicalPrinter(into_u8(printer_name), preset); + } + assert(printer); + m_printer = *printer; + + m_config = &m_printer.config; + + m_optgroup = new ConfigOptionsGroup(this, _L("Print Host upload"), m_config); + build_printhost_settings(m_optgroup); + m_optgroup->reload_config(); wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); + wxButton* btnOK = static_cast(this->FindWindowById(wxID_OK, this)); + btnOK->Bind(wxEVT_BUTTON, &PhysicalPrinterDialog::OnOK, this); wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); - topSizer->Add(printer_text , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); - topSizer->Add(printer_presets , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); - topSizer->Add(btns , 0, wxEXPAND | wxALL, 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(m_optgroup->sizer , 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); + topSizer->Add(btns , 0, wxEXPAND | wxALL, border); SetSizer(topSizer); topSizer->SetSizeHints(this); } +void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgroup) +{ + m_optgroup->append_single_option_line("host_type"); + + auto create_sizer_with_btn = [this](wxWindow* parent, ScalableButton** btn, const std::string& icon_name, const wxString& label) { + *btn = new ScalableButton(parent, wxID_ANY, icon_name, label, wxDefaultSize, wxDefaultPosition, wxBU_LEFT | wxBU_EXACTFIT); + (*btn)->SetFont(wxGetApp().normal_font()); + + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(*btn); + return sizer; + }; + + auto printhost_browse = [=](wxWindow* parent) + { + auto sizer = create_sizer_with_btn(parent, &m_printhost_browse_btn, "browse", _L("Browse") + " " + dots); + m_printhost_browse_btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent& e) { + BonjourDialog dialog(this, Preset::printer_technology(m_printer.config)); + if (dialog.show_and_lookup()) { + m_optgroup->set_value("print_host", std::move(dialog.get_selected()), true); + m_optgroup->get_field("print_host")->field_changed(); + } + }); + + return sizer; + }; + + auto print_host_test = [=](wxWindow* parent) { + auto sizer = create_sizer_with_btn(parent, &m_printhost_test_btn, "test", _L("Test")); + + m_printhost_test_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) { + std::unique_ptr host(PrintHost::get_print_host(m_config)); + if (!host) { + const wxString text = _L("Could not get a valid Printer Host reference"); + show_error(this, text); + return; + } + wxString msg; + if (host->test(msg)) { + show_info(this, host->get_test_ok_msg(), _L("Success!")); + } + else { + show_error(this, host->get_test_failed_msg(msg)); + } + }); + + return sizer; + }; + + // Set a wider width for a better alignment + Option option = m_optgroup->get_option("print_host"); + option.opt.width = Field::def_width_wider(); + Line host_line = m_optgroup->create_single_option_line(option); + host_line.append_widget(printhost_browse); + host_line.append_widget(print_host_test); + m_optgroup->append_line(host_line); + option = m_optgroup->get_option("printhost_apikey"); + option.opt.width = Field::def_width_wider(); + m_optgroup->append_single_option_line(option); + + const auto ca_file_hint = _u8L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate."); + + if (Http::ca_file_supported()) { + option = m_optgroup->get_option("printhost_cafile"); + option.opt.width = Field::def_width_wider(); + Line cafile_line = m_optgroup->create_single_option_line(option); + + auto printhost_cafile_browse = [=](wxWindow* parent) { + auto sizer = create_sizer_with_btn(parent, &m_printhost_cafile_browse_btn, "browse", _L("Browse") + " " + dots); + m_printhost_cafile_browse_btn->Bind(wxEVT_BUTTON, [this, m_optgroup](wxCommandEvent e) { + static const auto filemasks = _L("Certificate files (*.crt, *.pem)|*.crt;*.pem|All files|*.*"); + wxFileDialog openFileDialog(this, _L("Open CA certificate file"), "", "", filemasks, wxFD_OPEN | wxFD_FILE_MUST_EXIST); + if (openFileDialog.ShowModal() != wxID_CANCEL) { + m_optgroup->set_value("printhost_cafile", std::move(openFileDialog.GetPath()), true); + m_optgroup->get_field("printhost_cafile")->field_changed(); + } + }); + + return sizer; + }; + + cafile_line.append_widget(printhost_cafile_browse); + m_optgroup->append_line(cafile_line); + + Line cafile_hint{ "", "" }; + cafile_hint.full_width = 1; + cafile_hint.widget = [this, ca_file_hint](wxWindow* parent) { + auto txt = new wxStaticText(parent, wxID_ANY, ca_file_hint); + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(txt); + return sizer; + }; + m_optgroup->append_line(cafile_hint); + } + else { + Line line{ "", "" }; + line.full_width = 1; + + line.widget = [ca_file_hint](wxWindow* parent) { + std::string info = _u8L("HTTPS CA File") + ":\n\t" + + (boost::format(_u8L("On this system, %s uses HTTPS certificates from the system Certificate Store or Keychain.")) % SLIC3R_APP_NAME).str() + + "\n\t" + _u8L("To use a custom CA file, please import your CA file into Certificate Store / Keychain."); + + auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\n\t%2%") % info % ca_file_hint).str())); + txt->SetFont(wxGetApp().normal_font()); + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(txt, 1, wxEXPAND); + return sizer; + }; + + m_optgroup->append_line(line); + } + + for (const std::string& opt_key : std::vector{ "login", "password" }) { + option = m_optgroup->get_option(opt_key); + option.opt.width = Field::def_width_wider(); + m_optgroup->append_single_option_line(option); + } + + update_octoprint_visible(); +} + +void PhysicalPrinterDialog::update_octoprint_visible() +{ + const PrinterTechnology tech = Preset::printer_technology(m_printer.config); + // Only offer the host type selection for FFF, for SLA it's always the SL1 printer (at the moment) + Field* host_type = m_optgroup->get_field("host_type"); + if (tech == ptFFF) + host_type->enable(); + else { + host_type->set_value(int(PrintHostType::htOctoPrint), false); + host_type->disable(); + } +} + void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) { const int& em = em_unit(); + m_printhost_browse_btn->msw_rescale(); + m_printhost_test_btn->msw_rescale(); + if (m_printhost_cafile_browse_btn) + m_printhost_cafile_browse_btn->msw_rescale(); + + m_optgroup->msw_rescale(); + msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL }); const wxSize& size = wxSize(40 * em, 30 * em); @@ -798,5 +1017,46 @@ void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) Refresh(); } +void PhysicalPrinterDialog::OnOK(wxEvent& event) +{ + wxString printer_name = m_printer_name->GetValue(); + if (printer_name.IsEmpty()) { + show_error(this, _L("The supplied name is empty. It can't be saved.")); + return; + } + + PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; + const PhysicalPrinter* existing = printers.find_printer(into_u8(printer_name)); + if (existing && into_u8(printer_name) != printers.get_selected_printer_name()) + { + wxString msg_text = from_u8((boost::format(_u8L("Printer with name \"%1%\" already exists.")) % printer_name).str()); + msg_text += "\n" + _L("Replace?"); + wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO); + + if (dialog.ShowModal() == wxID_NO) + return; + + // Remove the printer from the list. + printers.delete_printer(into_u8(printer_name)); + } + + //upadte printer name, if it was changed + m_printer.name = into_u8(printer_name); + + // save new physical printer + printers.save_printer(m_printer); + + // update selection on the tab only when it was changed + if (m_printer.get_preset_name() != wxGetApp().preset_bundle->printers.get_selected_preset_name()) { + Tab* tab = wxGetApp().get_tab(Preset::TYPE_PRINTER); + if (tab) { + wxString preset_name = m_printer_presets->GetString(m_printer_presets->GetSelection()); + tab->select_preset(into_u8(preset_name)); + } + } + + event.Skip(); +} + }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 38b98d658..e1597bcfc 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -13,6 +13,7 @@ class wxString; class wxTextCtrl; +class ScalableButton; namespace Slic3r { @@ -33,7 +34,8 @@ public: ~PresetComboBox(); enum LabelItemType { - LABEL_ITEM_MARKER = 0xffffff01, + LABEL_ITEM_PHYSICAL_PRINTER = 0xffffff01, + LABEL_ITEM_MARKER, LABEL_ITEM_PHYSICAL_PRINTERS, LABEL_ITEM_WIZARD_PRINTERS, LABEL_ITEM_WIZARD_FILAMENTS, @@ -121,11 +123,13 @@ public: void set_extruder_idx(const int extr_idx) { m_extruder_idx = extr_idx; } int get_extruder_idx() const { return m_extruder_idx; } + bool is_selected_physical_printer(); + void update() override; void msw_rescale() override; private: - int m_extruder_idx = -1; + int m_extruder_idx = -1; }; @@ -135,8 +139,11 @@ private: class TabPresetComboBox : public PresetComboBox { + bool show_incompatible {false}; + std::function on_selection_changed { nullptr }; + public: - TabPresetComboBox(wxWindow *parent, Preset::Type preset_type, bool is_from_physical_printer = false); + TabPresetComboBox(wxWindow *parent, Preset::Type preset_type); ~TabPresetComboBox() {} void set_show_incompatible_presets(bool show_incompatible_presets) { show_incompatible = show_incompatible_presets; @@ -146,25 +153,33 @@ public: void update_dirty(); void msw_rescale() override; -private: - bool show_incompatible{false}; + void set_selection_changed_function(std::function sel_changed) { on_selection_changed = sel_changed; } }; //------------------------------------------ // PhysicalPrinterDialog //------------------------------------------ - +class ConfigOptionsGroup; class PhysicalPrinterDialog : public DPIDialog { - std::string printer_name; - std::string preset_name; + PhysicalPrinter m_printer; + DynamicPrintConfig* m_config { nullptr }; - wxTextCtrl* printer_text { nullptr }; - PresetComboBox* printer_presets; + wxTextCtrl* m_printer_name { nullptr }; + TabPresetComboBox* m_printer_presets { nullptr }; + ConfigOptionsGroup* m_optgroup { nullptr }; + + ScalableButton* m_printhost_browse_btn; + ScalableButton* m_printhost_test_btn; + ScalableButton* m_printhost_cafile_browse_btn {nullptr}; + + void build_printhost_settings(ConfigOptionsGroup* optgroup); + void update_octoprint_visible(); + void OnOK(wxEvent& event); public: - PhysicalPrinterDialog(const wxString& printer_name, int last_selected_preset); + PhysicalPrinterDialog(wxString printer_name); ~PhysicalPrinterDialog() {} protected: diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index bb19e139d..da5d51dc5 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -161,6 +161,13 @@ 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(); + select_preset(selected_string); + }); auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); @@ -3022,6 +3029,9 @@ void Tab::select_preset(std::string preset_name, bool delete_current) if (canceled) { update_tab_ui(); + // unselect physical printer selection to the correct synchronization of the printer presets between Tab and Plater + if (m_type == Preset::TYPE_PRINTER) + m_preset_bundle->physical_printers.unselect_printer(); // Trigger the on_presets_changed event so that we also restore the previous value in the plater selector, // if this action was initiated from the plater. on_presets_changed(); From 89035febfaf926394eaef82db007694dc87c9713 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 24 Jun 2020 09:20:04 +0200 Subject: [PATCH 05/31] Fixed includes --- src/slic3r/Utils/FixModelByWin10.cpp | 2 +- xs/xsp/Model.xsp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slic3r/Utils/FixModelByWin10.cpp b/src/slic3r/Utils/FixModelByWin10.cpp index 0de526432..a3683a84d 100644 --- a/src/slic3r/Utils/FixModelByWin10.cpp +++ b/src/slic3r/Utils/FixModelByWin10.cpp @@ -30,10 +30,10 @@ #include "libslic3r/Model.hpp" #include "libslic3r/Print.hpp" +#include "libslic3r/PresetBundle.hpp" #include "libslic3r/Format/3mf.hpp" #include "../GUI/GUI.hpp" #include "../GUI/I18N.hpp" -#include "../GUI/PresetBundle.hpp" #include #include diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index 4fb35578d..844b7c95e 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -12,7 +12,7 @@ #include "libslic3r/Format/OBJ.hpp" #include "libslic3r/Format/PRUS.hpp" #include "libslic3r/Format/STL.hpp" -#include "slic3r/GUI/PresetBundle.hpp" +#include "libslic3r/PresetBundle.hpp" %} %name{Slic3r::Model} class Model { From 8ac839f427ef2c0d1470de51e8d9515689296e83 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 24 Jun 2020 12:28:00 +0200 Subject: [PATCH 06/31] Physical printers: Delete selected printer + Added context menu for the cog-button near the printer presets --- src/libslic3r/Preset.cpp | 21 +++++++-- src/libslic3r/Preset.hpp | 3 ++ src/slic3r/GUI/PresetComboBoxes.cpp | 72 +++++++++++++++++++++-------- src/slic3r/GUI/PresetComboBoxes.hpp | 2 + 4 files changed, 76 insertions(+), 22 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 94c9577df..e17130f69 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1489,17 +1489,32 @@ void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_print bool PhysicalPrinterCollection::delete_printer(const std::string& name) { auto it = this->find_printer_internal(name); + if (it == m_printers.end()) + return false; const PhysicalPrinter& printer = *it; - if (it == m_printers.end()) - return false; - // Erase the preset file. boost::nowide::remove(printer.file.c_str()); m_printers.erase(it); return true; } +bool PhysicalPrinterCollection::delete_selected_printer() +{ + if (!has_selection()) + return false; + const PhysicalPrinter& printer = this->get_selected_printer(); + + // Erase the preset file. + boost::nowide::remove(printer.file.c_str()); + // Remove the preset from the list. + m_printers.erase(m_printers.begin() + m_idx_selected); + // unselect all printers + unselect_printer(); + + return true; +} + PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(const std::string& name) { auto it = this->find_printer_internal(name); diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index c08a1a0fb..a5837a9fe 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -612,6 +612,9 @@ public: // Delete the current preset, activate the first visible preset. // returns true if the preset was deleted successfully. bool delete_printer(const std::string& name); + // Delete the selected preset + // returns true if the preset was deleted successfully. + bool delete_selected_printer(); // Return the selected preset, without the user modifications applied. PhysicalPrinter& get_selected_printer() { return m_printers[m_idx_selected]; } diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index ce25d5690..e9da7dc9d 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "libslic3r/libslic3r.h" #include "libslic3r/PrintConfig.hpp" @@ -322,28 +323,14 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset edit_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent) { // In a case of a physical printer, for its editing open PhysicalPrinterDialog - if (m_type == Preset::TYPE_PRINTER && this->is_selected_physical_printer()) - { - PhysicalPrinterDialog dlg(this->GetString(this->GetSelection())); - if (dlg.ShowModal() == wxID_OK) { - update(); - return; - } + if (m_type == Preset::TYPE_PRINTER && this->is_selected_physical_printer()) { + this->show_edit_menu(); + return; } - Tab* tab = wxGetApp().get_tab(m_type); - if (!tab) + if (!switch_to_tab()) return; - int page_id = wxGetApp().tab_panel()->FindPage(tab); - if (page_id == wxNOT_FOUND) - return; - - wxGetApp().tab_panel()->SetSelection(page_id); - - // Switch to Settings NotePad - wxGetApp().mainframe->select_tab(); - /* In a case of a multi-material printing, for editing another Filament Preset * it's needed to select this preset for the "Filament settings" Tab */ @@ -355,7 +342,7 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset if ( !boost::algorithm::ends_with(selected_preset, Preset::suffix_modified()) ) { const std::string& preset_name = wxGetApp().preset_bundle->filaments.get_preset_name_by_alias(selected_preset); - tab->select_preset(preset_name); + wxGetApp().get_tab(m_type)->select_preset(preset_name); } } }); @@ -374,6 +361,53 @@ bool PlaterPresetComboBox::is_selected_physical_printer() return marker == LABEL_ITEM_PHYSICAL_PRINTER; } +bool PlaterPresetComboBox::switch_to_tab() +{ + Tab* tab = wxGetApp().get_tab(m_type); + if (!tab) + return false; + + int page_id = wxGetApp().tab_panel()->FindPage(tab); + if (page_id == wxNOT_FOUND) + return false; + + wxGetApp().tab_panel()->SetSelection(page_id); + // Switch to Settings NotePad + wxGetApp().mainframe->select_tab(); + return true; +} + +void PlaterPresetComboBox::show_edit_menu() +{ + wxMenu* menu = new wxMenu(); + + append_menu_item(menu, wxID_ANY, _L("Edit related printer profile"), "", + [this](wxCommandEvent&) { this->switch_to_tab(); }, "cog", menu, []() { return true; }, wxGetApp().plater()); + + 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("Delete physical printer"), "", + [this](wxCommandEvent&) { + const std::string& printer_name = m_preset_bundle->physical_printers.get_selected_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(); + update(); + }, "cross", menu, []() { return true; }, wxGetApp().plater()); + + wxGetApp().plater()->PopupMenu(menu); +} + // Only the compatible presets are shown. // If an incompatible preset is selected, it is shown as well. void PlaterPresetComboBox::update() diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index e1597bcfc..9261e92ef 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -124,6 +124,8 @@ public: int get_extruder_idx() const { return m_extruder_idx; } bool is_selected_physical_printer(); + bool switch_to_tab(); + void show_edit_menu(); void update() override; void msw_rescale() override; From 1a2926050fee0b5ab118054aaa4ccb65614d2063 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 25 Jun 2020 12:58:59 +0200 Subject: [PATCH 07/31] PhysicalPrinter. PhysicalPrinterDialog improvements --- src/libslic3r/Preset.cpp | 3 +- src/libslic3r/PrintConfig.cpp | 11 +++++++ src/libslic3r/PrintConfig.hpp | 13 ++++++++ src/slic3r/GUI/Field.cpp | 2 ++ src/slic3r/GUI/Field.hpp | 2 ++ src/slic3r/GUI/GUI.cpp | 2 ++ src/slic3r/GUI/OptionsGroup.cpp | 19 +++++++----- src/slic3r/GUI/OptionsGroup.hpp | 7 +++++ src/slic3r/GUI/PresetComboBoxes.cpp | 46 +++++++++++++++++++++-------- src/slic3r/GUI/PresetComboBoxes.hpp | 2 +- 10 files changed, 85 insertions(+), 22 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index e17130f69..abc508b48 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1354,7 +1354,8 @@ const std::vector& PhysicalPrinter::printer_options() "host_type", "print_host", "printhost_apikey", - "printhost_cafile", + "printhost_cafile", + "authorization_type", "login", "password" }; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 93ef170fb..01b17ec0d 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -150,6 +150,17 @@ void PrintConfigDef::init_common_params() def->tooltip = L("Related printer preset name"); def->mode = comAdvanced; def->set_default_value(new ConfigOptionString("")); + + def = this->add("authorization_type", coEnum); + def->label = L("Authorization Type"); +// def->tooltip = L(""); + def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); + def->enum_values.push_back("key"); + def->enum_values.push_back("user"); + def->enum_labels.push_back("KeyPassword"); + def->enum_labels.push_back("UserPassword"); + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionEnum(atKeyPassword)); } void PrintConfigDef::init_fff_params() diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index f28ef2a22..9b5c47512 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -33,6 +33,10 @@ enum PrintHostType { htOctoPrint, htDuet, htFlashAir, htAstroBox }; +enum AuthorizationType { + atKeyPassword, atUserPassword +}; + enum InfillPattern : int { ipRectilinear, ipMonotonous, ipGrid, ipTriangles, ipStars, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb, ipGyroid, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipCount, @@ -109,6 +113,15 @@ template<> inline const t_config_enum_values& ConfigOptionEnum::g return keys_map; } +template<> inline const t_config_enum_values& ConfigOptionEnum::get_enum_values() { + static t_config_enum_values keys_map; + if (keys_map.empty()) { + keys_map["key"] = atKeyPassword; + keys_map["user"] = atUserPassword; + } + return keys_map; +} + template<> inline const t_config_enum_values& ConfigOptionEnum::get_enum_values() { static t_config_enum_values keys_map; if (keys_map.empty()) { diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 8ab82e20d..9cb3d726d 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -1080,6 +1080,8 @@ boost::any& Choice::get_value() m_value = static_cast(ret_enum); else if (m_opt_id.compare("support_pillar_connection_mode") == 0) m_value = static_cast(ret_enum); + else if (m_opt_id == "authorization_type") + m_value = static_cast(ret_enum); } else if (m_opt.gui_type == "f_enum_open") { const int ret_enum = field->GetSelection(); diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 484b2059f..1a4997756 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -151,6 +151,8 @@ public: virtual wxSizer* getSizer() { return nullptr; } virtual wxWindow* getWindow() { return nullptr; } + wxStaticText* getLabel() { return m_Label; } + bool is_matched(const std::string& string, const std::string& pattern); void get_value_by_opt_type(wxString& str, const bool check_value = true); diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index b9516b12f..88c457668 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -194,6 +194,8 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); else if(opt_key.compare("support_pillar_connection_mode") == 0) config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); + else if(opt_key == "authorization_type") + config.set_key_value(opt_key, new ConfigOptionEnum(boost::any_cast(value))); } break; case coPoints:{ diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 819c214a8..1bebb8827 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -729,31 +729,34 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config opt_key == "fill_pattern" ) { ret = static_cast(config.option>(opt_key)->value); } - else if (opt_key.compare("ironing_type") == 0 ) { + else if (opt_key == "ironing_type") { ret = static_cast(config.option>(opt_key)->value); } - else if (opt_key.compare("gcode_flavor") == 0 ) { + else if (opt_key == "gcode_flavor") { ret = static_cast(config.option>(opt_key)->value); } - else if (opt_key.compare("support_material_pattern") == 0) { + else if (opt_key == "support_material_pattern") { ret = static_cast(config.option>(opt_key)->value); } - else if (opt_key.compare("seam_position") == 0) { + else if (opt_key == "seam_position") { ret = static_cast(config.option>(opt_key)->value); } - else if (opt_key.compare("host_type") == 0) { + else if (opt_key == "host_type") { ret = static_cast(config.option>(opt_key)->value); } - else if (opt_key.compare("display_orientation") == 0) { + else if (opt_key == "display_orientation") { ret = static_cast(config.option>(opt_key)->value); } - else if (opt_key.compare("support_pillar_connection_mode") == 0) { + else if (opt_key == "support_pillar_connection_mode") { ret = static_cast(config.option>(opt_key)->value); } + else if (opt_key == "authorization_type") { + ret = static_cast(config.option>(opt_key)->value); + } } break; case coPoints: - if (opt_key.compare("bed_shape") == 0) + if (opt_key == "bed_shape") ret = config.option(opt_key)->values; else ret = config.option(opt_key)->get_at(idx); diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index 2e6f9aa0f..edd4a15bc 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -149,6 +149,13 @@ public: return true; } + void show_field(const t_config_option_key& opt_key, bool show = true) { + Field* field = get_field(opt_key); + field->getWindow()->Show(show); + field->getLabel()->Show(show); + } + void hide_field(const t_config_option_key& opt_key) { show_field(opt_key, false); } + void set_name(const wxString& new_name) { stb->SetLabel(new_name); } diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index e9da7dc9d..b39582ee0 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -837,7 +837,7 @@ void TabPresetComboBox::update_dirty() PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) - : DPIDialog(NULL, wxID_ANY, _L("PhysicalPrinter"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) + : DPIDialog(NULL, wxID_ANY, _L("Physical Printer"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { SetFont(wxGetApp().normal_font()); SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); @@ -856,7 +856,7 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) // update values m_optgroup->reload_config(); - update_octoprint_visible(); + update(); }); m_printer_presets->update(); @@ -898,6 +898,11 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgroup) { + m_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + if (opt_key == "authorization_type") + this->update(); + }; + m_optgroup->append_single_option_line("host_type"); auto create_sizer_with_btn = [this](wxWindow* parent, ScalableButton** btn, const std::string& icon_name, const wxString& label) { @@ -952,6 +957,9 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr host_line.append_widget(printhost_browse); host_line.append_widget(print_host_test); m_optgroup->append_line(host_line); + + m_optgroup->append_single_option_line("authorization_type"); + option = m_optgroup->get_option("printhost_apikey"); option.opt.width = Field::def_width_wider(); m_optgroup->append_single_option_line(option); @@ -999,7 +1007,8 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr (boost::format(_u8L("On this system, %s uses HTTPS certificates from the system Certificate Store or Keychain.")) % SLIC3R_APP_NAME).str() + "\n\t" + _u8L("To use a custom CA file, please import your CA file into Certificate Store / Keychain."); - auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\n\t%2%") % info % ca_file_hint).str())); + //auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\n\t%2%") % info % ca_file_hint).str())); + auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\t%2%") % info % ca_file_hint).str())); txt->SetFont(wxGetApp().normal_font()); auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(txt, 1, wxEXPAND); @@ -1015,20 +1024,33 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr m_optgroup->append_single_option_line(option); } - update_octoprint_visible(); + update(); } -void PhysicalPrinterDialog::update_octoprint_visible() +void PhysicalPrinterDialog::update() { const PrinterTechnology tech = Preset::printer_technology(m_printer.config); // Only offer the host type selection for FFF, for SLA it's always the SL1 printer (at the moment) - Field* host_type = m_optgroup->get_field("host_type"); - if (tech == ptFFF) - host_type->enable(); - else { - host_type->set_value(int(PrintHostType::htOctoPrint), false); - host_type->disable(); + if (tech == ptFFF) { + m_optgroup->show_field("host_type"); + m_optgroup->hide_field("authorization_type"); + for (const std::string& opt_key : std::vector{ "login", "password" }) + m_optgroup->hide_field(opt_key); } + else { + m_optgroup->set_value("host_type", int(PrintHostType::htOctoPrint), false); + m_optgroup->hide_field("host_type"); + + m_optgroup->show_field("authorization_type"); + + AuthorizationType auth_type = m_config->option>("authorization_type")->value; + m_optgroup->show_field("printhost_apikey", auth_type == AuthorizationType::atKeyPassword); + + for (const std::string& opt_key : std::vector{ "login", "password" }) + m_optgroup->show_field(opt_key, auth_type == AuthorizationType::atUserPassword); + } + + this->Layout(); } void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) @@ -1044,7 +1066,7 @@ void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL }); - const wxSize& size = wxSize(40 * em, 30 * em); + const wxSize& size = wxSize(45 * em, 35 * em); SetMinSize(size); Fit(); diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 9261e92ef..196c4368e 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -177,7 +177,7 @@ class PhysicalPrinterDialog : public DPIDialog ScalableButton* m_printhost_cafile_browse_btn {nullptr}; void build_printhost_settings(ConfigOptionsGroup* optgroup); - void update_octoprint_visible(); + void update(); void OnOK(wxEvent& event); public: From d96b5f360661feaa2f964d9f4b18d1e586d2607b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 26 Jun 2020 09:58:39 +0200 Subject: [PATCH 08/31] 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(-) 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(); }); - 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); + 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, ""); + + 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}; }; From 6d4a0d91fce7bc8e85302d9b0f8d14b882c0cb9c Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 26 Jun 2020 16:58:53 +0200 Subject: [PATCH 09/31] Fixed typo in PresetComboBox.hpp and added missed include in libslic3r.h --- src/libslic3r/libslic3r.h | 1 + src/slic3r/GUI/PresetComboBoxes.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index db375ec14..3ea70d998 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -5,6 +5,7 @@ // this needs to be included early for MSVC (listing it in Build.PL is not enough) #include +#include #include #include #include diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 653c0e540..dce22bc82 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -13,7 +13,7 @@ class wxString; class wxTextCtrl; -class wxStatictext; +class wxStaticText; class ScalableButton; namespace Slic3r { From 0b88e86634bd291f524c24912061c9c1e9e71ef3 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 30 Jun 2020 14:12:47 +0200 Subject: [PATCH 10/31] PhysicalPrinter improvements: * implemented PresetForPrinter class --- src/libslic3r/Preset.cpp | 9 ++ src/libslic3r/Preset.hpp | 1 + src/slic3r/GUI/PresetComboBoxes.cpp | 154 ++++++++++++++++++++++------ src/slic3r/GUI/PresetComboBoxes.hpp | 51 +++++++-- 4 files changed, 175 insertions(+), 40 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 9af3dacf0..ec3e93338 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1375,6 +1375,15 @@ const std::string& PhysicalPrinter::get_printer_model() const return config.opt_string("printer_model"); } +bool PhysicalPrinter::has_empty_config() const +{ + return config.opt_string("print_host" ).empty() && + config.opt_string("printhost_apikey").empty() && + config.opt_string("printhost_cafile").empty() && + config.opt_string("login" ).empty() && + config.opt_string("password" ).empty(); +} + void PhysicalPrinter::update_from_preset(const Preset& preset) { config.apply_only(preset.config, printer_options(), false); diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index 6eb1fd2db..a076a9a21 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -556,6 +556,7 @@ public: static const std::vector& printer_options(); const std::string& get_preset_name() const; const std::string& get_printer_model() const; + bool has_empty_config() const; void save() { this->config.save(this->file); } void save_to(const std::string& file_name) const { this->config.save(file_name); } diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 88dd4b739..dc5365a13 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -884,6 +884,76 @@ void TabPresetComboBox::update_dirty() } +//------------------------------------------ +// PresetForPrinter +//------------------------------------------ + +PresetForPrinter::PresetForPrinter(PhysicalPrinterDialog* parent, bool is_all_enable) : + m_parent(parent) +{ + m_sizer = new wxBoxSizer(wxVERTICAL); + + m_delete_preset_btn = new ScalableButton(parent, wxID_ANY, "cross", "", wxDefaultSize, wxDefaultPosition, wxBU_LEFT | wxBU_EXACTFIT); + m_delete_preset_btn->SetFont(wxGetApp().normal_font()); + m_delete_preset_btn->SetToolTip(_L("Delete this preset from this printer device")); + m_delete_preset_btn->Bind(wxEVT_BUTTON, &PresetForPrinter::DeletePreset, this); + + m_presets_list = new TabPresetComboBox(parent, Preset::TYPE_PRINTER); + + if (is_all_enable) + m_presets_list->set_enable_all(); + + m_presets_list->set_selection_changed_function([this](int selection) { + std::string selected_string = Preset::remove_suffix_modified(m_presets_list->GetString(selection).ToUTF8().data()); + Preset* preset = wxGetApp().preset_bundle->printers.find_preset(selected_string); + assert(preset); + Preset& edited_preset = wxGetApp().preset_bundle->printers.get_edited_preset(); + if (preset->name == edited_preset.name) + preset = &edited_preset; + + // if created physical printer doesn't have any settings, use the settings from the selected preset + if (m_parent->get_printer()->has_empty_config()) { + // update Print Host upload from the selected preset + m_parent->get_printer()->update_from_preset(*preset); + // update values in parent (PhysicalPrinterDialog) + m_parent->update(); + } + + update_full_printer_name(); + }); + + m_full_printer_name = new wxStaticText(parent, wxID_ANY, ""); + + m_presets_list->update(); +} + +PresetForPrinter::~PresetForPrinter() +{ + m_presets_list->Destroy(); + m_delete_preset_btn->Destroy(); + m_full_printer_name->Destroy(); +} + +void PresetForPrinter::DeletePreset(wxEvent& event) +{ + +} + +void PresetForPrinter::update_full_printer_name() +{ + wxString printer_name = m_parent->get_printer_name(); + wxString preset_name = m_presets_list->GetString(m_presets_list->GetSelection()); + + m_full_printer_name->SetLabelText(printer_name + " * " + preset_name); +} + +void PresetForPrinter::msw_rescale() +{ + m_presets_list->msw_rescale(); + m_delete_preset_btn->msw_rescale(); +} + + //------------------------------------------ // PhysicalPrinterDialog //------------------------------------------ @@ -896,44 +966,31 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); int border = 10; + m_info_string = _("This printer name will be shown in the presets list") + ":\n"; - m_printer_presets = new TabPresetComboBox(this, Preset::TYPE_PRINTER); + TabPresetComboBox* 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"); + // if printer_name is empty it means that new printer is created, so enable all items in the preset list + m_presets.emplace_back(new PresetForPrinter(this, true)); } 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); - assert(preset); - Preset& edited_preset = wxGetApp().preset_bundle->printers.get_edited_preset(); - if (preset->name == edited_preset.name) - preset = &edited_preset; - m_printer.update_from_preset(*preset); - - update_printer_name(); - - // update values - m_optgroup->reload_config(); - update(); - }); - m_printer_presets->update(); - wxStaticText* label_top = new wxStaticText(this, wxID_ANY, _("Descriptive name for the printer device") + ":"); + + m_add_preset_btn = new ScalableButton(this, wxID_ANY, "add_copies", "", wxDefaultSize, wxDefaultPosition, wxBU_LEFT | wxBU_EXACTFIT); + m_add_preset_btn->SetFont(wxGetApp().normal_font()); + m_add_preset_btn->SetToolTip(_L("Add preset for this printer device")); + m_add_preset_btn->Bind(wxEVT_BUTTON, &PhysicalPrinterDialog::AddPreset, this); + m_printer_name = new wxTextCtrl(this, wxID_ANY, printer_name, wxDefaultPosition, wxDefaultSize); - m_printer_name->Bind(wxEVT_TEXT, [this](wxEvent&) { this->update_printer_name(); }); + m_printer_name->Bind(wxEVT_TEXT, [this](wxEvent&) { this->update_full_printer_names(); }); - 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, ""); - - update_printer_name(); + update_full_printer_names(); PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; PhysicalPrinter* printer = printers.find_printer(into_u8(printer_name)); @@ -948,19 +1005,27 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) m_optgroup = new ConfigOptionsGroup(this, _L("Print Host upload"), m_config); build_printhost_settings(m_optgroup); - m_optgroup->reload_config(); + //m_optgroup->reload_config(); wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); wxButton* btnOK = static_cast(this->FindWindowById(wxID_OK, this)); btnOK->Bind(wxEVT_BUTTON, &PhysicalPrinterDialog::OnOK, this); + wxBoxSizer* nameSizer = new wxBoxSizer(wxHORIZONTAL); + nameSizer->Add(m_printer_name, 1, wxEXPAND); + nameSizer->Add(m_add_preset_btn, 0, wxEXPAND | wxLEFT, border); + 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(nameSizer , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); + for (PresetForPrinter* preset : m_presets) + topSizer->Add(preset->sizer(), 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); @@ -968,6 +1033,14 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) topSizer->SetSizeHints(this); } +PhysicalPrinterDialog::~PhysicalPrinterDialog() +{ + for (PresetForPrinter* preset : m_presets) { + delete preset; + preset = nullptr; + } +} + void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgroup) { m_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { @@ -1101,6 +1174,8 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr void PhysicalPrinterDialog::update() { + m_optgroup->reload_config(); + const PrinterTechnology tech = Preset::printer_technology(m_printer.config); // Only offer the host type selection for FFF, for SLA it's always the SL1 printer (at the moment) if (tech == ptFFF) { @@ -1125,12 +1200,17 @@ 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); +wxString PhysicalPrinterDialog::get_printer_name() +{ + return m_info_string + m_printer_name->GetValue() + "\t"; +} + +void PhysicalPrinterDialog::update_full_printer_names() +{ + for (PresetForPrinter* preset : m_presets) + preset->update_full_printer_name(); + this->Layout(); } @@ -1147,6 +1227,9 @@ void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL }); + for (PresetForPrinter* preset : m_presets) + preset->msw_rescale(); + const wxSize& size = wxSize(45 * em, 35 * em); SetMinSize(size); @@ -1184,6 +1267,7 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) printers.save_printer(m_printer); // update selection on the tab only when it was changed + /* if (m_printer.get_preset_name() != wxGetApp().preset_bundle->printers.get_selected_preset_name()) { Tab* tab = wxGetApp().get_tab(Preset::TYPE_PRINTER); if (tab) { @@ -1191,9 +1275,15 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) tab->select_preset(into_u8(preset_name)); } } + */ event.Skip(); } +void PhysicalPrinterDialog::AddPreset(wxEvent& event) +{ + +} + }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index dce22bc82..3d5ae298f 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -166,32 +166,67 @@ public: }; +//------------------------------------------ +// PresetForPrinter +//------------------------------------------ +class PhysicalPrinterDialog; +class PresetForPrinter +{ + PhysicalPrinterDialog* m_parent { nullptr }; + + TabPresetComboBox* m_presets_list { nullptr }; + ScalableButton* m_delete_preset_btn { nullptr }; + wxStaticText* m_full_printer_name { nullptr }; + + wxBoxSizer* m_sizer { nullptr }; + + void DeletePreset(wxEvent& event); + +public: + PresetForPrinter(PhysicalPrinterDialog* parent, bool is_all_enable); + ~PresetForPrinter(); + + wxBoxSizer* sizer() { return m_sizer; } + void update_full_printer_name(); + + void msw_rescale(); + void on_sys_color_changed() {}; +}; + + //------------------------------------------ // PhysicalPrinterDialog //------------------------------------------ + class ConfigOptionsGroup; class PhysicalPrinterDialog : public DPIDialog { PhysicalPrinter m_printer; DynamicPrintConfig* m_config { nullptr }; + wxString m_info_string; wxTextCtrl* m_printer_name { nullptr }; - wxStaticText* m_full_printer_name { nullptr }; - TabPresetComboBox* m_printer_presets { nullptr }; + std::vector m_presets; + ConfigOptionsGroup* m_optgroup { nullptr }; - ScalableButton* m_printhost_browse_btn; - ScalableButton* m_printhost_test_btn; - ScalableButton* m_printhost_cafile_browse_btn {nullptr}; + ScalableButton* m_add_preset_btn {nullptr}; + ScalableButton* m_printhost_browse_btn {nullptr}; + ScalableButton* m_printhost_test_btn {nullptr}; + ScalableButton* m_printhost_cafile_browse_btn {nullptr}; void build_printhost_settings(ConfigOptionsGroup* optgroup); - void update(); - void update_printer_name(); void OnOK(wxEvent& event); + void AddPreset(wxEvent& event); public: PhysicalPrinterDialog(wxString printer_name); - ~PhysicalPrinterDialog() {} + ~PhysicalPrinterDialog(); + + void update(); + wxString get_printer_name(); + void update_full_printer_names(); + PhysicalPrinter* get_printer() {return &m_printer; } protected: void on_dpi_changed(const wxRect& suggested_rect) override; From c5197f33502effe0bd19a257db6235ca8df41edd Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 14 Jul 2020 15:34:08 +0200 Subject: [PATCH 11/31] PhysicalPrinterDialog is completed --- src/libslic3r/Preset.cpp | 82 +++++++++++++-- src/libslic3r/Preset.hpp | 28 +++-- src/slic3r/GUI/PresetComboBoxes.cpp | 156 ++++++++++++++++++++++------ src/slic3r/GUI/PresetComboBoxes.hpp | 13 ++- 4 files changed, 230 insertions(+), 49 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index ec3e93338..c9f5bd0af 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1345,6 +1345,11 @@ const Preset* PrinterPresetCollection::find_by_model_id(const std::string &model // *** PhysicalPrinter *** // ------------------------- +std::string PhysicalPrinter::separator() +{ + return " * "; +} + const std::vector& PhysicalPrinter::printer_options() { static std::vector s_opts; @@ -1370,9 +1375,9 @@ const std::string& PhysicalPrinter::get_preset_name() const return config.opt_string("preset_name"); } -const std::string& PhysicalPrinter::get_printer_model() const +const std::set& PhysicalPrinter::get_preset_names() const { - return config.opt_string("printer_model"); + return preset_names; } bool PhysicalPrinter::has_empty_config() const @@ -1384,20 +1389,62 @@ bool PhysicalPrinter::has_empty_config() const config.opt_string("password" ).empty(); } +void PhysicalPrinter::update_preset_names_in_config() +{ + if (!preset_names.empty()) { + std::string name; + for (auto el : preset_names) + name += el + ";"; + name.pop_back(); + config.set_key_value("preset_name", new ConfigOptionString(name)); + } +} + +void PhysicalPrinter::save(const std::string& file_name_from, const std::string& file_name_to) +{ + // rename the file + boost::nowide::rename(file_name_from.data(), file_name_to.data()); + this->file = file_name_to; + // save configuration + this->config.save(this->file); +} + 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)); + // add preset names to the options list + auto ret = preset_names.emplace(preset.name); + update_preset_names_in_config(); + update_full_name(); } void PhysicalPrinter::update_from_config(const DynamicPrintConfig& new_config) { config.apply_only(new_config, printer_options(), false); + + std::string str = config.opt_string("preset_name"); + std::set values{}; + if (!str.empty()) { + boost::split(values, str, boost::is_any_of(";")); + for (const std::string& val : values) + preset_names.emplace(val); + } + preset_names = values; + update_full_name(); } +void PhysicalPrinter::reset_presets() +{ + return preset_names.clear(); +} + +bool PhysicalPrinter::add_preset(const std::string& preset_name) +{ + return preset_names.emplace(preset_name).second; +} + PhysicalPrinter::PhysicalPrinter(const std::string& name, const Preset& preset) : name(name) { @@ -1412,16 +1459,23 @@ void PhysicalPrinter::set_name(const std::string& name) void PhysicalPrinter::update_full_name() { - full_name = name + " * " + get_preset_name(); + full_name = name + separator() + get_preset_name(); } std::string PhysicalPrinter::get_short_name(std::string full_name) { - int pos = full_name.find_first_of(" * "); + int pos = full_name.find(separator()); boost::erase_tail(full_name, full_name.length() - pos); return full_name; } +std::string PhysicalPrinter::get_preset_name(std::string full_name) +{ + int pos = full_name.find(separator()); + boost::erase_head(full_name, pos + 2); + return full_name; +} + // ----------------------------------- // *** PhysicalPrinterCollection *** @@ -1497,15 +1551,18 @@ std::string PhysicalPrinterCollection::path_from_name(const std::string& new_nam return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string(); } -void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_printer) +void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_printer, const std::string& renamed_from) { + std::string name = renamed_from.empty() ? edited_printer.name : renamed_from; // 1) Find the printer with a new_name or create a new one, // initialize it with the edited config. - auto it = this->find_printer_internal(edited_printer.name); - if (it != m_printers.end() && it->name == edited_printer.name) { + auto it = this->find_printer_internal(name); + if (it != m_printers.end() && it->name == name) { // Printer with the same name found. // Overwriting an existing preset. it->config = std::move(edited_printer.config); + it->name = edited_printer.name; + it->preset_names = edited_printer.preset_names; it->full_name = edited_printer.full_name; } else { @@ -1518,7 +1575,12 @@ void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_print PhysicalPrinter& printer = *it; if (printer.file.empty()) printer.file = this->path_from_name(printer.name); - printer.save(); + + if (printer.file == this->path_from_name(printer.name)) + printer.save(); + else + // if printer was renamed, we should rename a file and than save the config + printer.save(printer.file, this->path_from_name(printer.name)); // update idx_selected m_idx_selected = it - m_printers.begin(); diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index a076a9a21..d583bed20 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -549,20 +549,33 @@ public: std::string file; // Configuration data, loaded from a file, or set from the defaults. DynamicPrintConfig config; + // set of presets used with this physical printer + std::set preset_names; + + static std::string separator(); // Has this profile been loaded? bool loaded = false; - static const std::vector& printer_options(); - const std::string& get_preset_name() const; - const std::string& get_printer_model() const; + static const std::vector& printer_options(); + const std::string& get_preset_name() const; + + const std::set& get_preset_names() const; + bool has_empty_config() const; + void update_preset_names_in_config(); void save() { this->config.save(this->file); } - void save_to(const std::string& file_name) const { this->config.save(file_name); } + void save(const std::string& file_name_from, const std::string& file_name_to); + void update_from_preset(const Preset& preset); void update_from_config(const DynamicPrintConfig &new_config); + // add preset to the preset_names + // return false, if preset with this name is already exist in the set + bool add_preset(const std::string& preset_name); + void reset_presets(); + // Return a printer technology, return ptFFF if the printer technology is not set. static PrinterTechnology printer_technology(const DynamicPrintConfig& cfg) { auto* opt = cfg.option>("printer_technology"); @@ -578,6 +591,9 @@ public: // get printer name from the full name uncluded preset name static std::string get_short_name(std::string full_name); + // get preset name from the full name uncluded printer name + static std::string get_preset_name(std::string full_name); + protected: friend class PhysicalPrinterCollection; }; @@ -615,7 +631,7 @@ public: // Save the printer under a new name. If the name is different from the old one, // a new printer is stored into the list of printers. // New printer is activated. - void save_printer(const PhysicalPrinter& printer); + void save_printer(const PhysicalPrinter& printer, const std::string& renamed_from); // Delete the current preset, activate the first visible preset. // returns true if the preset was deleted successfully. @@ -633,8 +649,6 @@ public: // 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); } diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index dc5365a13..1473bf6da 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -41,6 +41,8 @@ static const std::pair THUMBNAIL_SIZE_3MF = { 256, 2 namespace Slic3r { namespace GUI { +#define BORDER_W 10 + // --------------------------------- // *** PresetComboBox *** // --------------------------------- @@ -762,8 +764,8 @@ void TabPresetComboBox::update() // 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(); + 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"; @@ -888,7 +890,7 @@ void TabPresetComboBox::update_dirty() // PresetForPrinter //------------------------------------------ -PresetForPrinter::PresetForPrinter(PhysicalPrinterDialog* parent, bool is_all_enable) : +PresetForPrinter::PresetForPrinter(PhysicalPrinterDialog* parent, const std::string& preset_name) : m_parent(parent) { m_sizer = new wxBoxSizer(wxVERTICAL); @@ -899,8 +901,7 @@ PresetForPrinter::PresetForPrinter(PhysicalPrinterDialog* parent, bool is_all_en m_delete_preset_btn->Bind(wxEVT_BUTTON, &PresetForPrinter::DeletePreset, this); m_presets_list = new TabPresetComboBox(parent, Preset::TYPE_PRINTER); - - if (is_all_enable) + if (preset_name.empty()) m_presets_list->set_enable_all(); m_presets_list->set_selection_changed_function([this](int selection) { @@ -921,22 +922,37 @@ PresetForPrinter::PresetForPrinter(PhysicalPrinterDialog* parent, bool is_all_en update_full_printer_name(); }); + m_presets_list->update(); + m_presets_list->SetStringSelection(from_u8(preset_name)); + + m_info_line = new wxStaticText(parent, wxID_ANY, _L("This printer will be shown in the presets list as") + ":"); m_full_printer_name = new wxStaticText(parent, wxID_ANY, ""); + m_full_printer_name->SetFont(wxGetApp().bold_font()); - m_presets_list->update(); + wxBoxSizer* preset_sizer = new wxBoxSizer(wxHORIZONTAL); + preset_sizer->Add(m_presets_list , 1, wxEXPAND); + preset_sizer->Add(m_delete_preset_btn , 0, wxEXPAND | wxLEFT, BORDER_W); + + wxBoxSizer* name_sizer = new wxBoxSizer(wxHORIZONTAL); + name_sizer->Add(m_info_line, 0, wxEXPAND); + name_sizer->Add(m_full_printer_name, 0, wxEXPAND | wxLEFT, BORDER_W); + + m_sizer->Add(preset_sizer , 0, wxEXPAND); + m_sizer->Add(name_sizer, 0, wxEXPAND); } PresetForPrinter::~PresetForPrinter() { m_presets_list->Destroy(); m_delete_preset_btn->Destroy(); + m_info_line->Destroy(); m_full_printer_name->Destroy(); } void PresetForPrinter::DeletePreset(wxEvent& event) { - + m_parent->DeletePreset(this); } void PresetForPrinter::update_full_printer_name() @@ -947,6 +963,22 @@ void PresetForPrinter::update_full_printer_name() m_full_printer_name->SetLabelText(printer_name + " * " + preset_name); } +std::string PresetForPrinter::get_preset_name() +{ + return into_u8(m_presets_list->GetString(m_presets_list->GetSelection())); +} + +void PresetForPrinter::DisableDeleteBtn() +{ + m_delete_preset_btn->Enable(false); +} + +void PresetForPrinter::EnableDeleteBtn() +{ + if (!m_delete_preset_btn->IsEnabled()) + m_delete_preset_btn->Enable(); +} + void PresetForPrinter::msw_rescale() { m_presets_list->msw_rescale(); @@ -965,22 +997,17 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) SetFont(wxGetApp().normal_font()); SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - int border = 10; - m_info_string = _("This printer name will be shown in the presets list") + ":\n"; - - TabPresetComboBox* printer_presets = new TabPresetComboBox(this, Preset::TYPE_PRINTER); - if (printer_name.IsEmpty()) { printer_name = _L("My Printer Device"); // if printer_name is empty it means that new printer is created, so enable all items in the preset list - m_presets.emplace_back(new PresetForPrinter(this, true)); + m_presets.emplace_back(new PresetForPrinter(this, "")); } else { std::string full_name = into_u8(printer_name); printer_name = from_u8(PhysicalPrinter::get_short_name(full_name)); } - wxStaticText* label_top = new wxStaticText(this, wxID_ANY, _("Descriptive name for the printer device") + ":"); + wxStaticText* label_top = new wxStaticText(this, wxID_ANY, _L("Descriptive name for the printer device") + ":"); m_add_preset_btn = new ScalableButton(this, wxID_ANY, "add_copies", "", wxDefaultSize, wxDefaultPosition, wxBU_LEFT | wxBU_EXACTFIT); m_add_preset_btn->SetFont(wxGetApp().normal_font()); @@ -990,17 +1017,26 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) m_printer_name = new wxTextCtrl(this, wxID_ANY, printer_name, wxDefaultPosition, wxDefaultSize); m_printer_name->Bind(wxEVT_TEXT, [this](wxEvent&) { this->update_full_printer_names(); }); - update_full_printer_names(); - PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; PhysicalPrinter* printer = printers.find_printer(into_u8(printer_name)); if (!printer) { const Preset& preset = wxGetApp().preset_bundle->printers.get_edited_preset(); printer = new PhysicalPrinter(into_u8(printer_name), preset); } + else + { + const std::set& preset_names = printer->get_preset_names(); + for (const std::string& preset_name : preset_names) + m_presets.emplace_back(new PresetForPrinter(this, preset_name)); + } assert(printer); m_printer = *printer; + if (m_presets.size() == 1) + m_presets.front()->DisableDeleteBtn(); + + update_full_printer_names(); + m_config = &m_printer.config; m_optgroup = new ConfigOptionsGroup(this, _L("Print Host upload"), m_config); @@ -1013,21 +1049,19 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) wxBoxSizer* nameSizer = new wxBoxSizer(wxHORIZONTAL); nameSizer->Add(m_printer_name, 1, wxEXPAND); - nameSizer->Add(m_add_preset_btn, 0, wxEXPAND | wxLEFT, border); + nameSizer->Add(m_add_preset_btn, 0, wxEXPAND | wxLEFT, BORDER_W); + + m_presets_sizer = new wxBoxSizer(wxVERTICAL); + for (PresetForPrinter* preset : m_presets) + m_presets_sizer->Add(preset->sizer(), 1, wxEXPAND | wxTOP, BORDER_W); wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); - topSizer->Add(label_top , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); - topSizer->Add(nameSizer , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border); - for (PresetForPrinter* preset : m_presets) - topSizer->Add(preset->sizer(), 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); + topSizer->Add(label_top , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); + topSizer->Add(nameSizer , 0, wxEXPAND | wxLEFT | wxRIGHT, BORDER_W); + topSizer->Add(m_presets_sizer , 0, wxEXPAND | wxLEFT | wxRIGHT, BORDER_W); + topSizer->Add(m_optgroup->sizer , 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); + topSizer->Add(btns , 0, wxEXPAND | wxALL, BORDER_W); SetSizer(topSizer); topSizer->SetSizeHints(this); @@ -1203,7 +1237,7 @@ void PhysicalPrinterDialog::update() wxString PhysicalPrinterDialog::get_printer_name() { - return m_info_string + m_printer_name->GetValue() + "\t"; + return m_printer_name->GetValue(); } void PhysicalPrinterDialog::update_full_printer_names() @@ -1260,11 +1294,39 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) printers.delete_printer(into_u8(printer_name)); } + std::set repeat_presets; + m_printer.reset_presets(); + for (PresetForPrinter* preset : m_presets) { + if (!m_printer.add_preset(preset->get_preset_name())) + repeat_presets.emplace(preset->get_preset_name()); + } + // update preset_names in printer config + m_printer.update_preset_names_in_config(); + + if (!repeat_presets.empty()) + { + wxString repeatable_presets = "\n"; + for (const std::string& preset_name : repeat_presets) + repeatable_presets += " " + from_u8(preset_name) + "\n"; + repeatable_presets += "\n"; + + wxString msg_text = from_u8((boost::format(_u8L("Next printer preset(s) is(are) duplicated:%1%" + "It(they) will be added just once for the printer \"%2%\".")) % repeatable_presets % printer_name).str()); + wxMessageDialog dialog(nullptr, msg_text, _L("Infornation"), wxICON_INFORMATION | wxOK); + dialog.ShowModal(); + } + + std::string renamed_from; + // temporary save previous printer name if it was edited + if (m_printer.name != _u8L("My Printer Device") && + m_printer.name != into_u8(printer_name)) + renamed_from = m_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); + printers.save_printer(m_printer, renamed_from); // update selection on the tab only when it was changed /* @@ -1282,7 +1344,41 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) void PhysicalPrinterDialog::AddPreset(wxEvent& event) { + // if printer_name is empty it means that new printer is created, so enable all items in the preset list + m_presets.emplace_back(new PresetForPrinter(this, "")); + // enable DELETE button for the first preset, if was disabled + m_presets.front()->EnableDeleteBtn(); + m_presets_sizer->Add(m_presets.back()->sizer(), 1, wxEXPAND | wxTOP, BORDER_W); + update_full_printer_names(); + + this->Fit(); +} + +void PhysicalPrinterDialog::DeletePreset(PresetForPrinter* preset_for_printer) +{ + if (m_presets.size() == 1) { + wxString msg_text = _L("It's not possible to delete last related preset for the printer."); + wxMessageDialog dialog(nullptr, msg_text, _L("Infornation"), wxICON_INFORMATION | wxOK); + dialog.ShowModal(); + return; + } + + assert(preset_for_printer); + auto it = std::find(m_presets.begin(), m_presets.end(), preset_for_printer); + if (it == m_presets.end()) + return; + + const int remove_id = it - m_presets.begin(); + m_presets_sizer->Remove(remove_id); + delete preset_for_printer; + m_presets.erase(it); + + if (m_presets.size() == 1) + m_presets.front()->DisableDeleteBtn(); + + this->Layout(); + this->Fit(); } diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 3d5ae298f..c818b6b91 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -15,6 +15,7 @@ class wxString; class wxTextCtrl; class wxStaticText; class ScalableButton; +class wxBoxSizer; namespace Slic3r { @@ -169,6 +170,7 @@ public: //------------------------------------------ // PresetForPrinter //------------------------------------------ +static std::string g_info_string = " (modified)"; class PhysicalPrinterDialog; class PresetForPrinter { @@ -176,6 +178,7 @@ class PresetForPrinter TabPresetComboBox* m_presets_list { nullptr }; ScalableButton* m_delete_preset_btn { nullptr }; + wxStaticText* m_info_line { nullptr }; wxStaticText* m_full_printer_name { nullptr }; wxBoxSizer* m_sizer { nullptr }; @@ -183,11 +186,14 @@ class PresetForPrinter void DeletePreset(wxEvent& event); public: - PresetForPrinter(PhysicalPrinterDialog* parent, bool is_all_enable); + PresetForPrinter(PhysicalPrinterDialog* parent, const std::string& preset_name); ~PresetForPrinter(); wxBoxSizer* sizer() { return m_sizer; } void update_full_printer_name(); + std::string get_preset_name(); + void DisableDeleteBtn(); + void EnableDeleteBtn(); void msw_rescale(); void on_sys_color_changed() {}; @@ -203,7 +209,6 @@ class PhysicalPrinterDialog : public DPIDialog { PhysicalPrinter m_printer; DynamicPrintConfig* m_config { nullptr }; - wxString m_info_string; wxTextCtrl* m_printer_name { nullptr }; std::vector m_presets; @@ -215,6 +220,8 @@ class PhysicalPrinterDialog : public DPIDialog ScalableButton* m_printhost_test_btn {nullptr}; ScalableButton* m_printhost_cafile_browse_btn {nullptr}; + wxBoxSizer* m_presets_sizer {nullptr}; + void build_printhost_settings(ConfigOptionsGroup* optgroup); void OnOK(wxEvent& event); void AddPreset(wxEvent& event); @@ -228,6 +235,8 @@ public: void update_full_printer_names(); PhysicalPrinter* get_printer() {return &m_printer; } + void DeletePreset(PresetForPrinter* preset_for_printer); + protected: void on_dpi_changed(const wxRect& suggested_rect) override; void on_sys_color_changed() override {}; From 5eac36a31066df16fc581206951fbfe675e177ab Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 17 Jul 2020 14:32:38 +0200 Subject: [PATCH 12/31] Update for PresetComboBoxes All "Printer-PresetName" pairs are like a separated items now + some code refactoring for PresetComboBoxes::update() --- src/libslic3r/Preset.cpp | 60 ++-- src/libslic3r/Preset.hpp | 41 ++- src/libslic3r/PresetBundle.cpp | 2 +- src/slic3r/GUI/Plater.cpp | 21 +- src/slic3r/GUI/PresetComboBoxes.cpp | 514 ++++++++++++++++++---------- src/slic3r/GUI/PresetComboBoxes.hpp | 49 ++- src/slic3r/GUI/Tab.cpp | 67 +++- src/slic3r/GUI/Tab.hpp | 5 +- 8 files changed, 489 insertions(+), 270 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index c9f5bd0af..ad7615f6d 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1370,11 +1370,6 @@ const std::vector& PhysicalPrinter::printer_options() return s_opts; } -const std::string& PhysicalPrinter::get_preset_name() const -{ - return config.opt_string("preset_name"); -} - const std::set& PhysicalPrinter::get_preset_names() const { return preset_names; @@ -1415,8 +1410,6 @@ void PhysicalPrinter::update_from_preset(const Preset& preset) // add preset names to the options list auto ret = preset_names.emplace(preset.name); update_preset_names_in_config(); - - update_full_name(); } void PhysicalPrinter::update_from_config(const DynamicPrintConfig& new_config) @@ -1431,8 +1424,6 @@ void PhysicalPrinter::update_from_config(const DynamicPrintConfig& new_config) preset_names.emplace(val); } preset_names = values; - - update_full_name(); } void PhysicalPrinter::reset_presets() @@ -1454,26 +1445,26 @@ PhysicalPrinter::PhysicalPrinter(const std::string& name, const Preset& preset) void PhysicalPrinter::set_name(const std::string& name) { this->name = name; - update_full_name(); } -void PhysicalPrinter::update_full_name() +std::string PhysicalPrinter::get_full_name(std::string preset_name) const { - full_name = name + separator() + get_preset_name(); + return name + separator() + preset_name; } std::string PhysicalPrinter::get_short_name(std::string full_name) { int pos = full_name.find(separator()); - boost::erase_tail(full_name, full_name.length() - pos); + if (pos > 0) + boost::erase_tail(full_name, full_name.length() - pos); return full_name; } -std::string PhysicalPrinter::get_preset_name(std::string full_name) +std::string PhysicalPrinter::get_preset_name(std::string name) { - int pos = full_name.find(separator()); - boost::erase_head(full_name, pos + 2); - return full_name; + int pos = name.find(separator()); + boost::erase_head(name, pos + 3); + return Preset::remove_suffix_modified(name); } @@ -1563,7 +1554,6 @@ void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_print it->config = std::move(edited_printer.config); it->name = edited_printer.name; it->preset_names = edited_printer.preset_names; - it->full_name = edited_printer.full_name; } else { // Creating a new printer. @@ -1615,17 +1605,43 @@ bool PhysicalPrinterCollection::delete_selected_printer() return true; } -PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(std::string name) +std::string PhysicalPrinterCollection::get_selected_full_printer_name() const { - name = PhysicalPrinter::get_short_name(name); - auto it = this->find_printer_internal(name); + return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_full_name(m_selected_preset); +} + +PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(const std::string& full_name) +{ + std::string printer_name = PhysicalPrinter::get_short_name(full_name); + auto it = this->find_printer_internal(printer_name); assert(it != m_printers.end()); // update idx_selected - m_idx_selected = it - m_printers.begin(); + m_idx_selected = it - m_printers.begin(); + // update name of the currently selected preset + m_selected_preset = it->get_preset_name(full_name); + if (m_selected_preset.empty()) + m_selected_preset = *it->preset_names.begin(); return *it; } +bool PhysicalPrinterCollection::has_selection() const +{ + return m_idx_selected != size_t(-1); +} + +void PhysicalPrinterCollection::unselect_printer() +{ + m_idx_selected = size_t(-1); + m_selected_preset.clear(); +} + +bool PhysicalPrinterCollection::is_selected(PhysicalPrinterCollection::ConstIterator it, const std::string& preset_name) const +{ + return m_idx_selected == it - m_printers.begin() && + m_selected_preset == preset_name; +} + namespace PresetUtils { const VendorProfile::PrinterModel* system_printer_model(const Preset &preset) diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index d583bed20..d30ea7059 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -539,12 +539,9 @@ public: 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. @@ -558,8 +555,6 @@ public: bool loaded = false; static const std::vector& printer_options(); - const std::string& get_preset_name() const; - const std::set& get_preset_names() const; bool has_empty_config() const; @@ -588,6 +583,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 full printer name included a name of the preset + std::string get_full_name(std::string preset_name) const; + // get printer name from the full name uncluded preset name static std::string get_short_name(std::string full_name); @@ -641,22 +639,29 @@ public: bool delete_selected_printer(); // Return the selected preset, without the user modifications applied. - PhysicalPrinter& get_selected_printer() { return m_printers[m_idx_selected]; } - const PhysicalPrinter& get_selected_printer() const { return m_printers[m_idx_selected]; } - size_t get_selected_idx() const { return m_idx_selected; } + PhysicalPrinter& get_selected_printer() { return m_printers[m_idx_selected]; } + const PhysicalPrinter& get_selected_printer() const { return m_printers[m_idx_selected]; } + + 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; } + std::string get_selected_printer_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().name; } + // Returns the config of the selected printer, or nullptr if no printer is selected. + DynamicPrintConfig* get_selected_printer_config() { return (m_idx_selected == size_t(-1)) ? nullptr : &(this->get_selected_printer().config); } + // Returns the config of the selected printer, or nullptr if no printer is selected. + PrinterTechnology get_selected_printer_technology() { return (m_idx_selected == size_t(-1)) ? PrinterTechnology::ptAny : this->get_selected_printer().printer_technology(); } + + // Each physical printer can have a several related preset, + // so, use the next functions to get an exact names of selections in the list: + // Returns the full name of the selected printer, or an empty string if no preset is selected. + std::string get_selected_full_printer_name() const; // 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); } + std::string get_selected_printer_preset_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : m_selected_preset; } // select printer with name and return reference on it - 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); } + PhysicalPrinter& select_printer_by_name(const std::string& full_name); + bool has_selection() const; + void unselect_printer() ; + bool is_selected(ConstIterator it, const std::string &preset_name) const; // Return a printer by an index. If the printer is active, a temporary copy is returned. PhysicalPrinter& printer(size_t idx) { return m_printers[idx]; } @@ -698,6 +703,8 @@ private: // Selected printer. size_t m_idx_selected = size_t(-1); + // The name of the preset which is currently select for this printer + std::string m_selected_preset; // Path to the directory to store the config files into. std::string m_dir_path; diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 7c4fa1cb2..7969966e5 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -458,7 +458,7 @@ void PresetBundle::export_selections(AppConfig &config) config.set("presets", "sla_material", sla_materials.get_selected_preset_name()); config.set("presets", "printer", printers.get_selected_preset_name()); - config.set("extras", "physical_printer", physical_printers.get_selected_printer_name()); + config.set("extras", "physical_printer", physical_printers.get_selected_full_printer_name()); } DynamicPrintConfig PresetBundle::full_config() const diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 048e17926..5673eece7 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3208,24 +3208,21 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt) if (preset_type == Preset::TYPE_FILAMENT) { wxGetApp().preset_bundle->set_filament_preset(idx, preset_name); } - - if (preset_type == Preset::TYPE_PRINTER) { - if(combo->is_selected_physical_printer()) { - // Select related printer preset on the Printer Settings Tab - const std::string printer_name = combo->GetString(selection).ToUTF8().data(); - PhysicalPrinter& printer = wxGetApp().preset_bundle->physical_printers.select_printer_by_name(printer_name); - preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type, printer.get_preset_name()); - } - else - wxGetApp().preset_bundle->physical_printers.unselect_printer(); - } + bool select_preset = !combo->selection_is_changed_according_to_physical_printers(); // TODO: ? if (preset_type == Preset::TYPE_FILAMENT && sidebar->is_multifilament()) { // Only update the plater UI for the 2nd and other filaments. combo->update(); } - else { + else if (select_preset) { + if (preset_type == Preset::TYPE_PRINTER) { + PhysicalPrinterCollection& physical_printers = wxGetApp().preset_bundle->physical_printers; + if(combo->is_selected_physical_printer()) + preset_name = physical_printers.get_selected_printer_preset_name(); + else + physical_printers.unselect_printer(); + } wxWindowUpdateLocker noUpdates(sidebar->presets_panel()); wxGetApp().get_tab(preset_type)->select_preset(preset_name); } diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 1473bf6da..e08cf101d 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -63,8 +63,7 @@ PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const m_type(preset_type), m_last_selected(wxNOT_FOUND), m_em_unit(em_unit(this)), - m_preset_bundle(wxGetApp().preset_bundle), - m_bitmap_cache(new BitmapCache) + m_preset_bundle(wxGetApp().preset_bundle) { SetFont(wxGetApp().normal_font()); #ifdef _WIN32 @@ -105,17 +104,31 @@ 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(); + + Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& evt) { + // see https://github.com/prusa3d/PrusaSlicer/issues/3889 + // Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender") + // m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive. + // So, use GetSelection() from event parameter + auto selected_item = evt.GetSelection(); + + auto marker = reinterpret_cast(this->GetClientData(selected_item)); + if (marker >= LABEL_ITEM_DISABLED && marker < LABEL_ITEM_MAX) + this->SetSelection(this->m_last_selected); + else if (on_selection_changed && (m_last_selected != selected_item || m_collection->current_is_dirty())) { + m_last_selected = selected_item; + on_selection_changed(selected_item); + evt.StopPropagation(); + } + evt.Skip(); + }); } PresetComboBox::~PresetComboBox() { - delete m_bitmap_cache; - m_bitmap_cache = nullptr; } void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type) @@ -123,12 +136,96 @@ void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type) this->SetClientData(item, (void*)label_item_type); } +void PresetComboBox::update(const std::string& select_preset_name) +{ + Freeze(); + Clear(); + size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected + + const std::deque& presets = m_collection->get_presets(); + + std::map> nonsys_presets; + wxString selected = ""; + if (!presets.front().is_visible) + set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); + + for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i) + { + const Preset& preset = presets[i]; + if (!preset.is_visible || !preset.is_compatible) + continue; + + // marker used for disable incompatible printer models for the selected physical printer + bool is_enabled = true; + + std::string bitmap_key = "tab"; + std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; + + 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"; + + wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "lock_closed", is_enabled, preset.is_compatible, preset.is_system || preset.is_default); + assert(bmp); + + if (preset.is_default || preset.is_system) { + int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp); + if (!is_enabled) + set_label_marker(item_id, LABEL_ITEM_DISABLED); + if (preset.name == select_preset_name ||//i == idx_selected || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) + selected_preset_item = GetCount() - 1; + } + else + { + 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 (preset.name == select_preset_name) + selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); + } + if (i + 1 == m_collection->num_default_presets()) + set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); + } + 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) { + 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) + selected_preset_item = GetCount() - 1; + } + } + + /* But, if selected_preset_item is still equal to INT_MAX, it means that + * there is no presets added to the list. + * So, select last combobox item ("Add/Remove preset") + */ + if (selected_preset_item == INT_MAX) + selected_preset_item = GetCount() - 1; + + SetSelection(selected_preset_item); + SetToolTip(GetString(selected_preset_item)); + Thaw(); + + m_last_selected = selected_preset_item; +} + 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(); @@ -142,9 +239,9 @@ void PresetComboBox::msw_rescale() void PresetComboBox::fill_width_height() { // To avoid asserts, each added bitmap to wxBitmapCombobox should be the same size, so - // set a bitmap's height to m_bitmapLock->GetHeight() and norm_icon_width to m_bitmapLock->GetWidth() - icon_height = m_bitmapLock.GetBmpHeight(); - norm_icon_width = m_bitmapLock.GetBmpWidth(); + // set a bitmap's height to m_bitmapCompatible->GetHeight() and norm_icon_width to m_bitmapCompatible->GetWidth() + icon_height = m_bitmapCompatible.GetBmpHeight(); + norm_icon_width = m_bitmapCompatible.GetBmpWidth(); /* It's supposed that standard size of an icon is 16px*16px for 100% scaled display. * So set sizes for solid_colored icons used for filament preset @@ -165,6 +262,110 @@ wxString PresetComboBox::separator(const std::string& label) return wxString::FromUTF8(separator_head()) + _(label) + wxString::FromUTF8(separator_tail()); } +wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, bool wide_icons, const std::string& main_icon_name, + bool is_compatible/* = true*/, bool is_system/* = false*/, bool is_single_bar/* = false*/, + std::string filament_rgb/* = ""*/, std::string extruder_rgb/* = ""*/) +{ + bitmap_key += ",h" + std::to_string(icon_height); + + wxBitmap* bmp = bitmap_cache().find(bitmap_key); + if (bmp == nullptr) { + // Create the bitmap with color bars. + std::vector bmps; + if (wide_icons) + // 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) + { + unsigned char rgb[3]; + // Paint the color bars. + bitmap_cache().parse_color(filament_rgb, rgb); + bmps.emplace_back(bitmap_cache().mksolid(is_single_bar ? wide_icon_width : norm_icon_width, icon_height, rgb)); + if (!is_single_bar) { + bitmap_cache().parse_color(extruder_rgb, rgb); + bmps.emplace_back(bitmap_cache().mksolid(thin_icon_width, icon_height, rgb)); + } + // Paint a lock at the system presets. + bmps.emplace_back(bitmap_cache().mkclear(space_icon_width, icon_height)); + } + else + { + // Paint the color bars. + bmps.emplace_back(bitmap_cache().mkclear(thin_space_icon_width, icon_height)); + bmps.emplace_back(create_scaled_bitmap(main_icon_name)); + // Paint a lock at the system presets. + bmps.emplace_back(bitmap_cache().mkclear(wide_space_icon_width, icon_height)); + } + bmps.emplace_back(is_system ? create_scaled_bitmap("lock_closed") : bitmap_cache().mkclear(norm_icon_width, icon_height)); + bmp = bitmap_cache().insert(bitmap_key, bmps); + } + + return bmp; +} + +wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, const std::string& main_icon_name, const std::string& next_icon_name, + bool is_enabled/* = true*/, bool is_compatible/* = true*/, bool is_system/* = false*/) +{ + bitmap_key += ",h" + std::to_string(icon_height); + + wxBitmap* bmp = bitmap_cache().find(bitmap_key); + if (bmp == nullptr) { + // Create the bitmap with color bars. + std::vector bmps; + bmps.emplace_back(m_type == Preset::TYPE_PRINTER ? create_scaled_bitmap(main_icon_name, this, 16, !is_enabled) : + is_compatible ? m_bitmapCompatible.bmp() : m_bitmapIncompatible.bmp()); + // Paint a lock at the system presets. + bmps.emplace_back(is_system ? create_scaled_bitmap(next_icon_name, this, 16, !is_enabled) : bitmap_cache().mkclear(norm_icon_width, icon_height)); + bmp = bitmap_cache().insert(bitmap_key, bmps); + } + + return bmp; +} + +bool PresetComboBox::is_selected_physical_printer() +{ + auto selected_item = this->GetSelection(); + auto marker = reinterpret_cast(this->GetClientData(selected_item)); + return marker == LABEL_ITEM_PHYSICAL_PRINTER; +} + +bool PresetComboBox::selection_is_changed_according_to_physical_printers() +{ + if (m_type != Preset::TYPE_PRINTER || !is_selected_physical_printer()) + return false; + + PhysicalPrinterCollection& physical_printers = m_preset_bundle->physical_printers; + + std::string selected_string = this->GetString(this->GetSelection()).ToUTF8().data(); + + std::string old_printer_full_name, old_printer_preset; + if (physical_printers.has_selection()) { + old_printer_full_name = physical_printers.get_selected_full_printer_name(); + old_printer_preset = physical_printers.get_selected_printer_preset_name(); + } + else + old_printer_preset = m_collection->get_edited_preset().name; + // Select related printer preset on the Printer Settings Tab + physical_printers.select_printer_by_name(selected_string); + std::string preset_name = physical_printers.get_selected_printer_preset_name(); + + // if new preset wasn't selected, there is no need to call update preset selection + if (old_printer_preset == preset_name) { + // we need just to update according Plater<->Tab PresetComboBox + if (dynamic_cast(this)!=nullptr) + wxGetApp().get_tab(m_type)->update_preset_choice(); + else if (dynamic_cast(this)!=nullptr) + wxGetApp().sidebar().update_presets(m_type); + return true; + } + + Tab* tab = wxGetApp().get_tab(Preset::TYPE_PRINTER); + if (tab) + tab->select_preset(preset_name, false, old_printer_full_name); + return true; +} + #ifdef __APPLE__ bool PresetComboBox::OnAddBitmap(const wxBitmap& bitmap) { @@ -245,25 +446,6 @@ 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); - if (dlg.ShowModal() == wxID_OK) - this->update(); - return; - } - if (marker >= LABEL_ITEM_WIZARD_PRINTERS) { - ConfigWizard::StartPage sp = ConfigWizard::SP_WELCOME; - switch (marker) { - case LABEL_ITEM_WIZARD_PRINTERS: sp = ConfigWizard::SP_PRINTERS; break; - 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); }); - } - */ if (marker == LABEL_ITEM_WIZARD_PRINTERS) show_add_menu(); else @@ -372,13 +554,6 @@ PlaterPresetComboBox::~PlaterPresetComboBox() edit_btn->Destroy(); } -bool PlaterPresetComboBox::is_selected_physical_printer() -{ - auto selected_item = this->GetSelection(); - auto marker = reinterpret_cast(this->GetClientData(selected_item)); - return marker == LABEL_ITEM_PHYSICAL_PRINTER; -} - bool PlaterPresetComboBox::switch_to_tab() { Tab* tab = wxGetApp().get_tab(m_type); @@ -465,7 +640,7 @@ void PlaterPresetComboBox::update() { unsigned char rgb[3]; extruder_color = m_preset_bundle->printers.get_edited_preset().config.opt_string("extruder_colour", (unsigned int)m_extruder_idx); - if (!m_bitmap_cache->parse_color(extruder_color, rgb)) + if (!bitmap_cache().parse_color(extruder_color, rgb)) // Extruder color is not defined. extruder_color.clear(); selected_filament_preset = m_collection->find_preset(m_preset_bundle->filament_presets[m_extruder_idx]); @@ -499,64 +674,33 @@ void PlaterPresetComboBox::update() continue; std::string bitmap_key, filament_rgb, extruder_rgb; + std::string bitmap_type_name = bitmap_key = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; + bool single_bar = false; - if (m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA) - bitmap_key = "sla_printer"; - else if (m_type == Preset::TYPE_FILAMENT) + if (m_type == Preset::TYPE_FILAMENT) { // Assign an extruder color to the selected item if the extruder color is defined. filament_rgb = preset.config.opt_string("filament_colour", 0); extruder_rgb = (selected && !extruder_color.empty()) ? extruder_color : filament_rgb; single_bar = filament_rgb == extruder_rgb; - bitmap_key = single_bar ? filament_rgb : filament_rgb + extruder_rgb; + bitmap_key += single_bar ? filament_rgb : filament_rgb + extruder_rgb; } - wxBitmap main_bmp = create_scaled_bitmap(m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name); // 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 += preset.is_compatible ? ",cmpt" : ",ncmpt"; bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst"; - 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. - std::vector bmps; - if (wide_icons) - // Paint a red flag for incompatible presets. - bmps.emplace_back(preset.is_compatible ? m_bitmap_cache->mkclear(norm_icon_width, icon_height) : m_bitmapIncompatible.bmp()); - - if (m_type == Preset::TYPE_FILAMENT) - { - unsigned char rgb[3]; - // Paint the color bars. - m_bitmap_cache->parse_color(filament_rgb, rgb); - bmps.emplace_back(m_bitmap_cache->mksolid(single_bar ? wide_icon_width : norm_icon_width, icon_height, rgb)); - if (!single_bar) { - m_bitmap_cache->parse_color(extruder_rgb, rgb); - bmps.emplace_back(m_bitmap_cache->mksolid(thin_icon_width, icon_height, rgb)); - } - // Paint a lock at the system presets. - bmps.emplace_back(m_bitmap_cache->mkclear(space_icon_width, icon_height)); - } - else - { - // Paint the color bars. - bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height)); - bmps.emplace_back(main_bmp); - // Paint a lock at the system presets. - bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height)); - } - bmps.emplace_back((preset.is_system || preset.is_default) ? m_bitmapLock.bmp() : m_bitmap_cache->mkclear(norm_icon_width, icon_height)); - bmp = m_bitmap_cache->insert(bitmap_key, bmps); - } + wxBitmap* bmp = get_bmp(bitmap_key, wide_icons, bitmap_type_name, + preset.is_compatible, preset.is_system || preset.is_default, + single_bar, filament_rgb, extruder_rgb); + assert(bmp); const std::string name = preset.alias.empty() ? preset.name : preset.alias; if (preset.is_default || preset.is_system) { - Append(wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), - !bmp ? main_bmp : *bmp); + Append(wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp); if (is_selected || // just in case: mark selected_preset_item as a first added element selected_preset_item == INT_MAX) { @@ -595,59 +739,26 @@ void PlaterPresetComboBox::update() const PhysicalPrinterCollection& ph_printers = m_preset_bundle->physical_printers; for (PhysicalPrinterCollection::ConstIterator it = ph_printers.begin(); it != ph_printers.end(); ++it) { - std::string bitmap_key = it->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; - if (wide_icons) - bitmap_key += "wide,"; - 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. - std::vector bmps; + for (const std::string preset_name : it->get_preset_names()) { + Preset* preset = m_collection->find_preset(preset_name); + if (!preset) + continue; + std::string main_icon_name, bitmap_key = main_icon_name = preset->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; 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(it->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name)); - // Paint a lock at the system presets. - bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width+norm_icon_width, icon_height)); - bmp = m_bitmap_cache->insert(bitmap_key, bmps); - } + bitmap_key += ",cmpt"; + bitmap_key += ",nsyst"; - 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) - selected_preset_item = GetCount() - 1; + wxBitmap* bmp = get_bmp(bitmap_key, wide_icons, main_icon_name); + assert(bmp); + + set_label_marker(Append(wxString::FromUTF8((it->get_full_name(preset_name) + (preset->is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp), LABEL_ITEM_PHYSICAL_PRINTER); + if (ph_printers.is_selected(it, preset_name) || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) + selected_preset_item = GetCount() - 1; + } } } - -/* - // add LABEL_ITEM_PHYSICAL_PRINTERS - std::string bitmap_key; - 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. - 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("printer")); - // 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); - } - 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) { @@ -657,23 +768,10 @@ void PlaterPresetComboBox::update() 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); - } + wxBitmap* bmp = get_bmp(bitmap_key, wide_icons, "edit_uni"); + assert(bmp); + if (m_type == Preset::TYPE_SLA_MATERIAL) set_label_marker(Append(separator(L("Add/Remove materials")), *bmp), LABEL_ITEM_WIZARD_MATERIALS); else @@ -731,8 +829,10 @@ TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type) update(); }); } - else if (on_selection_changed && (m_last_selected != selected_item || m_collection->current_is_dirty()) ) + else if (on_selection_changed && (m_last_selected != selected_item || m_collection->current_is_dirty()) ) { + m_last_selected = selected_item; on_selection_changed(selected_item); + } evt.StopPropagation(); }); @@ -754,7 +854,12 @@ void TabPresetComboBox::update() if (!presets.front().is_visible) set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); int idx_selected = m_collection->get_selected_idx(); - for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i) { + + std::string sel_preset_name = m_preset_bundle->physical_printers.get_selected_printer_preset_name(); + PrinterTechnology proper_pt = (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) ? + m_collection->find_preset(sel_preset_name)->printer_technology() : ptAny; + for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i) + { const Preset& preset = presets[i]; if (!preset.is_visible || (!show_incompatible && !preset.is_compatible && i != idx_selected)) continue; @@ -762,14 +867,12 @@ void TabPresetComboBox::update() // 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()*/; - } + if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) + is_enabled = m_enable_all ? true : preset.printer_technology() == proper_pt;//m_preset_bundle->physical_printers.get_selected_printer_technology(); 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, 16, !is_enabled); + std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; + if (m_type == Preset::TYPE_PRINTER) { bitmap_key += "_printer"; if (preset.printer_technology() == ptSLA) @@ -779,20 +882,12 @@ void TabPresetComboBox::update() } bitmap_key += preset.is_compatible ? ",cmpt" : ",ncmpt"; bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst"; - 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. - 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) ? (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); - } + wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "lock_closed", is_enabled, preset.is_compatible, preset.is_system || preset.is_default); + assert(bmp); if (preset.is_default || preset.is_system) { - int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), !bmp ? main_bmp : *bmp); + int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp); if (!is_enabled) set_label_marker(item_id, LABEL_ITEM_DISABLED); if (i == idx_selected || @@ -824,18 +919,38 @@ void TabPresetComboBox::update() selected_preset_item = GetCount() - 1; } } - if (m_type == Preset::TYPE_PRINTER) { - std::string 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. - std::vector bmps; - bmps.emplace_back(create_scaled_bitmap(m_main_bitmap_name, this)); - bmps.emplace_back(create_scaled_bitmap("edit_uni", this)); - bmp = m_bitmap_cache->insert(bitmap_key, bmps); + if (m_type == Preset::TYPE_PRINTER) + { + // add Physical printers, if any exists + if (!m_preset_bundle->physical_printers.empty()) { + set_label_marker(Append(separator(L("Physical printers")), wxNullBitmap)); + const PhysicalPrinterCollection& ph_printers = m_preset_bundle->physical_printers; + + for (PhysicalPrinterCollection::ConstIterator it = ph_printers.begin(); it != ph_printers.end(); ++it) { + for (const std::string preset_name : it->get_preset_names()) { + Preset* preset = m_collection->find_preset(preset_name); + if (!preset) + continue; + std::string main_icon_name = preset->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; + std::string bitmap_key = main_icon_name + ",nsyst"; + + wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "", true, true, false); + assert(bmp); + + set_label_marker(Append(wxString::FromUTF8((it->get_full_name(preset_name) + (preset->is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp), LABEL_ITEM_PHYSICAL_PRINTER); + if (ph_printers.is_selected(it, preset_name) || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) + selected_preset_item = GetCount() - 1; + } + } } + + // add "Add/Remove printers" item + wxBitmap* bmp = get_bmp("edit_preset_list", m_main_bitmap_name, "edit_uni", true, true, true); + assert(bmp); + set_label_marker(Append(separator(L("Add/Remove printers")), *bmp), LABEL_ITEM_WIZARD_PRINTERS); } @@ -869,11 +984,26 @@ void TabPresetComboBox::update_dirty() // 2) Update the labels. wxWindowUpdateLocker noUpdates(this); for (unsigned int ui_id = 0; ui_id < GetCount(); ++ui_id) { + auto marker = reinterpret_cast(this->GetClientData(ui_id)); + if (marker >= LABEL_ITEM_MARKER) + continue; + std::string old_label = GetString(ui_id).utf8_str().data(); std::string preset_name = Preset::remove_suffix_modified(old_label); + std::string ph_printer_name; + + if (marker == LABEL_ITEM_PHYSICAL_PRINTER) { + ph_printer_name = PhysicalPrinter::get_short_name(preset_name); + preset_name = PhysicalPrinter::get_preset_name(preset_name); + } + const Preset* preset = m_collection->find_preset(preset_name, false); if (preset) { std::string new_label = preset->is_dirty ? preset->name + Preset::suffix_modified() : preset->name; + + if (marker == LABEL_ITEM_PHYSICAL_PRINTER) + new_label = ph_printer_name + PhysicalPrinter::separator() + new_label; + if (old_label != new_label) SetString(ui_id, wxString::FromUTF8(new_label.c_str())); } @@ -885,6 +1015,12 @@ void TabPresetComboBox::update_dirty() #endif /* __APPLE __ */ } +void TabPresetComboBox::update_physical_printers( const std::string& preset_name) +{ + if (m_type == Preset::TYPE_PRINTER && update_ph_printers) + update_ph_printers(preset_name); +} + //------------------------------------------ // PresetForPrinter @@ -900,9 +1036,7 @@ PresetForPrinter::PresetForPrinter(PhysicalPrinterDialog* parent, const std::str m_delete_preset_btn->SetToolTip(_L("Delete this preset from this printer device")); m_delete_preset_btn->Bind(wxEVT_BUTTON, &PresetForPrinter::DeletePreset, this); - m_presets_list = new TabPresetComboBox(parent, Preset::TYPE_PRINTER); - if (preset_name.empty()) - m_presets_list->set_enable_all(); + m_presets_list = new PresetComboBox(parent, Preset::TYPE_PRINTER); m_presets_list->set_selection_changed_function([this](int selection) { std::string selected_string = Preset::remove_suffix_modified(m_presets_list->GetString(selection).ToUTF8().data()); @@ -922,8 +1056,7 @@ PresetForPrinter::PresetForPrinter(PhysicalPrinterDialog* parent, const std::str update_full_printer_name(); }); - m_presets_list->update(); - m_presets_list->SetStringSelection(from_u8(preset_name)); + m_presets_list->update(preset_name); m_info_line = new wxStaticText(parent, wxID_ANY, _L("This printer will be shown in the presets list as") + ":"); @@ -997,11 +1130,10 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) SetFont(wxGetApp().normal_font()); SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - if (printer_name.IsEmpty()) { - printer_name = _L("My Printer Device"); - // if printer_name is empty it means that new printer is created, so enable all items in the preset list - m_presets.emplace_back(new PresetForPrinter(this, "")); - } + m_default_name = _L("My Printer Device"); + + if (printer_name.IsEmpty()) + printer_name = m_default_name; else { std::string full_name = into_u8(printer_name); printer_name = from_u8(PhysicalPrinter::get_short_name(full_name)); @@ -1022,6 +1154,8 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) if (!printer) { const Preset& preset = wxGetApp().preset_bundle->printers.get_edited_preset(); printer = new PhysicalPrinter(into_u8(printer_name), preset); + // if printer_name is empty it means that new printer is created, so enable all items in the preset list + m_presets.emplace_back(new PresetForPrinter(this, preset.name)); } else { @@ -1275,7 +1409,11 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) { wxString printer_name = m_printer_name->GetValue(); if (printer_name.IsEmpty()) { - show_error(this, _L("The supplied name is empty. It can't be saved.")); + warning_catcher(this, _L("The supplied name is empty. It can't be saved.")); + return; + } + if (printer_name == m_default_name) { + warning_catcher(this, _L("You should to change a name of your printer device. It can't be saved.")); return; } @@ -1311,9 +1449,10 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) repeatable_presets += "\n"; wxString msg_text = from_u8((boost::format(_u8L("Next printer preset(s) is(are) duplicated:%1%" - "It(they) will be added just once for the printer \"%2%\".")) % repeatable_presets % printer_name).str()); - wxMessageDialog dialog(nullptr, msg_text, _L("Infornation"), wxICON_INFORMATION | wxOK); - dialog.ShowModal(); + "Should I add it(they) just once for the printer \"%2%\" and close the Editing Dialog?")) % repeatable_presets % printer_name).str()); + wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO); + if (dialog.ShowModal() == wxID_NO) + return; } std::string renamed_from; @@ -1344,8 +1483,7 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) void PhysicalPrinterDialog::AddPreset(wxEvent& event) { - // if printer_name is empty it means that new printer is created, so enable all items in the preset list - m_presets.emplace_back(new PresetForPrinter(this, "")); + m_presets.emplace_back(new PresetForPrinter(this)); // enable DELETE button for the first preset, if was disabled m_presets.front()->EnableDeleteBtn(); diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index c818b6b91..1f5ef026d 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -10,6 +10,7 @@ #include "libslic3r/Preset.hpp" #include "wxExtensions.hpp" #include "GUI_Utils.hpp" +#include "BitmapCache.hpp" class wxString; class wxTextCtrl; @@ -21,8 +22,6 @@ namespace Slic3r { namespace GUI { -class BitmapCache; - // --------------------------------- // *** PresetComboBox *** @@ -49,11 +48,22 @@ public: void set_label_marker(int item, LabelItemType label_item_type = LABEL_ITEM_MARKER); - virtual void update() {}; + void set_selection_changed_function(std::function sel_changed) { on_selection_changed = sel_changed; } + + bool is_selected_physical_printer(); + + // Return true, if physical printer was selected + // and next internal selection was accomplished + bool selection_is_changed_according_to_physical_printers(); + + void update(const std::string& select_preset); + + virtual void update(){}; virtual void msw_rescale(); protected: typedef std::size_t Marker; + std::function on_selection_changed { nullptr }; Preset::Type m_type; std::string m_main_bitmap_name; @@ -61,16 +71,16 @@ protected: PresetBundle* m_preset_bundle {nullptr}; PresetCollection* m_collection {nullptr}; - // Caching color bitmaps for the filament combo box. - BitmapCache* m_bitmap_cache {nullptr}; + // Caching bitmaps for the all bitmaps, used in preset comboboxes + static BitmapCache& bitmap_cache() { + static BitmapCache bmps; + return bmps; + } + // Indicator, that the preset is compatible with the selected printer. ScalableBitmap m_bitmapCompatible; // Indicator, that the preset is NOT compatible with the selected printer. 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; @@ -93,6 +103,13 @@ protected: #endif // __linux__ static wxString separator(const std::string& label); + wxBitmap* get_bmp( std::string bitmap_key, bool wide_icons, const std::string& main_icon_name, + bool is_compatible = true, bool is_system = false, bool is_single_bar = false, + std::string filament_rgb = "", std::string extruder_rgb = ""); + + wxBitmap* get_bmp( std::string bitmap_key, const std::string& main_icon_name, const std::string& next_icon_name, + bool is_enabled = true, bool is_compatible = true, bool is_system = false); + #ifdef __APPLE__ /* For PresetComboBox we use bitmaps that are created from images that are already scaled appropriately for Retina * (Contrary to the intuition, the `scale` argument for Bitmap's constructor doesn't mean @@ -128,7 +145,6 @@ public: void set_extruder_idx(const int extr_idx) { m_extruder_idx = extr_idx; } int get_extruder_idx() const { return m_extruder_idx; } - bool is_selected_physical_printer(); bool switch_to_tab(); void show_add_menu(); void show_edit_menu(); @@ -149,7 +165,8 @@ class TabPresetComboBox : public PresetComboBox { bool show_incompatible {false}; bool m_enable_all {false}; - std::function on_selection_changed { nullptr }; + + std::function update_ph_printers { nullptr }; public: TabPresetComboBox(wxWindow *parent, Preset::Type preset_type); @@ -157,12 +174,15 @@ public: void set_show_incompatible_presets(bool show_incompatible_presets) { show_incompatible = show_incompatible_presets; } + void set_update_physical_printers_function(std::function update_fn) { + update_ph_printers = update_fn; + } void update() override; void update_dirty(); + void update_physical_printers(const std::string& preset_name); 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; } }; @@ -176,7 +196,7 @@ class PresetForPrinter { PhysicalPrinterDialog* m_parent { nullptr }; - TabPresetComboBox* m_presets_list { nullptr }; + PresetComboBox* m_presets_list { nullptr }; ScalableButton* m_delete_preset_btn { nullptr }; wxStaticText* m_info_line { nullptr }; wxStaticText* m_full_printer_name { nullptr }; @@ -186,7 +206,7 @@ class PresetForPrinter void DeletePreset(wxEvent& event); public: - PresetForPrinter(PhysicalPrinterDialog* parent, const std::string& preset_name); + PresetForPrinter(PhysicalPrinterDialog* parent, const std::string& preset_name = ""); ~PresetForPrinter(); wxBoxSizer* sizer() { return m_sizer; } @@ -208,6 +228,7 @@ class ConfigOptionsGroup; class PhysicalPrinterDialog : public DPIDialog { PhysicalPrinter m_printer; + wxString m_default_name; DynamicPrintConfig* m_config { nullptr }; wxTextCtrl* m_printer_name { nullptr }; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 595283e98..dbea9b3f5 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -162,10 +162,20 @@ 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) { - std::string selected_string = m_presets_choice->GetString(selection).ToUTF8().data(); - update_physical_printers(selected_string); - // select preset - select_preset(selected_string); + if (!m_presets_choice->selection_is_changed_according_to_physical_printers()) + { + // for the printer presets set callback for the updating of the physical printers + if (m_type == Preset::TYPE_PRINTER) + m_presets_choice->set_update_physical_printers_function([this](std::string preset_name) { update_physical_printers(preset_name);}); + + // select preset + select_preset(m_presets_choice->GetString(selection).ToUTF8().data()); + + // Disable callback for the updating of the physical printers to avoid a case, + // when select_preset is called from the others than this place + if (m_type == Preset::TYPE_PRINTER) + m_presets_choice->set_update_physical_printers_function(nullptr); + } }); auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); @@ -764,9 +774,11 @@ void Tab::update_tab_ui() void Tab::update_physical_printers(std::string preset_name) { - if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) + PhysicalPrinterCollection& physical_printers = wxGetApp().preset_bundle->physical_printers; + if (physical_printers.has_selection() && + Preset::remove_suffix_modified(preset_name) != physical_printers.get_selected_printer_preset_name()) { - std::string printer_name = m_preset_bundle->physical_printers.get_selected_full_printer_name(); + std::string printer_name = 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" @@ -780,12 +792,14 @@ void Tab::update_physical_printers(std::string preset_name) 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); + physical_printers.get_selected_printer().update_from_preset(*preset); + physical_printers.select_printer_by_name(physical_printers.get_selected_printer().get_full_name(preset_name)); + return; } - else - // unselect physical printer, if it was selected - m_preset_bundle->physical_printers.unselect_printer(); } + + // 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. @@ -2148,11 +2162,10 @@ void TabPrinter::build_fff() line.append_widget(serial_test); optgroup->append_line(line); } -#endif optgroup = page->new_optgroup(L("Print Host upload")); build_printhost(optgroup.get()); - +#endif optgroup = page->new_optgroup(L("Firmware")); optgroup->append_single_option_line("gcode_flavor"); optgroup->append_single_option_line("silent_mode"); @@ -2310,8 +2323,10 @@ void TabPrinter::build_sla() optgroup->append_single_option_line("min_initial_exposure_time"); optgroup->append_single_option_line("max_initial_exposure_time"); + /* optgroup = page->new_optgroup(L("Print Host upload")); build_printhost(optgroup.get()); + */ const int notes_field_height = 25; // 250 @@ -2699,11 +2714,13 @@ void TabPrinter::update_fff() m_serial_test_btn->Disable(); } + /* { std::unique_ptr host(PrintHost::get_print_host(m_config)); m_print_host_test_btn->Enable(!m_config->opt_string("print_host").empty() && host->can_test()); m_printhost_browse_btn->Enable(host->has_auto_discovery()); } + */ bool have_multiple_extruders = m_extruders_count > 1; get_field("toolchange_gcode")->toggle(have_multiple_extruders); @@ -2942,10 +2959,15 @@ void Tab::update_page_tree_visibility() } +void Tab::update_preset_choice() +{ + m_presets_choice->update(); +} + // Called by the UI combo box when the user switches profiles, and also to delete the current profile. // Select a preset by a name.If !defined(name), then the default preset is selected. // If the current profile is modified, user is asked to save the changes. -void Tab::select_preset(std::string preset_name, bool delete_current) +void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, const std::string& last_selected_ph_printer_name/* =""*/) { if (preset_name.empty()) { if (delete_current) { @@ -3054,9 +3076,22 @@ void Tab::select_preset(std::string preset_name, bool delete_current) if (canceled) { update_tab_ui(); + /* // unselect physical printer selection to the correct synchronization of the printer presets between Tab and Plater if (m_type == Preset::TYPE_PRINTER) m_preset_bundle->physical_printers.unselect_printer(); + */ + + + // Check if preset really was changed. + // If preset selection was canceled and previously was selected physical printer, we should select it back + if (m_type == Preset::TYPE_PRINTER && !last_selected_ph_printer_name.empty()) { + if (m_presets->get_edited_preset().name == PhysicalPrinter::get_preset_name(last_selected_ph_printer_name)) { + m_preset_bundle->physical_printers.select_printer_by_name(last_selected_ph_printer_name); + m_presets_choice->update(); + } + } + // Trigger the on_presets_changed event so that we also restore the previous value in the plater selector, // if this action was initiated from the plater. on_presets_changed(); @@ -3098,6 +3133,10 @@ void Tab::select_preset(std::string preset_name, bool delete_current) else if (printer_technology == ptSLA && m_dependent_tabs.front() != Preset::Type::TYPE_SLA_PRINT) m_dependent_tabs = { Preset::Type::TYPE_SLA_PRINT, Preset::Type::TYPE_SLA_MATERIAL }; } + + //update physical printer's related printer preset if it's needed + m_presets_choice->update_physical_printers(preset_name); + load_current_preset(); } } @@ -3295,7 +3334,7 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach) // 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); + m_presets_choice->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 69720ff65..82df31b59 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -275,8 +275,9 @@ public: void load_current_preset(); void rebuild_page_tree(); void update_page_tree_visibility(); - // Select a new preset, possibly delete the current one. - void select_preset(std::string preset_name = "", bool delete_current = false); + void update_preset_choice(); + // Select a new preset, possibly delete the current one. + void select_preset(std::string preset_name = "", bool delete_current = false, const std::string& last_selected_ph_printer_name = ""); bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, const std::string& new_printer_name = ""); bool may_switch_to_SLA_preset(); From 72ec414f1e4492d67465efe368a4a224a21ed7eb Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 20 Jul 2020 14:56:09 +0200 Subject: [PATCH 13/31] PhysicalPrinters improvements: - Added possibility to correct delete presets considering with the physical printers - Smart switching to the printer preset if physical printer was selected --- src/libslic3r/Preset.cpp | 55 +++++++++- src/libslic3r/Preset.hpp | 9 +- src/slic3r/GUI/PresetComboBoxes.cpp | 154 ++++++++++++++++++++++++---- src/slic3r/GUI/PresetComboBoxes.hpp | 32 +++++- src/slic3r/GUI/Tab.cpp | 141 ++++++++++++++----------- src/slic3r/GUI/Tab.hpp | 2 +- 6 files changed, 302 insertions(+), 91 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index ad7615f6d..a55dc24ca 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1436,6 +1436,11 @@ bool PhysicalPrinter::add_preset(const std::string& preset_name) return preset_names.emplace(preset_name).second; } +bool PhysicalPrinter::delete_preset(const std::string& preset_name) +{ + return preset_names.erase(preset_name) > 0; +} + PhysicalPrinter::PhysicalPrinter(const std::string& name, const Preset& preset) : name(name) { @@ -1521,7 +1526,6 @@ void PhysicalPrinterCollection::load_printers(const std::string& dir_path, const } m_printers.insert(m_printers.end(), std::make_move_iterator(printers_loaded.begin()), std::make_move_iterator(printers_loaded.end())); std::sort(m_printers.begin(), m_printers.end()); -//! this->select_preset(first_visible_idx()); if (!errors_cummulative.empty()) throw std::runtime_error(errors_cummulative); } @@ -1542,8 +1546,11 @@ std::string PhysicalPrinterCollection::path_from_name(const std::string& new_nam return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string(); } -void PhysicalPrinterCollection::save_printer(const PhysicalPrinter& edited_printer, const std::string& renamed_from) +void PhysicalPrinterCollection::save_printer(PhysicalPrinter& edited_printer, const std::string& renamed_from/* = ""*/) { + // controll and update preset_names in edited_printer config + edited_printer.update_preset_names_in_config(); + std::string name = renamed_from.empty() ? edited_printer.name : renamed_from; // 1) Find the printer with a new_name or create a new one, // initialize it with the edited config. @@ -1605,6 +1612,33 @@ bool PhysicalPrinterCollection::delete_selected_printer() return true; } +bool PhysicalPrinterCollection::delete_preset_from_printers( const std::string& preset_name, bool first_check /*=true*/) +{ + if (first_check) { + for (auto printer: m_printers) + if (printer.preset_names.size()==1 && *printer.preset_names.begin() == preset_name) + return false; + } + + std::vector printers_for_delete; + for (PhysicalPrinter& printer : m_printers) + if (printer.preset_names.size() == 1 && *printer.preset_names.begin() == preset_name) + printers_for_delete.emplace_back(printer.name); + else if (printer.delete_preset(preset_name)) { + if (printer.name == get_selected_printer_name() && + preset_name == get_selected_printer_preset_name()) + select_printer(printer); + save_printer(printer); + } + + if (!printers_for_delete.empty()) { + for (const std::string& printer_name : printers_for_delete) + delete_printer(printer_name); + unselect_printer(); + } + return true; +} + std::string PhysicalPrinterCollection::get_selected_full_printer_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_full_name(m_selected_preset); @@ -1625,6 +1659,23 @@ PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(const std::st return *it; } +PhysicalPrinter& PhysicalPrinterCollection::select_printer(const std::string& printer_name) +{ + auto it = this->find_printer_internal(printer_name); + assert(it != m_printers.end()); + + // update idx_selected + m_idx_selected = it - m_printers.begin(); + // update name of the currently selected preset + m_selected_preset = *it->preset_names.begin(); + return *it; +} + +PhysicalPrinter& PhysicalPrinterCollection::select_printer(const PhysicalPrinter& printer) +{ + return select_printer(printer.name); +} + bool PhysicalPrinterCollection::has_selection() const { return m_idx_selected != size_t(-1); diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index d30ea7059..e8afb0f6f 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -569,6 +569,7 @@ public: // add preset to the preset_names // return false, if preset with this name is already exist in the set bool add_preset(const std::string& preset_name); + bool delete_preset(const std::string& preset_name); void reset_presets(); // Return a printer technology, return ptFFF if the printer technology is not set. @@ -629,7 +630,7 @@ public: // Save the printer under a new name. If the name is different from the old one, // a new printer is stored into the list of printers. // New printer is activated. - void save_printer(const PhysicalPrinter& printer, const std::string& renamed_from); + void save_printer(PhysicalPrinter& printer, const std::string& renamed_from = ""); // Delete the current preset, activate the first visible preset. // returns true if the preset was deleted successfully. @@ -637,6 +638,10 @@ public: // Delete the selected preset // returns true if the preset was deleted successfully. bool delete_selected_printer(); + // Delete preset_name preset from all printers: + // If there is last preset for the printer and first_check== false, then delete this printer + // returns true if all presets were deleted successfully. + bool delete_preset_from_printers(const std::string& preset_name, bool first_check = true); // Return the selected preset, without the user modifications applied. PhysicalPrinter& get_selected_printer() { return m_printers[m_idx_selected]; } @@ -659,6 +664,8 @@ public: // select printer with name and return reference on it PhysicalPrinter& select_printer_by_name(const std::string& full_name); + PhysicalPrinter& select_printer(const std::string &printer_name); + PhysicalPrinter& select_printer(const PhysicalPrinter& printer); bool has_selection() const; void unselect_printer() ; bool is_selected(ConstIterator it, const std::string &preset_name) const; diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index e08cf101d..bc1f48dd6 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -357,6 +357,8 @@ bool PresetComboBox::selection_is_changed_according_to_physical_printers() wxGetApp().get_tab(m_type)->update_preset_choice(); else if (dynamic_cast(this)!=nullptr) wxGetApp().sidebar().update_presets(m_type); + + this->update(); return true; } @@ -614,6 +616,8 @@ void PlaterPresetComboBox::show_edit_menu() return; m_preset_bundle->physical_printers.delete_selected_printer(); + + wxGetApp().get_tab(m_type)->update_preset_choice(); update(); }, "cross", menu, []() { return true; }, wxGetApp().plater()); @@ -855,9 +859,16 @@ void TabPresetComboBox::update() set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); int idx_selected = m_collection->get_selected_idx(); - std::string sel_preset_name = m_preset_bundle->physical_printers.get_selected_printer_preset_name(); - PrinterTechnology proper_pt = (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) ? - m_collection->find_preset(sel_preset_name)->printer_technology() : ptAny; + PrinterTechnology proper_pt = ptAny; + if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) { + std::string sel_preset_name = m_preset_bundle->physical_printers.get_selected_printer_preset_name(); + Preset* preset = m_collection->find_preset(sel_preset_name); + if (preset) + proper_pt = preset->printer_technology(); + else + m_preset_bundle->physical_printers.unselect_printer(); + } + for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i) { const Preset& preset = presets[i]; @@ -868,7 +879,7 @@ void TabPresetComboBox::update() 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.printer_technology() == proper_pt;//m_preset_bundle->physical_printers.get_selected_printer_technology(); + is_enabled = m_enable_all ? true : preset.printer_technology() == proper_pt; std::string bitmap_key = "tab"; std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; @@ -1017,8 +1028,49 @@ void TabPresetComboBox::update_dirty() void TabPresetComboBox::update_physical_printers( const std::string& preset_name) { - if (m_type == Preset::TYPE_PRINTER && update_ph_printers) - update_ph_printers(preset_name); + if (m_type != Preset::TYPE_PRINTER || !m_allow_to_update_physical_printers) + return; + + m_allow_to_update_physical_printers = false; + + PhysicalPrinterCollection& physical_printers = m_preset_bundle->physical_printers; + if (!physical_printers.has_selection()) + return; + + std::string printer_preset_name = physical_printers.get_selected_printer_preset_name(); + + if (Preset::remove_suffix_modified(preset_name) == printer_preset_name) { + if (!this->is_selected_physical_printer()) + physical_printers.unselect_printer(); + } + else + { + ChangePresetForPhysicalPrinterDialog dlg(Preset::remove_suffix_modified(preset_name)); + if(dlg.ShowModal() == wxID_OK) + { + if (dlg.m_selection == ChangePresetForPhysicalPrinterDialog::Switch) + // unselect physical printer, if it was selected + m_preset_bundle->physical_printers.unselect_printer(); + else + { + PhysicalPrinter printer = physical_printers.get_selected_printer(); + + if (dlg.m_selection == ChangePresetForPhysicalPrinterDialog::ChangePreset) + printer.delete_preset(printer_preset_name); + + if (printer.add_preset(preset_name)) + physical_printers.save_printer(printer); + else { + wxMessageDialog dialog(nullptr, _L("This preset is already exist for this physical printer. Please, select another one."), _L("Information"), wxICON_INFORMATION | wxOK); + dialog.ShowModal(); + } + + physical_printers.select_printer_by_name(printer.get_full_name(preset_name)); + } + } + else + wxGetApp().get_tab(Preset::TYPE_PRINTER)->select_preset(printer_preset_name); + } } @@ -1123,7 +1175,6 @@ void PresetForPrinter::msw_rescale() // PhysicalPrinterDialog //------------------------------------------ - PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) : DPIDialog(NULL, wxID_ANY, _L("Physical Printer"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { @@ -1427,9 +1478,6 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) if (dialog.ShowModal() == wxID_NO) return; - - // Remove the printer from the list. - printers.delete_printer(into_u8(printer_name)); } std::set repeat_presets; @@ -1438,8 +1486,6 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) if (!m_printer.add_preset(preset->get_preset_name())) repeat_presets.emplace(preset->get_preset_name()); } - // update preset_names in printer config - m_printer.update_preset_names_in_config(); if (!repeat_presets.empty()) { @@ -1467,16 +1513,10 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) // save new physical printer printers.save_printer(m_printer, renamed_from); - // update selection on the tab only when it was changed - /* - if (m_printer.get_preset_name() != wxGetApp().preset_bundle->printers.get_selected_preset_name()) { - Tab* tab = wxGetApp().get_tab(Preset::TYPE_PRINTER); - if (tab) { - wxString preset_name = m_printer_presets->GetString(m_printer_presets->GetSelection()); - tab->select_preset(into_u8(preset_name)); - } - } - */ + printers.select_printer(m_printer); + + // refresh preset list on Printer Settings Tab + wxGetApp().get_tab(Preset::TYPE_PRINTER)->update_preset_choice(); event.Skip(); } @@ -1520,4 +1560,74 @@ void PhysicalPrinterDialog::DeletePreset(PresetForPrinter* preset_for_printer) } +//----------------------------------------------- +// ChangePresetForPhysicalPrinterDialog +//----------------------------------------------- + +ChangePresetForPhysicalPrinterDialog::ChangePresetForPhysicalPrinterDialog(const std::string& preset_name) + : DPIDialog(nullptr, wxID_ANY, _L("Warning"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING/* | wxRESIZE_BORDER*/) +{ + SetFont(wxGetApp().normal_font()); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + + PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; + std::string printer_name = printers.get_selected_printer_name(); + std::string old_preset_name = printers.get_selected_printer_preset_name(); + + wxString msg_text = from_u8((boost::format(_u8L("You have selected physical printer \"%1%\"\n" + "with related printer preset \"%2%\"")) % + printer_name % old_preset_name).str()); + wxStaticText* label_top = new wxStaticText(this, wxID_ANY, msg_text); + label_top->SetFont(wxGetApp().bold_font()); + + wxString choices[] = { from_u8((boost::format(_u8L("Just switch to \"%1%\"")) % preset_name).str()), + from_u8((boost::format(_u8L("Change \"%1%\" to \"%2%\" for this physical printer")) % old_preset_name % preset_name).str()), + from_u8((boost::format(_u8L("Add \"%1%\" as a next preset for the the physical printer")) % preset_name).str()) }; + + wxRadioBox* selection_type_box = new wxRadioBox(this, wxID_ANY, _L("What would you like to do?"), wxDefaultPosition, wxDefaultSize, WXSIZEOF(choices), choices, + 3, wxRA_SPECIFY_ROWS); + selection_type_box->SetFont(wxGetApp().normal_font()); + selection_type_box->SetSelection(0); + + selection_type_box->Bind(wxEVT_RADIOBOX, [this](wxCommandEvent& e) { + int selection = e.GetSelection(); + m_selection = (SelectionType)selection; + }); + + auto radio_sizer = new wxBoxSizer(wxHORIZONTAL); + radio_sizer->Add(selection_type_box, 1, wxALIGN_CENTER_VERTICAL); + + wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); + wxButton* btnOK = static_cast(this->FindWindowById(wxID_OK, this)); + btnOK->Bind(wxEVT_BUTTON, &ChangePresetForPhysicalPrinterDialog::OnOK, this); + + wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); + + topSizer->Add(label_top, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); + topSizer->Add(radio_sizer, 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); + topSizer->Add(btns, 0, wxEXPAND | wxALL, BORDER_W); + + SetSizer(topSizer); + topSizer->SetSizeHints(this); +} + +void ChangePresetForPhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) +{ + const int& em = em_unit(); + + msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL }); + + const wxSize& size = wxSize(45 * em, 35 * em); + SetMinSize(size); + + Fit(); + Refresh(); +} + +void ChangePresetForPhysicalPrinterDialog::OnOK(wxEvent& event) +{ + event.Skip(); +} + + }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 1f5ef026d..1cea97e41 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -166,7 +166,7 @@ class TabPresetComboBox : public PresetComboBox bool show_incompatible {false}; bool m_enable_all {false}; - std::function update_ph_printers { nullptr }; + bool m_allow_to_update_physical_printers {false}; public: TabPresetComboBox(wxWindow *parent, Preset::Type preset_type); @@ -174,8 +174,8 @@ public: void set_show_incompatible_presets(bool show_incompatible_presets) { show_incompatible = show_incompatible_presets; } - void set_update_physical_printers_function(std::function update_fn) { - update_ph_printers = update_fn; + void allow_to_update_physical_printers() { + m_allow_to_update_physical_printers = m_type == Preset::TYPE_PRINTER; } void update() override; @@ -263,6 +263,32 @@ protected: void on_sys_color_changed() override {}; }; + +//------------------------------------------------ +// ChangePresetForPhysicalPrinterDialog +//------------------------------------------------ + +class ChangePresetForPhysicalPrinterDialog : public DPIDialog +{ + void OnOK(wxEvent& event); + +public: + + enum SelectionType + { + Switch, + ChangePreset, + AddPreset + } m_selection {Switch}; + + ChangePresetForPhysicalPrinterDialog(const std::string& preset_name); + ~ChangePresetForPhysicalPrinterDialog() {} + +protected: + void on_dpi_changed(const wxRect& suggested_rect) override; + void on_sys_color_changed() override {}; +}; + } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index dbea9b3f5..e498f56b7 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -164,17 +164,14 @@ void Tab::create_preset_tab() m_presets_choice->set_selection_changed_function([this](int selection) { if (!m_presets_choice->selection_is_changed_according_to_physical_printers()) { - // for the printer presets set callback for the updating of the physical printers + // For the printer presets allow to update a physical printer if it is needed. + // After call of the update_physical_printers() this possibility will be disabled again to avoid a case, + // when select_preset is called from the others than this place if (m_type == Preset::TYPE_PRINTER) - m_presets_choice->set_update_physical_printers_function([this](std::string preset_name) { update_physical_printers(preset_name);}); + m_presets_choice->allow_to_update_physical_printers(); // select preset select_preset(m_presets_choice->GetString(selection).ToUTF8().data()); - - // Disable callback for the updating of the physical printers to avoid a case, - // when select_preset is called from the others than this place - if (m_type == Preset::TYPE_PRINTER) - m_presets_choice->set_update_physical_printers_function(nullptr); } }); @@ -772,36 +769,6 @@ void Tab::update_tab_ui() m_presets_choice->update(); } -void Tab::update_physical_printers(std::string preset_name) -{ - PhysicalPrinterCollection& physical_printers = wxGetApp().preset_bundle->physical_printers; - if (physical_printers.has_selection() && - Preset::remove_suffix_modified(preset_name) != physical_printers.get_selected_printer_preset_name()) - { - std::string printer_name = 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; - physical_printers.get_selected_printer().update_from_preset(*preset); - physical_printers.select_printer_by_name(physical_printers.get_selected_printer().get_full_name(preset_name)); - return; - } - } - - // 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) @@ -2822,7 +2789,8 @@ void Tab::load_current_preset() { const Preset& preset = m_presets->get_edited_preset(); - (preset.is_default || preset.is_system) ? m_btn_delete_preset->Disable() : m_btn_delete_preset->Enable(true); +// (preset.is_default || preset.is_system) ? m_btn_delete_preset->Disable() : m_btn_delete_preset->Enable(true); + update_delete_preset_btn(); update(); if (m_type == Slic3r::Preset::TYPE_PRINTER) { @@ -2959,9 +2927,23 @@ void Tab::update_page_tree_visibility() } +void Tab::update_delete_preset_btn() +{ + if (m_type == Preset::TYPE_PRINTER && m_presets_choice->is_selected_physical_printer() && + m_preset_bundle->physical_printers.has_selection()) { + // we can't delete last preset from the physical printer + 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); + } +} + void Tab::update_preset_choice() { m_presets_choice->update(); + update_delete_preset_btn(); } // Called by the UI combo box when the user switches profiles, and also to delete the current profile. @@ -2971,16 +2953,55 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, { if (preset_name.empty()) { if (delete_current) { - // Find an alternate preset to be selected after the current preset is deleted. - const std::deque &presets = this->m_presets->get_presets(); - size_t idx_current = this->m_presets->get_idx_selected(); - // Find the next visible preset. - size_t idx_new = idx_current + 1; - if (idx_new < presets.size()) - for (; idx_new < presets.size() && ! presets[idx_new].is_visible; ++ idx_new) ; - if (idx_new == presets.size()) - for (idx_new = idx_current - 1; idx_new > 0 && ! presets[idx_new].is_visible; -- idx_new); - preset_name = presets[idx_new].name; + PhysicalPrinterCollection& physical_printers = m_preset_bundle->physical_printers; + 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(); + } + else { + // 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 + physical_printers.select_printer(printer); + + preset_name = physical_printers.get_selected_printer_preset_name(); + // revert delete_current value to avoid deleting of the new selected preset + delete_current = false; + } + } + else { + // Check preset for delete in physical printers + // Ask a customer about next action , if there is a printer with just one preset and this preset is equal to delete + if (m_type == Preset::TYPE_PRINTER && !physical_printers.empty() ) + { + // try to delete selected preset from the all printers it has + if (!physical_printers.delete_preset_from_printers(m_presets->get_edited_preset().name)) + { + wxMessageDialog dialog(nullptr, _L("There is/are a physical printer(s), which has/have one and only this printer preset.\n" + "This/Those printer(s) will be deletede after deleting of the selected preset.\n" + "Are you sure you want to delete the selected preset?"), _L("Warning"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION); + if (dialog.ShowModal() == wxID_NO) + return; + + // delete selected preset from printers and printer, if it's needed + physical_printers.delete_preset_from_printers(m_presets->get_edited_preset().name, false); + } + } + + // Find an alternate preset to be selected after the current preset is deleted. + const std::deque &presets = this->m_presets->get_presets(); + size_t idx_current = this->m_presets->get_idx_selected(); + // Find the next visible preset. + size_t idx_new = idx_current + 1; + if (idx_new < presets.size()) + for (; idx_new < presets.size() && ! presets[idx_new].is_visible; ++ idx_new) ; + if (idx_new == presets.size()) + for (idx_new = idx_current - 1; idx_new > 0 && ! presets[idx_new].is_visible; -- idx_new); + preset_name = presets[idx_new].name; + } } else { // If no name is provided, select the "-- default --" preset. preset_name = m_presets->default_preset().name; @@ -3075,23 +3096,16 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, } if (canceled) { - update_tab_ui(); - /* - // unselect physical printer selection to the correct synchronization of the printer presets between Tab and Plater - if (m_type == Preset::TYPE_PRINTER) - m_preset_bundle->physical_printers.unselect_printer(); - */ - - - // Check if preset really was changed. - // If preset selection was canceled and previously was selected physical printer, we should select it back - if (m_type == Preset::TYPE_PRINTER && !last_selected_ph_printer_name.empty()) { - if (m_presets->get_edited_preset().name == PhysicalPrinter::get_preset_name(last_selected_ph_printer_name)) { + if (m_type == Preset::TYPE_PRINTER) { + if (!last_selected_ph_printer_name.empty() && + m_presets->get_edited_preset().name == PhysicalPrinter::get_preset_name(last_selected_ph_printer_name)) { + // If preset selection was canceled and previously was selected physical printer, we should select it back m_preset_bundle->physical_printers.select_printer_by_name(last_selected_ph_printer_name); - m_presets_choice->update(); } } + update_tab_ui(); + // Trigger the on_presets_changed event so that we also restore the previous value in the plater selector, // if this action was initiated from the plater. on_presets_changed(); @@ -3334,6 +3348,7 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach) // 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 + m_presets_choice->allow_to_update_physical_printers(); m_presets_choice->update_physical_printers(name); // Add the new item into the UI component, remove dirty flags and activate the saved item. update_tab_ui(); @@ -3389,7 +3404,9 @@ void Tab::delete_preset() // Don't let the user delete the ' - default - ' configuration. std::string action = current_preset.is_external ? _utf8(L("remove")) : _utf8(L("delete")); // TRN remove/delete - const wxString msg = from_u8((boost::format(_utf8(L("Are you sure you want to %1% the selected preset?"))) % action).str()); + const wxString msg = m_presets_choice->is_selected_physical_printer() ? + from_u8((boost::format(_utf8(L("Are you sure you want to delete \"%1%\" preset from the physical printer?"))) % current_preset.name).str()) : + from_u8((boost::format(_utf8(L("Are you sure you want to %1% the selected preset?"))) % action).str()); action = current_preset.is_external ? _utf8(L("Remove")) : _utf8(L("Delete")); // TRN Remove/Delete wxString title = from_u8((boost::format(_utf8(L("%1% Preset"))) % action).str()); //action + _(L(" Preset")); diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 82df31b59..57129955b 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -275,6 +275,7 @@ public: void load_current_preset(); void rebuild_page_tree(); void update_page_tree_visibility(); + void update_delete_preset_btn(); void update_preset_choice(); // Select a new preset, possibly delete the current one. void select_preset(std::string preset_name = "", bool delete_current = false, const std::string& last_selected_ph_printer_name = ""); @@ -307,7 +308,6 @@ 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(); From 3d990a918904fb1ab10afa4f95f2885350821994 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 20 Jul 2020 16:27:39 +0200 Subject: [PATCH 14/31] First try to convert a user printer profiles to the physical printers --- src/libslic3r/Preset.cpp | 33 +++++++++++++++++++++++++++-- src/libslic3r/Preset.hpp | 1 + src/libslic3r/PresetBundle.cpp | 1 + src/slic3r/GUI/PresetComboBoxes.cpp | 6 ++++++ src/slic3r/GUI/PresetComboBoxes.hpp | 9 +++----- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index a55dc24ca..401de0fc3 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1481,7 +1481,7 @@ PhysicalPrinterCollection::PhysicalPrinterCollection( const std::vectorfind_printer(name, false)) { // This happens when there's is a preset (most likely legacy one) with the same name as a system preset // that's already been loaded from a bundle. - BOOST_LOG_TRIVIAL(warning) << "Preset already present, not loading: " << name; + BOOST_LOG_TRIVIAL(warning) << "Printer already present, not loading: " << name; continue; } try { @@ -1530,6 +1530,35 @@ void PhysicalPrinterCollection::load_printers(const std::string& dir_path, const throw std::runtime_error(errors_cummulative); } +// if there is saved user presets, contains information about "Print Host upload", +// Create default printers with this presets +// Throws an exception on error. +void PhysicalPrinterCollection::load_printers(const PrinterPresetCollection& printer_presets, std::string def_printer_name/* = ""*/) +{ + if (def_printer_name.empty()) + def_printer_name = "Printer"; + + int cnt=0; + std::string errors_cummulative; + // Store the loaded printers into a new vector + std::deque printers_loaded; + for (const Preset& preset: printer_presets) { + const DynamicPrintConfig& config = preset.config; + if (!config.opt_string("print_host").empty() || + !config.opt_string("printhost_apikey").empty() || + !config.opt_string("printhost_cafile").empty() ) { + PhysicalPrinter printer((boost::format("%1% %2%") % def_printer_name % ++cnt ).str(), preset); + printer.loaded = true; + printers_loaded.emplace_back(printer); + + save_printer(printer); + } + } + + if (!errors_cummulative.empty()) + throw std::runtime_error(errors_cummulative); +} + PhysicalPrinter* PhysicalPrinterCollection::find_printer( const std::string& name, bool first_visible_if_not_found) { PhysicalPrinter key(name); diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index e8afb0f6f..02f831136 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -626,6 +626,7 @@ public: // Load ini files of the particular type from the provided directory path. void load_printers(const std::string& dir_path, const std::string& subdir); + void load_printers(const PrinterPresetCollection &printer_presets, std::string def_printer_name = ""); // Save the printer under a new name. If the name is different from the old one, // a new printer is stored into the list of printers. diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 7969966e5..0e215a2ae 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -201,6 +201,7 @@ void PresetBundle::load_presets(AppConfig &config, const std::string &preferred_ } try { this->physical_printers.load_printers(dir_user_presets, "physical_printer"); + this->physical_printers.load_printers(this->printers); } catch (const std::runtime_error &err) { errors_cummulative += err.what(); } diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index bc1f48dd6..2d74344bd 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -131,6 +131,12 @@ PresetComboBox::~PresetComboBox() { } +BitmapCache& PresetComboBox::bitmap_cache() +{ + static BitmapCache bmps; + return bmps; +} + void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type) { this->SetClientData(item, (void*)label_item_type); diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 1cea97e41..89d043f7b 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -10,7 +10,7 @@ #include "libslic3r/Preset.hpp" #include "wxExtensions.hpp" #include "GUI_Utils.hpp" -#include "BitmapCache.hpp" +//#include "BitmapCache.hpp" class wxString; class wxTextCtrl; @@ -22,7 +22,7 @@ namespace Slic3r { namespace GUI { - +class BitmapCache; // --------------------------------- // *** PresetComboBox *** // --------------------------------- @@ -72,10 +72,7 @@ protected: PresetCollection* m_collection {nullptr}; // Caching bitmaps for the all bitmaps, used in preset comboboxes - static BitmapCache& bitmap_cache() { - static BitmapCache bmps; - return bmps; - } + static BitmapCache& bitmap_cache(); // Indicator, that the preset is compatible with the selected printer. ScalableBitmap m_bitmapCompatible; From 6d28d68e4a87e3e53baf4d5c84d19a8bf4e56a61 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 21 Jul 2020 16:21:18 +0200 Subject: [PATCH 15/31] PhysicalPrinter : Implemented synchronizations from user printer profiles with "Print Host upload" information to the new physical printers --- src/libslic3r/Preset.cpp | 102 ++++++++++++++++++++++------ src/libslic3r/Preset.hpp | 11 ++- src/libslic3r/PresetBundle.cpp | 4 +- src/slic3r/GUI/GUI_App.cpp | 44 ++++++++++++ src/slic3r/GUI/GUI_App.hpp | 1 + src/slic3r/GUI/PresetComboBoxes.cpp | 5 +- 6 files changed, 138 insertions(+), 29 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 401de0fc3..ae74bffd7 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1370,6 +1370,37 @@ const std::vector& PhysicalPrinter::printer_options() return s_opts; } +const std::vector& PhysicalPrinter::print_host_options() +{ + static std::vector s_opts; + if (s_opts.empty()) { + s_opts = { + "print_host", + "printhost_apikey", + "printhost_cafile" + }; + } + return s_opts; +} + +bool PhysicalPrinter::has_print_host_information(const PrinterPresetCollection& printer_presets) +{ + for (const Preset& preset : printer_presets) + if (has_print_host_information(preset.config)) + return true; + + return false; +} + +bool PhysicalPrinter::has_print_host_information(const DynamicPrintConfig& config) +{ + for (const std::string& opt : print_host_options()) + if (!config.opt_string(opt).empty()) + return true; + + return false; +} + const std::set& PhysicalPrinter::get_preset_names() const { return preset_names; @@ -1532,42 +1563,69 @@ void PhysicalPrinterCollection::load_printers(const std::string& dir_path, const // if there is saved user presets, contains information about "Print Host upload", // Create default printers with this presets -// Throws an exception on error. -void PhysicalPrinterCollection::load_printers(const PrinterPresetCollection& printer_presets, std::string def_printer_name/* = ""*/) +// Note! "Print Host upload" options will be cleared after physical printer creations +void PhysicalPrinterCollection::load_printers_from_presets(PrinterPresetCollection& printer_presets, std::string def_printer_name) { - if (def_printer_name.empty()) - def_printer_name = "Printer"; - int cnt=0; - std::string errors_cummulative; - // Store the loaded printers into a new vector - std::deque printers_loaded; - for (const Preset& preset: printer_presets) { - const DynamicPrintConfig& config = preset.config; - if (!config.opt_string("print_host").empty() || - !config.opt_string("printhost_apikey").empty() || - !config.opt_string("printhost_cafile").empty() ) { - PhysicalPrinter printer((boost::format("%1% %2%") % def_printer_name % ++cnt ).str(), preset); - printer.loaded = true; - printers_loaded.emplace_back(printer); + for (Preset& preset: printer_presets) { + DynamicPrintConfig& config = preset.config; + const std::vector& options = PhysicalPrinter::print_host_options(); - save_printer(printer); + for(const std::string& option : options) { + if (!config.opt_string(option).empty()) { + // check if printer with those "Print Host upload" options already exist + PhysicalPrinter* existed_printer = find_printer_with_same_config(config); + if (existed_printer) + // just add preset for this printer + existed_printer->add_preset(preset.name); + else { + // create new printer from this preset + PhysicalPrinter printer((boost::format("%1% %2%") % def_printer_name % ++cnt ).str(), preset); + printer.loaded = true; + save_printer(printer); + } + + // erase "Print Host upload" information from the preset + for (const std::string& opt : options) + config.opt_string(opt).clear(); + // save changes for preset + preset.save(); + + // update those changes for edited preset if it's equal to the preset + Preset& edited = printer_presets.get_edited_preset(); + if (preset.name == edited.name) { + for (const std::string& opt : options) + edited.config.opt_string(opt).clear(); + } + + break; + } } } - - if (!errors_cummulative.empty()) - throw std::runtime_error(errors_cummulative); } PhysicalPrinter* PhysicalPrinterCollection::find_printer( const std::string& name, bool first_visible_if_not_found) { - PhysicalPrinter key(name); auto it = this->find_printer_internal(name); // Ensure that a temporary copy is returned if the preset found is currently selected. - return (it != m_printers.end() && it->name == key.name) ? &this->printer(it - m_printers.begin()) : + return (it != m_printers.end() && it->name == name) ? &this->printer(it - m_printers.begin()) : first_visible_if_not_found ? &this->printer(0) : nullptr; } +PhysicalPrinter* PhysicalPrinterCollection::find_printer_with_same_config(const DynamicPrintConfig& config) +{ + for (const PhysicalPrinter& printer :*this) { + bool is_equal = true; + for (const std::string& opt : PhysicalPrinter::print_host_options()) + if (is_equal && printer.config.opt_string(opt) != config.opt_string(opt)) + is_equal = false; + + if (is_equal) + return find_printer(printer.name); + } + return nullptr; +} + // Generate a file path from a profile name. Add the ".ini" suffix if it is missing. std::string PhysicalPrinterCollection::path_from_name(const std::string& new_name) const { diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index 02f831136..98b805b4e 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -549,12 +549,15 @@ public: // set of presets used with this physical printer std::set preset_names; - static std::string separator(); - // Has this profile been loaded? bool loaded = false; + static std::string separator(); static const std::vector& printer_options(); + static const std::vector& print_host_options(); + static bool has_print_host_information(const PrinterPresetCollection& printer_presets); + static bool has_print_host_information(const DynamicPrintConfig& config); + const std::set& get_preset_names() const; bool has_empty_config() const; @@ -626,7 +629,7 @@ public: // Load ini files of the particular type from the provided directory path. void load_printers(const std::string& dir_path, const std::string& subdir); - void load_printers(const PrinterPresetCollection &printer_presets, std::string def_printer_name = ""); + void load_printers_from_presets(PrinterPresetCollection &printer_presets, std::string def_printer_name); // Save the printer under a new name. If the name is different from the old one, // a new printer is stored into the list of printers. @@ -704,6 +707,8 @@ private: return const_cast(this)->find_printer_internal(name); } + PhysicalPrinter* find_printer_with_same_config( const DynamicPrintConfig &config); + // List of printers // Use deque to force the container to allocate an object per each entry, // so that the addresses of the presets don't change during resizing of the container. diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 0e215a2ae..d074c77d7 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -201,7 +201,6 @@ void PresetBundle::load_presets(AppConfig &config, const std::string &preferred_ } try { this->physical_printers.load_printers(dir_user_presets, "physical_printer"); - this->physical_printers.load_printers(this->printers); } catch (const std::runtime_error &err) { errors_cummulative += err.what(); } @@ -436,8 +435,7 @@ void PresetBundle::load_selections(AppConfig &config, const std::string &preferr std::string initial_physical_printer_name = remove_ini_suffix(config.get("extras", "physical_printer")); // Activate physical printer from the config - const PhysicalPrinter* initial_physical_printer = physical_printers.find_printer(initial_physical_printer_name); - if (initial_physical_printer) + if (!initial_physical_printer_name.empty()) physical_printers.select_printer_by_name(initial_physical_printer_name); } diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 089a38c6f..f7689c6e9 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -28,6 +28,9 @@ #include #include +#include +#include + #include "libslic3r/Utils.hpp" #include "libslic3r/Model.hpp" #include "libslic3r/I18N.hpp" @@ -629,6 +632,43 @@ void GUI_App::set_auto_toolbar_icon_scale(float scale) const app_config->set("auto_toolbar_size", val); } +// check user printer_presets for the containing information about "Print Host upload" +void GUI_App::check_printer_presets() +{ + if (!PhysicalPrinter::has_print_host_information(preset_bundle->printers)) + return; + + wxString msg_text = _L("You have presets with saved options for \"Print Host upload\".\n" + "But from this version of PrusaSlicer we don't show/use this information in Printer Settings.\n" + "Now, this information will be exposed in physical printers settings.") + "\n\n" + + _L("Enter the name for the Printer device used by defaul during its creation.\n" + "Note: This name can be changed later from the physical printers settings") + ":"; + wxString msg_header = _L("Name for printer device"); + + // get custom gcode + wxTextEntryDialog dlg(nullptr, msg_text, msg_header, _L("Printer"), wxTextEntryDialogStyle); + + // detect TextCtrl and OK button + wxTextCtrl* textctrl{ nullptr }; + wxWindowList& dlg_items = dlg.GetChildren(); + for (auto item : dlg_items) { + textctrl = dynamic_cast(item); + if (textctrl) + break; + } + + if (textctrl) { + textctrl->SetSelection(0, textctrl->GetLastPosition()); + + wxButton* btn_OK = static_cast(dlg.FindWindowById(wxID_OK)); + btn_OK->Bind(wxEVT_UPDATE_UI, [textctrl](wxUpdateUIEvent& evt) { + evt.Enable(!textctrl->IsEmpty()); + }, btn_OK->GetId()); + } + if (dlg.ShowModal() == wxID_OK) + preset_bundle->physical_printers.load_printers_from_presets(preset_bundle->printers, into_u8(dlg.GetValue())); +} + void GUI_App::recreate_GUI(const wxString& msg_name) { mainframe->shutdown(); @@ -1171,6 +1211,10 @@ bool GUI_App::checked_tab(Tab* tab) // Update UI / Tabs to reflect changes in the currently loaded presets void GUI_App::load_current_presets() { + // check printer_presets for the containing information about "Print Host upload" + // and create physical printer from it, if any exists + check_printer_presets(); + PrinterTechnology printer_technology = preset_bundle->printers.get_edited_preset().printer_technology(); this->plater()->set_printer_technology(printer_technology); for (Tab *tab : tabs_list) diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 23567695c..db551610b 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -150,6 +150,7 @@ public: wxSize get_min_size() const; float toolbar_icon_scale(const bool is_limited = false) const; void set_auto_toolbar_icon_scale(float scale) const; + void check_printer_presets(); void recreate_GUI(const wxString& message); void system_info(); diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 2d74344bd..e527ef9c9 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -359,8 +359,11 @@ bool PresetComboBox::selection_is_changed_according_to_physical_printers() // if new preset wasn't selected, there is no need to call update preset selection if (old_printer_preset == preset_name) { // we need just to update according Plater<->Tab PresetComboBox - if (dynamic_cast(this)!=nullptr) + if (dynamic_cast(this)!=nullptr) { wxGetApp().get_tab(m_type)->update_preset_choice(); + // Synchronize config.ini with the current selections. + m_preset_bundle->export_selections(*wxGetApp().app_config); + } else if (dynamic_cast(this)!=nullptr) wxGetApp().sidebar().update_presets(m_type); From f7119c42f46b76aea67d914f48be663e4ab0a742 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 22 Jul 2020 13:23:44 +0200 Subject: [PATCH 16/31] PresetComboBox class:: code refactoring --- src/slic3r/GUI/PresetComboBoxes.cpp | 165 ++++++++++------------------ src/slic3r/GUI/PresetComboBoxes.hpp | 4 + 2 files changed, 65 insertions(+), 104 deletions(-) diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index e527ef9c9..4cf9ac40b 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -142,11 +142,36 @@ void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type) this->SetClientData(item, (void*)label_item_type); } +void PresetComboBox::invalidate_selection() +{ + m_last_selected = INT_MAX; // this value means that no one item is selected +} + +void PresetComboBox::validate_selection(bool predicate/*=false*/) +{ + if (predicate || + // just in case: mark m_last_selected as a first added element + m_last_selected == INT_MAX) + m_last_selected = GetCount() - 1; +} + +void PresetComboBox::update_selection() +{ + /* If selected_preset_item is still equal to INT_MAX, it means that + * there is no presets added to the list. + * So, select last combobox item ("Add/Remove preset") + */ + validate_selection(); + + SetSelection(m_last_selected); + SetToolTip(GetString(m_last_selected)); +} + void PresetComboBox::update(const std::string& select_preset_name) { Freeze(); Clear(); - size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected + invalidate_selection(); const std::deque& presets = m_collection->get_presets(); @@ -164,18 +189,13 @@ void PresetComboBox::update(const std::string& select_preset_name) // marker used for disable incompatible printer models for the selected physical printer bool is_enabled = true; - std::string bitmap_key = "tab"; - std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; - + std::string bitmap_key = "cb"; 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"; + std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "lock_closed", is_enabled, preset.is_compatible, preset.is_system || preset.is_default); assert(bmp); @@ -184,10 +204,7 @@ void PresetComboBox::update(const std::string& select_preset_name) int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp); if (!is_enabled) set_label_marker(item_id, LABEL_ITEM_DISABLED); - if (preset.name == select_preset_name ||//i == idx_selected || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX) - selected_preset_item = GetCount() - 1; + validate_selection(preset.name == select_preset_name); } else { @@ -207,25 +224,12 @@ void PresetComboBox::update(const std::string& select_preset_name) 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) - selected_preset_item = GetCount() - 1; + validate_selection(it->first == selected); } } - /* But, if selected_preset_item is still equal to INT_MAX, it means that - * there is no presets added to the list. - * So, select last combobox item ("Add/Remove preset") - */ - if (selected_preset_item == INT_MAX) - selected_preset_item = GetCount() - 1; - - SetSelection(selected_preset_item); - SetToolTip(GetString(selected_preset_item)); + update_selection(); Thaw(); - - m_last_selected = selected_preset_item; } void PresetComboBox::msw_rescale() @@ -272,6 +276,12 @@ wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, bool wide_icons, con bool is_compatible/* = true*/, bool is_system/* = false*/, bool is_single_bar/* = false*/, std::string filament_rgb/* = ""*/, std::string extruder_rgb/* = ""*/) { + // 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 += is_compatible ? ",cmpt" : ",ncmpt"; + + bitmap_key += is_system ? ",syst" : ",nsyst"; bitmap_key += ",h" + std::to_string(icon_height); wxBitmap* bmp = bitmap_cache().find(bitmap_key); @@ -313,6 +323,9 @@ wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, bool wide_icons, con wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, const std::string& main_icon_name, const std::string& next_icon_name, bool is_enabled/* = true*/, bool is_compatible/* = true*/, bool is_system/* = false*/) { + bitmap_key += !is_enabled ? "_disabled" : ""; + bitmap_key += is_compatible ? ",cmpt" : ",ncmpt"; + bitmap_key += is_system ? ",syst" : ",nsyst"; bitmap_key += ",h" + std::to_string(icon_height); wxBitmap* bmp = bitmap_cache().find(bitmap_key); @@ -645,7 +658,7 @@ void PlaterPresetComboBox::update() // Otherwise fill in the list from scratch. this->Freeze(); this->Clear(); - size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected + invalidate_selection(); const Preset* selected_filament_preset; std::string extruder_color; @@ -700,12 +713,6 @@ void PlaterPresetComboBox::update() bitmap_key += single_bar ? filament_rgb : filament_rgb + extruder_rgb; } - // 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 += preset.is_compatible ? ",cmpt" : ",ncmpt"; - bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst"; - wxBitmap* bmp = get_bmp(bitmap_key, wide_icons, bitmap_type_name, preset.is_compatible, preset.is_system || preset.is_default, single_bar, filament_rgb, extruder_rgb); @@ -714,12 +721,9 @@ void PlaterPresetComboBox::update() const std::string name = preset.alias.empty() ? preset.name : preset.alias; if (preset.is_default || preset.is_system) { Append(wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp); - if (is_selected || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX) { - selected_preset_item = GetCount() - 1; + validate_selection(is_selected); + if (is_selected) tooltip = wxString::FromUTF8(preset.name.c_str()); - } } else { @@ -737,10 +741,7 @@ void PlaterPresetComboBox::update() 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); - if (it->first == selected || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX) - selected_preset_item = GetCount() - 1; + validate_selection(it->first == selected); } } @@ -757,32 +758,18 @@ void PlaterPresetComboBox::update() if (!preset) continue; std::string main_icon_name, bitmap_key = main_icon_name = preset->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; - if (wide_icons) - bitmap_key += ",cmpt"; - bitmap_key += ",nsyst"; - - wxBitmap* bmp = get_bmp(bitmap_key, wide_icons, main_icon_name); + wxBitmap* bmp = get_bmp(main_icon_name, wide_icons, main_icon_name); assert(bmp); set_label_marker(Append(wxString::FromUTF8((it->get_full_name(preset_name) + (preset->is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp), LABEL_ITEM_PHYSICAL_PRINTER); - if (ph_printers.is_selected(it, preset_name) || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX) - selected_preset_item = GetCount() - 1; + validate_selection(ph_printers.is_selected(it, preset_name)); } } } } 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"; - - wxBitmap* bmp = get_bmp(bitmap_key, wide_icons, "edit_uni"); + wxBitmap* bmp = get_bmp("edit_preset_list", wide_icons, "edit_uni"); assert(bmp); if (m_type == Preset::TYPE_SLA_MATERIAL) @@ -791,18 +778,12 @@ void PlaterPresetComboBox::update() 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 - * there is no presets added to the list. - * So, select last combobox item ("Add/Remove preset") - */ - if (selected_preset_item == INT_MAX) - selected_preset_item = GetCount() - 1; - - SetSelection(selected_preset_item); - SetToolTip(tooltip.IsEmpty() ? GetString(selected_preset_item) : tooltip); - m_last_selected = selected_preset_item; + update_selection(); Thaw(); + if (!tooltip.IsEmpty()) + SetToolTip(tooltip); + // Update control min size after rescale (changed Display DPI under MSW) if (GetMinWidth() != 20 * m_em_unit) SetMinSize(wxSize(20 * m_em_unit, GetSize().GetHeight())); @@ -858,7 +839,7 @@ void TabPresetComboBox::update() { Freeze(); Clear(); - size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected + invalidate_selection(); const std::deque& presets = m_collection->get_presets(); @@ -890,18 +871,13 @@ void TabPresetComboBox::update() if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) is_enabled = m_enable_all ? true : preset.printer_technology() == proper_pt; - std::string bitmap_key = "tab"; - std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; - + std::string bitmap_key = "tab"; 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"; + std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "lock_closed", is_enabled, preset.is_compatible, preset.is_system || preset.is_default); assert(bmp); @@ -910,10 +886,7 @@ void TabPresetComboBox::update() int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *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) - selected_preset_item = GetCount() - 1; + validate_selection(i == idx_selected); } else { @@ -933,10 +906,7 @@ void TabPresetComboBox::update() 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) - selected_preset_item = GetCount() - 1; + validate_selection(it->first == selected); } } @@ -953,39 +923,26 @@ void TabPresetComboBox::update() if (!preset) continue; std::string main_icon_name = preset->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name; - std::string bitmap_key = main_icon_name + ",nsyst"; - wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "", true, true, false); + wxBitmap* bmp = get_bmp(main_icon_name, main_icon_name, "", true, true, false); assert(bmp); set_label_marker(Append(wxString::FromUTF8((it->get_full_name(preset_name) + (preset->is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp), LABEL_ITEM_PHYSICAL_PRINTER); - if (ph_printers.is_selected(it, preset_name) || - // just in case: mark selected_preset_item as a first added element - selected_preset_item == INT_MAX) - selected_preset_item = GetCount() - 1; + validate_selection(ph_printers.is_selected(it, preset_name)); } } } // add "Add/Remove printers" item - wxBitmap* bmp = get_bmp("edit_preset_list", m_main_bitmap_name, "edit_uni", true, true, true); + std::string icon_name = "edit_uni"; + wxBitmap* bmp = get_bmp("edit_preset_list, tab,", icon_name, ""); assert(bmp); 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 - * there is no presets added to the list. - * So, select last combobox item ("Add/Remove preset") - */ - if (selected_preset_item == INT_MAX) - selected_preset_item = GetCount() - 1; - - SetSelection(selected_preset_item); - SetToolTip(GetString(selected_preset_item)); + update_selection(); Thaw(); - - m_last_selected = selected_preset_item; } void TabPresetComboBox::msw_rescale() diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 89d043f7b..9a70818e1 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -91,6 +91,10 @@ protected: int thin_space_icon_width; int wide_space_icon_width; + void invalidate_selection(); + void validate_selection(bool predicate = false); + void update_selection(); + #ifdef __linux__ static const char* separator_head() { return "------- "; } static const char* separator_tail() { return " -------"; } From 299b783601c0584992aafb00689718c1ab51627e Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 22 Jul 2020 16:28:34 +0200 Subject: [PATCH 17/31] PhysicalPrinterDialog: Select first related preset for the printer, if printer was just created or previously selected preset doesn't exist now --- src/slic3r/GUI/PresetComboBoxes.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 4cf9ac40b..2c2b1d7a3 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -1479,10 +1479,12 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) // save new physical printer printers.save_printer(m_printer, renamed_from); - printers.select_printer(m_printer); - - // refresh preset list on Printer Settings Tab - wxGetApp().get_tab(Preset::TYPE_PRINTER)->update_preset_choice(); + if (m_printer.preset_names.find(printers.get_selected_printer_preset_name()) == m_printer.preset_names.end()) { + // select first preset for this printer + printers.select_printer(m_printer); + // refresh preset list on Printer Settings Tab + wxGetApp().get_tab(Preset::TYPE_PRINTER)->select_preset(printers.get_selected_printer_preset_name()); + } event.Skip(); } From a4c12b90f19786c00efb909819718f4801c47170 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 23 Jul 2020 12:17:18 +0200 Subject: [PATCH 18/31] PhysicalPrinterCollection: Use select_preset() instead of select_preset_by_name() + changed signature for select_preset() --- src/libslic3r/Preset.cpp | 31 +++++++++++------------------ src/libslic3r/Preset.hpp | 14 ++++++------- src/libslic3r/PresetBundle.cpp | 2 +- src/slic3r/GUI/PresetComboBoxes.cpp | 4 ++-- src/slic3r/GUI/Tab.cpp | 2 +- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index ae74bffd7..7e30831fe 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1731,34 +1731,27 @@ std::string PhysicalPrinterCollection::get_selected_full_printer_name() const return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_full_name(m_selected_preset); } -PhysicalPrinter& PhysicalPrinterCollection::select_printer_by_name(const std::string& full_name) +void PhysicalPrinterCollection::select_printer(const std::string& full_name) { std::string printer_name = PhysicalPrinter::get_short_name(full_name); auto it = this->find_printer_internal(printer_name); - assert(it != m_printers.end()); + if (it == m_printers.end()) { + unselect_printer(); + return; + } // update idx_selected - m_idx_selected = it - m_printers.begin(); + m_idx_selected = it - m_printers.begin(); + // update name of the currently selected preset - m_selected_preset = it->get_preset_name(full_name); - if (m_selected_preset.empty()) + if (printer_name == full_name) + // use first preset in the list m_selected_preset = *it->preset_names.begin(); - return *it; + else + m_selected_preset = it->get_preset_name(full_name); } -PhysicalPrinter& PhysicalPrinterCollection::select_printer(const std::string& printer_name) -{ - auto it = this->find_printer_internal(printer_name); - assert(it != m_printers.end()); - - // update idx_selected - m_idx_selected = it - m_printers.begin(); - // update name of the currently selected preset - m_selected_preset = *it->preset_names.begin(); - return *it; -} - -PhysicalPrinter& PhysicalPrinterCollection::select_printer(const PhysicalPrinter& printer) +void PhysicalPrinterCollection::select_printer(const PhysicalPrinter& printer) { return select_printer(printer.name); } diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index 98b805b4e..6b5a2a511 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -666,13 +666,13 @@ public: // 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() : m_selected_preset; } - // select printer with name and return reference on it - PhysicalPrinter& select_printer_by_name(const std::string& full_name); - PhysicalPrinter& select_printer(const std::string &printer_name); - PhysicalPrinter& select_printer(const PhysicalPrinter& printer); - bool has_selection() const; - void unselect_printer() ; - bool is_selected(ConstIterator it, const std::string &preset_name) const; + // Select printer by the full printer name, which contains name of printer, separator and name of selected preset + // If full_name doesn't contain name of selected preset, then select first preset in the list for this printer + void select_printer(const std::string& full_name); + void select_printer(const PhysicalPrinter& printer); + bool has_selection() const; + void unselect_printer() ; + bool is_selected(ConstIterator it, const std::string &preset_name) const; // Return a printer by an index. If the printer is active, a temporary copy is returned. PhysicalPrinter& printer(size_t idx) { return m_printers[idx]; } diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index d074c77d7..108985704 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -436,7 +436,7 @@ void PresetBundle::load_selections(AppConfig &config, const std::string &preferr // Activate physical printer from the config if (!initial_physical_printer_name.empty()) - physical_printers.select_printer_by_name(initial_physical_printer_name); + physical_printers.select_printer(initial_physical_printer_name); } // Export selections (current print, current filaments, current printer) into config.ini diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 2c2b1d7a3..f6a2a036b 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -366,7 +366,7 @@ bool PresetComboBox::selection_is_changed_according_to_physical_printers() else old_printer_preset = m_collection->get_edited_preset().name; // Select related printer preset on the Printer Settings Tab - physical_printers.select_printer_by_name(selected_string); + physical_printers.select_printer(selected_string); std::string preset_name = physical_printers.get_selected_printer_preset_name(); // if new preset wasn't selected, there is no need to call update preset selection @@ -1031,7 +1031,7 @@ void TabPresetComboBox::update_physical_printers( const std::string& preset_name dialog.ShowModal(); } - physical_printers.select_printer_by_name(printer.get_full_name(preset_name)); + physical_printers.select_printer(printer.get_full_name(preset_name)); } } else diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index e498f56b7..dd63dc141 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3100,7 +3100,7 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, if (!last_selected_ph_printer_name.empty() && m_presets->get_edited_preset().name == PhysicalPrinter::get_preset_name(last_selected_ph_printer_name)) { // If preset selection was canceled and previously was selected physical printer, we should select it back - m_preset_bundle->physical_printers.select_printer_by_name(last_selected_ph_printer_name); + m_preset_bundle->physical_printers.select_printer(last_selected_ph_printer_name); } } From 257e77ed407a13cd43eb9f233ee40d53d29c701e Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 23 Jul 2020 12:44:08 +0200 Subject: [PATCH 19/31] Fixed a typo --- src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/GUI/Tab.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index f7689c6e9..1b7278bd7 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -641,7 +641,7 @@ void GUI_App::check_printer_presets() wxString msg_text = _L("You have presets with saved options for \"Print Host upload\".\n" "But from this version of PrusaSlicer we don't show/use this information in Printer Settings.\n" "Now, this information will be exposed in physical printers settings.") + "\n\n" + - _L("Enter the name for the Printer device used by defaul during its creation.\n" + _L("Enter the name for the Printer device used by default during its creation.\n" "Note: This name can be changed later from the physical printers settings") + ":"; wxString msg_header = _L("Name for printer device"); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index dd63dc141..3f566eacb 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2981,7 +2981,7 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, if (!physical_printers.delete_preset_from_printers(m_presets->get_edited_preset().name)) { wxMessageDialog dialog(nullptr, _L("There is/are a physical printer(s), which has/have one and only this printer preset.\n" - "This/Those printer(s) will be deletede after deleting of the selected preset.\n" + "This/Those printer(s) will be deleted after deleting of the selected preset.\n" "Are you sure you want to delete the selected preset?"), _L("Warning"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION); if (dialog.ShowModal() == wxID_NO) return; From b155c3c4f829f3e77321939ebe356969ee35ce5f Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 24 Jul 2020 16:34:25 +0200 Subject: [PATCH 20/31] PhysicalPrinterDialog :: next improvement --- src/slic3r/CMakeLists.txt | 4 +- src/slic3r/GUI/PhysicalPrinterDialog.cpp | 556 +++++++++++++++++++++++ src/slic3r/GUI/PhysicalPrinterDialog.hpp | 105 +++++ src/slic3r/GUI/PresetComboBoxes.cpp | 539 ++-------------------- src/slic3r/GUI/PresetComboBoxes.hpp | 89 +--- 5 files changed, 702 insertions(+), 591 deletions(-) create mode 100644 src/slic3r/GUI/PhysicalPrinterDialog.cpp create mode 100644 src/slic3r/GUI/PhysicalPrinterDialog.hpp diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 49e069285..20ea4e33a 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -76,9 +76,11 @@ set(SLIC3R_GUI_SOURCES GUI/MainFrame.cpp GUI/MainFrame.hpp GUI/Plater.cpp + GUI/Plater.hpp GUI/PresetComboBoxes.hpp GUI/PresetComboBoxes.cpp - GUI/Plater.hpp + GUI/PhysicalPrinterDialog.hpp + GUI/PhysicalPrinterDialog.cpp GUI/GUI_ObjectList.cpp GUI/GUI_ObjectList.hpp GUI/GUI_ObjectManipulation.cpp diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp new file mode 100644 index 000000000..7d3c92c13 --- /dev/null +++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp @@ -0,0 +1,556 @@ +#include "PhysicalPrinterDialog.hpp" +#include "PresetComboBoxes.hpp" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "libslic3r/libslic3r.h" +#include "libslic3r/PrintConfig.hpp" +#include "libslic3r/PresetBundle.hpp" + +#include "GUI.hpp" +#include "GUI_App.hpp" +#include "MainFrame.hpp" +#include "format.hpp" +#include "Tab.hpp" +#include "wxExtensions.hpp" +#include "PrintHostDialogs.hpp" +#include "../Utils/ASCIIFolding.hpp" +#include "../Utils/PrintHost.hpp" +#include "../Utils/FixModelByWin10.hpp" +#include "../Utils/UndoRedo.hpp" +#include "RemovableDriveManager.hpp" +#include "BitmapCache.hpp" +#include "BonjourDialog.hpp" + +using Slic3r::GUI::format_wxstr; + +//static const std::pair THUMBNAIL_SIZE_3MF = { 256, 256 }; + +namespace Slic3r { +namespace GUI { + +#define BORDER_W 10 + +//------------------------------------------ +// PresetForPrinter +//------------------------------------------ + +PresetForPrinter::PresetForPrinter(PhysicalPrinterDialog* parent, const std::string& preset_name) : + m_parent(parent) +{ + m_sizer = new wxBoxSizer(wxVERTICAL); + + m_delete_preset_btn = new ScalableButton(parent, wxID_ANY, "cross", "", wxDefaultSize, wxDefaultPosition, /*wxBU_LEFT | */wxBU_EXACTFIT); + m_delete_preset_btn->SetFont(wxGetApp().normal_font()); + m_delete_preset_btn->SetToolTip(_L("Delete this preset from this printer device")); + m_delete_preset_btn->Bind(wxEVT_BUTTON, &PresetForPrinter::DeletePreset, this); + + m_presets_list = new PresetComboBox(parent, Preset::TYPE_PRINTER); + m_presets_list->set_printer_technology(parent->get_printer_technology()); + + m_presets_list->set_selection_changed_function([this](int selection) { + std::string selected_string = Preset::remove_suffix_modified(m_presets_list->GetString(selection).ToUTF8().data()); + Preset* preset = wxGetApp().preset_bundle->printers.find_preset(selected_string); + assert(preset); + Preset& edited_preset = wxGetApp().preset_bundle->printers.get_edited_preset(); + if (preset->name == edited_preset.name) + preset = &edited_preset; + + // if created physical printer doesn't have any settings, use the settings from the selected preset + if (m_parent->get_printer()->has_empty_config()) { + // update Print Host upload from the selected preset + m_parent->get_printer()->update_from_preset(*preset); + // update values in parent (PhysicalPrinterDialog) + m_parent->update(); + } + + // update PrinterTechnology if it was changed + if (m_presets_list->set_printer_technology(preset->printer_technology())) + m_parent->set_printer_technology(preset->printer_technology()); + + update_full_printer_name(); + }); + m_presets_list->update(preset_name); + + m_info_line = new wxStaticText(parent, wxID_ANY, _L("This printer will be shown in the presets list as") + ":"); + + m_full_printer_name = new wxStaticText(parent, wxID_ANY, ""); + m_full_printer_name->SetFont(wxGetApp().bold_font()); + + wxBoxSizer* preset_sizer = new wxBoxSizer(wxHORIZONTAL); + preset_sizer->Add(m_presets_list , 1, wxEXPAND); + preset_sizer->Add(m_delete_preset_btn , 0, wxEXPAND | wxLEFT, BORDER_W); + + wxBoxSizer* name_sizer = new wxBoxSizer(wxHORIZONTAL); + name_sizer->Add(m_info_line, 0, wxEXPAND); + name_sizer->Add(m_full_printer_name, 0, wxEXPAND | wxLEFT, BORDER_W); + + m_sizer->Add(preset_sizer , 0, wxEXPAND); + m_sizer->Add(name_sizer, 0, wxEXPAND); +} + +PresetForPrinter::~PresetForPrinter() +{ + m_presets_list->Destroy(); + m_delete_preset_btn->Destroy(); + m_info_line->Destroy(); + m_full_printer_name->Destroy(); +} + +void PresetForPrinter::DeletePreset(wxEvent& event) +{ + m_parent->DeletePreset(this); +} + +void PresetForPrinter::update_full_printer_name() +{ + wxString printer_name = m_parent->get_printer_name(); + wxString preset_name = m_presets_list->GetString(m_presets_list->GetSelection()); + + m_full_printer_name->SetLabelText(printer_name + " * " + preset_name); +} + +std::string PresetForPrinter::get_preset_name() +{ + return into_u8(m_presets_list->GetString(m_presets_list->GetSelection())); +} + +void PresetForPrinter::SuppressDelete() +{ + m_delete_preset_btn->Enable(false); + + // this case means that now we have only one related preset for the printer + // So, allow any selection + m_presets_list->set_printer_technology(ptAny); + m_presets_list->update(); +} + +void PresetForPrinter::AllowDelete() +{ + if (!m_delete_preset_btn->IsEnabled()) + m_delete_preset_btn->Enable(); + + m_presets_list->set_printer_technology(m_parent->get_printer_technology()); + m_presets_list->update(); +} + +void PresetForPrinter::msw_rescale() +{ + m_presets_list->msw_rescale(); + m_delete_preset_btn->msw_rescale(); +} + + +//------------------------------------------ +// PhysicalPrinterDialog +//------------------------------------------ + +PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) + : DPIDialog(NULL, wxID_ANY, _L("Physical Printer"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) +{ + SetFont(wxGetApp().normal_font()); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + + m_default_name = _L("My Printer Device"); + + if (printer_name.IsEmpty()) + printer_name = m_default_name; + else { + std::string full_name = into_u8(printer_name); + printer_name = from_u8(PhysicalPrinter::get_short_name(full_name)); + } + + wxStaticText* label_top = new wxStaticText(this, wxID_ANY, _L("Descriptive name for the printer device") + ":"); + + m_add_preset_btn = new ScalableButton(this, wxID_ANY, "add_copies", "", wxDefaultSize, wxDefaultPosition, /*wxBU_LEFT | */wxBU_EXACTFIT); + m_add_preset_btn->SetFont(wxGetApp().normal_font()); + m_add_preset_btn->SetToolTip(_L("Add preset for this printer device")); + m_add_preset_btn->Bind(wxEVT_BUTTON, &PhysicalPrinterDialog::AddPreset, this); + + m_printer_name = new wxTextCtrl(this, wxID_ANY, printer_name, wxDefaultPosition, wxDefaultSize); + m_printer_name->Bind(wxEVT_TEXT, [this](wxEvent&) { this->update_full_printer_names(); }); + + PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; + PhysicalPrinter* printer = printers.find_printer(into_u8(printer_name)); + if (!printer) { + const Preset& preset = wxGetApp().preset_bundle->printers.get_edited_preset(); + printer = new PhysicalPrinter(into_u8(printer_name), preset); + // if printer_name is empty it means that new printer is created, so enable all items in the preset list + m_presets.emplace_back(new PresetForPrinter(this, preset.name)); + } + else + { + const std::set& preset_names = printer->get_preset_names(); + for (const std::string& preset_name : preset_names) + m_presets.emplace_back(new PresetForPrinter(this, preset_name)); + } + assert(printer); + m_printer = *printer; + + if (m_presets.size() == 1) + m_presets.front()->SuppressDelete(); + + update_full_printer_names(); + + m_config = &m_printer.config; + + m_optgroup = new ConfigOptionsGroup(this, _L("Print Host upload"), m_config); + build_printhost_settings(m_optgroup); + //m_optgroup->reload_config(); + + wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); + wxButton* btnOK = static_cast(this->FindWindowById(wxID_OK, this)); + btnOK->Bind(wxEVT_BUTTON, &PhysicalPrinterDialog::OnOK, this); + + wxBoxSizer* nameSizer = new wxBoxSizer(wxHORIZONTAL); + nameSizer->Add(m_printer_name, 1, wxEXPAND); + nameSizer->Add(m_add_preset_btn, 0, wxEXPAND | wxLEFT, BORDER_W); + + m_presets_sizer = new wxBoxSizer(wxVERTICAL); + for (PresetForPrinter* preset : m_presets) + m_presets_sizer->Add(preset->sizer(), 1, wxEXPAND | wxTOP, BORDER_W); + + wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); + + topSizer->Add(label_top , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); + topSizer->Add(nameSizer , 0, wxEXPAND | wxLEFT | wxRIGHT, BORDER_W); + topSizer->Add(m_presets_sizer , 0, wxEXPAND | wxLEFT | wxRIGHT, BORDER_W); + topSizer->Add(m_optgroup->sizer , 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); + topSizer->Add(btns , 0, wxEXPAND | wxALL, BORDER_W); + + SetSizer(topSizer); + topSizer->SetSizeHints(this); +} + +PhysicalPrinterDialog::~PhysicalPrinterDialog() +{ + for (PresetForPrinter* preset : m_presets) { + delete preset; + preset = nullptr; + } +} + +void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgroup) +{ + m_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { + if (opt_key == "authorization_type") + this->update(); + }; + + m_optgroup->append_single_option_line("host_type"); + + auto create_sizer_with_btn = [this](wxWindow* parent, ScalableButton** btn, const std::string& icon_name, const wxString& label) { + *btn = new ScalableButton(parent, wxID_ANY, icon_name, label, wxDefaultSize, wxDefaultPosition, wxBU_LEFT | wxBU_EXACTFIT); + (*btn)->SetFont(wxGetApp().normal_font()); + + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(*btn); + return sizer; + }; + + auto printhost_browse = [=](wxWindow* parent) + { + auto sizer = create_sizer_with_btn(parent, &m_printhost_browse_btn, "browse", _L("Browse") + " " + dots); + m_printhost_browse_btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent& e) { + BonjourDialog dialog(this, Preset::printer_technology(m_printer.config)); + if (dialog.show_and_lookup()) { + m_optgroup->set_value("print_host", std::move(dialog.get_selected()), true); + m_optgroup->get_field("print_host")->field_changed(); + } + }); + + return sizer; + }; + + auto print_host_test = [=](wxWindow* parent) { + auto sizer = create_sizer_with_btn(parent, &m_printhost_test_btn, "test", _L("Test")); + + m_printhost_test_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) { + std::unique_ptr host(PrintHost::get_print_host(m_config)); + if (!host) { + const wxString text = _L("Could not get a valid Printer Host reference"); + show_error(this, text); + return; + } + wxString msg; + if (host->test(msg)) { + show_info(this, host->get_test_ok_msg(), _L("Success!")); + } + else { + show_error(this, host->get_test_failed_msg(msg)); + } + }); + + return sizer; + }; + + // Set a wider width for a better alignment + Option option = m_optgroup->get_option("print_host"); + option.opt.width = Field::def_width_wider(); + Line host_line = m_optgroup->create_single_option_line(option); + host_line.append_widget(printhost_browse); + host_line.append_widget(print_host_test); + m_optgroup->append_line(host_line); + + m_optgroup->append_single_option_line("authorization_type"); + + option = m_optgroup->get_option("printhost_apikey"); + option.opt.width = Field::def_width_wider(); + m_optgroup->append_single_option_line(option); + + const auto ca_file_hint = _u8L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate."); + + if (Http::ca_file_supported()) { + option = m_optgroup->get_option("printhost_cafile"); + option.opt.width = Field::def_width_wider(); + Line cafile_line = m_optgroup->create_single_option_line(option); + + auto printhost_cafile_browse = [=](wxWindow* parent) { + auto sizer = create_sizer_with_btn(parent, &m_printhost_cafile_browse_btn, "browse", _L("Browse") + " " + dots); + m_printhost_cafile_browse_btn->Bind(wxEVT_BUTTON, [this, m_optgroup](wxCommandEvent e) { + static const auto filemasks = _L("Certificate files (*.crt, *.pem)|*.crt;*.pem|All files|*.*"); + wxFileDialog openFileDialog(this, _L("Open CA certificate file"), "", "", filemasks, wxFD_OPEN | wxFD_FILE_MUST_EXIST); + if (openFileDialog.ShowModal() != wxID_CANCEL) { + m_optgroup->set_value("printhost_cafile", std::move(openFileDialog.GetPath()), true); + m_optgroup->get_field("printhost_cafile")->field_changed(); + } + }); + + return sizer; + }; + + cafile_line.append_widget(printhost_cafile_browse); + m_optgroup->append_line(cafile_line); + + Line cafile_hint{ "", "" }; + cafile_hint.full_width = 1; + cafile_hint.widget = [this, ca_file_hint](wxWindow* parent) { + auto txt = new wxStaticText(parent, wxID_ANY, ca_file_hint); + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(txt); + return sizer; + }; + m_optgroup->append_line(cafile_hint); + } + else { + Line line{ "", "" }; + line.full_width = 1; + + line.widget = [ca_file_hint](wxWindow* parent) { + std::string info = _u8L("HTTPS CA File") + ":\n\t" + + (boost::format(_u8L("On this system, %s uses HTTPS certificates from the system Certificate Store or Keychain.")) % SLIC3R_APP_NAME).str() + + "\n\t" + _u8L("To use a custom CA file, please import your CA file into Certificate Store / Keychain."); + + //auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\n\t%2%") % info % ca_file_hint).str())); + auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\t%2%") % info % ca_file_hint).str())); + txt->SetFont(wxGetApp().normal_font()); + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(txt, 1, wxEXPAND); + return sizer; + }; + + m_optgroup->append_line(line); + } + + for (const std::string& opt_key : std::vector{ "login", "password" }) { + option = m_optgroup->get_option(opt_key); + option.opt.width = Field::def_width_wider(); + m_optgroup->append_single_option_line(option); + } + + update(); +} + +void PhysicalPrinterDialog::update() +{ + m_optgroup->reload_config(); + + const PrinterTechnology tech = Preset::printer_technology(*m_config); + // Only offer the host type selection for FFF, for SLA it's always the SL1 printer (at the moment) + if (tech == ptFFF) { + m_optgroup->show_field("host_type"); + m_optgroup->hide_field("authorization_type"); + for (const std::string& opt_key : std::vector{ "login", "password" }) + m_optgroup->hide_field(opt_key); + } + else { + m_optgroup->set_value("host_type", int(PrintHostType::htOctoPrint), false); + m_optgroup->hide_field("host_type"); + + m_optgroup->show_field("authorization_type"); + + AuthorizationType auth_type = m_config->option>("authorization_type")->value; + m_optgroup->show_field("printhost_apikey", auth_type == AuthorizationType::atKeyPassword); + + for (const std::string& opt_key : std::vector{ "login", "password" }) + m_optgroup->show_field(opt_key, auth_type == AuthorizationType::atUserPassword); + } + + this->Layout(); +} + + +wxString PhysicalPrinterDialog::get_printer_name() +{ + return m_printer_name->GetValue(); +} + +void PhysicalPrinterDialog::update_full_printer_names() +{ + for (PresetForPrinter* preset : m_presets) + preset->update_full_printer_name(); + + this->Layout(); +} + +void PhysicalPrinterDialog::set_printer_technology(PrinterTechnology pt) +{ + m_config->set_key_value("printer_technology", new ConfigOptionEnum(pt)); + update(); +} + +PrinterTechnology PhysicalPrinterDialog::get_printer_technology() +{ + return m_printer.printer_technology(); +} + +void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) +{ + const int& em = em_unit(); + + m_printhost_browse_btn->msw_rescale(); + m_printhost_test_btn->msw_rescale(); + if (m_printhost_cafile_browse_btn) + m_printhost_cafile_browse_btn->msw_rescale(); + + m_optgroup->msw_rescale(); + + msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL }); + + for (PresetForPrinter* preset : m_presets) + preset->msw_rescale(); + + const wxSize& size = wxSize(45 * em, 35 * em); + SetMinSize(size); + + Fit(); + Refresh(); +} + +void PhysicalPrinterDialog::OnOK(wxEvent& event) +{ + wxString printer_name = m_printer_name->GetValue(); + if (printer_name.IsEmpty()) { + warning_catcher(this, _L("The supplied name is empty. It can't be saved.")); + return; + } + if (printer_name == m_default_name) { + warning_catcher(this, _L("You should to change a name of your printer device. It can't be saved.")); + return; + } + + PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; + const PhysicalPrinter* existing = printers.find_printer(into_u8(printer_name)); + if (existing && into_u8(printer_name) != printers.get_selected_printer_name()) + { + wxString msg_text = from_u8((boost::format(_u8L("Printer with name \"%1%\" already exists.")) % printer_name).str()); + msg_text += "\n" + _L("Replace?"); + wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO); + + if (dialog.ShowModal() == wxID_NO) + return; + } + + std::set repeat_presets; + m_printer.reset_presets(); + for (PresetForPrinter* preset : m_presets) { + if (!m_printer.add_preset(preset->get_preset_name())) + repeat_presets.emplace(preset->get_preset_name()); + } + + if (!repeat_presets.empty()) + { + wxString repeatable_presets = "\n"; + for (const std::string& preset_name : repeat_presets) + repeatable_presets += " " + from_u8(preset_name) + "\n"; + repeatable_presets += "\n"; + + wxString msg_text = from_u8((boost::format(_u8L("Next printer preset(s) is(are) duplicated:%1%" + "Should I add it(they) just once for the printer \"%2%\" and close the Editing Dialog?")) % repeatable_presets % printer_name).str()); + wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO); + if (dialog.ShowModal() == wxID_NO) + return; + } + + std::string renamed_from; + // temporary save previous printer name if it was edited + if (m_printer.name != _u8L("My Printer Device") && + m_printer.name != into_u8(printer_name)) + renamed_from = m_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, renamed_from); + + if (m_printer.preset_names.find(printers.get_selected_printer_preset_name()) == m_printer.preset_names.end()) { + // select first preset for this printer + printers.select_printer(m_printer); + // refresh preset list on Printer Settings Tab + wxGetApp().get_tab(Preset::TYPE_PRINTER)->select_preset(printers.get_selected_printer_preset_name()); + } + + event.Skip(); +} + +void PhysicalPrinterDialog::AddPreset(wxEvent& event) +{ + m_presets.emplace_back(new PresetForPrinter(this)); + // enable DELETE button for the first preset, if was disabled + m_presets.front()->AllowDelete(); + + m_presets_sizer->Add(m_presets.back()->sizer(), 1, wxEXPAND | wxTOP, BORDER_W); + update_full_printer_names(); + + this->Fit(); +} + +void PhysicalPrinterDialog::DeletePreset(PresetForPrinter* preset_for_printer) +{ + if (m_presets.size() == 1) { + wxString msg_text = _L("It's not possible to delete last related preset for the printer."); + wxMessageDialog dialog(nullptr, msg_text, _L("Infornation"), wxICON_INFORMATION | wxOK); + dialog.ShowModal(); + return; + } + + assert(preset_for_printer); + auto it = std::find(m_presets.begin(), m_presets.end(), preset_for_printer); + if (it == m_presets.end()) + return; + + const int remove_id = it - m_presets.begin(); + m_presets_sizer->Remove(remove_id); + delete preset_for_printer; + m_presets.erase(it); + + if (m_presets.size() == 1) + m_presets.front()->SuppressDelete(); + + this->Layout(); + this->Fit(); +} + + +}} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.hpp b/src/slic3r/GUI/PhysicalPrinterDialog.hpp new file mode 100644 index 000000000..3d0cf2d9f --- /dev/null +++ b/src/slic3r/GUI/PhysicalPrinterDialog.hpp @@ -0,0 +1,105 @@ +#ifndef slic3r_PhysicalPrinterDialog_hpp_ +#define slic3r_PhysicalPrinterDialog_hpp_ + +#include + +#include + +#include "libslic3r/Preset.hpp" +#include "GUI_Utils.hpp" + +class wxString; +class wxTextCtrl; +class wxStaticText; +class ScalableButton; +class wxBoxSizer; + +namespace Slic3r { + +namespace GUI { + +class PresetComboBox; + +//------------------------------------------ +// PresetForPrinter +//------------------------------------------ +//static std::string g_info_string = " (modified)"; +class PhysicalPrinterDialog; +class PresetForPrinter +{ + PhysicalPrinterDialog* m_parent { nullptr }; + + PresetComboBox* m_presets_list { nullptr }; + ScalableButton* m_delete_preset_btn { nullptr }; + wxStaticText* m_info_line { nullptr }; + wxStaticText* m_full_printer_name { nullptr }; + + wxBoxSizer* m_sizer { nullptr }; + + void DeletePreset(wxEvent& event); + +public: + PresetForPrinter(PhysicalPrinterDialog* parent, const std::string& preset_name = ""); + ~PresetForPrinter(); + + wxBoxSizer* sizer() { return m_sizer; } + void update_full_printer_name(); + std::string get_preset_name(); + void SuppressDelete(); + void AllowDelete(); + + void msw_rescale(); + void on_sys_color_changed() {}; +}; + + +//------------------------------------------ +// PhysicalPrinterDialog +//------------------------------------------ + +class ConfigOptionsGroup; +class PhysicalPrinterDialog : public DPIDialog +{ + PhysicalPrinter m_printer; + wxString m_default_name; + DynamicPrintConfig* m_config { nullptr }; + + wxTextCtrl* m_printer_name { nullptr }; + std::vector m_presets; + + ConfigOptionsGroup* m_optgroup { nullptr }; + + ScalableButton* m_add_preset_btn {nullptr}; + ScalableButton* m_printhost_browse_btn {nullptr}; + ScalableButton* m_printhost_test_btn {nullptr}; + ScalableButton* m_printhost_cafile_browse_btn {nullptr}; + + wxBoxSizer* m_presets_sizer {nullptr}; + + void build_printhost_settings(ConfigOptionsGroup* optgroup); + void OnOK(wxEvent& event); + void AddPreset(wxEvent& event); + +public: + PhysicalPrinterDialog(wxString printer_name); + ~PhysicalPrinterDialog(); + + void update(); + wxString get_printer_name(); + void update_full_printer_names(); + PhysicalPrinter* get_printer() {return &m_printer; } + void set_printer_technology(PrinterTechnology pt); + PrinterTechnology get_printer_technology(); + + void DeletePreset(PresetForPrinter* preset_for_printer); + +protected: + void on_dpi_changed(const wxRect& suggested_rect) override; + void on_sys_color_changed() override {}; +}; + + +} // namespace GUI +} // namespace Slic3r + +#endif diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index f6a2a036b..3edc3947a 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -24,20 +24,15 @@ #include "MainFrame.hpp" #include "format.hpp" #include "Tab.hpp" -#include "PrintHostDialogs.hpp" #include "ConfigWizard.hpp" #include "../Utils/ASCIIFolding.hpp" -#include "../Utils/PrintHost.hpp" #include "../Utils/FixModelByWin10.hpp" #include "../Utils/UndoRedo.hpp" -#include "RemovableDriveManager.hpp" #include "BitmapCache.hpp" -#include "BonjourDialog.hpp" +#include "PhysicalPrinterDialog.hpp" using Slic3r::GUI::format_wxstr; -static const std::pair THUMBNAIL_SIZE_3MF = { 256, 256 }; - namespace Slic3r { namespace GUI { @@ -142,6 +137,15 @@ void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type) this->SetClientData(item, (void*)label_item_type); } +bool PresetComboBox::set_printer_technology(PrinterTechnology pt) +{ + if (printer_technology != pt) { + printer_technology = pt; + return true; + } + return false; +} + void PresetComboBox::invalidate_selection() { m_last_selected = INT_MAX; // this value means that no one item is selected @@ -187,7 +191,7 @@ void PresetComboBox::update(const std::string& select_preset_name) continue; // marker used for disable incompatible printer models for the selected physical printer - bool is_enabled = true; + bool is_enabled = m_type == Preset::TYPE_PRINTER && printer_technology != ptAny ? preset.printer_technology() == printer_technology : true; std::string bitmap_key = "cb"; if (m_type == Preset::TYPE_PRINTER) { @@ -204,13 +208,13 @@ void PresetComboBox::update(const std::string& select_preset_name) int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp); if (!is_enabled) set_label_marker(item_id, LABEL_ITEM_DISABLED); - validate_selection(preset.name == select_preset_name); + validate_selection(preset.name == select_preset_name || (select_preset_name.empty() && is_enabled)); } else { 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 (preset.name == select_preset_name) + if (preset.name == select_preset_name || (select_preset_name.empty() && is_enabled)) selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); } if (i + 1 == m_collection->num_default_presets()) @@ -232,6 +236,11 @@ void PresetComboBox::update(const std::string& select_preset_name) Thaw(); } +void PresetComboBox::update() +{ + this->update(into_u8(this->GetString(this->GetSelection()))); +} + void PresetComboBox::msw_rescale() { m_em_unit = em_unit(this); @@ -547,7 +556,7 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset edit_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent) { // In a case of a physical printer, for its editing open PhysicalPrinterDialog - if (m_type == Preset::TYPE_PRINTER && this->is_selected_physical_printer()) { + if (m_type == Preset::TYPE_PRINTER/* && this->is_selected_physical_printer()*/) { this->show_edit_menu(); return; } @@ -598,7 +607,7 @@ void PlaterPresetComboBox::show_add_menu() { wxMenu* menu = new wxMenu(); - append_menu_item(menu, wxID_ANY, _L("Add/Remove logical printers"), "", + append_menu_item(menu, wxID_ANY, _L("Add/Remove presets"), "", [this](wxCommandEvent&) { wxTheApp->CallAfter([]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); }); }, "edit_uni", menu, []() { return true; }, wxGetApp().plater()); @@ -617,9 +626,10 @@ void PlaterPresetComboBox::show_edit_menu() { wxMenu* menu = new wxMenu(); - append_menu_item(menu, wxID_ANY, _L("Edit related printer profile"), "", + append_menu_item(menu, wxID_ANY, _L("Edit preset"), "", [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())); @@ -642,6 +652,12 @@ void PlaterPresetComboBox::show_edit_menu() wxGetApp().get_tab(m_type)->update_preset_choice(); update(); }, "cross", menu, []() { return true; }, wxGetApp().plater()); + } + else + append_menu_item(menu, wxID_ANY, _L("Add/Remove presets"), "", + [this](wxCommandEvent&) { + wxTheApp->CallAfter([]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); }); + }, "edit_uni", menu, []() { return true; }, wxGetApp().plater()); wxGetApp().plater()->PopupMenu(menu); } @@ -768,7 +784,7 @@ void PlaterPresetComboBox::update() } } - if (m_type == Preset::TYPE_PRINTER || m_type == Preset::TYPE_SLA_MATERIAL) { + if (/*m_type == Preset::TYPE_PRINTER || */m_type == Preset::TYPE_SLA_MATERIAL) { wxBitmap* bmp = get_bmp("edit_preset_list", wide_icons, "edit_uni"); assert(bmp); @@ -867,9 +883,6 @@ void TabPresetComboBox::update() // 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.printer_technology() == proper_pt; std::string bitmap_key = "tab"; if (m_type == Preset::TYPE_PRINTER) { @@ -1040,494 +1053,6 @@ void TabPresetComboBox::update_physical_printers( const std::string& preset_name } -//------------------------------------------ -// PresetForPrinter -//------------------------------------------ - -PresetForPrinter::PresetForPrinter(PhysicalPrinterDialog* parent, const std::string& preset_name) : - m_parent(parent) -{ - m_sizer = new wxBoxSizer(wxVERTICAL); - - m_delete_preset_btn = new ScalableButton(parent, wxID_ANY, "cross", "", wxDefaultSize, wxDefaultPosition, wxBU_LEFT | wxBU_EXACTFIT); - m_delete_preset_btn->SetFont(wxGetApp().normal_font()); - m_delete_preset_btn->SetToolTip(_L("Delete this preset from this printer device")); - m_delete_preset_btn->Bind(wxEVT_BUTTON, &PresetForPrinter::DeletePreset, this); - - m_presets_list = new PresetComboBox(parent, Preset::TYPE_PRINTER); - - m_presets_list->set_selection_changed_function([this](int selection) { - std::string selected_string = Preset::remove_suffix_modified(m_presets_list->GetString(selection).ToUTF8().data()); - Preset* preset = wxGetApp().preset_bundle->printers.find_preset(selected_string); - assert(preset); - Preset& edited_preset = wxGetApp().preset_bundle->printers.get_edited_preset(); - if (preset->name == edited_preset.name) - preset = &edited_preset; - - // if created physical printer doesn't have any settings, use the settings from the selected preset - if (m_parent->get_printer()->has_empty_config()) { - // update Print Host upload from the selected preset - m_parent->get_printer()->update_from_preset(*preset); - // update values in parent (PhysicalPrinterDialog) - m_parent->update(); - } - - update_full_printer_name(); - }); - m_presets_list->update(preset_name); - - m_info_line = new wxStaticText(parent, wxID_ANY, _L("This printer will be shown in the presets list as") + ":"); - - m_full_printer_name = new wxStaticText(parent, wxID_ANY, ""); - m_full_printer_name->SetFont(wxGetApp().bold_font()); - - wxBoxSizer* preset_sizer = new wxBoxSizer(wxHORIZONTAL); - preset_sizer->Add(m_presets_list , 1, wxEXPAND); - preset_sizer->Add(m_delete_preset_btn , 0, wxEXPAND | wxLEFT, BORDER_W); - - wxBoxSizer* name_sizer = new wxBoxSizer(wxHORIZONTAL); - name_sizer->Add(m_info_line, 0, wxEXPAND); - name_sizer->Add(m_full_printer_name, 0, wxEXPAND | wxLEFT, BORDER_W); - - m_sizer->Add(preset_sizer , 0, wxEXPAND); - m_sizer->Add(name_sizer, 0, wxEXPAND); -} - -PresetForPrinter::~PresetForPrinter() -{ - m_presets_list->Destroy(); - m_delete_preset_btn->Destroy(); - m_info_line->Destroy(); - m_full_printer_name->Destroy(); -} - -void PresetForPrinter::DeletePreset(wxEvent& event) -{ - m_parent->DeletePreset(this); -} - -void PresetForPrinter::update_full_printer_name() -{ - wxString printer_name = m_parent->get_printer_name(); - wxString preset_name = m_presets_list->GetString(m_presets_list->GetSelection()); - - m_full_printer_name->SetLabelText(printer_name + " * " + preset_name); -} - -std::string PresetForPrinter::get_preset_name() -{ - return into_u8(m_presets_list->GetString(m_presets_list->GetSelection())); -} - -void PresetForPrinter::DisableDeleteBtn() -{ - m_delete_preset_btn->Enable(false); -} - -void PresetForPrinter::EnableDeleteBtn() -{ - if (!m_delete_preset_btn->IsEnabled()) - m_delete_preset_btn->Enable(); -} - -void PresetForPrinter::msw_rescale() -{ - m_presets_list->msw_rescale(); - m_delete_preset_btn->msw_rescale(); -} - - -//------------------------------------------ -// PhysicalPrinterDialog -//------------------------------------------ - -PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) - : DPIDialog(NULL, wxID_ANY, _L("Physical Printer"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) -{ - SetFont(wxGetApp().normal_font()); - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - - m_default_name = _L("My Printer Device"); - - if (printer_name.IsEmpty()) - printer_name = m_default_name; - else { - std::string full_name = into_u8(printer_name); - printer_name = from_u8(PhysicalPrinter::get_short_name(full_name)); - } - - wxStaticText* label_top = new wxStaticText(this, wxID_ANY, _L("Descriptive name for the printer device") + ":"); - - m_add_preset_btn = new ScalableButton(this, wxID_ANY, "add_copies", "", wxDefaultSize, wxDefaultPosition, wxBU_LEFT | wxBU_EXACTFIT); - m_add_preset_btn->SetFont(wxGetApp().normal_font()); - m_add_preset_btn->SetToolTip(_L("Add preset for this printer device")); - m_add_preset_btn->Bind(wxEVT_BUTTON, &PhysicalPrinterDialog::AddPreset, this); - - m_printer_name = new wxTextCtrl(this, wxID_ANY, printer_name, wxDefaultPosition, wxDefaultSize); - m_printer_name->Bind(wxEVT_TEXT, [this](wxEvent&) { this->update_full_printer_names(); }); - - PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; - PhysicalPrinter* printer = printers.find_printer(into_u8(printer_name)); - if (!printer) { - const Preset& preset = wxGetApp().preset_bundle->printers.get_edited_preset(); - printer = new PhysicalPrinter(into_u8(printer_name), preset); - // if printer_name is empty it means that new printer is created, so enable all items in the preset list - m_presets.emplace_back(new PresetForPrinter(this, preset.name)); - } - else - { - const std::set& preset_names = printer->get_preset_names(); - for (const std::string& preset_name : preset_names) - m_presets.emplace_back(new PresetForPrinter(this, preset_name)); - } - assert(printer); - m_printer = *printer; - - if (m_presets.size() == 1) - m_presets.front()->DisableDeleteBtn(); - - update_full_printer_names(); - - m_config = &m_printer.config; - - m_optgroup = new ConfigOptionsGroup(this, _L("Print Host upload"), m_config); - build_printhost_settings(m_optgroup); - //m_optgroup->reload_config(); - - wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); - wxButton* btnOK = static_cast(this->FindWindowById(wxID_OK, this)); - btnOK->Bind(wxEVT_BUTTON, &PhysicalPrinterDialog::OnOK, this); - - wxBoxSizer* nameSizer = new wxBoxSizer(wxHORIZONTAL); - nameSizer->Add(m_printer_name, 1, wxEXPAND); - nameSizer->Add(m_add_preset_btn, 0, wxEXPAND | wxLEFT, BORDER_W); - - m_presets_sizer = new wxBoxSizer(wxVERTICAL); - for (PresetForPrinter* preset : m_presets) - m_presets_sizer->Add(preset->sizer(), 1, wxEXPAND | wxTOP, BORDER_W); - - wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); - - topSizer->Add(label_top , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); - topSizer->Add(nameSizer , 0, wxEXPAND | wxLEFT | wxRIGHT, BORDER_W); - topSizer->Add(m_presets_sizer , 0, wxEXPAND | wxLEFT | wxRIGHT, BORDER_W); - topSizer->Add(m_optgroup->sizer , 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); - topSizer->Add(btns , 0, wxEXPAND | wxALL, BORDER_W); - - SetSizer(topSizer); - topSizer->SetSizeHints(this); -} - -PhysicalPrinterDialog::~PhysicalPrinterDialog() -{ - for (PresetForPrinter* preset : m_presets) { - delete preset; - preset = nullptr; - } -} - -void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgroup) -{ - m_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { - if (opt_key == "authorization_type") - this->update(); - }; - - m_optgroup->append_single_option_line("host_type"); - - auto create_sizer_with_btn = [this](wxWindow* parent, ScalableButton** btn, const std::string& icon_name, const wxString& label) { - *btn = new ScalableButton(parent, wxID_ANY, icon_name, label, wxDefaultSize, wxDefaultPosition, wxBU_LEFT | wxBU_EXACTFIT); - (*btn)->SetFont(wxGetApp().normal_font()); - - auto sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(*btn); - return sizer; - }; - - auto printhost_browse = [=](wxWindow* parent) - { - auto sizer = create_sizer_with_btn(parent, &m_printhost_browse_btn, "browse", _L("Browse") + " " + dots); - m_printhost_browse_btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent& e) { - BonjourDialog dialog(this, Preset::printer_technology(m_printer.config)); - if (dialog.show_and_lookup()) { - m_optgroup->set_value("print_host", std::move(dialog.get_selected()), true); - m_optgroup->get_field("print_host")->field_changed(); - } - }); - - return sizer; - }; - - auto print_host_test = [=](wxWindow* parent) { - auto sizer = create_sizer_with_btn(parent, &m_printhost_test_btn, "test", _L("Test")); - - m_printhost_test_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& e) { - std::unique_ptr host(PrintHost::get_print_host(m_config)); - if (!host) { - const wxString text = _L("Could not get a valid Printer Host reference"); - show_error(this, text); - return; - } - wxString msg; - if (host->test(msg)) { - show_info(this, host->get_test_ok_msg(), _L("Success!")); - } - else { - show_error(this, host->get_test_failed_msg(msg)); - } - }); - - return sizer; - }; - - // Set a wider width for a better alignment - Option option = m_optgroup->get_option("print_host"); - option.opt.width = Field::def_width_wider(); - Line host_line = m_optgroup->create_single_option_line(option); - host_line.append_widget(printhost_browse); - host_line.append_widget(print_host_test); - m_optgroup->append_line(host_line); - - m_optgroup->append_single_option_line("authorization_type"); - - option = m_optgroup->get_option("printhost_apikey"); - option.opt.width = Field::def_width_wider(); - m_optgroup->append_single_option_line(option); - - const auto ca_file_hint = _u8L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate."); - - if (Http::ca_file_supported()) { - option = m_optgroup->get_option("printhost_cafile"); - option.opt.width = Field::def_width_wider(); - Line cafile_line = m_optgroup->create_single_option_line(option); - - auto printhost_cafile_browse = [=](wxWindow* parent) { - auto sizer = create_sizer_with_btn(parent, &m_printhost_cafile_browse_btn, "browse", _L("Browse") + " " + dots); - m_printhost_cafile_browse_btn->Bind(wxEVT_BUTTON, [this, m_optgroup](wxCommandEvent e) { - static const auto filemasks = _L("Certificate files (*.crt, *.pem)|*.crt;*.pem|All files|*.*"); - wxFileDialog openFileDialog(this, _L("Open CA certificate file"), "", "", filemasks, wxFD_OPEN | wxFD_FILE_MUST_EXIST); - if (openFileDialog.ShowModal() != wxID_CANCEL) { - m_optgroup->set_value("printhost_cafile", std::move(openFileDialog.GetPath()), true); - m_optgroup->get_field("printhost_cafile")->field_changed(); - } - }); - - return sizer; - }; - - cafile_line.append_widget(printhost_cafile_browse); - m_optgroup->append_line(cafile_line); - - Line cafile_hint{ "", "" }; - cafile_hint.full_width = 1; - cafile_hint.widget = [this, ca_file_hint](wxWindow* parent) { - auto txt = new wxStaticText(parent, wxID_ANY, ca_file_hint); - auto sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(txt); - return sizer; - }; - m_optgroup->append_line(cafile_hint); - } - else { - Line line{ "", "" }; - line.full_width = 1; - - line.widget = [ca_file_hint](wxWindow* parent) { - std::string info = _u8L("HTTPS CA File") + ":\n\t" + - (boost::format(_u8L("On this system, %s uses HTTPS certificates from the system Certificate Store or Keychain.")) % SLIC3R_APP_NAME).str() + - "\n\t" + _u8L("To use a custom CA file, please import your CA file into Certificate Store / Keychain."); - - //auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\n\t%2%") % info % ca_file_hint).str())); - auto txt = new wxStaticText(parent, wxID_ANY, from_u8((boost::format("%1%\n\t%2%") % info % ca_file_hint).str())); - txt->SetFont(wxGetApp().normal_font()); - auto sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(txt, 1, wxEXPAND); - return sizer; - }; - - m_optgroup->append_line(line); - } - - for (const std::string& opt_key : std::vector{ "login", "password" }) { - option = m_optgroup->get_option(opt_key); - option.opt.width = Field::def_width_wider(); - m_optgroup->append_single_option_line(option); - } - - update(); -} - -void PhysicalPrinterDialog::update() -{ - m_optgroup->reload_config(); - - const PrinterTechnology tech = Preset::printer_technology(m_printer.config); - // Only offer the host type selection for FFF, for SLA it's always the SL1 printer (at the moment) - if (tech == ptFFF) { - m_optgroup->show_field("host_type"); - m_optgroup->hide_field("authorization_type"); - for (const std::string& opt_key : std::vector{ "login", "password" }) - m_optgroup->hide_field(opt_key); - } - else { - m_optgroup->set_value("host_type", int(PrintHostType::htOctoPrint), false); - m_optgroup->hide_field("host_type"); - - m_optgroup->show_field("authorization_type"); - - AuthorizationType auth_type = m_config->option>("authorization_type")->value; - m_optgroup->show_field("printhost_apikey", auth_type == AuthorizationType::atKeyPassword); - - for (const std::string& opt_key : std::vector{ "login", "password" }) - m_optgroup->show_field(opt_key, auth_type == AuthorizationType::atUserPassword); - } - - this->Layout(); -} - - -wxString PhysicalPrinterDialog::get_printer_name() -{ - return m_printer_name->GetValue(); -} - -void PhysicalPrinterDialog::update_full_printer_names() -{ - for (PresetForPrinter* preset : m_presets) - preset->update_full_printer_name(); - - this->Layout(); -} - -void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) -{ - const int& em = em_unit(); - - m_printhost_browse_btn->msw_rescale(); - m_printhost_test_btn->msw_rescale(); - if (m_printhost_cafile_browse_btn) - m_printhost_cafile_browse_btn->msw_rescale(); - - m_optgroup->msw_rescale(); - - msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL }); - - for (PresetForPrinter* preset : m_presets) - preset->msw_rescale(); - - const wxSize& size = wxSize(45 * em, 35 * em); - SetMinSize(size); - - Fit(); - Refresh(); -} - -void PhysicalPrinterDialog::OnOK(wxEvent& event) -{ - wxString printer_name = m_printer_name->GetValue(); - if (printer_name.IsEmpty()) { - warning_catcher(this, _L("The supplied name is empty. It can't be saved.")); - return; - } - if (printer_name == m_default_name) { - warning_catcher(this, _L("You should to change a name of your printer device. It can't be saved.")); - return; - } - - PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; - const PhysicalPrinter* existing = printers.find_printer(into_u8(printer_name)); - if (existing && into_u8(printer_name) != printers.get_selected_printer_name()) - { - wxString msg_text = from_u8((boost::format(_u8L("Printer with name \"%1%\" already exists.")) % printer_name).str()); - msg_text += "\n" + _L("Replace?"); - wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO); - - if (dialog.ShowModal() == wxID_NO) - return; - } - - std::set repeat_presets; - m_printer.reset_presets(); - for (PresetForPrinter* preset : m_presets) { - if (!m_printer.add_preset(preset->get_preset_name())) - repeat_presets.emplace(preset->get_preset_name()); - } - - if (!repeat_presets.empty()) - { - wxString repeatable_presets = "\n"; - for (const std::string& preset_name : repeat_presets) - repeatable_presets += " " + from_u8(preset_name) + "\n"; - repeatable_presets += "\n"; - - wxString msg_text = from_u8((boost::format(_u8L("Next printer preset(s) is(are) duplicated:%1%" - "Should I add it(they) just once for the printer \"%2%\" and close the Editing Dialog?")) % repeatable_presets % printer_name).str()); - wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO); - if (dialog.ShowModal() == wxID_NO) - return; - } - - std::string renamed_from; - // temporary save previous printer name if it was edited - if (m_printer.name != _u8L("My Printer Device") && - m_printer.name != into_u8(printer_name)) - renamed_from = m_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, renamed_from); - - if (m_printer.preset_names.find(printers.get_selected_printer_preset_name()) == m_printer.preset_names.end()) { - // select first preset for this printer - printers.select_printer(m_printer); - // refresh preset list on Printer Settings Tab - wxGetApp().get_tab(Preset::TYPE_PRINTER)->select_preset(printers.get_selected_printer_preset_name()); - } - - event.Skip(); -} - -void PhysicalPrinterDialog::AddPreset(wxEvent& event) -{ - m_presets.emplace_back(new PresetForPrinter(this)); - // enable DELETE button for the first preset, if was disabled - m_presets.front()->EnableDeleteBtn(); - - m_presets_sizer->Add(m_presets.back()->sizer(), 1, wxEXPAND | wxTOP, BORDER_W); - update_full_printer_names(); - - this->Fit(); -} - -void PhysicalPrinterDialog::DeletePreset(PresetForPrinter* preset_for_printer) -{ - if (m_presets.size() == 1) { - wxString msg_text = _L("It's not possible to delete last related preset for the printer."); - wxMessageDialog dialog(nullptr, msg_text, _L("Infornation"), wxICON_INFORMATION | wxOK); - dialog.ShowModal(); - return; - } - - assert(preset_for_printer); - auto it = std::find(m_presets.begin(), m_presets.end(), preset_for_printer); - if (it == m_presets.end()) - return; - - const int remove_id = it - m_presets.begin(); - m_presets_sizer->Remove(remove_id); - delete preset_for_printer; - m_presets.erase(it); - - if (m_presets.size() == 1) - m_presets.front()->DisableDeleteBtn(); - - this->Layout(); - this->Fit(); -} - - //----------------------------------------------- // ChangePresetForPhysicalPrinterDialog //----------------------------------------------- @@ -1548,9 +1073,9 @@ ChangePresetForPhysicalPrinterDialog::ChangePresetForPhysicalPrinterDialog(const wxStaticText* label_top = new wxStaticText(this, wxID_ANY, msg_text); label_top->SetFont(wxGetApp().bold_font()); - wxString choices[] = { from_u8((boost::format(_u8L("Just switch to \"%1%\"")) % preset_name).str()), - from_u8((boost::format(_u8L("Change \"%1%\" to \"%2%\" for this physical printer")) % old_preset_name % preset_name).str()), - from_u8((boost::format(_u8L("Add \"%1%\" as a next preset for the the physical printer")) % preset_name).str()) }; + wxString choices[] = { from_u8((boost::format(_u8L("Change \"%1%\" to \"%2%\" for this physical printer")) % old_preset_name % preset_name).str()), + from_u8((boost::format(_u8L("Add \"%1%\" as a next preset for the the physical printer")) % preset_name).str()), + from_u8((boost::format(_u8L("Just switch to \"%1%\"")) % preset_name).str()) }; wxRadioBox* selection_type_box = new wxRadioBox(this, wxID_ANY, _L("What would you like to do?"), wxDefaultPosition, wxDefaultSize, WXSIZEOF(choices), choices, 3, wxRA_SPECIFY_ROWS); diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 9a70818e1..6b8017f31 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -1,16 +1,12 @@ #ifndef slic3r_PresetComboBoxes_hpp_ #define slic3r_PresetComboBoxes_hpp_ -#include - -#include #include #include #include "libslic3r/Preset.hpp" #include "wxExtensions.hpp" #include "GUI_Utils.hpp" -//#include "BitmapCache.hpp" class wxString; class wxTextCtrl; @@ -23,6 +19,7 @@ namespace Slic3r { namespace GUI { class BitmapCache; + // --------------------------------- // *** PresetComboBox *** // --------------------------------- @@ -47,8 +44,9 @@ public: }; void set_label_marker(int item, LabelItemType label_item_type = LABEL_ITEM_MARKER); + bool set_printer_technology(PrinterTechnology pt); - void set_selection_changed_function(std::function sel_changed) { on_selection_changed = sel_changed; } + void set_selection_changed_function(std::function sel_changed) { on_selection_changed = sel_changed; } bool is_selected_physical_printer(); @@ -58,7 +56,7 @@ public: void update(const std::string& select_preset); - virtual void update(){}; + virtual void update(); virtual void msw_rescale(); protected: @@ -91,6 +89,8 @@ protected: int thin_space_icon_width; int wide_space_icon_width; + PrinterTechnology printer_technology {ptAny}; + void invalidate_selection(); void validate_selection(bool predicate = false); void update_selection(); @@ -188,83 +188,6 @@ public: }; -//------------------------------------------ -// PresetForPrinter -//------------------------------------------ -static std::string g_info_string = " (modified)"; -class PhysicalPrinterDialog; -class PresetForPrinter -{ - PhysicalPrinterDialog* m_parent { nullptr }; - - PresetComboBox* m_presets_list { nullptr }; - ScalableButton* m_delete_preset_btn { nullptr }; - wxStaticText* m_info_line { nullptr }; - wxStaticText* m_full_printer_name { nullptr }; - - wxBoxSizer* m_sizer { nullptr }; - - void DeletePreset(wxEvent& event); - -public: - PresetForPrinter(PhysicalPrinterDialog* parent, const std::string& preset_name = ""); - ~PresetForPrinter(); - - wxBoxSizer* sizer() { return m_sizer; } - void update_full_printer_name(); - std::string get_preset_name(); - void DisableDeleteBtn(); - void EnableDeleteBtn(); - - void msw_rescale(); - void on_sys_color_changed() {}; -}; - - -//------------------------------------------ -// PhysicalPrinterDialog -//------------------------------------------ - -class ConfigOptionsGroup; -class PhysicalPrinterDialog : public DPIDialog -{ - PhysicalPrinter m_printer; - wxString m_default_name; - DynamicPrintConfig* m_config { nullptr }; - - wxTextCtrl* m_printer_name { nullptr }; - std::vector m_presets; - - ConfigOptionsGroup* m_optgroup { nullptr }; - - ScalableButton* m_add_preset_btn {nullptr}; - ScalableButton* m_printhost_browse_btn {nullptr}; - ScalableButton* m_printhost_test_btn {nullptr}; - ScalableButton* m_printhost_cafile_browse_btn {nullptr}; - - wxBoxSizer* m_presets_sizer {nullptr}; - - void build_printhost_settings(ConfigOptionsGroup* optgroup); - void OnOK(wxEvent& event); - void AddPreset(wxEvent& event); - -public: - PhysicalPrinterDialog(wxString printer_name); - ~PhysicalPrinterDialog(); - - void update(); - wxString get_printer_name(); - void update_full_printer_names(); - PhysicalPrinter* get_printer() {return &m_printer; } - - void DeletePreset(PresetForPrinter* preset_for_printer); - -protected: - void on_dpi_changed(const wxRect& suggested_rect) override; - void on_sys_color_changed() override {}; -}; - - //------------------------------------------------ // ChangePresetForPhysicalPrinterDialog //------------------------------------------------ From 924bda6ec08f8940347423b7f8b3e1e1d3115e88 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 27 Jul 2020 20:06:10 +0200 Subject: [PATCH 21/31] ChangePresetForPhysicalPrinterDialog and SavePresetWindow are merged to SavePresetDialog --- src/slic3r/GUI/PresetComboBoxes.cpp | 301 ++++++++++++++++++++-------- src/slic3r/GUI/PresetComboBoxes.hpp | 55 +++-- src/slic3r/GUI/Tab.cpp | 61 +----- 3 files changed, 253 insertions(+), 164 deletions(-) diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 3edc3947a..01c83921a 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -1005,106 +1005,135 @@ void TabPresetComboBox::update_dirty() #endif /* __APPLE __ */ } -void TabPresetComboBox::update_physical_printers( const std::string& preset_name) -{ - if (m_type != Preset::TYPE_PRINTER || !m_allow_to_update_physical_printers) - return; - - m_allow_to_update_physical_printers = false; - - PhysicalPrinterCollection& physical_printers = m_preset_bundle->physical_printers; - if (!physical_printers.has_selection()) - return; - - std::string printer_preset_name = physical_printers.get_selected_printer_preset_name(); - - if (Preset::remove_suffix_modified(preset_name) == printer_preset_name) { - if (!this->is_selected_physical_printer()) - physical_printers.unselect_printer(); - } - else - { - ChangePresetForPhysicalPrinterDialog dlg(Preset::remove_suffix_modified(preset_name)); - if(dlg.ShowModal() == wxID_OK) - { - if (dlg.m_selection == ChangePresetForPhysicalPrinterDialog::Switch) - // unselect physical printer, if it was selected - m_preset_bundle->physical_printers.unselect_printer(); - else - { - PhysicalPrinter printer = physical_printers.get_selected_printer(); - - if (dlg.m_selection == ChangePresetForPhysicalPrinterDialog::ChangePreset) - printer.delete_preset(printer_preset_name); - - if (printer.add_preset(preset_name)) - physical_printers.save_printer(printer); - else { - wxMessageDialog dialog(nullptr, _L("This preset is already exist for this physical printer. Please, select another one."), _L("Information"), wxICON_INFORMATION | wxOK); - dialog.ShowModal(); - } - - physical_printers.select_printer(printer.get_full_name(preset_name)); - } - } - else - wxGetApp().get_tab(Preset::TYPE_PRINTER)->select_preset(printer_preset_name); - } -} - //----------------------------------------------- -// ChangePresetForPhysicalPrinterDialog +// SavePresetDialog //----------------------------------------------- -ChangePresetForPhysicalPrinterDialog::ChangePresetForPhysicalPrinterDialog(const std::string& preset_name) - : DPIDialog(nullptr, wxID_ANY, _L("Warning"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING/* | wxRESIZE_BORDER*/) +SavePresetDialog::SavePresetDialog(TabPresetComboBox* preset_cb, const std::string& suffix) + : DPIDialog(nullptr, wxID_ANY, _L("Save preset"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING | wxRESIZE_BORDER), + m_preset_cb(preset_cb) { SetFont(wxGetApp().normal_font()); - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - - PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; - std::string printer_name = printers.get_selected_printer_name(); - std::string old_preset_name = printers.get_selected_printer_preset_name(); - - wxString msg_text = from_u8((boost::format(_u8L("You have selected physical printer \"%1%\"\n" - "with related printer preset \"%2%\"")) % - printer_name % old_preset_name).str()); - wxStaticText* label_top = new wxStaticText(this, wxID_ANY, msg_text); - label_top->SetFont(wxGetApp().bold_font()); - - wxString choices[] = { from_u8((boost::format(_u8L("Change \"%1%\" to \"%2%\" for this physical printer")) % old_preset_name % preset_name).str()), - from_u8((boost::format(_u8L("Add \"%1%\" as a next preset for the the physical printer")) % preset_name).str()), - from_u8((boost::format(_u8L("Just switch to \"%1%\"")) % preset_name).str()) }; - - wxRadioBox* selection_type_box = new wxRadioBox(this, wxID_ANY, _L("What would you like to do?"), wxDefaultPosition, wxDefaultSize, WXSIZEOF(choices), choices, - 3, wxRA_SPECIFY_ROWS); - selection_type_box->SetFont(wxGetApp().normal_font()); - selection_type_box->SetSelection(0); - - selection_type_box->Bind(wxEVT_RADIOBOX, [this](wxCommandEvent& e) { - int selection = e.GetSelection(); - m_selection = (SelectionType)selection; - }); - - auto radio_sizer = new wxBoxSizer(wxHORIZONTAL); - radio_sizer->Add(selection_type_box, 1, wxALIGN_CENTER_VERTICAL); - - wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); - wxButton* btnOK = static_cast(this->FindWindowById(wxID_OK, this)); - btnOK->Bind(wxEVT_BUTTON, &ChangePresetForPhysicalPrinterDialog::OnOK, this); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); - topSizer->Add(label_top, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); - topSizer->Add(radio_sizer, 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); - topSizer->Add(btns, 0, wxEXPAND | wxALL, BORDER_W); + add_common_items(topSizer, suffix); + add_items_for_edit_ph_printer(topSizer); + + // add dialog's buttons + wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); + wxButton* btnOK = static_cast(this->FindWindowById(wxID_OK, this)); + btnOK->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { accept(); }); + btnOK->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { + evt.Enable(!m_combo->GetValue().IsEmpty()); }); + + topSizer->Add(btns, 0, wxEXPAND | wxALL, BORDER_W); SetSizer(topSizer); topSizer->SetSizeHints(this); } -void ChangePresetForPhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) +void SavePresetDialog::add_common_items(wxBoxSizer* sizer, const std::string& suffix) +{ + const PresetCollection* presets = m_preset_cb->presets(); + const Preset& sel_preset = presets->get_selected_preset(); + std::string preset_name = sel_preset.is_default ? "Untitled" : + sel_preset.is_system ? (boost::format(("%1% - %2%")) % sel_preset.name % suffix).str() : + sel_preset.name; + + // if name contains extension + if (boost::iends_with(preset_name, ".ini")) { + size_t len = preset_name.length() - 4; + preset_name.resize(len); + } + + std::vector values; + for (const Preset& preset : *presets) { + if (preset.is_default || preset.is_system || preset.is_external) + continue; + values.push_back(preset.name); + } + + wxStaticText* label_top = new wxStaticText(this, wxID_ANY, from_u8((boost::format(_utf8(L("Save %s as:"))) % into_u8(wxGetApp().get_tab(m_preset_cb->type())->title())).str())); + m_combo = new wxComboBox(this, wxID_ANY, from_u8(preset_name), + wxDefaultPosition, wxDefaultSize, 0, 0, wxTE_PROCESS_ENTER); + for (auto value : values) + m_combo->Append(from_u8(value)); + + m_combo->Bind(wxEVT_TEXT_ENTER, [this](wxCommandEvent&) { accept(); }); + m_combo->Bind(wxEVT_TEXT, [this](wxCommandEvent&) { + update(normalize_utf8_nfc(m_combo->GetValue().ToUTF8())); + this->Layout(); + this->Fit(); + }); + + sizer->Add(label_top, 0, wxEXPAND | wxALL, BORDER_W); + sizer->Add(m_combo, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, BORDER_W); +} + +void SavePresetDialog::add_items_for_edit_ph_printer(wxBoxSizer* sizer) +{ + if (m_preset_cb->type() != Preset::TYPE_PRINTER || !m_preset_cb->is_selected_physical_printer()) + return; + + PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; + m_ph_printer_name = printers.get_selected_printer_name(); + m_old_preset_name = printers.get_selected_printer_preset_name(); + + wxString msg_text = from_u8((boost::format(_u8L("You have selected physical printer \"%1%\" \n" + "with related printer preset \"%2%\"")) % + m_ph_printer_name % m_old_preset_name).str()); + m_label = new wxStaticText(this, wxID_ANY, msg_text); + m_label->SetFont(wxGetApp().bold_font()); + + wxString choices[] = {"","",""}; + + m_action_radio_box = new wxRadioBox(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, + WXSIZEOF(choices), choices, 3, wxRA_SPECIFY_ROWS); + m_action_radio_box->SetFont(wxGetApp().normal_font()); + m_action_radio_box->SetSelection(0); + m_action_radio_box->Bind(wxEVT_RADIOBOX, [this](wxCommandEvent& e) { + m_action = (ActionType)e.GetSelection(); }); + m_action = ChangePreset; + + m_radio_sizer = new wxBoxSizer(wxHORIZONTAL); + m_radio_sizer->Add(m_action_radio_box, 1, wxALIGN_CENTER_VERTICAL); + + sizer->Add(m_label, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); + sizer->Add(m_radio_sizer, 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); + + update(m_preset_name); +} + +void SavePresetDialog::update(const std::string& preset_name) +{ + if (m_preset_cb->type() != Preset::TYPE_PRINTER || !m_preset_cb->is_selected_physical_printer()) + return; + + bool show = m_old_preset_name != preset_name; + + m_label->Show(show); + m_radio_sizer->ShowItems(show); + if (!show) { + this->SetMinSize(wxSize(100,50)); + return; + } + + wxString msg_text = from_u8((boost::format(_u8L("What would you like to do with \"%1%\" preset after saving?")) % preset_name).str()); + m_action_radio_box->SetLabel(msg_text); + + wxString choices[] = { from_u8((boost::format(_u8L("Change \"%1%\" to \"%2%\" for this physical printer \"%3%\"")) % m_old_preset_name % preset_name % m_ph_printer_name).str()), + from_u8((boost::format(_u8L("Add \"%1%\" as a next preset for the the physical printer \"%2%\"")) % preset_name % m_ph_printer_name).str()), + from_u8((boost::format(_u8L("Just switch to \"%1%\" preset")) % preset_name).str()) }; + + int n = 0; + for(const wxString& label: choices) + m_action_radio_box->SetString(n++, label); +} + +void SavePresetDialog::on_dpi_changed(const wxRect& suggested_rect) { const int& em = em_unit(); @@ -1117,10 +1146,106 @@ void ChangePresetForPhysicalPrinterDialog::on_dpi_changed(const wxRect& suggeste Refresh(); } -void ChangePresetForPhysicalPrinterDialog::OnOK(wxEvent& event) +bool SavePresetDialog::preset_name_is_accepted() { - event.Skip(); + const char* unusable_symbols = "<>[]:/\\|?*\""; + const std::string unusable_suffix = PresetCollection::get_suffix_modified();//"(modified)"; + for (size_t i = 0; i < std::strlen(unusable_symbols); i++) { + if (m_preset_name.find_first_of(unusable_symbols[i]) != std::string::npos) { + show_error(this, _L("The supplied name is not valid;") + "\n" + + _L("the following characters are not allowed:") + " " + unusable_symbols); + return false; + } + } + + if (m_preset_name.find(unusable_suffix) != std::string::npos) { + show_error(this, _L("The supplied name is not valid;") + "\n" + + _L("the following suffix is not allowed:") + "\n\t" + + from_u8(PresetCollection::get_suffix_modified())); + return false; + } + + if (m_preset_name == "- default -") { + show_error(this, _L("The supplied name is not available.")); + return false; + } + return true; +} + +bool SavePresetDialog::preset_is_possible_to_save() +{ + const Preset* existing = m_preset_cb->presets()->find_preset(m_preset_name, false); + if (existing && (existing->is_default || existing->is_system)) { + show_error(this, _L("Cannot overwrite a system profile.")); + return false; + } + if (existing && (existing->is_external)) { + show_error(this, _(L("Cannot overwrite an external profile."))); + return false; + } + if (existing && m_preset_name != m_preset_cb->presets()->get_selected_preset_name()) + { + wxString msg_text = GUI::from_u8((boost::format(_utf8(L("Preset with name \"%1%\" already exists."))) % m_preset_name).str()); + msg_text += "\n" + _L("Replace?"); + wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO); + + if (dialog.ShowModal() == wxID_NO) + return false; + + // Remove the preset from the list. + m_preset_cb->presets()->delete_preset(m_preset_name); + } + return true; +} + +void SavePresetDialog::update_physical_printers() +{ + if (m_action == UndefAction) + return; + + PhysicalPrinterCollection& physical_printers = wxGetApp().preset_bundle->physical_printers; + if (!physical_printers.has_selection()) + return; + + std::string printer_preset_name = physical_printers.get_selected_printer_preset_name(); + + if (m_action == Switch) + // unselect physical printer, if it was selected + physical_printers.unselect_printer(); + else + { + PhysicalPrinter printer = physical_printers.get_selected_printer(); + + if (m_action == ChangePreset) + printer.delete_preset(printer_preset_name); + + if (printer.add_preset(m_preset_name)) + physical_printers.save_printer(printer); + else { + wxMessageDialog dialog(nullptr, _L("This preset is already exist for this physical printer. Please, select another one."), _L("Information"), wxICON_INFORMATION | wxOK); + dialog.ShowModal(); + } + + physical_printers.select_printer(printer.get_full_name(m_preset_name)); + } +} + +void SavePresetDialog::accept() +{ + m_preset_name = normalize_utf8_nfc(m_combo->GetValue().ToUTF8()); + + if (m_preset_name.empty()) + return; + + if (!preset_name_is_accepted() || + !preset_is_possible_to_save()) + return; + + update_physical_printers(); + + EndModal(wxID_OK); } + }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 6b8017f31..fa4554a5e 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -13,6 +13,7 @@ class wxTextCtrl; class wxStaticText; class ScalableButton; class wxBoxSizer; +class wxComboBox; namespace Slic3r { @@ -167,50 +168,68 @@ class TabPresetComboBox : public PresetComboBox bool show_incompatible {false}; bool m_enable_all {false}; - bool m_allow_to_update_physical_printers {false}; - public: TabPresetComboBox(wxWindow *parent, Preset::Type preset_type); ~TabPresetComboBox() {} void set_show_incompatible_presets(bool show_incompatible_presets) { show_incompatible = show_incompatible_presets; } - void allow_to_update_physical_printers() { - m_allow_to_update_physical_printers = m_type == Preset::TYPE_PRINTER; - } void update() override; void update_dirty(); - void update_physical_printers(const std::string& preset_name); void msw_rescale() override; void set_enable_all(bool enable=true) { m_enable_all = enable; } + + PresetCollection* presets() const { return m_collection; } + Preset::Type type() const { return m_type; } }; //------------------------------------------------ -// ChangePresetForPhysicalPrinterDialog +// SavePresetDialog //------------------------------------------------ -class ChangePresetForPhysicalPrinterDialog : public DPIDialog +class SavePresetDialog : public DPIDialog { - void OnOK(wxEvent& event); + enum ActionType + { + ChangePreset, + AddPreset, + Switch, + UndefAction + }; + + TabPresetComboBox* m_preset_cb {nullptr}; + std::string m_preset_name; + wxComboBox* m_combo {nullptr}; + wxStaticText* m_label {nullptr}; + wxRadioBox* m_action_radio_box {nullptr}; + wxBoxSizer* m_radio_sizer {nullptr}; + ActionType m_action {UndefAction}; + + std::string m_ph_printer_name; + std::string m_old_preset_name; public: - enum SelectionType - { - Switch, - ChangePreset, - AddPreset - } m_selection {Switch}; + SavePresetDialog(TabPresetComboBox* preset_cb, const std::string& suffix); + ~SavePresetDialog() {} - ChangePresetForPhysicalPrinterDialog(const std::string& preset_name); - ~ChangePresetForPhysicalPrinterDialog() {} + std::string get_name() { return m_preset_name; } protected: void on_dpi_changed(const wxRect& suggested_rect) override; - void on_sys_color_changed() override {}; + void on_sys_color_changed() override {} + +private: + void add_common_items(wxBoxSizer *sizer, const std::string &suffix); + void add_items_for_edit_ph_printer(wxBoxSizer *sizer); + void update(const std::string &preset_name); + bool preset_name_is_accepted(); + bool preset_is_possible_to_save(); + void update_physical_printers(); + void accept(); }; } // namespace GUI diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 3f566eacb..a97c10f7d 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -164,11 +164,8 @@ void Tab::create_preset_tab() m_presets_choice->set_selection_changed_function([this](int selection) { if (!m_presets_choice->selection_is_changed_according_to_physical_printers()) { - // For the printer presets allow to update a physical printer if it is needed. - // After call of the update_physical_printers() this possibility will be disabled again to avoid a case, - // when select_preset is called from the others than this place - if (m_type == Preset::TYPE_PRINTER) - m_presets_choice->allow_to_update_physical_printers(); + if (m_type == Preset::TYPE_PRINTER && !m_presets_choice->is_selected_physical_printer()) + m_preset_bundle->physical_printers.unselect_printer(); // select preset select_preset(m_presets_choice->GetString(selection).ToUTF8().data()); @@ -3148,9 +3145,6 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, m_dependent_tabs = { Preset::Type::TYPE_SLA_PRINT, Preset::Type::TYPE_SLA_MATERIAL }; } - //update physical printer's related printer preset if it's needed - m_presets_choice->update_physical_printers(preset_name); - load_current_preset(); } } @@ -3290,56 +3284,10 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach) std::string suffix = detach ? _utf8(L("Detached")) : _CTX_utf8(L_CONTEXT("Copy", "PresetName"), "PresetName"); if (name.empty()) { - const Preset &preset = m_presets->get_selected_preset(); - auto default_name = preset.is_default ? "Untitled" : -// preset.is_system ? (boost::format(_CTX_utf8(L_CONTEXT("%1% - Copy", "PresetName"), "PresetName")) % preset.name).str() : - preset.is_system ? (boost::format(("%1% - %2%")) % preset.name % suffix).str() : - preset.name; - - bool have_extention = boost::iends_with(default_name, ".ini"); - if (have_extention) { - size_t len = default_name.length()-4; - default_name.resize(len); - } - //[map $_->name, grep !$_->default && !$_->external, @{$self->{presets}}], - std::vector values; - for (size_t i = 0; i < m_presets->size(); ++i) { - const Preset &preset = m_presets->preset(i); - if (preset.is_default || preset.is_system || preset.is_external) - continue; - values.push_back(preset.name); - } - - SavePresetWindow dlg(parent()); - dlg.build(title(), default_name, values); + SavePresetDialog dlg(m_presets_choice, suffix); if (dlg.ShowModal() != wxID_OK) return; name = dlg.get_name(); - if (name == "") { - show_error(this, _(L("The supplied name is empty. It can't be saved."))); - return; - } - const Preset *existing = m_presets->find_preset(name, false); - if (existing && (existing->is_default || existing->is_system)) { - show_error(this, _(L("Cannot overwrite a system profile."))); - return; - } - if (existing && (existing->is_external)) { - show_error(this, _(L("Cannot overwrite an external profile."))); - return; - } - if (existing && name != preset.name) - { - wxString msg_text = GUI::from_u8((boost::format(_utf8(L("Preset with name \"%1%\" already exists."))) % name).str()); - msg_text += "\n" + _(L("Replace?")); - wxMessageDialog dialog(nullptr, msg_text, _(L("Warning")), wxICON_WARNING | wxYES | wxNO); - - if (dialog.ShowModal() == wxID_NO) - return; - - // Remove the preset from the list. - m_presets->delete_preset(name); - } } // Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini @@ -3347,9 +3295,6 @@ 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 - m_presets_choice->allow_to_update_physical_printers(); - m_presets_choice->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. From 68ae95509fc4410baa9069cb407b8bb756e2be10 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 28 Jul 2020 11:31:16 +0200 Subject: [PATCH 22/31] Improved InfoMsg for a delete preset: * Now we show a list of printers name with selected preset + Added a edit_button for the editing of the physical printer fro the Settings Tab + Show whole list of the loaded presets with "Print host upload" --- src/libslic3r/Preset.cpp | 65 ++++++---- src/libslic3r/Preset.hpp | 11 +- src/slic3r/GUI/GUI_App.cpp | 38 ++---- src/slic3r/GUI/PhysicalPrinterDialog.cpp | 2 + src/slic3r/GUI/PresetComboBoxes.cpp | 15 ++- src/slic3r/GUI/PresetComboBoxes.hpp | 2 +- src/slic3r/GUI/Tab.cpp | 153 ++++++++++++++--------- src/slic3r/GUI/Tab.hpp | 3 +- 8 files changed, 173 insertions(+), 116 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 7e30831fe..c7acf8f49 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1383,13 +1383,14 @@ const std::vector& PhysicalPrinter::print_host_options() return s_opts; } -bool PhysicalPrinter::has_print_host_information(const PrinterPresetCollection& printer_presets) +std::vector PhysicalPrinter::presets_with_print_host_information(const PrinterPresetCollection& printer_presets) { + std::vector presets; for (const Preset& preset : printer_presets) if (has_print_host_information(preset.config)) - return true; + presets.emplace_back(preset.name); - return false; + return presets; } bool PhysicalPrinter::has_print_host_information(const DynamicPrintConfig& config) @@ -1564,7 +1565,7 @@ void PhysicalPrinterCollection::load_printers(const std::string& dir_path, const // if there is saved user presets, contains information about "Print Host upload", // Create default printers with this presets // Note! "Print Host upload" options will be cleared after physical printer creations -void PhysicalPrinterCollection::load_printers_from_presets(PrinterPresetCollection& printer_presets, std::string def_printer_name) +void PhysicalPrinterCollection::load_printers_from_presets(PrinterPresetCollection& printer_presets) { int cnt=0; for (Preset& preset: printer_presets) { @@ -1579,8 +1580,12 @@ void PhysicalPrinterCollection::load_printers_from_presets(PrinterPresetCollecti // just add preset for this printer existed_printer->add_preset(preset.name); else { + std::string new_printer_name = (boost::format("Printer %1%") % ++cnt ).str(); + while (find_printer(new_printer_name)) + new_printer_name = (boost::format("Printer %1%") % ++cnt).str(); + // create new printer from this preset - PhysicalPrinter printer((boost::format("%1% %2%") % def_printer_name % ++cnt ).str(), preset); + PhysicalPrinter printer(new_printer_name, preset); printer.loaded = true; save_printer(printer); } @@ -1699,33 +1704,51 @@ bool PhysicalPrinterCollection::delete_selected_printer() return true; } -bool PhysicalPrinterCollection::delete_preset_from_printers( const std::string& preset_name, bool first_check /*=true*/) +bool PhysicalPrinterCollection::delete_preset_from_printers( const std::string& preset_name) { - if (first_check) { - for (auto printer: m_printers) - if (printer.preset_names.size()==1 && *printer.preset_names.begin() == preset_name) - return false; - } - std::vector printers_for_delete; - for (PhysicalPrinter& printer : m_printers) + for (PhysicalPrinter& printer : m_printers) { if (printer.preset_names.size() == 1 && *printer.preset_names.begin() == preset_name) printers_for_delete.emplace_back(printer.name); - else if (printer.delete_preset(preset_name)) { - if (printer.name == get_selected_printer_name() && - preset_name == get_selected_printer_preset_name()) - select_printer(printer); + else if (printer.delete_preset(preset_name)) save_printer(printer); - } + } - if (!printers_for_delete.empty()) { + if (!printers_for_delete.empty()) for (const std::string& printer_name : printers_for_delete) delete_printer(printer_name); - unselect_printer(); - } + + unselect_printer(); return true; } +// Get list of printers which have more than one preset and "preset_name" preset is one of them +std::vector PhysicalPrinterCollection::get_printers_with_preset(const std::string& preset_name) +{ + std::vector printers; + + for (auto printer : m_printers) { + if (printer.preset_names.size() == 1) + continue; + if (printer.preset_names.find(preset_name) != printer.preset_names.end()) + printers.emplace_back(printer.name); + } + + return printers; +} + +// Get list of printers which has only "preset_name" preset +std::vector PhysicalPrinterCollection::get_printers_with_only_preset(const std::string& preset_name) +{ + std::vector printers; + + for (auto printer : m_printers) + if (printer.preset_names.size() == 1 && *printer.preset_names.begin() == preset_name) + printers.emplace_back(printer.name); + + return printers; +} + std::string PhysicalPrinterCollection::get_selected_full_printer_name() const { return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_full_name(m_selected_preset); diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index 6b5a2a511..e34fca4dd 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -555,7 +555,7 @@ public: static std::string separator(); static const std::vector& printer_options(); static const std::vector& print_host_options(); - static bool has_print_host_information(const PrinterPresetCollection& printer_presets); + static std::vector presets_with_print_host_information(const PrinterPresetCollection& printer_presets); static bool has_print_host_information(const DynamicPrintConfig& config); const std::set& get_preset_names() const; @@ -629,7 +629,7 @@ public: // Load ini files of the particular type from the provided directory path. void load_printers(const std::string& dir_path, const std::string& subdir); - void load_printers_from_presets(PrinterPresetCollection &printer_presets, std::string def_printer_name); + void load_printers_from_presets(PrinterPresetCollection &printer_presets); // Save the printer under a new name. If the name is different from the old one, // a new printer is stored into the list of printers. @@ -645,7 +645,12 @@ public: // Delete preset_name preset from all printers: // If there is last preset for the printer and first_check== false, then delete this printer // returns true if all presets were deleted successfully. - bool delete_preset_from_printers(const std::string& preset_name, bool first_check = true); + bool delete_preset_from_printers(const std::string& preset_name); + + // Get list of printers which have more than one preset and "preset_name" preset is one of them + std::vector get_printers_with_preset( const std::string &preset_name); + // Get list of printers which has only "preset_name" preset + std::vector get_printers_with_only_preset( const std::string &preset_name); // Return the selected preset, without the user modifications applied. PhysicalPrinter& get_selected_printer() { return m_printers[m_idx_selected]; } diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 1b7278bd7..410614b94 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -635,38 +635,22 @@ void GUI_App::set_auto_toolbar_icon_scale(float scale) const // check user printer_presets for the containing information about "Print Host upload" void GUI_App::check_printer_presets() { - if (!PhysicalPrinter::has_print_host_information(preset_bundle->printers)) + std::vector preset_names = PhysicalPrinter::presets_with_print_host_information(preset_bundle->printers); + if (preset_names.empty()) return; - wxString msg_text = _L("You have presets with saved options for \"Print Host upload\".\n" - "But from this version of PrusaSlicer we don't show/use this information in Printer Settings.\n" + wxString msg_text = _L("You have next presets with saved options for \"Print Host upload\"") + ":"; + for (const std::string& preset_name : preset_names) + msg_text += "\n \"" + from_u8(preset_name) + "\","; + msg_text.RemoveLast(); + msg_text += "\n\n" + _L("But from this version of PrusaSlicer we don't show/use this information in Printer Settings.\n" "Now, this information will be exposed in physical printers settings.") + "\n\n" + - _L("Enter the name for the Printer device used by default during its creation.\n" - "Note: This name can be changed later from the physical printers settings") + ":"; - wxString msg_header = _L("Name for printer device"); + _L("By default new Printer devices will be named as \"Printer N\" during its creation.\n" + "Note: This name can be changed later from the physical printers settings"); - // get custom gcode - wxTextEntryDialog dlg(nullptr, msg_text, msg_header, _L("Printer"), wxTextEntryDialogStyle); + wxMessageDialog(nullptr, msg_text, _L("Information"), wxOK | wxICON_INFORMATION).ShowModal(); - // detect TextCtrl and OK button - wxTextCtrl* textctrl{ nullptr }; - wxWindowList& dlg_items = dlg.GetChildren(); - for (auto item : dlg_items) { - textctrl = dynamic_cast(item); - if (textctrl) - break; - } - - if (textctrl) { - textctrl->SetSelection(0, textctrl->GetLastPosition()); - - wxButton* btn_OK = static_cast(dlg.FindWindowById(wxID_OK)); - btn_OK->Bind(wxEVT_UPDATE_UI, [textctrl](wxUpdateUIEvent& evt) { - evt.Enable(!textctrl->IsEmpty()); - }, btn_OK->GetId()); - } - if (dlg.ShowModal() == wxID_OK) - preset_bundle->physical_printers.load_printers_from_presets(preset_bundle->printers, into_u8(dlg.GetValue())); + preset_bundle->physical_printers.load_printers_from_presets(preset_bundle->printers); } void GUI_App::recreate_GUI(const wxString& msg_name) diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp index 7d3c92c13..f14f49801 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp @@ -510,6 +510,8 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) // refresh preset list on Printer Settings Tab wxGetApp().get_tab(Preset::TYPE_PRINTER)->select_preset(printers.get_selected_printer_preset_name()); } + else + wxGetApp().get_tab(Preset::TYPE_PRINTER)->update_preset_choice(); event.Skip(); } diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 01c83921a..666f10194 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -171,7 +171,7 @@ void PresetComboBox::update_selection() SetToolTip(GetString(m_last_selected)); } -void PresetComboBox::update(const std::string& select_preset_name) +void PresetComboBox::update(std::string select_preset_name) { Freeze(); Clear(); @@ -192,6 +192,8 @@ void PresetComboBox::update(const std::string& select_preset_name) // marker used for disable incompatible printer models for the selected physical printer bool is_enabled = m_type == Preset::TYPE_PRINTER && printer_technology != ptAny ? preset.printer_technology() == printer_technology : true; + if (select_preset_name.empty() && is_enabled) + select_preset_name = preset.name; std::string bitmap_key = "cb"; if (m_type == Preset::TYPE_PRINTER) { @@ -208,7 +210,7 @@ void PresetComboBox::update(const std::string& select_preset_name) int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp); if (!is_enabled) set_label_marker(item_id, LABEL_ITEM_DISABLED); - validate_selection(preset.name == select_preset_name || (select_preset_name.empty() && is_enabled)); + validate_selection(preset.name == select_preset_name); } else { @@ -659,6 +661,13 @@ void PlaterPresetComboBox::show_edit_menu() 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); } @@ -784,7 +793,7 @@ void PlaterPresetComboBox::update() } } - if (/*m_type == Preset::TYPE_PRINTER || */m_type == Preset::TYPE_SLA_MATERIAL) { + if (m_type == Preset::TYPE_PRINTER || m_type == Preset::TYPE_SLA_MATERIAL) { wxBitmap* bmp = get_bmp("edit_preset_list", wide_icons, "edit_uni"); assert(bmp); diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index fa4554a5e..a30d9f6e9 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -55,7 +55,7 @@ public: // and next internal selection was accomplished bool selection_is_changed_according_to_physical_printers(); - void update(const std::string& select_preset); + void update(std::string select_preset); virtual void update(); virtual void msw_rescale(); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index a97c10f7d..4dbe7cc74 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -35,6 +35,7 @@ #include "Plater.hpp" #include "MainFrame.hpp" #include "format.hpp" +#include "PhysicalPrinterDialog.hpp" namespace Slic3r { namespace GUI { @@ -180,6 +181,8 @@ void Tab::create_preset_tab() add_scaled_button(panel, &m_btn_save_preset, "save"); add_scaled_button(panel, &m_btn_delete_preset, "cross"); + if (m_type == Preset::Type::TYPE_PRINTER) + add_scaled_button(panel, &m_btn_edit_ph_printer, "cog"); m_show_incompatible_presets = false; add_scaled_bitmap(this, m_bmp_show_incompatible_presets, "flag_red"); @@ -191,6 +194,8 @@ void Tab::create_preset_tab() 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(); add_scaled_button(panel, &m_question_btn, "question"); m_question_btn->SetToolTip(_(L("Hover the cursor over buttons to find more information \n" @@ -245,6 +250,10 @@ void Tab::create_preset_tab() m_hsizer->Add(m_btn_save_preset, 0, wxALIGN_CENTER_VERTICAL); m_hsizer->AddSpacer(int(4 * scale_factor)); m_hsizer->Add(m_btn_delete_preset, 0, wxALIGN_CENTER_VERTICAL); + if (m_btn_edit_ph_printer) { + m_hsizer->AddSpacer(int(4 * scale_factor)); + m_hsizer->Add(m_btn_edit_ph_printer, 0, wxALIGN_CENTER_VERTICAL); + } m_hsizer->AddSpacer(int(/*16*/8 * scale_factor)); m_hsizer->Add(m_btn_hide_incompatible_presets, 0, wxALIGN_CENTER_VERTICAL); m_hsizer->AddSpacer(int(8 * scale_factor)); @@ -291,6 +300,13 @@ void Tab::create_preset_tab() toggle_show_hide_incompatible(); })); + 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(); + })); + // Fill cache for mode bitmaps m_mode_bitmap_cache.reserve(3); m_mode_bitmap_cache.push_back(ScalableBitmap(this, "mode_simple" , mode_icon_px_size())); @@ -2786,8 +2802,7 @@ void Tab::load_current_preset() { const Preset& preset = m_presets->get_edited_preset(); -// (preset.is_default || preset.is_system) ? m_btn_delete_preset->Disable() : m_btn_delete_preset->Enable(true); - update_delete_preset_btn(); + update_btns_enabling(); update(); if (m_type == Slic3r::Preset::TYPE_PRINTER) { @@ -2924,23 +2939,25 @@ void Tab::update_page_tree_visibility() } -void Tab::update_delete_preset_btn() +void Tab::update_btns_enabling() { - if (m_type == Preset::TYPE_PRINTER && m_presets_choice->is_selected_physical_printer() && - m_preset_bundle->physical_printers.has_selection()) { - // we can't delete last preset from the physical printer + // 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 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()); } void Tab::update_preset_choice() { m_presets_choice->update(); - update_delete_preset_btn(); + update_btns_enabling(); } // Called by the UI combo box when the user switches profiles, and also to delete the current profile. @@ -2950,55 +2967,16 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, { if (preset_name.empty()) { if (delete_current) { - PhysicalPrinterCollection& physical_printers = m_preset_bundle->physical_printers; - 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(); - } - else { - // 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 - physical_printers.select_printer(printer); - - preset_name = physical_printers.get_selected_printer_preset_name(); - // revert delete_current value to avoid deleting of the new selected preset - delete_current = false; - } - } - else { - // Check preset for delete in physical printers - // Ask a customer about next action , if there is a printer with just one preset and this preset is equal to delete - if (m_type == Preset::TYPE_PRINTER && !physical_printers.empty() ) - { - // try to delete selected preset from the all printers it has - if (!physical_printers.delete_preset_from_printers(m_presets->get_edited_preset().name)) - { - wxMessageDialog dialog(nullptr, _L("There is/are a physical printer(s), which has/have one and only this printer preset.\n" - "This/Those printer(s) will be deleted after deleting of the selected preset.\n" - "Are you sure you want to delete the selected preset?"), _L("Warning"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION); - if (dialog.ShowModal() == wxID_NO) - return; - - // delete selected preset from printers and printer, if it's needed - physical_printers.delete_preset_from_printers(m_presets->get_edited_preset().name, false); - } - } - - // Find an alternate preset to be selected after the current preset is deleted. - const std::deque &presets = this->m_presets->get_presets(); - size_t idx_current = this->m_presets->get_idx_selected(); - // Find the next visible preset. - size_t idx_new = idx_current + 1; - if (idx_new < presets.size()) - for (; idx_new < presets.size() && ! presets[idx_new].is_visible; ++ idx_new) ; - if (idx_new == presets.size()) - for (idx_new = idx_current - 1; idx_new > 0 && ! presets[idx_new].is_visible; -- idx_new); - preset_name = presets[idx_new].name; - } + // Find an alternate preset to be selected after the current preset is deleted. + const std::deque &presets = this->m_presets->get_presets(); + size_t idx_current = this->m_presets->get_idx_selected(); + // Find the next visible preset. + size_t idx_new = idx_current + 1; + if (idx_new < presets.size()) + for (; idx_new < presets.size() && ! presets[idx_new].is_visible; ++ idx_new) ; + if (idx_new == presets.size()) + for (idx_new = idx_current - 1; idx_new > 0 && ! presets[idx_new].is_visible; -- idx_new); + preset_name = presets[idx_new].name; } else { // If no name is provided, select the "-- default --" preset. preset_name = m_presets->default_preset().name; @@ -3349,15 +3327,70 @@ void Tab::delete_preset() // Don't let the user delete the ' - default - ' configuration. std::string action = current_preset.is_external ? _utf8(L("remove")) : _utf8(L("delete")); // TRN remove/delete - const wxString msg = m_presets_choice->is_selected_physical_printer() ? - from_u8((boost::format(_utf8(L("Are you sure you want to delete \"%1%\" preset from the physical printer?"))) % current_preset.name).str()) : - from_u8((boost::format(_utf8(L("Are you sure you want to %1% the selected preset?"))) % action).str()); + + 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()); + else + { + if (m_type == Preset::TYPE_PRINTER && !physical_printers.empty()) + { + // Check preset for delete in physical printers + // Ask a customer about next action, if there is a printer with just one preset and this preset is equal to delete + std::vector ph_printers = physical_printers.get_printers_with_preset(current_preset.name); + std::vector ph_printers_only = physical_printers.get_printers_with_only_preset(current_preset.name); + + if (!ph_printers.empty()) { + msg += _L("Next physical printer(s) has/have selected preset") + ":"; + for (const std::string& printer : ph_printers) + msg += "\n \"" + from_u8(printer) + "\","; + msg.RemoveLast(); + msg += "\n" + _L("Note, that selected preset will be deleted from this/those printer(s) too.")+ "\n\n"; + } + + if (!ph_printers_only.empty()) { + msg += _L("Next physical printer(s) has/have one and only selected preset") + ":"; + for (const std::string& printer : ph_printers_only) + msg += "\n \"" + from_u8(printer) + "\","; + msg.RemoveLast(); + msg += "\n" + _L("Note, that this/those printer(s) will be deleted after deleting of the selected preset.") + "\n\n"; + } + } + + msg += from_u8((boost::format(_u8L("Are you sure you want to %1% the selected preset?")) % action).str()); + } + action = current_preset.is_external ? _utf8(L("Remove")) : _utf8(L("Delete")); // TRN Remove/Delete wxString title = from_u8((boost::format(_utf8(L("%1% Preset"))) % action).str()); //action + _(L(" Preset")); if (current_preset.is_default || wxID_YES != wxMessageDialog(parent(), msg, title, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION).ShowModal()) return; + + // if we just delete preset from the physical printer + 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 + physical_printers.select_printer(printer); + + this->select_preset(physical_printers.get_selected_printer_preset_name()); + return; + } + + // delete selected preset from printers and printer, if it's needed + if (m_type == Preset::TYPE_PRINTER && !physical_printers.empty()) + physical_printers.delete_preset_from_printers(current_preset.name); + // Select will handle of the preset dependencies, of saving & closing the depending profiles, and // finally of deleting the preset. this->select_preset("", true); diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 57129955b..24f25e2d7 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -119,6 +119,7 @@ protected: ScalableButton* m_search_btn; ScalableButton* m_btn_save_preset; ScalableButton* m_btn_delete_preset; + ScalableButton* m_btn_edit_ph_printer {nullptr}; ScalableButton* m_btn_hide_incompatible_presets; wxBoxSizer* m_hsizer; wxBoxSizer* m_left_sizer; @@ -275,7 +276,7 @@ public: void load_current_preset(); void rebuild_page_tree(); void update_page_tree_visibility(); - void update_delete_preset_btn(); + void update_btns_enabling(); void update_preset_choice(); // Select a new preset, possibly delete the current one. void select_preset(std::string preset_name = "", bool delete_current = false, const std::string& last_selected_ph_printer_name = ""); From 96a364c3e6356d7107d6c51b4c1763c81d0d3435 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 29 Jul 2020 16:05:30 +0200 Subject: [PATCH 23/31] SavePresetDialog: Improvements --- src/slic3r/GUI/PresetComboBoxes.cpp | 303 ++++++++++++++++------------ src/slic3r/GUI/PresetComboBoxes.hpp | 64 ++++-- src/slic3r/GUI/Tab.cpp | 2 +- 3 files changed, 229 insertions(+), 140 deletions(-) diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 666f10194..35acbfd3a 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -1016,41 +1016,21 @@ void TabPresetComboBox::update_dirty() //----------------------------------------------- -// SavePresetDialog +// SavePresetDialog::Item //----------------------------------------------- -SavePresetDialog::SavePresetDialog(TabPresetComboBox* preset_cb, const std::string& suffix) - : DPIDialog(nullptr, wxID_ANY, _L("Save preset"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING | wxRESIZE_BORDER), - m_preset_cb(preset_cb) +SavePresetDialog::Item::Item(Preset::Type type, const std::string& suffix, wxBoxSizer* sizer, SavePresetDialog* parent): + m_type(type), + m_parent(parent) { - SetFont(wxGetApp().normal_font()); - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + Tab* tab = wxGetApp().get_tab(m_type); + assert(tab); + m_presets = tab->get_presets(); - wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); - - add_common_items(topSizer, suffix); - add_items_for_edit_ph_printer(topSizer); - - // add dialog's buttons - wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); - wxButton* btnOK = static_cast(this->FindWindowById(wxID_OK, this)); - btnOK->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { accept(); }); - btnOK->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { - evt.Enable(!m_combo->GetValue().IsEmpty()); }); - - topSizer->Add(btns, 0, wxEXPAND | wxALL, BORDER_W); - - SetSizer(topSizer); - topSizer->SetSizeHints(this); -} - -void SavePresetDialog::add_common_items(wxBoxSizer* sizer, const std::string& suffix) -{ - const PresetCollection* presets = m_preset_cb->presets(); - const Preset& sel_preset = presets->get_selected_preset(); - std::string preset_name = sel_preset.is_default ? "Untitled" : - sel_preset.is_system ? (boost::format(("%1% - %2%")) % sel_preset.name % suffix).str() : - sel_preset.name; + const Preset& sel_preset = m_presets->get_selected_preset(); + std::string preset_name = sel_preset.is_default ? "Untitled" : + sel_preset.is_system ? (boost::format(("%1% - %2%")) % sel_preset.name % suffix).str() : + sel_preset.name; // if name contains extension if (boost::iends_with(preset_name, ".ini")) { @@ -1059,34 +1039,166 @@ void SavePresetDialog::add_common_items(wxBoxSizer* sizer, const std::string& su } std::vector values; - for (const Preset& preset : *presets) { + for (const Preset& preset : *m_presets) { if (preset.is_default || preset.is_system || preset.is_external) continue; values.push_back(preset.name); } - wxStaticText* label_top = new wxStaticText(this, wxID_ANY, from_u8((boost::format(_utf8(L("Save %s as:"))) % into_u8(wxGetApp().get_tab(m_preset_cb->type())->title())).str())); - m_combo = new wxComboBox(this, wxID_ANY, from_u8(preset_name), - wxDefaultPosition, wxDefaultSize, 0, 0, wxTE_PROCESS_ENTER); + wxStaticText* label_top = new wxStaticText(m_parent, wxID_ANY, from_u8((boost::format(_utf8(L("Save %s as:"))) % into_u8(tab->title())).str())); + + m_valid_bmp = new wxStaticBitmap(m_parent, wxID_ANY, create_scaled_bitmap("tick_mark", m_parent)); + + m_combo = new wxComboBox(m_parent, wxID_ANY, from_u8(preset_name)/*, + wxDefaultPosition, wxDefaultSize, 0, 0, wxTE_PROCESS_ENTER*/); for (auto value : values) m_combo->Append(from_u8(value)); - m_combo->Bind(wxEVT_TEXT_ENTER, [this](wxCommandEvent&) { accept(); }); - m_combo->Bind(wxEVT_TEXT, [this](wxCommandEvent&) { - update(normalize_utf8_nfc(m_combo->GetValue().ToUTF8())); - this->Layout(); - this->Fit(); - }); + m_combo->Bind(wxEVT_TEXT, [this](wxCommandEvent&) { update(); }); - sizer->Add(label_top, 0, wxEXPAND | wxALL, BORDER_W); - sizer->Add(m_combo, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, BORDER_W); + m_valid_label = new wxStaticText(m_parent, wxID_ANY, ""); + m_valid_label->SetFont(wxGetApp().bold_font()); + + wxBoxSizer* combo_sizer = new wxBoxSizer(wxHORIZONTAL); + combo_sizer->Add(m_valid_bmp, 0, wxEXPAND | wxRIGHT, BORDER_W); + combo_sizer->Add(m_combo, 1, wxEXPAND, BORDER_W); + + sizer->Add(label_top, 0, wxEXPAND | wxTOP| wxBOTTOM, BORDER_W); + sizer->Add(combo_sizer, 0, wxEXPAND | wxBOTTOM, BORDER_W); + sizer->Add(m_valid_label, 0, wxEXPAND | wxLEFT, 3*BORDER_W/* + m_valid_bmp->GetBitmap().GetWidth()*/); + + if (m_type == Preset::TYPE_PRINTER) + m_parent->add_info_for_edit_ph_printer(sizer); + + update(); } -void SavePresetDialog::add_items_for_edit_ph_printer(wxBoxSizer* sizer) +void SavePresetDialog::Item::update() { - if (m_preset_cb->type() != Preset::TYPE_PRINTER || !m_preset_cb->is_selected_physical_printer()) - return; + m_preset_name = into_u8(m_combo->GetValue()); + m_valid_type = Valid; + wxString info_line; + + const char* unusable_symbols = "<>[]:/\\|?*\""; + + const std::string unusable_suffix = PresetCollection::get_suffix_modified();//"(modified)"; + for (size_t i = 0; i < std::strlen(unusable_symbols); i++) { + if (m_preset_name.find_first_of(unusable_symbols[i]) != std::string::npos) { + info_line = _L("The supplied name is not valid;") + "\n" + + _L("the following characters are not allowed:") + " " + unusable_symbols; + m_valid_type = NoValid; + break; + } + } + + if (m_valid_type == Valid && m_preset_name.find(unusable_suffix) != std::string::npos) { + info_line = _L("The supplied name is not valid;") + "\n" + + _L("the following suffix is not allowed:") + "\n\t" + + from_u8(PresetCollection::get_suffix_modified()); + m_valid_type = NoValid; + } + + if (m_valid_type == Valid && m_preset_name == "- default -") { + info_line = _L("The supplied name is not available."); + m_valid_type = NoValid; + } + + const Preset* existing = m_presets->find_preset(m_preset_name, false); + if (m_valid_type == Valid && existing && (existing->is_default || existing->is_system)) { + info_line = _L("Cannot overwrite a system profile."); + m_valid_type = NoValid; + } + if (m_valid_type == Valid && existing && (existing->is_external)) { + info_line = _L("Cannot overwrite an external profile."); + m_valid_type = NoValid; + } + if (m_valid_type == Valid && existing && m_preset_name != m_presets->get_selected_preset_name()) + { + info_line = from_u8((boost::format(_u8L("Preset with name \"%1%\" already exists.")) % m_preset_name).str()) + "\n" + + _L("Note: This preset will be replaced after saving"); + m_valid_type = Warning; + } + + m_valid_label->SetLabel(info_line); + m_valid_label->Show(!info_line.IsEmpty()); + + std::string bmp_name = m_valid_type == Warning ? "exclamation" : + m_valid_type == NoValid ? "cross" : "tick_mark" ; + m_valid_bmp->SetBitmap(create_scaled_bitmap(bmp_name, m_parent)); + + if (m_type == Preset::TYPE_PRINTER) + m_parent->update_info_for_edit_ph_printer(m_preset_name); + + m_parent->layout(); +} + +void SavePresetDialog::Item::accept() +{ + if (m_valid_type == Warning) + m_presets->delete_preset(m_preset_name); +} + + +//----------------------------------------------- +// SavePresetDialog +//----------------------------------------------- + +SavePresetDialog::SavePresetDialog(Preset::Type type, const std::string& suffix) + : DPIDialog(nullptr, wxID_ANY, _L("Save preset"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), 5 * wxGetApp().em_unit()), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING | wxRESIZE_BORDER) +{ + SetFont(wxGetApp().normal_font()); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + + wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); + + m_presets_sizer = new wxBoxSizer(wxVERTICAL); + + // Add first item + m_items.emplace_back(type, suffix, m_presets_sizer, this); + + // Add dialog's buttons + wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); + wxButton* btnOK = static_cast(this->FindWindowById(wxID_OK, this)); + btnOK->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { accept(); }); + btnOK->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(enable_ok_btn()); }); + + topSizer->Add(m_presets_sizer, 0, wxEXPAND | wxALL, BORDER_W); + topSizer->Add(btns, 0, wxEXPAND | wxALL, BORDER_W); + + SetSizer(topSizer); + topSizer->SetSizeHints(this); +} + +void SavePresetDialog::AddItem(Preset::Type type, const std::string& suffix) +{ + m_items.emplace_back(type, suffix, m_presets_sizer, this); +} + +std::string SavePresetDialog::get_name() +{ + return m_items.front().preset_name(); +} + +std::string SavePresetDialog::get_name(Preset::Type type) +{ + for (Item& item : m_items) + if (item.type() == type) + return item.preset_name(); + return ""; +} + +bool SavePresetDialog::enable_ok_btn() const +{ + for (Item item : m_items) + if (!item.is_valid()) + return false; + + return true; +} + +void SavePresetDialog::add_info_for_edit_ph_printer(wxBoxSizer* sizer) +{ PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers; m_ph_printer_name = printers.get_selected_printer_name(); m_old_preset_name = printers.get_selected_printer_preset_name(); @@ -1102,6 +1214,7 @@ void SavePresetDialog::add_items_for_edit_ph_printer(wxBoxSizer* sizer) m_action_radio_box = new wxRadioBox(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, WXSIZEOF(choices), choices, 3, wxRA_SPECIFY_ROWS); m_action_radio_box->SetFont(wxGetApp().normal_font()); + m_action_radio_box->SetLabelFont(wxGetApp().normal_font()); m_action_radio_box->SetSelection(0); m_action_radio_box->Bind(wxEVT_RADIOBOX, [this](wxCommandEvent& e) { m_action = (ActionType)e.GetSelection(); }); @@ -1110,18 +1223,13 @@ void SavePresetDialog::add_items_for_edit_ph_printer(wxBoxSizer* sizer) m_radio_sizer = new wxBoxSizer(wxHORIZONTAL); m_radio_sizer->Add(m_action_radio_box, 1, wxALIGN_CENTER_VERTICAL); - sizer->Add(m_label, 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); - sizer->Add(m_radio_sizer, 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); - - update(m_preset_name); + sizer->Add(m_label, 0, wxEXPAND | wxALL, 2*BORDER_W); + sizer->Add(m_radio_sizer, 1, wxEXPAND | wxLEFT, 2*BORDER_W); } -void SavePresetDialog::update(const std::string& preset_name) +void SavePresetDialog::update_info_for_edit_ph_printer(const std::string& preset_name) { - if (m_preset_cb->type() != Preset::TYPE_PRINTER || !m_preset_cb->is_selected_physical_printer()) - return; - - bool show = m_old_preset_name != preset_name; + bool show = wxGetApp().preset_bundle->physical_printers.has_selection() && m_old_preset_name != preset_name; m_label->Show(show); m_radio_sizer->ShowItems(show); @@ -1142,6 +1250,12 @@ void SavePresetDialog::update(const std::string& preset_name) m_action_radio_box->SetString(n++, label); } +void SavePresetDialog::layout() +{ + this->Layout(); + this->Fit(); +} + void SavePresetDialog::on_dpi_changed(const wxRect& suggested_rect) { const int& em = em_unit(); @@ -1149,65 +1263,13 @@ void SavePresetDialog::on_dpi_changed(const wxRect& suggested_rect) msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL }); const wxSize& size = wxSize(45 * em, 35 * em); - SetMinSize(size); + SetMinSize(/*size*/wxSize(100, 50)); Fit(); Refresh(); } -bool SavePresetDialog::preset_name_is_accepted() -{ - const char* unusable_symbols = "<>[]:/\\|?*\""; - const std::string unusable_suffix = PresetCollection::get_suffix_modified();//"(modified)"; - for (size_t i = 0; i < std::strlen(unusable_symbols); i++) { - if (m_preset_name.find_first_of(unusable_symbols[i]) != std::string::npos) { - show_error(this, _L("The supplied name is not valid;") + "\n" + - _L("the following characters are not allowed:") + " " + unusable_symbols); - return false; - } - } - - if (m_preset_name.find(unusable_suffix) != std::string::npos) { - show_error(this, _L("The supplied name is not valid;") + "\n" + - _L("the following suffix is not allowed:") + "\n\t" + - from_u8(PresetCollection::get_suffix_modified())); - return false; - } - - if (m_preset_name == "- default -") { - show_error(this, _L("The supplied name is not available.")); - return false; - } - return true; -} - -bool SavePresetDialog::preset_is_possible_to_save() -{ - const Preset* existing = m_preset_cb->presets()->find_preset(m_preset_name, false); - if (existing && (existing->is_default || existing->is_system)) { - show_error(this, _L("Cannot overwrite a system profile.")); - return false; - } - if (existing && (existing->is_external)) { - show_error(this, _(L("Cannot overwrite an external profile."))); - return false; - } - if (existing && m_preset_name != m_preset_cb->presets()->get_selected_preset_name()) - { - wxString msg_text = GUI::from_u8((boost::format(_utf8(L("Preset with name \"%1%\" already exists."))) % m_preset_name).str()); - msg_text += "\n" + _L("Replace?"); - wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO); - - if (dialog.ShowModal() == wxID_NO) - return false; - - // Remove the preset from the list. - m_preset_cb->presets()->delete_preset(m_preset_name); - } - return true; -} - -void SavePresetDialog::update_physical_printers() +void SavePresetDialog::update_physical_printers(const std::string& preset_name) { if (m_action == UndefAction) return; @@ -1228,29 +1290,20 @@ void SavePresetDialog::update_physical_printers() if (m_action == ChangePreset) printer.delete_preset(printer_preset_name); - if (printer.add_preset(m_preset_name)) + if (printer.add_preset(preset_name)) physical_printers.save_printer(printer); - else { - wxMessageDialog dialog(nullptr, _L("This preset is already exist for this physical printer. Please, select another one."), _L("Information"), wxICON_INFORMATION | wxOK); - dialog.ShowModal(); - } - physical_printers.select_printer(printer.get_full_name(m_preset_name)); + physical_printers.select_printer(printer.get_full_name(preset_name)); } } void SavePresetDialog::accept() { - m_preset_name = normalize_utf8_nfc(m_combo->GetValue().ToUTF8()); - - if (m_preset_name.empty()) - return; - - if (!preset_name_is_accepted() || - !preset_is_possible_to_save()) - return; - - update_physical_printers(); + for (Item& item : m_items) { + item.accept(); + if (item.type() == Preset::TYPE_PRINTER) + update_physical_printers(item.preset_name()); + } EndModal(wxID_OK); } diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index a30d9f6e9..c0de645df 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -14,6 +14,7 @@ class wxStaticText; class ScalableButton; class wxBoxSizer; class wxComboBox; +class wxStaticBitmap; namespace Slic3r { @@ -200,35 +201,70 @@ class SavePresetDialog : public DPIDialog UndefAction }; - TabPresetComboBox* m_preset_cb {nullptr}; - std::string m_preset_name; - wxComboBox* m_combo {nullptr}; - wxStaticText* m_label {nullptr}; + struct Item + { + enum ValidationType + { + Valid, + NoValid, + Warning + }; + + Item(Preset::Type type, const std::string& suffix, wxBoxSizer* sizer, SavePresetDialog* parent); + + void accept(); + + bool is_valid() const { return m_valid_type != NoValid; } + Preset::Type type() const { return m_type; } + std::string preset_name() const { return m_preset_name; } + + private: + Preset::Type m_type; + ValidationType m_valid_type; + std::string m_preset_name; + + SavePresetDialog* m_parent {nullptr}; + wxStaticBitmap* m_valid_bmp {nullptr}; + wxComboBox* m_combo {nullptr}; + wxStaticText* m_valid_label {nullptr}; + + PresetCollection* m_presets {nullptr}; + + void update(); + }; + + std::vector m_items; + + wxBoxSizer* m_presets_sizer {nullptr}; + wxStaticText* m_label {nullptr}; wxRadioBox* m_action_radio_box {nullptr}; wxBoxSizer* m_radio_sizer {nullptr}; ActionType m_action {UndefAction}; - std::string m_ph_printer_name; - std::string m_old_preset_name; + std::string m_ph_printer_name; + std::string m_old_preset_name; public: - SavePresetDialog(TabPresetComboBox* preset_cb, const std::string& suffix); + SavePresetDialog(Preset::Type type, const std::string& suffix); ~SavePresetDialog() {} - std::string get_name() { return m_preset_name; } + void AddItem(Preset::Type type, const std::string& suffix); + + std::string get_name(); + std::string get_name(Preset::Type type); + + bool enable_ok_btn() const; + void add_info_for_edit_ph_printer(wxBoxSizer *sizer); + void update_info_for_edit_ph_printer(const std::string &preset_name); + void layout(); protected: void on_dpi_changed(const wxRect& suggested_rect) override; void on_sys_color_changed() override {} private: - void add_common_items(wxBoxSizer *sizer, const std::string &suffix); - void add_items_for_edit_ph_printer(wxBoxSizer *sizer); - void update(const std::string &preset_name); - bool preset_name_is_accepted(); - bool preset_is_possible_to_save(); - void update_physical_printers(); + void update_physical_printers(const std::string& preset_name); void accept(); }; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 4dbe7cc74..9d37362ba 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3262,7 +3262,7 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach) std::string suffix = detach ? _utf8(L("Detached")) : _CTX_utf8(L_CONTEXT("Copy", "PresetName"), "PresetName"); if (name.empty()) { - SavePresetDialog dlg(m_presets_choice, suffix); + SavePresetDialog dlg(m_type, suffix); if (dlg.ShowModal() != wxID_OK) return; name = dlg.get_name(); From d84e70f59afaf7c052462f6a7cadf1fa28876eb9 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 30 Jul 2020 09:43:13 +0200 Subject: [PATCH 24/31] SavePresetDialog: Fixed OSX and Linux build + Added scaling of the validation icons --- src/slic3r/GUI/PresetComboBoxes.cpp | 34 ++++++++++++++++------------- src/slic3r/GUI/PresetComboBoxes.hpp | 1 + 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 35acbfd3a..77bdb3812 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -1049,9 +1049,8 @@ SavePresetDialog::Item::Item(Preset::Type type, const std::string& suffix, wxBox m_valid_bmp = new wxStaticBitmap(m_parent, wxID_ANY, create_scaled_bitmap("tick_mark", m_parent)); - m_combo = new wxComboBox(m_parent, wxID_ANY, from_u8(preset_name)/*, - wxDefaultPosition, wxDefaultSize, 0, 0, wxTE_PROCESS_ENTER*/); - for (auto value : values) + m_combo = new wxComboBox(m_parent, wxID_ANY, from_u8(preset_name)); + for (const std::string& value : values) m_combo->Append(from_u8(value)); m_combo->Bind(wxEVT_TEXT, [this](wxCommandEvent&) { update(); }); @@ -1060,12 +1059,12 @@ SavePresetDialog::Item::Item(Preset::Type type, const std::string& suffix, wxBox m_valid_label->SetFont(wxGetApp().bold_font()); wxBoxSizer* combo_sizer = new wxBoxSizer(wxHORIZONTAL); - combo_sizer->Add(m_valid_bmp, 0, wxEXPAND | wxRIGHT, BORDER_W); + combo_sizer->Add(m_valid_bmp, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, BORDER_W); combo_sizer->Add(m_combo, 1, wxEXPAND, BORDER_W); sizer->Add(label_top, 0, wxEXPAND | wxTOP| wxBOTTOM, BORDER_W); sizer->Add(combo_sizer, 0, wxEXPAND | wxBOTTOM, BORDER_W); - sizer->Add(m_valid_label, 0, wxEXPAND | wxLEFT, 3*BORDER_W/* + m_valid_bmp->GetBitmap().GetWidth()*/); + sizer->Add(m_valid_label, 0, wxEXPAND | wxLEFT, 3*BORDER_W); if (m_type == Preset::TYPE_PRINTER) m_parent->add_info_for_edit_ph_printer(sizer); @@ -1123,9 +1122,7 @@ void SavePresetDialog::Item::update() m_valid_label->SetLabel(info_line); m_valid_label->Show(!info_line.IsEmpty()); - std::string bmp_name = m_valid_type == Warning ? "exclamation" : - m_valid_type == NoValid ? "cross" : "tick_mark" ; - m_valid_bmp->SetBitmap(create_scaled_bitmap(bmp_name, m_parent)); + update_valid_bmp(); if (m_type == Preset::TYPE_PRINTER) m_parent->update_info_for_edit_ph_printer(m_preset_name); @@ -1133,6 +1130,13 @@ void SavePresetDialog::Item::update() m_parent->layout(); } +void SavePresetDialog::Item::update_valid_bmp() +{ + std::string bmp_name = m_valid_type == Warning ? "exclamation" : + m_valid_type == NoValid ? "cross" : "tick_mark" ; + m_valid_bmp->SetBitmap(create_scaled_bitmap(bmp_name, m_parent)); +} + void SavePresetDialog::Item::accept() { if (m_valid_type == Warning) @@ -1147,7 +1151,6 @@ void SavePresetDialog::Item::accept() SavePresetDialog::SavePresetDialog(Preset::Type type, const std::string& suffix) : DPIDialog(nullptr, wxID_ANY, _L("Save preset"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), 5 * wxGetApp().em_unit()), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING | wxRESIZE_BORDER) { - SetFont(wxGetApp().normal_font()); SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); @@ -1213,18 +1216,16 @@ void SavePresetDialog::add_info_for_edit_ph_printer(wxBoxSizer* sizer) m_action_radio_box = new wxRadioBox(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, WXSIZEOF(choices), choices, 3, wxRA_SPECIFY_ROWS); - m_action_radio_box->SetFont(wxGetApp().normal_font()); - m_action_radio_box->SetLabelFont(wxGetApp().normal_font()); m_action_radio_box->SetSelection(0); m_action_radio_box->Bind(wxEVT_RADIOBOX, [this](wxCommandEvent& e) { m_action = (ActionType)e.GetSelection(); }); m_action = ChangePreset; m_radio_sizer = new wxBoxSizer(wxHORIZONTAL); - m_radio_sizer->Add(m_action_radio_box, 1, wxALIGN_CENTER_VERTICAL); + m_radio_sizer->Add(m_action_radio_box, 1, wxEXPAND | wxTOP, 2*BORDER_W); - sizer->Add(m_label, 0, wxEXPAND | wxALL, 2*BORDER_W); - sizer->Add(m_radio_sizer, 1, wxEXPAND | wxLEFT, 2*BORDER_W); + sizer->Add(m_label, 0, wxEXPAND | wxLEFT | wxTOP, 3*BORDER_W); + sizer->Add(m_radio_sizer, 1, wxEXPAND | wxLEFT, 3*BORDER_W); } void SavePresetDialog::update_info_for_edit_ph_printer(const std::string& preset_name) @@ -1262,7 +1263,10 @@ void SavePresetDialog::on_dpi_changed(const wxRect& suggested_rect) msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL }); - const wxSize& size = wxSize(45 * em, 35 * em); + for (Item& item : m_items) + item.update_valid_bmp(); + + //const wxSize& size = wxSize(45 * em, 35 * em); SetMinSize(/*size*/wxSize(100, 50)); Fit(); diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index c0de645df..f31b67fbe 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -212,6 +212,7 @@ class SavePresetDialog : public DPIDialog Item(Preset::Type type, const std::string& suffix, wxBoxSizer* sizer, SavePresetDialog* parent); + void update_valid_bmp(); void accept(); bool is_valid() const { return m_valid_type != NoValid; } From 5eb3b21be791003fa575066c4d1096e9b879f509 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 30 Jul 2020 09:45:45 +0200 Subject: [PATCH 25/31] Added missed icons/tick_mark.svg --- resources/icons/tick_mark.svg | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 resources/icons/tick_mark.svg diff --git a/resources/icons/tick_mark.svg b/resources/icons/tick_mark.svg new file mode 100644 index 000000000..4ccab2192 --- /dev/null +++ b/resources/icons/tick_mark.svg @@ -0,0 +1,6 @@ + + + + + + From 171acf094c3b3a7320ab665a041a4bf2ba5b62fb Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 5 Aug 2020 16:34:01 +0200 Subject: [PATCH 26/31] Change license of libnest2d to LGPLv3 --- src/libnest2d/LICENSE.txt | 816 ++++++++------------------------------ 1 file changed, 160 insertions(+), 656 deletions(-) diff --git a/src/libnest2d/LICENSE.txt b/src/libnest2d/LICENSE.txt index dba13ed2d..07b1d92c0 100644 --- a/src/libnest2d/LICENSE.txt +++ b/src/libnest2d/LICENSE.txt @@ -1,661 +1,165 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. \ No newline at end of file From 1079d4644c04d075e783d3fb3ad59f13077fae32 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 6 Aug 2020 10:40:04 +0200 Subject: [PATCH 27/31] PhysicalPrinterDialog improvements : Printer device default name is changed to force the user to change it SavePresetDialog : Fixed OSX bug, when wxEVT_TEXT wasn't invoked after change selection in ComboBox --- src/slic3r/GUI/PhysicalPrinterDialog.cpp | 12 +++++++++--- src/slic3r/GUI/PresetComboBoxes.cpp | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp index f14f49801..12d1cd287 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp @@ -161,13 +161,15 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) SetFont(wxGetApp().normal_font()); SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - m_default_name = _L("My Printer Device"); + m_default_name = _L("Type here the name of your printer device"); + bool new_printer = true; if (printer_name.IsEmpty()) printer_name = m_default_name; else { std::string full_name = into_u8(printer_name); printer_name = from_u8(PhysicalPrinter::get_short_name(full_name)); + new_printer = false; } wxStaticText* label_top = new wxStaticText(this, wxID_ANY, _L("Descriptive name for the printer device") + ":"); @@ -206,7 +208,6 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) m_optgroup = new ConfigOptionsGroup(this, _L("Print Host upload"), m_config); build_printhost_settings(m_optgroup); - //m_optgroup->reload_config(); wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); wxButton* btnOK = static_cast(this->FindWindowById(wxID_OK, this)); @@ -230,6 +231,11 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) SetSizer(topSizer); topSizer->SetSizeHints(this); + + if (new_printer) { + m_printer_name->SetFocus(); + m_printer_name->SelectAll(); + } } PhysicalPrinterDialog::~PhysicalPrinterDialog() @@ -494,7 +500,7 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event) std::string renamed_from; // temporary save previous printer name if it was edited - if (m_printer.name != _u8L("My Printer Device") && + if (m_printer.name != into_u8(m_default_name) && m_printer.name != into_u8(printer_name)) renamed_from = m_printer.name; diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 77bdb3812..da33ee51a 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -1054,6 +1054,11 @@ SavePresetDialog::Item::Item(Preset::Type type, const std::string& suffix, wxBox m_combo->Append(from_u8(value)); m_combo->Bind(wxEVT_TEXT, [this](wxCommandEvent&) { update(); }); +#ifdef __WXOSX__ + // Under OSX wxEVT_TEXT wasn't invoked after change selection in combobox, + // So process wxEVT_COMBOBOX too + m_combo->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent&) { update(); }); +#endif //__WXOSX__ m_valid_label = new wxStaticText(m_parent, wxID_ANY, ""); m_valid_label->SetFont(wxGetApp().bold_font()); From 41b1dc3d80d43f4a2df141edd3d4b5bd1ee24ce1 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 6 Aug 2020 14:05:42 +0200 Subject: [PATCH 28/31] Fix of custom supports 3MF loading Multiple-part objects were not handled correctly --- src/libslic3r/Format/3mf.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 3612e6898..59dc85a0a 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -1878,10 +1878,11 @@ namespace Slic3r { volume->calculate_convex_hull(); // recreate custom supports from previously loaded attribute - assert(geometry.custom_supports.size() == triangles_count); for (unsigned i=0; im_supported_facets.set_triangle_from_string(i, geometry.custom_supports[i]); + size_t index = src_start_id/3 + i; + assert(index < geometry.custom_supports.size()); + if (! geometry.custom_supports[index].empty()) + volume->m_supported_facets.set_triangle_from_string(i, geometry.custom_supports[index]); } // apply the remaining volume's metadata From b6746a3937f89a27092e3119c38c1c2cbd9e373b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 7 Aug 2020 10:00:54 +0200 Subject: [PATCH 29/31] PhysicalPrinterDialog : Incompatible presets extracted to the separate group --- src/slic3r/GUI/PresetComboBoxes.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index da33ee51a..33ae4f54e 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -179,7 +179,9 @@ void PresetComboBox::update(std::string select_preset_name) const std::deque& presets = m_collection->get_presets(); - std::map> nonsys_presets; + std::map> nonsys_presets; + std::map incomp_presets; + wxString selected = ""; if (!presets.front().is_visible) set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); @@ -206,15 +208,15 @@ void PresetComboBox::update(std::string select_preset_name) wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "lock_closed", is_enabled, preset.is_compatible, preset.is_system || preset.is_default); assert(bmp); - if (preset.is_default || preset.is_system) { - int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp); - if (!is_enabled) - set_label_marker(item_id, LABEL_ITEM_DISABLED); + if (!is_enabled) + incomp_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), bmp); + else if (preset.is_default || preset.is_system) + { + Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp); validate_selection(preset.name == select_preset_name); } else { - 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 (preset.name == select_preset_name || (select_preset_name.empty() && is_enabled)) selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); @@ -233,6 +235,13 @@ void PresetComboBox::update(std::string select_preset_name) validate_selection(it->first == selected); } } + if (!incomp_presets.empty()) + { + set_label_marker(Append(separator(L("Incompatible presets")), wxNullBitmap)); + for (std::map::iterator it = incomp_presets.begin(); it != incomp_presets.end(); ++it) { + set_label_marker(Append(it->first, *it->second), LABEL_ITEM_DISABLED); + } + } update_selection(); Thaw(); From afcc14861f2c2a06f8d802c41af110e2e5476b1e Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 7 Aug 2020 10:42:25 +0200 Subject: [PATCH 30/31] Fix build on GCC (missing forward declaration) --- src/slic3r/GUI/PresetComboBoxes.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index f31b67fbe..7f51f775e 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -15,6 +15,7 @@ class ScalableButton; class wxBoxSizer; class wxComboBox; class wxStaticBitmap; +class wxRadioBox; namespace Slic3r { From f9e47b27028b7f513cea29843249894ae105ebc7 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Sat, 8 Aug 2020 17:03:20 +0200 Subject: [PATCH 31/31] Code refactoring: AppConfig.cpp(hpp) are removed from the GUI to libslic3r --- src/PrusaSlicer.cpp | 2 +- src/{slic3r/GUI => libslic3r}/AppConfig.cpp | 12 +++++++++--- src/{slic3r/GUI => libslic3r}/AppConfig.hpp | 3 ++- src/libslic3r/CMakeLists.txt | 2 ++ src/libslic3r/Preset.cpp | 2 +- src/libslic3r/PresetBundle.hpp | 3 +-- src/slic3r/CMakeLists.txt | 2 -- src/slic3r/Config/Snapshot.cpp | 1 - src/slic3r/GUI/3DScene.cpp | 2 +- src/slic3r/GUI/Camera.cpp | 2 +- src/slic3r/GUI/ConfigWizard_private.hpp | 1 - src/slic3r/GUI/GUI_App.cpp | 9 +++++++-- src/slic3r/GUI/Jobs/SLAImportJob.cpp | 1 - src/slic3r/GUI/MainFrame.cpp | 1 - src/slic3r/GUI/Mouse3DController.cpp | 1 - src/slic3r/GUI/Preferences.cpp | 2 +- src/slic3r/GUI/PrintHostDialogs.cpp | 2 +- 17 files changed, 27 insertions(+), 21 deletions(-) rename src/{slic3r/GUI => libslic3r}/AppConfig.cpp (97%) rename src/{slic3r/GUI => libslic3r}/AppConfig.hpp (99%) diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp index a0422f5fa..c37afb805 100644 --- a/src/PrusaSlicer.cpp +++ b/src/PrusaSlicer.cpp @@ -44,6 +44,7 @@ #include "libslic3r/Format/OBJ.hpp" #include "libslic3r/Format/SL1.hpp" #include "libslic3r/Utils.hpp" +#include "libslic3r/AppConfig.hpp" #include "PrusaSlicer.hpp" @@ -52,7 +53,6 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/InstanceCheck.hpp" - #include "slic3r/GUI/AppConfig.hpp" #include "slic3r/GUI/MainFrame.hpp" #include "slic3r/GUI/Plater.hpp" #endif /* SLIC3R_GUI */ diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/libslic3r/AppConfig.cpp similarity index 97% rename from src/slic3r/GUI/AppConfig.cpp rename to src/libslic3r/AppConfig.cpp index 93589e536..8b41bd271 100644 --- a/src/slic3r/GUI/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -15,8 +15,8 @@ #include #include -#include -#include "I18N.hpp" +//#include +//#include "I18N.hpp" namespace Slic3r { @@ -110,7 +110,7 @@ void AppConfig::set_defaults() erase("", "object_settings_size"); } -void AppConfig::load() +std::string AppConfig::load() { // 1) Read the complete config file into a boost::property_tree. namespace pt = boost::property_tree; @@ -120,10 +120,15 @@ void AppConfig::load() pt::read_ini(ifs, tree); } catch (pt::ptree_error& ex) { // Error while parsing config file. We'll customize the error message and rethrow to be displayed. + // ! But to avoid the use of _utf8 (related to use of wxWidgets) + // we will rethrow this exception from the place of load() call, if returned value wouldn't be empty + /* throw std::runtime_error( _utf8(L("Error parsing PrusaSlicer config file, it is probably corrupted. " "Try to manually delete the file to recover from the error. Your user profiles will not be affected.")) + "\n\n" + AppConfig::config_path() + "\n\n" + ex.what()); + */ + return ex.what(); } // 2) Parse the property_tree, extract the sections and key / value pairs. @@ -169,6 +174,7 @@ void AppConfig::load() // Override missing or keys with their defaults. this->set_defaults(); m_dirty = false; + return ""; } void AppConfig::save() diff --git a/src/slic3r/GUI/AppConfig.hpp b/src/libslic3r/AppConfig.hpp similarity index 99% rename from src/slic3r/GUI/AppConfig.hpp rename to src/libslic3r/AppConfig.hpp index 1e90d32e0..ffd1b9fdf 100644 --- a/src/slic3r/GUI/AppConfig.hpp +++ b/src/libslic3r/AppConfig.hpp @@ -29,7 +29,8 @@ public: void set_defaults(); // Load the slic3r.ini from a user profile directory (or a datadir, if configured). - void load(); + // return error string or empty strinf + std::string load(); // Store the slic3r.ini into a user profile directory (or a datadir, if configured). void save(); diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index f11a6e7c2..290b8953c 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -151,6 +151,8 @@ add_library(libslic3r STATIC Preset.hpp PresetBundle.cpp PresetBundle.hpp + AppConfig.cpp + AppConfig.hpp Print.cpp Print.hpp PrintBase.cpp diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 44e6675d1..7176ca81a 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1,7 +1,7 @@ #include #include "Preset.hpp" -#include "slic3r/GUI/AppConfig.hpp" +#include "AppConfig.hpp" #ifdef _MSC_VER #define WIN32_LEAN_AND_MEAN diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 2906584d3..567a12331 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -2,13 +2,12 @@ #define slic3r_PresetBundle_hpp_ #include "Preset.hpp" +#include "AppConfig.hpp" #include #include #include -#include "slic3r/GUI/AppConfig.hpp" - namespace Slic3r { // Bundle of Print + Filament + Printer presets. diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 849460792..f8598cea0 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -12,8 +12,6 @@ set(SLIC3R_GUI_SOURCES GUI/SysInfoDialog.hpp GUI/KBShortcutsDialog.cpp GUI/KBShortcutsDialog.hpp - GUI/AppConfig.cpp - GUI/AppConfig.hpp GUI/BackgroundSlicingProcess.cpp GUI/BackgroundSlicingProcess.hpp GUI/BitmapCache.cpp diff --git a/src/slic3r/Config/Snapshot.cpp b/src/slic3r/Config/Snapshot.cpp index f7d313418..30596b614 100644 --- a/src/slic3r/Config/Snapshot.cpp +++ b/src/slic3r/Config/Snapshot.cpp @@ -1,5 +1,4 @@ #include "Snapshot.hpp" -#include "../GUI/AppConfig.hpp" #include diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 5dc0d430f..d683fd90c 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -10,7 +10,6 @@ #if ENABLE_ENVIRONMENT_MAP #include "GUI_App.hpp" #include "Plater.hpp" -#include "AppConfig.hpp" #endif // ENABLE_ENVIRONMENT_MAP #include "libslic3r/ExtrusionEntity.hpp" @@ -24,6 +23,7 @@ #include "slic3r/GUI/BitmapCache.hpp" #include "libslic3r/Format/STL.hpp" #include "libslic3r/Utils.hpp" +#include "libslic3r/AppConfig.hpp" #include #include diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp index ac32767c4..c1bf8e825 100644 --- a/src/slic3r/GUI/Camera.cpp +++ b/src/slic3r/GUI/Camera.cpp @@ -1,8 +1,8 @@ #include "libslic3r/libslic3r.h" +#include "libslic3r/AppConfig.hpp" #include "Camera.hpp" #include "GUI_App.hpp" -#include "AppConfig.hpp" #if ENABLE_CAMERA_STATISTICS #include "Mouse3DController.hpp" #endif // ENABLE_CAMERA_STATISTICS diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index be2919861..9921552a7 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -22,7 +22,6 @@ #include "libslic3r/PrintConfig.hpp" #include "libslic3r/PresetBundle.hpp" #include "slic3r/Utils/PresetUpdater.hpp" -#include "AppConfig.hpp" #include "BedShapeDialog.hpp" #include "GUI.hpp" #include "wxExtensions.hpp" diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 38bda5f5e..82c2861bc 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -38,7 +38,6 @@ #include "GUI.hpp" #include "GUI_Utils.hpp" -#include "AppConfig.hpp" #include "3DScene.hpp" #include "MainFrame.hpp" #include "Plater.hpp" @@ -326,7 +325,13 @@ void GUI_App::init_app_config() // load settings app_conf_exists = app_config->exists(); if (app_conf_exists) { - app_config->load(); + std::string error = app_config->load(); + if (!error.empty()) + // Error while parsing config file. We'll customize the error message and rethrow to be displayed. + throw std::runtime_error( + _u8L("Error parsing PrusaSlicer config file, it is probably corrupted. " + "Try to manually delete the file to recover from the error. Your user profiles will not be affected.") + + "\n\n" + AppConfig::config_path() + "\n\n" + error); } } diff --git a/src/slic3r/GUI/Jobs/SLAImportJob.cpp b/src/slic3r/GUI/Jobs/SLAImportJob.cpp index cc779df2a..2d5d5b072 100644 --- a/src/slic3r/GUI/Jobs/SLAImportJob.cpp +++ b/src/slic3r/GUI/Jobs/SLAImportJob.cpp @@ -2,7 +2,6 @@ #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI_App.hpp" -#include "slic3r/GUI/AppConfig.hpp" #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp" #include "slic3r/Utils/SLAImport.hpp" diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 084280300..bbc1da534 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -20,7 +20,6 @@ #include "Tab.hpp" #include "ProgressStatusBar.hpp" #include "3DScene.hpp" -#include "AppConfig.hpp" #include "PrintHostDialogs.hpp" #include "wxExtensions.hpp" #include "GUI_ObjectList.hpp" diff --git a/src/slic3r/GUI/Mouse3DController.cpp b/src/slic3r/GUI/Mouse3DController.cpp index 9bbbf92a0..4c5ee2076 100644 --- a/src/slic3r/GUI/Mouse3DController.cpp +++ b/src/slic3r/GUI/Mouse3DController.cpp @@ -4,7 +4,6 @@ #include "Camera.hpp" #include "GUI_App.hpp" -#include "AppConfig.hpp" #include "GLCanvas3D.hpp" #include "Plater.hpp" #include "NotificationManager.hpp" diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 4b5808e16..242c3d851 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1,8 +1,8 @@ #include "Preferences.hpp" -#include "AppConfig.hpp" #include "OptionsGroup.hpp" #include "GUI_App.hpp" #include "I18N.hpp" +#include "libslic3r/AppConfig.hpp" namespace Slic3r { namespace GUI { diff --git a/src/slic3r/GUI/PrintHostDialogs.cpp b/src/slic3r/GUI/PrintHostDialogs.cpp index bae60e47f..216af5df4 100644 --- a/src/slic3r/GUI/PrintHostDialogs.cpp +++ b/src/slic3r/GUI/PrintHostDialogs.cpp @@ -15,11 +15,11 @@ #include "GUI.hpp" #include "GUI_App.hpp" -#include "AppConfig.hpp" #include "MsgDialog.hpp" #include "I18N.hpp" #include "../Utils/PrintHost.hpp" #include "wxExtensions.hpp" +#include "libslic3r/AppConfig.hpp" namespace fs = boost::filesystem;