ENH: remove create filament entry to guide

Jira: 4036

Change-Id: I86aa3423761956120e9bf42dcb8eca76dd44202b
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>
This commit is contained in:
maosheng.wei 2023-09-26 11:49:13 +08:00 committed by Lane.Wei
parent ffcfb4f6bd
commit 735ef3dc8a
24 changed files with 3398 additions and 329 deletions

View file

@ -2143,23 +2143,47 @@ bool PresetCollection::clone_presets_for_printer(std::vector<Preset const *> con
}, 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)
bool PresetCollection::create_presets_from_template_for_printer(std::vector<Preset const *> const & templates,
std::vector<std::string> & failures,
std::string const & printer,
std::function<std::string(std::string)> create_filament_id,
bool force_rewritten)
{
return false;
return clone_presets(templates, failures, [printer, create_filament_id](Preset &preset, Preset::Type &type) {
preset.name = preset.name.substr(0, preset.name.find("@")) + " @" + printer;
auto *compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers"));
compatible_printers->values = std::vector<std::string>{ printer };
preset.is_visible = true;
if (type == Preset::TYPE_FILAMENT)
preset.filament_id = create_filament_id(preset.name);
}, force_rewritten);
}
bool PresetCollection::clone_presets_for_filament(std::vector<Preset const *> const &presets,
bool PresetCollection::clone_presets_for_filament(Preset const * const &preset,
std::vector<std::string> & failures,
std::string const & filament_name,
std::string const & filament_id,
const std::string & vendor_name,
const std::string & compatible_printers,
bool force_rewritten)
{
return clone_presets(presets, failures, [filament_name, filament_id, vendor_name](Preset &preset, Preset::Type &type) {
preset.name = filament_name + " " + preset.name.substr(preset.name.find_last_of('@'));
if (type == Preset::TYPE_FILAMENT)
preset.config.option<ConfigOptionStrings>("filament_vendor", true)->values[0] = vendor_name;
preset.filament_id = filament_id;
std::vector<Preset const *> const presets = {preset};
return clone_presets(presets, failures, [&filament_name, &filament_id, &vendor_name, &compatible_printers](Preset &preset, Preset::Type &type) {
preset.name = filament_name + " @" + compatible_printers;
if (type == Preset::TYPE_FILAMENT) {
auto filament_vendor = preset.config.option<ConfigOptionStrings>("filament_vendor", true);
if (filament_vendor->values.empty()) {
filament_vendor->values.push_back(vendor_name);
} else {
filament_vendor->values = {vendor_name};
}
auto compatible_printers_option = preset.config.option<ConfigOptionStrings>("compatible_printers", true);
if (compatible_printers_option->values.empty()) { compatible_printers_option->values.push_back(compatible_printers);
} else {
compatible_printers_option->values = {compatible_printers};
}
preset.filament_id = filament_id;
}
},
force_rewritten);
}

View file

@ -20,6 +20,8 @@
#define PRESET_PRINTER_NAME "machine"
#define PRESET_SLA_PRINT_NAME "sla_print"
#define PRESET_SLA_MATERIALS_NAME "sla_materials"
#define PRESET_PROFILES_DIR "profiles"
#define PRESET_TEMPLATE_DIR "Template"
//BBS: iot preset type strings
#define PRESET_IOT_PRINTER_TYPE "printer"
@ -57,6 +59,9 @@
#define BBL_JSON_KEY_DEFAULT_MATERIALS "default_materials"
#define BBL_JSON_KEY_MODEL_ID "model_id"
//BBL: json path
namespace Slic3r {
class AppConfig;
@ -452,8 +457,10 @@ public:
bool clone_presets(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::function<void(Preset &, Preset::Type &)> 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, const std::string& vendor, bool force_rewritten = false);
bool create_presets_from_template_for_printer(
std::vector<Preset const *> const &templates, std::vector<std::string> &failures, std::string const &printer, std::function <std::string(std::string)> create_filament_id, bool force_rewritten = false);
bool clone_presets_for_filament(Preset const * const &preset, std::vector<std::string> &failures, std::string const &filament_name, std::string const &filament_id, const std::string& vendor,
const std::string& compatible_printers, bool force_rewritten = false);
std::map<std::string, std::vector<Preset const *>> get_filament_presets() const;

View file

@ -3270,7 +3270,7 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
}
config = *default_config;
config.apply(config_src);
if (instantiation == "false") {
if (instantiation == "false" && "Template" != vendor_name) {
config_maps.emplace(preset_name, std::move(config));
if ((presets_collection->type() == Preset::TYPE_FILAMENT) && (!filament_id.empty()))
filament_id_maps.emplace(preset_name, filament_id);
@ -3348,7 +3348,7 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
loaded.setting_id = setting_id;
loaded.filament_id = filament_id;
if (presets_collection->type() == Preset::TYPE_FILAMENT) {
if (filament_id.empty()) {
if (filament_id.empty() && "Template" != vendor_name) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": can not find filament_id for " << preset_name;
//throw ConfigurationError(format("can not find inherits %1% for %2%", inherits, preset_name));
reason = "Can not find filament_id for " + preset_name;

File diff suppressed because it is too large Load diff

View file

@ -15,10 +15,17 @@
namespace Slic3r {
namespace GUI {
class FilamentInfomation : public wxObject
{
public:
std::string filament_id;
std::string filament_name;
};
class CreateFilamentPresetDialog : public DPIDialog
{
public:
CreateFilamentPresetDialog(wxWindow *parent, bool modify_filament = false);
CreateFilamentPresetDialog(wxWindow *parent);
~CreateFilamentPresetDialog();
protected:
@ -58,24 +65,23 @@ private:
};
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<wxString, std::string> m_public_name_to_filament_id_map;
std::unordered_map<std::string, Preset *> m_all_presets_map;
bool m_modify_filament;
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;
std::vector<std::pair<RadioBox *, wxString>> m_create_type_btns;
std::unordered_map<CheckBox *, std::pair<std::string, Preset *>> m_filament_preset;
std::unordered_map<CheckBox *, std::pair<std::string, Preset *>> m_machint_filament_preset;
std::unordered_map<std::string, std::vector<Preset *>> m_filament_choice_map;
std::unordered_map<wxString, 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;
};
@ -117,7 +123,7 @@ protected:
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 update_presets_list(bool jast_template = false);
void on_preset_model_value_change(wxCommandEvent &e);
void clear_preset_combobox();
bool save_printable_area_config(Preset *preset);
@ -125,6 +131,7 @@ protected:
bool validate_input_valid();
void load_texture();
void load_model_stl();
bool load_system_and_user_presets_with_curr_model(PresetBundle &temp_preset_bundle, bool just_template = false);
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);
@ -133,12 +140,19 @@ protected:
wxString curr_create_printer_type();
private:
struct CreatePrinterType
{
wxString create_printer;
wxString create_nozzle;
wxString base_template;
wxString base_curr_printer;
};
CreatePrinterType m_create_type;
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;
@ -262,6 +276,67 @@ private:
wxStaticText * m_serial_text = nullptr;
};
class CreatePresetForPrinterDialog : public DPIDialog
{
public:
CreatePresetForPrinterDialog(wxWindow *parent, std::string filament_type, std::string filament_id, std::string filament_vendor, std::string filament_name);
~CreatePresetForPrinterDialog();
private:
void on_dpi_changed(const wxRect &suggested_rect) override;
void get_visible_printer_and_compatible_filament_presets();
wxBoxSizer *create_selected_printer_preset_sizer();
wxBoxSizer *create_selected_filament_preset_sizer();
wxBoxSizer *create_button_sizer();
private:
std::string m_filament_id;
std::string m_filament_name;
std::string m_filament_vendor;
std::string m_filament_type;
std::shared_ptr<PresetBundle> m_preset_bundle;
std::string m_filamnt_type;
ComboBox * m_selected_printer = nullptr;
ComboBox * m_selected_filament = nullptr;
Button * m_ok_btn = nullptr;
Button * m_cancel_btn = nullptr;
std::unordered_map<wxString, std::shared_ptr<Preset>> printer_choice_to_printer_preset;
std::unordered_map<wxString, std::shared_ptr<Preset>> filament_choice_to_filament_preset;
std::unordered_map<std::shared_ptr<Preset>, std::vector<std::shared_ptr<Preset>>> m_printer_compatible_filament_presets;//need be used when add presets
};
class EditFilamentPresetDialog : public DPIDialog
{
public:
EditFilamentPresetDialog(wxWindow *parent, FilamentInfomation *filament_info);
~EditFilamentPresetDialog();
private:
void on_dpi_changed(const wxRect &suggested_rect) override;
bool get_same_filament_id_presets(std::string filament_id);
void update_preset_tree();
wxBoxSizer *create_filament_basic_info();
wxBoxSizer *create_add_filament_btn();
wxBoxSizer *create_preset_tree_sizer();
wxBoxSizer *create_button_sizer();
private:
std::string m_filament_id;
std::string m_filament_name;
std::string m_vendor_name;
std::string m_filament_type;
std::string m_filament_serial;
Button * m_add_filament_btn = nullptr;
Button * m_del_filament_btn = nullptr;
Button * m_ok_btn = nullptr;
Button * m_cancel_btn = nullptr;
wxGridSizer * m_preset_tree_sizer = nullptr;
wxScrolledWindow * m_preset_tree_window = nullptr;
std::unordered_map<std::string, std::vector<std::shared_ptr<Preset>>> m_printer_compatible_presets;
};
}
}
#endif

View file

@ -175,6 +175,10 @@ wxDEFINE_EVENT(EVT_GLCANVAS_COLOR_MODE_CHANGED, SimpleEvent);
//BBS: print
wxDEFINE_EVENT(EVT_PRINT_FROM_SDCARD_VIEW, SimpleEvent);
wxDEFINE_EVENT(EVT_CREATE_FILAMENT, SimpleEvent);
wxDEFINE_EVENT(EVT_MODIFY_FILAMENT, SimpleEvent);
bool Plater::has_illegal_filename_characters(const wxString& wxs_name)
{
@ -790,31 +794,7 @@ 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 );
@ -1008,7 +988,7 @@ Sidebar::~Sidebar() {}
void Sidebar::create_printer_preset()
{
CreatePrinterPresetDialog dlg(p->m_panel_printer_title);
CreatePrinterPresetDialog dlg(wxGetApp().mainframe);
int res = dlg.ShowModal();
if (wxID_OK == res) {
wxGetApp().mainframe->update_side_preset_ui();
@ -2317,6 +2297,8 @@ struct Plater::priv
void on_action_split_objects(SimpleEvent&);
void on_action_split_volumes(SimpleEvent&);
void on_action_layersediting(SimpleEvent&);
void on_create_filament(SimpleEvent &);
void on_modify_filament(SimpleEvent &);
void on_object_select(SimpleEvent&);
void on_plate_name_change(SimpleEvent &);
@ -2545,6 +2527,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
this->q->Bind(EVT_PREVIEW_ONLY_MODE_HINT, &priv::show_preview_only_hint, this);
this->q->Bind(EVT_GLCANVAS_COLOR_MODE_CHANGED, &priv::on_change_color_mode, this);
this->q->Bind(wxEVT_SYS_COLOUR_CHANGED, &priv::on_apple_change_color_mode, this);
this->q->Bind(EVT_CREATE_FILAMENT, &priv::on_create_filament, this);
this->q->Bind(EVT_MODIFY_FILAMENT, &priv::on_modify_filament, this);
view3D = new View3D(q, bed, &model, config, &background_process);
//BBS: use partplater's gcode
@ -7519,6 +7503,33 @@ void Plater::priv::on_action_layersediting(SimpleEvent&)
notification_manager->set_move_from_overlay(view3D->is_layers_editing_enabled());
}
void Plater::priv::on_create_filament(SimpleEvent &)
{
CreateFilamentPresetDialog dlg(wxGetApp().mainframe);
int res = dlg.ShowModal();
if (wxID_OK == res) {
wxGetApp().mainframe->update_side_preset_ui();
update_ui_from_settings();
sidebar->update_all_preset_comboboxes();
CreatePresetSuccessfulDialog success_dlg(wxGetApp().mainframe, SuccessType::FILAMENT);
int res = success_dlg.ShowModal();
}
}
void Plater::priv::on_modify_filament(SimpleEvent &evt)
{
FilamentInfomation * filament_info = static_cast<FilamentInfomation *>(evt.GetEventObject());
EditFilamentPresetDialog dlg(wxGetApp().mainframe, filament_info);
int res = dlg.ShowModal();
if (wxID_OK == res) {
wxGetApp().mainframe->update_side_preset_ui();
update_ui_from_settings();
sidebar->update_all_preset_comboboxes();
/*CreatePresetSuccessfulDialog success_dlg(wxGetApp().mainframe, SuccessType::FILAMENT);
int res = success_dlg.ShowModal();*/
}
}
void Plater::priv::enter_gizmos_stack()
{
assert(m_undo_redo_stack_active == &m_undo_redo_stack_main);

View file

@ -96,7 +96,8 @@ wxDECLARE_EVENT(EVT_UPDATE_PLUGINS_WHEN_LAUNCH, wxCommandEvent);
wxDECLARE_EVENT(EVT_PREVIEW_ONLY_MODE_HINT, wxCommandEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_COLOR_MODE_CHANGED, SimpleEvent);
wxDECLARE_EVENT(EVT_PRINT_FROM_SDCARD_VIEW, SimpleEvent);
wxDECLARE_EVENT(EVT_CREATE_FILAMENT, SimpleEvent);
wxDECLARE_EVENT(EVT_MODIFY_FILAMENT, SimpleEvent);
const wxString DEFAULT_PROJECT_NAME = "Untitled";

View file

@ -27,6 +27,7 @@
#include <slic3r/Utils/Http.hpp>
#include <libslic3r/miniz_extension.hpp>
#include <libslic3r/Utils.hpp>
#include "CreatePresetsDialog.hpp"
using namespace nlohmann;
@ -34,6 +35,34 @@ namespace Slic3r { namespace GUI {
json m_ProfileJson;
static wxString update_custom_filaments()
{
json m_Res = json::object();
m_Res["command"] = "update_custom_filaments";
m_Res["sequence_id"] = "2000";
json m_CustomFilaments = json::array();
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
std::map<std::string, std::vector<Preset const *>> temp_filament_id_to_presets = preset_bundle->filaments.get_filament_presets();
json temp_j;
for (std::pair<std::string, std::vector<Preset const *>> filament_id_to_presets : temp_filament_id_to_presets) {
std::string filament_id = filament_id_to_presets.first;
if (filament_id.empty()) continue;
for (const Preset *preset : filament_id_to_presets.second) {
if (preset->is_system || filament_id.empty() || "null" == filament_id || filament_id.size() != 8 || filament_id[0] != 'P') break;
temp_j["id"] = preset->filament_id;
std::string preset_name = preset->name;
size_t index_at = preset_name.find_last_of('@');
if (std::string::npos != index_at) { preset_name = preset_name.substr(0, index_at - 1); }
temp_j["name"] = preset_name;
m_CustomFilaments.push_back(temp_j);
break;
}
}
m_Res["data"] = m_CustomFilaments;
wxString strJS = wxString::Format("HandleStudio(%s)", wxString::FromUTF8(m_Res.dump(-1, ' ', false, json::error_handler_t::ignore)));
return strJS;
}
GuideFrame::GuideFrame(GUI_App *pGUI, long style)
: DPIDialog((wxWindow *) (pGUI->mainframe), wxID_ANY, "BambuStudio", wxDefaultPosition, wxDefaultSize, style),
m_appconfig_new()
@ -322,6 +351,20 @@ void GuideFrame::OnScriptMessage(wxWebViewEvent &evt)
wxGetApp().CallAfter([this,strJS] { RunScript(strJS); });
}
else if (strCmd == "request_custom_filaments") {
wxString strJS = update_custom_filaments();
wxGetApp().CallAfter([this, strJS] { RunScript(strJS); });
}
else if (strCmd == "create_custom_filament") {
this->EndModal(wxID_OK);
wxQueueEvent(wxGetApp().plater(), new SimpleEvent(EVT_CREATE_FILAMENT));
} else if (strCmd == "modify_custom_filament") {
this->EndModal(wxID_OK);
FilamentInfomation *filament_info = new FilamentInfomation();
filament_info->filament_id = j["id"];
//filament_info->filament_name = j["name"];
wxQueueEvent(wxGetApp().plater(), new SimpleEvent(EVT_MODIFY_FILAMENT, filament_info));
}
else if (strCmd == "save_userguide_models")
{
json MSelected = j["data"];