mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 08:47:52 -06:00
PhysicalPrinterDialog :: next improvement
This commit is contained in:
parent
257e77ed40
commit
b155c3c4f8
5 changed files with 702 additions and 591 deletions
|
@ -76,9 +76,11 @@ set(SLIC3R_GUI_SOURCES
|
||||||
GUI/MainFrame.cpp
|
GUI/MainFrame.cpp
|
||||||
GUI/MainFrame.hpp
|
GUI/MainFrame.hpp
|
||||||
GUI/Plater.cpp
|
GUI/Plater.cpp
|
||||||
|
GUI/Plater.hpp
|
||||||
GUI/PresetComboBoxes.hpp
|
GUI/PresetComboBoxes.hpp
|
||||||
GUI/PresetComboBoxes.cpp
|
GUI/PresetComboBoxes.cpp
|
||||||
GUI/Plater.hpp
|
GUI/PhysicalPrinterDialog.hpp
|
||||||
|
GUI/PhysicalPrinterDialog.cpp
|
||||||
GUI/GUI_ObjectList.cpp
|
GUI/GUI_ObjectList.cpp
|
||||||
GUI/GUI_ObjectList.hpp
|
GUI/GUI_ObjectList.hpp
|
||||||
GUI/GUI_ObjectManipulation.cpp
|
GUI/GUI_ObjectManipulation.cpp
|
||||||
|
|
556
src/slic3r/GUI/PhysicalPrinterDialog.cpp
Normal file
556
src/slic3r/GUI/PhysicalPrinterDialog.cpp
Normal file
|
@ -0,0 +1,556 @@
|
||||||
|
#include "PhysicalPrinterDialog.hpp"
|
||||||
|
#include "PresetComboBoxes.hpp"
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
|
#include <wx/sizer.h>
|
||||||
|
#include <wx/stattext.h>
|
||||||
|
#include <wx/textctrl.h>
|
||||||
|
#include <wx/button.h>
|
||||||
|
#include <wx/statbox.h>
|
||||||
|
#include <wx/wupdlock.h>
|
||||||
|
|
||||||
|
#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<unsigned int, unsigned int> 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<std::string>& 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<wxButton*>(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<PrintHost> 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<std::string>{ "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<std::string>{ "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<ConfigOptionEnum<AuthorizationType>>("authorization_type")->value;
|
||||||
|
m_optgroup->show_field("printhost_apikey", auth_type == AuthorizationType::atKeyPassword);
|
||||||
|
|
||||||
|
for (const std::string& opt_key : std::vector<std::string>{ "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<PrinterTechnology>(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<std::string> 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
|
105
src/slic3r/GUI/PhysicalPrinterDialog.hpp
Normal file
105
src/slic3r/GUI/PhysicalPrinterDialog.hpp
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
#ifndef slic3r_PhysicalPrinterDialog_hpp_
|
||||||
|
#define slic3r_PhysicalPrinterDialog_hpp_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <wx/gdicmn.h>
|
||||||
|
|
||||||
|
#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<PresetForPrinter*> 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
|
|
@ -24,20 +24,15 @@
|
||||||
#include "MainFrame.hpp"
|
#include "MainFrame.hpp"
|
||||||
#include "format.hpp"
|
#include "format.hpp"
|
||||||
#include "Tab.hpp"
|
#include "Tab.hpp"
|
||||||
#include "PrintHostDialogs.hpp"
|
|
||||||
#include "ConfigWizard.hpp"
|
#include "ConfigWizard.hpp"
|
||||||
#include "../Utils/ASCIIFolding.hpp"
|
#include "../Utils/ASCIIFolding.hpp"
|
||||||
#include "../Utils/PrintHost.hpp"
|
|
||||||
#include "../Utils/FixModelByWin10.hpp"
|
#include "../Utils/FixModelByWin10.hpp"
|
||||||
#include "../Utils/UndoRedo.hpp"
|
#include "../Utils/UndoRedo.hpp"
|
||||||
#include "RemovableDriveManager.hpp"
|
|
||||||
#include "BitmapCache.hpp"
|
#include "BitmapCache.hpp"
|
||||||
#include "BonjourDialog.hpp"
|
#include "PhysicalPrinterDialog.hpp"
|
||||||
|
|
||||||
using Slic3r::GUI::format_wxstr;
|
using Slic3r::GUI::format_wxstr;
|
||||||
|
|
||||||
static const std::pair<unsigned int, unsigned int> THUMBNAIL_SIZE_3MF = { 256, 256 };
|
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
@ -142,6 +137,15 @@ void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type)
|
||||||
this->SetClientData(item, (void*)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()
|
void PresetComboBox::invalidate_selection()
|
||||||
{
|
{
|
||||||
m_last_selected = INT_MAX; // this value means that no one item is selected
|
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;
|
continue;
|
||||||
|
|
||||||
// marker used for disable incompatible printer models for the selected physical printer
|
// 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";
|
std::string bitmap_key = "cb";
|
||||||
if (m_type == Preset::TYPE_PRINTER) {
|
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);
|
int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp);
|
||||||
if (!is_enabled)
|
if (!is_enabled)
|
||||||
set_label_marker(item_id, LABEL_ITEM_DISABLED);
|
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
|
else
|
||||||
{
|
{
|
||||||
std::pair<wxBitmap*, bool> pair(bmp, is_enabled);
|
std::pair<wxBitmap*, bool> pair(bmp, is_enabled);
|
||||||
nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), std::pair<wxBitmap*, bool>(bmp, is_enabled));
|
nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), std::pair<wxBitmap*, bool>(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());
|
selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str());
|
||||||
}
|
}
|
||||||
if (i + 1 == m_collection->num_default_presets())
|
if (i + 1 == m_collection->num_default_presets())
|
||||||
|
@ -232,6 +236,11 @@ void PresetComboBox::update(const std::string& select_preset_name)
|
||||||
Thaw();
|
Thaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PresetComboBox::update()
|
||||||
|
{
|
||||||
|
this->update(into_u8(this->GetString(this->GetSelection())));
|
||||||
|
}
|
||||||
|
|
||||||
void PresetComboBox::msw_rescale()
|
void PresetComboBox::msw_rescale()
|
||||||
{
|
{
|
||||||
m_em_unit = em_unit(this);
|
m_em_unit = em_unit(this);
|
||||||
|
@ -547,7 +556,7 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset
|
||||||
edit_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent)
|
edit_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent)
|
||||||
{
|
{
|
||||||
// In a case of a physical printer, for its editing open PhysicalPrinterDialog
|
// 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();
|
this->show_edit_menu();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -598,7 +607,7 @@ void PlaterPresetComboBox::show_add_menu()
|
||||||
{
|
{
|
||||||
wxMenu* menu = new wxMenu();
|
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&) {
|
[this](wxCommandEvent&) {
|
||||||
wxTheApp->CallAfter([]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); });
|
wxTheApp->CallAfter([]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS); });
|
||||||
}, "edit_uni", menu, []() { return true; }, wxGetApp().plater());
|
}, "edit_uni", menu, []() { return true; }, wxGetApp().plater());
|
||||||
|
@ -617,9 +626,10 @@ void PlaterPresetComboBox::show_edit_menu()
|
||||||
{
|
{
|
||||||
wxMenu* menu = new wxMenu();
|
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());
|
[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"), "",
|
append_menu_item(menu, wxID_ANY, _L("Edit physical printer"), "",
|
||||||
[this](wxCommandEvent&) {
|
[this](wxCommandEvent&) {
|
||||||
PhysicalPrinterDialog dlg(this->GetString(this->GetSelection()));
|
PhysicalPrinterDialog dlg(this->GetString(this->GetSelection()));
|
||||||
|
@ -642,6 +652,12 @@ void PlaterPresetComboBox::show_edit_menu()
|
||||||
wxGetApp().get_tab(m_type)->update_preset_choice();
|
wxGetApp().get_tab(m_type)->update_preset_choice();
|
||||||
update();
|
update();
|
||||||
}, "cross", menu, []() { return true; }, wxGetApp().plater());
|
}, "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);
|
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");
|
wxBitmap* bmp = get_bmp("edit_preset_list", wide_icons, "edit_uni");
|
||||||
assert(bmp);
|
assert(bmp);
|
||||||
|
|
||||||
|
@ -867,9 +883,6 @@ void TabPresetComboBox::update()
|
||||||
|
|
||||||
// marker used for disable incompatible printer models for the selected physical printer
|
// marker used for disable incompatible printer models for the selected physical printer
|
||||||
bool is_enabled = true;
|
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";
|
std::string bitmap_key = "tab";
|
||||||
if (m_type == Preset::TYPE_PRINTER) {
|
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<std::string>& 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<wxButton*>(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<PrintHost> 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<std::string>{ "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<std::string>{ "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<ConfigOptionEnum<AuthorizationType>>("authorization_type")->value;
|
|
||||||
m_optgroup->show_field("printhost_apikey", auth_type == AuthorizationType::atKeyPassword);
|
|
||||||
|
|
||||||
for (const std::string& opt_key : std::vector<std::string>{ "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<std::string> 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
|
// ChangePresetForPhysicalPrinterDialog
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
|
@ -1548,9 +1073,9 @@ ChangePresetForPhysicalPrinterDialog::ChangePresetForPhysicalPrinterDialog(const
|
||||||
wxStaticText* label_top = new wxStaticText(this, wxID_ANY, msg_text);
|
wxStaticText* label_top = new wxStaticText(this, wxID_ANY, msg_text);
|
||||||
label_top->SetFont(wxGetApp().bold_font());
|
label_top->SetFont(wxGetApp().bold_font());
|
||||||
|
|
||||||
wxString choices[] = { from_u8((boost::format(_u8L("Just switch to \"%1%\"")) % 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("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("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,
|
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);
|
3, wxRA_SPECIFY_ROWS);
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
#ifndef slic3r_PresetComboBoxes_hpp_
|
#ifndef slic3r_PresetComboBoxes_hpp_
|
||||||
#define slic3r_PresetComboBoxes_hpp_
|
#define slic3r_PresetComboBoxes_hpp_
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <wx/panel.h>
|
|
||||||
#include <wx/bmpcbox.h>
|
#include <wx/bmpcbox.h>
|
||||||
#include <wx/gdicmn.h>
|
#include <wx/gdicmn.h>
|
||||||
|
|
||||||
#include "libslic3r/Preset.hpp"
|
#include "libslic3r/Preset.hpp"
|
||||||
#include "wxExtensions.hpp"
|
#include "wxExtensions.hpp"
|
||||||
#include "GUI_Utils.hpp"
|
#include "GUI_Utils.hpp"
|
||||||
//#include "BitmapCache.hpp"
|
|
||||||
|
|
||||||
class wxString;
|
class wxString;
|
||||||
class wxTextCtrl;
|
class wxTextCtrl;
|
||||||
|
@ -23,6 +19,7 @@ namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
class BitmapCache;
|
class BitmapCache;
|
||||||
|
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
// *** PresetComboBox ***
|
// *** PresetComboBox ***
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
|
@ -47,8 +44,9 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_label_marker(int item, LabelItemType label_item_type = LABEL_ITEM_MARKER);
|
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<void(int)> sel_changed) { on_selection_changed = sel_changed; }
|
void set_selection_changed_function(std::function<void(int)> sel_changed) { on_selection_changed = sel_changed; }
|
||||||
|
|
||||||
bool is_selected_physical_printer();
|
bool is_selected_physical_printer();
|
||||||
|
|
||||||
|
@ -58,7 +56,7 @@ public:
|
||||||
|
|
||||||
void update(const std::string& select_preset);
|
void update(const std::string& select_preset);
|
||||||
|
|
||||||
virtual void update(){};
|
virtual void update();
|
||||||
virtual void msw_rescale();
|
virtual void msw_rescale();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -91,6 +89,8 @@ protected:
|
||||||
int thin_space_icon_width;
|
int thin_space_icon_width;
|
||||||
int wide_space_icon_width;
|
int wide_space_icon_width;
|
||||||
|
|
||||||
|
PrinterTechnology printer_technology {ptAny};
|
||||||
|
|
||||||
void invalidate_selection();
|
void invalidate_selection();
|
||||||
void validate_selection(bool predicate = false);
|
void validate_selection(bool predicate = false);
|
||||||
void update_selection();
|
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<PresetForPrinter*> 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
|
// ChangePresetForPhysicalPrinterDialog
|
||||||
//------------------------------------------------
|
//------------------------------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue