DiffPresetDialog, non modal to compare two presets.

Added menu item "Window->Compare presets" to compare more than one type
of presets.
Code refactoring for PresetComboBox: Use suffix "modified" just for
PlaterPresetComboBox and TabPresetComboBox
Code refactoring. wxDataViewCtrl and related functions extracted from
DiffPresetDialog and UnsavedChangesDialog to the separate class
DiffViewCtrl
Code refactoring, Tab.cpp: Build all unregular pages on a first build of
the Printer Settings

Squashed commit of the following:

commit 91f45a8a2d97d252337c7306dd02db607fd79c00
Author: Vojtech Bubnik <bubnikv@gmail.com>
Date:   Thu Feb 4 09:34:29 2021 +0100

    Fixed after merge

commit 09aa502498b08c059ecdf334f5db1567739b4520
Merge: 6df8e83e1 0baa92fab
Author: Vojtech Bubnik <bubnikv@gmail.com>
Date:   Thu Feb 4 09:31:43 2021 +0100

    Merge remote-tracking branch 'remotes/origin/master' into ys_diff_dlg

commit 6df8e83e1af3ba096ac39d25985b6deb2e0a245b
Author: Vojtech Bubnik <bubnikv@gmail.com>
Date:   Thu Feb 4 09:29:53 2021 +0100

    Tiny beautification.

commit e781ceaaf7c39bc073476409cc02918d9f182930
Author: Vojtech Bubnik <bubnikv@gmail.com>
Date:   Wed Feb 3 18:05:19 2021 +0100

    Reworked copying of PresetBundles:
    1) Simplified by using the default copy constructors and copy operators.
    2) Made safer by not allowing PresetCollection and PhysicalPrinterPresetCollection
       to be copied or instantiated outside of PresetBundle.
    3) Fixed Preset::vendor pointers after copying PresetBundle.

commit a8f0b7aa5156465cdb3e3dbb86feb66a64bcebc0
Author: YuSanka <yusanka@gmail.com>
Date:   Mon Jan 25 16:13:53 2021 +0100

    DiffPresetsDialog: Show compatibility to print/printer presets selected in DiffPresetDialog

commit 597451f930a4330376966d8cf3350056d4f85a73
Merge: cce5b5710 59017a7da
Author: YuSanka <yusanka@gmail.com>
Date:   Thu Jan 21 12:14:48 2021 +0100

    Merge remote-tracking branch 'origin/master' into ys_diff_dlg

commit cce5b5710d1225c7eaa52d0abb4b3f66fbd3b6a1
Author: YuSanka <yusanka@gmail.com>
Date:   Thu Jan 21 12:11:40 2021 +0100

    DiffPresetDialog: Fixed crash on ASAN build

commit ad8d728d89d7a75c2ac136ea8cdbb730ab774cd9
Author: YuSanka <yusanka@gmail.com>
Date:   Wed Jan 20 16:38:28 2021 +0100

    FullCompareDialog improvements

commit 316bafbeec9bb63f731b653d296062d9e22dd02f
Author: YuSanka <yusanka@gmail.com>
Date:   Wed Jan 20 09:25:46 2021 +0100

    DiffPresetDialog improvements:
    * Update presets lists after save changes in edited preset or change printer_technology
    * Tab.cpp: Build all unregular pages on a first build of the Printer Settings

commit 01171c8ef50389d0801b0ccc5746ab0c3b731b11
Author: YuSanka <yusanka@gmail.com>
Date:   Tue Jan 19 17:26:28 2021 +0100

    DiffPresetDialog : improvements
    * This dialog is non-modal now
    * "Compare presets" menu item is moved from "View" to the "Window" menu group
    * Added info tooltips for the bitmap buttons between presets
    * Added "Show all presets" checkbox
    * Show full difference between printer presets with different count of extruders

commit 3d38b62f3c9de8aab352ed3bcff297d5c0239b2e
Merge: e50fe6de9 9a2310ae9
Author: YuSanka <yusanka@gmail.com>
Date:   Mon Jan 18 10:00:18 2021 +0100

    Merge remote-tracking branch 'origin/master' into ys_diff_dlg

commit e50fe6de984decadfef3d4b952f0eec8ab9e6670
Author: YuSanka <yusanka@gmail.com>
Date:   Sat Jan 16 02:27:24 2021 +0100

    DiffPresetDialog improvements
    Added menu item "View->Compare presets" to compare more than one type of presets

commit bf08b7c8c969ad0ca631b9eeac1bc231f474e72b
Author: YuSanka <yusanka@gmail.com>
Date:   Sat Jan 16 00:28:39 2021 +0100

    Code refactoring. wxDataViewCtrl and related functions extracted from DiffPresetDialog and UnsavedChangesDialog to the separate class DiffViewCtrl

