Skip to content

Commit

Permalink
ENH: custom filament sync with printer
Browse files Browse the repository at this point in the history
1. prompt sync user presets when create custom filament
2. Fix the issue of not displaying printers when creating custom Filaments based on presets when selecting PLA Aero Type.
3. Optimizing the traversal logic during AMS Setting Pop up reduces time complexity and allows for quick pop ups. Additionally, using nozzle calibers for retrieval and repairing custom materials may result in inaccurate retrieval.
4. Implement synchronization logic with the printer
	-a. Received slot information, reset the slot when the "filament_id" in the information does not exist in Studio
	-b. Received slot information, the nozzle temperature in the information is different from the preset nozzle temperature in Studio, reset the current temperature.

Jira: none

Change-Id: I511dc82563ec77a341839671d398607048ce1985
Signed-off-by: maosheng.wei <[email protected]>
  • Loading branch information
DanBao-Bambu authored and lanewei120 committed Mar 25, 2024
1 parent d75e79c commit 626e2a9
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 80 deletions.
4 changes: 4 additions & 0 deletions src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,10 @@ std::map<std::string, std::vector<Preset const *>> PresetCollection::get_filamen
{
std::map<std::string, std::vector<Preset const *>> filament_presets;
for (auto &preset : m_presets) {
if (preset.is_user()) {
if (preset.inherits() == "") { filament_presets[preset.filament_id].push_back(&preset); }
continue;
}
if (get_preset_base(preset) == &preset) { filament_presets[preset.filament_id].push_back(&preset); }
}
return filament_presets;
Expand Down
22 changes: 22 additions & 0 deletions src/libslic3r/PresetBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,28 @@ void PresetBundle::set_calibrate_printer(std::string name)
}
}

std::set<std::string> PresetBundle::get_printer_names_by_printer_type_and_nozzle(const std::string &printer_type, const std::string &nozzle_diameter_str)
{
std::set<std::string> printer_names;
std::ostringstream stream;

for (auto printer_it = this->printers.begin(); printer_it != this->printers.end(); printer_it++) {
if (!printer_it->is_system) continue;

ConfigOption * printer_model_opt = printer_it->config.option("printer_model");
ConfigOptionString *printer_model_str = dynamic_cast<ConfigOptionString *>(printer_model_opt);
if (!printer_model_str) continue;

// use printer_model as printer type
if (printer_model_str->value != printer_type) continue;

if (printer_it->name.find(nozzle_diameter_str) != std::string::npos) printer_names.insert(printer_it->name);
}
assert(printer_names.size() == 1);

return printer_names;
}

