mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-08-20 12:39:15 +08:00
FIX: create printer issue
Jira: 5034 5059 5053 5034 create printer but filament is repeat 5039 create successful dialog remove to center 5053 create existing printer copywriting adjustments and preset updates Delete printer secondary confirmation dialog Change-Id: Ifb3822d1e168459d2af11e02b31ecaf3719d338a Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>
This commit is contained in:
parent
eddd01fa26
commit
d2cec9453c
@ -2121,7 +2121,7 @@ bool PresetCollection::clone_presets(std::vector<Preset const *> const &presets,
|
||||
preset.is_visible = true;
|
||||
preset.is_project_embedded = false;
|
||||
modifier(preset, m_type);
|
||||
if (find_preset(preset.name)) {
|
||||
if (find_preset(preset.name) && !force_rewritten) {
|
||||
failures.push_back(preset.name);
|
||||
}
|
||||
preset.file = this->path_for_preset(preset);
|
||||
@ -2170,12 +2170,13 @@ bool PresetCollection::create_presets_from_template_for_printer(std::vector<Pres
|
||||
bool force_rewritten)
|
||||
{
|
||||
return clone_presets(templates, failures, [printer, create_filament_id](Preset &preset, Preset::Type &type) {
|
||||
preset.name = preset.name.substr(0, preset.name.find(" @")) + " @" + printer;
|
||||
std::string prefix = preset.name.substr(0, preset.name.find(" @"));
|
||||
preset.name = prefix + " @" + printer;
|
||||
auto *compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers"));
|
||||
compatible_printers->values = std::vector<std::string>{ printer };
|
||||
compatible_printers->values = std::vector<std::string>{printer};
|
||||
preset.is_visible = true;
|
||||
if (type == Preset::TYPE_FILAMENT)
|
||||
preset.filament_id = create_filament_id(preset.name);
|
||||
preset.filament_id = create_filament_id(prefix);
|
||||
}, force_rewritten);
|
||||
}
|
||||
|
||||
|
@ -320,9 +320,7 @@ static std::string calculate_md5(const std::string &input)
|
||||
|
||||
static std::string get_filament_id(std::string vendor_typr_serial)
|
||||
{
|
||||
std::string user_filament_id = "P" + calculate_md5(vendor_typr_serial).substr(0, 7);
|
||||
|
||||
std::unordered_map<std::string,std::vector<std::string>> filament_id_to_filament_name;
|
||||
std::unordered_map<std::string, std::set<std::string>> filament_id_to_filament_name;
|
||||
|
||||
// temp filament presets
|
||||
PresetBundle temp_preset_bundle;
|
||||
@ -337,7 +335,15 @@ static std::string get_filament_id(std::string vendor_typr_serial)
|
||||
|
||||
for (const Preset &preset : filament_presets) {
|
||||
std::string preset_name = preset.name;
|
||||
filament_id_to_filament_name[preset.filament_id].push_back(get_filament_name(preset_name));
|
||||
size_t index_at = preset_name.find_first_of('@');
|
||||
if (index_at == std::string::npos) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " filament preset name has no @ and name is: " << preset_name;
|
||||
continue;
|
||||
}
|
||||
std::string filament_name = preset_name.substr(0, index_at - 1);
|
||||
if (filament_name == vendor_typr_serial)
|
||||
return preset.filament_id;
|
||||
filament_id_to_filament_name[preset.filament_id].insert(filament_name);
|
||||
}
|
||||
// global filament presets
|
||||
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
|
||||
@ -346,9 +352,20 @@ static std::string get_filament_id(std::string vendor_typr_serial)
|
||||
if (filament_id_to_presets.first.empty()) continue;
|
||||
for (const Preset *preset : filament_id_to_presets.second) {
|
||||
std::string preset_name = preset->name;
|
||||
filament_id_to_filament_name[preset->filament_id].push_back(get_filament_name(preset_name));
|
||||
size_t index_at = preset_name.find_first_of('@');
|
||||
if (index_at == std::string::npos) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " filament preset name has no @ and name is: " << preset_name;
|
||||
continue;
|
||||
}
|
||||
std::string filament_name = preset_name.substr(0, index_at - 1);
|
||||
if (filament_name == vendor_typr_serial)
|
||||
return preset->filament_id;
|
||||
filament_id_to_filament_name[preset->filament_id].insert(filament_name);
|
||||
}
|
||||
}
|
||||
|
||||
std::string user_filament_id = "P" + calculate_md5(vendor_typr_serial).substr(0, 7);
|
||||
|
||||
while (filament_id_to_filament_name.find(user_filament_id) != filament_id_to_filament_name.end()) {//find same filament id
|
||||
bool have_same_filament_name = false;
|
||||
for (const std::string &name : filament_id_to_filament_name.find(user_filament_id)->second) {
|
||||
@ -2412,8 +2429,8 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page2_btns_item(wxWindow *parent)
|
||||
// Confirm if the printer preset has a duplicate name
|
||||
if (!rewritten && preset_bundle->printers.find_preset(printer_preset_name)) {
|
||||
MessageDialog dlg(this,
|
||||
_L("The preset you created already has a preset with the same name. Do you want to overwrite it?\n\tYes: Overwrite the printer preset with the "
|
||||
"same name, and filament and process presets with the same preset name will not be recreated.\n\tCancel: Do not create a preset, return to the "
|
||||
_L("The printer preset you created already has a preset with the same name. Do you want to overwrite it?\n\tYes: Overwrite the printer preset with the "
|
||||
"same name, and filament and process presets with the same preset name will be recreated \nand filament and process presets without the same preset name will be reserve.\n\tCancel: Do not create a preset, return to the "
|
||||
"creation interface."),
|
||||
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxCANCEL | wxYES_DEFAULT | wxCENTRE);
|
||||
int res = dlg.ShowModal();
|
||||
@ -2759,7 +2776,7 @@ void CreatePrinterPresetDialog::update_presets_list(bool just_template)
|
||||
// update filament preset window sizer
|
||||
for (const Preset &filament_preset : filament_presets) {
|
||||
if (filament_preset.is_compatible) {
|
||||
if (filament_preset.name == "Default Filament") continue;
|
||||
if (filament_preset.is_default) continue;
|
||||
Preset *temp_filament = new Preset(filament_preset);
|
||||
wxString filament_name = wxString::FromUTF8(temp_filament->name);
|
||||
m_filament_preset_template_sizer->Add(create_checkbox(m_filament_preset_panel, temp_filament, filament_name, m_filament_preset), 0,
|
||||
@ -2769,7 +2786,7 @@ void CreatePrinterPresetDialog::update_presets_list(bool just_template)
|
||||
|
||||
for (const Preset &process_preset : process_presets) {
|
||||
if (process_preset.is_compatible) {
|
||||
if (process_preset.name == "Default Setting") continue;
|
||||
if (process_preset.is_default) continue;
|
||||
|
||||
Preset *temp_process = new Preset(process_preset);
|
||||
wxString process_name = wxString::FromUTF8(temp_process->name);
|
||||
@ -3925,7 +3942,7 @@ void ExportConfigsDialog::data_init()
|
||||
|
||||
const std::deque<Preset> &filament_presets = preset_bundle.filaments.get_presets();
|
||||
for (const Preset &filament_preset : filament_presets) {
|
||||
if (filament_preset.is_system || "Default Filament" == filament_preset.name) continue;
|
||||
if (filament_preset.is_system || filament_preset.is_default) continue;
|
||||
if (filament_preset.is_compatible) {
|
||||
Preset *new_filament_preset = new Preset(filament_preset);
|
||||
m_filament_presets[preset_name].push_back(new_filament_preset);
|
||||
@ -3934,7 +3951,7 @@ void ExportConfigsDialog::data_init()
|
||||
|
||||
const std::deque<Preset> &process_presets = preset_bundle.prints.get_presets();
|
||||
for (const Preset &process_preset : process_presets) {
|
||||
if (process_preset.is_system || "Default Setting" == process_preset.name) continue;
|
||||
if (process_preset.is_system || process_preset.is_default) continue;
|
||||
if (process_preset.is_compatible) {
|
||||
Preset *new_prpcess_preset = new Preset(process_preset);
|
||||
m_process_presets[preset_name].push_back(new_prpcess_preset);
|
||||
@ -3947,7 +3964,7 @@ void ExportConfigsDialog::data_init()
|
||||
}
|
||||
const std::deque<Preset> &filament_presets = preset_bundle.filaments.get_presets();
|
||||
for (const Preset &filament_preset : filament_presets) {
|
||||
if (filament_preset.is_system || "Default Filament" == filament_preset.name) continue;
|
||||
if (filament_preset.is_system || filament_preset.is_default) continue;
|
||||
Preset *new_filament_preset = new Preset(filament_preset);
|
||||
const Preset *base_filament_preset = preset_bundle.filaments.get_preset_base(*new_filament_preset);
|
||||
|
||||
|
@ -423,4 +423,65 @@ void DownloadDialog::SetExtendedMessage(const wxString &extendedMessage)
|
||||
Fit();
|
||||
}
|
||||
|
||||
}} // namespace Slic3r::GUI
|
||||
DeleteConfirmDialog::DeleteConfirmDialog(wxWindow *parent, const wxString &title, const wxString &msg)
|
||||
: DPIDialog(parent ? parent : nullptr, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
|
||||
{
|
||||
this->SetBackgroundColour(*wxWHITE);
|
||||
this->SetSize(wxSize(FromDIP(450), FromDIP(200)));
|
||||
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
|
||||
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
|
||||
|
||||
wxBoxSizer *m_main_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
// top line
|
||||
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
|
||||
m_line_top->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
|
||||
m_main_sizer->Add(m_line_top, 0, wxEXPAND, 0);
|
||||
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
|
||||
|
||||
m_msg_text = new wxStaticText(this, wxID_ANY, msg);
|
||||
m_main_sizer->Add(m_msg_text, 0, wxEXPAND | wxALL, FromDIP(10));
|
||||
|
||||
wxBoxSizer *bSizer_button = new wxBoxSizer(wxHORIZONTAL);
|
||||
bSizer_button->Add(0, 0, 1, wxEXPAND, 0);
|
||||
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
|
||||
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
|
||||
m_cancel_btn = new Button(this, _L("Cancel"));
|
||||
m_cancel_btn->SetBackgroundColor(btn_bg_white);
|
||||
m_cancel_btn->SetBorderColor(*wxBLACK);
|
||||
m_cancel_btn->SetTextColor(wxColour(*wxBLACK));
|
||||
m_cancel_btn->SetFont(Label::Body_12);
|
||||
m_cancel_btn->SetSize(wxSize(FromDIP(58), FromDIP(24)));
|
||||
m_cancel_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
|
||||
m_cancel_btn->SetCornerRadius(FromDIP(12));
|
||||
bSizer_button->Add(m_cancel_btn, 0, wxRIGHT | wxBOTTOM, FromDIP(10));
|
||||
|
||||
|
||||
m_del_btn = new Button(this, _L("Delete"));
|
||||
m_del_btn->SetBackgroundColor(*wxRED);
|
||||
m_del_btn->SetBorderColor(*wxWHITE);
|
||||
m_del_btn->SetTextColor(wxColour(0xFFFFFE));
|
||||
m_del_btn->SetFont(Label::Body_12);
|
||||
m_del_btn->SetSize(wxSize(FromDIP(58), FromDIP(24)));
|
||||
m_del_btn->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
|
||||
m_del_btn->SetCornerRadius(FromDIP(12));
|
||||
bSizer_button->Add(m_del_btn, 0, wxRIGHT | wxBOTTOM, FromDIP(10));
|
||||
|
||||
m_main_sizer->Add(bSizer_button, 0, wxEXPAND, 0);
|
||||
m_del_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { EndModal(wxID_OK); });
|
||||
m_cancel_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { EndModal(wxID_CANCEL); });
|
||||
|
||||
SetSizer(m_main_sizer);
|
||||
Layout();
|
||||
Fit();
|
||||
wxGetApp().UpdateDlgDarkUI(this);
|
||||
}
|
||||
|
||||
DeleteConfirmDialog::~DeleteConfirmDialog() {}
|
||||
|
||||
|
||||
void DeleteConfirmDialog::on_dpi_changed(const wxRect &suggested_rect) {}
|
||||
|
||||
|
||||
} // namespace GUI
|
||||
|
||||
} // namespace Slic3r
|
||||
|
@ -371,6 +371,19 @@ private:
|
||||
wxString msg;
|
||||
};
|
||||
|
||||
class DeleteConfirmDialog : public DPIDialog
|
||||
{
|
||||
public:
|
||||
DeleteConfirmDialog(wxWindow *parent, const wxString &title, const wxString &msg);
|
||||
~DeleteConfirmDialog();
|
||||
virtual void on_dpi_changed(const wxRect &suggested_rect);
|
||||
|
||||
private:
|
||||
wxString msg;
|
||||
Button * m_del_btn = nullptr;
|
||||
Button * m_cancel_btn = nullptr;
|
||||
wxStaticText *m_msg_text = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -993,9 +993,10 @@ void Sidebar::create_printer_preset()
|
||||
int res = dlg.ShowModal();
|
||||
if (wxID_OK == res) {
|
||||
wxGetApp().mainframe->update_side_preset_ui();
|
||||
update_ui_from_settings();
|
||||
update_all_preset_comboboxes();
|
||||
wxGetApp().load_current_presets();
|
||||
CreatePresetSuccessfulDialog success_dlg(p->m_panel_filament_title, SuccessType::PRINTER);
|
||||
CreatePresetSuccessfulDialog success_dlg(wxGetApp().mainframe, SuccessType::PRINTER);
|
||||
int res = success_dlg.ShowModal();
|
||||
if (res == wxID_OK) {
|
||||
p->editing_filament = -1;
|
||||
|
@ -4525,8 +4525,12 @@ bool Tab::select_preset(std::string preset_name, bool delete_current /*=false*/,
|
||||
BOOST_LOG_TRIVIAL(info) << "delete print preset = " << preset.name << ", setting_id = " << preset.setting_id;
|
||||
preset_bundle->prints.delete_preset(preset.name);
|
||||
}
|
||||
|
||||
preset_bundle->update_compatible(PresetSelectCompatibleType::Always);
|
||||
preset_bundle->filaments.select_preset_by_name(old_filament_name, true);
|
||||
preset_bundle->prints.select_preset_by_name(old_process_name, true);
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " old filament name is:" << old_filament_name << " old process name is: " << old_process_name;
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -5004,10 +5008,22 @@ void Tab::delete_preset()
|
||||
|
||||
if (m_presets->get_preset_base(current_preset) == ¤t_preset) { //root preset
|
||||
if (current_preset.type == Preset::Type::TYPE_PRINTER && !current_preset.is_system) { //Customize third-party printers
|
||||
MessageDialog dlg(this, _L("If you want to delete this preset, all compatible filament and process presets will be deleted. \nDo you want to continue?"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
|
||||
wxYES_NO | wxYES_DEFAULT);
|
||||
Preset ¤t_preset = m_presets->get_selected_preset();
|
||||
int filament_preset_num = 0;
|
||||
int process_preset_num = 0;
|
||||
for (const Preset &preset : m_preset_bundle->filaments.get_presets()) {
|
||||
if (preset.is_compatible && preset.is_default) { filament_preset_num++; }
|
||||
}
|
||||
for (const Preset &preset : m_preset_bundle->prints.get_presets()) {
|
||||
if (preset.is_compatible && preset.is_default) { process_preset_num++; }
|
||||
}
|
||||
|
||||
DeleteConfirmDialog
|
||||
dlg(this, wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Delete"),
|
||||
wxString::Format(_L("%d Filament Preset and %d Process Preset is attached to this printer. Those presets would be deleted if the printer is deleted."),
|
||||
filament_preset_num, process_preset_num));
|
||||
int res = dlg.ShowModal();
|
||||
if (res != wxID_YES) return;
|
||||
if (res != wxID_OK) return;
|
||||
}
|
||||
int count = 0;
|
||||
wxString presets;
|
||||
|
Loading…
x
Reference in New Issue
Block a user