commit 7aeb63032b0bc2bd06e60990c060008660a5c44f
Author: YuSanka <yusanka@gmail.com>
Date:   Fri Jan 15 21:35:43 2021 +0100

    DiffPresetDialog: first implementation

commit 2f23d5af9d6b5dd670dfb7d06eedbe0e6d2960c6
Author: YuSanka <yusanka@gmail.com>
Date:   Thu Jan 14 16:28:43 2021 +0100

    Code refactoring for PresetComboBox.
    Use suffix "modified" just for PlaterPresetComboBox and TabPresetComboBox
This commit is contained in:
Vojtech Bubnik 2021-02-04 09:42:32 +01:00
parent 0baa92fab8
commit 4cdcfe6005
17 changed files with 1150 additions and 315 deletions

View file

@ -37,6 +37,7 @@
#include <string_view>
#include "GUI_App.hpp"
#include "UnsavedChangesDialog.hpp"
#ifdef _WIN32
#include <dbt.h>
@ -1190,6 +1191,10 @@ void MainFrame::init_menubar_as_editor()
windowMenu->AppendSeparator();
append_menu_item(windowMenu, wxID_ANY, _L("Open new instance") + "\tCtrl+Shift+I", _L("Open a new PrusaSlicer instance"),
[this](wxCommandEvent&) { start_new_slicer(); }, "", nullptr, [this]() {return m_plater != nullptr && wxGetApp().app_config->get("single_instance") != "1"; }, this);
windowMenu->AppendSeparator();
append_menu_item(windowMenu, wxID_ANY, _L("Compare presets")/* + "\tCtrl+F"*/, _L("Compare presets"),
[this](wxCommandEvent&) { diff_dialog.show();}, "compare", nullptr, []() {return true; }, this);
}
// View menu

View file

@ -16,6 +16,7 @@
#include "GUI_Utils.hpp"
#include "Event.hpp"
#include "UnsavedChangesDialog.hpp"
class wxNotebook;
class wxProgressDialog;
@ -190,6 +191,7 @@ public:
Plater* m_plater { nullptr };
wxNotebook* m_tabpanel { nullptr };
SettingsDialog m_settings_dialog;
DiffPresetDialog diff_dialog;
wxWindow* m_plater_page{ nullptr };
wxProgressDialog* m_progress_dialog { nullptr };
PrintHostQueueDialog* m_printhost_queue_dlg;

View file

