diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 79ae5d3001..1180698dd4 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -237,6 +237,9 @@ void AppConfig::set_defaults() if (get("enable_multi_machine").empty()) set_bool("enable_multi_machine", false); + if (get("drc_lossy_switch").empty()) + set_bool("drc_lossy_switch", false); + if (get("drc_bits").empty()) set("drc_bits", DRC_BITS_DEFAULT_STR); diff --git a/src/libslic3r/Format/DRC.hpp b/src/libslic3r/Format/DRC.hpp index 334157a70c..284af3364b 100644 --- a/src/libslic3r/Format/DRC.hpp +++ b/src/libslic3r/Format/DRC.hpp @@ -3,10 +3,10 @@ namespace Slic3r { -#define DRC_BITS_MIN 0 +#define DRC_BITS_MIN 8 #define DRC_BITS_MAX 30 -#define DRC_BITS_DEFAULT 0 -#define DRC_BITS_DEFAULT_STR "0" +#define DRC_BITS_DEFAULT 16 +#define DRC_BITS_DEFAULT_STR "16" class TriangleMesh; class ModelObject; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 89adf490de..929223f2da 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -14881,10 +14881,15 @@ void Plater::export_drc(bool extended, bool selection_only, bool multi_drcs) int speed = 0; AppConfig* app_config = wxGetApp().app_config; - if (app_config) bits = stoi(app_config->get("drc_bits")); - - if (bits < DRC_BITS_MIN) bits = DRC_BITS_MIN; - if (bits > DRC_BITS_MAX) bits = DRC_BITS_MAX; + if (app_config) { + if (app_config->get("drc_lossy_switch") == "true") { + bits = stoi(app_config->get("drc_bits")); + if (bits < DRC_BITS_MIN) bits = DRC_BITS_MIN; + if (bits > DRC_BITS_MAX) bits = DRC_BITS_MAX; + } else { + bits = 0; + } + } if (multi_drcs) { wxDirDialog dlg(this, _L("Choose a directory"), from_u8(wxGetApp().app_config->get_last_dir()), diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 61be19cabc..926c4f725a 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -795,6 +795,76 @@ wxBoxSizer *PreferencesDialog::create_item_auto_reslice(wxString title, wxString return sizer_row; } +wxBoxSizer* PreferencesDialog::create_item_draco(wxString title, wxString side_label, wxString tooltip) +{ + wxBoxSizer* m_sizer_input = new wxBoxSizer(wxHORIZONTAL); + + m_sizer_input->AddSpacer(FromDIP(DESIGN_LEFT_MARGIN)); + + auto checkbox_title = new wxStaticText(m_parent, wxID_ANY, title, wxDefaultPosition, DESIGN_TITLE_SIZE, wxST_NO_AUTORESIZE); + checkbox_title->SetForegroundColour(DESIGN_GRAY900_COLOR); + checkbox_title->SetFont(::Label::Body_14); + checkbox_title->Wrap(DESIGN_TITLE_SIZE.x); + checkbox_title->SetToolTip(tooltip); + + auto checkbox = new ::CheckBox(m_parent); + checkbox->SetValue(app_config->get_bool("drc_lossy_switch")); + checkbox->SetToolTip(tooltip); + + checkbox->Bind(wxEVT_TOGGLEBUTTON, [this, checkbox](wxCommandEvent& e) { + app_config->set_bool("drc_lossy_switch", checkbox->GetValue()); + app_config->save(); + if (m_draco_bits_textinput != nullptr) { + m_draco_bits_textinput->Enable(checkbox->GetValue()); + } + e.Skip(); + }); + + auto input = new ::TextInput(m_parent, wxEmptyString, side_label, wxEmptyString, wxDefaultPosition, wxSize(FromDIP(97), -1), wxTE_PROCESS_ENTER); + StateColor input_bg(std::pair(wxColour("#F0F0F1"), StateColor::Disabled), + std::pair(*wxWHITE, StateColor::Enabled)); + input->SetBackgroundColor(input_bg); + input->GetTextCtrl()->SetValue(app_config->get("drc_bits")); + wxTextValidator validator(wxFILTER_DIGITS); + input->SetToolTip(tooltip); + input->GetTextCtrl()->SetValidator(validator); + + m_sizer_input->Add(checkbox_title, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, FromDIP(3)); + m_sizer_input->Add(checkbox, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, FromDIP(5)); + m_sizer_input->Add(input, 0, wxALIGN_CENTER_VERTICAL); + + std::function set_draco_bits = [this, input]() { + long drc_bits = DRC_BITS_DEFAULT; + input->GetTextCtrl()->GetValue().ToLong(&drc_bits); + if (drc_bits > DRC_BITS_MAX) { + drc_bits = DRC_BITS_MAX; + input->GetTextCtrl()->SetValue(std::to_string(drc_bits)); + } else if (drc_bits < DRC_BITS_MIN) { + drc_bits = DRC_BITS_MIN; + input->GetTextCtrl()->SetValue(std::to_string(drc_bits)); + } + + app_config->set("drc_bits", std::to_string(drc_bits)); + app_config->save(); + }; + + input->GetTextCtrl()->Bind(wxEVT_TEXT_ENTER, [set_draco_bits](wxCommandEvent& e) { + set_draco_bits(); + e.Skip(); + }); + + input->GetTextCtrl()->Bind(wxEVT_KILL_FOCUS, [set_draco_bits](wxFocusEvent& e) { + set_draco_bits(); + e.Skip(); + }); + + input->Enable(app_config->get("drc_lossy_switch") == "true"); + input->Refresh(); + + m_draco_bits_textinput = input; + return m_sizer_input; +} + wxBoxSizer* PreferencesDialog::create_item_darkmode(wxString title,wxString tooltip, std::string param) { wxBoxSizer* m_sizer_checkbox = new wxBoxSizer(wxHORIZONTAL); @@ -1360,13 +1430,10 @@ void PreferencesDialog::create_items() g_sizer->Add(item_pop_up_filament_map_dialog); #endif - auto item_draco_position_bits = create_item_spinctrl(_L("Draco export dimensional accuracy"), - wxEmptyString, + auto item_draco_position_bits = create_item_draco(_L("Use lossy compression on Draco export"), _L("bits"), _L("Reducing the bits reduces the file precision and size.\n" - "0 disables quantization producing an effectively lossless but compressed file."), - "~16 bits may be recommended and within the tolerances of 3D printing.\n" - "drc_bits", DRC_BITS_MIN, DRC_BITS_MAX); + "~16 bits may be recommended and within the tolerances of 3D printing.")); g_sizer->Add(item_draco_position_bits); g_sizer->AddSpacer(FromDIP(10)); diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index c46c724702..bc80c5db98 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -12,6 +12,7 @@ #include "Widgets/ComboBox.hpp" #include "Widgets/CheckBox.hpp" #include "Widgets/TextInput.hpp" +#include "Widgets/SpinInput.hpp" #include "Widgets/TabCtrl.hpp" #include "slic3r/Utils/bambu_networking.hpp" @@ -68,6 +69,7 @@ public: ::CheckBox * m_internal_developer_mode_ckeckbox = {nullptr}; ::CheckBox * m_dark_mode_ckeckbox = {nullptr}; ::TextInput *m_backup_interval_textinput = {nullptr}; + ::TextInput *m_draco_bits_textinput = {nullptr}; ::ComboBox * m_network_version_combo = {nullptr}; wxBoxSizer * m_network_version_sizer = {nullptr}; std::vector m_available_versions; @@ -95,6 +97,7 @@ public: wxBoxSizer *create_camera_orbit_mult_input(wxString title, wxString tooltip); wxBoxSizer *create_item_backup(wxString title, wxString tooltip); wxBoxSizer *create_item_auto_reslice(wxString title, wxString checkbox_tooltip, wxString delay_tooltip); + wxBoxSizer* create_item_draco(wxString title, wxString side_label, wxString tooltip); wxBoxSizer *create_item_multiple_combobox(wxString title, wxString tooltip, std::string parama, std::vector vlista, std::vector vlistb); #ifdef WIN32 wxBoxSizer *create_item_link_association(wxString url_prefix, wxString website_name);