Config Wizard: Added check of the profile name for the custom printer.
#SPE-1344
This commit is contained in:
parent
dffca9c54a
commit
82b720eba1
5 changed files with 98 additions and 52 deletions
|
@ -18,7 +18,7 @@ namespace GUI {
|
|||
//static ModePaletteComboBox::PalettesMap MODE_PALETTES =
|
||||
static std::vector<std::pair<std::string, std::vector<std::string>>> MODE_PALETTES =
|
||||
{
|
||||
{ L("Palette 1 (default)"), { "#7DF028", "#FFDC00", "#E70000" } },
|
||||
{ L("Palette 1 (default)"), { "#00B000", "#FFDC00", "#E70000" } },
|
||||
{ L("Palette 2"), { "#FC766A", "#B0B8B4", "#184A45" } },
|
||||
{ L("Palette 3"), { "#567572", "#964F4C", "#696667" } },
|
||||
{ L("Palette 4"), { "#DA291C", "#56A8CB", "#53A567" } },
|
||||
|
|
|
@ -1176,31 +1176,20 @@ PageCustom::PageCustom(ConfigWizard *parent)
|
|||
: ConfigWizardPage(parent, _L("Custom Printer Setup"), _L("Custom Printer"))
|
||||
{
|
||||
cb_custom = new wxCheckBox(this, wxID_ANY, _L("Define a custom printer profile"));
|
||||
tc_profile_name = new wxTextCtrl(this, wxID_ANY, default_profile_name);
|
||||
auto *label = new wxStaticText(this, wxID_ANY, _L("Custom profile name:"));
|
||||
|
||||
wxGetApp().UpdateDarkUI(tc_profile_name);
|
||||
wxBoxSizer* profile_name_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
profile_name_editor = new SavePresetDialog::Item{ this, profile_name_sizer, default_profile_name };
|
||||
profile_name_editor->Enable(false);
|
||||
|
||||
tc_profile_name->Enable(false);
|
||||
tc_profile_name->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent &evt) {
|
||||
if (tc_profile_name->GetValue().IsEmpty()) {
|
||||
if (profile_name_prev.IsEmpty()) { tc_profile_name->SetValue(default_profile_name); }
|
||||
else { tc_profile_name->SetValue(profile_name_prev); }
|
||||
} else {
|
||||
profile_name_prev = tc_profile_name->GetValue();
|
||||
}
|
||||
evt.Skip();
|
||||
});
|
||||
|
||||
cb_custom->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &event) {
|
||||
tc_profile_name->Enable(custom_wanted());
|
||||
cb_custom->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &) {
|
||||
profile_name_editor->Enable(custom_wanted());
|
||||
wizard_p()->on_custom_setup(custom_wanted());
|
||||
|
||||
});
|
||||
|
||||
append(cb_custom);
|
||||
append(label);
|
||||
append(tc_profile_name);
|
||||
append(profile_name_sizer);
|
||||
}
|
||||
|
||||
PageUpdate::PageUpdate(ConfigWizard *parent)
|
||||
|
@ -2825,7 +2814,7 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
|||
preset_bundle->load_presets(*app_config, ForwardCompatibilitySubstitutionRule::EnableSilentDisableSystem,
|
||||
{preferred_model, preferred_variant, first_added_filament, first_added_sla_material});
|
||||
|
||||
if (!only_sla_mode && page_custom->custom_wanted()) {
|
||||
if (!only_sla_mode && page_custom->custom_wanted() && page_custom->is_valid_profile_name()) {
|
||||
// if unsaved changes was not cheched till this moment
|
||||
if (!check_unsaved_preset_changes &&
|
||||
!wxGetApp().check_and_keep_current_preset_changes(caption, _L("Custom printer was installed and it will be activated."), act_btns, &apply_keeped_changes))
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "slic3r/Utils/PresetUpdater.hpp"
|
||||
#include "BedShapeDialog.hpp"
|
||||
#include "GUI.hpp"
|
||||
#include "SavePresetDialog.hpp"
|
||||
#include "wxExtensions.hpp"
|
||||
|
||||
|
||||
|
@ -370,16 +371,20 @@ struct PageMaterials: ConfigWizardPage
|
|||
struct PageCustom: ConfigWizardPage
|
||||
{
|
||||
PageCustom(ConfigWizard *parent);
|
||||
~PageCustom() {
|
||||
if (profile_name_editor)
|
||||
delete profile_name_editor;
|
||||
}
|
||||
|
||||
bool custom_wanted() const { return cb_custom->GetValue(); }
|
||||
std::string profile_name() const { return into_u8(tc_profile_name->GetValue()); }
|
||||
bool custom_wanted() const { return cb_custom->GetValue(); }
|
||||
bool is_valid_profile_name() const { return profile_name_editor->is_valid();}
|
||||
std::string profile_name() const { return profile_name_editor->preset_name(); }
|
||||
|
||||
private:
|
||||
static const char* default_profile_name;
|
||||
|
||||
wxCheckBox *cb_custom;
|
||||
wxTextCtrl *tc_profile_name;
|
||||
wxString profile_name_prev;
|
||||
wxCheckBox *cb_custom {nullptr};
|
||||
SavePresetDialog::Item *profile_name_editor {nullptr};
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ constexpr auto BORDER_W = 10;
|
|||
|
||||
std::string SavePresetDialog::Item::get_init_preset_name(const std::string &suffix)
|
||||
{
|
||||
PresetBundle* preset_bundle = m_parent->get_preset_bundle();
|
||||
PresetBundle* preset_bundle = dynamic_cast<SavePresetDialog*>(m_parent)->get_preset_bundle();
|
||||
if (!preset_bundle)
|
||||
preset_bundle = wxGetApp().preset_bundle;
|
||||
m_presets = &preset_bundle->get_presets(m_type);
|
||||
|
@ -50,13 +50,14 @@ std::string SavePresetDialog::Item::get_init_preset_name(const std::string &suff
|
|||
|
||||
void SavePresetDialog::Item::init_input_name_ctrl(wxBoxSizer *input_name_sizer, const std::string preset_name)
|
||||
{
|
||||
if (m_parent->is_for_rename()) {
|
||||
if (m_use_text_ctrl) {
|
||||
#ifdef _WIN32
|
||||
long style = wxBORDER_SIMPLE;
|
||||
#else
|
||||
long style = 0L;
|
||||
#endif
|
||||
m_text_ctrl = new wxTextCtrl(m_parent, wxID_ANY, from_u8(preset_name), wxDefaultPosition, wxSize(35 * wxGetApp().em_unit(), -1), style);
|
||||
wxGetApp().UpdateDarkUI(m_text_ctrl);
|
||||
m_text_ctrl->Bind(wxEVT_TEXT, [this](wxCommandEvent&) { update(); });
|
||||
|
||||
input_name_sizer->Add(m_text_ctrl,1, wxEXPAND, BORDER_W);
|
||||
|
@ -86,13 +87,14 @@ void SavePresetDialog::Item::init_input_name_ctrl(wxBoxSizer *input_name_sizer,
|
|||
|
||||
wxString SavePresetDialog::Item::get_top_label_text() const
|
||||
{
|
||||
const std::string label_str = m_parent->is_for_rename() ?_u8L("Rename %s to:") : _u8L("Save %s as:");
|
||||
const std::string label_str = m_use_text_ctrl ?_u8L("Rename %s to:") : _u8L("Save %s as:");
|
||||
Tab* tab = wxGetApp().get_tab(m_type);
|
||||
return from_u8((boost::format(label_str) % into_u8(tab->title())).str());
|
||||
}
|
||||
|
||||
SavePresetDialog::Item::Item(Preset::Type type, const std::string& suffix, wxBoxSizer* sizer, SavePresetDialog* parent):
|
||||
m_type(type),
|
||||
m_use_text_ctrl(parent->is_for_rename()),
|
||||
m_parent(parent),
|
||||
m_valid_bmp(new wxStaticBitmap(m_parent, wxID_ANY, *get_bmp_bundle("tick_mark"))),
|
||||
m_valid_label(new wxStaticText(m_parent, wxID_ANY, ""))
|
||||
|
@ -110,15 +112,51 @@ SavePresetDialog::Item::Item(Preset::Type type, const std::string& suffix, wxBox
|
|||
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);
|
||||
parent->add_info_for_edit_ph_printer(sizer);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
SavePresetDialog::Item::Item(wxWindow* parent, wxBoxSizer* sizer, const std::string& def_name, PrinterTechnology pt /*= ptFFF*/):
|
||||
m_preset_name(def_name),
|
||||
m_printer_technology(pt),
|
||||
m_parent(parent),
|
||||
m_valid_bmp(new wxStaticBitmap(m_parent, wxID_ANY, *get_bmp_bundle("tick_mark"))),
|
||||
m_valid_label(new wxStaticText(m_parent, wxID_ANY, ""))
|
||||
{
|
||||
m_valid_label->SetFont(wxGetApp().bold_font());
|
||||
|
||||
wxBoxSizer* input_name_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
input_name_sizer->Add(m_valid_bmp, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, BORDER_W);
|
||||
init_input_name_ctrl(input_name_sizer, m_preset_name);
|
||||
|
||||
sizer->Add(input_name_sizer,0, wxEXPAND | wxBOTTOM, BORDER_W);
|
||||
sizer->Add(m_valid_label, 0, wxEXPAND | wxLEFT, 3*BORDER_W);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
const Preset* SavePresetDialog::Item::get_existing_preset() const
|
||||
{
|
||||
if (m_presets)
|
||||
return m_presets->find_preset(m_preset_name, false);
|
||||
|
||||
const std::vector<Preset::Type> types = m_printer_technology == ptFFF ?
|
||||
std::initializer_list{Preset::TYPE_PRINTER, Preset::TYPE_PRINT, Preset::TYPE_FILAMENT } :
|
||||
std::initializer_list{Preset::TYPE_PRINTER, Preset::TYPE_SLA_PRINT, Preset::TYPE_SLA_MATERIAL };
|
||||
|
||||
for (auto type : types) {
|
||||
const PresetCollection& presets = wxGetApp().preset_bundle->get_presets(type);
|
||||
if (const Preset* preset = presets.find_preset(m_preset_name, false))
|
||||
return preset;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SavePresetDialog::Item::update()
|
||||
{
|
||||
bool rename = m_parent->is_for_rename();
|
||||
m_preset_name = into_u8(rename ? m_text_ctrl->GetValue() : m_combo->GetValue());
|
||||
m_preset_name = into_u8(m_use_text_ctrl ? m_text_ctrl->GetValue() : m_combo->GetValue());
|
||||
|
||||
m_valid_type = ValidationType::Valid;
|
||||
wxString info_line;
|
||||
|
@ -138,7 +176,7 @@ void SavePresetDialog::Item::update()
|
|||
if (m_valid_type == ValidationType::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());
|
||||
from_u8(unusable_suffix);
|
||||
m_valid_type = ValidationType::NoValid;
|
||||
}
|
||||
|
||||
|
@ -147,24 +185,25 @@ void SavePresetDialog::Item::update()
|
|||
m_valid_type = ValidationType::NoValid;
|
||||
}
|
||||
|
||||
const Preset* existing = m_presets->find_preset(m_preset_name, false);
|
||||
const Preset* existing = get_existing_preset();
|
||||
if (m_valid_type == ValidationType::Valid && existing && (existing->is_default || existing->is_system)) {
|
||||
info_line = rename ? _L("The supplied name is used for a system profile.") :
|
||||
info_line = m_use_text_ctrl ? _L("The supplied name is used for a system profile.") :
|
||||
_L("Cannot overwrite a system profile.");
|
||||
m_valid_type = ValidationType::NoValid;
|
||||
}
|
||||
|
||||
if (m_valid_type == ValidationType::Valid && existing && (existing->is_external)) {
|
||||
info_line = rename ? _L("The supplied name is used for a external profile.") :
|
||||
info_line = m_use_text_ctrl ? _L("The supplied name is used for a external profile.") :
|
||||
_L("Cannot overwrite an external profile.");
|
||||
m_valid_type = ValidationType::NoValid;
|
||||
}
|
||||
|
||||
SavePresetDialog* dlg = dynamic_cast<SavePresetDialog*>(m_parent);
|
||||
if (m_valid_type == ValidationType::Valid && existing)
|
||||
{
|
||||
if (m_preset_name == m_presets->get_selected_preset_name()) {
|
||||
if ((!rename && m_presets->get_edited_preset().is_dirty) ||
|
||||
m_parent->get_preset_bundle()) // means that we save modifications from the DiffDialog
|
||||
if (m_presets && m_preset_name == m_presets->get_selected_preset_name()) {
|
||||
if ((!m_use_text_ctrl && m_presets->get_edited_preset().is_dirty) ||
|
||||
(dlg && dlg->get_preset_bundle())) // means that we save modifications from the DiffDialog
|
||||
info_line = _L("Save preset modifications to existing user profile");
|
||||
else
|
||||
info_line = _L("Nothing changed");
|
||||
|
@ -191,7 +230,7 @@ void SavePresetDialog::Item::update()
|
|||
const int max_path_length = 255;
|
||||
#endif
|
||||
|
||||
if (m_valid_type == ValidationType::Valid && m_presets->path_from_name(m_preset_name).length() >= max_path_length) {
|
||||
if (m_valid_type == ValidationType::Valid && m_presets && m_presets->path_from_name(m_preset_name).length() >= max_path_length) {
|
||||
info_line = _L("The name is too long.");
|
||||
m_valid_type = ValidationType::NoValid;
|
||||
}
|
||||
|
@ -206,23 +245,23 @@ void SavePresetDialog::Item::update()
|
|||
m_valid_type = ValidationType::NoValid;
|
||||
}
|
||||
|
||||
if (m_valid_type == ValidationType::Valid && m_presets->get_preset_name_by_alias(m_preset_name) != m_preset_name) {
|
||||
if (m_valid_type == ValidationType::Valid && m_presets && m_presets->get_preset_name_by_alias(m_preset_name) != m_preset_name) {
|
||||
info_line = _L("The name cannot be the same as a preset alias name.");
|
||||
m_valid_type = ValidationType::NoValid;
|
||||
}
|
||||
|
||||
if (!m_parent->get_info_line_extention().IsEmpty() && m_valid_type != ValidationType::NoValid)
|
||||
info_line += "\n\n" + m_parent->get_info_line_extention();
|
||||
if ((dlg && !dlg->get_info_line_extention().IsEmpty()) && m_valid_type != ValidationType::NoValid)
|
||||
info_line += "\n\n" + dlg->get_info_line_extention();
|
||||
|
||||
m_valid_label->SetLabel(info_line);
|
||||
m_valid_label->Show(!info_line.IsEmpty());
|
||||
|
||||
update_valid_bmp();
|
||||
|
||||
if (m_type == Preset::TYPE_PRINTER)
|
||||
m_parent->update_info_for_edit_ph_printer(m_preset_name);
|
||||
if (dlg && m_type == Preset::TYPE_PRINTER)
|
||||
dlg->update_info_for_edit_ph_printer(m_preset_name);
|
||||
|
||||
m_parent->layout();
|
||||
m_parent->Layout();
|
||||
}
|
||||
|
||||
void SavePresetDialog::Item::update_valid_bmp()
|
||||
|
@ -238,6 +277,13 @@ void SavePresetDialog::Item::accept()
|
|||
m_presets->delete_preset(m_preset_name);
|
||||
}
|
||||
|
||||
void SavePresetDialog::Item::Enable(bool enable /*= true*/)
|
||||
{
|
||||
m_valid_label->Enable(enable);
|
||||
m_valid_bmp->Enable(enable);
|
||||
m_use_text_ctrl ? m_text_ctrl->Enable(enable) : m_combo->Enable(enable);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------
|
||||
// SavePresetDialog
|
||||
|
@ -398,10 +444,11 @@ void SavePresetDialog::update_info_for_edit_ph_printer(const std::string& preset
|
|||
}
|
||||
}
|
||||
|
||||
void SavePresetDialog::layout()
|
||||
bool SavePresetDialog::Layout()
|
||||
{
|
||||
this->Layout();
|
||||
const bool ret = DPIDialog::Layout();
|
||||
this->Fit();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SavePresetDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||
|
|
|
@ -26,7 +26,7 @@ class SavePresetDialog : public DPIDialog
|
|||
Switch,
|
||||
UndefAction
|
||||
};
|
||||
|
||||
public:
|
||||
struct Item
|
||||
{
|
||||
enum class ValidationType
|
||||
|
@ -37,20 +37,24 @@ class SavePresetDialog : public DPIDialog
|
|||
};
|
||||
|
||||
Item(Preset::Type type, const std::string& suffix, wxBoxSizer* sizer, SavePresetDialog* parent);
|
||||
Item(wxWindow* parent, wxBoxSizer* sizer, const std::string& def_name, PrinterTechnology pt = ptFFF);
|
||||
|
||||
void update_valid_bmp();
|
||||
void accept();
|
||||
void Enable(bool enable = true);
|
||||
|
||||
bool is_valid() const { return m_valid_type != ValidationType::NoValid; }
|
||||
Preset::Type type() const { return m_type; }
|
||||
std::string preset_name() const { return m_preset_name; }
|
||||
|
||||
private:
|
||||
Preset::Type m_type;
|
||||
Preset::Type m_type {Preset::TYPE_INVALID};
|
||||
std::string m_preset_name;
|
||||
bool m_use_text_ctrl {true};
|
||||
|
||||
PrinterTechnology m_printer_technology {ptAny};
|
||||
ValidationType m_valid_type {ValidationType::NoValid};
|
||||
SavePresetDialog* m_parent {nullptr};
|
||||
wxWindow* m_parent {nullptr};
|
||||
wxStaticBitmap* m_valid_bmp {nullptr};
|
||||
wxComboBox* m_combo {nullptr};
|
||||
wxTextCtrl* m_text_ctrl {nullptr};
|
||||
|
@ -60,11 +64,12 @@ class SavePresetDialog : public DPIDialog
|
|||
|
||||
std::string get_init_preset_name(const std::string &suffix);
|
||||
void init_input_name_ctrl(wxBoxSizer *input_name_sizer, std::string preset_name);
|
||||
wxString get_top_label_text() const ;
|
||||
const Preset* get_existing_preset() const ;
|
||||
wxString get_top_label_text() const ;
|
||||
|
||||
void update();
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<Item*> m_items;
|
||||
|
||||
wxBoxSizer* m_presets_sizer {nullptr};
|
||||
|
@ -97,7 +102,7 @@ public:
|
|||
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();
|
||||
bool Layout() override;
|
||||
bool is_for_rename() { return m_use_for_rename; }
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in a new issue