@ -62,12 +62,12 @@ namespace GUI {
* control size calculation methods (virtual) are overridden.
**/
PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const wxSize& size) :
PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const wxSize& size, PresetBundle* preset_bundle/* = nullptr*/) :
wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, size, 0, nullptr, wxCB_READONLY),
m_type(preset_type),
m_last_selected(wxNOT_FOUND),
m_em_unit(em_unit(this)),
m_preset_bundle(wxGetApp().preset_bundle)
m_preset_bundle(preset_bundle ? preset_bundle : wxGetApp().preset_bundle)
{
SetFont(wxGetApp().normal_font());
#ifdef _WIN32
@ -208,6 +208,21 @@ void PresetComboBox::update_selection()
#endif
}
static std::string suffix(const Preset& preset)
{
return (preset.is_dirty ? Preset::suffix_modified() : "");
}
static std::string suffix(Preset* preset)
{
return (preset->is_dirty ? Preset::suffix_modified() : "");
}
wxString PresetComboBox::get_preset_name(const Preset & preset)
{
return from_u8(preset.name/* + suffix(preset)*/);
}
void PresetComboBox::update(std::string select_preset_name)
{
Freeze();
@ -226,7 +241,7 @@ void PresetComboBox::update(std::string select_preset_name)
for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i)
{
const Preset& preset = presets[i];
if (!preset.is_visible || !preset.is_compatible)
if (!m_show_all && (!preset.is_visible || !preset.is_compatible))
continue;
// marker used for disable incompatible printer models for the selected physical printer
@ -246,17 +261,17 @@ void PresetComboBox::update(std::string select_preset_name)
assert(bmp);
if (!is_enabled)
incomp_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), bmp);
incomp_presets.emplace(get_preset_name(preset), bmp);
else if (preset.is_default || preset.is_system)
{
Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp);
Append(get_preset_name(preset), *bmp);
validate_selection(preset.name == select_preset_name);
}
else
{
nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), std::pair<wxBitmap*, bool>(bmp, is_enabled));
nonsys_presets.emplace(get_preset_name(preset), std::pair<wxBitmap*, bool>(bmp, is_enabled));
if (preset.name == select_preset_name || (select_preset_name.empty() && is_enabled))
selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str());
selected = get_preset_name(preset);
}
if (i + 1 == m_collection->num_default_presets())
set_label_marker(Append(separator(L("System presets")), wxNullBitmap));
@ -329,11 +344,22 @@ bool PresetComboBox::del_physical_printer(const wxString& note_string/* = wxEmpt
return true;
}
void PresetComboBox::show_all(bool show_all)
{
m_show_all = show_all;
update();
}
void PresetComboBox::update()
{
this->update(into_u8(this->GetString(this->GetSelection())));
}
void PresetComboBox::update_from_bundle()
{
this->update(m_collection->get_selected_preset().name);
}
void PresetComboBox::msw_rescale()
{
m_em_unit = em_unit(this);
@ -745,6 +771,12 @@ void PlaterPresetComboBox::show_edit_menu()
wxGetApp().plater()->PopupMenu(menu);
}
wxString PlaterPresetComboBox::get_preset_name(const Preset& preset)
{
std::string name = preset.alias.empty() ? preset.name : preset.alias;
return from_u8(name + suffix(preset));
}
// Only the compatible presets are shown.
// If an incompatible preset is selected, it is shown as well.
void PlaterPresetComboBox::update()
@ -821,17 +853,17 @@ void PlaterPresetComboBox::update()
const std::string name = preset.alias.empty() ? preset.name : preset.alias;
if (preset.is_default || preset.is_system) {
Append(wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp);
Append(get_preset_name(preset), *bmp);
validate_selection(is_selected);
if (is_selected)
tooltip = wxString::FromUTF8(preset.name.c_str());
tooltip = from_u8(preset.name);
}
else
{
nonsys_presets.emplace(wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), bmp);
nonsys_presets.emplace(get_preset_name(preset), bmp);
if (is_selected) {
selected_user_preset = wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str());
tooltip = wxString::FromUTF8(preset.name.c_str());
selected_user_preset = get_preset_name(preset);
tooltip = from_u8(preset.name);
}
}
if (i + 1 == m_collection->num_default_presets())
@ -862,7 +894,7 @@ void PlaterPresetComboBox::update()
wxBitmap* bmp = get_bmp(main_icon_name, wide_icons, main_icon_name);
assert(bmp);
set_label_marker(Append(wxString::FromUTF8((it->get_full_name(preset_name) + (preset->is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp), LABEL_ITEM_PHYSICAL_PRINTER);
set_label_marker(Append(from_u8(it->get_full_name(preset_name) + suffix(preset)), *bmp), LABEL_ITEM_PHYSICAL_PRINTER);
validate_selection(ph_printers.is_selected(it, preset_name));
}
}
@ -946,6 +978,11 @@ TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type)
});
}
wxString TabPresetComboBox::get_preset_name(const Preset& preset)
{
return from_u8(preset.name + suffix(preset));
}
// Update the choice UI from the list of presets.
// If show_incompatible, all presets are shown, otherwise only the compatible presets are shown.
// If an incompatible preset is selected, it is shown as well.
@ -991,7 +1028,7 @@ void TabPresetComboBox::update()
assert(bmp);
if (preset.is_default || preset.is_system) {
int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp);
int item_id = Append(get_preset_name(preset), *bmp);
if (!is_enabled)
set_label_marker(item_id, LABEL_ITEM_DISABLED);
validate_selection(i == idx_selected);
@ -999,9 +1036,9 @@ void TabPresetComboBox::update()
else
{
std::pair<wxBitmap*, bool> pair(bmp, is_enabled);
nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), std::pair<wxBitmap*, bool>(bmp, is_enabled));
nonsys_presets.emplace(get_preset_name(preset), std::pair<wxBitmap*, bool>(bmp, is_enabled));
if (i == idx_selected)
selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str());
selected = get_preset_name(preset);
}
if (i + 1 == m_collection->num_default_presets())
set_label_marker(Append(separator(L("System presets")), wxNullBitmap));
@ -1035,7 +1072,7 @@ void TabPresetComboBox::update()
wxBitmap* bmp = get_bmp(main_icon_name, main_icon_name, "", true, true, false);
assert(bmp);
set_label_marker(Append(wxString::FromUTF8((it->get_full_name(preset_name) + (preset->is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp), LABEL_ITEM_PHYSICAL_PRINTER);
set_label_marker(Append(from_u8(it->get_full_name(preset_name) + suffix(preset)), *bmp), LABEL_ITEM_PHYSICAL_PRINTER);
validate_selection(ph_printers.is_selected(it, preset_name));
}
}
@ -1082,15 +1119,15 @@ void TabPresetComboBox::update_dirty()
preset_name = PhysicalPrinter::get_preset_name(preset_name);
}
const Preset* preset = m_collection->find_preset(preset_name, false);
Preset* preset = m_collection->find_preset(preset_name, false);
if (preset) {
std::string new_label = preset->is_dirty ? preset->name + Preset::suffix_modified() : preset->name;
std::string new_label = preset->name + suffix(preset);
if (marker == LABEL_ITEM_PHYSICAL_PRINTER)
new_label = ph_printer_name + PhysicalPrinter::separator() + new_label;
if (old_label != new_label)
SetString(ui_id, wxString::FromUTF8(new_label.c_str()));
SetString(ui_id, from_u8(new_label));
}
}
#ifdef __APPLE__

View file

@ -30,8 +30,9 @@ class BitmapCache;
// BitmapComboBox used to presets list on Sidebar and Tabs
class PresetComboBox : public wxBitmapComboBox
{
bool m_show_all { false };
public:
PresetComboBox(wxWindow* parent, Preset::Type preset_type, const wxSize& size = wxDefaultSize);
PresetComboBox(wxWindow* parent, Preset::Type preset_type, const wxSize& size = wxDefaultSize, PresetBundle* preset_bundle = nullptr);
~PresetComboBox();
enum LabelItemType {
@ -58,11 +59,16 @@ public:
bool selection_is_changed_according_to_physical_printers();
void update(std::string select_preset);
// select preset which is selected in PreseBundle
void update_from_bundle();
void edit_physical_printer();
void add_physical_printer();
bool del_physical_printer(const wxString& note_string = wxEmptyString);
virtual wxString get_preset_name(const Preset& preset);
Preset::Type get_type() { return m_type; }
void show_all(bool show_all);
virtual void update();
virtual void msw_rescale();
@ -158,6 +164,7 @@ public:
void show_add_menu();
void show_edit_menu();
wxString get_preset_name(const Preset& preset) override;
void update() override;
void msw_rescale() override;
@ -182,6 +189,7 @@ public:
show_incompatible = show_incompatible_presets;
}
wxString get_preset_name(const Preset& preset) override;
void update() override;
void update_dirty();
void msw_rescale() override;

View file

@ -326,6 +326,53 @@ const Option& OptionsSearcher::get_option(const std::string& opt_key) const
return options[it - options.begin()];
}
static Option create_option(const std::string& opt_key, const wxString& label, Preset::Type type, const GroupAndCategory& gc)
{
wxString suffix;
wxString suffix_local;
if (gc.category == "Machine limits") {
suffix = opt_key.back() == '1' ? L("Stealth") : L("Normal");
suffix_local = " " + _(suffix);
suffix = " " + suffix;
}
wxString category = gc.category;
if (type == Preset::TYPE_PRINTER && category.Contains("Extruder ")) {
std::string opt_idx = opt_key.substr(opt_key.find("#") + 1);
category = wxString::Format("%s %d", "Extruder", atoi(opt_idx.c_str()) + 1);
}
return Option{ boost::nowide::widen(opt_key), type,
(label + suffix).ToStdWstring(), (_(label) + suffix_local).ToStdWstring(),
gc.group.ToStdWstring(), _(gc.group).ToStdWstring(),
gc.category.ToStdWstring(), GUI::Tab::translate_category(category, type).ToStdWstring() };
}
Option OptionsSearcher::get_option(const std::string& opt_key, const wxString& label, Preset::Type type) const
{
auto it = std::lower_bound(options.begin(), options.end(), Option({ boost::nowide::widen(opt_key) }));
if(it->opt_key == boost::nowide::widen(opt_key))
return options[it - options.begin()];
if (groups_and_categories.find(opt_key) == groups_and_categories.end()) {
size_t pos = opt_key.find('#');
if (pos == std::string::npos)
return options[it - options.begin()];
std::string zero_opt_key = opt_key.substr(0, pos + 1) + "0";
if(groups_and_categories.find(zero_opt_key) == groups_and_categories.end())
return options[it - options.begin()];
return create_option(opt_key, label, type, groups_and_categories.at(zero_opt_key));
}
const GroupAndCategory& gc = groups_and_categories.at(opt_key);
if (gc.group.IsEmpty() || gc.category.IsEmpty())
return options[it - options.begin()];
return create_option(opt_key, label, type, gc);
}
void OptionsSearcher::add_key(const std::string& opt_key, const wxString& group, const wxString& category)
{
groups_and_categories[opt_key] = GroupAndCategory{group, category};

View file

@ -117,6 +117,7 @@ public:
const FoundOption& operator[](const size_t pos) const noexcept { return found[pos]; }
const Option& get_option(size_t pos_in_filter) const;
const Option& get_option(const std::string& opt_key) const;
Option get_option(const std::string& opt_key, const wxString& label, Preset::Type type) const;
const std::vector<FoundOption>& found_options() { return found; }
const GroupAndCategory& get_group_and_category (const std::string& opt_key) { return groups_and_categories[opt_key]; }

View file

@ -196,6 +196,7 @@ void Tab::create_preset_tab()
m_scaled_buttons.reserve(6);
m_scaled_buttons.reserve(2);
add_scaled_button(panel, &m_btn_compare_preset, "compare");
add_scaled_button(panel, &m_btn_save_preset, "save");
add_scaled_button(panel, &m_btn_delete_preset, "cross");
if (m_type == Preset::Type::TYPE_PRINTER)
@ -207,6 +208,7 @@ void Tab::create_preset_tab()
add_scaled_button(panel, &m_btn_hide_incompatible_presets, m_bmp_hide_incompatible_presets.name());
m_btn_compare_preset->SetToolTip(_L("Compare this preset with some another"));
// TRN "Save current Settings"
m_btn_save_preset->SetToolTip(from_u8((boost::format(_utf8(L("Save current %s"))) % m_title).str()));
m_btn_delete_preset->SetToolTip(_(L("Delete this preset")));
@ -271,6 +273,9 @@ void Tab::create_preset_tab()
m_hsizer->Add(m_undo_btn, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(int(32 * scale_factor));
m_hsizer->Add(m_search_btn, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(int(8*scale_factor));
m_hsizer->Add(m_btn_compare_preset, 0, wxALIGN_CENTER_VERTICAL);
m_hsizer->AddSpacer(int(16*scale_factor));
// m_hsizer->AddStretchSpacer(32);
// StretchSpacer has a strange behavior under OSX, so
// There is used just additional sizer for m_mode_sizer with right alignment
@ -338,6 +343,7 @@ void Tab::create_preset_tab()
m_page_view->SetScrollbars(1, 20, 1, 2);
m_hsizer->Add(m_page_view, 1, wxEXPAND | wxLEFT, 5);
m_btn_compare_preset->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { compare_preset(); }));
m_btn_save_preset->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { save_preset(); }));
m_btn_delete_preset->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) { delete_preset(); }));
m_btn_hide_incompatible_presets->Bind(wxEVT_BUTTON, ([this](wxCommandEvent e) {
@ -2066,11 +2072,18 @@ bool Tab::current_preset_is_dirty()
void TabPrinter::build()
{
m_presets = &m_preset_bundle->printers;
load_initial_data();
m_printer_technology = m_presets->get_selected_preset().printer_technology();
m_presets->get_selected_preset().printer_technology() == ptSLA ? build_sla() : build_fff();
// For DiffPresetDialog we use options list which is saved in Searcher class.
// Options for the Searcher is added in the moment of pages creation.
// So, build first of all printer pages for non-selected printer technology...
std::string def_preset_name = "- default " + std::string(m_printer_technology == ptSLA ? "FFF" : "SLA") + " -";
m_config = &m_presets->find_preset(def_preset_name)->config;
m_printer_technology == ptSLA ? build_fff() : build_sla();
// ... and than for selected printer technology
load_initial_data();
m_printer_technology == ptSLA ? build_sla() : build_fff();
}
void TabPrinter::build_print_host_upload_group(Page* page)
@ -2105,7 +2118,8 @@ void TabPrinter::build_fff()
m_initial_extruders_count = m_extruders_count = nozzle_diameter->values.size();
wxGetApp().sidebar().update_objects_list_extruder_column(m_initial_extruders_count);
const Preset* parent_preset = m_presets->get_selected_preset_parent();
const Preset* parent_preset = m_printer_technology == ptSLA ? nullptr // just for first build, if SLA printer preset is selected
: m_presets->get_selected_preset_parent();
m_sys_extruders_count = parent_preset == nullptr ? 0 :
static_cast<const ConfigOptionFloats*>(parent_preset->config.option("nozzle_diameter"))->values.size();
@ -2289,7 +2303,7 @@ void TabPrinter::build_fff()
build_preset_description_line(optgroup.get());
build_unregular_pages();
build_unregular_pages(true);
}
void TabPrinter::build_sla()
@ -2395,7 +2409,9 @@ void TabPrinter::append_option_line(ConfigOptionsGroupShp optgroup, const std::s
auto option = optgroup->get_option(opt_key, 0);
auto line = Line{ option.opt.full_label, "" };
line.append_option(option);
if (m_use_silent_mode)
if (m_use_silent_mode
|| m_printer_technology == ptSLA // just for first build, if SLA printer preset is selected
)
line.append_option(optgroup->get_option(opt_key, 1));
optgroup->append_line(line);
}
@ -2470,7 +2486,7 @@ PageShp TabPrinter::build_kinematics_page()
* but "Machine limits" and "Single extruder MM setup" too
* (These pages can changes according to the another values of a current preset)
* */
void TabPrinter::build_unregular_pages()
void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/)
{
size_t n_before_extruders = 2; // Count of pages before Extruder pages
bool is_marlin_flavor = m_config->option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor")->value == gcfMarlin;
@ -2481,18 +2497,6 @@ void TabPrinter::build_unregular_pages()
* */
Freeze();
#ifdef __WXMSW__
/* Workaround for correct layout of controls inside the created page:
* In some _strange_ way we should we should imitate page resizing.
*/
/* auto layout_page = [this](PageShp page)
{
const wxSize& sz = page->GetSize();
page->SetSize(sz.x + 1, sz.y + 1);
page->SetSize(sz);
};*/
#endif //__WXMSW__
// Add/delete Kinematics page according to is_marlin_flavor
size_t existed_page = 0;
for (size_t i = n_before_extruders; i < m_pages.size(); ++i) // first make sure it's not there already
@ -2504,12 +2508,12 @@ void TabPrinter::build_unregular_pages()
break;
}
if (existed_page < n_before_extruders && is_marlin_flavor) {
if (existed_page < n_before_extruders && (is_marlin_flavor || from_initial_build)) {
auto page = build_kinematics_page();
#ifdef __WXMSW__
// layout_page(page);
#endif
m_pages.insert(m_pages.begin() + n_before_extruders, page);
if (from_initial_build)
page->clear();
else
m_pages.insert(m_pages.begin() + n_before_extruders, page);
}
if (is_marlin_flavor)
@ -2527,7 +2531,8 @@ void TabPrinter::build_unregular_pages()
}
m_has_single_extruder_MM_page = false;
}
if (m_extruders_count > 1 && m_config->opt_bool("single_extruder_multi_material") && !m_has_single_extruder_MM_page) {
if (from_initial_build ||
(m_extruders_count > 1 && m_config->opt_bool("single_extruder_multi_material") && !m_has_single_extruder_MM_page)) {
// create a page, but pretend it's an extruder page, so we can add it to m_pages ourselves
auto page = add_options_page(L("Single extruder MM setup"), "printer", true);
auto optgroup = page->new_optgroup(L("Single extruder multimaterial parameters"));
@ -2536,8 +2541,12 @@ void TabPrinter::build_unregular_pages()
optgroup->append_single_option_line("parking_pos_retraction");
optgroup->append_single_option_line("extra_loading_move");
optgroup->append_single_option_line("high_current_on_filament_swap");
m_pages.insert(m_pages.end() - n_after_single_extruder_MM, page);
m_has_single_extruder_MM_page = true;
if (from_initial_build)
page->clear();
else {
m_pages.insert(m_pages.end() - n_after_single_extruder_MM, page);
m_has_single_extruder_MM_page = true;
}
}
// Build missed extruder pages
@ -2642,10 +2651,6 @@ void TabPrinter::build_unregular_pages()
line = optgroup->create_single_option_line("extruder_colour", wxEmptyString, extruder_idx);
line.append_widget(reset_to_filament_color);
optgroup->append_line(line);
#ifdef __WXMSW__
// layout_page(page);
#endif
}
// # remove extra pages
@ -2656,6 +2661,10 @@ void TabPrinter::build_unregular_pages()
Thaw();
m_extruders_count_old = m_extruders_count;
if (m_printer_technology == ptSLA/*from_initial_build*/)
return; // next part of code is no needed to execute at this moment
rebuild_page_tree();
// Reload preset pages with current configuration values
@ -3187,6 +3196,9 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/,
load_current_preset();
}
if (technology_changed)
wxGetApp().mainframe->diff_dialog.update_presets();
}
// If the current preset is dirty, the user is asked whether the changes may be discarded.
@ -3374,6 +3386,11 @@ void Tab::OnKeyDown(wxKeyEvent& event)
event.Skip();
}
void Tab::compare_preset()
{
wxGetApp().mainframe->diff_dialog.show(m_type);
}
// Save the current preset into file.
// This removes the "dirty" flag of the preset, possibly creates a new preset under a new name,
// and activates the new preset.
@ -3443,6 +3460,9 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach)
for (Preset::Type preset_type : dependent)
wxGetApp().get_tab(preset_type)->update_tab_ui();
}
// update preset comboboxes in DiffPresetDlg
wxGetApp().mainframe->diff_dialog.update_presets(m_type);
}
// Called for a currently selected preset.

View file

@ -112,6 +112,7 @@ protected:
const wxString m_title;
TabPresetComboBox* m_presets_choice;
ScalableButton* m_search_btn;
ScalableButton* m_btn_compare_preset;
ScalableButton* m_btn_save_preset;
ScalableButton* m_btn_delete_preset;
ScalableButton* m_btn_edit_ph_printer {nullptr};
@ -290,6 +291,7 @@ public:
void OnTreeSelChange(wxTreeEvent& event);
void OnKeyDown(wxKeyEvent& event);
void compare_preset();
void save_preset(std::string name = std::string(), bool detach = false);
void delete_preset();
void toggle_show_hide_incompatible();
@ -456,7 +458,7 @@ public:
void update_pages(); // update m_pages according to printer technology
void extruders_count_changed(size_t extruders_count);
PageShp build_kinematics_page();
void build_unregular_pages();
void build_unregular_pages(bool from_initial_build = false);
void on_preset_loaded() override;
void init_options_list() override;
void msw_rescale() override;

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,7 @@
#include "GUI_Utils.hpp"
#include "wxExtensions.hpp"
#include "libslic3r/Preset.hpp"
#include "libslic3r/PresetBundle.hpp"
class ScalableButton;
class wxStaticText;
@ -16,10 +16,11 @@ namespace Slic3r {
namespace GUI{
// ----------------------------------------------------------------------------
// ModelNode: a node inside UnsavedChangesModel
// ModelNode: a node inside DiffModel
// ----------------------------------------------------------------------------
class ModelNode;
class PresetComboBox;
using ModelNodePtrArray = std::vector<std::unique_ptr<ModelNode>>;
// On all of 3 different platforms Bitmap+Text icon column looks different
@ -42,17 +43,6 @@ class ModelNode
wxString m_old_color;
wxString m_new_color;
// TODO/FIXME:
// the GTK version of wxDVC (in particular wxDataViewCtrlInternal::ItemAdded)
// needs to know in advance if a node is or _will be_ a container.
// Thus implementing:
// bool IsContainer() const
// { return m_children.size()>0; }
// doesn't work with wxGTK when UnsavedChangesModel::AddToClassical is called
// AND the classical node was removed (a new node temporary without children
// would be added to the control)
bool m_container {true};
#ifdef __linux__
wxIcon get_bitmap(const wxString& color);
#else
@ -75,6 +65,17 @@ public:
wxString m_old_value;
wxString m_new_value;
// TODO/FIXME:
// the GTK version of wxDVC (in particular wxDataViewCtrlInternal::ItemAdded)
// needs to know in advance if a node is or _will be_ a container.
// Thus implementing:
// bool IsContainer() const
// { return m_children.size()>0; }
// doesn't work with wxGTK when DiffModel::AddToClassical is called
// AND the classical node was removed (a new node temporary without children
// would be added to the control)
bool m_container {true};
// preset(root) node
ModelNode(Preset::Type preset_type, wxWindow* parent_win, const wxString& text, const std::string& icon_name);
@ -107,13 +108,13 @@ public:
// ----------------------------------------------------------------------------
// UnsavedChangesModel
// DiffModel
// ----------------------------------------------------------------------------
class UnsavedChangesModel : public wxDataViewModel
class DiffModel : public wxDataViewModel
{
wxWindow* m_parent_win { nullptr };
std::vector<ModelNode*> m_preset_nodes;
ModelNodePtrArray m_preset_nodes;
wxDataViewCtrl* m_ctrl{ nullptr };
@ -143,8 +144,8 @@ public:
colMax
};
UnsavedChangesModel(wxWindow* parent);
~UnsavedChangesModel();
DiffModel(wxWindow* parent);
~DiffModel() {}
void SetAssociatedControl(wxDataViewCtrl* ctrl) { m_ctrl = ctrl; }
@ -159,6 +160,9 @@ public:
wxString GetColumnType(unsigned int col) const override;
void Rescale();
wxDataViewItem Delete(const wxDataViewItem& item);
void Clear();
wxDataViewItem GetParent(const wxDataViewItem& item) const override;
unsigned int GetChildren(const wxDataViewItem& parent, wxDataViewItemArray& array) const override;
@ -173,14 +177,60 @@ public:
};
// ----------------------------------------------------------------------------
// DiffViewCtrl
// ----------------------------------------------------------------------------
class DiffViewCtrl : public wxDataViewCtrl
{
bool m_has_long_strings{ false };
bool m_empty_selection { false };
int m_em_unit;
struct ItemData
{
std::string opt_key;
wxString opt_name;
wxString old_val;
wxString new_val;
Preset::Type type;
bool is_long{ false };
};
// tree items related to the options
std::map<wxDataViewItem, ItemData> m_items_map;
std::map<unsigned int, int> m_columns_width;
public:
DiffViewCtrl(wxWindow* parent, wxSize size);
~DiffViewCtrl() {}
DiffModel* model{ nullptr };
void AppendBmpTextColumn(const wxString& label, unsigned model_column, int width, bool set_expander = false);
void AppendToggleColumn_(const wxString& label, unsigned model_column, int width);
void Rescale(int em = 0);
void Append(const std::string& opt_key, Preset::Type type, wxString category_name, wxString group_name, wxString option_name,
wxString old_value, wxString new_value, const std::string category_icon_name);
void Clear();
wxString get_short_string(wxString full_string);
bool has_selection() { return !m_empty_selection; }
void context_menu(wxDataViewEvent& event);
void item_value_changed(wxDataViewEvent& event);
void set_em_unit(int em) { m_em_unit = em; }
std::vector<std::string> unselected_options(Preset::Type type);
std::vector<std::string> selected_options();
};
//------------------------------------------
// UnsavedChangesDialog
//------------------------------------------
class UnsavedChangesDialog : public DPIDialog
{
wxDataViewCtrl* m_tree { nullptr };
UnsavedChangesModel* m_tree_model { nullptr };
DiffViewCtrl* m_tree { nullptr };
ScalableButton* m_save_btn { nullptr };
ScalableButton* m_transfer_btn { nullptr };
ScalableButton* m_discard_btn { nullptr };
@ -188,7 +238,6 @@ class UnsavedChangesDialog : public DPIDialog
wxStaticText* m_info_line { nullptr };
wxCheckBox* m_remember_choice { nullptr };
bool m_empty_selection { false };
bool m_has_long_strings { false };
int m_save_btn_id { wxID_ANY };
int m_move_btn_id { wxID_ANY };
@ -209,19 +258,6 @@ class UnsavedChangesDialog : public DPIDialog
// selected action after Dialog closing
Action m_exit_action {Action::Undef};
struct ItemData
{
std::string opt_key;
wxString opt_name;
wxString old_val;
wxString new_val;
Preset::Type type;
bool is_long {false};
};
// tree items related to the options
std::map<wxDataViewItem, ItemData> m_items_map;
// preset names which are modified in SavePresetDialog and related types
std::vector<std::pair<std::string, Preset::Type>> names_and_types;
@ -230,13 +266,9 @@ public:
UnsavedChangesDialog(Preset::Type type, PresetCollection* dependent_presets, const std::string& new_selected_preset);
~UnsavedChangesDialog() {}
wxString get_short_string(wxString full_string);
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_tree(Preset::Type type, PresetCollection *presets);
void item_value_changed(wxDataViewEvent &event);
void context_menu(wxDataViewEvent &event);
void show_info_line(Action action, std::string preset_name = "");
void update_config(Action action);
void close(Action action);
@ -251,8 +283,8 @@ 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].first; }
std::vector<std::string> get_unselected_options(Preset::Type type);
std::vector<std::string> get_selected_options();
std::vector<std::string> get_unselected_options(Preset::Type type) { return m_tree->unselected_options(type); }
std::vector<std::string> get_selected_options() { return m_tree->selected_options(); }
protected:
void on_dpi_changed(const wxRect& suggested_rect) override;
@ -270,6 +302,48 @@ public:
~FullCompareDialog() {}
};
//------------------------------------------
// DiffPresetDialog
//------------------------------------------
class DiffPresetDialog : public DPIDialog
{
DiffViewCtrl* m_tree { nullptr };
wxStaticText* m_top_info_line { nullptr };
wxStaticText* m_bottom_info_line { nullptr };
wxCheckBox* m_show_all_presets { nullptr };
Preset::Type m_view_type { Preset::TYPE_INVALID };
PrinterTechnology m_pr_technology;
std::unique_ptr<PresetBundle> m_preset_bundle_left;
std::unique_ptr<PresetBundle> m_preset_bundle_right;
void update_tree();
void update_bundles_from_app();
void update_controls_visibility(Preset::Type type = Preset::TYPE_INVALID);
void update_compatibility(const std::string& preset_name, Preset::Type type, PresetBundle* preset_bundle);
struct DiffPresets
{
PresetComboBox* presets_left { nullptr };
ScalableButton* equal_bmp { nullptr };
PresetComboBox* presets_right { nullptr };
};
std::vector<DiffPresets> m_preset_combos;
public:
DiffPresetDialog();
~DiffPresetDialog() {}
void show(Preset::Type type = Preset::TYPE_INVALID);
void update_presets(Preset::Type type = Preset::TYPE_INVALID);
protected:
void on_dpi_changed(const wxRect& suggested_rect) override;
void on_sys_color_changed() override;
};
}
}