//BBS: check whether this is the only edited filament
bool PresetBundle::is_the_only_edited_filament(unsigned int filament_index)
{
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/PresetBundle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class PresetBundle

void set_calibrate_printer(std::string name);

std::set<std::string> get_printer_names_by_printer_type_and_nozzle(const std::string &printer_type, const std::string &nozzle_diameter_str);

PresetCollection prints;
PresetCollection sla_prints;
PresetCollection filaments;
Expand Down
119 changes: 54 additions & 65 deletions src/slic3r/GUI/AMSMaterialsSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,12 @@ void AMSMaterialsSetting::Popup(wxString filament, wxString sn, wxString temp_mi


std::set<std::string> filament_id_set;

PresetBundle* preset_bundle = wxGetApp().preset_bundle;
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
std::ostringstream stream;
stream << std::fixed << std::setprecision(1) << obj->nozzle_diameter;
std::string nozzle_diameter_str = stream.str();
std::set<std::string> printer_names = preset_bundle->get_printer_names_by_printer_type_and_nozzle(MachineObject::get_preset_printer_model_name(obj->printer_type), nozzle_diameter_str);

if (preset_bundle) {
BOOST_LOG_TRIVIAL(trace) << "system_preset_bundle filament number=" << preset_bundle->filaments.size();
for (auto filament_it = preset_bundle->filaments.begin(); filament_it != preset_bundle->filaments.end(); filament_it++) {
Expand All @@ -805,79 +809,64 @@ void AMSMaterialsSetting::Popup(wxString filament, wxString sn, wxString temp_mi
if (preset_bundle->filaments.get_preset_base(*filament_it) != &preset || (!filament_it->is_system && !obj->is_support_user_preset)) {
continue;
}

for (auto printer_it = preset_bundle->printers.begin(); printer_it != preset_bundle->printers.end(); printer_it++) {
// filter by system preset
if (!printer_it->is_system) continue;
// get printer_model
ConfigOption* printer_model_opt = printer_it->config.option("printer_model");
ConfigOptionString* printer_model_str = dynamic_cast<ConfigOptionString*>(printer_model_opt);
if (!printer_model_str )
continue;

// use printer_model as printer type
if (printer_model_str->value != MachineObject::get_preset_printer_model_name(obj->printer_type))
continue;
ConfigOption* printer_opt = filament_it->config.option("compatible_printers");
ConfigOptionStrings* printer_strs = dynamic_cast<ConfigOptionStrings*>(printer_opt);
for (auto printer_str : printer_strs->values) {
if (printer_it->name == printer_str) {
if (filament_id_set.find(filament_it->filament_id) != filament_id_set.end()) {
continue;
}
else {
filament_id_set.insert(filament_it->filament_id);
// name matched
if (filament_it->is_system) {
filament_items.push_back(filament_it->alias);
ConfigOption * printer_opt = filament_it->config.option("compatible_printers");
ConfigOptionStrings *printer_strs = dynamic_cast<ConfigOptionStrings *>(printer_opt);
for (auto printer_str : printer_strs->values) {
if (printer_names.find(printer_str) != printer_names.end()) {
if (filament_id_set.find(filament_it->filament_id) != filament_id_set.end()) {
continue;
} else {
filament_id_set.insert(filament_it->filament_id);
// name matched
if (filament_it->is_system) {
filament_items.push_back(filament_it->alias);
FilamentInfos filament_infos;
filament_infos.filament_id = filament_it->filament_id;
filament_infos.setting_id = filament_it->setting_id;
map_filament_items[filament_it->alias] = filament_infos;
} else {
char target = '@';
size_t pos = filament_it->name.find(target);
if (pos != std::string::npos) {
std::string user_preset_alias = filament_it->name.substr(0, pos - 1);
wxString wx_user_preset_alias = wxString(user_preset_alias.c_str(), wxConvUTF8);
user_preset_alias = wx_user_preset_alias.ToStdString();

filament_items.push_back(user_preset_alias);
FilamentInfos filament_infos;
filament_infos.filament_id = filament_it->filament_id;
filament_infos.setting_id = filament_it->setting_id;
map_filament_items[filament_it->alias] = filament_infos;
}
else {
char target = '@';
size_t pos = filament_it->name.find(target);
if (pos != std::string::npos) {
std::string user_preset_alias = filament_it->name.substr(0, pos-1);
wxString wx_user_preset_alias = wxString(user_preset_alias.c_str(), wxConvUTF8);
user_preset_alias = wx_user_preset_alias.ToStdString();

filament_items.push_back(user_preset_alias);
FilamentInfos filament_infos;
filament_infos.filament_id = filament_it->filament_id;
filament_infos.setting_id = filament_it->setting_id;
map_filament_items[user_preset_alias] = filament_infos;
}

filament_infos.filament_id = filament_it->filament_id;
filament_infos.setting_id = filament_it->setting_id;
map_filament_items[user_preset_alias] = filament_infos;
}
}

if (filament_it->filament_id == ams_filament_id) {
selection_idx = idx;

// update if nozzle_temperature_range is found
ConfigOption* opt_min = filament_it->config.option("nozzle_temperature_range_low");
if (opt_min) {
ConfigOptionInts* opt_min_ints = dynamic_cast<ConfigOptionInts*>(opt_min);
if (opt_min_ints) {
wxString text_nozzle_temp_min = wxString::Format("%d", opt_min_ints->get_at(0));
m_input_nozzle_min->GetTextCtrl()->SetValue(text_nozzle_temp_min);
}
if (filament_it->filament_id == ams_filament_id) {
selection_idx = idx;

// update if nozzle_temperature_range is found
ConfigOption *opt_min = filament_it->config.option("nozzle_temperature_range_low");
if (opt_min) {
ConfigOptionInts *opt_min_ints = dynamic_cast<ConfigOptionInts *>(opt_min);
if (opt_min_ints) {
wxString text_nozzle_temp_min = wxString::Format("%d", opt_min_ints->get_at(0));
m_input_nozzle_min->GetTextCtrl()->SetValue(text_nozzle_temp_min);
}
ConfigOption* opt_max = filament_it->config.option("nozzle_temperature_range_high");
if (opt_max) {
ConfigOptionInts* opt_max_ints = dynamic_cast<ConfigOptionInts*>(opt_max);
if (opt_max_ints) {
wxString text_nozzle_temp_max = wxString::Format("%d", opt_max_ints->get_at(0));
m_input_nozzle_max->GetTextCtrl()->SetValue(text_nozzle_temp_max);
}
}
ConfigOption *opt_max = filament_it->config.option("nozzle_temperature_range_high");
if (opt_max) {
ConfigOptionInts *opt_max_ints = dynamic_cast<ConfigOptionInts *>(opt_max);
if (opt_max_ints) {
wxString text_nozzle_temp_max = wxString::Format("%d", opt_max_ints->get_at(0));
m_input_nozzle_max->GetTextCtrl()->SetValue(text_nozzle_temp_max);
}
}
idx++;
}
idx++;
}
}
}

}
}

Expand Down
23 changes: 16 additions & 7 deletions src/slic3r/GUI/CreatePresetsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ void CreateFilamentPresetDialog::get_filament_presets_by_machine()

if (filament_types && filament_types->values.empty()) continue;
const std::string filament_type = filament_types->values[0];
if (filament_type != type_name) {
if (filament_type != system_filament_types_map[type_name]) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " preset type is not selected type and preset name is: " << preset->name;
continue;
}
Expand Down Expand Up @@ -3217,18 +3217,22 @@ CreatePresetSuccessfulDialog::CreatePresetSuccessfulDialog(wxWindow *parent, con
wxBoxSizer *success_text_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *success_text;
wxStaticText *next_step_text;
bool sync_user_preset_need_enabled = wxGetApp().getAgent() && wxGetApp().app_config->get("sync_user_preset") == "false";
switch (create_success_type) {
case PRINTER:
success_text = new wxStaticText(this, wxID_ANY, _L("Printer Created"));
next_step_text = new wxStaticText(this, wxID_ANY, _L("Please go to printer settings to edit your presets"));
break;
case FILAMENT:
success_text = new wxStaticText(this, wxID_ANY, _L("Filament Created"));
next_step_text = new wxStaticText(this, wxID_ANY, _L("Please go to filament setting to edit your presets if you need.\nPlease note that nozzle temperature, hot bed temperature, and maximum volumetric speed has a significant impact on printing quality. Please set them carefully."));
wxString prompt_text = _L("Please go to filament setting to edit your presets if you need.\nPlease note that nozzle temperature, hot bed temperature, and maximum "
"volumetric speed has a significant impact on printing quality. Please set them carefully.");
wxString sync_text = sync_user_preset_need_enabled ? _L("\n\nStudio has detected that your user presets synchronization function is not enabled, which may result in unsuccessful Filament settings on "
"the Device page. \nClick \"Sync user presets\" to enable the synchronization function.") : "";
next_step_text = new wxStaticText(this, wxID_ANY, prompt_text + sync_text);
break;
}
success_text->SetFont(Label::Head_18);
//next_step_text->SetFont(Label::Body_14);
success_text_sizer->Add(success_text, 0, wxEXPAND, 0);
success_text_sizer->Add(next_step_text, 0, wxEXPAND | wxTOP, FromDIP(5));
horizontal_sizer->Add(success_text_sizer, 0, wxEXPAND | wxALL, FromDIP(5));
Expand All @@ -3242,8 +3246,7 @@ CreatePresetSuccessfulDialog::CreatePresetSuccessfulDialog(wxWindow *parent, con
case PRINTER:
m_button_ok = new Button(this, _L("Printer Setting"));
break;
case FILAMENT:
m_button_ok = new Button(this, _L("OK"));
case FILAMENT: m_button_ok = sync_user_preset_need_enabled ? new Button(this, _L("Sync user presets")) : new Button(this, _L("OK"));
break;
}
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(27, 136, 68), StateColor::Pressed), std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Hovered),
Expand All @@ -3260,9 +3263,15 @@ CreatePresetSuccessfulDialog::CreatePresetSuccessfulDialog(wxWindow *parent, con
m_button_ok->SetCornerRadius(FromDIP(12));
btn_sizer->Add(m_button_ok, 0, wxRIGHT, FromDIP(10));

m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { EndModal(wxID_OK); });
m_button_ok->Bind(wxEVT_LEFT_DOWN, [this, sync_user_preset_need_enabled](wxMouseEvent &e) {
if (sync_user_preset_need_enabled) {
wxGetApp().app_config->set("sync_user_preset", "true");
wxGetApp().start_sync_user_preset();
}
EndModal(wxID_OK);
});

if (PRINTER == create_success_type) {
if (PRINTER == create_success_type || sync_user_preset_need_enabled) {
m_button_cancel = new Button(this, _L("Cancel"));
m_button_cancel->SetBackgroundColor(btn_bg_white);
m_button_cancel->SetBorderColor(wxColour(38, 46, 48));
Expand Down
Loading

0 comments on commit 626e2a9

Please sign in to comment.