From 1a2926050fee0b5ab118054aaa4ccb65614d2063 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 25 Jun 2020 12:58:59 +0200 Subject: [PATCH] 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: