NEW: [STUDIO-4036 STUDIO-4073] create filament and printer dialog

Jira: 4036 4073

Change-Id: I073ee4a2af4c86332e6d052f5d7322c9f2784184
(cherry picked from commit f4ec32929e1e6ebecd87e2e709636a43be497265)
This commit is contained in:
maosheng.wei
2023-08-21 17:59:42 +08:00
committed by Lane.Wei
parent 131161f29b
commit 743f485fad
15 changed files with 3040 additions and 15 deletions

View File

@@ -2065,7 +2065,7 @@ Preset& PresetCollection::load_preset(const std::string &path, const std::string
return preset;
}
bool PresetCollection::clone_presets(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::function<void(Preset &)> modifier)
bool PresetCollection::clone_presets(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::function<void(Preset &)> modifier, bool force_rewritten)
{
std::vector<Preset> new_presets;
for (auto curr_preset : presets) {
@@ -2095,26 +2095,32 @@ bool PresetCollection::clone_presets(std::vector<Preset const *> const &presets,
preset.config.option<ConfigOptionString>("printer_settings_id", true)->value = preset.name;
preset.updated_time = (long long) Slic3r::Utils::get_current_time_utc();
}
if (!failures.empty())
if (!failures.empty() && !force_rewritten)
return false;
lock();
for (auto preset : new_presets) {
auto it = this->find_preset_internal(preset.name);
assert(it == m_presets.end() || it->name != preset.name);
Preset & new_preset = *m_presets.insert(it, preset);
new_preset.save(nullptr);
assert((it == m_presets.end() || it->name != preset.name) || force_rewritten);
if (it == m_presets.end() || it->name != preset.name) {
Preset &new_preset = *m_presets.insert(it, preset);
new_preset.save(nullptr);
} else if (force_rewritten) {
*it = preset;
(*it).save(nullptr);
}
}
unlock();
return true;
}
bool PresetCollection::clone_presets_for_printer(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::string const &printer)
bool PresetCollection::clone_presets_for_printer(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::string const &printer, bool force_rewritten)
{
return clone_presets(presets, failures, [printer](Preset &preset) {
preset.name = preset.alias + " @ " + printer;
preset.alias = preset.name;
auto *compatible_printers = dynamic_cast<ConfigOptionStrings*>(preset.config.option("compatible_printers"));
compatible_printers->values = std::vector<std::string>{ printer };
});
}, force_rewritten);
}
bool PresetCollection::create_presets_from_template_for_printer(std::vector<std::string> const &templates, std::vector<std::string> &failures, std::string const &printer)
@@ -2125,13 +2131,15 @@ bool PresetCollection::create_presets_from_template_for_printer(std::vector<std:
bool PresetCollection::clone_presets_for_filament(std::vector<Preset const *> const &presets,
std::vector<std::string> & failures,
std::string const & filament_name,
std::string const & filament_id)
std::string const & filament_id,
bool force_rewritten)
{
return clone_presets(presets, failures, [filament_name, filament_id](Preset &preset) {
preset.name = filament_name + " " + preset.name.substr(preset.name.find_last_of('@'));
preset.alias = filament_name;
preset.filament_id = filament_id;
});
},
force_rewritten);
}
std::map<std::string, std::vector<Preset const *>> PresetCollection::get_filament_presets() const

View File

@@ -449,10 +449,10 @@ public:
Preset& load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select = true, Semver file_version = Semver(), bool is_custom_defined = false);
Preset& load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select = true, Semver file_version = Semver(), bool is_custom_defined = false);
bool clone_presets(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::function<void(Preset &)> modifier);
bool clone_presets_for_printer(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::string const &printer);
bool clone_presets(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::function<void(Preset &)> modifier, bool force_rewritten = false);
bool clone_presets_for_printer(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::string const &printer, bool force_rewritten = false);
bool create_presets_from_template_for_printer(std::vector<std::string> const &templates, std::vector<std::string> &failures, std::string const &printer);
bool clone_presets_for_filament(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::string const &filament_name, std::string const &filament_id);
bool clone_presets_for_filament(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::string const &filament_name, std::string const &filament_id, bool force_rewritten = false);
std::map<std::string, std::vector<Preset const *>> get_filament_presets() const;

View File

@@ -1202,7 +1202,6 @@ VendorProfile PresetBundle::get_custom_vendor_models() const
iter_model = vendor.models.emplace(vendor.models.end(), VendorProfile::PrinterModel{});
iter_model->name = model;
}
iter_model->variants.push_back(variant);
}
return vendor;
}

View File

@@ -416,6 +416,8 @@ set(SLIC3R_GUI_SOURCES
GUI/Calibration.cpp
GUI/PrintOptionsDialog.hpp
GUI/PrintOptionsDialog.cpp
GUI/CreatePresetsDialog.hpp
GUI/CreatePresetsDialog.cpp
Utils/json_diff.hpp
Utils/json_diff.cpp
GUI/KBShortcutsDialog.hpp

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,248 @@
#ifndef slic3r_CreatePresetsDialog_hpp_
#define slic3r_CreatePresetsDialog_hpp_
#include "libslic3r/Preset.hpp"
#include "wxExtensions.hpp"
#include "GUI_Utils.hpp"
#include "Widgets/Label.hpp"
#include "Widgets/TextInput.hpp"
#include "Widgets/Button.hpp"
#include "Widgets/RadioBox.hpp"
#include "Widgets/CheckBox.hpp"
#include "Widgets/ComboBox.hpp"
namespace Slic3r {
namespace GUI {
class CreateFilamentPresetDialog : public DPIDialog
{
public:
CreateFilamentPresetDialog(wxWindow *parent);
~CreateFilamentPresetDialog();
protected:
enum FilamentOptionType {
VENDOR = 0,
TYPE,
SERIAL,
FILAMENT_PRESET,
PRESET_FOR_PRINTER,
FILAMENT_NAME_COUNT
};
protected:
void on_dpi_changed(const wxRect &suggested_rect) override;
wxBoxSizer *create_item(FilamentOptionType option_type);
wxBoxSizer *create_vendor_item();
wxBoxSizer *create_type_item();
wxBoxSizer *create_serial_item();
wxBoxSizer *create_filament_preset_item();
wxBoxSizer *create_filament_preset_for_printer_item();
wxBoxSizer *create_button_item();
private:
void clear_filament_preset_map();
wxArrayString get_filament_preset_choices();
wxBoxSizer * create_radio_item(wxString title, wxWindow *parent, wxString tooltip, std::vector<std::pair<RadioBox *, wxString>> &radiobox_list);
void select_curr_radiobox(std::vector<std::pair<RadioBox *, wxString>> &radiobox_list, int btn_idx);
wxString curr_create_filament_type();
void get_filament_presets_by_machine();
void get_all_filament_presets();
private:
struct CreateType
{
wxString base_filament;
wxString base_filament_preset;
};
private:
std::vector<std::pair<RadioBox *, wxString>> m_create_type_btns;
std::vector<std::pair<CheckBox *, Preset *>> m_filament_preset;
std::unordered_map<CheckBox *, Preset *> m_machint_filament_preset;
std::unordered_map<std::string, std::vector<Preset *>> m_filament_choice_map;
std::unordered_map<std::string, std::string> m_public_name_to_filament_id_map;
std::unordered_map<std::string, Preset *> m_all_presets_map;
CreateType m_create_type;
Button * m_button_create = nullptr;
Button * m_button_cancel = nullptr;
ComboBox * m_filament_vendor_combobox = nullptr;
ComboBox * m_filament_type_combobox = nullptr;
ComboBox * m_exist_vendor_combobox = nullptr;
ComboBox * m_filament_preset_combobox = nullptr;
TextInput * m_filament_custom_vendor_input = nullptr;
wxGridSizer * m_filament_presets_sizer = nullptr;
wxPanel * m_filament_preset_panel = nullptr;
TextInput * m_filament_serial_input = nullptr;
};
class CreatePrinterPresetDialog : public DPIDialog
{
public:
CreatePrinterPresetDialog(wxWindow *parent);
~CreatePrinterPresetDialog();
protected:
void on_dpi_changed(const wxRect &suggested_rect) override;
/******************************************************** Control Construction *****************************************************/
wxBoxSizer *create_step_switch_item();
//Create Printer Page1
void create_printer_page1(wxWindow *parent);
wxBoxSizer *create_type_item(wxWindow *parent);
wxBoxSizer *create_printer_item(wxWindow *parent);
wxBoxSizer *create_nozzle_diameter_item(wxWindow *parent);
wxBoxSizer *create_bed_shape_item(wxWindow *parent);
wxBoxSizer *create_bed_size_item(wxWindow *parent);
wxBoxSizer *create_origin_item(wxWindow *parent);
wxBoxSizer *create_hot_bed_stl_item(wxWindow *parent);
wxBoxSizer *create_hot_bed_svg_item(wxWindow *parent);
wxBoxSizer *create_max_print_height_item(wxWindow *parent);
wxBoxSizer *create_page1_btns_item(wxWindow *parent);
//Improt Presets Page2
void create_printer_page2(wxWindow *parent);
wxBoxSizer *create_printer_preset_item(wxWindow *parent);
wxBoxSizer *create_presets_item(wxWindow *parent);
wxBoxSizer *create_presets_template_item(wxWindow *parent);
wxBoxSizer *create_page2_btns_item(wxWindow *parent);
void show_page1();
void show_page2();
/********************************************************** Data Interaction *******************************************************/
bool data_init();
void select_curr_radiobox(std::vector<std::pair<RadioBox *, wxString>> &radiobox_list, int btn_idx);
void select_all_preset_template(std::vector<std::pair<CheckBox *, Preset *>> &preset_templates);
void deselect_all_preset_template(std::vector<std::pair<CheckBox *, Preset *>> &preset_templates);
void update_presets_list();
void on_preset_model_value_change(wxCommandEvent &e);
void clear_preset_combobox();
void save_preset_config(Preset *preset);
bool validate_input_valid();
wxArrayString printer_preset_sort_with_nozzle_diameter(const VendorProfile &vendor_profile, float nozzle_diameter);
wxBoxSizer *create_radio_item(wxString title, wxWindow *parent, wxString tooltip, std::vector<std::pair<RadioBox *, wxString>> &radiobox_list);
wxString curr_create_preset_type();
wxString curr_create_printer_type();
private:
std::vector<std::pair<RadioBox *, wxString>> m_create_type_btns;
std::vector<std::pair<RadioBox *, wxString>> m_create_presets_btns;
std::vector<std::pair<CheckBox *, Preset *>> m_filament_preset;
std::vector<std::pair<CheckBox *, Preset *>> m_process_preset;
std::vector<wxString> m_create_printer_type;
std::vector<wxString> m_create_presets_type;
VendorProfile m_printer_preset_vendor_selected;
Slic3r::VendorProfile::PrinterModel m_printer_preset_model_selected;
bool rewritten = false;
Preset * m_printer_preset = nullptr;
wxStaticBitmap * m_step_1 = nullptr;
wxStaticBitmap * m_step_2 = nullptr;
Button * m_button_OK = nullptr;
Button * m_button_create = nullptr;
Button * m_button_page1_cancel = nullptr;
Button * m_button_page2_cancel = nullptr;
Button * m_button_page2_back = nullptr;
Button * m_button_bed_stl = nullptr;
Button * m_button_bed_svg = nullptr;
wxWindow * m_page1 = nullptr;
wxWindow * m_page2 = nullptr;
ComboBox * m_select_vendor = nullptr;
ComboBox * m_select_model = nullptr;
ComboBox * m_select_printer = nullptr;
CheckBox * m_can_not_find_vendor_combox = nullptr;
wxStaticText * m_can_not_find_vendor_text = nullptr;
wxTextCtrl * m_custom_vendor_model = nullptr;
ComboBox * m_nozzle_diameter = nullptr;
ComboBox * m_printer_vendor = nullptr;
ComboBox * m_printer_model = nullptr;
TextInput * m_bed_size_x_input = nullptr;
TextInput * m_bed_size_y_input = nullptr;
TextInput * m_bed_origin_x_input = nullptr;
TextInput * m_bed_origin_y_input = nullptr;
TextInput * m_print_height_input = nullptr;
wxGridSizer * m_filament_preset_template_sizer = nullptr;
wxGridSizer * m_process_preset_template_sizer = nullptr;
wxPanel * m_filament_preset_panel = nullptr;
wxPanel * m_process_preset_panel = nullptr;
wxPanel * m_preset_template_panel = nullptr;
};
enum SuccessType {
PRINTER = 0,
FILAMENT
};
class CreatePresetSuccessfulDialog : public DPIDialog
{
public:
CreatePresetSuccessfulDialog(wxWindow *parent, const SuccessType &create_success_type);
~CreatePresetSuccessfulDialog();
protected:
void on_dpi_changed(const wxRect &suggested_rect) override;
private:
Button *m_button_ok = nullptr;
Button *m_button_cancel = nullptr;
};
class ExportConfigsDialog : public DPIDialog
{
public:
ExportConfigsDialog(wxWindow *parent);
~ExportConfigsDialog();//to do: delete preset
protected:
void on_dpi_changed(const wxRect &suggested_rect) override;
wxBoxSizer *create_txport_config_item(wxWindow* parent);
wxBoxSizer *create_button_item(wxWindow *parent);
wxBoxSizer *create_select_printer(wxWindow *parent);
wxBoxSizer *create_radio_item(wxString title, wxWindow *parent, wxString tooltip, std::vector<std::pair<RadioBox *, wxString>> &radiobox_list);
struct ExportType
{
wxString preset_bundle;
wxString printer_preset;
wxString filament_preset;
wxString process_preset;
};
enum ExportCase {
INITIALIZE_FAIL = 0,
ADD_FILE_FAIL,
FINALIZE_FAIL,
OPEN_ZIP_WRITTEN_FILE,
EXPORT_SUCCESS,
};
private:
void data_init();
void select_curr_radiobox(std::vector<std::pair<RadioBox *, wxString>> &radiobox_list, int btn_idx);
ExportCase archive_preset_bundle_to_file(const wxString &path);
ExportCase archive_printer_preset_to_file(const wxString &path);
ExportCase archive_filament_preset_to_file(const wxString &path);
ExportCase archive_process_preset_to_file(const wxString &path);
private:
std::vector<std::pair<RadioBox *, wxString>> m_export_type_btns;
std::vector<std::pair<CheckBox *, Preset *>> m_preset;
std::unordered_map<std::string, Preset *> m_printer_presets;
std::unordered_map<std::string, std::vector<Preset *>> m_filament_presets;
std::unordered_map<std::string, std::vector<Preset *>> m_process_presets;
ExportType m_exprot_type;
wxGridSizer * m_preset_sizer = nullptr;
wxWindow * m_presets_window = nullptr;
Button * m_button_ok = nullptr;
Button * m_button_cancel = nullptr;
};
}
}
#endif

View File

@@ -3128,6 +3128,10 @@ struct ConfigsOverwriteConfirmDialog : MessageDialog
void MainFrame::export_config()
{
ExportConfigsDialog export_configs_dlg(nullptr);
export_configs_dlg.ShowModal();
return;
// Generate a cummulative configuration for the selected print, filaments and printer.
wxDirDialog dlg(this, _L("Choose a directory"),
from_u8(!m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir()), wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);

View File

@@ -564,10 +564,45 @@ Sidebar::Sidebar(Plater *parent)
wxGetApp().run_wizard(ConfigWizard::RR_USER, ConfigWizard::SP_PRINTERS);
});
StateColor create_printer_bg_col(std::pair<wxColour, int>(wxColour(219, 253, 231), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Normal));
StateColor create_printer_fg_col(std::pair<wxColour, int>(wxColour(107, 107, 106), StateColor::Pressed),
std::pair<wxColour, int>(wxColour(107, 107, 106), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(107, 107, 106), StateColor::Normal));
StateColor create_printer_bd_col(std::pair<wxColour, int>(wxColour(0, 174, 66), StateColor::Pressed), std::pair<wxColour, int>(wxColour(0, 174, 66), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(172, 172, 172), StateColor::Normal));
auto create_printer_preset_btn = new Button(p->m_panel_printer_title, _L("Create Printer"));
create_printer_preset_btn->SetFont(Label::Body_10);
create_printer_preset_btn->SetPaddingSize(wxSize(FromDIP(8), FromDIP(3)));
create_printer_preset_btn->SetCornerRadius(FromDIP(8));
create_printer_preset_btn->SetBackgroundColor(create_printer_bg_col);
create_printer_preset_btn->SetBorderColor(create_printer_bd_col);
create_printer_preset_btn->SetTextColor(create_printer_fg_col);
create_printer_preset_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) {
//CreateFilamentPresetDialog dlg(p->m_panel_printer_title);
CreatePrinterPresetDialog dlg(p->m_panel_printer_title);
int res = dlg.ShowModal();
if (wxID_OK == res) {
wxGetApp().mainframe->update_side_preset_ui();
update_all_preset_comboboxes();
CreatePresetSuccessfulDialog success_dlg(p->m_panel_filament_title, SuccessType::PRINTER);
int res = success_dlg.ShowModal();
if (res == wxID_OK) {
p->editing_filament = -1;
if (p->combo_printer->switch_to_tab())
p->editing_filament = 0;
}
}
});
wxBoxSizer* h_sizer_title = new wxBoxSizer(wxHORIZONTAL);
h_sizer_title->Add(p->m_printer_icon, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, em);
h_sizer_title->Add(p->m_text_printer_settings, 0, wxALIGN_CENTER);
h_sizer_title->AddStretchSpacer();
h_sizer_title->Add(create_printer_preset_btn, 0, wxRIGHT | wxALIGN_CENTER, FromDIP(10));
h_sizer_title->Add(p->m_printer_setting, 0, wxALIGN_CENTER);
h_sizer_title->Add(15 * em / 10, 0, 0, 0, 0);
h_sizer_title->SetMinSize(-1, 3 * em);
@@ -788,6 +823,31 @@ Sidebar::Sidebar(Plater *parent)
wxPostEvent(parent, SimpleEvent(EVT_SCHEDULE_BACKGROUND_PROCESS, parent));
}
}));
auto create_filament_preset_btn = new Button(p->m_panel_filament_title, _L("Create Filament"));
create_filament_preset_btn->SetFont(Label::Body_10);
create_filament_preset_btn->SetPaddingSize(wxSize(FromDIP(8), FromDIP(3)));
create_filament_preset_btn->SetCornerRadius(FromDIP(8));
create_filament_preset_btn->SetBackgroundColor(flush_bg_col);
create_filament_preset_btn->SetBorderColor(flush_bd_col);
create_filament_preset_btn->SetTextColor(flush_fg_col);
create_filament_preset_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) {
CreateFilamentPresetDialog dlg(p->m_panel_filament_title);
//CreatePrinterPresetDialog dlg(p->m_panel_filament_title);
int res = dlg.ShowModal();
if (wxID_OK == res) {
wxGetApp().mainframe->update_side_preset_ui();
update_ui_from_settings();
update_all_preset_comboboxes();
CreatePresetSuccessfulDialog success_dlg(p->m_panel_filament_title, SuccessType::FILAMENT);
int res = success_dlg.ShowModal();
/*if (res == wxID_OK) {
p->editing_filament = 0;
p->combos_filament[0]->switch_to_tab();
}*/
}
});
bSizer39->Add(create_filament_preset_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(5));
bSizer39->Add(p->m_flushing_volume_btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(5));
bSizer39->Hide(p->m_flushing_volume_btn);
bSizer39->Add(FromDIP(10), 0, 0, 0, 0 );

View File

@@ -25,6 +25,7 @@
#include "libslic3r/PrintBase.hpp"
#include "libslic3r/Calib.hpp"
#include "libslic3r/FlushVolCalc.hpp"
#include "CreatePresetsDialog.hpp"
#define FILAMENT_SYSTEM_COLORS_NUM 16

View File

@@ -3682,7 +3682,7 @@ void SelectMachineDialog::set_default_normal()
auto dialogSize = this->GetSize();
#ifdef __WINDOWS__
if (screenSize.y < dialogSize.y) {
if (screenSize.GetHeight() < dialogSize.GetHeight()) {
m_need_adaptation_screen = true;
m_scrollable_view->SetScrollRate(0, 5);
m_scrollable_view->SetSize(wxSize(-1, FromDIP(220)));
@@ -3843,7 +3843,7 @@ void SelectMachineDialog::set_default_from_sdcard()
auto dialogSize = this->GetSize();
#ifdef __WINDOWS__
if (screenSize.y < dialogSize.y) {
if (screenSize.GetHeight() < dialogSize.GetHeight()) {
m_need_adaptation_screen = true;
m_scrollable_view->SetScrollRate(0, 5);
m_scrollable_view->SetSize(wxSize(-1, FromDIP(220)));