Add extruder sync button

Co-authored-by: chunmao.guo <chunmao.guo@bambulab.com>
This commit is contained in:
Noisyfox
2026-05-21 09:04:26 +08:00
co-authored by chunmao.guo
parent 8f2ff7447e
commit e785f89833
7 changed files with 349 additions and 64 deletions
+113 -41
View File
@@ -802,6 +802,21 @@ UnsavedChangesDialog::UnsavedChangesDialog(const wxString &caption, const wxStri
wxGetApp().UpdateDlgDarkUI(this);
}
UnsavedChangesDialog::UnsavedChangesDialog(const wxString &caption, const wxString &header, DynamicConfig *config, int from, int to, bool left_to_right, NozzleVolumeType nozzle)
: DPIDialog(static_cast<wxWindow *>(wxGetApp().mainframe),
wxID_ANY,
caption,
wxDefaultPosition,
wxDefaultSize,
wxCAPTION | wxCLOSE_BOX)
, m_buttons(ActionButtons::SAVE | ActionButtons::DONT_SAVE)
{
SyncExtruderParams params { config, from, to, left_to_right, nozzle };
build(Preset::TYPE_PRINT, reinterpret_cast<PresetCollection*>(&params), "SyncExtruderParams", header);
this->CenterOnScreen();
wxGetApp().UpdateDlgDarkUI(this);
}
UnsavedChangesDialog::UnsavedChangesDialog(Preset::Type type, PresetCollection *dependent_presets, const std::string &new_selected_preset, bool no_transfer)
: m_new_selected_preset_name(new_selected_preset)
, DPIDialog(static_cast<wxWindow *>(wxGetApp().mainframe),
@@ -856,6 +871,12 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_
m_sizer_main->Add(0, 0, 0, wxTOP, 12);
SyncExtruderParams *params = nullptr;
if (new_selected_preset == "SyncExtruderParams") {
params = reinterpret_cast<SyncExtruderParams *>(dependent_presets);
dependent_presets = nullptr;
}
m_panel_tab = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(UNSAVE_CHANGE_DIALOG_SCROLL_WINDOW_SIZE.x, -1), wxTAB_TRAVERSAL);
m_panel_tab->SetBackgroundColour(GREY200);
wxBoxSizer *m_sizer_tab = new wxBoxSizer(wxVERTICAL);
@@ -865,7 +886,7 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_
wxBoxSizer *m_sizer_top = new wxBoxSizer(wxHORIZONTAL);
//m_sizer_top->Add(0, 0, 0, wxLEFT, UNSAVE_CHANGE_DIALOG_FIRST_VALUE_WIDTH);
// m_sizer_top->Add(0, 0, 0, wxLEFT, UNSAVE_CHANGE_DIALOG_FIRST_VALUE_WIDTH);
auto m_panel_temp = new wxPanel(m_table_top, wxID_ANY, wxDefaultPosition, wxSize(UNSAVE_CHANGE_DIALOG_FIRST_VALUE_WIDTH, -1), wxTAB_TRAVERSAL);
wxBoxSizer *top_title_temp_v = new wxBoxSizer(wxVERTICAL);
top_title_temp_v->SetMinSize(wxSize(UNSAVE_CHANGE_DIALOG_VALUE_WIDTH, -1));
@@ -880,7 +901,6 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_
m_panel_temp->Layout();
m_sizer_top->Add(m_panel_temp, 1, wxALIGN_CENTER, 0);
title_block_middle = new wxPanel(m_table_top, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
title_block_middle->SetBackgroundColour(wxColour(172, 172, 172));
@@ -889,10 +909,11 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_
wxBoxSizer *top_title_oldv = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *top_title_oldv_h = new wxBoxSizer(wxHORIZONTAL);
static_oldv_title = new wxStaticText(m_panel_oldv, wxID_ANY, _L("Old Value"), wxDefaultPosition, wxDefaultSize, 0);
std::string ucd_pt = wxGetApp().preset_bundle->printers.get_edited_preset().get_printer_type(wxGetApp().preset_bundle);
static_oldv_title = new wxStaticText(m_panel_oldv, wxID_ANY, params ? _L(DevPrinterConfigUtil::get_toolhead_display_name(ucd_pt, DEPUTY_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::SentenceCase)) + ": " + get_nozzle_volume_type_name(params->nozzle) : _L("Old Value"), wxDefaultPosition, wxDefaultSize, 0);
static_oldv_title->SetFont(::Label::Body_13);
static_oldv_title->Wrap(-1);
static_oldv_title->SetForegroundColour(*wxWHITE);
static_oldv_title->SetForegroundColour(params && params->left_to_right ? wxGetApp().get_label_clr_modified() : *wxWHITE);
top_title_oldv_h->Add(static_oldv_title, 0, wxALIGN_CENTER | wxBOTTOM | wxTOP, 5);
top_title_oldv->Add(top_title_oldv_h, 1, wxALIGN_CENTER, 0);
m_panel_oldv->SetSizer(top_title_oldv);
@@ -908,10 +929,11 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_
wxBoxSizer *top_title_newv = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *top_title_newv_h = new wxBoxSizer(wxHORIZONTAL);
static_newv_title = new wxStaticText(m_panel_newv, wxID_ANY, _L("New Value"), wxDefaultPosition, wxDefaultSize, 0);
static_newv_title = new wxStaticText(m_panel_newv, wxID_ANY, params ? _L(DevPrinterConfigUtil::get_toolhead_display_name(ucd_pt, MAIN_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::SentenceCase)) + ": " + get_nozzle_volume_type_name(params->nozzle) : _L("New Value"),
wxDefaultPosition, wxDefaultSize, 0);
static_newv_title->SetFont(::Label::Body_13);
static_newv_title->Wrap(-1);
static_newv_title->SetForegroundColour(*wxWHITE);
static_newv_title->SetForegroundColour(params && !params->left_to_right ? wxGetApp().get_label_clr_modified() : *wxWHITE);
top_title_newv_h->Add(static_newv_title, 0, wxALIGN_CENTER | wxBOTTOM | wxTOP, 5);
@@ -1000,14 +1022,15 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_
if (!m_transfer_btn && (ActionButtons::KEEP & m_buttons))
add_btn(&m_transfer_btn, m_move_btn_id, "menu_paste", Action::Transfer, _L("Transfer"), true);
bool is_copy = new_selected_preset == "SyncExtruderParams";
{ // "Don't save" / "Discard" button
std::string btn_icon = (ActionButtons::DONT_SAVE & m_buttons) ? "" : (dependent_presets || (ActionButtons::KEEP & m_buttons)) ? "blank_16" : "exit";
wxString btn_label = (ActionButtons::DONT_SAVE & m_buttons) ? _L("Don't save") : _L("Discard");
wxString btn_label = (ActionButtons::DONT_SAVE & m_buttons) ? (is_copy ? _L("No") : _L("Don't save")) : _L("Discard");
add_btn(&m_discard_btn, m_continue_btn_id, btn_icon, Action::Discard, btn_label, false);
}
// "Save" button
if (ActionButtons::SAVE & m_buttons) add_btn(&m_save_btn, m_save_btn_id, "save", Action::Save, _L("Save"), false);
if (ActionButtons::SAVE & m_buttons) add_btn(&m_save_btn, m_save_btn_id, "save", is_copy ? Action::Transfer : Action::Save, is_copy ? _L("Yes") : _L("Save"), false);
if (dependent_presets != nullptr) {
const wxString previous_profile = from_u8(dependent_presets->get_edited_preset().name);
@@ -1057,9 +1080,17 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_
Fit();
Centre(wxBOTH);
update(type, dependent_presets, new_selected_preset, header);
if (params) {
if (params->left_to_right)
update_tree(type, params->config, params->from, params->to);
else
update_tree(type, params->config, params->to, params->from);
m_action_line->SetLabel(header);
m_action_line->Wrap(UNSAVE_CHANGE_DIALOG_SCROLL_WINDOW_SIZE.x);
update_list(params);
} else {
update(type, dependent_presets, new_selected_preset, header);
}
//SetSizer(topSizer);
//topSizer->SetSizeHints(this);
@@ -1248,9 +1279,10 @@ static wxString get_string_value(std::string opt_key, const DynamicPrintConfig&
if (!option) {
return _L("N/A");
}
auto opt_vector = dynamic_cast<const ConfigOptionVectorBase *>(option);
if (option->is_scalar() && config.option(opt_key)->is_nil() ||
option->is_vector() && dynamic_cast<const ConfigOptionVectorBase *>(config.option(opt_key))->is_nil(opt_idx))
option->is_vector() && opt_vector && opt_idx >= 0 && opt_idx < opt_vector->size() && opt_vector->is_nil(opt_idx))
return _L("N/A");
wxString out;
@@ -1472,46 +1504,55 @@ void UnsavedChangesDialog::update(Preset::Type type, PresetCollection* dependent
update_list();
}
void UnsavedChangesDialog::update_list()
void UnsavedChangesDialog::update_list(SyncExtruderParams *params)
{
if (!m_scrolledWindow) {
Layout();
Fit();
return;
}
std::map<wxString, std::vector<PresetItem>> class_g_list;
std::map<wxString, std::vector<wxString>> class_c_list;
std::vector<wxString> category_list;
// group
for (auto i = 0; i < m_presetitems.size(); i++) {
if (class_g_list.count(m_presetitems[i].group_name) <= 0) {
auto name = m_presetitems[i].category_name + ":" + m_presetitems[i].group_name;
if (class_g_list.count(name) <= 0) {
std::vector<PresetItem> vp;
vp.push_back(m_presetitems[i]);
class_g_list.emplace(m_presetitems[i].group_name, vp);
class_g_list.emplace(name, vp);
} else {
//for (auto iter = class_g_list.begin(); iter != class_g_list.end(); iter++) iter->second.push_back(m_presetitems[i]);
class_g_list[m_presetitems[i].group_name].push_back(m_presetitems[i]);
class_g_list[name].push_back(m_presetitems[i]);
}
}
// category
for (auto i = 0; i < m_presetitems.size(); i++) {
auto name = m_presetitems[i].category_name + ":" + m_presetitems[i].group_name;
if (class_c_list.count(m_presetitems[i].category_name) <= 0) {
std::vector<wxString> vp;
vp.push_back(m_presetitems[i].group_name);
vp.push_back(name);
class_c_list.emplace(m_presetitems[i].category_name, vp);
category_list.push_back(m_presetitems[i].category_name);
} else {
/*for (auto iter = class_c_list.begin(); iter != class_c_list.end(); iter++)
iter->second.push_back(m_presetitems[i].group_name);*/
//class_c_list[m_presetitems[i].category_name].push_back(m_presetitems[i].group_name);
std::vector<wxString>::iterator it;
it = find(class_c_list[m_presetitems[i].category_name].begin(), class_c_list[m_presetitems[i].category_name].end(), m_presetitems[i].group_name);
it = find(class_c_list[m_presetitems[i].category_name].begin(), class_c_list[m_presetitems[i].category_name].end(), name);
if (it == class_c_list[m_presetitems[i].category_name].end()) {
class_c_list[m_presetitems[i].category_name].push_back(m_presetitems[i].group_name);
class_c_list[m_presetitems[i].category_name].push_back(name);
}
}
}
auto m_listsizer = new wxBoxSizer(wxVERTICAL);
for (auto iter = class_c_list.begin(); iter != class_c_list.end(); iter++) {
for (auto category : category_list) {
auto iter = class_c_list.find(category);
//category
auto panel_category = new wxPanel(m_scrolledWindow, wxID_ANY, wxDefaultPosition, wxSize(-1, UNSAVE_CHANGE_DIALOG_ITEM_HEIGHT), wxTAB_TRAVERSAL);
panel_category->SetBackgroundColour(GREY300);
@@ -1554,7 +1595,7 @@ void UnsavedChangesDialog::update_list()
wxBoxSizer *sizer_left_v = new wxBoxSizer(wxVERTICAL);
auto text_left = new wxStaticText(panel_left, wxID_ANY, gname, wxDefaultPosition, wxSize(-1, -1), 0);
auto text_left = new wxStaticText(panel_left, wxID_ANY, class_g_list[gname][0].group_name, wxDefaultPosition, wxSize(-1, -1), 0);
text_left->SetFont(::Label::Head_13);
text_left->Wrap(-1);
text_left->SetForegroundColour(GREY700);
@@ -1601,7 +1642,7 @@ void UnsavedChangesDialog::update_list()
auto text_oldv = new wxStaticText(panel_oldv, wxID_ANY, data.old_value, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
text_oldv->SetFont(::Label::Body_13);
text_oldv->Wrap(-1);
text_oldv->SetForegroundColour(GREY700);
text_oldv->SetForegroundColour(params && params->left_to_right ? wxGetApp().get_label_clr_modified() : GREY700);
sizer_old_v->Add(text_oldv, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5);
panel_oldv->SetSizer(sizer_old_v);
@@ -1615,7 +1656,7 @@ void UnsavedChangesDialog::update_list()
auto text_newv = new wxStaticText(panel_newv, wxID_ANY, data.new_value, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
text_newv->SetFont(::Label::Body_13);
text_newv->Wrap(-1);
text_newv->SetForegroundColour(GREY700);
text_newv->SetForegroundColour(params && !params->left_to_right ? wxGetApp().get_label_clr_modified() : GREY700);
sizer_new_v->Add(text_newv, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5);
@@ -1640,13 +1681,14 @@ void UnsavedChangesDialog::update_list()
}
m_scrolledWindow->SetSizer(m_listsizer);
// m_scrolledWindow->Layout();
wxSize text_size = m_action_line->GetTextExtent(m_action_line->GetLabel());
m_scrolledWindow->Layout();
/*wxSize text_size = m_action_line->GetTextExtent(m_action_line->GetLabel());
int width = UNSAVE_CHANGE_DIALOG_ACTION_LINE_SIZE.GetWidth();
// +2: Ensure that there is at least one line and that the content contains '\n'
int rows = int(text_size.GetWidth() / width) + 2;
int rows = int(text_size.GetWidth() / width) + 2;
int height = rows * text_size.GetHeight();
m_action_line->SetMinSize(wxSize(width, height));
m_action_line->Wrap(UNSAVE_CHANGE_DIALOG_ACTION_LINE_SIZE.GetWidth());*/
Layout();
Fit();
}
@@ -1662,6 +1704,23 @@ std::string UnsavedChangesDialog::subreplace(std::string resource_str, std::stri
return dst_str;
}
void UnsavedChangesDialog::update_tree(Preset::Type type, DynamicConfig * config, int from, int to)
{
Search::OptionsSearcher &searcher = wxGetApp().sidebar().get_searcher();
searcher.sort_options_by_key();
for (const std::string &opt_key : config->keys()) {
int variant_index = -2;
const Search::Option &option = searcher.get_option(opt_key, type, variant_index);
auto category = option.category_local;
auto opt = dynamic_cast<ConfigOptionVectorBase*>(config->option(opt_key));
std::string value_from = opt->vserialize()[from];
std::string value_to = opt->vserialize()[to];
PresetItem pi = {type, opt_key, category, option.group_local, option.label_local, into_u8(value_from), into_u8(value_to)};
m_presetitems.push_back(pi);
}
}
void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* presets_)
{
Search::OptionsSearcher& searcher = wxGetApp().sidebar().get_searcher();
@@ -1693,8 +1752,7 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres
//m_tree->model->AddPreset(type, from_u8(presets->get_edited_preset().name), old_pt);
// Collect dirty options.
const bool deep_compare = (type == Preset::TYPE_PRINTER ||
type == Preset::TYPE_FILAMENT || type == Preset::TYPE_SLA_MATERIAL);
const bool deep_compare = (type == Preset::TYPE_PRINTER || type == Preset::TYPE_PRINT || type == Preset::TYPE_FILAMENT || type == Preset::TYPE_SLA_MATERIAL);
auto dirty_options = presets->current_dirty_options(deep_compare);
// process changes of extruders count
@@ -1714,18 +1772,32 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres
}
}
auto variant_key = Preset::get_iot_type_string(type) + "_extruder_variant";
auto id_key = Preset::get_iot_type_string(type) + "_extruder_id";
auto extruder_variant = dynamic_cast<ConfigOptionStrings const *>(old_config.option(variant_key));
auto extruder_id = dynamic_cast<ConfigOptionInts const *>(old_config.option(id_key));
for (const std::string& opt_key : dirty_options) {
const std::string lookup_key = get_pure_opt_key(opt_key);
Search::Option option = searcher.get_option(lookup_key, type);
if (get_pure_opt_key(option.opt_key()) != lookup_key)
option = searcher.get_option(opt_key, get_full_label(opt_key, new_config), type);
if (get_pure_opt_key(option.opt_key()) != lookup_key) {
// When the found option is not the requested one.
// This can happen for dirty_options such as:
// "default_print_profile", "printer_model", "printer_settings_id",
// because they do not exist in the searcher.
int variant_index = -2;
const Search::Option &option = searcher.get_option(opt_key, type, variant_index);
if (option.opt_key() != opt_key && variant_index < -1) {
// When founded option isn't the correct one.
// It can be for dirty_options: "default_print_profile", "printer_model", "printer_settings_id",
// because of they don't exist in searcher
continue;
}
auto category = option.category_local;
if (variant_index >= 0) {
if (printer_options_with_variant_2.count(opt_key.substr(0, opt_key.find_last_of('#'))) > 0)
variant_index /= 2;
if (boost::nowide::narrow(category).find("Extruder ") == 0)
category = category.substr(0, 8);
if (extruder_id)
category = category + (wxString(" {") + (extruder_id->values[variant_index] == 1 ? _L("Left: ") : _L("Right: "))
+ L(extruder_variant->values[variant_index]) + "}");
else
category = category + (wxString(" {") + L(extruder_variant->values[variant_index]) + "}");
}
/*m_tree->Append(opt_key, type, option.category_local, option.group_local, option.label_local,
get_string_value(opt_key, old_config), get_string_value(opt_key, new_config), category_icon_map.at(option.category));*/
@@ -1733,7 +1805,7 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres
//PresetItem pi = {opt_key, type, 1983};
//m_presetitems.push_back()
PresetItem pi = {type, opt_key, option.category_local, option.group_local, option.label_local, get_string_value(opt_key, old_config), get_string_value(opt_key, new_config)};
PresetItem pi = {type, opt_key, category, option.group_local, option.label_local, get_string_value(opt_key, old_config), get_string_value(opt_key, new_config)};
m_presetitems.push_back(pi);
}
@@ -2273,7 +2345,7 @@ void DiffPresetDialog::update_tree()
wxString right_val = get_string_value(opt_key, right_congig);
const std::string lookup_key = get_pure_opt_key(opt_key);
Search::Option option = searcher.get_option(lookup_key, type);
Search::Option option = searcher.get_option(lookup_key, get_full_label(lookup_key, left_config), type);
if (get_pure_opt_key(option.opt_key()) != lookup_key)
option = searcher.get_option(opt_key, get_full_label(opt_key, left_config), type);
if (get_pure_opt_key(option.opt_key()) != lookup_key) {