From 34de2b49dfe8bc3fc1eefebdde9c6a82865a0242 Mon Sep 17 00:00:00 2001 From: Ian Bassi Date: Wed, 11 Nov 2026 19:18:28 -0300 Subject: [PATCH] Copy per-nozzle settings to every tool of a toolchanger, and choose which unsaved changes to keep (#17461) Co-authored-by: raistlin7447 --- docs/HLSD/per-nozzle-settings.md | 122 ++++ src/libslic3r/ParameterUtils.cpp | 52 ++ src/libslic3r/ParameterUtils.hpp | 4 + src/libslic3r/PrintConfig.cpp | 2 + src/slic3r/GUI/SettingsIndex.cpp | 6 + src/slic3r/GUI/SettingsIndex.hpp | 2 +- src/slic3r/GUI/Tab.cpp | 327 +++++---- src/slic3r/GUI/Tab.hpp | 4 +- src/slic3r/GUI/UnsavedChangesDialog.cpp | 829 +++++++++++++++-------- src/slic3r/GUI/UnsavedChangesDialog.hpp | 78 ++- tests/libslic3r/test_parameter_utils.cpp | 44 ++ 11 files changed, 1042 insertions(+), 428 deletions(-) create mode 100644 docs/HLSD/per-nozzle-settings.md diff --git a/docs/HLSD/per-nozzle-settings.md b/docs/HLSD/per-nozzle-settings.md new file mode 100644 index 0000000000..ad9f208560 --- /dev/null +++ b/docs/HLSD/per-nozzle-settings.md @@ -0,0 +1,122 @@ +# Per-nozzle settings — High Level Design + +## Purpose and scope + +On printers with several extruders, or with extruders that take different +nozzles, some settings must differ per nozzle: speeds and accelerations depend +on the nozzle's flow, retraction on the drive, and a filament's flow ratio or +temperature on both. These settings are stored once per *nozzle variant* instead +of once per preset. This document covers how the variants are stored, how a +value is found for an extruder, how the settings tabs edit them, and how the copy +button moves values between extruders or variants. + +## Variants and columns + +A variant is the pair of an extruder type and a nozzle volume type, written as +one string such as "Direct Drive Standard" or "Direct Drive High Flow". The +printer's `extruder_variant_list` holds, per extruder, the comma-separated +variants that extruder can take. Which one is in use comes from the project's +`nozzle_volume_type`, one entry per extruder, set in the sidebar. A Hybrid +extruder carries both Standard and High Flow nozzles, and each filament's own +volume type picks between them. + +Each per-variant setting is a vector with one value per *column*. Two parallel +vectors describe the columns of a preset: + +| Scope | Settings | Column keys | Values per column | +|----------|---------------------------------------------------|---------------------------------------------------|-------------------| +| Process | `print_options_with_variant` | `print_extruder_id`, `print_extruder_variant` | 1 | +| Printer | `printer_options_with_variant_1` | `printer_extruder_id`, `printer_extruder_variant` | 1 | +| Printer | `printer_options_with_variant_2` (machine limits) | `printer_extruder_id`, `printer_extruder_variant` | 2: normal, silent | +| Filament | `filament_options_with_variant` | `filament_extruder_variant` | 1 | + +A process or printer column belongs to one extruder (the id, 1-based) and one +variant. A filament column belongs only to a variant, and every extruder of that +variant shares it. Printer settings outside these sets that are still vectors, +such as `nozzle_diameter`, `extruder_type` or `extruder_offset`, have one value +per extruder instead. + +`DynamicPrintConfig::get_index_for_extruder` finds the column of an extruder: +the first whose id matches and whose variant string equals the extruder's type +and nozzle volume type, Hybrid counting as Standard. Given a stride, it returns +the position of the column's first value, and -1 when there is no such column. + +## Loading, sizing and slicing + +Profiles may store fewer values than columns, often a single value meant for +every column. `extend_default_config_length` pads every per-variant setting to +its column count with its first value whenever a preset is loaded: system, user, +cloud and project presets alike. User presets start from their parent's padded +vectors and apply their own values per variant. After loading, every column has +a value of its own, so editing one column never changes another. + +The printer's columns follow its extruder count. `set_num_extruders` rebuilds +`printer_extruder_id` and `printer_extruder_variant` from `extruder_variant_list` +and resizes the per-variant and per-extruder printer settings, padding new +entries with the first value. + +A process ships with columns for the tools of its profile. Raising the printer's +extruder count does not give it columns for the new tools, so +`add_process_columns_for_new_tools` adds one per variant of each such tool, +copied from tool 1's column of the same variant (the first column when tool 1 +has no such variant). The settings tabs run it in memory on every copy the +edited process is compared with: the selected preset, its parent, the edited +preset and, when it was clean, the saved baseline. The added columns therefore +never show as changes. A process with a single column is left alone: its one +value applies to every tool, and splitting it would make an edit reach the first +tool only. + +For slicing, `update_values_to_printer_extruders` reduces each per-variant +setting to one value per slot, a slot being an extruder and a nozzle volume type +it prints with. A slot without a column of its own reads the first column. A +process that still has one column is given a column per extruder variant first +(`ensure_process_variant_columns`), all holding that value. + +## Editing in the settings tabs + +The process and printer tabs have an extruder switch, the filament tab a variant +switch. Its tags name the selection as the user sees it: "T2 HF" on the process +tab, "Extruder 2: HF" on the printer tab, "Direct Drive HF" on the filament tab, +and the left and right nozzle names on Bambu dual-nozzle printers. +`switch_excluder` points every per-variant field of the pages at the selected +column. On the printer's Extruder page, the fields of per-extruder settings point +at the selected extruder instead. Groups holding such fields draw the per-nozzle +icon next to them. + +## Copying between extruders and variants + +The copy button next to the switch copies the values modified on the current +page, for the selected extruder or variant, to the others. What a value may be +copied to depends on the page: + +- On the process tab and the printer's Motion ability page, to every extruder + with the same extruder type whose nozzle has the selected nozzle volume type, + or is Hybrid. Values go into that extruder's column of the same variant. +- On the printer's Extruder page, per-extruder settings go to every other + extruder. Per-variant settings follow the rule above, so an extruder with + another nozzle volume type gets only the per-extruder ones. +- On the filament tab, to the filament's other variants. + +Values are never copied across nozzle volume types on the process and printer +tabs: Standard and High Flow values are tuned separately, and a copy would +overwrite one with the other. + +The copy is confirmed in the unsaved changes dialog in a copy mode. It shows one +column per extruder or variant, titled with the switch tags, and one row per +setting. Each setting carries its own position in every column, because one page +can mix per-variant and per-extruder settings. A cell whose value would change +has a checkbox, ticked by default. A cell without a value of that setting stays +empty. Tick-all boxes cover each row, group, category and column, and one covers +everything. Only the ticked values are written. + +## Implementation and verification + +The column handling lives in `PrintConfig.cpp` (`get_index_for_extruder`, +`update_values_to_printer_extruders`, `set_num_extruders`) and `Preset.cpp` +(`extend_default_config_length`). `add_process_columns_for_new_tools` is in +`ParameterUtils.cpp`. The switches, the copy button and the in-memory +completion are in `Tab.cpp`, the dialog in `UnsavedChangesDialog.cpp`. + +`tests/libslic3r/test_parameter_utils.cpp` covers the columns added for new +tools, and `tests/libslic3r/test_config_variant_expansion.cpp` the slicing +expansion. diff --git a/src/libslic3r/ParameterUtils.cpp b/src/libslic3r/ParameterUtils.cpp index 2edaa6b00e..612fbc395a 100644 --- a/src/libslic3r/ParameterUtils.cpp +++ b/src/libslic3r/ParameterUtils.cpp @@ -1,6 +1,12 @@ #include "ParameterUtils.hpp" +#include "Config.hpp" #include "PrintConfig.hpp" +#include +#include +#include +#include #include +#include #include #include #include @@ -88,4 +94,50 @@ int get_index_for_extruder_parameter(const DynamicPrintConfig &config, const std return variant_index; } +bool add_process_columns_for_new_tools(DynamicPrintConfig &process_config, const DynamicPrintConfig &printer_config) +{ + auto *ids = process_config.option("print_extruder_id"); + auto *variants = process_config.option("print_extruder_variant"); + const auto *tools = printer_config.option("extruder_variant_list"); + // A single column is shared by every tool; splitting it would make an edit reach the first tool only. + if (ids == nullptr || variants == nullptr || tools == nullptr || ids->size() < 2 || ids->size() != variants->size()) + return false; + + const size_t columns = ids->size(); + std::vector sources; // the column each added one copies + for (int tool = 1; tool <= int(tools->size()); ++tool) { + if (std::find(ids->values.begin(), ids->values.end(), tool) != ids->values.end()) + continue; + std::vector tool_variants; + boost::split(tool_variants, tools->get_at(tool - 1), boost::is_any_of(","), boost::token_compress_on); + for (std::string &variant : tool_variants) { + boost::trim(variant); + if (variant.empty()) + continue; + // Without a tool 1 column of this variant, the first column, which slicing falls back to. + size_t source = 0; + for (size_t i = 0; i < columns; ++i) + if (ids->values[i] == 1 && variants->values[i] == variant) { + source = i; + break; + } + ids->values.push_back(tool); + variants->values.push_back(variant); + sources.push_back(source); + } + } + if (sources.empty()) + return false; + + for (const std::string &key : print_options_with_variant) { + auto *opt = dynamic_cast(process_config.option(key)); + // An option with fewer values than columns gives the missing ones its first value already. + if (opt == nullptr || opt == ids || opt == variants || opt->size() != columns) + continue; + for (size_t source : sources) + opt->set_at(opt, opt->size(), source); + } + return true; +} + }; // namespace Slic3r diff --git a/src/libslic3r/ParameterUtils.hpp b/src/libslic3r/ParameterUtils.hpp index bf475c16bd..649492879c 100644 --- a/src/libslic3r/ParameterUtils.hpp +++ b/src/libslic3r/ParameterUtils.hpp @@ -13,6 +13,10 @@ std::vector get_other_layers_print_sequence(int sequence_num void get_other_layers_print_sequence(const std::vector &customize_sequences, int &sequence_nums, std::vector &sequence); extern int get_index_for_extruder_parameter(const DynamicPrintConfig &config, const std::string &opt_key, int cur_extruder_id, ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type); + +// Gives a per-tool process a column per variant for each printer tool it has none for, copied from tool 1's column of +// that variant. Returns whether it added any. See docs/HLSD/per-nozzle-settings.md. +bool add_process_columns_for_new_tools(DynamicPrintConfig &process_config, const DynamicPrintConfig &printer_config); } // namespace Slic3r #endif // slic3r_Parameter_Utils_hpp_ diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 60d2fdc03a..dea9b68c6b 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -10109,6 +10109,8 @@ std::set print_options_with_variant = { "inner_wall_speed", "small_perimeter_speed", //coFloatsOrPercents "small_perimeter_threshold", + "small_support_perimeter_speed", //coFloatsOrPercents + "small_support_perimeter_threshold", "sparse_infill_speed", "internal_solid_infill_speed", "top_surface_speed", diff --git a/src/slic3r/GUI/SettingsIndex.cpp b/src/slic3r/GUI/SettingsIndex.cpp index ffd5cdadeb..3ef58b9f5f 100644 --- a/src/slic3r/GUI/SettingsIndex.cpp +++ b/src/slic3r/GUI/SettingsIndex.cpp @@ -233,6 +233,12 @@ Option SettingsIndex::get_option(const std::string &opt_key, const wxString &lab return create_option(opt_key, label, type, gc); } +GroupAndCategory SettingsIndex::get_group_and_category(const std::string &opt_key, Preset::Type type) const +{ + auto it = m_groups_and_categories.find(get_key(opt_key, type)); + return it == m_groups_and_categories.end() ? GroupAndCategory{} : it->second; +} + void SettingsIndex::add_key(const std::string &opt_key, Preset::Type type, const wxString &group, const wxString &category, const wxString &icon) { // Update fields in place so a page rebuild (get_option after set_path) doesn't drop the diff --git a/src/slic3r/GUI/SettingsIndex.hpp b/src/slic3r/GUI/SettingsIndex.hpp index fd29696a08..9f894c0a6b 100644 --- a/src/slic3r/GUI/SettingsIndex.hpp +++ b/src/slic3r/GUI/SettingsIndex.hpp @@ -112,7 +112,7 @@ public: const Option &get_option(const std::string &opt_key, Preset::Type type, int &variant_index) const; Option get_option(const std::string &opt_key, const wxString &label, Preset::Type type) const; - const GroupAndCategory &get_group_and_category(const std::string &opt_key) { return m_groups_and_categories[opt_key]; } + GroupAndCategory get_group_and_category(const std::string &opt_key, Preset::Type type) const; void sort_options_by_key() { diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 081c85a4da..3cddbb97d8 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -557,6 +557,23 @@ void Tab::create_preset_tab() m_main_sizer->Add(m_tabctrl, 0, wxEXPAND | wxALL, 0 ); + // The copy button, in a box whose tooltip shows while the button is disabled. + auto create_extruder_sync = [this, panel]() { + m_extruder_sync_box = new wxPanel(panel, wxID_ANY); + m_extruder_sync_box->SetBackgroundColour(panel->GetBackgroundColour()); + m_extruder_sync_box->SetToolTip(_L("Synchronization of different extruder drives or nozzle volume types is not supported.")); + m_extruder_sync = nullptr; + add_scaled_button(m_extruder_sync_box, &m_extruder_sync, "extruder_sync"); + m_extruder_sync->SetToolTip(_L("Synchronize the modification of parameters to the corresponding parameters of another extruder.")); + m_extruder_sync->Bind(wxEVT_BUTTON, [this](auto &evt) { + evt.Skip(); + sync_excluder(); + }); + auto sync_box_sizer = new wxBoxSizer(wxHORIZONTAL); + sync_box_sizer->Add(m_extruder_sync, 1, wxEXPAND); + m_extruder_sync_box->SetSizer(sync_box_sizer); + }; + if (dynamic_cast(this) || dynamic_cast(this)) { m_extruder_switch = new MultiSwitchButton(panel); m_extruder_switch->SetFont(Label::Body_11); @@ -575,25 +592,12 @@ void Tab::create_preset_tab() switch_excluder(extruder_id); }); - m_extruder_sync_box = new wxPanel(panel, wxID_ANY); - m_extruder_sync_box->SetBackgroundColour(panel->GetBackgroundColour()); - m_extruder_sync_box->SetToolTip(_L("Synchronization of different extruder drives or nozzle volume types is not supported.")); - m_extruder_sync = nullptr; - add_scaled_button(m_extruder_sync_box, &m_extruder_sync, "extruder_sync"); - m_extruder_sync->SetToolTip(_L("Synchronize the modification of parameters to the corresponding parameters of another extruder.")); - m_extruder_sync->Bind(wxEVT_BUTTON, [this](auto &evt) { - evt.Skip(); - sync_excluder(); - }); + create_extruder_sync(); ScalableButton* icon = nullptr; add_scaled_button(panel, &icon, "multi_extruder"); icon->SetToolTip(_L("Parameters with this icon can be configured per nozzle.")); - auto sync_box_sizer = new wxBoxSizer(wxHORIZONTAL); - sync_box_sizer->Add(m_extruder_sync, 1, wxEXPAND); - m_extruder_sync_box->SetSizer(sync_box_sizer); - m_variant_sizer = new wxBoxSizer(wxHORIZONTAL); auto right_sizer = new wxBoxSizer(wxHORIZONTAL); auto left_sizer = new wxBoxSizer(wxHORIZONTAL); @@ -625,10 +629,13 @@ void Tab::create_preset_tab() ScalableButton* icon = nullptr; add_scaled_button(panel, &icon, "multi_extruder"); icon->SetToolTip(_L("Parameters with this icon can be configured per nozzle.")); + create_extruder_sync(); wxBoxSizer *top_sizer = new wxBoxSizer(wxHORIZONTAL); top_sizer->Add(icon, 0, wxALIGN_CENTER_VERTICAL); top_sizer->Add(m_variant_combo, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(2)); + top_sizer->AddStretchSpacer(1); + top_sizer->Add(m_extruder_sync_box, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, m_em_unit); m_variant_sizer = new wxBoxSizer(wxVERTICAL); m_variant_sizer->Add(top_sizer, 0, wxEXPAND | wxLEFT, m_em_unit); @@ -2074,6 +2081,21 @@ static wxString pad_combo_value_for_config(const DynamicPrintConfig &config) return config.opt_bool("pad_enable") ? (config.opt_bool("pad_around_object") ? _("Around object") : _("Below object")) : _("None"); } +// Orca: gives the process columns for tools its profile lacks, e.g. after the extruder count was raised. Every copy the +// edited process is compared with gets the same columns, so they do not show as changes. +static void add_selected_process_columns_for_new_tools(PresetBundle &bundle) +{ + PresetCollection &prints = bundle.prints; + const DynamicPrintConfig &printer = bundle.printers.get_edited_preset().config; + const bool saved = !prints.saved_is_dirty(); + add_process_columns_for_new_tools(prints.get_selected_preset().config, printer); + if (const Preset *parent = prints.get_selected_preset_parent()) + if (Preset *preset = prints.find_preset(parent->name)) + add_process_columns_for_new_tools(preset->config, printer); + if (add_process_columns_for_new_tools(prints.get_edited_preset().config, printer) && saved) + prints.update_saved_preset_from_current_preset(); +} + // Rebuilds the variant switch of every tab that has one, e.g. after the extruder count or a nozzle volume type changed. static void update_all_extruder_variants(int extruder_idx = -1) { @@ -5870,6 +5892,7 @@ void TabPrinter::extruders_count_changed(size_t extruders_count) if (m_extruders_count != extruders_count) { m_extruders_count = extruders_count; m_preset_bundle->on_extruders_count_changed(extruders_count); + add_selected_process_columns_for_new_tools(*m_preset_bundle); is_count_changed = true; wxGetApp().plater()->get_partplate_list().on_extruder_count_changed((int)m_extruders_count); @@ -7252,6 +7275,7 @@ void Tab::load_current_preset() wxGetApp().obj_list()->update_objects_list_filament_column(1); } if (m_type == Preset::TYPE_PRINT) { + add_selected_process_columns_for_new_tools(*m_preset_bundle); if (auto tab = wxGetApp().plate_tab) { tab->m_config->apply(*m_config); tab->update_extruder_variants(); @@ -8758,7 +8782,7 @@ wxSizer* TabPrinter::create_bed_shape_widget(wxWindow* parent) { Search::SettingsIndex& index = wxGetApp().sidebar().settings_index(); - const Search::GroupAndCategory& gc = index.get_group_and_category("printable_area"); + const Search::GroupAndCategory gc = index.get_group_and_category("printable_area", m_type); index.add_key("bed_custom_texture", m_type, gc.group, gc.category, gc.icon); index.add_key("bed_custom_model", m_type, gc.group, gc.category, gc.icon); } @@ -9048,6 +9072,18 @@ static wxString short_nozzle_volume_name(const std::string &volume_name) return from_u8(volume_name); } +// Orca: Bambu dual-nozzle printers name their toolheads (extruder 0 is the left, deputy one); others number their tools. +static bool has_toolhead_names(PresetBundle &bundle) { return bundle.get_printer_extruder_count() == 2 && bundle.is_bbl_vendor(); } + +static wxString extruder_display_name(PresetBundle &bundle, int extruder, ToolHeadNameCase name_case, bool short_name = false) +{ + if (!has_toolhead_names(bundle)) + return wxString::Format("T%d", extruder + 1); + const std::string pt = bundle.printers.get_edited_preset().get_printer_type(&bundle); + return _L(DevPrinterConfigUtil::get_toolhead_display_name(pt, extruder == 0 ? DEPUTY_EXTRUDER_ID : MAIN_EXTRUDER_ID, + ToolHeadComponent::Nozzle, name_case, short_name)); +} + std::vector Tab::generate_extruder_options() { std::vector options; @@ -9103,22 +9139,22 @@ std::vector Tab::generate_extruder_options() // Orca: the printer tab has one tag per extruder, named as its former "Extruder N" pages were. // parse_extruder_selection() counts a hybrid extruder as two tags; that still lines up because - // only the last extruder can be hybrid. + // only the last extruder can be hybrid. When the extruders have nozzle variants, the tag also names + // the one its pages edit, which the sidebar's nozzle volume type selects. if (m_type == Preset::TYPE_PRINTER) { - for (int i = 0; i < extruder_nums; ++i) - options.push_back(translate_category(wxString::Format("Extruder %d", i + 1), m_type)); + for (int i = 0; i < extruder_nums; ++i) { + wxString name = translate_category(wxString::Format("Extruder %d", i + 1), m_type); + const NozzleVolumeType volume_type = NozzleVolumeType(nozzle_volumes->values[i]); + if (m_extruder_switch_variants && volume_type != NozzleVolumeType::nvtHybrid) + // TRN Printer settings extruder tab: the extruder's name, e.g. "Extruder 2", and its nozzle flow tag, e.g. "HF". + name = wxString::Format(_L("%s: %s"), name, short_nozzle_volume_name(get_nozzle_volume_type_string(volume_type))); + options.push_back(name); + } return options; } - std::string pt = m_preset_bundle->printers.get_edited_preset().get_printer_type(m_preset_bundle); - // Orca: the main/deputy toolhead names describe a Bambu dual-nozzle printer, where extruder 0 is - // the left (deputy) and extruder 1 the right (main) nozzle. Other printers number their tools. - const bool toolhead_names = extruder_nums == 2 && m_preset_bundle->is_bbl_vendor(); for (int i = 0; i < extruder_nums; ++i) { - wxString extruder_name = !toolhead_names ? wxString::Format("T%d", i + 1) : - _L(DevPrinterConfigUtil::get_toolhead_display_name( - pt, (i == 0) ? DEPUTY_EXTRUDER_ID : MAIN_EXTRUDER_ID, - ToolHeadComponent::Nozzle, ToolHeadNameCase::TitleCase, true)); + wxString extruder_name = extruder_display_name(*m_preset_bundle, i, ToolHeadNameCase::TitleCase, true); NozzleVolumeType volume_type = NozzleVolumeType(nozzle_volumes->values[i]); if (volume_type == NozzleVolumeType::nvtHybrid) { @@ -9217,60 +9253,33 @@ NozzleVolumeType Tab::get_actual_nozzle_volume_type(int extruder_id) return m_actual_nozzle_volumes[extruder_id]; } -bool Tab::get_extruder_sync_enable_state(int extruder_id) +std::vector Tab::get_extruder_sync_targets(int extruder_id) { - Preset& printer_preset = m_preset_bundle->printers.get_edited_preset(); auto nozzle_volumes = m_preset_bundle->project_config.option("nozzle_volume_type"); - auto extruders = printer_preset.config.option("extruder_type"); - // Orca: every rule below describes the two toolheads of a dual-nozzle printer as left/right. - // A printer with any other extruder count has no single counterpart to copy to, so it gets no - // sync button (a toolchanger would need a target to be chosen). - if (nozzle_volumes->values.size() != 2 || extruders->values.size() != 2) { - return false; + auto extruders = m_preset_bundle->printers.get_edited_preset().config.option("extruder_type"); + const int count = int(std::min(nozzle_volumes->size(), extruders->size())); + std::vector targets; + if (extruder_id < 0 || extruder_id >= count) + return targets; + // A target needs the same drive and a nozzle that has the active nozzle's volume type. + const NozzleVolumeType nozzle = get_actual_nozzle_volume_type(extruder_id); + for (int i = 0; i < count; ++i) { + const auto volume = NozzleVolumeType(nozzle_volumes->values[i]); + if (i != extruder_id && extruders->values[i] == extruders->values[extruder_id] && + (volume == nozzle || volume == NozzleVolumeType::nvtHybrid)) + targets.push_back(i); } + return targets; +} - NozzleVolumeType left_nozzle = NozzleVolumeType(nozzle_volumes->values[0]); - NozzleVolumeType right_nozzle = NozzleVolumeType(nozzle_volumes->values[1]); - ExtruderType left_extruder = ExtruderType(extruders->values[0]); - ExtruderType right_extruder = ExtruderType(extruders->values[1]); - - if (left_extruder != right_extruder) { - return false; - } - - if (left_nozzle == right_nozzle) { - return true; - } - - if (left_nozzle != NozzleVolumeType::nvtHybrid && right_nozzle != NozzleVolumeType::nvtHybrid) { - return false; - } - - if (left_nozzle == NozzleVolumeType::nvtHybrid && right_nozzle == NozzleVolumeType::nvtHybrid) { - return true; - } - - // Hybrid rules - auto current_nozzle = get_actual_nozzle_volume_type(extruder_id); - if (left_nozzle != NozzleVolumeType::nvtHybrid) { - if (extruder_id == 0) { - return true; - } - if (extruder_id == 1 && current_nozzle == left_nozzle) { - return true; - } - return false; - } - if (right_nozzle != NozzleVolumeType::nvtHybrid) { - if (extruder_id == 1) { - return true; - } - if (extruder_id == 0 && current_nozzle == right_nozzle) { - return true; - } - return false; - } - return false; +bool Tab::extruder_sync_enabled() +{ + // Orca: a filament copies between its nozzle variants, and the printer's Extruder page between any extruders. + if (m_variant_combo) + return m_variant_combo->IsThisEnabled(); + if (is_printer_extruder_page(m_active_page)) + return m_preset_bundle->get_printer_extruder_count() >= 2; + return m_extruder_switch_variants && !get_extruder_sync_targets(get_current_active_extruder()).empty(); } bool Tab::variant_switch_active() const @@ -9288,9 +9297,7 @@ void Tab::update_variant_sizer_visibility() m_main_sizer->Show(m_variant_sizer, show); if (m_extruder_sync) { m_extruder_sync->Show(show); - // Orca: copying between extruders is offered only between nozzle variants, and not on the Extruder page. - m_extruder_sync->Enable(m_extruder_switch_variants && !is_printer_extruder_page(m_active_page) && - get_extruder_sync_enable_state(get_current_active_extruder())); + m_extruder_sync->Enable(extruder_sync_enabled()); } GetParent()->Layout(); } @@ -9307,10 +9314,10 @@ void Tab::switch_excluder(int extruder_id, bool reload) extruder_id = get_current_active_extruder(); if (!m_variant_combo && (extruder_id >= (int)nozzle_volumes->size() || extruder_id >= (int)extruders->size())) extruder_id = 0; + if (m_extruder_sync) + m_extruder_sync->Enable(extruder_sync_enabled()); if (m_extruder_switch) { int current_extruder = get_current_active_extruder(); - bool sync_enable = get_extruder_sync_enable_state(current_extruder); - m_extruder_sync->Enable(m_extruder_switch_variants && sync_enable && !is_printer_extruder_page(m_active_page)); m_extruder_sync->Show(); if (m_type != Preset::TYPE_PRINTER) { if (extruder_id == -1) @@ -9355,6 +9362,7 @@ void Tab::switch_excluder(int extruder_id, bool reload) const int idx = printer_options_with_variant_1.count(opt.second.first) > 0 ? page_index : extruder_id; const_cast(opt.second.second) = idx; page->m_opt_id_map.insert({opt.second.first + "#" + std::to_string(idx), opt.first}); + group->draw_multi_extruder = variant_switch_active(); continue; } auto iter = std::find(printer_extruder_options.begin(), printer_extruder_options.end(), opt.second.first); @@ -9383,76 +9391,145 @@ void Tab::switch_excluder(int extruder_id, bool reload) void Tab::sync_excluder() { - Preset & printer_preset = m_preset_bundle->printers.get_edited_preset(); - auto nozzle_volumes = m_preset_bundle->project_config.option("nozzle_volume_type"); - auto extruders = printer_preset.config.option("extruder_type"); + // Orca: copies the modified values of the switch's selection to the extruders that can take them, or, on the + // filament tab, to the filament's other nozzle variants. Each option keeps its values at its own position in every + // column: the variant column of the active nozzle, the extruder for per-extruder options of the printer's Extruder + // page, the variant for a filament. + const bool extruder_page = is_printer_extruder_page(m_active_page); // Motion ability options hold a (normal, silent) pair per variant, so switch_excluder indexes that page with stride 2. - const int stride = m_active_page->title().StartsWith("Motion ability") ? 2 : 1; - auto get_index_for_extruder = - [this, &extruders, stride, variant_keys = extruder_variant_keys[m_type >= Preset::TYPE_COUNT ? Preset::TYPE_PRINT : m_type]](int extruder_id, NozzleVolumeType nozzle_type) { - return m_config->get_index_for_extruder(extruder_id + 1, variant_keys.first, - ExtruderType(extruders->values[extruder_id]), nozzle_type, variant_keys.second, stride); + const int stride = m_active_page->title().StartsWith("Motion ability") ? 2 : 1; + const Preset::Type base_type = m_type >= Preset::TYPE_COUNT ? Preset::TYPE_PRINT : m_type; + const auto *extruders = m_preset_bundle->printers.get_edited_preset().config.option("extruder_type"); + const int source = m_variant_combo ? std::max(0, m_variant_combo->GetSelection()) : get_current_active_extruder(); + const NozzleVolumeType active_nozzle = m_variant_combo ? NozzleVolumeType::nvtStandard : get_actual_nozzle_volume_type(source); + const std::vector targets = m_variant_combo ? std::vector() : get_extruder_sync_targets(source); + auto position = [&](const std::string &key, int column) -> int { + if (m_variant_combo) + return filament_options_with_variant.count(key) > 0 ? column : -1; + if (extruder_page && printer_options_with_variant_1.count(key) == 0) + return column; + // A per-variant option goes only to an extruder with the same drive and the active nozzle's variant. + if (column != source && std::find(targets.begin(), targets.end(), column) == targets.end()) + return -1; + const auto variant_keys = extruder_variant_keys[base_type]; + return m_config->get_index_for_extruder(column + 1, variant_keys.first, ExtruderType(extruders->values[column]), active_nozzle, + variant_keys.second, stride); }; - int active_index = get_current_active_extruder(); - // The button copies to the other toolhead, so it is only offered when that other one exists; - // without this the `1 - active_index` below would index an extruder that is not there. - if (!get_extruder_sync_enable_state(active_index)) - return; - auto active_nozzle = get_actual_nozzle_volume_type(active_index); - int from_index = get_index_for_extruder(active_index, active_nozzle); - int dest_index = get_index_for_extruder(1 - active_index, active_nozzle); - if (from_index < 0 || dest_index < 0) // no variant column for this nozzle on one of the extruders + + // Extruders, or a filament's nozzle variants, in order. + std::vector columns; + if (m_variant_combo) { + const auto *variants = m_config->option("filament_extruder_variant"); + for (int variant = 0; variants != nullptr && variant < int(variants->size()); ++variant) + columns.push_back(variant); + } else if (extruder_page) { + for (int extruder = 0; extruder < m_preset_bundle->get_printer_extruder_count(); ++extruder) + columns.push_back(extruder); + } else { + if (position("", source) < 0) + return; + columns.push_back(source); + for (int extruder : targets) + if (position("", extruder) >= 0) + columns.push_back(extruder); + std::sort(columns.begin(), columns.end()); + } + if (columns.size() < 2) return; + + UnsavedChangesDialog::SyncExtruderParams params{nullptr, {}, 0, {}}; auto dirty_options = m_presets->current_dirty_options(true); - DynamicConfig config_origin, config_to_apply; + DynamicConfig config_origin; for (int i = 0; i < dirty_options.size(); ++i) { auto &opt = dirty_options[i]; auto n= opt.find('#'); if (n == std::string::npos) continue; - auto field = m_active_page->get_field(opt.substr(0, n), from_index + 256); - auto line = m_active_page->get_line(opt.substr(0, n), from_index + 256); - if (field == nullptr || line == nullptr) - continue; + const std::string key = opt.substr(0, n); + const int from = position(key, source); + auto field = from < 0 ? nullptr : m_active_page->get_field(key, from + 256); + auto line = from < 0 ? nullptr : m_active_page->get_line(key, from + 256); ++n; auto is_from_slot = [&](const std::string &dirty_opt) { int slot = std::atoi(dirty_opt.c_str() + n); - return slot >= from_index && slot < from_index + stride; + return slot >= from && slot < from + stride; }; bool dirty = is_from_slot(opt); while (i + 1 < dirty_options.size() && dirty_options[i + 1].compare(0, n, opt, 0, n) == 0) { dirty |= is_from_slot(dirty_options[i + 1]); ++i; } - if (dirty) { - auto key = opt.substr(0, n - 1); - auto option = dynamic_cast(m_config->option(key)); - auto option2 = dynamic_cast(option->clone()); - for (int s = 0; s < stride; ++s) - option2->set_at(option, dest_index + s, from_index + s); - if (*option == *option2) { - delete option2; - continue; - } - config_origin.set_key_value(key, option->clone()); - config_to_apply.set_key_value(key, option2); + if (field == nullptr || line == nullptr || !dirty) + continue; + UnsavedChangesDialog::SyncExtruderParams::Positions positions{stride, {}}; + size_t width = 0; // values the option needs to hold one for every column + for (int column : columns) { + positions.index.push_back(position(key, column)); + if (positions.index.back() >= 0) + width = std::max(width, size_t(positions.index.back() + stride)); + } + std::unique_ptr origin(dynamic_cast(m_config->option(key)->clone())); + // A vector shorter than the columns gives the missing ones its first value; pad it with that, so the + // dialog can read every column. + if (origin->size() < width) + origin->set_at(origin.get(), width - 1, width - 1); + const std::vector values = origin->vserialize(); + bool changes = false; + for (int index : positions.index) + for (int s = 0; index >= 0 && s < stride; ++s) + changes |= values[index + s] != values[from + s]; + if (changes) { + config_origin.set_key_value(key, origin.release()); + params.positions.emplace(key, std::move(positions)); } } - if (config_to_apply.empty()) { + if (config_origin.empty()) { MessageDialog md(wxGetApp().plater(), _L("No modifications need to be copied."), _L("Copy parameters"), wxICON_INFORMATION | wxOK); md.ShowModal(); return; } - std::string pt = m_preset_bundle->printers.get_edited_preset().get_printer_type(m_preset_bundle); - std::string active_nozzle_name = DevPrinterConfigUtil::get_toolhead_display_name(pt, active_index, ToolHeadComponent::Nozzle, ToolHeadNameCase::LowerCase); - std::string other_nozzle_name = DevPrinterConfigUtil::get_toolhead_display_name(pt, 1 - active_index, ToolHeadComponent::Nozzle, ToolHeadNameCase::LowerCase); - wxString title = wxString::Format(_L("Modify parameters of %s"), _L(active_nozzle_name)); - wxString header = wxString::Format(_L("Do you want to modify the following parameters of the %s to that of the %s?"), - _L(active_nozzle_name), _L(other_nozzle_name)); - UnsavedChangesDialog dlg(title, header, &config_origin, from_index, dest_index, active_index == 0, active_nozzle); + // Orca: the columns are named by this tab's switch tags. + const std::vector tags = generate_extruder_options(); + auto tag_name = [&](int column) { + const size_t tag = m_variant_combo ? size_t(column) : size_t(calculate_selection_index_for_extruder(column, active_nozzle)); + return tag < tags.size() ? tags[tag] : wxString::Format("T%d", column + 1); + }; + // A Bambu dual-nozzle printer's message names its nozzles within a sentence; the others use the tags. + const bool toolheads = !m_variant_combo && has_toolhead_names(*m_preset_bundle); + auto message_name = [&](int column) { + return toolheads ? extruder_display_name(*m_preset_bundle, column, ToolHeadNameCase::LowerCase) : tag_name(column); + }; + params.config = &config_origin; + wxString to_names; + for (int column : columns) { + if (column == source) + params.source = int(params.titles.size()); + else + to_names += (to_names.empty() ? "" : ", ") + message_name(column); + params.titles.push_back(tag_name(column)); + } + const wxString from_name = message_name(source); + wxString title = wxString::Format(_L("Modify parameters of %s"), to_names); + wxString header; + if (toolheads) + header = wxString::Format(_L("Do you want to modify the following parameters of the %s to that of the %s?"), to_names, from_name); + else + // TRN %1% is the extruder (or nozzle variant) the values are copied from, %2% the list of those they are copied to, as the switch names them, e.g. "T2 HF, T3 HF". + header = format_wxstr(_L("Do you want to copy the following parameters of %1% to %2%?"), from_name, to_names); + UnsavedChangesDialog dlg(title, header, base_type, params); dlg.ShowModal(); - if (dlg.transfer_changes()) { + DynamicConfig config_to_apply; + if (dlg.transfer_changes()) + for (const auto &[key, index] : dlg.get_sync_selection()) { + const auto &positions = params.positions.at(key); + const int from = positions.index[params.source]; + if (!config_to_apply.has(key)) + config_to_apply.set_key_value(key, m_config->option(key)->clone()); + for (int s = 0; s < positions.stride; ++s) + dynamic_cast(config_to_apply.option(key))->set_at(m_config->option(key), index + s, from + s); + } + if (!config_to_apply.empty()) { m_config->apply(config_to_apply); auto &applying_keys = const_cast(m_config_manipulation.applying_keys()); if (m_type > Preset::TYPE_COUNT) diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 8df7d6c84c..c698b7dff0 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -498,6 +498,7 @@ public: DynamicPrintConfig* get_config() { return m_config; } PresetCollection * get_presets() { return m_presets; } + const std::vector& pages() const { return m_pages; } TabPresetComboBox * get_combo_box() { return m_presets_choice; } virtual void on_value_change(const std::string& opt_key, const boost::any& value); @@ -536,7 +537,8 @@ public: void sync_excluder(); void parse_extruder_selection(int selection, int &extruder_id, NozzleVolumeType &nozzle_type); int calculate_selection_index_for_extruder(int extruder_id, NozzleVolumeType nozzle_type); - bool get_extruder_sync_enable_state(int extruder_id); + std::vector get_extruder_sync_targets(int extruder_id); + bool extruder_sync_enabled(); int get_current_active_extruder(); std::vector generate_extruder_options(); diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index fb23aff48d..322826ed0b 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -1,11 +1,15 @@ #include "UnsavedChangesDialog.hpp" +#include #include +#include +#include #include #include #include #include #include +#include #include "slic3r/GUI/Event.hpp" #include #include "libslic3r/Preset.hpp" @@ -16,8 +20,6 @@ #include #include "slic3r/GUI/GUI_Utils.hpp" #include "slic3r/GUI/Widgets/Label.hpp" -#include "slic3r/GUI/DeviceCore/DevConfigUtil.h" -#include "slic3r/GUI/DeviceCore/DevDefs.h" #include "slic3r/GUI/Widgets/StateColor.hpp" #include "slic3r/GUI/Widgets/Button.hpp" #include "slic3r/GUI/SettingsIndex.hpp" @@ -47,14 +49,16 @@ #include #include #include +#include +#include -#include "CalibUtils.hpp" #include "libslic3r/PrintConfig.hpp" #include "libslic3r/PresetBundle.hpp" #include "libslic3r/Color.hpp" #include "format.hpp" #include "ConfigValueFormatter.hpp" #include "GUI_App.hpp" +#include "OptionsGroup.hpp" #include "Plater.hpp" #include "Tab.hpp" #include "ExtraRenderers.hpp" @@ -611,6 +615,41 @@ void DiffModel::Clear() } +// Top-down order of the sidebar's preset sections. +static const Preset::Type PRESET_TYPE_ORDER[] = { + Preset::TYPE_PRINTER, Preset::TYPE_FILAMENT, Preset::TYPE_SLA_MATERIAL, Preset::TYPE_PRINT, Preset::TYPE_SLA_PRINT }; + +static int preset_type_rank(Preset::Type type) +{ + return int(std::find(std::begin(PRESET_TYPE_ORDER), std::end(PRESET_TYPE_ORDER), type) - std::begin(PRESET_TYPE_ORDER)); +} + +// opt_key -> its position on the settings pages, with the tabs taken in PRESET_TYPE_ORDER. +static std::map build_tab_order_map() +{ + std::vector tabs = wxGetApp().tabs_list; + std::stable_sort(tabs.begin(), tabs.end(), [](Tab *a, Tab *b) { return preset_type_rank(a->type()) < preset_type_rank(b->type()); }); + + std::map order; + for (Tab *tab : tabs) + for (const PageShp &page : tab->pages()) + for (const auto &optgroup : page->m_optgroups) + for (const Line &line : optgroup->get_lines()) + for (const Option &opt : line.get_options()) + order.emplace(get_pure_opt_key(opt.opt_id), int(order.size())); + return order; +} + +static int order_of(const std::map &tab_order, const std::string &opt_key) +{ + auto it = tab_order.find(get_pure_opt_key(opt_key)); + return it != tab_order.end() ? it->second : INT_MAX; +} + +// Same-named categories on different tabs must stay separate, so the keys carry the preset type. +static wxString preset_item_cat_key(const PresetItem &pi) { return wxString::Format("%d:", int(pi.type)) + pi.category_name; } +static wxString preset_item_grp_key(const PresetItem &pi) { return preset_item_cat_key(pi) + ":" + pi.group_name; } + // ---------------------------------------------------------------------------- // DiffViewCtrl // ---------------------------------------------------------------------------- @@ -809,7 +848,16 @@ static std::string none{"none"}; #define UNSAVE_CHANGE_DIALOG_ACTION_LINE_SIZE wxSize(FromDIP(490), -1) #define UNSAVE_CHANGE_DIALOG_FIRST_VALUE_WIDTH FromDIP(190) #define UNSAVE_CHANGE_DIALOG_VALUE_WIDTH FromDIP(150) +#define UNSAVE_CHANGE_DIALOG_VALUE_TEXT_WIDTH (UNSAVE_CHANGE_DIALOG_VALUE_WIDTH - FromDIP(10)) +#define UNSAVE_CHANGE_DIALOG_CATEGORY_INDENT FromDIP(23) +#define UNSAVE_CHANGE_DIALOG_GROUP_INDENT FromDIP(37) +#define UNSAVE_CHANGE_DIALOG_OPTION_INDENT FromDIP(51) +#define UNSAVE_CHANGE_DIALOG_ICON_WIDTH FromDIP(24) #define UNSAVE_CHANGE_DIALOG_ITEM_HEIGHT FromDIP(24) +#define UNSAVE_CHANGE_DIALOG_SYNC_CELL_PADDING FromDIP(8) +#define UNSAVE_CHANGE_DIALOG_TYPE_INDENT FromDIP(8) +// A row's checkbox and the gap after it +#define UNSAVE_CHANGE_DIALOG_CHECK_WIDTH FromDIP(22) #define UNSAVE_CHANGE_DIALOG_BUTTON_SIZE wxSize(FromDIP(70), FromDIP(24)) #define THUMB_COLOR wxColor(196, 196, 196) @@ -835,7 +883,7 @@ 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) +UnsavedChangesDialog::UnsavedChangesDialog(const wxString &caption, const wxString &header, Preset::Type type, SyncExtruderParams params) : DPIDialog(static_cast(wxGetApp().mainframe), wxID_ANY, caption, @@ -844,8 +892,7 @@ UnsavedChangesDialog::UnsavedChangesDialog(const wxString &caption, const wxStri 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(¶ms), "SyncExtruderParams", header); + build(type, reinterpret_cast(¶ms), "SyncExtruderParams", header); this->CenterOnScreen(); wxGetApp().UpdateDlgDarkUI(this); } @@ -893,6 +940,61 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_ { SetBackgroundColour(*wxWHITE); + SyncExtruderParams *params = nullptr; + if (new_selected_preset == "SyncExtruderParams") { + params = reinterpret_cast(dependent_presets); + dependent_presets = nullptr; + } + + // The rows size the columns, so collect them before building the header. + if (params) + update_tree(type, params->config); + else + update_tree(type, dependent_presets); + + // The sync dialog has a value column per extruder, each fitted to its content once the table is built. + const int value_columns = params ? int(params->titles.size()) : 2; + m_value_width = params ? wxDefaultCoord : UNSAVE_CHANGE_DIALOG_VALUE_WIDTH; + if (params) { + m_sync_columns.assign(value_columns + 1, {}); + m_first_value_width = m_content_width = wxDefaultCoord; + } else { + auto row_width = [this](const wxString &text, const wxFont &font, int indent) { + int w = 0, h = 0; + GetTextExtent(text, &w, &h, nullptr, nullptr, &font); + return indent + w + FromDIP(16); + }; + // Category headers span the row, so they widen the dialog rather than the label column. + m_first_value_width = UNSAVE_CHANGE_DIALOG_FIRST_VALUE_WIDTH; + int category_width = 0; + for (const PresetItem &pi : m_presetitems) { + const int option_w = row_width(pi.option_name, ::Label::Body_13, UNSAVE_CHANGE_DIALOG_OPTION_INDENT) + (pi.has_icon ? UNSAVE_CHANGE_DIALOG_ICON_WIDTH : 0); + m_first_value_width = std::max({m_first_value_width, option_w, row_width(pi.group_name, ::Label::Head_13, UNSAVE_CHANGE_DIALOG_GROUP_INDENT)}); + category_width = std::max(category_width, row_width(pi.category_name, ::Label::Head_13, UNSAVE_CHANGE_DIALOG_CATEGORY_INDENT)); + } + // Every row has its box before the label. + m_first_value_width = std::min(m_first_value_width + UNSAVE_CHANGE_DIALOG_CHECK_WIDTH, FromDIP(420)); + category_width += UNSAVE_CHANGE_DIALOG_CHECK_WIDTH; + m_content_width = std::min(std::max(m_first_value_width + 2 * UNSAVE_CHANGE_DIALOG_VALUE_WIDTH, category_width), FromDIP(760)); + } + + // update_list() gives every category, group and option one ITEM_HEIGHT row, and every type one outside the sync + // dialog, so this is the exact list height. + std::set row_types; + std::set row_cats, row_grps; + for (const PresetItem &pi : m_presetitems) { + row_types.insert(int(pi.type)); + row_cats.insert(preset_item_cat_key(pi)); + row_grps.insert(preset_item_grp_key(pi)); + } + const int row_count = int((params ? 0 : row_types.size()) + row_cats.size() + row_grps.size() + m_presetitems.size()); + const bool needs_scrollbar = row_count * UNSAVE_CHANGE_DIALOG_ITEM_HEIGHT > UNSAVE_CHANGE_DIALOG_SCROLL_WINDOW_SIZE.GetHeight(); + + // Overlay scrollbars report a width of 0 and take no space. + const int scrollbar_w = needs_scrollbar ? std::max(0, wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, this)) : 0; + if (!params) + m_content_width += scrollbar_w; + wxBoxSizer *m_sizer_main = new wxBoxSizer(wxVERTICAL); m_top_line = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL); @@ -902,7 +1004,7 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_ m_sizer_main->Add(0, 0, 0, wxTOP, 20); - m_action_line = new wxStaticText(this, wxID_ANY, wxEmptyString, wxDefaultPosition, UNSAVE_CHANGE_DIALOG_ACTION_LINE_SIZE, 0); + m_action_line = new wxStaticText(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(m_content_width, UNSAVE_CHANGE_DIALOG_ACTION_LINE_SIZE.y), 0); m_action_line->SetFont(::Label::Body_13); m_action_line->SetForegroundColour(wxColour("#363636")); m_action_line->Wrap(-1); @@ -910,13 +1012,7 @@ 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(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 = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(m_content_width, -1), wxTAB_TRAVERSAL); m_panel_tab->SetBackgroundColour(wxColour("#D9D9D9")); wxBoxSizer *m_sizer_tab = new wxBoxSizer(wxVERTICAL); @@ -926,69 +1022,80 @@ 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); - auto m_panel_temp = new wxPanel(m_table_top, wxID_ANY, wxDefaultPosition, wxSize(UNSAVE_CHANGE_DIALOG_FIRST_VALUE_WIDTH, -1), wxTAB_TRAVERSAL); + auto m_panel_temp = new wxPanel(m_table_top, wxID_ANY, wxDefaultPosition, wxSize(m_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)); + if (!params) + top_title_temp_v->SetMinSize(wxSize(UNSAVE_CHANGE_DIALOG_VALUE_WIDTH, -1)); wxBoxSizer *top_title_temp_h = new wxBoxSizer(wxHORIZONTAL); + + // Tick-all boxes of the header: every change or copy (column -1), or in the sync dialog every copy to one column. + std::vector> header_checks; + auto add_header_check = [this, &header_checks](wxPanel *panel, wxBoxSizer *sizer, int column) { + panel->SetBackgroundColour(wxColour("#D9D9D9")); + const size_t k = add_all_check(panel); + header_checks.emplace_back(k, column); + sizer->Add(m_all_checks[k].first, 0, wxALIGN_CENTER | wxRIGHT | wxRESERVE_SPACE_EVEN_IF_HIDDEN, FromDIP(4)); + }; + add_header_check(m_panel_temp, top_title_temp_h, -1); static_temp_title = new wxStaticText(m_panel_temp, wxID_ANY, _L("Settings"), wxDefaultPosition, wxDefaultSize, 0); static_temp_title->SetFont(::Label::Body_13); static_temp_title->Wrap(-1); static_temp_title->SetForegroundColour(wxColour("#363636")); top_title_temp_h->Add(static_temp_title, 0, wxALIGN_CENTER | wxBOTTOM | wxTOP, 5); - top_title_temp_v->Add(top_title_temp_h, 1, wxALIGN_CENTER, 0); + // The corner box sits above the boxes of the outermost rows: the categories in the sync dialog, else the preset types. + top_title_temp_v->Add(top_title_temp_h, 1, wxLEFT, params ? UNSAVE_CHANGE_DIALOG_CATEGORY_INDENT : UNSAVE_CHANGE_DIALOG_TYPE_INDENT); m_panel_temp->SetSizer(top_title_temp_v); m_panel_temp->Layout(); m_sizer_top->Add(m_panel_temp, 1, wxALIGN_CENTER, 0); + if (params) + m_sync_columns[0].push_back(m_panel_temp); - title_block_middle = new wxPanel(m_table_top, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - title_block_middle->SetBackgroundColour(wxColour(172, 172, 172)); + auto add_title = [this, m_sizer_top, params, &add_header_check](const wxString &label, bool highlight, int column) { + // The first separator keeps its default width, except in the sync dialog, which aligns its header with the rows. + auto separator = new wxPanel(m_table_top, wxID_ANY, wxDefaultPosition, !params && m_sizer_top->GetItemCount() == 1 ? wxDefaultSize : wxSize(1, -1), wxTAB_TRAVERSAL); + separator->SetBackgroundColour(wxColour(172, 172, 172)); + m_sizer_top->Add(separator, 0, wxBOTTOM | wxEXPAND | wxTOP, 2); - m_sizer_top->Add(title_block_middle, 0, wxBOTTOM | wxEXPAND | wxTOP, 2); - auto m_panel_oldv = new wxPanel( m_table_top, wxID_ANY, wxDefaultPosition, wxSize(UNSAVE_CHANGE_DIALOG_VALUE_WIDTH,-1), wxTAB_TRAVERSAL ); - wxBoxSizer *top_title_oldv = new wxBoxSizer(wxVERTICAL); - wxBoxSizer *top_title_oldv_h = new wxBoxSizer(wxHORIZONTAL); + auto panel = new wxPanel(m_table_top, wxID_ANY, wxDefaultPosition, wxSize(m_value_width, -1), wxTAB_TRAVERSAL); + auto sizer_v = new wxBoxSizer(wxVERTICAL); + auto sizer_h = new wxBoxSizer(wxHORIZONTAL); + if (column >= 0) + add_header_check(panel, sizer_h, column); + auto title = new wxStaticText(panel, wxID_ANY, label, wxDefaultPosition, wxDefaultSize, 0); + title->SetFont(::Label::Body_13); + title->Wrap(-1); + title->SetForegroundColour(highlight ? wxGetApp().get_label_clr_modified() : wxColour("#363636")); + sizer_h->Add(title, 0, wxALIGN_CENTER | wxBOTTOM | wxTOP, 5); + sizer_v->Add(sizer_h, 1, params ? wxLEFT : wxALIGN_CENTER, params ? UNSAVE_CHANGE_DIALOG_SYNC_CELL_PADDING : 0); + panel->SetSizer(sizer_v); + panel->Layout(); + m_sizer_top->Add(panel, 0, wxALIGN_CENTER, 0); + return title; + }; + if (params) { + // With a single target its column box would repeat the one ticking every copy. + for (int i = 0; i < value_columns; ++i) + m_sync_columns[i + 1].push_back( + add_title(params->titles[i], i == params->source, value_columns > 2 && i != params->source ? i : -1)->GetParent()); + } else { + static_oldv_title = add_title(_L("Old Value"), false, -1); + static_newv_title = add_title(_L("New Value"), false, -1); + } - 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(params && params->left_to_right ? wxGetApp().get_label_clr_modified() : wxColour("#363636")); - 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); - m_panel_oldv->Layout(); - m_sizer_top->Add(m_panel_oldv, 0, wxALIGN_CENTER, 0); - - title_block_right = new wxPanel(m_table_top, wxID_ANY, wxDefaultPosition, wxSize(1, -1), wxTAB_TRAVERSAL); - title_block_right->SetBackgroundColour(wxColour(172, 172, 172)); - - m_sizer_top->Add(title_block_right, 0, wxBOTTOM | wxEXPAND | wxTOP, 2); - - auto m_panel_newv = new wxPanel( m_table_top, wxID_ANY, wxDefaultPosition, wxSize( UNSAVE_CHANGE_DIALOG_VALUE_WIDTH,-1 ), wxTAB_TRAVERSAL ); - 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, 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(params && !params->left_to_right ? wxGetApp().get_label_clr_modified() : wxColour("#363636")); - - top_title_newv_h->Add(static_newv_title, 0, wxALIGN_CENTER | wxBOTTOM | wxTOP, 5); - - top_title_newv->Add(top_title_newv_h, 1, wxALIGN_CENTER, 0); - - m_panel_newv->SetSizer(top_title_newv); - m_panel_newv->Layout(); - m_sizer_top->Add(m_panel_newv, 0, wxALIGN_CENTER, 0); - //m_sizer_top->Add(top_title_newv, 1, wxALIGN_CENTER, 0); + if (scrollbar_w > 0) { + // Extend the header over the scrollbar so New Value lines up with its rows. + auto title_block_gutter = new wxPanel(m_table_top, wxID_ANY, wxDefaultPosition, wxSize(1, -1), wxTAB_TRAVERSAL); + title_block_gutter->SetBackgroundColour(wxColour(172, 172, 172)); + m_sizer_top->Add(title_block_gutter, 0, wxBOTTOM | wxEXPAND | wxTOP, 2); + m_sizer_top->AddSpacer(scrollbar_w - 1); + } m_table_top->SetSizer(m_sizer_top); m_table_top->Layout(); m_sizer_top->Fit(m_table_top); m_sizer_tab->Add(m_table_top, 1, 0, 0); - m_scrolledWindow = new wxScrolledWindow(m_panel_tab, wxID_ANY, wxDefaultPosition, UNSAVE_CHANGE_DIALOG_SCROLL_WINDOW_SIZE, wxNO_BORDER|wxVSCROLL); + m_scrolledWindow = new wxScrolledWindow(m_panel_tab, wxID_ANY, wxDefaultPosition, wxSize(m_content_width, UNSAVE_CHANGE_DIALOG_SCROLL_WINDOW_SIZE.y), wxNO_BORDER|wxVSCROLL); m_scrolledWindow->SetScrollRate(0, FromDIP(20)); m_scrolledWindow->SetBackgroundColour(GREY200); m_sizer_bottom = new wxBoxSizer(wxVERTICAL); @@ -1070,14 +1177,20 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_ add_btn(&m_transfer_btn, m_move_btn_id, "menu_paste", Action::Transfer, _L("Transfer"), true); bool is_copy = new_selected_preset == "SyncExtruderParams"; + // "Save" button; the sync dialog's Yes confirms its question, so it comes first. + auto add_save_btn = [&]() { + 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"), is_copy); + }; + if (is_copy) + add_save_btn(); { // "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) ? (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", is_copy ? Action::Transfer : Action::Save, is_copy ? _L("Yes") : _L("Save"), false); + if (!is_copy) + add_save_btn(); if (dependent_presets != nullptr) { const wxString previous_profile = from_u8(dependent_presets->get_edited_preset().name); @@ -1123,16 +1236,39 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection *dependent_ m_sizer_main->Add(0, 0, 1, wxTOP, 18); 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); + // Each column is as wide as its widest cell or title, every extruder's column alike. The header + // windows come first; each sits next to a 1 px separator. + int widths[2] = {0, 0}; // labels, values + for (size_t c = 0; c < m_sync_columns.size(); ++c) + for (size_t r = 0; r < m_sync_columns[c].size(); ++r) + widths[c > 0] = std::max(widths[c > 0], m_sync_columns[c][r]->GetBestSize().x + UNSAVE_CHANGE_DIALOG_SYNC_CELL_PADDING + (r == 0 ? 1 : 0)); + for (size_t c = 0; c < m_sync_columns.size(); ++c) + for (size_t r = 0; r < m_sync_columns[c].size(); ++r) { + m_sync_columns[c][r]->SetMinSize(wxSize(widths[c > 0] - (r == 0 ? 1 : 0), -1)); + m_sync_columns[c][r]->GetParent()->Layout(); + } + m_scrolledWindow->FitInside(); + const int fitted_width = widths[0] + value_columns * widths[1]; + m_scrolledWindow->SetMinSize(wxSize(fitted_width + scrollbar_w, UNSAVE_CHANGE_DIALOG_SCROLL_WINDOW_SIZE.y)); + m_action_line->SetMinSize(wxSize(fitted_width, -1)); + m_action_line->Wrap(fitted_width); } else { update(type, dependent_presets, new_selected_preset, header); } + for (const auto &[k, column] : header_checks) { + for (const auto &[check, opt_key, index, check_column] : m_sync_checks) + if (column < 0 || column == check_column) + m_all_checks[k].second.push_back(check); + if (column < 0) + for (const auto &option : m_option_checks) + m_all_checks[k].second.push_back(std::get<0>(option)); + } + // A box over a single one would only repeat it. + for (const auto &[all, cells] : m_all_checks) + all->Show(cells.size() > 1); + update_all_checks(); //SetSizer(topSizer); //topSizer->SetSizeHints(this); @@ -1388,12 +1524,20 @@ void UnsavedChangesDialog::update(Preset::Type type, PresetCollection* dependent } m_action_line->SetLabel(action_msg); - m_action_line->Wrap(UNSAVE_CHANGE_DIALOG_SCROLL_WINDOW_SIZE.x); + m_action_line->Wrap(m_content_width); - update_tree(type, presets); update_list(); } +bool UnsavedChangesDialog::value_clips(const wxString &value) const +{ + if (value.find('\n') != wxString::npos) + return true; + int w = 0, h = 0; + GetTextExtent(value, &w, &h, nullptr, nullptr, &::Label::Body_13); + return w > UNSAVE_CHANGE_DIALOG_VALUE_TEXT_WIDTH; +} + void UnsavedChangesDialog::update_list(SyncExtruderParams *params) { if (!m_scrolledWindow) { @@ -1402,199 +1546,278 @@ void UnsavedChangesDialog::update_list(SyncExtruderParams *params) return; } - std::map> class_g_list; - std::map> class_c_list; - std::vector category_list; + const std::map tab_order = build_tab_order_map(); + for (PresetItem &pi : m_presetitems) + pi.order = order_of(tab_order, pi.opt_key); - // group - for (auto i = 0; i < m_presetitems.size(); i++) { - auto name = m_presetitems[i].category_name + ":" + m_presetitems[i].group_name; - if (class_g_list.count(name) <= 0) { - std::vector vp; - vp.push_back(m_presetitems[i]); - 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[name].push_back(m_presetitems[i]); + // Each option's per-extruder rows share one tab-order slot, so ordering by slot alone would interleave the + // extruders. Anchor each type's extruder block at its first slot, per type so no type moves above its own rows. + std::map ext_anchor; + for (const PresetItem &pi : m_presetitems) + if (pi.extruder_id > 0) { + auto it = ext_anchor.find(pi.type); + if (it == ext_anchor.end()) + ext_anchor.emplace(pi.type, pi.order); + else + it->second = std::min(it->second, pi.order); } - } - // 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 vp; - 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::iterator it; - 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(name); - } - } - } + std::stable_sort(m_presetitems.begin(), m_presetitems.end(), + [&ext_anchor](const PresetItem &a, const PresetItem &b) { + const int ra = preset_type_rank(a.type), rb = preset_type_rank(b.type); + if (ra != rb) return ra < rb; + const int sa = a.extruder_id > 0 ? ext_anchor.at(a.type) : a.order; + const int sb = b.extruder_id > 0 ? ext_anchor.at(b.type) : b.order; + if (sa != sb) return sa < sb; + if (a.extruder_id != b.extruder_id) return a.extruder_id < b.extruder_id; + return a.order < b.order; + }); + auto value_tooltip = [](const wxString &full) { + const size_t cap = 500; // a whole g-code block is unreadable in a tooltip + return full.length() <= cap ? full : full.Left(cap) + "...\n\n" + _L("Click the compare button to see the full value."); + }; + + // A width of wxDefaultCoord keeps the label's natural width, which the sync dialog's fitted columns use. + auto make_label = [](wxWindow *parent, const wxString &text, const wxFont &font, int width, const wxColour &colour, + const wxString &tooltip = wxString(), long style = wxST_ELLIPSIZE_END) { + const bool natural = width == wxDefaultCoord; + auto t = new wxStaticText(parent, wxID_ANY, text, wxDefaultPosition, natural ? wxDefaultSize : wxSize(std::max(0, width), -1), style); + t->SetFont(font); + t->SetForegroundColour(colour); + t->SetToolTip(tooltip.IsEmpty() && !natural && t->GetTextExtent(text).GetWidth() > width ? text : tooltip); + return t; + }; + + // A box before a line's label: one change's own, or one ticking every change (or, in the sync dialog, copy) under it. + auto add_check_and_label = [this](wxSizer *sizer, ::CheckBox *check, wxStaticText *text, int indent) { + sizer->Add(check, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRESERVE_SPACE_EVEN_IF_HIDDEN, indent); + sizer->Add(text, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(4)); + }; + auto add_label = [this, &add_check_and_label](wxWindow *parent, wxSizer *sizer, wxStaticText *text, int indent) -> size_t { + const size_t k = add_all_check(parent); + add_check_and_label(sizer, m_all_checks[k].first, text, indent); + return k; + }; + // The label width of a line, or the natural one in the sync dialog. + auto label_width = [params](int width) { return params ? wxDefaultCoord : width; }; + + auto make_value_col = [&](wxWindow *parent, wxString value, bool modified, bool may_clip) { + auto panel = new wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(UNSAVE_CHANGE_DIALOG_VALUE_WIDTH, -1), wxTAB_TRAVERSAL); + auto sizer = new wxBoxSizer(wxVERTICAL); + // Before flattening, so g-code newlines survive in the tooltip. + const wxString tooltip = (may_clip && value_clips(value)) ? value_tooltip(value) : wxString(); + value.Replace("\n", " "); + value.Replace("\r", " "); + value.Trim(false); + auto text = make_label(panel, value, ::Label::Body_13, UNSAVE_CHANGE_DIALOG_VALUE_TEXT_WIDTH, + modified ? wxGetApp().get_label_clr_modified() : GREY700, tooltip, + wxST_ELLIPSIZE_END | wxALIGN_CENTRE_HORIZONTAL); + sizer->Add(text, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 5); + panel->SetSizer(sizer); + panel->Layout(); + return panel; + }; auto m_listsizer = new wxBoxSizer(wxVERTICAL); - 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); - wxBoxSizer *sizer_category = new wxBoxSizer(wxHORIZONTAL); - wxBoxSizer *sizer_category_v = new wxBoxSizer(wxHORIZONTAL); + auto finish_row = [&](wxWindow *panel, wxSizer *sizer) { + panel->SetSizer(sizer); + panel->Layout(); + m_listsizer->Add(panel, 0, wxEXPAND, 0); + }; - auto text_category = new wxStaticText(panel_category, wxID_ANY, iter->first, wxDefaultPosition, wxSize(-1, -1), 0); - text_category->SetFont(::Label::Head_13); - text_category->SetForegroundColour(GREY900); - text_category->Wrap(-1); + // Other preset types get no header, and so no box. + static constexpr size_t no_box = size_t(-1); + auto emit_type_header = [&](Preset::Type type) -> size_t { + wxString label; + switch (type) { + case Preset::TYPE_PRINT: label = _L("Process settings"); break; + case Preset::TYPE_FILAMENT: label = _L("Material settings"); break; + case Preset::TYPE_PRINTER: label = _L("Printer settings"); break; + default: return no_box; + } + auto panel = new wxPanel(m_scrolledWindow, wxID_ANY, wxDefaultPosition, wxSize(-1, UNSAVE_CHANGE_DIALOG_ITEM_HEIGHT), wxTAB_TRAVERSAL); + panel->SetBackgroundColour(GREY400); + auto sizer = new wxBoxSizer(wxHORIZONTAL); + const size_t all = add_label(panel, sizer, make_label(panel, label, ::Label::Head_16, + m_content_width - UNSAVE_CHANGE_DIALOG_TYPE_INDENT - FromDIP(8) - UNSAVE_CHANGE_DIALOG_CHECK_WIDTH, GREY900), + UNSAVE_CHANGE_DIALOG_TYPE_INDENT); + finish_row(panel, sizer); + return all; + }; - sizer_category_v->Add(text_category, 0, wxALIGN_CENTER | wxLEFT, 23); + auto emit_category = [&](const wxString &category_name) { + auto panel = new wxPanel(m_scrolledWindow, wxID_ANY, wxDefaultPosition, wxSize(-1, UNSAVE_CHANGE_DIALOG_ITEM_HEIGHT), wxTAB_TRAVERSAL); + panel->SetBackgroundColour(GREY300); + auto sizer = new wxBoxSizer(wxHORIZONTAL); + const size_t all = add_label(panel, sizer, make_label(panel, category_name, ::Label::Head_13, + label_width(m_content_width - UNSAVE_CHANGE_DIALOG_CATEGORY_INDENT - FromDIP(8) - UNSAVE_CHANGE_DIALOG_CHECK_WIDTH), GREY900), + UNSAVE_CHANGE_DIALOG_CATEGORY_INDENT); + finish_row(panel, sizer); + return all; + }; - sizer_category->Add(sizer_category_v, 1, wxEXPAND, 0); + auto emit_group = [&](const wxString &group_name) { + auto panel = new wxWindow(m_scrolledWindow, -1, wxDefaultPosition, wxSize(-1, UNSAVE_CHANGE_DIALOG_ITEM_HEIGHT)); + panel->SetBackgroundColour(GREY200); + auto sizer = new wxBoxSizer(wxHORIZONTAL); + auto panel_left = new wxPanel(panel, wxID_ANY, wxDefaultPosition, wxSize(m_first_value_width, -1), wxTAB_TRAVERSAL); + panel_left->SetBackgroundColour(GREY200); + auto left_sizer = new wxBoxSizer(wxHORIZONTAL); + const size_t all = add_label(panel_left, left_sizer, make_label(panel_left, group_name, ::Label::Head_13, + label_width(m_first_value_width - UNSAVE_CHANGE_DIALOG_GROUP_INDENT - FromDIP(8) - UNSAVE_CHANGE_DIALOG_CHECK_WIDTH), GREY700), + UNSAVE_CHANGE_DIALOG_GROUP_INDENT); + panel_left->SetSizer(left_sizer); + panel_left->Layout(); + sizer->Add(panel_left, 0, wxALIGN_CENTER, 0); + if (params) + m_sync_columns[0].push_back(panel_left); + finish_row(panel, sizer); + return all; + }; - panel_category->SetSizer(sizer_category); - panel_category->Layout(); - m_listsizer->Add(panel_category, 0, wxEXPAND, 0); + auto emit_option = [&](const PresetItem &data, size_t type_all, size_t category_all, size_t group_all) { + auto panel = new wxWindow(m_scrolledWindow, -1, wxDefaultPosition, wxSize(-1, UNSAVE_CHANGE_DIALOG_ITEM_HEIGHT)); + panel->SetBackgroundColour(GREY200); + auto sizer = new wxBoxSizer(wxHORIZONTAL); - /*auto item_line = new wxStaticLine(list, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL); - item_line->SetForegroundColour(wxColour(206, 206, 206)); - item_line->SetBackgroundColour(wxColour(206, 206, 206)); - sizer_list->Add(item_line, 0, wxALL, 0); */ - - // isset group - for (auto i = 0; i < iter->second.size(); i++) { - auto gname = iter->second[i]; - for (auto g = 0; g < class_g_list[gname].size(); g++) { - - //first group - if (g == 0) { - auto panel_item = new wxWindow(m_scrolledWindow, -1, wxDefaultPosition, wxSize(-1, UNSAVE_CHANGE_DIALOG_ITEM_HEIGHT)); - panel_item->SetBackgroundColour(GREY200); - - wxBoxSizer *sizer_item = new wxBoxSizer(wxHORIZONTAL); - - auto panel_left = new wxPanel(panel_item, wxID_ANY, wxDefaultPosition, wxSize(UNSAVE_CHANGE_DIALOG_FIRST_VALUE_WIDTH, -1), wxTAB_TRAVERSAL); - panel_left->SetBackgroundColour(GREY200); - - wxBoxSizer *sizer_left_v = new wxBoxSizer(wxVERTICAL); - - 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); - - sizer_left_v->Add(text_left, 0, wxLEFT, 37); - - panel_left->SetSizer(sizer_left_v); - panel_left->Layout(); - sizer_item->Add(panel_left, 0, wxALIGN_CENTER, 0); - - panel_item->SetSizer(sizer_item); - panel_item->Layout(); - m_listsizer->Add(panel_item, 0, wxEXPAND, 0); - } - - auto data = class_g_list[gname][g]; - - auto panel_item = new wxWindow(m_scrolledWindow, -1, wxDefaultPosition, wxSize(-1, UNSAVE_CHANGE_DIALOG_ITEM_HEIGHT)); - panel_item->SetBackgroundColour(GREY200); - - wxBoxSizer *sizer_item = new wxBoxSizer(wxHORIZONTAL); - - auto panel_left = new wxPanel(panel_item, wxID_ANY, wxDefaultPosition, wxSize(UNSAVE_CHANGE_DIALOG_FIRST_VALUE_WIDTH , -1), wxTAB_TRAVERSAL); - panel_left->SetBackgroundColour(GREY200); - - wxBoxSizer *sizer_left_v = new wxBoxSizer(wxVERTICAL); - - auto text_left = new wxStaticText(panel_left, wxID_ANY, data.option_name, wxDefaultPosition, wxSize(-1, -1), 0); - text_left->SetFont(::Label::Body_13); - text_left->Wrap(-1); - text_left->SetForegroundColour(GREY700); - - sizer_left_v->Add(text_left, 0, wxLEFT, 51 ); - - panel_left->SetSizer(sizer_left_v); - panel_left->Layout(); - sizer_item->Add(panel_left, 0, wxALIGN_CENTER, 0); - - auto panel_oldv = new wxPanel(panel_item, wxID_ANY, wxDefaultPosition, wxSize(UNSAVE_CHANGE_DIALOG_VALUE_WIDTH, -1), wxTAB_TRAVERSAL); - wxBoxSizer *sizer_old_v = new wxBoxSizer(wxVERTICAL); - - - data.old_value = subreplace(data.old_value.ToStdString(), "\n", " "); - 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(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); - panel_oldv->Layout(); - sizer_item->Add(panel_oldv, 0, wxALIGN_CENTER, 0); - - auto panel_newv = new wxPanel(panel_item, wxID_ANY, wxDefaultPosition, wxSize(UNSAVE_CHANGE_DIALOG_VALUE_WIDTH, -1), wxTAB_TRAVERSAL); - wxBoxSizer *sizer_new_v = new wxBoxSizer(wxVERTICAL); - - data.new_value = subreplace(data.new_value.ToStdString(), "\n", " "); - 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(params && !params->left_to_right ? wxGetApp().get_label_clr_modified() : GREY700); - - sizer_new_v->Add(text_newv, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5); - - panel_newv->SetSizer(sizer_new_v); - panel_newv->Layout(); - sizer_item->Add(panel_newv, 0, wxALIGN_CENTER, 0); - - panel_item->SetSizer(sizer_item); - panel_item->Layout(); - m_listsizer->Add(panel_item, 0, wxEXPAND, 0); - - - - ////if (g == class_g_list[gname].size() - 1) { - // auto item_line = new wxStaticLine(list, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL); - // item_line->SetForegroundColour(wxColour(206, 206, 206)); - // item_line->SetBackgroundColour(wxColour(206, 206, 206)); - // sizer_list->Add(item_line, 0, wxALL, 0); - ////} + auto panel_left = new wxPanel(panel, wxID_ANY, wxDefaultPosition, wxSize(m_first_value_width, -1), wxTAB_TRAVERSAL); + panel_left->SetBackgroundColour(GREY200); + auto left_sizer = new wxBoxSizer(wxHORIZONTAL); + const int text_w = m_first_value_width - UNSAVE_CHANGE_DIALOG_OPTION_INDENT - FromDIP(8) - UNSAVE_CHANGE_DIALOG_CHECK_WIDTH - + (data.has_icon ? UNSAVE_CHANGE_DIALOG_ICON_WIDTH : 0); + auto label = make_label(panel_left, data.option_name, ::Label::Body_13, label_width(text_w), GREY700); + size_t row_all = 0; + if (params) + row_all = add_label(panel_left, left_sizer, label, UNSAVE_CHANGE_DIALOG_OPTION_INDENT); + else { + // The change's own box. Extruder count has none: the per-extruder values follow it. + auto check = new ::CheckBox(panel_left); + add_check_and_label(left_sizer, check, label, UNSAVE_CHANGE_DIALOG_OPTION_INDENT); + if (data.opt_key == "extruders_count") + check->Hide(); + else { + check->SetValue(true); + check->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent &e) { update_all_checks(); e.Skip(); }); + m_option_checks.emplace_back(check, data.type, data.opt_key); + for (size_t k : {type_all, category_all, group_all}) + if (k != no_box) + m_all_checks[k].second.push_back(check); } } + if (data.has_icon) { + auto compare_btn = new Button(panel_left, "", "compare", 0, 16); + compare_btn->SetStyle(ButtonStyle::Regular, ButtonType::Icon); + compare_btn->SetPaddingSize(FromDIP(wxSize(1, 1))); + compare_btn->SetMinSize(FromDIP(wxSize(20, 20))); + compare_btn->SetSize(FromDIP(wxSize(20, 20))); + compare_btn->SetCanFocus(false); + compare_btn->SetToolTip(_L("Compare the full values")); + compare_btn->Bind(wxEVT_BUTTON, [this, data](wxCommandEvent &) { + FullCompareDialog(data.option_name, data.old_value, data.new_value, + static_oldv_title->GetLabel(), static_newv_title->GetLabel()).ShowModal(); + }); + left_sizer->Add(compare_btn, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, FromDIP(4)); + } + panel_left->SetSizer(left_sizer); + panel_left->Layout(); + sizer->Add(panel_left, 0, wxALIGN_CENTER, 0); + + if (params) { + m_sync_columns[0].push_back(panel_left); + // A target whose value differs from the source gets a checkbox for copying it. + DynamicPrintConfig value_config; + value_config.set_key_value(data.opt_key, params->config->option(data.opt_key)->clone()); + const auto values = dynamic_cast(params->config->option(data.opt_key))->vserialize(); + const auto &positions = params->positions.at(data.opt_key); + const int from = positions.index[params->source]; + for (int i = 0; i < int(params->titles.size()); ++i) { + // A column without a value of this option, e.g. an extruder without its nozzle variant, stays empty. + const int index = positions.index[i]; + bool differs = false; + for (int s = 0; index >= 0 && s < positions.stride; ++s) + differs |= values[from + s] != values[index + s]; + + auto cell = new wxPanel(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + cell->SetBackgroundColour(GREY200); + m_sync_columns[i + 1].push_back(cell); + auto cell_sizer = new wxBoxSizer(wxHORIZONTAL); + cell_sizer->AddSpacer(UNSAVE_CHANGE_DIALOG_SYNC_CELL_PADDING); + if (i != params->source) { + // A target that already has the value keeps the box's space, so its column stays aligned. + auto check = new ::CheckBox(cell); + cell_sizer->Add(check, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxRESERVE_SPACE_EVEN_IF_HIDDEN, FromDIP(4)); + if (differs) { + check->SetValue(true); + check->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent &e) { update_all_checks(); e.Skip(); }); + m_sync_checks.emplace_back(check, data.opt_key, index, i); + for (size_t k : {category_all, group_all, row_all}) + m_all_checks[k].second.push_back(check); + } else + check->Hide(); + } + if (index >= 0) + cell_sizer->Add(make_label(cell, get_string_value(data.opt_key + "#" + std::to_string(index), value_config), ::Label::Body_13, + wxDefaultCoord, i == params->source ? wxGetApp().get_label_clr_modified() : GREY700), + 0, wxALIGN_CENTER_VERTICAL); + cell->SetSizer(cell_sizer); + cell->Layout(); + sizer->Add(cell, 0, wxALIGN_CENTER, 0); + } + } else { + sizer->Add(make_value_col(panel, data.old_value, false, data.has_icon), 0, wxALIGN_CENTER, 0); + sizer->Add(make_value_col(panel, data.new_value, false, data.has_icon), 0, wxALIGN_CENTER, 0); + } + + finish_row(panel, sizer); + }; + + // Group by key, not adjacency: per-variant tags make one category recur at non-adjacent tab slots, so a walk that + // starts a section whenever the name changes would duplicate it. + struct Section { Preset::Type type; wxString name; std::vector group_keys; }; + std::map sections; // cat_key -> section + std::vector section_order; // cat_keys in first-encounter order + std::map> rows_by_group; // grp_key -> its rows, in tab order + for (const PresetItem &pi : m_presetitems) { + const wxString ckey = preset_item_cat_key(pi); + const wxString gkey = preset_item_grp_key(pi); + auto section = sections.try_emplace(ckey); + if (section.second) { + section.first->second = {pi.type, pi.category_name, {}}; + section_order.push_back(ckey); + } + auto group = rows_by_group.try_emplace(gkey); + if (group.second) + section.first->second.group_keys.push_back(gkey); + group.first->second.push_back(pi); + } + + Preset::Type shown_type = Preset::TYPE_INVALID; + size_t type_all = 0; + for (const wxString &ckey : section_order) { + const Section §ion = sections.at(ckey); + // The sync dialog copies within one tab, so it needs no type header. + if (section.type != shown_type && !params) { + shown_type = section.type; + type_all = emit_type_header(section.type); + } + const size_t category_all = emit_category(section.name); + for (const wxString &gkey : section.group_keys) { + const std::vector &rows = rows_by_group.at(gkey); + const size_t group_all = emit_group(rows.front().group_name); + for (const PresetItem &pi : rows) + emit_option(pi, type_all, category_all, group_all); + } } - m_scrolledWindow->SetSizer(m_listsizer); - 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 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(); + m_scrolledWindow->SetSizer(m_listsizer); + m_scrolledWindow->Layout(); + Layout(); + Fit(); } -std::string UnsavedChangesDialog::subreplace(std::string resource_str, std::string sub_str, std::string new_str) -{ - std::string dst_str = resource_str; - std::string::size_type pos = 0; - while ((pos = dst_str.find(sub_str)) != std::string::npos) - { - dst_str.replace(pos, sub_str.length(), new_str); - } - return dst_str; -} - -void UnsavedChangesDialog::update_tree(Preset::Type type, DynamicConfig * config, int from, int to) +void UnsavedChangesDialog::update_tree(Preset::Type type, DynamicConfig *config) { Search::SettingsIndex &index = wxGetApp().sidebar().settings_index(); index.sort_options_by_key(); @@ -1610,12 +1833,57 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, DynamicConfig * config option.category_local = (def && !def->category.empty() ? Tab::translate_category(from_u8(def->category), type) : _L("Others")).ToStdWstring(); } - auto category = option.category_local; - auto opt = dynamic_cast(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); + // update_list() reads the values of every extruder from the config. + m_presetitems.push_back({type, opt_key, option.category_local, option.group_local, option.label_local, {}, {}}); + } + + index.sort_options_by_label(); +} + +std::vector> UnsavedChangesDialog::get_sync_selection() const +{ + std::vector> selection; + for (const auto &[check, opt_key, index, column] : m_sync_checks) + if (check->GetValue()) + selection.emplace_back(opt_key, index); + return selection; +} + +size_t UnsavedChangesDialog::add_all_check(wxWindow *parent) +{ + const size_t k = m_all_checks.size(); + m_all_checks.push_back({new ::CheckBox(parent), {}}); + m_all_checks[k].first->Bind(wxEVT_TOGGLEBUTTON, [this, k](wxCommandEvent &e) { + for (::CheckBox *cell : m_all_checks[k].second) + cell->SetValue(m_all_checks[k].first->GetValue()); + update_all_checks(); + e.Skip(); + }); + return k; +} + +std::vector UnsavedChangesDialog::options_by_selection(const Preset::Type *type, bool selected) const +{ + std::vector options; + for (const PresetItem &item : m_presetitems) { + if (type != nullptr && item.type != *type) + continue; + auto check = std::find_if(m_option_checks.begin(), m_option_checks.end(), [&item](const auto &option) { + return std::get<1>(option) == item.type && std::get<2>(option) == item.opt_key; + }); + if ((check == m_option_checks.end() || std::get<0>(*check)->GetValue()) == selected) + options.push_back(item.opt_key); + } + return options; +} + +void UnsavedChangesDialog::update_all_checks() +{ + for (const auto &[all, cells] : m_all_checks) { + const auto checked = size_t(std::count_if(cells.begin(), cells.end(), [](const ::CheckBox *cell) { return cell->GetValue(); })); + // A partly ticked box holds false, so clicking it ticks everything under it. + all->SetValue(!cells.empty() && checked == cells.size()); + all->SetHalfChecked(checked > 0 && checked < cells.size()); } } @@ -1678,6 +1946,21 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres auto extruder_variant = dynamic_cast(new_config.option(variant_key)); auto extruder_id = dynamic_cast(new_config.option(id_key)); + auto extruder_variant_of = [type](const std::string& pure_key, int index) { + return type == Preset::TYPE_PRINTER && printer_options_with_variant_2.count(pure_key) > 0 ? index / 2 : index; + }; + + std::map dirty_variants_per_option; + std::map, int> dirty_variants_per_extruder; + for (const std::string& opt_key : dirty_options) { + const std::string pure_key = get_pure_opt_key(opt_key); + ++dirty_variants_per_option[pure_key]; + const size_t hash_pos = opt_key.find('#'); + const int variant = hash_pos == std::string::npos ? -1 : extruder_variant_of(pure_key, std::atoi(opt_key.c_str() + hash_pos + 1)); + if (extruder_id && variant >= 0 && variant < extruder_id->size()) + ++dirty_variants_per_extruder[{pure_key, extruder_id->values[variant]}]; + } + for (const std::string& opt_key : dirty_options) { int variant_index = -2; const Search::Option &option = index.get_option(opt_key, type, variant_index); @@ -1689,22 +1972,31 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres } wxString category = option.category_local; wxString label = option.label_local; - if (type == Preset::TYPE_PRINTER && variant_index >= 0 && - printer_options_with_variant_2.count(get_pure_opt_key(opt_key)) > 0) { - variant_index /= 2; - } + // A multi-extruder printer registers its per-extruder options under "Extruder N". + const bool on_extruder_page = option.category.compare(0, 9, L"Extruder ") == 0; + int row_extruder_id = on_extruder_page ? int(std::wcstol(option.category.c_str() + 9, nullptr, 10)) : 0; + if (variant_index >= 0) + variant_index = extruder_variant_of(get_pure_opt_key(opt_key), variant_index); if (variant_index >= 0 && extruder_variant && variant_index < extruder_variant->size()) { // Orca: Match the untranslated category and use the same extruder names as the printer tabs. - if (option.category.compare(0, 9, L"Extruder ") == 0) + if (on_extruder_page) category = _L("Extruder"); - wxString variant_label = L(extruder_variant->values[variant_index]); + const bool ambiguous = dirty_variants_per_option[get_pure_opt_key(opt_key)] > 1; + wxString variant_label = from_u8(extruder_variant->values[variant_index]); // Orca: An extruder name only disambiguates variants on printers with multiple extruders. - if (multiple_extruders && extruder_id && variant_index < extruder_id->size() && extruder_id->values[variant_index] > 0) { - const wxString extruder_name = Tab::translate_category( - wxString::Format("Extruder %d", extruder_id->values[variant_index]), Preset::TYPE_PRINTER); - variant_label = extruder_name + " (" + variant_label + ")"; + const bool named_extruder = multiple_extruders && extruder_id && variant_index < extruder_id->size() && extruder_id->values[variant_index] > 0; + if (named_extruder) { + const int id = extruder_id->values[variant_index]; + const wxString extruder_name = Tab::translate_category(wxString::Format("Extruder %d", id), Preset::TYPE_PRINTER); + const bool several_dirty_on_extruder = dirty_variants_per_extruder[{get_pure_opt_key(opt_key), id}] > 1; + variant_label = several_dirty_on_extruder ? extruder_name + " (" + variant_label + ")" : extruder_name; + if (on_extruder_page) + row_extruder_id = id; } - category = variant_label + ": " + category; + if (on_extruder_page && named_extruder) + category = variant_label; + else if (ambiguous) + category = variant_label + ": " + category; } /*m_tree->Append(opt_key, type, option.category_local, option.group_local, option.label_local, @@ -1714,6 +2006,8 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres //PresetItem pi = {opt_key, type, 1983}; //m_presetitems.push_back() PresetItem pi = {type, opt_key, category, option.group_local, label, get_string_value(opt_key, old_config), get_string_value(opt_key, new_config)}; + pi.has_icon = value_clips(pi.old_value) || value_clips(pi.new_value); + pi.extruder_id = row_extruder_id; m_presetitems.push_back(pi); } @@ -1806,22 +2100,22 @@ FullCompareDialog::FullCompareDialog(const wxString& option_name, const wxString std::set_difference(old_set.begin(), old_set.end(), new_set.begin(), new_set.end(), std::inserter(old_new_diff_set, old_new_diff_set.begin())); std::set_difference(new_set.begin(), new_set.end(), old_set.begin(), old_set.end(), std::inserter(new_old_diff_set, new_old_diff_set.begin())); - auto add_value = [grid_sizer, border, this](wxString label, const std::set& diff_set, bool is_colored = false) { + auto add_value = [grid_sizer, border, this](wxString label, const std::set& diff_set) { wxTextCtrl* text = new wxTextCtrl(this, wxID_ANY, label, wxDefaultPosition, wxSize(400, 400), wxTE_MULTILINE | wxTE_READONLY | wxBORDER_DEFAULT | wxTE_RICH); wxGetApp().UpdateDarkUI(text); - text->SetStyle(0, label.Len(), wxTextAttr(is_colored ? wxColour(orange) : wxNullColour, wxNullColour, this->GetFont())); + text->SetStyle(0, label.Len(), wxTextAttr(wxNullColour, wxNullColour, this->GetFont())); for (const wxString& str : diff_set) { int pos = label.First(str); if (pos == wxNOT_FOUND) continue; - text->SetStyle(pos, pos + (int)str.Len(), wxTextAttr(is_colored ? wxColour(orange) : wxNullColour, wxNullColour, this->GetFont().Bold())); + text->SetStyle(pos, pos + (int)str.Len(), wxTextAttr(wxGetApp().get_label_clr_modified(), wxNullColour, this->GetFont().Bold())); } grid_sizer->Add(text, 1, wxALL | wxEXPAND, border); }; add_value(old_value, old_new_diff_set); - add_value(new_value, new_old_diff_set, true); + add_value(new_value, new_old_diff_set); sizer->Add(grid_sizer, 1, wxEXPAND); @@ -1862,7 +2156,7 @@ void DiffPresetDialog::create_presets_sizer() { m_presets_sizer = new wxBoxSizer(wxVERTICAL); - for (auto new_type : { Preset::TYPE_PRINTER, Preset::TYPE_FILAMENT, Preset::TYPE_SLA_MATERIAL, Preset::TYPE_PRINT, Preset::TYPE_SLA_PRINT }) + for (auto new_type : PRESET_TYPE_ORDER) { const PresetCollection* collection = get_preset_collection(new_type); wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); @@ -2179,6 +2473,7 @@ void DiffPresetDialog::update_tree() m_tree->Clear(); wxString bottom_info = ""; bool show_tree = false; + const std::map tab_order = build_tab_order_map(); for (auto preset_combos : m_preset_combos) { @@ -2250,6 +2545,10 @@ void DiffPresetDialog::update_tree() get_category_icon("Basic information")); } + std::stable_sort(dirty_options.begin(), dirty_options.end(), [&tab_order](const std::string& a, const std::string& b) { + return order_of(tab_order, a) < order_of(tab_order, b); + }); + for (const std::string& opt_key : dirty_options) { wxString left_val = get_string_value(opt_key, left_config); wxString right_val = get_string_value(opt_key, right_congig); diff --git a/src/slic3r/GUI/UnsavedChangesDialog.hpp b/src/slic3r/GUI/UnsavedChangesDialog.hpp index 9aaf75b6fc..be65c28cfd 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.hpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.hpp @@ -9,8 +9,11 @@ #include "libslic3r/Config.hpp" #include "libslic3r/PrintConfig.hpp" #include +#include #include +#include #include +#include #include #include #include @@ -29,6 +32,7 @@ class ScalableButton; class wxStaticText; +class CheckBox; namespace Slic3r { namespace GUI{ @@ -276,6 +280,9 @@ struct PresetItem wxString option_name; wxString old_value; wxString new_value; + int order{ INT_MAX }; // position on the settings pages; rows on no page sort last + int extruder_id{ 0 }; // extruder of a per-extruder page row, else 0 + bool has_icon{ false }; // a value is too long to show, so the row has a compare button }; @@ -285,12 +292,11 @@ protected: wxPanel * m_top_line; wxPanel * m_panel_tab; wxPanel * m_table_top; - wxPanel * title_block_middle; - wxPanel * title_block_right; wxStaticText *static_temp_title; - wxStaticText *static_oldv_title; - wxStaticText *static_newv_title; + wxStaticText *static_oldv_title { nullptr }; + wxStaticText *static_newv_title { nullptr }; wxBoxSizer * m_sizer_bottom; + int m_value_width { 0 }; //DiffViewCtrl* m_tree { nullptr }; Button* m_save_btn { nullptr }; @@ -301,6 +307,9 @@ protected: wxStaticText* m_info_line { nullptr }; wxScrolledWindow* m_scrolledWindow{ nullptr }; + int m_first_value_width { 0 }; + int m_content_width { 0 }; + bool m_has_long_strings { false }; int m_save_btn_id { wxID_ANY }; int m_move_btn_id { wxID_ANY }; @@ -333,6 +342,15 @@ public: private: std::vector m_presetitems; + std::vector> m_sync_checks; // checkbox, option, value position and column of each copy + std::vector> m_option_checks; // checkbox, preset type and option of each change + std::vector>> m_all_checks; // a box ticking several changes or copies, and those + std::vector> m_sync_columns; // the label column, then one per extruder; the header window first + size_t add_all_check(wxWindow *parent); + void update_all_checks(); + // The options of the changed rows of the type (any type for nullptr) whose box is ticked, or not. A row without + // a box is always selected. + std::vector options_by_selection(const Preset::Type *type, bool selected) const; // preset names which are modified in SavePresetDialog and related types std::vector names_and_types; //std::vector> names_and_types; @@ -354,18 +372,23 @@ public: struct SyncExtruderParams { - DynamicConfig *config; - int from; - int to; - bool left_to_right; - NozzleVolumeType nozzle; + // Where an option's values are in each column, -1 for a column without one, and how many each holds. + struct Positions + { + int stride; + std::vector index; + }; + DynamicConfig *config; // the options to copy, with their values before the copy + std::vector titles; // the source and targets, in extruder (or nozzle variant) order + int source; // the source's column + std::map positions; // per option }; // show unsaved changes when preset is switching UnsavedChangesDialog(Preset::Type type, PresetCollection* dependent_presets, const std::string& new_selected_preset, bool no_transfer = false); // show unsaved changes for all another cases UnsavedChangesDialog(const wxString& caption, const wxString& header, const std::string& app_config_key, int act_buttons); - UnsavedChangesDialog(const wxString &caption, const wxString &header, DynamicConfig *config, int from, int to, bool left_to_right, NozzleVolumeType nozzle); + UnsavedChangesDialog(const wxString &caption, const wxString &header, Preset::Type type, SyncExtruderParams params); ~UnsavedChangesDialog() override = default; int ShowModal() override; @@ -373,15 +396,18 @@ public: void build(Preset::Type type, PresetCollection *dependent_presets, const std::string &new_selected_preset, const wxString &header = ""); void update(Preset::Type type, PresetCollection* dependent_presets, const std::string& new_selected_preset, const wxString& header); void update_list(SyncExtruderParams *params = nullptr); - std::string subreplace(std::string resource_str, std::string sub_str, std::string new_str); + bool value_clips(const wxString &value) const; void update_tree(Preset::Type type, PresetCollection *presets); - void update_tree(Preset::Type type, DynamicConfig *config, int from, int to); + void update_tree(Preset::Type type, DynamicConfig *config); void show_info_line(Action action, std::string preset_name = ""); void update_config(Action action); void close(Action action); // save information about saved presets and their types to names_and_types and show SavePresetDialog to set the names for new presets bool save(PresetCollection* dependent_presets, bool show_save_preset_dialog = true); + // Option and variant column of each ticked copy in the extruder sync dialog. + std::vector> get_sync_selection() const; + bool save_preset() const { return m_exit_action == Action::Save; } bool transfer_changes() const { return m_exit_action == Action::Transfer; } bool discard() const { return m_exit_action == Action::Discard; } @@ -394,30 +420,10 @@ public: // short version of the previous function, for the case, when just one preset is modified std::string get_preset_name() { return names_and_types[0].name; } - std::vector get_unselected_options(Preset::Type type) { /* return m_tree->options(type, false);*/return std::vector();} - std::vector get_selected_options (Preset::Type type) { - //return m_tree->options(type, true); - std::vector tmp; - for (int i = 0; i < m_presetitems.size(); i++) { - if (m_presetitems[i].type == type) { - tmp.push_back(m_presetitems[i].opt_key); - } - } - - return tmp; - } - std::vector get_selected_options() { - //return m_tree->selected_options(); - - std::vector tmp; - for (int i = 0; i < m_presetitems.size(); i++) - { - tmp.push_back(m_presetitems[i].opt_key); - } - - return tmp; - } - bool has_unselected_options() { /*return m_tree->has_unselected_options();*/return false;} + std::vector get_unselected_options(Preset::Type type) { return options_by_selection(&type, false); } + std::vector get_selected_options (Preset::Type type) { return options_by_selection(&type, true); } + std::vector get_selected_options() { return options_by_selection(nullptr, true); } + bool has_unselected_options() { return !options_by_selection(nullptr, false).empty(); } protected: void on_dpi_changed(const wxRect& suggested_rect) override; diff --git a/tests/libslic3r/test_parameter_utils.cpp b/tests/libslic3r/test_parameter_utils.cpp index a1a436eb83..e247200345 100644 --- a/tests/libslic3r/test_parameter_utils.cpp +++ b/tests/libslic3r/test_parameter_utils.cpp @@ -1,8 +1,11 @@ #include +#include #include +#include "libslic3r/Config.hpp" #include "libslic3r/ParameterUtils.hpp" +#include "libslic3r/PrintConfig.hpp" using namespace Slic3r; @@ -47,3 +50,44 @@ TEST_CASE("A sequence count without matching values gives no custom sequence", " CHECK(get_other_layers_print_sequence(-1, std::vector{1, 5, 2}).empty()); CHECK(get_other_layers_print_sequence(1, {}).empty()); } + +TEST_CASE("A process gets columns for tools added to the printer, copied from tool 1", "[ParameterUtils]") +{ + const std::string standard = "Direct Drive Standard", high_flow = "Direct Drive High Flow"; + // Two tools with a Standard and a High Flow column each, as a toolchanger profile ships them. + DynamicPrintConfig process; + process.option("print_extruder_id", true)->values = {1, 1, 2, 2}; + process.option("print_extruder_variant", true)->values = {standard, high_flow, standard, high_flow}; + process.option("outer_wall_speed", true)->values = {100., 200., 110., 210.}; + process.option("inner_wall_speed", true)->values = {50.}; + // The printer's extruder count raised to three. + DynamicPrintConfig printer; + printer.option("extruder_variant_list", true)->values = {standard + "," + high_flow, standard + "," + high_flow, + standard + "," + high_flow}; + + REQUIRE(add_process_columns_for_new_tools(process, printer)); + CHECK(process.option("print_extruder_id")->values == std::vector{1, 1, 2, 2, 3, 3}); + CHECK(process.option("print_extruder_variant")->values == + std::vector{standard, high_flow, standard, high_flow, standard, high_flow}); + // Each new column copies tool 1's column of its variant. + CHECK(process.option("outer_wall_speed")->values == std::vector{100., 200., 110., 210., 100., 200.}); + // A single value already serves every column. + CHECK(process.option("inner_wall_speed")->values == std::vector{50.}); + // Every tool has its columns now. + CHECK_FALSE(add_process_columns_for_new_tools(process, printer)); + CHECK(process.option("print_extruder_id")->values.size() == 6); +} + +TEST_CASE("A process with one column keeps it shared by every tool", "[ParameterUtils]") +{ + DynamicPrintConfig process; + process.option("print_extruder_id", true)->values = {1}; + process.option("print_extruder_variant", true)->values = {"Direct Drive Standard"}; + process.option("outer_wall_speed", true)->values = {30.}; + DynamicPrintConfig printer; + printer.option("extruder_variant_list", true)->values = {"Direct Drive Standard", "Direct Drive Standard"}; + + CHECK_FALSE(add_process_columns_for_new_tools(process, printer)); + CHECK(process.option("print_extruder_id")->values == std::vector{1}); + CHECK(process.option("outer_wall_speed")->values == std::vector{30.}); +}